Creating a storage buffer
When we want to not only read data from a buffer inside shaders, but we would also like to store data in it, we need to use storage buffers. These are created with a VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
usage.
How to do it...
- Take the handle of a logical device and store it in a variable of type
VkPhysicalDevice
namedphysical_device
. - Create a variable of type
VkBuffer
namedstorage_buffer
in which a handle of a created buffer will be stored. - Create a buffer of a desired size and usage using the
logical_device
variable. Specified usage must contain at least aVK_BUFFER_USAGE_STORAGE_BUFFER_BIT
flag. Store the created handle in thestorage_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 created buffer (refer to the Allocating and binding memory object to a buffer recipe from Chapter 4...