From 708d560c23d99e028722b7e98710371cca56fe5b Mon Sep 17 00:00:00 2001 From: Jeff Bolz Date: Thu, 12 Sep 2024 12:25:07 -0500 Subject: [PATCH] Allow compute derivative modes when the workgroup dimensions are spec constants --- .../spv.computeShaderDerivativesSpec.comp.out | 33 ++++++++++++++++--- ...spv.computeShaderDerivativesSpec2.comp.out | 33 ++++++++++++++++--- glslang/MachineIndependent/ParseHelper.cpp | 9 +++-- 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/Test/baseResults/spv.computeShaderDerivativesSpec.comp.out b/Test/baseResults/spv.computeShaderDerivativesSpec.comp.out index be4cc3ec4..e4afc6f5c 100644 --- a/Test/baseResults/spv.computeShaderDerivativesSpec.comp.out +++ b/Test/baseResults/spv.computeShaderDerivativesSpec.comp.out @@ -1,6 +1,31 @@ spv.computeShaderDerivativesSpec.comp -ERROR: 0:5: 'derivative_group_quadsNV' : requires local_size_x and local_size_y to be multiple of two -ERROR: 1 compilation errors. No code generated. +// Module Version 10000 +// Generated by (magic number): 8000b +// Id's are bound by 12 - -SPIR-V is not generated for failed compile or link + Capability Shader + Capability ComputeDerivativeGroupQuadsNV + Extension "SPV_NV_compute_shader_derivatives" + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint GLCompute 4 "main" + ExecutionMode 4 LocalSize 1 1 1 + ExecutionMode 4 DerivativeGroupQuadsNV + Source GLSL 450 + SourceExtension "GL_NV_compute_shader_derivatives" + Name 4 "main" + Decorate 7 SpecId 0 + Decorate 8 SpecId 1 + Decorate 11 BuiltIn WorkgroupSize + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeInt 32 0 + 7: 6(int) SpecConstant 1 + 8: 6(int) SpecConstant 1 + 9: 6(int) Constant 1 + 10: TypeVector 6(int) 3 + 11: 10(ivec3) SpecConstantComposite 7 8 9 + 4(main): 2 Function None 3 + 5: Label + Return + FunctionEnd diff --git a/Test/baseResults/spv.computeShaderDerivativesSpec2.comp.out b/Test/baseResults/spv.computeShaderDerivativesSpec2.comp.out index 3417ff778..a3b38cafd 100644 --- a/Test/baseResults/spv.computeShaderDerivativesSpec2.comp.out +++ b/Test/baseResults/spv.computeShaderDerivativesSpec2.comp.out @@ -1,6 +1,31 @@ spv.computeShaderDerivativesSpec2.comp -ERROR: 0:5: 'derivative_group_linearNV' : requires total group size to be multiple of four -ERROR: 1 compilation errors. No code generated. +// Module Version 10000 +// Generated by (magic number): 8000b +// Id's are bound by 12 - -SPIR-V is not generated for failed compile or link + Capability Shader + Capability ComputeDerivativeGroupLinearNV + Extension "SPV_NV_compute_shader_derivatives" + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint GLCompute 4 "main" + ExecutionMode 4 LocalSize 1 1 1 + ExecutionMode 4 DerivativeGroupLinearNV + Source ESSL 320 + SourceExtension "GL_NV_compute_shader_derivatives" + Name 4 "main" + Decorate 7 SpecId 0 + Decorate 8 SpecId 1 + Decorate 11 BuiltIn WorkgroupSize + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeInt 32 0 + 7: 6(int) SpecConstant 1 + 8: 6(int) SpecConstant 1 + 9: 6(int) Constant 1 + 10: TypeVector 6(int) 3 + 11: 10(ivec3) SpecConstantComposite 7 8 9 + 4(main): 2 Function None 3 + 5: Label + Return + FunctionEnd diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index f314b2783..215ccd991 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -9924,8 +9924,8 @@ void TParseContext::updateStandaloneQualifierDefaults(const TSourceLoc& loc, con if (publicType.shaderQualifiers.layoutDerivativeGroupQuads) { if (publicType.qualifier.storage == EvqVaryingIn) { - if ((intermediate.getLocalSize(0) & 1) || - (intermediate.getLocalSize(1) & 1)) + if ((intermediate.getLocalSizeSpecId(0) == TQualifier::layoutNotSet && (intermediate.getLocalSize(0) & 1)) || + (intermediate.getLocalSizeSpecId(1) == TQualifier::layoutNotSet && (intermediate.getLocalSize(1) & 1))) error(loc, "requires local_size_x and local_size_y to be multiple of two", "derivative_group_quadsNV", ""); else intermediate.setLayoutDerivativeMode(LayoutDerivativeGroupQuads); @@ -9935,7 +9935,10 @@ void TParseContext::updateStandaloneQualifierDefaults(const TSourceLoc& loc, con } if (publicType.shaderQualifiers.layoutDerivativeGroupLinear) { if (publicType.qualifier.storage == EvqVaryingIn) { - if((intermediate.getLocalSize(0) * + if (intermediate.getLocalSizeSpecId(0) == TQualifier::layoutNotSet && + intermediate.getLocalSizeSpecId(1) == TQualifier::layoutNotSet && + intermediate.getLocalSizeSpecId(2) == TQualifier::layoutNotSet && + (intermediate.getLocalSize(0) * intermediate.getLocalSize(1) * intermediate.getLocalSize(2)) % 4 != 0) error(loc, "requires total group size to be multiple of four", "derivative_group_linearNV", "");