diff --git a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp index b3bdbe9cc..50e4c3885 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp @@ -2214,11 +2214,72 @@ void WrappedID3D12GraphicsCommandList::DrawIndexedInstanced(UINT IndexCountPerIn } } +bool WrappedID3D12GraphicsCommandList::Serialise_Dispatch(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); + + if(m_State < WRITING) + m_Cmd->m_LastCmdListID = CommandList; + + D3D12NOTIMP("Serialise_DebugMessages"); + + if(m_State == EXECUTING) + { + if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + { + 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)) + { + Unwrap(list)->Dispatch(x, y, z); + m_Cmd->m_DrawcallCallback->PostRedraw(eventID, list); + } + } + } + else if(m_State == READING) + { + GetList(CommandList)->Dispatch(x, y, z); + + const string desc = m_pSerialiser->GetDebugStr(); + + m_Cmd->AddEvent(DISPATCH, desc); + string name = "Dispatch(" + ToStr::Get(x) + ", " + ToStr::Get(y) + ", " + ToStr::Get(z) + ")"; + + FetchDrawcall draw; + draw.name = name; + draw.dispatchDimension[0] = x; + draw.dispatchDimension[1] = y; + draw.dispatchDimension[2] = z; + + draw.flags |= eDraw_Dispatch; + + m_Cmd->AddDrawcall(draw, true); + } + + return true; +} + void WrappedID3D12GraphicsCommandList::Dispatch(UINT ThreadGroupCountX, UINT ThreadGroupCountY, UINT ThreadGroupCountZ) { - D3D12NOTIMP(__PRETTY_FUNCTION_SIGNATURE__); m_pReal->Dispatch(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); + + if(m_State >= WRITING) + { + SCOPED_SERIALISE_CONTEXT(DISPATCH); + Serialise_Dispatch(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); + + m_ListRecord->AddChunk(scope.Get()); + } } void WrappedID3D12GraphicsCommandList::ExecuteBundle(ID3D12GraphicsCommandList *pCommandList) @@ -2227,6 +2288,63 @@ void WrappedID3D12GraphicsCommandList::ExecuteBundle(ID3D12GraphicsCommandList * m_pReal->ExecuteBundle(Unwrap(pCommandList)); } +bool WrappedID3D12GraphicsCommandList::Serialise_ExecuteIndirect( + 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, count, GetResID(pCountBuffer)); + SERIALISE_ELEMENT(UINT64, countOffs, CountBufferOffset); + + if(m_State < WRITING) + m_Cmd->m_LastCmdListID = CommandList; + + D3D12NOTIMP("Serialise_DebugMessages"); + + if(m_State == EXECUTING) + { + pCommandSignature = GetResourceManager()->GetLiveAs(sig); + pArgumentBuffer = GetResourceManager()->GetLiveAs(arg); + pCountBuffer = GetResourceManager()->GetLiveAs(count); + + if(m_Cmd->ShouldRerecordCmd(CommandList) && m_Cmd->InRerecordRange(CommandList)) + { + ID3D12GraphicsCommandList *list = m_Cmd->RerecordCmdList(CommandList); + + Unwrap(list)->ExecuteIndirect(Unwrap(pCommandSignature), maxCount, Unwrap(pArgumentBuffer), + argOffs, Unwrap(pCountBuffer), countOffs); + } + } + else if(m_State == READING) + { + pCommandSignature = GetResourceManager()->GetLiveAs(sig); + pArgumentBuffer = GetResourceManager()->GetLiveAs(arg); + pCountBuffer = GetResourceManager()->GetLiveAs(count); + + GetList(CommandList) + ->ExecuteIndirect(Unwrap(pCommandSignature), maxCount, Unwrap(pArgumentBuffer), argOffs, + Unwrap(pCountBuffer), countOffs); + + const string desc = m_pSerialiser->GetDebugStr(); + + m_Cmd->AddEvent(EXEC_INDIRECT, desc); + string name = "ExecuteIndirect(...)"; + + FetchDrawcall draw; + draw.name = name; + + draw.flags |= eDraw_CmdList; + + m_Cmd->AddDrawcall(draw, true); + } + + return true; +} + void WrappedID3D12GraphicsCommandList::ExecuteIndirect(ID3D12CommandSignature *pCommandSignature, UINT MaxCommandCount, ID3D12Resource *pArgumentBuffer, @@ -2234,10 +2352,23 @@ void WrappedID3D12GraphicsCommandList::ExecuteIndirect(ID3D12CommandSignature *p ID3D12Resource *pCountBuffer, UINT64 CountBufferOffset) { - D3D12NOTIMP(__PRETTY_FUNCTION_SIGNATURE__); m_pReal->ExecuteIndirect(Unwrap(pCommandSignature), MaxCommandCount, Unwrap(pArgumentBuffer), ArgumentBufferOffset, Unwrap(pCountBuffer), CountBufferOffset); + + if(m_State >= WRITING) + { + SCOPED_SERIALISE_CONTEXT(EXEC_INDIRECT); + Serialise_ExecuteIndirect(pCommandSignature, MaxCommandCount, pArgumentBuffer, + ArgumentBufferOffset, pCountBuffer, CountBufferOffset); + + m_ListRecord->AddChunk(scope.Get()); + + m_ListRecord->MarkResourceFrameReferenced(GetResID(pCommandSignature), eFrameRef_Read); + m_ListRecord->MarkResourceFrameReferenced(GetResID(pArgumentBuffer), eFrameRef_Read); + m_ListRecord->MarkResourceFrameReferenced(GetResID(pCountBuffer), eFrameRef_Read); + } } + #pragma endregion Draws #pragma region Clears diff --git a/renderdoc/driver/d3d12/d3d12_commands.cpp b/renderdoc/driver/d3d12/d3d12_commands.cpp index e20fef941..6e9cc53a6 100644 --- a/renderdoc/driver/d3d12/d3d12_commands.cpp +++ b/renderdoc/driver/d3d12/d3d12_commands.cpp @@ -270,6 +270,9 @@ void WrappedID3D12CommandQueue::ProcessChunk(uint64_t offset, D3D12ChunkType chu case DRAW_INST: m_ReplayList->Serialise_DrawInstanced(0, 0, 0, 0); break; case DRAW_INDEXED_INST: m_ReplayList->Serialise_DrawIndexedInstanced(0, 0, 0, 0, 0); break; + case DISPATCH: m_ReplayList->Serialise_Dispatch(0, 0, 0); break; + case EXEC_INDIRECT: m_ReplayList->Serialise_ExecuteIndirect(NULL, 0, NULL, 0, NULL, 0); break; + case COPY_BUFFER: m_ReplayList->Serialise_CopyBufferRegion(NULL, 0, NULL, 0, 0); break; case COPY_TEXTURE: m_ReplayList->Serialise_CopyTextureRegion(NULL, 0, 0, 0, NULL, NULL); break; case COPY_RESOURCE: m_ReplayList->Serialise_CopyResource(NULL, NULL); break; diff --git a/renderdoc/driver/d3d12/d3d12_common.h b/renderdoc/driver/d3d12/d3d12_common.h index 904106bbe..46af33d4b 100644 --- a/renderdoc/driver/d3d12/d3d12_common.h +++ b/renderdoc/driver/d3d12/d3d12_common.h @@ -254,6 +254,9 @@ void Serialiser::Serialise(const char *name, D3D12Descriptor &el); \ D3D12_CHUNK_MACRO(DRAW_INDEXED_INST, "ID3D12GraphicsCommandList::DrawIndexedInstanced") \ D3D12_CHUNK_MACRO(DRAW_INST, "ID3D12GraphicsCommandList::DrawInstanced") \ + D3D12_CHUNK_MACRO(DISPATCH, "ID3D12GraphicsCommandList::Dispatch") \ + D3D12_CHUNK_MACRO(EXEC_INDIRECT, "ID3D12GraphicsCommandList::ExecuteIndirect") \ + \ D3D12_CHUNK_MACRO(COPY_BUFFER, "ID3D12GraphicsCommandList::CopyBufferRegion") \ D3D12_CHUNK_MACRO(COPY_TEXTURE, "ID3D12GraphicsCommandList::CopyTextureRegion") \ D3D12_CHUNK_MACRO(COPY_RESOURCE, "ID3D12GraphicsCommandList::CopyResource") \