Allowed types for specialization constants
The GLSL extension GL_KHR_vulkan_glsl says that specialization constants can only be used with scalar int, float or bool.
On the other hand, glslang compiles shaders with specialization constants whose type is any unsigned/signed integer variant of any size, or double.
Which types are actually allowed?
The additional permissiveness are due to SPIR-V. The spec allows types other than basic scalar types (including composite types and various number formats). Check section 1.9, "Specialization" and section 2.12, "Specialization" in https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.pdf.
Yes it is allowed in SPIR-V, my question was if it was also officially allowed in GLSL or if I'm relying on glslang's UB, given that glslang is the reference compiler for GLSL and the GLSL extension does not seem to allow it.
Well, yes. In as much as glslang emits SPIR-V, it will follow similar guidelines. Whether we should have different behaviours depending on target may be interesting to analyze.
From: maxime-modulopi @.> Sent: Wednesday, August 27, 2025 9:28:31 AM To: KhronosGroup/glslang @.> Cc: Diego Novillo @.>; Comment @.> Subject: Re: [KhronosGroup/glslang] Allowed types for specialization constants (Issue #3964)
[https://avatars.githubusercontent.com/u/144250665?s=20&v=4]maxime-modulopi left a comment (KhronosGroup/glslang#3964)https://github.com/KhronosGroup/glslang/issues/3964#issuecomment-3228214809
Yes it is allowed in SPIR-V, my question was if it was also officially allowed in GLSL or if I'm relying on glslang's UB, given that glslang is the reference compiler for GLSL and the GLSL extension does not seem to allow it.
— Reply to this email directly, view it on GitHubhttps://github.com/KhronosGroup/glslang/issues/3964#issuecomment-3228214809, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABXVCZ43TFBZ2ST3QP6NSXL3PWW77AVCNFSM6AAAAAB6J4ZM5GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTEMRYGIYTIOBQHE. You are receiving this because you commented.Message ID: @.***>
By "depending on target" you mean GLSL targeting GL drivers vs SPIR-V, right? If so, is it something that could be documented in the extension spec?
NVM, I forgot the extension is Vulkan-only.
There's also specialization constants in ARB_gl_spirv but it says
The constant_id can only be applied to a scalar int, a scalar float or a scalar bool.
The "Specialization Constants" section actually has the same text in both extensions (with the exception that ARB_gl_spirv does not have this fixup).
Given that the main implementation of GL_KHR_vulkan_glsl (glslang) seems to already support all byte sizes, it may be fine to adjust the wording to explicitly allow that?
ARB_gl_spirv however serves both as a GLSL extension and GL extension.
While the GLSL part only allows int, float and bool similarly to GL_KHR_vulkan_glsl, it is unclear if the GL part supports specifying non-32-bit values in the pConstantValue field of the SpecializeShaderARB function if SPIR-V with non-32-bit specialization constants is provided.