@zephyr3d/device 0.2.4 → 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.
- package/dist/base_types.js +7 -66
- package/dist/base_types.js.map +1 -1
- package/dist/builder/ast.js +112 -118
- package/dist/builder/ast.js.map +1 -1
- package/dist/builder/base.js +23 -25
- package/dist/builder/base.js.map +1 -1
- package/dist/builder/builtinfunc.js +19 -1
- package/dist/builder/builtinfunc.js.map +1 -1
- package/dist/builder/constructors.js +1 -1
- package/dist/builder/constructors.js.map +1 -1
- package/dist/builder/errors.js +7 -7
- package/dist/builder/errors.js.map +1 -1
- package/dist/builder/misc.js +10 -0
- package/dist/builder/misc.js.map +1 -0
- package/dist/builder/programbuilder.js +45 -32
- package/dist/builder/programbuilder.js.map +1 -1
- package/dist/builder/reflection.js.map +1 -1
- package/dist/builder/types.js +70 -70
- package/dist/builder/types.js.map +1 -1
- package/dist/device.js +72 -43
- package/dist/device.js.map +1 -1
- package/dist/gpuobject.js +82 -24
- package/dist/gpuobject.js.map +1 -1
- package/dist/helpers/drawtext.js +1 -0
- package/dist/helpers/drawtext.js.map +1 -1
- package/dist/helpers/font.js +1 -0
- package/dist/helpers/font.js.map +1 -1
- package/dist/helpers/glyphmanager.js +7 -7
- package/dist/helpers/glyphmanager.js.map +1 -1
- package/dist/helpers/textureatlas.js +3 -5
- package/dist/helpers/textureatlas.js.map +1 -1
- package/dist/index.d.ts +199 -152
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/pool.js +54 -25
- package/dist/pool.js.map +1 -1
- package/dist/timer.js.map +1 -1
- package/dist/uniformdata.js +2 -2
- package/dist/uniformdata.js.map +1 -1
- package/dist/vertexdata.js +27 -1
- package/dist/vertexdata.js.map +1 -1
- package/package.json +31 -16
package/dist/builder/ast.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ShaderType } from '../base_types.js';
|
|
2
2
|
import { semanticToAttrib } from '../gpuobject.js';
|
|
3
|
-
import { PBPrimitiveTypeInfo, PBPrimitiveType,
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
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(
|
|
341
|
+
toWebGL(_indent, _ctx) {
|
|
340
342
|
return '';
|
|
341
343
|
}
|
|
342
|
-
toWebGL2(
|
|
344
|
+
toWebGL2(_indent, _ctx) {
|
|
343
345
|
return '';
|
|
344
346
|
}
|
|
345
|
-
toWGSL(
|
|
347
|
+
toWGSL(_indent, _ctx) {
|
|
346
348
|
return '';
|
|
347
349
|
}
|
|
348
|
-
toString(
|
|
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
|
|
541
|
+
case 4:
|
|
540
542
|
return PBAddressSpace.UNIFORM;
|
|
541
|
-
case
|
|
543
|
+
case 5:
|
|
542
544
|
return PBAddressSpace.STORAGE;
|
|
543
|
-
case
|
|
544
|
-
case
|
|
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(
|
|
555
|
+
toWebGL(_indent, _ctx) {
|
|
554
556
|
return this.name;
|
|
555
557
|
}
|
|
556
|
-
toWebGL2(
|
|
558
|
+
toWebGL2(_indent, _ctx) {
|
|
557
559
|
return this.name;
|
|
558
560
|
}
|
|
559
561
|
toWGSL(indent, ctx) {
|
|
560
|
-
if (this.value.$declareType ===
|
|
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 ===
|
|
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(
|
|
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(
|
|
709
|
+
toWebGL(_indent, _ctx) {
|
|
708
710
|
let prefix = '';
|
|
709
711
|
switch(this.value.value.$declareType){
|
|
710
|
-
case
|
|
711
|
-
case
|
|
712
|
-
case
|
|
713
|
-
case
|
|
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(
|
|
725
|
+
toWebGL2(_indent, _ctx) {
|
|
724
726
|
let prefix = '';
|
|
725
727
|
switch(this.value.value.$declareType){
|
|
726
|
-
case
|
|
727
|
-
case
|
|
728
|
-
case
|
|
729
|
-
case
|
|
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(
|
|
741
|
+
toWGSL(_indent, _ctx) {
|
|
740
742
|
let prefix;
|
|
741
743
|
switch(this.value.value.$declareType){
|
|
742
|
-
case
|
|
743
|
-
case
|
|
744
|
-
case
|
|
745
|
-
case
|
|
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.
|
|
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
|
-
|
|
806
|
-
|
|
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
|
-
|
|
819
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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.
|
|
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
|
-
|
|
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(
|
|
1037
|
+
toWebGL(_indent, _ctx) {
|
|
1054
1038
|
throw new Error('GLSL does not support pointer type');
|
|
1055
1039
|
}
|
|
1056
|
-
toWebGL2(
|
|
1040
|
+
toWebGL2(_indent, _ctx) {
|
|
1057
1041
|
throw new Error('GLSL does not support pointer type');
|
|
1058
1042
|
}
|
|
1059
1043
|
toWGSL(indent, ctx) {
|
|
@@ -1407,6 +1391,14 @@ function unbracket(e) {
|
|
|
1407
1391
|
if (this.rvalue instanceof ASTCallFunction) {
|
|
1408
1392
|
this.rvalue.isStatement = false;
|
|
1409
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
|
+
}
|
|
1410
1402
|
}
|
|
1411
1403
|
getType() {
|
|
1412
1404
|
return null;
|
|
@@ -1512,35 +1504,35 @@ function unbracket(e) {
|
|
|
1512
1504
|
}
|
|
1513
1505
|
}
|
|
1514
1506
|
/** @internal */ class ASTDiscard extends ShaderAST {
|
|
1515
|
-
toWebGL(indent,
|
|
1507
|
+
toWebGL(indent, _ctx) {
|
|
1516
1508
|
return `${indent}discard;\n`;
|
|
1517
1509
|
}
|
|
1518
|
-
toWebGL2(indent,
|
|
1510
|
+
toWebGL2(indent, _ctx) {
|
|
1519
1511
|
return `${indent}discard;\n`;
|
|
1520
1512
|
}
|
|
1521
|
-
toWGSL(indent,
|
|
1513
|
+
toWGSL(indent, _ctx) {
|
|
1522
1514
|
return `${indent}discard;\n`;
|
|
1523
1515
|
}
|
|
1524
1516
|
}
|
|
1525
1517
|
/** @internal */ class ASTBreak extends ShaderAST {
|
|
1526
|
-
toWebGL(indent,
|
|
1518
|
+
toWebGL(indent, _ctx) {
|
|
1527
1519
|
return `${indent}break;\n`;
|
|
1528
1520
|
}
|
|
1529
|
-
toWebGL2(indent,
|
|
1521
|
+
toWebGL2(indent, _ctx) {
|
|
1530
1522
|
return `${indent}break;\n`;
|
|
1531
1523
|
}
|
|
1532
|
-
toWGSL(indent,
|
|
1524
|
+
toWGSL(indent, _ctx) {
|
|
1533
1525
|
return `${indent}break;\n`;
|
|
1534
1526
|
}
|
|
1535
1527
|
}
|
|
1536
1528
|
/** @internal */ class ASTContinue extends ShaderAST {
|
|
1537
|
-
toWebGL(indent,
|
|
1529
|
+
toWebGL(indent, _ctx) {
|
|
1538
1530
|
return `${indent}continue;\n`;
|
|
1539
1531
|
}
|
|
1540
|
-
toWebGL2(indent,
|
|
1532
|
+
toWebGL2(indent, _ctx) {
|
|
1541
1533
|
return `${indent}continue;\n`;
|
|
1542
1534
|
}
|
|
1543
|
-
toWGSL(indent,
|
|
1535
|
+
toWGSL(indent, _ctx) {
|
|
1544
1536
|
return `${indent}continue;\n`;
|
|
1545
1537
|
}
|
|
1546
1538
|
}
|
|
@@ -1656,7 +1648,7 @@ function unbracket(e) {
|
|
|
1656
1648
|
const args = thisArgs.map((arg)=>unbracket(arg.toWGSL(indent, ctx)));
|
|
1657
1649
|
return `${this.isStatement ? indent : ''}${this.name}(${args.join(',')})${this.isStatement ? ';\n' : ''}`;
|
|
1658
1650
|
}
|
|
1659
|
-
toString(
|
|
1651
|
+
toString(_deviceType) {
|
|
1660
1652
|
return `${this.name}(...)`;
|
|
1661
1653
|
}
|
|
1662
1654
|
}
|
|
@@ -1682,7 +1674,7 @@ function unbracket(e) {
|
|
|
1682
1674
|
let builtin = false;
|
|
1683
1675
|
let valueType = this.value.getType();
|
|
1684
1676
|
switch(this.value.value.$declareType){
|
|
1685
|
-
case
|
|
1677
|
+
case 1:
|
|
1686
1678
|
if (ctx.type === ShaderType.Vertex) {
|
|
1687
1679
|
prefix = 'attribute ';
|
|
1688
1680
|
ctx.defines.push(`#define ${this.value.name} ${semanticToAttrib(ctx.vertexAttributes[this.value.value.$location])}\n`);
|
|
@@ -1691,7 +1683,7 @@ function unbracket(e) {
|
|
|
1691
1683
|
// ctx.defines.push(`#define ${this.value.$str} ch_varying_${this.value.$location}\n`);
|
|
1692
1684
|
}
|
|
1693
1685
|
break;
|
|
1694
|
-
case
|
|
1686
|
+
case 2:
|
|
1695
1687
|
if (ctx.type === ShaderType.Vertex) {
|
|
1696
1688
|
prefix = 'varying ';
|
|
1697
1689
|
// ctx.defines.push(`#define ${this.value.$str} ch_varying_${this.value.$location}\n`);
|
|
@@ -1705,11 +1697,11 @@ function unbracket(e) {
|
|
|
1705
1697
|
}
|
|
1706
1698
|
}
|
|
1707
1699
|
break;
|
|
1708
|
-
case
|
|
1700
|
+
case 4:
|
|
1709
1701
|
prefix = 'uniform ';
|
|
1710
1702
|
valueType = ctx.typeReplacement?.get(this.value.value) || valueType;
|
|
1711
1703
|
break;
|
|
1712
|
-
case
|
|
1704
|
+
case 5:
|
|
1713
1705
|
throw new Error(`invalid variable declare type: ${this.value.name}`);
|
|
1714
1706
|
}
|
|
1715
1707
|
if (!builtin) {
|
|
@@ -1720,7 +1712,7 @@ function unbracket(e) {
|
|
|
1720
1712
|
let prefix = '';
|
|
1721
1713
|
let valueType = this.value.getType();
|
|
1722
1714
|
switch(this.value.value.$declareType){
|
|
1723
|
-
case
|
|
1715
|
+
case 1:
|
|
1724
1716
|
if (ctx.type === ShaderType.Fragment && valueType.isPrimitiveType() && valueType.isInteger()) {
|
|
1725
1717
|
prefix = 'flat in ';
|
|
1726
1718
|
} else {
|
|
@@ -1730,7 +1722,7 @@ function unbracket(e) {
|
|
|
1730
1722
|
ctx.defines.push(`#define ${this.value.name} ${semanticToAttrib(ctx.vertexAttributes[this.value.value.$location])}\n`);
|
|
1731
1723
|
}
|
|
1732
1724
|
break;
|
|
1733
|
-
case
|
|
1725
|
+
case 2:
|
|
1734
1726
|
if (ctx.type === ShaderType.Vertex) {
|
|
1735
1727
|
if (valueType.isPrimitiveType() && valueType.isInteger()) {
|
|
1736
1728
|
prefix = 'flat out ';
|
|
@@ -1741,7 +1733,7 @@ function unbracket(e) {
|
|
|
1741
1733
|
prefix = `layout(location = ${this.value.value.$location}) out `;
|
|
1742
1734
|
}
|
|
1743
1735
|
break;
|
|
1744
|
-
case
|
|
1736
|
+
case 4:
|
|
1745
1737
|
if (valueType.isStructType()) {
|
|
1746
1738
|
/*
|
|
1747
1739
|
if (valueType.layout !== 'std140') {
|
|
@@ -1752,7 +1744,7 @@ function unbracket(e) {
|
|
|
1752
1744
|
valueType = ctx.typeReplacement?.get(this.value.value) || valueType;
|
|
1753
1745
|
return `${indent}uniform ${valueType.toTypeName('webgl2', this.value.name)};\n`;
|
|
1754
1746
|
}
|
|
1755
|
-
case
|
|
1747
|
+
case 5:
|
|
1756
1748
|
throw new Error(`invalid variable declare type: ${this.value.name}`);
|
|
1757
1749
|
}
|
|
1758
1750
|
{
|
|
@@ -1763,18 +1755,18 @@ function unbracket(e) {
|
|
|
1763
1755
|
let prefix;
|
|
1764
1756
|
const isBlock = this.value.getType().isPrimitiveType() || this.value.getType().isStructType() || this.value.getType().isArrayType();
|
|
1765
1757
|
switch(this.value.value.$declareType){
|
|
1766
|
-
case
|
|
1767
|
-
case
|
|
1758
|
+
case 1:
|
|
1759
|
+
case 2:
|
|
1768
1760
|
// prefix = `@location(${this.value.value.$location}) var<out> `;
|
|
1769
1761
|
throw new Error(`Internal error`);
|
|
1770
|
-
case
|
|
1762
|
+
case 4:
|
|
1771
1763
|
prefix = `@group(${this.group}) @binding(${this.binding}) var${isBlock ? '<uniform>' : ''} `;
|
|
1772
1764
|
break;
|
|
1773
|
-
case
|
|
1765
|
+
case 5:
|
|
1774
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'
|
|
1775
1767
|
}> `;
|
|
1776
1768
|
break;
|
|
1777
|
-
case
|
|
1769
|
+
case 3:
|
|
1778
1770
|
prefix = `var<workgroup> `;
|
|
1779
1771
|
break;
|
|
1780
1772
|
default:
|
|
@@ -1952,12 +1944,14 @@ function unbracket(e) {
|
|
|
1952
1944
|
/** @internal */ start;
|
|
1953
1945
|
/** @internal */ end;
|
|
1954
1946
|
/** @internal */ open;
|
|
1955
|
-
|
|
1947
|
+
/** @internal */ reverse;
|
|
1948
|
+
constructor(init, start, end, open, reverse){
|
|
1956
1949
|
super();
|
|
1957
1950
|
this.init = init;
|
|
1958
1951
|
this.start = start;
|
|
1959
1952
|
this.end = end;
|
|
1960
1953
|
this.open = open;
|
|
1954
|
+
this.reverse = reverse;
|
|
1961
1955
|
this.statements = [];
|
|
1962
1956
|
if (this.start instanceof ASTCallFunction) {
|
|
1963
1957
|
this.start.isStatement = false;
|
|
@@ -1970,8 +1964,8 @@ function unbracket(e) {
|
|
|
1970
1964
|
const init = this.init.getType().toTypeName('webgl', this.init.name);
|
|
1971
1965
|
const start = unbracket(this.start.toWebGL(indent, ctx));
|
|
1972
1966
|
const end = unbracket(this.end.toWebGL(indent, ctx));
|
|
1973
|
-
const comp = this.open ? '<' : '<=';
|
|
1974
|
-
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`;
|
|
1975
1969
|
str += super.toWebGL(indent + ' ', ctx);
|
|
1976
1970
|
str += `${indent}}\n`;
|
|
1977
1971
|
return str;
|
|
@@ -1980,8 +1974,8 @@ function unbracket(e) {
|
|
|
1980
1974
|
const init = this.init.getType().toTypeName('webgl2', this.init.name);
|
|
1981
1975
|
const start = unbracket(this.start.toWebGL2(indent, ctx));
|
|
1982
1976
|
const end = unbracket(this.end.toWebGL2(indent, ctx));
|
|
1983
|
-
const comp = this.open ? '<' : '<=';
|
|
1984
|
-
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`;
|
|
1985
1979
|
str += super.toWebGL2(indent + ' ', ctx);
|
|
1986
1980
|
str += `${indent}}\n`;
|
|
1987
1981
|
return str;
|
|
@@ -1991,8 +1985,8 @@ function unbracket(e) {
|
|
|
1991
1985
|
const start = unbracket(this.start.toWGSL(indent, ctx));
|
|
1992
1986
|
const end = unbracket(this.end.toWGSL(indent, ctx));
|
|
1993
1987
|
const incr = new ASTScalar(1, this.init.getType()).toWGSL(indent, ctx);
|
|
1994
|
-
const comp = this.open ? '<' : '<=';
|
|
1995
|
-
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`;
|
|
1996
1990
|
str += super.toWGSL(indent + ' ', ctx);
|
|
1997
1991
|
str += `${indent}}\n`;
|
|
1998
1992
|
return str;
|
|
@@ -2007,7 +2001,7 @@ function unbracket(e) {
|
|
|
2007
2001
|
this.condition.isStatement = false;
|
|
2008
2002
|
}
|
|
2009
2003
|
}
|
|
2010
|
-
toWebGL(
|
|
2004
|
+
toWebGL(_indent, _ctx) {
|
|
2011
2005
|
throw new Error(`No do-while() loop support for WebGL1.0 device`);
|
|
2012
2006
|
}
|
|
2013
2007
|
toWebGL2(indent, ctx) {
|
|
@@ -2074,7 +2068,7 @@ function unbracket(e) {
|
|
|
2074
2068
|
getType() {
|
|
2075
2069
|
return this.type;
|
|
2076
2070
|
}
|
|
2077
|
-
toWebGL(indent,
|
|
2071
|
+
toWebGL(indent, _ctx) {
|
|
2078
2072
|
if (!this.builtin) {
|
|
2079
2073
|
let str = `${indent}struct ${this.type.structName} {\n`;
|
|
2080
2074
|
for (const arg of this.type.structMembers){
|
|
@@ -2086,7 +2080,7 @@ function unbracket(e) {
|
|
|
2086
2080
|
return '';
|
|
2087
2081
|
}
|
|
2088
2082
|
}
|
|
2089
|
-
toWebGL2(indent,
|
|
2083
|
+
toWebGL2(indent, _ctx) {
|
|
2090
2084
|
if (!this.builtin) {
|
|
2091
2085
|
let str = `${indent}struct ${this.type.structName} {\n`;
|
|
2092
2086
|
for (const arg of this.type.structMembers){
|
|
@@ -2098,7 +2092,7 @@ function unbracket(e) {
|
|
|
2098
2092
|
return '';
|
|
2099
2093
|
}
|
|
2100
2094
|
}
|
|
2101
|
-
toWGSL(indent,
|
|
2095
|
+
toWGSL(indent, _ctx) {
|
|
2102
2096
|
if (!this.builtin) {
|
|
2103
2097
|
let str = `${indent}struct ${this.type.structName} {\n`;
|
|
2104
2098
|
str += this.type.structMembers.map((arg, i)=>{
|