diff --git a/Test/baseResults/spv.subgroupSizeARB.frag.out b/Test/baseResults/spv.subgroupSizeARB.frag.out new file mode 100644 index 00000000..7ce78183 --- /dev/null +++ b/Test/baseResults/spv.subgroupSizeARB.frag.out @@ -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 diff --git a/Test/spv.subgroupSizeARB.frag b/Test/spv.subgroupSizeARB.frag new file mode 100644 index 00000000..45a1701d --- /dev/null +++ b/Test/spv.subgroupSizeARB.frag @@ -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; +} diff --git a/glslang/MachineIndependent/Initialize.cpp b/glslang/MachineIndependent/Initialize.cpp index 35681a5f..31b448ad 100644 --- a/glslang/MachineIndependent/Initialize.cpp +++ b/glslang/MachineIndependent/Initialize.cpp @@ -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); } diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp index ed0f5cad..93e364d9 100644 --- a/gtests/Spv.FromFile.cpp +++ b/gtests/Spv.FromFile.cpp @@ -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",