Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qssgshaderresourcemergecontext_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 QSSGSHADERRESOURCEMERGECONTEXT_P_H
5#define QSSGSHADERRESOURCEMERGECONTEXT_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
20
22
24{
25public:
26 // Resource bindings 0..2 are reserved for uniform buffers.
27 // (0 is cbMain, 1 is cbLights)
29
30 struct InOutVar {
31 QSSGShaderGeneratorStageFlags stageOutputFrom;
32 QSSGShaderGeneratorStageFlags stagesInputIn;
36 bool output;
37 };
38
39 struct Sampler {
45 };
46
47 struct BlockMember {
52 };
53
54 // Using QMap intentionally - while it is not strictly required to use an
55 // ordered map, being sorted by key when iterating is helpful to get the
56 // same ordered list of vertex inputs, uniforms, etc. on every run, which
57 // in turn helps shader (disk) cache efficiency due to not generating a
58 // different shader string just because QHash decided to iterate entries in
59 // a different order.
63
67
69 {
70 auto it = m_inOutVars.find(name);
71 if (it != m_inOutVars.end()) {
72 it->stagesInputIn |= stage;
73 return;
74 }
75 InOutVar var { {}, stage, type, name, m_nextFreeInLocation[int(stage)]++, false };
76 m_inOutVars.insert(name, var);
77 }
78
80 {
81 auto it = m_inOutVars.find(name);
82 if (it != m_inOutVars.end()) {
83 it->stageOutputFrom |= stage;
84 return;
85 }
86 InOutVar var { stage, {}, type, name, m_nextFreeOutLocation[int(stage)]++, true };
87 m_inOutVars.insert(name, var);
88 }
89
91 const QByteArray &name,
93 const QByteArray &conditionName = QByteArray())
94 {
95 if (m_samplers.contains(name))
96 return;
97 Sampler var { type, name, conditionType, conditionName, m_nextFreeResourceBinding++ };
98 m_samplers.insert(name, var);
99 }
100
102 const QByteArray &name,
104 const QByteArray &conditionName = QByteArray())
105 {
106 auto it = m_uniformMembers.constFind(name);
107 if (it != m_uniformMembers.constEnd()) {
108 if (it->conditionType != conditionType) {
109 qWarning("Encountered uniform %s with different conditions, this is not supported.",
110 name.constData());
111 }
112 return;
113 }
114 BlockMember var { type, name, conditionType, conditionName };
115 m_uniformMembers.insert(name, var);
116 }
117};
118
120
121#endif
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qhash.h:818
Definition qmap.h:186
void registerInput(QSSGShaderGeneratorStage stage, const QByteArray &type, const QByteArray &name)
void registerOutput(QSSGShaderGeneratorStage stage, const QByteArray &type, const QByteArray &name)
QMap< QByteArray, BlockMember > m_uniformMembers
void registerSampler(const QByteArray &type, const QByteArray &name, QSSGRenderShaderMetadata::Uniform::Condition conditionType=QSSGRenderShaderMetadata::Uniform::None, const QByteArray &conditionName=QByteArray())
void registerUniformMember(const QByteArray &type, const QByteArray &name, QSSGRenderShaderMetadata::Uniform::Condition conditionType=QSSGRenderShaderMetadata::Uniform::None, const QByteArray &conditionName=QByteArray())
QSet< QString >::iterator it
Combined button and popup list for selecting options.
#define qWarning
Definition qlogging.h:162
GLenum type
GLuint name
QSSGRenderShaderMetadata::Uniform::Condition conditionType
QSSGRenderShaderMetadata::Uniform::Condition conditionType