QRhiVertexInputAttribute Class

Describes a single vertex input element. More...

Header: #include <rhi/qrhi.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::GuiPrivate)
qmake: QT += gui-private
Since: Qt 6.6

Public Types

enum Format { Float4, Float3, Float2, Float, UNormByte4, …, SShort }

Public Functions

QRhiVertexInputAttribute()
QRhiVertexInputAttribute(int binding, int location, QRhiVertexInputAttribute::Format format, quint32 offset, int matrixSlice = -1)
int binding() const
QRhiVertexInputAttribute::Format format() const
int location() const
int matrixSlice() const
quint32 offset() const
void setBinding(int b)
void setFormat(QRhiVertexInputAttribute::Format f)
void setLocation(int loc)
void setMatrixSlice(int slice)
void setOffset(quint32 ofs)
size_t qHash(const QRhiVertexInputAttribute &v, size_t seed = 0)
bool operator!=(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b)
bool operator==(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b)

Detailed Description

The members specify the binding number, location, format, and offset for a single vertex input element.

Note: For HLSL it is assumed that the vertex shader translated from SPIR-V uses TEXCOORD<location> as the semantic for each input. Hence no separate semantic name and index.

As an example, assume a vertex shader with the following inputs:

 layout(location = 0) in vec4 position;
 layout(location = 1) in vec2 texcoord;

Now let's assume that we have 3 component vertex positions (x, y, z) and 2 component texture coordinates (u, v) are provided in a non-interleaved format in a buffer (or separate buffers even). Once two bindings are defined, the attributes could be specified as:

 QRhiVertexInputLayout inputLayout;
 inputLayout.setBindings({
     { 3 * sizeof(float) },
     { 2 * sizeof(float) }
 });
 inputLayout.setAttributes({
     { 0, 0, QRhiVertexInputAttribute::Float3, 0 },
     { 1, 1, QRhiVertexInputAttribute::Float2, 0 }
 });

Once a graphics pipeline with this vertex input layout is bound, the vertex inputs could be set up like the following for drawing a cube with 36 vertices, assuming we have a single buffer with first the positions and then the texture coordinates:

 const QRhiCommandBuffer::VertexInput vbufBindings[] = {
     { cubeBuf, 0 },
     { cubeBuf, 36 * 3 * sizeof(float) }
 };
 cb->setVertexInput(0, 2, vbufBindings);

When working with interleaved data, there will typically be just one binding, with multiple attributes referring to that same buffer binding point:

 QRhiVertexInputLayout inputLayout;
 inputLayout.setBindings({
     { 5 * sizeof(float) }
 });
 inputLayout.setAttributes({
     { 0, 0, QRhiVertexInputAttribute::Float3, 0 },
     { 0, 1, QRhiVertexInputAttribute::Float2, 3 * sizeof(float) }
 });

and then:

 const QRhiCommandBuffer::VertexInput vbufBinding(interleavedCubeBuf, 0);
 cb->setVertexInput(0, 1, &vbufBinding);

Note: This is a RHI API with limited compatibility guarantees, see QRhi for details.

See also QRhiCommandBuffer::setVertexInput().

Member Type Documentation

enum QRhiVertexInputAttribute::Format

Specifies the type of the element data.

ConstantValueDescription
QRhiVertexInputAttribute::Float40Four component float vector
QRhiVertexInputAttribute::Float31Three component float vector
QRhiVertexInputAttribute::Float22Two component float vector
QRhiVertexInputAttribute::Float3Float
QRhiVertexInputAttribute::UNormByte44Four component normalized unsigned byte vector
QRhiVertexInputAttribute::UNormByte25Two component normalized unsigned byte vector
QRhiVertexInputAttribute::UNormByte6Normalized unsigned byte
QRhiVertexInputAttribute::UInt47Four component unsigned integer vector
QRhiVertexInputAttribute::UInt38Three component unsigned integer vector
QRhiVertexInputAttribute::UInt29Two component unsigned integer vector
QRhiVertexInputAttribute::UInt10Unsigned integer
QRhiVertexInputAttribute::SInt411Four component signed integer vector
QRhiVertexInputAttribute::SInt312Three component signed integer vector
QRhiVertexInputAttribute::SInt213Two component signed integer vector
QRhiVertexInputAttribute::SInt14Signed integer
QRhiVertexInputAttribute::Half415Four component half precision (16 bit) float vector
QRhiVertexInputAttribute::Half316Three component half precision (16 bit) float vector
QRhiVertexInputAttribute::Half217Two component half precision (16 bit) float vector
QRhiVertexInputAttribute::Half18Half precision (16 bit) float
QRhiVertexInputAttribute::UShort419Four component unsigned short (16 bit) integer vector
QRhiVertexInputAttribute::UShort320Three component unsigned short (16 bit) integer vector
QRhiVertexInputAttribute::UShort221Two component unsigned short (16 bit) integer vector
QRhiVertexInputAttribute::UShort22Unsigned short (16 bit) integer
QRhiVertexInputAttribute::SShort423Four component signed short (16 bit) integer vector
QRhiVertexInputAttribute::SShort324Three component signed short (16 bit) integer vector
QRhiVertexInputAttribute::SShort225Two component signed short (16 bit) integer vector
QRhiVertexInputAttribute::SShort26Signed short (16 bit) integer

Note: Support for half precision floating point attributes is indicated at run time by the QRhi::Feature::HalfAttributes feature flag.

Note: Direct3D 11/12 supports 16 bit input attributes, but does not support the Half3, UShort3 or SShort3 types. The D3D backends pass through Half3 as Half4, UShort3 as UShort4, and SShort3 as SShort4. To ensure cross platform compatibility, 16 bit inputs should be padded to 8 bytes.

Member Function Documentation

[constexpr noexcept] QRhiVertexInputAttribute::QRhiVertexInputAttribute()

Constructs a default vertex input attribute description.

QRhiVertexInputAttribute::QRhiVertexInputAttribute(int binding, int location, QRhiVertexInputAttribute::Format format, quint32 offset, int matrixSlice = -1)

Constructs a vertex input attribute description with the specified binding number, location, format, and offset.

matrixSlice should be -1 except when this attribute corresponds to a row or column of a matrix (for example, a 4x4 matrix becomes 4 vec4s, consuming 4 consecutive vertex input locations), in which case it is the index of the row or column. location - matrixSlice must always be equal to the location for the first row or column of the unrolled matrix.

int QRhiVertexInputAttribute::binding() const

Returns the binding point index.

See also setBinding().

QRhiVertexInputAttribute::Format QRhiVertexInputAttribute::format() const

Returns the format of the vertex input element.

See also setFormat().

int QRhiVertexInputAttribute::location() const

Returns the location of the vertex input element.

See also setLocation().

int QRhiVertexInputAttribute::matrixSlice() const

Returns the matrix slice if the input element corresponds to a row or column of a matrix, or -1 if not relevant.

See also setMatrixSlice().

quint32 QRhiVertexInputAttribute::offset() const

Returns the byte offset for the input element.

See also setOffset().

void QRhiVertexInputAttribute::setBinding(int b)

Sets the binding point index to b. By default this is set to 0.

See also binding().

void QRhiVertexInputAttribute::setFormat(QRhiVertexInputAttribute::Format f)

Sets the format of the vertex input element to f. By default this is set to Float4.

See also format().

void QRhiVertexInputAttribute::setLocation(int loc)

Sets the location of the vertex input element to loc. By default this is set to 0.

See also location().

void QRhiVertexInputAttribute::setMatrixSlice(int slice)

Sets the matrix slice. By default this is set to -1, and should be set to a >= 0 value only when this attribute corresponds to a row or column of a matrix (for example, a 4x4 matrix becomes 4 vec4s, consuming 4 consecutive vertex input locations), in which case it is the index of the row or column. location - matrixSlice must always be equal to the location for the first row or column of the unrolled matrix.

See also matrixSlice().

void QRhiVertexInputAttribute::setOffset(quint32 ofs)

Sets the byte offset for the input element to ofs.

See also offset().

Related Non-Members

[noexcept] size_t qHash(const QRhiVertexInputAttribute &v, size_t seed = 0)

Returns the hash value for v, using seed to seed the calculation.

[noexcept] bool operator!=(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b)

Returns false if the values in the two QRhiVertexInputAttribute objects a and b are equal; otherwise returns true.

[noexcept] bool operator==(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b)

Returns true if the values in the two QRhiVertexInputAttribute objects a and b are equal.