@@ -40,8 +40,8 @@ constexpr char kLayoutMarkerBegin[] = "@@ LAYOUT-";
40
40
constexpr char kXfbDeclMarkerBegin [] = " @@ XFB-DECL" ;
41
41
constexpr char kXfbOutMarkerBegin [] = " @@ XFB-OUT" ;
42
42
constexpr char kMarkerEnd [] = " @@" ;
43
- constexpr char kLayoutParamsBegin = ' (' ;
44
- constexpr char kLayoutParamsEnd = ' )' ;
43
+ constexpr char kParamsBegin = ' (' ;
44
+ constexpr char kParamsEnd = ' )' ;
45
45
constexpr char kUniformQualifier [] = " uniform" ;
46
46
constexpr char kVersionDefine [] = " #version 450 core\n " ;
47
47
constexpr char kLineRasterDefine [] = R"( #version 450 core
@@ -101,13 +101,18 @@ class IntermediateShaderSource final : angle::NonCopyable
101
101
//
102
102
// layout(specifier, extra, args)
103
103
//
104
- // or if specifier is empty,
104
+ // or if | specifier| is empty:
105
105
//
106
106
// layout(extra, args)
107
107
//
108
108
void insertLayoutSpecifier (const std::string &name, const std::string &specifier);
109
109
110
- // Find @@ QUALIFIER-name @@ and replace it with |specifier|.
110
+ // Find @@ QUALIFIER-name(other qualifiers) @@ and replace it with:
111
+ //
112
+ // specifier other qualifiers
113
+ //
114
+ // or if |specifier| is empty, with nothing.
115
+ //
111
116
void insertQualifierSpecifier (const std::string &name, const std::string &specifier);
112
117
113
118
// Replace @@ XFB-DECL @@ with |decl|.
@@ -116,7 +121,7 @@ class IntermediateShaderSource final : angle::NonCopyable
116
121
// Replace @@ XFB-OUT @@ with |output| code block.
117
122
void insertTransformFeedbackOutput (const std::string &&output);
118
123
119
- // Remove @@ LAYOUT-name(*) @@ and @@ QUALIFIER-name @@ altogether, optionally replacing them
124
+ // Remove @@ LAYOUT-name(*) @@ and @@ QUALIFIER-name(*) @@ altogether, optionally replacing them
120
125
// with something to make sure the shader still compiles.
121
126
void eraseLayoutAndQualifierSpecifiers (const std::string &name, const std::string &replacement);
122
127
@@ -128,7 +133,7 @@ class IntermediateShaderSource final : angle::NonCopyable
128
133
{
129
134
// A piece of shader source code.
130
135
Text,
131
- // Block corresponding to @@ QUALIFIER-abc @@
136
+ // Block corresponding to @@ QUALIFIER-abc(other qualifiers) @@
132
137
Qualifier,
133
138
// Block corresponding to @@ LAYOUT-abc(extra, args) @@
134
139
Layout,
@@ -144,13 +149,13 @@ class IntermediateShaderSource final : angle::NonCopyable
144
149
// |text| contains some shader code if Text, or the id of macro ("abc" in examples above)
145
150
// being replaced if Qualifier or Layout.
146
151
std::string text;
147
- // If Layout, this contains extra parameters passed in parentheses, if any.
152
+ // If Qualifier or Layout, this contains extra parameters passed in parentheses, if any.
148
153
std::string args;
149
154
};
150
155
151
156
void addTextBlock (std::string &&text);
152
157
void addLayoutBlock (std::string &&name, std::string &&args);
153
- void addQualifierBlock (std::string &&name);
158
+ void addQualifierBlock (std::string &&name, std::string &&args );
154
159
void addTransformFeedbackDeclarationBlock ();
155
160
void addTransformFeedbackOutputBlock ();
156
161
@@ -175,10 +180,10 @@ void IntermediateShaderSource::addLayoutBlock(std::string &&name, std::string &&
175
180
mTokens .emplace_back (std::move (token));
176
181
}
177
182
178
- void IntermediateShaderSource::addQualifierBlock (std::string &&name)
183
+ void IntermediateShaderSource::addQualifierBlock (std::string &&name, std::string &&args )
179
184
{
180
185
ASSERT (!name.empty ());
181
- Token token = {TokenType::Qualifier, std::move (name), " " };
186
+ Token token = {TokenType::Qualifier, std::move (name), std::move (args) };
182
187
mTokens .emplace_back (std::move (token));
183
188
}
184
189
@@ -194,6 +199,21 @@ void IntermediateShaderSource::addTransformFeedbackOutputBlock()
194
199
mTokens .emplace_back (std::move (token));
195
200
}
196
201
202
+ size_t ExtractNameAndArgs (const std::string &source,
203
+ size_t cur,
204
+ std::string *nameOut,
205
+ std::string *argsOut)
206
+ {
207
+ *nameOut = angle::GetPrefix (source, cur, kParamsBegin );
208
+
209
+ // There should always be an extra args list (even if empty, for simplicity).
210
+ size_t readCount = nameOut->length () + 1 ;
211
+ *argsOut = angle::GetPrefix (source, cur + readCount, kParamsEnd );
212
+ readCount += argsOut->length () + 1 ;
213
+
214
+ return readCount;
215
+ }
216
+
197
217
IntermediateShaderSource::IntermediateShaderSource (const std::string &source)
198
218
{
199
219
size_t cur = 0 ;
@@ -216,21 +236,18 @@ IntermediateShaderSource::IntermediateShaderSource(const std::string &source)
216
236
{
217
237
cur += ConstStrLen (kQualifierMarkerBegin );
218
238
219
- // Get the id of the macro and add a qualifier block.
220
- std::string name = angle::GetPrefix (source, cur, kMarkerEnd ) ;
221
- cur += name. length ( );
222
- addQualifierBlock (std::move (name));
239
+ // Get the id and arguments of the macro and add a qualifier block.
240
+ std::string name, args ;
241
+ cur += ExtractNameAndArgs (source, cur, &name, &args );
242
+ addQualifierBlock (std::move (name), std::move (args) );
223
243
}
224
244
else if (source.compare (cur, ConstStrLen (kLayoutMarkerBegin ), kLayoutMarkerBegin ) == 0 )
225
245
{
226
246
cur += ConstStrLen (kLayoutMarkerBegin );
227
247
228
248
// Get the id and arguments of the macro and add a layout block.
229
- // There should always be an extra args list (even if empty, for simplicity).
230
- std::string name = angle::GetPrefix (source, cur, kLayoutParamsBegin );
231
- cur += name.length () + 1 ;
232
- std::string args = angle::GetPrefix (source, cur, kLayoutParamsEnd );
233
- cur += args.length () + 1 ;
249
+ std::string name, args;
250
+ cur += ExtractNameAndArgs (source, cur, &name, &args);
234
251
addLayoutBlock (std::move (name), std::move (args));
235
252
}
236
253
else if (source.compare (cur, ConstStrLen (kXfbDeclMarkerBegin ), kXfbDeclMarkerBegin ) == 0 )
@@ -283,6 +300,10 @@ void IntermediateShaderSource::insertQualifierSpecifier(const std::string &name,
283
300
{
284
301
block.type = TokenType::Text;
285
302
block.text = specifier;
303
+ if (!specifier.empty () && !block.args .empty ())
304
+ {
305
+ block.text += " " + block.args ;
306
+ }
286
307
break ;
287
308
}
288
309
}
0 commit comments