core::data::buffer class

container class for GPU data.

core::data::buffer is a data container for anything that will be uploaded to the GPU. This means that this can not contain any complex types (such as indirections). core::data::buffer can be incorrectly set up when giving incompatible memory::region bundled with vk::BufferUsageFlags.

constructors, destructors, conversion operators

buffer
public

member-functions

size
const public
usage
const public
memoryPropertyFlags
const public
region
const public
segments
const public
allocate
public
deallocate
public

Function documentation

core::data::buffer::buffer(const UID& uid, core::resource::cache& cache, vk::BufferUsageFlags usage, vk::MemoryPropertyFlags memoryPropertyFlags, memory::region&& memory_region)

Details

will do the minimal setup needed, no allocations happen at this point yet.

Parameters
uid in the UID that is assigned to this object
cache in which cache this object has been allocated in
usage in the usage flags that signify how the resource should be used by the GPU
memoryPropertyFlags in what are the properties of the memory (i.e. where does it live)
memory_region in what is the owning region of this memory. Note that this parameter also will dictate the size and alignment of the resource.

size_t core::data::buffer::size() const

Returns the total size in the memory::region that this buffer occupies.

vk::BufferUsageFlags core::data::buffer::usage() const

Returns the vk::BufferUsageFlags of this instance, showing the type of resource this is for the GPU

vk::MemoryPropertyFlags core::data::buffer::memoryPropertyFlags() const

Returns the vk::MemoryPropertyFlags, so you know where the data lives.

const memory::region& core::data::buffer::region() const

Details

Returns the associated memory::region, where the data lives.

const std::vector<memory::segment>& core::data::buffer::segments() const

Returns all committed memory::segments in the memory::region. Using this you can calculate fragmentation, and allocated size.

std::optional<memory::segment> core::data::buffer::allocate(size_t size)

Details

Will try to allocate a new memory::segment of atleast the given size. This method will adhere to the alignment requirements of the underlaying memory::region.

Parameters
size in the minimum expected size, this will auto-align/grow to the alignment requirements.
Returns optionally, a new allocated memory::segment of atleast the given size.

bool core::data::buffer::deallocate(memory::segment& segment)

Details

Parameters
segment in the target segment to deallocate.
Returns true in case the deallocation was successful.