From 0f6f06c5ec2ce789c86b92472c6fa23b6d20ac88 Mon Sep 17 00:00:00 2001 From: baldurk Date: Sun, 10 Jul 2016 16:19:37 +0300 Subject: [PATCH] Add and release live resources properly during replay --- renderdoc/driver/d3d12/d3d12_device.cpp | 14 ++++++++ renderdoc/driver/d3d12/d3d12_device_wrap.cpp | 35 ++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/renderdoc/driver/d3d12/d3d12_device.cpp b/renderdoc/driver/d3d12/d3d12_device.cpp index 1e2910708..23ec940a3 100644 --- a/renderdoc/driver/d3d12/d3d12_device.cpp +++ b/renderdoc/driver/d3d12/d3d12_device.cpp @@ -1126,6 +1126,15 @@ void WrappedID3D12Device::ReleaseResource(ID3D12DeviceChild *res) SCOPED_LOCK(m_ResourceStatesLock); m_ResourceStates.erase(id); } + + // wrapped resources get released all the time, we don't want to + // try and slerp in a resource release. Just the explicit ones + if(m_State < WRITING) + { + if(GetResourceManager()->HasLiveResource(id)) + GetResourceManager()->EraseLiveResource(id); + return; + } } bool WrappedID3D12Device::Serialise_SetShaderDebugPath(ID3D12DeviceChild *res, const char *p) @@ -1275,6 +1284,11 @@ ID3D12GraphicsCommandList *WrappedID3D12Device::GetNewList() HRESULT hr = CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_Alloc, NULL, __uuidof(ID3D12GraphicsCommandList), (void **)&ret); + if(m_State < WRITING) + { + GetResourceManager()->AddLiveResource(GetResID(ret), ret); + } + RDCASSERTEQUAL(hr, S_OK); } diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp index 1ab23a2ef..5e8973f3f 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp @@ -91,6 +91,10 @@ HRESULT WrappedID3D12Device::CreateCommandQueue(const D3D12_COMMAND_QUEUE_DESC * m_DeviceRecord->AddChunk(scope.Get()); } + else + { + GetResourceManager()->AddLiveResource(wrapped->GetResourceID(), wrapped); + } if(pDesc->Type == D3D12_COMMAND_LIST_TYPE_DIRECT) { @@ -166,6 +170,10 @@ HRESULT WrappedID3D12Device::CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE type record->AddChunk(scope.Get()); } + else + { + GetResourceManager()->AddLiveResource(wrapped->GetResourceID(), wrapped); + } *ppCommandAllocator = (ID3D12CommandAllocator *)wrapped; } @@ -240,6 +248,9 @@ HRESULT WrappedID3D12Device::CreateCommandList(UINT nodeMask, D3D12_COMMAND_LIST wrapped->Reset(pCommandAllocator, pInitialState); } + // during replay, the caller is responsible for calling AddLiveResource as this function + // can be called from ID3D12GraphicsCommandList::Reset serialising + *ppCommandList = (ID3D12GraphicsCommandList *)wrapped; } @@ -309,6 +320,10 @@ HRESULT WrappedID3D12Device::CreateGraphicsPipelineState(const D3D12_GRAPHICS_PI record->AddChunk(scope.Get()); } + else + { + GetResourceManager()->AddLiveResource(wrapped->GetResourceID(), wrapped); + } *ppPipelineState = (ID3D12PipelineState *)wrapped; } @@ -376,6 +391,10 @@ HRESULT WrappedID3D12Device::CreateComputePipelineState(const D3D12_COMPUTE_PIPE record->AddChunk(scope.Get()); } + else + { + GetResourceManager()->AddLiveResource(wrapped->GetResourceID(), wrapped); + } *ppPipelineState = (ID3D12PipelineState *)wrapped; } @@ -449,6 +468,10 @@ HRESULT WrappedID3D12Device::CreateDescriptorHeap(const D3D12_DESCRIPTOR_HEAP_DE GetResourceManager()->MarkPendingDirty(wrapped->GetResourceID()); } } + else + { + GetResourceManager()->AddLiveResource(wrapped->GetResourceID(), wrapped); + } *ppvHeap = (ID3D12DescriptorHeap *)wrapped; } @@ -523,6 +546,10 @@ HRESULT WrappedID3D12Device::CreateRootSignature(UINT nodeMask, const void *pBlo record->AddChunk(scope.Get()); } + else + { + GetResourceManager()->AddLiveResource(wrapped->GetResourceID(), wrapped); + } *ppvRootSignature = (ID3D12RootSignature *)wrapped; } @@ -668,6 +695,10 @@ HRESULT WrappedID3D12Device::CreateCommittedResource(const D3D12_HEAP_PROPERTIES GetResourceManager()->MarkPendingDirty(wrapped->GetResourceID()); } } + else + { + GetResourceManager()->AddLiveResource(wrapped->GetResourceID(), wrapped); + } { SCOPED_LOCK(m_ResourceStatesLock); @@ -764,6 +795,10 @@ HRESULT WrappedID3D12Device::CreateFence(UINT64 InitialValue, D3D12_FENCE_FLAGS record->AddChunk(scope.Get()); } + else + { + GetResourceManager()->AddLiveResource(wrapped->GetResourceID(), wrapped); + } *ppFence = (ID3D12Fence *)wrapped; }