Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QRhiShaderResourceBindings Class Referenceabstract

\inmodule QtGui 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
}
 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
 
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, const QRhiShaderResourceBindings &)
 

Detailed Description

\inmodule QtGui

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():

});
srb->create();
// ...
// ...
ps->create();
// ...
cb->setGraphicsPipeline(ps);
cb->setShaderResources(); // binds srb
\inmodule QtGui
Definition qrhi.h:1270
void setShaderResourceBindings(QRhiShaderResourceBindings *srb)
Associates with srb describing the resource binding layout and the resources (QRhiBuffer,...
Definition qrhi.h:1462
virtual bool create()=0
Creates the corresponding native graphics resources.
QRhi * rhi() const
Definition qrhi.cpp:3603
static QRhiShaderResourceBinding sampledTexture(int binding, StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler)
Definition qrhi.cpp:5640
static QRhiShaderResourceBinding uniformBuffer(int binding, StageFlags stage, QRhiBuffer *buf)
Definition qrhi.cpp:5526
\inmodule QtGui
Definition qrhi.h:1214
void setBindings(std::initializer_list< QRhiShaderResourceBinding > list)
Sets the list of bindings.
Definition qrhi.h:1218
virtual bool create()=0
QRhiShaderResourceBindings * newShaderResourceBindings()
Definition qrhi.cpp:10489
QRhiGraphicsPipeline * newGraphicsPipeline()
Definition qrhi.cpp:10466
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 1213 of file qrhi.h.

Member Enumeration Documentation

◆ UpdateFlag

Enumerator
BindingsAreSorted 

Definition at line 1236 of file qrhi.h.

Constructor & Destructor Documentation

◆ QRhiShaderResourceBindings()

QRhiShaderResourceBindings::QRhiShaderResourceBindings ( QRhiImplementation * rhi)
protected

Member Function Documentation

◆ bindingAt()

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

Definition at line 1227 of file qrhi.h.

◆ bindingCount()

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

Definition at line 1228 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 1225 of file qrhi.h.

Referenced by QRhiImplementation::sanityCheckShaderResourceBindings().

+ Here is the caller graph for this function:

◆ cendBindings()

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

Definition at line 1226 of file qrhi.h.

Referenced by QRhiImplementation::sanityCheckShaderResourceBindings().

+ Here is the caller graph for this function:

◆ create()

virtual bool QRhiShaderResourceBindings::create ( )
pure virtual

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

Referenced by QSSGRhiContextPrivate::srb().

+ Here is the caller graph for this function:

◆ 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 5348 of file qrhi.cpp.

References m_layoutDesc, m_layoutDescHash, and other().

+ Here is the call graph for this function:

◆ resourceType()

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

Implements QRhiResource.

Definition at line 5322 of file qrhi.cpp.

References QRhiResource::ShaderResourceBindings.

◆ 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 1232 of file qrhi.h.

Referenced by QSGBatchRenderer::GraphicsPipelineStateKey::create(), QSSGComputePipelineStateKey::create(), and QSSGGraphicsPipelineStateKey::create().

+ Here is the caller graph for this function:

◆ setBindings() [1/2]

template<typename InputIterator >
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 1220 of file qrhi.h.

◆ setBindings() [2/2]

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

Sets the list of bindings.

Definition at line 1218 of file qrhi.h.

References list.

Referenced by QSSGRenderReflectionMap::addReflectionMapEntry(), and QSSGRhiContextPrivate::srb().

+ Here is the caller graph for this function:

◆ updateResources()

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

Friends And Related Symbol Documentation

◆ operator<<

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

Definition at line 6357 of file qrhi.cpp.

◆ QRhiImplementation

friend class QRhiImplementation
friend

Definition at line 1252 of file qrhi.h.

Member Data Documentation

◆ BINDING_PREALLOC

constexpr int QRhiShaderResourceBindings::BINDING_PREALLOC = 12
staticconstexprprotected

Definition at line 1244 of file qrhi.h.

Referenced by QRhiShaderResourceBindings().

◆ m_bindings

◆ m_layoutDesc

QVector<quint32> QRhiShaderResourceBindings::m_layoutDesc
protected

◆ m_layoutDescHash

size_t QRhiShaderResourceBindings::m_layoutDescHash = 0
protected

Definition at line 1247 of file qrhi.h.

Referenced by isLayoutCompatible(), and QRhiImplementation::updateLayoutDesc().


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