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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
// 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);
SIMPLE_MODIFIER(ConstExpr);
SIMPLE_MODIFIER(GloballyCoherent)
#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)
// `__ref` modifier for by-reference parameter passing
SIMPLE_SYNTAX_CLASS(RefModifier, Modifier)
// 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(GLSLLocationLayoutModifier , GLSLParsedLayoutModifier)
SIMPLE_SYNTAX_CLASS(GLSLLocalSizeLayoutModifier, GLSLUnparsedLayoutModifier)
SIMPLE_SYNTAX_CLASS(GLSLLocalSizeXLayoutModifier, GLSLLocalSizeLayoutModifier)
SIMPLE_SYNTAX_CLASS(GLSLLocalSizeYLayoutModifier, GLSLLocalSizeLayoutModifier)
SIMPLE_SYNTAX_CLASS(GLSLLocalSizeZLayoutModifier, GLSLLocalSizeLayoutModifier)
SIMPLE_SYNTAX_CLASS(ShaderRecordNVLayoutModifier, GLSLParsedLayoutModifier)
// 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
SYNTAX_CLASS(HLSLRegisterSemantic, HLSLLayoutSemantic)
FIELD(Token, spaceName)
END_SYNTAX_CLASS()
// 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 `noperspective` modifier
SIMPLE_SYNTAX_CLASS(HLSLNoPerspectiveModifier, 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)
SYNTAX_CLASS(AttributeTargetModifier, Modifier)
// A class to which the declared attribute type is applicable
FIELD(SyntaxClass<RefObject>, syntaxClass)
END_SYNTAX_CLASS()
// Base class for checked and unchecked `[name(arg0, ...)]` style attribute.
SYNTAX_CLASS(AttributeBase, Modifier)
SYNTAX_FIELD(List<RefPtr<Expr>>, args)
END_SYNTAX_CLASS()
// A `[name(...)]` attribute that hasn't undergone any semantic analysis.
// After analysis, this will be transformed into a more specific case.
SYNTAX_CLASS(UncheckedAttribute, AttributeBase)
FIELD(RefPtr<Scope>, scope)
END_SYNTAX_CLASS()
// A `[name(arg0, ...)]` style attribute that has been validated.
SYNTAX_CLASS(Attribute, AttributeBase)
END_SYNTAX_CLASS()
// An `[unroll]` or `[unroll(count)]` attribute
SYNTAX_CLASS(UnrollAttribute, Attribute)
RAW(IntegerLiteralValue getCount();)
END_SYNTAX_CLASS()
SIMPLE_SYNTAX_CLASS(LoopAttribute, Attribute) // `[loop]`
SIMPLE_SYNTAX_CLASS(FastOptAttribute, Attribute) // `[fastopt]`
SIMPLE_SYNTAX_CLASS(AllowUAVConditionAttribute, Attribute) // `[allow_uav_condition]`
SIMPLE_SYNTAX_CLASS(BranchAttribute, Attribute) // `[branch]`
SIMPLE_SYNTAX_CLASS(FlattenAttribute, Attribute) // `[flatten]`
SIMPLE_SYNTAX_CLASS(ForceCaseAttribute, Attribute) // `[forcecase]`
SIMPLE_SYNTAX_CLASS(CallAttribute, Attribute) // `[call]`
// [[vk_push_constant]] [[push_constant]]
SIMPLE_SYNTAX_CLASS(PushConstantAttribute, Attribute)
// [[vk_binding]]
SYNTAX_CLASS(GLSLBindingAttribute, Attribute)
FIELD(int32_t, binding = 0)
FIELD(int32_t, set = 0)
END_SYNTAX_CLASS()
// TODO: for attributes that take arguments, the syntax node
// classes should provide accessors for the values of those arguments.
SIMPLE_SYNTAX_CLASS(MaxTessFactorAttribute, Attribute)
SIMPLE_SYNTAX_CLASS(OutputControlPointsAttribute, Attribute)
SIMPLE_SYNTAX_CLASS(OutputTopologyAttribute, Attribute)
SIMPLE_SYNTAX_CLASS(PartitioningAttribute, Attribute)
SYNTAX_CLASS(PatchConstantFuncAttribute, Attribute)
FIELD(RefPtr<FuncDecl>, patchConstantFuncDecl)
END_SYNTAX_CLASS()
SIMPLE_SYNTAX_CLASS(DomainAttribute, Attribute)
SIMPLE_SYNTAX_CLASS(EarlyDepthStencilAttribute, Attribute) // `[earlydepthstencil]`
// An HLSL `[numthreads(x,y,z)]` attribute
SYNTAX_CLASS(NumThreadsAttribute, Attribute)
// The number of threads to use along each axis
//
// TODO: These should be accessors that use the
// ordinary `args` list, rather than side data.
FIELD(int32_t, x)
FIELD(int32_t, y)
FIELD(int32_t, z)
END_SYNTAX_CLASS()
SYNTAX_CLASS(MaxVertexCountAttribute, Attribute)
// The number of max vertex count for geometry shader
//
// TODO: This should be an accessor that uses the
// ordinary `args` list, rather than side data.
FIELD(int32_t, value)
END_SYNTAX_CLASS()
SYNTAX_CLASS(InstanceAttribute, Attribute)
// The number of instances to run for geometry shader
//
// TODO: This should be an accessor that uses the
// ordinary `args` list, rather than side data.
FIELD(int32_t, value)
END_SYNTAX_CLASS()
// A `[shader("stageName")]` attribute, which marks an entry point
// to be compiled, and specifies the stage for that entry point
SYNTAX_CLASS(EntryPointAttribute, Attribute)
// The resolved stage that the entry point is targetting.
//
// TODO: This should be an accessor that uses the
// ordinary `args` list, rather than side data.
FIELD(Stage, stage);
END_SYNTAX_CLASS()
// A `[__vulkanRayPayload]` attribute, which is used in the
// standard library implementation to indicate that a variable
// actually represents the input/output interface for a Vulkan
// ray tracing shader to pass per-ray payload information.
SIMPLE_SYNTAX_CLASS(VulkanRayPayloadAttribute, Attribute)
// A `[__vulkanCallablePayload]` attribute, which is used in the
// standard library implementation to indicate that a variable
// actually represents the input/output interface for a Vulkan
// ray tracing shader to pass payload information to/from a callee.
SIMPLE_SYNTAX_CLASS(VulkanCallablePayloadAttribute, Attribute)
// A `[__vulkanHitAttributes]` attribute, which is used in the
// standard library implementation to indicate that a variable
// actually represents the output interface for a Vulkan
// intersection shader to pass hit attribute information.
SIMPLE_SYNTAX_CLASS(VulkanHitAttributesAttribute, Attribute)
// A `[mutating]` attribute, which indicates that a member
// function is allowed to modify things through its `this`
// argument.
//
SIMPLE_SYNTAX_CLASS(MutatingAttribute, Attribute)
// A `[__readNone]` attribute, which indicates that a function
// computes its results strictly based on argument values, without
// reading or writing through any pointer arguments, or any other
// state that could be observed by a caller.
//
SIMPLE_SYNTAX_CLASS(ReadNoneAttribute, Attribute)
// 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()
|