From 5452940739a95762f899d72d24b7b018e091c504 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 30 Oct 2017 17:47:23 +0000 Subject: [PATCH] Update D3D12 command queue wrapping code to new serialisation --- .../driver/d3d12/d3d12_command_queue_wrap.cpp | 642 +++++++++--------- 1 file changed, 311 insertions(+), 331 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp index a3dcfb89a..796a3c02b 100644 --- a/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp @@ -26,8 +26,9 @@ #include "d3d12_command_list.h" #include "d3d12_resources.h" +template bool WrappedID3D12CommandQueue::Serialise_UpdateTileMappings( - ID3D12Resource *pResource, UINT NumResourceRegions, + SerialiserType &ser, ID3D12Resource *pResource, UINT NumResourceRegions, const D3D12_TILED_RESOURCE_COORDINATE *pResourceRegionStartCoordinates, const D3D12_TILE_REGION_SIZE *pResourceRegionSizes, ID3D12Heap *pHeap, UINT NumRanges, const D3D12_TILE_RANGE_FLAGS *pRangeFlags, const UINT *pHeapRangeStartOffsets, @@ -50,9 +51,11 @@ void STDMETHODCALLTYPE WrappedID3D12CommandQueue::UpdateTileMappings( pHeapRangeStartOffsets, pRangeTileCounts, Flags); } +template bool WrappedID3D12CommandQueue::Serialise_CopyTileMappings( - ID3D12Resource *pDstResource, const D3D12_TILED_RESOURCE_COORDINATE *pDstRegionStartCoordinate, - ID3D12Resource *pSrcResource, const D3D12_TILED_RESOURCE_COORDINATE *pSrcRegionStartCoordinate, + SerialiserType &ser, ID3D12Resource *pDstResource, + const D3D12_TILED_RESOURCE_COORDINATE *pDstRegionStartCoordinate, ID3D12Resource *pSrcResource, + const D3D12_TILED_RESOURCE_COORDINATE *pSrcRegionStartCoordinate, const D3D12_TILE_REGION_SIZE *pRegionSize, D3D12_TILE_MAPPING_FLAGS Flags) { D3D12NOTIMP("Tiled Resources"); @@ -69,359 +72,314 @@ void STDMETHODCALLTYPE WrappedID3D12CommandQueue::CopyTileMappings( pSrcRegionStartCoordinate, pRegionSize, Flags); } -bool WrappedID3D12CommandQueue::Serialise_ExecuteCommandLists(UINT NumCommandLists, +template +bool WrappedID3D12CommandQueue::Serialise_ExecuteCommandLists(SerialiserType &ser, + UINT NumCommandLists, ID3D12CommandList *const *ppCommandLists) { - SERIALISE_ELEMENT(ResourceId, queueId, GetResourceID()); - SERIALISE_ELEMENT(UINT, numCmds, NumCommandLists); + ID3D12CommandQueue *pQueue = this; + SERIALISE_ELEMENT(pQueue); + SERIALISE_ELEMENT_ARRAY(ppCommandLists, NumCommandLists); - vector cmdIds; - ID3D12GraphicsCommandList **cmds = - m_State >= WRITING ? NULL : new ID3D12GraphicsCommandList *[numCmds]; - - if(m_State >= WRITING) { - for(UINT i = 0; i < numCmds; i++) + std::vector DebugMessages; + + if(ser.IsWriting()) + DebugMessages = m_pDevice->GetDebugMessages(); + + SERIALISE_ELEMENT(DebugMessages); + + if(ser.IsReading() && IsLoading(m_State)) { - D3D12ResourceRecord *record = GetRecord(ppCommandLists[i]); - RDCASSERT(record->bakedCommands); - if(record->bakedCommands) - cmdIds.push_back(record->bakedCommands->GetResourceID()); - } - } - - m_pSerialiser->Serialise("ppCommandLists", cmdIds); - - if(m_State < WRITING) - { - for(UINT i = 0; i < numCmds; i++) - { - cmds[i] = cmdIds[i] != ResourceId() - ? GetResourceManager()->GetLiveAs(cmdIds[i]) - : NULL; - } - } - - const string desc = m_pSerialiser->GetDebugStr(); - - // debug messages - { - vector debugMessages; - - if(m_State == WRITING_CAPFRAME) - debugMessages = m_pDevice->GetDebugMessages(); - - SERIALISE_ELEMENT(uint32_t, NumMessages, (uint32_t)debugMessages.size()); - - for(uint32_t i = 0; i < NumMessages; i++) - { - ScopedContext msgscope(m_pSerialiser, "DebugMessage", "DebugMessage", 0, false); - - std::string msgDesc; - if(m_State >= WRITING) - msgDesc = debugMessages[i].description; - - SERIALISE_ELEMENT(MessageCategory, Category, debugMessages[i].category); - SERIALISE_ELEMENT(MessageSeverity, Severity, debugMessages[i].severity); - SERIALISE_ELEMENT(uint32_t, ID, debugMessages[i].messageID); - SERIALISE_ELEMENT(string, Description, msgDesc); - - if(m_State == READING) - { - DebugMessage msg; - msg.source = MessageSource::API; - msg.category = Category; - msg.severity = Severity; - msg.messageID = ID; - msg.description = Description; - + for(const DebugMessage &msg : DebugMessages) m_Cmd.m_EventMessages.push_back(msg); - } } } - ID3D12CommandQueue *real = NULL; - - if(m_State <= EXECUTING) + if(IsReplayingAndReading()) { - real = Unwrap(GetResourceManager()->GetLiveAs(queueId)); + ID3D12CommandQueue *real = Unwrap(pQueue); - if(m_PrevQueueId != queueId) + if(m_PrevQueueId != GetResID(pQueue)) { RDCDEBUG("Previous queue execution was on queue %llu, now executing %llu, syncing GPU", - m_PrevQueueId, queueId); + m_PrevQueueId, GetResID(pQueue)); if(m_PrevQueueId != ResourceId()) - m_pDevice->GPUSync(GetResourceManager()->GetLiveAs(m_PrevQueueId)); + m_pDevice->GPUSync(GetResourceManager()->GetCurrentAs(m_PrevQueueId)); - m_PrevQueueId = queueId; + m_PrevQueueId = GetResID(pQueue); } - } - if(m_State == READING) - { - for(uint32_t i = 0; i < numCmds; i++) + if(IsLoading(m_State)) { - if(m_Cmd.m_BakedCmdListInfo[cmdIds[i]].executeEvents.empty() || - m_Cmd.m_BakedCmdListInfo[cmdIds[i]].executeEvents[0].patched) + for(uint32_t i = 0; i < NumCommandLists; i++) { - ID3D12CommandList *list = Unwrap(cmds[i]); - real->ExecuteCommandLists(1, &list); -#if ENABLED(SINGLE_FLUSH_VALIDATE) - m_pDevice->GPUSync(); -#endif - } - else - { - BakedCmdListInfo &info = m_Cmd.m_BakedCmdListInfo[cmdIds[i]]; + ResourceId cmd = GetResourceManager()->GetOriginalID(GetResID(ppCommandLists[i])); - // execute the first half of the cracked list - ID3D12CommandList *list = Unwrap(info.crackedLists[0]); - real->ExecuteCommandLists(1, &list); - - for(size_t c = 1; c < info.crackedLists.size(); c++) + if(m_Cmd.m_BakedCmdListInfo[cmd].executeEvents.empty() || + m_Cmd.m_BakedCmdListInfo[cmd].executeEvents[0].patched) { - // ensure all work on all queues has finished - m_pDevice->GPUSyncAllQueues(); - - // readback the patch buffer and perform patching - m_ReplayList->PatchExecuteIndirect(info, uint32_t(c - 1)); - - // execute next list with this indirect. - list = Unwrap(info.crackedLists[c]); + ID3D12CommandList *list = Unwrap(ppCommandLists[i]); real->ExecuteCommandLists(1, &list); - } - #if ENABLED(SINGLE_FLUSH_VALIDATE) - m_pDevice->GPUSync(); + m_pDevice->GPUSync(); #endif - } - } - - for(uint32_t i = 0; i < numCmds; i++) - { - ResourceId cmd = GetResourceManager()->GetLiveID(cmdIds[i]); - m_pDevice->ApplyBarriers(m_Cmd.m_BakedCmdListInfo[cmd].barriers); - } - - m_Cmd.AddEvent(desc); - - // we're adding multiple events, need to increment ourselves - m_Cmd.m_RootEventID++; - - string basename = "ExecuteCommandLists(" + ToStr(numCmds) + ")"; - - for(uint32_t c = 0; c < numCmds; c++) - { - string name = StringFormat::Fmt("=> %s[%u]: ID3D12CommandList(%s)", basename.c_str(), c, - ToStr(cmdIds[c]).c_str()); - - // add a fake marker - DrawcallDescription draw; - draw.name = name; - draw.flags = DrawFlags::PassBoundary | DrawFlags::BeginPass; - m_Cmd.AddEvent(name); - m_Cmd.AddDrawcall(draw, true); - m_Cmd.m_RootEventID++; - - BakedCmdListInfo &cmdBufInfo = m_Cmd.m_BakedCmdListInfo[cmdIds[c]]; - - // insert the baked command list in-line into this list of notes, assigning new event and - // drawIDs - m_Cmd.InsertDrawsAndRefreshIDs(cmdIds[c], cmdBufInfo.draw->children); - - for(size_t e = 0; e < cmdBufInfo.draw->executedCmds.size(); e++) - { - vector &submits = - m_Cmd.m_Partial[D3D12CommandData::Secondary].cmdListExecs[cmdBufInfo.draw->executedCmds[e]]; - - for(size_t s = 0; s < submits.size(); s++) - submits[s] += m_Cmd.m_RootEventID; - } - - for(size_t i = 0; i < cmdBufInfo.debugMessages.size(); i++) - { - DebugMessage msg = cmdBufInfo.debugMessages[i]; - msg.eventID += m_Cmd.m_RootEventID; - m_pDevice->AddDebugMessage(msg); - } - - // only primary command lists can be submitted - m_Cmd.m_Partial[D3D12CommandData::Primary].cmdListExecs[cmdIds[c]].push_back( - m_Cmd.m_RootEventID); - - m_Cmd.m_RootEventID += cmdBufInfo.eventCount; - m_Cmd.m_RootDrawcallID += cmdBufInfo.drawCount; - - name = StringFormat::Fmt("=> %s[%u]: Close(%s)", basename.c_str(), c, ToStr(cmdIds[c]).c_str()); - draw.name = name; - draw.flags = DrawFlags::PassBoundary | DrawFlags::EndPass; - m_Cmd.AddEvent(name); - m_Cmd.AddDrawcall(draw, true); - m_Cmd.m_RootEventID++; - } - - // account for the outer loop thinking we've added one event and incrementing, - // since we've done all the handling ourselves this will be off by one. - m_Cmd.m_RootEventID--; - } - else if(m_State == EXECUTING) - { - // account for the queue submit event - m_Cmd.m_RootEventID++; - - uint32_t startEID = m_Cmd.m_RootEventID; - - // advance m_CurEventID to match the events added when reading - for(uint32_t c = 0; c < numCmds; c++) - { - // 2 extra for the virtual labels around the command list - m_Cmd.m_RootEventID += 2 + m_Cmd.m_BakedCmdListInfo[cmdIds[c]].eventCount; - m_Cmd.m_RootDrawcallID += 2 + m_Cmd.m_BakedCmdListInfo[cmdIds[c]].drawCount; - } - - // same accounting for the outer loop as above - m_Cmd.m_RootEventID--; - - if(numCmds == 0) - { - // do nothing, don't bother with the logic below - } - else if(m_Cmd.m_LastEventID <= startEID) - { -#if ENABLED(VERBOSE_PARTIAL_REPLAY) - RDCDEBUG("Queue Submit no replay %u == %u", m_Cmd.m_LastEventID, startEID); -#endif - } - else if(m_Cmd.m_DrawcallCallback && m_Cmd.m_DrawcallCallback->RecordAllCmds()) - { -#if ENABLED(VERBOSE_PARTIAL_REPLAY) - RDCDEBUG("Queue Submit re-recording from %u", m_Cmd.m_RootEventID); -#endif - - vector rerecordedCmds; - - for(uint32_t c = 0; c < numCmds; c++) - { - ID3D12CommandList *cmd = m_Cmd.RerecordCmdList(cmdIds[c]); - ResourceId rerecord = GetResID(cmd); -#if ENABLED(VERBOSE_PARTIAL_REPLAY) - RDCDEBUG("Queue Submit fully re-recorded replay of %llu, using %llu", cmdIds[c], rerecord); -#endif - rerecordedCmds.push_back(Unwrap(cmd)); - - m_pDevice->ApplyBarriers(m_Cmd.m_BakedCmdListInfo[rerecord].barriers); - } - -#if ENABLED(SINGLE_FLUSH_VALIDATE) - for(size_t i = 0; i < rerecordedCmds.size(); i++) - { - real->ExecuteCommandLists(1, &rerecordedCmds[i]); - m_pDevice->GPUSync(); - } -#else - real->ExecuteCommandLists((UINT)rerecordedCmds.size(), &rerecordedCmds[0]); -#endif - } - else if(m_Cmd.m_LastEventID > startEID && m_Cmd.m_LastEventID < m_Cmd.m_RootEventID) - { -#if ENABLED(VERBOSE_PARTIAL_REPLAY) - RDCDEBUG("Queue Submit partial replay %u < %u", m_Cmd.m_LastEventID, m_Cmd.m_RootEventID); -#endif - - uint32_t eid = startEID; - - vector trimmedCmdIds; - vector trimmedCmds; - - for(uint32_t c = 0; c < numCmds; c++) - { - // account for the virtual label at the start of the events here - // so it matches up to baseEvent - eid++; - - uint32_t end = eid + m_Cmd.m_BakedCmdListInfo[cmdIds[c]].eventCount; - - if(eid == m_Cmd.m_Partial[D3D12CommandData::Primary].baseEvent) - { - ID3D12GraphicsCommandList *list = - m_Cmd.RerecordCmdList(cmdIds[c], D3D12CommandData::Primary); - ResourceId partial = GetResID(list); -#if ENABLED(VERBOSE_PARTIAL_REPLAY) - RDCDEBUG("Queue Submit partial replay of %llu at %u, using %llu", cmdIds[c], eid, partial); -#endif - trimmedCmdIds.push_back(partial); - trimmedCmds.push_back(Unwrap(list)); - } - else if(m_Cmd.m_LastEventID >= end) - { -#if ENABLED(VERBOSE_PARTIAL_REPLAY) - RDCDEBUG("Queue Submit full replay %llu", cmdIds[c]); -#endif - trimmedCmdIds.push_back(cmdIds[c]); - trimmedCmds.push_back(Unwrap(GetResourceManager()->GetLiveAs(cmdIds[c]))); } else { -#if ENABLED(VERBOSE_PARTIAL_REPLAY) - RDCDEBUG("Queue not submitting %llu", cmdIds[c]); -#endif - } + BakedCmdListInfo &info = m_Cmd.m_BakedCmdListInfo[cmd]; - // 1 extra to account for the virtual end command list label (begin is accounted for - // above) - eid += 1 + m_Cmd.m_BakedCmdListInfo[cmdIds[c]].eventCount; - } + // execute the first half of the cracked list + ID3D12CommandList *list = Unwrap(info.crackedLists[0]); + real->ExecuteCommandLists(1, &list); - RDCASSERT(trimmedCmds.size() > 0); + for(size_t c = 1; c < info.crackedLists.size(); c++) + { + // ensure all work on all queues has finished + m_pDevice->GPUSyncAllQueues(); + + // readback the patch buffer and perform patching + m_ReplayList->PatchExecuteIndirect(info, uint32_t(c - 1)); + + // execute next list with this indirect. + list = Unwrap(info.crackedLists[c]); + real->ExecuteCommandLists(1, &list); + } #if ENABLED(SINGLE_FLUSH_VALIDATE) - for(size_t i = 0; i < trimmedCmds.size(); i++) - { - real->ExecuteCommandLists(1, &trimmedCmds[i]); - m_pDevice->GPUSync(); - } -#else - real->ExecuteCommandLists((UINT)trimmedCmds.size(), &trimmedCmds[0]); + m_pDevice->GPUSync(); #endif + } + } - for(uint32_t i = 0; i < trimmedCmdIds.size(); i++) + for(uint32_t i = 0; i < NumCommandLists; i++) { - ResourceId cmd = trimmedCmdIds[i]; + ResourceId cmd = GetResID(ppCommandLists[i]); m_pDevice->ApplyBarriers(m_Cmd.m_BakedCmdListInfo[cmd].barriers); } + + m_Cmd.AddEvent(); + + // we're adding multiple events, need to increment ourselves + m_Cmd.m_RootEventID++; + + std::string basename = StringFormat::Fmt("ExecuteCommandLists(%u)", NumCommandLists); + + for(uint32_t c = 0; c < NumCommandLists; c++) + { + ResourceId cmd = GetResourceManager()->GetOriginalID(GetResID(ppCommandLists[c])); + + // add a fake marker + DrawcallDescription draw; + draw.name = StringFormat::Fmt("=> %s[%u]: ID3D12CommandList(%s)", basename.c_str(), c, + ToStr(cmd).c_str()); + draw.flags = DrawFlags::PassBoundary | DrawFlags::BeginPass; + m_Cmd.AddEvent(); + m_Cmd.AddDrawcall(draw, true); + m_Cmd.m_RootEventID++; + + BakedCmdListInfo &cmdBufInfo = m_Cmd.m_BakedCmdListInfo[cmd]; + + // insert the baked command list in-line into this list of notes, assigning new event and + // drawIDs + m_Cmd.InsertDrawsAndRefreshIDs(cmd, cmdBufInfo.draw->children); + + for(size_t e = 0; e < cmdBufInfo.draw->executedCmds.size(); e++) + { + vector &submits = m_Cmd.m_Partial[D3D12CommandData::Secondary] + .cmdListExecs[cmdBufInfo.draw->executedCmds[e]]; + + for(size_t s = 0; s < submits.size(); s++) + submits[s] += m_Cmd.m_RootEventID; + } + + for(size_t i = 0; i < cmdBufInfo.debugMessages.size(); i++) + { + DebugMessage msg = cmdBufInfo.debugMessages[i]; + msg.eventID += m_Cmd.m_RootEventID; + m_pDevice->AddDebugMessage(msg); + } + + // only primary command lists can be submitted + m_Cmd.m_Partial[D3D12CommandData::Primary].cmdListExecs[cmd].push_back(m_Cmd.m_RootEventID); + + m_Cmd.m_RootEventID += cmdBufInfo.eventCount; + m_Cmd.m_RootDrawcallID += cmdBufInfo.drawCount; + + draw.name = + StringFormat::Fmt("=> %s[%u]: Close(%s)", basename.c_str(), c, ToStr(cmd).c_str()); + draw.flags = DrawFlags::PassBoundary | DrawFlags::EndPass; + m_Cmd.AddEvent(); + m_Cmd.AddDrawcall(draw, true); + m_Cmd.m_RootEventID++; + } + + // account for the outer loop thinking we've added one event and incrementing, + // since we've done all the handling ourselves this will be off by one. + m_Cmd.m_RootEventID--; } else { + // account for the queue submit event + m_Cmd.m_RootEventID++; + + uint32_t startEID = m_Cmd.m_RootEventID; + + // advance m_CurEventID to match the events added when reading + for(uint32_t c = 0; c < NumCommandLists; c++) + { + ResourceId cmd = GetResourceManager()->GetOriginalID(GetResID(ppCommandLists[c])); + + // 2 extra for the virtual labels around the command list + m_Cmd.m_RootEventID += 2 + m_Cmd.m_BakedCmdListInfo[cmd].eventCount; + m_Cmd.m_RootDrawcallID += 2 + m_Cmd.m_BakedCmdListInfo[cmd].drawCount; + } + + // same accounting for the outer loop as above + m_Cmd.m_RootEventID--; + + if(NumCommandLists == 0) + { + // do nothing, don't bother with the logic below + } + else if(m_Cmd.m_LastEventID <= startEID) + { #if ENABLED(VERBOSE_PARTIAL_REPLAY) - RDCDEBUG("Queue Submit full replay %u >= %u", m_Cmd.m_LastEventID, m_Cmd.m_RootEventID); + RDCDEBUG("Queue Submit no replay %u == %u", m_Cmd.m_LastEventID, startEID); +#endif + } + else if(m_Cmd.m_DrawcallCallback && m_Cmd.m_DrawcallCallback->RecordAllCmds()) + { +#if ENABLED(VERBOSE_PARTIAL_REPLAY) + RDCDEBUG("Queue Submit re-recording from %u", m_Cmd.m_RootEventID); #endif - ID3D12CommandList **unwrapped = new ID3D12CommandList *[numCmds]; - for(uint32_t i = 0; i < numCmds; i++) - unwrapped[i] = Unwrap(cmds[i]); + vector rerecordedCmds; + + for(uint32_t c = 0; c < NumCommandLists; c++) + { + ResourceId cmdId = GetResourceManager()->GetOriginalID(GetResID(ppCommandLists[c])); + + ID3D12CommandList *cmd = m_Cmd.RerecordCmdList(cmdId); + ResourceId rerecord = GetResID(cmd); +#if ENABLED(VERBOSE_PARTIAL_REPLAY) + RDCDEBUG("Queue Submit fully re-recorded replay of %llu, using %llu", cmdId, rerecord); +#endif + rerecordedCmds.push_back(Unwrap(cmd)); + + m_pDevice->ApplyBarriers(m_Cmd.m_BakedCmdListInfo[rerecord].barriers); + } #if ENABLED(SINGLE_FLUSH_VALIDATE) - for(UINT i = 0; i < numCmds; i++) - { - real->ExecuteCommandLists(1, &unwrapped[i]); - m_pDevice->GPUSync(); - } + for(size_t i = 0; i < rerecordedCmds.size(); i++) + { + real->ExecuteCommandLists(1, &rerecordedCmds[i]); + m_pDevice->GPUSync(); + } #else - real->ExecuteCommandLists(numCmds, unwrapped); + real->ExecuteCommandLists((UINT)rerecordedCmds.size(), &rerecordedCmds[0]); +#endif + } + else if(m_Cmd.m_LastEventID > startEID && m_Cmd.m_LastEventID < m_Cmd.m_RootEventID) + { +#if ENABLED(VERBOSE_PARTIAL_REPLAY) + RDCDEBUG("Queue Submit partial replay %u < %u", m_Cmd.m_LastEventID, m_Cmd.m_RootEventID); #endif - SAFE_DELETE_ARRAY(unwrapped); + uint32_t eid = startEID; - for(uint32_t i = 0; i < numCmds; i++) + vector trimmedCmdIds; + vector trimmedCmds; + + for(uint32_t c = 0; c < NumCommandLists; c++) + { + ResourceId cmdId = GetResourceManager()->GetOriginalID(GetResID(ppCommandLists[c])); + + // account for the virtual label at the start of the events here + // so it matches up to baseEvent + eid++; + + uint32_t end = eid + m_Cmd.m_BakedCmdListInfo[cmdId].eventCount; + + if(eid == m_Cmd.m_Partial[D3D12CommandData::Primary].baseEvent) + { + ID3D12GraphicsCommandList *list = m_Cmd.RerecordCmdList(cmdId, D3D12CommandData::Primary); + ResourceId partial = GetResID(list); +#if ENABLED(VERBOSE_PARTIAL_REPLAY) + RDCDEBUG("Queue Submit partial replay of %llu at %u, using %llu", cmdId, eid, partial); +#endif + trimmedCmdIds.push_back(partial); + trimmedCmds.push_back(Unwrap(list)); + } + else if(m_Cmd.m_LastEventID >= end) + { +#if ENABLED(VERBOSE_PARTIAL_REPLAY) + RDCDEBUG("Queue Submit full replay %llu", cmdId); +#endif + trimmedCmdIds.push_back(cmdId); + trimmedCmds.push_back(Unwrap(ppCommandLists[c])); + } + else + { +#if ENABLED(VERBOSE_PARTIAL_REPLAY) + RDCDEBUG("Queue not submitting %llu", cmdId); +#endif + } + + // 1 extra to account for the virtual end command list label (begin is accounted for + // above) + eid += 1 + m_Cmd.m_BakedCmdListInfo[cmdId].eventCount; + } + + RDCASSERT(trimmedCmds.size() > 0); + +#if ENABLED(SINGLE_FLUSH_VALIDATE) + for(size_t i = 0; i < trimmedCmds.size(); i++) + { + real->ExecuteCommandLists(1, &trimmedCmds[i]); + m_pDevice->GPUSync(); + } +#else + real->ExecuteCommandLists((UINT)trimmedCmds.size(), &trimmedCmds[0]); +#endif + + for(uint32_t i = 0; i < trimmedCmdIds.size(); i++) + { + ResourceId cmd = trimmedCmdIds[i]; + m_pDevice->ApplyBarriers(m_Cmd.m_BakedCmdListInfo[cmd].barriers); + } + } + else { - ResourceId cmd = GetResourceManager()->GetLiveID(cmdIds[i]); - m_pDevice->ApplyBarriers(m_Cmd.m_BakedCmdListInfo[cmd].barriers); +#if ENABLED(VERBOSE_PARTIAL_REPLAY) + RDCDEBUG("Queue Submit full replay %u >= %u", m_Cmd.m_LastEventID, m_Cmd.m_RootEventID); +#endif + + ID3D12CommandList **unwrapped = new ID3D12CommandList *[NumCommandLists]; + for(uint32_t i = 0; i < NumCommandLists; i++) + unwrapped[i] = Unwrap(ppCommandLists[i]); + +#if ENABLED(SINGLE_FLUSH_VALIDATE) + for(UINT i = 0; i < NumCommandLists; i++) + { + real->ExecuteCommandLists(1, &unwrapped[i]); + m_pDevice->GPUSync(); + } +#else + real->ExecuteCommandLists(NumCommandLists, unwrapped); +#endif + + SAFE_DELETE_ARRAY(unwrapped); + + for(uint32_t i = 0; i < NumCommandLists; i++) + { + ResourceId cmd = GetResID(ppCommandLists[i]); + m_pDevice->ApplyBarriers(m_Cmd.m_BakedCmdListInfo[cmd].barriers); + } } } } - SAFE_DELETE_ARRAY(cmds); - return true; } @@ -434,13 +392,13 @@ void STDMETHODCALLTYPE WrappedID3D12CommandQueue::ExecuteCommandLists( m_pReal->ExecuteCommandLists(NumCommandLists, unwrapped); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { SCOPED_LOCK(m_Lock); SCOPED_LOCK(m_pDevice->GetCapTransitionLock()); - bool capframe = (m_State == WRITING_CAPFRAME); - set refdIDs; + bool capframe = IsActiveCapturing(m_State); + std::set refdIDs; for(UINT i = 0; i < NumCommandLists; i++) { @@ -555,11 +513,11 @@ void STDMETHODCALLTYPE WrappedID3D12CommandQueue::ExecuteCommandLists( if(capframe) { - vector maps = m_pDevice->GetMaps(); + std::vector maps = m_pDevice->GetMaps(); for(auto it = maps.begin(); it != maps.end(); ++it) { - WrappedID3D12Resource *res = it->res; + WrappedID3D12Resource *res = GetWrapped(it->res); UINT subres = it->subres; size_t size = (size_t)it->totalSize; @@ -609,10 +567,11 @@ void STDMETHODCALLTYPE WrappedID3D12CommandQueue::ExecuteCommandLists( } } - for(UINT i = 0; i < NumCommandLists; i++) { - SCOPED_SERIALISE_CONTEXT(EXECUTE_CMD_LISTS); - Serialise_ExecuteCommandLists(1, ppCommandLists + i); + WriteSerialiser &ser = m_ScratchSerialiser; + ser.SetDrawChunk(); + SCOPED_SERIALISE_CHUNK(D3D12Chunk::Queue_ExecuteCommandLists); + Serialise_ExecuteCommandLists(ser, NumCommandLists, ppCommandLists); m_QueueRecord->AddChunk(scope.Get()); } @@ -637,16 +596,16 @@ void STDMETHODCALLTYPE WrappedID3D12CommandQueue::EndEvent() m_pReal->EndEvent(); } -bool WrappedID3D12CommandQueue::Serialise_Signal(ID3D12Fence *pFence, UINT64 Value) +template +bool WrappedID3D12CommandQueue::Serialise_Signal(SerialiserType &ser, ID3D12Fence *pFence, + UINT64 Value) { - SERIALISE_ELEMENT(ResourceId, Fence, GetResID(pFence)); - SERIALISE_ELEMENT(UINT64, val, Value); + SERIALISE_ELEMENT(pFence); + SERIALISE_ELEMENT(Value); - if(m_State <= EXECUTING && GetResourceManager()->HasLiveResource(Fence)) + if(IsReplayingAndReading() && pFence) { - pFence = GetResourceManager()->GetLiveAs(Fence); - - m_pReal->Signal(Unwrap(pFence), val); + m_pReal->Signal(Unwrap(pFence), Value); } return true; @@ -654,12 +613,13 @@ bool WrappedID3D12CommandQueue::Serialise_Signal(ID3D12Fence *pFence, UINT64 Val HRESULT STDMETHODCALLTYPE WrappedID3D12CommandQueue::Signal(ID3D12Fence *pFence, UINT64 Value) { - if(m_State == WRITING_CAPFRAME) + if(IsActiveCapturing(m_State)) { SCOPED_LOCK(m_Lock); - SCOPED_SERIALISE_CONTEXT(SIGNAL); - Serialise_Signal(pFence, Value); + WriteSerialiser &ser = m_ScratchSerialiser; + SCOPED_SERIALISE_CHUNK(D3D12Chunk::Queue_Signal); + Serialise_Signal(ser, pFence, Value); m_QueueRecord->AddChunk(scope.Get()); GetResourceManager()->MarkResourceFrameReferenced(GetResID(pFence), eFrameRef_Read); @@ -668,15 +628,14 @@ HRESULT STDMETHODCALLTYPE WrappedID3D12CommandQueue::Signal(ID3D12Fence *pFence, return m_pReal->Signal(Unwrap(pFence), Value); } -bool WrappedID3D12CommandQueue::Serialise_Wait(ID3D12Fence *pFence, UINT64 Value) +template +bool WrappedID3D12CommandQueue::Serialise_Wait(SerialiserType &ser, ID3D12Fence *pFence, UINT64 Value) { - SERIALISE_ELEMENT(ResourceId, Fence, GetResID(pFence)); - SERIALISE_ELEMENT(UINT64, val, Value); + SERIALISE_ELEMENT(pFence); + SERIALISE_ELEMENT(Value); - if(m_State <= EXECUTING && GetResourceManager()->HasLiveResource(Fence)) + if(IsReplayingAndReading() && pFence) { - // pFence = GetResourceManager()->GetLiveAs(Fence); - m_pDevice->GPUSync(); } @@ -685,12 +644,13 @@ bool WrappedID3D12CommandQueue::Serialise_Wait(ID3D12Fence *pFence, UINT64 Value HRESULT STDMETHODCALLTYPE WrappedID3D12CommandQueue::Wait(ID3D12Fence *pFence, UINT64 Value) { - if(m_State == WRITING_CAPFRAME) + if(IsActiveCapturing(m_State)) { SCOPED_LOCK(m_Lock); - SCOPED_SERIALISE_CONTEXT(WAIT); - Serialise_Wait(pFence, Value); + WriteSerialiser &ser = m_ScratchSerialiser; + SCOPED_SERIALISE_CHUNK(D3D12Chunk::Queue_Wait); + Serialise_Wait(ser, pFence, Value); m_QueueRecord->AddChunk(scope.Get()); GetResourceManager()->MarkResourceFrameReferenced(GetResID(pFence), eFrameRef_Read); @@ -708,4 +668,24 @@ HRESULT STDMETHODCALLTYPE WrappedID3D12CommandQueue::GetClockCalibration(UINT64 UINT64 *pCpuTimestamp) { return m_pReal->GetClockCalibration(pGpuTimestamp, pCpuTimestamp); -} \ No newline at end of file +} + +INSTANTIATE_FUNCTION_SERIALISED( + void, WrappedID3D12CommandQueue, UpdateTileMappings, ID3D12Resource *pResource, + UINT NumResourceRegions, const D3D12_TILED_RESOURCE_COORDINATE *pResourceRegionStartCoordinates, + const D3D12_TILE_REGION_SIZE *pResourceRegionSizes, ID3D12Heap *pHeap, UINT NumRanges, + const D3D12_TILE_RANGE_FLAGS *pRangeFlags, const UINT *pHeapRangeStartOffsets, + const UINT *pRangeTileCounts, D3D12_TILE_MAPPING_FLAGS Flags); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12CommandQueue, CopyTileMappings, + ID3D12Resource *pDstResource, + const D3D12_TILED_RESOURCE_COORDINATE *pDstRegionStartCoordinate, + ID3D12Resource *pSrcResource, + const D3D12_TILED_RESOURCE_COORDINATE *pSrcRegionStartCoordinate, + const D3D12_TILE_REGION_SIZE *pRegionSize, + D3D12_TILE_MAPPING_FLAGS Flags); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12CommandQueue, ExecuteCommandLists, + UINT NumCommandLists, ID3D12CommandList *const *ppCommandLists); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12CommandQueue, Signal, ID3D12Fence *pFence, + UINT64 Value); +INSTANTIATE_FUNCTION_SERIALISED(void, WrappedID3D12CommandQueue, Wait, ID3D12Fence *pFence, + UINT64 Value); \ No newline at end of file