diff --git a/renderdoc/driver/d3d12/d3d12_command_queue.h b/renderdoc/driver/d3d12/d3d12_command_queue.h index a763b821e..0146dab25 100644 --- a/renderdoc/driver/d3d12/d3d12_command_queue.h +++ b/renderdoc/driver/d3d12/d3d12_command_queue.h @@ -90,6 +90,9 @@ class WrappedID3D12CommandQueue : public ID3D12CommandQueue, vector m_CmdListRecords; + // D3D12 guarantees that queues are thread-safe + Threading::CriticalSection m_Lock; + // command recording/replay data shared between queues and lists D3D12CommandData m_Cmd; diff --git a/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp index a366d4d5a..688f94dc5 100644 --- a/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp @@ -356,16 +356,16 @@ bool WrappedID3D12CommandQueue::Serialise_ExecuteCommandLists(UINT NumCommandLis void STDMETHODCALLTYPE WrappedID3D12CommandQueue::ExecuteCommandLists( UINT NumCommandLists, ID3D12CommandList *const *ppCommandLists) { - ID3D12CommandList **unwrapped = new ID3D12CommandList *[NumCommandLists]; + ID3D12CommandList **unwrapped = m_pDevice->GetTempArray(NumCommandLists); for(UINT i = 0; i < NumCommandLists; i++) unwrapped[i] = Unwrap(ppCommandLists[i]); m_pReal->ExecuteCommandLists(NumCommandLists, unwrapped); - SAFE_DELETE_ARRAY(unwrapped); - if(m_State >= WRITING) { + SCOPED_LOCK(m_Lock); + bool capframe = false; set refdIDs; @@ -576,6 +576,8 @@ HRESULT STDMETHODCALLTYPE WrappedID3D12CommandQueue::Signal(ID3D12Fence *pFence, { if(m_State == WRITING_CAPFRAME) { + SCOPED_LOCK(m_Lock); + SCOPED_SERIALISE_CONTEXT(SIGNAL); Serialise_Signal(pFence, Value); @@ -605,6 +607,8 @@ HRESULT STDMETHODCALLTYPE WrappedID3D12CommandQueue::Wait(ID3D12Fence *pFence, U { if(m_State == WRITING_CAPFRAME) { + SCOPED_LOCK(m_Lock); + SCOPED_SERIALISE_CONTEXT(WAIT); Serialise_Wait(pFence, Value);