@zephyr3d/device 0.2.3 → 0.2.5

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 (43) hide show
  1. package/README.md +1 -1
  2. package/dist/base_types.js +7 -66
  3. package/dist/base_types.js.map +1 -1
  4. package/dist/builder/ast.js +121 -118
  5. package/dist/builder/ast.js.map +1 -1
  6. package/dist/builder/base.js +29 -25
  7. package/dist/builder/base.js.map +1 -1
  8. package/dist/builder/builtinfunc.js +62 -19
  9. package/dist/builder/builtinfunc.js.map +1 -1
  10. package/dist/builder/constructors.js +1 -1
  11. package/dist/builder/constructors.js.map +1 -1
  12. package/dist/builder/errors.js +7 -7
  13. package/dist/builder/errors.js.map +1 -1
  14. package/dist/builder/misc.js +10 -0
  15. package/dist/builder/misc.js.map +1 -0
  16. package/dist/builder/programbuilder.js +65 -34
  17. package/dist/builder/programbuilder.js.map +1 -1
  18. package/dist/builder/reflection.js.map +1 -1
  19. package/dist/builder/types.js +74 -74
  20. package/dist/builder/types.js.map +1 -1
  21. package/dist/device.js +72 -43
  22. package/dist/device.js.map +1 -1
  23. package/dist/gpuobject.js +82 -24
  24. package/dist/gpuobject.js.map +1 -1
  25. package/dist/helpers/drawtext.js +1 -0
  26. package/dist/helpers/drawtext.js.map +1 -1
  27. package/dist/helpers/font.js +1 -0
  28. package/dist/helpers/font.js.map +1 -1
  29. package/dist/helpers/glyphmanager.js +7 -7
  30. package/dist/helpers/glyphmanager.js.map +1 -1
  31. package/dist/helpers/textureatlas.js +3 -5
  32. package/dist/helpers/textureatlas.js.map +1 -1
  33. package/dist/index.d.ts +267 -204
  34. package/dist/index.js +6 -5
  35. package/dist/index.js.map +1 -1
  36. package/dist/pool.js +102 -45
  37. package/dist/pool.js.map +1 -1
  38. package/dist/timer.js.map +1 -1
  39. package/dist/uniformdata.js +2 -2
  40. package/dist/uniformdata.js.map +1 -1
  41. package/dist/vertexdata.js +27 -1
  42. package/dist/vertexdata.js.map +1 -1
  43. package/package.json +31 -19
@@ -1,7 +1,9 @@
1
1
  import { ShaderType } from '../base_types.js';
2
2
  import { semanticToAttrib } from '../gpuobject.js';
3
- import { PBPrimitiveTypeInfo, PBPrimitiveType, PBTextureType, PBAddressSpace, PBPointerTypeInfo, typeBool, typeF32, typeI32, typeU32, typeVoid } from './types.js';
3
+ import { PBTextureType, PBPrimitiveTypeInfo, PBPrimitiveType, PBAddressSpace, PBPointerTypeInfo, typeBool, typeF32, typeI32, typeU32, typeVoid } from './types.js';
4
4
  import { PBASTError, PBTypeCastError, PBInternalError, PBParamTypeError } from './errors.js';
5
+ import { getCurrentProgramBuilder } from './misc.js';
6
+ import { ASSERT } from '@zephyr3d/base';
5
7
 
6
8
  const BuiltinInputStructNameVS = 'zVSInput';
7
9
  const BuiltinOutputStructNameVS = 'zVSOutput';
@@ -18,22 +20,22 @@ const BuiltinInputStructInstanceNameFS = 'zFSInputCpy';
18
20
  const BuiltinOutputStructInstanceNameFS = 'zFSOutputCpy';
19
21
  const BuiltinInputStructInstanceNameCS = 'zCSInputCpy';
20
22
  const BuiltinOutputStructInstanceNameCS = 'zCSOutputCpy';
21
- var DeclareType;
22
- (function(DeclareType) {
23
+ /** @internal */ var DeclareType = /*#__PURE__*/ function(DeclareType) {
23
24
  DeclareType[DeclareType["DECLARE_TYPE_NONE"] = 0] = "DECLARE_TYPE_NONE";
24
25
  DeclareType[DeclareType["DECLARE_TYPE_IN"] = 1] = "DECLARE_TYPE_IN";
25
26
  DeclareType[DeclareType["DECLARE_TYPE_OUT"] = 2] = "DECLARE_TYPE_OUT";
26
27
  DeclareType[DeclareType["DECLARE_TYPE_WORKGROUP"] = 3] = "DECLARE_TYPE_WORKGROUP";
27
28
  DeclareType[DeclareType["DECLARE_TYPE_UNIFORM"] = 4] = "DECLARE_TYPE_UNIFORM";
28
29
  DeclareType[DeclareType["DECLARE_TYPE_STORAGE"] = 5] = "DECLARE_TYPE_STORAGE";
29
- })(DeclareType || (DeclareType = {}));
30
- var ShaderPrecisionType;
31
- (function(ShaderPrecisionType) {
30
+ return DeclareType;
31
+ }({});
32
+ /** @internal */ var ShaderPrecisionType = /*#__PURE__*/ function(ShaderPrecisionType) {
32
33
  ShaderPrecisionType[ShaderPrecisionType["NONE"] = 0] = "NONE";
33
34
  ShaderPrecisionType[ShaderPrecisionType["HIGH"] = 1] = "HIGH";
34
35
  ShaderPrecisionType[ShaderPrecisionType["MEDIUM"] = 2] = "MEDIUM";
35
36
  ShaderPrecisionType[ShaderPrecisionType["LOW"] = 3] = "LOW";
36
- })(ShaderPrecisionType || (ShaderPrecisionType = {}));
37
+ return ShaderPrecisionType;
38
+ }({});
37
39
  /** @internal */ function getBuiltinParamName(shaderType) {
38
40
  switch(shaderType){
39
41
  case ShaderType.Vertex:
@@ -336,16 +338,16 @@ function unbracket(e) {
336
338
  getType() {
337
339
  return null;
338
340
  }
339
- toWebGL(indent, ctx) {
341
+ toWebGL(_indent, _ctx) {
340
342
  return '';
341
343
  }
342
- toWebGL2(indent, ctx) {
344
+ toWebGL2(_indent, _ctx) {
343
345
  return '';
344
346
  }
345
- toWGSL(indent, ctx) {
347
+ toWGSL(_indent, _ctx) {
346
348
  return '';
347
349
  }
348
- toString(deviceType) {
350
+ toString(_deviceType) {
349
351
  return this.constructor.name;
350
352
  }
351
353
  }
@@ -536,12 +538,12 @@ function unbracket(e) {
536
538
  }
537
539
  getAddressSpace() {
538
540
  switch(this.value.$declareType){
539
- case DeclareType.DECLARE_TYPE_UNIFORM:
541
+ case 4:
540
542
  return PBAddressSpace.UNIFORM;
541
- case DeclareType.DECLARE_TYPE_STORAGE:
543
+ case 5:
542
544
  return PBAddressSpace.STORAGE;
543
- case DeclareType.DECLARE_TYPE_IN:
544
- case DeclareType.DECLARE_TYPE_OUT:
545
+ case 1:
546
+ case 2:
545
547
  return null;
546
548
  default:
547
549
  return this.value.$global ? PBAddressSpace.PRIVATE : PBAddressSpace.FUNCTION;
@@ -550,24 +552,24 @@ function unbracket(e) {
550
552
  getType() {
551
553
  return this.value.$typeinfo;
552
554
  }
553
- toWebGL(indent, ctx) {
555
+ toWebGL(_indent, _ctx) {
554
556
  return this.name;
555
557
  }
556
- toWebGL2(indent, ctx) {
558
+ toWebGL2(_indent, _ctx) {
557
559
  return this.name;
558
560
  }
559
561
  toWGSL(indent, ctx) {
560
- if (this.value.$declareType === DeclareType.DECLARE_TYPE_IN) {
562
+ if (this.value.$declareType === 1) {
561
563
  const structName = getBuiltinInputStructInstanceName(ctx.type);
562
564
  return ctx.global[structName][this.name].$ast.toWGSL(indent, ctx);
563
- } else if (this.value.$declareType === DeclareType.DECLARE_TYPE_OUT) {
565
+ } else if (this.value.$declareType === 2) {
564
566
  const structName = getBuiltinOutputStructInstanceName(ctx.type);
565
567
  return ctx.global[structName][this.name].$ast.toWGSL(indent, ctx);
566
568
  } else {
567
569
  return this.name;
568
570
  }
569
571
  }
570
- toString(deviceType) {
572
+ toString(_deviceType) {
571
573
  return this.name;
572
574
  }
573
575
  }
@@ -704,13 +706,13 @@ function unbracket(e) {
704
706
  isReference() {
705
707
  return true;
706
708
  }
707
- toWebGL(indent, ctx) {
709
+ toWebGL(_indent, _ctx) {
708
710
  let prefix = '';
709
711
  switch(this.value.value.$declareType){
710
- case DeclareType.DECLARE_TYPE_IN:
711
- case DeclareType.DECLARE_TYPE_OUT:
712
- case DeclareType.DECLARE_TYPE_UNIFORM:
713
- case DeclareType.DECLARE_TYPE_STORAGE:
712
+ case 1:
713
+ case 2:
714
+ case 4:
715
+ case 5:
714
716
  throw new Error('invalid declare type');
715
717
  default:
716
718
  prefix = this.value.constExp && !this.value.isWritable() && !this.getType().isStructType() ? 'const ' : '';
@@ -720,13 +722,13 @@ function unbracket(e) {
720
722
  return `${prefix}${this.getType().toTypeName('webgl', this.value.name)}`;
721
723
  }
722
724
  }
723
- toWebGL2(indent, ctx) {
725
+ toWebGL2(_indent, _ctx) {
724
726
  let prefix = '';
725
727
  switch(this.value.value.$declareType){
726
- case DeclareType.DECLARE_TYPE_IN:
727
- case DeclareType.DECLARE_TYPE_OUT:
728
- case DeclareType.DECLARE_TYPE_UNIFORM:
729
- case DeclareType.DECLARE_TYPE_STORAGE:
728
+ case 1:
729
+ case 2:
730
+ case 4:
731
+ case 5:
730
732
  throw new Error('invalid declare type');
731
733
  default:
732
734
  prefix = this.value.constExp && !this.value.isWritable() && !this.getType().isStructType() ? 'const ' : '';
@@ -736,13 +738,13 @@ function unbracket(e) {
736
738
  return `${prefix}${this.getType().toTypeName('webgl2', this.value.name)}`;
737
739
  }
738
740
  }
739
- toWGSL(indent, ctx) {
741
+ toWGSL(_indent, _ctx) {
740
742
  let prefix;
741
743
  switch(this.value.value.$declareType){
742
- case DeclareType.DECLARE_TYPE_IN:
743
- case DeclareType.DECLARE_TYPE_OUT:
744
- case DeclareType.DECLARE_TYPE_UNIFORM:
745
- case DeclareType.DECLARE_TYPE_STORAGE:
744
+ case 1:
745
+ case 2:
746
+ case 4:
747
+ case 5:
746
748
  throw new Error('invalid declare type');
747
749
  default:
748
750
  {
@@ -773,11 +775,12 @@ function unbracket(e) {
773
775
  /** @internal */ type;
774
776
  /** @internal */ args;
775
777
  /** @internal */ constExp;
778
+ /** @internal */ convertedArgs;
776
779
  constructor(type, args){
777
780
  super();
778
781
  this.type = type;
779
782
  this.args = args;
780
- this.constExp = true;
783
+ this.convertedArgs = null;
781
784
  for (const arg of args){
782
785
  if (arg === null || arg === undefined) {
783
786
  throw new Error('invalid constructor argument');
@@ -787,6 +790,17 @@ function unbracket(e) {
787
790
  }
788
791
  this.constExp &&= !(arg instanceof ASTExpression) || arg.isConstExp();
789
792
  }
793
+ const deviceType = getCurrentProgramBuilder().getDevice().type;
794
+ const overloads = this.type.getConstructorOverloads(deviceType);
795
+ for (const overload of overloads){
796
+ this.convertedArgs = convertArgs(this.args, overload);
797
+ if (this.convertedArgs) {
798
+ break;
799
+ }
800
+ }
801
+ if (!this.convertedArgs) {
802
+ throw new Error(`no matching overload function found for type ${this.type.toTypeName(deviceType)}`);
803
+ }
790
804
  }
791
805
  getType() {
792
806
  return this.type;
@@ -802,48 +816,18 @@ function unbracket(e) {
802
816
  return null;
803
817
  }
804
818
  toWebGL(indent, ctx) {
805
- console.assert(!this.type.isArrayType(), 'array constructor not supported in webgl1 device');
806
- console.assert(this.type.isConstructible(), `type '${this.type.toTypeName('webgl')}' is not constructible`);
807
- const overloads = this.type.getConstructorOverloads('webgl');
808
- for (const overload of overloads){
809
- const convertedArgs = convertArgs(this.args, overload);
810
- if (convertedArgs) {
811
- const c = convertedArgs.args.map((arg)=>unbracket(arg.toWebGL(indent, ctx))).join(',');
812
- return `${convertedArgs.name}(${c})`;
813
- }
814
- }
815
- throw new Error(`no matching overload function found for type ${this.type.toTypeName('webgl')}`);
819
+ const c = this.convertedArgs.args.map((arg)=>unbracket(arg.toWebGL(indent, ctx))).join(',');
820
+ return `${this.convertedArgs.name}(${c})`;
816
821
  }
817
822
  toWebGL2(indent, ctx) {
818
- console.assert(this.type.isConstructible(), `type '${this.type.toTypeName('webgl2')}' is not constructible`, true);
819
- const overloads = this.type.getConstructorOverloads('webgl2');
820
- for (const overload of overloads){
821
- const convertedArgs = convertArgs(this.args, overload);
822
- if (convertedArgs) {
823
- const c = convertedArgs.args.map((arg)=>unbracket(arg.toWebGL2(indent, ctx))).join(',');
824
- return `${convertedArgs.name}(${c})`;
825
- }
826
- }
827
- throw new Error(`no matching overload function found for type ${this.type.toTypeName('webgl2')}`);
823
+ const c = this.convertedArgs.args.map((arg)=>unbracket(arg.toWebGL2(indent, ctx))).join(',');
824
+ return `${this.convertedArgs.name}(${c})`;
828
825
  }
829
826
  toWGSL(indent, ctx) {
830
- /*
831
- console.assert(
832
- this.type.isConstructible(),
833
- `type '${this.type.toTypeName('webgpu')}' is not constructible`,
834
- true
835
- );
836
- */ const overloads = this.type.getConstructorOverloads('webgpu');
837
- for (const overload of overloads){
838
- const convertedArgs = convertArgs(this.args, overload);
839
- if (convertedArgs) {
840
- const c = convertedArgs.args.map((arg)=>unbracket(arg.toWGSL(indent, ctx))).join(',');
841
- return `${convertedArgs.name}(${c})`;
842
- }
843
- }
844
- throw new Error(`no matching overload function found for type ${this.type.toTypeName('webgpu')}`);
827
+ const c = this.convertedArgs.args.map((arg)=>unbracket(arg.toWGSL(indent, ctx))).join(',');
828
+ return `${this.convertedArgs.name}(${c})`;
845
829
  }
846
- toString(deviceType) {
830
+ toString(_deviceType) {
847
831
  return 'constructor';
848
832
  }
849
833
  }
@@ -881,21 +865,21 @@ function unbracket(e) {
881
865
  getAddressSpace() {
882
866
  return null;
883
867
  }
884
- toWebGL(indent, ctx) {
868
+ toWebGL(_indent, _ctx) {
885
869
  switch(this.type.primitiveType){
886
870
  case PBPrimitiveType.F32:
887
871
  return toFixed(this.value);
888
872
  case PBPrimitiveType.I32:
889
873
  return toInt(this.value);
890
874
  case PBPrimitiveType.U32:
891
- return toUint(this.value);
875
+ return `${toUint(this.value)}u`;
892
876
  case PBPrimitiveType.BOOL:
893
877
  return String(!!this.value);
894
878
  default:
895
879
  throw new Error('Invalid scalar type');
896
880
  }
897
881
  }
898
- toWebGL2(indent, ctx) {
882
+ toWebGL2(_indent, _ctx) {
899
883
  switch(this.type.primitiveType){
900
884
  case PBPrimitiveType.F32:
901
885
  return toFixed(this.value);
@@ -909,7 +893,7 @@ function unbracket(e) {
909
893
  throw new Error('Invalid scalar type');
910
894
  }
911
895
  }
912
- toWGSL(indent, ctx) {
896
+ toWGSL(_indent, _ctx) {
913
897
  switch(this.type.primitiveType){
914
898
  case PBPrimitiveType.F32:
915
899
  return toFixed(this.value);
@@ -923,7 +907,7 @@ function unbracket(e) {
923
907
  throw new Error('Invalid scalar type');
924
908
  }
925
909
  }
926
- toString(deviceType) {
910
+ toString(_deviceType) {
927
911
  return `${this.value}`;
928
912
  }
929
913
  }
@@ -959,14 +943,14 @@ function unbracket(e) {
959
943
  return this.source.getAddressSpace();
960
944
  }
961
945
  toWebGL(indent, ctx) {
962
- return `${this.source.toWebGL(indent, ctx)}.${this.field}`;
946
+ return this.source instanceof ASTScalar ? `(${this.source.toWebGL(indent, ctx)}).${this.field}` : `${this.source.toWebGL(indent, ctx)}.${this.field}`;
963
947
  }
964
948
  toWebGL2(indent, ctx) {
965
- return `${this.source.toWebGL2(indent, ctx)}.${this.field}`;
949
+ return this.source instanceof ASTScalar ? `(${this.source.toWebGL(indent, ctx)}).${this.field}` : `${this.source.toWebGL(indent, ctx)}.${this.field}`;
966
950
  }
967
951
  toWGSL(indent, ctx) {
968
952
  const source = this.source.isPointer() ? new ASTReferenceOf(this.source) : this.source;
969
- return `${source.toWGSL(indent, ctx)}.${this.field}`;
953
+ return source instanceof ASTScalar ? `(${source.toWGSL(indent, ctx)}).${this.field}` : `${source.toWGSL(indent, ctx)}.${this.field}`;
970
954
  }
971
955
  toString(deviceType) {
972
956
  const source = this.source.isPointer() ? new ASTReferenceOf(this.source) : this.source;
@@ -1027,7 +1011,7 @@ function unbracket(e) {
1027
1011
  /** @internal */ type;
1028
1012
  constructor(value){
1029
1013
  super();
1030
- console.assert(value.isReference(), 'no pointer type for non-reference values', true);
1014
+ ASSERT(value.isReference(), 'no pointer type for non-reference values');
1031
1015
  this.value = value;
1032
1016
  this.type = new PBPointerTypeInfo(value.getType(), value.getAddressSpace());
1033
1017
  }
@@ -1050,10 +1034,10 @@ function unbracket(e) {
1050
1034
  getAddressSpace() {
1051
1035
  return this.value.getAddressSpace();
1052
1036
  }
1053
- toWebGL(indent, ctx) {
1037
+ toWebGL(_indent, _ctx) {
1054
1038
  throw new Error('GLSL does not support pointer type');
1055
1039
  }
1056
- toWebGL2(indent, ctx) {
1040
+ toWebGL2(_indent, _ctx) {
1057
1041
  throw new Error('GLSL does not support pointer type');
1058
1042
  }
1059
1043
  toWGSL(indent, ctx) {
@@ -1275,6 +1259,15 @@ function unbracket(e) {
1275
1259
  /** @internal */ type;
1276
1260
  constructor(condition, first, second){
1277
1261
  super();
1262
+ if (condition instanceof ASTCallFunction) {
1263
+ condition.isStatement = false;
1264
+ }
1265
+ if (first instanceof ASTCallFunction) {
1266
+ first.isStatement = false;
1267
+ }
1268
+ if (second instanceof ASTCallFunction) {
1269
+ second.isStatement = false;
1270
+ }
1278
1271
  this.condition = condition instanceof ASTExpression ? condition : new ASTScalar(condition, typeBool);
1279
1272
  let firstType = null;
1280
1273
  let secondType = null;
@@ -1398,6 +1391,14 @@ function unbracket(e) {
1398
1391
  if (this.rvalue instanceof ASTCallFunction) {
1399
1392
  this.rvalue.isStatement = false;
1400
1393
  }
1394
+ const ltype = this.lvalue.getType();
1395
+ const valueTypeLeft = ltype.isPointerType() ? ltype.pointerType : ltype;
1396
+ const rtype = this.checkScalarType(this.rvalue, valueTypeLeft);
1397
+ const rvalueIsPtr = rtype && rtype.isPointerType();
1398
+ const valueTypeRight = rvalueIsPtr ? rtype.pointerType : rtype;
1399
+ if (!valueTypeLeft.isCompatibleType(valueTypeRight)) {
1400
+ throw new PBTypeCastError(this.rvalue instanceof ASTExpression ? this.rvalue.toString(rtype.isPointerType() ? 'webgpu' : 'webgl') : `${this.rvalue}`, rtype, ltype);
1401
+ }
1401
1402
  }
1402
1403
  getType() {
1403
1404
  return null;
@@ -1503,35 +1504,35 @@ function unbracket(e) {
1503
1504
  }
1504
1505
  }
1505
1506
  /** @internal */ class ASTDiscard extends ShaderAST {
1506
- toWebGL(indent, ctx) {
1507
+ toWebGL(indent, _ctx) {
1507
1508
  return `${indent}discard;\n`;
1508
1509
  }
1509
- toWebGL2(indent, ctx) {
1510
+ toWebGL2(indent, _ctx) {
1510
1511
  return `${indent}discard;\n`;
1511
1512
  }
1512
- toWGSL(indent, ctx) {
1513
+ toWGSL(indent, _ctx) {
1513
1514
  return `${indent}discard;\n`;
1514
1515
  }
1515
1516
  }
1516
1517
  /** @internal */ class ASTBreak extends ShaderAST {
1517
- toWebGL(indent, ctx) {
1518
+ toWebGL(indent, _ctx) {
1518
1519
  return `${indent}break;\n`;
1519
1520
  }
1520
- toWebGL2(indent, ctx) {
1521
+ toWebGL2(indent, _ctx) {
1521
1522
  return `${indent}break;\n`;
1522
1523
  }
1523
- toWGSL(indent, ctx) {
1524
+ toWGSL(indent, _ctx) {
1524
1525
  return `${indent}break;\n`;
1525
1526
  }
1526
1527
  }
1527
1528
  /** @internal */ class ASTContinue extends ShaderAST {
1528
- toWebGL(indent, ctx) {
1529
+ toWebGL(indent, _ctx) {
1529
1530
  return `${indent}continue;\n`;
1530
1531
  }
1531
- toWebGL2(indent, ctx) {
1532
+ toWebGL2(indent, _ctx) {
1532
1533
  return `${indent}continue;\n`;
1533
1534
  }
1534
- toWGSL(indent, ctx) {
1535
+ toWGSL(indent, _ctx) {
1535
1536
  return `${indent}continue;\n`;
1536
1537
  }
1537
1538
  }
@@ -1647,7 +1648,7 @@ function unbracket(e) {
1647
1648
  const args = thisArgs.map((arg)=>unbracket(arg.toWGSL(indent, ctx)));
1648
1649
  return `${this.isStatement ? indent : ''}${this.name}(${args.join(',')})${this.isStatement ? ';\n' : ''}`;
1649
1650
  }
1650
- toString(deviceType) {
1651
+ toString(_deviceType) {
1651
1652
  return `${this.name}(...)`;
1652
1653
  }
1653
1654
  }
@@ -1673,7 +1674,7 @@ function unbracket(e) {
1673
1674
  let builtin = false;
1674
1675
  let valueType = this.value.getType();
1675
1676
  switch(this.value.value.$declareType){
1676
- case DeclareType.DECLARE_TYPE_IN:
1677
+ case 1:
1677
1678
  if (ctx.type === ShaderType.Vertex) {
1678
1679
  prefix = 'attribute ';
1679
1680
  ctx.defines.push(`#define ${this.value.name} ${semanticToAttrib(ctx.vertexAttributes[this.value.value.$location])}\n`);
@@ -1682,7 +1683,7 @@ function unbracket(e) {
1682
1683
  // ctx.defines.push(`#define ${this.value.$str} ch_varying_${this.value.$location}\n`);
1683
1684
  }
1684
1685
  break;
1685
- case DeclareType.DECLARE_TYPE_OUT:
1686
+ case 2:
1686
1687
  if (ctx.type === ShaderType.Vertex) {
1687
1688
  prefix = 'varying ';
1688
1689
  // ctx.defines.push(`#define ${this.value.$str} ch_varying_${this.value.$location}\n`);
@@ -1696,11 +1697,11 @@ function unbracket(e) {
1696
1697
  }
1697
1698
  }
1698
1699
  break;
1699
- case DeclareType.DECLARE_TYPE_UNIFORM:
1700
+ case 4:
1700
1701
  prefix = 'uniform ';
1701
1702
  valueType = ctx.typeReplacement?.get(this.value.value) || valueType;
1702
1703
  break;
1703
- case DeclareType.DECLARE_TYPE_STORAGE:
1704
+ case 5:
1704
1705
  throw new Error(`invalid variable declare type: ${this.value.name}`);
1705
1706
  }
1706
1707
  if (!builtin) {
@@ -1711,7 +1712,7 @@ function unbracket(e) {
1711
1712
  let prefix = '';
1712
1713
  let valueType = this.value.getType();
1713
1714
  switch(this.value.value.$declareType){
1714
- case DeclareType.DECLARE_TYPE_IN:
1715
+ case 1:
1715
1716
  if (ctx.type === ShaderType.Fragment && valueType.isPrimitiveType() && valueType.isInteger()) {
1716
1717
  prefix = 'flat in ';
1717
1718
  } else {
@@ -1721,7 +1722,7 @@ function unbracket(e) {
1721
1722
  ctx.defines.push(`#define ${this.value.name} ${semanticToAttrib(ctx.vertexAttributes[this.value.value.$location])}\n`);
1722
1723
  }
1723
1724
  break;
1724
- case DeclareType.DECLARE_TYPE_OUT:
1725
+ case 2:
1725
1726
  if (ctx.type === ShaderType.Vertex) {
1726
1727
  if (valueType.isPrimitiveType() && valueType.isInteger()) {
1727
1728
  prefix = 'flat out ';
@@ -1732,7 +1733,7 @@ function unbracket(e) {
1732
1733
  prefix = `layout(location = ${this.value.value.$location}) out `;
1733
1734
  }
1734
1735
  break;
1735
- case DeclareType.DECLARE_TYPE_UNIFORM:
1736
+ case 4:
1736
1737
  if (valueType.isStructType()) {
1737
1738
  /*
1738
1739
  if (valueType.layout !== 'std140') {
@@ -1743,7 +1744,7 @@ function unbracket(e) {
1743
1744
  valueType = ctx.typeReplacement?.get(this.value.value) || valueType;
1744
1745
  return `${indent}uniform ${valueType.toTypeName('webgl2', this.value.name)};\n`;
1745
1746
  }
1746
- case DeclareType.DECLARE_TYPE_STORAGE:
1747
+ case 5:
1747
1748
  throw new Error(`invalid variable declare type: ${this.value.name}`);
1748
1749
  }
1749
1750
  {
@@ -1754,18 +1755,18 @@ function unbracket(e) {
1754
1755
  let prefix;
1755
1756
  const isBlock = this.value.getType().isPrimitiveType() || this.value.getType().isStructType() || this.value.getType().isArrayType();
1756
1757
  switch(this.value.value.$declareType){
1757
- case DeclareType.DECLARE_TYPE_IN:
1758
- case DeclareType.DECLARE_TYPE_OUT:
1758
+ case 1:
1759
+ case 2:
1759
1760
  // prefix = `@location(${this.value.value.$location}) var<out> `;
1760
1761
  throw new Error(`Internal error`);
1761
- case DeclareType.DECLARE_TYPE_UNIFORM:
1762
+ case 4:
1762
1763
  prefix = `@group(${this.group}) @binding(${this.binding}) var${isBlock ? '<uniform>' : ''} `;
1763
1764
  break;
1764
- case DeclareType.DECLARE_TYPE_STORAGE:
1765
+ case 5:
1765
1766
  prefix = `@group(${this.group}) @binding(${this.binding}) var<storage, ${this.value.value.$readonly ? 'read' : 'read_write' //this.value.isWritable() || this.value.getType().haveAtomicMembers() ? 'read_write' : 'read'
1766
1767
  }> `;
1767
1768
  break;
1768
- case DeclareType.DECLARE_TYPE_WORKGROUP:
1769
+ case 3:
1769
1770
  prefix = `var<workgroup> `;
1770
1771
  break;
1771
1772
  default:
@@ -1943,12 +1944,14 @@ function unbracket(e) {
1943
1944
  /** @internal */ start;
1944
1945
  /** @internal */ end;
1945
1946
  /** @internal */ open;
1946
- constructor(init, start, end, open){
1947
+ /** @internal */ reverse;
1948
+ constructor(init, start, end, open, reverse){
1947
1949
  super();
1948
1950
  this.init = init;
1949
1951
  this.start = start;
1950
1952
  this.end = end;
1951
1953
  this.open = open;
1954
+ this.reverse = reverse;
1952
1955
  this.statements = [];
1953
1956
  if (this.start instanceof ASTCallFunction) {
1954
1957
  this.start.isStatement = false;
@@ -1961,8 +1964,8 @@ function unbracket(e) {
1961
1964
  const init = this.init.getType().toTypeName('webgl', this.init.name);
1962
1965
  const start = unbracket(this.start.toWebGL(indent, ctx));
1963
1966
  const end = unbracket(this.end.toWebGL(indent, ctx));
1964
- const comp = this.open ? '<' : '<=';
1965
- let str = `${indent}for (${init} = ${start}; ${this.init.name} ${comp} ${end}; ${this.init.name}++) {\n`;
1967
+ const comp = this.open ? this.reverse ? '>' : '<' : this.reverse ? '>=' : '<=';
1968
+ let str = `${indent}for (${init} = ${start}; ${this.init.name} ${comp} ${end}; ${this.init.name}${this.reverse ? '--' : '++'}) {\n`;
1966
1969
  str += super.toWebGL(indent + ' ', ctx);
1967
1970
  str += `${indent}}\n`;
1968
1971
  return str;
@@ -1971,8 +1974,8 @@ function unbracket(e) {
1971
1974
  const init = this.init.getType().toTypeName('webgl2', this.init.name);
1972
1975
  const start = unbracket(this.start.toWebGL2(indent, ctx));
1973
1976
  const end = unbracket(this.end.toWebGL2(indent, ctx));
1974
- const comp = this.open ? '<' : '<=';
1975
- let str = `${indent}for (${init} = ${start}; ${this.init.name} ${comp} ${end}; ${this.init.name}++) {\n`;
1977
+ const comp = this.open ? this.reverse ? '>' : '<' : this.reverse ? '>=' : '<=';
1978
+ let str = `${indent}for (${init} = ${start}; ${this.init.name} ${comp} ${end}; ${this.init.name}${this.reverse ? '--' : '++'}) {\n`;
1976
1979
  str += super.toWebGL2(indent + ' ', ctx);
1977
1980
  str += `${indent}}\n`;
1978
1981
  return str;
@@ -1982,8 +1985,8 @@ function unbracket(e) {
1982
1985
  const start = unbracket(this.start.toWGSL(indent, ctx));
1983
1986
  const end = unbracket(this.end.toWGSL(indent, ctx));
1984
1987
  const incr = new ASTScalar(1, this.init.getType()).toWGSL(indent, ctx);
1985
- const comp = this.open ? '<' : '<=';
1986
- let str = `${indent}for (${init} = ${start}; ${this.init.name} ${comp} ${end}; ${this.init.name} = ${this.init.name} + ${incr}) {\n`;
1988
+ const comp = this.open ? this.reverse ? '> ' : '<' : this.reverse ? '>=' : '<=';
1989
+ let str = `${indent}for (${init} = ${start}; ${this.init.name} ${comp} ${end}; ${this.init.name} = ${this.init.name} ${this.reverse ? '-' : '+'} ${incr}) {\n`;
1987
1990
  str += super.toWGSL(indent + ' ', ctx);
1988
1991
  str += `${indent}}\n`;
1989
1992
  return str;
@@ -1998,7 +2001,7 @@ function unbracket(e) {
1998
2001
  this.condition.isStatement = false;
1999
2002
  }
2000
2003
  }
2001
- toWebGL(indent, ctx) {
2004
+ toWebGL(_indent, _ctx) {
2002
2005
  throw new Error(`No do-while() loop support for WebGL1.0 device`);
2003
2006
  }
2004
2007
  toWebGL2(indent, ctx) {
@@ -2065,7 +2068,7 @@ function unbracket(e) {
2065
2068
  getType() {
2066
2069
  return this.type;
2067
2070
  }
2068
- toWebGL(indent, ctx) {
2071
+ toWebGL(indent, _ctx) {
2069
2072
  if (!this.builtin) {
2070
2073
  let str = `${indent}struct ${this.type.structName} {\n`;
2071
2074
  for (const arg of this.type.structMembers){
@@ -2077,7 +2080,7 @@ function unbracket(e) {
2077
2080
  return '';
2078
2081
  }
2079
2082
  }
2080
- toWebGL2(indent, ctx) {
2083
+ toWebGL2(indent, _ctx) {
2081
2084
  if (!this.builtin) {
2082
2085
  let str = `${indent}struct ${this.type.structName} {\n`;
2083
2086
  for (const arg of this.type.structMembers){
@@ -2089,7 +2092,7 @@ function unbracket(e) {
2089
2092
  return '';
2090
2093
  }
2091
2094
  }
2092
- toWGSL(indent, ctx) {
2095
+ toWGSL(indent, _ctx) {
2093
2096
  if (!this.builtin) {
2094
2097
  let str = `${indent}struct ${this.type.structName} {\n`;
2095
2098
  str += this.type.structMembers.map((arg, i)=>{