From 828055bb66a9facffc0628874ffe313b5eb57bae Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 7 Dec 2023 09:31:45 -0800 Subject: [PATCH] Added GetTextureComponentMappingString function --- .../interface/GraphicsAccessories.hpp | 2 + .../src/GraphicsAccessories.cpp | 22 +++++++++++ .../GraphicsEngine/interface/TextureView.h | 4 +- .../GraphicsAccessoriesTest.cpp | 37 +++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/Graphics/GraphicsAccessories/interface/GraphicsAccessories.hpp b/Graphics/GraphicsAccessories/interface/GraphicsAccessories.hpp index cec105af7..6f746e7df 100644 --- a/Graphics/GraphicsAccessories/interface/GraphicsAccessories.hpp +++ b/Graphics/GraphicsAccessories/interface/GraphicsAccessories.hpp @@ -734,6 +734,8 @@ TEXTURE_FORMAT TexFormatToSRGB(TEXTURE_FORMAT Fmt); String GetPipelineShadingRateFlagsString(PIPELINE_SHADING_RATE_FLAGS Flags); +String GetTextureComponentMappingString(const TextureComponentMapping& Mapping); + /// Returns the sparse texture properties assuming the standard tile shapes SparseTextureProperties GetStandardSparseTextureProperties(const TextureDesc& TexDesc); diff --git a/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp b/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp index 90a39dc91..fe58b2f8d 100644 --- a/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp +++ b/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp @@ -2245,6 +2245,28 @@ String GetPipelineShadingRateFlagsString(PIPELINE_SHADING_RATE_FLAGS Flags) return Result; } +String GetTextureComponentMappingString(const TextureComponentMapping& Mapping) +{ + static_assert(TEXTURE_COMPONENT_SWIZZLE_IDENTITY == 0, "TEXTURE_COMPONENT_SWIZZLE_IDENTITY == 0 is assumed below"); + static_assert(TEXTURE_COMPONENT_SWIZZLE_ZERO == 1, "TEXTURE_COMPONENT_SWIZZLE_ZERO == 1 is assumed below"); + static_assert(TEXTURE_COMPONENT_SWIZZLE_ONE == 2, "TEXTURE_COMPONENT_SWIZZLE_ONE == 2 is assumed below"); + static_assert(TEXTURE_COMPONENT_SWIZZLE_R == 3, "TEXTURE_COMPONENT_SWIZZLE_R == 3 is assumed below"); + static_assert(TEXTURE_COMPONENT_SWIZZLE_G == 4, "TEXTURE_COMPONENT_SWIZZLE_G == 4 is assumed below"); + static_assert(TEXTURE_COMPONENT_SWIZZLE_B == 5, "TEXTURE_COMPONENT_SWIZZLE_B == 5 is assumed below"); + static_assert(TEXTURE_COMPONENT_SWIZZLE_A == 6, "TEXTURE_COMPONENT_SWIZZLE_A == 6 is assumed below"); + String Str; + Str.reserve(4); + for (size_t Comp = 0; Comp < 4; ++Comp) + { + TEXTURE_COMPONENT_SWIZZLE ComponentSwizzle = Mapping[Comp]; + if (ComponentSwizzle == TEXTURE_COMPONENT_SWIZZLE_IDENTITY) + Str += "rgba"[Comp]; + else + Str += "_01rgba"[ComponentSwizzle]; + } + return Str; +} + SparseTextureProperties GetStandardSparseTextureProperties(const TextureDesc& TexDesc) { constexpr Uint32 SparseBlockSize = 64 << 10; diff --git a/Graphics/GraphicsEngine/interface/TextureView.h b/Graphics/GraphicsEngine/interface/TextureView.h index f02876b60..1c86bb58f 100644 --- a/Graphics/GraphicsEngine/interface/TextureView.h +++ b/Graphics/GraphicsEngine/interface/TextureView.h @@ -156,12 +156,12 @@ struct TextureComponentMapping return !(*this == RHS); } - constexpr TEXTURE_COMPONENT_SWIZZLE operator[](Uint32 Component) const + constexpr TEXTURE_COMPONENT_SWIZZLE operator[](size_t Component) const { return (&R)[Component]; } - constexpr TEXTURE_COMPONENT_SWIZZLE& operator[](Uint32 Component) + constexpr TEXTURE_COMPONENT_SWIZZLE& operator[](size_t Component) { return (&R)[Component]; } diff --git a/Tests/DiligentCoreTest/src/GraphicsAccessories/GraphicsAccessoriesTest.cpp b/Tests/DiligentCoreTest/src/GraphicsAccessories/GraphicsAccessoriesTest.cpp index c3b450779..ff1f016e9 100644 --- a/Tests/DiligentCoreTest/src/GraphicsAccessories/GraphicsAccessoriesTest.cpp +++ b/Tests/DiligentCoreTest/src/GraphicsAccessories/GraphicsAccessoriesTest.cpp @@ -739,6 +739,43 @@ TEST(GraphicsAccessories_GraphicsAccessories, GetPipelineShadingRateFlagsString) EXPECT_STREQ(GetPipelineShadingRateFlagsString(PIPELINE_SHADING_RATE_FLAG_PER_PRIMITIVE | PIPELINE_SHADING_RATE_FLAG_TEXTURE_BASED).c_str(), "PER_PRIMITIVE | TEXTURE_BASED"); } +TEST(GraphicsAccessories_GraphicsAccessories, GetTextureComponentMappingString) +{ + EXPECT_STREQ(GetTextureComponentMappingString(TextureComponentMapping::Identity()).c_str(), "rgba"); + EXPECT_STREQ(GetTextureComponentMappingString( + TextureComponentMapping(TEXTURE_COMPONENT_SWIZZLE_ZERO, TEXTURE_COMPONENT_SWIZZLE_ZERO, TEXTURE_COMPONENT_SWIZZLE_ZERO, TEXTURE_COMPONENT_SWIZZLE_ZERO)) + .c_str(), + "0000"); + EXPECT_STREQ(GetTextureComponentMappingString( + TextureComponentMapping(TEXTURE_COMPONENT_SWIZZLE_ONE, TEXTURE_COMPONENT_SWIZZLE_ONE, TEXTURE_COMPONENT_SWIZZLE_ONE, TEXTURE_COMPONENT_SWIZZLE_ONE)) + .c_str(), + "1111"); + EXPECT_STREQ(GetTextureComponentMappingString( + TextureComponentMapping(TEXTURE_COMPONENT_SWIZZLE_R, TEXTURE_COMPONENT_SWIZZLE_R, TEXTURE_COMPONENT_SWIZZLE_R, TEXTURE_COMPONENT_SWIZZLE_R)) + .c_str(), + "rrrr"); + EXPECT_STREQ(GetTextureComponentMappingString( + TextureComponentMapping(TEXTURE_COMPONENT_SWIZZLE_G, TEXTURE_COMPONENT_SWIZZLE_G, TEXTURE_COMPONENT_SWIZZLE_G, TEXTURE_COMPONENT_SWIZZLE_G)) + .c_str(), + "gggg"); + EXPECT_STREQ(GetTextureComponentMappingString( + TextureComponentMapping(TEXTURE_COMPONENT_SWIZZLE_B, TEXTURE_COMPONENT_SWIZZLE_B, TEXTURE_COMPONENT_SWIZZLE_B, TEXTURE_COMPONENT_SWIZZLE_B)) + .c_str(), + "bbbb"); + EXPECT_STREQ(GetTextureComponentMappingString( + TextureComponentMapping(TEXTURE_COMPONENT_SWIZZLE_A, TEXTURE_COMPONENT_SWIZZLE_A, TEXTURE_COMPONENT_SWIZZLE_A, TEXTURE_COMPONENT_SWIZZLE_A)) + .c_str(), + "aaaa"); + EXPECT_STREQ(GetTextureComponentMappingString( + TextureComponentMapping(TEXTURE_COMPONENT_SWIZZLE_A, TEXTURE_COMPONENT_SWIZZLE_B, TEXTURE_COMPONENT_SWIZZLE_G, TEXTURE_COMPONENT_SWIZZLE_R)) + .c_str(), + "abgr"); + EXPECT_STREQ(GetTextureComponentMappingString( + TextureComponentMapping(TEXTURE_COMPONENT_SWIZZLE_IDENTITY, TEXTURE_COMPONENT_SWIZZLE_IDENTITY, TEXTURE_COMPONENT_SWIZZLE_IDENTITY, TEXTURE_COMPONENT_SWIZZLE_ONE)) + .c_str(), + "rgb1"); +} + TEST(GraphicsAccessories_GraphicsAccessories, GetMipLevelProperties) { TextureDesc Desc;