diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp index cacbe7383..3b465fbf4 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp @@ -838,14 +838,16 @@ bool WrappedID3D12Device::Serialise_CreateDescriptorHeap( if(IsReplayingAndReading()) { + D3D12_DESCRIPTOR_HEAP_DESC PatchedDesc = Descriptor; + // inflate the heap so we can insert our own descriptors at the end // while patching, because DX12 has a stupid limitation to not be able // to set multiple descriptor heaps at once of the same type - if(Descriptor.Type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) + if(PatchedDesc.Type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) { if(m_D3D12Opts.ResourceBindingTier == D3D12_RESOURCE_BINDING_TIER_3 || - Descriptor.NumDescriptors + 16 <= 1000000) - Descriptor.NumDescriptors += 16; + PatchedDesc.NumDescriptors + 16 <= 1000000) + PatchedDesc.NumDescriptors += 16; else RDCERR( "RenderDoc needs extra descriptors for patching during analysis," @@ -853,7 +855,7 @@ bool WrappedID3D12Device::Serialise_CreateDescriptorHeap( } ID3D12DescriptorHeap *ret = NULL; - HRESULT hr = m_pDevice->CreateDescriptorHeap(&Descriptor, guid, (void **)&ret); + HRESULT hr = m_pDevice->CreateDescriptorHeap(&PatchedDesc, guid, (void **)&ret); if(FAILED(hr)) { diff --git a/renderdoc/driver/d3d12/d3d12_initstate.cpp b/renderdoc/driver/d3d12/d3d12_initstate.cpp index 3061ea919..7a51dad1b 100644 --- a/renderdoc/driver/d3d12/d3d12_initstate.cpp +++ b/renderdoc/driver/d3d12/d3d12_initstate.cpp @@ -601,6 +601,9 @@ bool D3D12ResourceManager::Serialise_InitialState(SerialiserType &ser, ResourceI UINT increment = m_Device->GetDescriptorHandleIncrementSize(desc.Type); + // only iterate over the 'real' number of descriptors, not the number after we've patched + desc.NumDescriptors = heap->GetNumDescriptors(); + for(uint32_t i = 0; i < RDCMIN(numElems, desc.NumDescriptors); i++) { Descriptors[i].Create(desc.Type, m_Device, handle); @@ -1024,14 +1027,14 @@ void D3D12ResourceManager::Apply_InitialState(ID3D12DeviceChild *live, if(type == Resource_DescriptorHeap) { - ID3D12DescriptorHeap *dstheap = (ID3D12DescriptorHeap *)live; - ID3D12DescriptorHeap *srcheap = (ID3D12DescriptorHeap *)data.resource; + WrappedID3D12DescriptorHeap *dstheap = (WrappedID3D12DescriptorHeap *)live; + WrappedID3D12DescriptorHeap *srcheap = (WrappedID3D12DescriptorHeap *)data.resource; if(srcheap) { // copy the whole heap m_Device->CopyDescriptorsSimple( - srcheap->GetDesc().NumDescriptors, dstheap->GetCPUDescriptorHandleForHeapStart(), + srcheap->GetNumDescriptors(), dstheap->GetCPUDescriptorHandleForHeapStart(), srcheap->GetCPUDescriptorHandleForHeapStart(), srcheap->GetDesc().Type); } }