diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-02-02 01:24:36 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-02-02 01:24:36 +0000 |
| commit | e577b44d66d75bdfcf6d80e0f5dcdb51fc46a11a (patch) | |
| tree | 224a4cefa9c85101cae58199d0e80cbbae74246d | |
| parent | Fixed gcc build error (diff) | |
| download | DiligentCore-e577b44d66d75bdfcf6d80e0f5dcdb51fc46a11a.tar.gz DiligentCore-e577b44d66d75bdfcf6d80e0f5dcdb51fc46a11a.zip | |
Reworked ShaderResourceLayoutTest.Textures and ShaderResourceLayoutTest.ImmutableSamplers to verify the actual texture contents
6 files changed, 204 insertions, 69 deletions
diff --git a/Tests/DiligentCoreAPITest/assets/shaders/ShaderResourceLayout/ImmutableSamplers.hlsl b/Tests/DiligentCoreAPITest/assets/shaders/ShaderResourceLayout/ImmutableSamplers.hlsl index 01418379..664818cc 100644 --- a/Tests/DiligentCoreAPITest/assets/shaders/ShaderResourceLayout/ImmutableSamplers.hlsl +++ b/Tests/DiligentCoreAPITest/assets/shaders/ShaderResourceLayout/ImmutableSamplers.hlsl @@ -14,41 +14,97 @@ SamplerState g_Tex2DArr_Static_sampler; SamplerState g_Tex2DArr_Mut_sampler [MUTABLE_TEX_ARRAY_SIZE]; SamplerState g_Tex2DArr_Dyn_sampler [DYNAMIC_TEX_ARRAY_SIZE]; +#ifdef VERTEX_SHADER -float4 UseResources() +# define Tex2D_Static_Ref float4(1, 0, 0, 0) +# define Tex2D_Mut_Ref float4(0, 1, 0, 0) +# define Tex2D_Dyn_Ref float4(0, 0, 1, 0) + +# define Tex2DArr_Static_Ref0 float4(1, 0, 0, 0) +# define Tex2DArr_Static_Ref1 float4(0, 1, 0, 0) + +# define Tex2DArr_Dyn_Ref0 float4(1, 0, 0, 0) +# define Tex2DArr_Dyn_Ref1 float4(0, 1, 0, 0) +# define Tex2DArr_Dyn_Ref2 float4(0, 0, 1, 0) + +#endif + +#ifdef PIXEL_SHADER + +# define Tex2D_Static_Ref float4(0, 1, 0, 0) +# define Tex2D_Mut_Ref float4(0, 0, 1, 0) +# define Tex2D_Dyn_Ref float4(0, 0, 0, 1) + +# define Tex2DArr_Static_Ref0 float4(0, 0, 1, 0) +# define Tex2DArr_Static_Ref1 float4(0, 0, 0, 1) + +# define Tex2DArr_Dyn_Ref0 float4(0, 1, 0, 0) +# define Tex2DArr_Dyn_Ref1 float4(0, 0, 1, 0) +# define Tex2DArr_Dyn_Ref2 float4(0, 0, 0, 1) + +#endif + +#define Tex2DArr_Mut_Ref0 float4(1, 0, 0, 0) +#define Tex2DArr_Mut_Ref1 float4(0, 1, 0, 0) +#define Tex2DArr_Mut_Ref2 float4(0, 0, 1, 0) +#define Tex2DArr_Mut_Ref3 float4(0, 0, 0, 1) + + +float4 CheckValue(float4 Val, float4 Expected) +{ + return float4(Val.x == Expected.x ? 1.0 : 0.0, + Val.y == Expected.y ? 1.0 : 0.0, + Val.z == Expected.z ? 1.0 : 0.0, + Val.w == Expected.w ? 1.0 : 0.0); +} + +float4 VerifyResources() { - float2 UV = float2(0.0, 0.0); - float4 f4Color = float4(0.0, 0.0, 0.0, 0.0); - f4Color += g_Tex2D_Static.SampleLevel(g_Tex2D_Static_sampler, UV.xy, 0.0); - f4Color += g_Tex2D_Mut. SampleLevel(g_Tex2D_Mut_sampler, UV.xy, 0.0); - f4Color += g_Tex2D_Dyn. SampleLevel(g_Tex2D_Dyn_sampler, UV.xy, 0.0); + float4 AllCorrect = float4(1.0, 1.0, 1.0, 1.0); - // glslang is not smart enough to unroll the loops even when explicitly told to do so + float2 UV = float2(0.5, 0.5); + AllCorrect *= CheckValue(g_Tex2D_Static.SampleLevel(g_Tex2D_Static_sampler, UV.xy, 0.0), Tex2D_Static_Ref); + AllCorrect *= CheckValue(g_Tex2D_Mut. SampleLevel(g_Tex2D_Mut_sampler, UV.xy, 0.0), Tex2D_Mut_Ref); + AllCorrect *= CheckValue(g_Tex2D_Dyn. SampleLevel(g_Tex2D_Dyn_sampler, UV.xy, 0.0), Tex2D_Dyn_Ref); - f4Color += g_Tex2DArr_Static[0].SampleLevel(g_Tex2DArr_Static_sampler, UV.xy, 0.0); - f4Color += g_Tex2DArr_Static[1].SampleLevel(g_Tex2DArr_Static_sampler, UV.xy, 0.0); + AllCorrect *= CheckValue(g_Tex2DArr_Static[0].SampleLevel(g_Tex2DArr_Static_sampler, UV.xy, 0.0), Tex2DArr_Static_Ref0); + AllCorrect *= CheckValue(g_Tex2DArr_Static[1].SampleLevel(g_Tex2DArr_Static_sampler, UV.xy, 0.0), Tex2DArr_Static_Ref1); - f4Color += g_Tex2DArr_Mut[0].SampleLevel(g_Tex2DArr_Mut_sampler[0], UV.xy, 0.0); - f4Color += g_Tex2DArr_Mut[1].SampleLevel(g_Tex2DArr_Mut_sampler[1], UV.xy, 0.0); - f4Color += g_Tex2DArr_Mut[2].SampleLevel(g_Tex2DArr_Mut_sampler[2], UV.xy, 0.0); - f4Color += g_Tex2DArr_Mut[3].SampleLevel(g_Tex2DArr_Mut_sampler[3], UV.xy, 0.0); + AllCorrect *= CheckValue(g_Tex2DArr_Mut[0].SampleLevel(g_Tex2DArr_Mut_sampler[0], UV.xy, 0.0), Tex2DArr_Mut_Ref0); + AllCorrect *= CheckValue(g_Tex2DArr_Mut[1].SampleLevel(g_Tex2DArr_Mut_sampler[1], UV.xy, 0.0), Tex2DArr_Mut_Ref1); + AllCorrect *= CheckValue(g_Tex2DArr_Mut[2].SampleLevel(g_Tex2DArr_Mut_sampler[2], UV.xy, 0.0), Tex2DArr_Mut_Ref2); + AllCorrect *= CheckValue(g_Tex2DArr_Mut[3].SampleLevel(g_Tex2DArr_Mut_sampler[3], UV.xy, 0.0), Tex2DArr_Mut_Ref3); - f4Color += g_Tex2DArr_Dyn[0].SampleLevel(g_Tex2DArr_Dyn_sampler[0], UV.xy, 0.0); - f4Color += g_Tex2DArr_Dyn[1].SampleLevel(g_Tex2DArr_Dyn_sampler[1], UV.xy, 0.0); - f4Color += g_Tex2DArr_Dyn[2].SampleLevel(g_Tex2DArr_Dyn_sampler[2], UV.xy, 0.0); + AllCorrect *= CheckValue(g_Tex2DArr_Dyn[0].SampleLevel(g_Tex2DArr_Dyn_sampler[0], UV.xy, 0.0), Tex2DArr_Dyn_Ref0); + AllCorrect *= CheckValue(g_Tex2DArr_Dyn[1].SampleLevel(g_Tex2DArr_Dyn_sampler[1], UV.xy, 0.0), Tex2DArr_Dyn_Ref1); + AllCorrect *= CheckValue(g_Tex2DArr_Dyn[2].SampleLevel(g_Tex2DArr_Dyn_sampler[2], UV.xy, 0.0), Tex2DArr_Dyn_Ref2); - return f4Color; + return AllCorrect; } -void VSMain(out float4 f4Color : COLOR, +void VSMain(in uint VertId : SV_VertexID, + out float4 f4Color : COLOR, out float4 f4Position : SV_Position) { - f4Color = UseResources(); - f4Position = float4(0.0, 0.0, 0.0, 1.0); + float4 Pos[6]; + Pos[0] = float4(-1.0, -0.5, 0.0, 1.0); + Pos[1] = float4(-0.5, +0.5, 0.0, 1.0); + Pos[2] = float4( 0.0, -0.5, 0.0, 1.0); + + Pos[3] = float4(+0.0, -0.5, 0.0, 1.0); + Pos[4] = float4(+0.5, +0.5, 0.0, 1.0); + Pos[5] = float4(+1.0, -0.5, 0.0, 1.0); + + f4Color = float4(VertId % 3 == 0 ? 1.0 : 0.0, + VertId % 3 == 1 ? 1.0 : 0.0, + VertId % 3 == 2 ? 1.0 : 0.0, + 1.0) * VerifyResources(); + + f4Position = Pos[VertId]; } float4 PSMain(in float4 in_f4Color : COLOR, in float4 f4Position : SV_Position) : SV_Target { - return in_f4Color + UseResources(); + return in_f4Color * VerifyResources(); } diff --git a/Tests/DiligentCoreAPITest/assets/shaders/ShaderResourceLayout/Textures.hlsl b/Tests/DiligentCoreAPITest/assets/shaders/ShaderResourceLayout/Textures.hlsl index 5f9ed026..ba32c315 100644 --- a/Tests/DiligentCoreAPITest/assets/shaders/ShaderResourceLayout/Textures.hlsl +++ b/Tests/DiligentCoreAPITest/assets/shaders/ShaderResourceLayout/Textures.hlsl @@ -8,40 +8,97 @@ Texture2D g_Tex2DArr_Dyn [DYNAMIC_TEX_ARRAY_SIZE]; // 3 SamplerState g_Sampler; -float4 UseResources() +#ifdef VERTEX_SHADER + +# define Tex2D_Static_Ref float4(1, 0, 0, 0) +# define Tex2D_Mut_Ref float4(0, 1, 0, 0) +# define Tex2D_Dyn_Ref float4(0, 0, 1, 0) + +# define Tex2DArr_Static_Ref0 float4(1, 0, 0, 0) +# define Tex2DArr_Static_Ref1 float4(0, 1, 0, 0) + +# define Tex2DArr_Dyn_Ref0 float4(1, 0, 0, 0) +# define Tex2DArr_Dyn_Ref1 float4(0, 1, 0, 0) +# define Tex2DArr_Dyn_Ref2 float4(0, 0, 1, 0) + +#endif + +#ifdef PIXEL_SHADER + +# define Tex2D_Static_Ref float4(0, 1, 0, 0) +# define Tex2D_Mut_Ref float4(0, 0, 1, 0) +# define Tex2D_Dyn_Ref float4(0, 0, 0, 1) + +# define Tex2DArr_Static_Ref0 float4(0, 0, 1, 0) +# define Tex2DArr_Static_Ref1 float4(0, 0, 0, 1) + +# define Tex2DArr_Dyn_Ref0 float4(0, 1, 0, 0) +# define Tex2DArr_Dyn_Ref1 float4(0, 0, 1, 0) +# define Tex2DArr_Dyn_Ref2 float4(0, 0, 0, 1) + +#endif + +#define Tex2DArr_Mut_Ref0 float4(1, 0, 0, 0) +#define Tex2DArr_Mut_Ref1 float4(0, 1, 0, 0) +#define Tex2DArr_Mut_Ref2 float4(0, 0, 1, 0) +#define Tex2DArr_Mut_Ref3 float4(0, 0, 0, 1) + + +float4 CheckValue(float4 Val, float4 Expected) { - float2 UV = float2(0.0, 0.0); - float4 f4Color = float4(0.0, 0.0, 0.0, 0.0); - f4Color += g_Tex2D_Static.SampleLevel(g_Sampler, UV.xy, 0.0); - f4Color += g_Tex2D_Mut. SampleLevel(g_Sampler, UV.xy, 0.0); - f4Color += g_Tex2D_Dyn. SampleLevel(g_Sampler, UV.xy, 0.0); + return float4(Val.x == Expected.x ? 1.0 : 0.0, + Val.y == Expected.y ? 1.0 : 0.0, + Val.z == Expected.z ? 1.0 : 0.0, + Val.w == Expected.w ? 1.0 : 0.0); +} - // glslang is not smart enough to unroll the loops even when explicitly told to do so +float4 VerifyResources() +{ + float4 AllCorrect = float4(1.0, 1.0, 1.0, 1.0); - f4Color += g_Tex2DArr_Static[0].SampleLevel(g_Sampler, UV.xy, 0.0); - f4Color += g_Tex2DArr_Static[1].SampleLevel(g_Sampler, UV.xy, 0.0); + float2 UV = float2(0.5, 0.5); + AllCorrect *= CheckValue(g_Tex2D_Static.SampleLevel(g_Sampler, UV.xy, 0.0), Tex2D_Static_Ref); + AllCorrect *= CheckValue(g_Tex2D_Mut. SampleLevel(g_Sampler, UV.xy, 0.0), Tex2D_Mut_Ref); + AllCorrect *= CheckValue(g_Tex2D_Dyn. SampleLevel(g_Sampler, UV.xy, 0.0), Tex2D_Dyn_Ref); - f4Color += g_Tex2DArr_Mut[0].SampleLevel(g_Sampler, UV.xy, 0.0); - f4Color += g_Tex2DArr_Mut[1].SampleLevel(g_Sampler, UV.xy, 0.0); - f4Color += g_Tex2DArr_Mut[2].SampleLevel(g_Sampler, UV.xy, 0.0); - f4Color += g_Tex2DArr_Mut[3].SampleLevel(g_Sampler, UV.xy, 0.0); + AllCorrect *= CheckValue(g_Tex2DArr_Static[0].SampleLevel(g_Sampler, UV.xy, 0.0), Tex2DArr_Static_Ref0); + AllCorrect *= CheckValue(g_Tex2DArr_Static[1].SampleLevel(g_Sampler, UV.xy, 0.0), Tex2DArr_Static_Ref1); - f4Color += g_Tex2DArr_Dyn[0].SampleLevel(g_Sampler, UV.xy, 0.0); - f4Color += g_Tex2DArr_Dyn[1].SampleLevel(g_Sampler, UV.xy, 0.0); - f4Color += g_Tex2DArr_Dyn[2].SampleLevel(g_Sampler, UV.xy, 0.0); + AllCorrect *= CheckValue(g_Tex2DArr_Mut[0].SampleLevel(g_Sampler, UV.xy, 0.0), Tex2DArr_Mut_Ref0); + AllCorrect *= CheckValue(g_Tex2DArr_Mut[1].SampleLevel(g_Sampler, UV.xy, 0.0), Tex2DArr_Mut_Ref1); + AllCorrect *= CheckValue(g_Tex2DArr_Mut[2].SampleLevel(g_Sampler, UV.xy, 0.0), Tex2DArr_Mut_Ref2); + AllCorrect *= CheckValue(g_Tex2DArr_Mut[3].SampleLevel(g_Sampler, UV.xy, 0.0), Tex2DArr_Mut_Ref3); - return f4Color; + AllCorrect *= CheckValue(g_Tex2DArr_Dyn[0].SampleLevel(g_Sampler, UV.xy, 0.0), Tex2DArr_Dyn_Ref0); + AllCorrect *= CheckValue(g_Tex2DArr_Dyn[1].SampleLevel(g_Sampler, UV.xy, 0.0), Tex2DArr_Dyn_Ref1); + AllCorrect *= CheckValue(g_Tex2DArr_Dyn[2].SampleLevel(g_Sampler, UV.xy, 0.0), Tex2DArr_Dyn_Ref2); + + return AllCorrect; } -void VSMain(out float4 f4Color : COLOR, +void VSMain(in uint VertId : SV_VertexID, + out float4 f4Color : COLOR, out float4 f4Position : SV_Position) { - f4Color = UseResources(); - f4Position = float4(0.0, 0.0, 0.0, 1.0); + float4 Pos[6]; + Pos[0] = float4(-1.0, -0.5, 0.0, 1.0); + Pos[1] = float4(-0.5, +0.5, 0.0, 1.0); + Pos[2] = float4( 0.0, -0.5, 0.0, 1.0); + + Pos[3] = float4(+0.0, -0.5, 0.0, 1.0); + Pos[4] = float4(+0.5, +0.5, 0.0, 1.0); + Pos[5] = float4(+1.0, -0.5, 0.0, 1.0); + + f4Color = float4(VertId % 3 == 0 ? 1.0 : 0.0, + VertId % 3 == 1 ? 1.0 : 0.0, + VertId % 3 == 2 ? 1.0 : 0.0, + 1.0) * VerifyResources(); + + f4Position = Pos[VertId]; } float4 PSMain(in float4 in_f4Color : COLOR, in float4 f4Position : SV_Position) : SV_Target { - return in_f4Color + UseResources(); + return in_f4Color * VerifyResources(); } diff --git a/Tests/DiligentCoreAPITest/include/TestingEnvironment.hpp b/Tests/DiligentCoreAPITest/include/TestingEnvironment.hpp index a3bbfbda..cb79e5d3 100644 --- a/Tests/DiligentCoreAPITest/include/TestingEnvironment.hpp +++ b/Tests/DiligentCoreAPITest/include/TestingEnvironment.hpp @@ -99,7 +99,7 @@ public: static TestingEnvironment* GetInstance() { return m_pTheEnvironment; } - RefCntAutoPtr<ITexture> CreateTexture(const char* Name, TEXTURE_FORMAT Fmt, BIND_FLAGS BindFlags, Uint32 Width, Uint32 Height); + RefCntAutoPtr<ITexture> CreateTexture(const char* Name, TEXTURE_FORMAT Fmt, BIND_FLAGS BindFlags, Uint32 Width, Uint32 Height, void* pInitData = nullptr); static void SetErrorAllowance(int NumErrorsToAllow, const char* InfoMessage = nullptr); diff --git a/Tests/DiligentCoreAPITest/src/ShaderResourceLayoutTest.cpp b/Tests/DiligentCoreAPITest/src/ShaderResourceLayoutTest.cpp index 400ac89b..41440235 100644 --- a/Tests/DiligentCoreAPITest/src/ShaderResourceLayoutTest.cpp +++ b/Tests/DiligentCoreAPITest/src/ShaderResourceLayoutTest.cpp @@ -27,6 +27,7 @@ #include <unordered_map> #include <vector> #include <algorithm> +#include <array> #include "TestingEnvironment.hpp" #include "ShaderMacroHelper.hpp" @@ -39,10 +40,15 @@ using namespace Diligent::Testing; namespace Diligent { -namespace Test + +namespace Testing { + void PrintShaderResources(IShader* pShader); -} +void RenderDrawCommandReference(ISwapChain* pSwapChain, const float* pClearColor = nullptr); + +} // namespace Testing + } // namespace Diligent namespace @@ -53,15 +59,14 @@ class ShaderResourceLayoutTest : public ::testing::Test protected: static void SetUpTestSuite() { - auto* pEnv = TestingEnvironment::GetInstance(); - auto pRenderTarget = pEnv->CreateTexture("ShaderResourceLayoutTest: test RTV", TEX_FORMAT_RGBA8_UNORM, BIND_RENDER_TARGET, 512, 512); - ASSERT_NE(pRenderTarget, nullptr); - pRTV = pRenderTarget->GetDefaultView(TEXTURE_VIEW_RENDER_TARGET); + auto* pEnv = TestingEnvironment::GetInstance(); + auto* pSwapChain = pEnv->GetSwapChain(); + RenderDrawCommandReference(pSwapChain); + pRTV = pSwapChain->GetCurrentBackBufferRTV(); } static void TearDownTestSuite() { - pRTV.Release(); TestingEnvironment::GetInstance()->Reset(); } @@ -141,7 +146,7 @@ protected: if (pShader && deviceCaps.Features.ShaderResourceQueries) { VerifyShaderResources(pShader, ExpectedResources, NumExpectedResources); - Diligent::Test::PrintShaderResources(pShader); + Diligent::Testing::PrintShaderResources(pShader); } return pShader; @@ -194,6 +199,7 @@ protected: GraphicsPipeline.RTVFormats[0] = TEX_FORMAT_RGBA8_UNORM; GraphicsPipeline.DSVFormat = TEX_FORMAT_UNKNOWN; + GraphicsPipeline.RasterizerDesc.CullMode = CULL_MODE_NONE; GraphicsPipeline.DepthStencilDesc.DepthEnable = False; pDevice->CreateGraphicsPipelineState(PSOCreateInfo, &pPSO); @@ -267,10 +273,10 @@ protected: void TestStructuredOrFormattedBuffer(bool IsFormatted); void TestRWStructuredOrFormattedBuffer(bool IsFormatted); - static RefCntAutoPtr<ITextureView> pRTV; + static ITextureView* pRTV; }; -RefCntAutoPtr<ITextureView> ShaderResourceLayoutTest::pRTV; +ITextureView* ShaderResourceLayoutTest::pRTV; #define SET_STATIC_VAR(PSO, ShaderFlags, VarName, SetMethod, ...) \ do \ @@ -404,24 +410,30 @@ void ShaderResourceLayoutTest::TestTexturesAndImtblSamplers(bool TestImtblSample std::vector<RefCntAutoPtr<ITexture>> pTextures(MaxTextures); std::vector<IDeviceObject*> pTexSRVs(MaxTextures); + constexpr Uint32 TexWidth = 256; + constexpr Uint32 TexHeight = 256; + + std::vector<Uint32> TexData(TexWidth * TexHeight); + std::array<Uint32, MaxTextures> TexColors = {0xFF, 0xFF00, 0xFF0000, 0xFF000000}; for (Uint32 i = 0; i < MaxTextures; ++i) { - pTextures[i] = pEnv->CreateTexture("Test texture", TEX_FORMAT_RGBA8_UNORM, BIND_SHADER_RESOURCE, 256, 256); + std::fill(TexData.begin(), TexData.end(), TexColors[i]); + pTextures[i] = pEnv->CreateTexture("Test texture", TEX_FORMAT_RGBA8_UNORM, BIND_SHADER_RESOURCE, TexWidth, TexHeight, TexData.data()); pTexSRVs[i] = pTextures[i]->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE); } SET_STATIC_VAR(pPSO, SHADER_TYPE_VERTEX, "g_Tex2D_Static", Set, pTexSRVs[0]); SET_STATIC_VAR(pPSO, SHADER_TYPE_VERTEX, "g_Tex2DArr_Static", SetArray, pTexSRVs.data(), 0, StaticTexArraySize); - SET_STATIC_VAR(pPSO, SHADER_TYPE_PIXEL, "g_Tex2D_Static", Set, pTexSRVs[0]); - SET_STATIC_VAR(pPSO, SHADER_TYPE_PIXEL, "g_Tex2DArr_Static", SetArray, pTexSRVs.data(), 0, StaticTexArraySize); + SET_STATIC_VAR(pPSO, SHADER_TYPE_PIXEL, "g_Tex2D_Static", Set, pTexSRVs[1]); + SET_STATIC_VAR(pPSO, SHADER_TYPE_PIXEL, "g_Tex2DArr_Static", SetArray, pTexSRVs.data() + 2, 0, StaticTexArraySize); - SET_SRB_VAR(pSRB, SHADER_TYPE_VERTEX, "g_Tex2D_Mut", Set, pTexSRVs[0]); + SET_SRB_VAR(pSRB, SHADER_TYPE_VERTEX, "g_Tex2D_Mut", Set, pTexSRVs[1]); SET_SRB_VAR(pSRB, SHADER_TYPE_VERTEX, "g_Tex2D_Dyn", Set, pTexSRVs[0]); SET_SRB_VAR(pSRB, SHADER_TYPE_VERTEX, "g_Tex2DArr_Mut", SetArray, pTexSRVs.data(), 0, MutableTexArraySize); - SET_SRB_VAR(pSRB, SHADER_TYPE_VERTEX, "g_Tex2DArr_Dyn", SetArray, pTexSRVs.data(), 0, DynamicTexArraySize); + SET_SRB_VAR(pSRB, SHADER_TYPE_VERTEX, "g_Tex2DArr_Dyn", SetArray, pTexSRVs.data() + 1, 0, DynamicTexArraySize); - SET_SRB_VAR(pSRB, SHADER_TYPE_PIXEL, "g_Tex2D_Mut", Set, pTexSRVs[0]); + SET_SRB_VAR(pSRB, SHADER_TYPE_PIXEL, "g_Tex2D_Mut", Set, pTexSRVs[2]); SET_SRB_VAR(pSRB, SHADER_TYPE_PIXEL, "g_Tex2D_Dyn", Set, pTexSRVs[0]); SET_SRB_VAR(pSRB, SHADER_TYPE_PIXEL, "g_Tex2DArr_Mut", SetArray, pTexSRVs.data(), 0, MutableTexArraySize); SET_SRB_VAR(pSRB, SHADER_TYPE_PIXEL, "g_Tex2DArr_Dyn", SetArray, pTexSRVs.data(), 0, DynamicTexArraySize); @@ -436,16 +448,22 @@ void ShaderResourceLayoutTest::TestTexturesAndImtblSamplers(bool TestImtblSample pContext->SetPipelineState(pPSO); pContext->CommitShaderResources(pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); - DrawAttribs DrawAttrs(3, DRAW_FLAG_VERIFY_ALL); + DrawAttribs DrawAttrs(6, DRAW_FLAG_VERIFY_ALL); pContext->Draw(DrawAttrs); - SET_SRB_VAR(pSRB, SHADER_TYPE_VERTEX, "g_Tex2D_Dyn", Set, pTexSRVs[1]); - SET_SRB_VAR(pSRB, SHADER_TYPE_VERTEX, "g_Tex2DArr_Dyn", SetArray, pTexSRVs.data(), 1, DynamicTexArraySize - 1); + SET_SRB_VAR(pSRB, SHADER_TYPE_VERTEX, "g_Tex2D_Dyn", Set, pTexSRVs[2]); + SET_SRB_VAR(pSRB, SHADER_TYPE_VERTEX, "g_Tex2DArr_Dyn", SetArray, pTexSRVs.data(), 0, 1); + SET_SRB_VAR(pSRB, SHADER_TYPE_VERTEX, "g_Tex2DArr_Dyn", SetArray, pTexSRVs.data() + 1, 1, DynamicTexArraySize - 1); - SET_SRB_VAR(pSRB, SHADER_TYPE_PIXEL, "g_Tex2D_Dyn", Set, pTexSRVs[1]); - SET_SRB_VAR(pSRB, SHADER_TYPE_PIXEL, "g_Tex2DArr_Dyn", SetArray, pTexSRVs.data(), 1, DynamicTexArraySize - 1); + SET_SRB_VAR(pSRB, SHADER_TYPE_PIXEL, "g_Tex2D_Dyn", Set, pTexSRVs[3]); + SET_SRB_VAR(pSRB, SHADER_TYPE_PIXEL, "g_Tex2DArr_Dyn", SetArray, pTexSRVs.data() + 1, 0, 1); + SET_SRB_VAR(pSRB, SHADER_TYPE_PIXEL, "g_Tex2DArr_Dyn", SetArray, pTexSRVs.data() + 2, 1, DynamicTexArraySize - 1); + + pContext->CommitShaderResources(pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); pContext->Draw(DrawAttrs); + + pEnv->GetSwapChain()->Present(); } TEST_F(ShaderResourceLayoutTest, Textures) diff --git a/Tests/DiligentCoreAPITest/src/ShaderVariableAccessTest.cpp b/Tests/DiligentCoreAPITest/src/ShaderVariableAccessTest.cpp index 4e7c89e2..fbfb650d 100644 --- a/Tests/DiligentCoreAPITest/src/ShaderVariableAccessTest.cpp +++ b/Tests/DiligentCoreAPITest/src/ShaderVariableAccessTest.cpp @@ -46,7 +46,7 @@ extern "C" namespace Diligent { -namespace Test +namespace Testing { void PrintShaderResources(IShader* pShader) @@ -258,7 +258,7 @@ TEST(ShaderResourceLayout, VariableAccess) if (!deviceCaps.IsMetalDevice()) { // Resource queries from shader are not supported in Metal - Diligent::Test::PrintShaderResources(pVS); + Diligent::Testing::PrintShaderResources(pVS); } } @@ -313,7 +313,7 @@ TEST(ShaderResourceLayout, VariableAccess) if (!deviceCaps.IsMetalDevice()) { // Resource queries from shader are not supported in Metal - Diligent::Test::PrintShaderResources(pPS); + Diligent::Testing::PrintShaderResources(pPS); } } diff --git a/Tests/DiligentCoreAPITest/src/TestingEnvironment.cpp b/Tests/DiligentCoreAPITest/src/TestingEnvironment.cpp index 7b011760..bfedb03d 100644 --- a/Tests/DiligentCoreAPITest/src/TestingEnvironment.cpp +++ b/Tests/DiligentCoreAPITest/src/TestingEnvironment.cpp @@ -426,7 +426,7 @@ void TestingEnvironment::Reset() m_NumAllowedErrors = 0; } -RefCntAutoPtr<ITexture> TestingEnvironment::CreateTexture(const char* Name, TEXTURE_FORMAT Fmt, BIND_FLAGS BindFlags, Uint32 Width, Uint32 Height) +RefCntAutoPtr<ITexture> TestingEnvironment::CreateTexture(const char* Name, TEXTURE_FORMAT Fmt, BIND_FLAGS BindFlags, Uint32 Width, Uint32 Height, void* pInitData) { TextureDesc TexDesc; @@ -437,8 +437,12 @@ RefCntAutoPtr<ITexture> TestingEnvironment::CreateTexture(const char* Name, TEXT TexDesc.Width = Width; TexDesc.Height = Height; + const auto FmtAttribs = GetTextureFormatAttribs(Fmt); + TextureSubResData Mip0Data{pInitData, FmtAttribs.ComponentSize * FmtAttribs.NumComponents * Width}; + TextureData TexData{&Mip0Data, 1}; + RefCntAutoPtr<ITexture> pTexture; - m_pDevice->CreateTexture(TexDesc, nullptr, &pTexture); + m_pDevice->CreateTexture(TexDesc, pInitData ? &TexData : nullptr, &pTexture); VERIFY_EXPR(pTexture != nullptr); return pTexture; |
