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
qssgrhicontext_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QSSGRHICONTEXT_P_H
5#define QSSGRHICONTEXT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtGui/rhi/qrhi.h>
19
20#include <QtQuick3DRuntimeRender/qtquick3druntimerenderexports.h>
21#include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h>
22#include <ssg/qssgrhicontext.h>
23
25
26struct QSSGRenderLayer;
28struct QSSGRenderModel;
29struct QSSGRenderMesh;
31
33{
34 using InputAssemblerState = QSSGRhiGraphicsPipelineState::InputAssemblerState;
35 static const InputAssemblerState &get(const QSSGRhiGraphicsPipelineState &ps) { return ps.ia; }
37};
38
40
42{
44 {
45 ps.shaderPipeline = pipeline;
46 }
47
49 {
50 return ps.shaderPipeline;
51 }
52};
53
54namespace QSSGRhiHelpers
55{
56
70
86
88{
89 switch (cullFaceMode) {
97 qWarning("FrontAndBack cull mode not supported");
101 }
102
103 Q_UNREACHABLE_RETURN(QRhiGraphicsPipeline::None);
104}
105
108// Fills out inputLayout.attributes[].location based on
109// inputLayoutInputNames and the provided shader reflection info.
110void bakeVertexInputLocations(QSSGRhiInputAssemblerState *ia, const QSSGRhiShaderPipeline &shaders, int instanceBufferBinding = 0);
111
112} // namespace QSSGRhiHelpers
113
115{
116 const auto &ia_a = QSSGRhiInputAssemblerStatePrivate::get(a);
117 const auto &ia_b = QSSGRhiInputAssemblerStatePrivate::get(b);
119 && a.samples == b.samples
120 && a.flags == b.flags
121 && a.stencilRef == b.stencilRef
122 && (std::memcmp(&a.stencilOpFrontState, &b.stencilOpFrontState, sizeof(QRhiGraphicsPipeline::StencilOpState)) == 0)
123 && a.stencilWriteMask == b.stencilWriteMask
124 && a.depthFunc == b.depthFunc
125 && a.cullMode == b.cullMode
126 && a.depthBias == b.depthBias
127 && a.slopeScaledDepthBias == b.slopeScaledDepthBias
128 && a.viewport == b.viewport
129 && a.scissor == b.scissor
130 && ia_a.topology == ia_b.topology
131 && ia_a.inputLayout == ia_b.inputLayout
132 && a.targetBlend.colorWrite == b.targetBlend.colorWrite
133 && a.targetBlend.srcColor == b.targetBlend.srcColor
134 && a.targetBlend.dstColor == b.targetBlend.dstColor
135 && a.targetBlend.opColor == b.targetBlend.opColor
136 && a.targetBlend.srcAlpha == b.targetBlend.srcAlpha
137 && a.targetBlend.dstAlpha == b.targetBlend.dstAlpha
138 && a.targetBlend.opAlpha == b.targetBlend.opAlpha
139 && a.colorAttachmentCount == b.colorAttachmentCount
140 && a.lineWidth == b.lineWidth
141 && a.polygonMode == b.polygonMode
142 && a.viewCount == b.viewCount;
143}
144
146{
147 return !(a == b);
148}
149
151{
152 // do not bother with all fields
154 ^ qHash(s.samples)
155 ^ qHash(s.viewCount)
156 ^ qHash(s.targetBlend.dstColor)
157 ^ qHash(s.depthFunc)
158 ^ qHash(s.cullMode)
159 ^ qHash(s.colorAttachmentCount)
160 ^ qHash(s.lineWidth)
161 ^ qHash(s.polygonMode)
162 ^ qHashBits(&s.stencilOpFrontState, sizeof(QRhiGraphicsPipeline::StencilOpState))
163 ^ (s.flags)
164 ^ (s.stencilRef << 6)
165 ^ (s.stencilWriteMask << 7);
166}
167
168// The lookup keys can be somewhat complicated due to having to handle cases
169// like "render a model in a shared scene between multiple View3Ds" (here both
170// the View3D ('layer/cid') and the model ('model') act as the lookup key since
171// while the model is the same, we still want different uniform buffers per
172// View3D), or the case of shadow maps where the shadow map (there can be as
173// many as lights) is taken into account too ('entry') together with an entry index
174// where more resolution is needed (e.g., cube maps).
175//
177{
178 const void *cid = nullptr; // Usually the sub-pass (see usage of QSSGPassKey)
179 const void *model = nullptr;
180 const void *entry = nullptr;
182};
183
184class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRhiBuffer
185{
186 Q_DISABLE_COPY(QSSGRhiBuffer)
187public:
190 QRhiBuffer::UsageFlags usageMask,
194
195 virtual ~QSSGRhiBuffer();
196
197 QRhiBuffer *buffer() const { return m_buffer; }
198 quint32 stride() const { return m_stride; }
200 const quint32 sz = quint32(m_buffer->size());
201 Q_ASSERT((sz % m_stride) == 0);
202 return sz / m_stride;
203 }
204 QRhiCommandBuffer::IndexFormat indexFormat() const { return m_indexFormat; }
205
206private:
207 QSSGRhiContext &m_context;
208 QRhiBuffer *m_buffer = nullptr;
209 quint32 m_stride;
210 QRhiCommandBuffer::IndexFormat m_indexFormat;
211};
212
214{
215 char name[64];
216 size_t size = 0;
217
218private:
219 size_t offset = SIZE_MAX;
220 bool maybeExists = true;
222};
223
225{
226 char name[64];
227 size_t typeSize = 0;
228 size_t itemCount = 0;
229
230private:
231 size_t offset = SIZE_MAX;
232 size_t size = 0;
233 bool maybeExists = true;
235};
236
237using QSSGRhiBufferPtr = std::shared_ptr<QSSGRhiBuffer>;
238
240{
241 return a.hTiling == b.hTiling && a.vTiling == b.vTiling && a.zTiling == b.zTiling
242 && a.minFilter == b.minFilter && a.magFilter == b.magFilter
243 && a.mipmap == b.mipmap;
244}
245
247{
248 return !(a == b);
249}
250
257
259{
260 LightProbe = 64, // must be larger than the largest value in SSGRenderableImage::Type
263 AoTexture,
268
270};
271
272// these are our current shader limits
273#define QSSG_MAX_NUM_LIGHTS 15
274#define QSSG_REDUCED_MAX_NUM_LIGHTS 5
275#define QSSG_MAX_NUM_SHADOW_MAPS 8
276
277// note this struct must exactly match the memory layout of the uniform block in
278// funcSampleLightVars.glsllib
280{
281 float position[4];
282 float direction[4]; // Specifies the light direction in world coordinates.
283 float diffuse[4];
284 float specular[4];
285 float coneAngle; // Specifies the outer cone angle of the spot light.
286 float innerConeAngle; // Specifies the inner cone angle of the spot light.
287 float constantAttenuation; // Specifies the constant light attenuation factor.
288 float linearAttenuation; // Specifies the linear light attenuation factor.
289 float quadraticAttenuation; // Specifies the quadratic light attenuation factor.
290 float padding[3]; // the next light array element must start at a vec4-aligned offset
291};
292
294{
296 float padding[3]; // first element must start at a vec4-aligned offset
298};
299
300// Default materials work with a regular combined image sampler for each shadowmap.
307
308class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRhiShaderPipeline
309{
310 Q_DISABLE_COPY(QSSGRhiShaderPipeline)
311public:
313
314 QSSGRhiContext &context() const { return m_context; }
315 bool isNull() const { return m_stages.isEmpty(); }
316
318 // Indicates that this shaderpipeline object is not going to be used with
319 // a QSSGRhiInputAssemblerState, i.e. bakeVertexInputLocations() will
320 // not be called.
321 UsedWithoutIa = 0x01
322 };
323 Q_DECLARE_FLAGS(StageFlags, StageFlag)
324
325 void addStage(const QRhiShaderStage &stage, StageFlags flags = {});
326 const QRhiShaderStage *cbeginStages() const { return m_stages.cbegin(); }
327 const QRhiShaderStage *cendStages() const { return m_stages.cend(); }
328
330 for (const QRhiShaderStage &s : m_stages) {
331 if (s.type() == QRhiShaderStage::Vertex)
332 return &s;
333 }
334 return nullptr;
335 }
337 for (const QRhiShaderStage &s : m_stages) {
338 if (s.type() == QRhiShaderStage::Fragment)
339 return &s;
340 }
341 return nullptr;
342 }
343
344 int ub0Size() const { return m_ub0Size; }
345 int ub0LightDataOffset() const { return m_ub0NextUBufOffset; }
347 {
348 return int(4 * sizeof(qint32) + m_lightsUniformData.count * sizeof(QSSGShaderLightData));
349 }
350
351 const QHash<QSSGRhiInputAssemblerState::InputSemantic, QShaderDescription::InOutVariable> &vertexInputs() const { return m_vertexInputs; }
352
353 // This struct is used purely for performance. It is used to quickly store
354 // and index common uniform names using the storeIndex argument in the
355 // setUniform method.
357 {
358 int cameraPositionIdx = -1;
359 int cameraDirectionIdx = -1;
360 int viewProjectionMatrixIdx = -1;
361 int projectionMatrixIdx = -1;
362 int inverseProjectionMatrixIdx = -1;
363 int viewMatrixIdx = -1;
364 int modelViewProjectionIdx = -1;
365 int normalMatrixIdx = -1;
366 int modelMatrixIdx = -1;
367 int lightProbeOrientationIdx = -1;
368 int lightProbePropertiesIdx = -1;
369 int material_emissiveColorIdx = -1;
370 int material_baseColorIdx = -1;
371 int material_specularIdx = -1;
372 int cameraPropertiesIdx = -1;
373 int light_ambient_totalIdx = -1;
374 int material_propertiesIdx = -1;
375 int material_properties2Idx = -1;
376 int material_properties3Idx = -1;
377 int material_properties4Idx = -1;
378 int material_properties5Idx = -1;
379 int material_attenuationIdx = -1;
380 int thicknessFactorIdx = -1;
381 int clearcoatNormalStrengthIdx = -1;
382 int clearcoatFresnelPowerIdx = -1;
383 int rhiPropertiesIdx = -1;
384 int displaceAmountIdx = -1;
385 int boneTransformsIdx = -1;
386 int boneNormalTransformsIdx = -1;
387 int shadowDepthAdjustIdx = -1;
388 int pointSizeIdx = -1;
389 int morphWeightsIdx = -1;
390 int reflectionProbeCubeMapCenter = -1;
391 int reflectionProbeBoxMax = -1;
392 int reflectionProbeBoxMin = -1;
393 int reflectionProbeCorrection = -1;
394 int specularAAIdx = -1;
395 int fogColorIdx = -1;
396 int fogSunColorIdx = -1;
397 int fogDepthPropertiesIdx = -1;
398 int fogHeightPropertiesIdx = -1;
399 int fogTransmitPropertiesIdx = -1;
400
402 {
403 int imageRotationsUniformIndex = -1;
404 int imageOffsetsUniformIndex = -1;
405 };
406 QVarLengthArray<ImageIndices, 16> imageIndices;
407 } commonUniformIndices;
408
410 int transform0 = -1;
411 int transform1 = -1;
412 int transform2 = -1;
413 int color = -1;
414 int data = -1;
415 } instanceLocations;
416
417 enum class UniformFlag {
418 Mat3 = 0x01
419 };
420 Q_DECLARE_FLAGS(UniformFlags, UniformFlag)
421
422 void setUniformValue(char *ubufData, const char *name, const QVariant &value, QSSGRenderShaderValue::Type type);
423 void setUniform(char *ubufData, const char *name, const void *data, size_t size, int *storeIndex = nullptr, UniformFlags flags = {});
424 void setUniformArray(char *ubufData, const char *name, const void *data, size_t itemCount, QSSGRenderShaderValue::Type type, int *storeIndex = nullptr);
425 int bindingForTexture(const char *name, int hint = -1);
426
427 void setLightsEnabled(bool enable) { m_lightsEnabled = enable; }
428 bool isLightingEnabled() const { return m_lightsEnabled; }
429
430 void resetShadowMaps() { m_shadowMaps.clear(); }
431 QSSGRhiShadowMapProperties &addShadowMap() { m_shadowMaps.append(QSSGRhiShadowMapProperties()); return m_shadowMaps.last(); }
432 int shadowMapCount() const { return m_shadowMaps.size(); }
433 const QSSGRhiShadowMapProperties &shadowMapAt(int index) const { return m_shadowMaps[index]; }
434 QSSGRhiShadowMapProperties &shadowMapAt(int index) { return m_shadowMaps[index]; }
435
436 void ensureCombinedMainLightsUniformBuffer(QRhiBuffer **ubuf);
437 void ensureUniformBuffer(QRhiBuffer **ubuf);
438
442 {
443 m_lightProbeTexture = texture; m_lightProbeHorzTile = hTile; m_lightProbeVertTile = vTile;
444 }
445 QRhiTexture *lightProbeTexture() const { return m_lightProbeTexture; }
446 QPair<QSSGRenderTextureCoordOp, QSSGRenderTextureCoordOp> lightProbeTiling() const
447 {
448 return {m_lightProbeHorzTile, m_lightProbeVertTile};
449 }
450
451 void setScreenTexture(QRhiTexture *texture) { m_screenTexture = texture; }
452 QRhiTexture *screenTexture() const { return m_screenTexture; }
453
454 void setDepthTexture(QRhiTexture *texture) { m_depthTexture = texture; }
455 QRhiTexture *depthTexture() const { return m_depthTexture; }
456
457 void setSsaoTexture(QRhiTexture *texture) { m_ssaoTexture = texture; }
458 QRhiTexture *ssaoTexture() const { return m_ssaoTexture; }
459
460 void setLightmapTexture(QRhiTexture *texture) { m_lightmapTexture = texture; }
461 QRhiTexture *lightmapTexture() const { return m_lightmapTexture; }
462
463 void resetExtraTextures() { m_extraTextures.clear(); }
464 void addExtraTexture(const QSSGRhiTexture &t) { m_extraTextures.append(t); }
465 int extraTextureCount() const { return m_extraTextures.size(); }
466 const QSSGRhiTexture &extraTextureAt(int index) const { return m_extraTextures[index]; }
467 QSSGRhiTexture &extraTextureAt(int index) { return m_extraTextures[index]; }
468
469 QSSGShaderLightsUniformData &lightsUniformData() { return m_lightsUniformData; }
470 InstanceLocations instanceBufferLocations() const { return instanceLocations; }
471
472 int offsetOfUniform(const QByteArray &name);
473
474private:
475 QSSGRhiContext &m_context;
476 QVarLengthArray<QRhiShaderStage, 2> m_stages;
477 int m_ub0Size = 0;
478 int m_ub0NextUBufOffset = 0;
479 QHash<QByteArray, QShaderDescription::BlockVariable> m_ub0;
480 QHash<QSSGRhiInputAssemblerState::InputSemantic, QShaderDescription::InOutVariable> m_vertexInputs;
481 QHash<QByteArray, QShaderDescription::InOutVariable> m_combinedImageSamplers;
482 int m_materialImageSamplerBindings[size_t(QSSGRhiSamplerBindingHints::BindingMapSize)];
483
484 QVarLengthArray<QSSGRhiShaderUniform, 32> m_uniforms; // members of the main (binding 0) uniform buffer
485 QVarLengthArray<QSSGRhiShaderUniformArray, 8> m_uniformArrays;
486 QHash<QByteArray, size_t> m_uniformIndex; // Maps uniform name to index in m_uniforms and m_uniformArrays
487
488 // transient (per-object) data; pointers are all non-owning
489 bool m_lightsEnabled = false;
490 QSSGShaderLightsUniformData m_lightsUniformData;
491 QVarLengthArray<QSSGRhiShadowMapProperties, QSSG_MAX_NUM_SHADOW_MAPS> m_shadowMaps;
492 QRhiTexture *m_lightProbeTexture = nullptr;
495 QRhiTexture *m_screenTexture = nullptr;
496 QRhiTexture *m_depthTexture = nullptr;
497 QRhiTexture *m_ssaoTexture = nullptr;
498 QRhiTexture *m_lightmapTexture = nullptr;
499 QVarLengthArray<QSSGRhiTexture, 8> m_extraTextures;
500};
501
502Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRhiShaderPipeline::StageFlags)
503Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRhiShaderPipeline::UniformFlags)
504
506
507class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRhiShaderResourceBindingList
508{
509public:
510 static const int MAX_SIZE = 32;
511
512 int p = 0;
513 size_t h = 0;
515
516 void clear() { p = 0; h = 0; }
517
519
521 : p(other.p),
522 h(other.h)
523 {
524 for (int i = 0; i < p; ++i)
525 v[i] = other.v[i];
526 }
527
529 {
530 if (this != &other) {
531 p = other.p;
532 h = other.h;
533 for (int i = 0; i < p; ++i)
534 v[i] = other.v[i];
535 }
536 return *this;
537 }
538
539 void addUniformBuffer(int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf, int offset = 0 , int size = 0);
540 void addTexture(int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler);
541};
542
544{
545 if (a.h != b.h)
546 return false;
547 if (a.p != b.p)
548 return false;
549 for (int i = 0; i < a.p; ++i) {
550 if (a.v[i] != b.v[i])
551 return false;
552 }
553 return true;
554}
555
557{
558 return !(a == b);
559}
560
562{
563 return bl.h ^ seed;
564}
565
567{
568 QRhiBuffer *ubuf = nullptr; // owned
569 QRhiShaderResourceBindings *srb = nullptr; // not owned
571 QRhiGraphicsPipeline *pipeline = nullptr; // not owned
573 QVector<quint32> renderTargetDescription;
575
576 void reset()
577 {
578 delete ubuf;
579 ubuf = nullptr;
580 srb = nullptr;
581 pipeline = nullptr;
582 }
583};
584
586{
589 QRhiTexture *depthTexture = nullptr; // either depthStencil or depthTexture are valid, never both
592 bool isValid() const { return texture && rpDesc && rt; }
594 delete rt;
595 rt = nullptr;
596 delete rpDesc;
597 rpDesc = nullptr;
598 }
599 void reset() {
601 delete texture;
602 delete depthStencil;
603 delete depthTexture;
604 *this = QSSGRhiRenderableTexture();
605 }
606};
607
609{
610 float d = 0.0f;
612};
613
626
628{
632 QList<QSSGRhiSortData> sortData;
634 int serial = -1;
635 bool sorting = false;
636};
637
639{
640public:
642 QVector<quint32> srbLayoutDescription;
643 struct {
648 {
649 const QVector<quint32> srbDesc = srb->serializedLayoutDescription();
650 return { shader, srbDesc, { qHash(srbDesc) } };
651 }
652};
653
655{
656 return a.shader == b.shader && a.srbLayoutDescription == b.srbLayoutDescription;
657}
658
660{
661 return !(a == b);
662}
663
664inline size_t qHash(const QSSGComputePipelineStateKey &k, size_t seed = 0) Q_DECL_NOTHROW
665{
666 return qHash(k.shader, seed) ^ k.extra.srbLayoutDescriptionHash;
667}
668
670{
671 QRhiTexture::Flags flags;
675};
676
677inline size_t qHash(const QSSGRhiDummyTextureKey &k, size_t seed) Q_DECL_NOTHROW
678{
679 return qHash(k.flags, seed)
680 ^ qHash(k.size.width() ^ k.size.height() ^ k.color.red() ^ k.color.green()
681 ^ k.color.blue() ^ k.color.alpha() ^ k.arraySize);
682}
683
685{
686 return a.flags == b.flags && a.size == b.size && a.color == b.color && a.arraySize == b.arraySize;
687}
688
690{
691 return !(a == b);
692}
693
695{
696public:
698 QVector<quint32> renderTargetDescription;
699 QVector<quint32> srbLayoutDescription;
700 struct {
705 const QRhiRenderPassDescriptor *rpDesc,
707 {
708 const QVector<quint32> rtDesc = rpDesc->serializedFormat();
709 const QVector<quint32> srbDesc = srb->serializedLayoutDescription();
710 return { state, rtDesc, srbDesc, { qHash(rtDesc), qHash(srbDesc) } };
711 }
712};
713
715{
716 return a.state == b.state
717 && a.renderTargetDescription == b.renderTargetDescription
718 && a.srbLayoutDescription == b.srbLayoutDescription;
719}
720
722{
723 return !(a == b);
724}
725
727{
728 return qHash(k.state, seed)
729 ^ k.extra.renderTargetDescriptionHash
730 ^ k.extra.srbLayoutDescriptionHash;
731}
732
733#define QSSGRHICTX_STAT(ctx, f) \
734 for (bool qssgrhictxlog_enabled = QSSGRhiContextStats::get(*ctx).isEnabled(); qssgrhictxlog_enabled; qssgrhictxlog_enabled = false) \
735 QSSGRhiContextStats::get(*ctx).f
736
737class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRhiContextStats
738{
739public:
740 [[nodiscard]] static QSSGRhiContextStats &get(QSSGRhiContext &rhiCtx);
741 [[nodiscard]] static const QSSGRhiContextStats &get(const QSSGRhiContext &rhiCtx);
742
743 struct DrawInfo {
744 quint64 callCount = 0;
745 quint64 vertexOrIndexCount = 0;
746 };
748 quint64 callCount = 0;
749 quint64 vertexOrIndexCount = 0;
751 };
762 {
763 externalRenderPass.rtName = QByteArrayLiteral("Qt Quick");
764 }
765
766 // The main render pass if renderMode==Offscreen, plus render passes
767 // for shadow maps, postprocessing effects, etc.
768 QVector<RenderPassInfo> renderPasses;
769
770 // An Underlay/Overlay/Inline renderMode will make the View3D add stuff
771 // to a render pass managed by Qt Quick. (external == not under the
772 // control of Qt Quick 3D)
774
775 int currentRenderPassIndex = -1;
776 };
777 struct GlobalInfo { // global as in per QSSGRhiContext which is per-QQuickWindow
778 quint64 meshDataSize = 0;
780 qint64 materialGenerationTime = 0;
781 qint64 effectGenerationTime = 0;
782 };
783
784 QHash<QSSGRenderLayer *, PerLayerInfo> perLayerInfo;
786
788 : rhiCtx(&context)
789 {
790 }
791
792 // The data collected have four consumers:
793 //
794 // - Printed on debug output when QSG_RENDERER_DEBUG has the relevant key.
795 // (this way the debug output from the 2D scenegraph renderer and these 3D
796 // statistics appear nicely intermixed)
797 // - Passed on to the QML profiler when profiling is enabled.
798 // - DebugView via QQuick3DRenderStats.
799 // - When tracing is enabled
800 //
801 // The first two are enabled globally, but DebugView needs a dynamic
802 // enable/disable since we want to collect data when a DebugView item
803 // becomes visible, but not otherwise.
804
805 static bool profilingEnabled();
806 static bool rendererDebugEnabled();
807
808 bool isEnabled() const;
809 void drawIndexed(quint32 indexCount, quint32 instanceCount);
810 void draw(quint32 vertexCount, quint32 instanceCount);
811
812 void meshDataSizeChanges(quint64 newSize) // can be called outside start-stop
813 {
814 globalInfo.meshDataSize = newSize;
815 }
816
817 void imageDataSizeChanges(quint64 newSize) // can be called outside start-stop
818 {
819 globalInfo.imageDataSize = newSize;
820 }
821
823 {
824 globalInfo.materialGenerationTime += ms;
825 }
826
828 {
829 globalInfo.effectGenerationTime += ms;
830 }
831
839
847
849 void stop(QSSGRenderLayer *layer);
850 void beginRenderPass(QRhiTextureRenderTarget *rt);
851 void endRenderPass();
852 void printRenderPass(const RenderPassInfo &rp);
853 void cleanupLayerInfo(QSSGRenderLayer *layer);
854
856 QSSGRenderLayer *layerKey = nullptr;
857 QSet<QSSGRenderLayer *> dynamicDataSources;
858};
859
860class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRhiContextPrivate
861{
862 Q_DECLARE_PUBLIC(QSSGRhiContext)
863
864 explicit QSSGRhiContextPrivate(QSSGRhiContext &rhiCtx, QRhi *rhi_)
865 : q_ptr(&rhiCtx)
866 , m_rhi(rhi_)
867 , m_stats(rhiCtx)
868 {}
869
870public:
871 using Textures = QSet<QRhiTexture *>;
872 using Meshes = QSet<QSSGRenderMesh *>;
873
874 [[nodiscard]] static QSSGRhiContextPrivate *get(QSSGRhiContext *q) { return q->d_ptr.get(); }
875 [[nodiscard]] static const QSSGRhiContextPrivate *get(const QSSGRhiContext *q) { return q->d_ptr.get(); }
876
877 [[nodiscard]] static bool shaderDebuggingEnabled();
878 [[nodiscard]] static bool editorMode();
879
880 void setMainRenderPassDescriptor(QRhiRenderPassDescriptor *rpDesc);
881 void setCommandBuffer(QRhiCommandBuffer *cb);
882 void setRenderTarget(QRhiRenderTarget *rt);
883 void setMainPassSampleCount(int samples);
884 void setMainPassViewCount(int viewCount);
885
886 void releaseCachedResources();
887
888 void registerTexture(QRhiTexture *texture);
889 void releaseTexture(QRhiTexture *texture);
890
891 void registerMesh(QSSGRenderMesh *mesh);
892 void releaseMesh(QSSGRenderMesh *mesh);
893
895
899
903
904 QRhiComputePipeline *computePipeline(const QShader &shader,
906
909
910 QSSGRhiDrawCallData &drawCallData(const QSSGRhiDrawCallDataKey &key);
911 void releaseDrawCallData(QSSGRhiDrawCallData &dcd);
912 void cleanupDrawCallData(const QSSGRenderModel *model);
913
914 QSSGRhiInstanceBufferData &instanceBufferData(QSSGRenderInstanceTable *instanceTable);
915
916 QSSGRhiInstanceBufferData &instanceBufferData(const QSSGRenderModel *model);
917
918 QSSGRhiParticleData &particleData(const QSSGRenderGraphObject *particlesOrModel);
919
920 QSSGRhiContext *q_ptr = nullptr;
921 QRhi *m_rhi = nullptr;
922
923 QRhiRenderPassDescriptor *m_mainRpDesc = nullptr;
924 QRhiCommandBuffer *m_cb = nullptr;
925 QRhiRenderTarget *m_rt = nullptr;
928 int m_mainSamples = 1;
929 int m_mainViewCount = 1;
930
931 QVector<QPair<QSSGRhiSamplerDescription, QRhiSampler*>> m_samplers;
932
933 QHash<QSSGRhiDrawCallDataKey, QSSGRhiDrawCallData> m_drawCallData;
934 QHash<QSSGRhiShaderResourceBindingList, QRhiShaderResourceBindings *> m_srbCache;
935 QHash<QSSGGraphicsPipelineStateKey, QRhiGraphicsPipeline *> m_pipelines;
936 QHash<QSSGComputePipelineStateKey, QRhiComputePipeline *> m_computePipelines;
937 QHash<QSSGRhiDummyTextureKey, QRhiTexture *> m_dummyTextures;
938 QHash<QSSGRenderInstanceTable *, QSSGRhiInstanceBufferData> m_instanceBuffers;
939 QHash<const QSSGRenderModel *, QSSGRhiInstanceBufferData> m_instanceBuffersLod;
940 QHash<const QSSGRenderGraphObject *, QSSGRhiParticleData> m_particleData;
942};
943
944inline bool operator==(const QSSGRhiDrawCallDataKey &a, const QSSGRhiDrawCallDataKey &b) noexcept
945{
946 return a.cid == b.cid && a.model == b.model && a.entry == b.entry && a.entryIdx == b.entryIdx;
947}
948
949inline bool operator!=(const QSSGRhiDrawCallDataKey &a, const QSSGRhiDrawCallDataKey &b) noexcept
950{
951 return !(a == b);
952}
953
954inline size_t qHash(const QSSGRhiDrawCallDataKey &k, size_t seed = 0) noexcept
955{
956 return qHash(quintptr(k.cid)
957 ^ quintptr(k.model)
958 ^ quintptr(k.entry)
959 ^ quintptr(k.entryIdx), seed);
960}
961
963
964#endif // QSSGRHICONTEXT_P_H
\inmodule QtCore
Definition qbytearray.h:57
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtGui
Definition qrhi.h:846
Type
Specifies storage type of buffer resource.
Definition qrhi.h:848
\inmodule QtGui
Definition qrhi.h:1651
IndexFormat
Specifies the index data type.
Definition qrhi.h:1653
\inmodule QtGui
Definition qrhi.h:1622
\inmodule QtGui
Definition qrhi.h:1270
CullMode
Specifies the culling mode.
Definition qrhi.h:1290
Topology
Specifies the primitive topology.
Definition qrhi.h:1280
\inmodule QtGui
Definition qrhi.h:1094
\inmodule QtGui
Definition qrhi.h:1142
virtual QVector< quint32 > serializedFormat() const =0
\inmodule QtGui
Definition qrhi.h:1158
\inmodule QtGui
Definition qrhi.h:1030
Filter
Specifies the minification, magnification, or mipmap filtering.
Definition qrhi.h:1032
AddressMode
Specifies the addressing mode.
Definition qrhi.h:1038
@ ClampToEdge
Definition qrhi.h:1040
\inmodule QtGui
Definition qrhi.h:439
\inmodule QtGui
Definition qrhi.h:1214
QVector< quint32 > serializedLayoutDescription() const
Definition qrhi.h:1232
\inmodule QtGui
Definition qrhi.h:379
\inmodule QtGui
Definition qrhi.h:1184
\inmodule QtGui
Definition qrhi.h:895
Format
Specifies the type of the element data.
Definition qrhi.h:234
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1804
static QSSGComputePipelineStateKey create(const QShader &shader, const QRhiShaderResourceBindings *srb)
struct QSSGComputePipelineStateKey::@763 extra
QVector< quint32 > srbLayoutDescription
static QSSGGraphicsPipelineStateKey create(const QSSGRhiGraphicsPipelineState &state, const QRhiRenderPassDescriptor *rpDesc, const QRhiShaderResourceBindings *srb)
QSSGRhiGraphicsPipelineState state
QVector< quint32 > srbLayoutDescription
QVector< quint32 > renderTargetDescription
struct QSSGGraphicsPipelineStateKey::@764 extra
QRhiBuffer * buffer() const
QRhiCommandBuffer::IndexFormat indexFormat() const
quint32 stride() const
quint32 numVertices() const
static const QSSGRhiContextPrivate * get(const QSSGRhiContext *q)
QHash< QSSGRenderInstanceTable *, QSSGRhiInstanceBufferData > m_instanceBuffers
QVector< QPair< QSSGRhiSamplerDescription, QRhiSampler * > > m_samplers
QHash< const QSSGRenderGraphObject *, QSSGRhiParticleData > m_particleData
QSSGRhiContextStats m_stats
QHash< const QSSGRenderModel *, QSSGRhiInstanceBufferData > m_instanceBuffersLod
QHash< QSSGRhiDummyTextureKey, QRhiTexture * > m_dummyTextures
QHash< QSSGRhiShaderResourceBindingList, QRhiShaderResourceBindings * > m_srbCache
QHash< QSSGRhiDrawCallDataKey, QSSGRhiDrawCallData > m_drawCallData
static QSSGRhiContextPrivate * get(QSSGRhiContext *q)
QHash< QSSGComputePipelineStateKey, QRhiComputePipeline * > m_computePipelines
QHash< QSSGGraphicsPipelineStateKey, QRhiGraphicsPipeline * > m_pipelines
void imageDataSizeChanges(quint64 newSize)
QSSGRhiContext * rhiCtx
static quint64 totalVertexCountForPass(const QSSGRhiContextStats::RenderPassInfo &pass)
void registerEffectShaderGenerationTime(qint64 ms)
void registerMaterialShaderGenerationTime(qint64 ms)
QSSGRhiContextStats(QSSGRhiContext &context)
void meshDataSizeChanges(quint64 newSize)
QHash< QSSGRenderLayer *, PerLayerInfo > perLayerInfo
static quint64 totalDrawCallCountForPass(const QSSGRhiContextStats::RenderPassInfo &pass)
QSet< QSSGRenderLayer * > dynamicDataSources
\inmodule QtQuick3D
const QRhiShaderStage * cendStages() const
QRhiTexture * ssaoTexture() const
const QHash< QSSGRhiInputAssemblerState::InputSemantic, QShaderDescription::InOutVariable > & vertexInputs() const
QRhiTexture * lightProbeTexture() const
QSSGRhiShaderPipeline(QSSGRhiContext &context)
QPair< QSSGRenderTextureCoordOp, QSSGRenderTextureCoordOp > lightProbeTiling() const
QSSGRhiTexture & extraTextureAt(int index)
void setLightProbeTexture(QRhiTexture *texture, QSSGRenderTextureCoordOp hTile=QSSGRenderTextureCoordOp::ClampToEdge, QSSGRenderTextureCoordOp vTile=QSSGRenderTextureCoordOp::ClampToEdge)
void setLightmapTexture(QRhiTexture *texture)
InstanceLocations instanceBufferLocations() const
void setDepthTexture(QRhiTexture *texture)
QSSGRhiShadowMapProperties & shadowMapAt(int index)
QRhiTexture * screenTexture() const
const QRhiShaderStage * cbeginStages() const
const QRhiShaderStage * fragmentStage() const
QRhiTexture * depthTexture() const
void addExtraTexture(const QSSGRhiTexture &t)
void setLightsEnabled(bool enable)
void setScreenTexture(QRhiTexture *texture)
const QSSGRhiShadowMapProperties & shadowMapAt(int index) const
QSSGRhiContext & context() const
const QRhiShaderStage * vertexStage() const
QSSGShaderLightsUniformData & lightsUniformData()
QSSGRhiShadowMapProperties & addShadowMap()
QRhiTexture * lightmapTexture() const
void setSsaoTexture(QRhiTexture *texture)
const QSSGRhiTexture & extraTextureAt(int index) const
QSSGRhiShaderResourceBindingList(const QSSGRhiShaderResourceBindingList &other)
QSSGRhiShaderResourceBindingList & operator=(const QSSGRhiShaderResourceBindingList &other) Q_DECL_NOTHROW
\inmodule QtGui
Definition qshader.h:81
\inmodule QtCore
Definition qsize.h:25
\inmodule QtCore
Definition qvariant.h:65
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
QRhiVertexInputAttribute::Format toVertexInputFormat(QSSGRenderComponentType compType, quint32 numComps)
QRhiGraphicsPipeline::CullMode toCullMode(QSSGCullFaceMode cullFaceMode)
QRhiGraphicsPipeline::Topology toTopology(QSSGRenderDrawMode drawMode)
void bakeVertexInputLocations(QSSGRhiInputAssemblerState *ia, const QSSGRhiShaderPipeline &shaders, int instanceBufferBinding)
QRhiSampler::Filter toRhi(QSSGRenderTextureFilterOp op)
Combined button and popup list for selecting options.
static void * context
#define QByteArrayLiteral(str)
Definition qbytearray.h:52
#define Q_DECL_NOTHROW
static QDBusError::ErrorType get(const char *name)
static int instanceCount
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
EGLOutputLayerEXT layer
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
size_t qHashBits(const void *p, size_t size, size_t seed) noexcept
Definition qhash.cpp:1089
#define qWarning
Definition qlogging.h:166
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLsizei samples
GLuint64 key
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLuint sampler
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
const void GLsizei GLsizei stride
GLenum GLuint buffer
GLuint color
[2]
GLenum type
GLenum GLuint GLenum GLsizei const GLchar * buf
GLbitfield flags
GLboolean enable
GLenum GLuint texture
GLuint start
GLenum GLuint GLintptr offset
GLuint name
GLfloat GLfloat GLfloat GLfloat h
GLdouble s
[6]
Definition qopenglext.h:235
GLuint entry
GLuint shader
Definition qopenglext.h:665
GLdouble GLdouble t
Definition qopenglext.h:243
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLsizei GLsizei GLuint * shaders
Definition qopenglext.h:677
GLfloat GLfloat p
[1]
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QSSGRenderTextureCoordOp
QSSGRenderTextureFilterOp
QSSGRenderComponentType
bool operator==(const QSSGRhiGraphicsPipelineState &a, const QSSGRhiGraphicsPipelineState &b) Q_DECL_NOTHROW
std::shared_ptr< QSSGRhiBuffer > QSSGRhiBufferPtr
QSSGRhiInputAssemblerStatePrivate::InputAssemblerState QSSGRhiInputAssemblerState
std::shared_ptr< QSSGRhiShaderPipeline > QSSGRhiShaderPipelinePtr
#define QSSG_MAX_NUM_LIGHTS
QSSGRhiSamplerBindingHints
size_t qHash(const QSSGRhiGraphicsPipelineState &s, size_t seed) Q_DECL_NOTHROW
bool operator!=(const QSSGRhiGraphicsPipelineState &a, const QSSGRhiGraphicsPipelineState &b) Q_DECL_NOTHROW
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
unsigned int quint32
Definition qtypes.h:50
size_t quintptr
Definition qtypes.h:167
int qint32
Definition qtypes.h:49
unsigned long long quint64
Definition qtypes.h:61
ptrdiff_t qsizetype
Definition qtypes.h:165
long long qint64
Definition qtypes.h:60
static size_t imageDataSize(const xcb_image_t *image)
QSqlQueryModel * model
[16]
QSharedPointer< T > other(t)
[5]
myFilter draw(painter, QPoint(0, 0), originalPixmap)
\variable QRhiGraphicsPipeline::TargetBlend::colorWrite
Definition qrhi.h:1372
QVector< RenderPassInfo > renderPasses
QSSGRhiShaderResourceBindingList bindings
QSSGRhiGraphicsPipelineState ps
QRhiShaderResourceBindings * srb
QVector< quint32 > renderTargetDescription
QRhiGraphicsPipeline * pipeline
QRhiTexture::Flags flags
static constexpr const QSSGRhiShaderPipeline * getShaderPipeline(const QSSGRhiGraphicsPipelineState &ps)
static void setShaderPipeline(QSSGRhiGraphicsPipelineState &ps, const QSSGRhiShaderPipeline *pipeline)
QSSGRhiGraphicsPipelineState::InputAssemblerState InputAssemblerState
static const InputAssemblerState & get(const QSSGRhiGraphicsPipelineState &ps)
static InputAssemblerState & get(QSSGRhiGraphicsPipelineState &ps)
QList< QSSGRhiSortData > sortData
QList< QSSGRhiSortData > sortData
QRhiTextureRenderTarget * rt
QRhiRenderPassDescriptor * rpDesc
QRhiRenderBuffer * depthStencil
\variable QSSGRhiGraphicsPipelineState::depthFunc
QVarLengthArray< ImageIndices, 16 > imageIndices
QSSGRhiSamplerDescription samplerDesc
QSSGShaderLightData lightData[QSSG_MAX_NUM_LIGHTS]