I've been using Vulkan for a while but I just now learned about specialization constants. The specification says:
Specialization constants are useful to allow a compute shader to have its local workgroup size changed at runtime by the user, for example.
Neat! I want to do almost exactly that, and I would like to use such varying constants for other purposes as well. But the examples of specialization constants given in the Vulkan specification (version 1.0.34 at the moment) all appear to be in SPIR-V, not GLSL, and my shaders are all written in GLSL. So I think I probably can't use this nice feature. :(
Am I right? Or is there a way to use specialization constants via GLSL, either as workgroup size constants, or as arbitrary constant variable values, or in some other fashion?
Sure, specialization constants can be used with GLSL in Vulkan as per GL_KHR_Vulkan.
It's a special layout qualifier, so your GLSL specialization constants will look like this:
layout (constant_id = 0) const int SSAO_KERNEL_SIZE = 64;
Values for those constants are then specified upon pipeline creation using the pSpecializationInfo member of the shader stage create info used in the pipeline create info.
This also works fine for e.g. compute shader workgroup sizes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With