Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qssgrhicontext_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 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
19#include <QtCore/qstack.h>
20#include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h>
21#include <QtGui/private/qrhi_p.h>
22#include "private/qquick3dprofiler_p.h"
23
25
26class QSSGRhiContext;
27class QSSGRhiBuffer;
28struct QSSGShaderLightProperties;
29struct QSSGRenderMesh;
30struct QSSGRenderModel;
33struct QSSGRenderLayer;
34
35struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRhiInputAssemblerState
36{
38 PositionSemantic, // attr_pos
39 NormalSemantic, // attr_norm
40 TexCoord0Semantic, // attr_uv0
41 TexCoord1Semantic, // attr_uv1
42 TangentSemantic, // attr_textan
43 BinormalSemantic, // attr_binormal
44 ColorSemantic, // attr_color
45 MaxTargetSemantic = ColorSemantic,
46 JointSemantic, // attr_joints
47 WeightSemantic, // attr_weights
48 TexCoordLightmapSemantic // attr_lightmapuv
49 };
50
54
55 std::array<quint8, MaxTargetSemantic + 1> targetOffsets = { UINT8_MAX, UINT8_MAX, UINT8_MAX, UINT8_MAX,
56 UINT8_MAX, UINT8_MAX, UINT8_MAX };
57 quint8 targetCount = 0;
58
59 static QRhiVertexInputAttribute::Format toVertexInputFormat(QSSGRenderComponentType compType, quint32 numComps);
60 static QRhiGraphicsPipeline::Topology toTopology(QSSGRenderDrawMode drawMode);
61
62 // Fills out inputLayout.attributes[].location based on
63 // inputLayoutInputNames and the provided shader reflection info.
64 void bakeVertexInputLocations(const QSSGRhiShaderPipeline &shaders, int instanceBufferBinding = 0);
65};
66
67class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRhiBuffer
68{
69 Q_DISABLE_COPY(QSSGRhiBuffer)
70public:
73 QRhiBuffer::UsageFlags usageMask,
77
78 virtual ~QSSGRhiBuffer();
79
80 QRhiBuffer *buffer() const { return m_buffer; }
81 quint32 stride() const { return m_stride; }
83 const quint32 sz = quint32(m_buffer->size());
84 Q_ASSERT((sz % m_stride) == 0);
85 return sz / m_stride;
86 }
87 QRhiCommandBuffer::IndexFormat indexFormat() const { return m_indexFormat; }
88
89private:
90 QSSGRhiContext &m_context;
91 QRhiBuffer *m_buffer = nullptr;
92 quint32 m_stride;
94};
95
97{
98 char name[64];
99 size_t size = 0;
100
101private:
102 size_t offset = SIZE_MAX;
103 bool maybeExists = true;
105};
106
108{
109 char name[64];
110 size_t typeSize = 0;
111 size_t itemCount = 0;
112
113private:
114 size_t offset = SIZE_MAX;
115 size_t size = 0;
116 bool maybeExists = true;
118};
119
120using QSSGRhiBufferPtr = std::shared_ptr<QSSGRhiBuffer>;
121
124
126{
133};
134
136{
137 return a.hTiling == b.hTiling && a.vTiling == b.vTiling && a.zTiling == b.zTiling
138 && a.minFilter == b.minFilter && a.magFilter == b.magFilter
139 && a.mipmap == b.mipmap;
140}
141
143{
144 return !(a == b);
145}
146
148{
152};
153
155{
156 LightProbe = 64, // must be larger than the largest value in SSGRenderableImage::Type
159 AoTexture,
161
163};
164
165// these are our current shader limits
166#define QSSG_MAX_NUM_LIGHTS 15
167#define QSSG_REDUCED_MAX_NUM_LIGHTS 5
168#define QSSG_MAX_NUM_SHADOW_MAPS 8
169
170// note this struct must exactly match the memory layout of the uniform block in
171// funcSampleLightVars.glsllib
173{
174 float position[4];
175 float direction[4]; // Specifies the light direction in world coordinates.
176 float diffuse[4];
177 float specular[4];
178 float coneAngle; // Specifies the outer cone angle of the spot light.
179 float innerConeAngle; // Specifies the inner cone angle of the spot light.
180 float constantAttenuation; // Specifies the constant light attenuation factor.
181 float linearAttenuation; // Specifies the linear light attenuation factor.
182 float quadraticAttenuation; // Specifies the quadratic light attenuation factor.
183 float padding[3]; // the next light array element must start at a vec4-aligned offset
184};
185
187{
189 float padding[3]; // first element must start at a vec4-aligned offset
191};
192
193// Default materials work with a regular combined image sampler for each shadowmap.
195{
198 int cachedBinding = -1; // -1 == invalid
199};
200
201class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRhiShaderPipeline
202{
203 Q_DISABLE_COPY(QSSGRhiShaderPipeline)
204public:
206
207 QSSGRhiContext &context() const { return m_context; }
208 bool isNull() const { return m_stages.isEmpty(); }
209
211 // Indicates that this shaderpipeline object is not going to be used with
212 // a QSSGRhiInputAssemblerState, i.e. bakeVertexInputLocations() will
213 // not be called.
214 UsedWithoutIa = 0x01
215 };
216 Q_DECLARE_FLAGS(StageFlags, StageFlag)
217
218 void addStage(const QRhiShaderStage &stage, StageFlags flags = {});
219 const QRhiShaderStage *cbeginStages() const { return m_stages.cbegin(); }
220 const QRhiShaderStage *cendStages() const { return m_stages.cend(); }
221
223 for (const QRhiShaderStage &s : m_stages) {
224 if (s.type() == QRhiShaderStage::Vertex)
225 return &s;
226 }
227 return nullptr;
228 }
230 for (const QRhiShaderStage &s : m_stages) {
231 if (s.type() == QRhiShaderStage::Fragment)
232 return &s;
233 }
234 return nullptr;
235 }
236
237 int ub0Size() const { return m_ub0Size; }
238 int ub0LightDataOffset() const { return m_ub0NextUBufOffset; }
240 {
241 return int(4 * sizeof(qint32) + m_lightsUniformData.count * sizeof(QSSGShaderLightData));
242 }
243
245
246 // This struct is used purely for performance. It is used to quickly store
247 // and index common uniform names using the storeIndex argument in the
248 // setUniform method.
250 {
251 int cameraPositionIdx = -1;
252 int cameraDirectionIdx = -1;
253 int viewProjectionMatrixIdx = -1;
254 int projectionMatrixIdx = -1;
255 int inverseProjectionMatrixIdx = -1;
256 int viewMatrixIdx = -1;
257 int modelViewProjectionIdx = -1;
258 int normalMatrixIdx = -1;
259 int modelMatrixIdx = -1;
260 int lightProbeOrientationIdx = -1;
261 int lightProbePropertiesIdx = -1;
262 int material_emissiveColorIdx = -1;
263 int material_baseColorIdx = -1;
264 int material_specularIdx = -1;
265 int cameraPropertiesIdx = -1;
266 int light_ambient_totalIdx = -1;
267 int material_propertiesIdx = -1;
268 int material_properties2Idx = -1;
269 int material_properties3Idx = -1;
270 int material_properties4Idx = -1;
271 int material_properties5Idx = -1;
272 int material_attenuationIdx = -1;
273 int thicknessFactorIdx = -1;
274 int rhiPropertiesIdx = -1;
275 int displaceAmountIdx = -1;
276 int boneTransformsIdx = -1;
277 int boneNormalTransformsIdx = -1;
278 int shadowDepthAdjustIdx = -1;
279 int pointSizeIdx = -1;
280 int morphWeightsIdx = -1;
281 int reflectionProbeCubeMapCenter = -1;
282 int reflectionProbeBoxMax = -1;
283 int reflectionProbeBoxMin = -1;
284 int reflectionProbeCorrection = -1;
285 int specularAAIdx = -1;
286 int fogColorIdx = -1;
287 int fogSunColorIdx = -1;
288 int fogDepthPropertiesIdx = -1;
289 int fogHeightPropertiesIdx = -1;
290 int fogTransmitPropertiesIdx = -1;
291
293 {
294 int imageRotationsUniformIndex = -1;
295 int imageOffsetsUniformIndex = -1;
296 };
298 } commonUniformIndices;
299
301 int transform0 = -1;
302 int transform1 = -1;
303 int transform2 = -1;
304 int color = -1;
305 int data = -1;
306 } instanceLocations;
307
308 enum class UniformFlag {
309 Mat3 = 0x01
310 };
311 Q_DECLARE_FLAGS(UniformFlags, UniformFlag)
312
313 void setUniformValue(char *ubufData, const char *name, const QVariant &value, QSSGRenderShaderDataType type);
314 void setUniform(char *ubufData, const char *name, const void *data, size_t size, int *storeIndex = nullptr, UniformFlags flags = {});
315 void setUniformArray(char *ubufData, const char *name, const void *data, size_t itemCount, QSSGRenderShaderDataType type, int *storeIndex = nullptr);
316 int bindingForTexture(const char *name, int hint = -1);
317
318 void setLightsEnabled(bool enable) { m_lightsEnabled = enable; }
319 bool isLightingEnabled() const { return m_lightsEnabled; }
320
321 void resetShadowMaps() { m_shadowMaps.clear(); }
322 QSSGRhiShadowMapProperties &addShadowMap() { m_shadowMaps.append(QSSGRhiShadowMapProperties()); return m_shadowMaps.last(); }
323 int shadowMapCount() const { return m_shadowMaps.size(); }
324 const QSSGRhiShadowMapProperties &shadowMapAt(int index) const { return m_shadowMaps[index]; }
325 QSSGRhiShadowMapProperties &shadowMapAt(int index) { return m_shadowMaps[index]; }
326
327 void ensureCombinedMainLightsUniformBuffer(QRhiBuffer **ubuf);
328 void ensureUniformBuffer(QRhiBuffer **ubuf);
329
333 {
334 m_lightProbeTexture = texture; m_lightProbeHorzTile = hTile; m_lightProbeVertTile = vTile;
335 }
336 QRhiTexture *lightProbeTexture() const { return m_lightProbeTexture; }
338 {
339 return {m_lightProbeHorzTile, m_lightProbeVertTile};
340 }
341
342 void setScreenTexture(QRhiTexture *texture) { m_screenTexture = texture; }
343 QRhiTexture *screenTexture() const { return m_screenTexture; }
344
345 void setDepthTexture(QRhiTexture *texture) { m_depthTexture = texture; }
346 QRhiTexture *depthTexture() const { return m_depthTexture; }
347
348 void setSsaoTexture(QRhiTexture *texture) { m_ssaoTexture = texture; }
349 QRhiTexture *ssaoTexture() const { return m_ssaoTexture; }
350
351 void setLightmapTexture(QRhiTexture *texture) { m_lightmapTexture = texture; }
352 QRhiTexture *lightmapTexture() const { return m_lightmapTexture; }
353
354 void resetExtraTextures() { m_extraTextures.clear(); }
355 void addExtraTexture(const QSSGRhiTexture &t) { m_extraTextures.append(t); }
356 int extraTextureCount() const { return m_extraTextures.size(); }
357 const QSSGRhiTexture &extraTextureAt(int index) const { return m_extraTextures[index]; }
358 QSSGRhiTexture &extraTextureAt(int index) { return m_extraTextures[index]; }
359
360 QSSGShaderLightsUniformData &lightsUniformData() { return m_lightsUniformData; }
361 InstanceLocations instanceBufferLocations() const { return instanceLocations; }
362
363 int offsetOfUniform(const QByteArray &name);
364
365private:
366 QSSGRhiContext &m_context;
368 int m_ub0Size = 0;
369 int m_ub0NextUBufOffset = 0;
373 int m_materialImageSamplerBindings[size_t(QSSGRhiSamplerBindingHints::BindingMapSize)];
374
375 QVarLengthArray<QSSGRhiShaderUniform, 32> m_uniforms; // members of the main (binding 0) uniform buffer
377 QHash<QByteArray, size_t> m_uniformIndex; // Maps uniform name to index in m_uniforms and m_uniformArrays
378
379 // transient (per-object) data; pointers are all non-owning
380 bool m_lightsEnabled = false;
381 QSSGShaderLightsUniformData m_lightsUniformData;
383 QRhiTexture *m_lightProbeTexture = nullptr;
386 QRhiTexture *m_screenTexture = nullptr;
387 QRhiTexture *m_depthTexture = nullptr;
388 QRhiTexture *m_ssaoTexture = nullptr;
389 QRhiTexture *m_lightmapTexture = nullptr;
391};
392
393Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRhiShaderPipeline::StageFlags)
394Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRhiShaderPipeline::UniformFlags)
395
397
398struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRhiGraphicsPipelineState
399{
401 int samples = 1;
402
403 bool depthTestEnable = false;
404 bool depthWriteEnable = false;
405 bool usesStencilRef = false;
409 quint32 stencilWriteMask = 0xFF;
410 quint32 stencilRef = 0;
411 int depthBias = 0;
412 float slopeScaledDepthBias = 0.0f;
413 bool blendEnable = false;
415 int colorAttachmentCount = 1;
416
418 bool scissorEnable = false;
420
422 float lineWidth = 1.0f;
423
425
426 static QRhiGraphicsPipeline::CullMode toCullMode(QSSGCullFaceMode cullFaceMode);
427};
428
430{
431 return a.shaderPipeline == b.shaderPipeline
432 && a.samples == b.samples
433 && a.depthTestEnable == b.depthTestEnable
434 && a.depthWriteEnable == b.depthWriteEnable
435 && a.usesStencilRef == b.usesStencilRef
436 && a.stencilRef == b.stencilRef
437 && (std::memcmp(&a.stencilOpFrontState, &b.stencilOpFrontState, sizeof(QRhiGraphicsPipeline::StencilOpState)) == 0)
438 && a.stencilWriteMask == b.stencilWriteMask
439 && a.depthFunc == b.depthFunc
440 && a.cullMode == b.cullMode
441 && a.depthBias == b.depthBias
442 && a.slopeScaledDepthBias == b.slopeScaledDepthBias
443 && a.blendEnable == b.blendEnable
444 && a.scissorEnable == b.scissorEnable
445 && a.viewport == b.viewport
446 && a.scissor == b.scissor
447 && a.ia.topology == b.ia.topology
448 && a.ia.inputLayout == b.ia.inputLayout
449 && a.targetBlend.colorWrite == b.targetBlend.colorWrite
450 && a.targetBlend.srcColor == b.targetBlend.srcColor
451 && a.targetBlend.dstColor == b.targetBlend.dstColor
452 && a.targetBlend.opColor == b.targetBlend.opColor
453 && a.targetBlend.srcAlpha == b.targetBlend.srcAlpha
454 && a.targetBlend.dstAlpha == b.targetBlend.dstAlpha
455 && a.targetBlend.opAlpha == b.targetBlend.opAlpha
456 && a.colorAttachmentCount == b.colorAttachmentCount
457 && a.lineWidth == b.lineWidth
458 && a.polygonMode == b.polygonMode;
459}
460
462{
463 return !(a == b);
464}
465
467{
468 // do not bother with all fields
469 return qHash(s.shaderPipeline, seed)
470 ^ qHash(s.samples)
471 ^ qHash(s.targetBlend.dstColor)
472 ^ qHash(s.depthFunc)
473 ^ qHash(s.cullMode)
474 ^ qHash(s.colorAttachmentCount)
475 ^ qHash(s.lineWidth)
476 ^ qHash(s.polygonMode)
477 ^ qHashBits(&s.stencilOpFrontState, sizeof(QRhiGraphicsPipeline::StencilOpState))
478 ^ (s.depthTestEnable << 1)
479 ^ (s.depthWriteEnable << 2)
480 ^ (s.blendEnable << 3)
481 ^ (s.scissorEnable << 4)
482 ^ (s.usesStencilRef << 5)
483 ^ (s.stencilRef << 6)
484 ^ (s.stencilWriteMask << 7);
485}
486
488{
492 struct {
497 const QRhiRenderPassDescriptor *rpDesc,
499 {
500 const QVector<quint32> rtDesc = rpDesc->serializedFormat();
501 const QVector<quint32> srbDesc = srb->serializedLayoutDescription();
502 return { state, rtDesc, srbDesc, { qHash(rtDesc), qHash(srbDesc) } };
503 }
504};
505
507{
508 return a.state == b.state
509 && a.renderTargetDescription == b.renderTargetDescription
510 && a.srbLayoutDescription == b.srbLayoutDescription;
511}
512
514{
515 return !(a == b);
516}
517
519{
520 return qHash(k.state, seed)
521 ^ k.extra.renderTargetDescriptionHash
522 ^ k.extra.srbLayoutDescriptionHash;
523}
524
526{
529 struct {
534 {
535 const QVector<quint32> srbDesc = srb->serializedLayoutDescription();
536 return { shader, srbDesc, { qHash(srbDesc) } };
537 }
538};
539
541{
542 return a.shader == b.shader && a.srbLayoutDescription == b.srbLayoutDescription;
543}
544
546{
547 return !(a == b);
548}
549
550inline size_t qHash(const QSSGComputePipelineStateKey &k, size_t seed = 0) Q_DECL_NOTHROW
551{
553}
554
556{
557 static const int MAX_SIZE = 32;
558
559 int p = 0;
560 size_t h = 0;
562
563 void clear() { p = 0; h = 0; }
564
566
568 : p(other.p),
569 h(other.h)
570 {
571 for (int i = 0; i < p; ++i)
572 v[i] = other.v[i];
573 }
574
576 {
577 if (this != &other) {
578 p = other.p;
579 h = other.h;
580 for (int i = 0; i < p; ++i)
581 v[i] = other.v[i];
582 }
583 return *this;
584 }
585
586 void addUniformBuffer(int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf, int offset, int size);
587 void addTexture(int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler);
588};
589
591{
592 if (a.h != b.h)
593 return false;
594 if (a.p != b.p)
595 return false;
596 for (int i = 0; i < a.p; ++i) {
597 if (a.v[i] != b.v[i])
598 return false;
599 }
600 return true;
601}
602
604{
605 return !(a == b);
606}
607
609{
610 return bl.h ^ seed;
611}
612
613inline void QSSGRhiShaderResourceBindingList::addUniformBuffer(int binding, QRhiShaderResourceBinding::StageFlags stage,
614 QRhiBuffer *buf, int offset = 0, int size = 0)
615{
616#ifdef QT_DEBUG
617 if (p == MAX_SIZE) {
618 qWarning("Out of shader resource bindings slots (max is %d)", MAX_SIZE);
619 return;
620 }
621#endif
623 h ^= qintptr(buf);
624 d->binding = binding;
625 d->stage = stage;
627 d->u.ubuf.buf = buf;
628 d->u.ubuf.offset = offset;
629 d->u.ubuf.maybeSize = size; // 0 = all
630 d->u.ubuf.hasDynamicOffset = false;
631}
632
633inline void QSSGRhiShaderResourceBindingList::addTexture(int binding, QRhiShaderResourceBinding::StageFlags stage,
635{
636#ifdef QT_DEBUG
638 qWarning("Out of shader resource bindings slots (max is %d)", MAX_SIZE);
639 return;
640 }
641#endif
643 h ^= qintptr(tex) ^ qintptr(sampler);
644 d->binding = binding;
645 d->stage = stage;
647 d->u.stex.count = 1;
648 d->u.stex.texSamplers[0].tex = tex;
649 d->u.stex.texSamplers[0].sampler = sampler;
650}
651
652// The lookup keys can be somewhat complicated due to having to handle cases
653// like "render a model in a shared scene between multiple View3Ds" (here both
654// the View3D ('layer') and the model ('model') act as the lookup key since
655// while the model is the same, we still want different uniform buffers per
656// View3D), or the case of shadow maps where the shadow map (there can be as
657// many as lights) is taken into account too ('entry').
658//
660{
661 enum Selector {
676 };
677 const void *layer;
678 const void *model;
679 const void *entry;
680 int index;
682};
683
685{
686 return a.selector == b.selector && a.layer == b.layer && a.model == b.model && a.entry == b.entry && a.index == b.index;
687}
688
690{
691 return !(a == b);
692}
693
694inline size_t qHash(const QSSGRhiDrawCallDataKey &k, size_t seed = 0) Q_DECL_NOTHROW
695{
696 return qHash(quintptr(k.layer)
697 ^ quintptr(k.model)
698 ^ quintptr(k.entry)
699 ^ quintptr(k.selector)
700 ^ quintptr(k.index), seed);
701}
702
704{
705 QRhiBuffer *ubuf = nullptr; // owned
706 QRhiShaderResourceBindings *srb = nullptr; // not owned
708 QRhiGraphicsPipeline *pipeline = nullptr; // not owned
712};
713
715{
720 bool isValid() const { return texture && rpDesc && rt; }
722 delete rt;
723 rt = nullptr;
724 delete rpDesc;
725 rpDesc = nullptr;
726 }
727 void reset() {
729 delete texture;
730 delete depthStencil;
731 *this = QSSGRhiRenderableTexture();
732 }
733};
734
736{
737 float d = 0.0f;
739};
740
742{
743 QRhiBuffer *buffer = nullptr;
749 int serial = -1;
750 bool owned = true;
751 bool sorting = false;
752};
753
755{
761 int serial = -1;
762 bool sorting = false;
763};
764
766{
767 QRhiTexture::Flags flags;
770};
771
772inline size_t qHash(const QSSGRhiDummyTextureKey &k, size_t seed) Q_DECL_NOTHROW
773{
774 return qHash(k.flags, seed)
775 ^ qHash(k.size.width() ^ k.size.height() ^ k.color.red() ^ k.color.green()
776 ^ k.color.blue() ^ k.color.alpha());
777}
778
780{
781 return a.flags == b.flags && a.size == b.size && a.color == b.color;
782}
783
785{
786 return !(a == b);
787}
788
789#define QSSGRHICTX_STAT(ctx, f) for (bool qssgrhictxlog_enabled = ctx->stats().isEnabled(); qssgrhictxlog_enabled; qssgrhictxlog_enabled = false) ctx->stats().f
790
791class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRhiContextStats
792{
793public:
794 struct DrawInfo {
795 quint64 callCount = 0;
796 quint64 vertexOrIndexCount = 0;
797 };
799 quint64 callCount = 0;
800 quint64 vertexOrIndexCount = 0;
802 };
810 };
813 {
814 externalRenderPass.rtName = QByteArrayLiteral("Qt Quick");
815 }
816
817 // The main render pass if renderMode==Offscreen, plus render passes
818 // for shadow maps, postprocessing effects, etc.
820
821 // An Underlay/Overlay/Inline renderMode will make the View3D add stuff
822 // to a render pass managed by Qt Quick. (external == not under the
823 // control of Qt Quick 3D)
825
826 int currentRenderPassIndex = -1;
827 };
828 struct GlobalInfo { // global as in per QSSGRhiContext which is per-QQuickWindow
829 quint64 meshDataSize = 0;
831 qint64 materialGenerationTime = 0;
832 qint64 effectGenerationTime = 0;
833 };
834
837
840 {
841 }
842
843 // The data collected have four consumers:
844 //
845 // - Printed on debug output when QSG_RENDERER_DEBUG has the relevant key.
846 // (this way the debug output from the 2D scenegraph renderer and these 3D
847 // statistics appear nicely intermixed)
848 // - Passed on to the QML profiler when profiling is enabled.
849 // - DebugView via QQuick3DRenderStats.
850 // - When tracing is enabled
851 //
852 // The first two are enabled globally, but DebugView needs a dynamic
853 // enable/disable since we want to collect data when a DebugView item
854 // becomes visible, but not otherwise.
855
856 static bool profilingEnabled()
857 {
859 return enabled;
860 }
861
863 {
864 static bool enabled = qgetenv("QSG_RENDERER_DEBUG").contains(QByteArrayLiteral("render"));
865 return enabled;
866 }
867
868 bool isEnabled() const;
869 void drawIndexed(quint32 indexCount, quint32 instanceCount);
870 void draw(quint32 vertexCount, quint32 instanceCount);
871
872 void meshDataSizeChanges(quint64 newSize) // can be called outside start-stop
873 {
874 globalInfo.meshDataSize = newSize;
875 }
876
877 void imageDataSizeChanges(quint64 newSize) // can be called outside start-stop
878 {
879 globalInfo.imageDataSize = newSize;
880 }
881
883 {
884 globalInfo.materialGenerationTime += ms;
885 }
886
888 {
889 globalInfo.effectGenerationTime += ms;
890 }
891
893 {
894 return pass.draws.callCount
898 }
899
901 {
902 return pass.draws.vertexOrIndexCount
906 }
907
909 void stop(QSSGRenderLayer *layer);
910 void beginRenderPass(QRhiTextureRenderTarget *rt);
911 void endRenderPass();
912 void printRenderPass(const RenderPassInfo &rp);
913 void cleanupLayerInfo(QSSGRenderLayer *layer);
914
916 QSSGRenderLayer *layerKey = nullptr;
918};
919
921
922class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRhiContext
923{
924 Q_DISABLE_COPY(QSSGRhiContext)
925public:
926 explicit QSSGRhiContext(QRhi *rhi = nullptr);
928
929 void initialize(QRhi *rhi);
930 QRhi *rhi() const { return m_rhi; }
931 bool isValid() const { return m_rhi != nullptr; }
932
933 void setMainRenderPassDescriptor(QRhiRenderPassDescriptor *rpDesc) { m_mainRpDesc = rpDesc; }
934 QRhiRenderPassDescriptor *mainRenderPassDescriptor() const { return m_mainRpDesc; }
935
937 QRhiCommandBuffer *commandBuffer() const { return m_cb; }
938
939 void setRenderTarget(QRhiRenderTarget *rt) { m_rt = rt; }
940 QRhiRenderTarget *renderTarget() const { return m_rt; }
941
942 void setMainPassSampleCount(int samples) { m_mainSamples = samples; }
943 int mainPassSampleCount() const { return m_mainSamples; }
944
946 void releaseDrawCallData(QSSGRhiDrawCallData &dcd);
952
954 {
955 return m_drawCallData[key];
956 }
957
958 QRhiSampler *sampler(const QSSGRhiSamplerDescription &samplerDescription);
959 void checkAndAdjustForNPoT(QRhiTexture *texture, QSSGRhiSamplerDescription *samplerDescription);
960
961 void registerTexture(QRhiTexture *texture);
962 void releaseTexture(QRhiTexture *texture);
963 QSet<QRhiTexture *> registeredTextures() const { return m_textures; }
964
965 void registerMesh(QSSGRenderMesh *mesh);
966 void releaseMesh(QSSGRenderMesh *mesh);
967 QSet<QSSGRenderMesh *> registeredMeshes() const { return m_meshes; }
968
970
971 void cleanupDrawCallData(const QSSGRenderModel *model);
972
973 QRhiTexture *dummyTexture(QRhiTexture::Flags flags, QRhiResourceUpdateBatch *rub,
974 const QSize &size = QSize(64, 64), const QColor &fillColor = Qt::black);
975
976 static inline QRhiCommandBuffer::BeginPassFlags commonPassFlags()
977 {
978 // We do not use GPU compute at all at the moment, this means we can
979 // get a small performance gain with OpenGL by declaring this.
981 }
982
983 static bool shaderDebuggingEnabled();
984 static bool editorMode();
985
987 {
988 return m_instanceBuffers[instanceTable];
989 }
990
992 {
993 return m_instanceBuffersLod[model];
994 }
995
997 {
998 return m_particleData[particlesOrModel];
999 }
1000
1001 QSSGRhiContextStats &stats() { return m_stats; }
1002
1003 int maxUniformBufferRange() const { return m_rhi->resourceLimit(QRhi::MaxUniformBufferRange); }
1004
1005 void releaseCachedResources();
1006
1007private:
1008 QRhi *m_rhi = nullptr;
1009 QRhiRenderPassDescriptor *m_mainRpDesc = nullptr;
1010 QRhiCommandBuffer *m_cb = nullptr;
1011 QRhiRenderTarget *m_rt = nullptr;
1012 int m_mainSamples = 1;
1018 QSet<QRhiTexture *> m_textures;
1019 QSet<QSSGRenderMesh *> m_meshes;
1024 QSSGRhiContextStats m_stats;
1025};
1026
1028{
1029 switch (op) {
1031 return QRhiSampler::Nearest;
1033 return QRhiSampler::Linear;
1034 default:
1035 break;
1036 }
1037 return QRhiSampler::Linear;
1038}
1039
1041{
1042 switch (tiling) {
1044 return QRhiSampler::Repeat;
1046 return QRhiSampler::Mirror;
1049 default:
1050 break;
1051 }
1053}
1054
1056
1057#endif
\inmodule QtCore
Definition qbytearray.h:57
bool contains(char c) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qbytearray.h:583
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtCore
Definition qhash.h:818
Definition qlist.h:74
\inmodule QtGui
Definition qrhi.h:834
Type
Specifies storage type of buffer resource.
Definition qrhi.h:836
\inmodule QtGui
Definition qrhi.h:1614
@ DoNotTrackResourcesForCompute
Definition qrhi.h:1623
IndexFormat
Specifies the index data type.
Definition qrhi.h:1616
\inmodule QtGui
Definition qrhi.h:1585
\inmodule QtGui
Definition qrhi.h:1241
PolygonMode
Specifies the polygon rasterization mode.
Definition qrhi.h:1350
CompareOp
Specifies the depth or stencil comparison function.
Definition qrhi.h:1321
CullMode
Specifies the culling mode.
Definition qrhi.h:1261
Topology
Specifies the primitive topology.
Definition qrhi.h:1251
static const QRhiShaderResourceBinding::Data * shaderResourceBindingData(const QRhiShaderResourceBinding &binding)
Definition qrhi_p.h:210
\inmodule QtGui
Definition qrhi.h:1071
\inmodule QtGui
Definition qrhi.h:1119
virtual QVector< quint32 > serializedFormat() const =0
\inmodule QtGui
Definition qrhi.h:1135
\inmodule QtGui
Definition qrhi.h:1694
\inmodule QtGui
Definition qrhi.h:1007
Filter
Specifies the minification, magnification, or mipmap filtering.
Definition qrhi.h:1009
AddressMode
Specifies the addressing mode.
Definition qrhi.h:1015
@ ClampToEdge
Definition qrhi.h:1017
\inmodule QtGui
Definition qrhi.h:138
\inmodule QtGui
Definition qrhi.h:431
\inmodule QtGui
Definition qrhi.h:1190
QVector< quint32 > serializedLayoutDescription() const
Definition qrhi.h:1208
\inmodule QtGui
Definition qrhi.h:371
\inmodule QtGui
Definition qrhi.h:1161
\inmodule QtGui
Definition qrhi.h:883
Format
Specifies the type of the element data.
Definition qrhi.h:234
\inmodule QtGui
Definition qrhi.h:313
\inmodule QtGui
Definition qrhi.h:85
\inmodule QtGui
Definition qrhi.h:1767
@ MaxUniformBufferRange
Definition qrhi.h:1858
QRhiBuffer * buffer() const
QRhiCommandBuffer::IndexFormat indexFormat() const
quint32 stride() const
quint32 numVertices() const
void imageDataSizeChanges(quint64 newSize)
static bool rendererDebugEnabled()
static quint64 totalVertexCountForPass(const QSSGRhiContextStats::RenderPassInfo &pass)
void registerEffectShaderGenerationTime(qint64 ms)
void registerMaterialShaderGenerationTime(qint64 ms)
static bool profilingEnabled()
QSSGRhiContext & context
QSSGRhiContextStats(QSSGRhiContext &context)
void meshDataSizeChanges(quint64 newSize)
QHash< QSSGRenderLayer *, PerLayerInfo > perLayerInfo
static quint64 totalDrawCallCountForPass(const QSSGRhiContextStats::RenderPassInfo &pass)
QSet< QSSGRenderLayer * > dynamicDataSources
void setMainPassSampleCount(int samples)
bool isValid() const
int mainPassSampleCount() const
QSSGRhiInstanceBufferData & instanceBufferData(QSSGRenderInstanceTable *instanceTable)
void setMainRenderPassDescriptor(QRhiRenderPassDescriptor *rpDesc)
QRhiCommandBuffer * commandBuffer() const
int maxUniformBufferRange() const
static QRhiCommandBuffer::BeginPassFlags commonPassFlags()
QSet< QSSGRenderMesh * > registeredMeshes() const
QSSGRhiDrawCallData & drawCallData(const QSSGRhiDrawCallDataKey &key)
QSSGRhiContextStats & stats()
QRhi * rhi() const
QSet< QRhiTexture * > registeredTextures() const
QSSGRhiParticleData & particleData(const QSSGRenderGraphObject *particlesOrModel)
void setRenderTarget(QRhiRenderTarget *rt)
QRhiRenderTarget * renderTarget() const
QRhiRenderPassDescriptor * mainRenderPassDescriptor() const
QHash< QSSGGraphicsPipelineStateKey, QRhiGraphicsPipeline * > pipelines() const
void setCommandBuffer(QRhiCommandBuffer *cb)
QSSGRhiInstanceBufferData & instanceBufferData(const QSSGRenderModel *model)
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
Definition qset.h:18
\inmodule QtGui
Definition qshader.h:81
\inmodule QtCore
Definition qsize.h:25
\inmodule QtCore
Definition qvariant.h:64
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
Combined button and popup list for selecting options.
@ black
Definition qnamespace.h:29
static void * context
#define QByteArrayLiteral(str)
Definition qbytearray.h:52
#define Q_DECL_NOTHROW
std::pair< T1, T2 > QPair
static bool initialize()
Definition qctf.cpp:67
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:924
#define qWarning
Definition qlogging.h:162
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
GLenum GLenum GLsizei const GLuint GLboolean enabled
const void GLsizei GLsizei stride
GLenum GLuint buffer
GLenum type
GLenum GLuint GLenum GLsizei const GLchar * buf
GLbitfield flags
GLboolean enable
GLenum GLuint texture
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint start
GLenum GLuint GLintptr offset
GLuint name
GLfloat GLfloat GLfloat GLfloat h
GLuint shader
Definition qopenglext.h:665
GLdouble GLdouble t
Definition qopenglext.h:243
GLsizei GLsizei GLuint * shaders
Definition qopenglext.h:677
GLdouble s
[6]
Definition qopenglext.h:235
GLfloat GLfloat p
[1]
#define Q_QUICK3D_PROFILING_ENABLED
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QSSGRenderTextureCoordOp
QSSGRenderShaderDataType
QSSGRenderTextureFilterOp
QSSGRenderComponentType
bool operator!=(const QSSGRhiSamplerDescription &a, const QSSGRhiSamplerDescription &b) Q_DECL_NOTHROW
std::shared_ptr< QSSGRhiBuffer > QSSGRhiBufferPtr
std::shared_ptr< QSSGRhiShaderPipeline > QSSGRhiShaderPipelinePtr
QRhiSampler::Filter toRhi(QSSGRenderTextureFilterOp op)
#define QSSG_MAX_NUM_LIGHTS
bool operator==(const QSSGRhiSamplerDescription &a, const QSSGRhiSamplerDescription &b) Q_DECL_NOTHROW
QSSGRhiSamplerBindingHints
size_t qHash(const QSSGRhiGraphicsPipelineState &s, size_t seed) 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)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
unsigned int quint32
Definition qtypes.h:45
size_t quintptr
Definition qtypes.h:72
int qint32
Definition qtypes.h:44
unsigned long long quint64
Definition qtypes.h:56
ptrdiff_t qsizetype
Definition qtypes.h:70
long long qint64
Definition qtypes.h:55
unsigned char quint8
Definition qtypes.h:41
ptrdiff_t qintptr
Definition qtypes.h:71
#define enabled
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:1343
struct QSSGComputePipelineStateKey::@761 extra
static QSSGComputePipelineStateKey create(const QShader &shader, const QRhiShaderResourceBindings *srb)
QVector< quint32 > srbLayoutDescription
static QSSGGraphicsPipelineStateKey create(const QSSGRhiGraphicsPipelineState &state, const QRhiRenderPassDescriptor *rpDesc, const QRhiShaderResourceBindings *srb)
QSSGRhiGraphicsPipelineState state
QVector< quint32 > srbLayoutDescription
struct QSSGGraphicsPipelineStateKey::@759 extra
QVector< quint32 > renderTargetDescription
QVector< RenderPassInfo > renderPasses
QSSGRhiShaderResourceBindingList bindings
QSSGRhiGraphicsPipelineState ps
QRhiShaderResourceBindings * srb
QVector< quint32 > renderTargetDescription
QRhiGraphicsPipeline * pipeline
QRhiTexture::Flags flags
QSSGRhiInputAssemblerState ia
QRhiGraphicsPipeline::TargetBlend targetBlend
const QSSGRhiShaderPipeline * shaderPipeline
QVarLengthArray< InputSemantic, 8 > inputs
QRhiVertexInputLayout inputLayout
QRhiGraphicsPipeline::Topology topology
QList< QSSGRhiSortData > sortData
QList< QSSGRhiSortData > sortData
QRhiTextureRenderTarget * rt
QRhiRenderPassDescriptor * rpDesc
QRhiRenderBuffer * depthStencil
QRhiSampler::AddressMode hTiling
QRhiSampler::Filter minFilter
QRhiSampler::Filter magFilter
QRhiSampler::AddressMode vTiling
QRhiSampler::Filter mipmap
QRhiSampler::AddressMode zTiling
QVarLengthArray< ImageIndices, 16 > imageIndices
void addUniformBuffer(int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf, int offset, int size)
void addTexture(int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler)
QSSGRhiShaderResourceBindingList(const QSSGRhiShaderResourceBindingList &other)
QSSGRhiShaderResourceBindingList & operator=(const QSSGRhiShaderResourceBindingList &other) Q_DECL_NOTHROW
QSSGRhiSamplerDescription samplerDesc
QRhiTexture * texture
QSSGShaderLightData lightData[QSSG_MAX_NUM_LIGHTS]