tp::Buffer class

Represents a linear array of data visible to the device.

It is generally not used directly, but instead gets passed to commands or descriptors through tp::BufferView objects that view a contiguous range of its data.

Base classes

class Ownable
A customizable base class that is used for objects returned by the API in an OwningPtr.

Public static functions

static auto getRequiredViewAlignment(const Device* device, BufferUsageMask usage) -> uint64_t
Returns the minimum required alignment in bytes for the views of any buffer with the given usage flags. It is always a power of two not larger than 256 bytes.

Constructors, destructors, conversion operators

operator const BufferView() const
Casting operator returning the default tp::BufferView object.

Public functions

auto createTexelView(uint64_t offset, uint64_t size, Format format) -> BufferView
Creates a texel buffer view of the buffer data.
auto getDefaultView() const -> const BufferView
Returns the default tp::BufferView object that views the entire buffer range.
auto getDeviceAddress() const -> DeviceAddress
Returns the device address of the buffer that can then be used for accessing it in shaders.
auto getMemoryLocation() const -> MemoryLocation
Returns the tp::MemoryLocation that the buffer has been allocated from.
auto getRequiredViewAlignment() const -> uint64_t
Returns the minimum required alignment in bytes for the views of this buffer. It is always a power of two not larger than 256 bytes.
auto getSize() const -> uint64_t
Returns the size of the buffer in bytes.
auto getView(uint64_t offset, uint64_t size) const -> BufferView
Returns a view of a specified contiguous range of the buffer data.
auto mapForHostAccess(bool readAccess = true, bool writeAccess = true) const -> HostAccessibleMemory
Maps the buffer's memory for direct read or write operations by the application. tp::Buffer::mapForHostRead or tp::Buffer::mapForHostWrite should be preferred over this generic access.
auto mapForHostRead() const -> HostReadableMemory
Maps the buffer's memory for direct read operations by the application.
auto mapForHostWrite() const -> HostWritableMemory
Maps the buffer's memory for direct write operations by the application.
auto vkGetBufferHandle() const -> VkBufferHandle
Returns the associated VkBuffer handle.
auto vmaGetMemoryAllocationHandle() const -> VmaAllocationHandle
Returns the associated <a href='https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/struct_vma_allocation.html">VmaAllocation handle.

Function documentation

static uint64_t tp::Buffer::getRequiredViewAlignment(const Device* device, BufferUsageMask usage)

Returns the minimum required alignment in bytes for the views of any buffer with the given usage flags. It is always a power of two not larger than 256 bytes.

Parameters
device The device that the parent buffer will be allocated from.
usage The usage of the buffer.

tp::Buffer::operator const BufferView() const

Casting operator returning the default tp::BufferView object.

BufferView tp::Buffer::createTexelView(uint64_t offset, uint64_t size, Format format)

Creates a texel buffer view of the buffer data.

Parameters
offset The offset to the viewed buffer in bytes. Must be a multiple of tp::Buffer::getRequiredViewAlignment.
size The size of the buffer view in bytes.
format The format that the viewed data will be interpreted as when bound as a texel buffer descriptor. Must not be tp::Format::Undefined.

DeviceAddress tp::Buffer::getDeviceAddress() const

Returns the device address of the buffer that can then be used for accessing it in shaders.

BufferView tp::Buffer::getView(uint64_t offset, uint64_t size) const

Returns a view of a specified contiguous range of the buffer data.

Parameters
offset The offset to the viewed buffer in bytes. Must be a multiple of tp::Buffer::getRequiredViewAlignment.
size The size of the buffer view in bytes.

HostAccessibleMemory tp::Buffer::mapForHostAccess(bool readAccess = true, bool writeAccess = true) const

Maps the buffer's memory for direct read or write operations by the application. tp::Buffer::mapForHostRead or tp::Buffer::mapForHostWrite should be preferred over this generic access.

Parameters
readAccess If true, specifies that the application intends to read from the memory.
writeAccess If true, specifies that the application intends to write to the memory.

HostReadableMemory tp::Buffer::mapForHostRead() const

Maps the buffer's memory for direct read operations by the application.

HostWritableMemory tp::Buffer::mapForHostWrite() const

Maps the buffer's memory for direct write operations by the application.