From 8e3d38ce2cb84bccb4b95db58e983af9da3a8d58 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 22 Jul 2020 13:26:29 +0100 Subject: [PATCH] Fix crash if texture is discarded with NULL region (means all discarded) --- renderdoc/driver/d3d12/d3d12_debug.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_debug.cpp b/renderdoc/driver/d3d12/d3d12_debug.cpp index 13cd53961..f9b1e4f48 100644 --- a/renderdoc/driver/d3d12/d3d12_debug.cpp +++ b/renderdoc/driver/d3d12/d3d12_debug.cpp @@ -743,6 +743,9 @@ void D3D12DebugManager::FillWithDiscardPattern(ID3D12GraphicsCommandListX *cmd, return; } + UINT firstSub = region ? region->FirstSubresource : 0; + UINT numSubs = region ? region->NumSubresources : GetNumSubresources(m_pDevice, &desc); + if(desc.SampleDesc.Count > 1) { // we can't do discard patterns for MSAA on compute comand lists @@ -876,9 +879,9 @@ void D3D12DebugManager::FillWithDiscardPattern(ID3D12GraphicsCommandListX *cmd, D3D12_CPU_DESCRIPTOR_HANDLE rtv = GetCPUHandle(MSAA_RTV); D3D12_CPU_DESCRIPTOR_HANDLE dsv = GetCPUHandle(MSAA_DSV); - for(UINT sub = 0; sub < region->NumSubresources; sub++) + for(UINT sub = 0; sub < numSubs; sub++) { - UINT subresource = region->FirstSubresource + sub; + UINT subresource = firstSub + sub; if(depth) { dsvDesc.Texture2DMSArray.FirstArraySlice = GetSliceForSubresource(res, subresource); @@ -949,9 +952,6 @@ void D3D12DebugManager::FillWithDiscardPattern(ID3D12GraphicsCommandListX *cmd, m_DiscardPatterns[desc.Format] = buf; } - UINT firstSub = region ? region->FirstSubresource : 0; - UINT numSubs = region ? region->NumSubresources : GetNumSubresources(m_pDevice, &desc); - for(UINT sub = firstSub; sub < firstSub + numSubs; sub++) { D3D12_RESOURCE_BARRIER b = {};