Skip to content

Commit 86e5c67

Browse files
committed
D3D12 ShaderFeedback fix GPU hang when analysing ExecuteIndrect
Need to recreate the EI command signature using the same root signature that is is bound i.e. the modified root signature which includes the resources for the shader feedback analysis This only needs to be done if the EI command signature modifies the root arguments i.e. setting root constants, updating bindings
1 parent 8b3a87e commit 86e5c67

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

renderdoc/driver/d3d12/d3d12_shader_feedback.cpp

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,8 +1133,12 @@ static bool AddArraySlots(WrappedID3D12PipelineState::ShaderEntry *shad, uint32_
11331133

11341134
struct D3D12StatCallback : public D3D12ActionCallback
11351135
{
1136-
D3D12StatCallback(WrappedID3D12Device *dev, ID3D12QueryHeap *heap)
1137-
: m_pDevice(dev), m_PipeStatsQueryHeap(heap)
1136+
D3D12StatCallback(WrappedID3D12Device *dev, ID3D12QueryHeap *heap, ID3D12RootSignature *rootSig,
1137+
ID3D12CommandSignature **ppCommandSignature)
1138+
: m_pDevice(dev),
1139+
m_PipeStatsQueryHeap(heap),
1140+
m_pRootSignature(rootSig),
1141+
m_ppCommandSignature(ppCommandSignature)
11381142
{
11391143
m_pDevice->GetQueue()->GetCommandData()->m_ActionCallback = this;
11401144
}
@@ -1143,6 +1147,46 @@ struct D3D12StatCallback : public D3D12ActionCallback
11431147
{
11441148
if(cmd->GetType() == D3D12_COMMAND_LIST_TYPE_DIRECT)
11451149
cmd->BeginQuery(m_PipeStatsQueryHeap, D3D12_QUERY_TYPE_PIPELINE_STATISTICS, 0);
1150+
1151+
D3D12CommandData *cmdData = m_pDevice->GetQueue()->GetCommandData();
1152+
WrappedID3D12CommandSignature *comSig =
1153+
(WrappedID3D12CommandSignature *)cmdData->m_IndirectData.commandSig;
1154+
if(comSig)
1155+
{
1156+
// Need to create a new command signature using our modified root signature if the command
1157+
// signature modifies the root arguments i.e. setting root constants, updating bindings.
1158+
bool needNewCommandSig = false;
1159+
for(D3D12_INDIRECT_ARGUMENT_DESC &arg : comSig->sig.arguments)
1160+
{
1161+
D3D12_INDIRECT_ARGUMENT_TYPE argType = arg.Type;
1162+
if(argType == D3D12_INDIRECT_ARGUMENT_TYPE_VERTEX_BUFFER_VIEW ||
1163+
argType == D3D12_INDIRECT_ARGUMENT_TYPE_INDEX_BUFFER_VIEW ||
1164+
argType == D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT ||
1165+
argType == D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT_BUFFER_VIEW ||
1166+
argType == D3D12_INDIRECT_ARGUMENT_TYPE_SHADER_RESOURCE_VIEW ||
1167+
argType == D3D12_INDIRECT_ARGUMENT_TYPE_UNORDERED_ACCESS_VIEW ||
1168+
argType == D3D12_INDIRECT_ARGUMENT_TYPE_INCREMENTING_CONSTANT)
1169+
{
1170+
needNewCommandSig = true;
1171+
break;
1172+
}
1173+
}
1174+
if(needNewCommandSig)
1175+
{
1176+
D3D12_COMMAND_SIGNATURE_DESC comSigDesc;
1177+
comSigDesc.ByteStride = comSig->sig.ByteStride;
1178+
comSigDesc.NodeMask = 0;
1179+
comSigDesc.NumArgumentDescs = (uint32_t)comSig->sig.arguments.size();
1180+
comSigDesc.pArgumentDescs = comSig->sig.arguments.data();
1181+
1182+
m_pDevice->CreateCommandSignature(&comSigDesc, m_pRootSignature,
1183+
__uuidof(ID3D12CommandSignature),
1184+
(void **)m_ppCommandSignature);
1185+
1186+
RDCASSERT(*m_ppCommandSignature);
1187+
cmdData->m_IndirectData.commandSig = *m_ppCommandSignature;
1188+
}
1189+
}
11461190
}
11471191

11481192
bool PostDraw(uint32_t eid, ID3D12GraphicsCommandListX *cmd) override
@@ -1186,6 +1230,8 @@ struct D3D12StatCallback : public D3D12ActionCallback
11861230
void AliasEvent(uint32_t primary, uint32_t alias) override {}
11871231
WrappedID3D12Device *m_pDevice;
11881232
ID3D12QueryHeap *m_PipeStatsQueryHeap;
1233+
ID3D12RootSignature *m_pRootSignature = NULL;
1234+
ID3D12CommandSignature **m_ppCommandSignature = NULL;
11891235
};
11901236

11911237
bool D3D12Replay::FetchShaderFeedback(uint32_t eventId)
@@ -1477,8 +1523,9 @@ bool D3D12Replay::FetchShaderFeedback(uint32_t eventId)
14771523
D3D12RenderState::SignatureElement(eRootUAV, GetResID(m_BindlessFeedback.FeedbackBuffer), 0);
14781524
}
14791525

1526+
ID3D12CommandSignature *modComSig = NULL;
14801527
{
1481-
D3D12StatCallback cb(m_pDevice, m_BindlessFeedback.PipeStatsHeap);
1528+
D3D12StatCallback cb(m_pDevice, m_BindlessFeedback.PipeStatsHeap, annotatedSig, &modComSig);
14821529

14831530
m_pDevice->ReplayLog(0, eventId, eReplay_OnlyDraw);
14841531

@@ -1497,6 +1544,7 @@ bool D3D12Replay::FetchShaderFeedback(uint32_t eventId)
14971544

14981545
SAFE_RELEASE(annotatedPipe);
14991546
SAFE_RELEASE(annotatedSig);
1547+
SAFE_RELEASE(modComSig);
15001548

15011549
rs = prev;
15021550

0 commit comments

Comments
 (0)