Fix missing D3D12 counter

Improve D3D12 action callback match the Vulkan callback.

1.D3D12 action callback add Misc type callback to process copies/clears/etc actions.
2.D3D12GPUTimerCallback, D3D12AMDActionCallback, D3D12QuadOverdrawCallback and D3D12InitPostVSCallback implement Misc type callbacks.
3.Modify D3D12CommandData::HandlePreCallback to be consistent with Vulkan, and add the ActionFlags parameter.
4.Define corresponding macros for the action callbacks of Draw, Dispatch, Execute Bundle, Copy, and Clear commands.
This commit is contained in:
丛越
2021-08-11 18:10:40 +01:00
committed by Baldur Karlsson
parent da4c6497e7
commit 752c839072
6 changed files with 169 additions and 34 deletions
@@ -3157,11 +3157,9 @@ bool WrappedID3D12GraphicsCommandList::Serialise_DrawInstanced(SerialiserType &s
{
ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID);
uint32_t eventId = m_Cmd->HandlePreCallback(list);
uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Drawcall);
Unwrap(list)->DrawInstanced(VertexCountPerInstance, InstanceCount, StartVertexLocation,
StartInstanceLocation);
if(eventId && m_Cmd->m_ActionCallback->PostDraw(eventId, list))
{
Unwrap(list)->DrawInstanced(VertexCountPerInstance, InstanceCount, StartVertexLocation,
@@ -3240,11 +3238,9 @@ bool WrappedID3D12GraphicsCommandList::Serialise_DrawIndexedInstanced(
{
ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID);
uint32_t eventId = m_Cmd->HandlePreCallback(list);
uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Drawcall);
Unwrap(list)->DrawIndexedInstanced(IndexCountPerInstance, InstanceCount, StartIndexLocation,
BaseVertexLocation, StartInstanceLocation);
if(eventId && m_Cmd->m_ActionCallback->PostDraw(eventId, list))
{
Unwrap(list)->DrawIndexedInstanced(IndexCountPerInstance, InstanceCount, StartIndexLocation,
@@ -3324,14 +3320,12 @@ bool WrappedID3D12GraphicsCommandList::Serialise_Dispatch(SerialiserType &ser, U
{
ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID);
uint32_t eventId = m_Cmd->HandlePreCallback(list, true);
uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Dispatch);
Unwrap(list)->Dispatch(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ);
if(eventId && m_Cmd->m_ActionCallback->PostDraw(eventId, list))
if(eventId && m_Cmd->m_ActionCallback->PostDispatch(eventId, list))
{
Unwrap(list)->Dispatch(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ);
m_Cmd->m_ActionCallback->PostRedraw(eventId, list);
m_Cmd->m_ActionCallback->PostRedispatch(eventId, list);
}
}
}
@@ -3394,14 +3388,12 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ExecuteBundle(SerialiserType &s
{
ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID);
uint32_t eventId = m_Cmd->HandlePreCallback(list, true);
uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::CmdList);
Unwrap(list)->ExecuteBundle(Unwrap(pBundle));
if(eventId && m_Cmd->m_ActionCallback->PostDraw(eventId, list))
if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::CmdList, list))
{
Unwrap(list)->ExecuteBundle(Unwrap(pBundle));
m_Cmd->m_ActionCallback->PostRedraw(eventId, list);
m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::CmdList, list);
}
}
}
@@ -4310,7 +4302,13 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ExecuteIndirect(
{
ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID);
uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::MultiAction);
ReplayExecuteIndirect(Unwrap(list));
if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::MultiAction, list))
{
ReplayExecuteIndirect(Unwrap(list));
m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::MultiAction, list);
}
}
}
else
@@ -4485,9 +4483,21 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ClearDepthStencilView(
{
if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID))
{
Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))
->ClearDepthStencilView(Unwrap(DepthStencilView), ClearFlags, Depth, Stencil, NumRects,
pRects);
ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID);
uint32_t eventId =
m_Cmd->HandlePreCallback(list, ActionFlags::Clear | ActionFlags::ClearDepthStencil);
Unwrap(list)->ClearDepthStencilView(Unwrap(DepthStencilView), ClearFlags, Depth, Stencil,
NumRects, pRects);
if(eventId &&
m_Cmd->m_ActionCallback->PostMisc(
eventId, ActionFlags::Clear | ActionFlags::ClearDepthStencil, list))
{
Unwrap(list)->ClearDepthStencilView(Unwrap(DepthStencilView), ClearFlags, Depth, Stencil,
NumRects, pRects);
m_Cmd->m_ActionCallback->PostRemisc(
eventId, ActionFlags::Clear | ActionFlags::ClearDepthStencil, list);
}
}
}
else
@@ -4581,8 +4591,19 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ClearRenderTargetView(
{
if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID))
{
Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))
->ClearRenderTargetView(Unwrap(RenderTargetView), ColorRGBA, NumRects, pRects);
ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID);
uint32_t eventId =
m_Cmd->HandlePreCallback(list, ActionFlags::Clear | ActionFlags::ClearColor);
Unwrap(list)->ClearRenderTargetView(Unwrap(RenderTargetView), ColorRGBA, NumRects, pRects);
if(eventId &&
m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Clear | ActionFlags::ClearColor,
list))
{
Unwrap(list)->ClearRenderTargetView(Unwrap(RenderTargetView), ColorRGBA, NumRects, pRects);
m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear | ActionFlags::ClearColor,
list);
}
}
}
else
@@ -4675,9 +4696,19 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ClearUnorderedAccessViewUint(
{
if(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);
ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID);
uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Clear);
Unwrap(list)->ClearUnorderedAccessViewUint(Unwrap(ViewGPUHandleInCurrentHeap),
Unwrap(ViewCPUHandle), Unwrap(pResource), Values,
NumRects, pRects);
if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Clear, list))
{
Unwrap(list)->ClearUnorderedAccessViewUint(Unwrap(ViewGPUHandleInCurrentHeap),
Unwrap(ViewCPUHandle), Unwrap(pResource),
Values, NumRects, pRects);
m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear, list);
}
}
}
else
@@ -4779,9 +4810,19 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ClearUnorderedAccessViewFloat(
{
if(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);
ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID);
uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Clear);
Unwrap(list)->ClearUnorderedAccessViewFloat(Unwrap(ViewGPUHandleInCurrentHeap),
Unwrap(ViewCPUHandle), Unwrap(pResource),
Values, NumRects, pRects);
if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Clear, list))
{
Unwrap(list)->ClearUnorderedAccessViewFloat(Unwrap(ViewGPUHandleInCurrentHeap),
Unwrap(ViewCPUHandle), Unwrap(pResource),
Values, NumRects, pRects);
m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear, list);
}
}
}
else
@@ -4950,8 +4991,16 @@ bool WrappedID3D12GraphicsCommandList::Serialise_CopyBufferRegion(SerialiserType
if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID))
{
ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID);
uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Copy);
Unwrap(list)->CopyBufferRegion(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer), SrcOffset,
NumBytes);
if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, list))
{
Unwrap(list)->CopyBufferRegion(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer),
SrcOffset, NumBytes);
m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, list);
}
}
}
else
@@ -5045,7 +5094,14 @@ bool WrappedID3D12GraphicsCommandList::Serialise_CopyTextureRegion(
if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID))
{
ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID);
uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Copy);
Unwrap(list)->CopyTextureRegion(&unwrappedDst, DstX, DstY, DstZ, &unwrappedSrc, pSrcBox);
if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, list))
{
Unwrap(list)->CopyTextureRegion(&unwrappedDst, DstX, DstY, DstZ, &unwrappedSrc, pSrcBox);
m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, list);
}
}
}
else
@@ -5153,7 +5209,14 @@ bool WrappedID3D12GraphicsCommandList::Serialise_CopyResource(SerialiserType &se
if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID))
{
ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID);
uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Copy);
Unwrap(list)->CopyResource(Unwrap(pDstResource), Unwrap(pSrcResource));
if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, list))
{
Unwrap(list)->CopyResource(Unwrap(pDstResource), Unwrap(pSrcResource));
m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, list);
}
}
}
else
@@ -5339,8 +5402,16 @@ bool WrappedID3D12GraphicsCommandList::Serialise_CopyTiles(
if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID))
{
ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID);
uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Copy);
Unwrap(list)->CopyTiles(Unwrap(pTiledResource), &TileRegionStartCoordinate, &TileRegionSize,
Unwrap(pBuffer), BufferStartOffsetInBytes, Flags);
if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, list))
{
Unwrap(list)->CopyTiles(Unwrap(pTiledResource), &TileRegionStartCoordinate,
&TileRegionSize, Unwrap(pBuffer), BufferStartOffsetInBytes, Flags);
m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, list);
}
}
}
else
+19 -5
View File
@@ -1494,7 +1494,7 @@ void D3D12CommandData::GetIndirectBuffer(size_t size, ID3D12Resource **buf, uint
m_IndirectOffset = AlignUp16(m_IndirectOffset + size);
}
uint32_t D3D12CommandData::HandlePreCallback(ID3D12GraphicsCommandListX *list, bool dispatch,
uint32_t D3D12CommandData::HandlePreCallback(ID3D12GraphicsCommandListX *list, ActionFlags type,
uint32_t multiDrawOffset)
{
if(!m_ActionCallback)
@@ -1529,10 +1529,24 @@ uint32_t D3D12CommandData::HandlePreCallback(ID3D12GraphicsCommandListX *list, b
eventId += multiDrawOffset;
if(dispatch)
m_ActionCallback->PreDispatch(eventId, list);
else
m_ActionCallback->PreDraw(eventId, list);
switch(type)
{
case ActionFlags::Drawcall:
{
m_ActionCallback->PreDraw(eventId, list);
break;
}
case ActionFlags::Dispatch:
{
m_ActionCallback->PreDispatch(eventId, list);
break;
}
default:
{
m_ActionCallback->PreMisc(eventId, type, list);
break;
}
}
return eventId;
}
+7 -2
View File
@@ -127,6 +127,11 @@ struct D3D12ActionCallback
virtual bool PostDispatch(uint32_t eid, ID3D12GraphicsCommandListX *cmd) = 0;
virtual void PostRedispatch(uint32_t eid, ID3D12GraphicsCommandListX *cmd) = 0;
// finally, these are for copy/blit/resolve/clear/etc
virtual void PreMisc(uint32_t eid, ActionFlags flags, ID3D12GraphicsCommandListX *cmd) = 0;
virtual bool PostMisc(uint32_t eid, ActionFlags flags, ID3D12GraphicsCommandListX *cmd) = 0;
virtual void PostRemisc(uint32_t eid, ActionFlags flags, ID3D12GraphicsCommandListX *cmd) = 0;
// called immediately before a command list is closed
virtual void PreCloseCommandList(ID3D12GraphicsCommandListX *cmd) = 0;
// if a command list is recorded once and submitted N > 1 times, then the same
@@ -367,8 +372,8 @@ struct D3D12CommandData
// util function to handle fetching the right eventId, calling any
// aliases then calling PreDraw/PreDispatch.
uint32_t HandlePreCallback(ID3D12GraphicsCommandListX *list, bool dispatch = false,
uint32_t multiDrawOffset = 0);
uint32_t HandlePreCallback(ID3D12GraphicsCommandListX *list,
ActionFlags type = ActionFlags::Drawcall, uint32_t multiDrawOffset = 0);
bool InRerecordRange(ResourceId cmdid);
bool HasRerecordCmdList(ResourceId cmdid);
+37
View File
@@ -252,6 +252,24 @@ struct D3D12AMDActionCallback : public D3D12ActionCallback
{
PostRedraw(eid, cmd);
}
void PreMisc(uint32_t eid, ActionFlags flags, ID3D12GraphicsCommandListX *cmd) override
{
if(flags & ActionFlags::PassBoundary)
return;
PreDraw(eid, cmd);
}
bool PostMisc(uint32_t eid, ActionFlags flags, ID3D12GraphicsCommandListX *cmd) override
{
if(flags & ActionFlags::PassBoundary)
return false;
return PostDraw(eid, cmd);
}
void PostRemisc(uint32_t eid, ActionFlags flags, ID3D12GraphicsCommandListX *cmd) override
{
if(flags & ActionFlags::PassBoundary)
return;
PostRedraw(eid, cmd);
}
void AliasEvent(uint32_t primary, uint32_t alias) override
{
@@ -416,6 +434,25 @@ struct D3D12GPUTimerCallback : public D3D12ActionCallback
{
PostRedraw(eid, cmd);
}
void PreMisc(uint32_t eid, ActionFlags flags, ID3D12GraphicsCommandListX *cmd) override
{
if(flags & ActionFlags::PassBoundary)
return;
PreDraw(eid, cmd);
}
bool PostMisc(uint32_t eid, ActionFlags flags, ID3D12GraphicsCommandListX *cmd) override
{
if(flags & ActionFlags::PassBoundary)
return false;
return PostDraw(eid, cmd);
}
void PostRemisc(uint32_t eid, ActionFlags flags, ID3D12GraphicsCommandListX *cmd) override
{
if(flags & ActionFlags::PassBoundary)
return;
PostRedraw(eid, cmd);
}
void PreCloseCommandList(ID3D12GraphicsCommandListX *cmd) override{};
void AliasEvent(uint32_t primary, uint32_t alias) override
{
+4
View File
@@ -241,6 +241,10 @@ struct D3D12QuadOverdrawCallback : public D3D12ActionCallback
void PreDispatch(uint32_t eid, ID3D12GraphicsCommandListX *cmd) {}
bool PostDispatch(uint32_t eid, ID3D12GraphicsCommandListX *cmd) { return false; }
void PostRedispatch(uint32_t eid, ID3D12GraphicsCommandListX *cmd) {}
// Ditto copy/etc
void PreMisc(uint32_t eid, ActionFlags flags, ID3D12GraphicsCommandListX *cmd) {}
bool PostMisc(uint32_t eid, ActionFlags flags, ID3D12GraphicsCommandListX *cmd) { return false; }
void PostRemisc(uint32_t eid, ActionFlags flags, ID3D12GraphicsCommandListX *cmd) {}
void PreCloseCommandList(ID3D12GraphicsCommandListX *cmd) {}
void AliasEvent(uint32_t primary, uint32_t alias)
{
+4
View File
@@ -1325,6 +1325,10 @@ struct D3D12InitPostVSCallback : public D3D12ActionCallback
void PreDispatch(uint32_t eid, ID3D12GraphicsCommandListX *cmd) override {}
bool PostDispatch(uint32_t eid, ID3D12GraphicsCommandListX *cmd) override { return false; }
void PostRedispatch(uint32_t eid, ID3D12GraphicsCommandListX *cmd) override {}
// Ditto copy/etc
void PreMisc(uint32_t eid, ActionFlags flags, ID3D12GraphicsCommandListX *cmd) {}
bool PostMisc(uint32_t eid, ActionFlags flags, ID3D12GraphicsCommandListX *cmd) { return false; }
void PostRemisc(uint32_t eid, ActionFlags flags, ID3D12GraphicsCommandListX *cmd) {}
void PreCloseCommandList(ID3D12GraphicsCommandListX *cmd) override {}
void AliasEvent(uint32_t primary, uint32_t alias) override
{