Creating a uniform buffer
In Vulkan, uniform variables used inside shaders cannot be placed in a global namespace. They can be defined only inside uniform buffers. For these, we need to create buffers with a VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
usage.
How to do it...
- Take the created logical device and use its handle to initialize a variable of type
VkDevice
namedlogical_device
. - Create a variable of type
VkBuffer
nameduniform_buffer
. It will hold the handle of the created buffer.
- Create a buffer using a
logical_device
variable and specifying the desired size and usage. The latter must contain at least aVK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
flag. Store the handle of the buffer in theuniform_buffer
variable (refer to the Creating a buffer recipe from Chapter 4, Resources and Memory). - Allocate a memory object with a
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
property (or use a range of an existing memory object) and bind it to the buffer (refer to the Allocating and binding memory object to a buffer recipe...