@zephyr3d/device 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/base_types.js +602 -0
  2. package/dist/base_types.js.map +1 -0
  3. package/dist/builder/ast.js +2135 -0
  4. package/dist/builder/ast.js.map +1 -0
  5. package/dist/builder/base.js +477 -0
  6. package/dist/builder/base.js.map +1 -0
  7. package/dist/builder/builtinfunc.js +4101 -0
  8. package/dist/builder/builtinfunc.js.map +1 -0
  9. package/dist/builder/constructors.js +173 -0
  10. package/dist/builder/constructors.js.map +1 -0
  11. package/dist/builder/errors.js +148 -0
  12. package/dist/builder/errors.js.map +1 -0
  13. package/dist/builder/programbuilder.js +2323 -0
  14. package/dist/builder/programbuilder.js.map +1 -0
  15. package/dist/builder/reflection.js +60 -0
  16. package/dist/builder/reflection.js.map +1 -0
  17. package/dist/builder/types.js +1563 -0
  18. package/dist/builder/types.js.map +1 -0
  19. package/dist/device.js +515 -0
  20. package/dist/device.js.map +1 -0
  21. package/dist/gpuobject.js +2047 -0
  22. package/dist/gpuobject.js.map +1 -0
  23. package/dist/helpers/drawtext.js +187 -0
  24. package/dist/helpers/drawtext.js.map +1 -0
  25. package/dist/helpers/font.js +189 -0
  26. package/dist/helpers/font.js.map +1 -0
  27. package/dist/helpers/glyphmanager.js +121 -0
  28. package/dist/helpers/glyphmanager.js.map +1 -0
  29. package/dist/helpers/textureatlas.js +170 -0
  30. package/dist/helpers/textureatlas.js.map +1 -0
  31. package/dist/index.d.ts +3873 -0
  32. package/dist/index.js +16 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/timer.js +38 -0
  35. package/dist/timer.js.map +1 -0
  36. package/dist/uniformdata.js +147 -0
  37. package/dist/uniformdata.js.map +1 -0
  38. package/dist/vertexdata.js +135 -0
  39. package/dist/vertexdata.js.map +1 -0
  40. package/package.json +69 -0
@@ -0,0 +1,2135 @@
1
+ import { ShaderType } from '../base_types.js';
2
+ import { semanticToAttrib } from '../gpuobject.js';
3
+ import { PBPrimitiveTypeInfo, PBPrimitiveType, PBTextureType, PBAddressSpace, PBPointerTypeInfo, typeBool, typeF32, typeI32, typeU32, typeVoid } from './types.js';
4
+ import { PBASTError, PBTypeCastError, PBInternalError, PBParamTypeError } from './errors.js';
5
+
6
+ const BuiltinInputStructNameVS = 'uu_VSInput';
7
+ const BuiltinOutputStructNameVS = 'uu_VSOutput';
8
+ const BuiltinInputStructNameFS = 'uu_FSInput';
9
+ const BuiltinOutputStructNameFS = 'uu_FSOutput';
10
+ const BuiltinInputStructNameCS = 'uu_CSInput';
11
+ const BuiltinOutputStructNameCS = 'uu_CSOutput';
12
+ const BuiltinInputStructInstanceNameVS = 'uu_VSInputCpy';
13
+ const BuiltinOutputStructInstanceNameVS = 'uu_VSOutputCpy';
14
+ const BuiltinInputStructInstanceNameFS = 'uu_FSInputCpy';
15
+ const BuiltinOutputStructInstanceNameFS = 'uu_FSOutputCpy';
16
+ const BuiltinInputStructInstanceNameCS = 'uu_CSInputCpy';
17
+ const BuiltinOutputStructInstanceNameCS = 'uu_CSOutputCpy';
18
+ var DeclareType;
19
+ (function(DeclareType) {
20
+ DeclareType[DeclareType["DECLARE_TYPE_NONE"] = 0] = "DECLARE_TYPE_NONE";
21
+ DeclareType[DeclareType["DECLARE_TYPE_IN"] = 1] = "DECLARE_TYPE_IN";
22
+ DeclareType[DeclareType["DECLARE_TYPE_OUT"] = 2] = "DECLARE_TYPE_OUT";
23
+ DeclareType[DeclareType["DECLARE_TYPE_WORKGROUP"] = 3] = "DECLARE_TYPE_WORKGROUP";
24
+ DeclareType[DeclareType["DECLARE_TYPE_UNIFORM"] = 4] = "DECLARE_TYPE_UNIFORM";
25
+ DeclareType[DeclareType["DECLARE_TYPE_STORAGE"] = 5] = "DECLARE_TYPE_STORAGE";
26
+ })(DeclareType || (DeclareType = {}));
27
+ var ShaderPrecisionType;
28
+ (function(ShaderPrecisionType) {
29
+ ShaderPrecisionType[ShaderPrecisionType["NONE"] = 0] = "NONE";
30
+ ShaderPrecisionType[ShaderPrecisionType["HIGH"] = 1] = "HIGH";
31
+ ShaderPrecisionType[ShaderPrecisionType["MEDIUM"] = 2] = "MEDIUM";
32
+ ShaderPrecisionType[ShaderPrecisionType["LOW"] = 3] = "LOW";
33
+ })(ShaderPrecisionType || (ShaderPrecisionType = {}));
34
+ /** @internal */ function getBuiltinInputStructInstanceName(shaderType) {
35
+ switch(shaderType){
36
+ case ShaderType.Vertex:
37
+ return BuiltinInputStructInstanceNameVS;
38
+ case ShaderType.Fragment:
39
+ return BuiltinInputStructInstanceNameFS;
40
+ case ShaderType.Compute:
41
+ return BuiltinInputStructInstanceNameCS;
42
+ default:
43
+ return null;
44
+ }
45
+ }
46
+ /** @internal */ function getBuiltinOutputStructInstanceName(shaderType) {
47
+ switch(shaderType){
48
+ case ShaderType.Vertex:
49
+ return BuiltinOutputStructInstanceNameVS;
50
+ case ShaderType.Fragment:
51
+ return BuiltinOutputStructInstanceNameFS;
52
+ case ShaderType.Compute:
53
+ return BuiltinOutputStructInstanceNameCS;
54
+ default:
55
+ return null;
56
+ }
57
+ }
58
+ /** @internal */ function getBuiltinInputStructName(shaderType) {
59
+ switch(shaderType){
60
+ case ShaderType.Vertex:
61
+ return BuiltinInputStructNameVS;
62
+ case ShaderType.Fragment:
63
+ return BuiltinInputStructNameFS;
64
+ case ShaderType.Compute:
65
+ return BuiltinInputStructNameCS;
66
+ default:
67
+ return null;
68
+ }
69
+ }
70
+ /** @internal */ function getBuiltinOutputStructName(shaderType) {
71
+ switch(shaderType){
72
+ case ShaderType.Vertex:
73
+ return BuiltinOutputStructNameVS;
74
+ case ShaderType.Fragment:
75
+ return BuiltinOutputStructNameFS;
76
+ case ShaderType.Compute:
77
+ return BuiltinOutputStructNameCS;
78
+ default:
79
+ return null;
80
+ }
81
+ }
82
+ /** @internal */ function getTextureSampleType(type) {
83
+ switch(type.textureType){
84
+ case PBTextureType.TEX_1D:
85
+ case PBTextureType.TEX_STORAGE_1D:
86
+ case PBTextureType.TEX_2D:
87
+ case PBTextureType.TEX_STORAGE_2D:
88
+ case PBTextureType.TEX_2D_ARRAY:
89
+ case PBTextureType.TEX_STORAGE_2D_ARRAY:
90
+ case PBTextureType.TEX_3D:
91
+ case PBTextureType.TEX_STORAGE_3D:
92
+ case PBTextureType.TEX_CUBE:
93
+ case PBTextureType.TEX_EXTERNAL:
94
+ return new PBPrimitiveTypeInfo(PBPrimitiveType.F32VEC4);
95
+ case PBTextureType.TEX_DEPTH_2D_ARRAY:
96
+ case PBTextureType.TEX_DEPTH_2D:
97
+ case PBTextureType.TEX_DEPTH_CUBE:
98
+ return new PBPrimitiveTypeInfo(PBPrimitiveType.F32);
99
+ case PBTextureType.ITEX_2D_ARRAY:
100
+ case PBTextureType.ITEX_1D:
101
+ case PBTextureType.ITEX_2D:
102
+ case PBTextureType.ITEX_3D:
103
+ case PBTextureType.ITEX_CUBE:
104
+ return new PBPrimitiveTypeInfo(PBPrimitiveType.I32);
105
+ case PBTextureType.UTEX_2D_ARRAY:
106
+ case PBTextureType.UTEX_1D:
107
+ case PBTextureType.UTEX_2D:
108
+ case PBTextureType.UTEX_3D:
109
+ case PBTextureType.UTEX_CUBE:
110
+ return new PBPrimitiveTypeInfo(PBPrimitiveType.U32);
111
+ default:
112
+ return null;
113
+ }
114
+ }
115
+ /** @internal */ function genSamplerName(textureName, comparison) {
116
+ return `ch_auto_sampler_${textureName}${comparison ? '_comparison' : ''}`;
117
+ }
118
+ /** @internal */ const builtinVariables = {
119
+ webgl: {
120
+ position: {
121
+ name: 'gl_Position',
122
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.F32VEC4),
123
+ stage: 'vertex'
124
+ },
125
+ pointSize: {
126
+ name: 'gl_PointSize',
127
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.F32),
128
+ stage: 'vertex'
129
+ },
130
+ fragCoord: {
131
+ name: 'gl_FragCoord',
132
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.F32VEC4),
133
+ stage: 'fragment'
134
+ },
135
+ frontFacing: {
136
+ name: 'gl_FrontFacing',
137
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.BOOL),
138
+ stage: 'fragment'
139
+ },
140
+ fragDepth: {
141
+ name: 'gl_FragDepthEXT',
142
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.F32),
143
+ inOrOut: 'out',
144
+ extension: 'GL_EXT_frag_depth',
145
+ stage: 'fragment'
146
+ }
147
+ },
148
+ webgl2: {
149
+ vertexIndex: {
150
+ name: 'gl_VertexID',
151
+ semantic: 'vertex_index',
152
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.U32),
153
+ inOrOut: 'in',
154
+ stage: 'vertex'
155
+ },
156
+ instanceIndex: {
157
+ name: 'gl_InstanceID',
158
+ semantic: 'instance_index',
159
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.U32),
160
+ inOrOut: 'in',
161
+ stage: 'vertex'
162
+ },
163
+ position: {
164
+ name: 'gl_Position',
165
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.F32VEC4),
166
+ stage: 'vertex'
167
+ },
168
+ pointSize: {
169
+ name: 'gl_PointSize',
170
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.F32),
171
+ stage: 'vertex'
172
+ },
173
+ fragCoord: {
174
+ name: 'gl_FragCoord',
175
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.F32VEC4),
176
+ stage: 'fragment'
177
+ },
178
+ frontFacing: {
179
+ name: 'gl_FrontFacing',
180
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.BOOL),
181
+ stage: 'fragment'
182
+ },
183
+ fragDepth: {
184
+ name: 'gl_FragDepth',
185
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.F32),
186
+ stage: 'fragment'
187
+ }
188
+ },
189
+ webgpu: {
190
+ vertexIndex: {
191
+ name: 'ch_builtin_vertexIndex',
192
+ semantic: 'vertex_index',
193
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.U32),
194
+ inOrOut: 'in',
195
+ stage: 'vertex'
196
+ },
197
+ instanceIndex: {
198
+ name: 'ch_builtin_instanceIndex',
199
+ semantic: 'instance_index',
200
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.U32),
201
+ inOrOut: 'in',
202
+ stage: 'vertex'
203
+ },
204
+ position: {
205
+ name: 'ch_builtin_position',
206
+ semantic: 'position',
207
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.F32VEC4),
208
+ inOrOut: 'out',
209
+ stage: 'vertex'
210
+ },
211
+ fragCoord: {
212
+ name: 'ch_builtin_fragCoord',
213
+ semantic: 'position',
214
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.F32VEC4),
215
+ inOrOut: 'in',
216
+ stage: 'fragment'
217
+ },
218
+ frontFacing: {
219
+ name: 'ch_builtin_frontFacing',
220
+ semantic: 'front_facing',
221
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.BOOL),
222
+ inOrOut: 'in',
223
+ stage: 'fragment'
224
+ },
225
+ fragDepth: {
226
+ name: 'ch_builtin_fragDepth',
227
+ semantic: 'frag_depth',
228
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.F32),
229
+ inOrOut: 'out',
230
+ stage: 'fragment'
231
+ },
232
+ localInvocationId: {
233
+ name: 'ch_builtin_localInvocationId',
234
+ semantic: 'local_invocation_id',
235
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.U32VEC3),
236
+ inOrOut: 'in',
237
+ stage: 'compute'
238
+ },
239
+ globalInvocationId: {
240
+ name: 'ch_builtin_globalInvocationId',
241
+ semantic: 'global_invocation_id',
242
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.U32VEC3),
243
+ inOrOut: 'in',
244
+ stage: 'compute'
245
+ },
246
+ workGroupId: {
247
+ name: 'ch_builtin_workGroupId',
248
+ semantic: 'workgroup_id',
249
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.U32VEC3),
250
+ inOrOut: 'in',
251
+ stage: 'compute'
252
+ },
253
+ numWorkGroups: {
254
+ name: 'ch_builtin_numWorkGroups',
255
+ semantic: 'num_workgroups',
256
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.U32VEC3),
257
+ inOrOut: 'in',
258
+ stage: 'compute'
259
+ },
260
+ sampleMaskIn: {
261
+ name: 'ch_builtin_sampleMaskIn',
262
+ semantic: 'sample_mask_in',
263
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.U32),
264
+ inOrOut: 'in',
265
+ stage: 'fragment'
266
+ },
267
+ sampleMaskOut: {
268
+ name: 'ch_builtin_sampleMaskOut',
269
+ semantic: 'sample_mask_out',
270
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.U32),
271
+ inOrOut: 'out',
272
+ stage: 'fragment'
273
+ },
274
+ sampleIndex: {
275
+ name: 'ch_builtin_sampleIndex',
276
+ semantic: 'sample_index',
277
+ type: new PBPrimitiveTypeInfo(PBPrimitiveType.U32),
278
+ inOrOut: 'in',
279
+ stage: 'fragment'
280
+ }
281
+ }
282
+ };
283
+ function toFixed(n) {
284
+ return n % 1 === 0 ? n.toFixed(1) : String(n);
285
+ }
286
+ function toInt(n) {
287
+ return String(n | 0);
288
+ }
289
+ function toUint(n) {
290
+ return String(n >>> 0);
291
+ }
292
+ function unbracket(e) {
293
+ e = e.trim();
294
+ if (e[0] === '(' && e[e.length - 1] === ')') {
295
+ let match = 0;
296
+ for(let i = 1; i < e.length - 1; i++){
297
+ if (e[i] === '(') {
298
+ match++;
299
+ } else if (e[i] === ')') {
300
+ match--;
301
+ if (match < 0) {
302
+ break;
303
+ }
304
+ }
305
+ }
306
+ if (match > 0) {
307
+ throw new PBInternalError(`Invalid expression: ${e}`);
308
+ } else if (match === 0) {
309
+ return e.substring(1, e.length - 1);
310
+ }
311
+ }
312
+ return e;
313
+ }
314
+ /** @internal */ class ShaderAST {
315
+ isReference() {
316
+ return false;
317
+ }
318
+ isPointer() {
319
+ return !!this.getType()?.isPointerType();
320
+ }
321
+ getType() {
322
+ return null;
323
+ }
324
+ toWebGL(indent, ctx) {
325
+ return '';
326
+ }
327
+ toWebGL2(indent, ctx) {
328
+ return '';
329
+ }
330
+ toWGSL(indent, ctx) {
331
+ return '';
332
+ }
333
+ toString(deviceType) {
334
+ return this.constructor.name;
335
+ }
336
+ }
337
+ /** @internal */ class ASTExpression extends ShaderAST {
338
+ }
339
+ /** @internal */ class ASTFunctionParameter extends ASTExpression {
340
+ /** @internal */ paramAST;
341
+ /** @internal */ writable;
342
+ constructor(init){
343
+ super();
344
+ this.paramAST = init;
345
+ this.writable = false;
346
+ }
347
+ getType() {
348
+ return this.paramAST.getType();
349
+ }
350
+ markWritable() {
351
+ if (this.paramAST instanceof ASTPrimitive) {
352
+ console.warn(`Write to non-output parameter ${this.paramAST.value.$str}`);
353
+ }
354
+ this.writable = true;
355
+ }
356
+ isWritable() {
357
+ return this.writable;
358
+ }
359
+ getAddressSpace() {
360
+ return this.paramAST.getAddressSpace();
361
+ }
362
+ isConstExp() {
363
+ return this.paramAST.isConstExp();
364
+ }
365
+ isReference() {
366
+ return this.paramAST.isReference();
367
+ }
368
+ toWebGL(indent, ctx) {
369
+ return this.paramAST.toWebGL(indent, ctx);
370
+ }
371
+ toWebGL2(indent, ctx) {
372
+ return this.paramAST.toWebGL2(indent, ctx);
373
+ }
374
+ toWGSL(indent, ctx) {
375
+ return this.paramAST.toWGSL(indent, ctx);
376
+ }
377
+ }
378
+ /** @internal */ class ASTScope extends ShaderAST {
379
+ statements;
380
+ constructor(){
381
+ super();
382
+ this.statements = [];
383
+ }
384
+ toWebGL(indent, ctx) {
385
+ return this.statements.filter((stmt)=>!(stmt instanceof ASTCallFunction) || stmt.isStatement).map((stmt)=>stmt.toWebGL(indent, ctx)).join('');
386
+ }
387
+ toWebGL2(indent, ctx) {
388
+ return this.statements.filter((stmt)=>!(stmt instanceof ASTCallFunction) || stmt.isStatement).map((stmt)=>stmt.toWebGL2(indent, ctx)).join('');
389
+ }
390
+ toWGSL(indent, ctx) {
391
+ return this.statements.filter((stmt)=>!(stmt instanceof ASTCallFunction) || stmt.isStatement).map((stmt)=>{
392
+ if (stmt instanceof ASTCallFunction) {
393
+ if (!stmt.getType().isVoidType()) {
394
+ return `${indent}_ = ${stmt.toWGSL('', ctx)}`;
395
+ }
396
+ }
397
+ return stmt.toWGSL(indent, ctx);
398
+ }).join('');
399
+ }
400
+ }
401
+ /** @internal */ class ASTNakedScope extends ASTScope {
402
+ toWebGL(indent, ctx) {
403
+ return `${indent}{\n${super.toWebGL(indent + ' ', ctx)}${indent}}\n`;
404
+ }
405
+ toWebGL2(indent, ctx) {
406
+ return `${indent}{\n${super.toWebGL2(indent + ' ', ctx)}${indent}}\n`;
407
+ }
408
+ toWGSL(indent, ctx) {
409
+ return `${indent}{\n${super.toWGSL(indent + ' ', ctx)}${indent}}\n`;
410
+ }
411
+ }
412
+ /** @internal */ class ASTGlobalScope extends ASTScope {
413
+ /** @internal */ uniforms;
414
+ constructor(){
415
+ super();
416
+ this.uniforms = [];
417
+ }
418
+ findFunctions(name) {
419
+ const result = [];
420
+ for (const stmt of this.statements){
421
+ if (stmt instanceof ASTFunction && stmt.name === name) {
422
+ result.push(stmt);
423
+ }
424
+ }
425
+ return result;
426
+ }
427
+ toWebGL(indent, ctx) {
428
+ // TODO: precision
429
+ const precisions = `${indent}precision highp float;\n${indent}precision highp int;\n`;
430
+ const version = `${indent}#version 100\n`;
431
+ const body = ctx.types.map((val)=>val.toWebGL(indent, ctx)).join('') + this.uniforms.map((uniform)=>uniform.toWebGL(indent, ctx)).join('') + ctx.inputs.map((input)=>input.toWebGL(indent, ctx)).join('') + ctx.outputs.map((output)=>output.toWebGL(indent, ctx)).join('') + super.toWebGL(indent, ctx);
432
+ for (const k of ctx.builtins){
433
+ const info = builtinVariables.webgl[k];
434
+ if (info.extension) {
435
+ ctx.extensions.add(info.extension);
436
+ }
437
+ }
438
+ const extensions = [
439
+ ...ctx.extensions
440
+ ].map((s)=>`${indent}#extension ${s}: enable\n`).join('');
441
+ const defines = ctx.defines.join('');
442
+ return version + extensions + precisions + defines + body;
443
+ }
444
+ toWebGL2(indent, ctx) {
445
+ const precisions = `${indent}precision highp float;\n${indent}precision highp int;\n`;
446
+ const version = `${indent}#version 300 es\n`;
447
+ const body = ctx.types.map((val)=>val.toWebGL2(indent, ctx)).join('') + this.uniforms.map((uniform)=>uniform.toWebGL2(indent, ctx)).join('') + ctx.inputs.map((input)=>input.toWebGL2(indent, ctx)).join('') + ctx.outputs.map((output)=>output.toWebGL2(indent, ctx)).join('') + super.toWebGL2(indent, ctx);
448
+ for (const k of ctx.builtins){
449
+ const info = builtinVariables.webgl2[k];
450
+ if (info.extension) {
451
+ ctx.extensions.add(info.extension);
452
+ }
453
+ }
454
+ const extensions = [
455
+ ...ctx.extensions
456
+ ].map((s)=>`${indent}#extension ${s}: enable\n`).join('');
457
+ const defines = ctx.defines.join('');
458
+ return version + extensions + precisions + defines + body;
459
+ }
460
+ toWGSL(indent, ctx) {
461
+ const structNames = ctx.type === ShaderType.Vertex ? [
462
+ BuiltinInputStructNameVS,
463
+ BuiltinOutputStructNameVS
464
+ ] : ctx.type === ShaderType.Fragment ? [
465
+ BuiltinInputStructNameFS,
466
+ BuiltinOutputStructNameFS
467
+ ] : [
468
+ BuiltinInputStructNameCS
469
+ ];
470
+ const usedBuiltins = [];
471
+ for (const k of ctx.builtins){
472
+ usedBuiltins.push(builtinVariables.webgpu[k].name);
473
+ }
474
+ const allBuiltins = Object.keys(builtinVariables.webgpu).map((val)=>builtinVariables.webgpu[val].name);
475
+ for (const type of ctx.types){
476
+ if (type instanceof ASTStructDefine && structNames.indexOf(type.type.structName) >= 0) {
477
+ for(let i = type.type.structMembers.length - 1; i >= 0; i--){
478
+ const member = type.type.structMembers[i];
479
+ if (allBuiltins.indexOf(member.name) >= 0 && usedBuiltins.indexOf(member.name) < 0) {
480
+ type.type.structMembers.splice(i, 1);
481
+ type.prefix.splice(i, 1);
482
+ }
483
+ }
484
+ }
485
+ }
486
+ ctx.types = ctx.types.filter((val)=>!(val instanceof ASTStructDefine) || val.type.structMembers.length > 0);
487
+ return ctx.types.map((val)=>val.toWGSL(indent, ctx)).join('') + this.uniforms.map((uniform)=>uniform.toWGSL(indent, ctx)).join('') + super.toWGSL(indent, ctx);
488
+ }
489
+ }
490
+ /** @internal */ class ASTPrimitive extends ASTExpression {
491
+ /** @internal */ value;
492
+ /** @internal */ ref;
493
+ /** @internal */ writable;
494
+ /** @internal */ constExp;
495
+ constructor(value){
496
+ super();
497
+ this.value = value;
498
+ this.ref = null;
499
+ this.writable = false;
500
+ this.constExp = false;
501
+ }
502
+ get name() {
503
+ return this.value.$str;
504
+ }
505
+ isReference() {
506
+ return true;
507
+ }
508
+ isConstExp() {
509
+ return this.constExp;
510
+ }
511
+ markWritable() {
512
+ this.writable = true;
513
+ this.constExp = false;
514
+ if (this.ref) {
515
+ this.ref.markWritable();
516
+ }
517
+ }
518
+ isWritable() {
519
+ const type = this.getType();
520
+ return this.writable || type.isAtomicI32() || type.isAtomicU32() || type.isStructType() && type.isWritable();
521
+ }
522
+ getAddressSpace() {
523
+ switch(this.value.$declareType){
524
+ case DeclareType.DECLARE_TYPE_UNIFORM:
525
+ return PBAddressSpace.UNIFORM;
526
+ case DeclareType.DECLARE_TYPE_STORAGE:
527
+ return PBAddressSpace.STORAGE;
528
+ case DeclareType.DECLARE_TYPE_IN:
529
+ case DeclareType.DECLARE_TYPE_OUT:
530
+ return null;
531
+ default:
532
+ return this.value.$global ? PBAddressSpace.PRIVATE : PBAddressSpace.FUNCTION;
533
+ }
534
+ }
535
+ getType() {
536
+ return this.value.$typeinfo;
537
+ }
538
+ toWebGL(indent, ctx) {
539
+ return this.name;
540
+ }
541
+ toWebGL2(indent, ctx) {
542
+ return this.name;
543
+ }
544
+ toWGSL(indent, ctx) {
545
+ if (this.value.$declareType === DeclareType.DECLARE_TYPE_IN) {
546
+ const structName = getBuiltinInputStructInstanceName(ctx.type);
547
+ return ctx.global[structName][this.name].$ast.toWGSL(indent, ctx);
548
+ } else if (this.value.$declareType === DeclareType.DECLARE_TYPE_OUT) {
549
+ const structName = getBuiltinOutputStructInstanceName(ctx.type);
550
+ return ctx.global[structName][this.name].$ast.toWGSL(indent, ctx);
551
+ } else {
552
+ return this.name;
553
+ }
554
+ }
555
+ toString(deviceType) {
556
+ return this.name;
557
+ }
558
+ }
559
+ /** @internal */ class ASTLValue extends ShaderAST {
560
+ }
561
+ /** @internal */ class ASTLValueScalar extends ASTLValue {
562
+ /** @internal */ value;
563
+ constructor(value){
564
+ super();
565
+ if (value.getAddressSpace() === PBAddressSpace.UNIFORM) {
566
+ throw new PBASTError(value, 'cannot assign to uniform variable');
567
+ }
568
+ this.value = value;
569
+ if (this.value instanceof ASTCallFunction) {
570
+ this.value.isStatement = false;
571
+ }
572
+ }
573
+ getType() {
574
+ return this.value.getType();
575
+ }
576
+ markWritable() {
577
+ this.value.markWritable();
578
+ }
579
+ isWritable() {
580
+ return this.value.isWritable();
581
+ }
582
+ isReference() {
583
+ return this.value.isReference();
584
+ }
585
+ toWebGL(indent, ctx) {
586
+ return this.value.toWebGL(indent, ctx);
587
+ }
588
+ toWebGL2(indent, ctx) {
589
+ return this.value.toWebGL2(indent, ctx);
590
+ }
591
+ toWGSL(indent, ctx) {
592
+ return this.value.toWGSL(indent, ctx);
593
+ }
594
+ toString(deviceType) {
595
+ return this.value.toString(deviceType);
596
+ }
597
+ }
598
+ /** @internal */ class ASTLValueHash extends ASTLValue {
599
+ /** @internal */ scope;
600
+ /** @internal */ field;
601
+ /** @internal */ type;
602
+ constructor(scope, field, type){
603
+ super();
604
+ this.scope = scope;
605
+ this.field = field;
606
+ this.type = type;
607
+ }
608
+ getType() {
609
+ return this.type;
610
+ }
611
+ markWritable() {
612
+ this.scope.markWritable();
613
+ }
614
+ isWritable() {
615
+ return this.scope.isWritable();
616
+ }
617
+ isReference() {
618
+ return this.scope.isReference();
619
+ }
620
+ toWebGL(indent, ctx) {
621
+ return `${this.scope.toWebGL(indent, ctx)}.${this.field}`;
622
+ }
623
+ toWebGL2(indent, ctx) {
624
+ return `${this.scope.toWebGL2(indent, ctx)}.${this.field}`;
625
+ }
626
+ toWGSL(indent, ctx) {
627
+ const scope = this.scope.isPointer() ? new ASTReferenceOf(this.scope) : this.scope;
628
+ return `${scope.toWGSL(indent, ctx)}.${this.field}`;
629
+ }
630
+ toString(deviceType) {
631
+ const scope = this.scope.isPointer() ? new ASTReferenceOf(this.scope) : this.scope;
632
+ return `${scope.toString(deviceType)}.${this.field}`;
633
+ }
634
+ }
635
+ /** @internal */ class ASTLValueArray extends ASTLValue {
636
+ /** @internal */ value;
637
+ /** @internal */ index;
638
+ /** @internal */ type;
639
+ constructor(value, index, type){
640
+ super();
641
+ this.value = value;
642
+ this.index = index;
643
+ this.type = type;
644
+ if (this.index instanceof ASTCallFunction) {
645
+ this.index.isStatement = false;
646
+ }
647
+ }
648
+ getType() {
649
+ return this.type;
650
+ }
651
+ markWritable() {
652
+ this.value.markWritable();
653
+ }
654
+ isWritable() {
655
+ return this.value.isWritable();
656
+ }
657
+ isReference() {
658
+ return this.value.isReference();
659
+ }
660
+ toWebGL(indent, ctx) {
661
+ return `${this.value.toWebGL(indent, ctx)}[${this.index.toWebGL(indent, ctx)}]`;
662
+ }
663
+ toWebGL2(indent, ctx) {
664
+ return `${this.value.toWebGL2(indent, ctx)}[${this.index.toWebGL2(indent, ctx)}]`;
665
+ }
666
+ toWGSL(indent, ctx) {
667
+ const value = this.value.isPointer() ? new ASTReferenceOf(this.value) : this.value;
668
+ return `${value.toWGSL(indent, ctx)}[${this.index.toWGSL(indent, ctx)}]`;
669
+ }
670
+ toString(deviceType) {
671
+ const value = this.value.isPointer() ? new ASTReferenceOf(this.value) : this.value;
672
+ return `${value.toString(deviceType)}[${this.index.toString(deviceType)}]`;
673
+ }
674
+ }
675
+ /** @internal */ class ASTLValueDeclare extends ASTLValue {
676
+ /** @internal */ value;
677
+ constructor(value){
678
+ super();
679
+ this.value = value;
680
+ this.value.constExp = true;
681
+ }
682
+ getType() {
683
+ return this.value.getType();
684
+ }
685
+ markWritable() {}
686
+ isWritable() {
687
+ return false;
688
+ }
689
+ isReference() {
690
+ return true;
691
+ }
692
+ toWebGL(indent, ctx) {
693
+ let prefix = '';
694
+ switch(this.value.value.$declareType){
695
+ case DeclareType.DECLARE_TYPE_IN:
696
+ case DeclareType.DECLARE_TYPE_OUT:
697
+ case DeclareType.DECLARE_TYPE_UNIFORM:
698
+ case DeclareType.DECLARE_TYPE_STORAGE:
699
+ throw new Error('invalid declare type');
700
+ default:
701
+ prefix = this.value.constExp && !this.value.isWritable() && !this.getType().isStructType() ? 'const ' : '';
702
+ break;
703
+ }
704
+ {
705
+ return `${prefix}${this.getType().toTypeName('webgl', this.value.name)}`;
706
+ }
707
+ }
708
+ toWebGL2(indent, ctx) {
709
+ let prefix = '';
710
+ switch(this.value.value.$declareType){
711
+ case DeclareType.DECLARE_TYPE_IN:
712
+ case DeclareType.DECLARE_TYPE_OUT:
713
+ case DeclareType.DECLARE_TYPE_UNIFORM:
714
+ case DeclareType.DECLARE_TYPE_STORAGE:
715
+ throw new Error('invalid declare type');
716
+ default:
717
+ prefix = this.value.constExp && !this.value.isWritable() && !this.getType().isStructType() ? 'const ' : '';
718
+ break;
719
+ }
720
+ {
721
+ return `${prefix}${this.getType().toTypeName('webgl2', this.value.name)}`;
722
+ }
723
+ }
724
+ toWGSL(indent, ctx) {
725
+ let prefix;
726
+ switch(this.value.value.$declareType){
727
+ case DeclareType.DECLARE_TYPE_IN:
728
+ case DeclareType.DECLARE_TYPE_OUT:
729
+ case DeclareType.DECLARE_TYPE_UNIFORM:
730
+ case DeclareType.DECLARE_TYPE_STORAGE:
731
+ throw new Error('invalid declare type');
732
+ default:
733
+ {
734
+ const addressSpace = this.value.getAddressSpace();
735
+ const readonly = this.getType().isPointerType() || !this.value.isWritable() && (addressSpace === PBAddressSpace.PRIVATE || addressSpace === PBAddressSpace.FUNCTION);
736
+ const moduleScope = addressSpace === PBAddressSpace.PRIVATE;
737
+ const storageAccessMode = addressSpace === PBAddressSpace.STORAGE && this.value.isWritable() ? ', read_write' : '';
738
+ const decorator = addressSpace !== PBAddressSpace.FUNCTION ? `<${addressSpace}${storageAccessMode}>` : '';
739
+ prefix = readonly ? moduleScope ? 'const ' : 'let ' : `var${decorator} `;
740
+ break;
741
+ }
742
+ }
743
+ {
744
+ // const decl = this.value.value.$global ? this.getType().toTypeName('webgpu', this.value.name) : this.value.name;
745
+ const type = this.getType();
746
+ if (type.isPointerType() && (this.value.isWritable() || this.value.ref.isWritable())) {
747
+ type.writable = true;
748
+ }
749
+ const decl = type.toTypeName('webgpu', this.value.name);
750
+ return `${prefix}${decl}`;
751
+ }
752
+ }
753
+ toString(deviceType) {
754
+ return this.value.toString(deviceType);
755
+ }
756
+ }
757
+ /** @internal */ class ASTShaderExpConstructor extends ASTExpression {
758
+ /** @internal */ type;
759
+ /** @internal */ args;
760
+ /** @internal */ constExp;
761
+ constructor(type, args){
762
+ super();
763
+ this.type = type;
764
+ this.args = args;
765
+ this.constExp = true;
766
+ for (const arg of args){
767
+ if (arg === null || arg === undefined) {
768
+ throw new Error('invalid constructor argument');
769
+ }
770
+ if (arg instanceof ASTCallFunction) {
771
+ arg.isStatement = false;
772
+ }
773
+ this.constExp &&= !(arg instanceof ASTExpression) || arg.isConstExp();
774
+ }
775
+ }
776
+ getType() {
777
+ return this.type;
778
+ }
779
+ markWritable() {}
780
+ isWritable() {
781
+ return false;
782
+ }
783
+ isConstExp() {
784
+ return this.constExp;
785
+ }
786
+ getAddressSpace() {
787
+ return null;
788
+ }
789
+ toWebGL(indent, ctx) {
790
+ console.assert(!this.type.isArrayType(), 'array constructor not supported in webgl1 device');
791
+ console.assert(this.type.isConstructible(), `type '${this.type.toTypeName('webgl')}' is not constructible`);
792
+ const overloads = this.type.getConstructorOverloads('webgl');
793
+ for (const overload of overloads){
794
+ const convertedArgs = convertArgs(this.args, overload);
795
+ if (convertedArgs) {
796
+ const c = convertedArgs.args.map((arg)=>unbracket(arg.toWebGL(indent, ctx))).join(',');
797
+ return `${convertedArgs.name}(${c})`;
798
+ }
799
+ }
800
+ throw new Error(`no matching overload function found for type ${this.type.toTypeName('webgl')}`);
801
+ }
802
+ toWebGL2(indent, ctx) {
803
+ console.assert(this.type.isConstructible(), `type '${this.type.toTypeName('webgl2')}' is not constructible`, true);
804
+ const overloads = this.type.getConstructorOverloads('webgl2');
805
+ for (const overload of overloads){
806
+ const convertedArgs = convertArgs(this.args, overload);
807
+ if (convertedArgs) {
808
+ const c = convertedArgs.args.map((arg)=>unbracket(arg.toWebGL2(indent, ctx))).join(',');
809
+ return `${convertedArgs.name}(${c})`;
810
+ }
811
+ }
812
+ throw new Error(`no matching overload function found for type ${this.type.toTypeName('webgl2')}`);
813
+ }
814
+ toWGSL(indent, ctx) {
815
+ /*
816
+ console.assert(
817
+ this.type.isConstructible(),
818
+ `type '${this.type.toTypeName('webgpu')}' is not constructible`,
819
+ true
820
+ );
821
+ */ const overloads = this.type.getConstructorOverloads('webgpu');
822
+ for (const overload of overloads){
823
+ const convertedArgs = convertArgs(this.args, overload);
824
+ if (convertedArgs) {
825
+ const c = convertedArgs.args.map((arg)=>unbracket(arg.toWGSL(indent, ctx))).join(',');
826
+ return `${convertedArgs.name}(${c})`;
827
+ }
828
+ }
829
+ throw new Error(`no matching overload function found for type ${this.type.toTypeName('webgpu')}`);
830
+ }
831
+ toString(deviceType) {
832
+ return 'constructor';
833
+ }
834
+ }
835
+ /** @internal */ class ASTScalar extends ASTExpression {
836
+ /** @internal */ value;
837
+ /** @internal */ type;
838
+ constructor(value, type){
839
+ super();
840
+ this.value = value;
841
+ this.type = type;
842
+ if (typeof value === 'number') {
843
+ if (type.primitiveType === PBPrimitiveType.BOOL) {
844
+ throw new PBTypeCastError(value, typeof value, type);
845
+ }
846
+ if (type.primitiveType === PBPrimitiveType.I32 && (!Number.isInteger(value) || value < 0x80000000 >> 0 || value > 0xffffffff)) {
847
+ throw new PBTypeCastError(value, typeof value, type);
848
+ }
849
+ if (value < 0 && type.primitiveType === PBPrimitiveType.U32 && (!Number.isInteger(value) || value < 0 || value > 0xffffffff)) {
850
+ throw new PBTypeCastError(value, typeof value, type);
851
+ }
852
+ } else if (type.primitiveType !== PBPrimitiveType.BOOL) {
853
+ throw new PBTypeCastError(value, typeof value, type);
854
+ }
855
+ }
856
+ getType() {
857
+ return this.type;
858
+ }
859
+ markWritable() {}
860
+ isWritable() {
861
+ return false;
862
+ }
863
+ isConstExp() {
864
+ return true;
865
+ }
866
+ getAddressSpace() {
867
+ return null;
868
+ }
869
+ toWebGL(indent, ctx) {
870
+ switch(this.type.primitiveType){
871
+ case PBPrimitiveType.F32:
872
+ return toFixed(this.value);
873
+ case PBPrimitiveType.I32:
874
+ return toInt(this.value);
875
+ case PBPrimitiveType.U32:
876
+ return toUint(this.value);
877
+ case PBPrimitiveType.BOOL:
878
+ return String(!!this.value);
879
+ default:
880
+ throw new Error('Invalid scalar type');
881
+ }
882
+ }
883
+ toWebGL2(indent, ctx) {
884
+ switch(this.type.primitiveType){
885
+ case PBPrimitiveType.F32:
886
+ return toFixed(this.value);
887
+ case PBPrimitiveType.I32:
888
+ return toInt(this.value);
889
+ case PBPrimitiveType.U32:
890
+ return `${toUint(this.value)}u`;
891
+ case PBPrimitiveType.BOOL:
892
+ return String(!!this.value);
893
+ default:
894
+ throw new Error('Invalid scalar type');
895
+ }
896
+ }
897
+ toWGSL(indent, ctx) {
898
+ switch(this.type.primitiveType){
899
+ case PBPrimitiveType.F32:
900
+ return toFixed(this.value);
901
+ case PBPrimitiveType.I32:
902
+ return toInt(this.value);
903
+ case PBPrimitiveType.U32:
904
+ return `${toUint(this.value)}u`;
905
+ case PBPrimitiveType.BOOL:
906
+ return String(!!this.value);
907
+ default:
908
+ throw new Error('Invalid scalar type');
909
+ }
910
+ }
911
+ toString(deviceType) {
912
+ return `${this.value}`;
913
+ }
914
+ }
915
+ /** @internal */ class ASTHash extends ASTExpression {
916
+ /** @internal */ source;
917
+ /** @internal */ field;
918
+ /** @internal */ type;
919
+ constructor(source, field, type){
920
+ super();
921
+ this.source = source;
922
+ this.field = field;
923
+ this.type = type;
924
+ if (this.source instanceof ASTCallFunction) {
925
+ this.source.isStatement = false;
926
+ }
927
+ }
928
+ getType() {
929
+ return this.type;
930
+ }
931
+ isReference() {
932
+ return this.source.isReference();
933
+ }
934
+ isConstExp() {
935
+ return this.source.isConstExp();
936
+ }
937
+ markWritable() {
938
+ this.source.markWritable();
939
+ }
940
+ isWritable() {
941
+ return this.source.isWritable();
942
+ }
943
+ getAddressSpace() {
944
+ return this.source.getAddressSpace();
945
+ }
946
+ toWebGL(indent, ctx) {
947
+ return `${this.source.toWebGL(indent, ctx)}.${this.field}`;
948
+ }
949
+ toWebGL2(indent, ctx) {
950
+ return `${this.source.toWebGL2(indent, ctx)}.${this.field}`;
951
+ }
952
+ toWGSL(indent, ctx) {
953
+ const source = this.source.isPointer() ? new ASTReferenceOf(this.source) : this.source;
954
+ return `${source.toWGSL(indent, ctx)}.${this.field}`;
955
+ }
956
+ toString(deviceType) {
957
+ const source = this.source.isPointer() ? new ASTReferenceOf(this.source) : this.source;
958
+ return `${source.toString(deviceType)}.${this.field}`;
959
+ }
960
+ }
961
+ /** @internal */ class ASTCast extends ASTExpression {
962
+ /** @internal */ sourceValue;
963
+ /** @internal */ castType;
964
+ constructor(source, type){
965
+ super();
966
+ this.sourceValue = source;
967
+ this.castType = type;
968
+ if (this.sourceValue instanceof ASTCallFunction) {
969
+ this.sourceValue.isStatement = false;
970
+ }
971
+ }
972
+ getType() {
973
+ return this.castType;
974
+ }
975
+ markWritable() {}
976
+ isWritable() {
977
+ return false;
978
+ }
979
+ isConstExp() {
980
+ return this.sourceValue.isConstExp();
981
+ }
982
+ getAddressSpace() {
983
+ return null;
984
+ }
985
+ toWebGL(indent, ctx) {
986
+ if (!this.castType.isCompatibleType(this.sourceValue.getType())) {
987
+ return `${this.castType.toTypeName('webgl')}(${unbracket(this.sourceValue.toWebGL(indent, ctx))})`;
988
+ } else {
989
+ return this.sourceValue.toWebGL(indent, ctx);
990
+ }
991
+ }
992
+ toWebGL2(indent, ctx) {
993
+ if (!this.castType.isCompatibleType(this.sourceValue.getType())) {
994
+ return `${this.castType.toTypeName('webgl2')}(${unbracket(this.sourceValue.toWebGL2(indent, ctx))})`;
995
+ } else {
996
+ return this.sourceValue.toWebGL2(indent, ctx);
997
+ }
998
+ }
999
+ toWGSL(indent, ctx) {
1000
+ if (!this.castType.isCompatibleType(this.sourceValue.getType())) {
1001
+ return `${this.castType.toTypeName('webgpu')}(${unbracket(this.sourceValue.toWGSL(indent, ctx))})`;
1002
+ } else {
1003
+ return this.sourceValue.toWGSL(indent, ctx);
1004
+ }
1005
+ }
1006
+ toString(deviceType) {
1007
+ return `${this.castType.toTypeName(deviceType)}(${unbracket(this.sourceValue.toString(deviceType))})`;
1008
+ }
1009
+ }
1010
+ /** @internal */ class ASTAddressOf extends ASTExpression {
1011
+ /** @internal */ value;
1012
+ /** @internal */ type;
1013
+ constructor(value){
1014
+ super();
1015
+ console.assert(value.isReference(), 'no pointer type for non-reference values', true);
1016
+ this.value = value;
1017
+ this.type = new PBPointerTypeInfo(value.getType(), value.getAddressSpace());
1018
+ }
1019
+ getType() {
1020
+ return this.type;
1021
+ }
1022
+ isConstExp() {
1023
+ return false;
1024
+ }
1025
+ markWritable() {
1026
+ const addressSpace = this.value.getAddressSpace();
1027
+ if (addressSpace === PBAddressSpace.UNIFORM) {
1028
+ throw new PBASTError(this.value, 'uniforms are not writable');
1029
+ }
1030
+ this.value.markWritable();
1031
+ }
1032
+ isWritable() {
1033
+ return this.value.isWritable();
1034
+ }
1035
+ getAddressSpace() {
1036
+ return this.value.getAddressSpace();
1037
+ }
1038
+ toWebGL(indent, ctx) {
1039
+ throw new Error('GLSL does not support pointer type');
1040
+ }
1041
+ toWebGL2(indent, ctx) {
1042
+ throw new Error('GLSL does not support pointer type');
1043
+ }
1044
+ toWGSL(indent, ctx) {
1045
+ const ast = this.value instanceof ASTFunctionParameter ? this.value.paramAST : this.value;
1046
+ return ast instanceof ASTReferenceOf ? ast.value.toWGSL(indent, ctx) : `(&${ast.toWGSL(indent, ctx)})`;
1047
+ }
1048
+ toString(deviceType) {
1049
+ const ast = this.value instanceof ASTFunctionParameter ? this.value.paramAST : this.value;
1050
+ return ast instanceof ASTReferenceOf ? ast.value.toString(deviceType) : `(&${ast.toString(deviceType)})`;
1051
+ }
1052
+ }
1053
+ /** @internal */ class ASTReferenceOf extends ASTExpression {
1054
+ /** @internal */ value;
1055
+ constructor(value){
1056
+ super();
1057
+ this.value = value;
1058
+ if (this.value instanceof ASTCallFunction) {
1059
+ this.value.isStatement = false;
1060
+ }
1061
+ }
1062
+ getType() {
1063
+ const type = this.value.getType();
1064
+ return type.isPointerType() ? type.pointerType : type;
1065
+ }
1066
+ isReference() {
1067
+ return true;
1068
+ }
1069
+ markWritable() {
1070
+ this.value.markWritable();
1071
+ }
1072
+ isWritable() {
1073
+ return this.value.isWritable();
1074
+ }
1075
+ isConstExp() {
1076
+ return false;
1077
+ }
1078
+ getAddressSpace() {
1079
+ return this.value instanceof ASTExpression ? this.value.getAddressSpace() : null;
1080
+ }
1081
+ toWebGL(indent, ctx) {
1082
+ return this.value.toWebGL(indent, ctx);
1083
+ }
1084
+ toWebGL2(indent, ctx) {
1085
+ return this.value.toWebGL2(indent, ctx);
1086
+ }
1087
+ toWGSL(indent, ctx) {
1088
+ return this.value.getType().isPointerType() ? `(*${this.value.toWGSL(indent, ctx)})` : this.value.toWGSL(indent, ctx);
1089
+ }
1090
+ toString(deviceType) {
1091
+ return `*${this.value.toString(deviceType)}`;
1092
+ }
1093
+ }
1094
+ /** @internal */ class ASTUnaryFunc extends ASTExpression {
1095
+ /** @internal */ value;
1096
+ /** @internal */ op;
1097
+ /** @internal */ type;
1098
+ constructor(value, op, type){
1099
+ super();
1100
+ this.value = value;
1101
+ this.op = op;
1102
+ this.type = type;
1103
+ if (this.value instanceof ASTCallFunction) {
1104
+ this.value.isStatement = false;
1105
+ }
1106
+ }
1107
+ getType() {
1108
+ return this.type;
1109
+ }
1110
+ markWritable() {}
1111
+ isWritable() {
1112
+ return false;
1113
+ }
1114
+ isConstExp() {
1115
+ return this.value.isConstExp();
1116
+ }
1117
+ getAddressSpace() {
1118
+ return null;
1119
+ }
1120
+ toWebGL(indent, ctx) {
1121
+ return `${this.op}${this.value.toWebGL(indent, ctx)}`;
1122
+ }
1123
+ toWebGL2(indent, ctx) {
1124
+ return `${this.op}${this.value.toWebGL2(indent, ctx)}`;
1125
+ }
1126
+ toWGSL(indent, ctx) {
1127
+ const value = this.value.isPointer() ? new ASTReferenceOf(this.value) : this.value;
1128
+ return `${this.op}${value.toWGSL(indent, ctx)}`;
1129
+ }
1130
+ toString(deviceType) {
1131
+ const value = this.value.isPointer() ? new ASTReferenceOf(this.value) : this.value;
1132
+ return `${this.op}${value.toString(deviceType)}`;
1133
+ }
1134
+ }
1135
+ /** @internal */ class ASTBinaryFunc extends ASTExpression {
1136
+ /** @internal */ left;
1137
+ /** @internal */ right;
1138
+ /** @internal */ type;
1139
+ /** @internal */ op;
1140
+ constructor(left, right, op, type){
1141
+ super();
1142
+ this.left = left;
1143
+ this.right = right;
1144
+ this.op = op;
1145
+ this.type = type;
1146
+ if (this.left instanceof ASTCallFunction) {
1147
+ this.left.isStatement = false;
1148
+ }
1149
+ if (this.right instanceof ASTCallFunction) {
1150
+ this.right.isStatement = false;
1151
+ }
1152
+ }
1153
+ getType() {
1154
+ return this.type;
1155
+ }
1156
+ markWritable() {}
1157
+ isWritable() {
1158
+ return false;
1159
+ }
1160
+ isConstExp() {
1161
+ return this.left.isConstExp() && this.right.isConstExp();
1162
+ }
1163
+ getAddressSpace() {
1164
+ return null;
1165
+ }
1166
+ toWebGL(indent, ctx) {
1167
+ return `(${this.left.toWebGL(indent, ctx)} ${this.op} ${this.right.toWebGL(indent, ctx)})`;
1168
+ }
1169
+ toWebGL2(indent, ctx) {
1170
+ return `(${this.left.toWebGL2(indent, ctx)} ${this.op} ${this.right.toWebGL2(indent, ctx)})`;
1171
+ }
1172
+ toWGSL(indent, ctx) {
1173
+ const left = this.left.isPointer() ? new ASTReferenceOf(this.left) : this.left;
1174
+ const right = this.right.isPointer() ? new ASTReferenceOf(this.right) : this.right;
1175
+ return `(${left.toWGSL(indent, ctx)} ${this.op} ${right.toWGSL(indent, ctx)})`;
1176
+ }
1177
+ toString(deviceType) {
1178
+ const left = this.left.isPointer() ? new ASTReferenceOf(this.left) : this.left;
1179
+ const right = this.right.isPointer() ? new ASTReferenceOf(this.right) : this.right;
1180
+ return `(${left.toString(deviceType)} ${this.op} ${right.toString(deviceType)})`;
1181
+ }
1182
+ }
1183
+ /** @internal */ class ASTArrayIndex extends ASTExpression {
1184
+ /** @internal */ source;
1185
+ /** @internal */ index;
1186
+ /** @internal */ type;
1187
+ constructor(source, index, type){
1188
+ super();
1189
+ this.source = source;
1190
+ this.index = index;
1191
+ this.type = type;
1192
+ if (this.source instanceof ASTCallFunction) {
1193
+ this.source.isStatement = false;
1194
+ }
1195
+ if (this.index instanceof ASTCallFunction) {
1196
+ this.index.isStatement = false;
1197
+ }
1198
+ }
1199
+ getType() {
1200
+ return this.type;
1201
+ }
1202
+ isReference() {
1203
+ return this.source.isReference();
1204
+ }
1205
+ markWritable() {
1206
+ this.source.markWritable();
1207
+ }
1208
+ isWritable() {
1209
+ return this.source.isWritable();
1210
+ }
1211
+ isConstExp() {
1212
+ return this.source.isConstExp() && this.index.isConstExp();
1213
+ }
1214
+ getAddressSpace() {
1215
+ return this.source.getAddressSpace();
1216
+ }
1217
+ toWebGL(indent, ctx) {
1218
+ return `${this.source.toWebGL(indent, ctx)}[${unbracket(this.index.toWebGL(indent, ctx))}]`;
1219
+ }
1220
+ toWebGL2(indent, ctx) {
1221
+ return `${this.source.toWebGL2(indent, ctx)}[${unbracket(this.index.toWebGL2(indent, ctx))}]`;
1222
+ }
1223
+ toWGSL(indent, ctx) {
1224
+ return `${this.source.toWGSL(indent, ctx)}[${unbracket(this.index.toWGSL(indent, ctx))}]`;
1225
+ }
1226
+ toString(deviceType) {
1227
+ return `${this.source.toString(deviceType)}[${unbracket(this.index.toString(deviceType))}]`;
1228
+ }
1229
+ }
1230
+ /** @internal */ class ASTTouch extends ShaderAST {
1231
+ /** @internal */ value;
1232
+ constructor(value){
1233
+ super();
1234
+ if (value.getType().isVoidType()) {
1235
+ throw new Error('can not touch void type');
1236
+ }
1237
+ if (value instanceof ASTCallFunction) {
1238
+ value.isStatement = false;
1239
+ }
1240
+ this.value = value;
1241
+ }
1242
+ toWebGL(indent, ctx) {
1243
+ return `${indent}${this.value.toWebGL('', ctx)};\n`;
1244
+ }
1245
+ toWebGL2(indent, ctx) {
1246
+ return `${indent}${this.value.toWebGL2('', ctx)};\n`;
1247
+ }
1248
+ toWGSL(indent, ctx) {
1249
+ if (!this.value.getType().isVoidType()) {
1250
+ return `${indent}_ = ${this.value.toWGSL('', ctx)};\n`;
1251
+ } else {
1252
+ return `${indent}${this.value.toWGSL('', ctx)};\n`;
1253
+ }
1254
+ }
1255
+ }
1256
+ /** @internal */ class ASTSelect extends ASTExpression {
1257
+ /** @internal */ condition;
1258
+ /** @internal */ first;
1259
+ /** @internal */ second;
1260
+ /** @internal */ type;
1261
+ constructor(condition, first, second){
1262
+ super();
1263
+ this.condition = condition instanceof ASTExpression ? condition : new ASTScalar(condition, typeBool);
1264
+ let firstType = null;
1265
+ let secondType = null;
1266
+ if (first instanceof ASTExpression) {
1267
+ firstType = first.getType();
1268
+ this.first = first;
1269
+ if (first instanceof ASTCallFunction) {
1270
+ first.isStatement = false;
1271
+ }
1272
+ } else if (typeof first === 'number') {
1273
+ if (!Number.isInteger(first)) {
1274
+ this.first = new ASTScalar(first, typeF32);
1275
+ firstType = typeF32;
1276
+ }
1277
+ } else if (typeof first === 'boolean') {
1278
+ this.first = new ASTScalar(first, typeBool);
1279
+ firstType = typeBool;
1280
+ } else {
1281
+ throw new Error('select: invalid first value');
1282
+ }
1283
+ if (second instanceof ASTExpression) {
1284
+ secondType = second.getType();
1285
+ this.second = second;
1286
+ if (second instanceof ASTCallFunction) {
1287
+ second.isStatement = false;
1288
+ }
1289
+ } else if (typeof second === 'number') {
1290
+ if (!Number.isInteger(second)) {
1291
+ this.second = new ASTScalar(second, typeF32);
1292
+ secondType = typeF32;
1293
+ }
1294
+ } else if (typeof second === 'boolean') {
1295
+ this.second = new ASTScalar(second, typeBool);
1296
+ secondType = typeBool;
1297
+ } else {
1298
+ throw new Error('select: invalid second value');
1299
+ }
1300
+ if (!firstType && !secondType) {
1301
+ throw new Error('select: cannot determine the value types');
1302
+ }
1303
+ if (firstType && secondType) {
1304
+ if (!firstType.isCompatibleType(secondType)) {
1305
+ throw new Error('select: first value and second value must be the same type');
1306
+ } else {
1307
+ this.type = firstType;
1308
+ }
1309
+ } else if (!firstType) {
1310
+ if (secondType.typeId === typeF32.typeId) {
1311
+ this.first = new ASTScalar(first, typeF32);
1312
+ } else if (secondType.typeId === typeI32.typeId) {
1313
+ this.first = new ASTScalar(first, typeI32);
1314
+ } else if (secondType.typeId === typeU32.typeId) {
1315
+ this.first = new ASTScalar(first, typeU32);
1316
+ } else {
1317
+ throw new Error('select: invalid type of the first value');
1318
+ }
1319
+ this.type = secondType;
1320
+ } else {
1321
+ if (firstType.typeId === typeF32.typeId) {
1322
+ this.second = new ASTScalar(second, typeF32);
1323
+ } else if (firstType.typeId === typeI32.typeId) {
1324
+ this.second = new ASTScalar(second, typeI32);
1325
+ } else if (firstType.typeId === typeU32.typeId) {
1326
+ this.second = new ASTScalar(second, typeU32);
1327
+ } else {
1328
+ throw new Error('select: invalid type of the second value');
1329
+ }
1330
+ this.type = firstType;
1331
+ }
1332
+ }
1333
+ getType() {
1334
+ return this.type;
1335
+ }
1336
+ isConstExp() {
1337
+ return false;
1338
+ }
1339
+ markWritable() {}
1340
+ isWritable() {
1341
+ return false;
1342
+ }
1343
+ getAddressSpace() {
1344
+ return null;
1345
+ }
1346
+ toWebGL(indent, ctx) {
1347
+ return `${indent}(${this.condition.toWebGL('', ctx)} ? ${this.first.toWebGL('', ctx)} : ${this.second.toWebGL('', ctx)})`;
1348
+ }
1349
+ toWebGL2(indent, ctx) {
1350
+ return `${indent}(${this.condition.toWebGL2('', ctx)} ? ${this.first.toWebGL2('', ctx)} : ${this.second.toWebGL2('', ctx)})`;
1351
+ }
1352
+ toWGSL(indent, ctx) {
1353
+ return `${indent}select(${this.second.toWGSL('', ctx)}, ${this.first.toWGSL('', ctx)}, ${this.condition.toWGSL('', ctx)})`;
1354
+ //return `${indent}${this.condition.toWGSL('', ctx)} ? ${this.first.toWGSL('', ctx)} : ${this.second.toWGSL('', ctx)}`;
1355
+ }
1356
+ }
1357
+ /** @internal */ class ASTAssignment extends ShaderAST {
1358
+ /** @internal */ lvalue;
1359
+ /** @internal */ rvalue;
1360
+ constructor(lvalue, rvalue){
1361
+ super();
1362
+ if (!lvalue.isReference()) {
1363
+ throw new Error('assignment: l-value required');
1364
+ }
1365
+ this.lvalue = lvalue;
1366
+ this.rvalue = rvalue;
1367
+ if (!(this.lvalue instanceof ASTLValueDeclare)) {
1368
+ if (this.lvalue.getType().isPointerType()) {
1369
+ throw new PBASTError(this.lvalue, 'cannot assign to read-only variable');
1370
+ }
1371
+ this.lvalue.markWritable();
1372
+ } else if (this.lvalue.getType().isPointerType()) {
1373
+ if (this.rvalue instanceof ASTPrimitive) {
1374
+ this.lvalue.value.ref = this.rvalue.ref;
1375
+ } else if (this.rvalue instanceof ASTAddressOf) {
1376
+ this.lvalue.value.ref = this.rvalue.value;
1377
+ } else {
1378
+ throw new PBASTError(this.lvalue, 'invalid pointer assignment');
1379
+ }
1380
+ } else if (this.rvalue instanceof ASTExpression) {
1381
+ this.lvalue.value.constExp = this.rvalue.isConstExp();
1382
+ }
1383
+ if (this.rvalue instanceof ASTCallFunction) {
1384
+ this.rvalue.isStatement = false;
1385
+ }
1386
+ }
1387
+ getType() {
1388
+ return null;
1389
+ }
1390
+ toWebGL(indent, ctx) {
1391
+ let rhs = null;
1392
+ const ltype = this.lvalue.getType();
1393
+ const rtype = this.checkScalarType(this.rvalue, ltype);
1394
+ if (!ltype.isCompatibleType(rtype)) {
1395
+ throw new PBTypeCastError(this.rvalue instanceof ASTExpression ? this.rvalue.toString('webgl') : `${this.rvalue}`, rtype, ltype);
1396
+ }
1397
+ if (typeof this.rvalue === 'number' || typeof this.rvalue === 'boolean') {
1398
+ rhs = rtype.primitiveType === PBPrimitiveType.F32 ? toFixed(this.rvalue) : String(this.rvalue);
1399
+ } else {
1400
+ rhs = unbracket(this.rvalue.toWebGL(indent, ctx));
1401
+ }
1402
+ if (this.lvalue instanceof ASTLValueDeclare) {
1403
+ this.lvalue.value.constExp &&= !(this.rvalue instanceof ASTExpression) || this.rvalue.isConstExp();
1404
+ }
1405
+ return `${indent}${this.lvalue.toWebGL(indent, ctx)} = ${rhs};\n`;
1406
+ }
1407
+ toWebGL2(indent, ctx) {
1408
+ let rhs = null;
1409
+ const ltype = this.lvalue.getType();
1410
+ const rtype = this.checkScalarType(this.rvalue, ltype);
1411
+ if (!ltype.isCompatibleType(rtype)) {
1412
+ throw new PBTypeCastError(this.rvalue instanceof ASTExpression ? this.rvalue.toString('webgl2') : `${this.rvalue}`, rtype, ltype);
1413
+ }
1414
+ if (typeof this.rvalue === 'number' || typeof this.rvalue === 'boolean') {
1415
+ rhs = rtype.primitiveType === PBPrimitiveType.F32 ? toFixed(this.rvalue) : String(this.rvalue);
1416
+ } else {
1417
+ rhs = unbracket(this.rvalue.toWebGL2(indent, ctx));
1418
+ }
1419
+ if (this.lvalue instanceof ASTLValueDeclare) {
1420
+ this.lvalue.value.constExp &&= !(this.rvalue instanceof ASTExpression) || this.rvalue.isConstExp();
1421
+ }
1422
+ return `${indent}${this.lvalue.toWebGL2(indent, ctx)} = ${rhs};\n`;
1423
+ }
1424
+ toWGSL(indent, ctx) {
1425
+ const ltype = this.lvalue.getType();
1426
+ const [valueTypeLeft, lvalueIsPtr] = ltype.isPointerType() ? [
1427
+ ltype.pointerType,
1428
+ true
1429
+ ] : [
1430
+ ltype,
1431
+ false
1432
+ ];
1433
+ const rtype = this.checkScalarType(this.rvalue, valueTypeLeft);
1434
+ const rvalueIsPtr = rtype && rtype.isPointerType();
1435
+ const valueTypeRight = rvalueIsPtr ? rtype.pointerType : rtype;
1436
+ if (!valueTypeLeft.isCompatibleType(valueTypeRight)) {
1437
+ throw new PBTypeCastError(this.rvalue instanceof ASTExpression ? this.rvalue.toString('webgpu') : `${this.rvalue}`, rtype, ltype);
1438
+ }
1439
+ if (this.lvalue instanceof ASTLValueScalar || this.lvalue instanceof ASTLValueDeclare) {
1440
+ const structName = valueTypeLeft.isStructType() ? valueTypeLeft.structName : null;
1441
+ if (structName && ctx.types.findIndex((val)=>val instanceof ASTStructDefine && val.type.structName === structName) < 0) {
1442
+ return '';
1443
+ }
1444
+ }
1445
+ let rhs;
1446
+ if (typeof this.rvalue === 'number' || typeof this.rvalue === 'boolean') {
1447
+ rhs = rtype.primitiveType === PBPrimitiveType.F32 ? toFixed(this.rvalue) : String(this.rvalue);
1448
+ } else {
1449
+ rhs = unbracket(this.rvalue.toWGSL(indent, ctx));
1450
+ }
1451
+ const name = this.lvalue.toWGSL(indent, ctx);
1452
+ if (lvalueIsPtr && !rvalueIsPtr) {
1453
+ if (this.lvalue instanceof ASTLValueDeclare) {
1454
+ throw new Error(`rvalue must be pointer type: ${rhs}`);
1455
+ } else {
1456
+ return `${indent}*(${name}) = ${rhs};\n`;
1457
+ }
1458
+ } else if (rvalueIsPtr && !lvalueIsPtr) {
1459
+ return `${indent}${name} = *(${rhs});\n`;
1460
+ } else {
1461
+ return `${indent}${name} = ${rhs};\n`;
1462
+ }
1463
+ }
1464
+ checkScalarType(value, targetType) {
1465
+ if (value instanceof ASTExpression) {
1466
+ return value.getType();
1467
+ }
1468
+ const isBool = typeof value === 'boolean';
1469
+ const isInt = typeof value === 'number' && Number.isInteger(value) && value >= 0x80000000 >> 0 && value <= 0x7fffffff;
1470
+ const isUint = typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= 0xffffffff;
1471
+ const isFloat = typeof value === 'number';
1472
+ if (targetType.isPrimitiveType()) {
1473
+ switch(targetType.primitiveType){
1474
+ case PBPrimitiveType.BOOL:
1475
+ return isBool ? targetType : isInt ? typeI32 : isUint ? typeU32 : typeF32;
1476
+ case PBPrimitiveType.F32:
1477
+ return isFloat ? targetType : typeBool;
1478
+ case PBPrimitiveType.I32:
1479
+ return isInt ? targetType : isBool ? typeBool : isUint ? typeU32 : typeF32;
1480
+ case PBPrimitiveType.U32:
1481
+ return isUint ? targetType : isBool ? typeBool : isInt ? typeI32 : typeF32;
1482
+ default:
1483
+ return null;
1484
+ }
1485
+ } else {
1486
+ return isBool ? typeBool : isInt ? typeI32 : isUint ? typeU32 : typeF32;
1487
+ }
1488
+ }
1489
+ }
1490
+ /** @internal */ class ASTDiscard extends ShaderAST {
1491
+ toWebGL(indent, ctx) {
1492
+ return `${indent}discard;\n`;
1493
+ }
1494
+ toWebGL2(indent, ctx) {
1495
+ return `${indent}discard;\n`;
1496
+ }
1497
+ toWGSL(indent, ctx) {
1498
+ return `${indent}discard;\n`;
1499
+ }
1500
+ }
1501
+ /** @internal */ class ASTBreak extends ShaderAST {
1502
+ toWebGL(indent, ctx) {
1503
+ return `${indent}break;\n`;
1504
+ }
1505
+ toWebGL2(indent, ctx) {
1506
+ return `${indent}break;\n`;
1507
+ }
1508
+ toWGSL(indent, ctx) {
1509
+ return `${indent}break;\n`;
1510
+ }
1511
+ }
1512
+ /** @internal */ class ASTContinue extends ShaderAST {
1513
+ toWebGL(indent, ctx) {
1514
+ return `${indent}continue;\n`;
1515
+ }
1516
+ toWebGL2(indent, ctx) {
1517
+ return `${indent}continue;\n`;
1518
+ }
1519
+ toWGSL(indent, ctx) {
1520
+ return `${indent}continue;\n`;
1521
+ }
1522
+ }
1523
+ /** @internal */ class ASTReturn extends ShaderAST {
1524
+ /** @internal */ value;
1525
+ constructor(value){
1526
+ super();
1527
+ this.value = value;
1528
+ if (this.value instanceof ASTCallFunction) {
1529
+ this.value.isStatement = false;
1530
+ }
1531
+ }
1532
+ toWebGL(indent, ctx) {
1533
+ return this.value ? `${indent}return ${unbracket(this.value.toWebGL(indent, ctx))};\n` : `${indent}return;\n`;
1534
+ }
1535
+ toWebGL2(indent, ctx) {
1536
+ return this.value ? `${indent}return ${unbracket(this.value.toWebGL2(indent, ctx))};\n` : `${indent}return;\n`;
1537
+ }
1538
+ toWGSL(indent, ctx) {
1539
+ return this.value ? `${indent}return ${unbracket(this.value.toWGSL(indent, ctx))};\n` : `${indent}return;\n`;
1540
+ }
1541
+ }
1542
+ /** @internal */ class ASTCallFunction extends ASTExpression {
1543
+ /** @internal */ name;
1544
+ /** @internal */ args;
1545
+ /** @internal */ retType;
1546
+ /** @internal */ func;
1547
+ /** @internal */ isStatement;
1548
+ constructor(name, args, func, deviceType, retType){
1549
+ super();
1550
+ this.name = name;
1551
+ this.args = args;
1552
+ this.retType = func?.returnType ?? retType ?? typeVoid;
1553
+ this.func = func;
1554
+ this.isStatement = true;
1555
+ if (func) {
1556
+ if (func.funcType.argTypes.length !== this.args.length) {
1557
+ throw new PBInternalError(`ASTCallFunction(): number of parameters mismatch`);
1558
+ }
1559
+ for(let i = 0; i < this.args.length; i++){
1560
+ const funcArg = func.funcType.argTypes[i];
1561
+ if (funcArg.byRef) {
1562
+ if (deviceType === 'webgpu') {
1563
+ const argAddressSpace = args[i].getAddressSpace();
1564
+ if (argAddressSpace !== PBAddressSpace.FUNCTION && argAddressSpace !== PBAddressSpace.PRIVATE) {
1565
+ throw new PBParamTypeError(name, 'pointer type of function parameter must be function or private');
1566
+ }
1567
+ const argType = funcArg.type;
1568
+ if (!argType.isPointerType()) {
1569
+ throw new PBInternalError(`ASTCallFunction(): invalid reference type`);
1570
+ }
1571
+ if (argType.addressSpace === PBAddressSpace.UNKNOWN) {
1572
+ argType.addressSpace = argAddressSpace;
1573
+ } else if (argType.addressSpace !== argAddressSpace) {
1574
+ throw new PBParamTypeError(name, `invalid pointer parameter address space '${argAddressSpace}', should be '${argType.addressSpace}`);
1575
+ }
1576
+ }
1577
+ this.args[i].markWritable();
1578
+ }
1579
+ }
1580
+ }
1581
+ for (const arg of this.args){
1582
+ if (arg instanceof ASTCallFunction) {
1583
+ arg.isStatement = false;
1584
+ }
1585
+ }
1586
+ }
1587
+ getType() {
1588
+ return this.retType;
1589
+ }
1590
+ isConstExp() {
1591
+ return false;
1592
+ }
1593
+ markWritable() {}
1594
+ isWritable() {
1595
+ return false;
1596
+ }
1597
+ getAddressSpace() {
1598
+ return null;
1599
+ }
1600
+ toWebGL(indent, ctx) {
1601
+ if (this.name === 'dFdx' || this.name === 'dFdy' || this.name === 'fwidth') {
1602
+ ctx.extensions.add('GL_OES_standard_derivatives');
1603
+ } else if (this.name === 'texture2DLodEXT' || this.name === 'texture2DProjLodEXT' || this.name === 'textureCubeLodEXT' || this.name === 'texture2DGradEXT' || this.name === 'texture2DProjGradEXT' || this.name === 'textureCubeGradEXT') {
1604
+ ctx.extensions.add('GL_EXT_shader_texture_lod');
1605
+ }
1606
+ const args = this.args.map((arg)=>unbracket(arg.toWebGL(indent, ctx)));
1607
+ return `${this.isStatement ? indent : ''}${this.name}(${args.join(',')})${this.isStatement ? ';\n' : ''}`;
1608
+ }
1609
+ toWebGL2(indent, ctx) {
1610
+ const args = this.args.map((arg)=>unbracket(arg.toWebGL2(indent, ctx)));
1611
+ return `${this.isStatement ? indent : ''}${this.name}(${args.join(',')})${this.isStatement ? ';\n' : ''}`;
1612
+ }
1613
+ toWGSL(indent, ctx) {
1614
+ let thisArgs = this.args.filter((val)=>{
1615
+ const type = val.getType();
1616
+ if (val instanceof ASTPrimitive && type.isStructType() && ctx.types.findIndex((t)=>t instanceof ASTStructDefine && t.type.structName === type.structName) < 0) {
1617
+ return false;
1618
+ }
1619
+ return true;
1620
+ });
1621
+ if (this.func) {
1622
+ let argsNew;
1623
+ const convertedArgs = convertArgs(thisArgs, this.func.funcType);
1624
+ if (convertedArgs) {
1625
+ argsNew = convertedArgs.args;
1626
+ }
1627
+ if (!argsNew) {
1628
+ throw new Error(`no matching overloading found for function '${this.name}'`);
1629
+ }
1630
+ thisArgs = argsNew;
1631
+ }
1632
+ const args = thisArgs.map((arg)=>unbracket(arg.toWGSL(indent, ctx)));
1633
+ return `${this.isStatement ? indent : ''}${this.name}(${args.join(',')})${this.isStatement ? ';\n' : ''}`;
1634
+ }
1635
+ toString(deviceType) {
1636
+ return `${this.name}(...)`;
1637
+ }
1638
+ }
1639
+ /** @internal */ class ASTDeclareVar extends ShaderAST {
1640
+ /** @internal */ value;
1641
+ /** @internal */ group;
1642
+ /** @internal */ binding;
1643
+ /** @internal */ blockName;
1644
+ constructor(exp){
1645
+ super();
1646
+ this.value = exp;
1647
+ this.group = 0;
1648
+ this.binding = 0;
1649
+ }
1650
+ isReference() {
1651
+ return true;
1652
+ }
1653
+ isPointer() {
1654
+ return this.value.getType().isPointerType();
1655
+ }
1656
+ toWebGL(indent, ctx) {
1657
+ let prefix = '';
1658
+ let builtin = false;
1659
+ let valueType = this.value.getType();
1660
+ switch(this.value.value.$declareType){
1661
+ case DeclareType.DECLARE_TYPE_IN:
1662
+ if (ctx.type === ShaderType.Vertex) {
1663
+ prefix = 'attribute ';
1664
+ ctx.defines.push(`#define ${this.value.name} ${semanticToAttrib(ctx.vertexAttributes[this.value.value.$location])}\n`);
1665
+ } else {
1666
+ prefix = 'varying ';
1667
+ // ctx.defines.push(`#define ${this.value.$str} ch_varying_${this.value.$location}\n`);
1668
+ }
1669
+ break;
1670
+ case DeclareType.DECLARE_TYPE_OUT:
1671
+ if (ctx.type === ShaderType.Vertex) {
1672
+ prefix = 'varying ';
1673
+ // ctx.defines.push(`#define ${this.value.$str} ch_varying_${this.value.$location}\n`);
1674
+ } else {
1675
+ builtin = true;
1676
+ if (ctx.mrt) {
1677
+ ctx.defines.push(`#define ${this.value.name} gl_FragData[${this.value.value.$location}]\n`);
1678
+ ctx.extensions.add('GL_EXT_draw_buffers');
1679
+ } else {
1680
+ ctx.defines.push(`#define ${this.value.name} gl_FragColor\n`);
1681
+ }
1682
+ }
1683
+ break;
1684
+ case DeclareType.DECLARE_TYPE_UNIFORM:
1685
+ prefix = 'uniform ';
1686
+ valueType = ctx.typeReplacement?.get(this.value.value) || valueType;
1687
+ break;
1688
+ case DeclareType.DECLARE_TYPE_STORAGE:
1689
+ throw new Error(`invalid variable declare type: ${this.value.name}`);
1690
+ }
1691
+ if (!builtin) {
1692
+ return `${indent}${prefix}${valueType.toTypeName('webgl', this.value.name)};\n`;
1693
+ }
1694
+ }
1695
+ toWebGL2(indent, ctx) {
1696
+ let prefix = '';
1697
+ let valueType = this.value.getType();
1698
+ switch(this.value.value.$declareType){
1699
+ case DeclareType.DECLARE_TYPE_IN:
1700
+ if (ctx.type === ShaderType.Fragment && valueType.isPrimitiveType() && valueType.isInteger()) {
1701
+ prefix = 'flat in ';
1702
+ } else {
1703
+ prefix = 'in ';
1704
+ }
1705
+ if (ctx.type === ShaderType.Vertex) {
1706
+ ctx.defines.push(`#define ${this.value.name} ${semanticToAttrib(ctx.vertexAttributes[this.value.value.$location])}\n`);
1707
+ }
1708
+ break;
1709
+ case DeclareType.DECLARE_TYPE_OUT:
1710
+ if (ctx.type === ShaderType.Vertex) {
1711
+ if (valueType.isPrimitiveType() && valueType.isInteger()) {
1712
+ prefix = 'flat out ';
1713
+ } else {
1714
+ prefix = 'out ';
1715
+ }
1716
+ } else {
1717
+ prefix = `layout(location = ${this.value.value.$location}) out `;
1718
+ }
1719
+ break;
1720
+ case DeclareType.DECLARE_TYPE_UNIFORM:
1721
+ if (valueType.isStructType()) {
1722
+ /*
1723
+ if (valueType.layout !== 'std140') {
1724
+ throw new errors.PBASTError(this, 'uniform buffer layout must be std140');
1725
+ }
1726
+ */ return `${indent}layout(std140) uniform ${this.blockName} { ${valueType.structName} ${this.value.name}; };\n`;
1727
+ } else {
1728
+ valueType = ctx.typeReplacement?.get(this.value.value) || valueType;
1729
+ return `${indent}uniform ${valueType.toTypeName('webgl2', this.value.name)};\n`;
1730
+ }
1731
+ case DeclareType.DECLARE_TYPE_STORAGE:
1732
+ throw new Error(`invalid variable declare type: ${this.value.name}`);
1733
+ }
1734
+ {
1735
+ return `${indent}${prefix}${this.value.getType().toTypeName('webgl2', this.value.name)};\n`;
1736
+ }
1737
+ }
1738
+ toWGSL(indent, ctx) {
1739
+ let prefix;
1740
+ const isBlock = this.value.getType().isPrimitiveType() || this.value.getType().isStructType() || this.value.getType().isArrayType();
1741
+ switch(this.value.value.$declareType){
1742
+ case DeclareType.DECLARE_TYPE_IN:
1743
+ case DeclareType.DECLARE_TYPE_OUT:
1744
+ // prefix = `@location(${this.value.value.$location}) var<out> `;
1745
+ throw new Error(`Internal error`);
1746
+ case DeclareType.DECLARE_TYPE_UNIFORM:
1747
+ if (this.group === undefined) {
1748
+ debugger;
1749
+ }
1750
+ prefix = `@group(${this.group}) @binding(${this.binding}) var${isBlock ? '<uniform>' : ''} `;
1751
+ break;
1752
+ case DeclareType.DECLARE_TYPE_STORAGE:
1753
+ prefix = `@group(${this.group}) @binding(${this.binding}) var<storage, ${this.value.isWritable() ? 'read_write' : 'read'}> `;
1754
+ break;
1755
+ case DeclareType.DECLARE_TYPE_WORKGROUP:
1756
+ prefix = `var<workgroup> `;
1757
+ break;
1758
+ default:
1759
+ prefix = `${this.value.getType().isPointerType() ? 'let' : 'var'}${this.value.value.$global && !this.value.getType().isPointerType() ? '<private>' : ''} `;
1760
+ }
1761
+ {
1762
+ const type = this.value.getType();
1763
+ const structName = type.isStructType() ? type.structName : null;
1764
+ if (structName && ctx.types.findIndex((val)=>val instanceof ASTStructDefine && val.type.structName === structName) < 0) {
1765
+ return '';
1766
+ } else {
1767
+ return `${indent}${prefix}${type.toTypeName('webgpu', this.value.name)};\n`;
1768
+ }
1769
+ }
1770
+ }
1771
+ toString(deviceType) {
1772
+ return this.value.toString(deviceType);
1773
+ }
1774
+ }
1775
+ /** @internal */ class ASTFunction extends ASTScope {
1776
+ /** @internal */ name;
1777
+ /** @internal */ args;
1778
+ /** @internal */ isBuiltin;
1779
+ /** @internal */ isMainFunc;
1780
+ /** @internal */ funcType;
1781
+ /** @internal */ builtins;
1782
+ /** @internal */ returnType;
1783
+ constructor(name, args, isMainFunc, type, isBuiltin = false){
1784
+ super();
1785
+ this.name = name;
1786
+ this.args = args;
1787
+ this.funcType = type;
1788
+ this.builtins = [];
1789
+ this.isBuiltin = isBuiltin;
1790
+ this.isMainFunc = isMainFunc;
1791
+ this.returnType = type ? type.returnType : null;
1792
+ }
1793
+ toWebGL(indent, ctx) {
1794
+ if (!this.isBuiltin) {
1795
+ let str = '';
1796
+ const p = [];
1797
+ for (const param of this.args){
1798
+ let exp;
1799
+ let name;
1800
+ let qualifier;
1801
+ if (param.paramAST instanceof ASTPrimitive) {
1802
+ exp = param.paramAST.value;
1803
+ name = param.paramAST.name;
1804
+ qualifier = '';
1805
+ } else {
1806
+ exp = param.paramAST.value.value;
1807
+ name = param.paramAST.value.name;
1808
+ qualifier = `${exp.$inout} `;
1809
+ }
1810
+ p.push(`${qualifier}${param.getType().toTypeName('webgl', name)}`);
1811
+ }
1812
+ str += `${indent}${this.returnType.toTypeName('webgl')} ${this.name}(${p.join(',')}) {\n`;
1813
+ str += super.toWebGL(indent + ' ', ctx);
1814
+ str += `${indent}}\n`;
1815
+ return str;
1816
+ } else {
1817
+ return '';
1818
+ }
1819
+ }
1820
+ toWebGL2(indent, ctx) {
1821
+ if (!this.isBuiltin) {
1822
+ let str = '';
1823
+ const p = [];
1824
+ for (const param of this.args){
1825
+ let exp;
1826
+ let name;
1827
+ let qualifier;
1828
+ if (param.paramAST instanceof ASTPrimitive) {
1829
+ exp = param.paramAST.value;
1830
+ name = param.paramAST.name;
1831
+ qualifier = '';
1832
+ } else {
1833
+ exp = param.paramAST.value.value;
1834
+ name = param.paramAST.value.name;
1835
+ qualifier = `${exp.$inout} `;
1836
+ }
1837
+ p.push(`${qualifier}${param.getType().toTypeName('webgl2', name)}`);
1838
+ }
1839
+ str += `${indent}${this.returnType.toTypeName('webgl2')} ${this.name}(${p.join(',')}) {\n`;
1840
+ str += super.toWebGL2(indent + ' ', ctx);
1841
+ str += `${indent}}\n`;
1842
+ return str;
1843
+ } else {
1844
+ return '';
1845
+ }
1846
+ }
1847
+ toWGSL(indent, ctx) {
1848
+ if (!this.isBuiltin) {
1849
+ let str = '';
1850
+ const p = [
1851
+ ...this.builtins
1852
+ ];
1853
+ for (const param of this.args){
1854
+ const name = param.paramAST instanceof ASTPrimitive ? param.paramAST.name : param.paramAST.value.name;
1855
+ const paramType = param.paramAST instanceof ASTPrimitive ? param.paramAST.getType() : param.paramAST.value.getType();
1856
+ const dataType = paramType.isPointerType() ? paramType.pointerType : paramType;
1857
+ if (dataType.isStructType() && ctx.types.findIndex((t)=>t instanceof ASTStructDefine && t.type.structName === dataType.structName) < 0) {
1858
+ continue;
1859
+ }
1860
+ p.push(`${paramType.toTypeName('webgpu', name)}`);
1861
+ }
1862
+ let t = '';
1863
+ if (this.isMainFunc) {
1864
+ switch(ctx.type){
1865
+ case ShaderType.Vertex:
1866
+ t = '@vertex ';
1867
+ break;
1868
+ case ShaderType.Fragment:
1869
+ t = '@fragment ';
1870
+ break;
1871
+ case ShaderType.Compute:
1872
+ t = `@compute @workgroup_size(${ctx.workgroupSize[0]}, ${ctx.workgroupSize[1]}, ${ctx.workgroupSize[2]}) `;
1873
+ break;
1874
+ }
1875
+ }
1876
+ const retName = this.returnType.isVoidType() ? null : this.returnType.toTypeName('webgpu');
1877
+ const retStr = retName ? ` -> ${retName}` : '';
1878
+ str += `${indent}${t}fn ${this.name}(${p.join(',')})${retStr} {\n`;
1879
+ str += super.toWGSL(indent + ' ', ctx);
1880
+ str += `${indent}}\n`;
1881
+ return str;
1882
+ } else {
1883
+ return '';
1884
+ }
1885
+ }
1886
+ }
1887
+ /** @internal */ class ASTIf extends ASTScope {
1888
+ /** @internal */ keyword;
1889
+ /** @internal */ condition;
1890
+ /** @internal */ nextElse;
1891
+ constructor(keyword, condition){
1892
+ super();
1893
+ this.keyword = keyword;
1894
+ this.condition = condition;
1895
+ this.nextElse = null;
1896
+ if (this.condition instanceof ASTCallFunction) {
1897
+ this.condition.isStatement = false;
1898
+ }
1899
+ }
1900
+ toWebGL(indent, ctx) {
1901
+ let str = `${indent}${this.keyword} ${this.condition ? '(' + unbracket(this.condition.toWebGL(indent, ctx)) + ')' : ''} {\n`;
1902
+ str += super.toWebGL(indent + ' ', ctx);
1903
+ str += `${indent}}\n`;
1904
+ if (this.nextElse) {
1905
+ str += this.nextElse.toWebGL(indent, ctx);
1906
+ }
1907
+ return str;
1908
+ }
1909
+ toWebGL2(indent, ctx) {
1910
+ let str = `${indent}${this.keyword} ${this.condition ? '(' + unbracket(this.condition.toWebGL2(indent, ctx)) + ')' : ''} {\n`;
1911
+ str += super.toWebGL2(indent + ' ', ctx);
1912
+ str += `${indent}}\n`;
1913
+ if (this.nextElse) {
1914
+ str += this.nextElse.toWebGL2(indent, ctx);
1915
+ }
1916
+ return str;
1917
+ }
1918
+ toWGSL(indent, ctx) {
1919
+ let str = `${indent}${this.keyword} ${this.condition ? '(' + unbracket(this.condition.toWGSL(indent, ctx)) + ')' : ''} {\n`;
1920
+ str += super.toWGSL(indent + ' ', ctx);
1921
+ str += `${indent}}\n`;
1922
+ if (this.nextElse) {
1923
+ str += this.nextElse.toWGSL(indent, ctx);
1924
+ }
1925
+ return str;
1926
+ }
1927
+ }
1928
+ /** @internal */ class ASTRange extends ASTScope {
1929
+ /** @internal */ init;
1930
+ /** @internal */ start;
1931
+ /** @internal */ end;
1932
+ /** @internal */ open;
1933
+ constructor(init, start, end, open){
1934
+ super();
1935
+ this.init = init;
1936
+ this.start = start;
1937
+ this.end = end;
1938
+ this.open = open;
1939
+ this.statements = [];
1940
+ if (this.start instanceof ASTCallFunction) {
1941
+ this.start.isStatement = false;
1942
+ }
1943
+ if (this.end instanceof ASTCallFunction) {
1944
+ this.end.isStatement = false;
1945
+ }
1946
+ }
1947
+ toWebGL(indent, ctx) {
1948
+ const init = this.init.getType().toTypeName('webgl', this.init.name);
1949
+ const start = unbracket(this.start.toWebGL(indent, ctx));
1950
+ const end = unbracket(this.end.toWebGL(indent, ctx));
1951
+ const comp = this.open ? '<' : '<=';
1952
+ let str = `${indent}for (${init} = ${start}; ${this.init.name} ${comp} ${end}; ${this.init.name}++) {\n`;
1953
+ str += super.toWebGL(indent + ' ', ctx);
1954
+ str += `${indent}}\n`;
1955
+ return str;
1956
+ }
1957
+ toWebGL2(indent, ctx) {
1958
+ const init = this.init.getType().toTypeName('webgl2', this.init.name);
1959
+ const start = unbracket(this.start.toWebGL2(indent, ctx));
1960
+ const end = unbracket(this.end.toWebGL2(indent, ctx));
1961
+ const comp = this.open ? '<' : '<=';
1962
+ let str = `${indent}for (${init} = ${start}; ${this.init.name} ${comp} ${end}; ${this.init.name}++) {\n`;
1963
+ str += super.toWebGL2(indent + ' ', ctx);
1964
+ str += `${indent}}\n`;
1965
+ return str;
1966
+ }
1967
+ toWGSL(indent, ctx) {
1968
+ const init = `var ${this.init.getType().toTypeName('webgpu', this.init.name)}`;
1969
+ const start = unbracket(this.start.toWGSL(indent, ctx));
1970
+ const end = unbracket(this.end.toWGSL(indent, ctx));
1971
+ const incr = new ASTScalar(1, this.init.getType()).toWGSL(indent, ctx);
1972
+ const comp = this.open ? '<' : '<=';
1973
+ let str = `${indent}for (${init} = ${start}; ${this.init.name} ${comp} ${end}; ${this.init.name} = ${this.init.name} + ${incr}) {\n`;
1974
+ str += super.toWGSL(indent + ' ', ctx);
1975
+ str += `${indent}}\n`;
1976
+ return str;
1977
+ }
1978
+ }
1979
+ /** @internal */ class ASTDoWhile extends ASTScope {
1980
+ /** @internal */ condition;
1981
+ constructor(condition){
1982
+ super();
1983
+ this.condition = condition;
1984
+ if (this.condition instanceof ASTCallFunction) {
1985
+ this.condition.isStatement = false;
1986
+ }
1987
+ }
1988
+ toWebGL(indent, ctx) {
1989
+ let str = `${indent}do {\n`;
1990
+ str += super.toWebGL(indent + ' ', ctx);
1991
+ str += `${indent}} while(${unbracket(this.condition.toWebGL(indent, ctx))});\n`;
1992
+ return str;
1993
+ }
1994
+ toWebGL2(indent, ctx) {
1995
+ let str = `${indent}do {\n`;
1996
+ str += super.toWebGL2(indent + ' ', ctx);
1997
+ str += `${indent}} while(${unbracket(this.condition.toWebGL2(indent, ctx))});\n`;
1998
+ return str;
1999
+ }
2000
+ toWGSL(indent, ctx) {
2001
+ let str = `${indent}loop {\n`;
2002
+ str += super.toWGSL(indent + ' ', ctx);
2003
+ str += `${indent} if (!(${unbracket(this.condition.toWGSL(indent, ctx))})) { break; }\n`;
2004
+ str += `${indent}}\n`;
2005
+ return str;
2006
+ }
2007
+ }
2008
+ /** @internal */ class ASTWhile extends ASTScope {
2009
+ /** @internal */ condition;
2010
+ constructor(condition){
2011
+ super();
2012
+ this.condition = condition;
2013
+ if (this.condition instanceof ASTCallFunction) {
2014
+ this.condition.isStatement = false;
2015
+ }
2016
+ }
2017
+ toWebGL(indent, ctx) {
2018
+ let str = `${indent}while(${unbracket(this.condition.toWebGL(indent, ctx))}) {\n`;
2019
+ str += super.toWebGL(indent + ' ', ctx);
2020
+ str += `${indent}}\n`;
2021
+ return str;
2022
+ }
2023
+ toWebGL2(indent, ctx) {
2024
+ let str = `${indent}while(${unbracket(this.condition.toWebGL2(indent, ctx))}) {\n`;
2025
+ str += super.toWebGL2(indent + ' ', ctx);
2026
+ str += `${indent}}\n`;
2027
+ return str;
2028
+ }
2029
+ toWGSL(indent, ctx) {
2030
+ let str = `${indent}for(;${unbracket(this.condition.toWGSL(indent, ctx))};) {\n`;
2031
+ str += super.toWGSL(indent + ' ', ctx);
2032
+ str += `${indent}}\n`;
2033
+ return str;
2034
+ /*
2035
+ let str = `${indent}loop {\n`;
2036
+ const newIndent = indent + ' ';
2037
+ str += `${newIndent}if (!(${unbracket(this.condition.toWGSL(indent, ctx))})) { break; }\n`;
2038
+ str += super.toWGSL(newIndent, ctx);
2039
+ str += `${indent}}\n`;
2040
+ return str;
2041
+ */ }
2042
+ }
2043
+ /** @internal */ class ASTStructDefine extends ShaderAST {
2044
+ /** @internal */ type;
2045
+ /** @internal */ prefix;
2046
+ /** @internal */ builtin;
2047
+ constructor(type, builtin){
2048
+ super();
2049
+ this.prefix = null;
2050
+ this.builtin = builtin;
2051
+ this.type = type;
2052
+ }
2053
+ getType() {
2054
+ return this.type;
2055
+ }
2056
+ toWebGL(indent, ctx) {
2057
+ if (!this.builtin) {
2058
+ let str = `${indent}struct ${this.type.structName} {\n`;
2059
+ for (const arg of this.type.structMembers){
2060
+ str += `${indent} ${arg.type.toTypeName('webgl', arg.name)};\n`;
2061
+ }
2062
+ str += `${indent}};\n`;
2063
+ return str;
2064
+ } else {
2065
+ return '';
2066
+ }
2067
+ }
2068
+ toWebGL2(indent, ctx) {
2069
+ if (!this.builtin) {
2070
+ let str = `${indent}struct ${this.type.structName} {\n`;
2071
+ for (const arg of this.type.structMembers){
2072
+ str += `${indent} ${arg.type.toTypeName('webgl2', arg.name)};\n`;
2073
+ }
2074
+ str += `${indent}};\n`;
2075
+ return str;
2076
+ } else {
2077
+ return '';
2078
+ }
2079
+ }
2080
+ toWGSL(indent, ctx) {
2081
+ if (!this.builtin) {
2082
+ let str = `${indent}struct ${this.type.structName} {\n`;
2083
+ str += this.type.structMembers.map((arg, i)=>{
2084
+ const prefix = this.prefix ? this.prefix[i] : '';
2085
+ const sizePrefix = arg.type.getLayoutSize(this.type.layout) !== arg.type.getLayoutSize('default') ? `@size(${arg.type.getLayoutSize(this.type.layout)}) ` : '';
2086
+ const alignPrefix = i > 0 && arg.type.getLayoutAlignment(this.type.layout) !== arg.type.getLayoutAlignment('default') ? `@align(${arg.type.getLayoutAlignment(this.type.layout)}) ` : '';
2087
+ return `${indent} ${prefix}${alignPrefix}${sizePrefix}${arg.type.toTypeName('webgpu', arg.name)}`;
2088
+ }).join(',\n');
2089
+ str += `\n${indent}};\n`;
2090
+ return str;
2091
+ } else {
2092
+ return '';
2093
+ }
2094
+ }
2095
+ }
2096
+ function convertArgs(args, overload) {
2097
+ if (args.length !== overload.argTypes.length) {
2098
+ return null;
2099
+ }
2100
+ const result = [];
2101
+ for(let i = 0; i < args.length; i++){
2102
+ const isRef = !!overload.argTypes[i].byRef;
2103
+ const argType = isRef ? overload.argTypes[i].type.pointerType : overload.argTypes[i].type;
2104
+ const arg = args[i];
2105
+ if (typeof arg === 'number') {
2106
+ if (!isRef && argType.isPrimitiveType() && argType.isScalarType() && argType.primitiveType !== PBPrimitiveType.BOOL) {
2107
+ result.push(new ASTScalar(arg, argType));
2108
+ } else {
2109
+ return null;
2110
+ }
2111
+ } else if (typeof arg === 'boolean') {
2112
+ if (!isRef && argType.isPrimitiveType() && argType.primitiveType === PBPrimitiveType.BOOL) {
2113
+ result.push(new ASTScalar(arg, argType));
2114
+ } else {
2115
+ return null;
2116
+ }
2117
+ } else if (argType.isCompatibleType(arg.getType())) {
2118
+ if (isRef) {
2119
+ arg.markWritable();
2120
+ result.push(new ASTAddressOf(arg));
2121
+ } else {
2122
+ result.push(arg);
2123
+ }
2124
+ } else {
2125
+ return null;
2126
+ }
2127
+ }
2128
+ return {
2129
+ name: overload.name,
2130
+ args: result
2131
+ };
2132
+ }
2133
+
2134
+ export { ASTAddressOf, ASTArrayIndex, ASTAssignment, ASTBinaryFunc, ASTBreak, ASTCallFunction, ASTCast, ASTContinue, ASTDeclareVar, ASTDiscard, ASTDoWhile, ASTExpression, ASTFunction, ASTFunctionParameter, ASTGlobalScope, ASTHash, ASTIf, ASTLValue, ASTLValueArray, ASTLValueDeclare, ASTLValueHash, ASTLValueScalar, ASTNakedScope, ASTPrimitive, ASTRange, ASTReferenceOf, ASTReturn, ASTScalar, ASTScope, ASTSelect, ASTShaderExpConstructor, ASTStructDefine, ASTTouch, ASTUnaryFunc, ASTWhile, DeclareType, ShaderAST, ShaderPrecisionType, builtinVariables, genSamplerName, getBuiltinInputStructInstanceName, getBuiltinInputStructName, getBuiltinOutputStructInstanceName, getBuiltinOutputStructName, getTextureSampleType };
2135
+ //# sourceMappingURL=ast.js.map