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
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 bool flat;
38 };
39
47
54
55 // Using QMap intentionally - while it is not strictly required to use an
56 // ordered map, being sorted by key when iterating is helpful to get the
57 // same ordered list of vertex inputs, uniforms, etc. on every run, which
58 // in turn helps shader (disk) cache efficiency due to not generating a
59 // different shader string just because QHash decided to iterate entries in
60 // a different order.
61 QMap<QByteArray, InOutVar> m_inOutVars;
62 QMap<QByteArray, Sampler> m_samplers;
63 QMap<QByteArray, BlockMember> m_uniformMembers;
64
66 QHash<int, int> m_nextFreeInLocation;
67 QHash<int, int> m_nextFreeOutLocation;
68
69 int viewCount = 1;
70
71 void registerInput(QSSGShaderGeneratorStage stage, const QByteArray &type, const QByteArray &name, bool flat = false)
72 {
73 auto it = m_inOutVars.find(name);
74 if (it != m_inOutVars.end()) {
75 it->stagesInputIn |= stage;
76 return;
77 }
78 InOutVar var { {}, stage, type, name, m_nextFreeInLocation[int(stage)]++, false, flat };
79 m_inOutVars.insert(name, var);
80 }
81
82 void registerOutput(QSSGShaderGeneratorStage stage, const QByteArray &type, const QByteArray &name, bool flat = false)
83 {
84 auto it = m_inOutVars.find(name);
85 if (it != m_inOutVars.end()) {
86 it->stageOutputFrom |= stage;
87 return;
88 }
89 InOutVar var { stage, {}, type, name, m_nextFreeOutLocation[int(stage)]++, true, flat };
90 m_inOutVars.insert(name, var);
91 }
92
94 const QByteArray &name,
96 const QByteArray &conditionName = QByteArray())
97 {
98 if (m_samplers.contains(name))
99 return;
100 Sampler var { type, name, conditionType, conditionName, m_nextFreeResourceBinding++ };
101 m_samplers.insert(name, var);
102 }
103
105 const QByteArray &name,
107 const QByteArray &conditionName = QByteArray())
108 {
109 auto it = m_uniformMembers.constFind(name);
110 if (it != m_uniformMembers.constEnd()) {
111 if (it->conditionType != conditionType) {
112 qWarning("Encountered uniform %s with different conditions, this is not supported.",
113 name.constData());
114 }
115 return;
116 }
117 BlockMember var { type, name, conditionType, conditionName };
118 m_uniformMembers.insert(name, var);
119 }
120};
121
123
124#endif
\inmodule QtCore
Definition qbytearray.h:57
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 registerInput(QSSGShaderGeneratorStage stage, const QByteArray &type, const QByteArray &name, bool flat=false)
void registerOutput(QSSGShaderGeneratorStage stage, const QByteArray &type, const QByteArray &name, bool flat=false)
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.
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
#define qWarning
Definition qlogging.h:166
GLenum type
GLuint name
QSSGRenderShaderMetadata::Uniform::Condition conditionType
QSSGRenderShaderMetadata::Uniform::Condition conditionType