From 0cbaefe557791f8a88b142cb92a4c2022da553fc Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 16 Oct 2025 00:21:40 +0100 Subject: [PATCH] Match target subresource in use for D3D12 pixel history work --- renderdoc/driver/d3d12/d3d12_debug.h | 2 +- renderdoc/driver/d3d12/d3d12_pixelhistory.cpp | 64 +++++++++++++++++-- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_debug.h b/renderdoc/driver/d3d12/d3d12_debug.h index 45c6e7d6a..b223b0de4 100644 --- a/renderdoc/driver/d3d12/d3d12_debug.h +++ b/renderdoc/driver/d3d12/d3d12_debug.h @@ -222,7 +222,7 @@ public: void PixelHistoryCopyPixel(ID3D12GraphicsCommandListX *cmd, ID3D12Resource *dstBuffer, D3D12CopyPixelParams ¶ms, size_t offset); - bool PixelHistorySetupResources(D3D12PixelHistoryResources &resources, + bool PixelHistorySetupResources(D3D12PixelHistoryResources &resources, Subresource sub, WrappedID3D12Resource *targetImage, const D3D12_RESOURCE_DESC &desc, uint32_t numEvents); bool PixelHistoryDestroyResources(D3D12PixelHistoryResources &resources); diff --git a/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp b/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp index 632f35246..0a888693c 100644 --- a/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp +++ b/renderdoc/driver/d3d12/d3d12_pixelhistory.cpp @@ -468,12 +468,30 @@ void D3D12DebugManager::PixelHistoryCopyPixel(ID3D12GraphicsCommandListX *cmd, D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; srvDesc.ViewDimension = p.multisampled ? D3D12_SRV_DIMENSION_TEXTURE2DMS : D3D12_SRV_DIMENSION_TEXTURE2D; + if(p.arraySlice > 0) + { + srvDesc.ViewDimension = + p.multisampled ? D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY : D3D12_SRV_DIMENSION_TEXTURE2DARRAY; + if(p.multisampled) + srvDesc.Texture2DMSArray.ArraySize = ~0U; + else + srvDesc.Texture2DArray.ArraySize = ~0U; + } + srvDesc.Format = p.srcImageFormat; srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; if(!p.multisampled) { - srvDesc.Texture2D.MipLevels = 1; - srvDesc.Texture2D.PlaneSlice = p.planeSlice; + if(p.arraySlice > 0) + { + srvDesc.Texture2DArray.MipLevels = 1; + srvDesc.Texture2DArray.PlaneSlice = p.planeSlice; + } + else + { + srvDesc.Texture2D.MipLevels = 1; + srvDesc.Texture2D.PlaneSlice = p.planeSlice; + } } m_pDevice->CreateShaderResourceView(p.srcImage, &srvDesc, srv); @@ -673,9 +691,6 @@ protected: // already based on the target mip/slice if(p.srcImage == m_CallbackInfo.colorImage || p.srcImage == m_CallbackInfo.dsImage) { - // TODO: Is this always true when we call CopyImagePixel? Also need to test this case with MSAA - baseMip = 0; - baseSlice = 0; copy3d = false; } else if(copy3d) @@ -2674,6 +2689,7 @@ private: }; bool D3D12DebugManager::PixelHistorySetupResources(D3D12PixelHistoryResources &resources, + Subresource sub, WrappedID3D12Resource *targetImage, const D3D12_RESOURCE_DESC &desc, uint32_t numEvents) @@ -2719,6 +2735,24 @@ bool D3D12DebugManager::PixelHistorySetupResources(D3D12PixelHistoryResources &r rtvDesc.Format = imageDesc.Format; rtvDesc.ViewDimension = imageDesc.SampleDesc.Count > 1 ? D3D12_RTV_DIMENSION_TEXTURE2DMS : D3D12_RTV_DIMENSION_TEXTURE2D; + + if(imageDesc.DepthOrArraySize > 1) + { + if(imageDesc.SampleDesc.Count > 1) + { + rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY; + rtvDesc.Texture2DMSArray.FirstArraySlice = sub.slice; + rtvDesc.Texture2DMSArray.ArraySize = 1; + } + else + { + rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DARRAY; + rtvDesc.Texture2DArray.FirstArraySlice = sub.slice; + rtvDesc.Texture2DArray.ArraySize = 1; + rtvDesc.Texture2DArray.MipSlice = sub.mip; + } + } + D3D12_CPU_DESCRIPTOR_HANDLE rtv = m_pDevice->GetDebugManager()->GetCPUHandle(PIXEL_HISTORY_RTV); m_pDevice->CreateRenderTargetView(colorImage, &rtvDesc, rtv); @@ -2741,6 +2775,24 @@ bool D3D12DebugManager::PixelHistorySetupResources(D3D12PixelHistoryResources &r dsvDesc.Format = imageDesc.Format; dsvDesc.ViewDimension = imageDesc.SampleDesc.Count > 1 ? D3D12_DSV_DIMENSION_TEXTURE2DMS : D3D12_DSV_DIMENSION_TEXTURE2D; + + if(imageDesc.DepthOrArraySize > 1) + { + if(imageDesc.SampleDesc.Count > 1) + { + dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY; + dsvDesc.Texture2DMSArray.FirstArraySlice = sub.slice; + dsvDesc.Texture2DMSArray.ArraySize = 1; + } + else + { + dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DARRAY; + dsvDesc.Texture2DArray.FirstArraySlice = sub.slice; + dsvDesc.Texture2DArray.ArraySize = 1; + dsvDesc.Texture2DArray.MipSlice = sub.mip; + } + } + D3D12_CPU_DESCRIPTOR_HANDLE dsv = m_pDevice->GetDebugManager()->GetCPUHandle(PIXEL_HISTORY_DSV); m_pDevice->CreateDepthStencilView(dsImage, &dsvDesc, dsv); @@ -2874,7 +2926,7 @@ rdcarray D3D12Replay::PixelHistory(rdcarray event // TODO: perhaps should allocate most resources after D3D12OcclusionCallback, since we will // get a smaller subset of events that passed the occlusion query. D3D12PixelHistoryResources resources = {}; - if(!GetDebugManager()->PixelHistorySetupResources(resources, pResource, resDesc, + if(!GetDebugManager()->PixelHistorySetupResources(resources, sub, pResource, resDesc, (uint32_t)events.size())) { SAFE_RELEASE(pOcclusionQueryHeap);