![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtGui More...
#include <qrhi.h>
Public Types | |
enum | IndexFormat { IndexUInt16 , IndexUInt32 } |
Specifies the index data type. More... | |
enum | BeginPassFlag { ExternalContent = 0x01 , DoNotTrackResourcesForCompute = 0x02 } |
Flag values for QRhi::beginPass() More... | |
using | DynamicOffset = QPair< int, quint32 > |
Synonym for QPair<int, quint32>. | |
using | VertexInput = QPair< QRhiBuffer *, quint32 > |
Synonym for QPair<QRhiBuffer *, quint32>. | |
![]() | |
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 | resourceUpdate (QRhiResourceUpdateBatch *resourceUpdates) |
Sometimes committing resource updates is necessary or just more convenient without starting a render pass. | |
void | beginPass (QRhiRenderTarget *rt, const QColor &colorClearValue, const QRhiDepthStencilClearValue &depthStencilClearValue, QRhiResourceUpdateBatch *resourceUpdates=nullptr, BeginPassFlags flags={}) |
Records starting a new render pass targeting the render target rt. | |
void | endPass (QRhiResourceUpdateBatch *resourceUpdates=nullptr) |
Records ending the current render pass. | |
void | setGraphicsPipeline (QRhiGraphicsPipeline *ps) |
Records setting a new graphics pipeline ps. | |
void | setShaderResources (QRhiShaderResourceBindings *srb=nullptr, int dynamicOffsetCount=0, const DynamicOffset *dynamicOffsets=nullptr) |
Records binding a set of shader resources, such as, uniform buffers or textures, that are made visible to one or more shader stages. | |
void | setVertexInput (int startBinding, int bindingCount, const VertexInput *bindings, QRhiBuffer *indexBuf=nullptr, quint32 indexOffset=0, IndexFormat indexFormat=IndexUInt16) |
Records vertex input bindings. | |
void | setViewport (const QRhiViewport &viewport) |
Records setting the active viewport rectangle specified in viewport. | |
void | setScissor (const QRhiScissor &scissor) |
Records setting the active scissor rectangle specified in scissor. | |
void | setBlendConstants (const QColor &c) |
Records setting the active blend constants to c. | |
void | setStencilRef (quint32 refValue) |
Records setting the active stencil reference value to refValue. | |
void | draw (quint32 vertexCount, quint32 instanceCount=1, quint32 firstVertex=0, quint32 firstInstance=0) |
Records a non-indexed draw. | |
void | drawIndexed (quint32 indexCount, quint32 instanceCount=1, quint32 firstIndex=0, qint32 vertexOffset=0, quint32 firstInstance=0) |
Records an indexed draw. | |
void | debugMarkBegin (const QByteArray &name) |
Records a named debug group on the command buffer with the specified name. | |
void | debugMarkEnd () |
Records the end of a debug group. | |
void | debugMarkMsg (const QByteArray &msg) |
Inserts a debug message msg into the command stream. | |
void | beginComputePass (QRhiResourceUpdateBatch *resourceUpdates=nullptr, BeginPassFlags flags={}) |
Records starting a new compute pass. | |
void | endComputePass (QRhiResourceUpdateBatch *resourceUpdates=nullptr) |
Records ending the current compute pass. | |
void | setComputePipeline (QRhiComputePipeline *ps) |
Records setting a new compute pipeline ps. | |
void | dispatch (int x, int y, int z) |
Records dispatching compute work items, with x, y, and z specifying the number of local workgroups in the corresponding dimension. | |
const QRhiNativeHandles * | nativeHandles () |
void | beginExternal () |
To be called when the application before the application is about to enqueue commands to the current pass' command buffer by calling graphics API functions directly. | |
void | endExternal () |
To be called once the externally added commands are recorded to the command buffer or context. | |
double | lastCompletedGpuTime () |
![]() | |
virtual | ~QRhiResource () |
Destructor. | |
virtual Type | resourceType () const =0 |
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 |
QRhi * | rhi () const |
Protected Member Functions | |
QRhiCommandBuffer (QRhiImplementation *rhi) | |
![]() | |
QRhiResource (QRhiImplementation *rhi) | |
Additional Inherited Members | |
![]() | |
QRhiImplementation * | m_rhi = nullptr |
quint64 | m_id |
QByteArray | m_objectName |
\inmodule QtGui
Command buffer resource.
Not creatable by applications at the moment. The only ways to obtain a valid QRhiCommandBuffer are to get it from the targeted swapchain via QRhiSwapChain::currentFrameCommandBuffer(), or, in case of rendering completely offscreen, initializing one via QRhi::beginOffscreenFrame().
Flag values for QRhi::beginPass()
\value ExternalContent Specifies that there will be a call to QRhiCommandBuffer::beginExternal() in this pass. Some backends, Vulkan in particular, will fail if this flag is not set and beginExternal() is still called.
\value DoNotTrackResourcesForCompute Specifies that there is no need to track resources used in this pass if the only purpose of such tracking is to generate barriers for compute. Implies that there are no compute passes in the frame. This is an optimization hint that may be taken into account by certain backends, OpenGL in particular, allowing them to skip certain operations. When this flag is set for a render pass in a frame, calling \l{QRhiCommandBuffer::beginComputePass()}{beginComputePass()} in that frame may lead to unexpected behavior, depending on the resource dependencies between the render and compute passes.
Enumerator | |
---|---|
ExternalContent | |
DoNotTrackResourcesForCompute |
|
protected |
void QRhiCommandBuffer::beginComputePass | ( | QRhiResourceUpdateBatch * | resourceUpdates = nullptr , |
BeginPassFlags | flags = {} |
||
) |
Records starting a new compute pass.
resourceUpdates, when not null, specifies a resource update batch that is to be committed and then released.
flags is not currently used.
Definition at line 9400 of file qrhi.cpp.
References QRhiImplementation::beginComputePass(), and QRhiResource::m_rhi.
void QRhiCommandBuffer::beginExternal | ( | ) |
To be called when the application before the application is about to enqueue commands to the current pass' command buffer by calling graphics API functions directly.
With Vulkan, Metal, or Direct3D 12 one can query the native command buffer or encoder objects via nativeHandles() and enqueue commands to them. With OpenGL or Direct3D 11 the (device) context can be retrieved from QRhi::nativeHandles(). However, this must never be done without ensuring the QRhiCommandBuffer's state stays up-to-date. Hence the requirement for wrapping any externally added command recording between beginExternal() and endExternal(). Conceptually this is the same as QPainter's \l{QPainter::beginNativePainting()}{beginNativePainting()} and \l{QPainter::endNativePainting()}{endNativePainting()} functions.
For OpenGL in particular, this function has an additional task: it makes sure the context is made current on the current thread.
set*
or draw*
) must be called on the QRhiCommandBuffer until endExternal().Definition at line 9511 of file qrhi.cpp.
References QRhiImplementation::beginExternal(), and QRhiResource::m_rhi.
void QRhiCommandBuffer::beginPass | ( | QRhiRenderTarget * | rt, |
const QColor & | colorClearValue, | ||
const QRhiDepthStencilClearValue & | depthStencilClearValue, | ||
QRhiResourceUpdateBatch * | resourceUpdates = nullptr , |
||
BeginPassFlags | flags = {} |
||
) |
Records starting a new render pass targeting the render target rt.
resourceUpdates, when not null, specifies a resource update batch that is to be committed and then released.
The color and depth/stencil buffers of the render target are normally cleared. The clear values are specified in colorClearValue and depthStencilClearValue. The exception is when the render target was created with QRhiTextureRenderTarget::PreserveColorContents and/or QRhiTextureRenderTarget::PreserveDepthStencilContents. The clear values are ignored then.
set
and draw
functions can only be called inside a pass. Also, with the exception of setGraphicsPipeline(), they expect to have a pipeline set already on the command buffer. Unspecified issues may arise otherwise, depending on the backend.If rt is a QRhiTextureRenderTarget, beginPass() performs a check to see if the texture and renderbuffer objects referenced from the render target are up-to-date. This is similar to what setShaderResources() does for QRhiShaderResourceBindings. If any of the attachments had been rebuilt since QRhiTextureRenderTarget::create(), an implicit call to create() is made on rt. Therefore, if rt has a QRhiTexture color attachment texture
, and one needs to make the texture a different size, the following is then valid:
flags allow controlling certain advanced functionality. One commonly used flag is ExternalContents
. This should be specified whenever beginExternal() will be called within the pass started by this function.
Definition at line 9045 of file qrhi.cpp.
References QRhiImplementation::beginPass(), and QRhiResource::m_rhi.
Referenced by QSGBatchRenderer::Renderer::beginRenderPass().
void QRhiCommandBuffer::debugMarkBegin | ( | const QByteArray & | name | ) |
Records a named debug group on the command buffer with the specified name.
This is shown in graphics debugging tools such as \l{https://renderdoc.org/}{RenderDoc} and \l{https://developer.apple.com/xcode/}{XCode}. The end of the grouping is indicated by debugMarkEnd().
Definition at line 9348 of file qrhi.cpp.
References QRhiImplementation::debugMarkBegin(), and QRhiResource::m_rhi.
void QRhiCommandBuffer::debugMarkEnd | ( | ) |
Records the end of a debug group.
Definition at line 9361 of file qrhi.cpp.
References QRhiImplementation::debugMarkEnd(), and QRhiResource::m_rhi.
void QRhiCommandBuffer::debugMarkMsg | ( | const QByteArray & | msg | ) |
Inserts a debug message msg into the command stream.
Definition at line 9376 of file qrhi.cpp.
References QRhiImplementation::debugMarkMsg(), and QRhiResource::m_rhi.
void QRhiCommandBuffer::dispatch | ( | int | x, |
int | y, | ||
int | z | ||
) |
Records dispatching compute work items, with x, y, and z specifying the number of local workgroups in the corresponding dimension.
{layout(local_size_x = 16, local_size_y = 16) in;}. For example, with OpenGL the minimum value mandated by the specification for the number of invocations in a single local work group (the product of local_size_x
, local_size_y
, and local_size_z
) is 1024, while with OpenGL ES (3.1) the value may be as low as 128. This means that the example given above may be rejected by some OpenGL ES implementations as the number of invocations is 256. Definition at line 9453 of file qrhi.cpp.
References QRhiImplementation::dispatch(), and QRhiResource::m_rhi.
void QRhiCommandBuffer::draw | ( | quint32 | vertexCount, |
quint32 | instanceCount = 1 , |
||
quint32 | firstVertex = 0 , |
||
quint32 | firstInstance = 0 |
||
) |
Records a non-indexed draw.
The number of vertices is specified in vertexCount. For instanced drawing set instanceCount to a value other than 1. firstVertex is the index of the first vertex to draw. When drawing multiple instances, the first instance ID is specified by firstInstance.
Definition at line 9290 of file qrhi.cpp.
References QRhiImplementation::draw(), instanceCount, and QRhiResource::m_rhi.
void QRhiCommandBuffer::drawIndexed | ( | quint32 | indexCount, |
quint32 | instanceCount = 1 , |
||
quint32 | firstIndex = 0 , |
||
qint32 | vertexOffset = 0 , |
||
quint32 | firstInstance = 0 |
||
) |
Records an indexed draw.
The number of vertices is specified in indexCount. firstIndex is the base index. The effective offset in the index buffer is given by {indexOffset + firstIndex * n} where
n
is 2 or 4 depending on the index element type. indexOffset
is specified in setVertexInput().
For instanced drawing set instanceCount to a value other than 1. When drawing multiple instances, the first instance ID is specified by firstInstance.
vertexOffset (also called {base vertex}) is a signed value that is added to the element index before indexing into the vertex buffer. Support for this is not always available, and the value is ignored when the feature QRhi::BaseVertex is reported as unsupported.
Definition at line 9327 of file qrhi.cpp.
References QRhiImplementation::drawIndexed(), instanceCount, and QRhiResource::m_rhi.
void QRhiCommandBuffer::endComputePass | ( | QRhiResourceUpdateBatch * | resourceUpdates = nullptr | ) |
Records ending the current compute pass.
resourceUpdates, when not null, specifies a resource update batch that is to be committed and then released.
Definition at line 9411 of file qrhi.cpp.
References QRhiImplementation::endComputePass(), and QRhiResource::m_rhi.
void QRhiCommandBuffer::endExternal | ( | ) |
To be called once the externally added commands are recorded to the command buffer or context.
Definition at line 9526 of file qrhi.cpp.
References QRhiImplementation::endExternal(), and QRhiResource::m_rhi.
void QRhiCommandBuffer::endPass | ( | QRhiResourceUpdateBatch * | resourceUpdates = nullptr | ) |
Records ending the current render pass.
resourceUpdates, when not null, specifies a resource update batch that is to be committed and then released.
Definition at line 9062 of file qrhi.cpp.
References QRhiImplementation::endPass(), and QRhiResource::m_rhi.
Referenced by QSGBatchRenderer::Renderer::endRenderPass().
double QRhiCommandBuffer::lastCompletedGpuTime | ( | ) |
Care must be exercised with the interpretation of the value, as its precision and granularity is often not controlled by Qt, and depends on the underlying graphics API and its implementation. In particular, comparing the values between different graphics APIs and hardware is discouraged and may be meaningless.
The timing values may become available asynchronously. The returned value may therefore be 0 or the last known value referring to some previous frame. The value my also become 0 again under certain conditions, such as when resizing the window. It can be expected that the most up-to-date available value is retrieved in beginFrame() and becomes queriable via this function once beginFrame() returns.
{currently_recorded - 1}) frame. It may refer to
{currently_recorded - 2} or
{currently_recorded - 3} as well. The exact behavior may depend on the graphics API and its implementation.Definition at line 9561 of file qrhi.cpp.
References QRhiImplementation::lastCompletedGpuTime(), and QRhiResource::m_rhi.
Referenced by QSGGuiThreadRenderLoop::renderWindow(), and QSGRenderThread::syncAndRender().
const QRhiNativeHandles * QRhiCommandBuffer::nativeHandles | ( | ) |
Definition at line 9467 of file qrhi.cpp.
References QRhiResource::m_rhi, and QRhiImplementation::nativeHandles().
|
overridevirtual |
Implements QRhiResource.
Definition at line 7660 of file qrhi.cpp.
References QRhiResource::CommandBuffer.
void QRhiCommandBuffer::resourceUpdate | ( | QRhiResourceUpdateBatch * | resourceUpdates | ) |
Sometimes committing resource updates is necessary or just more convenient without starting a render pass.
Calling this function with resourceUpdates is an alternative to passing resourceUpdates to a beginPass() call (or endPass(), which would be typical in case of readbacks).
Definition at line 8986 of file qrhi.cpp.
References QRhiResource::m_rhi, and QRhiImplementation::resourceUpdate().
Referenced by addOpaqueDepthPrePassBindings(), QSSGRhiCubeRenderer::prepareCube(), QSSGSubsetRenderable::prepareInstancing(), QSSGParticleRenderer::prepareParticlesForModel(), QSSGRhiQuadRenderer::prepareQuad(), QSGBatchRenderer::Renderer::prepareRenderPass(), QSGRhiAtlasTexture::Texture::removedFromAtlas(), QSSGCustomMaterialSystem::rhiPrepareRenderable(), QSSGParticleRenderer::rhiPrepareRenderable(), and rhiPrepareResourcesForShadowMap().
Records setting the active blend constants to c.
This can only be called when the bound pipeline has QRhiGraphicsPipeline::UsesBlendConstants set.
Definition at line 9256 of file qrhi.cpp.
References QRhiResource::m_rhi, and QRhiImplementation::setBlendConstants().
void QRhiCommandBuffer::setComputePipeline | ( | QRhiComputePipeline * | ps | ) |
Records setting a new compute pipeline ps.
Definition at line 9429 of file qrhi.cpp.
References QRhiResource::m_rhi, and QRhiImplementation::setComputePipeline().
void QRhiCommandBuffer::setGraphicsPipeline | ( | QRhiGraphicsPipeline * | ps | ) |
Records setting a new graphics pipeline ps.
set
or draw
commands on the command buffer.Definition at line 9082 of file qrhi.cpp.
References QRhiResource::m_rhi, Q_ASSERT, and QRhiImplementation::setGraphicsPipeline().
void QRhiCommandBuffer::setScissor | ( | const QRhiScissor & | scissor | ) |
Records setting the active scissor rectangle specified in scissor.
This can only be called when the bound pipeline has \l{QRhiGraphicsPipeline::UsesScissor}{UsesScissor} set. When the flag is set on the active pipeline, this function must be called because scissor testing will get enabled and so a scissor rectangle must be provided.
Definition at line 9242 of file qrhi.cpp.
References QRhiResource::m_rhi, and QRhiImplementation::setScissor().
void QRhiCommandBuffer::setShaderResources | ( | QRhiShaderResourceBindings * | srb = nullptr , |
int | dynamicOffsetCount = 0 , |
||
const DynamicOffset * | dynamicOffsets = nullptr |
||
) |
Records binding a set of shader resources, such as, uniform buffers or textures, that are made visible to one or more shader stages.
srb can be null in which case the current graphics or compute pipeline's associated QRhiShaderResourceBindings is used. When srb is non-null, it must be \l{QRhiShaderResourceBindings::isLayoutCompatible()}{layout-compatible}, meaning the layout (number of bindings, the type and binding number of each binding) must fully match the QRhiShaderResourceBindings that was associated with the pipeline at the time of calling the pipeline's create().
There are cases when a seemingly unnecessary setShaderResources() call is mandatory: when rebuilding a resource referenced from srb, for example changing the size of a QRhiBuffer followed by a QRhiBuffer::create(), this is the place where associated native objects (such as descriptor sets in case of Vulkan) are updated to refer to the current native resources that back the QRhiBuffer, QRhiTexture, QRhiSampler objects referenced from srb. In this case setShaderResources() must be called even if srb is the same as in the last call.
When srb is not null, the QRhiShaderResourceBindings object the pipeline was built with in create() is guaranteed to be not accessed in any form. In fact, it does not need to be valid even at this point: destroying the pipeline's associated srb after create() and instead explicitly specifying another, \l{QRhiShaderResourceBindings::isLayoutCompatible()}{layout compatible} one in every setShaderResources() call is valid.
dynamicOffsets allows specifying buffer offsets for uniform buffers that were associated with srb via QRhiShaderResourceBinding::uniformBufferWithDynamicOffset(). This is different from providing the offset in the srb itself: dynamic offsets do not require building a new QRhiShaderResourceBindings for every different offset, can avoid writing the underlying descriptors (with backends where applicable), and so they may be more efficient. Each element of dynamicOffsets is a binding
- offset
pair. dynamicOffsetCount specifies the number of elements in dynamicOffsets.
Definition at line 9140 of file qrhi.cpp.
References QRhiResource::m_rhi, and QRhiImplementation::setShaderResources().
Records setting the active stencil reference value to refValue.
This can only be called when the bound pipeline has QRhiGraphicsPipeline::UsesStencilRef set.
Definition at line 9270 of file qrhi.cpp.
References QRhiResource::m_rhi, and QRhiImplementation::setStencilRef().
void QRhiCommandBuffer::setVertexInput | ( | int | startBinding, |
int | bindingCount, | ||
const VertexInput * | bindings, | ||
QRhiBuffer * | indexBuf = nullptr , |
||
quint32 | indexOffset = 0 , |
||
IndexFormat | indexFormat = IndexUInt16 |
||
) |
Records vertex input bindings.
The index buffer used by subsequent drawIndexed() commands is specified by indexBuf, indexOffset, and indexFormat. indexBuf can be set to null when indexed drawing is not needed.
Vertex buffer bindings are batched. startBinding specifies the first binding number. The recorded command then binds each buffer from bindings to the binding point {startBinding + i} where
i
is the index in bindings. Each element in bindings specifies a QRhiBuffer and an offset.
Superfluous vertex input and index changes in the same pass are ignored automatically with most backends and therefore applications do not need to overoptimize to avoid calls to this function.
As a simple example, take a vertex shader with two inputs:
\badcode layout(location = 0) in vec4 position; layout(location = 1) in vec3 color;
and assume we have the data available in interleaved format, using only 2 floats for position (so 5 floats per vertex: x, y, r, g, b). A QRhiGraphicsPipeline for this shader can then be created using the input layout:
Here there is one buffer binding (binding number 0), with two inputs referencing it. When recording the pass, once the pipeline is set, the vertex bindings can be specified simply like the following, assuming vbuf is the QRhiBuffer with all the interleaved position+color data:
Definition at line 9202 of file qrhi.cpp.
References QRhiResource::m_rhi, and QRhiImplementation::setVertexInput().
void QRhiCommandBuffer::setViewport | ( | const QRhiViewport & | viewport | ) |
Records setting the active viewport rectangle specified in viewport.
With backends where the underlying graphics API has scissoring always enabled, this function also sets the scissor to match the viewport whenever the active QRhiGraphicsPipeline does not have \l{QRhiGraphicsPipeline::UsesScissor}{UsesScissor} set.
Definition at line 9223 of file qrhi.cpp.
References QRhiResource::m_rhi, QRhiImplementation::setViewport(), and viewport().