From a4ff65b59aa72680e2efc344836980750ec5da6f Mon Sep 17 00:00:00 2001 From: Jovan Ristic Date: Fri, 5 Jan 2024 16:35:44 -0800 Subject: [PATCH] Fix D3D12 pixel history on 16 bit depth targets. * Trying to copy a D16_UNORM source to a destination with format R32_TYPELESS causes an invalid argument error. --- renderdoc/driver/d3d12/d3d12_pixelhistory.cpp | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp b/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp index c7eb541a5..d85fab3e8 100644 --- a/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp +++ b/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp @@ -234,6 +234,13 @@ bool IsDepthFormat(D3D12_RESOURCE_DESC desc, CompType typeCast) return false; } +DXGI_FORMAT GetDepthCopyFormat(DXGI_FORMAT format) +{ + if(format == DXGI_FORMAT_D16_UNORM) + return DXGI_FORMAT_R16_TYPELESS; + return DXGI_FORMAT_R32_TYPELESS; +} + void ReplayDraw(ID3D12GraphicsCommandListX *cmd, const ActionDescription &action) { // TODO: Once this is fully supported for indirect draws, this should be moved to WrappedID3D12Device @@ -1088,7 +1095,7 @@ private: : D3D12_RESOURCE_STATE_DEPTH_WRITE; targetCopyParams.srcImageFormat = GetDepthSRVFormat(m_CallbackInfo.targetDesc.Format, 0); targetCopyParams.depthcopy = true; - targetCopyParams.copyFormat = DXGI_FORMAT_R32_TYPELESS; + targetCopyParams.copyFormat = GetDepthCopyFormat(m_CallbackInfo.targetDesc.Format); offset += offsetof(struct D3D12PixelHistoryValue, depth); } @@ -1119,7 +1126,6 @@ private: WrappedID3D12Resource *depthImage = m_pDevice->GetResourceManager()->GetCurrentAs(resId); - // TODO: What about D16? Still copy as 32 bit? 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) @@ -1127,8 +1133,8 @@ private: D3D12CopyPixelParams depthCopyParams = targetCopyParams; depthCopyParams.srcImage = depthImage; - depthCopyParams.srcImageFormat = GetDepthSRVFormat(depthImage->GetDesc().Format, 0); - depthCopyParams.copyFormat = DXGI_FORMAT_R32_TYPELESS; + depthCopyParams.srcImageFormat = GetDepthSRVFormat(depthFormat, 0); + depthCopyParams.copyFormat = GetDepthCopyFormat(depthFormat); depthCopyParams.depthcopy = true; depthCopyParams.srcImageState = m_SavedState.dsv.GetDSV().Flags & D3D12_DSV_FLAG_READ_ONLY_DEPTH ? D3D12_RESOURCE_STATE_DEPTH_READ @@ -1137,7 +1143,7 @@ private: if(IsDepthAndStencilFormat(depthFormat)) { - depthCopyParams.srcImageFormat = GetDepthSRVFormat(depthImage->GetDesc().Format, 1); + depthCopyParams.srcImageFormat = GetDepthSRVFormat(depthFormat, 1); depthCopyParams.copyFormat = DXGI_FORMAT_R8_TYPELESS; depthCopyParams.planeSlice = 1; depthCopyParams.srcImageState = @@ -2034,11 +2040,12 @@ struct D3D12PixelHistoryPerFragmentCallback : D3D12PixelHistoryCallback storeOffset += offsetof(struct D3D12PerFragmentInfo, shaderOut); if(depthEnabled) { + DXGI_FORMAT depthFormat = m_CallbackInfo.dsImage->GetDesc().Format; + D3D12CopyPixelParams depthCopyParams = colorCopyParams; depthCopyParams.srcImage = m_CallbackInfo.dsImage; - depthCopyParams.srcImageFormat = - GetDepthSRVFormat(m_CallbackInfo.dsImage->GetDesc().Format, 0); - depthCopyParams.copyFormat = DXGI_FORMAT_R32_TYPELESS; + depthCopyParams.srcImageFormat = GetDepthSRVFormat(depthFormat, 0); + depthCopyParams.copyFormat = GetDepthCopyFormat(depthFormat); depthCopyParams.srcImageState = D3D12_RESOURCE_STATE_DEPTH_WRITE; depthCopyParams.planeSlice = 0; depthCopyParams.depthcopy = true; @@ -2089,11 +2096,12 @@ struct D3D12PixelHistoryPerFragmentCallback : D3D12PixelHistoryCallback if(prevState.dsv.GetResResourceId() != ResourceId()) { + DXGI_FORMAT depthFormat = m_CallbackInfo.dsImage->GetDesc().Format; + D3D12CopyPixelParams depthCopyParams = colorCopyParams; depthCopyParams.srcImage = m_CallbackInfo.dsImage; - depthCopyParams.srcImageFormat = - GetDepthSRVFormat(m_CallbackInfo.dsImage->GetDesc().Format, 0); - depthCopyParams.copyFormat = DXGI_FORMAT_R32_TYPELESS; + depthCopyParams.srcImageFormat = GetDepthSRVFormat(depthFormat, 0); + depthCopyParams.copyFormat = GetDepthCopyFormat(depthFormat); depthCopyParams.srcImageState = D3D12_RESOURCE_STATE_DEPTH_WRITE; depthCopyParams.depthcopy = true; CopyImagePixel(cmd, depthCopyParams,