@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,4101 @@
1
+ import { PBPrimitiveType, typeU32, typeF32, typeAtomicI32, typeI32, typeAtomicU32, typeVoid, PBFunctionTypeInfo, typeF32Vec2, typeF32Vec3, typeF32Vec4, typeI32Vec2, typeI32Vec3, typeI32Vec4, typeU32Vec2, typeU32Vec3, typeU32Vec4, typeMat2, typeMat3x2, typeMat4x2, typeMat2x3, typeMat3, typeMat4x3, typeMat2x4, typeMat3x4, typeMat4, typeFrexpResult, typeFrexpResultVec2, typeFrexpResultVec3, typeFrexpResultVec4, typeBool, typeTex1D, typeITex1D, typeUTex1D, typeTex2D, typeITex2D, typeUTex2D, typeTex2DArray, typeITex2DArray, typeUTex2DArray, typeTex3D, typeITex3D, typeUTex3D, typeTexCube, typeITexCube, typeUTexCube, typeTexCubeArray, typeITexCubeArray, typeUTexCubeArray, typeTexMultisampled2D, typeITexMultisampled2D, typeUTexMultisampled2D, typeTexDepth2D, typeTexDepth2DArray, typeTexDepthCube, typeTexDepthCubeArray, typeTexDepthMultisampled2D, typeTexStorage1D_rgba8unorm, typeTexStorage1D_rgba8snorm, typeTexStorage1D_rgba8uint, typeTexStorage1D_rgba8sint, typeTexStorage1D_rgba16uint, typeTexStorage1D_rgba16sint, typeTexStorage1D_rgba16float, typeTexStorage1D_rgba32uint, typeTexStorage1D_rgba32sint, typeTexStorage1D_rgba32float, typeTexStorage1D_rg32uint, typeTexStorage1D_rg32sint, typeTexStorage1D_rg32float, typeTexStorage1D_r32uint, typeTexStorage1D_r32sint, typeTexStorage1D_r32float, typeTexStorage2D_rgba8unorm, typeTexStorage2D_rgba8snorm, typeTexStorage2D_rgba8uint, typeTexStorage2D_rgba8sint, typeTexStorage2D_rgba16uint, typeTexStorage2D_rgba16sint, typeTexStorage2D_rgba16float, typeTexStorage2D_rgba32uint, typeTexStorage2D_rgba32sint, typeTexStorage2D_rgba32float, typeTexStorage2D_rg32uint, typeTexStorage2D_rg32sint, typeTexStorage2D_rg32float, typeTexStorage2D_r32uint, typeTexStorage2D_r32sint, typeTexStorage2D_r32float, typeTexStorage2DArray_rgba8unorm, typeTexStorage2DArray_rgba8snorm, typeTexStorage2DArray_rgba8uint, typeTexStorage2DArray_rgba8sint, typeTexStorage2DArray_rgba16uint, typeTexStorage2DArray_rgba16sint, typeTexStorage2DArray_rgba16float, typeTexStorage2DArray_rgba32uint, typeTexStorage2DArray_rgba32sint, typeTexStorage2DArray_rgba32float, typeTexStorage2DArray_rg32uint, typeTexStorage2DArray_rg32sint, typeTexStorage2DArray_rg32float, typeTexStorage2DArray_r32uint, typeTexStorage2DArray_r32sint, typeTexStorage2DArray_r32float, typeTexStorage3D_rgba8unorm, typeTexStorage3D_rgba8snorm, typeTexStorage3D_rgba8uint, typeTexStorage3D_rgba8sint, typeTexStorage3D_rgba16uint, typeTexStorage3D_rgba16sint, typeTexStorage3D_rgba16float, typeTexStorage3D_rgba32uint, typeTexStorage3D_rgba32sint, typeTexStorage3D_rgba32float, typeTexStorage3D_rg32uint, typeTexStorage3D_rg32sint, typeTexStorage3D_rg32float, typeTexStorage3D_r32uint, typeTexStorage3D_r32sint, typeTexStorage3D_r32float, typeSampler, typeSamplerComparison, typeTexExternal, typeBVec2, typeBVec3, typeBVec4 } from './types.js';
2
+ import { ASTAddressOf, ASTScalar, ASTFunction, ASTUnaryFunc, ASTBinaryFunc } from './ast.js';
3
+ import { PBShaderExp } from './base.js';
4
+ import { PBParamLengthError, PBDeviceNotSupport, PBParamValueError, PBParamTypeError, PBOverloadingMatchError } from './errors.js';
5
+
6
+ const genTypeList = [
7
+ [
8
+ typeF32,
9
+ typeF32Vec2,
10
+ typeF32Vec3,
11
+ typeF32Vec4
12
+ ],
13
+ [
14
+ typeI32,
15
+ typeI32Vec2,
16
+ typeI32Vec3,
17
+ typeI32Vec4
18
+ ],
19
+ [
20
+ typeU32,
21
+ typeU32Vec2,
22
+ typeU32Vec3,
23
+ typeU32Vec4
24
+ ],
25
+ [
26
+ typeBool,
27
+ typeBVec2,
28
+ typeBVec3,
29
+ typeBVec4
30
+ ]
31
+ ];
32
+ const genMatrixTypeList = [
33
+ typeMat2,
34
+ typeMat2x3,
35
+ typeMat2x4,
36
+ typeMat3x2,
37
+ typeMat3,
38
+ typeMat3x4,
39
+ typeMat4x2,
40
+ typeMat4x3,
41
+ typeMat4
42
+ ];
43
+ function matchFunctionOverloadings(pb, name, ...args) {
44
+ const bit = pb.getDevice().type === 'webgl' ? MASK_WEBGL1 : pb.getDevice().type === 'webgl2' ? MASK_WEBGL2 : MASK_WEBGPU;
45
+ const overloadings = builtinFunctionsAll?.[name].overloads.filter((val)=>!!(val[1] & bit)).map((val)=>val[0]);
46
+ if (!overloadings || overloadings.length === 0) {
47
+ throw new PBDeviceNotSupport(`builtin shader function '${name}'`);
48
+ }
49
+ const argsNonArray = args.map((val)=>pb.normalizeExpValue(val));
50
+ const matchResult = pb._matchFunctionOverloading(overloadings, argsNonArray);
51
+ if (!matchResult) {
52
+ throw new PBOverloadingMatchError(name);
53
+ }
54
+ return matchResult;
55
+ }
56
+ function callBuiltinChecked(pb, matchResult) {
57
+ return pb.$callFunction(matchResult[0].name, matchResult[1], matchResult[0]);
58
+ }
59
+ function callBuiltin(pb, name, ...args) {
60
+ return callBuiltinChecked(pb, matchFunctionOverloadings(pb, name, ...args));
61
+ }
62
+ function genMatrixType(name, shaderTypeMask, r, args) {
63
+ const result = [];
64
+ for(let i = 0; i < genMatrixTypeList.length; i++){
65
+ const returnType = r || genMatrixTypeList[i];
66
+ const argTypes = args.map((arg)=>{
67
+ return {
68
+ type: arg || genMatrixTypeList[i]
69
+ };
70
+ });
71
+ result.push([
72
+ new ASTFunction(name, null, false, new PBFunctionTypeInfo(name, returnType, argTypes), true),
73
+ shaderTypeMask
74
+ ]);
75
+ }
76
+ return result;
77
+ }
78
+ function genType(name, shaderTypeMask, r, args, vecOnly) {
79
+ if (args.findIndex((val)=>typeof val === 'number') < 0) {
80
+ return [
81
+ [
82
+ new ASTFunction(name, null, false, new PBFunctionTypeInfo(name, r, args.map((arg)=>({
83
+ type: arg
84
+ }))), true),
85
+ shaderTypeMask
86
+ ]
87
+ ];
88
+ } else {
89
+ const result = [];
90
+ let i = vecOnly ? 1 : 0;
91
+ for(; i < 4; i++){
92
+ const returnType = typeof r === 'number' ? genTypeList[r][i] : r;
93
+ const argTypes = args.map((arg)=>{
94
+ if (typeof arg === 'number') {
95
+ return {
96
+ type: genTypeList[arg][i]
97
+ };
98
+ } else {
99
+ return {
100
+ type: arg
101
+ };
102
+ }
103
+ });
104
+ result.push([
105
+ new ASTFunction(name, null, false, new PBFunctionTypeInfo(name, returnType, argTypes), true),
106
+ shaderTypeMask
107
+ ]);
108
+ }
109
+ return result;
110
+ }
111
+ }
112
+ function unaryFunc(a, op, type) {
113
+ const exp = new PBShaderExp('', type);
114
+ exp.$ast = new ASTUnaryFunc(a, op, type);
115
+ return exp;
116
+ }
117
+ function binaryFunc(a, b, op, type) {
118
+ const exp = new PBShaderExp('', type);
119
+ exp.$ast = new ASTBinaryFunc(a, b, op, type);
120
+ return exp;
121
+ }
122
+ const MASK_WEBGL1 = 1 << 0;
123
+ const MASK_WEBGL2 = 1 << 1;
124
+ const MASK_WEBGPU = 1 << 2;
125
+ const MASK_WEBGL = MASK_WEBGL1 | MASK_WEBGL2;
126
+ const MASK_ALL = MASK_WEBGL | MASK_WEBGPU;
127
+ const builtinFunctionsAll = {
128
+ add_2: {
129
+ overloads: [
130
+ ...genType('', MASK_ALL, 0, [
131
+ 0,
132
+ 0
133
+ ]),
134
+ ...genType('', MASK_ALL, 1, [
135
+ 1,
136
+ 1
137
+ ]),
138
+ ...genType('', MASK_ALL, 2, [
139
+ 2,
140
+ 2
141
+ ]),
142
+ ...genType('', MASK_ALL, 3, [
143
+ 3,
144
+ 3
145
+ ]),
146
+ ...genType('', MASK_ALL, typeF32Vec2, [
147
+ typeF32,
148
+ typeF32Vec2
149
+ ]),
150
+ ...genType('', MASK_ALL, typeF32Vec2, [
151
+ typeF32Vec2,
152
+ typeF32
153
+ ]),
154
+ ...genType('', MASK_ALL, typeF32Vec3, [
155
+ typeF32,
156
+ typeF32Vec3
157
+ ]),
158
+ ...genType('', MASK_ALL, typeF32Vec3, [
159
+ typeF32Vec3,
160
+ typeF32
161
+ ]),
162
+ ...genType('', MASK_ALL, typeF32Vec4, [
163
+ typeF32,
164
+ typeF32Vec4
165
+ ]),
166
+ ...genType('', MASK_ALL, typeF32Vec4, [
167
+ typeF32Vec4,
168
+ typeF32
169
+ ]),
170
+ ...genType('', MASK_ALL, typeI32Vec2, [
171
+ typeI32,
172
+ typeI32Vec2
173
+ ]),
174
+ ...genType('', MASK_ALL, typeI32Vec2, [
175
+ typeI32Vec2,
176
+ typeI32
177
+ ]),
178
+ ...genType('', MASK_ALL, typeI32Vec3, [
179
+ typeI32,
180
+ typeI32Vec3
181
+ ]),
182
+ ...genType('', MASK_ALL, typeI32Vec3, [
183
+ typeI32Vec3,
184
+ typeI32
185
+ ]),
186
+ ...genType('', MASK_ALL, typeI32Vec4, [
187
+ typeI32,
188
+ typeI32Vec4
189
+ ]),
190
+ ...genType('', MASK_ALL, typeI32Vec4, [
191
+ typeI32Vec4,
192
+ typeI32
193
+ ]),
194
+ ...genType('', MASK_ALL, typeU32Vec2, [
195
+ typeU32,
196
+ typeU32Vec2
197
+ ]),
198
+ ...genType('', MASK_ALL, typeU32Vec2, [
199
+ typeU32Vec2,
200
+ typeU32
201
+ ]),
202
+ ...genType('', MASK_ALL, typeU32Vec3, [
203
+ typeU32,
204
+ typeU32Vec3
205
+ ]),
206
+ ...genType('', MASK_ALL, typeU32Vec3, [
207
+ typeU32Vec3,
208
+ typeU32
209
+ ]),
210
+ ...genType('', MASK_ALL, typeU32Vec4, [
211
+ typeU32,
212
+ typeU32Vec4
213
+ ]),
214
+ ...genType('', MASK_ALL, typeU32Vec4, [
215
+ typeU32Vec4,
216
+ typeU32
217
+ ]),
218
+ ...genMatrixType('', MASK_ALL, null, [
219
+ null,
220
+ null
221
+ ])
222
+ ],
223
+ normalizeFunc (pb, name, ...args) {
224
+ if (args.length === 2 && typeof args[0] === 'number' && typeof args[1] === 'number') {
225
+ return args[0] + args[1];
226
+ }
227
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
228
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '+', matchResult[0].returnType);
229
+ }
230
+ },
231
+ add: {
232
+ overloads: [],
233
+ normalizeFunc (pb, name, ...args) {
234
+ if (args.length < 2) {
235
+ throw new PBParamLengthError('add');
236
+ }
237
+ let result = args[0];
238
+ for(let i = 1; i < args.length; i++){
239
+ result = pb.add_2(result, args[i]);
240
+ }
241
+ return result;
242
+ }
243
+ },
244
+ sub: {
245
+ overloads: [
246
+ ...genType('', MASK_ALL, 0, [
247
+ 0,
248
+ 0
249
+ ]),
250
+ ...genType('', MASK_ALL, 1, [
251
+ 1,
252
+ 1
253
+ ]),
254
+ ...genType('', MASK_ALL, 2, [
255
+ 2,
256
+ 2
257
+ ]),
258
+ ...genType('', MASK_ALL, 3, [
259
+ 3,
260
+ 3
261
+ ]),
262
+ ...genType('', MASK_ALL, typeF32Vec2, [
263
+ typeF32,
264
+ typeF32Vec2
265
+ ]),
266
+ ...genType('', MASK_ALL, typeF32Vec2, [
267
+ typeF32Vec2,
268
+ typeF32
269
+ ]),
270
+ ...genType('', MASK_ALL, typeF32Vec3, [
271
+ typeF32,
272
+ typeF32Vec3
273
+ ]),
274
+ ...genType('', MASK_ALL, typeF32Vec3, [
275
+ typeF32Vec3,
276
+ typeF32
277
+ ]),
278
+ ...genType('', MASK_ALL, typeF32Vec4, [
279
+ typeF32,
280
+ typeF32Vec4
281
+ ]),
282
+ ...genType('', MASK_ALL, typeF32Vec4, [
283
+ typeF32Vec4,
284
+ typeF32
285
+ ]),
286
+ ...genType('', MASK_ALL, typeI32Vec2, [
287
+ typeI32,
288
+ typeI32Vec2
289
+ ]),
290
+ ...genType('', MASK_ALL, typeI32Vec2, [
291
+ typeI32Vec2,
292
+ typeI32
293
+ ]),
294
+ ...genType('', MASK_ALL, typeI32Vec3, [
295
+ typeI32,
296
+ typeI32Vec3
297
+ ]),
298
+ ...genType('', MASK_ALL, typeI32Vec3, [
299
+ typeI32Vec3,
300
+ typeI32
301
+ ]),
302
+ ...genType('', MASK_ALL, typeI32Vec4, [
303
+ typeI32,
304
+ typeI32Vec4
305
+ ]),
306
+ ...genType('', MASK_ALL, typeI32Vec4, [
307
+ typeI32Vec4,
308
+ typeI32
309
+ ]),
310
+ ...genType('', MASK_ALL, typeU32Vec2, [
311
+ typeU32,
312
+ typeU32Vec2
313
+ ]),
314
+ ...genType('', MASK_ALL, typeU32Vec2, [
315
+ typeU32Vec2,
316
+ typeU32
317
+ ]),
318
+ ...genType('', MASK_ALL, typeU32Vec3, [
319
+ typeU32,
320
+ typeU32Vec3
321
+ ]),
322
+ ...genType('', MASK_ALL, typeU32Vec3, [
323
+ typeU32Vec3,
324
+ typeU32
325
+ ]),
326
+ ...genType('', MASK_ALL, typeU32Vec4, [
327
+ typeU32,
328
+ typeU32Vec4
329
+ ]),
330
+ ...genType('', MASK_ALL, typeU32Vec4, [
331
+ typeU32Vec4,
332
+ typeU32
333
+ ]),
334
+ ...genMatrixType('', MASK_ALL, null, [
335
+ null,
336
+ null
337
+ ])
338
+ ],
339
+ normalizeFunc (pb, name, ...args) {
340
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
341
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '-', matchResult[0].returnType);
342
+ }
343
+ },
344
+ div: {
345
+ overloads: [
346
+ ...genType('', MASK_ALL, 0, [
347
+ 0,
348
+ 0
349
+ ]),
350
+ ...genType('', MASK_ALL, 1, [
351
+ 1,
352
+ 1
353
+ ]),
354
+ ...genType('', MASK_ALL, 2, [
355
+ 2,
356
+ 2
357
+ ]),
358
+ ...genType('', MASK_ALL, 3, [
359
+ 3,
360
+ 3
361
+ ]),
362
+ ...genType('', MASK_ALL, typeF32Vec2, [
363
+ typeF32,
364
+ typeF32Vec2
365
+ ]),
366
+ ...genType('', MASK_ALL, typeF32Vec2, [
367
+ typeF32Vec2,
368
+ typeF32
369
+ ]),
370
+ ...genType('', MASK_ALL, typeF32Vec3, [
371
+ typeF32,
372
+ typeF32Vec3
373
+ ]),
374
+ ...genType('', MASK_ALL, typeF32Vec3, [
375
+ typeF32Vec3,
376
+ typeF32
377
+ ]),
378
+ ...genType('', MASK_ALL, typeF32Vec4, [
379
+ typeF32,
380
+ typeF32Vec4
381
+ ]),
382
+ ...genType('', MASK_ALL, typeF32Vec4, [
383
+ typeF32Vec4,
384
+ typeF32
385
+ ]),
386
+ ...genType('', MASK_ALL, typeI32Vec2, [
387
+ typeI32,
388
+ typeI32Vec2
389
+ ]),
390
+ ...genType('', MASK_ALL, typeI32Vec2, [
391
+ typeI32Vec2,
392
+ typeI32
393
+ ]),
394
+ ...genType('', MASK_ALL, typeI32Vec3, [
395
+ typeI32,
396
+ typeI32Vec3
397
+ ]),
398
+ ...genType('', MASK_ALL, typeI32Vec3, [
399
+ typeI32Vec3,
400
+ typeI32
401
+ ]),
402
+ ...genType('', MASK_ALL, typeI32Vec4, [
403
+ typeI32,
404
+ typeI32Vec4
405
+ ]),
406
+ ...genType('', MASK_ALL, typeI32Vec4, [
407
+ typeI32Vec4,
408
+ typeI32
409
+ ]),
410
+ ...genType('', MASK_ALL, typeU32Vec2, [
411
+ typeU32,
412
+ typeU32Vec2
413
+ ]),
414
+ ...genType('', MASK_ALL, typeU32Vec2, [
415
+ typeU32Vec2,
416
+ typeU32
417
+ ]),
418
+ ...genType('', MASK_ALL, typeU32Vec3, [
419
+ typeU32,
420
+ typeU32Vec3
421
+ ]),
422
+ ...genType('', MASK_ALL, typeU32Vec3, [
423
+ typeU32Vec3,
424
+ typeU32
425
+ ]),
426
+ ...genType('', MASK_ALL, typeU32Vec4, [
427
+ typeU32,
428
+ typeU32Vec4
429
+ ]),
430
+ ...genType('', MASK_ALL, typeU32Vec4, [
431
+ typeU32Vec4,
432
+ typeU32
433
+ ])
434
+ ],
435
+ normalizeFunc (pb, name, ...args) {
436
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
437
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '/', matchResult[0].returnType);
438
+ }
439
+ },
440
+ mul_2: {
441
+ overloads: [
442
+ ...genType('', MASK_ALL, 0, [
443
+ 0,
444
+ 0
445
+ ]),
446
+ ...genType('', MASK_ALL, 1, [
447
+ 1,
448
+ 1
449
+ ]),
450
+ ...genType('', MASK_ALL, 2, [
451
+ 2,
452
+ 2
453
+ ]),
454
+ ...genType('', MASK_ALL, 3, [
455
+ 3,
456
+ 3
457
+ ]),
458
+ ...genType('', MASK_ALL, typeF32Vec2, [
459
+ typeF32,
460
+ typeF32Vec2
461
+ ]),
462
+ ...genType('', MASK_ALL, typeF32Vec2, [
463
+ typeF32Vec2,
464
+ typeF32
465
+ ]),
466
+ ...genType('', MASK_ALL, typeF32Vec3, [
467
+ typeF32,
468
+ typeF32Vec3
469
+ ]),
470
+ ...genType('', MASK_ALL, typeF32Vec3, [
471
+ typeF32Vec3,
472
+ typeF32
473
+ ]),
474
+ ...genType('', MASK_ALL, typeF32Vec4, [
475
+ typeF32,
476
+ typeF32Vec4
477
+ ]),
478
+ ...genType('', MASK_ALL, typeF32Vec4, [
479
+ typeF32Vec4,
480
+ typeF32
481
+ ]),
482
+ ...genType('', MASK_ALL, typeI32Vec2, [
483
+ typeI32,
484
+ typeI32Vec2
485
+ ]),
486
+ ...genType('', MASK_ALL, typeI32Vec2, [
487
+ typeI32Vec2,
488
+ typeI32
489
+ ]),
490
+ ...genType('', MASK_ALL, typeI32Vec3, [
491
+ typeI32,
492
+ typeI32Vec3
493
+ ]),
494
+ ...genType('', MASK_ALL, typeI32Vec3, [
495
+ typeI32Vec3,
496
+ typeI32
497
+ ]),
498
+ ...genType('', MASK_ALL, typeI32Vec4, [
499
+ typeI32,
500
+ typeI32Vec4
501
+ ]),
502
+ ...genType('', MASK_ALL, typeI32Vec4, [
503
+ typeI32Vec4,
504
+ typeI32
505
+ ]),
506
+ ...genType('', MASK_ALL, typeU32Vec2, [
507
+ typeU32,
508
+ typeU32Vec2
509
+ ]),
510
+ ...genType('', MASK_ALL, typeU32Vec2, [
511
+ typeU32Vec2,
512
+ typeU32
513
+ ]),
514
+ ...genType('', MASK_ALL, typeU32Vec3, [
515
+ typeU32,
516
+ typeU32Vec3
517
+ ]),
518
+ ...genType('', MASK_ALL, typeU32Vec3, [
519
+ typeU32Vec3,
520
+ typeU32
521
+ ]),
522
+ ...genType('', MASK_ALL, typeU32Vec4, [
523
+ typeU32,
524
+ typeU32Vec4
525
+ ]),
526
+ ...genType('', MASK_ALL, typeU32Vec4, [
527
+ typeU32Vec4,
528
+ typeU32
529
+ ]),
530
+ ...genMatrixType('', MASK_ALL, null, [
531
+ typeF32,
532
+ null
533
+ ]),
534
+ ...genMatrixType('', MASK_ALL, null, [
535
+ null,
536
+ typeF32
537
+ ]),
538
+ ...genType('', MASK_ALL, typeMat2, [
539
+ typeMat2,
540
+ typeMat2
541
+ ]),
542
+ ...genType('', MASK_ALL, typeMat3x2, [
543
+ typeMat2,
544
+ typeMat3x2
545
+ ]),
546
+ ...genType('', MASK_ALL, typeMat4x2, [
547
+ typeMat2,
548
+ typeMat4x2
549
+ ]),
550
+ ...genType('', MASK_ALL, typeF32Vec2, [
551
+ typeMat2,
552
+ typeF32Vec2
553
+ ]),
554
+ ...genType('', MASK_ALL, typeF32Vec2, [
555
+ typeF32Vec2,
556
+ typeMat2
557
+ ]),
558
+ ...genType('', MASK_ALL, typeMat2x3, [
559
+ typeMat2x3,
560
+ typeMat2
561
+ ]),
562
+ ...genType('', MASK_ALL, typeMat3, [
563
+ typeMat2x3,
564
+ typeMat3x2
565
+ ]),
566
+ ...genType('', MASK_ALL, typeMat4x3, [
567
+ typeMat2x3,
568
+ typeMat4x2
569
+ ]),
570
+ ...genType('', MASK_ALL, typeF32Vec3, [
571
+ typeMat2x3,
572
+ typeF32Vec2
573
+ ]),
574
+ ...genType('', MASK_ALL, typeF32Vec2, [
575
+ typeF32Vec3,
576
+ typeMat2x3
577
+ ]),
578
+ ...genType('', MASK_ALL, typeMat2x4, [
579
+ typeMat2x4,
580
+ typeMat2
581
+ ]),
582
+ ...genType('', MASK_ALL, typeMat3x4, [
583
+ typeMat2x4,
584
+ typeMat3x2
585
+ ]),
586
+ ...genType('', MASK_ALL, typeMat4, [
587
+ typeMat2x4,
588
+ typeMat4x2
589
+ ]),
590
+ ...genType('', MASK_ALL, typeF32Vec4, [
591
+ typeMat2x4,
592
+ typeF32Vec2
593
+ ]),
594
+ ...genType('', MASK_ALL, typeF32Vec2, [
595
+ typeF32Vec4,
596
+ typeMat2x4
597
+ ]),
598
+ ...genType('', MASK_ALL, typeMat2, [
599
+ typeMat3x2,
600
+ typeMat2x3
601
+ ]),
602
+ ...genType('', MASK_ALL, typeMat3x2, [
603
+ typeMat3x2,
604
+ typeMat3
605
+ ]),
606
+ ...genType('', MASK_ALL, typeMat4x2, [
607
+ typeMat3x2,
608
+ typeMat4x3
609
+ ]),
610
+ ...genType('', MASK_ALL, typeF32Vec2, [
611
+ typeMat3x2,
612
+ typeF32Vec3
613
+ ]),
614
+ ...genType('', MASK_ALL, typeF32Vec3, [
615
+ typeF32Vec2,
616
+ typeMat3x2
617
+ ]),
618
+ ...genType('', MASK_ALL, typeMat2x3, [
619
+ typeMat3,
620
+ typeMat2x3
621
+ ]),
622
+ ...genType('', MASK_ALL, typeMat3, [
623
+ typeMat3,
624
+ typeMat3
625
+ ]),
626
+ ...genType('', MASK_ALL, typeMat4x3, [
627
+ typeMat3,
628
+ typeMat4x3
629
+ ]),
630
+ ...genType('', MASK_ALL, typeF32Vec3, [
631
+ typeMat3,
632
+ typeF32Vec3
633
+ ]),
634
+ ...genType('', MASK_ALL, typeF32Vec3, [
635
+ typeF32Vec3,
636
+ typeMat3
637
+ ]),
638
+ ...genType('', MASK_ALL, typeMat2x4, [
639
+ typeMat3x4,
640
+ typeMat2x3
641
+ ]),
642
+ ...genType('', MASK_ALL, typeMat3x4, [
643
+ typeMat3x4,
644
+ typeMat3
645
+ ]),
646
+ ...genType('', MASK_ALL, typeMat4, [
647
+ typeMat3x4,
648
+ typeMat4x3
649
+ ]),
650
+ ...genType('', MASK_ALL, typeF32Vec4, [
651
+ typeMat3x4,
652
+ typeF32Vec3
653
+ ]),
654
+ ...genType('', MASK_ALL, typeF32Vec3, [
655
+ typeF32Vec4,
656
+ typeMat3x4
657
+ ]),
658
+ ...genType('', MASK_ALL, typeMat2, [
659
+ typeMat4x2,
660
+ typeMat2x4
661
+ ]),
662
+ ...genType('', MASK_ALL, typeMat3x2, [
663
+ typeMat4x2,
664
+ typeMat3x4
665
+ ]),
666
+ ...genType('', MASK_ALL, typeMat4x2, [
667
+ typeMat4x2,
668
+ typeMat4
669
+ ]),
670
+ ...genType('', MASK_ALL, typeF32Vec2, [
671
+ typeMat4x2,
672
+ typeF32Vec4
673
+ ]),
674
+ ...genType('', MASK_ALL, typeF32Vec4, [
675
+ typeF32Vec2,
676
+ typeMat4x2
677
+ ]),
678
+ ...genType('', MASK_ALL, typeMat2x3, [
679
+ typeMat4x3,
680
+ typeMat2x4
681
+ ]),
682
+ ...genType('', MASK_ALL, typeMat3, [
683
+ typeMat4x3,
684
+ typeMat3x4
685
+ ]),
686
+ ...genType('', MASK_ALL, typeMat4x3, [
687
+ typeMat4x3,
688
+ typeMat4
689
+ ]),
690
+ ...genType('', MASK_ALL, typeF32Vec3, [
691
+ typeMat4x3,
692
+ typeF32Vec4
693
+ ]),
694
+ ...genType('', MASK_ALL, typeF32Vec4, [
695
+ typeF32Vec3,
696
+ typeMat4x3
697
+ ]),
698
+ ...genType('', MASK_ALL, typeMat2x4, [
699
+ typeMat4,
700
+ typeMat2x4
701
+ ]),
702
+ ...genType('', MASK_ALL, typeMat3x4, [
703
+ typeMat4,
704
+ typeMat3x4
705
+ ]),
706
+ ...genType('', MASK_ALL, typeMat4, [
707
+ typeMat4,
708
+ typeMat4
709
+ ]),
710
+ ...genType('', MASK_ALL, typeF32Vec4, [
711
+ typeMat4,
712
+ typeF32Vec4
713
+ ]),
714
+ ...genType('', MASK_ALL, typeF32Vec4, [
715
+ typeF32Vec4,
716
+ typeMat4
717
+ ])
718
+ ],
719
+ normalizeFunc (pb, name, ...args) {
720
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
721
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '*', matchResult[0].returnType);
722
+ }
723
+ },
724
+ mul: {
725
+ overloads: [],
726
+ normalizeFunc (pb, name, ...args) {
727
+ if (args.length < 2) {
728
+ throw new PBParamLengthError('mul');
729
+ }
730
+ let result = args[0];
731
+ for(let i = 1; i < args.length; i++){
732
+ result = pb.mul_2(result, args[i]);
733
+ }
734
+ return result;
735
+ }
736
+ },
737
+ mod: {
738
+ overloads: [
739
+ ...genType('mod', MASK_ALL, 0, [
740
+ 0,
741
+ 0
742
+ ]),
743
+ ...genType('mod', MASK_ALL, 1, [
744
+ 1,
745
+ 1
746
+ ]),
747
+ ...genType('mod', MASK_ALL, 2, [
748
+ 2,
749
+ 2
750
+ ]),
751
+ ...genType('mod', MASK_ALL, 3, [
752
+ 3,
753
+ 3
754
+ ])
755
+ ],
756
+ normalizeFunc (pb, name, ...args) {
757
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
758
+ const argType = matchResult[1][0].getType();
759
+ const isIntegerType = argType.isPrimitiveType() && (argType.scalarType === PBPrimitiveType.I32 || argType.scalarType === PBPrimitiveType.U32);
760
+ if (pb.getDevice().type === 'webgl' && isIntegerType) {
761
+ throw new PBDeviceNotSupport('integer modulus');
762
+ }
763
+ if (pb.getDevice().type === 'webgpu' || isIntegerType) {
764
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '%', matchResult[0].returnType);
765
+ } else {
766
+ return callBuiltinChecked(pb, matchResult);
767
+ }
768
+ }
769
+ },
770
+ radians: {
771
+ overloads: genType('radians', MASK_ALL, 0, [
772
+ 0
773
+ ])
774
+ },
775
+ degrees: {
776
+ overloads: genType('degrees', MASK_ALL, 0, [
777
+ 0
778
+ ])
779
+ },
780
+ sin: {
781
+ overloads: genType('sin', MASK_ALL, 0, [
782
+ 0
783
+ ])
784
+ },
785
+ cos: {
786
+ overloads: genType('cos', MASK_ALL, 0, [
787
+ 0
788
+ ])
789
+ },
790
+ tan: {
791
+ overloads: genType('tan', MASK_ALL, 0, [
792
+ 0
793
+ ])
794
+ },
795
+ asin: {
796
+ overloads: genType('asin', MASK_ALL, 0, [
797
+ 0
798
+ ])
799
+ },
800
+ acos: {
801
+ overloads: genType('acos', MASK_ALL, 0, [
802
+ 0
803
+ ])
804
+ },
805
+ atan: {
806
+ overloads: genType('atan', MASK_ALL, 0, [
807
+ 0
808
+ ])
809
+ },
810
+ atan2: {
811
+ overloads: [
812
+ ...genType('atan', MASK_WEBGL, 0, [
813
+ 0,
814
+ 0
815
+ ]),
816
+ ...genType('atan2', MASK_WEBGPU, 0, [
817
+ 0,
818
+ 0
819
+ ])
820
+ ]
821
+ },
822
+ sinh: {
823
+ overloads: genType('sinh', MASK_WEBGL2 | MASK_WEBGPU, 0, [
824
+ 0
825
+ ])
826
+ },
827
+ cosh: {
828
+ overloads: genType('cosh', MASK_WEBGL2 | MASK_WEBGPU, 0, [
829
+ 0
830
+ ])
831
+ },
832
+ tanh: {
833
+ overloads: genType('tanh', MASK_WEBGL2 | MASK_WEBGPU, 0, [
834
+ 0
835
+ ])
836
+ },
837
+ asinh: {
838
+ overloads: genType('asinh', MASK_WEBGL2, 0, [
839
+ 0
840
+ ])
841
+ },
842
+ acosh: {
843
+ overloads: genType('acosh', MASK_WEBGL2, 0, [
844
+ 0
845
+ ])
846
+ },
847
+ atanh: {
848
+ overloads: genType('atanh', MASK_WEBGL2, 0, [
849
+ 0
850
+ ])
851
+ },
852
+ pow: {
853
+ overloads: genType('pow', MASK_ALL, 0, [
854
+ 0,
855
+ 0
856
+ ])
857
+ },
858
+ exp: {
859
+ overloads: genType('exp', MASK_ALL, 0, [
860
+ 0
861
+ ])
862
+ },
863
+ exp2: {
864
+ overloads: genType('exp2', MASK_ALL, 0, [
865
+ 0
866
+ ])
867
+ },
868
+ log: {
869
+ overloads: genType('log', MASK_ALL, 0, [
870
+ 0
871
+ ])
872
+ },
873
+ log2: {
874
+ overloads: genType('log2', MASK_ALL, 0, [
875
+ 0
876
+ ])
877
+ },
878
+ sqrt: {
879
+ overloads: genType('sqrt', MASK_ALL, 0, [
880
+ 0
881
+ ])
882
+ },
883
+ inverseSqrt: {
884
+ overloads: [
885
+ ...genType('inversesqrt', MASK_WEBGL, 0, [
886
+ 0
887
+ ]),
888
+ ...genType('inverseSqrt', MASK_WEBGPU, 0, [
889
+ 0
890
+ ])
891
+ ]
892
+ },
893
+ abs: {
894
+ overloads: [
895
+ ...genType('abs', MASK_ALL, 0, [
896
+ 0
897
+ ]),
898
+ ...genType('abs', MASK_WEBGL2 | MASK_WEBGPU, 1, [
899
+ 1
900
+ ]),
901
+ ...genType('abs', MASK_WEBGPU, 2, [
902
+ 2
903
+ ])
904
+ ]
905
+ },
906
+ sign: {
907
+ overloads: [
908
+ ...genType('sign', MASK_ALL, 0, [
909
+ 0
910
+ ]),
911
+ ...genType('sign', MASK_WEBGL2, 1, [
912
+ 1
913
+ ])
914
+ ]
915
+ },
916
+ floor: {
917
+ overloads: genType('floor', MASK_ALL, 0, [
918
+ 0
919
+ ])
920
+ },
921
+ ceil: {
922
+ overloads: genType('ceil', MASK_ALL, 0, [
923
+ 0
924
+ ])
925
+ },
926
+ fract: {
927
+ overloads: genType('fract', MASK_ALL, 0, [
928
+ 0
929
+ ])
930
+ },
931
+ fma: {
932
+ overloads: genType('fma', MASK_ALL, 0, [
933
+ 0,
934
+ 0,
935
+ 0
936
+ ]),
937
+ normalizeFunc (pb, name, ...args) {
938
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
939
+ if (pb.getDevice().type === 'webgpu') {
940
+ return callBuiltinChecked(pb, matchResult);
941
+ } else {
942
+ return pb.add(pb.mul(args[0], args[1]), args[2]);
943
+ }
944
+ }
945
+ },
946
+ round: {
947
+ overloads: genType('round', MASK_WEBGPU, 0, [
948
+ 0
949
+ ])
950
+ },
951
+ trunc: {
952
+ overloads: genType('trunc', MASK_WEBGPU, 0, [
953
+ 0
954
+ ])
955
+ },
956
+ // TODO: modf
957
+ min: {
958
+ overloads: [
959
+ ...genType('min', MASK_ALL, 0, [
960
+ 0,
961
+ 0
962
+ ]),
963
+ ...genType('min', MASK_WEBGL2 | MASK_WEBGPU, 1, [
964
+ 1,
965
+ 1
966
+ ]),
967
+ ...genType('min', MASK_WEBGL2 | MASK_WEBGPU, 2, [
968
+ 2,
969
+ 2
970
+ ])
971
+ ]
972
+ },
973
+ max: {
974
+ overloads: [
975
+ ...genType('max', MASK_ALL, 0, [
976
+ 0,
977
+ 0
978
+ ]),
979
+ ...genType('max', MASK_WEBGL2 | MASK_WEBGPU, 1, [
980
+ 1,
981
+ 1
982
+ ]),
983
+ ...genType('max', MASK_WEBGL2 | MASK_WEBGPU, 2, [
984
+ 2,
985
+ 2
986
+ ])
987
+ ]
988
+ },
989
+ clamp: {
990
+ overloads: [
991
+ ...genType('clamp', MASK_ALL, 0, [
992
+ 0,
993
+ 0,
994
+ 0
995
+ ]),
996
+ ...genType('clamp', MASK_WEBGL2 | MASK_WEBGPU, 1, [
997
+ 1,
998
+ 1,
999
+ 1
1000
+ ]),
1001
+ ...genType('clamp', MASK_WEBGL2 | MASK_WEBGPU, 2, [
1002
+ 2,
1003
+ 2,
1004
+ 2
1005
+ ])
1006
+ ]
1007
+ },
1008
+ mix: {
1009
+ overloads: [
1010
+ ...genType('mix', MASK_ALL, 0, [
1011
+ 0,
1012
+ 0,
1013
+ 0
1014
+ ]),
1015
+ ...genType('mix', MASK_ALL, 0, [
1016
+ 0,
1017
+ 0,
1018
+ typeF32
1019
+ ])
1020
+ ]
1021
+ },
1022
+ step: {
1023
+ overloads: genType('step', MASK_ALL, 0, [
1024
+ 0,
1025
+ 0
1026
+ ])
1027
+ },
1028
+ smoothStep: {
1029
+ overloads: genType('smoothstep', MASK_ALL, 0, [
1030
+ 0,
1031
+ 0,
1032
+ 0
1033
+ ])
1034
+ },
1035
+ isnan: {
1036
+ overloads: genType('isnan', MASK_WEBGL2, 3, [
1037
+ 0
1038
+ ])
1039
+ },
1040
+ isinf: {
1041
+ overloads: genType('isinf', MASK_WEBGL2, 3, [
1042
+ 0
1043
+ ])
1044
+ },
1045
+ length: {
1046
+ overloads: genType('length', MASK_ALL, typeF32, [
1047
+ 0
1048
+ ])
1049
+ },
1050
+ distance: {
1051
+ overloads: genType('distance', MASK_ALL, typeF32, [
1052
+ 0,
1053
+ 0
1054
+ ])
1055
+ },
1056
+ dot: {
1057
+ overloads: [
1058
+ ...genType('dot', MASK_ALL, typeF32, [
1059
+ 0,
1060
+ 0
1061
+ ], true),
1062
+ ...genType('dot', MASK_WEBGPU, typeI32, [
1063
+ 1,
1064
+ 1
1065
+ ], true),
1066
+ ...genType('dot', MASK_WEBGPU, typeU32, [
1067
+ 2,
1068
+ 2
1069
+ ], true)
1070
+ ]
1071
+ },
1072
+ cross: {
1073
+ overloads: genType('cross', MASK_ALL, typeF32Vec3, [
1074
+ typeF32Vec3,
1075
+ typeF32Vec3
1076
+ ])
1077
+ },
1078
+ normalize: {
1079
+ overloads: genType('normalize', MASK_ALL, 0, [
1080
+ 0
1081
+ ], true)
1082
+ },
1083
+ faceForward: {
1084
+ overloads: [
1085
+ ...genType('faceforward', MASK_WEBGL, 0, [
1086
+ 0,
1087
+ 0,
1088
+ 0
1089
+ ], true),
1090
+ ...genType('faceForward', MASK_WEBGPU, 0, [
1091
+ 0,
1092
+ 0,
1093
+ 0
1094
+ ], true)
1095
+ ]
1096
+ },
1097
+ reflect: {
1098
+ overloads: genType('reflect', MASK_ALL, 0, [
1099
+ 0,
1100
+ 0
1101
+ ], true)
1102
+ },
1103
+ refract: {
1104
+ overloads: genType('refract', MASK_ALL, 0, [
1105
+ 0,
1106
+ 0,
1107
+ typeF32
1108
+ ], true)
1109
+ },
1110
+ frexp: {
1111
+ overloads: [
1112
+ ...genType('frexp', MASK_WEBGPU, typeFrexpResult, [
1113
+ typeF32
1114
+ ]),
1115
+ ...genType('frexp', MASK_WEBGPU, typeFrexpResultVec2, [
1116
+ typeF32Vec2
1117
+ ]),
1118
+ ...genType('frexp', MASK_WEBGPU, typeFrexpResultVec3, [
1119
+ typeF32Vec3
1120
+ ]),
1121
+ ...genType('frexp', MASK_WEBGPU, typeFrexpResultVec4, [
1122
+ typeF32Vec4
1123
+ ])
1124
+ ]
1125
+ },
1126
+ outerProduct: {
1127
+ overloads: [
1128
+ ...genType('outerProduct', MASK_WEBGL2, typeMat2, [
1129
+ typeF32Vec2,
1130
+ typeF32Vec2
1131
+ ]),
1132
+ ...genType('outerProduct', MASK_WEBGL2, typeMat3, [
1133
+ typeF32Vec3,
1134
+ typeF32Vec3
1135
+ ]),
1136
+ ...genType('outerProduct', MASK_WEBGL2, typeMat4, [
1137
+ typeF32Vec4,
1138
+ typeF32Vec4
1139
+ ]),
1140
+ ...genType('outerProduct', MASK_WEBGL2, typeMat2x3, [
1141
+ typeF32Vec3,
1142
+ typeF32Vec2
1143
+ ]),
1144
+ ...genType('outerProduct', MASK_WEBGL2, typeMat3x2, [
1145
+ typeF32Vec2,
1146
+ typeF32Vec3
1147
+ ]),
1148
+ ...genType('outerProduct', MASK_WEBGL2, typeMat2x4, [
1149
+ typeF32Vec4,
1150
+ typeF32Vec2
1151
+ ]),
1152
+ ...genType('outerProduct', MASK_WEBGL2, typeMat4x2, [
1153
+ typeF32Vec2,
1154
+ typeF32Vec4
1155
+ ]),
1156
+ ...genType('outerProduct', MASK_WEBGL2, typeMat3x4, [
1157
+ typeF32Vec4,
1158
+ typeF32Vec3
1159
+ ]),
1160
+ ...genType('outerProduct', MASK_WEBGL2, typeMat4x3, [
1161
+ typeF32Vec3,
1162
+ typeF32Vec4
1163
+ ])
1164
+ ]
1165
+ },
1166
+ transpose: {
1167
+ overloads: [
1168
+ ...genType('transpose', MASK_WEBGL2 | MASK_WEBGPU, typeMat2, [
1169
+ typeMat2
1170
+ ]),
1171
+ ...genType('transpose', MASK_WEBGL2 | MASK_WEBGPU, typeMat3, [
1172
+ typeMat3
1173
+ ]),
1174
+ ...genType('transpose', MASK_WEBGL2 | MASK_WEBGPU, typeMat4, [
1175
+ typeMat4
1176
+ ]),
1177
+ ...genType('transpose', MASK_WEBGL2 | MASK_WEBGPU, typeMat2x3, [
1178
+ typeMat3x2
1179
+ ]),
1180
+ ...genType('transpose', MASK_WEBGL2 | MASK_WEBGPU, typeMat3x2, [
1181
+ typeMat2x3
1182
+ ]),
1183
+ ...genType('transpose', MASK_WEBGL2 | MASK_WEBGPU, typeMat2x4, [
1184
+ typeMat4x2
1185
+ ]),
1186
+ ...genType('transpose', MASK_WEBGL2 | MASK_WEBGPU, typeMat4x2, [
1187
+ typeMat2x4
1188
+ ]),
1189
+ ...genType('transpose', MASK_WEBGL2 | MASK_WEBGPU, typeMat3x4, [
1190
+ typeMat4x3
1191
+ ]),
1192
+ ...genType('transpose', MASK_WEBGL2 | MASK_WEBGPU, typeMat4x3, [
1193
+ typeMat3x4
1194
+ ])
1195
+ ]
1196
+ },
1197
+ determinant: {
1198
+ overloads: [
1199
+ ...genType('determinant', MASK_WEBGL2 | MASK_WEBGPU, typeF32, [
1200
+ typeMat2
1201
+ ]),
1202
+ ...genType('determinant', MASK_WEBGL2 | MASK_WEBGPU, typeF32, [
1203
+ typeMat3
1204
+ ]),
1205
+ ...genType('determinant', MASK_WEBGL2 | MASK_WEBGPU, typeF32, [
1206
+ typeMat4
1207
+ ])
1208
+ ]
1209
+ },
1210
+ inverse: {
1211
+ overloads: [
1212
+ ...genType('inverse', MASK_WEBGL2, typeMat2, [
1213
+ typeMat2
1214
+ ]),
1215
+ ...genType('inverse', MASK_WEBGL2, typeMat3, [
1216
+ typeMat3
1217
+ ]),
1218
+ ...genType('inverse', MASK_WEBGL2, typeMat4, [
1219
+ typeMat4
1220
+ ])
1221
+ ]
1222
+ },
1223
+ lessThan: {
1224
+ overloads: [
1225
+ ...genType('lessThan', MASK_ALL, 3, [
1226
+ 0,
1227
+ 0
1228
+ ]),
1229
+ ...genType('lessThan', MASK_ALL, 3, [
1230
+ 1,
1231
+ 1
1232
+ ]),
1233
+ ...genType('lessThan', MASK_ALL, 3, [
1234
+ 2,
1235
+ 2
1236
+ ])
1237
+ ],
1238
+ normalizeFunc (pb, name, ...args) {
1239
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1240
+ const argType = matchResult[1][0].getType();
1241
+ if (pb.getDevice().type === 'webgpu' || argType.isPrimitiveType() && argType.isScalarType()) {
1242
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '<', matchResult[0].returnType);
1243
+ } else {
1244
+ return callBuiltinChecked(pb, matchResult);
1245
+ }
1246
+ }
1247
+ },
1248
+ lessThanEqual: {
1249
+ overloads: [
1250
+ ...genType('lessThanEqual', MASK_ALL, 3, [
1251
+ 0,
1252
+ 0
1253
+ ]),
1254
+ ...genType('lessThanEqual', MASK_ALL, 3, [
1255
+ 1,
1256
+ 1
1257
+ ]),
1258
+ ...genType('lessThanEqual', MASK_ALL, 3, [
1259
+ 2,
1260
+ 2
1261
+ ])
1262
+ ],
1263
+ normalizeFunc (pb, name, ...args) {
1264
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1265
+ const argType = matchResult[1][0].getType();
1266
+ if (pb.getDevice().type === 'webgpu' || argType.isPrimitiveType() && argType.isScalarType()) {
1267
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '<=', matchResult[0].returnType);
1268
+ } else {
1269
+ return callBuiltinChecked(pb, matchResult);
1270
+ }
1271
+ }
1272
+ },
1273
+ greaterThan: {
1274
+ overloads: [
1275
+ ...genType('greaterThan', MASK_ALL, 3, [
1276
+ 0,
1277
+ 0
1278
+ ]),
1279
+ ...genType('greaterThan', MASK_ALL, 3, [
1280
+ 1,
1281
+ 1
1282
+ ]),
1283
+ ...genType('greaterThan', MASK_ALL, 3, [
1284
+ 2,
1285
+ 2
1286
+ ])
1287
+ ],
1288
+ normalizeFunc (pb, name, ...args) {
1289
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1290
+ const argType = matchResult[1][0].getType();
1291
+ if (pb.getDevice().type === 'webgpu' || argType.isPrimitiveType() && argType.isScalarType()) {
1292
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '>', matchResult[0].returnType);
1293
+ } else {
1294
+ return callBuiltinChecked(pb, matchResult);
1295
+ }
1296
+ }
1297
+ },
1298
+ greaterThanEqual: {
1299
+ overloads: [
1300
+ ...genType('greaterThanEqual', MASK_ALL, 3, [
1301
+ 0,
1302
+ 0
1303
+ ]),
1304
+ ...genType('greaterThanEqual', MASK_ALL, 3, [
1305
+ 1,
1306
+ 1
1307
+ ]),
1308
+ ...genType('greaterThanEqual', MASK_ALL, 3, [
1309
+ 2,
1310
+ 2
1311
+ ])
1312
+ ],
1313
+ normalizeFunc (pb, name, ...args) {
1314
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1315
+ const argType = matchResult[1][0].getType();
1316
+ if (pb.getDevice().type === 'webgpu' || argType.isPrimitiveType() && argType.isScalarType()) {
1317
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '>=', matchResult[0].returnType);
1318
+ } else {
1319
+ return callBuiltinChecked(pb, matchResult);
1320
+ }
1321
+ }
1322
+ },
1323
+ compEqual: {
1324
+ overloads: [
1325
+ ...genType('equal', MASK_ALL, 3, [
1326
+ 0,
1327
+ 0
1328
+ ]),
1329
+ ...genType('equal', MASK_ALL, 3, [
1330
+ 1,
1331
+ 1
1332
+ ]),
1333
+ ...genType('equal', MASK_ALL, 3, [
1334
+ 2,
1335
+ 2
1336
+ ]),
1337
+ ...genType('equal', MASK_ALL, 3, [
1338
+ 3,
1339
+ 3
1340
+ ])
1341
+ ],
1342
+ normalizeFunc (pb, name, ...args) {
1343
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1344
+ const argType = matchResult[1][0].getType();
1345
+ if (pb.getDevice().type === 'webgpu' || argType.isPrimitiveType() && argType.isScalarType()) {
1346
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '==', matchResult[0].returnType);
1347
+ } else {
1348
+ return callBuiltinChecked(pb, matchResult);
1349
+ }
1350
+ }
1351
+ },
1352
+ compNotEqual: {
1353
+ overloads: [
1354
+ ...genType('notEqual', MASK_ALL, 3, [
1355
+ 0,
1356
+ 0
1357
+ ]),
1358
+ ...genType('notEqual', MASK_ALL, 3, [
1359
+ 1,
1360
+ 1
1361
+ ]),
1362
+ ...genType('notEqual', MASK_ALL, 3, [
1363
+ 2,
1364
+ 2
1365
+ ]),
1366
+ ...genType('notEqual', MASK_ALL, 3, [
1367
+ 3,
1368
+ 3
1369
+ ])
1370
+ ],
1371
+ normalizeFunc (pb, name, ...args) {
1372
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1373
+ const argType = matchResult[1][0].getType();
1374
+ if (pb.getDevice().type === 'webgpu' || argType.isPrimitiveType() && argType.isScalarType()) {
1375
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '!=', matchResult[0].returnType);
1376
+ } else {
1377
+ return callBuiltinChecked(pb, matchResult);
1378
+ }
1379
+ }
1380
+ },
1381
+ equal: {
1382
+ overloads: [
1383
+ ...genType('equal', MASK_ALL, typeBool, [
1384
+ 0,
1385
+ 0
1386
+ ]),
1387
+ ...genType('equal', MASK_ALL, typeBool, [
1388
+ 1,
1389
+ 1
1390
+ ]),
1391
+ ...genType('equal', MASK_ALL, typeBool, [
1392
+ 2,
1393
+ 2
1394
+ ]),
1395
+ ...genType('equal', MASK_ALL, typeBool, [
1396
+ 3,
1397
+ 3
1398
+ ])
1399
+ ],
1400
+ normalizeFunc (pb, name, ...args) {
1401
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1402
+ const argType = matchResult[1][0].getType();
1403
+ if (pb.getDevice().type === 'webgpu' && argType.isPrimitiveType() && !argType.isScalarType()) {
1404
+ return pb.all(pb.compEqual(args[0], args[1]));
1405
+ } else {
1406
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '==', matchResult[0].returnType);
1407
+ }
1408
+ }
1409
+ },
1410
+ notEqual: {
1411
+ overloads: [
1412
+ ...genType('notEqual', MASK_ALL, typeBool, [
1413
+ 0,
1414
+ 0
1415
+ ]),
1416
+ ...genType('notEqual', MASK_ALL, typeBool, [
1417
+ 1,
1418
+ 1
1419
+ ]),
1420
+ ...genType('notEqual', MASK_ALL, typeBool, [
1421
+ 2,
1422
+ 2
1423
+ ]),
1424
+ ...genType('notEqual', MASK_ALL, typeBool, [
1425
+ 3,
1426
+ 3
1427
+ ])
1428
+ ],
1429
+ normalizeFunc (pb, name, ...args) {
1430
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1431
+ const argType = matchResult[1][0].getType();
1432
+ if (pb.getDevice().type === 'webgpu' && argType.isPrimitiveType() && !argType.isScalarType()) {
1433
+ return pb.any(pb.compNotEqual(args[0], args[1]));
1434
+ } else {
1435
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '!=', matchResult[0].returnType);
1436
+ }
1437
+ }
1438
+ },
1439
+ any: {
1440
+ overloads: genType('any', MASK_ALL, typeBool, [
1441
+ 3
1442
+ ], true)
1443
+ },
1444
+ all: {
1445
+ overloads: genType('all', MASK_ALL, typeBool, [
1446
+ 3
1447
+ ], true)
1448
+ },
1449
+ not: {
1450
+ overloads: genType('not', MASK_ALL, 3, [
1451
+ 3
1452
+ ]),
1453
+ normalizeFunc (pb, name, ...args) {
1454
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1455
+ const argType = matchResult[1][0].getType();
1456
+ if (pb.getDevice().type === 'webgpu' || argType.isPrimitiveType() && argType.isScalarType()) {
1457
+ return unaryFunc(matchResult[1][0], '!', matchResult[0].returnType);
1458
+ } else {
1459
+ return callBuiltinChecked(pb, matchResult);
1460
+ }
1461
+ }
1462
+ },
1463
+ neg: {
1464
+ overloads: [
1465
+ ...genType('neg', MASK_ALL, 0, [
1466
+ 0
1467
+ ]),
1468
+ ...genType('neg', MASK_ALL, 1, [
1469
+ 1
1470
+ ])
1471
+ ],
1472
+ normalizeFunc (pb, name, ...args) {
1473
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1474
+ return unaryFunc(matchResult[1][0], '-', matchResult[0].returnType);
1475
+ }
1476
+ },
1477
+ or_2: {
1478
+ overloads: genType('or', MASK_ALL, typeBool, [
1479
+ 3,
1480
+ 3
1481
+ ]),
1482
+ normalizeFunc (pb, name, ...args) {
1483
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1484
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '||', matchResult[0].returnType);
1485
+ }
1486
+ },
1487
+ or: {
1488
+ overloads: [],
1489
+ normalizeFunc (pb, name, ...args) {
1490
+ if (args.length < 2) {
1491
+ throw new PBParamLengthError('or');
1492
+ }
1493
+ let result = args[0];
1494
+ for(let i = 1; i < args.length; i++){
1495
+ result = pb.or_2(result, args[i]);
1496
+ }
1497
+ return result;
1498
+ }
1499
+ },
1500
+ compOr: {
1501
+ overloads: [
1502
+ ...genType('compOr', MASK_WEBGL2 | MASK_WEBGPU, 1, [
1503
+ 1,
1504
+ 1
1505
+ ]),
1506
+ ...genType('compOr', MASK_WEBGL2 | MASK_WEBGPU, 2, [
1507
+ 2,
1508
+ 2
1509
+ ])
1510
+ ],
1511
+ normalizeFunc (pb, name, ...args) {
1512
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1513
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '|', matchResult[0].returnType);
1514
+ }
1515
+ },
1516
+ and_2: {
1517
+ overloads: genType('and', MASK_ALL, typeBool, [
1518
+ 3,
1519
+ 3
1520
+ ]),
1521
+ normalizeFunc (pb, name, ...args) {
1522
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1523
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '&&', matchResult[0].returnType);
1524
+ }
1525
+ },
1526
+ and: {
1527
+ overloads: [],
1528
+ normalizeFunc (pb, name, ...args) {
1529
+ if (args.length < 2) {
1530
+ throw new PBParamLengthError('and');
1531
+ }
1532
+ let result = args[0];
1533
+ for(let i = 1; i < args.length; i++){
1534
+ result = pb.and_2(result, args[i]);
1535
+ }
1536
+ return result;
1537
+ }
1538
+ },
1539
+ compAnd: {
1540
+ overloads: [
1541
+ ...genType('compAnd', MASK_WEBGL2 | MASK_WEBGPU, 1, [
1542
+ 1,
1543
+ 1
1544
+ ]),
1545
+ ...genType('compAnd', MASK_WEBGL2 | MASK_WEBGPU, 2, [
1546
+ 2,
1547
+ 2
1548
+ ])
1549
+ ],
1550
+ normalizeFunc (pb, name, ...args) {
1551
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1552
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '&', matchResult[0].returnType);
1553
+ }
1554
+ },
1555
+ compXor: {
1556
+ overloads: [
1557
+ ...genType('compXor', MASK_WEBGL2 | MASK_WEBGPU, 1, [
1558
+ 1,
1559
+ 1
1560
+ ]),
1561
+ ...genType('compXor', MASK_WEBGL2 | MASK_WEBGPU, 2, [
1562
+ 2,
1563
+ 2
1564
+ ])
1565
+ ],
1566
+ normalizeFunc (pb, name, ...args) {
1567
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1568
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '^', matchResult[0].returnType);
1569
+ }
1570
+ },
1571
+ sal: {
1572
+ overloads: [
1573
+ ...genType('sal', MASK_WEBGL2 | MASK_WEBGPU, 1, [
1574
+ 1,
1575
+ 2
1576
+ ]),
1577
+ ...genType('sal', MASK_WEBGL2 | MASK_WEBGPU, 2, [
1578
+ 2,
1579
+ 2
1580
+ ])
1581
+ ],
1582
+ normalizeFunc (pb, name, ...args) {
1583
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1584
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '<<', matchResult[0].returnType);
1585
+ }
1586
+ },
1587
+ sar: {
1588
+ overloads: [
1589
+ ...genType('sar', MASK_WEBGL2 | MASK_WEBGPU, 1, [
1590
+ 1,
1591
+ 2
1592
+ ]),
1593
+ ...genType('sar', MASK_WEBGL2 | MASK_WEBGPU, 2, [
1594
+ 2,
1595
+ 2
1596
+ ])
1597
+ ],
1598
+ normalizeFunc (pb, name, ...args) {
1599
+ const matchResult = matchFunctionOverloadings(pb, name, ...args);
1600
+ return binaryFunc(matchResult[1][0], matchResult[1][1], '>>', matchResult[0].returnType);
1601
+ }
1602
+ },
1603
+ arrayLength: {
1604
+ overloads: [],
1605
+ normalizeFunc (pb, name, ...args) {
1606
+ if (args.length !== 1) {
1607
+ throw new PBParamLengthError('arrayLength');
1608
+ }
1609
+ if (!(args[0] instanceof PBShaderExp)) {
1610
+ throw new PBParamValueError('arrayLength', 'array');
1611
+ }
1612
+ const type = args[0].$ast.getType();
1613
+ const arrayType = type.isPointerType() ? type.pointerType : type;
1614
+ if (!arrayType.isArrayType() || arrayType.dimension !== 0) {
1615
+ throw new PBParamTypeError('arrayLength', 'array');
1616
+ }
1617
+ const arg = type.isArrayType() ? pb.addressOf(args[0]).$ast : args[0].$ast;
1618
+ return pb.$callFunctionNoCheck(name, [
1619
+ arg
1620
+ ], typeU32);
1621
+ }
1622
+ },
1623
+ select: {
1624
+ overloads: [
1625
+ ...genType('select', MASK_WEBGPU, 0, [
1626
+ 0,
1627
+ 0,
1628
+ typeBool
1629
+ ]),
1630
+ ...genType('select', MASK_WEBGPU, 1, [
1631
+ 1,
1632
+ 1,
1633
+ typeBool
1634
+ ]),
1635
+ ...genType('select', MASK_WEBGPU, 2, [
1636
+ 2,
1637
+ 2,
1638
+ typeBool
1639
+ ]),
1640
+ ...genType('select', MASK_WEBGPU, 3, [
1641
+ 3,
1642
+ 3,
1643
+ typeBool
1644
+ ]),
1645
+ ...genType('select', MASK_WEBGPU, 0, [
1646
+ 0,
1647
+ 0,
1648
+ 3
1649
+ ], true),
1650
+ ...genType('select', MASK_WEBGPU, 1, [
1651
+ 1,
1652
+ 1,
1653
+ 3
1654
+ ], true),
1655
+ ...genType('select', MASK_WEBGPU, 2, [
1656
+ 2,
1657
+ 2,
1658
+ 3
1659
+ ], true),
1660
+ ...genType('select', MASK_WEBGPU, 3, [
1661
+ 3,
1662
+ 3,
1663
+ 3
1664
+ ], true),
1665
+ ...genType('mix', MASK_WEBGL2, 0, [
1666
+ 0,
1667
+ 0,
1668
+ 3
1669
+ ]),
1670
+ ...genType('mix', MASK_WEBGL2, 1, [
1671
+ 1,
1672
+ 1,
1673
+ 3
1674
+ ]),
1675
+ ...genType('mix', MASK_WEBGL2, 2, [
1676
+ 2,
1677
+ 2,
1678
+ 3
1679
+ ])
1680
+ ]
1681
+ },
1682
+ floatBitsToInt: {
1683
+ overloads: genType('floatBitsToInt', MASK_WEBGL2, 1, [
1684
+ 0
1685
+ ])
1686
+ },
1687
+ floatBitsToUint: {
1688
+ overloads: genType('floatBitsToUint', MASK_WEBGL2, 2, [
1689
+ 0
1690
+ ])
1691
+ },
1692
+ intBitsToFloat: {
1693
+ overloads: genType('intBitsToFloat', MASK_WEBGL2, 0, [
1694
+ 1
1695
+ ])
1696
+ },
1697
+ uintBitsToFloat: {
1698
+ overloads: genType('uintBitsToFloat', MASK_WEBGL2, 0, [
1699
+ 2
1700
+ ])
1701
+ },
1702
+ pack4x8snorm: {
1703
+ overloads: genType('pack4x8snorm', MASK_WEBGPU, typeU32, [
1704
+ typeF32Vec4
1705
+ ])
1706
+ },
1707
+ unpack4x8snorm: {
1708
+ overloads: genType('unpack4x8snorm', MASK_WEBGPU, typeF32Vec4, [
1709
+ typeU32
1710
+ ])
1711
+ },
1712
+ pack4x8unorm: {
1713
+ overloads: genType('pack4x8unorm', MASK_WEBGPU, typeU32, [
1714
+ typeF32Vec4
1715
+ ])
1716
+ },
1717
+ unpack4x8unorm: {
1718
+ overloads: genType('unpack4x8unorm', MASK_WEBGPU, typeF32Vec4, [
1719
+ typeU32
1720
+ ])
1721
+ },
1722
+ pack2x16snorm: {
1723
+ overloads: [
1724
+ ...genType('pack2x16snorm', MASK_WEBGPU, typeU32, [
1725
+ typeF32Vec2
1726
+ ]),
1727
+ ...genType('packSnorm2x16', MASK_WEBGL2, typeU32, [
1728
+ typeF32Vec2
1729
+ ])
1730
+ ]
1731
+ },
1732
+ unpack2x16snorm: {
1733
+ overloads: [
1734
+ ...genType('unpack2x16snorm', MASK_WEBGPU, typeF32Vec2, [
1735
+ typeU32
1736
+ ]),
1737
+ ...genType('unpackSnorm2x16', MASK_WEBGL2, typeF32Vec2, [
1738
+ typeU32
1739
+ ])
1740
+ ]
1741
+ },
1742
+ pack2x16unorm: {
1743
+ overloads: [
1744
+ ...genType('pack2x16unorm', MASK_WEBGPU, typeU32, [
1745
+ typeF32Vec2
1746
+ ]),
1747
+ ...genType('packUnorm2x16', MASK_WEBGL2, typeU32, [
1748
+ typeF32Vec2
1749
+ ])
1750
+ ]
1751
+ },
1752
+ unpack2x16unorm: {
1753
+ overloads: [
1754
+ ...genType('unpack2x16unorm', MASK_WEBGPU, typeF32Vec2, [
1755
+ typeU32
1756
+ ]),
1757
+ ...genType('unpackUnorm2x16', MASK_WEBGL2, typeF32Vec2, [
1758
+ typeU32
1759
+ ])
1760
+ ]
1761
+ },
1762
+ pack2x16float: {
1763
+ overloads: [
1764
+ ...genType('pack2x16float', MASK_WEBGPU, typeU32, [
1765
+ typeF32Vec2
1766
+ ]),
1767
+ ...genType('packHalf2x16', MASK_WEBGL2, typeU32, [
1768
+ typeF32Vec2
1769
+ ])
1770
+ ]
1771
+ },
1772
+ unpack2x16float: {
1773
+ overloads: [
1774
+ ...genType('unpack2x16float', MASK_WEBGPU, typeF32Vec2, [
1775
+ typeU32
1776
+ ]),
1777
+ ...genType('unpackHalf2x16', MASK_WEBGL2, typeF32Vec2, [
1778
+ typeU32
1779
+ ])
1780
+ ]
1781
+ },
1782
+ matrixCompMult: {
1783
+ overloads: genMatrixType('matrixCompMult', MASK_WEBGL, null, [
1784
+ null,
1785
+ null
1786
+ ])
1787
+ },
1788
+ dpdx: {
1789
+ overloads: [
1790
+ ...genType('dFdx', MASK_WEBGL, 0, [
1791
+ 0
1792
+ ]),
1793
+ ...genType('dpdx', MASK_WEBGPU, 0, [
1794
+ 0
1795
+ ])
1796
+ ]
1797
+ },
1798
+ dpdy: {
1799
+ overloads: [
1800
+ ...genType('dFdy', MASK_WEBGL, 0, [
1801
+ 0
1802
+ ]),
1803
+ ...genType('dpdy', MASK_WEBGPU, 0, [
1804
+ 0
1805
+ ])
1806
+ ]
1807
+ },
1808
+ fwidth: {
1809
+ overloads: genType('fwidth', MASK_ALL, 0, [
1810
+ 0
1811
+ ])
1812
+ },
1813
+ dpdxCoarse: {
1814
+ overloads: [
1815
+ ...genType('dpdxCoarse', MASK_WEBGPU, 0, [
1816
+ 0
1817
+ ]),
1818
+ ...genType('dFdx', MASK_WEBGL, 0, [
1819
+ 0
1820
+ ])
1821
+ ]
1822
+ },
1823
+ dpdxFine: {
1824
+ overloads: [
1825
+ ...genType('dpdxFine', MASK_WEBGPU, 0, [
1826
+ 0
1827
+ ]),
1828
+ ...genType('dFdx', MASK_WEBGL, 0, [
1829
+ 0
1830
+ ])
1831
+ ]
1832
+ },
1833
+ dpdyCoarse: {
1834
+ overloads: [
1835
+ ...genType('dpdyCoarse', MASK_WEBGPU, 0, [
1836
+ 0
1837
+ ]),
1838
+ ...genType('dFdy', MASK_WEBGL, 0, [
1839
+ 0
1840
+ ])
1841
+ ]
1842
+ },
1843
+ dpdyFine: {
1844
+ overloads: [
1845
+ ...genType('dpdyFine', MASK_WEBGPU, 0, [
1846
+ 0
1847
+ ]),
1848
+ ...genType('dFdy', MASK_WEBGL, 0, [
1849
+ 0
1850
+ ])
1851
+ ]
1852
+ },
1853
+ // textureDimensions(tex: PBShaderExp, level?: number|PBShaderExp);
1854
+ textureDimensions: {
1855
+ overloads: [
1856
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1857
+ typeTex1D,
1858
+ typeI32
1859
+ ]),
1860
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1861
+ typeITex1D,
1862
+ typeI32
1863
+ ]),
1864
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1865
+ typeUTex1D,
1866
+ typeI32
1867
+ ]),
1868
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1869
+ typeTex2D,
1870
+ typeI32
1871
+ ]),
1872
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1873
+ typeITex2D,
1874
+ typeI32
1875
+ ]),
1876
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1877
+ typeUTex2D,
1878
+ typeI32
1879
+ ]),
1880
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1881
+ typeTex2DArray,
1882
+ typeI32
1883
+ ]),
1884
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1885
+ typeITex2DArray,
1886
+ typeI32
1887
+ ]),
1888
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1889
+ typeUTex2DArray,
1890
+ typeI32
1891
+ ]),
1892
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
1893
+ typeTex3D,
1894
+ typeI32
1895
+ ]),
1896
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
1897
+ typeITex3D,
1898
+ typeI32
1899
+ ]),
1900
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
1901
+ typeUTex3D,
1902
+ typeI32
1903
+ ]),
1904
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1905
+ typeTexCube,
1906
+ typeI32
1907
+ ]),
1908
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1909
+ typeITexCube,
1910
+ typeI32
1911
+ ]),
1912
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1913
+ typeUTexCube,
1914
+ typeI32
1915
+ ]),
1916
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1917
+ typeTexCubeArray,
1918
+ typeI32
1919
+ ]),
1920
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1921
+ typeITexCubeArray,
1922
+ typeI32
1923
+ ]),
1924
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1925
+ typeUTexCubeArray,
1926
+ typeI32
1927
+ ]),
1928
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1929
+ typeTexMultisampled2D
1930
+ ]),
1931
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1932
+ typeITexMultisampled2D
1933
+ ]),
1934
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1935
+ typeUTexMultisampled2D
1936
+ ]),
1937
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1938
+ typeTexDepth2D,
1939
+ typeI32
1940
+ ]),
1941
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1942
+ typeTexDepth2DArray,
1943
+ typeI32
1944
+ ]),
1945
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1946
+ typeTexDepthCube,
1947
+ typeI32
1948
+ ]),
1949
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1950
+ typeTexDepthCubeArray,
1951
+ typeI32
1952
+ ]),
1953
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
1954
+ typeTexDepthMultisampled2D
1955
+ ]),
1956
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1957
+ typeTexStorage1D_rgba8unorm
1958
+ ]),
1959
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1960
+ typeTexStorage1D_rgba8snorm
1961
+ ]),
1962
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1963
+ typeTexStorage1D_rgba8uint
1964
+ ]),
1965
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1966
+ typeTexStorage1D_rgba8sint
1967
+ ]),
1968
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1969
+ typeTexStorage1D_rgba16uint
1970
+ ]),
1971
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1972
+ typeTexStorage1D_rgba16sint
1973
+ ]),
1974
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1975
+ typeTexStorage1D_rgba16float
1976
+ ]),
1977
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1978
+ typeTexStorage1D_rgba32uint
1979
+ ]),
1980
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1981
+ typeTexStorage1D_rgba32sint
1982
+ ]),
1983
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1984
+ typeTexStorage1D_rgba32float
1985
+ ]),
1986
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1987
+ typeTexStorage1D_rg32uint
1988
+ ]),
1989
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1990
+ typeTexStorage1D_rg32sint
1991
+ ]),
1992
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1993
+ typeTexStorage1D_rg32float
1994
+ ]),
1995
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1996
+ typeTexStorage1D_r32uint
1997
+ ]),
1998
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
1999
+ typeTexStorage1D_r32sint
2000
+ ]),
2001
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32, [
2002
+ typeTexStorage1D_r32float
2003
+ ]),
2004
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2005
+ typeTexStorage2D_rgba8unorm
2006
+ ]),
2007
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2008
+ typeTexStorage2D_rgba8snorm
2009
+ ]),
2010
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2011
+ typeTexStorage2D_rgba8uint
2012
+ ]),
2013
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2014
+ typeTexStorage2D_rgba8sint
2015
+ ]),
2016
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2017
+ typeTexStorage2D_rgba16uint
2018
+ ]),
2019
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2020
+ typeTexStorage2D_rgba16sint
2021
+ ]),
2022
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2023
+ typeTexStorage2D_rgba16float
2024
+ ]),
2025
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2026
+ typeTexStorage2D_rgba32uint
2027
+ ]),
2028
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2029
+ typeTexStorage2D_rgba32sint
2030
+ ]),
2031
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2032
+ typeTexStorage2D_rgba32float
2033
+ ]),
2034
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2035
+ typeTexStorage2D_rg32uint
2036
+ ]),
2037
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2038
+ typeTexStorage2D_rg32sint
2039
+ ]),
2040
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2041
+ typeTexStorage2D_rg32float
2042
+ ]),
2043
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2044
+ typeTexStorage2D_r32uint
2045
+ ]),
2046
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2047
+ typeTexStorage2D_r32sint
2048
+ ]),
2049
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2050
+ typeTexStorage2D_r32float
2051
+ ]),
2052
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2053
+ typeTexStorage2DArray_rgba8unorm
2054
+ ]),
2055
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2056
+ typeTexStorage2DArray_rgba8snorm
2057
+ ]),
2058
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2059
+ typeTexStorage2DArray_rgba8uint
2060
+ ]),
2061
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2062
+ typeTexStorage2DArray_rgba8sint
2063
+ ]),
2064
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2065
+ typeTexStorage2DArray_rgba16uint
2066
+ ]),
2067
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2068
+ typeTexStorage2DArray_rgba16sint
2069
+ ]),
2070
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2071
+ typeTexStorage2DArray_rgba16float
2072
+ ]),
2073
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2074
+ typeTexStorage2DArray_rgba32uint
2075
+ ]),
2076
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2077
+ typeTexStorage2DArray_rgba32sint
2078
+ ]),
2079
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2080
+ typeTexStorage2DArray_rgba32float
2081
+ ]),
2082
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2083
+ typeTexStorage2DArray_rg32uint
2084
+ ]),
2085
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2086
+ typeTexStorage2DArray_rg32sint
2087
+ ]),
2088
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2089
+ typeTexStorage2DArray_rg32float
2090
+ ]),
2091
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2092
+ typeTexStorage2DArray_r32uint
2093
+ ]),
2094
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2095
+ typeTexStorage2DArray_r32sint
2096
+ ]),
2097
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec2, [
2098
+ typeTexStorage2DArray_r32float
2099
+ ]),
2100
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
2101
+ typeTexStorage3D_rgba8unorm
2102
+ ]),
2103
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
2104
+ typeTexStorage3D_rgba8snorm
2105
+ ]),
2106
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
2107
+ typeTexStorage3D_rgba8uint
2108
+ ]),
2109
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
2110
+ typeTexStorage3D_rgba8sint
2111
+ ]),
2112
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
2113
+ typeTexStorage3D_rgba16uint
2114
+ ]),
2115
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
2116
+ typeTexStorage3D_rgba16sint
2117
+ ]),
2118
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
2119
+ typeTexStorage3D_rgba16float
2120
+ ]),
2121
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
2122
+ typeTexStorage3D_rgba32uint
2123
+ ]),
2124
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
2125
+ typeTexStorage3D_rgba32sint
2126
+ ]),
2127
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
2128
+ typeTexStorage3D_rgba32float
2129
+ ]),
2130
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
2131
+ typeTexStorage3D_rg32uint
2132
+ ]),
2133
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
2134
+ typeTexStorage3D_rg32sint
2135
+ ]),
2136
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
2137
+ typeTexStorage3D_rg32float
2138
+ ]),
2139
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
2140
+ typeTexStorage3D_r32uint
2141
+ ]),
2142
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
2143
+ typeTexStorage3D_r32sint
2144
+ ]),
2145
+ ...genType('textureDimensions', MASK_WEBGPU, typeU32Vec3, [
2146
+ typeTexStorage3D_r32float
2147
+ ]),
2148
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec2, [
2149
+ typeTex1D,
2150
+ typeI32
2151
+ ]),
2152
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec2, [
2153
+ typeTex2D,
2154
+ typeI32
2155
+ ]),
2156
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec2, [
2157
+ typeITex1D,
2158
+ typeI32
2159
+ ]),
2160
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec2, [
2161
+ typeITex2D,
2162
+ typeI32
2163
+ ]),
2164
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec2, [
2165
+ typeUTex1D,
2166
+ typeI32
2167
+ ]),
2168
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec2, [
2169
+ typeUTex2D,
2170
+ typeI32
2171
+ ]),
2172
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec2, [
2173
+ typeTex2DArray,
2174
+ typeI32
2175
+ ]),
2176
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec2, [
2177
+ typeITex2DArray,
2178
+ typeI32
2179
+ ]),
2180
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec2, [
2181
+ typeUTex2DArray,
2182
+ typeI32
2183
+ ]),
2184
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec2, [
2185
+ typeTexCube,
2186
+ typeI32
2187
+ ]),
2188
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec2, [
2189
+ typeITexCube,
2190
+ typeI32
2191
+ ]),
2192
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec2, [
2193
+ typeUTexCube,
2194
+ typeI32
2195
+ ]),
2196
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec3, [
2197
+ typeTex3D,
2198
+ typeI32
2199
+ ]),
2200
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec3, [
2201
+ typeITex3D,
2202
+ typeI32
2203
+ ]),
2204
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec3, [
2205
+ typeUTex3D,
2206
+ typeI32
2207
+ ]),
2208
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec2, [
2209
+ typeTexDepth2D,
2210
+ typeI32
2211
+ ]),
2212
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec2, [
2213
+ typeTexDepthCube,
2214
+ typeI32
2215
+ ]),
2216
+ ...genType('textureSize', MASK_WEBGL2, typeI32Vec2, [
2217
+ typeTexDepth2DArray,
2218
+ typeI32
2219
+ ])
2220
+ ],
2221
+ normalizeFunc (pb, name, ...args) {
2222
+ if (args.length < 1 || args.length > 2) {
2223
+ throw new PBParamLengthError('textureDimensions');
2224
+ }
2225
+ if (!(args[0] instanceof PBShaderExp)) {
2226
+ throw new PBParamValueError('textureDimensions', 'tex');
2227
+ }
2228
+ const texType = args[0].$ast.getType();
2229
+ if (!texType.isTextureType()) {
2230
+ throw new PBParamTypeError('textureDimensions', 'tex');
2231
+ }
2232
+ if (pb.getDevice().type === 'webgpu') {
2233
+ if (texType.isMultisampledTexture() || texType.isStorageTexture()) {
2234
+ if (args[1] !== undefined) {
2235
+ throw new PBParamValueError('textureDimensions', 'level');
2236
+ }
2237
+ }
2238
+ return callBuiltin(pb, name, ...args);
2239
+ } else if (pb.getDevice().type === 'webgl2') {
2240
+ const tex = args[0];
2241
+ const level = args[1] || 0;
2242
+ return texType.is1DTexture() ? callBuiltin(pb, name, tex, level).x : callBuiltin(pb, name, tex, level);
2243
+ }
2244
+ }
2245
+ },
2246
+ // textureGather(tex: PBShaderExp, sampler: PBShaderExp, coords: PBShaderExp);
2247
+ // textureGather(component: number|PBShaderExp, tex: PBShaderExp, sampler: PBShaderExp, coords: PBShaderExp);
2248
+ textureGather: {
2249
+ overloads: [
2250
+ ...genType('textureGather', MASK_WEBGPU, typeF32Vec4, [
2251
+ typeI32,
2252
+ typeTex2D,
2253
+ typeSampler,
2254
+ typeF32Vec2
2255
+ ]),
2256
+ ...genType('textureGather', MASK_WEBGPU, typeI32Vec4, [
2257
+ typeI32,
2258
+ typeITex2D,
2259
+ typeSampler,
2260
+ typeF32Vec2
2261
+ ]),
2262
+ ...genType('textureGather', MASK_WEBGPU, typeU32Vec4, [
2263
+ typeI32,
2264
+ typeUTex2D,
2265
+ typeSampler,
2266
+ typeF32Vec2
2267
+ ]),
2268
+ ...genType('textureGather', MASK_WEBGPU, typeF32Vec4, [
2269
+ typeI32,
2270
+ typeTexCube,
2271
+ typeSampler,
2272
+ typeF32Vec3
2273
+ ]),
2274
+ ...genType('textureGather', MASK_WEBGPU, typeI32Vec4, [
2275
+ typeI32,
2276
+ typeITexCube,
2277
+ typeSampler,
2278
+ typeF32Vec3
2279
+ ]),
2280
+ ...genType('textureGather', MASK_WEBGPU, typeU32Vec4, [
2281
+ typeI32,
2282
+ typeUTexCube,
2283
+ typeSampler,
2284
+ typeF32Vec3
2285
+ ]),
2286
+ ...genType('textureGather', MASK_WEBGPU, typeF32Vec4, [
2287
+ typeTexDepth2D,
2288
+ typeSampler,
2289
+ typeF32Vec2
2290
+ ]),
2291
+ ...genType('textureGather', MASK_WEBGPU, typeF32Vec4, [
2292
+ typeTexDepthCube,
2293
+ typeSampler,
2294
+ typeF32Vec3
2295
+ ])
2296
+ ]
2297
+ },
2298
+ // textureArrayGather(tex: PBShaderExp, sampler: PBShaderExp, coords: PBShaderExp, arrayIndex: number|PBShaderExp);
2299
+ // textureArrayGather(component: number|PBShaderExp, tex: PBShaderExp, sampler: PBShaderExp, coords: PBShaderExp, arrayIndex: number|PBShaderExp);
2300
+ textureArrayGather: {
2301
+ overloads: [
2302
+ ...genType('textureGather', MASK_WEBGPU, typeF32Vec4, [
2303
+ typeI32,
2304
+ typeTex2DArray,
2305
+ typeSampler,
2306
+ typeF32Vec2,
2307
+ typeI32
2308
+ ]),
2309
+ ...genType('textureGather', MASK_WEBGPU, typeI32Vec4, [
2310
+ typeI32,
2311
+ typeITex2DArray,
2312
+ typeSampler,
2313
+ typeF32Vec2,
2314
+ typeI32
2315
+ ]),
2316
+ ...genType('textureGather', MASK_WEBGPU, typeU32Vec4, [
2317
+ typeI32,
2318
+ typeUTex2DArray,
2319
+ typeSampler,
2320
+ typeF32Vec2,
2321
+ typeI32
2322
+ ]),
2323
+ ...genType('textureGather', MASK_WEBGPU, typeF32Vec4, [
2324
+ typeI32,
2325
+ typeTexCubeArray,
2326
+ typeSampler,
2327
+ typeF32Vec3,
2328
+ typeI32
2329
+ ]),
2330
+ ...genType('textureGather', MASK_WEBGPU, typeI32Vec4, [
2331
+ typeI32,
2332
+ typeITexCubeArray,
2333
+ typeSampler,
2334
+ typeF32Vec3,
2335
+ typeI32
2336
+ ]),
2337
+ ...genType('textureGather', MASK_WEBGPU, typeU32Vec4, [
2338
+ typeI32,
2339
+ typeUTexCubeArray,
2340
+ typeSampler,
2341
+ typeF32Vec3,
2342
+ typeI32
2343
+ ]),
2344
+ ...genType('textureGather', MASK_WEBGPU, typeF32Vec4, [
2345
+ typeTexDepth2DArray,
2346
+ typeSampler,
2347
+ typeF32Vec2,
2348
+ typeI32
2349
+ ]),
2350
+ ...genType('textureGather', MASK_WEBGPU, typeF32Vec4, [
2351
+ typeTexDepthCubeArray,
2352
+ typeSampler,
2353
+ typeF32Vec3,
2354
+ typeI32
2355
+ ])
2356
+ ]
2357
+ },
2358
+ // textureGatherCompare(tex: PBShaderExp, samplerCompare: PBShaderExp, coords: PBShaderExp, depthRef: number|PBShaderExp);
2359
+ textureGatherCompare: {
2360
+ overloads: [
2361
+ ...genType('textureGatherCompare', MASK_WEBGPU, typeF32Vec4, [
2362
+ typeTexDepth2D,
2363
+ typeSamplerComparison,
2364
+ typeF32Vec2,
2365
+ typeF32
2366
+ ]),
2367
+ ...genType('textureGatherCompare', MASK_WEBGPU, typeF32Vec4, [
2368
+ typeTexDepthCube,
2369
+ typeSamplerComparison,
2370
+ typeF32Vec3,
2371
+ typeF32
2372
+ ])
2373
+ ]
2374
+ },
2375
+ // textureArrayGatherCompare(tex: PBShaderExp, samplerCompare: PBShaderExp, coords: PBShaderExp, arrayIndex: number|PBShaderExp, depthRef: number|PBShaderExp);
2376
+ textureArrayGatherCompare: {
2377
+ overloads: [
2378
+ ...genType('textureGatherCompare', MASK_WEBGPU, typeF32Vec4, [
2379
+ typeTexDepth2DArray,
2380
+ typeSamplerComparison,
2381
+ typeF32Vec2,
2382
+ typeI32,
2383
+ typeF32
2384
+ ]),
2385
+ ...genType('textureGatherCompare', MASK_WEBGPU, typeF32Vec4, [
2386
+ typeTexDepthCubeArray,
2387
+ typeSamplerComparison,
2388
+ typeF32Vec3,
2389
+ typeI32,
2390
+ typeF32
2391
+ ])
2392
+ ]
2393
+ },
2394
+ // textureLoad(tex: PBShaderExp, coords: number|PBShaderExp, levelOrSampleIndex: number|PBShaderExp);
2395
+ textureLoad: {
2396
+ overloads: [
2397
+ ...genType('textureLoad', MASK_WEBGPU, typeF32Vec4, [
2398
+ typeTex1D,
2399
+ typeI32,
2400
+ typeI32
2401
+ ]),
2402
+ ...genType('textureLoad', MASK_WEBGPU, typeI32Vec4, [
2403
+ typeITex1D,
2404
+ typeI32,
2405
+ typeI32
2406
+ ]),
2407
+ ...genType('textureLoad', MASK_WEBGPU, typeU32Vec4, [
2408
+ typeUTex1D,
2409
+ typeI32,
2410
+ typeI32
2411
+ ]),
2412
+ ...genType('textureLoad', MASK_WEBGPU, typeF32Vec4, [
2413
+ typeTex2D,
2414
+ typeI32Vec2,
2415
+ typeI32
2416
+ ]),
2417
+ ...genType('textureLoad', MASK_WEBGPU, typeI32Vec4, [
2418
+ typeITex2D,
2419
+ typeI32Vec2,
2420
+ typeI32
2421
+ ]),
2422
+ ...genType('textureLoad', MASK_WEBGPU, typeU32Vec4, [
2423
+ typeUTex2D,
2424
+ typeI32Vec2,
2425
+ typeI32
2426
+ ]),
2427
+ ...genType('textureLoad', MASK_WEBGPU, typeF32Vec4, [
2428
+ typeTex3D,
2429
+ typeI32Vec3,
2430
+ typeI32
2431
+ ]),
2432
+ ...genType('textureLoad', MASK_WEBGPU, typeI32Vec4, [
2433
+ typeITex3D,
2434
+ typeI32Vec3,
2435
+ typeI32
2436
+ ]),
2437
+ ...genType('textureLoad', MASK_WEBGPU, typeU32Vec4, [
2438
+ typeUTex3D,
2439
+ typeI32Vec3,
2440
+ typeI32
2441
+ ]),
2442
+ ...genType('textureLoad', MASK_WEBGPU, typeF32Vec4, [
2443
+ typeTexMultisampled2D,
2444
+ typeI32Vec2,
2445
+ typeI32
2446
+ ]),
2447
+ ...genType('textureLoad', MASK_WEBGPU, typeI32Vec4, [
2448
+ typeITexMultisampled2D,
2449
+ typeI32Vec2,
2450
+ typeI32
2451
+ ]),
2452
+ ...genType('textureLoad', MASK_WEBGPU, typeU32Vec4, [
2453
+ typeUTexMultisampled2D,
2454
+ typeI32Vec2,
2455
+ typeI32
2456
+ ]),
2457
+ ...genType('textureLoad', MASK_WEBGPU, typeF32Vec4, [
2458
+ typeTexExternal,
2459
+ typeI32Vec2
2460
+ ]),
2461
+ ...genType('textureLoad', MASK_WEBGPU, typeF32, [
2462
+ typeTexDepth2D,
2463
+ typeI32Vec2,
2464
+ typeI32
2465
+ ]),
2466
+ ...genType('textureLoad', MASK_WEBGPU, typeF32, [
2467
+ typeTexDepthMultisampled2D,
2468
+ typeI32Vec2,
2469
+ typeI32
2470
+ ]),
2471
+ ...genType('texelFetch', MASK_WEBGL2, typeF32Vec4, [
2472
+ typeTex1D,
2473
+ typeI32Vec2,
2474
+ typeI32
2475
+ ]),
2476
+ ...genType('texelFetch', MASK_WEBGL2, typeF32Vec4, [
2477
+ typeTex2D,
2478
+ typeI32Vec2,
2479
+ typeI32
2480
+ ]),
2481
+ ...genType('texelFetch', MASK_WEBGL2, typeF32Vec4, [
2482
+ typeTex3D,
2483
+ typeI32Vec3,
2484
+ typeI32
2485
+ ]),
2486
+ ...genType('texelFetch', MASK_WEBGL2, typeU32Vec4, [
2487
+ typeTexExternal,
2488
+ typeI32Vec2,
2489
+ typeI32
2490
+ ]),
2491
+ ...genType('texelFetch', MASK_WEBGL2, typeF32Vec4, [
2492
+ typeITex1D,
2493
+ typeI32Vec2,
2494
+ typeI32
2495
+ ]),
2496
+ ...genType('texelFetch', MASK_WEBGL2, typeI32Vec4, [
2497
+ typeITex2D,
2498
+ typeI32Vec2,
2499
+ typeI32
2500
+ ]),
2501
+ ...genType('texelFetch', MASK_WEBGL2, typeI32Vec4, [
2502
+ typeITex3D,
2503
+ typeI32Vec3,
2504
+ typeI32
2505
+ ]),
2506
+ ...genType('texelFetch', MASK_WEBGL2, typeF32Vec4, [
2507
+ typeUTex1D,
2508
+ typeI32Vec2,
2509
+ typeI32
2510
+ ]),
2511
+ ...genType('texelFetch', MASK_WEBGL2, typeU32Vec4, [
2512
+ typeUTex2D,
2513
+ typeI32Vec2,
2514
+ typeI32
2515
+ ]),
2516
+ ...genType('texelFetch', MASK_WEBGL2, typeU32Vec4, [
2517
+ typeUTex3D,
2518
+ typeI32Vec3,
2519
+ typeI32
2520
+ ])
2521
+ ],
2522
+ normalizeFunc (pb, name, ...args) {
2523
+ if (args.length === 0) {
2524
+ throw new PBParamLengthError('textureLoad');
2525
+ }
2526
+ if (!(args[0] instanceof PBShaderExp)) {
2527
+ throw new PBParamValueError('textureLoad', 'tex');
2528
+ }
2529
+ const texType = args[0].$ast.getType();
2530
+ if (!texType.isTextureType()) {
2531
+ throw new PBParamTypeError('textureLoad', 'tex');
2532
+ }
2533
+ if (pb.getDevice().type === 'webgl2') {
2534
+ if (args.length !== 3) {
2535
+ throw new PBParamLengthError('textureLoad');
2536
+ }
2537
+ if (texType.is1DTexture()) {
2538
+ if (typeof args[1] === 'number') {
2539
+ if (!Number.isInteger(args[1])) {
2540
+ throw new PBParamTypeError('textureLoad', 'coord');
2541
+ }
2542
+ } else if (args[1] instanceof PBShaderExp) {
2543
+ const coordType = args[1].$ast.getType();
2544
+ if (!coordType.isPrimitiveType() || !coordType.isScalarType() || coordType.scalarType !== PBPrimitiveType.I32) {
2545
+ throw new PBParamTypeError('textureLoad', 'coord');
2546
+ }
2547
+ } else {
2548
+ throw new PBParamTypeError('textureLoad', 'coord');
2549
+ }
2550
+ args[1] = pb.ivec2(args[1], 0);
2551
+ }
2552
+ } else if (pb.getDevice().type === 'webgpu' && texType.isExternalTexture()) {
2553
+ args = args.slice(0, 2);
2554
+ }
2555
+ return callBuiltin(pb, name, ...args);
2556
+ }
2557
+ },
2558
+ // textureArrayLoad(tex: PBShaderExp, coords: number|PBShaderExp, arrayIndex: number|PBShaderExp, level: number|PBShaderExp);
2559
+ textureArrayLoad: {
2560
+ overloads: [
2561
+ ...genType('textureLoad', MASK_WEBGPU, typeF32Vec4, [
2562
+ typeTex2DArray,
2563
+ typeI32Vec2,
2564
+ typeI32,
2565
+ typeI32
2566
+ ]),
2567
+ ...genType('textureLoad', MASK_WEBGPU, typeI32Vec4, [
2568
+ typeITex2DArray,
2569
+ typeI32Vec2,
2570
+ typeI32,
2571
+ typeI32
2572
+ ]),
2573
+ ...genType('textureLoad', MASK_WEBGPU, typeU32Vec4, [
2574
+ typeUTex2DArray,
2575
+ typeI32Vec2,
2576
+ typeI32,
2577
+ typeI32
2578
+ ]),
2579
+ ...genType('textureLoad', MASK_WEBGPU, typeF32, [
2580
+ typeTexDepth2DArray,
2581
+ typeI32Vec2,
2582
+ typeI32,
2583
+ typeI32
2584
+ ]),
2585
+ ...genType('texelFetch', MASK_WEBGL2, typeF32Vec4, [
2586
+ typeTex2DArray,
2587
+ typeI32Vec3,
2588
+ typeI32
2589
+ ]),
2590
+ ...genType('texelFetch', MASK_WEBGL2, typeI32Vec4, [
2591
+ typeITex2DArray,
2592
+ typeI32Vec3,
2593
+ typeI32
2594
+ ]),
2595
+ ...genType('texelFetch', MASK_WEBGL2, typeU32Vec4, [
2596
+ typeUTex2DArray,
2597
+ typeI32Vec3,
2598
+ typeI32
2599
+ ])
2600
+ ],
2601
+ normalizeFunc (pb, name, ...args) {
2602
+ if (pb.getDevice().type === 'webgl2') {
2603
+ if (args.length !== 4) {
2604
+ throw new PBParamLengthError('textureArrayLoad');
2605
+ }
2606
+ const tex = args[0];
2607
+ const coords = pb.ivec3(args[1], args[2]);
2608
+ const level = args[3];
2609
+ return callBuiltin(pb, name, tex, coords, level);
2610
+ } else {
2611
+ return callBuiltin(pb, name, ...args);
2612
+ }
2613
+ }
2614
+ },
2615
+ // textureStore(tex: PBShaderExp, coords: number|PBShaderExp, value: PBShaderExp);
2616
+ textureStore: {
2617
+ overloads: [
2618
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2619
+ typeTexStorage1D_rgba8unorm,
2620
+ typeU32,
2621
+ typeF32Vec4
2622
+ ]),
2623
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2624
+ typeTexStorage1D_rgba8snorm,
2625
+ typeU32,
2626
+ typeF32Vec4
2627
+ ]),
2628
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2629
+ typeTexStorage1D_rgba8uint,
2630
+ typeU32,
2631
+ typeU32Vec4
2632
+ ]),
2633
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2634
+ typeTexStorage1D_rgba8sint,
2635
+ typeU32,
2636
+ typeI32Vec4
2637
+ ]),
2638
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2639
+ typeTexStorage1D_rgba16uint,
2640
+ typeU32,
2641
+ typeU32Vec4
2642
+ ]),
2643
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2644
+ typeTexStorage1D_rgba16sint,
2645
+ typeU32,
2646
+ typeI32Vec4
2647
+ ]),
2648
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2649
+ typeTexStorage1D_rgba16float,
2650
+ typeU32,
2651
+ typeF32Vec4
2652
+ ]),
2653
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2654
+ typeTexStorage1D_rgba32uint,
2655
+ typeU32,
2656
+ typeU32Vec4
2657
+ ]),
2658
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2659
+ typeTexStorage1D_rgba32sint,
2660
+ typeU32,
2661
+ typeI32Vec4
2662
+ ]),
2663
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2664
+ typeTexStorage1D_rgba32float,
2665
+ typeU32,
2666
+ typeF32Vec4
2667
+ ]),
2668
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2669
+ typeTexStorage1D_rg32uint,
2670
+ typeU32,
2671
+ typeU32Vec4
2672
+ ]),
2673
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2674
+ typeTexStorage1D_rg32sint,
2675
+ typeU32,
2676
+ typeI32Vec4
2677
+ ]),
2678
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2679
+ typeTexStorage1D_rg32float,
2680
+ typeU32,
2681
+ typeF32Vec4
2682
+ ]),
2683
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2684
+ typeTexStorage1D_r32uint,
2685
+ typeU32,
2686
+ typeU32Vec4
2687
+ ]),
2688
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2689
+ typeTexStorage1D_r32sint,
2690
+ typeU32,
2691
+ typeI32Vec4
2692
+ ]),
2693
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2694
+ typeTexStorage1D_r32float,
2695
+ typeU32,
2696
+ typeF32Vec4
2697
+ ]),
2698
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2699
+ typeTexStorage2D_rgba8unorm,
2700
+ typeU32Vec2,
2701
+ typeF32Vec4
2702
+ ]),
2703
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2704
+ typeTexStorage2D_rgba8snorm,
2705
+ typeU32Vec2,
2706
+ typeF32Vec4
2707
+ ]),
2708
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2709
+ typeTexStorage2D_rgba8uint,
2710
+ typeU32Vec2,
2711
+ typeU32Vec4
2712
+ ]),
2713
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2714
+ typeTexStorage2D_rgba8sint,
2715
+ typeU32Vec2,
2716
+ typeI32Vec4
2717
+ ]),
2718
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2719
+ typeTexStorage2D_rgba16uint,
2720
+ typeU32Vec2,
2721
+ typeU32Vec4
2722
+ ]),
2723
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2724
+ typeTexStorage2D_rgba16sint,
2725
+ typeU32Vec2,
2726
+ typeI32Vec4
2727
+ ]),
2728
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2729
+ typeTexStorage2D_rgba16float,
2730
+ typeU32Vec2,
2731
+ typeF32Vec4
2732
+ ]),
2733
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2734
+ typeTexStorage2D_rgba32uint,
2735
+ typeU32Vec2,
2736
+ typeU32Vec4
2737
+ ]),
2738
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2739
+ typeTexStorage2D_rgba32sint,
2740
+ typeU32Vec2,
2741
+ typeI32Vec4
2742
+ ]),
2743
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2744
+ typeTexStorage2D_rgba32float,
2745
+ typeU32Vec2,
2746
+ typeF32Vec4
2747
+ ]),
2748
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2749
+ typeTexStorage2D_rg32uint,
2750
+ typeU32Vec2,
2751
+ typeU32Vec4
2752
+ ]),
2753
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2754
+ typeTexStorage2D_rg32sint,
2755
+ typeU32Vec2,
2756
+ typeI32Vec4
2757
+ ]),
2758
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2759
+ typeTexStorage2D_rg32float,
2760
+ typeU32Vec2,
2761
+ typeF32Vec4
2762
+ ]),
2763
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2764
+ typeTexStorage2D_r32uint,
2765
+ typeU32Vec2,
2766
+ typeU32Vec4
2767
+ ]),
2768
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2769
+ typeTexStorage2D_r32sint,
2770
+ typeU32Vec2,
2771
+ typeI32Vec4
2772
+ ]),
2773
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2774
+ typeTexStorage2D_r32float,
2775
+ typeU32Vec2,
2776
+ typeF32Vec4
2777
+ ]),
2778
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2779
+ typeTexStorage3D_rgba8unorm,
2780
+ typeU32Vec3,
2781
+ typeF32Vec4
2782
+ ]),
2783
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2784
+ typeTexStorage3D_rgba8snorm,
2785
+ typeU32Vec3,
2786
+ typeF32Vec4
2787
+ ]),
2788
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2789
+ typeTexStorage3D_rgba8uint,
2790
+ typeU32Vec3,
2791
+ typeU32Vec4
2792
+ ]),
2793
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2794
+ typeTexStorage3D_rgba8sint,
2795
+ typeU32Vec3,
2796
+ typeI32Vec4
2797
+ ]),
2798
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2799
+ typeTexStorage3D_rgba16uint,
2800
+ typeU32Vec3,
2801
+ typeU32Vec4
2802
+ ]),
2803
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2804
+ typeTexStorage3D_rgba16sint,
2805
+ typeU32Vec3,
2806
+ typeI32Vec4
2807
+ ]),
2808
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2809
+ typeTexStorage3D_rgba16float,
2810
+ typeU32Vec3,
2811
+ typeF32Vec4
2812
+ ]),
2813
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2814
+ typeTexStorage3D_rgba32uint,
2815
+ typeU32Vec3,
2816
+ typeU32Vec4
2817
+ ]),
2818
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2819
+ typeTexStorage3D_rgba32sint,
2820
+ typeU32Vec3,
2821
+ typeI32Vec4
2822
+ ]),
2823
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2824
+ typeTexStorage3D_rgba32float,
2825
+ typeU32Vec3,
2826
+ typeF32Vec4
2827
+ ]),
2828
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2829
+ typeTexStorage3D_rg32uint,
2830
+ typeU32Vec3,
2831
+ typeU32Vec4
2832
+ ]),
2833
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2834
+ typeTexStorage3D_rg32sint,
2835
+ typeU32Vec3,
2836
+ typeI32Vec4
2837
+ ]),
2838
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2839
+ typeTexStorage3D_rg32float,
2840
+ typeU32Vec3,
2841
+ typeF32Vec4
2842
+ ]),
2843
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2844
+ typeTexStorage3D_r32uint,
2845
+ typeU32Vec3,
2846
+ typeU32Vec4
2847
+ ]),
2848
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2849
+ typeTexStorage3D_r32sint,
2850
+ typeU32Vec3,
2851
+ typeI32Vec4
2852
+ ]),
2853
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2854
+ typeTexStorage3D_r32float,
2855
+ typeU32Vec3,
2856
+ typeF32Vec4
2857
+ ])
2858
+ ]
2859
+ },
2860
+ // textureArrayStore(tex: PBShaderExp, coords: PBShaderExp, arrayIndex: number|PBShaderExp, value: PBShaderExp);
2861
+ textureArrayStore: {
2862
+ overloads: [
2863
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2864
+ typeTexStorage2DArray_rgba8unorm,
2865
+ typeI32Vec2,
2866
+ typeI32,
2867
+ typeF32Vec4
2868
+ ]),
2869
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2870
+ typeTexStorage2DArray_rgba8snorm,
2871
+ typeI32Vec2,
2872
+ typeI32,
2873
+ typeF32Vec4
2874
+ ]),
2875
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2876
+ typeTexStorage2DArray_rgba8uint,
2877
+ typeI32Vec2,
2878
+ typeI32,
2879
+ typeU32Vec4
2880
+ ]),
2881
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2882
+ typeTexStorage2DArray_rgba8sint,
2883
+ typeI32Vec2,
2884
+ typeI32,
2885
+ typeI32Vec4
2886
+ ]),
2887
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2888
+ typeTexStorage2DArray_rgba16uint,
2889
+ typeI32Vec2,
2890
+ typeI32,
2891
+ typeU32Vec4
2892
+ ]),
2893
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2894
+ typeTexStorage2DArray_rgba16sint,
2895
+ typeI32Vec2,
2896
+ typeI32,
2897
+ typeI32Vec4
2898
+ ]),
2899
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2900
+ typeTexStorage2DArray_rgba16float,
2901
+ typeI32Vec2,
2902
+ typeI32,
2903
+ typeF32Vec4
2904
+ ]),
2905
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2906
+ typeTexStorage2DArray_rgba32uint,
2907
+ typeI32Vec2,
2908
+ typeI32,
2909
+ typeU32Vec4
2910
+ ]),
2911
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2912
+ typeTexStorage2DArray_rgba32sint,
2913
+ typeI32Vec2,
2914
+ typeI32,
2915
+ typeI32Vec4
2916
+ ]),
2917
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2918
+ typeTexStorage2DArray_rgba32float,
2919
+ typeI32Vec2,
2920
+ typeI32,
2921
+ typeF32Vec4
2922
+ ]),
2923
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2924
+ typeTexStorage2DArray_rg32uint,
2925
+ typeI32Vec2,
2926
+ typeI32,
2927
+ typeU32Vec4
2928
+ ]),
2929
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2930
+ typeTexStorage2DArray_rg32sint,
2931
+ typeI32Vec2,
2932
+ typeI32,
2933
+ typeI32Vec4
2934
+ ]),
2935
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2936
+ typeTexStorage2DArray_rg32float,
2937
+ typeI32Vec2,
2938
+ typeI32,
2939
+ typeF32Vec4
2940
+ ]),
2941
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2942
+ typeTexStorage2DArray_r32uint,
2943
+ typeI32Vec2,
2944
+ typeI32,
2945
+ typeU32Vec4
2946
+ ]),
2947
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2948
+ typeTexStorage2DArray_r32sint,
2949
+ typeI32Vec2,
2950
+ typeI32,
2951
+ typeI32Vec4
2952
+ ]),
2953
+ ...genType('textureStore', MASK_WEBGPU, typeVoid, [
2954
+ typeTexStorage2DArray_r32float,
2955
+ typeI32Vec2,
2956
+ typeI32,
2957
+ typeF32Vec4
2958
+ ])
2959
+ ]
2960
+ },
2961
+ // textureNumLayers(tex: PBShaderExp);
2962
+ textureNumLayers: {
2963
+ overloads: [
2964
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
2965
+ typeTex2DArray
2966
+ ]),
2967
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
2968
+ typeITex2DArray
2969
+ ]),
2970
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
2971
+ typeUTex2DArray
2972
+ ]),
2973
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
2974
+ typeTexCubeArray
2975
+ ]),
2976
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
2977
+ typeITexCubeArray
2978
+ ]),
2979
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
2980
+ typeUTexCubeArray
2981
+ ]),
2982
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
2983
+ typeTexDepth2DArray
2984
+ ]),
2985
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
2986
+ typeTexDepthCubeArray
2987
+ ]),
2988
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
2989
+ typeTexStorage2DArray_r32float
2990
+ ]),
2991
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
2992
+ typeTexStorage2DArray_r32sint
2993
+ ]),
2994
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
2995
+ typeTexStorage2DArray_r32uint
2996
+ ]),
2997
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
2998
+ typeTexStorage2DArray_rg32float
2999
+ ]),
3000
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
3001
+ typeTexStorage2DArray_rg32sint
3002
+ ]),
3003
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
3004
+ typeTexStorage2DArray_rg32uint
3005
+ ]),
3006
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
3007
+ typeTexStorage2DArray_rgba16float
3008
+ ]),
3009
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
3010
+ typeTexStorage2DArray_rgba16sint
3011
+ ]),
3012
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
3013
+ typeTexStorage2DArray_rgba16uint
3014
+ ]),
3015
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
3016
+ typeTexStorage2DArray_rgba32float
3017
+ ]),
3018
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
3019
+ typeTexStorage2DArray_rgba32sint
3020
+ ]),
3021
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
3022
+ typeTexStorage2DArray_rgba32uint
3023
+ ]),
3024
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
3025
+ typeTexStorage2DArray_rgba8sint
3026
+ ]),
3027
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
3028
+ typeTexStorage2DArray_rgba8snorm
3029
+ ]),
3030
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
3031
+ typeTexStorage2DArray_rgba8uint
3032
+ ]),
3033
+ ...genType('textureNumLayers', MASK_WEBGPU, typeI32, [
3034
+ typeTexStorage2DArray_rgba8unorm
3035
+ ])
3036
+ ]
3037
+ },
3038
+ // textureNumLevels(tex: PBShaderExp);
3039
+ textureNumLevels: {
3040
+ overloads: [
3041
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3042
+ typeTex1D
3043
+ ]),
3044
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3045
+ typeITex1D
3046
+ ]),
3047
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3048
+ typeUTex1D
3049
+ ]),
3050
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3051
+ typeTex2D
3052
+ ]),
3053
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3054
+ typeITex2D
3055
+ ]),
3056
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3057
+ typeUTex2D
3058
+ ]),
3059
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3060
+ typeTex2DArray
3061
+ ]),
3062
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3063
+ typeITex2DArray
3064
+ ]),
3065
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3066
+ typeUTex2DArray
3067
+ ]),
3068
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3069
+ typeTex3D
3070
+ ]),
3071
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3072
+ typeITex3D
3073
+ ]),
3074
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3075
+ typeUTex3D
3076
+ ]),
3077
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3078
+ typeTexCube
3079
+ ]),
3080
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3081
+ typeITexCube
3082
+ ]),
3083
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3084
+ typeUTexCube
3085
+ ]),
3086
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3087
+ typeTexCubeArray
3088
+ ]),
3089
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3090
+ typeITexCubeArray
3091
+ ]),
3092
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3093
+ typeUTexCubeArray
3094
+ ]),
3095
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3096
+ typeTexDepth2D
3097
+ ]),
3098
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3099
+ typeTexDepth2DArray
3100
+ ]),
3101
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3102
+ typeTexDepthCube
3103
+ ]),
3104
+ ...genType('textureNumLevels', MASK_WEBGPU, typeI32, [
3105
+ typeTexDepthCubeArray
3106
+ ])
3107
+ ]
3108
+ },
3109
+ // textureNumSamples(tex: PBShaderExp);
3110
+ textureNumSamples: {
3111
+ overloads: [
3112
+ ...genType('textureNumSamples', MASK_WEBGPU, typeI32, [
3113
+ typeTexMultisampled2D
3114
+ ]),
3115
+ ...genType('textureNumSamples', MASK_WEBGPU, typeI32, [
3116
+ typeITexMultisampled2D
3117
+ ]),
3118
+ ...genType('textureNumSamples', MASK_WEBGPU, typeI32, [
3119
+ typeUTexMultisampled2D
3120
+ ]),
3121
+ ...genType('textureNumSamples', MASK_WEBGPU, typeI32, [
3122
+ typeTexDepthMultisampled2D
3123
+ ])
3124
+ ]
3125
+ },
3126
+ // textureSample(tex: texture, coords: number|PBShaderExp);
3127
+ textureSample: {
3128
+ overloads: [
3129
+ ...genType('textureSample', MASK_WEBGPU, typeF32Vec4, [
3130
+ typeTex1D,
3131
+ typeSampler,
3132
+ typeF32
3133
+ ]),
3134
+ ...genType('textureSample', MASK_WEBGPU, typeF32Vec4, [
3135
+ typeTex2D,
3136
+ typeSampler,
3137
+ typeF32Vec2
3138
+ ]),
3139
+ ...genType('textureSample', MASK_WEBGPU, typeF32Vec4, [
3140
+ typeTex3D,
3141
+ typeSampler,
3142
+ typeF32Vec3
3143
+ ]),
3144
+ ...genType('textureSample', MASK_WEBGPU, typeF32Vec4, [
3145
+ typeTexCube,
3146
+ typeSampler,
3147
+ typeF32Vec3
3148
+ ]),
3149
+ ...genType('textureSample', MASK_WEBGPU, typeF32, [
3150
+ typeTexDepth2D,
3151
+ typeSampler,
3152
+ typeF32Vec2
3153
+ ]),
3154
+ ...genType('textureSample', MASK_WEBGPU, typeF32, [
3155
+ typeTexDepthCube,
3156
+ typeSampler,
3157
+ typeF32Vec3
3158
+ ]),
3159
+ ...genType('textureSampleBaseClampToEdge', MASK_WEBGPU, typeF32Vec4, [
3160
+ typeTexExternal,
3161
+ typeSampler,
3162
+ typeF32Vec2
3163
+ ]),
3164
+ ...genType('texture', MASK_WEBGL2, typeF32Vec4, [
3165
+ typeTex1D,
3166
+ typeF32Vec2
3167
+ ]),
3168
+ ...genType('texture', MASK_WEBGL2, typeF32Vec4, [
3169
+ typeTex2D,
3170
+ typeF32Vec2
3171
+ ]),
3172
+ ...genType('texture', MASK_WEBGL2, typeF32Vec4, [
3173
+ typeTexExternal,
3174
+ typeF32Vec2
3175
+ ]),
3176
+ ...genType('texture', MASK_WEBGL2, typeF32Vec4, [
3177
+ typeTexDepth2D,
3178
+ typeF32Vec2
3179
+ ]),
3180
+ ...genType('texture', MASK_WEBGL2, typeF32Vec4, [
3181
+ typeTex3D,
3182
+ typeF32Vec3
3183
+ ]),
3184
+ ...genType('texture', MASK_WEBGL2, typeF32Vec4, [
3185
+ typeTexCube,
3186
+ typeF32Vec3
3187
+ ]),
3188
+ ...genType('texture', MASK_WEBGL2, typeF32Vec4, [
3189
+ typeTexDepthCube,
3190
+ typeF32Vec3
3191
+ ]),
3192
+ ...genType('texture2D', MASK_WEBGL1, typeF32Vec4, [
3193
+ typeTex1D,
3194
+ typeF32Vec2
3195
+ ]),
3196
+ ...genType('texture2D', MASK_WEBGL1, typeF32Vec4, [
3197
+ typeTex2D,
3198
+ typeF32Vec2
3199
+ ]),
3200
+ ...genType('texture2D', MASK_WEBGL1, typeF32Vec4, [
3201
+ typeTexExternal,
3202
+ typeF32Vec2
3203
+ ]),
3204
+ ...genType('texture2D', MASK_WEBGL1, typeF32Vec4, [
3205
+ typeTexDepth2D,
3206
+ typeF32Vec2
3207
+ ]),
3208
+ ...genType('textureCube', MASK_WEBGL1, typeF32Vec4, [
3209
+ typeTexCube,
3210
+ typeF32Vec3
3211
+ ]),
3212
+ ...genType('textureCube', MASK_WEBGL1, typeF32Vec4, [
3213
+ typeTexDepthCube,
3214
+ typeF32Vec3
3215
+ ])
3216
+ ],
3217
+ normalizeFunc (pb, name, ...args) {
3218
+ if (args.length !== 2) {
3219
+ throw new PBParamLengthError('textureSample');
3220
+ }
3221
+ const tex = args[0];
3222
+ if (!(tex instanceof PBShaderExp)) {
3223
+ throw new PBParamTypeError('textureSample', 'texture');
3224
+ }
3225
+ const texType = tex.$ast.getType();
3226
+ if (!texType.isTextureType()) {
3227
+ throw new PBParamTypeError('textureSample', 'texture');
3228
+ }
3229
+ if (pb.getDevice().type === 'webgpu') {
3230
+ const sampler = pb.getDefaultSampler(tex, false);
3231
+ const coords = args[1];
3232
+ const ret = callBuiltin(pb, name, tex, sampler, coords);
3233
+ if (ret.$ast.getType().isCompatibleType(typeF32)) {
3234
+ return pb.vec4(ret);
3235
+ } else {
3236
+ return ret;
3237
+ }
3238
+ } else {
3239
+ pb.getDefaultSampler(tex, false);
3240
+ if (texType.is1DTexture()) {
3241
+ if (args[1] instanceof PBShaderExp) {
3242
+ const coordType = args[1].$ast.getType();
3243
+ if (!coordType.isPrimitiveType() || !coordType.isScalarType() || coordType.scalarType !== PBPrimitiveType.F32) {
3244
+ throw new PBParamTypeError('textureSample', 'coord');
3245
+ }
3246
+ } else if (typeof args[1] !== 'number') {
3247
+ throw new PBParamTypeError('textureSample', 'coord');
3248
+ }
3249
+ args[1] = pb.vec2(args[1], 0);
3250
+ }
3251
+ return callBuiltin(pb, name, ...args);
3252
+ }
3253
+ }
3254
+ },
3255
+ // textureArraySample(tex: PBShaderExp, coords: PBShaderExp, arrayIndex: number|PBShaderExp)
3256
+ textureArraySample: {
3257
+ overloads: [
3258
+ ...genType('textureSample', MASK_WEBGPU, typeF32Vec4, [
3259
+ typeTex2DArray,
3260
+ typeSampler,
3261
+ typeF32Vec2,
3262
+ typeI32
3263
+ ]),
3264
+ ...genType('textureSample', MASK_WEBGPU, typeF32Vec4, [
3265
+ typeTexCubeArray,
3266
+ typeSampler,
3267
+ typeF32Vec3,
3268
+ typeI32
3269
+ ]),
3270
+ ...genType('textureSample', MASK_WEBGPU, typeF32, [
3271
+ typeTexDepth2DArray,
3272
+ typeSampler,
3273
+ typeF32Vec2,
3274
+ typeI32
3275
+ ]),
3276
+ ...genType('textureSample', MASK_WEBGPU, typeF32, [
3277
+ typeTexDepthCubeArray,
3278
+ typeSampler,
3279
+ typeF32Vec3,
3280
+ typeI32
3281
+ ]),
3282
+ ...genType('texture', MASK_WEBGL2, typeF32Vec4, [
3283
+ typeTex2DArray,
3284
+ typeF32Vec3
3285
+ ]),
3286
+ ...genType('texture', MASK_WEBGL2, typeF32Vec4, [
3287
+ typeTexDepth2DArray,
3288
+ typeF32Vec3
3289
+ ])
3290
+ ],
3291
+ normalizeFunc (pb, name, ...args) {
3292
+ if (args.length !== 3) {
3293
+ throw new PBParamLengthError('textureArraySample');
3294
+ }
3295
+ const tex = args[0];
3296
+ if (!(tex instanceof PBShaderExp)) {
3297
+ throw new PBParamTypeError('textureArraySample', 'texture');
3298
+ }
3299
+ const texType = tex.$ast.getType();
3300
+ if (!texType.isTextureType()) {
3301
+ throw new PBParamTypeError('textureArraySample', 'texture');
3302
+ }
3303
+ if (pb.getDevice().type === 'webgpu') {
3304
+ const sampler = pb.getDefaultSampler(tex, false);
3305
+ const coords = args[1];
3306
+ const arrayIndex = args[2];
3307
+ const ret = callBuiltin(pb, name, tex, sampler, coords, arrayIndex);
3308
+ if (ret.$ast.getType().isCompatibleType(typeF32)) {
3309
+ return pb.vec4(ret);
3310
+ } else {
3311
+ return ret;
3312
+ }
3313
+ } else {
3314
+ pb.getDefaultSampler(tex, false);
3315
+ const coords = args[1];
3316
+ const arrayIndex = args[2];
3317
+ const coordsComposit = pb.vec3(coords, pb.float(arrayIndex));
3318
+ return callBuiltin(pb, name, tex, coordsComposit);
3319
+ }
3320
+ }
3321
+ },
3322
+ // textureSampleBias(tex: PBShaderExp, coords: PBShaderExp, bias: number|PBShaderExp)
3323
+ textureSampleBias: {
3324
+ overloads: [
3325
+ ...genType('textureSampleBias', MASK_WEBGPU, typeF32Vec4, [
3326
+ typeTex2D,
3327
+ typeSampler,
3328
+ typeF32Vec2,
3329
+ typeF32
3330
+ ]),
3331
+ ...genType('textureSampleBias', MASK_WEBGPU, typeF32Vec4, [
3332
+ typeTex3D,
3333
+ typeSampler,
3334
+ typeF32Vec3,
3335
+ typeF32
3336
+ ]),
3337
+ ...genType('textureSampleBias', MASK_WEBGPU, typeF32Vec4, [
3338
+ typeTexCube,
3339
+ typeSampler,
3340
+ typeF32Vec3,
3341
+ typeF32
3342
+ ]),
3343
+ ...genType('texture', MASK_WEBGL2, typeF32Vec4, [
3344
+ typeTex2D,
3345
+ typeF32Vec2,
3346
+ typeF32
3347
+ ]),
3348
+ ...genType('texture', MASK_WEBGL2, typeF32Vec4, [
3349
+ typeTex3D,
3350
+ typeF32Vec3,
3351
+ typeF32
3352
+ ]),
3353
+ ...genType('texture', MASK_WEBGL2, typeF32Vec4, [
3354
+ typeTexCube,
3355
+ typeF32Vec3,
3356
+ typeF32
3357
+ ]),
3358
+ ...genType('texture2D', MASK_WEBGL1, typeF32Vec4, [
3359
+ typeTex2D,
3360
+ typeF32Vec2,
3361
+ typeF32
3362
+ ]),
3363
+ ...genType('textureCube', MASK_WEBGL1, typeF32Vec4, [
3364
+ typeTexCube,
3365
+ typeF32Vec3,
3366
+ typeF32
3367
+ ])
3368
+ ],
3369
+ normalizeFunc (pb, name, ...args) {
3370
+ if (args.length !== 3) {
3371
+ throw new PBParamLengthError('textureSampleBias');
3372
+ }
3373
+ const tex = args[0];
3374
+ if (!(tex instanceof PBShaderExp)) {
3375
+ throw new PBParamTypeError('textureSampleBias', 'texture');
3376
+ }
3377
+ const texType = tex.$ast.getType();
3378
+ if (!texType.isTextureType()) {
3379
+ throw new PBParamTypeError('textureSampleBias', 'texture');
3380
+ }
3381
+ if (pb.getDevice().type === 'webgpu') {
3382
+ const sampler = pb.getDefaultSampler(tex, false);
3383
+ return callBuiltin(pb, name, tex, sampler, args[1], args[2]);
3384
+ } else {
3385
+ pb.getDefaultSampler(tex, false);
3386
+ return callBuiltin(pb, name, ...args);
3387
+ }
3388
+ }
3389
+ },
3390
+ // textureArraySampleBias(tex: PBShaderExp, coords: PBShaderExp, arrayIndex: number|PBShaderExp, bias: number|PBShaderExp)
3391
+ textureArraySampleBias: {
3392
+ overloads: [
3393
+ ...genType('textureSampleBias', MASK_WEBGPU, typeF32Vec4, [
3394
+ typeTex2DArray,
3395
+ typeSampler,
3396
+ typeF32Vec2,
3397
+ typeI32,
3398
+ typeF32
3399
+ ]),
3400
+ ...genType('textureSampleBias', MASK_WEBGPU, typeF32Vec4, [
3401
+ typeTexCubeArray,
3402
+ typeSampler,
3403
+ typeF32Vec3,
3404
+ typeI32,
3405
+ typeF32
3406
+ ]),
3407
+ ...genType('texture', MASK_WEBGL2, typeF32Vec4, [
3408
+ typeTex2DArray,
3409
+ typeF32Vec3,
3410
+ typeF32
3411
+ ])
3412
+ ],
3413
+ normalizeFunc (pb, name, ...args) {
3414
+ if (args.length !== 4) {
3415
+ throw new PBParamLengthError('textureArraySampleBias');
3416
+ }
3417
+ const tex = args[0];
3418
+ if (!(tex instanceof PBShaderExp)) {
3419
+ throw new PBParamTypeError('textureArraySampleBias', 'texture');
3420
+ }
3421
+ const texType = tex.$ast.getType();
3422
+ if (!texType.isTextureType()) {
3423
+ throw new PBParamTypeError('textureArraySampleBias', 'texture');
3424
+ }
3425
+ if (pb.getDevice().type === 'webgpu') {
3426
+ const sampler = pb.getDefaultSampler(tex, false);
3427
+ return callBuiltin(pb, name, tex, sampler, args[1], args[2], args[3]);
3428
+ } else if (pb.getDevice().type === 'webgl2') {
3429
+ pb.getDefaultSampler(tex, false);
3430
+ const coords = args[1];
3431
+ const arrayIndex = args[2];
3432
+ const coordsComposit = pb.vec3(coords, pb.float(arrayIndex));
3433
+ return callBuiltin(pb, name, tex, coordsComposit, args[3]);
3434
+ }
3435
+ }
3436
+ },
3437
+ // textureSampleCompare(tex: PBShaderExp, coords: PBShaderExp, depthRef: number|PBShaderExp)
3438
+ textureSampleCompare: {
3439
+ overloads: [
3440
+ ...genType('textureSampleCompare', MASK_WEBGPU, typeF32, [
3441
+ typeTexDepth2D,
3442
+ typeSamplerComparison,
3443
+ typeF32Vec2,
3444
+ typeF32
3445
+ ]),
3446
+ ...genType('textureSampleCompare', MASK_WEBGPU, typeF32, [
3447
+ typeTexDepthCube,
3448
+ typeSamplerComparison,
3449
+ typeF32Vec3,
3450
+ typeF32
3451
+ ]),
3452
+ ...genType('texture', MASK_WEBGL2, typeF32, [
3453
+ typeTexDepth2D,
3454
+ typeF32Vec3
3455
+ ]),
3456
+ ...genType('texture', MASK_WEBGL2, typeF32, [
3457
+ typeTexDepthCube,
3458
+ typeF32Vec4
3459
+ ])
3460
+ ],
3461
+ normalizeFunc (pb, name, ...args) {
3462
+ if (args.length !== 3) {
3463
+ throw new PBParamLengthError('textureSampleCompare');
3464
+ }
3465
+ const tex = args[0];
3466
+ if (!(tex instanceof PBShaderExp)) {
3467
+ throw new PBParamTypeError('textureSampleCompare', 'texture');
3468
+ }
3469
+ const texType = tex.$ast.getType();
3470
+ if (!texType.isTextureType() || !texType.isDepthTexture()) {
3471
+ throw new PBParamTypeError('textureSampleCompare', 'texture');
3472
+ }
3473
+ if (pb.getDevice().type === 'webgpu') {
3474
+ const sampler = pb.getDefaultSampler(args[0], true);
3475
+ return callBuiltin(pb, name, tex, sampler, args[1], args[2]);
3476
+ } else {
3477
+ pb.getDefaultSampler(args[0], true);
3478
+ let coordsComposite;
3479
+ if (texType.isCubeTexture() || texType.isArrayTexture()) {
3480
+ coordsComposite = pb.vec4(args[1], args[2]);
3481
+ } else {
3482
+ coordsComposite = pb.vec3(args[1], args[2]);
3483
+ }
3484
+ return callBuiltin(pb, name, tex, coordsComposite);
3485
+ }
3486
+ }
3487
+ },
3488
+ // textureArraySampleCompare(tex: PBShaderExp, coords: PBShaderExp, arrayIndex: number|PBShaderExp, depthRef: number|PBShaderExp)
3489
+ textureArraySampleCompare: {
3490
+ overloads: [
3491
+ ...genType('textureSampleCompare', MASK_WEBGPU, typeF32, [
3492
+ typeTexDepth2DArray,
3493
+ typeSamplerComparison,
3494
+ typeF32Vec2,
3495
+ typeI32,
3496
+ typeF32
3497
+ ]),
3498
+ ...genType('textureSampleCompare', MASK_WEBGPU, typeF32, [
3499
+ typeTexDepthCubeArray,
3500
+ typeSamplerComparison,
3501
+ typeF32Vec3,
3502
+ typeI32,
3503
+ typeF32
3504
+ ]),
3505
+ ...genType('texture', MASK_WEBGL2, typeF32, [
3506
+ typeTexDepth2DArray,
3507
+ typeF32Vec4
3508
+ ])
3509
+ ],
3510
+ normalizeFunc (pb, name, ...args) {
3511
+ if (args.length !== 4) {
3512
+ throw new PBParamLengthError('textureArraySampleCompare');
3513
+ }
3514
+ const tex = args[0];
3515
+ if (!(tex instanceof PBShaderExp)) {
3516
+ throw new PBParamTypeError('textureArraySampleCompare', 'texture');
3517
+ }
3518
+ const texType = tex.$ast.getType();
3519
+ if (!texType.isTextureType() || !texType.isDepthTexture()) {
3520
+ throw new PBParamTypeError('textureArraySampleCompare', 'texture');
3521
+ }
3522
+ if (pb.getDevice().type === 'webgpu') {
3523
+ const sampler = pb.getDefaultSampler(args[0], true);
3524
+ return callBuiltin(pb, name, tex, sampler, args[1], args[2], args[3]);
3525
+ } else {
3526
+ pb.getDefaultSampler(args[0], true);
3527
+ const coordsComposite = pb.vec4(args[1], pb.float(args[2]), args[3]);
3528
+ return callBuiltin(pb, name, tex, coordsComposite);
3529
+ }
3530
+ }
3531
+ },
3532
+ // textureSampleLevel(tex: PBShaderExp, coords: PBShaderExp, level: number|PBShaderExp)
3533
+ textureSampleLevel: {
3534
+ overloads: [
3535
+ ...genType('textureSampleLevel', MASK_WEBGPU, typeF32Vec4, [
3536
+ typeTex2D,
3537
+ typeSampler,
3538
+ typeF32Vec2,
3539
+ typeF32
3540
+ ]),
3541
+ ...genType('textureSampleLevel', MASK_WEBGPU, typeF32Vec4, [
3542
+ typeTex3D,
3543
+ typeSampler,
3544
+ typeF32Vec3,
3545
+ typeF32
3546
+ ]),
3547
+ ...genType('textureSampleLevel', MASK_WEBGPU, typeF32Vec4, [
3548
+ typeTexCube,
3549
+ typeSampler,
3550
+ typeF32Vec3,
3551
+ typeF32
3552
+ ]),
3553
+ ...genType('textureSampleLevel', MASK_WEBGPU, typeF32Vec4, [
3554
+ typeTexExternal,
3555
+ typeSampler,
3556
+ typeF32Vec2
3557
+ ]),
3558
+ ...genType('textureSampleLevel', MASK_WEBGPU, typeF32, [
3559
+ typeTexDepth2D,
3560
+ typeSampler,
3561
+ typeF32Vec2,
3562
+ typeI32
3563
+ ]),
3564
+ ...genType('textureSampleLevel', MASK_WEBGPU, typeF32, [
3565
+ typeTexDepthCube,
3566
+ typeSampler,
3567
+ typeF32Vec3,
3568
+ typeI32
3569
+ ]),
3570
+ ...genType('textureLod', MASK_WEBGL2, typeF32Vec4, [
3571
+ typeTex2D,
3572
+ typeF32Vec2,
3573
+ typeF32
3574
+ ]),
3575
+ ...genType('textureLod', MASK_WEBGL2, typeF32Vec4, [
3576
+ typeTexDepth2D,
3577
+ typeF32Vec2,
3578
+ typeF32
3579
+ ]),
3580
+ ...genType('textureLod', MASK_WEBGL2, typeF32Vec4, [
3581
+ typeTexExternal,
3582
+ typeF32Vec2,
3583
+ typeF32
3584
+ ]),
3585
+ ...genType('textureLod', MASK_WEBGL2, typeF32Vec4, [
3586
+ typeTex3D,
3587
+ typeF32Vec3,
3588
+ typeF32
3589
+ ]),
3590
+ ...genType('textureLod', MASK_WEBGL2, typeF32Vec4, [
3591
+ typeTexCube,
3592
+ typeF32Vec3,
3593
+ typeF32
3594
+ ]),
3595
+ ...genType('textureLod', MASK_WEBGL2, typeF32Vec4, [
3596
+ typeTexDepthCube,
3597
+ typeF32Vec3,
3598
+ typeF32
3599
+ ]),
3600
+ ...genType('texture2DLodEXT', MASK_WEBGL1, typeF32Vec4, [
3601
+ typeTex2D,
3602
+ typeF32Vec2,
3603
+ typeF32
3604
+ ]),
3605
+ ...genType('texture2DLodEXT', MASK_WEBGL1, typeF32Vec4, [
3606
+ typeTexDepth2D,
3607
+ typeF32Vec2,
3608
+ typeF32
3609
+ ]),
3610
+ ...genType('texture2DLodEXT', MASK_WEBGL1, typeF32Vec4, [
3611
+ typeTexExternal,
3612
+ typeF32Vec2,
3613
+ typeF32
3614
+ ]),
3615
+ ...genType('textureCubeLodEXT', MASK_WEBGL1, typeF32Vec4, [
3616
+ typeTexCube,
3617
+ typeF32Vec3,
3618
+ typeF32
3619
+ ]),
3620
+ ...genType('textureCubeLodEXT', MASK_WEBGL1, typeF32Vec4, [
3621
+ typeTexDepthCube,
3622
+ typeF32Vec3,
3623
+ typeF32
3624
+ ])
3625
+ ],
3626
+ normalizeFunc (pb, name, ...args) {
3627
+ const tex = args[0];
3628
+ if (!(tex instanceof PBShaderExp)) {
3629
+ throw new PBParamTypeError('textureSampleLevel', 'texture');
3630
+ }
3631
+ const texType = tex.$ast.getType();
3632
+ if (!texType.isTextureType()) {
3633
+ throw new PBParamTypeError('textureSampleLevel', 'texture');
3634
+ }
3635
+ if (pb.getDevice().type === 'webgpu') {
3636
+ if (texType.isExternalTexture()) {
3637
+ return pb.textureLoad(tex, pb.ivec2(args[1]), 0);
3638
+ } else {
3639
+ const sampler = pb.getDefaultSampler(tex, false);
3640
+ const level = texType.isDepthTexture() && (typeof args[2] === 'number' || args[2] instanceof PBShaderExp && args[2].$ast.getType().isCompatibleType(typeF32)) ? pb.int(args[2]) : args[2];
3641
+ const ret = texType.isExternalTexture() ? callBuiltin(pb, name, tex, sampler, args[1]) : callBuiltin(pb, name, tex, sampler, args[1], level);
3642
+ if (ret.$ast.getType().isCompatibleType(typeF32)) {
3643
+ return pb.vec4(ret);
3644
+ } else {
3645
+ return ret;
3646
+ }
3647
+ }
3648
+ } else {
3649
+ pb.getDefaultSampler(tex, false);
3650
+ return texType.isExternalTexture() ? callBuiltin(pb, name, args[0], args[1], 0) : callBuiltin(pb, name, args[0], args[1], args[2]);
3651
+ }
3652
+ }
3653
+ },
3654
+ // textureArraySampleLevel(tex: PBShaderExp, coords: PBShaderExp, arrayIndex: number|PBShaderExp, level: number|PBShaderExp)
3655
+ textureArraySampleLevel: {
3656
+ overloads: [
3657
+ ...genType('textureSampleLevel', MASK_WEBGPU, typeF32Vec4, [
3658
+ typeTex2DArray,
3659
+ typeSampler,
3660
+ typeF32Vec2,
3661
+ typeI32,
3662
+ typeF32
3663
+ ]),
3664
+ ...genType('textureSampleLevel', MASK_WEBGPU, typeF32Vec4, [
3665
+ typeTexCubeArray,
3666
+ typeSampler,
3667
+ typeF32Vec3,
3668
+ typeI32,
3669
+ typeF32
3670
+ ]),
3671
+ ...genType('textureSampleLevel', MASK_WEBGPU, typeF32, [
3672
+ typeTexDepth2DArray,
3673
+ typeSampler,
3674
+ typeF32Vec2,
3675
+ typeI32,
3676
+ typeI32
3677
+ ]),
3678
+ ...genType('textureSampleLevel', MASK_WEBGPU, typeF32, [
3679
+ typeTexDepthCubeArray,
3680
+ typeSampler,
3681
+ typeF32Vec3,
3682
+ typeI32,
3683
+ typeI32
3684
+ ]),
3685
+ ...genType('textureLod', MASK_WEBGL2, typeF32Vec4, [
3686
+ typeTex2DArray,
3687
+ typeF32Vec3,
3688
+ typeF32
3689
+ ])
3690
+ ],
3691
+ normalizeFunc (pb, name, ...args) {
3692
+ if (args.length !== 4) {
3693
+ throw new PBParamLengthError('textureArraySampleLevel');
3694
+ }
3695
+ const tex = args[0];
3696
+ if (!(tex instanceof PBShaderExp)) {
3697
+ throw new PBParamTypeError('textureArraySampleLevel', 'texture');
3698
+ }
3699
+ const texType = tex.$ast.getType();
3700
+ if (!texType.isTextureType()) {
3701
+ throw new PBParamTypeError('textureArraySampleLevel', 'texture');
3702
+ }
3703
+ if (pb.getDevice().type === 'webgpu') {
3704
+ const sampler = pb.getDefaultSampler(tex, false);
3705
+ const level = texType.isDepthTexture() && (typeof args[3] === 'number' || args[3] instanceof PBShaderExp && args[3].$ast.getType().isCompatibleType(typeF32)) ? pb.int(args[3]) : args[3];
3706
+ const ret = callBuiltin(pb, name, tex, sampler, args[1], args[2], level);
3707
+ if (ret.$ast.getType().isCompatibleType(typeF32)) {
3708
+ return pb.vec4(ret);
3709
+ } else {
3710
+ return ret;
3711
+ }
3712
+ } else {
3713
+ pb.getDefaultSampler(tex, false);
3714
+ const coordsComposite = pb.vec3(args[1], pb.float(args[2]));
3715
+ return callBuiltin(pb, name, tex, coordsComposite, args[3]);
3716
+ }
3717
+ }
3718
+ },
3719
+ // textureSampleCompare(tex: PBShaderExp, coords: PBShaderExp, depthRef: number|PBShaderExp)
3720
+ textureSampleCompareLevel: {
3721
+ overloads: [
3722
+ ...genType('textureSampleCompareLevel', MASK_WEBGPU, typeF32, [
3723
+ typeTexDepth2D,
3724
+ typeSamplerComparison,
3725
+ typeF32Vec2,
3726
+ typeF32
3727
+ ]),
3728
+ ...genType('textureSampleCompareLevel', MASK_WEBGPU, typeF32, [
3729
+ typeTexDepthCube,
3730
+ typeSamplerComparison,
3731
+ typeF32Vec3,
3732
+ typeF32
3733
+ ]),
3734
+ ...genType('textureLod', MASK_WEBGL2, typeF32, [
3735
+ typeTexDepth2D,
3736
+ typeF32Vec3,
3737
+ typeF32
3738
+ ]),
3739
+ ...genType('texture', MASK_WEBGL2, typeF32, [
3740
+ typeTexDepthCube,
3741
+ typeF32Vec4
3742
+ ])
3743
+ ],
3744
+ normalizeFunc (pb, name, ...args) {
3745
+ if (args.length !== 3) {
3746
+ throw new PBParamLengthError('textureSampleCompareLevel');
3747
+ }
3748
+ const tex = args[0];
3749
+ if (!(tex instanceof PBShaderExp)) {
3750
+ throw new PBParamTypeError('textureSampleCompareLevel', 'texture');
3751
+ }
3752
+ const texType = tex.$ast.getType();
3753
+ if (!texType.isTextureType() || !texType.isDepthTexture()) {
3754
+ throw new PBParamTypeError('textureSampleCompareLevel', 'texture');
3755
+ }
3756
+ if (pb.getDevice().type === 'webgpu') {
3757
+ const sampler = pb.getDefaultSampler(tex, true);
3758
+ return callBuiltin(pb, name, tex, sampler, args[1], args[2]);
3759
+ } else {
3760
+ pb.getDefaultSampler(args[0], true);
3761
+ let coordsComposite;
3762
+ if (texType.isCubeTexture() || texType.isArrayTexture()) {
3763
+ coordsComposite = pb.vec4(args[1], args[2]);
3764
+ } else {
3765
+ coordsComposite = pb.vec3(args[1], args[2]);
3766
+ }
3767
+ return texType.isCubeTexture() ? callBuiltin(pb, name, tex, coordsComposite) : callBuiltin(pb, name, tex, coordsComposite, 0);
3768
+ }
3769
+ }
3770
+ },
3771
+ // textureArraySampleCompareLevel(tex: PBShaderExp, coords: PBShaderExp, arrayIndex: number|PBShaderExp, depthRef: number|PBShaderExp)
3772
+ textureArraySampleCompareLevel: {
3773
+ overloads: [
3774
+ ...genType('textureSampleCompareLevel', MASK_WEBGPU, typeF32, [
3775
+ typeTexDepth2DArray,
3776
+ typeSamplerComparison,
3777
+ typeF32Vec2,
3778
+ typeI32,
3779
+ typeF32
3780
+ ]),
3781
+ ...genType('textureSampleCompareLevel', MASK_WEBGPU, typeF32, [
3782
+ typeTexDepthCubeArray,
3783
+ typeSamplerComparison,
3784
+ typeF32Vec3,
3785
+ typeI32,
3786
+ typeF32
3787
+ ]),
3788
+ ...genType('texture', MASK_WEBGL2, typeF32, [
3789
+ typeTexDepth2DArray,
3790
+ typeF32Vec4
3791
+ ])
3792
+ ],
3793
+ normalizeFunc (pb, name, ...args) {
3794
+ if (args.length !== 4) {
3795
+ throw new PBParamLengthError('textureArraySampleCompareLevel');
3796
+ }
3797
+ const tex = args[0];
3798
+ if (!(tex instanceof PBShaderExp)) {
3799
+ throw new PBParamTypeError('textureArraySampleCompareLevel', 'texture');
3800
+ }
3801
+ const texType = tex.$ast.getType();
3802
+ if (!texType.isTextureType() || !texType.isDepthTexture()) {
3803
+ throw new PBParamTypeError('textureArraySampleCompareLevel', 'texture');
3804
+ }
3805
+ if (pb.getDevice().type === 'webgpu') {
3806
+ const sampler = pb.getDefaultSampler(tex, true);
3807
+ return callBuiltin(pb, name, tex, sampler, args[1], args[2], args[3]);
3808
+ } else {
3809
+ pb.getDefaultSampler(args[0], true);
3810
+ const coordsComposite = pb.vec4(args[1], pb.float(args[2]), args[3]);
3811
+ return callBuiltin(pb, name, tex, coordsComposite);
3812
+ }
3813
+ }
3814
+ },
3815
+ // textureSampleGrad(tex: PBShaderExp, coords: PBShaderExp, ddx: PBShaderExp, ddy: PBShaderExp)
3816
+ textureSampleGrad: {
3817
+ overloads: [
3818
+ ...genType('textureSampleGrad', MASK_WEBGPU, typeF32Vec4, [
3819
+ typeTex2D,
3820
+ typeSampler,
3821
+ typeF32Vec2,
3822
+ typeF32Vec2,
3823
+ typeF32Vec2
3824
+ ]),
3825
+ ...genType('textureSampleGrad', MASK_WEBGPU, typeF32Vec4, [
3826
+ typeTex3D,
3827
+ typeSampler,
3828
+ typeF32Vec3,
3829
+ typeF32Vec3,
3830
+ typeF32Vec3
3831
+ ]),
3832
+ ...genType('textureSampleGrad', MASK_WEBGPU, typeF32Vec4, [
3833
+ typeTexCube,
3834
+ typeSampler,
3835
+ typeF32Vec3,
3836
+ typeF32Vec3,
3837
+ typeF32Vec3
3838
+ ]),
3839
+ ...genType('textureGrad', MASK_WEBGL2, typeF32Vec4, [
3840
+ typeTex2D,
3841
+ typeF32Vec2,
3842
+ typeF32Vec2,
3843
+ typeF32Vec2
3844
+ ]),
3845
+ ...genType('textureGrad', MASK_WEBGL2, typeF32Vec4, [
3846
+ typeTex3D,
3847
+ typeF32Vec3,
3848
+ typeF32Vec3,
3849
+ typeF32Vec3
3850
+ ]),
3851
+ ...genType('textureGrad', MASK_WEBGL2, typeF32Vec4, [
3852
+ typeTexCube,
3853
+ typeF32Vec3,
3854
+ typeF32Vec3,
3855
+ typeF32Vec3
3856
+ ]),
3857
+ ...genType('texture2DGradEXT', MASK_WEBGL1, typeF32Vec4, [
3858
+ typeTex2D,
3859
+ typeF32Vec2,
3860
+ typeF32Vec2,
3861
+ typeF32Vec2
3862
+ ]),
3863
+ ...genType('textureCubeGradEXT', MASK_WEBGL1, typeF32Vec4, [
3864
+ typeTexCube,
3865
+ typeF32Vec3,
3866
+ typeF32Vec3,
3867
+ typeF32Vec3
3868
+ ])
3869
+ ],
3870
+ normalizeFunc (pb, name, ...args) {
3871
+ if (args.length !== 4) {
3872
+ throw new PBParamLengthError('textureSampleGrad');
3873
+ }
3874
+ const tex = args[0];
3875
+ if (!(tex instanceof PBShaderExp)) {
3876
+ throw new PBParamTypeError('textureSampleGrad', 'texture');
3877
+ }
3878
+ const texType = tex.$ast.getType();
3879
+ if (!texType.isTextureType()) {
3880
+ throw new PBParamTypeError('textureSampleGrad', 'texture');
3881
+ }
3882
+ if (pb.getDevice().type === 'webgpu') {
3883
+ const sampler = pb.getDefaultSampler(tex, false);
3884
+ return callBuiltin(pb, name, tex, sampler, args[1], args[2], args[3]);
3885
+ } else {
3886
+ pb.getDefaultSampler(tex, false);
3887
+ return callBuiltin(pb, name, ...args);
3888
+ }
3889
+ }
3890
+ },
3891
+ // textureArraySampleGrad(tex: PBShaderExp, coords: PBShaderExp, arrayIndex: number|PBShaderExp, ddx: PBShaderExp, ddy: PBShaderExp)
3892
+ textureArraySampleGrad: {
3893
+ overloads: [
3894
+ ...genType('textureSampleGrad', MASK_WEBGPU, typeF32Vec4, [
3895
+ typeTex2DArray,
3896
+ typeSampler,
3897
+ typeF32Vec2,
3898
+ typeI32,
3899
+ typeF32Vec2,
3900
+ typeF32Vec2
3901
+ ]),
3902
+ ...genType('textureSampleGrad', MASK_WEBGPU, typeF32Vec4, [
3903
+ typeTexCubeArray,
3904
+ typeSampler,
3905
+ typeF32Vec3,
3906
+ typeI32,
3907
+ typeF32Vec3,
3908
+ typeF32Vec3
3909
+ ]),
3910
+ ...genType('textureGrad', MASK_WEBGL2, typeF32Vec4, [
3911
+ typeTex2DArray,
3912
+ typeF32Vec3,
3913
+ typeF32Vec2,
3914
+ typeF32Vec2
3915
+ ])
3916
+ ],
3917
+ normalizeFunc (pb, name, ...args) {
3918
+ if (args.length !== 5) {
3919
+ throw new PBParamLengthError('textureArraySampleGrad');
3920
+ }
3921
+ const tex = args[0];
3922
+ if (!(tex instanceof PBShaderExp)) {
3923
+ throw new PBParamTypeError('textureArraySampleGrad', 'texture');
3924
+ }
3925
+ const texType = tex.$ast.getType();
3926
+ if (!texType.isTextureType() || !texType.isArrayTexture()) {
3927
+ throw new PBParamTypeError('textureArraySampleGrad', 'texture');
3928
+ }
3929
+ if (pb.getDevice().type === 'webgpu') {
3930
+ const sampler = pb.getDefaultSampler(tex, false);
3931
+ return callBuiltin(pb, name, tex, sampler, args[1], args[2], args[3], args[4]);
3932
+ } else {
3933
+ pb.getDefaultSampler(tex, false);
3934
+ const coordsComposite = pb.vec3(args[1], pb.float(args[2]));
3935
+ return callBuiltin(pb, name, tex, coordsComposite, args[3], args[4]);
3936
+ }
3937
+ }
3938
+ },
3939
+ storageBarrier: {
3940
+ overloads: genType('storageBarrier', MASK_WEBGPU, typeVoid, [])
3941
+ },
3942
+ workgroupBarrier: {
3943
+ overloads: genType('workgroupBarrier', MASK_WEBGPU, typeVoid, [])
3944
+ },
3945
+ atomicLoad: {
3946
+ overloades: [],
3947
+ normalizeFunc (pb, name, ...args) {
3948
+ if (args.length !== 1) {
3949
+ throw new PBParamLengthError(name);
3950
+ }
3951
+ const arg = args[0];
3952
+ if (!(arg instanceof PBShaderExp)) {
3953
+ throw new PBParamTypeError(name, 'ptr');
3954
+ }
3955
+ if (arg.$ast.getType().typeId === typeAtomicI32.typeId) {
3956
+ return pb.$callFunctionNoCheck(name, [
3957
+ new ASTAddressOf(arg.$ast)
3958
+ ], typeI32);
3959
+ } else if (arg.$ast.getType().typeId === typeAtomicU32.typeId) {
3960
+ return pb.$callFunctionNoCheck(name, [
3961
+ new ASTAddressOf(arg.$ast)
3962
+ ], typeU32);
3963
+ } else {
3964
+ throw new PBParamValueError(name, 'ptr must be atomic type');
3965
+ }
3966
+ }
3967
+ },
3968
+ atomicStore: {
3969
+ overloades: [],
3970
+ normalizeFunc (pb, name, ...args) {
3971
+ if (args.length !== 2) {
3972
+ throw new PBParamLengthError(name);
3973
+ }
3974
+ const arg1 = args[0];
3975
+ const arg2 = args[1];
3976
+ if (!(arg1 instanceof PBShaderExp)) {
3977
+ throw new PBParamTypeError(name, 'ptr');
3978
+ }
3979
+ if (arg1.$ast.getType().typeId === typeAtomicI32.typeId) {
3980
+ if (typeof arg2 === 'number') {
3981
+ if (!Number.isInteger(arg2)) {
3982
+ throw new PBParamValueError(name, 'value');
3983
+ }
3984
+ return pb.$callFunctionNoCheck(name, [
3985
+ new ASTAddressOf(arg1.$ast),
3986
+ new ASTScalar(arg2, typeI32)
3987
+ ], typeVoid);
3988
+ } else if (arg2 instanceof PBShaderExp) {
3989
+ if (arg2.$ast.getType().typeId !== typeI32.typeId) {
3990
+ throw new PBParamTypeError(name, 'value');
3991
+ }
3992
+ return pb.$callFunctionNoCheck(name, [
3993
+ new ASTAddressOf(arg1.$ast),
3994
+ arg2.$ast
3995
+ ], typeVoid);
3996
+ } else {
3997
+ throw new PBParamTypeError(name, 'value');
3998
+ }
3999
+ } else if (arg1.$ast.getType().typeId === typeAtomicU32.typeId) {
4000
+ if (typeof arg2 === 'number') {
4001
+ if (!Number.isInteger(arg2)) {
4002
+ throw new PBParamValueError(name, 'value');
4003
+ }
4004
+ return pb.$callFunctionNoCheck(name, [
4005
+ new ASTAddressOf(arg1.$ast),
4006
+ new ASTScalar(arg2, typeU32)
4007
+ ], typeVoid);
4008
+ } else if (arg2 instanceof PBShaderExp) {
4009
+ if (arg2.$ast.getType().typeId !== typeU32.typeId) {
4010
+ throw new PBParamTypeError(name, 'value');
4011
+ }
4012
+ return pb.$callFunctionNoCheck(name, [
4013
+ new ASTAddressOf(arg1.$ast),
4014
+ arg2.$ast
4015
+ ], typeVoid);
4016
+ } else {
4017
+ throw new PBParamTypeError(name, 'value');
4018
+ }
4019
+ } else {
4020
+ throw new PBParamValueError(name, 'ptr must be atomic type');
4021
+ }
4022
+ }
4023
+ }
4024
+ };
4025
+ for (const name of [
4026
+ 'atomicAdd',
4027
+ 'atomicSub',
4028
+ 'atomicMax',
4029
+ 'atomicMin',
4030
+ 'atomicAnd',
4031
+ 'atomicOr',
4032
+ 'atomicXor'
4033
+ ]){
4034
+ builtinFunctionsAll[name] = {
4035
+ overloades: [],
4036
+ normalizeFunc (pb, name, ...args) {
4037
+ if (args.length !== 2) {
4038
+ throw new PBParamLengthError(name);
4039
+ }
4040
+ const arg1 = args[0];
4041
+ const arg2 = args[1];
4042
+ if (!(arg1 instanceof PBShaderExp)) {
4043
+ throw new PBParamTypeError(name, 'ptr');
4044
+ }
4045
+ if (arg1.$ast.getType().typeId === typeAtomicI32.typeId) {
4046
+ if (typeof arg2 === 'number') {
4047
+ if (!Number.isInteger(arg2)) {
4048
+ throw new PBParamValueError(name, 'value');
4049
+ }
4050
+ return pb.$callFunctionNoCheck(name, [
4051
+ new ASTAddressOf(arg1.$ast),
4052
+ new ASTScalar(arg2, typeI32)
4053
+ ], typeI32);
4054
+ } else if (arg2 instanceof PBShaderExp) {
4055
+ if (arg2.$ast.getType().typeId !== typeI32.typeId) {
4056
+ throw new PBParamTypeError(name, 'value');
4057
+ }
4058
+ return pb.$callFunctionNoCheck(name, [
4059
+ new ASTAddressOf(arg1.$ast),
4060
+ arg2.$ast
4061
+ ], typeI32);
4062
+ } else {
4063
+ throw new PBParamTypeError(name, 'value');
4064
+ }
4065
+ } else if (arg1.$ast.getType().typeId === typeAtomicU32.typeId) {
4066
+ if (typeof arg2 === 'number') {
4067
+ if (!Number.isInteger(arg2)) {
4068
+ throw new PBParamValueError(name, 'value');
4069
+ }
4070
+ return pb.$callFunctionNoCheck(name, [
4071
+ new ASTAddressOf(arg1.$ast),
4072
+ new ASTScalar(arg2, typeU32)
4073
+ ], typeU32);
4074
+ } else if (arg2 instanceof PBShaderExp) {
4075
+ if (arg2.$ast.getType().typeId !== typeU32.typeId) {
4076
+ throw new PBParamTypeError(name, 'value');
4077
+ }
4078
+ return pb.$callFunctionNoCheck(name, [
4079
+ new ASTAddressOf(arg1.$ast),
4080
+ arg2.$ast
4081
+ ], typeU32);
4082
+ } else {
4083
+ throw new PBParamTypeError(name, 'value');
4084
+ }
4085
+ } else {
4086
+ throw new PBParamValueError(name, 'ptr must be atomic type');
4087
+ }
4088
+ }
4089
+ };
4090
+ }
4091
+ /** @internal */ function setBuiltinFuncs(cls) {
4092
+ for (const k of Object.keys(builtinFunctionsAll)){
4093
+ cls.prototype[k] = function(...args) {
4094
+ const normalizeFunc = builtinFunctionsAll?.[k]?.normalizeFunc || callBuiltin;
4095
+ return normalizeFunc(this, k, ...args);
4096
+ };
4097
+ }
4098
+ }
4099
+
4100
+ export { setBuiltinFuncs };
4101
+ //# sourceMappingURL=builtinfunc.js.map