Skip to content

Commit b05313c

Browse files
authored
Unwrap top-level array for OutVertices when flattenArgument. (#6943)
For primitives and vertices output of mesh shader, we need to unwrap the top-level array to get correct semantic index. Fixes #6940
1 parent dfa1c81 commit b05313c

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

lib/HLSL/HLModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ void HLModule::GetParameterRowsAndCols(
885885
DxilParameterAnnotation &paramAnnotation) {
886886
if (Ty->isPointerTy())
887887
Ty = Ty->getPointerElementType();
888-
// For array input of HS, DS, GS,
888+
// For array input of HS, DS, GS and array output of MS,
889889
// we need to skip the first level which size is based on primitive type.
890890
DxilParamInputQual inputQual = paramAnnotation.GetParamInputQual();
891891
bool skipOneLevelArray = inputQual == DxilParamInputQual::InputPatch;

lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5300,7 +5300,9 @@ void SROA_Parameter_HLSL::flattenArgument(
53005300
// Unwrap top-level array if primitive
53015301
if (inputQual == DxilParamInputQual::InputPatch ||
53025302
inputQual == DxilParamInputQual::OutputPatch ||
5303-
inputQual == DxilParamInputQual::InputPrimitive) {
5303+
inputQual == DxilParamInputQual::InputPrimitive ||
5304+
inputQual == DxilParamInputQual::OutPrimitives ||
5305+
inputQual == DxilParamInputQual::OutVertices) {
53045306
Type *Ty = Arg->getType();
53055307
if (Ty->isPointerTy())
53065308
Ty = Ty->getPointerElementType();
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %dxc -E main -T gs_6_0 %s | FileCheck %s
2+
3+
// Make sure only one semnatic index created.
4+
// CHECK:; COORD 0 xyzw 0 NONE float xyzw
5+
// CHECK-NOT:; COORD 1 xyzw 0 NONE float xyzw
6+
7+
struct MyStruct
8+
{
9+
float4 pos : SV_Position;
10+
float2 a : AAA;
11+
};
12+
13+
struct MyStruct2
14+
{
15+
uint3 X : XXX;
16+
float4 p[3] : PPP;
17+
uint3 Y : YYY;
18+
};
19+
20+
int g1;
21+
22+
[maxvertexcount(12)]
23+
void main(line float4 array[2] : COORD, inout PointStream<MyStruct> OutputStream0)
24+
{
25+
float4 r = array[0];
26+
MyStruct a = (MyStruct)0;
27+
MyStruct2 b = (MyStruct2)0;
28+
a.pos = array[r.x];
29+
a.a = r.xy;
30+
b.X = r.xyz;
31+
b.Y = a.pos.xyz;
32+
b.p[2] = a.pos * 44;
33+
OutputStream0.Append(a);
34+
OutputStream0.RestartStrip();
35+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %dxc -T ms_6_6 %s | FileCheck %s
2+
3+
// For https://github.com/microsoft/DirectXShaderCompiler/issues/6940
4+
// Ensure the shader compiles when the semantic is directly on the parameter.
5+
// Only one semantic index should be created.
6+
7+
// CHECK:; SV_Position 0 xyzw 0 POS float xyzw
8+
// CHECK-NOT:; SV_Position 1 xyzw 0 POS float xyzw
9+
10+
// CHECK:; A 0 xyzw 0 NONE uint
11+
// CHECK-NOT: ; A 1 xyzw 0 NONE uint
12+
13+
#define GROUP_SIZE 30
14+
15+
cbuffer Constant : register(b0)
16+
{
17+
uint numPrims;
18+
}
19+
static const uint numVerts = 3;
20+
21+
[RootSignature("RootConstants(num32BitConstants=1, b0)")]
22+
[numthreads(GROUP_SIZE, 1, 1)]
23+
[OutputTopology("triangle")]
24+
void main(
25+
uint gtid : SV_GroupThreadID,
26+
out indices uint3 tris[GROUP_SIZE],
27+
out vertices float4 verts[GROUP_SIZE] : SV_Position,
28+
out primitives uint4 t[GROUP_SIZE] : A
29+
)
30+
{
31+
SetMeshOutputCounts(numVerts, numPrims);
32+
33+
if (gtid < numVerts)
34+
{
35+
verts[gtid] = 0;
36+
}
37+
38+
if (gtid < numPrims)
39+
{
40+
tris[gtid] = uint3(0, 1, 2);
41+
}
42+
}

0 commit comments

Comments
 (0)