1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
// modifier-defs.h
// Syntax class definitions for modifiers.
// Simple modifiers have no state beyond their identity
#define SIMPLE_MODIFIER(NAME) \
SIMPLE_SYNTAX_CLASS(NAME##Modifier, Modifier)
SIMPLE_MODIFIER(In);
SIMPLE_MODIFIER(Out);
SIMPLE_MODIFIER(Const);
SIMPLE_MODIFIER(Instance);
SIMPLE_MODIFIER(Builtin);
SIMPLE_MODIFIER(Inline);
SIMPLE_MODIFIER(Public);
SIMPLE_MODIFIER(Require);
SIMPLE_MODIFIER(Param);
SIMPLE_MODIFIER(Extern);
SIMPLE_MODIFIER(Input);
SIMPLE_MODIFIER(Transparent);
SIMPLE_MODIFIER(FromStdLib);
SIMPLE_MODIFIER(Prefix);
SIMPLE_MODIFIER(Postfix);
SIMPLE_MODIFIER(Exported);
#undef SIMPLE_MODIFIER
// A modifier that marks something as an operation that
// has a one-to-one translation to the IR, and thus
// has no direct definition in the high-level language.
//
SYNTAX_CLASS(IntrinsicOpModifier, Modifier)
// token that names the intrinsic op
FIELD(Token, opToken)
// The opcode for the intrinsic operation
FIELD_INIT(IROp, op, kIROp_Nop)
END_SYNTAX_CLASS()
// A modifier that marks something as an intrinsic function,
// for some subset of targets.
SYNTAX_CLASS(TargetIntrinsicModifier, Modifier)
// Token that names the target that the operation
// is an intrisic for.
FIELD(Token, targetToken)
// A custom definition for the operation
FIELD(Token, definitionToken)
END_SYNTAX_CLASS()
// A modifier that marks a declaration as representing a
// specialization that should be preferred on a particular
// target.
SYNTAX_CLASS(SpecializedForTargetModifier, Modifier)
// Token that names the target that the operation
// has been specialized for.
FIELD(Token, targetToken)
END_SYNTAX_CLASS()
// A modifier to tag something as an intrinsic that requires
// a certain GLSL extension to be enabled when used
SYNTAX_CLASS(RequiredGLSLExtensionModifier, Modifier)
FIELD(Token, extensionNameToken)
END_SYNTAX_CLASS()
// A modifier to tag something as an intrinsic that requires
// a certain GLSL version to be enabled when used
SYNTAX_CLASS(RequiredGLSLVersionModifier, Modifier)
FIELD(Token, versionNumberToken)
END_SYNTAX_CLASS()
SIMPLE_SYNTAX_CLASS(InOutModifier, OutModifier)
// This is a special sentinel modifier that gets added
// to the list when we have multiple variable declarations
// all sharing the same modifiers:
//
// static uniform int a : FOO, *b : register(x0);
//
// In this case both `a` and `b` share the syntax
// for part of their modifier list, but then have
// their own modifiers as well:
//
// a: SemanticModifier("FOO") --> SharedModifiers --> StaticModifier --> UniformModifier
// /
// b: RegisterModifier("x0") /
//
SIMPLE_SYNTAX_CLASS(SharedModifiers, Modifier)
// A GLSL `layout` modifier
//
// We use a distinct modifier for each key that
// appears within the `layout(...)` construct,
// and each key might have an optional value token.
//
// TODO: We probably want a notion of "modifier groups"
// so that we can recover good source location info
// for modifiers that were part of the same vs.
// different constructs.
ABSTRACT_SYNTAX_CLASS(GLSLLayoutModifier, Modifier)
// The token used to introduce the modifier is stored
// as the `nameToken` field.
// TODO: may want to accept a full expression here
FIELD(Token, valToken)
END_SYNTAX_CLASS()
// AST nodes to represent the begin/end of a `layout` modifier group
ABSTRACT_SYNTAX_CLASS(GLSLLayoutModifierGroupMarker, Modifier)
END_SYNTAX_CLASS()
SIMPLE_SYNTAX_CLASS(GLSLLayoutModifierGroupBegin, GLSLLayoutModifierGroupMarker)
SIMPLE_SYNTAX_CLASS(GLSLLayoutModifierGroupEnd, GLSLLayoutModifierGroupMarker)
// We divide GLSL `layout` modifiers into those we have parsed
// (in the sense of having some notion of their semantics), and
// those we have not.
ABSTRACT_SYNTAX_CLASS(GLSLParsedLayoutModifier , GLSLLayoutModifier)
END_SYNTAX_CLASS()
SIMPLE_SYNTAX_CLASS(GLSLUnparsedLayoutModifier , GLSLLayoutModifier)
// Specific cases for known GLSL `layout` modifiers that we need to work with
SIMPLE_SYNTAX_CLASS(GLSLConstantIDLayoutModifier , GLSLParsedLayoutModifier)
SIMPLE_SYNTAX_CLASS(GLSLBindingLayoutModifier , GLSLParsedLayoutModifier)
SIMPLE_SYNTAX_CLASS(GLSLSetLayoutModifier , GLSLParsedLayoutModifier)
SIMPLE_SYNTAX_CLASS(GLSLLocationLayoutModifier , GLSLParsedLayoutModifier)
SIMPLE_SYNTAX_CLASS(GLSLPushConstantLayoutModifier, GLSLParsedLayoutModifier)
SIMPLE_SYNTAX_CLASS(GLSLLocalSizeLayoutModifier, GLSLUnparsedLayoutModifier)
SIMPLE_SYNTAX_CLASS(GLSLLocalSizeXLayoutModifier, GLSLLocalSizeLayoutModifier)
SIMPLE_SYNTAX_CLASS(GLSLLocalSizeYLayoutModifier, GLSLLocalSizeLayoutModifier)
SIMPLE_SYNTAX_CLASS(GLSLLocalSizeZLayoutModifier, GLSLLocalSizeLayoutModifier)
// A catch-all for single-keyword modifiers
SIMPLE_SYNTAX_CLASS(SimpleModifier, Modifier)
// Some GLSL-specific modifiers
SIMPLE_SYNTAX_CLASS(GLSLBufferModifier , SimpleModifier)
SIMPLE_SYNTAX_CLASS(GLSLWriteOnlyModifier, SimpleModifier)
SIMPLE_SYNTAX_CLASS(GLSLReadOnlyModifier , SimpleModifier)
SIMPLE_SYNTAX_CLASS(GLSLPatchModifier , SimpleModifier)
// Indicates that this is a variable declaration that corresponds to
// a parameter block declaration in the source program.
SIMPLE_SYNTAX_CLASS(ImplicitParameterGroupVariableModifier , Modifier)
// Indicates that this is a type that corresponds to the element
// type of a parameter block declaration in the source program.
SIMPLE_SYNTAX_CLASS(ImplicitParameterGroupElementTypeModifier, Modifier)
// An HLSL semantic
ABSTRACT_SYNTAX_CLASS(HLSLSemantic, Modifier)
FIELD(Token, name)
END_SYNTAX_CLASS()
// An HLSL semantic that affects layout
SYNTAX_CLASS(HLSLLayoutSemantic, HLSLSemantic)
FIELD(Token, registerName)
FIELD(Token, componentMask)
END_SYNTAX_CLASS()
// An HLSL `register` semantic
SIMPLE_SYNTAX_CLASS(HLSLRegisterSemantic, HLSLLayoutSemantic)
// TODO(tfoley): `packoffset`
SIMPLE_SYNTAX_CLASS(HLSLPackOffsetSemantic, HLSLLayoutSemantic)
// An HLSL semantic that just associated a declaration with a semantic name
SIMPLE_SYNTAX_CLASS(HLSLSimpleSemantic, HLSLSemantic)
// GLSL
// Directives that came in via the preprocessor, but
// that we need to keep around for later steps
SIMPLE_SYNTAX_CLASS(GLSLPreprocessorDirective, Modifier)
// A GLSL `#version` directive
SYNTAX_CLASS(GLSLVersionDirective, GLSLPreprocessorDirective)
// Token giving the version number to use
FIELD(Token, versionNumberToken)
// Optional token giving the sub-profile to be used
FIELD(Token, glslProfileToken)
END_SYNTAX_CLASS()
// A GLSL `#extension` directive
SYNTAX_CLASS(GLSLExtensionDirective, GLSLPreprocessorDirective)
// Token giving the version number to use
FIELD(Token, extensionNameToken)
// Optional token giving the sub-profile to be used
FIELD(Token, dispositionToken)
END_SYNTAX_CLASS()
SYNTAX_CLASS(ParameterGroupReflectionName, Modifier)
FIELD(NameLoc, nameAndLoc)
END_SYNTAX_CLASS()
// A modifier that indicates a built-in base type (e.g., `float`)
SYNTAX_CLASS(BuiltinTypeModifier, Modifier)
FIELD(BaseType, tag)
END_SYNTAX_CLASS()
// A modifier that indicates a built-in type that isn't a base type (e.g., `vector`)
//
// TODO(tfoley): This deserves a better name than "magic"
SYNTAX_CLASS(MagicTypeModifier, Modifier)
FIELD(String, name)
FIELD(uint32_t, tag)
END_SYNTAX_CLASS()
// A modifier applied to declarations of builtin types to indicate how they
// should be lowered to the IR.
//
// TODO: This should really subsume `BuiltinTypeModifier` and
// `MagicTypeModifier` so that we don't have to apply all of them.
SYNTAX_CLASS(IntrinsicTypeModifier, Modifier)
// The IR opcode to use when constructing a type
FIELD(uint32_t, irOp)
// Additional literal opreands to provide when creating instances.
// (e.g., for a texture type this passes in shape/mutability info)
FIELD(List<uint32_t>, irOperands)
END_SYNTAX_CLASS()
// Modifiers that affect the storage layout for matrices
SIMPLE_SYNTAX_CLASS(MatrixLayoutModifier, Modifier)
// Modifiers that specify row- and column-major layout, respectively
SIMPLE_SYNTAX_CLASS(RowMajorLayoutModifier, MatrixLayoutModifier)
SIMPLE_SYNTAX_CLASS(ColumnMajorLayoutModifier, MatrixLayoutModifier)
// The HLSL flavor of those modifiers
SIMPLE_SYNTAX_CLASS(HLSLRowMajorLayoutModifier, RowMajorLayoutModifier)
SIMPLE_SYNTAX_CLASS(HLSLColumnMajorLayoutModifier, ColumnMajorLayoutModifier)
// The GLSL flavor of those modifiers
//
// Note(tfoley): The GLSL versions of these modifiers are "backwards"
// in the sense that when a GLSL programmer requests row-major layout,
// we actually interpret that as requesting column-major. This makes
// sense because we interpret matrix conventions backwards from how
// GLSL specifies them.
SIMPLE_SYNTAX_CLASS(GLSLRowMajorLayoutModifier, ColumnMajorLayoutModifier)
SIMPLE_SYNTAX_CLASS(GLSLColumnMajorLayoutModifier, RowMajorLayoutModifier)
// More HLSL Keyword
ABSTRACT_SYNTAX_CLASS(InterpolationModeModifier, Modifier)
END_SYNTAX_CLASS()
// HLSL `nointerpolation` modifier
SIMPLE_SYNTAX_CLASS(HLSLNoInterpolationModifier, InterpolationModeModifier)
// HLSL `linear` modifier
SIMPLE_SYNTAX_CLASS(HLSLLinearModifier, InterpolationModeModifier)
// HLSL `sample` modifier
SIMPLE_SYNTAX_CLASS(HLSLSampleModifier, InterpolationModeModifier)
// HLSL `centroid` modifier
SIMPLE_SYNTAX_CLASS(HLSLCentroidModifier, InterpolationModeModifier)
// HLSL `precise` modifier
SIMPLE_SYNTAX_CLASS(HLSLPreciseModifier, Modifier)
// HLSL `shared` modifier (which is used by the effect system,
// and shouldn't be confused with `groupshared`)
SIMPLE_SYNTAX_CLASS(HLSLEffectSharedModifier, Modifier)
// HLSL `groupshared` modifier
SIMPLE_SYNTAX_CLASS(HLSLGroupSharedModifier, Modifier)
// HLSL `static` modifier (probably doesn't need to be
// treated as HLSL-specific)
SIMPLE_SYNTAX_CLASS(HLSLStaticModifier, Modifier)
// HLSL `uniform` modifier (distinct meaning from GLSL
// use of the keyword)
SIMPLE_SYNTAX_CLASS(HLSLUniformModifier, Modifier)
// HLSL `volatile` modifier (ignored)
SIMPLE_SYNTAX_CLASS(HLSLVolatileModifier, Modifier)
// An HLSL `[name(arg0, ...)]` style attribute.
SYNTAX_CLASS(HLSLAttribute, Modifier)
SYNTAX_FIELD(List<RefPtr<Expr>>, args)
END_SYNTAX_CLASS()
// An HLSL `[name(...)]` attribute that hasn't undergone
// any semantic analysis.
// After analysis, this might be transformed into a more specific case.
SIMPLE_SYNTAX_CLASS(HLSLUncheckedAttribute, HLSLAttribute)
// An HLSL `[numthreads(x,y,z)]` attribute
SYNTAX_CLASS(HLSLNumThreadsAttribute, HLSLAttribute)
// The number of threads to use along each axis
FIELD(int32_t, x)
FIELD(int32_t, y)
FIELD(int32_t, z)
END_SYNTAX_CLASS()
SYNTAX_CLASS(HLSLMaxVertexCountAttribute, HLSLAttribute)
// The number of max vertex count for geometry shader
FIELD(int32_t, value)
END_SYNTAX_CLASS()
SYNTAX_CLASS(HLSLInstanceAttribute, HLSLAttribute)
// The number of instances to run for geometry shader
FIELD(int32_t, value)
END_SYNTAX_CLASS()
// HLSL modifiers for geometry shader input topology
SIMPLE_SYNTAX_CLASS(HLSLGeometryShaderInputPrimitiveTypeModifier, Modifier)
SIMPLE_SYNTAX_CLASS(HLSLPointModifier , HLSLGeometryShaderInputPrimitiveTypeModifier)
SIMPLE_SYNTAX_CLASS(HLSLLineModifier , HLSLGeometryShaderInputPrimitiveTypeModifier)
SIMPLE_SYNTAX_CLASS(HLSLTriangleModifier , HLSLGeometryShaderInputPrimitiveTypeModifier)
SIMPLE_SYNTAX_CLASS(HLSLLineAdjModifier , HLSLGeometryShaderInputPrimitiveTypeModifier)
SIMPLE_SYNTAX_CLASS(HLSLTriangleAdjModifier , HLSLGeometryShaderInputPrimitiveTypeModifier)
// A modifier to be attached to syntax after we've computed layout
SYNTAX_CLASS(ComputedLayoutModifier, Modifier)
FIELD(RefPtr<Layout>, layout)
END_SYNTAX_CLASS()
SYNTAX_CLASS(TupleVarModifier, Modifier)
// FIELD_INIT(TupleFieldModifier*, tupleField, nullptr)
END_SYNTAX_CLASS()
// A modifier to indicate that a constructor/initializer can be used
// to perform implicit type conversion, and to specify the cost of
// the conversion, if applied.
SYNTAX_CLASS(ImplicitConversionModifier, Modifier)
// The conversion cost, used to rank conversions
FIELD(ConversionCost, cost)
END_SYNTAX_CLASS()
// A marker modifier used to indicate that a declaration was created as
// part of type legalization.
SYNTAX_CLASS(LegalizedModifier, Modifier)
FIELD(String, originalMangledName)
END_SYNTAX_CLASS()
|