class GpuBuffer

Inherits: CoreObject

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

Public

Methods

~GpuBuffer

virtual ~GpuBuffer() noexcept = default

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().

GetInformation

const GpuBufferInformation &GetInformation() const

Returns information describing the buffer.

Write

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

Writes the data into the CPU cached buffer.

Data will be synced with the render proxy on the next sync call.

WriteTyped

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

Same as Write(), but 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.

ZeroOut

void ZeroOut(u32 offset, u32 length)

Clears the specified area of the cache.

Data will be synced with the render proxy on the next sync call.

Read

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

Reads the data from the cached buffer.

Note the cached data only includes writes done by the CPU. It will not account for writes done explicitly on the render thread or on the GPU.

Map

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

Maps the cache 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.

staticCreate

static SPtr<GpuBuffer> Create(const GpuBufferCreateInformation &createInformation)

Creates a new buffer.

staticGetFormatSize

static u32 GetFormatSize(GpuBufferFormat format)

Returns the size of a single element in the buffer, of the provided format, in bytes.

staticGetIndexSize

static u32 GetIndexSize(IndexType type)

Returns the size of a single index buffer element of the specified type, in bytes.

staticCalculateTotalBufferSize

static u32 CalculateTotalBufferSize(const GpuBufferInformation &information, const SPtr<GpuDevice> &gpuDevice)

Calculates the size of a buffer described by the provided information, in bytes.

staticCalculateSuballocatedBufferSize

static u32 CalculateSuballocatedBufferSize(const GpuBufferInformation &information, const SPtr<GpuDevice> &gpuDevice)

Calculates the distance between two buffers, in case the buffer contains sub-allocated buffers.

This is guaranteed to be at least the request size of a single sub-allocated buffer, but may be larger due to alignment requirements.

staticCalculateSuballocatedBufferSize

static u32 CalculateSuballocatedBufferSize(const GpuBufferInformation &information, const GpuDevice &gpuDevice)

Protected

Constructors

GpuBuffer

GpuBuffer(const GpuBufferCreateInformation &createInformation)

Methods

Initialize

void Initialize() override

Initializes all the internal data of this object.

Must be called right after construction for new objects, or after deserialization for deserialized objects. If requested, render proxy is created and queued for initialization on the render thread.

Destroy

void Destroy() override

Frees all the data held by this object.

If the object has a render proxy, the internal reference to the render proxy will be released, but the proxy will not be destroyed unless this was the last reference. If render proxy destruction does happen, it is not immediate, but rather queued for destruction on the render thread.

CreateRenderProxy

SPtr<render::RenderProxy> CreateRenderProxy() const override

Creates an object that contains render thread specific data and methods for this object.

Can be null if such object is not required.

CreateRenderProxySyncPacket

RenderProxySyncPacket *CreateRenderProxySyncPacket(FrameAllocator &allocator, u32 flags) override

Creates a data packet that will be used for syncing the core object with it's render proxy.

Caller must free the retrieved packet using the provided allocator when done using it.

Fields

mInformation

mSuballocationSize

u32 mSuballocationSize

mTotalSize

u32 mTotalSize

mCache

u8 * mCache