class render::GpuBuffer

Inherits: RenderProxy

Defines a buffer that can be used for operations on the GPU.

Public

Methods

~GpuBuffer

virtual ~GpuBuffer() noexcept

GetInformation

const GpuBufferInformation &GetInformation() const

Returns information describing the buffer.

SetName

virtual void SetName(const StringView &name)

Assigns an name to the buffer, primarily used for easier debugging.

GetName

const String &GetName() const

Returns the name of the buffer.

Primarily used for debugging purposes.

Map

GpuBufferMappedScope Map(u32 offset, u32 size, GpuMapOptions options)

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

GpuBufferMappedScope Map(GpuMapOptions options)

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

void Write(u32 offset, u32 length, const void *source)

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

u32 WriteTyped(u32 offset, const GpuDataParameterTypeInformation &typeInformation, const void *source)

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

void ZeroOut(u32 offset, u32 length)

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

void Read(u32 offset, u32 length, void *destination)

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

u32 GetTotalSize() const

Returns the total size of this buffer in bytes.

GetSuballocationSize

u32 GetSuballocationSize() const

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

void *GetMappedMemory() const

Returns a pointer to persistently mapped memory, or nullptr if not mappable.

Flush

virtual void Flush(u32 offset, u32 size)

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

virtual void Invalidate(u32 offset, u32 size)

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.

GetDevice

GpuDevice &GetDevice() const

Gets the GPU device the buffer is created on.

GetUseMask

virtual GpuQueueMask GetUseMask(GpuAccessFlags accessFlags = GpuAccessFlag::Read | GpuAccessFlag::Write) = 0

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

virtual u32 GetBoundCount() const = 0

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

virtual u32 GetUseCount() const = 0

Returns the amount of submitted command buffers that the buffer is bound to.

IsRangeBound

virtual bool IsRangeBound(u32 offset, u32 size) const = 0

Checks if any suballocation overlapping the given byte range is bound.

IsRangeInUse

virtual bool IsRangeInUse(u32 offset, u32 size) const = 0

Checks if any suballocation overlapping the given byte range is in use.

Protected

Constructors

GpuBuffer

GpuBuffer(GpuDevice &device, const GpuBufferCreateInformation &createInformation, u32 suballocationSize)

Constructs a new GPU buffer.

Methods

SyncFromCoreObject

void SyncFromCoreObject(const CoreSyncData &data, FrameAllocator &allocator) override

Update internal data from provided memory buffer that was populated with data from the owning CoreObject.

RecreateInternalBuffer

virtual void RecreateInternalBuffer() = 0

Recreates the underlying buffer.

Note this will clear all currently written data. Old buffer will be released once its done being used.

ValidateMap

void ValidateMap(u32 offset, u32 size, GpuMapOptions options)

Logs a warning if the offset we're trying to map is currently being used on GPU, or is bound to any command buffer.

Fields

mInformation

mDevice

GpuDevice & mDevice

mName

String mName

mSuballocationSize

u32 mSuballocationSize

mTotalSize

u32 mTotalSize

mMappedMemory

void * mMappedMemory