Skip to content

Commit

Permalink
Fix DEBUG_COMMAND_STREAM mode
Browse files Browse the repository at this point in the history
Fixes #7966
  • Loading branch information
pixelflinger committed Jan 16, 2025
1 parent c435fc7 commit 288e81f
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 34 deletions.
6 changes: 6 additions & 0 deletions filament/backend/include/backend/DescriptorSetOffsetArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include <backend/DriverApiForward.h>

#include <utils/ostream.h>

#include <initializer_list>
#include <memory>

Expand Down Expand Up @@ -98,4 +100,8 @@ class DescriptorSetOffsetArray {

} // namespace filament::backend

#if !defined(NDEBUG)
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::DescriptorSetOffsetArray& rhs);
#endif

#endif //TNT_FILAMENT_BACKEND_COMMANDSTREAMVECTOR_H
35 changes: 5 additions & 30 deletions filament/backend/include/backend/DriverEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,18 +440,6 @@ enum class SamplerType : uint8_t {
SAMPLER_CUBEMAP_ARRAY, //!< Cube map array texture (feature level 2)
};

inline const char* stringify(SamplerType samplerType) {
switch (samplerType) {
case SamplerType::SAMPLER_2D: return "SAMPLER_2D";
case SamplerType::SAMPLER_2D_ARRAY: return "SAMPLER_2D_ARRAY";
case SamplerType::SAMPLER_CUBEMAP: return "SAMPLER_CUBEMAP";
case SamplerType::SAMPLER_EXTERNAL: return "SAMPLER_EXTERNAL";
case SamplerType::SAMPLER_3D: return "SAMPLER_3D";
case SamplerType::SAMPLER_CUBEMAP_ARRAY: return "SAMPLER_CUBEMAP_ARRAY";
}
return "UNKNOWN";
}

//! Subpass type
enum class SubpassType : uint8_t {
SUBPASS_INPUT
Expand Down Expand Up @@ -781,23 +769,6 @@ enum class TextureUsage : uint16_t {
ALL_ATTACHMENTS = COLOR_ATTACHMENT | DEPTH_ATTACHMENT | STENCIL_ATTACHMENT | SUBPASS_INPUT, //!< Mask of all attachments
};

inline const char* stringify(TextureUsage usage) {
switch (usage) {
case TextureUsage::NONE: return "NONE";
case TextureUsage::COLOR_ATTACHMENT: return "COLOR_ATTACHMENT";
case TextureUsage::DEPTH_ATTACHMENT: return "DEPTH_ATTACHMENT";
case TextureUsage::STENCIL_ATTACHMENT: return "STENCIL_ATTACHMENT";
case TextureUsage::UPLOADABLE: return "UPLOADABLE";
case TextureUsage::SAMPLEABLE: return "SAMPLEABLE";
case TextureUsage::SUBPASS_INPUT: return "SUBPASS_INPUT";
case TextureUsage::BLIT_SRC: return "BLIT_SRC";
case TextureUsage::BLIT_DST: return "BLIT_DST";
case TextureUsage::PROTECTED: return "PROTECTED";
case TextureUsage::DEFAULT: return "DEFAULT";
default: return "UNKNOWN";
}
}

//! Texture swizzle
enum class TextureSwizzle : uint8_t {
SUBSTITUTE_ZERO,
Expand Down Expand Up @@ -1381,12 +1352,16 @@ utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::Textu
utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::TextureUsage usage);
utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::BufferObjectBinding binding);
utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::TextureSwizzle swizzle);
utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::ShaderStage shaderStage);
utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::ShaderStageFlags stageFlags);
utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::CompilerPriorityQueue compilerPriorityQueue);
utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::PushConstantVariant pushConstantVariant);
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::AttributeArray& type);
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::DescriptorSetLayout& dsl);
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::PolygonOffset& po);
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::RasterState& rs);
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::RenderPassParams& b);
utils::io::ostream& operator<<(utils::io::ostream& out, const filament::backend::Viewport& v);
utils::io::ostream& operator<<(utils::io::ostream& out, filament::backend::ShaderStageFlags stageFlags);
#endif

#endif // TNT_FILAMENT_BACKEND_DRIVERENUMS_H
2 changes: 1 addition & 1 deletion filament/backend/src/CommandStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static void printParameterPack(io::ostream& out, const FIRST& first, const REMAI
}

static UTILS_NOINLINE UTILS_UNUSED std::string extractMethodName(std::string& command) noexcept {
constexpr const char startPattern[] = "::Command<&(filament::backend::Driver::";
constexpr const char startPattern[] = "::Command<&filament::backend::Driver::";
auto pos = command.rfind(startPattern);
auto end = command.rfind('(');
pos += sizeof(startPattern) - 1;
Expand Down
11 changes: 9 additions & 2 deletions filament/backend/src/Handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@

#include <backend/Handle.h>

#include <utils/compiler.h>
#include <utils/CallStack.h>
#include <utils/ostream.h>

#ifndef NDEBUG
# include <string>
#endif

#include <utils/CallStack.h>
#include <stddef.h>

using namespace utils;

namespace filament::backend {

#ifndef NDEBUG

static char const * const kOurNamespace = "filament::backend";
static char const * const kOurNamespace = "filament::backend::";

// removes all occurrences of "what" from "str"
UTILS_NOINLINE
Expand Down Expand Up @@ -67,6 +71,9 @@ template io::ostream& operator<<(io::ostream& out, const Handle<HwSwapChain>& h)
template io::ostream& operator<<(io::ostream& out, const Handle<HwStream>& h) noexcept;
template io::ostream& operator<<(io::ostream& out, const Handle<HwTimerQuery>& h) noexcept;
template io::ostream& operator<<(io::ostream& out, const Handle<HwBufferObject>& h) noexcept;
template io::ostream& operator<<(io::ostream& out, const Handle<HwDescriptorSet>& h) noexcept;
template io::ostream& operator<<(io::ostream& out, const Handle<HwDescriptorSetLayout>& h) noexcept;
template io::ostream& operator<<(io::ostream& out, const Handle<HwVertexBufferInfo>& h) noexcept;

#endif

Expand Down
30 changes: 30 additions & 0 deletions filament/backend/src/metal/MetalDriver.mm
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,36 @@
}
}

// fixme: TextureUsage is a bitfield
inline const char* stringify(TextureUsage usage) {
switch (usage) {
case TextureUsage::NONE: return "NONE";
case TextureUsage::COLOR_ATTACHMENT: return "COLOR_ATTACHMENT";
case TextureUsage::DEPTH_ATTACHMENT: return "DEPTH_ATTACHMENT";
case TextureUsage::STENCIL_ATTACHMENT: return "STENCIL_ATTACHMENT";
case TextureUsage::UPLOADABLE: return "UPLOADABLE";
case TextureUsage::SAMPLEABLE: return "SAMPLEABLE";
case TextureUsage::SUBPASS_INPUT: return "SUBPASS_INPUT";
case TextureUsage::BLIT_SRC: return "BLIT_SRC";
case TextureUsage::BLIT_DST: return "BLIT_DST";
case TextureUsage::PROTECTED: return "PROTECTED";
case TextureUsage::DEFAULT: return "DEFAULT";
default: return "UNKNOWN";
}
}

inline const char* stringify(SamplerType samplerType) {
switch (samplerType) {
case SamplerType::SAMPLER_2D: return "SAMPLER_2D";
case SamplerType::SAMPLER_2D_ARRAY: return "SAMPLER_2D_ARRAY";
case SamplerType::SAMPLER_CUBEMAP: return "SAMPLER_CUBEMAP";
case SamplerType::SAMPLER_EXTERNAL: return "SAMPLER_EXTERNAL";
case SamplerType::SAMPLER_3D: return "SAMPLER_3D";
case SamplerType::SAMPLER_CUBEMAP_ARRAY: return "SAMPLER_CUBEMAP_ARRAY";
}
return "UNKNOWN";
}

void MetalDriver::createTextureR(Handle<HwTexture> th, SamplerType target, uint8_t levels,
TextureFormat format, uint8_t samples, uint32_t width, uint32_t height,
uint32_t depth, TextureUsage usage) {
Expand Down
47 changes: 46 additions & 1 deletion filament/backend/src/ostream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
*/

#include <backend/BufferDescriptor.h>
#include <backend/DescriptorSetOffsetArray.h>
#include <backend/DriverEnums.h>
#include <backend/PipelineState.h>
#include <backend/PixelBufferDescriptor.h>
#include <backend/TargetBufferInfo.h>

#include <utils/ostream.h>

#include <variant>

using namespace filament;
using namespace backend;
using namespace utils;
Expand Down Expand Up @@ -475,11 +478,53 @@ io::ostream& operator<<(io::ostream& out, RenderPassParams const& params) {
}

io::ostream& operator<<(io::ostream& out, MRT const& mrt) {
// TODO: implement decoding of enum
// TODO: implement decoding of MRT
out << "MRT{...}";
return out;
}

io::ostream& operator<<(io::ostream& out, ShaderStage shaderStage) {
switch (shaderStage) {
CASE(ShaderStage, VERTEX)
CASE(ShaderStage, FRAGMENT)
CASE(ShaderStage, COMPUTE)
}
return out;
}

io::ostream& operator<<(io::ostream& out, CompilerPriorityQueue compilerPriorityQueue) {
switch (compilerPriorityQueue) {
CASE(CompilerPriorityQueue, HIGH)
CASE(CompilerPriorityQueue, LOW)
}
return out;
}

io::ostream& operator<<(io::ostream& out, TextureUsage usage) {
// TODO: implement decoding of TextureUsage bitfield
out << uint32_t(usage);
return out;
}

io::ostream& operator<<(io::ostream& out, PushConstantVariant pushConstantVariant) {
std::visit([&](auto&& arg) {
out << arg;
}, pushConstantVariant);
return out;
}

io::ostream& operator<<(io::ostream& out, DescriptorSetLayout const& dsl) {
// TODO: implement decoding of DescriptorSetLayout
out << "DescriptorSetLayout{...}";
return out;
}

io::ostream& operator<<(io::ostream& out, DescriptorSetOffsetArray const& dsa) {
// TODO: implement decoding of DescriptorSetOffsetArray
out << "DescriptorSetOffsetArray{...}";
return out;
}

io::ostream& operator<<(io::ostream& stream, ShaderStageFlags stageFlags) {
const char* str = nullptr;
switch (stageFlags) {
Expand Down
5 changes: 5 additions & 0 deletions libs/utils/include/utils/CString.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// NOTE: this header should not include STL headers

#include <utils/compiler.h>
#include <utils/ostream.h>

#include <assert.h>
#include <stddef.h>
Expand Down Expand Up @@ -181,6 +182,10 @@ class UTILS_PUBLIC CString {
};

private:
#if !defined(NDEBUG)
friend io::ostream& operator<<(io::ostream& out, const CString& rhs);
#endif

struct Data {
size_type length;
};
Expand Down
7 changes: 7 additions & 0 deletions libs/utils/include/utils/Invocable.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef TNT_UTILS_INVOKABLE_H
#define TNT_UTILS_INVOKABLE_H

#include <utils/ostream.h>

#include <type_traits>
#include <utility>

Expand Down Expand Up @@ -81,6 +83,11 @@ class Invocable<R(Args...)> {
explicit operator bool() const noexcept;

private:
#if !defined(NDEBUG)
friend io::ostream& operator<<(io::ostream& out, const Invocable&) {
return out << "Invocable<>"; // TODO: is there a way to do better here?
}
#endif
void* mInvocable = nullptr;
void (*mDeleter)(void*) = nullptr;
R (* mInvoker)(void*, Args...) = nullptr;
Expand Down
8 changes: 8 additions & 0 deletions libs/utils/src/CString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <utils/CString.h>

#include <utils/compiler.h>
#include <utils/ostream.h>

#include <algorithm>
#include <memory>
Expand Down Expand Up @@ -97,4 +98,11 @@ CString& CString::replace(size_type pos, size_type len, const CString& str) noex
return *this;
}

#if !defined(NDEBUG)
io::ostream& operator<<(io::ostream& out, const utils::CString& rhs) {
return out << rhs.c_str_safe();
}
#endif

} // namespace utils

0 comments on commit 288e81f

Please sign in to comment.