Make gl_SubGroupARB a flat int in Vulkan

gl_SubGroupARB was being correctly declared as an Input variable in
Vulkan but it was missing the Flat decoration, which made spirv-val emit
the VUID-StandaloneSpirv-Flat-04744 validation error with shaders using
that built-in.
This commit is contained in:
Ricardo Garcia 2022-09-21 10:04:50 +02:00
parent b40f87f1d3
commit d4865f0b68
4 changed files with 86 additions and 6 deletions

View File

@ -0,0 +1,34 @@
spv.subgroupSizeARB.frag
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 12
Capability Shader
Capability SubgroupBallotKHR
Extension "SPV_KHR_shader_ballot"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 8 10
ExecutionMode 4 OriginUpperLeft
Source GLSL 450
SourceExtension "GL_ARB_shader_ballot"
SourceExtension "GL_KHR_shader_subgroup_basic"
Name 4 "main"
Name 8 "result"
Name 10 "gl_SubGroupSizeARB"
Decorate 8(result) Location 0
Decorate 10(gl_SubGroupSizeARB) Flat
Decorate 10(gl_SubGroupSizeARB) BuiltIn SubgroupSize
2: TypeVoid
3: TypeFunction 2
6: TypeInt 32 0
7: TypePointer Output 6(int)
8(result): 7(ptr) Variable Output
9: TypePointer Input 6(int)
10(gl_SubGroupSizeARB): 9(ptr) Variable Input
4(main): 2 Function None 3
5: Label
11: 6(int) Load 10(gl_SubGroupSizeARB)
Store 8(result) 11
Return
FunctionEnd

View File

@ -0,0 +1,10 @@
#version 450
#extension GL_ARB_shader_ballot : enable
#extension GL_KHR_shader_subgroup_basic : enable
layout(location = 0) out uint result;
void main (void)
{
result = gl_SubGroupSizeARB;
}

View File

@ -7653,6 +7653,23 @@ static void SpecialQualifier(const char* name, TStorageQualifier qualifier, TBui
symQualifier.builtIn = builtIn;
}
//
// Modify the symbol's flat decoration.
//
// Safe to call even if name is not present.
//
// Originally written to transform gl_SubGroupSizeARB from uniform to fragment input in Vulkan.
//
static void ModifyFlatDecoration(const char* name, bool flat, TSymbolTable& symbolTable)
{
TSymbol* symbol = symbolTable.find(name);
if (symbol == nullptr)
return;
TQualifier& symQualifier = symbol->getWritableType().getQualifier();
symQualifier.flat = flat;
}
//
// To tag built-in variables with their TBuiltInVariable enum. Use this when the
// normal declaration text already gets the qualifier right, and all that's needed
@ -8036,9 +8053,12 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
BuiltInVariable("gl_SubGroupLeMaskARB", EbvSubGroupLeMask, symbolTable);
BuiltInVariable("gl_SubGroupLtMaskARB", EbvSubGroupLtMask, symbolTable);
if (spvVersion.vulkan > 0)
if (spvVersion.vulkan > 0) {
// Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
if (language == EShLangFragment)
ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
}
else
BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
}
@ -8470,9 +8490,12 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
BuiltInVariable("gl_SubGroupLeMaskARB", EbvSubGroupLeMask, symbolTable);
BuiltInVariable("gl_SubGroupLtMaskARB", EbvSubGroupLtMask, symbolTable);
if (spvVersion.vulkan > 0)
if (spvVersion.vulkan > 0) {
// Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
if (language == EShLangFragment)
ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
}
else
BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
}
@ -8687,9 +8710,12 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
BuiltInVariable("gl_SubGroupLeMaskARB", EbvSubGroupLeMask, symbolTable);
BuiltInVariable("gl_SubGroupLtMaskARB", EbvSubGroupLtMask, symbolTable);
if (spvVersion.vulkan > 0)
if (spvVersion.vulkan > 0) {
// Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
if (language == EShLangFragment)
ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
}
else
BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
}
@ -8877,9 +8903,12 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
BuiltInVariable("gl_SubGroupLeMaskARB", EbvSubGroupLeMask, symbolTable);
BuiltInVariable("gl_SubGroupLtMaskARB", EbvSubGroupLtMask, symbolTable);
if (spvVersion.vulkan > 0)
if (spvVersion.vulkan > 0) {
// Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
if (language == EShLangFragment)
ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
}
else
BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
@ -9075,9 +9104,12 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
BuiltInVariable("gl_SubGroupLeMaskARB", EbvSubGroupLeMask, symbolTable);
BuiltInVariable("gl_SubGroupLtMaskARB", EbvSubGroupLtMask, symbolTable);
if (spvVersion.vulkan > 0)
if (spvVersion.vulkan > 0) {
// Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
if (language == EShLangFragment)
ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
}
else
BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
}
@ -9202,9 +9234,12 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
BuiltInVariable("gl_SubGroupLeMaskARB", EbvSubGroupLeMask, symbolTable);
BuiltInVariable("gl_SubGroupLtMaskARB", EbvSubGroupLtMask, symbolTable);
if (spvVersion.vulkan > 0)
if (spvVersion.vulkan > 0) {
// Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
if (language == EShLangFragment)
ModifyFlatDecoration("gl_SubGroupSizeARB", true, symbolTable);
}
else
BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
}

View File

@ -480,6 +480,7 @@ INSTANTIATE_TEST_SUITE_P(
"spv.storageBuffer.vert",
"spv.terminate.frag",
"spv.subgroupUniformControlFlow.vert",
"spv.subgroupSizeARB.frag",
"spv.precise.tese",
"spv.precise.tesc",
"spv.viewportindex.tese",