From 8acd5ab27d60f368e429a9b6df398c55f4a60cfa Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 26 Oct 2016 10:48:03 +0200 Subject: [PATCH] Capture and replay commands executed on multiple queues --- .../driver/d3d12/d3d12_command_queue_wrap.cpp | 18 ++++++++++----- renderdoc/driver/d3d12/d3d12_device.cpp | 22 ++++++++++++------- renderdoc/driver/d3d12/d3d12_device.h | 4 ++++ renderdoc/driver/d3d12/d3d12_device_wrap.cpp | 20 ++++++++--------- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp index 688f94dc5..27a693656 100644 --- a/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp @@ -52,6 +52,7 @@ void STDMETHODCALLTYPE WrappedID3D12CommandQueue::CopyTileMappings( bool WrappedID3D12CommandQueue::Serialise_ExecuteCommandLists(UINT NumCommandLists, ID3D12CommandList *const *ppCommandLists) { + SERIALISE_ELEMENT(ResourceId, queueId, GetResourceID()); SERIALISE_ELEMENT(UINT, numCmds, NumCommandLists); vector cmdIds; @@ -119,6 +120,11 @@ bool WrappedID3D12CommandQueue::Serialise_ExecuteCommandLists(UINT NumCommandLis } } + ID3D12CommandQueue *real = NULL; + + if(m_State <= EXECUTING) + real = Unwrap(GetResourceManager()->GetLiveAs(queueId)); + if(m_State == READING) { for(uint32_t i = 0; i < numCmds; i++) @@ -127,7 +133,7 @@ bool WrappedID3D12CommandQueue::Serialise_ExecuteCommandLists(UINT NumCommandLis m_Cmd.m_BakedCmdListInfo[cmdIds[i]].executeEvents[0].patched) { ID3D12CommandList *list = Unwrap(cmds[i]); - m_pReal->ExecuteCommandLists(1, &list); + real->ExecuteCommandLists(1, &list); } else { @@ -135,7 +141,7 @@ bool WrappedID3D12CommandQueue::Serialise_ExecuteCommandLists(UINT NumCommandLis // execute the first half of the cracked list ID3D12CommandList *list = Unwrap(info.crackedLists[0]); - m_pReal->ExecuteCommandLists(1, &list); + real->ExecuteCommandLists(1, &list); for(size_t c = 1; c < info.crackedLists.size(); c++) { @@ -146,7 +152,7 @@ bool WrappedID3D12CommandQueue::Serialise_ExecuteCommandLists(UINT NumCommandLis // execute next list with this indirect. list = Unwrap(info.crackedLists[c]); - m_pReal->ExecuteCommandLists(1, &list); + real->ExecuteCommandLists(1, &list); } } } @@ -266,7 +272,7 @@ bool WrappedID3D12CommandQueue::Serialise_ExecuteCommandLists(UINT NumCommandLis m_pDevice->ApplyBarriers(m_Cmd.m_BakedCmdListInfo[rerecord].barriers); } - m_pReal->ExecuteCommandLists((UINT)rerecordedCmds.size(), &rerecordedCmds[0]); + real->ExecuteCommandLists((UINT)rerecordedCmds.size(), &rerecordedCmds[0]); } else if(m_Cmd.m_LastEventID > startEID && m_Cmd.m_LastEventID < m_Cmd.m_RootEventID) { @@ -320,7 +326,7 @@ bool WrappedID3D12CommandQueue::Serialise_ExecuteCommandLists(UINT NumCommandLis RDCASSERT(trimmedCmds.size() > 0); - m_pReal->ExecuteCommandLists((UINT)trimmedCmds.size(), &trimmedCmds[0]); + real->ExecuteCommandLists((UINT)trimmedCmds.size(), &trimmedCmds[0]); for(uint32_t i = 0; i < trimmedCmdIds.size(); i++) { @@ -337,7 +343,7 @@ bool WrappedID3D12CommandQueue::Serialise_ExecuteCommandLists(UINT NumCommandLis ID3D12CommandList **unwrapped = new ID3D12CommandList *[numCmds]; for(uint32_t i = 0; i < numCmds; i++) unwrapped[i] = Unwrap(cmds[i]); - m_pReal->ExecuteCommandLists(numCmds, unwrapped); + real->ExecuteCommandLists(numCmds, unwrapped); SAFE_DELETE_ARRAY(unwrapped); for(uint32_t i = 0; i < numCmds; i++) diff --git a/renderdoc/driver/d3d12/d3d12_device.cpp b/renderdoc/driver/d3d12/d3d12_device.cpp index 1d57bafad..42d12a702 100644 --- a/renderdoc/driver/d3d12/d3d12_device.cpp +++ b/renderdoc/driver/d3d12/d3d12_device.cpp @@ -1386,10 +1386,11 @@ bool WrappedID3D12Device::EndFrameCapture(void *dev, void *wnd) Serialiser *m_pFileSerialiser = RenderDoc::Inst().OpenWriteSerialiser( m_FrameCounter, &m_InitParams, jpgbuf, len, thwidth, thheight); - if(m_Queue->GetResourceRecord()->ContainsExecuteIndirect) - { - WrappedID3D12Resource::RefBuffers(GetResourceManager()); - } + std::vector queues = m_Queues; + + for(auto it = queues.begin(); it != queues.end(); ++it) + if((*it)->GetResourceRecord()->ContainsExecuteIndirect) + WrappedID3D12Resource::RefBuffers(GetResourceManager()); { CACHE_THREAD_SERIALISER(); @@ -1425,10 +1426,14 @@ bool WrappedID3D12Device::EndFrameCapture(void *dev, void *wnd) map recordlist; + for(auto it = queues.begin(); it != queues.end(); ++it) { - const vector &cmdListRecords = m_Queue->GetCmdLists(); + WrappedID3D12CommandQueue *q = *it; - RDCDEBUG("Flushing %u command list records to file serialiser", (uint32_t)cmdListRecords.size()); + const vector &cmdListRecords = q->GetCmdLists(); + + RDCDEBUG("Flushing %u command list records from queue %llu", (uint32_t)cmdListRecords.size(), + q->GetResourceID()); for(size_t i = 0; i < cmdListRecords.size(); i++) { @@ -1438,7 +1443,7 @@ bool WrappedID3D12Device::EndFrameCapture(void *dev, void *wnd) (uint32_t)recordlist.size(), cmdListRecords[i]->GetResourceID()); } - m_Queue->GetResourceRecord()->Insert(recordlist); + q->GetResourceRecord()->Insert(recordlist); } { @@ -1462,7 +1467,8 @@ bool WrappedID3D12Device::EndFrameCapture(void *dev, void *wnd) m_State = WRITING_IDLE; - m_Queue->ClearAfterCapture(); + for(auto it = queues.begin(); it != queues.end(); ++it) + (*it)->ClearAfterCapture(); GetResourceManager()->MarkUnwrittenResources(); diff --git a/renderdoc/driver/d3d12/d3d12_device.h b/renderdoc/driver/d3d12/d3d12_device.h index 483210c15..209128da4 100644 --- a/renderdoc/driver/d3d12/d3d12_device.h +++ b/renderdoc/driver/d3d12/d3d12_device.h @@ -224,6 +224,10 @@ class WrappedID3D12Device : public IFrameCapturer, public ID3DDevice, public ID3 private: ID3D12Device *m_pDevice; + // list of all queues being captured + std::vector m_Queues; + + // the queue we use for all internal work, the first DIRECT queue WrappedID3D12CommandQueue *m_Queue; ID3D12CommandAllocator *m_Alloc; diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp index 7673412c2..c0960f13a 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp @@ -58,15 +58,15 @@ bool WrappedID3D12Device::Serialise_CreateCommandQueue(Serialiser *localSerialis GetResourceManager()->AddLiveResource(Queue, ret); - if(Descriptor.Type == D3D12_COMMAND_LIST_TYPE_DIRECT) + WrappedID3D12CommandQueue *wrapped = (WrappedID3D12CommandQueue *)ret; + + if(Descriptor.Type == D3D12_COMMAND_LIST_TYPE_DIRECT && m_Queue == NULL) { - if(m_Queue != NULL) - RDCERR("Don't support multiple direct queues yet!"); - - m_Queue = (WrappedID3D12CommandQueue *)ret; - + m_Queue = wrapped; CreateInternalResources(); } + + m_Queues.push_back(wrapped); } } @@ -104,16 +104,14 @@ HRESULT WrappedID3D12Device::CreateCommandQueue(const D3D12_COMMAND_QUEUE_DESC * GetResourceManager()->AddLiveResource(wrapped->GetResourceID(), wrapped); } - if(pDesc->Type == D3D12_COMMAND_LIST_TYPE_DIRECT) + if(pDesc->Type == D3D12_COMMAND_LIST_TYPE_DIRECT && m_Queue == NULL) { - if(m_Queue != NULL) - RDCERR("Don't support multiple queues yet!"); - m_Queue = wrapped; - CreateInternalResources(); } + m_Queues.push_back(wrapped); + *ppCommandQueue = (ID3D12CommandQueue *)wrapped; }