- Qt 6.9
- Qt GUI
- C++ Classes
- QtGuiPrivate
- QRhiShaderStage
- Qt 6.9.0 Reference Documentation

# QRhiShaderStage Class

Specifies the type and the shader code for a shader stage in the pipeline. 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

- List of all members, including inherited members

## Public Types

enum | Type { Vertex, TessellationControl, TessellationEvaluation, Fragment, Compute, Geometry }

## Public Functions

| QRhiShaderStage()
| QRhiShaderStage(QRhiShaderStage::Type type, const QShader &shader, QShader::Variant v = QShader::StandardShader)
void | setShader(const QShader &s)
void | setShaderVariant(QShader::Variant v)
void | setType(QRhiShaderStage::Type t)
QShader | shader() const
QShader::Variant | shaderVariant() const
QRhiShaderStage::Type | type() const

## Related Non-Members

size_t | qHash(const QRhiShaderStage &key, size_t seed = 0)
bool | operator!=(const QRhiShaderStage &a, const QRhiShaderStage &b)
bool | operator==(const QRhiShaderStage &a, const QRhiShaderStage &b)

## Detailed Description

When setting up a QRhiGraphicsPipeline, a collection of shader stages are specified. The QRhiShaderStage contains a QShader and some associated metadata, such as the graphics pipeline stage, and the shader variant to select. There is no need to specify the shader language or version because the QRhi backend in use at runtime will take care of choosing the appropriate shader version from the collection within the QShader.

The typical usage is in combination with QRhiGraphicsPipeline::setShaderStages(), shown here with a simple approach to load the QShader from `.qsb` files generated offline or at build time:

     QShader getShader(const QString &name)
     {
         QFile f(name);
         return f.open(QIODevice::ReadOnly) ? QShader::fromSerialized(f.readAll()) : QShader();
     }

     QShader vs = getShader("material.vert.qsb");
     QShader fs = getShader("material.frag.qsb");
     pipeline->setShaderStages({
         { QRhiShaderStage::Vertex, vs },
         { QRhiShaderStage::Fragment, fs }
     });

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

## Member Type Documentation

### enum QRhiShaderStage::Type

Specifies the type of the shader stage.

Constant | Value | Description
--- | --- | ---
`QRhiShaderStage::Vertex` | `0` | Vertex stage
`QRhiShaderStage::TessellationControl` | `1` | Tessellation control (hull shader) stage. Must be used only when the QRhi::Tessellation feature is supported.
`QRhiShaderStage::TessellationEvaluation` | `2` | Tessellation evaluation (domain shader) stage. Must be used only when the QRhi::Tessellation feature is supported.
`QRhiShaderStage::Fragment` | `4` | Fragment (pixel shader) stage
`QRhiShaderStage::Compute` | `5` | Compute stage. Must be used only when the QRhi::Compute feature is supported.
`QRhiShaderStage::Geometry` | `3` | Geometry stage. Must be used only when the QRhi::GeometryShader feature is supported.

## Member Function Documentation

### `[noexcept]` QRhiShaderStage::QRhiShaderStage()

Constructs a shader stage description for the vertex stage with an empty QShader.

### QRhiShaderStage::QRhiShaderStage(QRhiShaderStage::Type type, const QShader &shader, QShader::Variant v = QShader::StandardShader)

Constructs a shader stage description with the type of the stage and the shader.

The shader variant v defaults to QShader::StandardShader. A QShader contains multiple source and binary versions of a shader. In addition, it can also contain variants of the shader with slightly modified code. v can then be used to select the desired variant.

### void QRhiShaderStage::setShader(const QShader &s)

Sets the shader collection s.

See also shader().

### void QRhiShaderStage::setShaderVariant(QShader::Variant v)

Sets the requested shader variant v.

See also shaderVariant().

### void QRhiShaderStage::setType(QRhiShaderStage::Type t)

Sets the type of the stage to t. Setters should rarely be needed in pratice. Most applications will likely use the QRhiShaderStage constructor in most cases.

See also type().

### QShader QRhiShaderStage::shader() const

Returns the QShader to be used for this stage in the graphics pipeline.

See also setShader().

### QShader::Variant QRhiShaderStage::shaderVariant() const

Returns the requested shader variant.

See also setShaderVariant().

### QRhiShaderStage::Type QRhiShaderStage::type() const

Returns the type of the stage.

See also setType().

## Related Non-Members

### `[noexcept]` size_t qHash(const QRhiShaderStage &key, size_t seed = 0)

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

### `[noexcept]` bool operator!=(const QRhiShaderStage &a, const QRhiShaderStage &b)

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

### `[noexcept]` bool operator==(const QRhiShaderStage &a, const QRhiShaderStage &b)

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