class
render::GpuBuffer
Defines a buffer that can be used for operations on the GPU.
Public
Methods
~GpuBuffer
GetInformation
Returns information describing the buffer.
SetName
Assigns an name to the buffer, primarily used for easier debugging.
GetName
Returns the name of the buffer.
Primarily used for debugging purposes.
Map
Maps the buffer and returns an RAII mapped region that automatically handles flush on destruction.
- offset
- Offset in bytes from which to map.
- size
- Size of the region to map, in bytes.
- options
- Specifies read/write intent for the mapping.
Returns: RAII mapped region containing the mapped memory pointer.
Map
Maps the entire buffer and returns an RAII mapped region.
- options
- Specifies read/write intent for the mapping.
Returns: RAII mapped region containing the mapped memory pointer.
Write
Writes the data of the specified length into the buffer at the provided offset. must contain at least bytes.
Buffer must support CPU writes. This mean it's either explicitly created with StoreOnCPUWithGPUAccess flag, or running on a GPU that supports CPU access. The latter usually means running on an integrated GPU with shared memory.
After all writes are finished make sure to call Flush() to make the writes visible to the GPU.
WriteTyped
Writes the data into the buffer at the provided offset.
Takes care of respecting the padding/alignment requirements of the provided type. (e.g. a 3x3 matrix will be padded with 4 bytes in each row).
must contain at least as many bytes as the size provided in . Returns the total number of written bytes, including the padding.
Buffer must support CPU writes. This mean it's either explicitly created with StoreOnCPUWithGPUAccess flag, or running on a GPU that supports CPU access. The latter usually means running on an integrated GPU with shared memory.
After all writes are finished make sure to call Flush() to make the writes visible to the GPU.
ZeroOut
Clears the specified area of the buffer.
Buffer must support CPU writes. This mean it's either explicitly created with StoreOnCPUWithGPUAccess flag, or running on a GPU that supports CPU access. The latter usually means running on an integrated GPU with shared memory.
After all writes are finished make sure to call Flush() to make the writes visible to the GPU.
Read
Reads the data from the buffer at the provided offset.
Buffer must support CPU reads. This mean it's either explicitly created with StoreOnCPUWithGPUAccess flag, or running on a GPU that supports CPU access. The latter usually means running on an integrated GPU with shared memory.
If GPU wrote to this buffer you must ensure to issue an execution barrier which ensures all GPU units finish writing to the buffer, a GPU memory barrier that makes sure it flushes it caches into memory, and then finally call Invalidate(), which forces CPU to fetch the data from the memory rather than its caches. All of this must be done before reading the data.
GetTotalSize
Returns the total size of this buffer in bytes.
GetSuballocationSize
In case this buffer is containing multiple sub-allocated buffers, returns the size of one sub-allocation.
Note this size might be different than requested during creation as platform alignment requirements for suballocation must be respected.
If the buffer doesn't have any suballocated buffers, this is equivalent to GetTotalSize().
GetMappedMemory
Returns a pointer to persistently mapped memory, or nullptr if not mappable.
Flush
Flushes CPU writes to make them visible to the GPU.
Only relevant for non-coherent memory.
- offset
- Offset from buffer start, in bytes.
- size
- Size of region to flush, in bytes.
Invalidate
Invalidates GPU writes to make them visible to the CPU.
Only relevant for non-coherent memory.
- offset
- Offset from buffer start, in bytes.
- size
- Size of region to invalidate, in bytes.
GetUseMask
Returns if the buffer is currently being used on the GPU, and if so on which queues is it scheduled.
Allows the caller so synchronize command buffer execution after buffer is done being used.
GetBoundCount
Returns the amount of command buffers that the buffer is currently bound to.
Note that this does not specify if the command buffer has been submitted for execution or not.
GetUseCount
Returns the amount of submitted command buffers that the buffer is bound to.
IsRangeBound
Checks if any suballocation overlapping the given byte range is bound.
IsRangeInUse
Checks if any suballocation overlapping the given byte range is in use.
Protected
Constructors
GpuBuffer
Constructs a new GPU buffer.
Methods
SyncFromCoreObject
Update internal data from provided memory buffer that was populated with data from the owning CoreObject.
RecreateInternalBuffer
Recreates the underlying buffer.
Note this will clear all currently written data. Old buffer will be released once its done being used.
ValidateMap
Logs a warning if the offset we're trying to map is currently being used on GPU, or is bound to any command buffer.