diff --git a/filament/backend/include/backend/DescriptorSetOffsetArray.h b/filament/backend/include/backend/DescriptorSetOffsetArray.h index 3c7b85664bc..55c06dbeb2d 100644 --- a/filament/backend/include/backend/DescriptorSetOffsetArray.h +++ b/filament/backend/include/backend/DescriptorSetOffsetArray.h @@ -19,6 +19,8 @@ #include +#include + #include #include @@ -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 diff --git a/filament/backend/include/backend/DriverEnums.h b/filament/backend/include/backend/DriverEnums.h index 358c5420260..ea4c41dfd33 100644 --- a/filament/backend/include/backend/DriverEnums.h +++ b/filament/backend/include/backend/DriverEnums.h @@ -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 @@ -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, @@ -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 diff --git a/filament/backend/src/CommandStream.cpp b/filament/backend/src/CommandStream.cpp index d12ac923bb5..bb2207be530 100644 --- a/filament/backend/src/CommandStream.cpp +++ b/filament/backend/src/CommandStream.cpp @@ -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; diff --git a/filament/backend/src/Handle.cpp b/filament/backend/src/Handle.cpp index 91d0ee0a3a1..77c1fbc6be4 100644 --- a/filament/backend/src/Handle.cpp +++ b/filament/backend/src/Handle.cpp @@ -16,11 +16,15 @@ #include +#include +#include +#include + #ifndef NDEBUG # include #endif -#include +#include using namespace utils; @@ -28,7 +32,7 @@ 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 @@ -67,6 +71,9 @@ template io::ostream& operator<<(io::ostream& out, const Handle& h) template io::ostream& operator<<(io::ostream& out, const Handle& h) noexcept; template io::ostream& operator<<(io::ostream& out, const Handle& h) noexcept; template io::ostream& operator<<(io::ostream& out, const Handle& h) noexcept; +template io::ostream& operator<<(io::ostream& out, const Handle& h) noexcept; +template io::ostream& operator<<(io::ostream& out, const Handle& h) noexcept; +template io::ostream& operator<<(io::ostream& out, const Handle& h) noexcept; #endif diff --git a/filament/backend/src/metal/MetalDriver.mm b/filament/backend/src/metal/MetalDriver.mm index 46dcb3716ea..a8eee36dcb7 100644 --- a/filament/backend/src/metal/MetalDriver.mm +++ b/filament/backend/src/metal/MetalDriver.mm @@ -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 th, SamplerType target, uint8_t levels, TextureFormat format, uint8_t samples, uint32_t width, uint32_t height, uint32_t depth, TextureUsage usage) { diff --git a/filament/backend/src/ostream.cpp b/filament/backend/src/ostream.cpp index 36d93dfbec3..a7c8d0dafeb 100644 --- a/filament/backend/src/ostream.cpp +++ b/filament/backend/src/ostream.cpp @@ -15,6 +15,7 @@ */ #include +#include #include #include #include @@ -22,6 +23,8 @@ #include +#include + using namespace filament; using namespace backend; using namespace utils; @@ -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) { diff --git a/libs/utils/include/utils/CString.h b/libs/utils/include/utils/CString.h index d5b7695106d..9db39bc73fb 100644 --- a/libs/utils/include/utils/CString.h +++ b/libs/utils/include/utils/CString.h @@ -20,6 +20,7 @@ // NOTE: this header should not include STL headers #include +#include #include #include @@ -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; }; diff --git a/libs/utils/include/utils/Invocable.h b/libs/utils/include/utils/Invocable.h index 49b43071813..2243e7872c3 100644 --- a/libs/utils/include/utils/Invocable.h +++ b/libs/utils/include/utils/Invocable.h @@ -17,6 +17,8 @@ #ifndef TNT_UTILS_INVOKABLE_H #define TNT_UTILS_INVOKABLE_H +#include + #include #include @@ -81,6 +83,11 @@ class Invocable { 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; diff --git a/libs/utils/src/CString.cpp b/libs/utils/src/CString.cpp index 28b58d5f392..3e540a22e89 100644 --- a/libs/utils/src/CString.cpp +++ b/libs/utils/src/CString.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -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 +