Skip to content

Commit

Permalink
Unwrap top-level array for OutVertices when flattenArgument. (#6943)
Browse files Browse the repository at this point in the history
For primitives and vertices output of mesh shader, we need to unwrap the
top-level array to get correct semantic index.

Fixes #6940
  • Loading branch information
python3kgae authored Oct 2, 2024
1 parent dfa1c81 commit b05313c
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/HLSL/HLModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ void HLModule::GetParameterRowsAndCols(
DxilParameterAnnotation &paramAnnotation) {
if (Ty->isPointerTy())
Ty = Ty->getPointerElementType();
// For array input of HS, DS, GS,
// For array input of HS, DS, GS and array output of MS,
// we need to skip the first level which size is based on primitive type.
DxilParamInputQual inputQual = paramAnnotation.GetParamInputQual();
bool skipOneLevelArray = inputQual == DxilParamInputQual::InputPatch;
Expand Down
4 changes: 3 additions & 1 deletion lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5300,7 +5300,9 @@ void SROA_Parameter_HLSL::flattenArgument(
// Unwrap top-level array if primitive
if (inputQual == DxilParamInputQual::InputPatch ||
inputQual == DxilParamInputQual::OutputPatch ||
inputQual == DxilParamInputQual::InputPrimitive) {
inputQual == DxilParamInputQual::InputPrimitive ||
inputQual == DxilParamInputQual::OutPrimitives ||
inputQual == DxilParamInputQual::OutVertices) {
Type *Ty = Arg->getType();
if (Ty->isPointerTy())
Ty = Ty->getPointerElementType();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// RUN: %dxc -E main -T gs_6_0 %s | FileCheck %s

// Make sure only one semnatic index created.
// CHECK:; COORD 0 xyzw 0 NONE float xyzw
// CHECK-NOT:; COORD 1 xyzw 0 NONE float xyzw

struct MyStruct
{
float4 pos : SV_Position;
float2 a : AAA;
};

struct MyStruct2
{
uint3 X : XXX;
float4 p[3] : PPP;
uint3 Y : YYY;
};

int g1;

[maxvertexcount(12)]
void main(line float4 array[2] : COORD, inout PointStream<MyStruct> OutputStream0)
{
float4 r = array[0];
MyStruct a = (MyStruct)0;
MyStruct2 b = (MyStruct2)0;
a.pos = array[r.x];
a.a = r.xy;
b.X = r.xyz;
b.Y = a.pos.xyz;
b.p[2] = a.pos * 44;
OutputStream0.Append(a);
OutputStream0.RestartStrip();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// RUN: %dxc -T ms_6_6 %s | FileCheck %s

// For https://github.com/microsoft/DirectXShaderCompiler/issues/6940
// Ensure the shader compiles when the semantic is directly on the parameter.
// Only one semantic index should be created.

// CHECK:; SV_Position 0 xyzw 0 POS float xyzw
// CHECK-NOT:; SV_Position 1 xyzw 0 POS float xyzw

// CHECK:; A 0 xyzw 0 NONE uint
// CHECK-NOT: ; A 1 xyzw 0 NONE uint

#define GROUP_SIZE 30

cbuffer Constant : register(b0)
{
uint numPrims;
}
static const uint numVerts = 3;

[RootSignature("RootConstants(num32BitConstants=1, b0)")]
[numthreads(GROUP_SIZE, 1, 1)]
[OutputTopology("triangle")]
void main(
uint gtid : SV_GroupThreadID,
out indices uint3 tris[GROUP_SIZE],
out vertices float4 verts[GROUP_SIZE] : SV_Position,
out primitives uint4 t[GROUP_SIZE] : A
)
{
SetMeshOutputCounts(numVerts, numPrims);

if (gtid < numVerts)
{
verts[gtid] = 0;
}

if (gtid < numPrims)
{
tris[gtid] = uint3(0, 1, 2);
}
}

0 comments on commit b05313c

Please sign in to comment.