QRhiBuffer Class

Vertex, index, or uniform (constant) buffer resource. More...

Header: #include <QRhiBuffer>
qmake: QT += rhi
Inherits: QRhiResource

Public Types

enum Type { Immutable, Static, Dynamic }
enum UsageFlag { VertexBuffer, IndexBuffer, UniformBuffer, StorageBuffer }
flags UsageFlags

Public Functions

virtual bool build() = 0
void setSize(int sz)
void setType(QRhiBuffer::Type t)
void setUsage(QRhiBuffer::UsageFlags u)
int size() const
QRhiBuffer::Type type() const
QRhiBuffer::UsageFlags usage() const

Reimplemented Public Functions

virtual QRhiResource::Type resourceType() const override

Protected Variables

int m_size
QRhiBuffer::Type m_type
QRhiBuffer::UsageFlags m_usage

Additional Inherited Members

Detailed Description

Vertex, index, or uniform (constant) buffer resource.

Member Type Documentation

enum QRhiBuffer::Type

Specifies storage type of buffer resource.

ConstantValueDescription
QRhiBuffer::Immutable0Indicates that the data is not expected to change ever after the initial upload. Under the hood such buffer resources are typically placed in device local (GPU) memory (on systems where applicable). Uploading new data is possible, but may be expensive. The upload typically happens by copying to a separate, host visible staging buffer from which a GPU buffer-to-buffer copy is issued into the actual GPU-only buffer.
QRhiBuffer::Static1Indicates that the data is expected to change only infrequently. Typically placed in device local (GPU) memory, where applicable. On backends where host visible staging buffers are used for uploading, the staging buffers are kept around for this type, unlike with Immutable, so subsequent uploads do not suffer in performance. Frequent updates, especially updates in consecutive frames, should be avoided.
QRhiBuffer::Dynamic2Indicates that the data is expected to change frequently. Not recommended for large buffers. Typically backed by host visible memory in 2 copies in order to allow for changing without stalling the graphics pipeline. The double buffering is managed transparently to the applications and is not exposed in the API here in any form. This is the recommended, and, with some backends, the only possible, type for buffers with UniformBuffer usage.

enum QRhiBuffer::UsageFlag
flags QRhiBuffer::UsageFlags

Flag values to specify how the buffer is going to be used.

ConstantValueDescription
QRhiBuffer::VertexBuffer1 << 0Vertex buffer. This allows the QRhiBuffer to be used in QRhiCommandBuffer::setVertexInput().
QRhiBuffer::IndexBuffer1 << 1Index buffer. This allows the QRhiBuffer to be used in QRhiCommandBuffer::setVertexInput().
QRhiBuffer::UniformBuffer1 << 2Uniform buffer (also called constant buffer). This allows the QRhiBuffer to be used in combination with QRhiShaderResourceBinding::UniformBuffer. When NonDynamicUniformBuffers is reported as not supported, this usage can only be combined with the type Dynamic.
QRhiBuffer::StorageBuffer1 << 3Storage buffer. This allows the QRhiBuffer to be used in combination with QRhiShaderResourceBinding::BufferLoad, QRhiShaderResourceBinding::BufferStore, or QRhiShaderResourceBinding::BufferLoadStore. This usage can only be combined with the types Immutable or Static, and is only available when the Compute feature is reported as supported.

The UsageFlags type is a typedef for QFlags<UsageFlag>. It stores an OR combination of UsageFlag values.

Property Documentation

Member Function Documentation

[pure virtual] bool QRhiBuffer::build()

Creates the corresponding native graphics resources. If there are already resources present due to an earlier build() with no corresponding release(), then release() is called implicitly first.

Returns true when successful, false when a graphics operation failed. Regardless of the return value, calling release() is always safe.

[override virtual] QRhiResource::Type QRhiBuffer::resourceType() const

Reimplemented from QRhiResource::resourceType().

Returns the resource type.

void QRhiBuffer::setSize(int sz)

Sets the size of the buffer in bytes. The size is normally specified in QRhi::newBuffer() so this function is only used when the size has to be changed. As with other setters, the size only takes effect when calling build(), and for already built buffers this involves releasing the previous native resource and creating new ones under the hood.

Backends may choose to allocate buffers bigger than sz in order to fulfill alignment requirements. This is hidden from the applications and size() will always report the size requested in sz.

See also size().

void QRhiBuffer::setType(QRhiBuffer::Type t)

See also type().

void QRhiBuffer::setUsage(QRhiBuffer::UsageFlags u)

See also usage().

int QRhiBuffer::size() const

See also setSize().

QRhiBuffer::Type QRhiBuffer::type() const

See also setType().

QRhiBuffer::UsageFlags QRhiBuffer::usage() const

See also setUsage().

Member Variable Documentation

Related Non-Members

Macro Documentation