diff --git a/renderdoc/driver/d3d12/d3d12_command_list.h b/renderdoc/driver/d3d12/d3d12_command_list.h index b09750446..6c12583b9 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list.h +++ b/renderdoc/driver/d3d12/d3d12_command_list.h @@ -201,8 +201,8 @@ private: static rdcstr GetChunkName(uint32_t idx); D3D12ResourceManager *GetResourceManager() { return m_pDevice->GetResourceManager(); } - rdcarray> m_ImmediateASCallbacks; - rdcarray> m_PendingASCallbacks; + rdcarray> m_ImmediateCallbacks; + rdcarray> m_PendingCallbacks; rdcarray> m_UnusedCleanupCallbacks; public: ALLOCATE_WITH_WRAPPED_POOL(WrappedID3D12GraphicsCommandList); @@ -253,34 +253,39 @@ public: bool ValidateRootGPUVA(D3D12_GPU_VIRTUAL_ADDRESS buffer); - void AddSubmissionASBuildCallback(bool waitForSubmission, const std::function &postBldExec, - const std::function &unusedCleanup) + void AddSubmissionASBuildCallback(bool waitForSubmission, const std::function &callback, + const std::function &cleanupCallback) { - if(waitForSubmission) - m_PendingASCallbacks.push_back(postBldExec); - else - m_ImmediateASCallbacks.push_back(postBldExec); - m_UnusedCleanupCallbacks.push_back(unusedCleanup); + if(callback) + { + if(waitForSubmission) + m_PendingCallbacks.push_back(callback); + else + m_ImmediateCallbacks.push_back(callback); + } + + if(cleanupCallback) + m_UnusedCleanupCallbacks.push_back(cleanupCallback); } - bool ExecuteImmediateASBuildCallbacks() + bool ExecuteImmediateCallbacks() { bool success = true; - for(std::function &func : m_ImmediateASCallbacks) + for(std::function &func : m_ImmediateCallbacks) { success &= func(); } - m_ImmediateASCallbacks.clear(); + m_ImmediateCallbacks.clear(); m_UnusedCleanupCallbacks.clear(); return success; } - void TakeWaitingASBuildCallbacks(rdcarray> &callbacks) + void TakeWaitingCallbacks(rdcarray> &callbacks) { - callbacks.append(std::move(m_PendingASCallbacks)); - m_PendingASCallbacks.clear(); + callbacks.append(std::move(m_PendingCallbacks)); + m_PendingCallbacks.clear(); } template diff --git a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp index 84c7037ef..e1c420e41 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp @@ -409,8 +409,8 @@ HRESULT WrappedID3D12GraphicsCommandList::ResetInternal(ID3D12CommandAllocator * } m_RayDispatches.clear(); - m_ImmediateASCallbacks.clear(); - m_PendingASCallbacks.clear(); + m_ImmediateCallbacks.clear(); + m_PendingCallbacks.clear(); for(std::function &func : m_UnusedCleanupCallbacks) func(); diff --git a/renderdoc/driver/d3d12/d3d12_command_queue.h b/renderdoc/driver/d3d12/d3d12_command_queue.h index a174f9095..2a7c3e910 100644 --- a/renderdoc/driver/d3d12/d3d12_command_queue.h +++ b/renderdoc/driver/d3d12/d3d12_command_queue.h @@ -173,11 +173,11 @@ class WrappedID3D12CommandQueue : public ID3D12CommandQueue1, CaptureState &m_State; // tracking ray dispatches that are pending during capture, to free them once the execution is finished - ID3D12Fence *m_RayFence = NULL; + ID3D12Fence *m_CallbackFence = NULL; UINT64 m_RayFenceValue = 1; rdcarray m_RayDispatchesPending; - ID3D12Fence *GetRayFence(); + ID3D12Fence *GetCallbackFence(); bool m_MarkedActive = false; diff --git a/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp index df2fb29a5..443aaa974 100644 --- a/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp @@ -796,18 +796,18 @@ bool WrappedID3D12CommandQueue::Serialise_ExecuteCommandLists(SerialiserType &se return true; } -ID3D12Fence *WrappedID3D12CommandQueue::GetRayFence() +ID3D12Fence *WrappedID3D12CommandQueue::GetCallbackFence() { // if we don't have a fence for this queue tracking, create it now - if(!m_RayFence) + if(!m_CallbackFence) { // create this unwrapped so that it doesn't get recorded into captures m_pDevice->GetReal()->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), - (void **)&m_RayFence); - m_RayFence->SetName(L"Queue Ray Fence"); + (void **)&m_CallbackFence); + m_CallbackFence->SetName(L"Queue Callback Fence"); } - return m_RayFence; + return m_CallbackFence; } void WrappedID3D12CommandQueue::ExecuteCommandLists(UINT NumCommandLists, @@ -840,7 +840,7 @@ void WrappedID3D12CommandQueue::ExecuteCommandListsInternal(UINT NumCommandLists { SERIALISE_TIME_CALL(m_pReal->ExecuteCommandLists(NumCommandLists, unwrapped)); - rdcarray> pendingASBuildCallbacks; + rdcarray> pendingCallbacks; for(UINT i = 0; i < NumCommandLists; i++) { @@ -852,24 +852,24 @@ void WrappedID3D12CommandQueue::ExecuteCommandListsInternal(UINT NumCommandLists RDCLOG("Submit-callbacks for %s", ToStr(wrapped->GetResourceID()).c_str()); } - if(!wrapped->ExecuteImmediateASBuildCallbacks()) + if(!wrapped->ExecuteImmediateCallbacks()) { - RDCERR("Unable to execute post build for acc struct"); + RDCERR("Unable to execute list submission callback"); } - wrapped->TakeWaitingASBuildCallbacks(pendingASBuildCallbacks); + wrapped->TakeWaitingCallbacks(pendingCallbacks); } - if(!pendingASBuildCallbacks.empty()) + if(!pendingCallbacks.empty()) { - ID3D12Fence *fence = GetRayFence(); + ID3D12Fence *fence = GetCallbackFence(); // these callbacks need to be synchronised at every submission to process them as soon as the // results are available, since we could submit a build on one queue and then a dependent // build on another queue later once it's finished without any intermediate submissions on the // first queue. For that reason we pass these to the RT handler to hold onto, and tick it - GetResourceManager()->GetRTManager()->AddPendingASBuilds(fence, m_RayFenceValue, - pendingASBuildCallbacks); + GetResourceManager()->GetRTManager()->AddPendingCallbacks(fence, m_RayFenceValue, + pendingCallbacks); // add the signal for those callbacks to wait on HRESULT hr = m_pReal->Signal(fence, m_RayFenceValue++); @@ -1030,7 +1030,7 @@ void WrappedID3D12CommandQueue::ExecuteCommandListsInternal(UINT NumCommandLists m_RayDispatchesPending.append(rayDispatches); - HRESULT hr = m_pReal->Signal(GetRayFence(), m_RayFenceValue++); + HRESULT hr = m_pReal->Signal(GetCallbackFence(), m_RayFenceValue++); CHECK_HR(m_pDevice, hr); RDCASSERTEQUAL(hr, S_OK); } diff --git a/renderdoc/driver/d3d12/d3d12_commands.cpp b/renderdoc/driver/d3d12/d3d12_commands.cpp index 501d98bc3..209b3e7c6 100644 --- a/renderdoc/driver/d3d12/d3d12_commands.cpp +++ b/renderdoc/driver/d3d12/d3d12_commands.cpp @@ -560,7 +560,7 @@ WrappedID3D12CommandQueue::~WrappedID3D12CommandQueue() { SAFE_DELETE(m_FrameReader); - SAFE_RELEASE(m_RayFence); + SAFE_RELEASE(m_CallbackFence); for(SDObject *o : m_Cmd.m_EventAnnotations) delete o; @@ -682,8 +682,8 @@ HRESULT STDMETHODCALLTYPE WrappedID3D12CommandQueue::QueryInterface(REFIID riid, void WrappedID3D12CommandQueue::CheckAndFreeRayDispatches() { UINT64 signalled = 0; - if(m_RayFence) - signalled = m_RayFence->GetCompletedValue(); + if(m_CallbackFence) + signalled = m_CallbackFence->GetCompletedValue(); for(PatchedRayDispatch::Resources &ray : m_RayDispatchesPending) { diff --git a/renderdoc/driver/d3d12/d3d12_manager.cpp b/renderdoc/driver/d3d12/d3d12_manager.cpp index 1828577b1..fcd320644 100644 --- a/renderdoc/driver/d3d12/d3d12_manager.cpp +++ b/renderdoc/driver/d3d12/d3d12_manager.cpp @@ -1230,20 +1230,20 @@ void D3D12RTManager::AddBuildTimer(uint32_t q, uint64_t size) } } -void D3D12RTManager::AddPendingASBuilds(ID3D12Fence *fence, UINT64 waitValue, - const rdcarray> &callbacks) +void D3D12RTManager::AddPendingCallbacks(ID3D12Fence *fence, UINT64 waitValue, + const rdcarray> &callbacks) { - SCOPED_LOCK(m_PendingASBuildsLock); + SCOPED_LOCK(m_PendingCallbacksLock); for(const std::function &cb : callbacks) { fence->AddRef(); - m_PendingASBuilds.push_back({fence, waitValue, cb}); + m_PendingCallbacks.push_back({fence, waitValue, cb}); } } void D3D12RTManager::TickASManagement() { - CheckPendingASBuilds(); + CheckPendingCallbacks(); CheckASCaching(); } @@ -1533,17 +1533,17 @@ void D3D12RTManager::CheckASCaching() m_InMemASBuildDatas.erase(first, last - first + 1); } -void D3D12RTManager::CheckPendingASBuilds() +void D3D12RTManager::CheckPendingCallbacks() { std::map fenceValues; - SCOPED_LOCK(m_PendingASBuildsLock); + SCOPED_LOCK(m_PendingCallbacksLock); - if(m_PendingASBuilds.empty()) + if(m_PendingCallbacks.empty()) return; - for(size_t i = 0; i < m_PendingASBuilds.size(); i++) + for(size_t i = 0; i < m_PendingCallbacks.size(); i++) { - PendingASBuild &build = m_PendingASBuilds[i]; + PendingCallbacks &build = m_PendingCallbacks[i]; // first time we see each fence, get the completed value if(fenceValues[build.fence] == 0) @@ -1556,9 +1556,9 @@ void D3D12RTManager::CheckPendingASBuilds() build.callback(); // swap with last if this isn't already last - we don't need to keep order - if(i < m_PendingASBuilds.size() - 1) - std::swap(build, m_PendingASBuilds.back()); - m_PendingASBuilds.pop_back(); + if(i < m_PendingCallbacks.size() - 1) + std::swap(build, m_PendingCallbacks.back()); + m_PendingCallbacks.pop_back(); } } } diff --git a/renderdoc/driver/d3d12/d3d12_manager.h b/renderdoc/driver/d3d12/d3d12_manager.h index 425aaef50..0abdeced7 100644 --- a/renderdoc/driver/d3d12/d3d12_manager.h +++ b/renderdoc/driver/d3d12/d3d12_manager.h @@ -1271,8 +1271,8 @@ public: UINT64 ArgumentBufferOffset, ID3D12Resource *pCountBuffer, UINT64 CountBufferOffset); - void AddPendingASBuilds(ID3D12Fence *fence, UINT64 waitValue, - const rdcarray> &callbacks); + void AddPendingCallbacks(ID3D12Fence *fence, UINT64 waitValue, + const rdcarray> &callbacks); void TickASManagement(); // this disk cache is primarily single threaded - either the disk cache thread owns @@ -1354,7 +1354,7 @@ private: void InitReplayBlasPatchingResources(); void CheckASCaching(); - void CheckPendingASBuilds(); + void CheckPendingCallbacks(); void CopyFromVA(ID3D12GraphicsCommandList4 *unwrappedCmd, ID3D12Resource *dstRes, uint64_t dstOffset, D3D12_GPU_VIRTUAL_ADDRESS sourceVA, uint64_t byteSize); @@ -1426,14 +1426,14 @@ private: uint32_t GetFreeQuery(); - struct PendingASBuild + struct PendingCallbacks { ID3D12Fence *fence; UINT64 fenceValue; std::function callback; }; - Threading::CriticalSection m_PendingASBuildsLock; - rdcarray m_PendingASBuilds; + Threading::CriticalSection m_PendingCallbacksLock; + rdcarray m_PendingCallbacks; }; struct D3D12ResourceManagerConfiguration