Skip to content

Commit a742bb6

Browse files
authored
[Spirv] Fix for validation error VUID-StandaloneSpirv-Flat-04744 (#5276)
generated SPIR-V is invalid: [VUID-StandaloneSpirv-Flat-04744] Fragment OpEntryPoint operand 4 with Input interfaces with integer or float type must have a Flat decoration for Entry Point id 1. %SubgroupLocalInvocationId = OpVariable %_ptr_Input_uint Input
1 parent 2afa325 commit a742bb6

4 files changed

Lines changed: 49 additions & 0 deletions

File tree

tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3435,12 +3435,14 @@ SpirvVariable *DeclResultIdMapper::getBuiltinVar(spv::BuiltIn builtIn,
34353435
if (builtInVar != builtinToVarMap.end()) {
34363436
return builtInVar->second;
34373437
}
3438+
bool mayNeedFlatDecoration = false;
34383439
spv::StorageClass sc = spv::StorageClass::Max;
34393440
// Valid builtins supported
34403441
switch (builtIn) {
34413442
case spv::BuiltIn::SubgroupSize:
34423443
case spv::BuiltIn::SubgroupLocalInvocationId:
34433444
needsLegalization = true;
3445+
mayNeedFlatDecoration = true;
34443446
LLVM_FALLTHROUGH;
34453447
case spv::BuiltIn::HitTNV:
34463448
case spv::BuiltIn::RayTmaxNV:
@@ -3481,6 +3483,9 @@ SpirvVariable *DeclResultIdMapper::getBuiltinVar(spv::BuiltIn builtIn,
34813483
// Create a dummy StageVar for this builtin variable
34823484
auto var = spvBuilder.addStageBuiltinVar(type, sc, builtIn,
34833485
/*isPrecise*/ false, loc);
3486+
if (mayNeedFlatDecoration && spvContext.isPS()) {
3487+
spvBuilder.decorateFlat(var, loc);
3488+
}
34843489

34853490
const hlsl::SigPoint *sigPoint =
34863491
hlsl::SigPoint::GetSigPoint(hlsl::SigPointFromInputQual(
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %dxc -T ps_6_0 -E main -fspv-target-env=vulkan1.1
2+
3+
// CHECK: ; Version: 1.3
4+
5+
// CHECK: OpCapability GroupNonUniform
6+
7+
// CHECK: OpEntryPoint Fragment
8+
// CHECK-SAME: %SubgroupSize
9+
10+
// CHECK: OpDecorate %SubgroupSize BuiltIn SubgroupSize
11+
// CHECK: OpDecorate %SubgroupSize Flat
12+
13+
// CHECK: %SubgroupSize = OpVariable %_ptr_Input_uint Input
14+
15+
float4 main() : SV_Target {
16+
// CHECK: OpLoad %uint %SubgroupSize
17+
uint laneCount = WaveGetLaneCount();
18+
return float4(laneCount, 1, 1, 1);
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %dxc -T ps_6_0 -E main -fspv-target-env=vulkan1.1
2+
3+
// CHECK: ; Version: 1.3
4+
5+
// CHECK: OpCapability GroupNonUniform
6+
7+
// CHECK: OpEntryPoint Fragment
8+
// CHECK-SAME: %SubgroupLocalInvocationId
9+
10+
// CHECK: OpDecorate %SubgroupLocalInvocationId BuiltIn SubgroupLocalInvocationId
11+
// CHECK: OpDecorate %SubgroupLocalInvocationId Flat
12+
13+
// CHECK: %SubgroupLocalInvocationId = OpVariable %_ptr_Input_uint Input
14+
15+
float4 main() : SV_Target {
16+
// CHECK: OpLoad %uint %SubgroupLocalInvocationId
17+
uint laneIndex = WaveGetLaneIndex();
18+
return float4(laneIndex, 1, 1, 1);
19+
}

tools/clang/unittests/SPIRV/CodeGenSpirvTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,12 @@ TEST_F(FileTest, SM6WaveGetLaneCount) {
15411541
TEST_F(FileTest, SM6WaveGetLaneIndex) {
15421542
runFileTest("sm6.wave-get-lane-index.hlsl");
15431543
}
1544+
TEST_F(FileTest, SM6WaveGetLaneCountPS) {
1545+
runFileTest("sm6.wave-get-lane-count.ps.hlsl");
1546+
}
1547+
TEST_F(FileTest, SM6WaveGetLaneIndexPS) {
1548+
runFileTest("sm6.wave-get-lane-index.ps.hlsl");
1549+
}
15441550
TEST_F(FileTest, SM6WaveBuiltInNoDuplicate) {
15451551
runFileTest("sm6.wave.builtin.no-dup.hlsl");
15461552
}

0 commit comments

Comments
 (0)