From 96a7639c2e009dc5beea8db8f01eea2cc72485c9 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 3 May 2022 14:06:07 +0100 Subject: [PATCH] Add test of flow control constructs in D3D11 shader debugging --- .../demos/d3d11/d3d11_shader_debug_zoo.cpp | 117 +++++++++++++++++- .../tests/D3D11/D3D11_Shader_Debug_Zoo.py | 31 ++++- 2 files changed, 145 insertions(+), 3 deletions(-) diff --git a/util/test/demos/d3d11/d3d11_shader_debug_zoo.cpp b/util/test/demos/d3d11/d3d11_shader_debug_zoo.cpp index 044b4aa45..a089e2bc8 100644 --- a/util/test/demos/d3d11/d3d11_shader_debug_zoo.cpp +++ b/util/test/demos/d3d11/d3d11_shader_debug_zoo.cpp @@ -680,6 +680,113 @@ float4 main(v2f IN) : SV_Target0 return float4(0.4f, 0.4f, 0.4f, 0.4f); } +)EOSHADER"; + + std::string flowPixel = R"EOSHADER( + +float4 main(v2f IN) : SV_Target0 +{ + uint zero = IN.tri; + + float4 ret = float4(0,0,0,0); + + // test multiple ifs + if(zero < 5) + { + ret.w += 2.0f; + } + else + { + ret.w += 4.0f; + } + + if(zero > 1) + { + ret.w += 8.0f; + } + else + { + ret.w += 16.0f; + } + + // test nested ifs + if(zero < 5) + { + if(zero > 1) + { + ret.z += 2.0f; + } + else + { + ret.z += 4.0f; + } + } + else + { + if(zero < 10) + { + ret.z += 8.0f; + } + else + { + ret.z += 16.0f; + } + } + + // test loops + ret.y = 1.0f; + for(uint i=0; i < zero + 5; i++) + { + ret.y += 1.0f; + } + + for(uint j=0; j < zero; j++) + { + ret.y += 100.0f; + } + + for(uint k=0; k < zero + 2; k++) + { + for(uint l=0; l < zero + 3; l++) + { + ret.y += 10.0f; + } + } + + // test switches + switch(zero) + { + // fallthrough + case 1: + case 0: + ret.x += 1.0f; + break; + case 3: + case 4: + ret.x += 2.0f; + break; + default: + break; + } + + switch(zero+4) + { + // fallthrough + case 1: + case 0: + ret.x += 4.0f; + break; + case 3: + case 4: + ret.x += 8.0f; + break; + default: + break; + } + + return ret; +} + )EOSHADER"; std::string msaaPixel = R"EOSHADER( @@ -769,10 +876,11 @@ float4 main(v2f IN, uint samp : SV_SampleIndex) : SV_Target0 ID3D11VertexShaderPtr vs = CreateVS(vsblob); ID3D11PixelShaderPtr ps = CreatePS(psblob); + ID3D11PixelShaderPtr flowps = CreatePS(Compile(common + flowPixel, "main", "ps_5_0")); static const uint32_t texDim = AlignUp(numTests, 64U) * 4; - ID3D11Texture2DPtr fltTex = MakeTexture(DXGI_FORMAT_R32G32B32A32_FLOAT, texDim, 4).RTV(); + ID3D11Texture2DPtr fltTex = MakeTexture(DXGI_FORMAT_R32G32B32A32_FLOAT, texDim, 8).RTV(); ID3D11RenderTargetViewPtr fltRT = MakeRTV(fltTex); float triWidth = 8.0f / float(texDim); @@ -888,8 +996,14 @@ float4 main(v2f IN, uint samp : SV_SampleIndex) : SV_Target0 ctx->OMSetRenderTargetsAndUnorderedAccessViews(1, &fltRT.GetInterfacePtr(), NULL, 1, 2, uavs, NULL); + setMarker("Main Test"); ctx->DrawInstanced(3, numTests, 0, 0); + RSSetViewport({0.0f, 4.0f, (float)texDim, 4.0f, 0.0f, 1.0f}); + ctx->PSSetShader(flowps, NULL, 0); + setMarker("Flow Test"); + ctx->DrawInstanced(3, 1, 0, 0); + ctx->OMSetRenderTargets(1, &msaaRT.GetInterfacePtr(), NULL); RSSetViewport({0.0f, 0.0f, 8.0f, 8.0f, 0.0f, 1.0f}); @@ -897,6 +1011,7 @@ float4 main(v2f IN, uint samp : SV_SampleIndex) : SV_Target0 ctx->IASetInputLayout(defaultLayout); ctx->VSSetShader(vsmsaa, NULL, 0); ctx->PSSetShader(psmsaa, NULL, 0); + setMarker("MSAA Test"); ctx->Draw(3, 0); Present(); diff --git a/util/test/tests/D3D11/D3D11_Shader_Debug_Zoo.py b/util/test/tests/D3D11/D3D11_Shader_Debug_Zoo.py index 75707f1a0..1597257e1 100644 --- a/util/test/tests/D3D11/D3D11_Shader_Debug_Zoo.py +++ b/util/test/tests/D3D11/D3D11_Shader_Debug_Zoo.py @@ -8,7 +8,7 @@ class D3D11_Shader_Debug_Zoo(rdtest.TestCase): def check_capture(self): # Jump to the action - action = self.find_action("Draw") + action = self.find_action("Main Test").next self.controller.SetFrameEvent(action.eventId, False) @@ -41,8 +41,35 @@ class D3D11_Shader_Debug_Zoo(rdtest.TestCase): rdtest.log.success("Test {} matched as expected".format(test)) rdtest.log.end_section("General tests") + rdtest.log.begin_section("Flow tests") + action = self.find_action("Flow Test").next + self.controller.SetFrameEvent(action.eventId, False) + pipe: rd.PipeState = self.controller.GetPipelineState() + + # Debug the shader + trace: rd.ShaderDebugTrace = self.controller.DebugPixel(0, 4, rd.ReplayController.NoPreference, + rd.ReplayController.NoPreference) + + cycles, variables = self.process_trace(trace) + + output = self.find_output_source_var(trace, rd.ShaderBuiltin.ColorOutput, 0) + + debugged = self.evaluate_source_var(output, variables) + + try: + self.check_pixel_value(pipe.GetOutputTargets()[0].resourceId, 0, 4, debugged.value.f32v[0:4]) + self.check_pixel_value(pipe.GetOutputTargets()[0].resourceId, 0, 4, [9.0, 66.0, 4.0, 18.0]) + except rdtest.TestFailureException as ex: + raise rdtest.TestFailureException("Flow test did not match. {}".format(str(ex))) + finally: + self.controller.FreeTrace(trace) + + rdtest.log.success("Flow test matched as expected") + + rdtest.log.end_section("Flow tests") + rdtest.log.begin_section("MSAA tests") - action = action.next + action = self.find_action("MSAA Test").next self.controller.SetFrameEvent(action.eventId, False) pipe: rd.PipeState = self.controller.GetPipelineState() for test in range(4):