struct render::GpuBufferUtility

Provides various utility operations on GpuBuffer.

Public

Methods

staticCreateStaging

static SPtr<GpuBuffer> CreateStaging(const SPtr<GpuBuffer> &buffer, bool readable)

Creates a staging buffer that can be used for as copy source or destination for the provided buffer.

buffer
Buffer to create the the staging buffer for. The staging buffer will have enough size to fit the contents of this buffer.
readable
True if the buffer needs to be CPU-readable, false if the buffer needs to be CPU-writeable.

Returns: Newly created buffer.

staticWrite

static void Write(const SPtr<GpuBuffer> &buffer, u32 offset, u32 length, const void *source, GpuBufferWriteFlags writeFlags = GpuBufferWriteFlag::Normal, SPtr<GpuCommandBuffer> commandBuffer = nullptr)

Writes data into a buffer while accounting for the fact that the buffer might not be directly CPU-writable.

Only buffers with StoreOnCPUWithGPUAccess flag, or staging write buffers are directly writable by the CPU. And only in the case they are not currently being used by the GPU.

If a buffer is being used by the GPU, or is not directly CPU-writable, this method will internally create a staging buffer, write the data into it, and then copy the staging buffer into the destination buffer using the provided command buffer. If no command buffer is provided, it will use a transfer buffer which will be submitted automatically before the next regular command buffer submission.

offset
Offset in bytes into the destination buffer at which to copy the data to.
length
Length of the area you want to copy, in bytes.
source
Source buffer containing the data to write. Data is read from the start of the buffer ( is only applied to the destination).
writeFlags
Optional write flags that may you can use to control behavior of the write operation if the buffer is used by the GPU.
commandBuffer
Command buffer on which to encode the staging buffer copy, in case the buffer is not directly writeable. If not provided the operation will be queued on a transfer command buffer that will be submitted just before next regular command buffer submission (or at the latest, at the end of the current frame).

staticRead

static void Read(const SPtr<GpuBuffer> &buffer, u32 offset, u32 length, void *destination, const SPtr<GpuQueue> &gpuQueue = nullptr)

Reads data from a buffer while accounting for the fact that the buffer might not be directly CPU-readable.

Only buffers with StoreOnCPUWithGPUAccess flag, or staging read buffers are directly readable by the CPU. And only in the case they are not currently being used by the GPU.

If a buffer is being used by the GPU, or is not directly CPU-readable, this method will internally create a staging buffer, copy the source buffer into the staging buffer using the provided GPU queue, and then read the data from the staging buffer. If no GPU queue is provided, it will use the default graphics queue.

Note if the buffer is currently used on the GPU, this method will block until the GPU is done executing, stalling the pipeline.

buffer
Buffer to read from.
offset
Offset in bytes from which to copy the data.
length
Length of the area you want to copy, in bytes.
destination
Destination buffer large enough to store the read data. Data is written from the start of the buffer ( is only applied to the source).
gpuQueue
GPU queue on which to perform the read. If not specified the default transfer queue will be used.

staticReadAsync

static TAsyncOp<SPtr<MemoryDataStream>> ReadAsync(const SPtr<GpuBuffer> &buffer, u32 offset, u32 length, GpuCommandBuffer &commandBuffer)

Performs a non-blocking read operation.

The GPU will execute the read when the command buffer reaches the execution point and the asynchronous operation will be signaled with the return value.

commandBuffer
Command buffer to queue the operation on.
offset
Offset in bytes from which to read the data.
length
Length of the area you want to read, in bytes.

Returns: Operation that will be signaled when the data is ready to be read.