@zephyr3d/device 0.2.5 → 0.2.6

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 (41) hide show
  1. package/dist/base_types.js +12 -13
  2. package/dist/base_types.js.map +1 -1
  3. package/dist/builder/ast.js +34 -48
  4. package/dist/builder/ast.js.map +1 -1
  5. package/dist/builder/base.js +6 -2
  6. package/dist/builder/base.js.map +1 -1
  7. package/dist/builder/builtinfunc.js +42 -6
  8. package/dist/builder/builtinfunc.js.map +1 -1
  9. package/dist/builder/constructors.js +2 -0
  10. package/dist/builder/constructors.js.map +1 -1
  11. package/dist/builder/errors.js +4 -4
  12. package/dist/builder/errors.js.map +1 -1
  13. package/dist/builder/misc.js +1 -1
  14. package/dist/builder/misc.js.map +1 -1
  15. package/dist/builder/programbuilder.js +18 -27
  16. package/dist/builder/programbuilder.js.map +1 -1
  17. package/dist/builder/reflection.js +1 -1
  18. package/dist/builder/reflection.js.map +1 -1
  19. package/dist/builder/types.js +7 -6
  20. package/dist/builder/types.js.map +1 -1
  21. package/dist/device.js +150 -39
  22. package/dist/device.js.map +1 -1
  23. package/dist/gpuobject.js +2 -1
  24. package/dist/gpuobject.js.map +1 -1
  25. package/dist/helpers/drawtext.js +29 -25
  26. package/dist/helpers/drawtext.js.map +1 -1
  27. package/dist/helpers/font.js.map +1 -1
  28. package/dist/helpers/glyphmanager.js +26 -8
  29. package/dist/helpers/glyphmanager.js.map +1 -1
  30. package/dist/helpers/textureatlas.js +7 -3
  31. package/dist/helpers/textureatlas.js.map +1 -1
  32. package/dist/index.d.ts +290 -266
  33. package/dist/pool.js +15 -6
  34. package/dist/pool.js.map +1 -1
  35. package/dist/timer.js +3 -2
  36. package/dist/timer.js.map +1 -1
  37. package/dist/uniformdata.js +1 -1
  38. package/dist/uniformdata.js.map +1 -1
  39. package/dist/vertexdata.js +2 -2
  40. package/dist/vertexdata.js.map +1 -1
  41. package/package.json +80 -80
@@ -45,7 +45,7 @@ const BuiltinOutputStructInstanceNameCS = 'zCSOutputCpy';
45
45
  case ShaderType.Compute:
46
46
  return BuiltinParamNameCS;
47
47
  default:
48
- return null;
48
+ throw new Error(`Invalid shader type: ${shaderType}`);
49
49
  }
50
50
  }
51
51
  /** @internal */ function getBuiltinInputStructInstanceName(shaderType) {
@@ -57,7 +57,7 @@ const BuiltinOutputStructInstanceNameCS = 'zCSOutputCpy';
57
57
  case ShaderType.Compute:
58
58
  return BuiltinInputStructInstanceNameCS;
59
59
  default:
60
- return null;
60
+ throw new Error(`Invalid shader type: ${shaderType}`);
61
61
  }
62
62
  }
63
63
  /** @internal */ function getBuiltinOutputStructInstanceName(shaderType) {
@@ -69,7 +69,7 @@ const BuiltinOutputStructInstanceNameCS = 'zCSOutputCpy';
69
69
  case ShaderType.Compute:
70
70
  return BuiltinOutputStructInstanceNameCS;
71
71
  default:
72
- return null;
72
+ throw new Error(`Invalid shader type: ${shaderType}`);
73
73
  }
74
74
  }
75
75
  /** @internal */ function getBuiltinInputStructName(shaderType) {
@@ -81,7 +81,7 @@ const BuiltinOutputStructInstanceNameCS = 'zCSOutputCpy';
81
81
  case ShaderType.Compute:
82
82
  return BuiltinInputStructNameCS;
83
83
  default:
84
- return null;
84
+ throw new Error(`Invalid shader type: ${shaderType}`);
85
85
  }
86
86
  }
87
87
  /** @internal */ function getBuiltinOutputStructName(shaderType) {
@@ -93,7 +93,7 @@ const BuiltinOutputStructInstanceNameCS = 'zCSOutputCpy';
93
93
  case ShaderType.Compute:
94
94
  return BuiltinOutputStructNameCS;
95
95
  default:
96
- return null;
96
+ throw new Error(`Invalid shader type: ${shaderType}`);
97
97
  }
98
98
  }
99
99
  /** @internal */ function getTextureSampleType(type) {
@@ -126,7 +126,7 @@ const BuiltinOutputStructInstanceNameCS = 'zCSOutputCpy';
126
126
  case PBTextureType.UTEX_CUBE:
127
127
  return new PBPrimitiveTypeInfo(PBPrimitiveType.U32);
128
128
  default:
129
- return null;
129
+ throw new Error(`Invalid texture type: ${type}`);
130
130
  }
131
131
  }
132
132
  /** @internal */ function genSamplerName(textureName, comparison) {
@@ -448,7 +448,7 @@ function unbracket(e) {
448
448
  const body = ctx.types.map((val)=>val.toWebGL(indent, ctx)).join('') + this.uniforms.map((uniform)=>uniform.toWebGL(indent, ctx)).join('') + ctx.inputs.map((input)=>input.toWebGL(indent, ctx)).join('') + ctx.outputs.map((output)=>output.toWebGL(indent, ctx)).join('') + super.toWebGL(indent, ctx);
449
449
  for (const k of ctx.builtins){
450
450
  const info = builtinVariables.webgl[k];
451
- if (info.extension) {
451
+ if ('extension' in info) {
452
452
  ctx.extensions.add(info.extension);
453
453
  }
454
454
  }
@@ -464,7 +464,7 @@ function unbracket(e) {
464
464
  const body = ctx.types.map((val)=>val.toWebGL2(indent, ctx)).join('') + this.uniforms.map((uniform)=>uniform.toWebGL2(indent, ctx)).join('') + ctx.inputs.map((input)=>input.toWebGL2(indent, ctx)).join('') + ctx.outputs.map((output)=>output.toWebGL2(indent, ctx)).join('') + super.toWebGL2(indent, ctx);
465
465
  for (const k of ctx.builtins){
466
466
  const info = builtinVariables.webgl2[k];
467
- if (info.extension) {
467
+ if ('extension' in info) {
468
468
  ctx.extensions.add(info.extension);
469
469
  }
470
470
  }
@@ -493,7 +493,7 @@ function unbracket(e) {
493
493
  if (type instanceof ASTStructDefine && structNames.indexOf(type.type.structName) >= 0) {
494
494
  for(let i = type.type.structMembers.length - 1; i >= 0; i--){
495
495
  const member = type.type.structMembers[i];
496
- if (allBuiltins.indexOf(member.name) >= 0 && usedBuiltins.indexOf(member.name) < 0) {
496
+ if ('name' in member && allBuiltins.indexOf(member.name) >= 0 && usedBuiltins.indexOf(member.name) < 0) {
497
497
  type.type.structMembers.splice(i, 1);
498
498
  type.prefix.splice(i, 1);
499
499
  }
@@ -718,9 +718,7 @@ function unbracket(e) {
718
718
  prefix = this.value.constExp && !this.value.isWritable() && !this.getType().isStructType() ? 'const ' : '';
719
719
  break;
720
720
  }
721
- {
722
- return `${prefix}${this.getType().toTypeName('webgl', this.value.name)}`;
723
- }
721
+ return `${prefix}${this.getType().toTypeName('webgl', this.value.name)}`;
724
722
  }
725
723
  toWebGL2(_indent, _ctx) {
726
724
  let prefix = '';
@@ -734,9 +732,7 @@ function unbracket(e) {
734
732
  prefix = this.value.constExp && !this.value.isWritable() && !this.getType().isStructType() ? 'const ' : '';
735
733
  break;
736
734
  }
737
- {
738
- return `${prefix}${this.getType().toTypeName('webgl2', this.value.name)}`;
739
- }
735
+ return `${prefix}${this.getType().toTypeName('webgl2', this.value.name)}`;
740
736
  }
741
737
  toWGSL(_indent, _ctx) {
742
738
  let prefix;
@@ -757,15 +753,13 @@ function unbracket(e) {
757
753
  break;
758
754
  }
759
755
  }
760
- {
761
- // const decl = this.value.value.$global ? this.getType().toTypeName('webgpu', this.value.name) : this.value.name;
762
- const type = this.getType();
763
- if (type.isPointerType() && (this.value.isWritable() || this.value.ref.isWritable())) {
764
- type.writable = true;
765
- }
766
- const decl = type.toTypeName('webgpu', this.value.name);
767
- return `${prefix}${decl}`;
756
+ // const decl = this.value.value.$global ? this.getType().toTypeName('webgpu', this.value.name) : this.value.name;
757
+ const type = this.getType();
758
+ if (type.isPointerType() && (this.value.isWritable() || this.value.ref.isWritable())) {
759
+ type.writable = true;
768
760
  }
761
+ const decl = type.toTypeName('webgpu', this.value.name);
762
+ return `${prefix}${decl}`;
769
763
  }
770
764
  toString(deviceType) {
771
765
  return this.value.toString(deviceType);
@@ -780,7 +774,7 @@ function unbracket(e) {
780
774
  super();
781
775
  this.type = type;
782
776
  this.args = args;
783
- this.convertedArgs = null;
777
+ this.constExp = true;
784
778
  for (const arg of args){
785
779
  if (arg === null || arg === undefined) {
786
780
  throw new Error('invalid constructor argument');
@@ -793,8 +787,9 @@ function unbracket(e) {
793
787
  const deviceType = getCurrentProgramBuilder().getDevice().type;
794
788
  const overloads = this.type.getConstructorOverloads(deviceType);
795
789
  for (const overload of overloads){
796
- this.convertedArgs = convertArgs(this.args, overload);
797
- if (this.convertedArgs) {
790
+ const convertedArgs = convertArgs(this.args, overload);
791
+ if (convertedArgs) {
792
+ this.convertedArgs = convertedArgs;
798
793
  break;
799
794
  }
800
795
  }
@@ -1404,7 +1399,7 @@ function unbracket(e) {
1404
1399
  return null;
1405
1400
  }
1406
1401
  toWebGL(indent, ctx) {
1407
- let rhs = null;
1402
+ let rhs;
1408
1403
  const ltype = this.lvalue.getType();
1409
1404
  const rtype = this.checkScalarType(this.rvalue, ltype);
1410
1405
  if (!ltype.isCompatibleType(rtype)) {
@@ -1421,7 +1416,7 @@ function unbracket(e) {
1421
1416
  return `${indent}${this.lvalue.toWebGL(indent, ctx)} = ${rhs};\n`;
1422
1417
  }
1423
1418
  toWebGL2(indent, ctx) {
1424
- let rhs = null;
1419
+ let rhs;
1425
1420
  const ltype = this.lvalue.getType();
1426
1421
  const rtype = this.checkScalarType(this.rvalue, ltype);
1427
1422
  if (!ltype.isCompatibleType(rtype)) {
@@ -1629,7 +1624,7 @@ function unbracket(e) {
1629
1624
  toWGSL(indent, ctx) {
1630
1625
  let thisArgs = this.args;
1631
1626
  if (this.func) {
1632
- let argsNew;
1627
+ let argsNew = null;
1633
1628
  const convertedArgs = convertArgs(thisArgs, this.func.funcType);
1634
1629
  if (convertedArgs) {
1635
1630
  argsNew = convertedArgs.args;
@@ -1662,6 +1657,7 @@ function unbracket(e) {
1662
1657
  this.value = exp;
1663
1658
  this.group = 0;
1664
1659
  this.binding = 0;
1660
+ this.blockName = '';
1665
1661
  }
1666
1662
  isReference() {
1667
1663
  return true;
@@ -1707,6 +1703,7 @@ function unbracket(e) {
1707
1703
  if (!builtin) {
1708
1704
  return `${indent}${prefix}${valueType.toTypeName('webgl', this.value.name)};\n`;
1709
1705
  }
1706
+ return '';
1710
1707
  }
1711
1708
  toWebGL2(indent, ctx) {
1712
1709
  let prefix = '';
@@ -1747,9 +1744,7 @@ function unbracket(e) {
1747
1744
  case 5:
1748
1745
  throw new Error(`invalid variable declare type: ${this.value.name}`);
1749
1746
  }
1750
- {
1751
- return `${indent}${prefix}${this.value.getType().toTypeName('webgl2', this.value.name)};\n`;
1752
- }
1747
+ return `${indent}${prefix}${this.value.getType().toTypeName('webgl2', this.value.name)};\n`;
1753
1748
  }
1754
1749
  toWGSL(indent, ctx) {
1755
1750
  let prefix;
@@ -1772,14 +1767,12 @@ function unbracket(e) {
1772
1767
  default:
1773
1768
  prefix = `${this.value.getType().isPointerType() ? 'let' : 'var'}${this.value.value.$global && !this.value.getType().isPointerType() ? '<private>' : ''} `;
1774
1769
  }
1775
- {
1776
- const type = this.value.getType();
1777
- const structName = type.isStructType() ? type.structName : null;
1778
- if (structName && ctx.types.findIndex((val)=>val instanceof ASTStructDefine && val.type.structName === structName) < 0) {
1779
- return '';
1780
- } else {
1781
- return `${indent}${prefix}${type.toTypeName('webgpu', this.value.name)};\n`;
1782
- }
1770
+ const type = this.value.getType();
1771
+ const structName = type.isStructType() ? type.structName : null;
1772
+ if (structName && ctx.types.findIndex((val)=>val instanceof ASTStructDefine && val.type.structName === structName) < 0) {
1773
+ return '';
1774
+ } else {
1775
+ return `${indent}${prefix}${type.toTypeName('webgpu', this.value.name)};\n`;
1783
1776
  }
1784
1777
  }
1785
1778
  toString(deviceType) {
@@ -2046,14 +2039,7 @@ function unbracket(e) {
2046
2039
  str += super.toWGSL(indent + ' ', ctx);
2047
2040
  str += `${indent}}\n`;
2048
2041
  return str;
2049
- /*
2050
- let str = `${indent}loop {\n`;
2051
- const newIndent = indent + ' ';
2052
- str += `${newIndent}if (!(${unbracket(this.condition.toWGSL(indent, ctx))})) { break; }\n`;
2053
- str += super.toWGSL(newIndent, ctx);
2054
- str += `${indent}}\n`;
2055
- return str;
2056
- */ }
2042
+ }
2057
2043
  }
2058
2044
  /** @internal */ class ASTStructDefine extends ShaderAST {
2059
2045
  /** @internal */ type;