From 351f287a5904c02dbddafd92460bbf5592f83dc6 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 11 Dec 2025 14:24:27 +0000 Subject: [PATCH] Eliminate original/live ID distinction by respecify IDs on D3D12 --- renderdoc/driver/d3d12/d3d12_command_list.h | 4 +- .../driver/d3d12/d3d12_command_list4_wrap.cpp | 2 +- .../driver/d3d12/d3d12_command_list_wrap.cpp | 42 ++++++---- renderdoc/driver/d3d12/d3d12_command_queue.h | 2 +- renderdoc/driver/d3d12/d3d12_commands.cpp | 34 +++++--- renderdoc/driver/d3d12/d3d12_device.cpp | 10 +-- renderdoc/driver/d3d12/d3d12_device.h | 5 ++ .../d3d12/d3d12_device_rescreate_wrap.cpp | 13 +-- renderdoc/driver/d3d12/d3d12_device_wrap.cpp | 68 ++++++++++------ renderdoc/driver/d3d12/d3d12_device_wrap1.cpp | 2 +- .../driver/d3d12/d3d12_device_wrap13.cpp | 2 +- .../driver/d3d12/d3d12_device_wrap14.cpp | 4 +- renderdoc/driver/d3d12/d3d12_device_wrap2.cpp | 8 +- renderdoc/driver/d3d12/d3d12_device_wrap3.cpp | 4 +- renderdoc/driver/d3d12/d3d12_device_wrap4.cpp | 10 +-- renderdoc/driver/d3d12/d3d12_device_wrap5.cpp | 4 +- renderdoc/driver/d3d12/d3d12_device_wrap7.cpp | 6 +- renderdoc/driver/d3d12/d3d12_device_wrap9.cpp | 8 +- renderdoc/driver/d3d12/d3d12_initstate.cpp | 3 +- renderdoc/driver/d3d12/d3d12_manager.cpp | 2 +- renderdoc/driver/d3d12/d3d12_replay.cpp | 4 +- renderdoc/driver/d3d12/d3d12_resources.cpp | 19 +++-- renderdoc/driver/d3d12/d3d12_resources.h | 81 ++++++++++--------- 23 files changed, 196 insertions(+), 141 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_command_list.h b/renderdoc/driver/d3d12/d3d12_command_list.h index 3db5c1558..641c7c1e8 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list.h +++ b/renderdoc/driver/d3d12/d3d12_command_list.h @@ -207,8 +207,8 @@ private: public: ALLOCATE_WITH_WRAPPED_POOL(WrappedID3D12GraphicsCommandList); - WrappedID3D12GraphicsCommandList(ID3D12GraphicsCommandList *real, WrappedID3D12Device *device, - CaptureState &state); + WrappedID3D12GraphicsCommandList(ResourceId id, ID3D12GraphicsCommandList *real, + WrappedID3D12Device *device, CaptureState &state); virtual ~WrappedID3D12GraphicsCommandList(); ResourceId GetResourceID() { return m_ResourceID; } diff --git a/renderdoc/driver/d3d12/d3d12_command_list4_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list4_wrap.cpp index 1cb5a1919..157586762 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list4_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list4_wrap.cpp @@ -745,7 +745,7 @@ bool WrappedID3D12GraphicsCommandList::ProcessASBuildAfterSubmission( // // CreateAccStruct deletes any previous overlapping ASs on the ASB D3D12AccelerationStructure *accStructAtDestOffset = NULL; - if(dstASB->CreateAccStruct(destASBOffset, type, byteSize, dstASId, &accStructAtDestOffset)) + if(dstASB->CreateAccStruct(dstASId, destASBOffset, type, byteSize, &accStructAtDestOffset)) { D3D12ResourceRecord *record = rm->AddResourceRecord(accStructAtDestOffset->GetResourceID()); record->type = Resource_AccelerationStructure; diff --git a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp index 3fb31cd85..57a6f6e0f 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp @@ -214,11 +214,10 @@ bool WrappedID3D12GraphicsCommandList::Serialise_Reset(SerialiserType &ser, } } - if(rerecord) { ID3D12GraphicsCommandList *listptr = NULL; HRESULT hr = - m_pDevice->CreateCommandList(nodeMask, type, pAllocator, pInitialState, + m_pDevice->CreateCommandList(BakedCommandList, nodeMask, type, pAllocator, pInitialState, __uuidof(ID3D12GraphicsCommandList), (void **)&listptr); if(FAILED(hr)) @@ -231,19 +230,30 @@ bool WrappedID3D12GraphicsCommandList::Serialise_Reset(SerialiserType &ser, // this is a safe upcast because it's a wrapped object ID3D12GraphicsCommandListX *list = (ID3D12GraphicsCommandListX *)listptr; - // we store under both baked and non baked ID. - // The baked ID is the 'real' entry, the non baked is simply so it - // can be found in the subsequent serialised commands that ref the - // non-baked ID. The baked ID is referenced by the submit itself. - // - // In Close() we erase the non-baked reference, and since - // we know you can only be recording a command list once at a time - // (even if it's baked to several command listsin the frame) - // there's no issue with clashes here. - m_Cmd->m_RerecordCmds[BakedCommandList] = list; - m_Cmd->m_RerecordCmds[CommandList] = list; + if(rerecord) + { + // we store under both baked and non baked ID. + // The baked ID is the 'real' entry, the non baked is simply so it + // can be found in the subsequent serialised commands that ref the + // non-baked ID. The baked ID is referenced by the submit itself. + // + // In Close() we erase the non-baked reference, and since + // we know you can only be recording a command list once at a time + // (even if it's baked to several command listsin the frame) + // there's no issue with clashes here. + m_Cmd->m_RerecordCmds[BakedCommandList] = list; + m_Cmd->m_RerecordCmds[CommandList] = list; + } + else + { + list->Close(); + } + // always create a version of this list even if we're not re-recording, so the serialisation + // has an object to find m_Cmd->m_RerecordCmdList.push_back(list); + + GetResourceManager()->AddLiveResource(BakedCommandList, list); } D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; @@ -287,7 +297,7 @@ bool WrappedID3D12GraphicsCommandList::Serialise_Reset(SerialiserType &ser, { ID3D12GraphicsCommandList *list = NULL; HRESULT hr = - m_pDevice->CreateCommandList(nodeMask, type, pAllocator, pInitialState, + m_pDevice->CreateCommandList(BakedCommandList, nodeMask, type, pAllocator, pInitialState, __uuidof(ID3D12GraphicsCommandList), (void **)&list); RDCASSERTEQUAL(hr, S_OK); @@ -312,6 +322,10 @@ bool WrappedID3D12GraphicsCommandList::Serialise_Reset(SerialiserType &ser, GetResourceManager()->RemoveReplacement(CommandList); GetResourceManager()->ReplaceResource(CommandList, BakedCommandList); + + // this is a safe upcast because it's a wrapped object + ID3D12GraphicsCommandListX *listX = (ID3D12GraphicsCommandListX *)list; + m_Cmd->m_RerecordCmdList.push_back(listX); } else { diff --git a/renderdoc/driver/d3d12/d3d12_command_queue.h b/renderdoc/driver/d3d12/d3d12_command_queue.h index dc53fa508..0a4918381 100644 --- a/renderdoc/driver/d3d12/d3d12_command_queue.h +++ b/renderdoc/driver/d3d12/d3d12_command_queue.h @@ -215,7 +215,7 @@ class WrappedID3D12CommandQueue : public ID3D12CommandQueue1, public: ALLOCATE_WITH_WRAPPED_POOL(WrappedID3D12CommandQueue); - WrappedID3D12CommandQueue(ID3D12CommandQueue *real, WrappedID3D12Device *device, + WrappedID3D12CommandQueue(ResourceId id, ID3D12CommandQueue *real, WrappedID3D12Device *device, CaptureState &state); virtual ~WrappedID3D12CommandQueue(); diff --git a/renderdoc/driver/d3d12/d3d12_commands.cpp b/renderdoc/driver/d3d12/d3d12_commands.cpp index 4f6abeebd..844566af9 100644 --- a/renderdoc/driver/d3d12/d3d12_commands.cpp +++ b/renderdoc/driver/d3d12/d3d12_commands.cpp @@ -493,7 +493,7 @@ HRESULT STDMETHODCALLTYPE WrappedDownlevelQueue::Present(ID3D12GraphicsCommandLi return m_pQueue.Present(pOpenCommandList, pSourceTex2D, hWindow, Flags); } -WrappedID3D12CommandQueue::WrappedID3D12CommandQueue(ID3D12CommandQueue *real, +WrappedID3D12CommandQueue::WrappedID3D12CommandQueue(ResourceId id, ID3D12CommandQueue *real, WrappedID3D12Device *device, CaptureState &state) : RefCounter12(real), m_pDevice(device), @@ -519,13 +519,14 @@ WrappedID3D12CommandQueue::WrappedID3D12CommandQueue(ID3D12CommandQueue *real, if(RenderDoc::Inst().IsReplayApp()) { - m_ReplayList = new WrappedID3D12GraphicsCommandList(NULL, m_pDevice, state); + m_ReplayList = new WrappedID3D12GraphicsCommandList(ResourceId(), NULL, m_pDevice, state); m_ReplayList->SetCommandData(&m_Cmd); } - // create a temporary and grab its resource ID - m_ResourceID = ResourceIDGen::GetNewUniqueID(); + if(id == ResourceId()) + id = ResourceIDGen::GetNewUniqueID(); + m_ResourceID = id; m_QueueRecord = NULL; m_CreationRecord = NULL; @@ -557,6 +558,8 @@ WrappedID3D12CommandQueue::WrappedID3D12CommandQueue(ID3D12CommandQueue *real, WrappedID3D12CommandQueue::~WrappedID3D12CommandQueue() { + SAFE_DELETE(m_ReplayList); + SAFE_DELETE(m_FrameReader); SAFE_RELEASE(m_RayFence); @@ -1119,6 +1122,14 @@ RDResult WrappedID3D12CommandQueue::ReplayLog(CaptureState readType, uint32_t st { m_State = readType; + if(!partial) + { + for(size_t i = 0; i < m_Cmd.m_RerecordCmdList.size(); i++) + SAFE_RELEASE(m_Cmd.m_RerecordCmdList[i]); + + m_Cmd.m_RerecordCmdList.clear(); + } + if(!m_FrameReader) { RETURN_ERROR_RESULT(ResultCode::InvalidParameter, @@ -1328,16 +1339,13 @@ RDResult WrappedID3D12CommandQueue::ReplayLog(CaptureState readType, uint32_t st m_StructuredFile = NULL; - for(size_t i = 0; i < m_Cmd.m_RerecordCmdList.size(); i++) - SAFE_RELEASE(m_Cmd.m_RerecordCmdList[i]); - m_Cmd.m_RerecordCmds.clear(); - m_Cmd.m_RerecordCmdList.clear(); return ResultCode::Succeeded; } -WrappedID3D12GraphicsCommandList::WrappedID3D12GraphicsCommandList(ID3D12GraphicsCommandList *real, +WrappedID3D12GraphicsCommandList::WrappedID3D12GraphicsCommandList(ResourceId id, + ID3D12GraphicsCommandList *real, WrappedID3D12Device *device, CaptureState &state) : m_RefCounter(real, false), m_pList(real), m_pDevice(device), m_State(state) @@ -1370,8 +1378,9 @@ WrappedID3D12GraphicsCommandList::WrappedID3D12GraphicsCommandList(ID3D12Graphic m_pList->QueryInterface(__uuidof(ID3D12GraphicsCommandList10), (void **)&m_pList10); } - // create a temporary and grab its resource ID - m_ResourceID = ResourceIDGen::GetNewUniqueID(); + m_ResourceID = id; + if(id == ResourceId()) + m_ResourceID = ResourceIDGen::GetNewUniqueID(); RDCEraseEl(m_Init); @@ -1445,6 +1454,9 @@ WrappedID3D12GraphicsCommandList::~WrappedID3D12GraphicsCommandList() m_pDevice->GetResourceManager()->ReleaseCurrentResource(GetResourceID()); + if(IsReplayMode(m_State) && m_pDevice->GetResourceManager()->HasLiveResource(GetResourceID())) + m_pDevice->GetResourceManager()->EraseLiveResource(GetResourceID()); + SAFE_RELEASE(m_WrappedDebug.m_pReal); SAFE_RELEASE(m_WrappedDebug.m_pReal1); SAFE_RELEASE(m_WrappedDebug.m_pReal2); diff --git a/renderdoc/driver/d3d12/d3d12_device.cpp b/renderdoc/driver/d3d12/d3d12_device.cpp index 80a5486b8..e5ba20f68 100644 --- a/renderdoc/driver/d3d12/d3d12_device.cpp +++ b/renderdoc/driver/d3d12/d3d12_device.cpp @@ -809,7 +809,6 @@ WrappedID3D12Device::WrappedID3D12Device(ID3D12Device *realDevice, D3D12InitPara m_ResourceManager = new D3D12ResourceManager(m_State, this); - // create a temporary and grab its resource ID m_ResourceID = ResourceIDGen::GetNewUniqueID(); m_DeviceRecord = NULL; @@ -1894,7 +1893,7 @@ bool WrappedID3D12Device::Serialise_WrapSwapchainBuffer(SerialiserType &ser, IDX } else { - WrappedID3D12Resource *wrapped = new WrappedID3D12Resource(fakeBB, NULL, 0, this); + WrappedID3D12Resource *wrapped = new WrappedID3D12Resource(SwapbufferID, fakeBB, NULL, 0, this); fakeBB = wrapped; fakeBB->SetName(L"Swap Chain Buffer"); @@ -1936,7 +1935,7 @@ IUnknown *WrappedID3D12Device::WrapSwapchainBuffer(IDXGISwapper *swapper, DXGI_F } else { - pRes = new WrappedID3D12Resource((ID3D12Resource *)realSurface, NULL, 0, this); + pRes = new WrappedID3D12Resource(ResourceId(), (ID3D12Resource *)realSurface, NULL, 0, this); ResourceId id = GetResID(pRes); @@ -4097,8 +4096,7 @@ bool WrappedID3D12Device::Serialise_CreateAS(SerialiserType &ser, ID3D12Resource { WrappedID3D12Resource *asbWrappedResource = (WrappedID3D12Resource *)pResource; D3D12AccelerationStructure *accStructAtOffset = NULL; - if(asbWrappedResource->CreateAccStruct(resourceOffset, type, byteSize, ResourceId(), - &accStructAtOffset)) + if(asbWrappedResource->CreateAccStruct(asId, resourceOffset, type, byteSize, &accStructAtOffset)) { GetResourceManager()->AddLiveResource(asId, accStructAtOffset); @@ -5363,7 +5361,7 @@ RDResult WrappedID3D12Device::ReadLogInitialisation(RDCFile *rdc, bool storeStru if(IsStructuredExporting(m_State)) { - m_Queue = new WrappedID3D12CommandQueue(NULL, this, m_State); + m_Queue = new WrappedID3D12CommandQueue(ResourceId(), NULL, this, m_State); m_Queues.push_back(m_Queue); } diff --git a/renderdoc/driver/d3d12/d3d12_device.h b/renderdoc/driver/d3d12/d3d12_device.h index e7ac39e2f..36e24e9d3 100644 --- a/renderdoc/driver/d3d12/d3d12_device.h +++ b/renderdoc/driver/d3d12/d3d12_device.h @@ -1459,6 +1459,11 @@ public: ID3D12PipelineState *pInitialState, REFIID riid, void **ppCommandList); + ResourceId m_NextListID; + HRESULT CreateCommandList(ResourceId id, UINT nodeMask, D3D12_COMMAND_LIST_TYPE type, + ID3D12CommandAllocator *pCommandAllocator, + ID3D12PipelineState *pInitialState, REFIID riid, void **ppCommandList); + IMPLEMENT_FUNCTION_THREAD_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CheckFeatureSupport, D3D12_FEATURE Feature, void *pFeatureSupportData, UINT FeatureSupportDataSize); diff --git a/renderdoc/driver/d3d12/d3d12_device_rescreate_wrap.cpp b/renderdoc/driver/d3d12/d3d12_device_rescreate_wrap.cpp index fef4ee60d..4139a4c88 100644 --- a/renderdoc/driver/d3d12/d3d12_device_rescreate_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_rescreate_wrap.cpp @@ -248,7 +248,7 @@ bool WrappedID3D12Device::Serialise_CreateResource( SetObjName(ret, StringFormat::Fmt("%s Resource %s %s", ResourceTypeName, ToStr(desc.Dimension).c_str(), ToStr(pResource).c_str())); - ret = new WrappedID3D12Resource(ret, pHeap, HeapOffset, this, gpuAddress); + ret = new WrappedID3D12Resource(pResource, ret, pHeap, HeapOffset, this, gpuAddress); switch(chunkType) { @@ -448,7 +448,8 @@ HRESULT WrappedID3D12Device::CreateResource( UINT NumSubresources = GetNumSubresources(m_pDevice, &desc); - WrappedID3D12Resource *wrapped = new WrappedID3D12Resource(realRes, pHeap, HeapOffset, this); + WrappedID3D12Resource *wrapped = + new WrappedID3D12Resource(ResourceId(), realRes, pHeap, HeapOffset, this); if(IsCaptureMode(m_State)) { @@ -824,7 +825,7 @@ bool WrappedID3D12Device::Serialise_OpenSharedHandle(SerialiserType &ser, HANDLE } else { - ret = new WrappedID3D12Fence(ret, this); + ret = new WrappedID3D12Fence(resourceId, ret, this); GetResourceManager()->AddLiveResource(resourceId, ret); } @@ -896,7 +897,7 @@ bool WrappedID3D12Device::Serialise_OpenSharedHandle(SerialiserType &ser, HANDLE } else { - ret = new WrappedID3D12Heap(ret, this); + ret = new WrappedID3D12Heap(resourceId, ret, this); GetResourceManager()->AddLiveResource(resourceId, ret); } @@ -1055,7 +1056,7 @@ HRESULT WrappedID3D12Device::OpenSharedHandleInternal(D3D12Chunk chunkType, if(riid_internal == __uuidof(ID3D12Fence1)) real = (ID3D12Fence1 *)ret; - WrappedID3D12Fence *wrapped = new WrappedID3D12Fence(real, this); + WrappedID3D12Fence *wrapped = new WrappedID3D12Fence(ResourceId(), real, this); wrappedDeviceChild = wrapped; @@ -1080,7 +1081,7 @@ HRESULT WrappedID3D12Device::OpenSharedHandleInternal(D3D12Chunk chunkType, } else if(isHeap) { - WrappedID3D12Heap *wrapped = new WrappedID3D12Heap((ID3D12Heap *)ret, this); + WrappedID3D12Heap *wrapped = new WrappedID3D12Heap(ResourceId(), (ID3D12Heap *)ret, this); if(HeapFlags & D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT) wrapped->Evict(); diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp index d6eb75b02..5470c33f9 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp @@ -116,7 +116,7 @@ bool WrappedID3D12Device::Serialise_CreateCommandQueue(SerialiserType &ser, { SetObjName(ret, StringFormat::Fmt("Command Queue %s", ToStr(pCommandQueue).c_str())); - ret = new WrappedID3D12CommandQueue(ret, this, m_State); + ret = new WrappedID3D12CommandQueue(pCommandQueue, ret, this, m_State); GetResourceManager()->AddLiveResource(pCommandQueue, ret); @@ -163,7 +163,8 @@ HRESULT WrappedID3D12Device::CreateCommandQueue(const D3D12_COMMAND_QUEUE_DESC * if(SUCCEEDED(ret)) { - WrappedID3D12CommandQueue *wrapped = new WrappedID3D12CommandQueue(real, this, m_State); + WrappedID3D12CommandQueue *wrapped = + new WrappedID3D12CommandQueue(ResourceId(), real, this, m_State); if(IsCaptureMode(m_State)) { @@ -246,7 +247,7 @@ bool WrappedID3D12Device::Serialise_CreateCommandAllocator(SerialiserType &ser, } else { - ret = new WrappedID3D12CommandAllocator(ret, this); + ret = new WrappedID3D12CommandAllocator(pCommandAllocator, ret, this); m_CommandAllocators.push_back(ret); @@ -274,7 +275,8 @@ HRESULT WrappedID3D12Device::CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE type if(SUCCEEDED(ret)) { - WrappedID3D12CommandAllocator *wrapped = new WrappedID3D12CommandAllocator(real, this); + WrappedID3D12CommandAllocator *wrapped = + new WrappedID3D12CommandAllocator(ResourceId(), real, this); if(IsCaptureMode(m_State)) { @@ -338,7 +340,7 @@ bool WrappedID3D12Device::Serialise_CreateCommandList(SerialiserType &ser, UINT // don't pass the initial state. We are about to immediately close the command list anyway, and // otherwise we would need to wait on it ID3D12GraphicsCommandList *list = NULL; - HRESULT hr = CreateCommandList(nodeMask, type, pCommandAllocator, NULL, + HRESULT hr = CreateCommandList(pCommandList, nodeMask, type, pCommandAllocator, NULL, __uuidof(ID3D12GraphicsCommandList), (void **)&list); if(FAILED(hr)) @@ -417,7 +419,9 @@ HRESULT WrappedID3D12Device::CreateCommandList(UINT nodeMask, D3D12_COMMAND_LIST if(SUCCEEDED(ret)) { WrappedID3D12GraphicsCommandList *wrapped = - new WrappedID3D12GraphicsCommandList(real, this, m_State); + new WrappedID3D12GraphicsCommandList(m_NextListID, real, this, m_State); + + m_NextListID = ResourceId(); if(m_pAMDExtObject) { @@ -488,6 +492,16 @@ HRESULT WrappedID3D12Device::CreateCommandList(UINT nodeMask, D3D12_COMMAND_LIST return ret; } +HRESULT WrappedID3D12Device::CreateCommandList(ResourceId id, UINT nodeMask, + D3D12_COMMAND_LIST_TYPE type, + ID3D12CommandAllocator *pCommandAllocator, + ID3D12PipelineState *pInitialState, REFIID riid, + void **ppCommandList) +{ + m_NextListID = id; + return CreateCommandList(nodeMask, type, pCommandAllocator, pInitialState, riid, ppCommandList); +} + template bool WrappedID3D12Device::Serialise_CreateGraphicsPipelineState( SerialiserType &ser, const D3D12_GRAPHICS_PIPELINE_STATE_DESC *pDesc, REFIID riid, @@ -530,7 +544,7 @@ bool WrappedID3D12Device::Serialise_CreateGraphicsPipelineState( } WrappedID3D12PipelineState *wrapped = new WrappedID3D12PipelineState( - GetResourceManager()->CreateDeferredHandle(), this); + pPipelineState, GetResourceManager()->CreateDeferredHandle(), this); wrapped->graphics = new D3D12_EXPANDED_PIPELINE_STATE_STREAM_DESC(OrigDescriptor); @@ -552,7 +566,7 @@ bool WrappedID3D12Device::Serialise_CreateGraphicsPipelineState( } else { - WrappedID3D12Shader *entry = WrappedID3D12Shader::AddShader(*shaders[i], this); + WrappedID3D12Shader *entry = WrappedID3D12Shader::AddShader(ResourceId(), *shaders[i], this); entry->AddRef(); shaders[i]->pShaderBytecode = entry; @@ -657,7 +671,7 @@ void WrappedID3D12Device::ProcessCreatedGraphicsPSO(ID3D12PipelineState *real, m_UsedDXIL = true; } - WrappedID3D12PipelineState *wrapped = new WrappedID3D12PipelineState(real, this); + WrappedID3D12PipelineState *wrapped = new WrappedID3D12PipelineState(ResourceId(), real, this); if(IsCaptureMode(m_State)) { @@ -720,7 +734,7 @@ void WrappedID3D12Device::ProcessCreatedGraphicsPSO(ID3D12PipelineState *real, } else { - WrappedID3D12Shader *sh = WrappedID3D12Shader::AddShader(*shaders[i], this); + WrappedID3D12Shader *sh = WrappedID3D12Shader::AddShader(ResourceId(), *shaders[i], this); sh->AddRef(); if(m_GlobalEXTUAV != ~0U) sh->SetShaderExtSlot(m_GlobalEXTUAV, m_GlobalEXTUAVSpace); @@ -836,11 +850,12 @@ bool WrappedID3D12Device::Serialise_CreateComputePipelineState( OrigDescriptor.CS.BytecodeLength); WrappedID3D12PipelineState *wrapped = new WrappedID3D12PipelineState( - GetResourceManager()->CreateDeferredHandle(), this); + pPipelineState, GetResourceManager()->CreateDeferredHandle(), this); wrapped->compute = new D3D12_EXPANDED_PIPELINE_STATE_STREAM_DESC(OrigDescriptor); - WrappedID3D12Shader *entry = WrappedID3D12Shader::AddShader(wrapped->compute->CS, this); + WrappedID3D12Shader *entry = + WrappedID3D12Shader::AddShader(ResourceId(), wrapped->compute->CS, this); entry->AddRef(); if(m_GlobalEXTUAV != ~0U) @@ -902,7 +917,7 @@ void WrappedID3D12Device::ProcessCreatedComputePSO(ID3D12PipelineState *real, ui if(DXBC::DXBCContainer::CheckForDXIL(pDesc->CS.pShaderBytecode, pDesc->CS.BytecodeLength)) m_UsedDXIL = true; - WrappedID3D12PipelineState *wrapped = new WrappedID3D12PipelineState(real, this); + WrappedID3D12PipelineState *wrapped = new WrappedID3D12PipelineState(ResourceId(), real, this); if(IsCaptureMode(m_State)) { @@ -946,7 +961,8 @@ void WrappedID3D12Device::ProcessCreatedComputePSO(ID3D12PipelineState *real, ui wrapped->compute = new D3D12_EXPANDED_PIPELINE_STATE_STREAM_DESC(*pDesc); - WrappedID3D12Shader *sh = WrappedID3D12Shader::AddShader(wrapped->compute->CS, this); + WrappedID3D12Shader *sh = + WrappedID3D12Shader::AddShader(ResourceId(), wrapped->compute->CS, this); sh->AddRef(); wrapped->compute->CS.pShaderBytecode = sh; @@ -1056,7 +1072,7 @@ bool WrappedID3D12Device::Serialise_CreateDescriptorHeap( else { WrappedID3D12DescriptorHeap *wrapped = - new WrappedID3D12DescriptorHeap(ret, this, PatchedDesc, Descriptor.NumDescriptors); + new WrappedID3D12DescriptorHeap(pHeap, ret, this, PatchedDesc, Descriptor.NumDescriptors); wrapped->SetOriginalGPUBase(originalGPUBase); @@ -1095,7 +1111,7 @@ HRESULT WrappedID3D12Device::CreateDescriptorHeap(const D3D12_DESCRIPTOR_HEAP_DE if(SUCCEEDED(ret)) { WrappedID3D12DescriptorHeap *wrapped = new WrappedID3D12DescriptorHeap( - real, this, *pDescriptorHeapDesc, pDescriptorHeapDesc->NumDescriptors); + ResourceId(), real, this, *pDescriptorHeapDesc, pDescriptorHeapDesc->NumDescriptors); if(IsCaptureMode(m_State)) { @@ -1170,7 +1186,7 @@ bool WrappedID3D12Device::Serialise_CreateRootSignature(SerialiserType &ser, UIN } else { - ret = new WrappedID3D12RootSignature(ret, this); + ret = new WrappedID3D12RootSignature(pRootSignature, ret, this); GetResourceManager()->AddLiveResource(pRootSignature, ret); } @@ -1230,7 +1246,7 @@ HRESULT WrappedID3D12Device::CreateRootSignature(UINT nodeMask, const void *pBlo return ret; } - wrapped = new WrappedID3D12RootSignature(real, this); + wrapped = new WrappedID3D12RootSignature(ResourceId(), real, this); } wrapped->sig = DecodeRootSig(pBlobWithRootSignature, blobLengthInBytes); @@ -1624,7 +1640,7 @@ bool WrappedID3D12Device::Serialise_CreateHeap(SerialiserType &ser, const D3D12_ } else { - ret = new WrappedID3D12Heap(ret, this); + ret = new WrappedID3D12Heap(pHeap, ret, this); GetResourceManager()->AddLiveResource(pHeap, ret); } @@ -1656,7 +1672,7 @@ HRESULT WrappedID3D12Device::CreateHeap(const D3D12_HEAP_DESC *pDesc, REFIID rii if(SUCCEEDED(ret)) { - WrappedID3D12Heap *wrapped = new WrappedID3D12Heap(real, this); + WrappedID3D12Heap *wrapped = new WrappedID3D12Heap(ResourceId(), real, this); if(IsCaptureMode(m_State)) { @@ -1721,7 +1737,7 @@ bool WrappedID3D12Device::Serialise_CreateFence(SerialiserType &ser, UINT64 Init } else { - ret = new WrappedID3D12Fence(ret, this); + ret = new WrappedID3D12Fence(pFence, ret, this); GetResourceManager()->AddLiveResource(pFence, ret); } @@ -1754,7 +1770,7 @@ HRESULT WrappedID3D12Device::CreateFence(UINT64 InitialValue, D3D12_FENCE_FLAGS if(SUCCEEDED(ret)) { - WrappedID3D12Fence *wrapped = new WrappedID3D12Fence(real, this); + WrappedID3D12Fence *wrapped = new WrappedID3D12Fence(ResourceId(), real, this); if(IsCaptureMode(m_State)) { @@ -1813,7 +1829,7 @@ bool WrappedID3D12Device::Serialise_CreateQueryHeap(SerialiserType &ser, } else { - ret = new WrappedID3D12QueryHeap(ret, this); + ret = new WrappedID3D12QueryHeap(pQueryHeap, ret, this); GetResourceManager()->AddLiveResource(pQueryHeap, ret); } @@ -1839,7 +1855,7 @@ HRESULT WrappedID3D12Device::CreateQueryHeap(const D3D12_QUERY_HEAP_DESC *pDesc, if(SUCCEEDED(ret)) { - WrappedID3D12QueryHeap *wrapped = new WrappedID3D12QueryHeap(real, this); + WrappedID3D12QueryHeap *wrapped = new WrappedID3D12QueryHeap(ResourceId(), real, this); if(IsCaptureMode(m_State)) { @@ -1900,7 +1916,7 @@ bool WrappedID3D12Device::Serialise_CreateCommandSignature(SerialiserType &ser, else { WrappedID3D12CommandSignature *wrapped = - new WrappedID3D12CommandSignature(ret, this, Descriptor); + new WrappedID3D12CommandSignature(pCommandSignature, ret, this, Descriptor); ret = wrapped; @@ -1947,7 +1963,7 @@ HRESULT WrappedID3D12Device::CreateCommandSignature(const D3D12_COMMAND_SIGNATUR return ret; } - wrapped = new WrappedID3D12CommandSignature(real, this, *pDesc); + wrapped = new WrappedID3D12CommandSignature(ResourceId(), real, this, *pDesc); } if(IsCaptureMode(m_State)) diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap1.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap1.cpp index 9083b3d23..9967bb1be 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap1.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap1.cpp @@ -48,7 +48,7 @@ HRESULT WrappedID3D12Device::CreatePipelineLibrary(_In_reads_(BlobLength) const if(BlobLength > 0) return D3D12_ERROR_DRIVER_VERSION_MISMATCH; - WrappedID3D12PipelineLibrary *pipeLibrary = new WrappedID3D12PipelineLibrary(this); + WrappedID3D12PipelineLibrary *pipeLibrary = new WrappedID3D12PipelineLibrary(ResourceId(), this); if(riid == __uuidof(ID3D12PipelineLibrary)) { diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap13.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap13.cpp index cef85c21f..315ee04aa 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap13.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap13.cpp @@ -43,7 +43,7 @@ HRESULT WrappedID3D12Device::OpenExistingHeapFromAddress1(const void *pAddress, if(SUCCEEDED(ret)) { - WrappedID3D12Heap *wrapped = new WrappedID3D12Heap(real, this); + WrappedID3D12Heap *wrapped = new WrappedID3D12Heap(ResourceId(), real, this); if(IsCaptureMode(m_State)) { diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap14.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap14.cpp index b8e49a65f..67d3854e1 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap14.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap14.cpp @@ -118,7 +118,7 @@ bool WrappedID3D12Device::Serialise_CreateRootSignatureFromSubobjectInLibrary( } else { - ret = new WrappedID3D12RootSignature(ret, this); + ret = new WrappedID3D12RootSignature(pRootSignature, ret, this); GetResourceManager()->AddLiveResource(pRootSignature, ret); } @@ -179,7 +179,7 @@ HRESULT WrappedID3D12Device::CreateRootSignatureFromSubobjectInLibrary( return ret; } - wrapped = new WrappedID3D12RootSignature(real, this); + wrapped = new WrappedID3D12RootSignature(ResourceId(), real, this); } wrapped->sig = diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap2.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap2.cpp index d64e8dd3b..0af3b1c41 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap2.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap2.cpp @@ -110,7 +110,7 @@ bool WrappedID3D12Device::Serialise_CreatePipelineState(SerialiserType &ser, } WrappedID3D12PipelineState *wrapped = new WrappedID3D12PipelineState( - GetResourceManager()->CreateDeferredHandle(), this); + pPipelineState, GetResourceManager()->CreateDeferredHandle(), this); D3D12_EXPANDED_PIPELINE_STATE_STREAM_DESC *storedDesc = new D3D12_EXPANDED_PIPELINE_STATE_STREAM_DESC(OrigDescriptor); @@ -133,7 +133,7 @@ bool WrappedID3D12Device::Serialise_CreatePipelineState(SerialiserType &ser, } else { - WrappedID3D12Shader *entry = WrappedID3D12Shader::AddShader(*shaders[i], this); + WrappedID3D12Shader *entry = WrappedID3D12Shader::AddShader(ResourceId(), *shaders[i], this); entry->AddRef(); shaders[i]->pShaderBytecode = entry; @@ -277,7 +277,7 @@ HRESULT WrappedID3D12Device::CreatePipelineState(const D3D12_PIPELINE_STATE_STRE if(SUCCEEDED(ret)) { - WrappedID3D12PipelineState *wrapped = new WrappedID3D12PipelineState(real, this); + WrappedID3D12PipelineState *wrapped = new WrappedID3D12PipelineState(ResourceId(), real, this); if(IsCaptureMode(m_State)) { @@ -357,7 +357,7 @@ HRESULT WrappedID3D12Device::CreatePipelineState(const D3D12_PIPELINE_STATE_STRE } else { - WrappedID3D12Shader *sh = WrappedID3D12Shader::AddShader(*shaders[i], this); + WrappedID3D12Shader *sh = WrappedID3D12Shader::AddShader(ResourceId(), *shaders[i], this); sh->AddRef(); shaders[i]->pShaderBytecode = sh; } diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap3.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap3.cpp index 51018e85a..7cf102da8 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap3.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap3.cpp @@ -40,7 +40,7 @@ HRESULT WrappedID3D12Device::OpenExistingHeapFromAddress(const void *pAddress, R if(SUCCEEDED(ret)) { - WrappedID3D12Heap *wrapped = new WrappedID3D12Heap(real, this); + WrappedID3D12Heap *wrapped = new WrappedID3D12Heap(ResourceId(), real, this); if(IsCaptureMode(m_State)) { @@ -112,7 +112,7 @@ HRESULT WrappedID3D12Device::OpenExistingHeapFromFileMapping(HANDLE hFileMapping if(SUCCEEDED(ret)) { - WrappedID3D12Heap *wrapped = new WrappedID3D12Heap(real, this); + WrappedID3D12Heap *wrapped = new WrappedID3D12Heap(ResourceId(), real, this); if(IsCaptureMode(m_State)) { diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap4.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap4.cpp index ab0a8b7db..1ef5f3a5d 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap4.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap4.cpp @@ -134,7 +134,7 @@ HRESULT WrappedID3D12Device::CreateCommandList1(UINT nodeMask, D3D12_COMMAND_LIS if(SUCCEEDED(ret)) { WrappedID3D12GraphicsCommandList *wrapped = - new WrappedID3D12GraphicsCommandList(real, this, m_State); + new WrappedID3D12GraphicsCommandList(ResourceId(), real, this, m_State); if(m_pAMDExtObject) { @@ -219,7 +219,7 @@ HRESULT WrappedID3D12Device::CreateProtectedResourceSession( if(SUCCEEDED(ret)) { WrappedID3D12ProtectedResourceSession *wrapped = - new WrappedID3D12ProtectedResourceSession(real, this); + new WrappedID3D12ProtectedResourceSession(ResourceId(), real, this); if(riid == __uuidof(ID3D12ProtectedResourceSession)) *ppSession = (ID3D12ProtectedResourceSession *)wrapped; @@ -277,7 +277,7 @@ bool WrappedID3D12Device::Serialise_CreateHeap1(SerialiserType &ser, const D3D12 } else { - ret = new WrappedID3D12Heap(ret, this); + ret = new WrappedID3D12Heap(pHeap, ret, this); GetResourceManager()->AddLiveResource(pHeap, ret); } @@ -312,7 +312,7 @@ HRESULT WrappedID3D12Device::CreateHeap1(const D3D12_HEAP_DESC *pDesc, if(SUCCEEDED(ret)) { - WrappedID3D12Heap *wrapped = new WrappedID3D12Heap(real, this); + WrappedID3D12Heap *wrapped = new WrappedID3D12Heap(ResourceId(), real, this); if(IsCaptureMode(m_State)) { @@ -370,7 +370,7 @@ ID3D12Fence *WrappedID3D12Device::CreateProtectedSessionFence(ID3D12Fence *real) // we basically treat this kind of like CreateFence and serialise it as such, and guess at the // parameters to CreateFence. - wrapped = new WrappedID3D12Fence(real, this); + wrapped = new WrappedID3D12Fence(ResourceId(), real, this); } if(IsCaptureMode(m_State)) diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap5.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap5.cpp index 0d13f8f48..bd079c098 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap5.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap5.cpp @@ -173,7 +173,7 @@ bool WrappedID3D12Device::Serialise_CreateStateObject(SerialiserType &ser, } WrappedID3D12StateObject *wrapped = new WrappedID3D12StateObject( - GetResourceManager()->CreateDeferredHandle(), true, this); + pStateObject, GetResourceManager()->CreateDeferredHandle(), true, this); wrapped->exports = new D3D12ShaderExportDatabase(pStateObject, GetResourceManager()->GetRTManager()); @@ -266,7 +266,7 @@ WrappedID3D12Device::CreateStateObject(const D3D12_STATE_OBJECT_DESC *pDesc, REF if(SUCCEEDED(ret)) { - WrappedID3D12StateObject *wrapped = new WrappedID3D12StateObject(real, false, this); + WrappedID3D12StateObject *wrapped = new WrappedID3D12StateObject(ResourceId(), real, false, this); if(IsCaptureMode(m_State)) { diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap7.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap7.cpp index a5efa8dd2..0925e7aa0 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap7.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap7.cpp @@ -130,7 +130,7 @@ bool WrappedID3D12Device::Serialise_AddToStateObject(SerialiserType &ser, } WrappedID3D12StateObject *wrapped = new WrappedID3D12StateObject( - GetResourceManager()->CreateDeferredHandle(), true, this); + pNewStateObject, GetResourceManager()->CreateDeferredHandle(), true, this); // TODO: Apply m_GlobalEXTUAV, m_GlobalEXTUAVSpace for processing extensions in the DXBC files? @@ -230,7 +230,7 @@ HRESULT STDMETHODCALLTYPE WrappedID3D12Device::AddToStateObject( if(SUCCEEDED(ret)) { - WrappedID3D12StateObject *wrapped = new WrappedID3D12StateObject(real, false, this); + WrappedID3D12StateObject *wrapped = new WrappedID3D12StateObject(ResourceId(), real, false, this); if(IsCaptureMode(m_State)) { @@ -321,7 +321,7 @@ HRESULT WrappedID3D12Device::CreateProtectedResourceSession1( if(SUCCEEDED(ret)) { WrappedID3D12ProtectedResourceSession *wrapped = - new WrappedID3D12ProtectedResourceSession(real, this); + new WrappedID3D12ProtectedResourceSession(ResourceId(), real, this); if(riid == __uuidof(ID3D12ProtectedResourceSession)) *ppSession = (ID3D12ProtectedResourceSession *)wrapped; diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap9.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap9.cpp index ec05c891f..bc35a1280 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap9.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap9.cpp @@ -43,7 +43,8 @@ HRESULT WrappedID3D12Device::CreateShaderCacheSession(_In_ const D3D12_SHADER_CA if(SUCCEEDED(ret)) { - WrappedID3D12ShaderCacheSession *wrapped = new WrappedID3D12ShaderCacheSession(real, this); + WrappedID3D12ShaderCacheSession *wrapped = + new WrappedID3D12ShaderCacheSession(ResourceId(), real, this); if(riid == __uuidof(ID3D12ShaderCacheSession)) *ppvSession = (ID3D12ShaderCacheSession *)wrapped; @@ -98,7 +99,7 @@ bool WrappedID3D12Device::Serialise_CreateCommandQueue1(SerialiserType &ser, { SetObjName(ret, StringFormat::Fmt("Command Queue %s", ToStr(pCommandQueue).c_str())); - ret = new WrappedID3D12CommandQueue(ret, this, m_State); + ret = new WrappedID3D12CommandQueue(pCommandQueue, ret, this, m_State); GetResourceManager()->AddLiveResource(pCommandQueue, ret); @@ -145,7 +146,8 @@ HRESULT WrappedID3D12Device::CreateCommandQueue1(const D3D12_COMMAND_QUEUE_DESC if(SUCCEEDED(ret)) { - WrappedID3D12CommandQueue *wrapped = new WrappedID3D12CommandQueue(real, this, m_State); + WrappedID3D12CommandQueue *wrapped = + new WrappedID3D12CommandQueue(ResourceId(), real, this, m_State); if(IsCaptureMode(m_State)) { diff --git a/renderdoc/driver/d3d12/d3d12_initstate.cpp b/renderdoc/driver/d3d12/d3d12_initstate.cpp index 5f1cef249..9436407b8 100644 --- a/renderdoc/driver/d3d12/d3d12_initstate.cpp +++ b/renderdoc/driver/d3d12/d3d12_initstate.cpp @@ -853,7 +853,8 @@ bool D3D12ResourceManager::Serialise_InitialState(SerialiserType &ser, ResourceI return false; } - copyheap = new WrappedID3D12DescriptorHeap(copyheap, m_Device, desc, heap->GetNumDescriptors()); + copyheap = new WrappedID3D12DescriptorHeap(ResourceId(), copyheap, m_Device, desc, + heap->GetNumDescriptors()); D3D12_CPU_DESCRIPTOR_HANDLE handle = copyheap->GetCPUDescriptorHandleForHeapStart(); diff --git a/renderdoc/driver/d3d12/d3d12_manager.cpp b/renderdoc/driver/d3d12/d3d12_manager.cpp index 4e7dd3cb9..da3189752 100644 --- a/renderdoc/driver/d3d12/d3d12_manager.cpp +++ b/renderdoc/driver/d3d12/d3d12_manager.cpp @@ -3935,7 +3935,7 @@ void D3D12ResourceManager::SerialiseResourceStates( for(auto it = initialStates.begin(); it != initialStates.end(); ++it) { // ignore internal resources, we only care about restoring states for captured resources - if(GetOriginalID(it->first) == it->first) + if(ResourceIDGen::IsReplayOnlyID(it->first)) continue; if(processed.find(it->first) == processed.end()) diff --git a/renderdoc/driver/d3d12/d3d12_replay.cpp b/renderdoc/driver/d3d12/d3d12_replay.cpp index 02770bb3e..4251f7e24 100644 --- a/renderdoc/driver/d3d12/d3d12_replay.cpp +++ b/renderdoc/driver/d3d12/d3d12_replay.cpp @@ -407,7 +407,7 @@ rdcarray D3D12Replay::GetTextures() for(auto it = m_pDevice->GetResourceList().begin(); it != m_pDevice->GetResourceList().end(); it++) { if(it->second->GetDesc().Dimension != D3D12_RESOURCE_DIMENSION_BUFFER && - m_pDevice->GetResourceManager()->GetOriginalID(it->first) != it->first) + !ResourceIDGen::IsReplayOnlyID(it->first)) ret.push_back(GetTexture(it->first)); } @@ -3578,7 +3578,7 @@ void D3D12Replay::BuildShader(ShaderEncoding sourceEncoding, const bytebuf &sour byteCode.BytecodeLength = dxbcLength; byteCode.pShaderBytecode = dxbcBytes; - WrappedID3D12Shader *sh = WrappedID3D12Shader::AddShader(byteCode, m_pDevice); + WrappedID3D12Shader *sh = WrappedID3D12Shader::AddShader(ResourceId(), byteCode, m_pDevice); sh->AddRef(); diff --git a/renderdoc/driver/d3d12/d3d12_resources.cpp b/renderdoc/driver/d3d12/d3d12_resources.cpp index e9143ae5e..f51bde62d 100644 --- a/renderdoc/driver/d3d12/d3d12_resources.cpp +++ b/renderdoc/driver/d3d12/d3d12_resources.cpp @@ -142,10 +142,10 @@ ID3D12DeviceChild *Unwrap(ID3D12DeviceChild *ptr) WRAPPED_POOL_INST(D3D12AccelerationStructure); D3D12AccelerationStructure::D3D12AccelerationStructure( - WrappedID3D12Device *wrappedDevice, ResourceId id, WrappedID3D12Resource *bufferRes, + ResourceId id, WrappedID3D12Device *wrappedDevice, WrappedID3D12Resource *bufferRes, D3D12BufferOffset bufferOffset, D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type, UINT64 byteSize) - : WrappedDeviceChild12(NULL, wrappedDevice, id), + : WrappedDeviceChild12(id, NULL, wrappedDevice), m_asbWrappedResource(bufferRes), m_asbWrappedResourceBufferOffset(bufferOffset), type(type), @@ -159,8 +159,8 @@ D3D12AccelerationStructure::~D3D12AccelerationStructure() Shutdown(); } -WrappedID3D12Heap::WrappedID3D12Heap(ID3D12Heap *real, WrappedID3D12Device *device) - : WrappedDeviceChild12(real, device) +WrappedID3D12Heap::WrappedID3D12Heap(ResourceId id, ID3D12Heap *real, WrappedID3D12Device *device) + : WrappedDeviceChild12(id, real, device) { D3D12_HEAP_DESC desc = GetDesc(); if((desc.Flags & D3D12_HEAP_FLAG_DENY_BUFFERS) == 0) @@ -190,10 +190,9 @@ WrappedID3D12Heap::WrappedID3D12Heap(ID3D12Heap *real, WrappedID3D12Device *devi } } -bool WrappedID3D12Resource::CreateAccStruct(D3D12BufferOffset bufferOffset, +bool WrappedID3D12Resource::CreateAccStruct(ResourceId id, D3D12BufferOffset bufferOffset, D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type, - UINT64 byteSize, ResourceId id, - D3D12AccelerationStructure **accStruct) + UINT64 byteSize, D3D12AccelerationStructure **accStruct) { SCOPED_LOCK(m_accStructResourcesCS); auto existing = m_accelerationStructMap.find(bufferOffset); @@ -205,7 +204,7 @@ bool WrappedID3D12Resource::CreateAccStruct(D3D12BufferOffset bufferOffset, } m_accelerationStructMap[bufferOffset] = - new D3D12AccelerationStructure(m_pDevice, id, this, bufferOffset, type, byteSize); + new D3D12AccelerationStructure(id, m_pDevice, this, bufferOffset, type, byteSize); *accStruct = m_accelerationStructMap[bufferOffset]; @@ -571,11 +570,11 @@ void WrappedID3D12DescriptorHeap::SetToDescriptorCache(uint32_t index, const Des cachedDescriptors[index] = view; } -WrappedID3D12DescriptorHeap::WrappedID3D12DescriptorHeap(ID3D12DescriptorHeap *real, +WrappedID3D12DescriptorHeap::WrappedID3D12DescriptorHeap(ResourceId id, ID3D12DescriptorHeap *real, WrappedID3D12Device *device, const D3D12_DESCRIPTOR_HEAP_DESC &desc, UINT UnpatchedNumDescriptors) - : WrappedDeviceChild12(real, device) + : WrappedDeviceChild12(id, real, device) { realCPUBase = real->GetCPUDescriptorHandleForHeapStart(); if(desc.Flags & D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE) diff --git a/renderdoc/driver/d3d12/d3d12_resources.h b/renderdoc/driver/d3d12/d3d12_resources.h index 3e2259243..5dba2032c 100644 --- a/renderdoc/driver/d3d12/d3d12_resources.h +++ b/renderdoc/driver/d3d12/d3d12_resources.h @@ -55,12 +55,11 @@ D3D12_UNORDERED_ACCESS_VIEW_DESC MakeUAVDesc(const D3D12_RESOURCE_DESC &desc); class TrackedResource12 { public: - TrackedResource12(ResourceId id = ResourceId()) + TrackedResource12(ResourceId id) { if(id == ResourceId()) - m_ID = ResourceIDGen::GetNewUniqueID(); - else - m_ID = id; + id = ResourceIDGen::GetNewUniqueID(); + m_ID = id; m_pRecord = NULL; } ResourceId GetResourceID() { return m_ID; } @@ -85,7 +84,7 @@ protected: WrappedID3D12Device *m_pDevice; int32_t m_Resident = 1; - WrappedDeviceChild12(NestedType *real, WrappedID3D12Device *device, ResourceId id = ResourceId()) + WrappedDeviceChild12(ResourceId id, NestedType *real, WrappedID3D12Device *device) : RefCounter12(real), TrackedResource12(id), m_pDevice(device) { m_pDevice->SoftRef(); @@ -359,8 +358,9 @@ public: TypeEnum = Resource_CommandAllocator, }; - WrappedID3D12CommandAllocator(ID3D12CommandAllocator *real, WrappedID3D12Device *device) - : WrappedDeviceChild12(real, device) + WrappedID3D12CommandAllocator(ResourceId id, ID3D12CommandAllocator *real, + WrappedID3D12Device *device) + : WrappedDeviceChild12(id, real, device) { } virtual ~WrappedID3D12CommandAllocator() { Shutdown(); } @@ -391,9 +391,10 @@ public: TypeEnum = Resource_CommandSignature, }; - WrappedID3D12CommandSignature(ID3D12CommandSignature *real, WrappedID3D12Device *device, + WrappedID3D12CommandSignature(ResourceId id, ID3D12CommandSignature *real, + WrappedID3D12Device *device, const D3D12_COMMAND_SIGNATURE_DESC &Descriptor) - : WrappedDeviceChild12(real, device) + : WrappedDeviceChild12(id, real, device) { sig.ByteStride = Descriptor.ByteStride; sig.arguments.assign(Descriptor.pArgumentDescs, Descriptor.NumArgumentDescs); @@ -506,7 +507,7 @@ public: TypeEnum = Resource_DescriptorHeap, }; - WrappedID3D12DescriptorHeap(ID3D12DescriptorHeap *real, WrappedID3D12Device *device, + WrappedID3D12DescriptorHeap(ResourceId id, ID3D12DescriptorHeap *real, WrappedID3D12Device *device, const D3D12_DESCRIPTOR_HEAP_DESC &desc, UINT UnpatchedNumDescriptors); virtual ~WrappedID3D12DescriptorHeap(); @@ -612,8 +613,8 @@ public: TypeEnum = Resource_Fence, }; - WrappedID3D12Fence(ID3D12Fence *real, WrappedID3D12Device *device) - : WrappedDeviceChild12(real, device) + WrappedID3D12Fence(ResourceId id, ID3D12Fence *real, WrappedID3D12Device *device) + : WrappedDeviceChild12(id, real, device) { } virtual ~WrappedID3D12Fence() { Shutdown(); } @@ -655,9 +656,9 @@ public: TypeEnum = Resource_ProtectedResourceSession, }; - WrappedID3D12ProtectedResourceSession(ID3D12ProtectedResourceSession *real, + WrappedID3D12ProtectedResourceSession(ResourceId id, ID3D12ProtectedResourceSession *real, WrappedID3D12Device *device) - : WrappedDeviceChild12(real, device) + : WrappedDeviceChild12(id, real, device) { } virtual ~WrappedID3D12ProtectedResourceSession() { Shutdown(); } @@ -733,7 +734,7 @@ public: ID3D12Resource *GetUnwrappedWholeMemBuffer() { return m_WholeMem; } - WrappedID3D12Heap(ID3D12Heap *real, WrappedID3D12Device *device); + WrappedID3D12Heap(ResourceId id, ID3D12Heap *real, WrappedID3D12Device *device); virtual ~WrappedID3D12Heap() { SAFE_RELEASE(m_WholeMem); @@ -771,7 +772,7 @@ public: if(riid == __uuidof(ID3D12ProtectedResourceSession)) { *ppProtectedSession = new WrappedID3D12ProtectedResourceSession( - (ID3D12ProtectedResourceSession *)iface, m_pDevice); + ResourceId(), (ID3D12ProtectedResourceSession *)iface, m_pDevice); } else { @@ -881,8 +882,8 @@ public: m_InternalResources = internalResources; } - ShaderEntry(const D3D12_SHADER_BYTECODE &byteCode, WrappedID3D12Device *device) - : WrappedDeviceChild12(NULL, device), m_Key(byteCode) + ShaderEntry(ResourceId id, const D3D12_SHADER_BYTECODE &byteCode, WrappedID3D12Device *device) + : WrappedDeviceChild12(id, NULL, device), m_Key(byteCode) { m_Bytecode.assign((const byte *)byteCode.pShaderBytecode, byteCode.BytecodeLength); m_DXBCFile = NULL; @@ -917,13 +918,14 @@ public: ShaderEntry(const ShaderEntry &e) = delete; ShaderEntry &operator=(const ShaderEntry &e) = delete; - static ShaderEntry *AddShader(const D3D12_SHADER_BYTECODE &byteCode, WrappedID3D12Device *device) + static ShaderEntry *AddShader(ResourceId id, const D3D12_SHADER_BYTECODE &byteCode, + WrappedID3D12Device *device) { DXBCKey key(byteCode); ShaderEntry *shader = m_Shaders[key]; if(shader == NULL) - shader = m_Shaders[key] = new ShaderEntry(byteCode, device); + shader = m_Shaders[key] = new ShaderEntry(id, byteCode, device); return shader; } @@ -1038,8 +1040,8 @@ public: ShaderEntry *AS() { return graphics ? (ShaderEntry *)graphics->AS.pShaderBytecode : NULL; } ShaderEntry *MS() { return graphics ? (ShaderEntry *)graphics->MS.pShaderBytecode : NULL; } ShaderEntry *CS() { return compute ? (ShaderEntry *)compute->CS.pShaderBytecode : NULL; } - WrappedID3D12PipelineState(ID3D12PipelineState *real, WrappedID3D12Device *device) - : WrappedDeviceChild12(real, device) + WrappedID3D12PipelineState(ResourceId id, ID3D12PipelineState *real, WrappedID3D12Device *device) + : WrappedDeviceChild12(id, real, device) { if(IsReplayMode(m_pDevice->GetState())) m_pDevice->GetPipelineList().push_back(this); @@ -1278,8 +1280,9 @@ public: TypeEnum = Resource_StateObject, }; - WrappedID3D12StateObject(ID3D12StateObject *real, bool deferredHandle, WrappedID3D12Device *device) - : WrappedDeviceChild12(real, device) + WrappedID3D12StateObject(ResourceId id, ID3D12StateObject *real, bool deferredHandle, + WrappedID3D12Device *device) + : WrappedDeviceChild12(id, real, device) { if(!deferredHandle) SetNewReal(real); @@ -1423,8 +1426,8 @@ public: TypeEnum = Resource_QueryHeap, }; - WrappedID3D12QueryHeap(ID3D12QueryHeap *real, WrappedID3D12Device *device) - : WrappedDeviceChild12(real, device) + WrappedID3D12QueryHeap(ResourceId id, ID3D12QueryHeap *real, WrappedID3D12Device *device) + : WrappedDeviceChild12(id, real, device) { } virtual ~WrappedID3D12QueryHeap() { Shutdown(); } @@ -1477,9 +1480,9 @@ public: return this->GetResourceID(); } - bool CreateAccStruct(D3D12BufferOffset bufferOffset, + bool CreateAccStruct(ResourceId id, D3D12BufferOffset bufferOffset, D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE type, UINT64 byteSize, - ResourceId id, D3D12AccelerationStructure **accStruct); + D3D12AccelerationStructure **accStruct); bool GetAccStructIfExist(D3D12BufferOffset bufferOffset, D3D12AccelerationStructure **accStruct = NULL); @@ -1530,9 +1533,9 @@ public: TypeEnum = Resource_Resource, }; - WrappedID3D12Resource(ID3D12Resource *real, ID3D12Heap *heap, UINT64 HeapOffset, + WrappedID3D12Resource(ResourceId id, ID3D12Resource *real, ID3D12Heap *heap, UINT64 HeapOffset, WrappedID3D12Device *device, UINT64 origAddress = 0) - : WrappedDeviceChild12(real, device) + : WrappedDeviceChild12(id, real, device) { m_OrigAddress = origAddress; if(IsReplayMode(device->GetState())) @@ -1654,7 +1657,7 @@ public: if(riid == __uuidof(ID3D12ProtectedResourceSession)) { *ppProtectedSession = new WrappedID3D12ProtectedResourceSession( - (ID3D12ProtectedResourceSession *)iface, m_pDevice); + ResourceId(), (ID3D12ProtectedResourceSession *)iface, m_pDevice); } else { @@ -1707,8 +1710,8 @@ public: TypeEnum = Resource_RootSignature, }; - WrappedID3D12RootSignature(ID3D12RootSignature *real, WrappedID3D12Device *device) - : WrappedDeviceChild12(real, device) + WrappedID3D12RootSignature(ResourceId id, ID3D12RootSignature *real, WrappedID3D12Device *device) + : WrappedDeviceChild12(id, real, device) { } virtual ~WrappedID3D12RootSignature() { Shutdown(); } @@ -1724,7 +1727,10 @@ public: TypeEnum = Resource_PipelineLibrary, }; - WrappedID3D12PipelineLibrary(WrappedID3D12Device *device) : WrappedDeviceChild12(NULL, device) {} + WrappedID3D12PipelineLibrary(ResourceId id, WrappedID3D12Device *device) + : WrappedDeviceChild12(id, NULL, device) + { + } virtual ~WrappedID3D12PipelineLibrary() { Shutdown(); } virtual HRESULT STDMETHODCALLTYPE StorePipeline(_In_opt_ LPCWSTR pName, _In_ ID3D12PipelineState *pPipeline) @@ -1792,8 +1798,9 @@ public: TypeEnum = Resource_ShaderCacheSession, }; - WrappedID3D12ShaderCacheSession(ID3D12ShaderCacheSession *real, WrappedID3D12Device *device) - : WrappedDeviceChild12(real, device) + WrappedID3D12ShaderCacheSession(ResourceId id, ID3D12ShaderCacheSession *real, + WrappedID3D12Device *device) + : WrappedDeviceChild12(id, real, device) { } virtual ~WrappedID3D12ShaderCacheSession() { Shutdown(); } @@ -1832,7 +1839,7 @@ class D3D12AccelerationStructure : public WrappedDeviceChild12