Dispatching compute work
Apart from drawing, Vulkan can be used to perform general computations. For this purpose, we need to write compute shaders and execute them--this is called dispatching. When we want to issue computational work to be performed, we need to specify how many separate compute shader instances should be executed and how they are divided into workgroups.
How to do it...
- Take the handle of a command buffer and store it in a variable of type
VkCommandBuffer
namedcommand_buffer
. Make sure the command buffer is in the recording state and no render pass is currently started. - Store the number of local workgroups along the x dimension in a variable of type
uint32_t
namedx_size
. - The number of local workgroups in the y dimensions should be stored in a variable of type
uint32_t
namedy_size
.
- Use the number of local workgroups along the z dimension to initialize a variable of type
uint32_t
namedz_size
. - Record the
vkCmdDispatch( command_buffer, x_size, y_size, z_size )
function using...