Writing compute shaders
Compute shaders are used, as the name suggests, for general mathematical calculations. They are executed in (local) groups of a defined, three-dimensional size, which may have access to a common set of data. At the same time, many local groups can be executed to generate results faster.
How to do it...
- Create a text file. Select a name for the file, but use a
comp
extension for it (for example,shader.comp
). - Insert
#version 450
in the first line of the file. - Using an input layout qualifier, define the size of the local workgroup:
layout( local_size_x = <x size>, local_size_y = <y size>, local_size_z = <z size> ) in;
- Define uniform variables that correspond to descriptor resources created in the application. To define a uniform variable:
- Specify the number of descriptor set and a binding number in which a given resource can be accessed:
layout (set=<set index>, binding=<binding index>)
- Provide a
uniform
storage qualifier - Specify the type of the...
- Specify the number of descriptor set and a binding number in which a given resource can be accessed: