From 7e8c22ce6853c118051038f2479b62cc55dd2de0 Mon Sep 17 00:00:00 2001 From: Jovan Ristic Date: Fri, 29 Dec 2023 21:44:04 -0800 Subject: [PATCH] Fix D3D12 pixel history MSAA test issues. * Add missing resource transitions for the dispatch copy to fix validation issues encountered while running the test. * Adjust the MSAA copy path to use the second channel for stencil to fix copies failing to output anything, which manifested as the fragment only showing one primitive without correct output data. --- renderdoc/data/hlsl/d3d12_pixelhistory.hlsl | 4 ++-- renderdoc/driver/d3d12/d3d12_pixelhistory.cpp | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/renderdoc/data/hlsl/d3d12_pixelhistory.hlsl b/renderdoc/data/hlsl/d3d12_pixelhistory.hlsl index deb79b61e..af7206f28 100644 --- a/renderdoc/data/hlsl/d3d12_pixelhistory.hlsl +++ b/renderdoc/data/hlsl/d3d12_pixelhistory.hlsl @@ -40,7 +40,7 @@ Texture2DArray copyin_depth : register(t0); Texture2DArray copyin_stencil : register(t1); Texture2DMSArray copyin_depth_ms : register(t2); -Texture2DMSArray copyin_stencil_ms : register(t3); +Texture2DMSArray copyin_stencil_ms : register(t3); Texture2DArray copyin_float : register(t4); Texture2DMSArray copyin_float_ms : register(t5); @@ -70,7 +70,7 @@ RWBuffer copyout_int : register(u4); } else if(copy_stencil) { - uint val = copyin_stencil_ms.sample[src_coord.z][uint3(src_coord.xy, src_coord.w)]; + uint val = copyin_stencil_ms.sample[src_coord.z][uint3(src_coord.xy, src_coord.w)].g; copyout_stencil[dst_slot] = val; } else diff --git a/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp b/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp index 448b58677..242521c00 100644 --- a/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp +++ b/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp @@ -596,8 +596,27 @@ protected: // copy using a compute shader into a staging image first if(p.multisampled) { - // TODO: Is a resource transition needed here? + // For pipeline barriers. + D3D12_RESOURCE_BARRIER barriers[2] = {}; + barriers[0] = barrier; + barriers[0].Transition.StateAfter = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE; + // Validation will complain if we don't transition all subresources for an SRV. + barriers[0].Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; + + barriers[1].Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + barriers[1].Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; + barriers[1].Transition.pResource = m_CallbackInfo.dstBuffer; + barriers[1].Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST; + barriers[1].Transition.StateAfter = D3D12_RESOURCE_STATE_UNORDERED_ACCESS; + barriers[1].Transition.Subresource = 0; + + cmd->ResourceBarrier(2, barriers); + m_pDevice->GetDebugManager()->PixelHistoryCopyPixel(cmd, m_CallbackInfo.dstBuffer, p, offset); + + std::swap(barriers[0].Transition.StateBefore, barriers[0].Transition.StateAfter); + std::swap(barriers[1].Transition.StateBefore, barriers[1].Transition.StateAfter); + cmd->ResourceBarrier(2, barriers); } else {