Using push constants in shaders
When we provide data to shaders, we usually use uniform buffers, storage buffers, or other types of descriptor resources. Unfortunately, updating such resources may not be too convenient, especially when we need to provide data that changes frequently.
For this purpose, push constants were introduced. Through them we can provide data in a simplified and much faster way than by updating descriptor resources. However, we need to fit into a much smaller amount of available space.
Accessing push constants in GLSL shaders is similar to using uniform buffers.
How to do it...
- Create a shader file.
- Define a uniform block:
- Provide a
push_constant
layout qualifier:layout( push_constant )
- Use a
uniform
storage qualifier
- Provide a
- Provide a unique name of the block
- Inside the braces, define a set of uniform variables
- Specify the name of the block instance
<instance name>
.
- Inside the
void main()
function, access uniform variables using a block instance name:
<instance name...