Skip to content

Commit e9f5c93

Browse files
committed
Add DXIL Debugger Support for workgroup query functions
HLSL WaveGetLaneCount() WaveIsFirstLane() DXIL DXOp::WaveGetLaneCount DXOp::WaveIsFirstLane
1 parent 5e6cfd7 commit e9f5c93

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

renderdoc/driver/shaders/dxil/dxil_debug.cpp

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,23 @@ bool ThreadState::JumpToBlock(const Block *target, bool divergencePoint)
17041704
return true;
17051705
}
17061706

1707+
void ThreadState::GetSubgroupActiveLanes(const rdcarray<bool> &activeMask,
1708+
const rdcarray<ThreadState> &workgroup,
1709+
rdcarray<uint32_t> &activeLanes) const
1710+
{
1711+
const uint32_t firstLaneInSub = m_WorkgroupIndex - m_SubgroupIdx;
1712+
for(uint32_t lane = firstLaneInSub; lane < firstLaneInSub + m_GlobalState.subgroupSize; lane++)
1713+
{
1714+
// wave operations exclude helpers
1715+
if(activeMask[lane])
1716+
{
1717+
if(!m_GlobalState.waveOpsIncludeHelpers && workgroup[lane - firstLaneInSub].m_Helper)
1718+
continue;
1719+
activeLanes.push_back(lane - firstLaneInSub);
1720+
}
1721+
}
1722+
}
1723+
17071724
bool ThreadState::ExecuteInstruction(DebugAPIWrapper *apiWrapper,
17081725
const rdcarray<ThreadState> &workgroup,
17091726
const rdcarray<bool> &activeMask)
@@ -3647,12 +3664,24 @@ bool ThreadState::ExecuteInstruction(DebugAPIWrapper *apiWrapper,
36473664
break;
36483665
}
36493666
// Wave/Subgroup Operations
3667+
case DXOp::WaveGetLaneCount:
3668+
{
3669+
result.value.u32v[0] = m_GlobalState.subgroupSize;
3670+
break;
3671+
}
36503672
case DXOp::WaveGetLaneIndex:
36513673
{
3652-
// SV_PrimitiveID
36533674
result.value.u32v[0] = m_SubgroupIdx;
36543675
break;
36553676
}
3677+
case DXOp::WaveIsFirstLane:
3678+
{
3679+
// determine active lane indices in our subgroup
3680+
rdcarray<uint32_t> activeLanes;
3681+
GetSubgroupActiveLanes(activeMask, workgroup, activeLanes);
3682+
result.value.u32v[0] = (m_WorkgroupIndex == activeLanes[0]) ? 1 : 0;
3683+
break;
3684+
}
36563685
case DXOp::WaveActiveOp:
36573686
{
36583687
// WaveActiveOp(value,op,sop)
@@ -3666,19 +3695,7 @@ bool ThreadState::ExecuteInstruction(DebugAPIWrapper *apiWrapper,
36663695

36673696
// determine active lane indices in our subgroup
36683697
rdcarray<uint32_t> activeLanes;
3669-
3670-
const uint32_t firstLaneInSub = m_WorkgroupIndex - m_SubgroupIdx;
3671-
for(uint32_t lane = firstLaneInSub; lane < firstLaneInSub + m_GlobalState.subgroupSize;
3672-
lane++)
3673-
{
3674-
// wave operations exclude helpers
3675-
if(activeMask[lane])
3676-
{
3677-
if(!m_GlobalState.waveOpsIncludeHelpers && workgroup[lane - firstLaneInSub].m_Helper)
3678-
continue;
3679-
activeLanes.push_back(lane - firstLaneInSub);
3680-
}
3681-
}
3698+
GetSubgroupActiveLanes(activeMask, workgroup, activeLanes);
36823699

36833700
ShaderVariable accum;
36843701
RDCASSERT(GetShaderVariable(inst.args[1], opCode, dxOpCode, accum));
@@ -4023,8 +4040,6 @@ bool ThreadState::ExecuteInstruction(DebugAPIWrapper *apiWrapper,
40234040
case DXOp::EmitThenCutStream:
40244041

40254042
// Wave/Subgroup Operations
4026-
case DXOp::WaveIsFirstLane:
4027-
case DXOp::WaveGetLaneCount:
40284043
case DXOp::WaveAnyTrue:
40294044
case DXOp::WaveAllTrue:
40304045
case DXOp::WaveActiveAllEqual:

renderdoc/driver/shaders/dxil/dxil_debug.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ struct ThreadState
302302
bool IsVariableAssigned(const Id id) const;
303303

304304
ShaderVariable GetBuiltin(ShaderBuiltin builtin);
305+
void GetSubgroupActiveLanes(const rdcarray<bool> &activeMask,
306+
const rdcarray<ThreadState> &workgroup,
307+
rdcarray<uint32_t> &activeLanes) const;
305308

306309
struct AnnotationProperties
307310
{

renderdoc/driver/shaders/dxil/dxil_reflect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,9 @@ rdcstr Program::GetDebugStatus()
18701870
"Only supported when debugging pixel shaders dx.op call `%s` %s",
18711871
callFunc->name.c_str(), ToStr(dxOpCode).c_str());
18721872
continue;
1873+
case DXOp::WaveGetLaneCount:
18731874
case DXOp::WaveGetLaneIndex:
1875+
case DXOp::WaveIsFirstLane:
18741876
case DXOp::WaveActiveOp:
18751877
if(!D3D_Hack_EnableGroups())
18761878
return StringFormat::Fmt("Unsupported dx.op call `%s` %s", callFunc->name.c_str(),
@@ -1896,8 +1898,6 @@ rdcstr Program::GetDebugStatus()
18961898
case DXOp::StorePatchConstant:
18971899
case DXOp::OutputControlPointID:
18981900
case DXOp::CycleCounterLegacy:
1899-
case DXOp::WaveIsFirstLane:
1900-
case DXOp::WaveGetLaneCount:
19011901
case DXOp::WaveAnyTrue:
19021902
case DXOp::WaveAllTrue:
19031903
case DXOp::WaveActiveAllEqual:

0 commit comments

Comments
 (0)