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.
Creating a uniform buffer
How to do it...
- Take the created logical device and use its handle to initialize a variable of type VkDevice named logical_device.
- Create a variable of type VkBuffer named uniform_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 a VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT flag. Store the handle of the buffer in the uniform_buffer variable (refer to the Creating a buffer recipe from Chapter 4, Resources...