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

이 예에서는 ubufQRhiBuffer, textureQRhiTexture, samplerQRhiSampler 로 가정합니다. 또한 이 예에서는 버텍스 셰이더에도 균일 블록이 존재하므로 버텍스 스테이지에도 동일한 버퍼가 표시된다고 가정합니다.

고급 사용법

위의 예시를 바탕으로 이제 패스에 완전히 동일한 파이프라인과 텍스처가 다른 셰이더를 사용해야 한다고 가정해 보겠습니다. 이를 위해 별도의 QRhiGraphicsPipeline 을 생성하는 것은 지나치게 많은 작업이 될 수 있습니다. 그래서 QRhiCommandBuffer::setShaderResources()는 srb 인수를 지정할 수 있습니다. 레이아웃(즉, 바인딩 수와 바인딩 포인트)이 두 QRhiShaderResourceBinding 간에 일치하는 한, 애초에 파이프라인이 그 중 하나를 사용하여 생성되었다고 가정하면 둘 다 동일한 파이프라인에서 사용할 수 있습니다. 자세한 내용은 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 을 반환하는 경우 otherQRhiCommandBuffer::setShaderResources()로 안전하게 전달될 수 있으므로 QRhiShaderResourceBindings 대신 파이프라인과 함께 사용할 수 있습니다.

참고: 이 함수는 기본 데이터 구조의 베이킹 중에 생성된 데이터에 의존하므로 create() 함수가 성공적으로 수행된 후에만 호출해야 합니다. 이렇게 하면 이 함수는 두 개의 바인딩 목록을 반복하고 각 쌍에 대해 QRhiShaderResourceBinding::isLayoutCompatible()를 호출하는 것보다 더 효율적인 비교 접근 방식을 구현할 수 있습니다. 이는 특히 이 함수가 자주 호출되는 경우에 유용합니다.

serializedLayoutDescription()도 참조하세요 .

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

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

리소스 타입을 리턴합니다.

QVector<quint32> QRhiShaderResourceBindings::serializedLayoutDescription() const

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

두 개의 객체 srb1srb2 가 주어졌을 때 이 함수에서 반환된 데이터가 동일하면 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)

반복자 firstlast 에서 바인딩 목록을 설정합니다.

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