PySide6.QtGui.QRhiShaderResourceBindings¶
- class QRhiShaderResourceBindings¶
Encapsulates resources for making buffer, texture, sampler resources visible to shaders. More…
Added in version 6.6.
Synopsis¶
Methods¶
def
bindingAt()def
bindingCount()def
cbeginBindings()def
cendBindings()def
setBindings()
Virtual methods¶
def
create()
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
QRhiShaderResourceBindingsis a collection ofQRhiShaderResourceBindingobjects, 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
QRhiShaderResourceBindingscould be created and then passed tosetShaderResourceBindings():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
ubufis aQRhiBuffer,textureis aQRhiTexture, whilesampleris aQRhiSampler. 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
QRhiGraphicsPipelinejust for this would be an overkill. This is whysetShaderResources()allows specifying asrbargument. As long as the layouts (so the number of bindings and the binding points) match between twoQRhiShaderResourceBindings, they can both be used with the same pipeline, assuming the pipeline was created with one of them in the first place. SeeisLayoutCompatible()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
QRhifor details.- class UpdateFlag¶
- PySide6.QtGui.QRhiShaderResourceBindings.m_layoutDescHash¶
- PySide6.QtGui.QRhiShaderResourceBindings.m_layoutDesc¶
- bindingAt(index)¶
- Parameters:
index – int
- Return type:
Returns the binding at the specified
index.- bindingCount()¶
- Return type:
int
Returns the number of bindings.
- cbeginBindings()¶
- Return type:
Returns a const iterator pointing to the first item in the binding list.
- cendBindings()¶
- Return type:
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(), thendestroy()is called implicitly first.Returns
truewhen successful,falsewhen failed. Regardless of the return value, callingdestroy()is always safe.- isLayoutCompatible(other)¶
- Parameters:
other –
QRhiShaderResourceBindings- Return type:
bool
Returns
trueif the layout is compatible withother. 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
QRhiGraphicsPipelinecreated with thisQRhiShaderResourceBindings, and the function returnstrue,othercan then safely be passed tosetShaderResources(), and so be used with the pipeline in place of thisQRhiShaderResourceBindings.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 callingisLayoutCompatible()on each pair. This becomes relevant especially when this function is called at a high frequency.See also
- 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
srb1andsrb2, if the data returned from this function is identical, thensrb1->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
QRhithe object belongs to. It is not meant for storing on disk, reusing between processes, or using with multipleQRhiinstances with potentially different backends.See also
- setBindings(bindings)¶
- Parameters:
bindings – .list of QRhiShaderResourceBinding
- abstract updateResources([flags={}])¶
- Parameters:
flags – Combination of
UpdateFlag