QRhiShaderResourceBindings Class
バッファ、テクスチャ、サンプラーリソースをシェーダーから見えるようにするためのリソースをカプセル化します。詳細...
ヘッダー | #include <rhi/qrhi.h> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::GuiPrivate) |
qmake: | QT += gui-private |
以来: | Qt 6.6 |
継承: | QRhiResource |
パブリックな型
flags | UpdateFlags |
パブリック関数
const QRhiShaderResourceBinding * | bindingAt(qsizetype index) const |
qsizetype | bindingCount() const |
const QRhiShaderResourceBinding * | cbeginBindings() const |
const QRhiShaderResourceBinding * | cendBindings() const |
bool | isLayoutCompatible(const QRhiShaderResourceBindings *other) const |
QVector<quint32> | serializedLayoutDescription() const |
void | setBindings(std::initializer_list<QRhiShaderResourceBinding> list) |
void | setBindings(InputIterator first, InputIterator last) |
再実装されたパブリック関数
virtual QRhiResource::Type | resourceType() const override |
詳細説明
QRhiShaderResourceBindings は、QRhiShaderResourceBinding オブジェクトのコレクションで、各オブジェクトは単一のバインディングを記述します。
次のインターフェイスを持つフラグメントシェーダを例にとります:
layout(std140, binding = 0) uniform buf { mat4 mvp; int flip; } ubuf; layout(binding = 1) uniform sampler2D tex;
シェーダにリソースを見えるようにするには、次のQRhiShaderResourceBindingsを作成し、QRhiGraphicsPipeline::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
これは、ubuf
がQRhiBuffer であり、texture
がQRhiTexture であり、sampler がQRhiSampler であると仮定しています。また、この例では、頂点シェーダにもユニフォームブロックが存在すると仮定しているので、同じバッファが頂点ステージからも見えるようになります。
高度な使用法
上記の例に基づいて、まったく同じパイプラインとシェーダを別のテクスチャで使 用するパスが必要になったとしましょう。このためだけにまったく別のQRhiGraphicsPipeline を作成するのはやりすぎでしょう。このため、QRhiCommandBuffer::setShaderResources ()では、srb 引数を指定できます。2つのQRhiShaderResourceBindings間でレイアウト(バインディングの数とバインディングポイント)が一致する限り、パイプラインが最初にどちらかで作成されたと仮定して、どちらも同じパイプラインで使用できます。詳細はisLayoutCompatible() を参照してください。
QRhiShaderResourceBindings *srb2 = rhi->newShaderResourceBindings(); // ... cb->setGraphicsPipeline(ps); cb->setShaderResources(srb2); // binds srb2
注意: これは互換性が限定的に保証された RHI API です。詳細はQRhi を参照してください。
メンバー関数ドキュメント
const QRhiShaderResourceBinding *QRhiShaderResourceBindings::bindingAt(qsizetype index) const
指定 さ れたindex でのバ イ ンデ ィ ン グ を返 し ます。
qsizetype QRhiShaderResourceBindings::bindingCount() const
バインディングの数を返します。
const QRhiShaderResourceBinding *QRhiShaderResourceBindings::cbeginBindings() const
バインディングリストの最初の項目を指すイテレータを返します。
const QRhiShaderResourceBinding *QRhiShaderResourceBindings::cendBindings() const
バインディングリストの最後の項目の直後を指すイテレータを返します。
bool QRhiShaderResourceBindings::isLayoutCompatible(const QRhiShaderResourceBindings *other) const
レイアウトがother と互換性がある場合、true
を返します。レイアウトには、実際のリソース(バッファやテクスチャなど)や関連するパラメータ(オフセットやサイズなど)は含まれません。ただし、バインディングポイント、パイプラインステージ、リソースタイプは含まれます。互換性を保つためには、バインディングの数と順序も一致しなければなりません。
このQRhiShaderResourceBindings で作成されたQRhiGraphicsPipeline があり、この関数がtrue
を返す場合、other をQRhiCommandBuffer::setShaderResources() に安全に渡すことができるため、このQRhiShaderResourceBindings の代わりにパイプラインで使用することができます。
注: この関数は、create()が成功した後にのみ呼び出されなければならない。なぜなら、この関数は、基礎となるデータ構造の構築中に生成されたデータに依存しているからである。こうすることで、この関数は、2つのバインディング・リストを繰り返し処理し、各ペアでQRhiShaderResourceBinding::isLayoutCompatible() を呼び出すよりも効率的な比較アプローチを実装することができます。このことは、特にこの関数が高い頻度で呼び出される場合に重要になります。
serializedLayoutDescription()も参照 。
[override virtual]
QRhiResource::Type QRhiShaderResourceBindings::resourceType() const
再実装:QRhiResource::resourceType() const.
リソース型を返します。
QVector<quint32> QRhiShaderResourceBindings::serializedLayoutDescription() const
バインディングリストのレイアウトを記述する不透明なブロブ、つまりlayout compatibility tests に関連するデータを含む整数のベクトルを返します。
2つのオブジェクトsrb1
とsrb2
が与えられたとき、この関数から返されるデータが同じであれば、srb1->isLayoutCompatible(srb2)
、その逆も同様です。
注: 返されたデータは、そのオブジェクトが属するQRhi の存続期間中、メモリへの保存や比較に使用されることを意図しています。ディスクに保存したり、プロセス間で再利用したり、異なるバックエンドを持つ可能性のある複数のQRhi インスタンスで使用したりするためのものではありません。
isLayoutCompatible()も参照してください 。
void QRhiShaderResourceBindings::setBindings(std::initializer_list<QRhiShaderResourceBinding> list)
バ イ ンデ ィ ン グのlist を設定。
template <typename InputIterator> void QRhiShaderResourceBindings::setBindings(InputIterator first, InputIterator last)
イ テ レー タfirst とlast のバ イ ンデ ィ ン グの リ ス ト を設定 し ます。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.