From 3aa8398ec27eb35a76bb25d8a3f0ae60f67ec952 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 30 Oct 2017 17:47:46 +0000 Subject: [PATCH] Update D3D12 command list wrapping code to new serialisation --- renderdoc/driver/d3d12/d3d12_command_list.h | 11 +- .../driver/d3d12/d3d12_command_list_wrap.cpp | 4737 +++++++++-------- renderdoc/driver/d3d12/d3d12_commands.cpp | 22 +- renderdoc/driver/d3d12/d3d12_commands.h | 57 +- renderdoc/driver/d3d12/d3d12_debug.cpp | 44 +- renderdoc/driver/d3d12/d3d12_replay.cpp | 20 +- renderdoc/driver/d3d12/d3d12_state.cpp | 25 +- renderdoc/driver/d3d12/d3d12_state.h | 4 +- 8 files changed, 2435 insertions(+), 2485 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_command_list.h b/renderdoc/driver/d3d12/d3d12_command_list.h index dc918951c..cd1dbb01c 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list.h +++ b/renderdoc/driver/d3d12/d3d12_command_list.h @@ -123,10 +123,8 @@ public: ID3D12GraphicsCommandList *GetReal() { return m_pReal; } WrappedID3D12Device *GetWrappedDevice() { return m_pDevice; } D3D12ResourceRecord *GetResourceRecord() { return m_ListRecord; } - ID3D12GraphicsCommandList *GetList(ResourceId id); - ID3D12GraphicsCommandList *GetWrappedList(ResourceId id); - ID3D12GraphicsCommandList *GetCrackedList(ResourceId id); - ID3D12GraphicsCommandList *GetWrappedCrackedList(ResourceId id); + ID3D12GraphicsCommandList *GetCrackedList(); + ID3D12GraphicsCommandList *GetWrappedCrackedList(); void SetAMDMarkerInterface(IAmdExtD3DCommandListMarker *marker) { m_AMDMarkers = marker; } void SetCommandData(D3D12CommandData *cmd) { m_Cmd = cmd; } @@ -137,7 +135,7 @@ public: m_Init.type = type; } - bool ValidateRootGPUVA(ResourceId buffer); + bool ValidateRootGPUVA(D3D12_GPU_VIRTUAL_ADDRESS buffer); ////////////////////////////// // implement IUnknown @@ -376,7 +374,8 @@ public: IMPLEMENT_FUNCTION_SERIALISED(virtual void STDMETHODCALLTYPE, EndEvent, ); - void ReserveExecuteIndirect(ID3D12GraphicsCommandList *list, ResourceId sig, UINT maxCount); + void ReserveExecuteIndirect(ID3D12GraphicsCommandList *list, + WrappedID3D12CommandSignature *comSig, UINT maxCount); void PatchExecuteIndirect(BakedCmdListInfo &info, uint32_t executeIndex); void ReplayExecuteIndirect(ID3D12GraphicsCommandList *list, BakedCmdListInfo &info); diff --git a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp index d134db467..080ce9f31 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp @@ -23,104 +23,104 @@ ******************************************************************************/ #include "d3d12_command_list.h" +#include "driver/dxgi/dxgi_common.h" #include "driver/ihv/amd/official/DXExt/AmdExtD3DCommandListMarkerApi.h" #include "d3d12_command_queue.h" -ID3D12GraphicsCommandList *WrappedID3D12GraphicsCommandList::GetList(ResourceId id) +#define CACHE_THREAD_SERIALISER() WriteSerialiser &ser = m_pDevice->GetThreadSerialiser(); + +ID3D12GraphicsCommandList *WrappedID3D12GraphicsCommandList::GetCrackedList() { - return GetResourceManager()->GetLiveAs(id)->GetReal(); + return Unwrap(m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].crackedLists.back()); } -ID3D12GraphicsCommandList *WrappedID3D12GraphicsCommandList::GetWrappedList(ResourceId id) +ID3D12GraphicsCommandList *WrappedID3D12GraphicsCommandList::GetWrappedCrackedList() { - return GetResourceManager()->GetLiveAs(id); + return m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].crackedLists.back(); } -ID3D12GraphicsCommandList *WrappedID3D12GraphicsCommandList::GetCrackedList(ResourceId id) +template +bool WrappedID3D12GraphicsCommandList::Serialise_Close(SerialiserType &ser) { - return Unwrap(m_Cmd->m_BakedCmdListInfo[id].crackedLists.back()); -} + ResourceId BakedCommandList; -ID3D12GraphicsCommandList *WrappedID3D12GraphicsCommandList::GetWrappedCrackedList(ResourceId id) -{ - return m_Cmd->m_BakedCmdListInfo[id].crackedLists.back(); -} - -bool WrappedID3D12GraphicsCommandList::Serialise_Close() -{ - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - - ResourceId bakedCmdId; - - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - D3D12ResourceRecord *record = GetResourceManager()->GetResourceRecord(CommandList); + D3D12ResourceRecord *record = m_ListRecord; RDCASSERT(record->bakedCommands); if(record->bakedCommands) - bakedCmdId = record->bakedCommands->GetResourceID(); + BakedCommandList = record->bakedCommands->GetResourceID(); } - SERIALISE_ELEMENT(ResourceId, bakeId, bakedCmdId); + SERIALISE_ELEMENT_LOCAL(CommandList, GetResourceID()); + SERIALISE_ELEMENT(BakedCommandList); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList)) + m_Cmd->m_LastCmdListID = BakedCommandList; + + if(IsActiveReplaying(m_State)) { - ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(CommandList); + if(m_Cmd->ShouldRerecordCmd(BakedCommandList)) + { + ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(BakedCommandList); #if ENABLED(VERBOSE_PARTIAL_REPLAY) - RDCDEBUG("Ending partial command list for %llu baked to %llu", CommandList, bakeId); + RDCDEBUG("Ending partial command list for %llu baked to %llu", CommandList, BakedCommandList); #endif - int &markerCount = m_Cmd->m_BakedCmdListInfo[CommandList].markerCount; + int &markerCount = m_Cmd->m_BakedCmdListInfo[BakedCommandList].markerCount; - for(int i = 0; i < markerCount; i++) - D3D12MarkerRegion::End(list); + for(int i = 0; i < markerCount; i++) + D3D12MarkerRegion::End(list); - list->Close(); + list->Close(); - // erase the non-baked reference to this command list so that we don't have - // duplicates when it comes time to clean up. See below in in Reset() - m_Cmd->m_RerecordCmds.erase(CommandList); + // erase the non-baked reference to this command list so that we don't have + // duplicates when it comes time to clean up. See below in in Reset() + m_Cmd->m_RerecordCmds.erase(CommandList); - if(m_Cmd->m_Partial[D3D12CommandData::Primary].partialParent == CommandList) - m_Cmd->m_Partial[D3D12CommandData::Primary].partialParent = ResourceId(); + if(m_Cmd->m_Partial[D3D12CommandData::Primary].partialParent == CommandList) + m_Cmd->m_Partial[D3D12CommandData::Primary].partialParent = ResourceId(); + } + + m_Cmd->m_BakedCmdListInfo[CommandList].curEventID = 0; } - - m_Cmd->m_BakedCmdListInfo[CommandList].curEventID = 0; - } - else if(m_State == READING) - { - ID3D12GraphicsCommandList *list = GetList(CommandList); - - GetResourceManager()->RemoveReplacement(CommandList); - - list->Close(); - - if(!m_Cmd->m_BakedCmdListInfo[CommandList].crackedLists.empty()) + else { - GetCrackedList(CommandList)->Close(); + GetResourceManager()->GetLiveAs(CommandList)->Close(); + + if(!m_Cmd->m_BakedCmdListInfo[BakedCommandList].crackedLists.empty()) + { + GetCrackedList()->Close(); + } + + if(!m_Cmd->m_BakedCmdListInfo[BakedCommandList].curEvents.empty()) + { + DrawcallDescription draw; + draw.name = "API Calls"; + draw.flags |= DrawFlags::SetMarker | DrawFlags::APICalls; + + m_Cmd->AddDrawcall(draw, true); + + m_Cmd->m_BakedCmdListInfo[BakedCommandList].curEventID++; + } + + { + if(m_Cmd->GetDrawcallStack().size() > 1) + m_Cmd->GetDrawcallStack().pop_back(); + } + + BakedCmdListInfo &baked = m_Cmd->m_BakedCmdListInfo[BakedCommandList]; + BakedCmdListInfo &parent = m_Cmd->m_BakedCmdListInfo[CommandList]; + + baked.eventCount = baked.curEventID; + baked.curEventID = 0; + baked.parentList = CommandList; + + parent.curEventID = 0; + parent.eventCount = 0; + parent.drawCount = 0; } - - if(!m_Cmd->m_BakedCmdListInfo[CommandList].curEvents.empty()) - { - DrawcallDescription draw; - draw.name = "API Calls"; - draw.flags |= DrawFlags::SetMarker | DrawFlags::APICalls; - - m_Cmd->AddDrawcall(draw, true); - - m_Cmd->m_BakedCmdListInfo[CommandList].curEventID++; - } - - { - if(m_Cmd->GetDrawcallStack().size() > 1) - m_Cmd->GetDrawcallStack().pop_back(); - } - - m_Cmd->m_BakedCmdListInfo[bakeId].BakeFrom(CommandList, m_Cmd->m_BakedCmdListInfo[CommandList]); } return true; @@ -128,11 +128,13 @@ bool WrappedID3D12GraphicsCommandList::Serialise_Close() HRESULT WrappedID3D12GraphicsCommandList::Close() { - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { { - SCOPED_SERIALISE_CONTEXT(CLOSE_LIST); - Serialise_Close(); + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_Close); + Serialise_Close(ser); m_ListRecord->AddChunk(scope.Get()); } @@ -143,162 +145,175 @@ HRESULT WrappedID3D12GraphicsCommandList::Close() return m_pReal->Close(); } -bool WrappedID3D12GraphicsCommandList::Serialise_Reset(ID3D12CommandAllocator *pAllocator, +template +bool WrappedID3D12GraphicsCommandList::Serialise_Reset(SerialiserType &ser, + ID3D12CommandAllocator *pAllocator, ID3D12PipelineState *pInitialState) { // parameters to create the list with if needed - SERIALISE_ELEMENT(IID, riid, m_Init.riid); - SERIALISE_ELEMENT(UINT, nodeMask, m_Init.nodeMask); - SERIALISE_ELEMENT(D3D12_COMMAND_LIST_TYPE, type, m_Init.type); + SERIALISE_ELEMENT_LOCAL(riid, m_Init.riid); + SERIALISE_ELEMENT_LOCAL(nodeMask, m_Init.nodeMask); + SERIALISE_ELEMENT_LOCAL(type, m_Init.type); - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(ResourceId, Allocator, GetResID(pAllocator)); - SERIALISE_ELEMENT(ResourceId, State, GetResID(pInitialState)); + ResourceId BakedCommandList; - ResourceId bakedCmdId; - - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - D3D12ResourceRecord *record = GetResourceManager()->GetResourceRecord(CommandList); + D3D12ResourceRecord *record = m_ListRecord; RDCASSERT(record->bakedCommands); if(record->bakedCommands) - bakedCmdId = record->bakedCommands->GetResourceID(); + BakedCommandList = record->bakedCommands->GetResourceID(); } - SERIALISE_ELEMENT(ResourceId, bakeId, bakedCmdId); + SERIALISE_ELEMENT(BakedCommandList); + SERIALISE_ELEMENT_LOCAL(CommandList, GetResourceID()); + SERIALISE_ELEMENT(pAllocator); + SERIALISE_ELEMENT(pInitialState); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - const uint32_t length = m_Cmd->m_BakedCmdListInfo[bakeId].eventCount; + m_Cmd->m_LastCmdListID = BakedCommandList; - bool partial = false; - int partialType = D3D12CommandData::ePartialNum; - - // check for partial execution of this command list - for(int p = 0; p < D3D12CommandData::ePartialNum; p++) + if(IsActiveReplaying(m_State)) { - const vector &baseEvents = m_Cmd->m_Partial[p].cmdListExecs[bakeId]; + const uint32_t length = m_Cmd->m_BakedCmdListInfo[BakedCommandList].eventCount; - for(auto it = baseEvents.begin(); it != baseEvents.end(); ++it) + bool partial = false; + int partialType = D3D12CommandData::ePartialNum; + + // check for partial execution of this command list + for(int p = 0; p < D3D12CommandData::ePartialNum; p++) { - if(*it <= m_Cmd->m_LastEventID && m_Cmd->m_LastEventID < (*it + length)) + const std::vector &baseEvents = m_Cmd->m_Partial[p].cmdListExecs[BakedCommandList]; + + for(auto it = baseEvents.begin(); it != baseEvents.end(); ++it) { + if(*it <= m_Cmd->m_LastEventID && m_Cmd->m_LastEventID < (*it + length)) + { #if ENABLED(VERBOSE_PARTIAL_REPLAY) - RDCDEBUG("Reset - partial detected %u < %u < %u, %llu -> %llu", *it, m_Cmd->m_LastEventID, - *it + length, CommandList, bakeId); + RDCDEBUG("Reset - partial detected %u < %u < %u, %llu -> %llu", *it, + m_Cmd->m_LastEventID, *it + length, CommandList, BakedCommandList); #endif - m_Cmd->m_Partial[p].partialParent = CommandList; - m_Cmd->m_Partial[p].baseEvent = *it; + m_Cmd->m_Partial[p].partialParent = BakedCommandList; + m_Cmd->m_Partial[p].baseEvent = *it; - partial = true; - partialType = p; + partial = true; + partialType = p; + } } } - } - if(partial || (m_Cmd->m_DrawcallCallback && m_Cmd->m_DrawcallCallback->RecordAllCmds())) - { - pAllocator = GetResourceManager()->GetLiveAs(Allocator); - pInitialState = - State == ResourceId() ? NULL : GetResourceManager()->GetLiveAs(State); - - ID3D12GraphicsCommandList *list = NULL; - HRESULT hr = m_pDevice->CreateCommandList(nodeMask, type, pAllocator, pInitialState, riid, - (void **)&list); - - if(FAILED(hr)) - RDCERR("Failed on resource serialise-creation, hr: 0x%08x", hr); - - if(partial) + if(partial || (m_Cmd->m_DrawcallCallback && m_Cmd->m_DrawcallCallback->RecordAllCmds())) { - m_Cmd->m_Partial[partialType].resultPartialCmdList = list; + ID3D12GraphicsCommandList *list = NULL; + HRESULT hr = m_pDevice->CreateCommandList(nodeMask, type, pAllocator, pInitialState, riid, + (void **)&list); + + if(FAILED(hr)) + RDCERR("Failed on resource serialise-creation, hr: %s", ToStr(hr).c_str()); + + if(partial) + { + m_Cmd->m_Partial[partialType].resultPartialCmdList = list; + } + else + { + // we store under both baked and non baked ID. + // The baked ID is the 'real' entry, the non baked is simply so it + // can be found in the subsequent serialised commands that ref the + // non-baked ID. The baked ID is referenced by the submit itself. + // + // In Close() we erase the non-baked reference, and since + // we know you can only be recording a command list once at a time + // (even if it's baked to several command listsin the frame) + // there's no issue with clashes here. + m_Cmd->m_RerecordCmds[BakedCommandList] = list; + m_Cmd->m_RerecordCmds[CommandList] = list; + } + + m_Cmd->m_RenderState.pipe = GetResID(pInitialState); } - else - { - // we store under both baked and non baked ID. - // The baked ID is the 'real' entry, the non baked is simply so it - // can be found in the subsequent serialised commands that ref the - // non-baked ID. The baked ID is referenced by the submit itself. - // - // In Close() we erase the non-baked reference, and since - // we know you can only be recording a command list once at a time - // (even if it's baked to several command listsin the frame) - // there's no issue with clashes here. - m_Cmd->m_RerecordCmds[bakeId] = list; - m_Cmd->m_RerecordCmds[CommandList] = list; - } - - m_Cmd->m_RenderState.pipe = GetResID(pInitialState); - } - - m_Cmd->m_BakedCmdListInfo[CommandList].markerCount = 0; - m_Cmd->m_BakedCmdListInfo[CommandList].curEventID = 0; - m_Cmd->m_BakedCmdListInfo[CommandList].executeEvents = - m_Cmd->m_BakedCmdListInfo[bakeId].executeEvents; - } - else if(m_State == READING) - { - pAllocator = GetResourceManager()->GetLiveAs(Allocator); - pInitialState = - State == ResourceId() ? NULL : GetResourceManager()->GetLiveAs(State); - - if(!GetResourceManager()->HasLiveResource(bakeId)) - { - ID3D12GraphicsCommandList *list = NULL; - m_pDevice->CreateCommandList(nodeMask, type, pAllocator, pInitialState, riid, (void **)&list); - - GetResourceManager()->AddLiveResource(bakeId, list); // whenever a command-building chunk asks for the command list, it // will get our baked version. - GetResourceManager()->ReplaceResource(CommandList, bakeId); + if(GetResourceManager()->HasReplacement(CommandList)) + GetResourceManager()->RemoveReplacement(CommandList); + + GetResourceManager()->ReplaceResource(CommandList, BakedCommandList); + + m_Cmd->m_BakedCmdListInfo[CommandList].markerCount = + m_Cmd->m_BakedCmdListInfo[BakedCommandList].markerCount = 0; + m_Cmd->m_BakedCmdListInfo[CommandList].curEventID = + m_Cmd->m_BakedCmdListInfo[BakedCommandList].curEventID = 0; + m_Cmd->m_BakedCmdListInfo[CommandList].executeEvents = + m_Cmd->m_BakedCmdListInfo[BakedCommandList].executeEvents; } else { - GetList(CommandList)->Reset(Unwrap(pAllocator), Unwrap(pInitialState)); - } - - { - D3D12DrawcallTreeNode *draw = new D3D12DrawcallTreeNode; - m_Cmd->m_BakedCmdListInfo[CommandList].draw = draw; - + if(!GetResourceManager()->HasLiveResource(BakedCommandList)) { - if(m_Cmd->m_CrackedAllocators[Allocator] == NULL) - { - 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[Allocator], - pInitialState, riid, (void **)&list); + m_pDevice->CreateCommandList(nodeMask, type, pAllocator, pInitialState, riid, (void **)&list); - RDCASSERT(m_Cmd->m_BakedCmdListInfo[CommandList].crackedLists.empty()); - m_Cmd->m_BakedCmdListInfo[CommandList].crackedLists.push_back(list); + GetResourceManager()->AddLiveResource(BakedCommandList, list); + + // whenever a command-building chunk asks for the command list, it + // will get our baked version. + if(GetResourceManager()->HasReplacement(CommandList)) + GetResourceManager()->RemoveReplacement(CommandList); + + GetResourceManager()->ReplaceResource(CommandList, BakedCommandList); + } + else + { + ID3D12GraphicsCommandList *list = + GetResourceManager()->GetLiveAs(BakedCommandList)->GetReal(); + list->Reset(Unwrap(pAllocator), Unwrap(pInitialState)); } - 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; + { + D3D12DrawcallTreeNode *draw = new D3D12DrawcallTreeNode; + m_Cmd->m_BakedCmdListInfo[BakedCommandList].draw = draw; - // On list execute we increment all child events/drawcalls by - // m_RootEventID and insert them into the tree. - m_Cmd->m_BakedCmdListInfo[CommandList].curEventID = 0; - m_Cmd->m_BakedCmdListInfo[CommandList].eventCount = 0; - m_Cmd->m_BakedCmdListInfo[CommandList].drawCount = 0; + { + if(m_Cmd->m_CrackedAllocators[GetResID(pAllocator)] == NULL) + { + HRESULT hr = m_pDevice->CreateCommandAllocator( + type, __uuidof(ID3D12CommandAllocator), + (void **)&m_Cmd->m_CrackedAllocators[GetResID(pAllocator)]); + RDCASSERTEQUAL(hr, S_OK); + } - m_Cmd->m_BakedCmdListInfo[CommandList].drawStack.push_back(draw); + ID3D12GraphicsCommandList *list = NULL; + m_pDevice->CreateCommandList(nodeMask, type, + m_Cmd->m_CrackedAllocators[GetResID(pAllocator)], + pInitialState, riid, (void **)&list); - // reset state - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - state.m_ResourceManager = GetResourceManager(); - state.pipe = GetResID(pInitialState); + RDCASSERT(m_Cmd->m_BakedCmdListInfo[BakedCommandList].crackedLists.empty()); + m_Cmd->m_BakedCmdListInfo[BakedCommandList].crackedLists.push_back(list); + } + + m_Cmd->m_BakedCmdListInfo[CommandList].type = + m_Cmd->m_BakedCmdListInfo[BakedCommandList].type = type; + m_Cmd->m_BakedCmdListInfo[CommandList].nodeMask = + m_Cmd->m_BakedCmdListInfo[BakedCommandList].nodeMask = nodeMask; + m_Cmd->m_BakedCmdListInfo[CommandList].allocator = + m_Cmd->m_BakedCmdListInfo[BakedCommandList].allocator = GetResID(pAllocator); + + // On list execute we increment all child events/drawcalls by + // m_RootEventID and insert them into the tree. + m_Cmd->m_BakedCmdListInfo[BakedCommandList].curEventID = 0; + m_Cmd->m_BakedCmdListInfo[BakedCommandList].eventCount = 0; + m_Cmd->m_BakedCmdListInfo[BakedCommandList].drawCount = 0; + + m_Cmd->m_BakedCmdListInfo[BakedCommandList].drawStack.push_back(draw); + + // reset state + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[BakedCommandList].state; + state.m_ResourceManager = GetResourceManager(); + state.pipe = GetResID(pInitialState); + } } } @@ -308,7 +323,7 @@ bool WrappedID3D12GraphicsCommandList::Serialise_Reset(ID3D12CommandAllocator *p HRESULT WrappedID3D12GraphicsCommandList::Reset(ID3D12CommandAllocator *pAllocator, ID3D12PipelineState *pInitialState) { - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { bool firstTime = false; @@ -333,8 +348,9 @@ HRESULT WrappedID3D12GraphicsCommandList::Reset(ID3D12CommandAllocator *pAllocat m_ListRecord->bakedCommands->cmdInfo = new CmdListRecordingInfo(); { - SCOPED_SERIALISE_CONTEXT(RESET_LIST); - Serialise_Reset(pAllocator, pInitialState); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_Reset); + Serialise_Reset(ser, pAllocator, pInitialState); m_ListRecord->AddChunk(scope.Get()); } @@ -359,119 +375,85 @@ void WrappedID3D12GraphicsCommandList::ClearState(ID3D12PipelineState *pPipeline m_pReal->ClearState(Unwrap(pPipelineState)); } -bool WrappedID3D12GraphicsCommandList::Serialise_ResourceBarrier(UINT NumBarriers, - const D3D12_RESOURCE_BARRIER *pBarriers) +template +bool WrappedID3D12GraphicsCommandList::Serialise_ResourceBarrier( + SerialiserType &ser, UINT NumBarriers, const D3D12_RESOURCE_BARRIER *pBarriers) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, num, NumBarriers); - SERIALISE_ELEMENT_ARR(D3D12_RESOURCE_BARRIER, barriers, pBarriers, num); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT_ARRAY(pBarriers, NumBarriers); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - vector filtered; - if(m_State <= EXECUTING) + if(IsReplayingAndReading()) { - filtered.reserve(num); + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); - // non-transition barriers allow NULLs, but for transition barriers filter out any that - // reference the NULL resource - this means the resource wasn't used elsewhere so was discarded - // from the capture - for(UINT i = 0; i < num; i++) - if(barriers[i].Type != D3D12_RESOURCE_BARRIER_TYPE_TRANSITION || - barriers[i].Transition.pResource) - filtered.push_back(barriers[i]); - } - - if(m_State == EXECUTING) - { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + std::vector filtered; { - ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(CommandList); + filtered.reserve(NumBarriers); + // non-transition barriers allow NULLs, but for transition barriers filter out any that + // reference the NULL resource - this means the resource wasn't used elsewhere so was + // discarded from the capture + for(UINT i = 0; i < NumBarriers; i++) + { + if(pBarriers[i].Type != D3D12_RESOURCE_BARRIER_TYPE_TRANSITION || + pBarriers[i].Transition.pResource) + { + filtered.push_back(pBarriers[i]); + + // unwrap it + D3D12_RESOURCE_BARRIER &b = filtered.back(); + + if(b.Type == D3D12_RESOURCE_BARRIER_TYPE_TRANSITION) + { + b.Transition.pResource = Unwrap(b.Transition.pResource); + } + else if(b.Type == D3D12_RESOURCE_BARRIER_TYPE_ALIASING) + { + b.Aliasing.pResourceBefore = Unwrap(b.Aliasing.pResourceBefore); + b.Aliasing.pResourceAfter = Unwrap(b.Aliasing.pResourceAfter); + } + else if(b.Type == D3D12_RESOURCE_BARRIER_TYPE_UAV) + { + b.UAV.pResource = Unwrap(b.UAV.pResource); + } + } + } + } + + if(IsActiveReplaying(m_State)) + { + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + pCommandList = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + + if(!filtered.empty()) + Unwrap(pCommandList)->ResourceBarrier((UINT)filtered.size(), &filtered[0]); + } + else + { + pCommandList = NULL; + } + } + else + { if(!filtered.empty()) - Unwrap(list)->ResourceBarrier((UINT)filtered.size(), &filtered[0]); - - ResourceId cmd = GetResID(list); - - // need to re-wrap the barriers - for(UINT i = 0; i < num; i++) { - D3D12_RESOURCE_BARRIER b = barriers[i]; - - switch(b.Type) - { - case D3D12_RESOURCE_BARRIER_TYPE_TRANSITION: - { - b.Transition.pResource = - (ID3D12Resource *)GetResourceManager()->GetWrapper(b.Transition.pResource); - break; - } - case D3D12_RESOURCE_BARRIER_TYPE_ALIASING: - { - b.Aliasing.pResourceBefore = - (ID3D12Resource *)GetResourceManager()->GetWrapper(b.Aliasing.pResourceBefore); - b.Aliasing.pResourceAfter = - (ID3D12Resource *)GetResourceManager()->GetWrapper(b.Aliasing.pResourceAfter); - break; - } - case D3D12_RESOURCE_BARRIER_TYPE_UAV: - { - b.UAV.pResource = (ID3D12Resource *)GetResourceManager()->GetWrapper(b.UAV.pResource); - break; - } - } - - m_Cmd->m_BakedCmdListInfo[cmd].barriers.push_back(b); + Unwrap(pCommandList)->ResourceBarrier((UINT)filtered.size(), &filtered[0]); + GetCrackedList()->ResourceBarrier((UINT)filtered.size(), &filtered[0]); } } - } - else if(m_State == READING) - { - ID3D12GraphicsCommandList *list = GetList(CommandList); - if(!filtered.empty()) + if(pCommandList) { - list->ResourceBarrier((UINT)filtered.size(), &filtered[0]); - GetCrackedList(CommandList)->ResourceBarrier((UINT)filtered.size(), &filtered[0]); - } + ResourceId cmd = GetResID(pCommandList); - ResourceId cmd = GetResID(GetResourceManager()->GetWrapper(list)); - - // need to re-wrap the barriers - for(UINT i = 0; i < num; i++) - { - D3D12_RESOURCE_BARRIER b = barriers[i]; - - switch(b.Type) - { - case D3D12_RESOURCE_BARRIER_TYPE_TRANSITION: - { - b.Transition.pResource = - (ID3D12Resource *)GetResourceManager()->GetWrapper(b.Transition.pResource); - break; - } - case D3D12_RESOURCE_BARRIER_TYPE_ALIASING: - { - b.Aliasing.pResourceBefore = - (ID3D12Resource *)GetResourceManager()->GetWrapper(b.Aliasing.pResourceBefore); - b.Aliasing.pResourceAfter = - (ID3D12Resource *)GetResourceManager()->GetWrapper(b.Aliasing.pResourceAfter); - break; - } - case D3D12_RESOURCE_BARRIER_TYPE_UAV: - { - b.UAV.pResource = (ID3D12Resource *)GetResourceManager()->GetWrapper(b.UAV.pResource); - break; - } - } - - m_Cmd->m_BakedCmdListInfo[cmd].barriers.push_back(b); + for(UINT i = 0; i < NumBarriers; i++) + m_Cmd->m_BakedCmdListInfo[cmd].barriers.push_back(pBarriers[i]); } } - SAFE_DELETE_ARRAY(barriers); - return true; } @@ -501,10 +483,11 @@ void WrappedID3D12GraphicsCommandList::ResourceBarrier(UINT NumBarriers, m_pReal->ResourceBarrier(NumBarriers, barriers); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(RESOURCE_BARRIER); - Serialise_ResourceBarrier(NumBarriers, pBarriers); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_ResourceBarrier); + Serialise_ResourceBarrier(ser, NumBarriers, pBarriers); m_ListRecord->AddChunk(scope.Get()); @@ -515,30 +498,35 @@ void WrappedID3D12GraphicsCommandList::ResourceBarrier(UINT NumBarriers, #pragma region State Setting +template bool WrappedID3D12GraphicsCommandList::Serialise_IASetPrimitiveTopology( - D3D12_PRIMITIVE_TOPOLOGY PrimitiveTopology) + SerialiserType &ser, D3D12_PRIMITIVE_TOPOLOGY PrimitiveTopology) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(D3D12_PRIMITIVE_TOPOLOGY, topo, PrimitiveTopology); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(PrimitiveTopology); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList))->IASetPrimitiveTopology(topo); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->IASetPrimitiveTopology(PrimitiveTopology); - m_Cmd->m_RenderState.topo = topo; + m_Cmd->m_RenderState.topo = PrimitiveTopology; + } } - } - else if(m_State == READING) - { - m_Cmd->m_BakedCmdListInfo[CommandList].state.topo = topo; + else + { + m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state.topo = PrimitiveTopology; - GetList(CommandList)->IASetPrimitiveTopology(topo); - GetCrackedList(CommandList)->IASetPrimitiveTopology(topo); + Unwrap(pCommandList)->IASetPrimitiveTopology(PrimitiveTopology); + GetCrackedList()->IASetPrimitiveTopology(PrimitiveTopology); + } } return true; @@ -548,53 +536,57 @@ void WrappedID3D12GraphicsCommandList::IASetPrimitiveTopology(D3D12_PRIMITIVE_TO { m_pReal->IASetPrimitiveTopology(PrimitiveTopology); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_TOPOLOGY); - Serialise_IASetPrimitiveTopology(PrimitiveTopology); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_IASetPrimitiveTopology); + Serialise_IASetPrimitiveTopology(ser, PrimitiveTopology); m_ListRecord->AddChunk(scope.Get()); } } -bool WrappedID3D12GraphicsCommandList::Serialise_RSSetViewports(UINT NumViewports, +template +bool WrappedID3D12GraphicsCommandList::Serialise_RSSetViewports(SerialiserType &ser, + UINT NumViewports, const D3D12_VIEWPORT *pViewports) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, num, NumViewports); - SERIALISE_ELEMENT_ARR(D3D12_VIEWPORT, views, pViewports, num); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT_ARRAY(pViewports, NumViewports); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList))->RSSetViewports(num, views); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->RSSetViewports(NumViewports, pViewports); - if(m_Cmd->m_RenderState.views.size() < num) - m_Cmd->m_RenderState.views.resize(num); + if(m_Cmd->m_RenderState.views.size() < NumViewports) + m_Cmd->m_RenderState.views.resize(NumViewports); - for(UINT i = 0; i < num; i++) - m_Cmd->m_RenderState.views[i] = views[i]; + for(UINT i = 0; i < NumViewports; i++) + m_Cmd->m_RenderState.views[i] = pViewports[i]; + } + } + else + { + Unwrap(pCommandList)->RSSetViewports(NumViewports, pViewports); + GetCrackedList()->RSSetViewports(NumViewports, pViewports); + + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; + + if(state.views.size() < NumViewports) + state.views.resize(NumViewports); + + for(UINT i = 0; i < NumViewports; i++) + state.views[i] = pViewports[i]; } } - else if(m_State == READING) - { - GetList(CommandList)->RSSetViewports(num, views); - GetCrackedList(CommandList)->RSSetViewports(num, views); - - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - - if(state.views.size() < num) - state.views.resize(num); - - for(UINT i = 0; i < num; i++) - state.views[i] = views[i]; - } - - SAFE_DELETE_ARRAY(views); return true; } @@ -604,53 +596,56 @@ void WrappedID3D12GraphicsCommandList::RSSetViewports(UINT NumViewports, { m_pReal->RSSetViewports(NumViewports, pViewports); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_VIEWPORTS); - Serialise_RSSetViewports(NumViewports, pViewports); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_RSSetViewports); + Serialise_RSSetViewports(ser, NumViewports, pViewports); m_ListRecord->AddChunk(scope.Get()); } } -bool WrappedID3D12GraphicsCommandList::Serialise_RSSetScissorRects(UINT NumRects, +template +bool WrappedID3D12GraphicsCommandList::Serialise_RSSetScissorRects(SerialiserType &ser, UINT NumRects, const D3D12_RECT *pRects) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, num, NumRects); - SERIALISE_ELEMENT_ARR(D3D12_RECT, rects, pRects, num); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT_ARRAY(pRects, NumRects); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList))->RSSetScissorRects(num, rects); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->RSSetScissorRects(NumRects, pRects); - if(m_Cmd->m_RenderState.scissors.size() < num) - m_Cmd->m_RenderState.scissors.resize(num); + if(m_Cmd->m_RenderState.scissors.size() < NumRects) + m_Cmd->m_RenderState.scissors.resize(NumRects); - for(UINT i = 0; i < num; i++) - m_Cmd->m_RenderState.scissors[i] = rects[i]; + for(UINT i = 0; i < NumRects; i++) + m_Cmd->m_RenderState.scissors[i] = pRects[i]; + } + } + else + { + Unwrap(pCommandList)->RSSetScissorRects(NumRects, pRects); + GetCrackedList()->RSSetScissorRects(NumRects, pRects); + + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; + + if(state.scissors.size() < NumRects) + state.scissors.resize(NumRects); + + for(UINT i = 0; i < NumRects; i++) + state.scissors[i] = pRects[i]; } } - else if(m_State == READING) - { - GetList(CommandList)->RSSetScissorRects(num, rects); - GetCrackedList(CommandList)->RSSetScissorRects(num, rects); - - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - - if(state.scissors.size() < num) - state.scissors.resize(num); - - for(UINT i = 0; i < num; i++) - state.scissors[i] = rects[i]; - } - - SAFE_DELETE_ARRAY(rects); return true; } @@ -659,44 +654,46 @@ void WrappedID3D12GraphicsCommandList::RSSetScissorRects(UINT NumRects, const D3 { m_pReal->RSSetScissorRects(NumRects, pRects); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_SCISSORS); - Serialise_RSSetScissorRects(NumRects, pRects); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_RSSetScissorRects); + Serialise_RSSetScissorRects(ser, NumRects, pRects); m_ListRecord->AddChunk(scope.Get()); } } -bool WrappedID3D12GraphicsCommandList::Serialise_OMSetBlendFactor(const FLOAT BlendFactor[4]) +template +bool WrappedID3D12GraphicsCommandList::Serialise_OMSetBlendFactor(SerialiserType &ser, + const FLOAT BlendFactor[4]) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT_ARRAY(BlendFactor, FIXED_COUNT(4)); - float factor[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - - if(m_State >= WRITING && BlendFactor) - memcpy(factor, BlendFactor, sizeof(float) * 4); - - m_pSerialiser->SerialisePODArray<4>("BlendFactor", factor); - - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList))->OMSetBlendFactor(factor); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->OMSetBlendFactor(BlendFactor); - memcpy(m_Cmd->m_RenderState.blendFactor, factor, sizeof(factor)); + memcpy(m_Cmd->m_RenderState.blendFactor, BlendFactor, sizeof(float) * 4); + } } - } - else if(m_State == READING) - { - GetList(CommandList)->OMSetBlendFactor(factor); - GetCrackedList(CommandList)->OMSetBlendFactor(factor); + else + { + Unwrap(pCommandList)->OMSetBlendFactor(BlendFactor); + GetCrackedList()->OMSetBlendFactor(BlendFactor); - memcpy(m_Cmd->m_BakedCmdListInfo[CommandList].state.blendFactor, factor, sizeof(factor)); + memcpy(m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state.blendFactor, BlendFactor, + sizeof(float) * 4); + } } return true; @@ -706,38 +703,44 @@ void WrappedID3D12GraphicsCommandList::OMSetBlendFactor(const FLOAT BlendFactor[ { m_pReal->OMSetBlendFactor(BlendFactor); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_BLENDFACTOR); - Serialise_OMSetBlendFactor(BlendFactor); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_OMSetBlendFactor); + Serialise_OMSetBlendFactor(ser, BlendFactor); m_ListRecord->AddChunk(scope.Get()); } } -bool WrappedID3D12GraphicsCommandList::Serialise_OMSetStencilRef(UINT StencilRef) +template +bool WrappedID3D12GraphicsCommandList::Serialise_OMSetStencilRef(SerialiserType &ser, UINT StencilRef) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, ref, StencilRef); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(StencilRef); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList))->OMSetStencilRef(ref); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->OMSetStencilRef(StencilRef); - m_Cmd->m_RenderState.stencilRef = ref; + m_Cmd->m_RenderState.stencilRef = StencilRef; + } } - } - else if(m_State == READING) - { - GetList(CommandList)->OMSetStencilRef(ref); - GetCrackedList(CommandList)->OMSetStencilRef(ref); + else + { + Unwrap(pCommandList)->OMSetStencilRef(StencilRef); + GetCrackedList()->OMSetStencilRef(StencilRef); - m_Cmd->m_BakedCmdListInfo[CommandList].state.stencilRef = ref; + m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state.stencilRef = StencilRef; + } } return true; @@ -747,66 +750,63 @@ void WrappedID3D12GraphicsCommandList::OMSetStencilRef(UINT StencilRef) { m_pReal->OMSetStencilRef(StencilRef); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_STENCIL); - Serialise_OMSetStencilRef(StencilRef); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_OMSetStencilRef); + Serialise_OMSetStencilRef(ser, StencilRef); m_ListRecord->AddChunk(scope.Get()); } } +template bool WrappedID3D12GraphicsCommandList::Serialise_SetDescriptorHeaps( - UINT NumDescriptorHeaps, ID3D12DescriptorHeap *const *ppDescriptorHeaps) + SerialiserType &ser, UINT NumDescriptorHeaps, ID3D12DescriptorHeap *const *ppDescriptorHeaps) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT_ARRAY(ppDescriptorHeaps, NumDescriptorHeaps); - std::vector DescriptorHeaps; - - if(m_State >= WRITING) + if(IsReplayingAndReading()) { - DescriptorHeaps.resize(NumDescriptorHeaps); - for(UINT i = 0; i < NumDescriptorHeaps; i++) - DescriptorHeaps[i] = GetResID(ppDescriptorHeaps[i]); - } + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); - m_pSerialiser->Serialise("DescriptorHeaps", DescriptorHeaps); + if(IsActiveReplaying(m_State)) + { + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + std::vector heaps; + heaps.resize(NumDescriptorHeaps); + for(size_t i = 0; i < heaps.size(); i++) + heaps[i] = Unwrap(ppDescriptorHeaps[i]); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->SetDescriptorHeaps(NumDescriptorHeaps, heaps.data()); - if(m_State == EXECUTING) - { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_RenderState.heaps.resize(heaps.size()); + for(size_t i = 0; i < heaps.size(); i++) + m_Cmd->m_RenderState.heaps[i] = GetResID(ppDescriptorHeaps[i]); + } + } + else { std::vector heaps; - heaps.resize(DescriptorHeaps.size()); + heaps.resize(NumDescriptorHeaps); for(size_t i = 0; i < heaps.size(); i++) - heaps[i] = Unwrap(GetResourceManager()->GetLiveAs(DescriptorHeaps[i])); + heaps[i] = Unwrap(ppDescriptorHeaps[i]); - Unwrap(m_Cmd->RerecordCmdList(CommandList))->SetDescriptorHeaps((UINT)heaps.size(), &heaps[0]); + Unwrap(pCommandList)->SetDescriptorHeaps(NumDescriptorHeaps, heaps.data()); + GetCrackedList()->SetDescriptorHeaps(NumDescriptorHeaps, heaps.data()); - m_Cmd->m_RenderState.heaps.resize(heaps.size()); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; + + state.heaps.resize(heaps.size()); for(size_t i = 0; i < heaps.size(); i++) - m_Cmd->m_RenderState.heaps[i] = GetResourceManager()->GetLiveID(DescriptorHeaps[i]); + state.heaps[i] = GetResID(ppDescriptorHeaps[i]); } } - else if(m_State == READING) - { - std::vector heaps; - heaps.resize(DescriptorHeaps.size()); - for(size_t i = 0; i < heaps.size(); i++) - heaps[i] = Unwrap(GetResourceManager()->GetLiveAs(DescriptorHeaps[i])); - - GetList(CommandList)->SetDescriptorHeaps((UINT)heaps.size(), &heaps[0]); - GetCrackedList(CommandList)->SetDescriptorHeaps((UINT)heaps.size(), &heaps[0]); - - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - - state.heaps.resize(heaps.size()); - for(size_t i = 0; i < heaps.size(); i++) - state.heaps[i] = GetResourceManager()->GetLiveID(DescriptorHeaps[i]); - } return true; } @@ -820,10 +820,11 @@ void WrappedID3D12GraphicsCommandList::SetDescriptorHeaps(UINT NumDescriptorHeap m_pReal->SetDescriptorHeaps(NumDescriptorHeaps, heaps); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_DESC_HEAPS); - Serialise_SetDescriptorHeaps(NumDescriptorHeaps, ppDescriptorHeaps); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetDescriptorHeaps); + Serialise_SetDescriptorHeaps(ser, NumDescriptorHeaps, ppDescriptorHeaps); m_ListRecord->AddChunk(scope.Get()); for(UINT i = 0; i < NumDescriptorHeaps; i++) @@ -831,64 +832,65 @@ void WrappedID3D12GraphicsCommandList::SetDescriptorHeaps(UINT NumDescriptorHeap } } -bool WrappedID3D12GraphicsCommandList::Serialise_IASetIndexBuffer(const D3D12_INDEX_BUFFER_VIEW *pView) +template +bool WrappedID3D12GraphicsCommandList::Serialise_IASetIndexBuffer(SerialiserType &ser, + const D3D12_INDEX_BUFFER_VIEW *pView) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(bool, HasView, pView != NULL); - SERIALISE_ELEMENT_OPT(D3D12_INDEX_BUFFER_VIEW, view, *pView, HasView); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT_OPT(pView); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(CommandList); - - if(HasView) + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - Unwrap(list)->IASetIndexBuffer(&view); + ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); - WrappedID3D12Resource::GetResIDFromAddr( - view.BufferLocation, m_Cmd->m_RenderState.ibuffer.buf, m_Cmd->m_RenderState.ibuffer.offs); - m_Cmd->m_RenderState.ibuffer.bytewidth = (view.Format == DXGI_FORMAT_R32_UINT ? 4 : 2); - m_Cmd->m_RenderState.ibuffer.size = view.SizeInBytes; + Unwrap(list)->IASetIndexBuffer(pView); + + if(pView) + { + WrappedID3D12Resource::GetResIDFromAddr(pView->BufferLocation, + m_Cmd->m_RenderState.ibuffer.buf, + m_Cmd->m_RenderState.ibuffer.offs); + m_Cmd->m_RenderState.ibuffer.bytewidth = (pView->Format == DXGI_FORMAT_R32_UINT ? 4 : 2); + m_Cmd->m_RenderState.ibuffer.size = pView->SizeInBytes; + } + else + { + m_Cmd->m_RenderState.ibuffer.buf = ResourceId(); + m_Cmd->m_RenderState.ibuffer.offs = 0; + m_Cmd->m_RenderState.ibuffer.bytewidth = 2; + } } - else - { - Unwrap(list)->IASetIndexBuffer(NULL); - - m_Cmd->m_RenderState.ibuffer.buf = ResourceId(); - m_Cmd->m_RenderState.ibuffer.offs = 0; - m_Cmd->m_RenderState.ibuffer.bytewidth = 2; - } - } - } - else if(m_State == READING) - { - ID3D12GraphicsCommandList *list = GetList(CommandList); - - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - - if(HasView) - { - list->IASetIndexBuffer(&view); - GetCrackedList(CommandList)->IASetIndexBuffer(&view); - - WrappedID3D12Resource::GetResIDFromAddr(view.BufferLocation, state.ibuffer.buf, - state.ibuffer.offs); - state.ibuffer.bytewidth = (view.Format == DXGI_FORMAT_R32_UINT ? 4 : 2); - state.ibuffer.size = view.SizeInBytes; } else { - list->IASetIndexBuffer(NULL); - GetCrackedList(CommandList)->IASetIndexBuffer(NULL); + ID3D12GraphicsCommandList *list = pCommandList; - state.ibuffer.buf = ResourceId(); - state.ibuffer.offs = 0; - state.ibuffer.bytewidth = 2; + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; + + list->IASetIndexBuffer(pView); + GetCrackedList()->IASetIndexBuffer(pView); + + if(pView) + { + WrappedID3D12Resource::GetResIDFromAddr(pView->BufferLocation, state.ibuffer.buf, + state.ibuffer.offs); + state.ibuffer.bytewidth = (pView->Format == DXGI_FORMAT_R32_UINT ? 4 : 2); + state.ibuffer.size = pView->SizeInBytes; + } + else + { + state.ibuffer.buf = ResourceId(); + state.ibuffer.offs = 0; + state.ibuffer.bytewidth = 2; + } } } @@ -899,10 +901,11 @@ void WrappedID3D12GraphicsCommandList::IASetIndexBuffer(const D3D12_INDEX_BUFFER { m_pReal->IASetIndexBuffer(pView); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_IBUFFER); - Serialise_IASetIndexBuffer(pView); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_IASetIndexBuffer); + Serialise_IASetIndexBuffer(ser, pView); m_ListRecord->AddChunk(scope.Get()); if(pView) @@ -911,58 +914,62 @@ void WrappedID3D12GraphicsCommandList::IASetIndexBuffer(const D3D12_INDEX_BUFFER } } +template bool WrappedID3D12GraphicsCommandList::Serialise_IASetVertexBuffers( - UINT StartSlot, UINT NumViews, const D3D12_VERTEX_BUFFER_VIEW *pViews) + SerialiserType &ser, UINT StartSlot, UINT NumViews, const D3D12_VERTEX_BUFFER_VIEW *pViews) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, start, StartSlot); - SERIALISE_ELEMENT(UINT, num, NumViews); - SERIALISE_ELEMENT_ARR(D3D12_VERTEX_BUFFER_VIEW, views, pViews, num); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(StartSlot); + SERIALISE_ELEMENT_ARRAY(pViews, NumViews); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList))->IASetVertexBuffers(start, num, views); - - if(m_Cmd->m_RenderState.vbuffers.size() < start + num) - m_Cmd->m_RenderState.vbuffers.resize(start + num); - - for(UINT i = 0; i < num; i++) + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - WrappedID3D12Resource::GetResIDFromAddr(views[i].BufferLocation, - m_Cmd->m_RenderState.vbuffers[start + i].buf, - m_Cmd->m_RenderState.vbuffers[start + i].offs); + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->IASetVertexBuffers(StartSlot, NumViews, pViews); - m_Cmd->m_RenderState.vbuffers[start + i].stride = views[i].StrideInBytes; - m_Cmd->m_RenderState.vbuffers[start + i].size = views[i].SizeInBytes; + if(m_Cmd->m_RenderState.vbuffers.size() < StartSlot + NumViews) + m_Cmd->m_RenderState.vbuffers.resize(StartSlot + NumViews); + + for(UINT i = 0; i < NumViews; i++) + { + WrappedID3D12Resource::GetResIDFromAddr(pViews[i].BufferLocation, + m_Cmd->m_RenderState.vbuffers[StartSlot + i].buf, + m_Cmd->m_RenderState.vbuffers[StartSlot + i].offs); + + m_Cmd->m_RenderState.vbuffers[StartSlot + i].stride = pViews[i].StrideInBytes; + m_Cmd->m_RenderState.vbuffers[StartSlot + i].size = pViews[i].SizeInBytes; + } + } + } + else + { + Unwrap(pCommandList)->IASetVertexBuffers(StartSlot, NumViews, pViews); + GetCrackedList()->IASetVertexBuffers(StartSlot, NumViews, pViews); + + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; + + if(state.vbuffers.size() < StartSlot + NumViews) + state.vbuffers.resize(StartSlot + NumViews); + + for(UINT i = 0; i < NumViews; i++) + { + WrappedID3D12Resource::GetResIDFromAddr(pViews[i].BufferLocation, + state.vbuffers[StartSlot + i].buf, + state.vbuffers[StartSlot + i].offs); + + state.vbuffers[StartSlot + i].stride = pViews[i].StrideInBytes; + state.vbuffers[StartSlot + i].size = pViews[i].SizeInBytes; } } } - else if(m_State == READING) - { - GetList(CommandList)->IASetVertexBuffers(start, num, views); - GetCrackedList(CommandList)->IASetVertexBuffers(start, num, views); - - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - - if(state.vbuffers.size() < start + num) - state.vbuffers.resize(start + num); - - for(UINT i = 0; i < num; i++) - { - WrappedID3D12Resource::GetResIDFromAddr( - views[i].BufferLocation, state.vbuffers[start + i].buf, state.vbuffers[start + i].offs); - - state.vbuffers[start + i].stride = views[i].StrideInBytes; - state.vbuffers[start + i].size = views[i].SizeInBytes; - } - } - - SAFE_DELETE_ARRAY(views); return true; } @@ -972,10 +979,11 @@ void WrappedID3D12GraphicsCommandList::IASetVertexBuffers(UINT StartSlot, UINT N { m_pReal->IASetVertexBuffers(StartSlot, NumViews, pViews); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_VBUFFERS); - Serialise_IASetVertexBuffers(StartSlot, NumViews, pViews); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_IASetVertexBuffers); + Serialise_IASetVertexBuffers(ser, StartSlot, NumViews, pViews); m_ListRecord->AddChunk(scope.Get()); for(UINT i = 0; i < NumViews; i++) @@ -984,63 +992,65 @@ void WrappedID3D12GraphicsCommandList::IASetVertexBuffers(UINT StartSlot, UINT N } } +template bool WrappedID3D12GraphicsCommandList::Serialise_SOSetTargets( - UINT StartSlot, UINT NumViews, const D3D12_STREAM_OUTPUT_BUFFER_VIEW *pViews) + SerialiserType &ser, UINT StartSlot, UINT NumViews, const D3D12_STREAM_OUTPUT_BUFFER_VIEW *pViews) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, start, StartSlot); - SERIALISE_ELEMENT(UINT, num, NumViews); - SERIALISE_ELEMENT_ARR(D3D12_STREAM_OUTPUT_BUFFER_VIEW, views, pViews, num); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(StartSlot); + SERIALISE_ELEMENT_ARRAY(pViews, NumViews); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList))->SOSetTargets(start, num, views); - - if(m_Cmd->m_RenderState.streamouts.size() < start + num) - m_Cmd->m_RenderState.streamouts.resize(start + num); - - for(UINT i = 0; i < num; i++) + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - D3D12RenderState::StreamOut &so = m_Cmd->m_RenderState.streamouts[start + i]; + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->SOSetTargets(StartSlot, NumViews, pViews); - WrappedID3D12Resource::GetResIDFromAddr(views[i].BufferLocation, so.buf, so.offs); + if(m_Cmd->m_RenderState.streamouts.size() < StartSlot + NumViews) + m_Cmd->m_RenderState.streamouts.resize(StartSlot + NumViews); - WrappedID3D12Resource::GetResIDFromAddr(views[i].BufferFilledSizeLocation, so.countbuf, + for(UINT i = 0; i < NumViews; i++) + { + D3D12RenderState::StreamOut &so = m_Cmd->m_RenderState.streamouts[StartSlot + i]; + + WrappedID3D12Resource::GetResIDFromAddr(pViews[i].BufferLocation, so.buf, so.offs); + + WrappedID3D12Resource::GetResIDFromAddr(pViews[i].BufferFilledSizeLocation, so.countbuf, + so.countoffs); + + so.size = pViews[i].SizeInBytes; + } + } + } + else + { + Unwrap(pCommandList)->SOSetTargets(StartSlot, NumViews, pViews); + GetCrackedList()->SOSetTargets(StartSlot, NumViews, pViews); + + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; + + if(state.streamouts.size() < StartSlot + NumViews) + state.streamouts.resize(StartSlot + NumViews); + + for(UINT i = 0; i < NumViews; i++) + { + D3D12RenderState::StreamOut &so = state.streamouts[StartSlot + i]; + + WrappedID3D12Resource::GetResIDFromAddr(pViews[i].BufferLocation, so.buf, so.offs); + + WrappedID3D12Resource::GetResIDFromAddr(pViews[i].BufferFilledSizeLocation, so.countbuf, so.countoffs); - so.size = views[i].SizeInBytes; + so.size = pViews[i].SizeInBytes; } } } - else if(m_State == READING) - { - GetList(CommandList)->SOSetTargets(start, num, views); - GetCrackedList(CommandList)->SOSetTargets(start, num, views); - - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - - if(state.streamouts.size() < start + num) - state.streamouts.resize(start + num); - - for(UINT i = 0; i < num; i++) - { - D3D12RenderState::StreamOut &so = state.streamouts[start + i]; - - WrappedID3D12Resource::GetResIDFromAddr(views[i].BufferLocation, so.buf, so.offs); - - WrappedID3D12Resource::GetResIDFromAddr(views[i].BufferFilledSizeLocation, so.countbuf, - so.countoffs); - - so.size = views[i].SizeInBytes; - } - } - - SAFE_DELETE_ARRAY(views); return true; } @@ -1050,10 +1060,11 @@ void WrappedID3D12GraphicsCommandList::SOSetTargets(UINT StartSlot, UINT NumView { m_pReal->SOSetTargets(StartSlot, NumViews, pViews); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_SOTARGETS); - Serialise_SOSetTargets(StartSlot, NumViews, pViews); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SOSetTargets); + Serialise_SOSetTargets(ser, StartSlot, NumViews, pViews); m_ListRecord->AddChunk(scope.Get()); for(UINT i = 0; i < NumViews; i++) @@ -1062,31 +1073,35 @@ void WrappedID3D12GraphicsCommandList::SOSetTargets(UINT StartSlot, UINT NumView } } -bool WrappedID3D12GraphicsCommandList::Serialise_SetPipelineState(ID3D12PipelineState *pPipelineState) +template +bool WrappedID3D12GraphicsCommandList::Serialise_SetPipelineState(SerialiserType &ser, + ID3D12PipelineState *pPipelineState) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(ResourceId, pipe, GetResID(pPipelineState)); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(pPipelineState); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - pPipelineState = GetResourceManager()->GetLiveAs(pipe); - Unwrap(m_Cmd->RerecordCmdList(CommandList))->SetPipelineState(Unwrap(pPipelineState)); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->SetPipelineState(Unwrap(pPipelineState)); - m_Cmd->m_RenderState.pipe = GetResID(pPipelineState); + m_Cmd->m_RenderState.pipe = GetResID(pPipelineState); + } } - } - else if(m_State == READING) - { - pPipelineState = GetResourceManager()->GetLiveAs(pipe); - GetList(CommandList)->SetPipelineState(Unwrap(pPipelineState)); - GetCrackedList(CommandList)->SetPipelineState(Unwrap(pPipelineState)); + else + { + Unwrap(pCommandList)->SetPipelineState(Unwrap(pPipelineState)); + GetCrackedList()->SetPipelineState(Unwrap(pPipelineState)); - m_Cmd->m_BakedCmdListInfo[CommandList].state.pipe = GetResID(pPipelineState); + m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state.pipe = GetResID(pPipelineState); + } } return true; @@ -1096,101 +1111,90 @@ void WrappedID3D12GraphicsCommandList::SetPipelineState(ID3D12PipelineState *pPi { m_pReal->SetPipelineState(Unwrap(pPipelineState)); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_PIPE); - Serialise_SetPipelineState(pPipelineState); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetPipelineState); + Serialise_SetPipelineState(ser, pPipelineState); m_ListRecord->AddChunk(scope.Get()); m_ListRecord->MarkResourceFrameReferenced(GetResID(pPipelineState), eFrameRef_Read); } } +template bool WrappedID3D12GraphicsCommandList::Serialise_OMSetRenderTargets( - UINT NumRenderTargetDescriptors, const D3D12_CPU_DESCRIPTOR_HANDLE *pRenderTargetDescriptors, + SerialiserType &ser, UINT NumRenderTargetDescriptors, + const D3D12_CPU_DESCRIPTOR_HANDLE *pRenderTargetDescriptors, BOOL RTsSingleHandleToDescriptorRange, const D3D12_CPU_DESCRIPTOR_HANDLE *pDepthStencilDescriptor) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, num, NumRenderTargetDescriptors); - SERIALISE_ELEMENT(bool, singlehandle, RTsSingleHandleToDescriptorRange != FALSE); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(NumRenderTargetDescriptors); + SERIALISE_ELEMENT_TYPED(bool, RTsSingleHandleToDescriptorRange); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; + // if RTsSingleHandleToDescriptorRange is true, we only have up to 1 actual handle + UINT numHandles = RTsSingleHandleToDescriptorRange ? RDCMIN(1U, NumRenderTargetDescriptors) + : NumRenderTargetDescriptors; - UINT numHandles = singlehandle ? RDCMIN(1U, num) : num; + SERIALISE_ELEMENT_ARRAY(pRenderTargetDescriptors, numHandles); + SERIALISE_ELEMENT_OPT(pDepthStencilDescriptor); - std::vector rts; - - if(m_State >= WRITING) + if(IsReplayingAndReading()) { - rts.resize(numHandles); - // indexing pRenderTargetDescriptors with [i] is fine since if single handle is true, - // i will only ever be 0 (so we do equivalent of *pRenderTargetDescriptors) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + std::vector unwrappedRTs; + unwrappedRTs.resize(numHandles); for(UINT i = 0; i < numHandles; i++) - rts[i] = ToPortableHandle(pRenderTargetDescriptors[i]); - } + unwrappedRTs[i] = Unwrap(pRenderTargetDescriptors[i]); - m_pSerialiser->Serialise("pRenderTargetDescriptors", rts); + D3D12_CPU_DESCRIPTOR_HANDLE unwrappedDSV; + if(pDepthStencilDescriptor) + unwrappedDSV = Unwrap(*pDepthStencilDescriptor); - SERIALISE_ELEMENT(PortableHandle, dsv, pDepthStencilDescriptor - ? ToPortableHandle(*pDepthStencilDescriptor) - : PortableHandle(0)); - - if(m_State == EXECUTING) - { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = CPUHandleFromPortableHandle(GetResourceManager(), dsv); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->OMSetRenderTargets(NumRenderTargetDescriptors, unwrappedRTs.data(), + RTsSingleHandleToDescriptorRange, + pDepthStencilDescriptor ? &unwrappedDSV : NULL); - D3D12_CPU_DESCRIPTOR_HANDLE *rtHandles = new D3D12_CPU_DESCRIPTOR_HANDLE[numHandles]; + m_Cmd->m_RenderState.rts.resize(numHandles); - for(UINT i = 0; i < numHandles; i++) - rtHandles[i] = CPUHandleFromPortableHandle(GetResourceManager(), rts[i]); + for(UINT i = 0; i < numHandles; i++) + m_Cmd->m_RenderState.rts[i] = pRenderTargetDescriptors[i]; - Unwrap(m_Cmd->RerecordCmdList(CommandList)) - ->OMSetRenderTargets(num, rtHandles, singlehandle ? TRUE : FALSE, - dsv.heap != ResourceId() ? &dsvHandle : NULL); + m_Cmd->m_RenderState.rtSingle = RTsSingleHandleToDescriptorRange != FALSE; - m_Cmd->m_RenderState.rts.resize(numHandles); - - for(UINT i = 0; i < numHandles; i++) - m_Cmd->m_RenderState.rts[i] = rts[i]; - - m_Cmd->m_RenderState.rtSingle = singlehandle; - - m_Cmd->m_RenderState.dsv = dsv; - - SAFE_DELETE_ARRAY(rtHandles); + m_Cmd->m_RenderState.dsv = + pDepthStencilDescriptor ? *pDepthStencilDescriptor : D3D12_CPU_DESCRIPTOR_HANDLE(); + } } - } - else if(m_State == READING) - { - D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = CPUHandleFromPortableHandle(GetResourceManager(), dsv); + else + { + Unwrap(pCommandList) + ->OMSetRenderTargets(NumRenderTargetDescriptors, unwrappedRTs.data(), + RTsSingleHandleToDescriptorRange, + pDepthStencilDescriptor ? &unwrappedDSV : NULL); + GetCrackedList()->OMSetRenderTargets(NumRenderTargetDescriptors, unwrappedRTs.data(), + RTsSingleHandleToDescriptorRange, + pDepthStencilDescriptor ? &unwrappedDSV : NULL); - D3D12_CPU_DESCRIPTOR_HANDLE *rtHandles = new D3D12_CPU_DESCRIPTOR_HANDLE[numHandles]; + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; - for(UINT i = 0; i < numHandles; i++) - rtHandles[i] = CPUHandleFromPortableHandle(GetResourceManager(), rts[i]); + state.rts.resize(numHandles); - GetList(CommandList) - ->OMSetRenderTargets(num, rtHandles, singlehandle ? TRUE : FALSE, - dsv.heap != ResourceId() ? &dsvHandle : NULL); - GetCrackedList(CommandList) - ->OMSetRenderTargets(num, rtHandles, singlehandle ? TRUE : FALSE, - dsv.heap != ResourceId() ? &dsvHandle : NULL); + for(UINT i = 0; i < numHandles; i++) + state.rts[i] = pRenderTargetDescriptors[i]; - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + state.rtSingle = RTsSingleHandleToDescriptorRange != FALSE; - state.rts.resize(numHandles); - - for(UINT i = 0; i < numHandles; i++) - state.rts[i] = rts[i]; - - state.rtSingle = singlehandle; - - state.dsv = dsv; - - SAFE_DELETE_ARRAY(rtHandles); + state.dsv = pDepthStencilDescriptor ? *pDepthStencilDescriptor : D3D12_CPU_DESCRIPTOR_HANDLE(); + } } return true; @@ -1213,11 +1217,12 @@ void WrappedID3D12GraphicsCommandList::OMSetRenderTargets( m_pReal->OMSetRenderTargets(num, unwrapped, RTsSingleHandleToDescriptorRange, pDepthStencilDescriptor ? &dsv : NULL); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_RTVS); - Serialise_OMSetRenderTargets(num, pRenderTargetDescriptors, RTsSingleHandleToDescriptorRange, - pDepthStencilDescriptor); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_OMSetRenderTargets); + Serialise_OMSetRenderTargets(ser, num, pRenderTargetDescriptors, + RTsSingleHandleToDescriptorRange, pDepthStencilDescriptor); m_ListRecord->AddChunk(scope.Get()); for(UINT i = 0; i < numHandles; i++) @@ -1240,46 +1245,49 @@ void WrappedID3D12GraphicsCommandList::OMSetRenderTargets( #pragma region Compute Root Signatures +template bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRootSignature( - ID3D12RootSignature *pRootSignature) + SerialiserType &ser, ID3D12RootSignature *pRootSignature) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(ResourceId, sig, GetResID(pRootSignature)); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(pRootSignature); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - pRootSignature = GetResourceManager()->GetLiveAs(sig); - Unwrap(m_Cmd->RerecordCmdList(CommandList))->SetComputeRootSignature(Unwrap(pRootSignature)); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->SetComputeRootSignature(Unwrap(pRootSignature)); - // From the docs - // (https://msdn.microsoft.com/en-us/library/windows/desktop/dn903950(v=vs.85).aspx) - // "If a root signature is changed on a command list, all previous root signature bindings - // become stale and all newly expected bindings must be set before Draw/Dispatch; otherwise, - // the behavior is undefined. If the root signature is redundantly set to the same one - // currently set, existing root signature bindings do not become stale." - if(m_Cmd->m_RenderState.compute.rootsig != GetResID(pRootSignature)) - m_Cmd->m_RenderState.compute.sigelems.clear(); + // From the docs + // (https://msdn.microsoft.com/en-us/library/windows/desktop/dn903950(v=vs.85).aspx) + // "If a root signature is changed on a command list, all previous root signature bindings + // become stale and all newly expected bindings must be set before Draw/Dispatch; otherwise, + // the behavior is undefined. If the root signature is redundantly set to the same one + // currently set, existing root signature bindings do not become stale." + if(m_Cmd->m_RenderState.compute.rootsig != GetResID(pRootSignature)) + m_Cmd->m_RenderState.compute.sigelems.clear(); - m_Cmd->m_RenderState.compute.rootsig = GetResID(pRootSignature); + m_Cmd->m_RenderState.compute.rootsig = GetResID(pRootSignature); + } } - } - else if(m_State == READING) - { - pRootSignature = GetResourceManager()->GetLiveAs(sig); + else + { + Unwrap(pCommandList)->SetComputeRootSignature(Unwrap(pRootSignature)); + GetCrackedList()->SetComputeRootSignature(Unwrap(pRootSignature)); - GetList(CommandList)->SetComputeRootSignature(Unwrap(pRootSignature)); - GetCrackedList(CommandList)->SetComputeRootSignature(Unwrap(pRootSignature)); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - - if(state.compute.rootsig != GetResID(pRootSignature)) - state.compute.sigelems.clear(); - state.compute.rootsig = GetResID(pRootSignature); + if(state.compute.rootsig != GetResID(pRootSignature)) + state.compute.sigelems.clear(); + state.compute.rootsig = GetResID(pRootSignature); + } } return true; @@ -1289,10 +1297,11 @@ void WrappedID3D12GraphicsCommandList::SetComputeRootSignature(ID3D12RootSignatu { m_pReal->SetComputeRootSignature(Unwrap(pRootSignature)); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_COMP_ROOT_SIG); - Serialise_SetComputeRootSignature(pRootSignature); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetComputeRootSignature); + Serialise_SetComputeRootSignature(ser, pRootSignature); m_ListRecord->AddChunk(scope.Get()); m_ListRecord->MarkResourceFrameReferenced(GetResID(pRootSignature), eFrameRef_Read); @@ -1302,53 +1311,50 @@ void WrappedID3D12GraphicsCommandList::SetComputeRootSignature(ID3D12RootSignatu } } +template bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRootDescriptorTable( - UINT RootParameterIndex, D3D12_GPU_DESCRIPTOR_HANDLE BaseDescriptor) + SerialiserType &ser, UINT RootParameterIndex, D3D12_GPU_DESCRIPTOR_HANDLE BaseDescriptor) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, idx, RootParameterIndex); - SERIALISE_ELEMENT(PortableHandle, Descriptor, ToPortableHandle(BaseDescriptor)); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(RootParameterIndex); + SERIALISE_ELEMENT(BaseDescriptor); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList)) - ->SetComputeRootDescriptorTable( - idx, GPUHandleFromPortableHandle(GetResourceManager(), Descriptor)); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->SetComputeRootDescriptorTable(RootParameterIndex, Unwrap(BaseDescriptor)); - WrappedID3D12DescriptorHeap *heap = - GetResourceManager()->GetLiveAs(Descriptor.heap); + if(m_Cmd->m_RenderState.compute.sigelems.size() < RootParameterIndex + 1) + m_Cmd->m_RenderState.compute.sigelems.resize(RootParameterIndex + 1); - if(m_Cmd->m_RenderState.compute.sigelems.size() < idx + 1) - m_Cmd->m_RenderState.compute.sigelems.resize(idx + 1); - - m_Cmd->m_RenderState.compute.sigelems[idx] = - D3D12RenderState::SignatureElement(eRootTable, GetResID(heap), (UINT64)Descriptor.index); + m_Cmd->m_RenderState.compute.sigelems[RootParameterIndex] = + D3D12RenderState::SignatureElement(eRootTable, + GetResID(GetWrapped(BaseDescriptor)->nonsamp.heap), + (UINT64)GetWrapped(BaseDescriptor)->nonsamp.idx); + } } - } - else if(m_State == READING) - { - GetList(CommandList) - ->SetComputeRootDescriptorTable( - idx, GPUHandleFromPortableHandle(GetResourceManager(), Descriptor)); - GetCrackedList(CommandList) - ->SetComputeRootDescriptorTable( - idx, GPUHandleFromPortableHandle(GetResourceManager(), Descriptor)); + else + { + Unwrap(pCommandList)->SetComputeRootDescriptorTable(RootParameterIndex, Unwrap(BaseDescriptor)); + GetCrackedList()->SetComputeRootDescriptorTable(RootParameterIndex, Unwrap(BaseDescriptor)); - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; - if(state.compute.sigelems.size() < idx + 1) - state.compute.sigelems.resize(idx + 1); + if(state.compute.sigelems.size() < RootParameterIndex + 1) + state.compute.sigelems.resize(RootParameterIndex + 1); - WrappedID3D12DescriptorHeap *heap = - GetResourceManager()->GetLiveAs(Descriptor.heap); - - state.compute.sigelems[idx] = - D3D12RenderState::SignatureElement(eRootTable, GetResID(heap), (UINT64)Descriptor.index); + state.compute.sigelems[RootParameterIndex] = D3D12RenderState::SignatureElement( + eRootTable, GetResID(GetWrapped(BaseDescriptor)->nonsamp.heap), + (UINT64)GetWrapped(BaseDescriptor)->nonsamp.idx); + } } return true; @@ -1359,10 +1365,11 @@ void WrappedID3D12GraphicsCommandList::SetComputeRootDescriptorTable( { m_pReal->SetComputeRootDescriptorTable(RootParameterIndex, Unwrap(BaseDescriptor)); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_COMP_ROOT_TABLE); - Serialise_SetComputeRootDescriptorTable(RootParameterIndex, BaseDescriptor); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetComputeRootDescriptorTable); + Serialise_SetComputeRootDescriptorTable(ser, RootParameterIndex, BaseDescriptor); m_ListRecord->AddChunk(scope.Get()); m_ListRecord->MarkResourceFrameReferenced(GetResID(GetWrapped(BaseDescriptor)->nonsamp.heap), @@ -1407,40 +1414,49 @@ void WrappedID3D12GraphicsCommandList::SetComputeRootDescriptorTable( } } +template bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRoot32BitConstant( - UINT RootParameterIndex, UINT SrcData, UINT DestOffsetIn32BitValues) + SerialiserType &ser, UINT RootParameterIndex, UINT SrcData, UINT DestOffsetIn32BitValues) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, idx, RootParameterIndex); - SERIALISE_ELEMENT(UINT, val, SrcData); - SERIALISE_ELEMENT(UINT, offs, DestOffsetIn32BitValues); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(RootParameterIndex); + SERIALISE_ELEMENT(SrcData); + SERIALISE_ELEMENT(DestOffsetIn32BitValues); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList))->SetComputeRoot32BitConstant(idx, val, offs); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->SetComputeRoot32BitConstant(RootParameterIndex, SrcData, DestOffsetIn32BitValues); - if(m_Cmd->m_RenderState.compute.sigelems.size() < idx + 1) - m_Cmd->m_RenderState.compute.sigelems.resize(idx + 1); + if(m_Cmd->m_RenderState.compute.sigelems.size() < RootParameterIndex + 1) + m_Cmd->m_RenderState.compute.sigelems.resize(RootParameterIndex + 1); - m_Cmd->m_RenderState.compute.sigelems[idx].SetConstant(offs, val); + m_Cmd->m_RenderState.compute.sigelems[RootParameterIndex].SetConstant( + DestOffsetIn32BitValues, SrcData); + } } - } - else if(m_State == READING) - { - GetList(CommandList)->SetComputeRoot32BitConstant(idx, val, offs); - GetCrackedList(CommandList)->SetComputeRoot32BitConstant(idx, val, offs); + else + { + Unwrap(pCommandList) + ->SetComputeRoot32BitConstant(RootParameterIndex, SrcData, DestOffsetIn32BitValues); + GetCrackedList()->SetComputeRoot32BitConstant(RootParameterIndex, SrcData, + DestOffsetIn32BitValues); - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; - if(state.compute.sigelems.size() < idx + 1) - state.compute.sigelems.resize(idx + 1); + if(state.compute.sigelems.size() < RootParameterIndex + 1) + state.compute.sigelems.resize(RootParameterIndex + 1); - state.compute.sigelems[idx].SetConstant(offs, val); + state.compute.sigelems[RootParameterIndex].SetConstant(DestOffsetIn32BitValues, SrcData); + } } return true; @@ -1452,54 +1468,66 @@ void WrappedID3D12GraphicsCommandList::SetComputeRoot32BitConstant(UINT RootPara { m_pReal->SetComputeRoot32BitConstant(RootParameterIndex, SrcData, DestOffsetIn32BitValues); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_COMP_ROOT_CONST); - Serialise_SetComputeRoot32BitConstant(RootParameterIndex, SrcData, DestOffsetIn32BitValues); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetComputeRoot32BitConstant); + Serialise_SetComputeRoot32BitConstant(ser, RootParameterIndex, SrcData, DestOffsetIn32BitValues); m_ListRecord->AddChunk(scope.Get()); } } +template bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRoot32BitConstants( - UINT RootParameterIndex, UINT Num32BitValuesToSet, const void *pSrcData, - UINT DestOffsetIn32BitValues) + SerialiserType &ser, UINT RootParameterIndex, UINT Num32BitValuesToSet, + const void *pSrcVoidData, UINT DestOffsetIn32BitValues) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, idx, RootParameterIndex); - SERIALISE_ELEMENT(UINT, num, Num32BitValuesToSet); - SERIALISE_ELEMENT(UINT, offs, DestOffsetIn32BitValues); - SERIALISE_ELEMENT_ARR(UINT, data, (UINT *)pSrcData, num); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(RootParameterIndex); + SERIALISE_ELEMENT(Num32BitValuesToSet); + SERIALISE_ELEMENT(DestOffsetIn32BitValues); + const UINT *pSrcData = (const UINT *)pSrcVoidData; + SERIALISE_ELEMENT_ARRAY(pSrcData, Num32BitValuesToSet); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList))->SetComputeRoot32BitConstants(idx, num, data, offs); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->SetComputeRoot32BitConstants(RootParameterIndex, Num32BitValuesToSet, pSrcData, + DestOffsetIn32BitValues); - if(m_Cmd->m_RenderState.compute.sigelems.size() < idx + 1) - m_Cmd->m_RenderState.compute.sigelems.resize(idx + 1); + if(m_Cmd->m_RenderState.compute.sigelems.size() < RootParameterIndex + 1) + m_Cmd->m_RenderState.compute.sigelems.resize(RootParameterIndex + 1); - m_Cmd->m_RenderState.compute.sigelems[idx].SetConstants(num, data, offs); + m_Cmd->m_RenderState.compute.sigelems[RootParameterIndex].SetConstants( + Num32BitValuesToSet, pSrcData, DestOffsetIn32BitValues); + } + } + else + { + Unwrap(pCommandList) + ->SetComputeRoot32BitConstants(RootParameterIndex, Num32BitValuesToSet, pSrcData, + DestOffsetIn32BitValues); + GetCrackedList()->SetComputeRoot32BitConstants(RootParameterIndex, Num32BitValuesToSet, + pSrcData, DestOffsetIn32BitValues); + + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; + + if(state.compute.sigelems.size() < RootParameterIndex + 1) + state.compute.sigelems.resize(RootParameterIndex + 1); + + state.compute.sigelems[RootParameterIndex].SetConstants(Num32BitValuesToSet, pSrcData, + DestOffsetIn32BitValues); } } - else if(m_State == READING) - { - GetList(CommandList)->SetComputeRoot32BitConstants(idx, num, data, offs); - GetCrackedList(CommandList)->SetComputeRoot32BitConstants(idx, num, data, offs); - - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - - if(state.compute.sigelems.size() < idx + 1) - state.compute.sigelems.resize(idx + 1); - - state.compute.sigelems[idx].SetConstants(num, data, offs); - } - - SAFE_DELETE_ARRAY(data); return true; } @@ -1512,69 +1540,66 @@ void WrappedID3D12GraphicsCommandList::SetComputeRoot32BitConstants(UINT RootPar m_pReal->SetComputeRoot32BitConstants(RootParameterIndex, Num32BitValuesToSet, pSrcData, DestOffsetIn32BitValues); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_COMP_ROOT_CONSTS); - Serialise_SetComputeRoot32BitConstants(RootParameterIndex, Num32BitValuesToSet, pSrcData, + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetComputeRoot32BitConstants); + Serialise_SetComputeRoot32BitConstants(ser, RootParameterIndex, Num32BitValuesToSet, pSrcData, DestOffsetIn32BitValues); m_ListRecord->AddChunk(scope.Get()); } } +template bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRootConstantBufferView( - UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation) + SerialiserType &ser, UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation) { - ResourceId id; - UINT64 offs = 0; + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(RootParameterIndex); + SERIALISE_ELEMENT_TYPED(D3D12BufferLocation, BufferLocation); + + if(IsReplayingAndReading()) + { + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(ValidateRootGPUVA(BufferLocation)) + return true; + + ResourceId id; + uint64_t offs; - if(m_State >= WRITING) WrappedID3D12Resource::GetResIDFromAddr(BufferLocation, id, offs); - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, idx, RootParameterIndex); - SERIALISE_ELEMENT(ResourceId, buffer, id); - SERIALISE_ELEMENT(UINT64, byteOffset, offs); - - if(m_State < WRITING) - { - m_Cmd->m_LastCmdListID = CommandList; - - if(ValidateRootGPUVA(buffer)) - return true; - } - - if(m_State == EXECUTING) - { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - WrappedID3D12Resource *pRes = GetResourceManager()->GetLiveAs(buffer); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->SetComputeRootConstantBufferView(RootParameterIndex, BufferLocation); - Unwrap(m_Cmd->RerecordCmdList(CommandList)) - ->SetComputeRootConstantBufferView(idx, pRes->GetGPUVirtualAddress() + byteOffset); + if(m_Cmd->m_RenderState.compute.sigelems.size() < RootParameterIndex + 1) + m_Cmd->m_RenderState.compute.sigelems.resize(RootParameterIndex + 1); - if(m_Cmd->m_RenderState.compute.sigelems.size() < idx + 1) - m_Cmd->m_RenderState.compute.sigelems.resize(idx + 1); - - m_Cmd->m_RenderState.compute.sigelems[idx] = - D3D12RenderState::SignatureElement(eRootCBV, GetResID(pRes), byteOffset); + m_Cmd->m_RenderState.compute.sigelems[RootParameterIndex] = + D3D12RenderState::SignatureElement(eRootCBV, id, offs); + } } - } - else if(m_State == READING) - { - WrappedID3D12Resource *pRes = GetResourceManager()->GetLiveAs(buffer); + else + { + Unwrap(pCommandList)->SetComputeRootConstantBufferView(RootParameterIndex, BufferLocation); + GetCrackedList()->SetComputeRootConstantBufferView(RootParameterIndex, BufferLocation); - GetList(CommandList)->SetComputeRootConstantBufferView(idx, pRes->GetGPUVirtualAddress() + byteOffset); - GetCrackedList(CommandList) - ->SetComputeRootConstantBufferView(idx, pRes->GetGPUVirtualAddress() + byteOffset); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + if(state.compute.sigelems.size() < RootParameterIndex + 1) + state.compute.sigelems.resize(RootParameterIndex + 1); - if(state.compute.sigelems.size() < idx + 1) - state.compute.sigelems.resize(idx + 1); - - state.compute.sigelems[idx] = - D3D12RenderState::SignatureElement(eRootCBV, GetResID(pRes), byteOffset); + state.compute.sigelems[RootParameterIndex] = + D3D12RenderState::SignatureElement(eRootCBV, id, offs); + } } return true; @@ -1585,10 +1610,11 @@ void WrappedID3D12GraphicsCommandList::SetComputeRootConstantBufferView( { m_pReal->SetComputeRootConstantBufferView(RootParameterIndex, BufferLocation); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_COMP_ROOT_CBV); - Serialise_SetComputeRootConstantBufferView(RootParameterIndex, BufferLocation); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetComputeRootConstantBufferView); + Serialise_SetComputeRootConstantBufferView(ser, RootParameterIndex, BufferLocation); ResourceId id; UINT64 offs = 0; @@ -1599,59 +1625,55 @@ void WrappedID3D12GraphicsCommandList::SetComputeRootConstantBufferView( } } +template bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRootShaderResourceView( - UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation) + SerialiserType &ser, UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation) { - ResourceId id; - UINT64 offs = 0; + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(RootParameterIndex); + SERIALISE_ELEMENT_TYPED(D3D12BufferLocation, BufferLocation); + + if(IsReplayingAndReading()) + { + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(ValidateRootGPUVA(BufferLocation)) + return true; + + ResourceId id; + uint64_t offs; - if(m_State >= WRITING) WrappedID3D12Resource::GetResIDFromAddr(BufferLocation, id, offs); - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, idx, RootParameterIndex); - SERIALISE_ELEMENT(ResourceId, buffer, id); - SERIALISE_ELEMENT(UINT64, byteOffset, offs); - - if(m_State < WRITING) - { - m_Cmd->m_LastCmdListID = CommandList; - - if(ValidateRootGPUVA(buffer)) - return true; - } - - if(m_State == EXECUTING) - { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - WrappedID3D12Resource *pRes = GetResourceManager()->GetLiveAs(buffer); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->SetComputeRootShaderResourceView(RootParameterIndex, BufferLocation); - Unwrap(m_Cmd->RerecordCmdList(CommandList)) - ->SetComputeRootShaderResourceView(idx, pRes->GetGPUVirtualAddress() + byteOffset); + if(m_Cmd->m_RenderState.compute.sigelems.size() < RootParameterIndex + 1) + m_Cmd->m_RenderState.compute.sigelems.resize(RootParameterIndex + 1); - if(m_Cmd->m_RenderState.compute.sigelems.size() < idx + 1) - m_Cmd->m_RenderState.compute.sigelems.resize(idx + 1); - - m_Cmd->m_RenderState.compute.sigelems[idx] = - D3D12RenderState::SignatureElement(eRootSRV, GetResID(pRes), byteOffset); + m_Cmd->m_RenderState.compute.sigelems[RootParameterIndex] = + D3D12RenderState::SignatureElement(eRootSRV, id, offs); + } } - } - else if(m_State == READING) - { - WrappedID3D12Resource *pRes = GetResourceManager()->GetLiveAs(buffer); + else + { + Unwrap(pCommandList)->SetComputeRootShaderResourceView(RootParameterIndex, BufferLocation); + GetCrackedList()->SetComputeRootShaderResourceView(RootParameterIndex, BufferLocation); - GetList(CommandList)->SetComputeRootShaderResourceView(idx, pRes->GetGPUVirtualAddress() + byteOffset); - GetCrackedList(CommandList) - ->SetComputeRootShaderResourceView(idx, pRes->GetGPUVirtualAddress() + byteOffset); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + if(state.compute.sigelems.size() < RootParameterIndex + 1) + state.compute.sigelems.resize(RootParameterIndex + 1); - if(state.compute.sigelems.size() < idx + 1) - state.compute.sigelems.resize(idx + 1); - - state.compute.sigelems[idx] = - D3D12RenderState::SignatureElement(eRootSRV, GetResID(pRes), byteOffset); + state.compute.sigelems[RootParameterIndex] = + D3D12RenderState::SignatureElement(eRootSRV, id, offs); + } } return true; @@ -1662,10 +1684,11 @@ void WrappedID3D12GraphicsCommandList::SetComputeRootShaderResourceView( { m_pReal->SetComputeRootShaderResourceView(RootParameterIndex, BufferLocation); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_COMP_ROOT_SRV); - Serialise_SetComputeRootShaderResourceView(RootParameterIndex, BufferLocation); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetComputeRootShaderResourceView); + Serialise_SetComputeRootShaderResourceView(ser, RootParameterIndex, BufferLocation); ResourceId id; UINT64 offs = 0; @@ -1676,60 +1699,55 @@ void WrappedID3D12GraphicsCommandList::SetComputeRootShaderResourceView( } } +template bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRootUnorderedAccessView( - UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation) + SerialiserType &ser, UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation) { - ResourceId id; - UINT64 offs = 0; + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(RootParameterIndex); + SERIALISE_ELEMENT_TYPED(D3D12BufferLocation, BufferLocation); + + if(IsReplayingAndReading()) + { + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(ValidateRootGPUVA(BufferLocation)) + return true; + + ResourceId id; + uint64_t offs; - if(m_State >= WRITING) WrappedID3D12Resource::GetResIDFromAddr(BufferLocation, id, offs); - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, idx, RootParameterIndex); - SERIALISE_ELEMENT(ResourceId, buffer, id); - SERIALISE_ELEMENT(UINT64, byteOffset, offs); - - if(m_State < WRITING) - { - m_Cmd->m_LastCmdListID = CommandList; - - if(ValidateRootGPUVA(buffer)) - return true; - } - - if(m_State == EXECUTING) - { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - WrappedID3D12Resource *pRes = GetResourceManager()->GetLiveAs(buffer); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->SetComputeRootUnorderedAccessView(RootParameterIndex, BufferLocation); - Unwrap(m_Cmd->RerecordCmdList(CommandList)) - ->SetComputeRootUnorderedAccessView(idx, pRes->GetGPUVirtualAddress() + byteOffset); + if(m_Cmd->m_RenderState.compute.sigelems.size() < RootParameterIndex + 1) + m_Cmd->m_RenderState.compute.sigelems.resize(RootParameterIndex + 1); - if(m_Cmd->m_RenderState.compute.sigelems.size() < idx + 1) - m_Cmd->m_RenderState.compute.sigelems.resize(idx + 1); - - m_Cmd->m_RenderState.compute.sigelems[idx] = - D3D12RenderState::SignatureElement(eRootUAV, GetResID(pRes), byteOffset); + m_Cmd->m_RenderState.compute.sigelems[RootParameterIndex] = + D3D12RenderState::SignatureElement(eRootUAV, id, offs); + } } - } - else if(m_State == READING) - { - WrappedID3D12Resource *pRes = GetResourceManager()->GetLiveAs(buffer); + else + { + Unwrap(pCommandList)->SetComputeRootUnorderedAccessView(RootParameterIndex, BufferLocation); + GetCrackedList()->SetComputeRootUnorderedAccessView(RootParameterIndex, BufferLocation); - GetList(CommandList) - ->SetComputeRootUnorderedAccessView(idx, pRes->GetGPUVirtualAddress() + byteOffset); - GetCrackedList(CommandList) - ->SetComputeRootUnorderedAccessView(idx, pRes->GetGPUVirtualAddress() + byteOffset); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + if(state.compute.sigelems.size() < RootParameterIndex + 1) + state.compute.sigelems.resize(RootParameterIndex + 1); - if(state.compute.sigelems.size() < idx + 1) - state.compute.sigelems.resize(idx + 1); - - state.compute.sigelems[idx] = - D3D12RenderState::SignatureElement(eRootUAV, GetResID(pRes), byteOffset); + state.compute.sigelems[RootParameterIndex] = + D3D12RenderState::SignatureElement(eRootUAV, id, offs); + } } return true; @@ -1740,10 +1758,11 @@ void WrappedID3D12GraphicsCommandList::SetComputeRootUnorderedAccessView( { m_pReal->SetComputeRootUnorderedAccessView(RootParameterIndex, BufferLocation); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_COMP_ROOT_UAV); - Serialise_SetComputeRootUnorderedAccessView(RootParameterIndex, BufferLocation); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetComputeRootUnorderedAccessView); + Serialise_SetComputeRootUnorderedAccessView(ser, RootParameterIndex, BufferLocation); ResourceId id; UINT64 offs = 0; @@ -1758,46 +1777,49 @@ void WrappedID3D12GraphicsCommandList::SetComputeRootUnorderedAccessView( #pragma region Graphics Root Signatures +template bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootSignature( - ID3D12RootSignature *pRootSignature) + SerialiserType &ser, ID3D12RootSignature *pRootSignature) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(ResourceId, sig, GetResID(pRootSignature)); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(pRootSignature); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - pRootSignature = GetResourceManager()->GetLiveAs(sig); - Unwrap(m_Cmd->RerecordCmdList(CommandList))->SetGraphicsRootSignature(Unwrap(pRootSignature)); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->SetGraphicsRootSignature(Unwrap(pRootSignature)); - // From the docs - // (https://msdn.microsoft.com/en-us/library/windows/desktop/dn903950(v=vs.85).aspx) - // "If a root signature is changed on a command list, all previous root signature bindings - // become stale and all newly expected bindings must be set before Draw/Dispatch; otherwise, - // the behavior is undefined. If the root signature is redundantly set to the same one - // currently set, existing root signature bindings do not become stale." - if(m_Cmd->m_RenderState.graphics.rootsig != GetResID(pRootSignature)) - m_Cmd->m_RenderState.graphics.sigelems.clear(); + // From the docs + // (https://msdn.microsoft.com/en-us/library/windows/desktop/dn903950(v=vs.85).aspx) + // "If a root signature is changed on a command list, all previous root signature bindings + // become stale and all newly expected bindings must be set before Draw/Dispatch; otherwise, + // the behavior is undefined. If the root signature is redundantly set to the same one + // currently set, existing root signature bindings do not become stale." + if(m_Cmd->m_RenderState.graphics.rootsig != GetResID(pRootSignature)) + m_Cmd->m_RenderState.graphics.sigelems.clear(); - m_Cmd->m_RenderState.graphics.rootsig = GetResID(pRootSignature); + m_Cmd->m_RenderState.graphics.rootsig = GetResID(pRootSignature); + } } - } - else if(m_State == READING) - { - pRootSignature = GetResourceManager()->GetLiveAs(sig); + else + { + Unwrap(pCommandList)->SetGraphicsRootSignature(Unwrap(pRootSignature)); + GetCrackedList()->SetGraphicsRootSignature(Unwrap(pRootSignature)); - GetList(CommandList)->SetGraphicsRootSignature(Unwrap(pRootSignature)); - GetCrackedList(CommandList)->SetGraphicsRootSignature(Unwrap(pRootSignature)); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - - if(state.graphics.rootsig != GetResID(pRootSignature)) - state.graphics.sigelems.clear(); - state.graphics.rootsig = GetResID(pRootSignature); + if(state.graphics.rootsig != GetResID(pRootSignature)) + state.graphics.sigelems.clear(); + state.graphics.rootsig = GetResID(pRootSignature); + } } return true; @@ -1807,10 +1829,11 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRootSignature(ID3D12RootSignat { m_pReal->SetGraphicsRootSignature(Unwrap(pRootSignature)); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_GFX_ROOT_SIG); - Serialise_SetGraphicsRootSignature(pRootSignature); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetGraphicsRootSignature); + Serialise_SetGraphicsRootSignature(ser, pRootSignature); m_ListRecord->AddChunk(scope.Get()); m_ListRecord->MarkResourceFrameReferenced(GetResID(pRootSignature), eFrameRef_Read); @@ -1820,53 +1843,50 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRootSignature(ID3D12RootSignat } } +template bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootDescriptorTable( - UINT RootParameterIndex, D3D12_GPU_DESCRIPTOR_HANDLE BaseDescriptor) + SerialiserType &ser, UINT RootParameterIndex, D3D12_GPU_DESCRIPTOR_HANDLE BaseDescriptor) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, idx, RootParameterIndex); - SERIALISE_ELEMENT(PortableHandle, Descriptor, ToPortableHandle(BaseDescriptor)); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(RootParameterIndex); + SERIALISE_ELEMENT(BaseDescriptor); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList)) - ->SetGraphicsRootDescriptorTable( - idx, GPUHandleFromPortableHandle(GetResourceManager(), Descriptor)); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->SetGraphicsRootDescriptorTable(RootParameterIndex, Unwrap(BaseDescriptor)); - WrappedID3D12DescriptorHeap *heap = - GetResourceManager()->GetLiveAs(Descriptor.heap); + if(m_Cmd->m_RenderState.graphics.sigelems.size() < RootParameterIndex + 1) + m_Cmd->m_RenderState.graphics.sigelems.resize(RootParameterIndex + 1); - if(m_Cmd->m_RenderState.graphics.sigelems.size() < idx + 1) - m_Cmd->m_RenderState.graphics.sigelems.resize(idx + 1); - - m_Cmd->m_RenderState.graphics.sigelems[idx] = - D3D12RenderState::SignatureElement(eRootTable, GetResID(heap), (UINT64)Descriptor.index); + m_Cmd->m_RenderState.graphics.sigelems[RootParameterIndex] = + D3D12RenderState::SignatureElement(eRootTable, + GetResID(GetWrapped(BaseDescriptor)->nonsamp.heap), + (UINT64)GetWrapped(BaseDescriptor)->nonsamp.idx); + } } - } - else if(m_State == READING) - { - GetList(CommandList) - ->SetGraphicsRootDescriptorTable( - idx, GPUHandleFromPortableHandle(GetResourceManager(), Descriptor)); - GetCrackedList(CommandList) - ->SetGraphicsRootDescriptorTable( - idx, GPUHandleFromPortableHandle(GetResourceManager(), Descriptor)); + else + { + Unwrap(pCommandList)->SetGraphicsRootDescriptorTable(RootParameterIndex, Unwrap(BaseDescriptor)); + GetCrackedList()->SetGraphicsRootDescriptorTable(RootParameterIndex, Unwrap(BaseDescriptor)); - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; - if(state.graphics.sigelems.size() < idx + 1) - state.graphics.sigelems.resize(idx + 1); + if(state.graphics.sigelems.size() < RootParameterIndex + 1) + state.graphics.sigelems.resize(RootParameterIndex + 1); - WrappedID3D12DescriptorHeap *heap = - GetResourceManager()->GetLiveAs(Descriptor.heap); - - state.graphics.sigelems[idx] = - D3D12RenderState::SignatureElement(eRootTable, GetResID(heap), (UINT64)Descriptor.index); + state.graphics.sigelems[RootParameterIndex] = D3D12RenderState::SignatureElement( + eRootTable, GetResID(GetWrapped(BaseDescriptor)->nonsamp.heap), + (UINT64)GetWrapped(BaseDescriptor)->nonsamp.idx); + } } return true; @@ -1877,10 +1897,11 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable( { m_pReal->SetGraphicsRootDescriptorTable(RootParameterIndex, Unwrap(BaseDescriptor)); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_GFX_ROOT_TABLE); - Serialise_SetGraphicsRootDescriptorTable(RootParameterIndex, BaseDescriptor); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetGraphicsRootDescriptorTable); + Serialise_SetGraphicsRootDescriptorTable(ser, RootParameterIndex, BaseDescriptor); m_ListRecord->AddChunk(scope.Get()); m_ListRecord->MarkResourceFrameReferenced(GetResID(GetWrapped(BaseDescriptor)->nonsamp.heap), @@ -1925,40 +1946,49 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable( } } +template bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRoot32BitConstant( - UINT RootParameterIndex, UINT SrcData, UINT DestOffsetIn32BitValues) + SerialiserType &ser, UINT RootParameterIndex, UINT SrcData, UINT DestOffsetIn32BitValues) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, idx, RootParameterIndex); - SERIALISE_ELEMENT(UINT, val, SrcData); - SERIALISE_ELEMENT(UINT, offs, DestOffsetIn32BitValues); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(RootParameterIndex); + SERIALISE_ELEMENT(SrcData); + SERIALISE_ELEMENT(DestOffsetIn32BitValues); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList))->SetGraphicsRoot32BitConstant(idx, val, offs); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->SetGraphicsRoot32BitConstant(RootParameterIndex, SrcData, DestOffsetIn32BitValues); - if(m_Cmd->m_RenderState.graphics.sigelems.size() < idx + 1) - m_Cmd->m_RenderState.graphics.sigelems.resize(idx + 1); + if(m_Cmd->m_RenderState.graphics.sigelems.size() < RootParameterIndex + 1) + m_Cmd->m_RenderState.graphics.sigelems.resize(RootParameterIndex + 1); - m_Cmd->m_RenderState.graphics.sigelems[idx].SetConstant(offs, val); + m_Cmd->m_RenderState.graphics.sigelems[RootParameterIndex].SetConstant( + DestOffsetIn32BitValues, SrcData); + } } - } - else if(m_State == READING) - { - GetList(CommandList)->SetGraphicsRoot32BitConstant(idx, val, offs); - GetCrackedList(CommandList)->SetGraphicsRoot32BitConstant(idx, val, offs); + else + { + Unwrap(pCommandList) + ->SetGraphicsRoot32BitConstant(RootParameterIndex, SrcData, DestOffsetIn32BitValues); + GetCrackedList()->SetGraphicsRoot32BitConstant(RootParameterIndex, SrcData, + DestOffsetIn32BitValues); - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; - if(state.graphics.sigelems.size() < idx + 1) - state.graphics.sigelems.resize(idx + 1); + if(state.graphics.sigelems.size() < RootParameterIndex + 1) + state.graphics.sigelems.resize(RootParameterIndex + 1); - state.graphics.sigelems[idx].SetConstant(offs, val); + state.graphics.sigelems[RootParameterIndex].SetConstant(DestOffsetIn32BitValues, SrcData); + } } return true; @@ -1970,54 +2000,66 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRoot32BitConstant(UINT RootPar { m_pReal->SetGraphicsRoot32BitConstant(RootParameterIndex, SrcData, DestOffsetIn32BitValues); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_GFX_ROOT_CONST); - Serialise_SetGraphicsRoot32BitConstant(RootParameterIndex, SrcData, DestOffsetIn32BitValues); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetGraphicsRoot32BitConstant); + Serialise_SetGraphicsRoot32BitConstant(ser, RootParameterIndex, SrcData, DestOffsetIn32BitValues); m_ListRecord->AddChunk(scope.Get()); } } +template bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRoot32BitConstants( - UINT RootParameterIndex, UINT Num32BitValuesToSet, const void *pSrcData, - UINT DestOffsetIn32BitValues) + SerialiserType &ser, UINT RootParameterIndex, UINT Num32BitValuesToSet, + const void *pSrcVoidData, UINT DestOffsetIn32BitValues) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, idx, RootParameterIndex); - SERIALISE_ELEMENT(UINT, num, Num32BitValuesToSet); - SERIALISE_ELEMENT(UINT, offs, DestOffsetIn32BitValues); - SERIALISE_ELEMENT_ARR(UINT, data, (UINT *)pSrcData, num); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(RootParameterIndex); + SERIALISE_ELEMENT(Num32BitValuesToSet); + SERIALISE_ELEMENT(DestOffsetIn32BitValues); + const UINT *pSrcData = (const UINT *)pSrcVoidData; + SERIALISE_ELEMENT_ARRAY(pSrcData, Num32BitValuesToSet); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList))->SetGraphicsRoot32BitConstants(idx, num, data, offs); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->SetGraphicsRoot32BitConstants(RootParameterIndex, Num32BitValuesToSet, pSrcData, + DestOffsetIn32BitValues); - if(m_Cmd->m_RenderState.graphics.sigelems.size() < idx + 1) - m_Cmd->m_RenderState.graphics.sigelems.resize(idx + 1); + if(m_Cmd->m_RenderState.graphics.sigelems.size() < RootParameterIndex + 1) + m_Cmd->m_RenderState.graphics.sigelems.resize(RootParameterIndex + 1); - m_Cmd->m_RenderState.graphics.sigelems[idx].SetConstants(num, data, offs); + m_Cmd->m_RenderState.graphics.sigelems[RootParameterIndex].SetConstants( + Num32BitValuesToSet, pSrcData, DestOffsetIn32BitValues); + } + } + else + { + Unwrap(pCommandList) + ->SetGraphicsRoot32BitConstants(RootParameterIndex, Num32BitValuesToSet, pSrcData, + DestOffsetIn32BitValues); + GetCrackedList()->SetGraphicsRoot32BitConstants(RootParameterIndex, Num32BitValuesToSet, + pSrcData, DestOffsetIn32BitValues); + + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; + + if(state.graphics.sigelems.size() < RootParameterIndex + 1) + state.graphics.sigelems.resize(RootParameterIndex + 1); + + state.graphics.sigelems[RootParameterIndex].SetConstants(Num32BitValuesToSet, pSrcData, + DestOffsetIn32BitValues); } } - else if(m_State == READING) - { - GetList(CommandList)->SetGraphicsRoot32BitConstants(idx, num, data, offs); - GetCrackedList(CommandList)->SetGraphicsRoot32BitConstants(idx, num, data, offs); - - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - - if(state.graphics.sigelems.size() < idx + 1) - state.graphics.sigelems.resize(idx + 1); - - state.graphics.sigelems[idx].SetConstants(num, data, offs); - } - - SAFE_DELETE_ARRAY(data); return true; } @@ -2030,70 +2072,66 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRoot32BitConstants(UINT RootPa m_pReal->SetGraphicsRoot32BitConstants(RootParameterIndex, Num32BitValuesToSet, pSrcData, DestOffsetIn32BitValues); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_GFX_ROOT_CONSTS); - Serialise_SetGraphicsRoot32BitConstants(RootParameterIndex, Num32BitValuesToSet, pSrcData, + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetGraphicsRoot32BitConstants); + Serialise_SetGraphicsRoot32BitConstants(ser, RootParameterIndex, Num32BitValuesToSet, pSrcData, DestOffsetIn32BitValues); m_ListRecord->AddChunk(scope.Get()); } } +template bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootConstantBufferView( - UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation) + SerialiserType &ser, UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation) { - ResourceId id; - UINT64 offs = 0; + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(RootParameterIndex); + SERIALISE_ELEMENT_TYPED(D3D12BufferLocation, BufferLocation); + + if(IsReplayingAndReading()) + { + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(ValidateRootGPUVA(BufferLocation)) + return true; + + ResourceId id; + uint64_t offs; - if(m_State >= WRITING) WrappedID3D12Resource::GetResIDFromAddr(BufferLocation, id, offs); - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, idx, RootParameterIndex); - SERIALISE_ELEMENT(ResourceId, buffer, id); - SERIALISE_ELEMENT(UINT64, byteOffset, offs); - - if(m_State < WRITING) - { - m_Cmd->m_LastCmdListID = CommandList; - - if(ValidateRootGPUVA(buffer)) - return true; - } - - if(m_State == EXECUTING) - { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - WrappedID3D12Resource *pRes = GetResourceManager()->GetLiveAs(buffer); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->SetGraphicsRootConstantBufferView(RootParameterIndex, BufferLocation); - Unwrap(m_Cmd->RerecordCmdList(CommandList)) - ->SetGraphicsRootConstantBufferView(idx, pRes->GetGPUVirtualAddress() + byteOffset); + if(m_Cmd->m_RenderState.graphics.sigelems.size() < RootParameterIndex + 1) + m_Cmd->m_RenderState.graphics.sigelems.resize(RootParameterIndex + 1); - if(m_Cmd->m_RenderState.graphics.sigelems.size() < idx + 1) - m_Cmd->m_RenderState.graphics.sigelems.resize(idx + 1); - - m_Cmd->m_RenderState.graphics.sigelems[idx] = - D3D12RenderState::SignatureElement(eRootCBV, GetResID(pRes), byteOffset); + m_Cmd->m_RenderState.graphics.sigelems[RootParameterIndex] = + D3D12RenderState::SignatureElement(eRootCBV, id, offs); + } } - } - else if(m_State == READING) - { - WrappedID3D12Resource *pRes = GetResourceManager()->GetLiveAs(buffer); + else + { + Unwrap(pCommandList)->SetGraphicsRootConstantBufferView(RootParameterIndex, BufferLocation); + GetCrackedList()->SetGraphicsRootConstantBufferView(RootParameterIndex, BufferLocation); - GetList(CommandList) - ->SetGraphicsRootConstantBufferView(idx, pRes->GetGPUVirtualAddress() + byteOffset); - GetCrackedList(CommandList) - ->SetGraphicsRootConstantBufferView(idx, pRes->GetGPUVirtualAddress() + byteOffset); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + if(state.graphics.sigelems.size() < RootParameterIndex + 1) + state.graphics.sigelems.resize(RootParameterIndex + 1); - if(state.graphics.sigelems.size() < idx + 1) - state.graphics.sigelems.resize(idx + 1); - - state.graphics.sigelems[idx] = - D3D12RenderState::SignatureElement(eRootCBV, GetResID(pRes), byteOffset); + state.graphics.sigelems[RootParameterIndex] = + D3D12RenderState::SignatureElement(eRootCBV, id, offs); + } } return true; @@ -2104,10 +2142,11 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRootConstantBufferView( { m_pReal->SetGraphicsRootConstantBufferView(RootParameterIndex, BufferLocation); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_GFX_ROOT_CBV); - Serialise_SetGraphicsRootConstantBufferView(RootParameterIndex, BufferLocation); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetGraphicsRootConstantBufferView); + Serialise_SetGraphicsRootConstantBufferView(ser, RootParameterIndex, BufferLocation); ResourceId id; UINT64 offs = 0; @@ -2118,60 +2157,55 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRootConstantBufferView( } } +template bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootShaderResourceView( - UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation) + SerialiserType &ser, UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation) { - ResourceId id; - UINT64 offs = 0; + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(RootParameterIndex); + SERIALISE_ELEMENT_TYPED(D3D12BufferLocation, BufferLocation); + + if(IsReplayingAndReading()) + { + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(ValidateRootGPUVA(BufferLocation)) + return true; + + ResourceId id; + uint64_t offs; - if(m_State >= WRITING) WrappedID3D12Resource::GetResIDFromAddr(BufferLocation, id, offs); - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, idx, RootParameterIndex); - SERIALISE_ELEMENT(ResourceId, buffer, id); - SERIALISE_ELEMENT(UINT64, byteOffset, offs); - - if(m_State < WRITING) - { - m_Cmd->m_LastCmdListID = CommandList; - - if(ValidateRootGPUVA(buffer)) - return true; - } - - if(m_State == EXECUTING) - { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - WrappedID3D12Resource *pRes = GetResourceManager()->GetLiveAs(buffer); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->SetGraphicsRootShaderResourceView(RootParameterIndex, BufferLocation); - Unwrap(m_Cmd->RerecordCmdList(CommandList)) - ->SetGraphicsRootShaderResourceView(idx, pRes->GetGPUVirtualAddress() + byteOffset); + if(m_Cmd->m_RenderState.graphics.sigelems.size() < RootParameterIndex + 1) + m_Cmd->m_RenderState.graphics.sigelems.resize(RootParameterIndex + 1); - if(m_Cmd->m_RenderState.graphics.sigelems.size() < idx + 1) - m_Cmd->m_RenderState.graphics.sigelems.resize(idx + 1); - - m_Cmd->m_RenderState.graphics.sigelems[idx] = - D3D12RenderState::SignatureElement(eRootSRV, GetResID(pRes), byteOffset); + m_Cmd->m_RenderState.graphics.sigelems[RootParameterIndex] = + D3D12RenderState::SignatureElement(eRootSRV, id, offs); + } } - } - else if(m_State == READING) - { - WrappedID3D12Resource *pRes = GetResourceManager()->GetLiveAs(buffer); + else + { + Unwrap(pCommandList)->SetGraphicsRootShaderResourceView(RootParameterIndex, BufferLocation); + GetCrackedList()->SetGraphicsRootShaderResourceView(RootParameterIndex, BufferLocation); - GetList(CommandList) - ->SetGraphicsRootShaderResourceView(idx, pRes->GetGPUVirtualAddress() + byteOffset); - GetCrackedList(CommandList) - ->SetGraphicsRootShaderResourceView(idx, pRes->GetGPUVirtualAddress() + byteOffset); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + if(state.graphics.sigelems.size() < RootParameterIndex + 1) + state.graphics.sigelems.resize(RootParameterIndex + 1); - if(state.graphics.sigelems.size() < idx + 1) - state.graphics.sigelems.resize(idx + 1); - - state.graphics.sigelems[idx] = - D3D12RenderState::SignatureElement(eRootSRV, GetResID(pRes), byteOffset); + state.graphics.sigelems[RootParameterIndex] = + D3D12RenderState::SignatureElement(eRootSRV, id, offs); + } } return true; @@ -2182,10 +2216,11 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRootShaderResourceView( { m_pReal->SetGraphicsRootShaderResourceView(RootParameterIndex, BufferLocation); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_GFX_ROOT_SRV); - Serialise_SetGraphicsRootShaderResourceView(RootParameterIndex, BufferLocation); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetGraphicsRootShaderResourceView); + Serialise_SetGraphicsRootShaderResourceView(ser, RootParameterIndex, BufferLocation); ResourceId id; UINT64 offs = 0; @@ -2196,60 +2231,55 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRootShaderResourceView( } } +template bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootUnorderedAccessView( - UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation) + SerialiserType &ser, UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation) { - ResourceId id; - UINT64 offs = 0; + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(RootParameterIndex); + SERIALISE_ELEMENT_TYPED(D3D12BufferLocation, BufferLocation); + + if(IsReplayingAndReading()) + { + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(ValidateRootGPUVA(BufferLocation)) + return true; + + ResourceId id; + uint64_t offs; - if(m_State >= WRITING) WrappedID3D12Resource::GetResIDFromAddr(BufferLocation, id, offs); - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, idx, RootParameterIndex); - SERIALISE_ELEMENT(ResourceId, buffer, id); - SERIALISE_ELEMENT(UINT64, byteOffset, offs); - - if(m_State < WRITING) - { - m_Cmd->m_LastCmdListID = CommandList; - - if(ValidateRootGPUVA(buffer)) - return true; - } - - if(m_State == EXECUTING) - { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - WrappedID3D12Resource *pRes = GetResourceManager()->GetLiveAs(buffer); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->SetGraphicsRootUnorderedAccessView(RootParameterIndex, BufferLocation); - Unwrap(m_Cmd->RerecordCmdList(CommandList)) - ->SetGraphicsRootUnorderedAccessView(idx, pRes->GetGPUVirtualAddress() + byteOffset); + if(m_Cmd->m_RenderState.graphics.sigelems.size() < RootParameterIndex + 1) + m_Cmd->m_RenderState.graphics.sigelems.resize(RootParameterIndex + 1); - if(m_Cmd->m_RenderState.graphics.sigelems.size() < idx + 1) - m_Cmd->m_RenderState.graphics.sigelems.resize(idx + 1); - - m_Cmd->m_RenderState.graphics.sigelems[idx] = - D3D12RenderState::SignatureElement(eRootUAV, GetResID(pRes), byteOffset); + m_Cmd->m_RenderState.graphics.sigelems[RootParameterIndex] = + D3D12RenderState::SignatureElement(eRootUAV, id, offs); + } } - } - else if(m_State == READING) - { - WrappedID3D12Resource *pRes = GetResourceManager()->GetLiveAs(buffer); + else + { + Unwrap(pCommandList)->SetGraphicsRootUnorderedAccessView(RootParameterIndex, BufferLocation); + GetCrackedList()->SetGraphicsRootUnorderedAccessView(RootParameterIndex, BufferLocation); - GetList(CommandList) - ->SetGraphicsRootUnorderedAccessView(idx, pRes->GetGPUVirtualAddress() + byteOffset); - GetCrackedList(CommandList) - ->SetGraphicsRootUnorderedAccessView(idx, pRes->GetGPUVirtualAddress() + byteOffset); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + if(state.graphics.sigelems.size() < RootParameterIndex + 1) + state.graphics.sigelems.resize(RootParameterIndex + 1); - if(state.graphics.sigelems.size() < idx + 1) - state.graphics.sigelems.resize(idx + 1); - - state.graphics.sigelems[idx] = - D3D12RenderState::SignatureElement(eRootUAV, GetResID(pRes), byteOffset); + state.graphics.sigelems[RootParameterIndex] = + D3D12RenderState::SignatureElement(eRootUAV, id, offs); + } } return true; @@ -2260,10 +2290,11 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRootUnorderedAccessView( { m_pReal->SetGraphicsRootUnorderedAccessView(RootParameterIndex, BufferLocation); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_GFX_ROOT_UAV); - Serialise_SetGraphicsRootUnorderedAccessView(RootParameterIndex, BufferLocation); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetGraphicsRootUnorderedAccessView); + Serialise_SetGraphicsRootUnorderedAccessView(ser, RootParameterIndex, BufferLocation); ResourceId id; UINT64 offs = 0; @@ -2278,32 +2309,31 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRootUnorderedAccessView( #pragma region Queries / Events -bool WrappedID3D12GraphicsCommandList::Serialise_BeginQuery(ID3D12QueryHeap *pQueryHeap, +template +bool WrappedID3D12GraphicsCommandList::Serialise_BeginQuery(SerialiserType &ser, + ID3D12QueryHeap *pQueryHeap, D3D12_QUERY_TYPE Type, UINT Index) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(ResourceId, heap, GetResID(pQueryHeap)); - SERIALISE_ELEMENT(D3D12_QUERY_TYPE, type, Type); - SERIALISE_ELEMENT(UINT, idx, Index); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(pQueryHeap); + SERIALISE_ELEMENT(Type); + SERIALISE_ELEMENT(Index); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) + { + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + } + } + else { - pQueryHeap = GetResourceManager()->GetLiveAs(heap); - - // Unwrap(m_Cmd->RerecordCmdList(CommandList))->BeginQuery(Unwrap(pQueryHeap), type, idx); } - } - else if(m_State == READING) - { - pQueryHeap = GetResourceManager()->GetLiveAs(heap); - - // GetList(CommandList)->BeginQuery(Unwrap(pQueryHeap), type, idx); - // GetCrackedList(CommandList)->BeginQuery(Unwrap(pQueryHeap), type, idx); } return true; @@ -2314,10 +2344,11 @@ void WrappedID3D12GraphicsCommandList::BeginQuery(ID3D12QueryHeap *pQueryHeap, { m_pReal->BeginQuery(Unwrap(pQueryHeap), Type, Index); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(BEGIN_QUERY); - Serialise_BeginQuery(pQueryHeap, Type, Index); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_BeginQuery); + Serialise_BeginQuery(ser, pQueryHeap, Type, Index); m_ListRecord->AddChunk(scope.Get()); @@ -2325,32 +2356,31 @@ void WrappedID3D12GraphicsCommandList::BeginQuery(ID3D12QueryHeap *pQueryHeap, } } -bool WrappedID3D12GraphicsCommandList::Serialise_EndQuery(ID3D12QueryHeap *pQueryHeap, +template +bool WrappedID3D12GraphicsCommandList::Serialise_EndQuery(SerialiserType &ser, + ID3D12QueryHeap *pQueryHeap, D3D12_QUERY_TYPE Type, UINT Index) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(ResourceId, heap, GetResID(pQueryHeap)); - SERIALISE_ELEMENT(D3D12_QUERY_TYPE, type, Type); - SERIALISE_ELEMENT(UINT, idx, Index); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(pQueryHeap); + SERIALISE_ELEMENT(Type); + SERIALISE_ELEMENT(Index); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) + { + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + } + } + else { - pQueryHeap = GetResourceManager()->GetLiveAs(heap); - - // Unwrap(m_Cmd->RerecordCmdList(CommandList))->EndQuery(Unwrap(pQueryHeap), type, idx); } - } - else if(m_State == READING) - { - pQueryHeap = GetResourceManager()->GetLiveAs(heap); - - // GetList(CommandList)->EndQuery(Unwrap(pQueryHeap), type, idx); - // GetCrackedList(CommandList)->EndQuery(Unwrap(pQueryHeap), type, idx); } return true; @@ -2361,10 +2391,12 @@ void WrappedID3D12GraphicsCommandList::EndQuery(ID3D12QueryHeap *pQueryHeap, D3D { m_pReal->EndQuery(Unwrap(pQueryHeap), Type, Index); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(END_QUERY); - Serialise_EndQuery(pQueryHeap, Type, Index); + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_EndQuery); + Serialise_EndQuery(ser, pQueryHeap, Type, Index); m_ListRecord->AddChunk(scope.Get()); @@ -2372,43 +2404,34 @@ void WrappedID3D12GraphicsCommandList::EndQuery(ID3D12QueryHeap *pQueryHeap, D3D } } +template bool WrappedID3D12GraphicsCommandList::Serialise_ResolveQueryData( - ID3D12QueryHeap *pQueryHeap, D3D12_QUERY_TYPE Type, UINT StartIndex, UINT NumQueries, - ID3D12Resource *pDestinationBuffer, UINT64 AlignedDestinationBufferOffset) + SerialiserType &ser, ID3D12QueryHeap *pQueryHeap, D3D12_QUERY_TYPE Type, UINT StartIndex, + UINT NumQueries, ID3D12Resource *pDestinationBuffer, UINT64 AlignedDestinationBufferOffset) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(ResourceId, heap, GetResID(pQueryHeap)); - SERIALISE_ELEMENT(D3D12_QUERY_TYPE, type, Type); - SERIALISE_ELEMENT(UINT, start, StartIndex); - SERIALISE_ELEMENT(UINT, num, NumQueries); - SERIALISE_ELEMENT(ResourceId, buf, GetResID(pDestinationBuffer)); - SERIALISE_ELEMENT(UINT64, offs, AlignedDestinationBufferOffset); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(pQueryHeap); + SERIALISE_ELEMENT(Type); + SERIALISE_ELEMENT(StartIndex); + SERIALISE_ELEMENT(NumQueries); + SERIALISE_ELEMENT(pDestinationBuffer); + SERIALISE_ELEMENT(AlignedDestinationBufferOffset); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) + { + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + } + } + else { - pQueryHeap = GetResourceManager()->GetLiveAs(heap); - pDestinationBuffer = GetResourceManager()->GetLiveAs(buf); - - /* - Unwrap(m_Cmd->RerecordCmdList(CommandList)) - ->ResolveQueryData(Unwrap(pQueryHeap), type, start, num, Unwrap(pDestinationBuffer), - offs);*/ } - } - else if(m_State == READING) - { - pQueryHeap = GetResourceManager()->GetLiveAs(heap); - pDestinationBuffer = GetResourceManager()->GetLiveAs(buf); - - // GetList(CommandList)->ResolveQueryData(Unwrap(pQueryHeap), type, start, num, - // Unwrap(pDestinationBuffer), offs); - // GetCrackedList(CommandList)->ResolveQueryData(Unwrap(pQueryHeap), type, start, num, - // Unwrap(pDestinationBuffer), offs); } return true; @@ -2423,10 +2446,11 @@ void WrappedID3D12GraphicsCommandList::ResolveQueryData(ID3D12QueryHeap *pQueryH m_pReal->ResolveQueryData(Unwrap(pQueryHeap), Type, StartIndex, NumQueries, Unwrap(pDestinationBuffer), AlignedDestinationBufferOffset); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(RESOLVE_QUERY); - Serialise_ResolveQueryData(pQueryHeap, Type, StartIndex, NumQueries, pDestinationBuffer, + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_ResolveQueryData); + Serialise_ResolveQueryData(ser, pQueryHeap, Type, StartIndex, NumQueries, pDestinationBuffer, AlignedDestinationBufferOffset); m_ListRecord->AddChunk(scope.Get()); @@ -2436,19 +2460,24 @@ void WrappedID3D12GraphicsCommandList::ResolveQueryData(ID3D12QueryHeap *pQueryH } } -bool WrappedID3D12GraphicsCommandList::Serialise_SetPredication(ID3D12Resource *pBuffer, +template +bool WrappedID3D12GraphicsCommandList::Serialise_SetPredication(SerialiserType &ser, + ID3D12Resource *pBuffer, UINT64 AlignedBufferOffset, D3D12_PREDICATION_OP Operation) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(ResourceId, buffer, GetResID(pBuffer)); - SERIALISE_ELEMENT(UINT64, offs, AlignedBufferOffset); - SERIALISE_ELEMENT(D3D12_PREDICATION_OP, op, Operation); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(pBuffer); + SERIALISE_ELEMENT(AlignedBufferOffset); + SERIALISE_ELEMENT(Operation); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; + if(IsReplayingAndReading()) + { + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); - // don't replay predication at all + // don't replay predication at all + } return true; } @@ -2459,10 +2488,11 @@ void WrappedID3D12GraphicsCommandList::SetPredication(ID3D12Resource *pBuffer, { m_pReal->SetPredication(Unwrap(pBuffer), AlignedBufferOffset, Operation); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_PREDICATION); - Serialise_SetPredication(pBuffer, AlignedBufferOffset, Operation); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_SetPredication); + Serialise_SetPredication(ser, pBuffer, AlignedBufferOffset, Operation); m_ListRecord->AddChunk(scope.Get()); m_ListRecord->MarkResourceFrameReferenced(GetResID(pBuffer), eFrameRef_Read); @@ -2638,25 +2668,27 @@ inline string PIX3DecodeEventString(const UINT64 *pData) return formatString; } -bool WrappedID3D12GraphicsCommandList::Serialise_SetMarker(UINT Metadata, const void *pData, UINT Size) +template +bool WrappedID3D12GraphicsCommandList::Serialise_SetMarker(SerialiserType &ser, UINT Metadata, + const void *pData, UINT Size) { - string markerText = ""; + std::string MarkerText = ""; - if(m_State >= WRITING && pData && Size) + if(ser.IsWriting() && pData && Size) { if(Metadata == PIX_EVENT_UNICODE_VERSION) { const wchar_t *w = (const wchar_t *)pData; - markerText = StringFormat::Wide2UTF8(std::wstring(w, w + Size)); + MarkerText = StringFormat::Wide2UTF8(std::wstring(w, w + Size)); } else if(Metadata == PIX_EVENT_ANSI_VERSION) { const char *c = (const char *)pData; - markerText = string(c, c + Size); + MarkerText = string(c, c + Size); } else if(Metadata == PIX_EVENT_PIX3BLOB_VERSION) { - markerText = PIX3DecodeEventString((UINT64 *)pData); + MarkerText = PIX3DecodeEventString((UINT64 *)pData); } else { @@ -2664,31 +2696,35 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetMarker(UINT Metadata, const } } - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - m_pSerialiser->Serialise("MarkerText", markerText); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(MarkerText); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(CommandList); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); - D3D12MarkerRegion::Set(list, markerText); + D3D12MarkerRegion::Set(list, MarkerText); + } } - } - else if(m_State == READING) - { - D3D12MarkerRegion::Set(GetWrappedList(CommandList), markerText); - D3D12MarkerRegion::Set(GetWrappedCrackedList(CommandList), markerText); + else + { + D3D12MarkerRegion::Set(pCommandList, MarkerText); + D3D12MarkerRegion::Set(GetWrappedCrackedList(), MarkerText); - DrawcallDescription draw; - draw.name = markerText; - draw.flags |= DrawFlags::SetMarker; + DrawcallDescription draw; + draw.name = MarkerText; + draw.flags |= DrawFlags::SetMarker; - m_Cmd->AddDrawcall(draw, false); + m_Cmd->AddDrawcall(draw, false); + } } return true; @@ -2701,35 +2737,38 @@ void WrappedID3D12GraphicsCommandList::SetMarker(UINT Metadata, const void *pDat if(m_AMDMarkers && Metadata == PIX_EVENT_UNICODE_VERSION) m_AMDMarkers->SetMarker(StringFormat::Wide2UTF8((const wchar_t *)pData).c_str()); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(SET_MARKER); - Serialise_SetMarker(Metadata, pData, Size); + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::SetMarker); + Serialise_SetMarker(ser, Metadata, pData, Size); m_ListRecord->AddChunk(scope.Get()); } } -bool WrappedID3D12GraphicsCommandList::Serialise_BeginEvent(UINT Metadata, const void *pData, - UINT Size) +template +bool WrappedID3D12GraphicsCommandList::Serialise_BeginEvent(SerialiserType &ser, UINT Metadata, + const void *pData, UINT Size) { - string markerText = ""; + std::string MarkerText = ""; - if(m_State >= WRITING && pData && Size) + if(ser.IsWriting() && pData && Size) { if(Metadata == PIX_EVENT_UNICODE_VERSION) { const wchar_t *w = (const wchar_t *)pData; - markerText = StringFormat::Wide2UTF8(std::wstring(w, w + Size)); + MarkerText = StringFormat::Wide2UTF8(std::wstring(w, w + Size)); } else if(Metadata == PIX_EVENT_ANSI_VERSION) { const char *c = (const char *)pData; - markerText = string(c, c + Size); + MarkerText = string(c, c + Size); } else if(Metadata == PIX_EVENT_PIX3BLOB_VERSION) { - markerText = PIX3DecodeEventString((UINT64 *)pData); + MarkerText = PIX3DecodeEventString((UINT64 *)pData); } else { @@ -2737,33 +2776,37 @@ bool WrappedID3D12GraphicsCommandList::Serialise_BeginEvent(UINT Metadata, const } } - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - m_pSerialiser->Serialise("MarkerText", markerText); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(MarkerText); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(CommandList); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); - m_Cmd->m_BakedCmdListInfo[CommandList].markerCount++; + m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].markerCount++; - D3D12MarkerRegion::Begin(list, markerText); + D3D12MarkerRegion::Begin(list, MarkerText); + } } - } - else if(m_State == READING) - { - D3D12MarkerRegion::Begin(GetWrappedList(CommandList), markerText); - D3D12MarkerRegion::Begin(GetWrappedCrackedList(CommandList), markerText); + else + { + D3D12MarkerRegion::Begin(pCommandList, MarkerText); + D3D12MarkerRegion::Begin(GetWrappedCrackedList(), MarkerText); - DrawcallDescription draw; - draw.name = markerText; - draw.flags |= DrawFlags::PushMarker; + DrawcallDescription draw; + draw.name = MarkerText; + draw.flags |= DrawFlags::PushMarker; - m_Cmd->AddDrawcall(draw, false); + m_Cmd->AddDrawcall(draw, false); + } } return true; @@ -2776,55 +2819,62 @@ void WrappedID3D12GraphicsCommandList::BeginEvent(UINT Metadata, const void *pDa if(m_AMDMarkers && Metadata == PIX_EVENT_UNICODE_VERSION) m_AMDMarkers->PushMarker(StringFormat::Wide2UTF8((const wchar_t *)pData).c_str()); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(BEGIN_EVENT); - Serialise_BeginEvent(Metadata, pData, Size); + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::PushMarker); + Serialise_BeginEvent(ser, Metadata, pData, Size); m_ListRecord->AddChunk(scope.Get()); } } -bool WrappedID3D12GraphicsCommandList::Serialise_EndEvent() +template +bool WrappedID3D12GraphicsCommandList::Serialise_EndEvent(SerialiserType &ser) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == READING && !m_Cmd->m_BakedCmdListInfo[CommandList].curEvents.empty()) + if(IsReplayingAndReading()) { - DrawcallDescription draw; - draw.name = "API Calls"; - draw.flags = DrawFlags::SetMarker | DrawFlags::APICalls; + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); - m_Cmd->AddDrawcall(draw, true); - } - - if(m_State == EXECUTING) - { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(CommandList); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); - int &markerCount = m_Cmd->m_BakedCmdListInfo[CommandList].markerCount; - markerCount = RDCMAX(0, markerCount - 1); + int &markerCount = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].markerCount; + markerCount = RDCMAX(0, markerCount - 1); - D3D12MarkerRegion::End(list); + D3D12MarkerRegion::End(list); + } } - } - else if(m_State == READING) - { - D3D12MarkerRegion::End(GetWrappedList(CommandList)); - D3D12MarkerRegion::End(GetWrappedCrackedList(CommandList)); + else + { + if(!m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].curEvents.empty()) + { + DrawcallDescription draw; + draw.name = "API Calls"; + draw.flags = DrawFlags::SetMarker | DrawFlags::APICalls; - // dummy draw that is consumed when this command buffer - // is being in-lined into the call stream - DrawcallDescription draw; - draw.name = "Pop()"; - draw.flags = DrawFlags::PopMarker; + m_Cmd->AddDrawcall(draw, true); + } - m_Cmd->AddDrawcall(draw, false); + D3D12MarkerRegion::End(pCommandList); + D3D12MarkerRegion::End(GetWrappedCrackedList()); + + // dummy draw that is consumed when this command buffer + // is being in-lined into the call stream + DrawcallDescription draw; + draw.name = "Pop()"; + draw.flags = DrawFlags::PopMarker; + + m_Cmd->AddDrawcall(draw, false); + } } return true; @@ -2837,10 +2887,12 @@ void WrappedID3D12GraphicsCommandList::EndEvent() if(m_AMDMarkers) m_AMDMarkers->PopMarker(); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(END_EVENT); - Serialise_EndEvent(); + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::PopMarker); + Serialise_EndEvent(ser); m_ListRecord->AddChunk(scope.Get()); } @@ -2850,58 +2902,66 @@ void WrappedID3D12GraphicsCommandList::EndEvent() #pragma region Draws -bool WrappedID3D12GraphicsCommandList::Serialise_DrawInstanced(UINT VertexCountPerInstance, +template +bool WrappedID3D12GraphicsCommandList::Serialise_DrawInstanced(SerialiserType &ser, + UINT VertexCountPerInstance, UINT InstanceCount, UINT StartVertexLocation, UINT StartInstanceLocation) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, vtxCount, VertexCountPerInstance); - SERIALISE_ELEMENT(UINT, instCount, InstanceCount); - SERIALISE_ELEMENT(UINT, startVtx, StartVertexLocation); - SERIALISE_ELEMENT(UINT, startInst, StartInstanceLocation); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(VertexCountPerInstance); + SERIALISE_ELEMENT(InstanceCount); + SERIALISE_ELEMENT(StartVertexLocation); + SERIALISE_ELEMENT(StartInstanceLocation); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(CommandList); - - uint32_t eventID = m_Cmd->HandlePreCallback(list); - - Unwrap(list)->DrawInstanced(vtxCount, instCount, startVtx, startInst); - - if(eventID && m_Cmd->m_DrawcallCallback->PostDraw(eventID, list)) + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - Unwrap(list)->DrawInstanced(vtxCount, instCount, startVtx, startInst); - m_Cmd->m_DrawcallCallback->PostRedraw(eventID, list); + ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + + uint32_t eventID = m_Cmd->HandlePreCallback(list); + + Unwrap(list)->DrawInstanced(VertexCountPerInstance, InstanceCount, StartVertexLocation, + StartInstanceLocation); + + if(eventID && m_Cmd->m_DrawcallCallback->PostDraw(eventID, list)) + { + Unwrap(list)->DrawInstanced(VertexCountPerInstance, InstanceCount, StartVertexLocation, + StartInstanceLocation); + m_Cmd->m_DrawcallCallback->PostRedraw(eventID, list); + } } } - } - else if(m_State == READING) - { - GetList(CommandList)->DrawInstanced(vtxCount, instCount, startVtx, startInst); - GetCrackedList(CommandList)->DrawInstanced(vtxCount, instCount, startVtx, startInst); + else + { + Unwrap(pCommandList) + ->DrawInstanced(VertexCountPerInstance, InstanceCount, StartVertexLocation, + StartInstanceLocation); + GetCrackedList()->DrawInstanced(VertexCountPerInstance, InstanceCount, StartVertexLocation, + StartInstanceLocation); - const string desc = m_pSerialiser->GetDebugStr(); + m_Cmd->AddEvent(); - m_Cmd->AddEvent(desc); - string name = "DrawInstanced(" + ToStr(vtxCount) + ", " + ToStr(instCount) + ")"; + DrawcallDescription draw; + draw.name = StringFormat::Fmt("DrawInstanced(%u, %u)", VertexCountPerInstance, InstanceCount); + draw.numIndices = VertexCountPerInstance; + draw.numInstances = InstanceCount; + draw.indexOffset = 0; + draw.vertexOffset = StartVertexLocation; + draw.instanceOffset = StartInstanceLocation; - DrawcallDescription draw; - draw.name = name; - draw.numIndices = vtxCount; - draw.numInstances = instCount; - draw.indexOffset = 0; - draw.vertexOffset = startVtx; - draw.instanceOffset = startInst; + draw.flags |= DrawFlags::Drawcall | DrawFlags::Instanced; - draw.flags |= DrawFlags::Drawcall | DrawFlags::Instanced; - - m_Cmd->AddDrawcall(draw, true); + m_Cmd->AddDrawcall(draw, true); + } } return true; @@ -2914,70 +2974,78 @@ void WrappedID3D12GraphicsCommandList::DrawInstanced(UINT VertexCountPerInstance m_pReal->DrawInstanced(VertexCountPerInstance, InstanceCount, StartVertexLocation, StartInstanceLocation); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(DRAW_INST); - Serialise_DrawInstanced(VertexCountPerInstance, InstanceCount, StartVertexLocation, + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_DrawInstanced); + Serialise_DrawInstanced(ser, VertexCountPerInstance, InstanceCount, StartVertexLocation, StartInstanceLocation); m_ListRecord->AddChunk(scope.Get()); } } -bool WrappedID3D12GraphicsCommandList::Serialise_DrawIndexedInstanced(UINT IndexCountPerInstance, - UINT InstanceCount, - UINT StartIndexLocation, - INT BaseVertexLocation, - UINT StartInstanceLocation) +template +bool WrappedID3D12GraphicsCommandList::Serialise_DrawIndexedInstanced( + SerialiserType &ser, UINT IndexCountPerInstance, UINT InstanceCount, UINT StartIndexLocation, + INT BaseVertexLocation, UINT StartInstanceLocation) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, idxCount, IndexCountPerInstance); - SERIALISE_ELEMENT(UINT, instCount, InstanceCount); - SERIALISE_ELEMENT(UINT, startIdx, StartIndexLocation); - SERIALISE_ELEMENT(INT, startVtx, BaseVertexLocation); - SERIALISE_ELEMENT(UINT, startInst, StartInstanceLocation); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(IndexCountPerInstance); + SERIALISE_ELEMENT(InstanceCount); + SERIALISE_ELEMENT(StartIndexLocation); + SERIALISE_ELEMENT(BaseVertexLocation); + SERIALISE_ELEMENT(StartInstanceLocation); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(CommandList); - - uint32_t eventID = m_Cmd->HandlePreCallback(list); - - Unwrap(list)->DrawIndexedInstanced(idxCount, instCount, startIdx, startVtx, startInst); - - if(eventID && m_Cmd->m_DrawcallCallback->PostDraw(eventID, list)) + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - Unwrap(list)->DrawIndexedInstanced(idxCount, instCount, startIdx, startVtx, startInst); - m_Cmd->m_DrawcallCallback->PostRedraw(eventID, list); + ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + + uint32_t eventID = m_Cmd->HandlePreCallback(list); + + Unwrap(list)->DrawIndexedInstanced(IndexCountPerInstance, InstanceCount, StartIndexLocation, + BaseVertexLocation, StartInstanceLocation); + + if(eventID && m_Cmd->m_DrawcallCallback->PostDraw(eventID, list)) + { + Unwrap(list)->DrawIndexedInstanced(IndexCountPerInstance, InstanceCount, StartIndexLocation, + BaseVertexLocation, StartInstanceLocation); + m_Cmd->m_DrawcallCallback->PostRedraw(eventID, list); + } } } - } - else if(m_State == READING) - { - GetList(CommandList)->DrawIndexedInstanced(idxCount, instCount, startIdx, startVtx, startInst); - GetCrackedList(CommandList)->DrawIndexedInstanced(idxCount, instCount, startIdx, startVtx, startInst); + else + { + Unwrap(pCommandList) + ->DrawIndexedInstanced(IndexCountPerInstance, InstanceCount, StartIndexLocation, + BaseVertexLocation, StartInstanceLocation); + GetCrackedList()->DrawIndexedInstanced(IndexCountPerInstance, InstanceCount, StartIndexLocation, + BaseVertexLocation, StartInstanceLocation); - const string desc = m_pSerialiser->GetDebugStr(); + m_Cmd->AddEvent(); - m_Cmd->AddEvent(desc); - string name = "DrawIndexedInstanced(" + ToStr(idxCount) + ", " + ToStr(instCount) + ")"; + DrawcallDescription draw; + draw.name = + StringFormat::Fmt("DrawIndexedInstanced(%u, %u)", IndexCountPerInstance, InstanceCount); + draw.numIndices = IndexCountPerInstance; + draw.numInstances = InstanceCount; + draw.indexOffset = StartIndexLocation; + draw.baseVertex = BaseVertexLocation; + draw.instanceOffset = StartInstanceLocation; - DrawcallDescription draw; - draw.name = name; - draw.numIndices = idxCount; - draw.numInstances = instCount; - draw.indexOffset = startIdx; - draw.baseVertex = startVtx; - draw.instanceOffset = startInst; + draw.flags |= DrawFlags::Drawcall | DrawFlags::Instanced | DrawFlags::UseIBuffer; - draw.flags |= DrawFlags::Drawcall | DrawFlags::Instanced | DrawFlags::UseIBuffer; - - m_Cmd->AddDrawcall(draw, true); + m_Cmd->AddDrawcall(draw, true); + } } return true; @@ -2992,64 +3060,69 @@ void WrappedID3D12GraphicsCommandList::DrawIndexedInstanced(UINT IndexCountPerIn m_pReal->DrawIndexedInstanced(IndexCountPerInstance, InstanceCount, StartIndexLocation, BaseVertexLocation, StartInstanceLocation); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(DRAW_INDEXED_INST); - Serialise_DrawIndexedInstanced(IndexCountPerInstance, InstanceCount, StartIndexLocation, + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_DrawIndexedInstanced); + Serialise_DrawIndexedInstanced(ser, IndexCountPerInstance, InstanceCount, StartIndexLocation, BaseVertexLocation, StartInstanceLocation); m_ListRecord->AddChunk(scope.Get()); } } -bool WrappedID3D12GraphicsCommandList::Serialise_Dispatch(UINT ThreadGroupCountX, +template +bool WrappedID3D12GraphicsCommandList::Serialise_Dispatch(SerialiserType &ser, UINT ThreadGroupCountX, UINT ThreadGroupCountY, UINT ThreadGroupCountZ) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(UINT, x, ThreadGroupCountX); - SERIALISE_ELEMENT(UINT, y, ThreadGroupCountY); - SERIALISE_ELEMENT(UINT, z, ThreadGroupCountZ); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(ThreadGroupCountX); + SERIALISE_ELEMENT(ThreadGroupCountY); + SERIALISE_ELEMENT(ThreadGroupCountZ); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(CommandList); - - uint32_t eventID = m_Cmd->HandlePreCallback(list, true); - - Unwrap(list)->Dispatch(x, y, z); - - if(eventID && m_Cmd->m_DrawcallCallback->PostDraw(eventID, list)) + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - Unwrap(list)->Dispatch(x, y, z); - m_Cmd->m_DrawcallCallback->PostRedraw(eventID, list); + ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + + uint32_t eventID = m_Cmd->HandlePreCallback(list, true); + + Unwrap(list)->Dispatch(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); + + if(eventID && m_Cmd->m_DrawcallCallback->PostDraw(eventID, list)) + { + Unwrap(list)->Dispatch(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); + m_Cmd->m_DrawcallCallback->PostRedraw(eventID, list); + } } } - } - else if(m_State == READING) - { - GetList(CommandList)->Dispatch(x, y, z); - GetCrackedList(CommandList)->Dispatch(x, y, z); + else + { + Unwrap(pCommandList)->Dispatch(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); + GetCrackedList()->Dispatch(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); - const string desc = m_pSerialiser->GetDebugStr(); + m_Cmd->AddEvent(); - m_Cmd->AddEvent(desc); - string name = "Dispatch(" + ToStr(x) + ", " + ToStr(y) + ", " + ToStr(z) + ")"; + DrawcallDescription draw; + draw.name = StringFormat::Fmt("Dispatch(%u, %u, %u)", ThreadGroupCountX, ThreadGroupCountY, + ThreadGroupCountZ); + draw.dispatchDimension[0] = ThreadGroupCountX; + draw.dispatchDimension[1] = ThreadGroupCountY; + draw.dispatchDimension[2] = ThreadGroupCountZ; - DrawcallDescription draw; - draw.name = name; - draw.dispatchDimension[0] = x; - draw.dispatchDimension[1] = y; - draw.dispatchDimension[2] = z; + draw.flags |= DrawFlags::Dispatch; - draw.flags |= DrawFlags::Dispatch; - - m_Cmd->AddDrawcall(draw, true); + m_Cmd->AddDrawcall(draw, true); + } } return true; @@ -3060,73 +3133,62 @@ void WrappedID3D12GraphicsCommandList::Dispatch(UINT ThreadGroupCountX, UINT Thr { m_pReal->Dispatch(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(DISPATCH); - Serialise_Dispatch(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_Dispatch); + Serialise_Dispatch(ser, ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); m_ListRecord->AddChunk(scope.Get()); } } -bool WrappedID3D12GraphicsCommandList::Serialise_ExecuteBundle(ID3D12GraphicsCommandList *pCommandList) +template +bool WrappedID3D12GraphicsCommandList::Serialise_ExecuteBundle(SerialiserType &ser, + ID3D12GraphicsCommandList *pBundle) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(pBundle); - ResourceId Bundle; - - if(m_State >= WRITING) + if(IsReplayingAndReading()) { - D3D12ResourceRecord *record = GetRecord(pCommandList); - RDCASSERT(record->bakedCommands); - if(record->bakedCommands) - Bundle = record->bakedCommands->GetResourceID(); - } + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); - m_pSerialiser->Serialise("Bundle", Bundle); - - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) - { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(CommandList); - - uint32_t eventID = m_Cmd->HandlePreCallback(list, true); - - ID3D12GraphicsCommandList *bundle = - GetResourceManager()->GetLiveAs(Bundle); - - Unwrap(list)->ExecuteBundle(Unwrap(bundle)); - - if(eventID && m_Cmd->m_DrawcallCallback->PostDraw(eventID, list)) + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - Unwrap(list)->ExecuteBundle(Unwrap(bundle)); - m_Cmd->m_DrawcallCallback->PostRedraw(eventID, list); + ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + + uint32_t eventID = m_Cmd->HandlePreCallback(list, true); + + Unwrap(list)->ExecuteBundle(Unwrap(pBundle)); + + if(eventID && m_Cmd->m_DrawcallCallback->PostDraw(eventID, list)) + { + Unwrap(list)->ExecuteBundle(Unwrap(pBundle)); + m_Cmd->m_DrawcallCallback->PostRedraw(eventID, list); + } } } - } - else if(m_State == READING) - { - ID3D12GraphicsCommandList *bundle = - GetResourceManager()->GetLiveAs(Bundle); + else + { + Unwrap(pCommandList)->ExecuteBundle(Unwrap(pBundle)); + GetCrackedList()->ExecuteBundle(Unwrap(pBundle)); - GetList(CommandList)->ExecuteBundle(Unwrap(bundle)); - GetCrackedList(CommandList)->ExecuteBundle(Unwrap(bundle)); + m_Cmd->AddEvent(); - const string desc = m_pSerialiser->GetDebugStr(); + DrawcallDescription draw; + draw.name = StringFormat::Fmt("ExecuteBundle(%s)", + ToStr(GetResourceManager()->GetOriginalID(GetResID(pBundle)))); - m_Cmd->AddEvent(desc); - string name = "ExecuteBundle(" + ToStr(Bundle) + ")"; + draw.flags |= DrawFlags::CmdList; - DrawcallDescription draw; - draw.name = name; - - draw.flags |= DrawFlags::CmdList; - - m_Cmd->AddDrawcall(draw, true); + m_Cmd->AddDrawcall(draw, true); + } } return true; @@ -3136,10 +3198,12 @@ void WrappedID3D12GraphicsCommandList::ExecuteBundle(ID3D12GraphicsCommandList * { m_pReal->ExecuteBundle(Unwrap(pCommandList)); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(EXEC_BUNDLE); - Serialise_ExecuteBundle(pCommandList); + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_ExecuteBundle); + Serialise_ExecuteBundle(ser, pCommandList); m_ListRecord->AddChunk(scope.Get()); @@ -3155,31 +3219,29 @@ void WrappedID3D12GraphicsCommandList::ExecuteBundle(ID3D12GraphicsCommandList * } /* - * ExecuteIndirect needs special handling - whenever we encounter an ExecuteIndirect during READING + * ExecuteIndirect needs special handling - whenever we encounter an ExecuteIndirect during loading * time we crack the list into two, and copy off the argument buffer in the first part and execute * with the copy destination in the second part. * * Then when we come to ExecuteCommandLists this list, we go step by step through the cracked lists, * executing the first, then syncing to the GPU and patching the argument buffer before continuing. * - * At READING time we reserve a maxCount number of drawcalls and events, and later on when patching + * At loading time we reserve a maxCount number of drawcalls and events, and later on when patching * the argument buffer we fill in the parameters/names and remove any excess draws that weren't * actually executed. * - * During EXECUTING we read the patched argument buffer and execute any commands needed by hand on - * the CPU. + * During active replaying we read the patched argument buffer and execute any commands needed by + * hand on the CPU. */ void WrappedID3D12GraphicsCommandList::ReserveExecuteIndirect(ID3D12GraphicsCommandList *list, - ResourceId sig, UINT maxCount) + WrappedID3D12CommandSignature *comSig, + UINT maxCount) { - WrappedID3D12CommandSignature *comSig = - GetResourceManager()->GetLiveAs(sig); - const bool multidraw = (maxCount > 1 || comSig->sig.numDraws > 1); const uint32_t sigSize = (uint32_t)comSig->sig.arguments.size(); - RDCASSERT(m_State == READING); + RDCASSERT(IsLoading(m_State)); BakedCmdListInfo &cmdInfo = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID]; @@ -3195,7 +3257,7 @@ void WrappedID3D12GraphicsCommandList::ReserveExecuteIndirect(ID3D12GraphicsComm case D3D12_INDIRECT_ARGUMENT_TYPE_DRAW_INDEXED: case D3D12_INDIRECT_ARGUMENT_TYPE_DRAW: // add dummy event and drawcall - m_Cmd->AddEvent(""); + m_Cmd->AddEvent(); m_Cmd->AddDrawcall(DrawcallDescription(), true); cmdInfo.curEventID++; break; @@ -3206,7 +3268,7 @@ void WrappedID3D12GraphicsCommandList::ReserveExecuteIndirect(ID3D12GraphicsComm case D3D12_INDIRECT_ARGUMENT_TYPE_SHADER_RESOURCE_VIEW: case D3D12_INDIRECT_ARGUMENT_TYPE_UNORDERED_ACCESS_VIEW: // add dummy event - m_Cmd->AddEvent(""); + m_Cmd->AddEvent(); cmdInfo.curEventID++; break; default: RDCERR("Unexpected argument type! %d", arg.Type); break; @@ -3234,8 +3296,7 @@ void WrappedID3D12GraphicsCommandList::PatchExecuteIndirect(BakedCmdListInfo &in exec.patched = true; - WrappedID3D12CommandSignature *comSig = - GetResourceManager()->GetLiveAs(exec.sig); + WrappedID3D12CommandSignature *comSig = exec.sig; uint32_t count = exec.maxCount; @@ -3251,7 +3312,6 @@ void WrappedID3D12GraphicsCommandList::PatchExecuteIndirect(BakedCmdListInfo &in const bool multidraw = (count > 1 || comSig->sig.numDraws > 1); const uint32_t sigSize = (uint32_t)comSig->sig.arguments.size(); const bool gfx = comSig->sig.graphics; - const char *sigTypeString = gfx ? "Graphics" : "Compute"; // + 1 is because baseEvent refers to the marker before the commands exec.lastEvent = exec.baseEvent + 1 + sigSize * count; @@ -3313,22 +3373,6 @@ void WrappedID3D12GraphicsCommandList::PatchExecuteIndirect(BakedCmdListInfo &in // assign the draw's EID eid = draw.eventID; - string eventStr = draw.name; - - // a bit of a hack, but manually construct serialised event data for this command - eventStr += "\n{\n"; - eventStr += - StringFormat::Fmt("\tVertexCountPerInstance: %u\n", args->VertexCountPerInstance); - eventStr += StringFormat::Fmt("\tInstanceCount: %u\n", args->InstanceCount); - eventStr += StringFormat::Fmt("\tStartVertexLocation: %u\n", args->StartVertexLocation); - eventStr += StringFormat::Fmt("\tStartInstanceLocation: %u\n", args->StartInstanceLocation); - eventStr += "}\n"; - - APIEvent &ev = draw.events.back(); - ev.eventDesc = eventStr; - - RDCASSERT(ev.eventID == eid); - m_Cmd->AddUsage(draws[idx]); // advance @@ -3358,22 +3402,6 @@ void WrappedID3D12GraphicsCommandList::PatchExecuteIndirect(BakedCmdListInfo &in // assign the draw's EID eid = draw.eventID; - string eventStr = draw.name; - - // a bit of a hack, but manually construct serialised event data for this command - eventStr += "\n{\n"; - eventStr += StringFormat::Fmt("\tIndexCountPerInstance: %u\n", args->IndexCountPerInstance); - eventStr += StringFormat::Fmt("\tInstanceCount: %u\n", args->InstanceCount); - eventStr += StringFormat::Fmt("\tBaseVertexLocation: %u\n", args->BaseVertexLocation); - eventStr += StringFormat::Fmt("\tStartIndexLocation: %u\n", args->StartIndexLocation); - eventStr += StringFormat::Fmt("\tStartInstanceLocation: %u\n", args->StartInstanceLocation); - eventStr += "}\n"; - - APIEvent &ev = draw.events.back(); - ev.eventDesc = eventStr; - - RDCASSERT(ev.eventID == eid); - m_Cmd->AddUsage(draws[idx]); // advance @@ -3401,20 +3429,6 @@ void WrappedID3D12GraphicsCommandList::PatchExecuteIndirect(BakedCmdListInfo &in // assign the draw's EID eid = draw.eventID; - string eventStr = draw.name; - - // a bit of a hack, but manually construct serialised event data for this command - eventStr += "\n{\n"; - eventStr += StringFormat::Fmt("\tThreadGroupCountX: %u\n", args->ThreadGroupCountX); - eventStr += StringFormat::Fmt("\tThreadGroupCountY: %u\n", args->ThreadGroupCountY); - eventStr += StringFormat::Fmt("\tThreadGroupCountZ: %u\n", args->ThreadGroupCountZ); - eventStr += "}\n"; - - APIEvent &ev = draw.events.back(); - ev.eventDesc = eventStr; - - RDCASSERT(ev.eventID == eid); - m_Cmd->AddUsage(draws[idx]); // advance @@ -3426,39 +3440,8 @@ void WrappedID3D12GraphicsCommandList::PatchExecuteIndirect(BakedCmdListInfo &in case D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT: { size_t argSize = sizeof(uint32_t) * arg.Constant.Num32BitValuesToSet; - uint32_t *values = (uint32_t *)data; data += argSize; - string name = StringFormat::Fmt("[%u] arg%u: IndirectSet%sRoot32bitConstants()\n", i, a, - sigTypeString); - - // a bit of a hack, but manually construct serialised event data for this command - name += "{\n"; - name += StringFormat::Fmt("\tConstant.RootParameterIndex: %u\n", - arg.Constant.RootParameterIndex); - name += StringFormat::Fmt("\tConstant.DestOffsetIn32BitValues: %u\n", - arg.Constant.DestOffsetIn32BitValues); - name += StringFormat::Fmt("\tConstant.Num32BitValuesToSet: %u\n", - arg.Constant.Num32BitValuesToSet); - for(uint32_t val = 0; val < arg.Constant.Num32BitValuesToSet; val++) - name += StringFormat::Fmt("\tvalues[%u]: %u\n", val, values[val]); - name += "}\n"; - - DrawcallDescription &draw = draws[idx].draw; - APIEvent *ev = NULL; - - for(APIEvent &e : draw.events) - { - if(e.eventID == eid) - { - ev = &e; - break; - } - } - - if(ev) - ev->eventDesc = name; - // advance only the EID, since we're still in the same draw eid++; @@ -3478,32 +3461,6 @@ void WrappedID3D12GraphicsCommandList::PatchExecuteIndirect(BakedCmdListInfo &in if(res) vb->BufferLocation = res->GetGPUVirtualAddress() + offs; - string name = StringFormat::Fmt("[%u] arg%u: IndirectIASetVertexBuffers()\n", i, a); - - // a bit of a hack, but manually construct serialised event data for this command - name += "{\n"; - name += StringFormat::Fmt("\tVertexBuffer.Slot: %u\n", arg.VertexBuffer.Slot); - name += StringFormat::Fmt("\tView.BufferLocation: %llu\n", id); - name += StringFormat::Fmt("\tView.BufferLocation: %llu\n", offs); - name += StringFormat::Fmt("\tView.SizeInBytes: %u\n", vb->SizeInBytes); - name += StringFormat::Fmt("\tView.StrideInBytes: %u\n", vb->StrideInBytes); - name += "}\n"; - - DrawcallDescription &draw = draws[idx].draw; - APIEvent *ev = NULL; - - for(APIEvent &e : draw.events) - { - if(e.eventID == eid) - { - ev = &e; - break; - } - } - - if(ev) - ev->eventDesc = name; - // advance only the EID, since we're still in the same draw eid++; @@ -3523,31 +3480,6 @@ void WrappedID3D12GraphicsCommandList::PatchExecuteIndirect(BakedCmdListInfo &in if(res) ib->BufferLocation = res->GetGPUVirtualAddress() + offs; - string name = StringFormat::Fmt("[%u] arg%u: IndirectIASetIndexBuffer()\n", i, a); - - // a bit of a hack, but manually construct serialised event data for this command - name += "{\n"; - name += StringFormat::Fmt("\tView.BufferLocation: %llu\n", id); - name += StringFormat::Fmt("\tView.BufferLocation: %llu\n", offs); - name += StringFormat::Fmt("\tView.SizeInBytes: %u\n", ib->SizeInBytes); - name += StringFormat::Fmt("\tView.Format: %s\n", ToStr(ib->Format).c_str()); - name += "}\n"; - - DrawcallDescription &draw = draws[idx].draw; - APIEvent *ev = NULL; - - for(APIEvent &e : draw.events) - { - if(e.eventID == eid) - { - ev = &e; - break; - } - } - - if(ev) - ev->eventDesc = name; - // advance only the EID, since we're still in the same draw eid++; @@ -3569,43 +3501,6 @@ void WrappedID3D12GraphicsCommandList::PatchExecuteIndirect(BakedCmdListInfo &in if(res) *addr = res->GetGPUVirtualAddress() + offs; - const uint32_t rootIdx = arg.Constant.RootParameterIndex; - const char *argTypeString = "Unknown"; - - if(arg.Type == D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT_BUFFER_VIEW) - argTypeString = "ConstantBuffer"; - else if(arg.Type == D3D12_INDIRECT_ARGUMENT_TYPE_SHADER_RESOURCE_VIEW) - argTypeString = "ShaderResource"; - else if(arg.Type == D3D12_INDIRECT_ARGUMENT_TYPE_UNORDERED_ACCESS_VIEW) - argTypeString = "UnorderedAccess"; - else - RDCERR("Unexpected argument type! %d", arg.Type); - - string name = StringFormat::Fmt("[%u] arg%u: IndirectSet%sRoot%sView()\n", i, a, - sigTypeString, argTypeString); - - // a bit of a hack, but manually construct serialised event data for this command - name += "{\n"; - name += StringFormat::Fmt("\tView.RootParameterIndex: %u\n", rootIdx); - name += StringFormat::Fmt("\tBufferLocation: %llu\n", id); - name += StringFormat::Fmt("\tBufferLocation_Offset: %llu\n", offs); - name += "}\n"; - - DrawcallDescription &draw = draws[idx].draw; - APIEvent *ev = NULL; - - for(APIEvent &e : draw.events) - { - if(e.eventID == eid) - { - ev = &e; - break; - } - } - - if(ev) - ev->eventDesc = name; - // advance only the EID, since we're still in the same draw eid++; @@ -3670,8 +3565,7 @@ void WrappedID3D12GraphicsCommandList::ReplayExecuteIndirect(ID3D12GraphicsComma BakedCmdListInfo::ExecuteData &exec = info.executeEvents[executeIndex]; - WrappedID3D12CommandSignature *comSig = - GetResourceManager()->GetLiveAs(exec.sig); + WrappedID3D12CommandSignature *comSig = exec.sig; uint32_t count = exec.realCount; uint32_t origCount = exec.realCount; @@ -3998,135 +3892,132 @@ void WrappedID3D12GraphicsCommandList::ReplayExecuteIndirect(ID3D12GraphicsComma cmdInfo.curEventID++; } +template bool WrappedID3D12GraphicsCommandList::Serialise_ExecuteIndirect( - ID3D12CommandSignature *pCommandSignature, UINT MaxCommandCount, ID3D12Resource *pArgumentBuffer, - UINT64 ArgumentBufferOffset, ID3D12Resource *pCountBuffer, UINT64 CountBufferOffset) + SerialiserType &ser, ID3D12CommandSignature *pCommandSignature, UINT MaxCommandCount, + ID3D12Resource *pArgumentBuffer, UINT64 ArgumentBufferOffset, ID3D12Resource *pCountBuffer, + UINT64 CountBufferOffset) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(ResourceId, sig, GetResID(pCommandSignature)); - SERIALISE_ELEMENT(UINT, maxCount, MaxCommandCount); - SERIALISE_ELEMENT(ResourceId, arg, GetResID(pArgumentBuffer)); - SERIALISE_ELEMENT(UINT64, argOffs, ArgumentBufferOffset); - SERIALISE_ELEMENT(ResourceId, countbuf, GetResID(pCountBuffer)); - SERIALISE_ELEMENT(UINT64, countOffs, CountBufferOffset); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(pCommandSignature); + SERIALISE_ELEMENT(MaxCommandCount); + SERIALISE_ELEMENT(pArgumentBuffer); + SERIALISE_ELEMENT(ArgumentBufferOffset); + SERIALISE_ELEMENT(pCountBuffer); + SERIALISE_ELEMENT(CountBufferOffset); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + if(IsActiveReplaying(m_State)) { - ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(CommandList); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); - BakedCmdListInfo &bakeInfo = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID]; + BakedCmdListInfo &bakeInfo = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID]; - ReplayExecuteIndirect(Unwrap(list), bakeInfo); + ReplayExecuteIndirect(Unwrap(list), bakeInfo); + } } - } - else if(m_State == READING) - { - const string desc = m_pSerialiser->GetDebugStr(); - - WrappedID3D12CommandSignature *comSig = - GetResourceManager()->GetLiveAs(sig); - - ID3D12Resource *argBuf = GetResourceManager()->GetLiveAs(arg); - ID3D12Resource *countBuf = GetResourceManager()->GetLiveAs(countbuf); - - m_Cmd->AddEvent(desc); - - DrawcallDescription draw; - draw.name = "ExecuteIndirect"; - - draw.flags |= DrawFlags::MultiDraw; - - if(maxCount > 1 || comSig->sig.numDraws > 1) - draw.flags |= DrawFlags::PushMarker; else - draw.flags |= DrawFlags::SetMarker; - - // this drawcall needs an event to anchor its file offset. This is a bit of a hack, - // but a proper solution for handling 'fake' events that don't correspond to actual - // events in the file, or duplicates, is overkill. - draw.events = {m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].curEvents.back()}; - m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].curEvents.pop_back(); - - m_Cmd->AddDrawcall(draw, false); - - D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); - - drawNode.resourceUsage.push_back( - std::make_pair(GetResourceManager()->GetLiveID(arg), - EventUsage(drawNode.draw.eventID, ResourceUsage::Indirect))); - drawNode.resourceUsage.push_back( - std::make_pair(GetResourceManager()->GetLiveID(countbuf), - EventUsage(drawNode.draw.eventID, ResourceUsage::Indirect))); - - ID3D12GraphicsCommandList *cracked = GetCrackedList(CommandList); - - BakedCmdListInfo::ExecuteData exec; - exec.baseEvent = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].curEventID; - exec.sig = sig; - exec.maxCount = maxCount; - exec.countBuf = countBuf; - exec.countOffs = countOffs; - - // allocate space for patched indirect buffer - m_Cmd->GetIndirectBuffer(comSig->sig.ByteStride * maxCount, &exec.argBuf, &exec.argOffs); - - // transition buffer to COPY_SOURCE/COPY_DEST, copy, and back to INDIRECT_ARG - D3D12_RESOURCE_BARRIER barriers[2] = {}; - barriers[0].Transition.pResource = Unwrap(argBuf); - barriers[0].Transition.StateBefore = D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT; - barriers[0].Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_SOURCE; - barriers[1].Transition.pResource = Unwrap(exec.argBuf); - barriers[1].Transition.StateBefore = D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT; - barriers[1].Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST; - cracked->ResourceBarrier(2, barriers); - - cracked->CopyBufferRegion(Unwrap(exec.argBuf), exec.argOffs, Unwrap(argBuf), argOffs, - comSig->sig.ByteStride * maxCount); - - std::swap(barriers[0].Transition.StateBefore, barriers[0].Transition.StateAfter); - std::swap(barriers[1].Transition.StateBefore, barriers[1].Transition.StateAfter); - cracked->ResourceBarrier(2, barriers); - - cracked->Close(); - - // open new cracked list and re-apply the current state { - 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; + WrappedID3D12CommandSignature *comSig = (WrappedID3D12CommandSignature *)pCommandSignature; - ResourceId allocid = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].allocator; - ID3D12CommandAllocator *allocator = m_Cmd->m_CrackedAllocators[allocid]; + m_Cmd->AddEvent(); - ID3D12GraphicsCommandList *list = NULL; - m_pDevice->CreateCommandList(nodeMask, type, allocator, NULL, - __uuidof(ID3D12GraphicsCommandList), (void **)&list); + DrawcallDescription draw; + draw.name = "ExecuteIndirect"; - m_Cmd->m_BakedCmdListInfo[CommandList].crackedLists.push_back(list); + draw.flags |= DrawFlags::MultiDraw; - m_Cmd->m_BakedCmdListInfo[CommandList].state.ApplyState(list); + if(MaxCommandCount > 1 || comSig->sig.numDraws > 1) + draw.flags |= DrawFlags::PushMarker; + else + draw.flags |= DrawFlags::SetMarker; + + // this drawcall needs an event to anchor its file offset. This is a bit of a hack, + // but a proper solution for handling 'fake' events that don't correspond to actual + // events in the file, or duplicates, is overkill. + draw.events = {m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].curEvents.back()}; + m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].curEvents.pop_back(); + + m_Cmd->AddDrawcall(draw, false); + + D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); + + drawNode.resourceUsage.push_back(std::make_pair( + GetResID(pArgumentBuffer), EventUsage(drawNode.draw.eventID, ResourceUsage::Indirect))); + drawNode.resourceUsage.push_back(std::make_pair( + GetResID(pCountBuffer), EventUsage(drawNode.draw.eventID, ResourceUsage::Indirect))); + + ID3D12GraphicsCommandList *cracked = GetCrackedList(); + + BakedCmdListInfo::ExecuteData exec; + exec.baseEvent = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].curEventID; + exec.sig = comSig; + exec.maxCount = MaxCommandCount; + exec.countBuf = pCountBuffer; + exec.countOffs = CountBufferOffset; + + // allocate space for patched indirect buffer + m_Cmd->GetIndirectBuffer(comSig->sig.ByteStride * MaxCommandCount, &exec.argBuf, &exec.argOffs); + + // transition buffer to COPY_SOURCE/COPY_DEST, copy, and back to INDIRECT_ARG + D3D12_RESOURCE_BARRIER barriers[2] = {}; + barriers[0].Transition.pResource = Unwrap(pArgumentBuffer); + barriers[0].Transition.StateBefore = D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT; + barriers[0].Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_SOURCE; + barriers[1].Transition.pResource = Unwrap(exec.argBuf); + barriers[1].Transition.StateBefore = D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT; + barriers[1].Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST; + cracked->ResourceBarrier(2, barriers); + + cracked->CopyBufferRegion(Unwrap(exec.argBuf), exec.argOffs, Unwrap(pArgumentBuffer), + ArgumentBufferOffset, comSig->sig.ByteStride * MaxCommandCount); + + std::swap(barriers[0].Transition.StateBefore, barriers[0].Transition.StateAfter); + std::swap(barriers[1].Transition.StateBefore, barriers[1].Transition.StateAfter); + cracked->ResourceBarrier(2, barriers); + + cracked->Close(); + + // open new cracked list and re-apply the current state + { + 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; + + 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, allocator, NULL, + __uuidof(ID3D12GraphicsCommandList), (void **)&list); + + m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].crackedLists.push_back(list); + + m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state.ApplyState(list); + } + + // perform indirect draw, but from patched buffer. It will be patched between the above list + // and this list during the first execution of the command list + Unwrap(pCommandList) + ->ExecuteIndirect(comSig->GetReal(), MaxCommandCount, Unwrap(exec.argBuf), exec.argOffs, + Unwrap(pCountBuffer), CountBufferOffset); + GetCrackedList()->ExecuteIndirect(comSig->GetReal(), MaxCommandCount, Unwrap(exec.argBuf), + exec.argOffs, Unwrap(pCountBuffer), CountBufferOffset); + + m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].executeEvents.push_back(exec); + + m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].curEventID++; + + // reserve the right number of drawcalls and events, to later be patched up with the actual + // details + ReserveExecuteIndirect(pCommandList, comSig, MaxCommandCount); } - - // perform indirect draw, but from patched buffer. It will be patched between the above list and - // this list during the first execution of the command list - GetList(CommandList) - ->ExecuteIndirect(comSig->GetReal(), maxCount, Unwrap(exec.argBuf), exec.argOffs, - Unwrap(countBuf), countOffs); - GetCrackedList(CommandList) - ->ExecuteIndirect(comSig->GetReal(), maxCount, Unwrap(exec.argBuf), exec.argOffs, - Unwrap(countBuf), countOffs); - - m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].executeEvents.push_back(exec); - - m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].curEventID++; - - // reserve the right number of drawcalls and events, to later be patched up with the actual - // details - ReserveExecuteIndirect(GetList(CommandList), sig, maxCount); } return true; @@ -4142,10 +4033,12 @@ void WrappedID3D12GraphicsCommandList::ExecuteIndirect(ID3D12CommandSignature *p m_pReal->ExecuteIndirect(Unwrap(pCommandSignature), MaxCommandCount, Unwrap(pArgumentBuffer), ArgumentBufferOffset, Unwrap(pCountBuffer), CountBufferOffset); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(EXEC_INDIRECT); - Serialise_ExecuteIndirect(pCommandSignature, MaxCommandCount, pArgumentBuffer, + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_ExecuteIndirect); + Serialise_ExecuteIndirect(ser, pCommandSignature, MaxCommandCount, pArgumentBuffer, ArgumentBufferOffset, pCountBuffer, CountBufferOffset); m_ListRecord->AddChunk(scope.Get()); @@ -4162,64 +4055,62 @@ void WrappedID3D12GraphicsCommandList::ExecuteIndirect(ID3D12CommandSignature *p #pragma region Clears +template bool WrappedID3D12GraphicsCommandList::Serialise_ClearDepthStencilView( - D3D12_CPU_DESCRIPTOR_HANDLE DepthStencilView, D3D12_CLEAR_FLAGS ClearFlags, FLOAT Depth, - UINT8 Stencil, UINT NumRects, const D3D12_RECT *pRects) + SerialiserType &ser, D3D12_CPU_DESCRIPTOR_HANDLE DepthStencilView, D3D12_CLEAR_FLAGS ClearFlags, + FLOAT Depth, UINT8 Stencil, UINT NumRects, const D3D12_RECT *pRects) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(PortableHandle, dsv, ToPortableHandle(DepthStencilView)); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(DepthStencilView); + SERIALISE_ELEMENT(ClearFlags); + SERIALISE_ELEMENT(Depth); + SERIALISE_ELEMENT(Stencil); + SERIALISE_ELEMENT_ARRAY(pRects, NumRects); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - SERIALISE_ELEMENT(D3D12_CLEAR_FLAGS, f, ClearFlags); - SERIALISE_ELEMENT(FLOAT, d, Depth); - SERIALISE_ELEMENT(UINT8, s, Stencil); - SERIALISE_ELEMENT(UINT, num, NumRects); - SERIALISE_ELEMENT_ARR(D3D12_RECT, rects, pRects, num); - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - DepthStencilView = CPUHandleFromPortableHandle(GetResourceManager(), dsv); + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList)) - ->ClearDepthStencilView(DepthStencilView, f, d, s, num, rects); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->ClearDepthStencilView(Unwrap(DepthStencilView), ClearFlags, Depth, Stencil, NumRects, + pRects); + } + } + else + { + Unwrap(pCommandList) + ->ClearDepthStencilView(Unwrap(DepthStencilView), ClearFlags, Depth, Stencil, NumRects, + pRects); + GetCrackedList()->ClearDepthStencilView(Unwrap(DepthStencilView), ClearFlags, Depth, Stencil, + NumRects, pRects); + + { + m_Cmd->AddEvent(); + + D3D12Descriptor *descriptor = GetWrapped(DepthStencilView); + + DrawcallDescription draw; + draw.name = StringFormat::Fmt("ClearDepthStencilView(%f, %hhu)", Depth, Stencil); + draw.flags |= DrawFlags::Clear | DrawFlags::ClearDepthStencil; + draw.copyDestination = + GetResourceManager()->GetOriginalID(GetResID(descriptor->nonsamp.resource)); + + m_Cmd->AddDrawcall(draw, true); + + D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); + + drawNode.resourceUsage.push_back( + std::make_pair(GetResID(descriptor->nonsamp.resource), + EventUsage(drawNode.draw.eventID, ResourceUsage::Clear))); + } } } - else if(m_State == READING) - { - DepthStencilView = CPUHandleFromPortableHandle(GetResourceManager(), dsv); - - GetList(CommandList)->ClearDepthStencilView(DepthStencilView, f, d, s, num, rects); - GetCrackedList(CommandList)->ClearDepthStencilView(DepthStencilView, f, d, s, num, rects); - - const string desc = m_pSerialiser->GetDebugStr(); - - { - m_Cmd->AddEvent(desc); - string name = "ClearDepthStencilView(" + ToStr(d) + "," + ToStr(s) + ")"; - - D3D12Descriptor *descriptor = DescriptorFromPortableHandle(GetResourceManager(), dsv); - - DrawcallDescription draw; - draw.name = name; - draw.flags |= DrawFlags::Clear | DrawFlags::ClearDepthStencil; - draw.copyDestination = - GetResourceManager()->GetOriginalID(GetResID(descriptor->nonsamp.resource)); - - m_Cmd->AddDrawcall(draw, true); - - D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); - - drawNode.resourceUsage.push_back( - std::make_pair(GetResID(descriptor->nonsamp.resource), - EventUsage(drawNode.draw.eventID, ResourceUsage::Clear))); - } - } - - SAFE_DELETE_ARRAY(rects); return true; } @@ -4231,10 +4122,13 @@ void WrappedID3D12GraphicsCommandList::ClearDepthStencilView( m_pReal->ClearDepthStencilView(Unwrap(DepthStencilView), ClearFlags, Depth, Stencil, NumRects, pRects); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(CLEAR_DSV); - Serialise_ClearDepthStencilView(DepthStencilView, ClearFlags, Depth, Stencil, NumRects, pRects); + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_ClearDepthStencilView); + Serialise_ClearDepthStencilView(ser, DepthStencilView, ClearFlags, Depth, Stencil, NumRects, + pRects); m_ListRecord->AddChunk(scope.Get()); @@ -4246,69 +4140,57 @@ void WrappedID3D12GraphicsCommandList::ClearDepthStencilView( } } +template bool WrappedID3D12GraphicsCommandList::Serialise_ClearRenderTargetView( - D3D12_CPU_DESCRIPTOR_HANDLE RenderTargetView, const FLOAT ColorRGBA[4], UINT NumRects, - const D3D12_RECT *pRects) + SerialiserType &ser, D3D12_CPU_DESCRIPTOR_HANDLE RenderTargetView, const FLOAT ColorRGBA[4], + UINT NumRects, const D3D12_RECT *pRects) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(PortableHandle, rtv, ToPortableHandle(RenderTargetView)); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(RenderTargetView); + SERIALISE_ELEMENT_ARRAY(ColorRGBA, FIXED_COUNT(4)); + SERIALISE_ELEMENT_ARRAY(pRects, NumRects); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - float Color[4] = {0}; - - if(m_State >= WRITING) - memcpy(Color, ColorRGBA, sizeof(float) * 4); - - m_pSerialiser->SerialisePODArray<4>("ColorRGBA", Color); - - SERIALISE_ELEMENT(UINT, num, NumRects); - SERIALISE_ELEMENT_ARR(D3D12_RECT, rects, pRects, num); - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - RenderTargetView = CPUHandleFromPortableHandle(GetResourceManager(), rtv); + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList)) - ->ClearRenderTargetView(RenderTargetView, Color, num, rects); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->ClearRenderTargetView(Unwrap(RenderTargetView), ColorRGBA, NumRects, pRects); + } + } + else + { + Unwrap(pCommandList)->ClearRenderTargetView(Unwrap(RenderTargetView), ColorRGBA, NumRects, pRects); + GetCrackedList()->ClearRenderTargetView(Unwrap(RenderTargetView), ColorRGBA, NumRects, pRects); + + { + m_Cmd->AddEvent(); + + D3D12Descriptor *descriptor = GetWrapped(RenderTargetView); + + DrawcallDescription draw; + draw.name = StringFormat::Fmt("ClearRenderTargetView(%f, %f, %f, %f)", ColorRGBA[0], + ColorRGBA[0], ColorRGBA[0], ColorRGBA[0]); + draw.flags |= DrawFlags::Clear | DrawFlags::ClearColor; + draw.copyDestination = + GetResourceManager()->GetOriginalID(GetResID(descriptor->nonsamp.resource)); + + m_Cmd->AddDrawcall(draw, true); + + D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); + + drawNode.resourceUsage.push_back( + std::make_pair(GetResID(descriptor->nonsamp.resource), + EventUsage(drawNode.draw.eventID, ResourceUsage::Clear))); + } } } - else if(m_State == READING) - { - RenderTargetView = CPUHandleFromPortableHandle(GetResourceManager(), rtv); - - GetList(CommandList)->ClearRenderTargetView(RenderTargetView, Color, num, rects); - GetCrackedList(CommandList)->ClearRenderTargetView(RenderTargetView, Color, num, rects); - - const string desc = m_pSerialiser->GetDebugStr(); - - { - m_Cmd->AddEvent(desc); - string name = "ClearRenderTargetView(" + ToStr(Color[0]) + "," + ToStr(Color[1]) + "," + - ToStr(Color[2]) + "," + ToStr(Color[3]) + ")"; - - D3D12Descriptor *descriptor = DescriptorFromPortableHandle(GetResourceManager(), rtv); - - DrawcallDescription draw; - draw.name = name; - draw.flags |= DrawFlags::Clear | DrawFlags::ClearColor; - draw.copyDestination = - GetResourceManager()->GetOriginalID(GetResID(descriptor->nonsamp.resource)); - - m_Cmd->AddDrawcall(draw, true); - - D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); - - drawNode.resourceUsage.push_back( - std::make_pair(GetResID(descriptor->nonsamp.resource), - EventUsage(drawNode.draw.eventID, ResourceUsage::Clear))); - } - } - - SAFE_DELETE_ARRAY(rects); return true; } @@ -4319,10 +4201,12 @@ void WrappedID3D12GraphicsCommandList::ClearRenderTargetView( { m_pReal->ClearRenderTargetView(Unwrap(RenderTargetView), ColorRGBA, NumRects, pRects); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(CLEAR_RTV); - Serialise_ClearRenderTargetView(RenderTargetView, ColorRGBA, NumRects, pRects); + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_ClearRenderTargetView); + Serialise_ClearRenderTargetView(ser, RenderTargetView, ColorRGBA, NumRects, pRects); m_ListRecord->AddChunk(scope.Get()); @@ -4334,76 +4218,61 @@ void WrappedID3D12GraphicsCommandList::ClearRenderTargetView( } } +template bool WrappedID3D12GraphicsCommandList::Serialise_ClearUnorderedAccessViewUint( - D3D12_GPU_DESCRIPTOR_HANDLE ViewGPUHandleInCurrentHeap, D3D12_CPU_DESCRIPTOR_HANDLE ViewCPUHandle, - ID3D12Resource *pResource, const UINT Values[4], UINT NumRects, const D3D12_RECT *pRects) + SerialiserType &ser, D3D12_GPU_DESCRIPTOR_HANDLE ViewGPUHandleInCurrentHeap, + D3D12_CPU_DESCRIPTOR_HANDLE ViewCPUHandle, ID3D12Resource *pResource, const UINT Values[4], + UINT NumRects, const D3D12_RECT *pRects) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(PortableHandle, gpuhandle, ToPortableHandle(ViewGPUHandleInCurrentHeap)); - SERIALISE_ELEMENT(PortableHandle, cpuhandle, ToPortableHandle(ViewCPUHandle)); - SERIALISE_ELEMENT(ResourceId, res, GetResID(pResource)); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(ViewGPUHandleInCurrentHeap); + SERIALISE_ELEMENT(ViewCPUHandle); + SERIALISE_ELEMENT(pResource); + SERIALISE_ELEMENT_ARRAY(Values, FIXED_COUNT(4)); + SERIALISE_ELEMENT_ARRAY(pRects, NumRects); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - UINT vals[4] = {0}; - - if(m_State >= WRITING) - memcpy(vals, Values, sizeof(UINT) * 4); - - m_pSerialiser->SerialisePODArray<4>("Values", vals); - - SERIALISE_ELEMENT(UINT, num, NumRects); - SERIALISE_ELEMENT_ARR(D3D12_RECT, rects, pRects, num); - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - ViewGPUHandleInCurrentHeap = GPUHandleFromPortableHandle(GetResourceManager(), gpuhandle); - ViewCPUHandle = CPUHandleFromPortableHandle(GetResourceManager(), cpuhandle); - pResource = GetResourceManager()->GetLiveAs(res); + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList)) - ->ClearUnorderedAccessViewUint(ViewGPUHandleInCurrentHeap, ViewCPUHandle, - Unwrap(pResource), vals, num, rects); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->ClearUnorderedAccessViewUint(Unwrap(ViewGPUHandleInCurrentHeap), Unwrap(ViewCPUHandle), + Unwrap(pResource), Values, NumRects, pRects); + } + } + else + { + Unwrap(pCommandList) + ->ClearUnorderedAccessViewUint(Unwrap(ViewGPUHandleInCurrentHeap), Unwrap(ViewCPUHandle), + Unwrap(pResource), Values, NumRects, pRects); + GetCrackedList()->ClearUnorderedAccessViewUint(Unwrap(ViewGPUHandleInCurrentHeap), + Unwrap(ViewCPUHandle), Unwrap(pResource), + Values, NumRects, pRects); + + { + m_Cmd->AddEvent(); + + DrawcallDescription draw; + draw.name = StringFormat::Fmt("ClearUnorderedAccessViewUint(%u, %u, %u, %u)", Values[0], + Values[1], Values[2], Values[3]); + draw.flags |= DrawFlags::Clear; + draw.copyDestination = GetResourceManager()->GetOriginalID(GetResID(pResource)); + + m_Cmd->AddDrawcall(draw, true); + + D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); + + drawNode.resourceUsage.push_back(std::make_pair( + GetResID(pResource), EventUsage(drawNode.draw.eventID, ResourceUsage::Clear))); + } } } - else if(m_State == READING) - { - ViewGPUHandleInCurrentHeap = GPUHandleFromPortableHandle(GetResourceManager(), gpuhandle); - ViewCPUHandle = CPUHandleFromPortableHandle(GetResourceManager(), cpuhandle); - pResource = GetResourceManager()->GetLiveAs(res); - - GetList(CommandList) - ->ClearUnorderedAccessViewUint(ViewGPUHandleInCurrentHeap, ViewCPUHandle, Unwrap(pResource), - vals, num, rects); - GetCrackedList(CommandList) - ->ClearUnorderedAccessViewUint(ViewGPUHandleInCurrentHeap, ViewCPUHandle, Unwrap(pResource), - vals, num, rects); - - const string desc = m_pSerialiser->GetDebugStr(); - - { - m_Cmd->AddEvent(desc); - string name = "ClearUnorderedAccessViewUint(" + ToStr(vals[0]) + "," + ToStr(vals[1]) + "," + - ToStr(vals[2]) + "," + ToStr(vals[3]) + ")"; - - DrawcallDescription draw; - draw.name = name; - draw.flags |= DrawFlags::Clear; - draw.copyDestination = res; - - m_Cmd->AddDrawcall(draw, true); - - D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); - - drawNode.resourceUsage.push_back(std::make_pair( - GetResID(pResource), EventUsage(drawNode.draw.eventID, ResourceUsage::Clear))); - } - } - - SAFE_DELETE_ARRAY(rects); return true; } @@ -4415,11 +4284,13 @@ void WrappedID3D12GraphicsCommandList::ClearUnorderedAccessViewUint( m_pReal->ClearUnorderedAccessViewUint(Unwrap(ViewGPUHandleInCurrentHeap), Unwrap(ViewCPUHandle), Unwrap(pResource), Values, NumRects, pRects); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(CLEAR_UAV_INT); - Serialise_ClearUnorderedAccessViewUint(ViewGPUHandleInCurrentHeap, ViewCPUHandle, pResource, - Values, NumRects, pRects); + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_ClearUnorderedAccessViewUint); + Serialise_ClearUnorderedAccessViewUint(ser, ViewGPUHandleInCurrentHeap, ViewCPUHandle, + pResource, Values, NumRects, pRects); m_ListRecord->AddChunk(scope.Get()); @@ -4437,76 +4308,61 @@ void WrappedID3D12GraphicsCommandList::ClearUnorderedAccessViewUint( } } +template bool WrappedID3D12GraphicsCommandList::Serialise_ClearUnorderedAccessViewFloat( - D3D12_GPU_DESCRIPTOR_HANDLE ViewGPUHandleInCurrentHeap, D3D12_CPU_DESCRIPTOR_HANDLE ViewCPUHandle, - ID3D12Resource *pResource, const FLOAT Values[4], UINT NumRects, const D3D12_RECT *pRects) + SerialiserType &ser, D3D12_GPU_DESCRIPTOR_HANDLE ViewGPUHandleInCurrentHeap, + D3D12_CPU_DESCRIPTOR_HANDLE ViewCPUHandle, ID3D12Resource *pResource, const FLOAT Values[4], + UINT NumRects, const D3D12_RECT *pRects) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(PortableHandle, gpuhandle, ToPortableHandle(ViewGPUHandleInCurrentHeap)); - SERIALISE_ELEMENT(PortableHandle, cpuhandle, ToPortableHandle(ViewCPUHandle)); - SERIALISE_ELEMENT(ResourceId, res, GetResID(pResource)); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(ViewGPUHandleInCurrentHeap); + SERIALISE_ELEMENT(ViewCPUHandle); + SERIALISE_ELEMENT(pResource); + SERIALISE_ELEMENT_ARRAY(Values, FIXED_COUNT(4)); + SERIALISE_ELEMENT_ARRAY(pRects, NumRects); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - FLOAT vals[4] = {0}; - - if(m_State >= WRITING) - memcpy(vals, Values, sizeof(FLOAT) * 4); - - m_pSerialiser->SerialisePODArray<4>("Values", vals); - - SERIALISE_ELEMENT(UINT, num, NumRects); - SERIALISE_ELEMENT_ARR(D3D12_RECT, rects, pRects, num); - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - ViewGPUHandleInCurrentHeap = GPUHandleFromPortableHandle(GetResourceManager(), gpuhandle); - ViewCPUHandle = CPUHandleFromPortableHandle(GetResourceManager(), cpuhandle); - pResource = GetResourceManager()->GetLiveAs(res); + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList)) - ->ClearUnorderedAccessViewFloat(ViewGPUHandleInCurrentHeap, ViewCPUHandle, - Unwrap(pResource), vals, num, rects); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->ClearUnorderedAccessViewFloat(Unwrap(ViewGPUHandleInCurrentHeap), Unwrap(ViewCPUHandle), + Unwrap(pResource), Values, NumRects, pRects); + } + } + else + { + Unwrap(pCommandList) + ->ClearUnorderedAccessViewFloat(Unwrap(ViewGPUHandleInCurrentHeap), Unwrap(ViewCPUHandle), + Unwrap(pResource), Values, NumRects, pRects); + GetCrackedList()->ClearUnorderedAccessViewFloat(Unwrap(ViewGPUHandleInCurrentHeap), + Unwrap(ViewCPUHandle), Unwrap(pResource), + Values, NumRects, pRects); + + { + m_Cmd->AddEvent(); + + DrawcallDescription draw; + draw.name = StringFormat::Fmt("ClearUnorderedAccessViewFloat(%f, %f, %f, %f)", Values[0], + Values[1], Values[2], Values[3]); + draw.flags |= DrawFlags::Clear; + draw.copyDestination = GetResourceManager()->GetOriginalID(GetResID(pResource)); + + m_Cmd->AddDrawcall(draw, true); + + D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); + + drawNode.resourceUsage.push_back(std::make_pair( + GetResID(pResource), EventUsage(drawNode.draw.eventID, ResourceUsage::Clear))); + } } } - else if(m_State == READING) - { - ViewGPUHandleInCurrentHeap = GPUHandleFromPortableHandle(GetResourceManager(), gpuhandle); - ViewCPUHandle = CPUHandleFromPortableHandle(GetResourceManager(), cpuhandle); - pResource = GetResourceManager()->GetLiveAs(res); - - GetList(CommandList) - ->ClearUnorderedAccessViewFloat(ViewGPUHandleInCurrentHeap, ViewCPUHandle, - Unwrap(pResource), vals, num, rects); - GetCrackedList(CommandList) - ->ClearUnorderedAccessViewFloat(ViewGPUHandleInCurrentHeap, ViewCPUHandle, - Unwrap(pResource), vals, num, rects); - - const string desc = m_pSerialiser->GetDebugStr(); - - { - m_Cmd->AddEvent(desc); - string name = "ClearUnorderedAccessViewFloat(" + ToStr(vals[0]) + "," + ToStr(vals[1]) + "," + - ToStr(vals[2]) + "," + ToStr(vals[3]) + ")"; - - DrawcallDescription draw; - draw.name = name; - draw.flags |= DrawFlags::Clear; - draw.copyDestination = res; - - m_Cmd->AddDrawcall(draw, true); - - D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); - - drawNode.resourceUsage.push_back(std::make_pair( - GetResID(pResource), EventUsage(drawNode.draw.eventID, ResourceUsage::Clear))); - } - } - - SAFE_DELETE_ARRAY(rects); return true; } @@ -4518,11 +4374,13 @@ void WrappedID3D12GraphicsCommandList::ClearUnorderedAccessViewFloat( m_pReal->ClearUnorderedAccessViewFloat(Unwrap(ViewGPUHandleInCurrentHeap), Unwrap(ViewCPUHandle), Unwrap(pResource), Values, NumRects, pRects); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(CLEAR_UAV_FLOAT); - Serialise_ClearUnorderedAccessViewFloat(ViewGPUHandleInCurrentHeap, ViewCPUHandle, pResource, - Values, NumRects, pRects); + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_ClearUnorderedAccessViewFloat); + Serialise_ClearUnorderedAccessViewFloat(ser, ViewGPUHandleInCurrentHeap, ViewCPUHandle, + pResource, Values, NumRects, pRects); m_ListRecord->AddChunk(scope.Get()); @@ -4540,33 +4398,34 @@ void WrappedID3D12GraphicsCommandList::ClearUnorderedAccessViewFloat( } } -bool WrappedID3D12GraphicsCommandList::Serialise_DiscardResource(ID3D12Resource *pResource, +template +bool WrappedID3D12GraphicsCommandList::Serialise_DiscardResource(SerialiserType &ser, + ID3D12Resource *pResource, const D3D12_DISCARD_REGION *pRegion) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(ResourceId, res, GetResID(pResource)); - SERIALISE_ELEMENT(BOOL, HasRegion, pRegion != NULL); - SERIALISE_ELEMENT_OPT(D3D12_DISCARD_REGION, region, *pRegion, HasRegion); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(pResource); + SERIALISE_ELEMENT_OPT(pRegion); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - pResource = GetResourceManager()->GetLiveAs(res); + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - Unwrap(m_Cmd->RerecordCmdList(CommandList)) - ->DiscardResource(Unwrap(pResource), HasRegion ? ®ion : NULL); + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + { + Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) + ->DiscardResource(Unwrap(pResource), pRegion); + } + } + else + { + Unwrap(pCommandList)->DiscardResource(Unwrap(pResource), pRegion); + GetCrackedList()->DiscardResource(Unwrap(pResource), pRegion); } - } - else if(m_State == READING) - { - pResource = GetResourceManager()->GetLiveAs(res); - - GetList(CommandList)->DiscardResource(Unwrap(pResource), HasRegion ? ®ion : NULL); - GetCrackedList(CommandList)->DiscardResource(Unwrap(pResource), HasRegion ? ®ion : NULL); } return true; @@ -4577,10 +4436,11 @@ void WrappedID3D12GraphicsCommandList::DiscardResource(ID3D12Resource *pResource { m_pReal->DiscardResource(Unwrap(pResource), pRegion); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(DISCARD_RESOURCE); - Serialise_DiscardResource(pResource, pRegion); + CACHE_THREAD_SERIALISER(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_DiscardResource); + Serialise_DiscardResource(ser, pResource, pRegion); m_ListRecord->AddChunk(scope.Get()); m_ListRecord->MarkResourceFrameReferenced(GetResID(pResource), eFrameRef_Write); @@ -4591,69 +4451,69 @@ void WrappedID3D12GraphicsCommandList::DiscardResource(ID3D12Resource *pResource #pragma region Copies -bool WrappedID3D12GraphicsCommandList::Serialise_CopyBufferRegion(ID3D12Resource *pDstBuffer, +template +bool WrappedID3D12GraphicsCommandList::Serialise_CopyBufferRegion(SerialiserType &ser, + ID3D12Resource *pDstBuffer, UINT64 DstOffset, ID3D12Resource *pSrcBuffer, UINT64 SrcOffset, UINT64 NumBytes) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(ResourceId, dst, GetResID(pDstBuffer)); - SERIALISE_ELEMENT(UINT64, dstoffs, DstOffset); - SERIALISE_ELEMENT(ResourceId, src, GetResID(pSrcBuffer)); - SERIALISE_ELEMENT(UINT64, srcoffs, SrcOffset); - SERIALISE_ELEMENT(UINT64, num, NumBytes); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(pDstBuffer); + SERIALISE_ELEMENT(DstOffset); + SERIALISE_ELEMENT(pSrcBuffer); + SERIALISE_ELEMENT(SrcOffset); + SERIALISE_ELEMENT(NumBytes); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - pDstBuffer = GetResourceManager()->GetLiveAs(dst); - pSrcBuffer = GetResourceManager()->GetLiveAs(src); + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(CommandList); - Unwrap(list)->CopyBufferRegion(Unwrap(pDstBuffer), dstoffs, Unwrap(pSrcBuffer), srcoffs, num); - } - } - else if(m_State == READING) - { - pDstBuffer = GetResourceManager()->GetLiveAs(dst); - pSrcBuffer = GetResourceManager()->GetLiveAs(src); - - GetList(CommandList)->CopyBufferRegion(Unwrap(pDstBuffer), dstoffs, Unwrap(pSrcBuffer), srcoffs, num); - GetCrackedList(CommandList) - ->CopyBufferRegion(Unwrap(pDstBuffer), dstoffs, Unwrap(pSrcBuffer), srcoffs, num); - - const string desc = m_pSerialiser->GetDebugStr(); - - { - m_Cmd->AddEvent(desc); - string name = "CopyBufferRegion(" + ToStr(src) + "," + ToStr(dst) + ")"; - - DrawcallDescription draw; - draw.name = name; - draw.flags |= DrawFlags::Copy; - - draw.copySource = src; - draw.copyDestination = dst; - - m_Cmd->AddDrawcall(draw, true); - - D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); - - if(src == dst) + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - drawNode.resourceUsage.push_back(std::make_pair( - GetResID(pSrcBuffer), EventUsage(drawNode.draw.eventID, ResourceUsage::Copy))); + ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + Unwrap(list)->CopyBufferRegion(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer), SrcOffset, + NumBytes); } - else + } + else + { + Unwrap(pCommandList) + ->CopyBufferRegion(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer), SrcOffset, NumBytes); + GetCrackedList()->CopyBufferRegion(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer), + SrcOffset, NumBytes); + { - drawNode.resourceUsage.push_back(std::make_pair( - GetResID(pSrcBuffer), EventUsage(drawNode.draw.eventID, ResourceUsage::CopySrc))); - drawNode.resourceUsage.push_back(std::make_pair( - GetResID(pDstBuffer), EventUsage(drawNode.draw.eventID, ResourceUsage::CopyDst))); + m_Cmd->AddEvent(); + + DrawcallDescription draw; + draw.copySource = GetResourceManager()->GetOriginalID(GetResID(pSrcBuffer)); + draw.copyDestination = GetResourceManager()->GetOriginalID(GetResID(pDstBuffer)); + + draw.name = StringFormat::Fmt("CopyBufferRegion(%s, %s)", ToStr(draw.copyDestination).c_str(), + ToStr(draw.copySource).c_str()); + draw.flags |= DrawFlags::Copy; + + m_Cmd->AddDrawcall(draw, true); + + D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); + + if(pSrcBuffer == pDstBuffer) + { + drawNode.resourceUsage.push_back(std::make_pair( + GetResID(pSrcBuffer), EventUsage(drawNode.draw.eventID, ResourceUsage::Copy))); + } + else + { + drawNode.resourceUsage.push_back(std::make_pair( + GetResID(pSrcBuffer), EventUsage(drawNode.draw.eventID, ResourceUsage::CopySrc))); + drawNode.resourceUsage.push_back(std::make_pair( + GetResID(pDstBuffer), EventUsage(drawNode.draw.eventID, ResourceUsage::CopyDst))); + } } } } @@ -4667,10 +4527,12 @@ void WrappedID3D12GraphicsCommandList::CopyBufferRegion(ID3D12Resource *pDstBuff { m_pReal->CopyBufferRegion(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer), SrcOffset, NumBytes); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(COPY_BUFFER); - Serialise_CopyBufferRegion(pDstBuffer, DstOffset, pSrcBuffer, SrcOffset, NumBytes); + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_CopyBufferRegion); + Serialise_CopyBufferRegion(ser, pDstBuffer, DstOffset, pSrcBuffer, SrcOffset, NumBytes); m_ListRecord->AddChunk(scope.Get()); m_ListRecord->MarkResourceFrameReferenced(GetResID(pDstBuffer), eFrameRef_Write); @@ -4678,70 +4540,76 @@ void WrappedID3D12GraphicsCommandList::CopyBufferRegion(ID3D12Resource *pDstBuff } } +template bool WrappedID3D12GraphicsCommandList::Serialise_CopyTextureRegion( - const D3D12_TEXTURE_COPY_LOCATION *pDst, UINT DstX, UINT DstY, UINT DstZ, + SerialiserType &ser, const D3D12_TEXTURE_COPY_LOCATION *pDst, UINT DstX, UINT DstY, UINT DstZ, const D3D12_TEXTURE_COPY_LOCATION *pSrc, const D3D12_BOX *pSrcBox) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(D3D12_TEXTURE_COPY_LOCATION, dst, *pDst); - SERIALISE_ELEMENT(UINT, dstX, DstX); - SERIALISE_ELEMENT(UINT, dstY, DstY); - SERIALISE_ELEMENT(UINT, dstZ, DstZ); - SERIALISE_ELEMENT(D3D12_TEXTURE_COPY_LOCATION, src, *pSrc); - SERIALISE_ELEMENT(bool, HasSrcBox, pSrcBox != NULL); - SERIALISE_ELEMENT_OPT(D3D12_BOX, box, *pSrcBox, HasSrcBox); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT_LOCAL(dst, *pDst); + SERIALISE_ELEMENT(DstX); + SERIALISE_ELEMENT(DstY); + SERIALISE_ELEMENT(DstZ); + SERIALISE_ELEMENT_LOCAL(src, *pSrc); + SERIALISE_ELEMENT_OPT(pSrcBox); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); + + D3D12_TEXTURE_COPY_LOCATION unwrappedDst = dst; + unwrappedDst.pResource = Unwrap(unwrappedDst.pResource); + D3D12_TEXTURE_COPY_LOCATION unwrappedSrc = src; + unwrappedSrc.pResource = Unwrap(unwrappedSrc.pResource); + + if(IsActiveReplaying(m_State)) { - ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(CommandList); - Unwrap(list)->CopyTextureRegion(&dst, dstX, dstY, dstZ, &src, HasSrcBox ? &box : NULL); - } - } - else if(m_State == READING) - { - GetList(CommandList)->CopyTextureRegion(&dst, dstX, dstY, dstZ, &src, HasSrcBox ? &box : NULL); - GetCrackedList(CommandList)->CopyTextureRegion(&dst, dstX, dstY, dstZ, &src, HasSrcBox ? &box : NULL); - - const string desc = m_pSerialiser->GetDebugStr(); - - { - m_Cmd->AddEvent(desc); - - ResourceId liveSrc = GetResID(GetResourceManager()->GetWrapper(src.pResource)); - ResourceId liveDst = GetResID(GetResourceManager()->GetWrapper(dst.pResource)); - - ResourceId origSrc = GetResourceManager()->GetOriginalID(liveSrc); - ResourceId origDst = GetResourceManager()->GetOriginalID(liveDst); - - string name = "CopyTextureRegion(" + ToStr(origSrc) + "," + ToStr(origDst) + ")"; - - DrawcallDescription draw; - draw.name = name; - draw.flags |= DrawFlags::Copy; - - draw.copySource = origSrc; - draw.copyDestination = origDst; - - m_Cmd->AddDrawcall(draw, true); - - D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); - - if(origSrc == origDst) + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - drawNode.resourceUsage.push_back( - std::make_pair(liveSrc, EventUsage(drawNode.draw.eventID, ResourceUsage::Copy))); + ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + Unwrap(list)->CopyTextureRegion(&unwrappedDst, DstX, DstY, DstZ, &unwrappedSrc, pSrcBox); } - else + } + else + { + Unwrap(pCommandList)->CopyTextureRegion(&unwrappedDst, DstX, DstY, DstZ, &unwrappedSrc, pSrcBox); + GetCrackedList()->CopyTextureRegion(&unwrappedDst, DstX, DstY, DstZ, &unwrappedSrc, pSrcBox); + { - drawNode.resourceUsage.push_back( - std::make_pair(liveSrc, EventUsage(drawNode.draw.eventID, ResourceUsage::CopySrc))); - drawNode.resourceUsage.push_back( - std::make_pair(liveDst, EventUsage(drawNode.draw.eventID, ResourceUsage::CopyDst))); + m_Cmd->AddEvent(); + + ResourceId liveSrc = GetResID(src.pResource); + ResourceId liveDst = GetResID(dst.pResource); + + ResourceId origSrc = GetResourceManager()->GetOriginalID(liveSrc); + ResourceId origDst = GetResourceManager()->GetOriginalID(liveDst); + + DrawcallDescription draw; + draw.name = StringFormat::Fmt("CopyTextureRegion(%s, %s)", ToStr(origSrc).c_str(), + ToStr(origDst).c_str()); + draw.flags |= DrawFlags::Copy; + + draw.copySource = origSrc; + draw.copyDestination = origDst; + + m_Cmd->AddDrawcall(draw, true); + + D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); + + if(origSrc == origDst) + { + drawNode.resourceUsage.push_back( + std::make_pair(liveSrc, EventUsage(drawNode.draw.eventID, ResourceUsage::Copy))); + } + else + { + drawNode.resourceUsage.push_back( + std::make_pair(liveSrc, EventUsage(drawNode.draw.eventID, ResourceUsage::CopySrc))); + drawNode.resourceUsage.push_back( + std::make_pair(liveDst, EventUsage(drawNode.draw.eventID, ResourceUsage::CopyDst))); + } } } } @@ -4762,10 +4630,12 @@ void WrappedID3D12GraphicsCommandList::CopyTextureRegion(const D3D12_TEXTURE_COP m_pReal->CopyTextureRegion(&dst, DstX, DstY, DstZ, &src, pSrcBox); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(COPY_TEXTURE); - Serialise_CopyTextureRegion(pDst, DstX, DstY, DstZ, pSrc, pSrcBox); + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_CopyTextureRegion); + Serialise_CopyTextureRegion(ser, pDst, DstX, DstY, DstZ, pSrc, pSrcBox); m_ListRecord->AddChunk(scope.Get()); m_ListRecord->MarkResourceFrameReferenced(GetResID(pDst->pResource), eFrameRef_Write); @@ -4773,64 +4643,61 @@ void WrappedID3D12GraphicsCommandList::CopyTextureRegion(const D3D12_TEXTURE_COP } } -bool WrappedID3D12GraphicsCommandList::Serialise_CopyResource(ID3D12Resource *pDstResource, +template +bool WrappedID3D12GraphicsCommandList::Serialise_CopyResource(SerialiserType &ser, + ID3D12Resource *pDstResource, ID3D12Resource *pSrcResource) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(ResourceId, dst, GetResID(pDstResource)); - SERIALISE_ELEMENT(ResourceId, src, GetResID(pSrcResource)); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(pDstResource); + SERIALISE_ELEMENT(pSrcResource); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - pDstResource = GetResourceManager()->GetLiveAs(dst); - pSrcResource = GetResourceManager()->GetLiveAs(src); + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(CommandList); - Unwrap(list)->CopyResource(Unwrap(pDstResource), Unwrap(pSrcResource)); - } - } - else if(m_State == READING) - { - pDstResource = GetResourceManager()->GetLiveAs(dst); - pSrcResource = GetResourceManager()->GetLiveAs(src); - - GetList(CommandList)->CopyResource(Unwrap(pDstResource), Unwrap(pSrcResource)); - GetCrackedList(CommandList)->CopyResource(Unwrap(pDstResource), Unwrap(pSrcResource)); - - const string desc = m_pSerialiser->GetDebugStr(); - - { - m_Cmd->AddEvent(desc); - - string name = "CopyResource(" + ToStr(src) + "," + ToStr(dst) + ")"; - - DrawcallDescription draw; - draw.name = name; - draw.flags |= DrawFlags::Copy; - - draw.copySource = src; - draw.copyDestination = dst; - - m_Cmd->AddDrawcall(draw, true); - - D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); - - if(pSrcResource == pDstResource) + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - drawNode.resourceUsage.push_back(std::make_pair( - GetResID(pSrcResource), EventUsage(drawNode.draw.eventID, ResourceUsage::Copy))); + ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + Unwrap(list)->CopyResource(Unwrap(pDstResource), Unwrap(pSrcResource)); } - else + } + else + { + Unwrap(pCommandList)->CopyResource(Unwrap(pDstResource), Unwrap(pSrcResource)); + GetCrackedList()->CopyResource(Unwrap(pDstResource), Unwrap(pSrcResource)); + { - drawNode.resourceUsage.push_back(std::make_pair( - GetResID(pSrcResource), EventUsage(drawNode.draw.eventID, ResourceUsage::CopySrc))); - drawNode.resourceUsage.push_back(std::make_pair( - GetResID(pDstResource), EventUsage(drawNode.draw.eventID, ResourceUsage::CopyDst))); + m_Cmd->AddEvent(); + + DrawcallDescription draw; + draw.copySource = GetResourceManager()->GetOriginalID(GetResID(pSrcResource)); + draw.copyDestination = GetResourceManager()->GetOriginalID(GetResID(pDstResource)); + + draw.name = StringFormat::Fmt("CopyResource(%s, %s)", ToStr(draw.copyDestination).c_str(), + ToStr(draw.copySource).c_str()); + draw.flags |= DrawFlags::Copy; + + m_Cmd->AddDrawcall(draw, true); + + D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); + + if(pSrcResource == pDstResource) + { + drawNode.resourceUsage.push_back(std::make_pair( + GetResID(pSrcResource), EventUsage(drawNode.draw.eventID, ResourceUsage::Copy))); + } + else + { + drawNode.resourceUsage.push_back(std::make_pair( + GetResID(pSrcResource), EventUsage(drawNode.draw.eventID, ResourceUsage::CopySrc))); + drawNode.resourceUsage.push_back(std::make_pair( + GetResID(pDstResource), EventUsage(drawNode.draw.eventID, ResourceUsage::CopyDst))); + } } } } @@ -4843,10 +4710,12 @@ void WrappedID3D12GraphicsCommandList::CopyResource(ID3D12Resource *pDstResource { m_pReal->CopyResource(Unwrap(pDstResource), Unwrap(pSrcResource)); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(COPY_RESOURCE); - Serialise_CopyResource(pDstResource, pSrcResource); + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_CopyResource); + Serialise_CopyResource(ser, pDstResource, pSrcResource); m_ListRecord->AddChunk(scope.Get()); m_ListRecord->MarkResourceFrameReferenced(GetResID(pDstResource), eFrameRef_Write); @@ -4854,73 +4723,69 @@ void WrappedID3D12GraphicsCommandList::CopyResource(ID3D12Resource *pDstResource } } -bool WrappedID3D12GraphicsCommandList::Serialise_ResolveSubresource(ID3D12Resource *pDstResource, - UINT DstSubresource, - ID3D12Resource *pSrcResource, - UINT SrcSubresource, - DXGI_FORMAT Format) +template +bool WrappedID3D12GraphicsCommandList::Serialise_ResolveSubresource( + SerialiserType &ser, ID3D12Resource *pDstResource, UINT DstSubresource, + ID3D12Resource *pSrcResource, UINT SrcSubresource, DXGI_FORMAT Format) { - SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); - SERIALISE_ELEMENT(ResourceId, dst, GetResID(pDstResource)); - SERIALISE_ELEMENT(UINT, dstSub, DstSubresource); - SERIALISE_ELEMENT(ResourceId, src, GetResID(pSrcResource)); - SERIALISE_ELEMENT(UINT, srcSub, SrcSubresource); - SERIALISE_ELEMENT(DXGI_FORMAT, fmt, Format); + ID3D12GraphicsCommandList *pCommandList = this; + SERIALISE_ELEMENT(pCommandList); + SERIALISE_ELEMENT(pDstResource); + SERIALISE_ELEMENT(DstSubresource); + SERIALISE_ELEMENT(pSrcResource); + SERIALISE_ELEMENT(SrcSubresource); + SERIALISE_ELEMENT(Format); - if(m_State < WRITING) - m_Cmd->m_LastCmdListID = CommandList; - - if(m_State == EXECUTING) + if(IsReplayingAndReading()) { - pDstResource = GetResourceManager()->GetLiveAs(dst); - pSrcResource = GetResourceManager()->GetLiveAs(src); + m_Cmd->m_LastCmdListID = GetResourceManager()->GetOriginalID(GetResID(pCommandList)); - if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + if(IsActiveReplaying(m_State)) { - ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(CommandList); - Unwrap(list)->ResolveSubresource(Unwrap(pDstResource), dstSub, Unwrap(pSrcResource), srcSub, - fmt); - } - } - else if(m_State == READING) - { - pDstResource = GetResourceManager()->GetLiveAs(dst); - pSrcResource = GetResourceManager()->GetLiveAs(src); - - GetList(CommandList) - ->ResolveSubresource(Unwrap(pDstResource), dstSub, Unwrap(pSrcResource), srcSub, fmt); - GetCrackedList(CommandList) - ->ResolveSubresource(Unwrap(pDstResource), dstSub, Unwrap(pSrcResource), srcSub, fmt); - - const string desc = m_pSerialiser->GetDebugStr(); - - { - m_Cmd->AddEvent(desc); - - string name = "ResolveSubresource(" + ToStr(src) + "," + ToStr(dst) + ")"; - - DrawcallDescription draw; - draw.name = name; - draw.flags |= DrawFlags::Resolve; - - draw.copySource = src; - draw.copyDestination = dst; - - m_Cmd->AddDrawcall(draw, true); - - D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); - - if(pSrcResource == pDstResource) + if(m_Cmd->ShouldRerecordCmd(m_Cmd->m_LastCmdListID) && + m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - drawNode.resourceUsage.push_back(std::make_pair( - GetResID(pSrcResource), EventUsage(drawNode.draw.eventID, ResourceUsage::Resolve))); + ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + Unwrap(list)->ResolveSubresource(Unwrap(pDstResource), DstSubresource, Unwrap(pSrcResource), + SrcSubresource, Format); } - else + } + else + { + Unwrap(pCommandList) + ->ResolveSubresource(Unwrap(pDstResource), DstSubresource, Unwrap(pSrcResource), + SrcSubresource, Format); + GetCrackedList()->ResolveSubresource(Unwrap(pDstResource), DstSubresource, + Unwrap(pSrcResource), SrcSubresource, Format); + { - drawNode.resourceUsage.push_back(std::make_pair( - GetResID(pSrcResource), EventUsage(drawNode.draw.eventID, ResourceUsage::ResolveSrc))); - drawNode.resourceUsage.push_back(std::make_pair( - GetResID(pDstResource), EventUsage(drawNode.draw.eventID, ResourceUsage::ResolveDst))); + m_Cmd->AddEvent(); + + DrawcallDescription draw; + draw.copySource = GetResourceManager()->GetOriginalID(GetResID(pSrcResource)); + draw.copyDestination = GetResourceManager()->GetOriginalID(GetResID(pDstResource)); + + draw.name = + StringFormat::Fmt("ResolveSubresource(%s, %s)", ToStr(draw.copyDestination).c_str(), + ToStr(draw.copySource).c_str()); + draw.flags |= DrawFlags::Resolve; + + m_Cmd->AddDrawcall(draw, true); + + D3D12DrawcallTreeNode &drawNode = m_Cmd->GetDrawcallStack().back()->children.back(); + + if(pSrcResource == pDstResource) + { + drawNode.resourceUsage.push_back(std::make_pair( + GetResID(pSrcResource), EventUsage(drawNode.draw.eventID, ResourceUsage::Resolve))); + } + else + { + drawNode.resourceUsage.push_back(std::make_pair( + GetResID(pSrcResource), EventUsage(drawNode.draw.eventID, ResourceUsage::ResolveSrc))); + drawNode.resourceUsage.push_back(std::make_pair( + GetResID(pDstResource), EventUsage(drawNode.draw.eventID, ResourceUsage::ResolveDst))); + } } } } @@ -4936,10 +4801,13 @@ void WrappedID3D12GraphicsCommandList::ResolveSubresource(ID3D12Resource *pDstRe m_pReal->ResolveSubresource(Unwrap(pDstResource), DstSubresource, Unwrap(pSrcResource), SrcSubresource, Format); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - SCOPED_SERIALISE_CONTEXT(RESOLVE_SUBRESOURCE); - Serialise_ResolveSubresource(pDstResource, DstSubresource, pSrcResource, SrcSubresource, Format); + CACHE_THREAD_SERIALISER(); + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::List_ResolveSubresource); + Serialise_ResolveSubresource(ser, pDstResource, DstSubresource, pSrcResource, SrcSubresource, + Format); m_ListRecord->AddChunk(scope.Get()); m_ListRecord->MarkResourceFrameReferenced(GetResID(pDstResource), eFrameRef_Write); @@ -4947,8 +4815,10 @@ void WrappedID3D12GraphicsCommandList::ResolveSubresource(ID3D12Resource *pDstRe } } +template bool WrappedID3D12GraphicsCommandList::Serialise_CopyTiles( - ID3D12Resource *pTiledResource, const D3D12_TILED_RESOURCE_COORDINATE *pTileRegionStartCoordinate, + SerialiserType &ser, ID3D12Resource *pTiledResource, + const D3D12_TILED_RESOURCE_COORDINATE *pTileRegionStartCoordinate, const D3D12_TILE_REGION_SIZE *pTileRegionSize, ID3D12Resource *pBuffer, UINT64 BufferStartOffsetInBytes, D3D12_TILE_COPY_FLAGS Flags) { @@ -4967,3 +4837,142 @@ void WrappedID3D12GraphicsCommandList::CopyTiles( } #pragma endregion Copies + +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, Close); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, Reset, + ID3D12CommandAllocator *pAllocator, + ID3D12PipelineState *pInitialState); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, ResourceBarrier, + UINT NumBarriers, const D3D12_RESOURCE_BARRIER *pBarriers); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, IASetPrimitiveTopology, + D3D12_PRIMITIVE_TOPOLOGY PrimitiveTopology); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, RSSetViewports, + UINT NumViewports, const D3D12_VIEWPORT *pViewports); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, RSSetScissorRects, + UINT NumRects, const D3D12_RECT *pRects); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, OMSetBlendFactor, + const FLOAT BlendFactor[4]); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, OMSetStencilRef, + UINT StencilRef); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, SetDescriptorHeaps, + UINT NumDescriptorHeaps, + ID3D12DescriptorHeap *const *ppDescriptorHeaps); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, IASetIndexBuffer, + const D3D12_INDEX_BUFFER_VIEW *pView); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, IASetVertexBuffers, + UINT StartSlot, UINT NumViews, + const D3D12_VERTEX_BUFFER_VIEW *pViews); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, SOSetTargets, UINT StartSlot, + UINT NumViews, const D3D12_STREAM_OUTPUT_BUFFER_VIEW *pViews); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, SetPipelineState, + ID3D12PipelineState *pPipelineState); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, OMSetRenderTargets, + UINT NumRenderTargetDescriptors, + const D3D12_CPU_DESCRIPTOR_HANDLE *pRenderTargetDescriptors, + BOOL RTsSingleHandleToDescriptorRange, + const D3D12_CPU_DESCRIPTOR_HANDLE *pDepthStencilDescriptor); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, SetComputeRootSignature, + ID3D12RootSignature *pRootSignature); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, SetComputeRootDescriptorTable, + UINT RootParameterIndex, D3D12_GPU_DESCRIPTOR_HANDLE BaseDescriptor); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, SetComputeRoot32BitConstant, + UINT RootParameterIndex, UINT SrcData, UINT DestOffsetIn32BitValues); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, SetComputeRoot32BitConstants, + UINT RootParameterIndex, UINT Num32BitValuesToSet, + const void *pSrcData, UINT DestOffsetIn32BitValues); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, + SetComputeRootConstantBufferView, UINT RootParameterIndex, + D3D12_GPU_VIRTUAL_ADDRESS BufferLocation); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, + SetComputeRootShaderResourceView, UINT RootParameterIndex, + D3D12_GPU_VIRTUAL_ADDRESS BufferLocation); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, + SetComputeRootUnorderedAccessView, UINT RootParameterIndex, + D3D12_GPU_VIRTUAL_ADDRESS BufferLocation); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, SetGraphicsRootSignature, + ID3D12RootSignature *pRootSignature); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, + SetGraphicsRootDescriptorTable, UINT RootParameterIndex, + D3D12_GPU_DESCRIPTOR_HANDLE BaseDescriptor); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, SetGraphicsRoot32BitConstant, + UINT RootParameterIndex, UINT SrcData, UINT DestOffsetIn32BitValues); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, SetGraphicsRoot32BitConstants, + UINT RootParameterIndex, UINT Num32BitValuesToSet, + const void *pSrcData, UINT DestOffsetIn32BitValues); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, + SetGraphicsRootConstantBufferView, UINT RootParameterIndex, + D3D12_GPU_VIRTUAL_ADDRESS BufferLocation); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, + SetGraphicsRootShaderResourceView, UINT RootParameterIndex, + D3D12_GPU_VIRTUAL_ADDRESS BufferLocation); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, + SetGraphicsRootUnorderedAccessView, UINT RootParameterIndex, + D3D12_GPU_VIRTUAL_ADDRESS BufferLocation); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, BeginQuery, + ID3D12QueryHeap *pQueryHeap, D3D12_QUERY_TYPE Type, UINT Index); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, EndQuery, + ID3D12QueryHeap *pQueryHeap, D3D12_QUERY_TYPE Type, UINT Index); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, ResolveQueryData, + ID3D12QueryHeap *pQueryHeap, D3D12_QUERY_TYPE Type, UINT StartIndex, + UINT NumQueries, ID3D12Resource *pDestinationBuffer, + UINT64 AlignedDestinationBufferOffset); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, SetPredication, + ID3D12Resource *pBuffer, UINT64 AlignedBufferOffset, + D3D12_PREDICATION_OP Operation); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, SetMarker, UINT Metadata, + const void *pData, UINT Size); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, BeginEvent, UINT Metadata, + const void *pData, UINT Size); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, EndEvent); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, DrawInstanced, + UINT VertexCountPerInstance, UINT InstanceCount, + UINT StartVertexLocation, UINT StartInstanceLocation); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, DrawIndexedInstanced, + UINT IndexCountPerInstance, UINT InstanceCount, + UINT StartIndexLocation, INT BaseVertexLocation, + UINT StartInstanceLocation); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, Dispatch, + UINT ThreadGroupCountX, UINT ThreadGroupCountY, + UINT ThreadGroupCountZ); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, ExecuteBundle, + ID3D12GraphicsCommandList *pCommandList); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, ExecuteIndirect, + ID3D12CommandSignature *pCommandSignature, UINT MaxCommandCount, + ID3D12Resource *pArgumentBuffer, UINT64 ArgumentBufferOffset, + ID3D12Resource *pCountBuffer, UINT64 CountBufferOffset); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, ClearDepthStencilView, + D3D12_CPU_DESCRIPTOR_HANDLE DepthStencilView, + D3D12_CLEAR_FLAGS ClearFlags, FLOAT Depth, UINT8 Stencil, + UINT NumRects, const D3D12_RECT *pRects); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, ClearRenderTargetView, + D3D12_CPU_DESCRIPTOR_HANDLE RenderTargetView, + const FLOAT ColorRGBA[4], UINT NumRects, const D3D12_RECT *pRects); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, ClearUnorderedAccessViewUint, + D3D12_GPU_DESCRIPTOR_HANDLE ViewGPUHandleInCurrentHeap, + D3D12_CPU_DESCRIPTOR_HANDLE ViewCPUHandle, ID3D12Resource *pResource, + const UINT Values[4], UINT NumRects, const D3D12_RECT *pRects); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, ClearUnorderedAccessViewFloat, + D3D12_GPU_DESCRIPTOR_HANDLE ViewGPUHandleInCurrentHeap, + D3D12_CPU_DESCRIPTOR_HANDLE ViewCPUHandle, ID3D12Resource *pResource, + const FLOAT Values[4], UINT NumRects, const D3D12_RECT *pRects); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, DiscardResource, + ID3D12Resource *pResource, const D3D12_DISCARD_REGION *pRegion); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, CopyBufferRegion, + ID3D12Resource *pDstBuffer, UINT64 DstOffset, + ID3D12Resource *pSrcBuffer, UINT64 SrcOffset, UINT64 NumBytes); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, CopyTextureRegion, + const D3D12_TEXTURE_COPY_LOCATION *pDst, UINT DstX, UINT DstY, + UINT DstZ, const D3D12_TEXTURE_COPY_LOCATION *pSrc, + const D3D12_BOX *pSrcBox); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, CopyResource, + ID3D12Resource *pDstResource, ID3D12Resource *pSrcResource); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, ResolveSubresource, + ID3D12Resource *pDstResource, UINT DstSubresource, + ID3D12Resource *pSrcResource, UINT SrcSubresource, + DXGI_FORMAT Format); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12GraphicsCommandList, CopyTiles, + ID3D12Resource *pTiledResource, + const D3D12_TILED_RESOURCE_COORDINATE *pTileRegionStartCoordinate, + const D3D12_TILE_REGION_SIZE *pTileRegionSize, + ID3D12Resource *pBuffer, UINT64 BufferStartOffsetInBytes, + D3D12_TILE_COPY_FLAGS Flags); diff --git a/renderdoc/driver/d3d12/d3d12_commands.cpp b/renderdoc/driver/d3d12/d3d12_commands.cpp index b00025d33..e412af307 100644 --- a/renderdoc/driver/d3d12/d3d12_commands.cpp +++ b/renderdoc/driver/d3d12/d3d12_commands.cpp @@ -556,8 +556,7 @@ void WrappedID3D12CommandQueue::ReplayLog(CaptureState readType, uint32_t startE if(it != m_Cmd.m_DrawcallUses.end()) { - BakedCmdListInfo &cmdInfo = - m_Cmd.m_BakedCmdListInfo[m_Cmd.m_BakedCmdListInfo[it->cmdList].parentList]; + BakedCmdListInfo &cmdInfo = m_Cmd.m_BakedCmdListInfo[it->cmdList]; cmdInfo.curEventID = it->relativeEID; } } @@ -719,24 +718,17 @@ WrappedID3D12GraphicsCommandList::~WrappedID3D12GraphicsCommandList() SAFE_RELEASE(m_pReal); } -bool WrappedID3D12GraphicsCommandList::ValidateRootGPUVA(ResourceId buffer) +bool WrappedID3D12GraphicsCommandList::ValidateRootGPUVA(D3D12_GPU_VIRTUAL_ADDRESS buffer) { - if(!GetResourceManager()->HasLiveResource(buffer)) + if(buffer == 0) { // abort, we don't have this buffer. Print errors while reading if(IsLoading(m_State)) { - if(buffer != ResourceId()) - { - RDCERR("Don't have live buffer for %llu", buffer); - } - else - { - m_pDevice->AddDebugMessage(MessageCategory::Resource_Manipulation, MessageSeverity::Medium, - MessageSource::IncorrectAPIUse, - "Binding 0 as a GPU Virtual Address in a root constant is " - "invalid. This call will be dropped during replay."); - } + m_pDevice->AddDebugMessage(MessageCategory::Resource_Manipulation, MessageSeverity::Medium, + MessageSource::IncorrectAPIUse, + "Binding 0 as a GPU Virtual Address in a root constant is " + "invalid. This call will be dropped during replay."); } return true; diff --git a/renderdoc/driver/d3d12/d3d12_commands.h b/renderdoc/driver/d3d12/d3d12_commands.h index ef4653816..d9477edee 100644 --- a/renderdoc/driver/d3d12/d3d12_commands.h +++ b/renderdoc/driver/d3d12/d3d12_commands.h @@ -121,57 +121,24 @@ struct D3D12DrawcallCallback virtual void AliasEvent(uint32_t primary, uint32_t alias) = 0; }; +class WrappedID3D12CommandSignature; + struct BakedCmdListInfo { - void BakeFrom(ResourceId parentID, BakedCmdListInfo &parent) - { - draw = parent.draw; - curEvents = parent.curEvents; - debugMessages = parent.debugMessages; - eventCount = parent.curEventID; - drawCount = parent.drawCount; - crackedLists.swap(parent.crackedLists); - executeEvents.swap(parent.executeEvents); - - parentList = parentID; - - curEventID = 0; - - parent.draw = NULL; - parent.curEventID = 0; - parent.eventCount = 0; - parent.drawCount = 0; - parent.curEvents.clear(); - parent.debugMessages.clear(); - } - void ShiftForRemoved(uint32_t shiftDrawID, uint32_t shiftEID, size_t idx); struct ExecuteData { - ExecuteData() - : baseEvent(0), - lastEvent(0), - patched(false), - argBuf(NULL), - countBuf(NULL), - argOffs(0), - countOffs(0), - maxCount(0), - realCount(0) - { - } - - uint32_t baseEvent; - uint32_t lastEvent; - bool patched; - ID3D12Resource *argBuf; - ID3D12Resource *countBuf; - uint64_t argOffs; - uint64_t countOffs; - ResourceId sig; - UINT maxCount; - UINT realCount; + uint32_t baseEvent = 0; + uint32_t lastEvent = 0; + bool patched = false; + ID3D12Resource *argBuf = NULL; + ID3D12Resource *countBuf = NULL; + uint64_t argOffs = 0; + uint64_t countOffs = 0; + WrappedID3D12CommandSignature *sig = NULL; + UINT maxCount = 0; + UINT realCount = 0; }; vector crackedLists; diff --git a/renderdoc/driver/d3d12/d3d12_debug.cpp b/renderdoc/driver/d3d12/d3d12_debug.cpp index c69a44663..fa80be74e 100644 --- a/renderdoc/driver/d3d12/d3d12_debug.cpp +++ b/renderdoc/driver/d3d12/d3d12_debug.cpp @@ -33,6 +33,7 @@ #include "maths/vec.h" #include "stb/stb_truetype.h" #include "strings/string_utils.h" +#include "d3d12_command_list.h" #include "d3d12_command_queue.h" #include "d3d12_device.h" @@ -6955,8 +6956,7 @@ ResourceId D3D12DebugManager::RenderOverlay(ResourceId texid, CompType typeHint, ID3D12Resource *renderDepth = NULL; - D3D12Descriptor *dsView = - DescriptorFromPortableHandle(m_WrappedDevice->GetResourceManager(), rs.dsv); + D3D12Descriptor *dsView = GetWrapped(rs.dsv); D3D12_RESOURCE_DESC depthTexDesc = {}; D3D12_DEPTH_STENCIL_VIEW_DESC dsViewDesc = {}; @@ -7141,8 +7141,8 @@ ResourceId D3D12DebugManager::RenderOverlay(ResourceId texid, CompType typeHint, rs.pipe = GetResID(pso); rs.rtSingle = true; rs.rts.resize(1); - rs.rts[0] = ToPortableHandle(rtv); - rs.dsv = PortableHandle(); + rs.rts[0] = rtv; + rs.dsv = D3D12_CPU_DESCRIPTOR_HANDLE(); m_WrappedDevice->ReplayLog(0, eventID, eReplay_OnlyDraw); @@ -7233,8 +7233,8 @@ ResourceId D3D12DebugManager::RenderOverlay(ResourceId texid, CompType typeHint, rs.pipe = GetResID(redPSO); rs.rtSingle = true; rs.rts.resize(1); - rs.rts[0] = ToPortableHandle(rtv); - rs.dsv = PortableHandle(); + rs.rts[0] = rtv; + rs.dsv = D3D12_CPU_DESCRIPTOR_HANDLE(); m_WrappedDevice->ReplayLog(0, eventID, eReplay_OnlyDraw); @@ -7312,8 +7312,8 @@ ResourceId D3D12DebugManager::RenderOverlay(ResourceId texid, CompType typeHint, rs.pipe = GetResID(pso); rs.rtSingle = true; rs.rts.resize(1); - rs.rts[0] = ToPortableHandle(rtv); - rs.dsv = ToPortableHandle(dsv); + rs.rts[0] = rtv; + rs.dsv = dsv; m_WrappedDevice->ReplayLog(0, eventID, eReplay_OnlyDraw); @@ -7341,7 +7341,7 @@ ResourceId D3D12DebugManager::RenderOverlay(ResourceId texid, CompType typeHint, list = NULL; bool rtSingle = rs.rtSingle; - vector rts = rs.rts; + std::vector rts = rs.rts; if(overlay == DebugOverlay::ClearBeforePass) m_WrappedDevice->ReplayLog(0, events[0], eReplay_WithoutDraw); @@ -7350,20 +7350,14 @@ ResourceId D3D12DebugManager::RenderOverlay(ResourceId texid, CompType typeHint, for(size_t i = 0; i < rts.size(); i++) { - PortableHandle ph = rtSingle ? rts[0] : rts[i]; + D3D12Descriptor *desc = rtSingle ? GetWrapped(rts[0]) : GetWrapped(rts[i]); - WrappedID3D12DescriptorHeap *heap = - m_WrappedDevice->GetResourceManager()->GetLiveAs(ph.heap); - - if(heap) + if(desc) { - D3D12_CPU_DESCRIPTOR_HANDLE clearrtv = heap->GetCPUDescriptorHandleForHeapStart(); - clearrtv.ptr += ph.index * sizeof(D3D12Descriptor); - if(rtSingle) - clearrtv.ptr += i * sizeof(D3D12Descriptor); + desc += i; - list->ClearRenderTargetView(clearrtv, black, 0, NULL); + Unwrap(list)->ClearRenderTargetView(UnwrapCPU(desc), black, 0, NULL); } } @@ -7519,13 +7513,9 @@ ResourceId D3D12DebugManager::RenderOverlay(ResourceId texid, CompType typeHint, Vec4f viewport(rs.views[0].Width, rs.views[0].Height); - if(rs.dsv.heap != ResourceId()) + if(rs.dsv.ptr) { - WrappedID3D12DescriptorHeap *realDSVHeap = - m_WrappedDevice->GetResourceManager()->GetLiveAs(rs.dsv.heap); - - D3D12_CPU_DESCRIPTOR_HANDLE realDSV = realDSVHeap->GetCPUDescriptorHandleForHeapStart(); - realDSV.ptr += sizeof(D3D12Descriptor) * rs.dsv.index; + D3D12_CPU_DESCRIPTOR_HANDLE realDSV = Unwrap(rs.dsv); list->OMSetRenderTargets(1, &rtv, TRUE, &realDSV); } @@ -7856,8 +7846,8 @@ ResourceId D3D12DebugManager::RenderOverlay(ResourceId texid, CompType typeHint, rs.pipe = GetResID(redPSO); rs.rtSingle = true; rs.rts.resize(1); - rs.rts[0] = ToPortableHandle(rtv); - rs.dsv = ToPortableHandle(dsv); + rs.rts[0] = rtv; + rs.dsv = dsv; m_WrappedDevice->ReplayLog(0, eventID, eReplay_OnlyDraw); diff --git a/renderdoc/driver/d3d12/d3d12_replay.cpp b/renderdoc/driver/d3d12/d3d12_replay.cpp index baec5ea35..8e3926d51 100644 --- a/renderdoc/driver/d3d12/d3d12_replay.cpp +++ b/renderdoc/driver/d3d12/d3d12_replay.cpp @@ -1099,12 +1099,10 @@ void D3D12Replay::SavePipelineState() { D3D12Pipe::View &view = state.m_OM.RenderTargets[i]; - PortableHandle h = rs.rtSingle ? rs.rts[0] : rs.rts[i]; + D3D12Descriptor *desc = rs.rtSingle ? GetWrapped(rs.rts[0]) : GetWrapped(rs.rts[i]); - if(h.heap != ResourceId()) + if(desc) { - D3D12Descriptor *desc = DescriptorFromPortableHandle(rm, h); - if(rs.rtSingle) desc += i; @@ -1118,9 +1116,9 @@ void D3D12Replay::SavePipelineState() { D3D12Pipe::View &view = state.m_OM.DepthTarget; - if(rs.dsv.heap != ResourceId()) + if(rs.dsv.ptr) { - D3D12Descriptor *desc = DescriptorFromPortableHandle(rm, rs.dsv); + D3D12Descriptor *desc = GetWrapped(rs.dsv); view.RootElement = 0; view.Immediate = false; @@ -1255,12 +1253,10 @@ bool D3D12Replay::IsRenderOutput(ResourceId id) for(size_t i = 0; i < rs.rts.size(); i++) { - PortableHandle h = rs.rtSingle ? rs.rts[0] : rs.rts[i]; + D3D12Descriptor *desc = rs.rtSingle ? GetWrapped(rs.rts[0]) : GetWrapped(rs.rts[i]); - if(h.heap != ResourceId()) + if(desc) { - D3D12Descriptor *desc = DescriptorFromPortableHandle(m_pDevice->GetResourceManager(), h); - if(rs.rtSingle) desc += i; @@ -1269,9 +1265,9 @@ bool D3D12Replay::IsRenderOutput(ResourceId id) } } - if(rs.dsv.heap != ResourceId()) + if(rs.dsv.ptr) { - D3D12Descriptor *desc = DescriptorFromPortableHandle(m_pDevice->GetResourceManager(), rs.dsv); + D3D12Descriptor *desc = GetWrapped(rs.dsv); if(id == GetResID(desc->nonsamp.resource)) return true; diff --git a/renderdoc/driver/d3d12/d3d12_state.cpp b/renderdoc/driver/d3d12/d3d12_state.cpp index 3ec206682..7839b6429 100644 --- a/renderdoc/driver/d3d12/d3d12_state.cpp +++ b/renderdoc/driver/d3d12/d3d12_state.cpp @@ -34,7 +34,7 @@ D3D12RenderState::D3D12RenderState() rts.clear(); rtSingle = false; - dsv = PortableHandle(); + dsv = D3D12_CPU_DESCRIPTOR_HANDLE(); m_ResourceManager = NULL; @@ -89,7 +89,7 @@ vector D3D12RenderState::GetRTVIDs() const { if(!rts.empty()) { - const D3D12Descriptor *descs = DescriptorFromPortableHandle(GetResourceManager(), rts[0]); + const D3D12Descriptor *descs = GetWrapped(rts[0]); for(UINT i = 0; i < rts.size(); i++) { @@ -102,13 +102,10 @@ vector D3D12RenderState::GetRTVIDs() const { for(UINT i = 0; i < rts.size(); i++) { - WrappedID3D12DescriptorHeap *heap = - GetResourceManager()->GetLiveAs(rts[0].heap); + const D3D12Descriptor *desc = GetWrapped(rts[i]); - const D3D12Descriptor &desc = heap->GetDescriptors()[rts[i].index]; - - RDCASSERT(desc.GetType() == D3D12DescriptorType::RTV); - ret.push_back(GetResID(desc.nonsamp.resource)); + RDCASSERT(desc->GetType() == D3D12DescriptorType::RTV); + ret.push_back(GetResID(desc->nonsamp.resource)); } } @@ -117,9 +114,9 @@ vector D3D12RenderState::GetRTVIDs() const ResourceId D3D12RenderState::GetDSVID() const { - if(dsv.heap != ResourceId()) + if(dsv.ptr) { - const D3D12Descriptor *desc = DescriptorFromPortableHandle(GetResourceManager(), dsv); + const D3D12Descriptor *desc = GetWrapped(dsv); RDCASSERT(desc->GetType() == D3D12DescriptorType::DSV); @@ -186,20 +183,20 @@ void D3D12RenderState::ApplyState(ID3D12GraphicsCommandList *cmd) const } } - if(!rts.empty() || dsv.heap != ResourceId()) + if(!rts.empty() || dsv.ptr) { D3D12_CPU_DESCRIPTOR_HANDLE rtHandles[8]; - D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = CPUHandleFromPortableHandle(GetResourceManager(), dsv); + D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = Unwrap(dsv); UINT rtCount = (UINT)rts.size(); UINT numActualHandles = rtSingle ? RDCMIN(1U, rtCount) : rtCount; for(UINT i = 0; i < numActualHandles; i++) - rtHandles[i] = CPUHandleFromPortableHandle(GetResourceManager(), rts[i]); + rtHandles[i] = Unwrap(rts[i]); // need to unwrap here, as FromPortableHandle unwraps too. Unwrap(cmd)->OMSetRenderTargets((UINT)rts.size(), rtHandles, rtSingle ? TRUE : FALSE, - dsv.heap != ResourceId() ? &dsvHandle : NULL); + dsv.ptr ? &dsvHandle : NULL); } } diff --git a/renderdoc/driver/d3d12/d3d12_state.h b/renderdoc/driver/d3d12/d3d12_state.h index 92f6dc38b..a7ed59e8e 100644 --- a/renderdoc/driver/d3d12/d3d12_state.h +++ b/renderdoc/driver/d3d12/d3d12_state.h @@ -52,9 +52,9 @@ struct D3D12RenderState vector views; vector scissors; - vector rts; + vector rts; bool rtSingle; - PortableHandle dsv; + D3D12_CPU_DESCRIPTOR_HANDLE dsv; vector GetRTVIDs() const; ResourceId GetDSVID() const;