Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/DXIL/DxilOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ static const OP::OpCodeProperty CoreOps_OpCodeProps[] = {
"SetMeshOutputCounts",
OCC::SetMeshOutputCounts,
"setMeshOutputCounts",
Attribute::None,
Attribute::NoDuplicate,
0,
{},
{}}, // Overloads: v
Expand Down Expand Up @@ -1552,7 +1552,7 @@ static const OP::OpCodeProperty CoreOps_OpCodeProps[] = {
"DispatchMesh",
OCC::DispatchMesh,
"dispatchMesh",
Attribute::None,
Attribute::NoDuplicate,
1,
{{0x100}},
{{0x0}}}, // Overloads: u
Expand Down
2 changes: 2 additions & 0 deletions lib/HLSL/HLOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ static AttributeSet GetHLFunctionAttributes(LLVMContext &C,
case IntrinsicOp::IOP_GroupMemoryBarrier:
case IntrinsicOp::IOP_AllMemoryBarrierWithGroupSync:
case IntrinsicOp::IOP_AllMemoryBarrier:
case IntrinsicOp::IOP_SetMeshOutputCounts:
case IntrinsicOp::IOP_DispatchMesh:
addAttr(Attribute::NoDuplicate);
break;
}
Expand Down
50 changes: 50 additions & 0 deletions tools/clang/test/CodeGenHLSL/mesh-val/sinkSetMeshOutputCounts.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// RUN: %dxc -E main -T ms_6_5 %s | FileCheck %s

// Test that SetMeshOutputCounts has noduplicate attribute, preventing the
// optimizer from sinking/duplicating the call into branches that compute
// the count values.

// CHECK: dx.op.setMeshOutputCounts
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// CHECK: dx.op.setMeshOutputCounts
// CHECK: call void @dx.op.setMeshOutputCounts
// CHECK-NOT: call void @dx.op.setMeshOutputCounts
// CHECK: declare void @dx.op.setMeshOutputCounts(i32, i32, i32) [[Attrs:#[0-9]+]]
// CHECK: attributes [[Attrs]] = { noduplicate nounwind }

// CHECK: noduplicate

#define MAX_VERT 32
#define MAX_PRIM 16
#define NUM_THREADS 32

struct MeshPerVertex {
float4 position : SV_Position;
};

struct MeshPayload {
float normal;
};

[numthreads(NUM_THREADS, 1, 1)]
[outputtopology("triangle")]
void main(
out indices uint3 primIndices[MAX_PRIM],
out vertices MeshPerVertex verts[MAX_VERT],
in payload MeshPayload mpl,
in uint tig : SV_GroupIndex,
in uint vid : SV_ViewID
)
{
// Compute counts in a branch - optimizer used to sink SetMeshOutputCounts
// into each branch, producing two copies and failing validation.
uint nverts, nprims;
if (vid % 2) {
nverts = MAX_VERT;
nprims = MAX_PRIM;
} else {
nverts = MAX_VERT / 2;
nprims = MAX_PRIM / 2;
}
SetMeshOutputCounts(nverts, nprims);

if (tig < nverts) {
verts[tig].position = float4(0, 0, 0, 1);
}
if (tig < nprims) {
primIndices[tig] = uint3(tig * 3, tig * 3 + 1, tig * 3 + 2);
}
}
4 changes: 2 additions & 2 deletions utils/hct/hctdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4156,7 +4156,7 @@ def UFI(name, **mappings):
"SetMeshOutputCounts",
"Mesh shader intrinsic SetMeshOutputCounts",
"v",
"",
"nd",
[
retvoid_param,
db_dxil_param(2, "i32", "numVertices", "number of output vertices"),
Expand Down Expand Up @@ -4234,7 +4234,7 @@ def UFI(name, **mappings):
"DispatchMesh",
"Amplification shader intrinsic DispatchMesh",
"u",
"",
"nd",
[
retvoid_param,
db_dxil_param(2, "i32", "threadGroupCountX", "thread group count x"),
Expand Down
Loading