core::ivk::buffer_t class

maps a memory region and interfaces with the driver for read/writes

buffers are used to map regions of memory that the driver should know about, either because they will be used to map GPU resources (geometry, textures, etc..), or because they are used for synchronising information between CPU/GPU (compute results). This class will handle most of the needs for synchonising, and how-to upload the data to the relevant locations as well as managing the internals.

constructors, destructors, conversion operators

buffer_t
constructs a buffer from the given buffer_data, as well as optionally sets a staging resource.
public

member-functions

reserve
tries to reserve a region of memory of at least the given size in thye buffer.
public
reserve
tries to reserve all requested sizes in the memory::region of this buffer.
public
commit
tries to find the appropriate method to update the buffer with the commit instructions.
public
deallocate
marks the specific region of memory available again.
public
copy_from
allows you to copy from one buffer into another.
public
is_busy
const public
wait_until_ready
forcibly wait until all operations are done, or the timeout has been reached.
const public
copy_to_host
makes the buffer available on the host.
const public
copy_to_host
makes the buffer available on the host.
const public
gpu_buffer
const public
data
const public
buffer_info
public

Function documentation

core::ivk::buffer_t::buffer_t(core::resource::cache_t& cache, const core::resource::metadata& metaData, psl::meta::file* metaFile, core::resource::handle<core::ivk::context> context, core::resource::handle<core::data::buffer_t> buffer_data, std::optional<core::resource::handle<core::ivk::buffer_t>> staging_buffer = std::nullopt)

Brief

constructs a buffer from the given buffer_data, as well as optionally sets a staging resource.

Details

Parameters
cache
metaData
metaFile
context
buffer_data in the data source to bind to this buffer. (see note for more info)
staging_buffer in the staging buffer to use in case staging is needed. (see warning for more info)

std::optional<memory::segment> core::ivk::buffer_t::reserve(vk::DeviceSize size)

Brief

tries to reserve a region of memory of at least the given size in thye buffer.

Parameters
size in the minimum size to allocate
Returns a memory::segment on success.

std::vector<std::pair<memory::segment, memory::range_t>> core::ivk::buffer_t::reserve(std::vector<vk::DeviceSize> sizes, bool optimize = false)

Brief

tries to reserve all requested sizes in the memory::region of this buffer.

Details

optmized version of reserve() that works on a batch of data. It will try to satisfy allocating regions of memory of atleast the given accumulative size. Depending on the optimize boolean parameter's value this can be in one optimized memory::segment (true), or in equal amount of memory::segments as there were elements in the sizes requested container (false). when optimize is true, the returned memory::range_t in the pair signifies the offset from the start of the segment (where the actual memory you requested resides). when optimize is false, range always starts at 0, and ends at the actual allocated size.

Parameters
sizes in a container with minimum sizes you want to request.
optimize in signifies if we should we try to collapse multiple memory::segments into one segment if possible, avoiding fragmentation and overhead.
Returns a vector with as many contained elements as the requested sizes container has.

bool core::ivk::buffer_t::commit(std::vector<core::gfx::commit_instruction> instructions)

Brief

tries to find the appropriate method to update the buffer with the commit instructions.

Details

this method tries to commit the given instruction into the buffer. depending on the type of buffer how this does that can differ greatly.

Parameters
instructions in all the instructions you wish to send to the GPU in this batch.
Returns success if the instruction has been sent.

bool core::ivk::buffer_t::deallocate(memory::segment& segment)

Brief

marks the specific region of memory available again.

Details

Parameters
segment in the region you wish to free up.
Returns success in case the region was freed. note that in case the buffer was not the owner of the memory::segment, false will be returned.

bool core::ivk::buffer_t::copy_from(const buffer_t& other, const std::vector<vk::BufferCopy>& copyRegions)

Brief

allows you to copy from one buffer into another.

Parameters
other in the buffer to copy from into this instance.
copyRegions in the batch of copy instructions.
Returns true in case the instructions were successfully uploaded to the GPU.

bool core::ivk::buffer_t::is_busy() const

Details

Returns in case the GPU/driver is busy.

std::optional<resource::handle<buffer_t>> core::ivk::buffer_t::copy_to_host(bool compressed_copy = true) const

Brief

makes the buffer available on the host.

Parameters
compressed_copy in when compressed is true, then the buffer will collapse all empty regions and return a buffer that is the size of all actual committed memory.
Returns a handle to a HOST_VISIBLE buffer on success.

std::optional<resource::handle<buffer_t>> core::ivk::buffer_t::copy_to_host(const std::vector<vk::BufferCopy>& copyRegions) const

Brief

makes the buffer available on the host.

Parameters
copyRegions in the regions the new buffer will consist out of. The new buffer will be the size of the accumulate size of the copyRegions (+ alignment rules).
Returns a handle to a HOST_VISIBLE buffer on success.

const vk::Buffer& core::ivk::buffer_t::gpu_buffer() const

Returns the vk::Buffer handle.

core::resource::handle<core::data::buffer_t> core::ivk::buffer_t::data() const

Returns the internal buffer data.

vk::DescriptorBufferInfo& core::ivk::buffer_t::buffer_info()

Returns the vulkan descriptor buffer info.