summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-02-02 18:54:15 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-02-02 18:54:15 +0000
commit45cf6c4037a6789da7521907dfb53390833c60e2 (patch)
tree6d1b61c9a3a69a25e20eca2afed72760add0dada
parentReworked ShaderResourceLayoutTest.ConstantBuffers to validate resource bindings (diff)
downloadDiligentCore-45cf6c4037a6789da7521907dfb53390833c60e2.tar.gz
DiligentCore-45cf6c4037a6789da7521907dfb53390833c60e2.zip
Updated ShaderResourceLayoutTest.Samplers to validate texture contents
-rw-r--r--Tests/DiligentCoreAPITest/assets/shaders/ShaderResourceLayout/Samplers.hlsl66
-rw-r--r--Tests/DiligentCoreAPITest/src/ShaderResourceLayoutTest.cpp9
2 files changed, 53 insertions, 22 deletions
diff --git a/Tests/DiligentCoreAPITest/assets/shaders/ShaderResourceLayout/Samplers.hlsl b/Tests/DiligentCoreAPITest/assets/shaders/ShaderResourceLayout/Samplers.hlsl
index ad8cbe72..27c5e059 100644
--- a/Tests/DiligentCoreAPITest/assets/shaders/ShaderResourceLayout/Samplers.hlsl
+++ b/Tests/DiligentCoreAPITest/assets/shaders/ShaderResourceLayout/Samplers.hlsl
@@ -10,40 +10,66 @@ SamplerState g_SamArr_Dyn [DYNAMIC_SAM_ARRAY_SIZE]; // 3
SamplerState g_Sampler;
-float4 UseResources()
+#define TexRefValue float4(1.0, 0.0, 1.0, 0.0)
+
+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.SampleLevel(g_Sam_Static, UV.xy, 0.0);
- f4Color += g_Tex2D.SampleLevel(g_Sam_Mut, UV.xy, 0.0);
- f4Color += g_Tex2D.SampleLevel(g_Sam_Dyn, 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);
+}
+
+float4 VerifyResources()
+{
+ float4 AllCorrect = float4(1.0, 1.0, 1.0, 1.0);
+
+ float2 UV = float2(0.5, 0.5);
+
+ AllCorrect *= CheckValue(g_Tex2D.SampleLevel(g_Sam_Static, UV.xy, 0.0), TexRefValue);
+ AllCorrect *= CheckValue(g_Tex2D.SampleLevel(g_Sam_Mut, UV.xy, 0.0), TexRefValue);
+ AllCorrect *= CheckValue(g_Tex2D.SampleLevel(g_Sam_Dyn, UV.xy, 0.0), TexRefValue);
// glslang is not smart enough to unroll the loops even when explicitly told to do so
- f4Color += g_Tex2D.SampleLevel(g_SamArr_Static[0], UV.xy, 0.0);
- f4Color += g_Tex2D.SampleLevel(g_SamArr_Static[1], UV.xy, 0.0);
+ AllCorrect *= CheckValue(g_Tex2D.SampleLevel(g_SamArr_Static[0], UV.xy, 0.0), TexRefValue);
+ AllCorrect *= CheckValue(g_Tex2D.SampleLevel(g_SamArr_Static[1], UV.xy, 0.0), TexRefValue);
- f4Color += g_Tex2D.SampleLevel(g_SamArr_Mut[0], UV.xy, 0.0);
- f4Color += g_Tex2D.SampleLevel(g_SamArr_Mut[1], UV.xy, 0.0);
- f4Color += g_Tex2D.SampleLevel(g_SamArr_Mut[2], UV.xy, 0.0);
- f4Color += g_Tex2D.SampleLevel(g_SamArr_Mut[3], UV.xy, 0.0);
+ AllCorrect *= CheckValue(g_Tex2D.SampleLevel(g_SamArr_Mut[0], UV.xy, 0.0), TexRefValue);
+ AllCorrect *= CheckValue(g_Tex2D.SampleLevel(g_SamArr_Mut[1], UV.xy, 0.0), TexRefValue);
+ AllCorrect *= CheckValue(g_Tex2D.SampleLevel(g_SamArr_Mut[2], UV.xy, 0.0), TexRefValue);
+ AllCorrect *= CheckValue(g_Tex2D.SampleLevel(g_SamArr_Mut[3], UV.xy, 0.0), TexRefValue);
- f4Color += g_Tex2D.SampleLevel(g_SamArr_Dyn[0], UV.xy, 0.0);
- f4Color += g_Tex2D.SampleLevel(g_SamArr_Dyn[1], UV.xy, 0.0);
- f4Color += g_Tex2D.SampleLevel(g_SamArr_Dyn[2], UV.xy, 0.0);
+ AllCorrect *= CheckValue(g_Tex2D.SampleLevel(g_SamArr_Dyn[0], UV.xy, 0.0), TexRefValue);
+ AllCorrect *= CheckValue(g_Tex2D.SampleLevel(g_SamArr_Dyn[1], UV.xy, 0.0), TexRefValue);
+ AllCorrect *= CheckValue(g_Tex2D.SampleLevel(g_SamArr_Dyn[2], UV.xy, 0.0), TexRefValue);
- 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/src/ShaderResourceLayoutTest.cpp b/Tests/DiligentCoreAPITest/src/ShaderResourceLayoutTest.cpp
index b76a8244..8507405a 100644
--- a/Tests/DiligentCoreAPITest/src/ShaderResourceLayoutTest.cpp
+++ b/Tests/DiligentCoreAPITest/src/ShaderResourceLayoutTest.cpp
@@ -1302,8 +1302,13 @@ TEST_F(ShaderResourceLayoutTest, Samplers)
pSamObjs[i] = pSamplers[i];
}
- auto pTex2D = pEnv->CreateTexture("ShaderResourceLayoutTest: test RTV", TEX_FORMAT_RGBA8_UNORM, BIND_SHADER_RESOURCE, 512, 512);
+ constexpr Uint32 TexWidth = 256;
+ constexpr Uint32 TexHeight = 256;
+ std::vector<Uint32> TexData(TexWidth * TexHeight, 0x00FF00FFu);
+
+ auto pTex2D = pEnv->CreateTexture("ShaderResourceLayoutTest: test RTV", TEX_FORMAT_RGBA8_UNORM, BIND_SHADER_RESOURCE, TexWidth, TexHeight, TexData.data());
auto* pTex2DSRV = pTex2D->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE);
+
SET_STATIC_VAR(pPSO, SHADER_TYPE_VERTEX, "g_Tex2D", Set, pTex2DSRV);
SET_STATIC_VAR(pPSO, SHADER_TYPE_PIXEL, "g_Tex2D", Set, pTex2DSRV);
@@ -1335,7 +1340,7 @@ TEST_F(ShaderResourceLayoutTest, Samplers)
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_Sam_Dyn", Set, pSamObjs[1]);