Providing data to shaders through push constants
During drawing or dispatching computational work, specific shader stages are executed--the ones defined during the pipeline creation. So the shaders can perform their job, we need to provide data to them. Most of the time we use descriptor sets, as they allow us to provide kilobytes or even megabytes of data through buffers or images. But using them is quite complicated. And, what's more important, frequent changes of descriptor sets may impact the performance of our application. But sometimes, we need to provide a small amount of data in a fast and easy way. We can do this using push constants.
How to do it...
- Store the handle of a command buffer in a variable of type
VkCommandBuffer
namedcommand_buffer
. Make sure it is in a recording state. - Take the layout of a pipeline that uses a range of push constants. Store the handle of the layout in a variable of type
VkPipelineLayout
namedpipeline_layout
. - Through a variable of type
VkShaderStageFlags...