このページでは

QRhiShaderResourceBindings Class

バッファ、テクスチャ、サンプラーリソースをシェーダーから利用できるようにするためのリソースをカプセル化します。詳細...

ヘッダー: #include <rhi/qrhi.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS GuiPrivate)
target_link_libraries(mytarget PRIVATE Qt6::GuiPrivate)
qmake: QT += gui-private
以下のように: Qt 6.6
継承元: QRhiResource

パブリック関数

const QRhiShaderResourceBinding *bindingAt(qsizetype index) const
qsizetype bindingCount() const
const QRhiShaderResourceBinding *cbeginBindings() const
const QRhiShaderResourceBinding *cendBindings() const
virtual bool create() = 0
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 オブジェクトの集合であり、各オブジェクトは 1 つのバインディングを表します。

次のようなインターフェースを持つフラグメントシェーダーを例に挙げます。

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 イテレータを返します。

const QRhiShaderResourceBinding *QRhiShaderResourceBindings::cendBindings() const

バインディングリストの最後の要素の直後を指す const イテレータを返します。

[pure virtual] bool QRhiShaderResourceBindings::create()

対応するリソースバインディングセットを作成します。基盤となるグラフィックスAPIによっては、ネイティブのグラフィックスリソースの作成を伴う場合があるため、この操作が低コストであると想定すべきではありません。

以前に create() が呼び出されており、対応する `destroy()` が実行されていない場合、まず暗黙的に `destroy()` が呼び出されます。

成功した場合はtrue を、失敗した場合はfalse を返します。戻り値にかかわらず、destroy()の呼び出しは常に安全です。

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` からのバインディングのリストを設定します。

© 2026 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.