@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.
- package/dist/base_types.js +12 -13
- package/dist/base_types.js.map +1 -1
- package/dist/builder/ast.js +34 -48
- package/dist/builder/ast.js.map +1 -1
- package/dist/builder/base.js +6 -2
- package/dist/builder/base.js.map +1 -1
- package/dist/builder/builtinfunc.js +42 -6
- package/dist/builder/builtinfunc.js.map +1 -1
- package/dist/builder/constructors.js +2 -0
- package/dist/builder/constructors.js.map +1 -1
- package/dist/builder/errors.js +4 -4
- package/dist/builder/errors.js.map +1 -1
- package/dist/builder/misc.js +1 -1
- package/dist/builder/misc.js.map +1 -1
- package/dist/builder/programbuilder.js +18 -27
- package/dist/builder/programbuilder.js.map +1 -1
- package/dist/builder/reflection.js +1 -1
- package/dist/builder/reflection.js.map +1 -1
- package/dist/builder/types.js +7 -6
- package/dist/builder/types.js.map +1 -1
- package/dist/device.js +150 -39
- package/dist/device.js.map +1 -1
- package/dist/gpuobject.js +2 -1
- package/dist/gpuobject.js.map +1 -1
- package/dist/helpers/drawtext.js +29 -25
- package/dist/helpers/drawtext.js.map +1 -1
- package/dist/helpers/font.js.map +1 -1
- package/dist/helpers/glyphmanager.js +26 -8
- package/dist/helpers/glyphmanager.js.map +1 -1
- package/dist/helpers/textureatlas.js +7 -3
- package/dist/helpers/textureatlas.js.map +1 -1
- package/dist/index.d.ts +290 -266
- package/dist/pool.js +15 -6
- package/dist/pool.js.map +1 -1
- package/dist/timer.js +3 -2
- package/dist/timer.js.map +1 -1
- package/dist/uniformdata.js +1 -1
- package/dist/uniformdata.js.map +1 -1
- package/dist/vertexdata.js +2 -2
- package/dist/vertexdata.js.map +1 -1
- package/package.json +80 -80
package/dist/builder/ast.js
CHANGED
|
@@ -45,7 +45,7 @@ const BuiltinOutputStructInstanceNameCS = 'zCSOutputCpy';
|
|
|
45
45
|
case ShaderType.Compute:
|
|
46
46
|
return BuiltinParamNameCS;
|
|
47
47
|
default:
|
|
48
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
762
|
-
|
|
763
|
-
|
|
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.
|
|
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
|
-
|
|
797
|
-
if (
|
|
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
|
|
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
|
|
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
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
}
|
|
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;
|