A buffer view represents a contiguous range of a buffer and a specific format to be used to interpret the data. Buffer views are used to enable shaders to access buffer contents interpreted as formatted data. In order to create a valid buffer view, the buffer must have been created with at least one of the following usage flags:
VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT
VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT
Buffer views are represented by VkBufferView
handles:
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkBufferView)
To create a buffer view, call:
VkResult vkCreateBufferView( VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBufferView* pView);
device
is the logical device that creates the buffer view.
pCreateInfo
is a pointer to an instance of the
VkBufferViewCreateInfo
structure containing parameters to be used
to create the buffer.
pAllocator
controls host memory allocation as described in the
Memory Allocation chapter.
pView
points to a VkBufferView
handle in which the resulting
buffer view object is returned.
The VkBufferViewCreateInfo
structure is defined as:
typedef struct VkBufferViewCreateInfo { VkStructureType sType; const void* pNext; VkBufferViewCreateFlags flags; VkBuffer buffer; VkFormat format; VkDeviceSize offset; VkDeviceSize range; } VkBufferViewCreateInfo;
sType
is the type of this structure.
pNext
is NULL
or a pointer to an extension-specific structure.
flags
is reserved for future use.
buffer
is a VkBuffer
on which the view will be created.
format
is a VkFormat
describing the format of the data
elements in the buffer.
offset
is an offset in bytes from the base address of the buffer.
Accesses to the buffer view from shaders use addressing that is relative
to this starting offset.
range
is a size in bytes of the buffer view.
If range
is equal to VK_WHOLE_SIZE
, the range from
offset
to the end of the buffer is used.
If VK_WHOLE_SIZE
is used and the remaining size of the buffer is
not a multiple of the element size of format
, then the nearest
smaller multiple is used.
To destroy a buffer view, call:
void vkDestroyBufferView( VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator);
device
is the logical device that destroys the buffer view.
bufferView
is the buffer view to destroy.
pAllocator
controls host memory allocation as described in the
Memory Allocation chapter.