From ed0138a2428b2c68784d17b1c8335406197e5d72 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 29 Oct 2020 16:12:33 +0000 Subject: [PATCH] Test that debugging sampling from vert shaders in D3D12 works correctly * We also test that pixel shaders can be debugged even if they have DENY_ROOT_SIGNATURE_ACCESS enabled. --- .../demos/d3d12/d3d12_shader_debug_zoo.cpp | 72 ++++++++++++++++++- .../tests/D3D12/D3D12_Shader_Debug_Zoo.py | 40 +++++++++++ 2 files changed, 110 insertions(+), 2 deletions(-) diff --git a/util/test/demos/d3d12/d3d12_shader_debug_zoo.cpp b/util/test/demos/d3d12/d3d12_shader_debug_zoo.cpp index e3dba3c19..f4efc00e3 100644 --- a/util/test/demos/d3d12/d3d12_shader_debug_zoo.cpp +++ b/util/test/demos/d3d12/d3d12_shader_debug_zoo.cpp @@ -36,6 +36,40 @@ RD_TEST(D3D12_Shader_Debug_Zoo, D3D12GraphicsTest) float negone; }; + std::string vertexSampleVS = R"EOSHADER( + +Texture2D intex : register(t0); + +struct v2f { float4 pos : SV_Position; float4 col : COL; }; + +v2f main(uint vid : SV_VertexID) +{ + float2 positions[] = { + float2(-1.0f, 1.0f), + float2( 1.0f, 1.0f), + float2(-1.0f, -1.0f), + float2( 1.0f, -1.0f), + }; + + v2f ret = (v2f)0; + ret.pos = float4(positions[vid], 0, 1); + ret.col = intex.Load(float3(0,0,0)); + return ret; +} + +)EOSHADER"; + + std::string vertexSamplePS = R"EOSHADER( + +struct v2f { float4 pos : SV_Position; float4 col : COL; }; + +float4 main(v2f IN) : SV_Target0 +{ + return IN.col; +} + +)EOSHADER"; + std::string pixelBlit = R"EOSHADER( cbuffer rootconsts : register(b0) @@ -780,6 +814,11 @@ float4 main(v2f IN, uint samp : SV_SampleIndex) : SV_Target0 D3D12_CPU_DESCRIPTOR_HANDLE uav2cpu = uavView2.CreateClearCPU(6); D3D12_GPU_DESCRIPTOR_HANDLE uav2gpu = uavView2.CreateGPU(6); + // need to create non-structured version for clearing + uavView2 = MakeUAV(structBuf2).Format(DXGI_FORMAT_R32_UINT); + uav2cpu = uavView2.CreateClearCPU(8); + uav2gpu = uavView2.CreateGPU(8); + // Create resources for MSAA draw ID3DBlobPtr vsmsaablob = Compile(D3DDefaultVertex, "main", "vs_5_0"); ID3DBlobPtr psmsaablob = Compile(msaaPixel, "main", "ps_5_0"); @@ -809,6 +848,15 @@ float4 main(v2f IN, uint samp : SV_SampleIndex) : SV_Target0 }); ID3D12PipelineStatePtr blitpso = MakePSO().RootSig(blitSig).VS(vsblob).PS(psblob); + vsblob = Compile(vertexSampleVS, "main", "vs_5_0"); + psblob = Compile(vertexSamplePS, "main", "ps_5_0"); + ID3D12RootSignaturePtr vertexSampleSig = MakeSig( + { + tableParam(D3D12_SHADER_VISIBILITY_VERTEX, D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 0, 0, 1, 7), + }, + D3D12_ROOT_SIGNATURE_FLAG_DENY_PIXEL_SHADER_ROOT_ACCESS); + ID3D12PipelineStatePtr vertexSamplePSO = MakePSO().RootSig(vertexSampleSig).VS(vsblob).PS(psblob); + while(Running()) { ID3D12GraphicsCommandListPtr cmd = GetCommandBuffer(); @@ -849,7 +897,7 @@ float4 main(v2f IN, uint samp : SV_SampleIndex) : SV_Target0 cmd->ClearUnorderedAccessViewUint(uav2gpu, uav2cpu, structBuf2, zero, 0, NULL); // Add a marker so we can easily locate this draw - cmd->SetMarker(1, markers[i], (UINT)strlen(markers[i])); + setMarker(cmd, markers[i]); cmd->DrawInstanced(3, numTests, 0, 0); ResourceBarrier(cmd, fltTex, D3D12_RESOURCE_STATE_RENDER_TARGET, @@ -882,9 +930,29 @@ float4 main(v2f IN, uint samp : SV_SampleIndex) : SV_Target0 RSSetScissorRect(cmd, {0, 0, 8, 8}); // Add a marker so we can easily locate this draw - cmd->SetMarker(1, "MSAA", 4); + setMarker(cmd, "MSAA"); cmd->DrawInstanced(3, 1, 0, 0); + OMSetRenderTargets(cmd, {fltRTV}, {}); + ClearRenderTargetView(cmd, fltRTV, {0.3f, 0.5f, 0.8f, 1.0f}); + + ResourceBarrier(cmd, fltTex, D3D12_RESOURCE_STATE_RENDER_TARGET, + D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); + + OMSetRenderTargets(cmd, {rtv}, {}); + RSSetViewport(cmd, {50.0f, 50.0f, 10.0f, 10.0f, 0.0f, 1.0f}); + RSSetScissorRect(cmd, {50, 50, 60, 60}); + + cmd->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + cmd->SetGraphicsRootSignature(vertexSampleSig); + cmd->SetPipelineState(vertexSamplePSO); + cmd->SetGraphicsRootDescriptorTable(0, m_CBVUAVSRV->GetGPUDescriptorHandleForHeapStart()); + setMarker(cmd, "VertexSample"); + cmd->DrawInstanced(4, 1, 0, 0); + + ResourceBarrier(cmd, fltTex, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, + D3D12_RESOURCE_STATE_RENDER_TARGET); + FinishUsingBackbuffer(cmd, D3D12_RESOURCE_STATE_RENDER_TARGET); cmd->Close(); diff --git a/util/test/tests/D3D12/D3D12_Shader_Debug_Zoo.py b/util/test/tests/D3D12/D3D12_Shader_Debug_Zoo.py index 7980ba08d..f34207a24 100644 --- a/util/test/tests/D3D12/D3D12_Shader_Debug_Zoo.py +++ b/util/test/tests/D3D12/D3D12_Shader_Debug_Zoo.py @@ -85,6 +85,46 @@ class D3D12_Shader_Debug_Zoo(rdtest.TestCase): rdtest.log.end_section("MSAA tests") + test_marker: rd.DrawcallDescription = self.find_draw("VertexSample") + draw = test_marker.next + self.controller.SetFrameEvent(draw.eventId, False) + pipe: rd.PipeState = self.controller.GetPipelineState() + + # Debug the vertex shader + trace: rd.ShaderDebugTrace = self.controller.DebugVertex(0, 0, 0, 0) + + cycles, variables = self.process_trace(trace) + + output = self.find_output_source_var(trace, rd.ShaderBuiltin.Undefined, 1) + + debugged = self.evaluate_source_var(output, variables) + + if not rdtest.value_compare(debugged.value.fv[0:4], [0.3, 0.5, 0.8, 1.0]): + failed = True + rdtest.log.error( + "Vertex shader color output did not match expectation ({}). {}".format(str(debugged.value.fv[0:4]), + str(ex))) + + rdtest.log.success("VertexSample VS was debugged correctly") + + # Debug the pixel shader + trace: rd.ShaderDebugTrace = self.controller.DebugPixel(51, 51, 0, 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) + + # Validate the debug output result + try: + self.check_pixel_value(pipe.GetOutputTargets()[0].resourceId, 51, 51, debugged.value.fv[0:4]) + except rdtest.TestFailureException as ex: + failed = True + rdtest.log.error("Vertex sample pixel shader output did not match. {}".format(str(ex))) + + rdtest.log.success("VertexSample PS was debugged correctly") + if failed: raise rdtest.TestFailureException("Some tests were not as expected")