Skip to content

Commit 73565d6

Browse files
Add noduplicate attribute to SetMeshOutputCounts and DispatchMesh intrinsics
Agent-Logs-Url: https://github.com/microsoft/DirectXShaderCompiler/sessions/0efbd2d6-46d4-4a20-89eb-cb685105780b Co-authored-by: chrisbieneman <[email protected]>
1 parent c303adc commit 73565d6

4 files changed

Lines changed: 56 additions & 4 deletions

File tree

lib/DXIL/DxilOperations.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ static const OP::OpCodeProperty CoreOps_OpCodeProps[] = {
15101510
"SetMeshOutputCounts",
15111511
OCC::SetMeshOutputCounts,
15121512
"setMeshOutputCounts",
1513-
Attribute::None,
1513+
Attribute::NoDuplicate,
15141514
0,
15151515
{},
15161516
{}}, // Overloads: v
@@ -1552,7 +1552,7 @@ static const OP::OpCodeProperty CoreOps_OpCodeProps[] = {
15521552
"DispatchMesh",
15531553
OCC::DispatchMesh,
15541554
"dispatchMesh",
1555-
Attribute::None,
1555+
Attribute::NoDuplicate,
15561556
1,
15571557
{{0x100}},
15581558
{{0x0}}}, // Overloads: u

lib/HLSL/HLOperations.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ static AttributeSet GetHLFunctionAttributes(LLVMContext &C,
531531
case IntrinsicOp::IOP_GroupMemoryBarrier:
532532
case IntrinsicOp::IOP_AllMemoryBarrierWithGroupSync:
533533
case IntrinsicOp::IOP_AllMemoryBarrier:
534+
case IntrinsicOp::IOP_SetMeshOutputCounts:
535+
case IntrinsicOp::IOP_DispatchMesh:
534536
addAttr(Attribute::NoDuplicate);
535537
break;
536538
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// RUN: %dxc -E main -T ms_6_5 %s | FileCheck %s
2+
3+
// Test that SetMeshOutputCounts has noduplicate attribute, preventing the
4+
// optimizer from sinking/duplicating the call into branches that compute
5+
// the count values.
6+
7+
// CHECK: dx.op.setMeshOutputCounts
8+
// CHECK: noduplicate
9+
10+
#define MAX_VERT 32
11+
#define MAX_PRIM 16
12+
#define NUM_THREADS 32
13+
14+
struct MeshPerVertex {
15+
float4 position : SV_Position;
16+
};
17+
18+
struct MeshPayload {
19+
float normal;
20+
};
21+
22+
[numthreads(NUM_THREADS, 1, 1)]
23+
[outputtopology("triangle")]
24+
void main(
25+
out indices uint3 primIndices[MAX_PRIM],
26+
out vertices MeshPerVertex verts[MAX_VERT],
27+
in payload MeshPayload mpl,
28+
in uint tig : SV_GroupIndex,
29+
in uint vid : SV_ViewID
30+
)
31+
{
32+
// Compute counts in a branch - optimizer used to sink SetMeshOutputCounts
33+
// into each branch, producing two copies and failing validation.
34+
uint nverts, nprims;
35+
if (vid % 2) {
36+
nverts = MAX_VERT;
37+
nprims = MAX_PRIM;
38+
} else {
39+
nverts = MAX_VERT / 2;
40+
nprims = MAX_PRIM / 2;
41+
}
42+
SetMeshOutputCounts(nverts, nprims);
43+
44+
if (tig < nverts) {
45+
verts[tig].position = float4(0, 0, 0, 1);
46+
}
47+
if (tig < nprims) {
48+
primIndices[tig] = uint3(tig * 3, tig * 3 + 1, tig * 3 + 2);
49+
}
50+
}

utils/hct/hctdb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4156,7 +4156,7 @@ def UFI(name, **mappings):
41564156
"SetMeshOutputCounts",
41574157
"Mesh shader intrinsic SetMeshOutputCounts",
41584158
"v",
4159-
"",
4159+
"nd",
41604160
[
41614161
retvoid_param,
41624162
db_dxil_param(2, "i32", "numVertices", "number of output vertices"),
@@ -4234,7 +4234,7 @@ def UFI(name, **mappings):
42344234
"DispatchMesh",
42354235
"Amplification shader intrinsic DispatchMesh",
42364236
"u",
4237-
"",
4237+
"nd",
42384238
[
42394239
retvoid_param,
42404240
db_dxil_param(2, "i32", "threadGroupCountX", "thread group count x"),

0 commit comments

Comments
 (0)