Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Vulkan specialization constants be expressed in GLSL?

Tags:

glsl

vulkan

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?

like image 405
mjwach Avatar asked Nov 23 '16 20:11

mjwach


1 Answers

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.

like image 103
Sascha Willems Avatar answered Oct 20 '22 23:10

Sascha Willems