Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QRhiShaderResourceBindings Class Referenceabstract

\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h More...

#include <qrhi.h>

Inheritance diagram for QRhiShaderResourceBindings:
Collaboration diagram for QRhiShaderResourceBindings:

Public Types

enum  UpdateFlag { BindingsAreSorted = 0x01 }
Public Types inherited from QRhiResource
enum  Type {
  Buffer , Texture , Sampler , RenderBuffer ,
  RenderPassDescriptor , SwapChainRenderTarget , TextureRenderTarget , ShaderResourceBindings ,
  GraphicsPipeline , SwapChain , ComputePipeline , CommandBuffer ,
  ShadingRateMap
}
 Specifies type of the resource. More...

Public Member Functions

QRhiResource::Type resourceType () const override
void setBindings (std::initializer_list< QRhiShaderResourceBinding > list)
 Sets the list of bindings.
template<typename InputIterator>
void setBindings (InputIterator first, InputIterator last)
 Sets the list of bindings from the iterators first and last.
const QRhiShaderResourceBindingcbeginBindings () const
const QRhiShaderResourceBindingcendBindings () const
const QRhiShaderResourceBindingbindingAt (qsizetype index) const
qsizetype bindingCount () const
bool isLayoutCompatible (const QRhiShaderResourceBindings *other) const
QVector< quint32serializedLayoutDescription () const
virtual bool create ()=0
 Creates the corresponding resource binding set.
virtual void updateResources (UpdateFlags flags={})=0
Public Member Functions inherited from QRhiResource
virtual ~QRhiResource ()
 Destructor.
virtual void destroy ()=0
 Releases (or requests deferred releasing of) the underlying native graphics resources.
void deleteLater ()
 When called without a frame being recorded, this function is equivalent to deleting the object.
QByteArray name () const
void setName (const QByteArray &name)
 Sets a name for the object.
quint64 globalResourceId () const
QRhirhi () const

Protected Member Functions

 QRhiShaderResourceBindings (QRhiImplementation *rhi)
Protected Member Functions inherited from QRhiResource
 QRhiResource (QRhiImplementation *rhi)

Protected Attributes

QVarLengthArray< QRhiShaderResourceBinding, BINDING_PREALLOCm_bindings
size_t m_layoutDescHash = 0
QVector< quint32m_layoutDesc
Protected Attributes inherited from QRhiResource
QRhiImplementationm_rhi = nullptr
quint64 m_id
QByteArray m_objectName

Static Protected Attributes

static constexpr int BINDING_PREALLOC = 12

Friends

class QRhiImplementation
Q_GUI_EXPORT QDebug operator<< (QDebug dbg, const QRhiShaderResourceBindings &srb)

Detailed Description

\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h

Since
6.6

Encapsulates resources for making buffer, texture, sampler resources visible to shaders.

A QRhiShaderResourceBindings is a collection of QRhiShaderResourceBinding objects, each of which describe a single binding.

Take a fragment shader with the following interface:

\badcode 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 QRhiShaderResourceBindings could be created and then passed to QRhiGraphicsPipeline::setShaderResourceBindings():

QRhiShaderResourceBindings *srb = rhi->newShaderResourceBindings();
});
srb->create();
// ...
// ...
ps->create();
// ...
cb->setGraphicsPipeline(ps);
cb->setShaderResources(); // binds srb
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1309
void setShaderResourceBindings(QRhiShaderResourceBindings *srb)
Associates with srb describing the resource binding layout and the resources (QRhiBuffer,...
Definition qrhi.h:1502
virtual bool create()=0
Creates the corresponding native graphics resources.
QRhi * rhi() const
Definition qrhi.cpp:3743
static QRhiShaderResourceBinding sampledTexture(int binding, StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler)
Definition qrhi.cpp:5977
static QRhiShaderResourceBinding uniformBuffer(int binding, StageFlags stage, QRhiBuffer *buf)
Definition qrhi.cpp:5863
QRhiShaderResourceBindings(QRhiImplementation *rhi)
Definition qrhi.cpp:5635
void setBindings(std::initializer_list< QRhiShaderResourceBinding > list)
Sets the list of bindings.
Definition qrhi.h:1257
virtual bool create()=0
Creates the corresponding resource binding set.
QRhiGraphicsPipeline * newGraphicsPipeline()
Definition qrhi.cpp:11200
GLuint sampler
GLenum GLuint texture
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)

This assumes that ubuf is a QRhiBuffer, texture is a QRhiTexture, while sampler is a QRhiSampler. 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.

Definition at line 1252 of file qrhi.h.

Member Enumeration Documentation

◆ UpdateFlag

Enumerator
BindingsAreSorted 

Definition at line 1275 of file qrhi.h.

Constructor & Destructor Documentation

◆ QRhiShaderResourceBindings()

QRhiShaderResourceBindings::QRhiShaderResourceBindings ( QRhiImplementation * rhi)
protected

Definition at line 5635 of file qrhi.cpp.

Member Function Documentation

◆ bindingAt()

const QRhiShaderResourceBinding * QRhiShaderResourceBindings::bindingAt ( qsizetype index) const
inline
Returns
the binding at the specified index.

Definition at line 1266 of file qrhi.h.

◆ bindingCount()

qsizetype QRhiShaderResourceBindings::bindingCount ( ) const
inline
Returns
the number of bindings.

Definition at line 1267 of file qrhi.h.

◆ cbeginBindings()

const QRhiShaderResourceBinding * QRhiShaderResourceBindings::cbeginBindings ( ) const
inline
Returns
a const iterator pointing to the first item in the binding list.

Definition at line 1264 of file qrhi.h.

◆ cendBindings()

const QRhiShaderResourceBinding * QRhiShaderResourceBindings::cendBindings ( ) const
inline
Returns
a const iterator pointing just after the last item in the binding list.

Definition at line 1265 of file qrhi.h.

◆ create()

virtual bool QRhiShaderResourceBindings::create ( )
pure virtual

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(), then destroy() is called implicitly first.

Returns
true when successful, false when failed. Regardless of the return value, calling destroy() is always safe.

Implemented in QD3D11ShaderResourceBindings, QGles2ShaderResourceBindings, QMetalShaderResourceBindings, QNullShaderResourceBindings, and QVkShaderResourceBindings.

◆ isLayoutCompatible()

bool QRhiShaderResourceBindings::isLayoutCompatible ( const QRhiShaderResourceBindings * other) const
Returns
true if the layout is compatible with other. 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 QRhiGraphicsPipeline created with this QRhiShaderResourceBindings, and the function returns true, other can then safely be passed to QRhiCommandBuffer::setShaderResources(), and so be used with the pipeline in place of this QRhiShaderResourceBindings.

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 calling QRhiShaderResourceBinding::isLayoutCompatible() on each pair. This becomes relevant especially when this function is called at a high frequency.
See also
serializedLayoutDescription()

Definition at line 5670 of file qrhi.cpp.

◆ resourceType()

QRhiResource::Type QRhiShaderResourceBindings::resourceType ( ) const
overridevirtual
Returns
the resource type.

Implements QRhiResource.

Definition at line 5644 of file qrhi.cpp.

◆ serializedLayoutDescription()

QVector< quint32 > QRhiShaderResourceBindings::serializedLayoutDescription ( ) const
inline
Returns
a vector of integers containing an opaque blob describing the layout of the binding list, i.e. the data relevant for \l{isLayoutCompatible()}{layout compatibility tests}.

Given two objects srb1 and srb2, if the data returned from this function is identical, then {srb1->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 QRhi the object belongs to. It is not meant for storing on disk, reusing between processes, or using with multiple QRhi instances with potentially different backends.
See also
isLayoutCompatible()

Definition at line 1271 of file qrhi.h.

◆ setBindings() [1/2]

template<typename InputIterator>
void QRhiShaderResourceBindings::setBindings ( InputIterator first,
InputIterator last )
inline

Sets the list of bindings from the iterators first and last.

Definition at line 1259 of file qrhi.h.

◆ setBindings() [2/2]

void QRhiShaderResourceBindings::setBindings ( std::initializer_list< QRhiShaderResourceBinding > list)
inline

Sets the list of bindings.

Definition at line 1257 of file qrhi.h.

◆ updateResources()

virtual void QRhiShaderResourceBindings::updateResources ( UpdateFlags flags = {})
pure virtual

◆ operator<<

Q_GUI_EXPORT QDebug operator<< ( QDebug dbg,
const QRhiShaderResourceBindings & srb )
friend

Definition at line 6678 of file qrhi.cpp.

◆ QRhiImplementation

friend class QRhiImplementation
friend

Definition at line 1291 of file qrhi.h.

Member Data Documentation

◆ BINDING_PREALLOC

int QRhiShaderResourceBindings::BINDING_PREALLOC = 12
staticconstexprprotected

Definition at line 1283 of file qrhi.h.

◆ m_bindings

QVarLengthArray<QRhiShaderResourceBinding, BINDING_PREALLOC> QRhiShaderResourceBindings::m_bindings
protected

Definition at line 1285 of file qrhi.h.

◆ m_layoutDesc

QVector<quint32> QRhiShaderResourceBindings::m_layoutDesc
protected

Definition at line 1290 of file qrhi.h.

◆ m_layoutDescHash

size_t QRhiShaderResourceBindings::m_layoutDescHash = 0
protected

Definition at line 1286 of file qrhi.h.


The documentation for this class was generated from the following files: