From 68523abad9e8a56266dc87e067d21bb7e5431e5b Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 28 Jun 2017 10:48:42 +0100 Subject: [PATCH] Add a separate command list for data uploads * Since D3D12 doesn't allow recording to multiple commands at once, if we end up doing a partial replay and including a data upload that uses a list to upload, we need a separate list and allocator. --- renderdoc/driver/d3d12/d3d12_device.cpp | 31 ++++++++++++++++++------- renderdoc/driver/d3d12/d3d12_device.h | 4 ++-- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_device.cpp b/renderdoc/driver/d3d12/d3d12_device.cpp index 0f61979f6..5c1869616 100644 --- a/renderdoc/driver/d3d12/d3d12_device.cpp +++ b/renderdoc/driver/d3d12/d3d12_device.cpp @@ -935,10 +935,12 @@ bool WrappedID3D12Device::Serialise_MapDataWrite(Serialiser *localSerialiser, } // then afterwards just execute a list to copy the result - ID3D12GraphicsCommandList *list = GetNewList(); - list->CopyBufferRegion(r, begin, uploadBuf, 0, end - begin); - list->Close(); - ExecuteList(list); + m_DataUploadList->Reset(m_DataUploadAlloc, NULL); + m_DataUploadList->CopyBufferRegion(r, begin, uploadBuf, 0, end - begin); + m_DataUploadList->Close(); + ID3D12CommandList *l = m_DataUploadList; + GetQueue()->ExecuteCommandLists(1, &l); + GPUSync(); } else { @@ -1050,13 +1052,15 @@ bool WrappedID3D12Device::Serialise_WriteToSubresource(Serialiser *localSerialis } // then afterwards just execute a list to copy the result - ID3D12GraphicsCommandList *list = GetNewList(); + m_DataUploadList->Reset(m_DataUploadAlloc, NULL); UINT64 copySize = dataSize; if(HasBox) copySize = RDCMIN(copySize, UINT64(box.right - box.left)); - list->CopyBufferRegion(r, HasBox ? box.left : 0, uploadBuf, 0, copySize); - list->Close(); - ExecuteList(list); + m_DataUploadList->CopyBufferRegion(r, HasBox ? box.left : 0, uploadBuf, 0, copySize); + m_DataUploadList->Close(); + ID3D12CommandList *l = m_DataUploadList; + GetQueue()->ExecuteCommandLists(1, &l); + GPUSync(); } else { @@ -2055,6 +2059,14 @@ void WrappedID3D12Device::CreateInternalResources() CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), (void **)&m_GPUSyncFence); m_GPUSyncHandle = ::CreateEvent(NULL, FALSE, FALSE, NULL); + CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, __uuidof(ID3D12CommandAllocator), + (void **)&m_DataUploadAlloc); + + CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_DataUploadAlloc, NULL, + __uuidof(ID3D12GraphicsCommandList), (void **)&m_DataUploadList); + + m_DataUploadList->Close(); + m_GPUSyncCounter = 0; RDCASSERT(m_DebugManager == NULL); @@ -2077,6 +2089,9 @@ void WrappedID3D12Device::DestroyInternalResources() delete m_DebugManager; m_DebugManager = NULL; + SAFE_RELEASE(m_DataUploadList); + SAFE_RELEASE(m_DataUploadAlloc); + SAFE_RELEASE(m_Alloc); SAFE_RELEASE(m_GPUSyncFence); CloseHandle(m_GPUSyncHandle); diff --git a/renderdoc/driver/d3d12/d3d12_device.h b/renderdoc/driver/d3d12/d3d12_device.h index 35804ca9b..85d21b673 100644 --- a/renderdoc/driver/d3d12/d3d12_device.h +++ b/renderdoc/driver/d3d12/d3d12_device.h @@ -232,8 +232,8 @@ private: // the queue we use for all internal work, the first DIRECT queue WrappedID3D12CommandQueue *m_Queue; - ID3D12CommandAllocator *m_Alloc; - ID3D12GraphicsCommandList *m_List; + ID3D12CommandAllocator *m_Alloc, *m_DataUploadAlloc; + ID3D12GraphicsCommandList *m_List, *m_DataUploadList; ID3D12Fence *m_GPUSyncFence; HANDLE m_GPUSyncHandle; UINT64 m_GPUSyncCounter;