PySide6.QtGui.QRhiShaderResourceBindings

class QRhiShaderResourceBindings

Encapsulates resources for making buffer, texture, sampler resources visible to shaders. More

Inheritance diagram of PySide6.QtGui.QRhiShaderResourceBindings

Added in version 6.6.

Synopsis

Methods

Virtual methods

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description

A QRhiShaderResourceBindings is a collection of QRhiShaderResourceBinding objects, each of which describe a single binding.

Take a fragment shader with the following interface:

layout(std140, binding = 0) uniform buf {
    mat4 mvp;
    int flip;
} ubuf;

layout(binding = 1) uniform sampler2D tex;

To make resources visible to the shader, the following QRhiShaderResourceBindings could be created and then passed to setShaderResourceBindings() :

QRhiShaderResourceBindings *srb = rhi->newShaderResourceBindings();
srb->setBindings({
    QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, ubuf),
    QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, texture, sampler)
});
srb->create();
// ...
QRhiGraphicsPipeline *ps = rhi->newGraphicsPipeline();
// ...
ps->setShaderResourceBindings(srb);
ps->create();
// ...
cb->setGraphicsPipeline(ps);
cb->setShaderResources(); // binds srb

This assumes that ubuf is a QRhiBuffer , texture is a QRhiTexture , while sampler is a QRhiSampler . The example also assumes that the uniform block is present in the vertex shader as well so the same buffer is made visible to the vertex stage too.

Advanced usage

Building on the above example, let’s assume that a pass now needs to use the exact same pipeline and shaders with a different texture. Creating a whole separate QRhiGraphicsPipeline just for this would be an overkill. This is why setShaderResources() allows specifying a srb argument. As long as the layouts (so the number of bindings and the binding points) match between two QRhiShaderResourceBindings , they can both be used with the same pipeline, assuming the pipeline was created with one of them in the first place. See isLayoutCompatible() for more details.

QRhiShaderResourceBindings *srb2 = rhi->newShaderResourceBindings();
// ...
cb->setGraphicsPipeline(ps);
cb->setShaderResources(srb2); // binds srb2

Note

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

class UpdateFlag
PySide6.QtGui.QRhiShaderResourceBindings.m_layoutDescHash
PySide6.QtGui.QRhiShaderResourceBindings.m_layoutDesc
bindingAt(index)
Parameters:

index – int

Return type:

QRhiShaderResourceBinding

Returns the binding at the specified index.

bindingCount()
Return type:

int

Returns the number of bindings.

cbeginBindings()
Return type:

QRhiShaderResourceBinding

Returns a const iterator pointing to the first item in the binding list.

cendBindings()
Return type:

QRhiShaderResourceBinding

Returns a const iterator pointing just after the last item in the binding list.

abstract create()
Return type:

bool

Creates the corresponding resource binding set. Depending on the underlying graphics API, this may involve creating native graphics resources, and therefore it should not be assumed that this is a cheap operation.

If create() has been called before with no corresponding destroy() , then destroy() is called implicitly first.

Returns true when successful, false when failed. Regardless of the return value, calling destroy() is always safe.

isLayoutCompatible(other)
Parameters:

otherQRhiShaderResourceBindings

Return type:

bool

Returns true if the layout is compatible with other. The layout does not include the actual resource (such as, buffer or texture) and related parameters (such as, offset or size). It does include the binding point, pipeline stage, and resource type, however. The number and order of the bindings must also match in order to be compatible.

When there is a QRhiGraphicsPipeline created with this QRhiShaderResourceBindings , and the function returns true, other can then safely be passed to setShaderResources() , and so be used with the pipeline in place of this QRhiShaderResourceBindings .

Note

This function must only be called after a successful create() , because it relies on data generated during the baking of the underlying data structures. This way the function can implement a comparison approach that is more efficient than iterating through two binding lists and calling isLayoutCompatible() on each pair. This becomes relevant especially when this function is called at a high frequency.

serializedLayoutDescription()
Return type:

.list of quint32

Returns a vector of integers containing an opaque blob describing the layout of the binding list, i.e. the data relevant for layout compatibility tests .

Given two objects srb1 and srb2, if the data returned from this function is identical, then srb1->isLayoutCompatible(srb2), and vice versa hold true as well.

Note

The returned data is meant to be used for storing in memory and comparisons during the lifetime of the QRhi the object belongs to. It is not meant for storing on disk, reusing between processes, or using with multiple QRhi instances with potentially different backends.

setBindings(bindings)
Parameters:

bindings – .list of QRhiShaderResourceBinding

abstract updateResources([flags={}])
Parameters:

flags – Combination of UpdateFlag