From cc7942c3e95f2f8dc908cb6ae3031d34402b5ea5 Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Tue, 2 Apr 2024 16:12:12 +0100 Subject: [PATCH] D3D12 Pixel History don't try to read depth for non-graphics pipelines --- renderdoc/driver/d3d12/d3d12_pixelhistory.cpp | 65 ++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp b/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp index 4ba0fc8f4..3733d32c1 100644 --- a/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp +++ b/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp @@ -1213,42 +1213,47 @@ private: return; // Get the bound depth format for this event - ResourceId resId = m_SavedState.dsv.GetResResourceId(); - if(resId != ResourceId()) + WrappedID3D12PipelineState *pipe = + m_pDevice->GetResourceManager()->GetCurrentAs(m_SavedState.pipe); + if(pipe && pipe->IsGraphics()) { - WrappedID3D12Resource *depthImage = - m_pDevice->GetResourceManager()->GetCurrentAs(resId); - - DXGI_FORMAT depthFormat = m_SavedState.dsv.GetDSV().Format; - // Descriptors with unknown type are valid and indicate to use the resource's format - if(depthFormat == DXGI_FORMAT_UNKNOWN) - depthFormat = depthImage->GetDesc().Format; - - D3D12CopyPixelParams depthCopyParams = targetCopyParams; - depthCopyParams.srcImage = depthImage; - depthCopyParams.srcImageFormat = GetDepthSRVFormat(depthFormat, 0); - depthCopyParams.copyFormat = GetDepthCopyFormat(depthFormat); - depthCopyParams.depthcopy = true; - fallback = m_SavedState.dsv.GetDSV().Flags & D3D12_DSV_FLAG_READ_ONLY_DEPTH - ? D3D12_RESOURCE_STATE_DEPTH_READ - : D3D12_RESOURCE_STATE_DEPTH_WRITE; - depthCopyParams.srcImageState = rtOutput ? fallback : nonRtFallback; - CopyImagePixel(cmd, depthCopyParams, offset + offsetof(struct D3D12PixelHistoryValue, depth)); - - if(IsDepthAndStencilFormat(depthFormat)) + ResourceId resId = m_SavedState.dsv.GetResResourceId(); + if(resId != ResourceId()) { - depthCopyParams.srcImageFormat = GetDepthSRVFormat(depthFormat, 1); - depthCopyParams.copyFormat = DXGI_FORMAT_R8_TYPELESS; - depthCopyParams.planeSlice = 1; - fallback = m_SavedState.dsv.GetDSV().Flags & D3D12_DSV_FLAG_READ_ONLY_STENCIL + WrappedID3D12Resource *depthImage = + m_pDevice->GetResourceManager()->GetCurrentAs(resId); + + DXGI_FORMAT depthFormat = m_SavedState.dsv.GetDSV().Format; + // Descriptors with unknown type are valid and indicate to use the resource's format + if(depthFormat == DXGI_FORMAT_UNKNOWN) + depthFormat = depthImage->GetDesc().Format; + + D3D12CopyPixelParams depthCopyParams = targetCopyParams; + depthCopyParams.srcImage = depthImage; + depthCopyParams.srcImageFormat = GetDepthSRVFormat(depthFormat, 0); + depthCopyParams.copyFormat = GetDepthCopyFormat(depthFormat); + depthCopyParams.depthcopy = true; + fallback = m_SavedState.dsv.GetDSV().Flags & D3D12_DSV_FLAG_READ_ONLY_DEPTH ? D3D12_RESOURCE_STATE_DEPTH_READ : D3D12_RESOURCE_STATE_DEPTH_WRITE; depthCopyParams.srcImageState = rtOutput ? fallback : nonRtFallback; - CopyImagePixel(cmd, depthCopyParams, - offset + offsetof(struct D3D12PixelHistoryValue, stencil)); - } + CopyImagePixel(cmd, depthCopyParams, offset + offsetof(struct D3D12PixelHistoryValue, depth)); - m_DepthFormats.insert(std::make_pair(eid, depthFormat)); + if(IsDepthAndStencilFormat(depthFormat)) + { + depthCopyParams.srcImageFormat = GetDepthSRVFormat(depthFormat, 1); + depthCopyParams.copyFormat = DXGI_FORMAT_R8_TYPELESS; + depthCopyParams.planeSlice = 1; + fallback = m_SavedState.dsv.GetDSV().Flags & D3D12_DSV_FLAG_READ_ONLY_STENCIL + ? D3D12_RESOURCE_STATE_DEPTH_READ + : D3D12_RESOURCE_STATE_DEPTH_WRITE; + depthCopyParams.srcImageState = rtOutput ? fallback : nonRtFallback; + CopyImagePixel(cmd, depthCopyParams, + offset + offsetof(struct D3D12PixelHistoryValue, stencil)); + } + + m_DepthFormats.insert(std::make_pair(eid, depthFormat)); + } } }