From 8fbf7ede1b2047bc2d5c5bf7316f807d5bbd945f Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 26 Oct 2016 08:56:41 +0200 Subject: [PATCH] Make a cracked allocator per real allocator, for threaded recording * Threaded recording means the recording chunks are all interleaved in the log so we may be cracking multiple command lists at the same time and so need multiple allocators. Since the original capture obeyed the rule of only recording to one list from an allocator at once, making a cracked allocator for each also obeys that rule. --- .../driver/d3d12/d3d12_command_list_wrap.cpp | 20 +++++++++---------- renderdoc/driver/d3d12/d3d12_commands.cpp | 2 -- renderdoc/driver/d3d12/d3d12_commands.h | 3 ++- renderdoc/driver/d3d12/d3d12_device.cpp | 6 ++---- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp index 6ddf91ddf..c1ad81cbb 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp @@ -254,15 +254,16 @@ bool WrappedID3D12GraphicsCommandList::Serialise_Reset(ID3D12CommandAllocator *p m_Cmd->m_BakedCmdListInfo[CommandList].draw = draw; { - if(m_Cmd->m_CrackedAllocators[type] == NULL) + if(m_Cmd->m_CrackedAllocators[Allocator] == NULL) { - HRESULT hr = m_pDevice->CreateCommandAllocator( - type, __uuidof(ID3D12CommandAllocator), (void **)&m_Cmd->m_CrackedAllocators[type]); + HRESULT hr = + m_pDevice->CreateCommandAllocator(type, __uuidof(ID3D12CommandAllocator), + (void **)&m_Cmd->m_CrackedAllocators[Allocator]); RDCASSERTEQUAL(hr, S_OK); } ID3D12GraphicsCommandList *list = NULL; - m_pDevice->CreateCommandList(nodeMask, type, m_Cmd->m_CrackedAllocators[type], + m_pDevice->CreateCommandList(nodeMask, type, m_Cmd->m_CrackedAllocators[Allocator], pInitialState, riid, (void **)&list); RDCASSERT(m_Cmd->m_BakedCmdListInfo[CommandList].crackedLists.empty()); @@ -271,6 +272,7 @@ bool WrappedID3D12GraphicsCommandList::Serialise_Reset(ID3D12CommandAllocator *p m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].type = type; m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].nodeMask = nodeMask; + m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].allocator = Allocator; // On list execute we increment all child events/drawcalls by // m_RootEventID and insert them into the tree. @@ -3736,15 +3738,11 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ExecuteIndirect( D3D12_COMMAND_LIST_TYPE type = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].type; UINT nodeMask = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].nodeMask; - if(m_Cmd->m_CrackedAllocators[type] == NULL) - { - HRESULT hr = m_pDevice->CreateCommandAllocator(type, __uuidof(ID3D12CommandAllocator), - (void **)&m_Cmd->m_CrackedAllocators[type]); - RDCASSERTEQUAL(hr, S_OK); - } + ResourceId allocid = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].allocator; + ID3D12CommandAllocator *allocator = m_Cmd->m_CrackedAllocators[allocid]; ID3D12GraphicsCommandList *list = NULL; - m_pDevice->CreateCommandList(nodeMask, type, m_Cmd->m_CrackedAllocators[type], NULL, + m_pDevice->CreateCommandList(nodeMask, type, allocator, NULL, __uuidof(ID3D12GraphicsCommandList), (void **)&list); m_Cmd->m_BakedCmdListInfo[CommandList].crackedLists.push_back(list); diff --git a/renderdoc/driver/d3d12/d3d12_commands.cpp b/renderdoc/driver/d3d12/d3d12_commands.cpp index 37bcdb08d..4b76ef814 100644 --- a/renderdoc/driver/d3d12/d3d12_commands.cpp +++ b/renderdoc/driver/d3d12/d3d12_commands.cpp @@ -749,8 +749,6 @@ D3D12CommandData::D3D12CommandData() m_FirstEventID = 0; m_LastEventID = ~0U; - RDCEraseEl(m_CrackedAllocators); - m_pDevice = NULL; m_pSerialiser = NULL; diff --git a/renderdoc/driver/d3d12/d3d12_commands.h b/renderdoc/driver/d3d12/d3d12_commands.h index 1d5aa023a..2ccbebf14 100644 --- a/renderdoc/driver/d3d12/d3d12_commands.h +++ b/renderdoc/driver/d3d12/d3d12_commands.h @@ -183,6 +183,7 @@ struct BakedCmdListInfo vector > resourceUsage; + ResourceId allocator; D3D12_COMMAND_LIST_TYPE type; UINT nodeMask; D3D12RenderState state; @@ -210,7 +211,7 @@ struct D3D12CommandData ResourceId m_LastCmdListID; - ID3D12CommandAllocator *m_CrackedAllocators[4]; + map m_CrackedAllocators; vector m_IndirectBuffers; static const uint64_t m_IndirectSize = 4 * 1024 * 1024; diff --git a/renderdoc/driver/d3d12/d3d12_device.cpp b/renderdoc/driver/d3d12/d3d12_device.cpp index 090a3e353..1d57bafad 100644 --- a/renderdoc/driver/d3d12/d3d12_device.cpp +++ b/renderdoc/driver/d3d12/d3d12_device.cpp @@ -2069,10 +2069,8 @@ void WrappedID3D12Device::ReadLogInitialisation() it->second.crackedLists.clear(); } - SAFE_RELEASE(cmd.m_CrackedAllocators[D3D12_COMMAND_LIST_TYPE_DIRECT]); - SAFE_RELEASE(cmd.m_CrackedAllocators[D3D12_COMMAND_LIST_TYPE_BUNDLE]); - SAFE_RELEASE(cmd.m_CrackedAllocators[D3D12_COMMAND_LIST_TYPE_COMPUTE]); - SAFE_RELEASE(cmd.m_CrackedAllocators[D3D12_COMMAND_LIST_TYPE_COPY]); + for(auto it = cmd.m_CrackedAllocators.begin(); it != cmd.m_CrackedAllocators.end(); it++) + SAFE_RELEASE(it->second); } #if !defined(RELEASE)