From 46e4ccb5ee9fabcd172808e0cf8b021ca48af0c8 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 18 Nov 2016 21:19:18 +0100 Subject: [PATCH] Batch up command lists used for preparing and applying initial state --- renderdoc/driver/d3d12/d3d12_commands.cpp | 2 +- renderdoc/driver/d3d12/d3d12_device.cpp | 48 ++++++++++++++++++++++- renderdoc/driver/d3d12/d3d12_device.h | 10 +++++ renderdoc/driver/d3d12/d3d12_manager.cpp | 16 ++++---- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_commands.cpp b/renderdoc/driver/d3d12/d3d12_commands.cpp index 5a9106c91..642269732 100644 --- a/renderdoc/driver/d3d12/d3d12_commands.cpp +++ b/renderdoc/driver/d3d12/d3d12_commands.cpp @@ -466,7 +466,7 @@ void WrappedID3D12CommandQueue::ReplayLog(LogState readType, uint32_t startEvent if(readType == READING) { - GetResourceManager()->ApplyInitialContents(); + m_pDevice->ApplyInitialContents(); m_pDevice->ExecuteLists(); m_pDevice->FlushLists(); diff --git a/renderdoc/driver/d3d12/d3d12_device.cpp b/renderdoc/driver/d3d12/d3d12_device.cpp index d273d6a3e..2afad61ca 100644 --- a/renderdoc/driver/d3d12/d3d12_device.cpp +++ b/renderdoc/driver/d3d12/d3d12_device.cpp @@ -529,6 +529,20 @@ HRESULT WrappedID3D12Device::QueryInterface(REFIID riid, void **ppvObject) return m_RefCounter.QueryInterface(riid, ppvObject); } +void WrappedID3D12Device::ApplyInitialContents() +{ + initStateCurBatch = 0; + initStateCurList = NULL; + + GetResourceManager()->ApplyInitialContents(); + + // close the final list + initStateCurList->Close(); + + initStateCurBatch = 0; + initStateCurList = NULL; +} + void WrappedID3D12Device::CheckForDeath() { if(!m_Alive) @@ -1145,8 +1159,18 @@ void WrappedID3D12Device::StartFrameCapture(void *dev, void *wnd) // and go into the frame record. { SCOPED_LOCK(m_CapTransitionLock); + + initStateCurBatch = 0; + initStateCurList = NULL; + GetResourceManager()->PrepareInitialContents(); + // close the final list + initStateCurList->Close(); + + initStateCurBatch = 0; + initStateCurList = NULL; + ExecuteLists(); FlushLists(); @@ -1925,6 +1949,26 @@ ID3D12GraphicsCommandList *WrappedID3D12Device::GetNewList() return ret; } +ID3D12GraphicsCommandList *WrappedID3D12Device::GetInitialStateList() +{ + if(initStateCurBatch >= initialStateMaxBatch) + { + CloseInitialStateList(); + } + + if(initStateCurList == NULL) + initStateCurList = GetNewList(); + + return initStateCurList; +} + +void WrappedID3D12Device::CloseInitialStateList() +{ + initStateCurList->Close(); + initStateCurList = NULL; + initStateCurBatch = 0; +} + void WrappedID3D12Device::ExecuteList(ID3D12GraphicsCommandList *list, ID3D12CommandQueue *queue) { if(queue == NULL) @@ -2119,7 +2163,7 @@ void WrappedID3D12Device::ReadLogInitialisation() { frameOffset = offset; - GetResourceManager()->ApplyInitialContents(); + ApplyInitialContents(); m_Queue->ReplayLog(READING, 0, 0, false); } @@ -2216,7 +2260,7 @@ void WrappedID3D12Device::ReplayLog(uint32_t startEventID, uint32_t endEventID, if(!partial) { - GetResourceManager()->ApplyInitialContents(); + ApplyInitialContents(); GetResourceManager()->ReleaseInFrameResources(); ExecuteLists(); diff --git a/renderdoc/driver/d3d12/d3d12_device.h b/renderdoc/driver/d3d12/d3d12_device.h index 4bb35c08b..5ad661654 100644 --- a/renderdoc/driver/d3d12/d3d12_device.h +++ b/renderdoc/driver/d3d12/d3d12_device.h @@ -416,7 +416,17 @@ public: // -> FlushLists()--------back to freecmds--------^ } m_InternalCmds; + // batch this many initial state lists together. Balance between + // creating fewer temporary lists and making too bloated lists + static const int initialStateMaxBatch = 100; + int initStateCurBatch; + ID3D12GraphicsCommandList *initStateCurList; + ID3D12GraphicsCommandList *GetNewList(); + ID3D12GraphicsCommandList *GetInitialStateList(); + void CloseInitialStateList(); + void ApplyInitialContents(); + void ExecuteList(ID3D12GraphicsCommandList *list, ID3D12CommandQueue *queue = NULL); void ExecuteLists(ID3D12CommandQueue *queue = NULL); void FlushLists(bool forceSync = false, ID3D12CommandQueue *queue = NULL); diff --git a/renderdoc/driver/d3d12/d3d12_manager.cpp b/renderdoc/driver/d3d12/d3d12_manager.cpp index 033dbc440..a56fd44e8 100644 --- a/renderdoc/driver/d3d12/d3d12_manager.cpp +++ b/renderdoc/driver/d3d12/d3d12_manager.cpp @@ -703,11 +703,9 @@ bool D3D12ResourceManager::Prepare_InitialState(ID3D12DeviceChild *res) if(SUCCEEDED(hr)) { - ID3D12GraphicsCommandList *list = Unwrap(m_Device->GetNewList()); + ID3D12GraphicsCommandList *list = Unwrap(m_Device->GetInitialStateList()); list->CopyResource(copyDst, r->GetReal()); - - list->Close(); } else { @@ -716,6 +714,8 @@ bool D3D12ResourceManager::Prepare_InitialState(ID3D12DeviceChild *res) if(nonresident) { + m_Device->CloseInitialStateList(); + m_Device->ExecuteLists(); m_Device->FlushLists(); @@ -768,7 +768,7 @@ bool D3D12ResourceManager::Prepare_InitialState(ID3D12DeviceChild *res) if(SUCCEEDED(hr)) { - ID3D12GraphicsCommandList *list = Unwrap(m_Device->GetNewList()); + ID3D12GraphicsCommandList *list = Unwrap(m_Device->GetInitialStateList()); vector barriers; @@ -817,8 +817,6 @@ bool D3D12ResourceManager::Prepare_InitialState(ID3D12DeviceChild *res) if(!barriers.empty()) list->ResourceBarrier((UINT)barriers.size(), &barriers[0]); - - list->Close(); } else { @@ -827,6 +825,8 @@ bool D3D12ResourceManager::Prepare_InitialState(ID3D12DeviceChild *res) if(nonresident) { + m_Device->CloseInitialStateList(); + m_Device->ExecuteLists(); m_Device->FlushLists(); @@ -1185,7 +1185,7 @@ void D3D12ResourceManager::Apply_InitialState(ID3D12DeviceChild *live, InitialCo } else { - ID3D12GraphicsCommandList *list = Unwrap(m_Device->GetNewList()); + ID3D12GraphicsCommandList *list = Unwrap(m_Device->GetInitialStateList()); vector barriers; @@ -1255,8 +1255,6 @@ void D3D12ResourceManager::Apply_InitialState(ID3D12DeviceChild *live, InitialCo if(!barriers.empty()) list->ResourceBarrier((UINT)barriers.size(), &barriers[0]); - list->Close(); - #if ENABLED(SINGLE_FLUSH_VALIDATE) m_Device->ExecuteLists(); m_Device->FlushLists(true);