이 페이지에서

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 객체들의 모음이며, 각 객체는 하나의 바인딩을 설명합니다.

다음과 같은 인터페이스를 가진 프래그먼트 셰이더를 예로 들어 보겠습니다.

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 인수를 지정할 수 있도록 합니다. 두 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()이 성공적으로 수행된 후에만 호출되어야 합니다. 이는 기본 데이터 구조의 베이킹 과정에서 생성된 데이터에 의존하기 때문입니다. 이를 통해 이 함수는 두 바인딩 리스트를 순회하며 각 쌍에 대해 QRhiShaderResourceBinding::isLayoutCompatible()를 호출하는 방식보다 더 효율적인 비교 방식을 구현할 수 있습니다. 이는 특히 이 함수가 높은 빈도로 호출될 때 중요해집니다.

serializedLayoutDescription()도 참조하십시오 .

[override virtual] QRhiResource::Type QRhiShaderResourceBindings::resourceType() const

QRhiResource::resourceType() const를 재구현합니다.

리소스 유형을 반환합니다.

QVector<quint32> QRhiShaderResourceBindings::serializedLayoutDescription() const

바인딩 리스트의 레이아웃, 즉 ` layout compatibility tests`와 관련된 데이터를 설명하는 불투명한 블롭을 포함하는 정수 벡터를 반환합니다.

두 객체 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.