@zephyr3d/device 0.2.4 → 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 +19 -79
- package/dist/base_types.js.map +1 -1
- package/dist/builder/ast.js +142 -162
- package/dist/builder/ast.js.map +1 -1
- package/dist/builder/base.js +29 -27
- package/dist/builder/base.js.map +1 -1
- package/dist/builder/builtinfunc.js +61 -7
- package/dist/builder/builtinfunc.js.map +1 -1
- package/dist/builder/constructors.js +3 -1
- package/dist/builder/constructors.js.map +1 -1
- package/dist/builder/errors.js +11 -11
- 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 +62 -58
- 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 +76 -75
- package/dist/builder/types.js.map +1 -1
- package/dist/device.js +220 -80
- package/dist/device.js.map +1 -1
- package/dist/gpuobject.js +84 -25
- package/dist/gpuobject.js.map +1 -1
- package/dist/helpers/drawtext.js +30 -25
- 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 +33 -15
- package/dist/helpers/glyphmanager.js.map +1 -1
- package/dist/helpers/textureatlas.js +10 -8
- package/dist/helpers/textureatlas.js.map +1 -1
- package/dist/index.d.ts +465 -394
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/pool.js +69 -31
- package/dist/pool.js.map +1 -1
- package/dist/timer.js +3 -2
- package/dist/timer.js.map +1 -1
- package/dist/uniformdata.js +3 -3
- package/dist/uniformdata.js.map +1 -1
- package/dist/vertexdata.js +29 -3
- package/dist/vertexdata.js.map +1 -1
- package/package.json +80 -65
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
* Gets the variable which is the vertex attribute of specified semantic
|
|
43
43
|
* @param attrib - The vertex semantic
|
|
44
44
|
*/ attribute(attrib) {
|
|
45
|
-
return this._attribList[attrib]
|
|
45
|
+
return this._attribList[attrib] ?? null;
|
|
46
46
|
}
|
|
47
47
|
/** @internal */ setAttrib(attrib, exp) {
|
|
48
48
|
this._attribList[attrib] = exp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reflection.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reflection.js","sources":["../../src/builder/reflection.ts"],"sourcesContent":["import type { PBGlobalScope, ProgramBuilder } from './programbuilder';\r\nimport type { PBShaderExp } from './base';\r\nimport type { VertexSemantic } from '../gpuobject';\r\nimport type { Nullable } from '@zephyr3d/base';\r\n\r\n/**\r\n * Shader variable getter function type\r\n * @public\r\n */\r\nexport type PBReflectionTagGetter = (scope: PBGlobalScope) => PBShaderExp;\r\n\r\n/**\r\n * Reflection interface for program builder\r\n * @public\r\n */\r\nexport class PBReflection {\r\n /** @internal */\r\n private readonly _builder: ProgramBuilder;\r\n /** @internal */\r\n private _tagList: Partial<Record<string, PBReflectionTagGetter>>;\r\n /** @internal */\r\n private _attribList: Partial<Record<string, PBShaderExp>>;\r\n constructor(builder: ProgramBuilder) {\r\n this._builder = builder;\r\n this._tagList = {};\r\n this._attribList = {};\r\n }\r\n /** Gets all the vertex attributes that was used by the program */\r\n get vertexAttributes() {\r\n return this._builder.getVertexAttributes();\r\n }\r\n /**\r\n * Check if specified vertex attribute was used by the program\r\n * @param attrib - The vertex attribute to check\r\n */\r\n hasVertexAttribute(attrib: number) {\r\n return this.vertexAttributes.indexOf(attrib) >= 0;\r\n }\r\n /**\r\n * Clear all contents\r\n */\r\n clear() {\r\n this._tagList = {};\r\n this._attribList = {};\r\n }\r\n /**\r\n * Gets the variable that has tagged with given string\r\n * @param name - The tag string\r\n */\r\n tag(name: string): PBShaderExp;\r\n /**\r\n * Creates a new tag by specifying a function to get the tagged variable\r\n * @param name - The tag name\r\n * @param getter - The getter function\r\n */\r\n tag(name: string, getter: PBReflectionTagGetter): void;\r\n /**\r\n * Creates multiple tags from an object that contains the tag names and the getter functions\r\n * @param values - The object that contains the tag names and the getter functions\r\n */\r\n tag(values: Record<string, PBReflectionTagGetter>): void;\r\n tag(\r\n arg0: string | Record<string, PBReflectionTagGetter>,\r\n arg1?: PBReflectionTagGetter\r\n ): Nullable<PBShaderExp> | void {\r\n if (typeof arg0 === 'string') {\r\n if (arg1 === undefined) {\r\n return this.getTag(arg0);\r\n } else {\r\n this.addTag(arg0, arg1);\r\n }\r\n } else {\r\n for (const k of Object.keys(arg0)) {\r\n this.addTag(k, arg0[k]);\r\n }\r\n }\r\n }\r\n /**\r\n * Gets the variable which is the vertex attribute of specified semantic\r\n * @param attrib - The vertex semantic\r\n */\r\n attribute(attrib: VertexSemantic) {\r\n return this._attribList[attrib] ?? null;\r\n }\r\n /** @internal */\r\n setAttrib(attrib: VertexSemantic, exp: PBShaderExp) {\r\n this._attribList[attrib] = exp;\r\n }\r\n /** @internal */\r\n private addTag(name: string, exp: PBReflectionTagGetter) {\r\n this._tagList[name] = exp;\r\n }\r\n /** @internal */\r\n private getTag(name: string) {\r\n const getter = this._tagList[name];\r\n return getter ? getter(this._builder.getGlobalScope()) : null;\r\n }\r\n}\r\n"],"names":["PBReflection","builder","_builder","_tagList","_attribList","vertexAttributes","getVertexAttributes","hasVertexAttribute","attrib","indexOf","clear","tag","arg0","arg1","undefined","getTag","addTag","k","Object","keys","attribute","setAttrib","exp","name","getter","getGlobalScope"],"mappings":"AAWA;;;AAGC,IACM,MAAMA,YAAAA,CAAAA;qBAEX,QAA0C;qBAE1C,QAAiE;qBAEjE,WAA0D;AAC1D,IAAA,WAAA,CAAYC,OAAuB,CAAE;QACnC,IAAI,CAACC,QAAQ,GAAGD,OAAAA;QAChB,IAAI,CAACE,QAAQ,GAAG,EAAC;QACjB,IAAI,CAACC,WAAW,GAAG,EAAC;AACtB;uEAEA,IAAIC,gBAAmB,GAAA;AACrB,QAAA,OAAO,IAAI,CAACH,QAAQ,CAACI,mBAAmB,EAAA;AAC1C;AACA;;;MAIAC,kBAAAA,CAAmBC,MAAc,EAAE;AACjC,QAAA,OAAO,IAAI,CAACH,gBAAgB,CAACI,OAAO,CAACD,MAAW,CAAA,IAAA,CAAA;AAClD;AACA;;AAEC,MACDE,KAAQ,GAAA;QACN,IAAI,CAACP,QAAQ,GAAG,EAAC;QACjB,IAAI,CAACC,WAAW,GAAG,EAAC;AACtB;IAiBAO,GACEC,CAAAA,IAAoD,EACpDC,IAA4B,EACE;QAC9B,IAAI,OAAOD,SAAS,QAAU,EAAA;AAC5B,YAAA,IAAIC,SAASC,SAAW,EAAA;gBACtB,OAAO,IAAI,CAACC,MAAM,CAACH,IAAAA,CAAAA;aACd,MAAA;gBACL,IAAI,CAACI,MAAM,CAACJ,IAAMC,EAAAA,IAAAA,CAAAA;AACpB;SACK,MAAA;AACL,YAAA,KAAK,MAAMI,CAAAA,IAAKC,MAAOC,CAAAA,IAAI,CAACP,IAAO,CAAA,CAAA;AACjC,gBAAA,IAAI,CAACI,MAAM,CAACC,CAAGL,EAAAA,IAAI,CAACK,CAAE,CAAA,CAAA;AACxB;AACF;AACF;AACA;;;MAIAG,SAAAA,CAAUZ,MAAsB,EAAE;AAChC,QAAA,OAAO,IAAI,CAACJ,WAAW,CAACI,OAAO,IAAI,IAAA;AACrC;AACA,qBACAa,SAAAA,CAAUb,MAAsB,EAAEc,GAAgB,EAAE;AAClD,QAAA,IAAI,CAAClB,WAAW,CAACI,MAAAA,CAAO,GAAGc,GAAAA;AAC7B;AACA,qBACA,MAAQN,CAAOO,IAAY,EAAED,GAA0B,EAAE;AACvD,QAAA,IAAI,CAACnB,QAAQ,CAACoB,IAAAA,CAAK,GAAGD,GAAAA;AACxB;AACA,qBACQP,MAAOQ,CAAAA,IAAY,EAAE;AAC3B,QAAA,MAAMC,MAAS,GAAA,IAAI,CAACrB,QAAQ,CAACoB,IAAK,CAAA;AAClC,QAAA,OAAOC,SAASA,MAAO,CAAA,IAAI,CAACtB,QAAQ,CAACuB,cAAc,EAAM,CAAA,GAAA,IAAA;AAC3D;AACF;;;;"}
|
package/dist/builder/types.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ASSERT } from '@zephyr3d/base';
|
|
2
|
+
|
|
1
3
|
const F16_BITMASK = 1;
|
|
2
4
|
const F32_BITMASK = 2;
|
|
3
5
|
const BOOL_BITMASK = 3;
|
|
@@ -32,7 +34,7 @@ function getAlignment(type) {
|
|
|
32
34
|
return Math.max(alignment, 16);
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
|
-
function getAlignmentPacked(
|
|
37
|
+
function getAlignmentPacked(_type) {
|
|
36
38
|
return 1;
|
|
37
39
|
}
|
|
38
40
|
function getSize(type) {
|
|
@@ -100,8 +102,10 @@ function typeToTypedArray(type) {
|
|
|
100
102
|
return PBPrimitiveType.U8;
|
|
101
103
|
}
|
|
102
104
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Primitive types
|
|
107
|
+
* @public
|
|
108
|
+
*/ var PBPrimitiveType = /*#__PURE__*/ function(PBPrimitiveType) {
|
|
105
109
|
PBPrimitiveType[PBPrimitiveType["NONE"] = 0] = "NONE";
|
|
106
110
|
PBPrimitiveType[PBPrimitiveType["F16"] = makePrimitiveType(F16_BITMASK, 1, 1, 0)] = "F16";
|
|
107
111
|
PBPrimitiveType[PBPrimitiveType["F16VEC2"] = makePrimitiveType(F16_BITMASK, 1, 2, 0)] = "F16VEC2";
|
|
@@ -172,7 +176,8 @@ var PBPrimitiveType;
|
|
|
172
176
|
PBPrimitiveType[PBPrimitiveType["MAT4x2"] = makePrimitiveType(F32_BITMASK, 4, 2, 0)] = "MAT4x2";
|
|
173
177
|
PBPrimitiveType[PBPrimitiveType["MAT4x3"] = makePrimitiveType(F32_BITMASK, 4, 3, 0)] = "MAT4x3";
|
|
174
178
|
PBPrimitiveType[PBPrimitiveType["MAT4"] = makePrimitiveType(F32_BITMASK, 4, 4, 0)] = "MAT4";
|
|
175
|
-
|
|
179
|
+
return PBPrimitiveType;
|
|
180
|
+
}({});
|
|
176
181
|
const primitiveTypeMapWebGL = {
|
|
177
182
|
[PBPrimitiveType.F32]: 'float',
|
|
178
183
|
[PBPrimitiveType.F32VEC2]: 'vec2',
|
|
@@ -239,8 +244,10 @@ const BITFLAG_FLOAT = 1 << 8;
|
|
|
239
244
|
const BITFLAG_INT = 1 << 9;
|
|
240
245
|
const BITFLAG_UINT = 1 << 10;
|
|
241
246
|
const BITFLAG_EXTERNAL = 1 << 11;
|
|
242
|
-
|
|
243
|
-
|
|
247
|
+
/**
|
|
248
|
+
* Texture types
|
|
249
|
+
* @public
|
|
250
|
+
*/ var PBTextureType = /*#__PURE__*/ function(PBTextureType) {
|
|
244
251
|
PBTextureType[PBTextureType["TEX_1D"] = BITFLAG_1D | BITFLAG_FLOAT] = "TEX_1D";
|
|
245
252
|
PBTextureType[PBTextureType["ITEX_1D"] = BITFLAG_1D | BITFLAG_INT] = "ITEX_1D";
|
|
246
253
|
PBTextureType[PBTextureType["UTEX_1D"] = BITFLAG_1D | BITFLAG_UINT] = "UTEX_1D";
|
|
@@ -272,7 +279,8 @@ var PBTextureType;
|
|
|
272
279
|
PBTextureType[PBTextureType["TEX_DEPTH_CUBE_ARRAY"] = BITFLAG_CUBE | BITFLAG_ARRAY | BITFLAG_DEPTH] = "TEX_DEPTH_CUBE_ARRAY";
|
|
273
280
|
PBTextureType[PBTextureType["TEX_DEPTH_MULTISAMPLED_2D"] = BITFLAG_2D | BITFLAG_MULTISAMPLED | BITFLAG_DEPTH] = "TEX_DEPTH_MULTISAMPLED_2D";
|
|
274
281
|
PBTextureType[PBTextureType["TEX_EXTERNAL"] = BITFLAG_EXTERNAL] = "TEX_EXTERNAL";
|
|
275
|
-
|
|
282
|
+
return PBTextureType;
|
|
283
|
+
}({});
|
|
276
284
|
const textureTypeMapWebGL = {
|
|
277
285
|
[PBTextureType.TEX_1D]: 'highp sampler2D',
|
|
278
286
|
[PBTextureType.TEX_2D]: 'highp sampler2D',
|
|
@@ -352,35 +360,27 @@ const storageTexelFormatMap = {
|
|
|
352
360
|
rgba32ui: 'rgba32uint',
|
|
353
361
|
rgba32i: 'rgba32sint'
|
|
354
362
|
};
|
|
355
|
-
|
|
356
|
-
|
|
363
|
+
/**
|
|
364
|
+
* Sampler access mode
|
|
365
|
+
* @public
|
|
366
|
+
*/ var PBSamplerAccessMode = /*#__PURE__*/ function(PBSamplerAccessMode) {
|
|
357
367
|
PBSamplerAccessMode[PBSamplerAccessMode["UNKNOWN"] = 0] = "UNKNOWN";
|
|
358
368
|
PBSamplerAccessMode[PBSamplerAccessMode["SAMPLE"] = 1] = "SAMPLE";
|
|
359
369
|
PBSamplerAccessMode[PBSamplerAccessMode["COMPARISON"] = 2] = "COMPARISON";
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
PBAddressSpace["
|
|
367
|
-
PBAddressSpace["
|
|
368
|
-
PBAddressSpace["
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
PBTypeClass[PBTypeClass["ARRAY"] = 2] = "ARRAY";
|
|
375
|
-
PBTypeClass[PBTypeClass["POINTER"] = 3] = "POINTER";
|
|
376
|
-
PBTypeClass[PBTypeClass["ATOMIC_I32"] = 4] = "ATOMIC_I32";
|
|
377
|
-
PBTypeClass[PBTypeClass["ATOMIC_U32"] = 5] = "ATOMIC_U32";
|
|
378
|
-
PBTypeClass[PBTypeClass["TEXTURE"] = 6] = "TEXTURE";
|
|
379
|
-
PBTypeClass[PBTypeClass["SAMPLER"] = 7] = "SAMPLER";
|
|
380
|
-
PBTypeClass[PBTypeClass["FUNCTION"] = 8] = "FUNCTION";
|
|
381
|
-
PBTypeClass[PBTypeClass["VOID"] = 9] = "VOID";
|
|
382
|
-
PBTypeClass[PBTypeClass["ANY"] = 10] = "ANY";
|
|
383
|
-
})(PBTypeClass || (PBTypeClass = {}));
|
|
370
|
+
return PBSamplerAccessMode;
|
|
371
|
+
}({});
|
|
372
|
+
/**
|
|
373
|
+
* Shader variable address space
|
|
374
|
+
* @public
|
|
375
|
+
*/ var PBAddressSpace = /*#__PURE__*/ function(PBAddressSpace) {
|
|
376
|
+
PBAddressSpace["UNKNOWN"] = "unknown";
|
|
377
|
+
PBAddressSpace["FUNCTION"] = "function";
|
|
378
|
+
PBAddressSpace["PRIVATE"] = "private";
|
|
379
|
+
PBAddressSpace["WORKGROUP"] = "workgroup";
|
|
380
|
+
PBAddressSpace["UNIFORM"] = "uniform";
|
|
381
|
+
PBAddressSpace["STORAGE"] = "storage";
|
|
382
|
+
return PBAddressSpace;
|
|
383
|
+
}({});
|
|
384
384
|
/**
|
|
385
385
|
* Abstract base class for any type
|
|
386
386
|
* @public
|
|
@@ -441,7 +441,7 @@ var PBTypeClass;
|
|
|
441
441
|
/** @internal */ isStorable() {
|
|
442
442
|
return false;
|
|
443
443
|
}
|
|
444
|
-
/** @internal */ getConstructorOverloads(
|
|
444
|
+
/** @internal */ getConstructorOverloads(_deviceType) {
|
|
445
445
|
return [];
|
|
446
446
|
}
|
|
447
447
|
/**
|
|
@@ -457,7 +457,7 @@ var PBTypeClass;
|
|
|
457
457
|
* @public
|
|
458
458
|
*/ class PBVoidTypeInfo extends PBTypeInfo {
|
|
459
459
|
constructor(){
|
|
460
|
-
super(
|
|
460
|
+
super(9, null);
|
|
461
461
|
}
|
|
462
462
|
/** {@inheritDoc PBTypeInfo.isVoidType} */ isVoidType() {
|
|
463
463
|
return true;
|
|
@@ -468,7 +468,7 @@ var PBTypeClass;
|
|
|
468
468
|
/** @internal */ genTypeId() {
|
|
469
469
|
return 'void';
|
|
470
470
|
}
|
|
471
|
-
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(
|
|
471
|
+
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(_offset) {
|
|
472
472
|
return null;
|
|
473
473
|
}
|
|
474
474
|
}
|
|
@@ -477,7 +477,7 @@ var PBTypeClass;
|
|
|
477
477
|
* @public
|
|
478
478
|
*/ class PBAnyTypeInfo extends PBTypeInfo {
|
|
479
479
|
constructor(){
|
|
480
|
-
super(
|
|
480
|
+
super(10, null);
|
|
481
481
|
}
|
|
482
482
|
/** {@inheritDoc PBTypeInfo.isAnyType} */ isAnyType() {
|
|
483
483
|
return true;
|
|
@@ -488,10 +488,10 @@ var PBTypeClass;
|
|
|
488
488
|
/** @internal */ genTypeId() {
|
|
489
489
|
return 'any';
|
|
490
490
|
}
|
|
491
|
-
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(
|
|
491
|
+
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(_offset) {
|
|
492
492
|
return null;
|
|
493
493
|
}
|
|
494
|
-
/** {@inheritDoc PBTypeInfo.isCompatibleType} */ isCompatibleType(
|
|
494
|
+
/** {@inheritDoc PBTypeInfo.isCompatibleType} */ isCompatibleType(_other) {
|
|
495
495
|
return true;
|
|
496
496
|
}
|
|
497
497
|
}
|
|
@@ -502,7 +502,7 @@ var PBTypeClass;
|
|
|
502
502
|
/** @internal */ static cachedTypes = {};
|
|
503
503
|
/** @internal */ static cachedCtorOverloads = {};
|
|
504
504
|
constructor(type){
|
|
505
|
-
super(
|
|
505
|
+
super(1, {
|
|
506
506
|
primitiveType: type
|
|
507
507
|
});
|
|
508
508
|
}
|
|
@@ -785,7 +785,7 @@ var PBTypeClass;
|
|
|
785
785
|
return varName ? `${typename} ${varName}` : typename;
|
|
786
786
|
}
|
|
787
787
|
}
|
|
788
|
-
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(
|
|
788
|
+
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(_offset) {
|
|
789
789
|
return null;
|
|
790
790
|
}
|
|
791
791
|
/** @internal */ genTypeId() {
|
|
@@ -797,7 +797,7 @@ var PBTypeClass;
|
|
|
797
797
|
* @public
|
|
798
798
|
*/ class PBStructTypeInfo extends PBTypeInfo {
|
|
799
799
|
constructor(name, layout, members){
|
|
800
|
-
super(
|
|
800
|
+
super(1, {
|
|
801
801
|
layout: layout || 'default',
|
|
802
802
|
structName: name,
|
|
803
803
|
structMembers: members.map((val)=>{
|
|
@@ -841,6 +841,7 @@ var PBTypeClass;
|
|
|
841
841
|
return member.type.isAtomicI32() || member.type.isAtomicU32();
|
|
842
842
|
}
|
|
843
843
|
}
|
|
844
|
+
return false;
|
|
844
845
|
}
|
|
845
846
|
/**
|
|
846
847
|
* Creates a new struct type by extending this type
|
|
@@ -979,7 +980,7 @@ var PBTypeClass;
|
|
|
979
980
|
}
|
|
980
981
|
/** @internal */ calcAlignmentAndSizePacked() {
|
|
981
982
|
for (const member of this.structMembers){
|
|
982
|
-
member.alignment = getAlignmentPacked(
|
|
983
|
+
member.alignment = getAlignmentPacked();
|
|
983
984
|
member.size = getSizePacked(member.type);
|
|
984
985
|
}
|
|
985
986
|
}
|
|
@@ -989,7 +990,7 @@ var PBTypeClass;
|
|
|
989
990
|
* @public
|
|
990
991
|
*/ class PBArrayTypeInfo extends PBTypeInfo {
|
|
991
992
|
constructor(elementType, dimension){
|
|
992
|
-
super(
|
|
993
|
+
super(2, {
|
|
993
994
|
elementType: elementType,
|
|
994
995
|
dimension: Number(dimension) || 0
|
|
995
996
|
});
|
|
@@ -1014,7 +1015,7 @@ var PBTypeClass;
|
|
|
1014
1015
|
return this.detail.elementType.isHostSharable();
|
|
1015
1016
|
}
|
|
1016
1017
|
/** @internal */ isConstructible() {
|
|
1017
|
-
return this.dimension && this.detail.elementType.isConstructible();
|
|
1018
|
+
return !!this.dimension && this.detail.elementType.isConstructible();
|
|
1018
1019
|
}
|
|
1019
1020
|
/** @internal */ isStorable() {
|
|
1020
1021
|
return true;
|
|
@@ -1039,8 +1040,8 @@ var PBTypeClass;
|
|
|
1039
1040
|
const typename = `array<${elementTypeName}${this.dimension ? ', ' + this.dimension : ''}>`;
|
|
1040
1041
|
return varName ? `${varName}: ${typename}` : typename;
|
|
1041
1042
|
} else {
|
|
1042
|
-
|
|
1043
|
-
|
|
1043
|
+
ASSERT(!!this.dimension, 'runtime-sized array not supported for webgl');
|
|
1044
|
+
ASSERT(!this.elementType.isArrayType(), 'multi-dimensional arrays not supported for webgl');
|
|
1044
1045
|
const elementTypeName = this.elementType.toTypeName(deviceType, varName);
|
|
1045
1046
|
return `${elementTypeName}[${this.dimension}]`;
|
|
1046
1047
|
}
|
|
@@ -1056,7 +1057,7 @@ var PBTypeClass;
|
|
|
1056
1057
|
}
|
|
1057
1058
|
return this.elementType.isAnyType() ? 0 : this.dimension * align(this.elementType.getLayoutSize(layout), elementAlignment);
|
|
1058
1059
|
}
|
|
1059
|
-
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(
|
|
1060
|
+
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(_offset) {
|
|
1060
1061
|
return null;
|
|
1061
1062
|
}
|
|
1062
1063
|
isCompatibleType(other) {
|
|
@@ -1078,11 +1079,11 @@ var PBTypeClass;
|
|
|
1078
1079
|
*/ class PBPointerTypeInfo extends PBTypeInfo {
|
|
1079
1080
|
/** @internal */ writable;
|
|
1080
1081
|
constructor(pointerType, addressSpace){
|
|
1081
|
-
super(
|
|
1082
|
+
super(3, {
|
|
1082
1083
|
pointerType,
|
|
1083
1084
|
addressSpace
|
|
1084
1085
|
});
|
|
1085
|
-
|
|
1086
|
+
ASSERT(pointerType.isStorable(), 'the pointee type must be storable');
|
|
1086
1087
|
this.writable = false;
|
|
1087
1088
|
}
|
|
1088
1089
|
/** Get type of the pointer */ get pointerType() {
|
|
@@ -1105,7 +1106,7 @@ var PBTypeClass;
|
|
|
1105
1106
|
}
|
|
1106
1107
|
/** @internal */ toTypeName(device, varName) {
|
|
1107
1108
|
if (device === 'webgpu') {
|
|
1108
|
-
const addressSpace = this.addressSpace ===
|
|
1109
|
+
const addressSpace = this.addressSpace === "unknown" ? "function" : this.addressSpace;
|
|
1109
1110
|
/*
|
|
1110
1111
|
const mode = addressSpace === PBAddressSpace.UNIFORM || (addressSpace === PBAddressSpace.STORAGE && !this.writable) ? 'read' : 'read_write'
|
|
1111
1112
|
const typename = `ptr<${addressSpace}, ${this.pointerType.toTypeName(device)}, ${mode}>`;
|
|
@@ -1113,14 +1114,14 @@ var PBTypeClass;
|
|
|
1113
1114
|
When writing a variable declaration or a pointer type in WGSL source:
|
|
1114
1115
|
For the storage address space, the access mode is optional, and defaults to read.
|
|
1115
1116
|
For other address spaces, the access mode must not be written.
|
|
1116
|
-
*/ const mode = addressSpace ===
|
|
1117
|
+
*/ const mode = addressSpace === "storage" && this.writable ? ', read_write' : '';
|
|
1117
1118
|
const typename = `ptr<${addressSpace}, ${this.pointerType.toTypeName(device)} ${mode}>`;
|
|
1118
1119
|
return varName ? `${varName}: ${typename}` : typename;
|
|
1119
1120
|
} else {
|
|
1120
1121
|
throw new Error('pointer type not supported for webgl');
|
|
1121
1122
|
}
|
|
1122
1123
|
}
|
|
1123
|
-
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(
|
|
1124
|
+
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(_offset) {
|
|
1124
1125
|
return null;
|
|
1125
1126
|
}
|
|
1126
1127
|
/** @internal */ genTypeId() {
|
|
@@ -1132,7 +1133,7 @@ var PBTypeClass;
|
|
|
1132
1133
|
* @public
|
|
1133
1134
|
*/ class PBAtomicI32TypeInfo extends PBTypeInfo {
|
|
1134
1135
|
constructor(){
|
|
1135
|
-
super(
|
|
1136
|
+
super(4, null);
|
|
1136
1137
|
}
|
|
1137
1138
|
/** {@inheritDoc PBTypeInfo.isPointerType} */ haveAtomicMembers() {
|
|
1138
1139
|
return true;
|
|
@@ -1154,10 +1155,10 @@ var PBTypeClass;
|
|
|
1154
1155
|
throw new Error('atomic type not supported for webgl');
|
|
1155
1156
|
}
|
|
1156
1157
|
}
|
|
1157
|
-
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(
|
|
1158
|
+
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(_offset) {
|
|
1158
1159
|
return null;
|
|
1159
1160
|
}
|
|
1160
|
-
/** @internal */ getLayoutAlignment(
|
|
1161
|
+
/** @internal */ getLayoutAlignment(_layout) {
|
|
1161
1162
|
return 4;
|
|
1162
1163
|
}
|
|
1163
1164
|
/** @internal */ getLayoutSize() {
|
|
@@ -1175,7 +1176,7 @@ var PBTypeClass;
|
|
|
1175
1176
|
* @public
|
|
1176
1177
|
*/ class PBAtomicU32TypeInfo extends PBTypeInfo {
|
|
1177
1178
|
constructor(){
|
|
1178
|
-
super(
|
|
1179
|
+
super(5, null);
|
|
1179
1180
|
}
|
|
1180
1181
|
/** {@inheritDoc PBTypeInfo.isPointerType} */ haveAtomicMembers() {
|
|
1181
1182
|
return true;
|
|
@@ -1197,10 +1198,10 @@ var PBTypeClass;
|
|
|
1197
1198
|
throw new Error('atomic type not supported for webgl');
|
|
1198
1199
|
}
|
|
1199
1200
|
}
|
|
1200
|
-
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(
|
|
1201
|
+
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(_offset) {
|
|
1201
1202
|
return null;
|
|
1202
1203
|
}
|
|
1203
|
-
/** @internal */ getLayoutAlignment(
|
|
1204
|
+
/** @internal */ getLayoutAlignment(_layout) {
|
|
1204
1205
|
return 4;
|
|
1205
1206
|
}
|
|
1206
1207
|
/** @internal */ getLayoutSize() {
|
|
@@ -1218,7 +1219,7 @@ var PBTypeClass;
|
|
|
1218
1219
|
* @public
|
|
1219
1220
|
*/ class PBSamplerTypeInfo extends PBTypeInfo {
|
|
1220
1221
|
constructor(accessMode){
|
|
1221
|
-
super(
|
|
1222
|
+
super(7, {
|
|
1222
1223
|
accessMode: accessMode
|
|
1223
1224
|
});
|
|
1224
1225
|
}
|
|
@@ -1233,13 +1234,13 @@ var PBTypeClass;
|
|
|
1233
1234
|
}
|
|
1234
1235
|
/** @internal */ toTypeName(deviceType, varName) {
|
|
1235
1236
|
if (deviceType === 'webgpu') {
|
|
1236
|
-
const typename = this.accessMode ===
|
|
1237
|
+
const typename = this.accessMode === 1 ? 'sampler' : 'sampler_comparison';
|
|
1237
1238
|
return varName ? `${varName}: ${typename}` : typename;
|
|
1238
1239
|
} else {
|
|
1239
1240
|
throw new Error('sampler type not supported for webgl');
|
|
1240
1241
|
}
|
|
1241
1242
|
}
|
|
1242
|
-
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(
|
|
1243
|
+
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(_offset) {
|
|
1243
1244
|
return null;
|
|
1244
1245
|
}
|
|
1245
1246
|
/** @internal */ genTypeId() {
|
|
@@ -1251,14 +1252,14 @@ var PBTypeClass;
|
|
|
1251
1252
|
* @public
|
|
1252
1253
|
*/ class PBTextureTypeInfo extends PBTypeInfo {
|
|
1253
1254
|
constructor(textureType, texelFormat, readable, writable){
|
|
1254
|
-
super(
|
|
1255
|
+
super(6, {
|
|
1255
1256
|
textureType: textureType,
|
|
1256
|
-
readable,
|
|
1257
|
-
writable,
|
|
1258
|
-
storageTexelFormat: texelFormat
|
|
1257
|
+
readable: readable ?? false,
|
|
1258
|
+
writable: writable ?? false,
|
|
1259
|
+
storageTexelFormat: texelFormat ?? null
|
|
1259
1260
|
});
|
|
1260
|
-
|
|
1261
|
-
|
|
1261
|
+
ASSERT(!!textureTypeMapWGSL[textureType], 'unsupported texture type');
|
|
1262
|
+
ASSERT(!(textureType & BITFLAG_STORAGE) || !!texelFormat && texelFormat in storageTexelFormatMap, `invalid texel format for storage texture: ${texelFormat}`);
|
|
1262
1263
|
}
|
|
1263
1264
|
/** Get the texture type */ get textureType() {
|
|
1264
1265
|
return this.detail.textureType;
|
|
@@ -1328,12 +1329,12 @@ var PBTypeClass;
|
|
|
1328
1329
|
}
|
|
1329
1330
|
return varName ? `${varName}: ${typename}` : typename;
|
|
1330
1331
|
} else {
|
|
1331
|
-
const typename =
|
|
1332
|
-
|
|
1332
|
+
const typename = deviceType === 'webgl' ? textureTypeMapWebGL[this.textureType] : textureTypeMapWebGL2[this.textureType];
|
|
1333
|
+
ASSERT(!!typename, 'unsupported texture type');
|
|
1333
1334
|
return varName ? `${typename} ${varName}` : typename;
|
|
1334
1335
|
}
|
|
1335
1336
|
}
|
|
1336
|
-
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(
|
|
1337
|
+
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(_offset) {
|
|
1337
1338
|
return null;
|
|
1338
1339
|
}
|
|
1339
1340
|
/** @internal */ genTypeId() {
|
|
@@ -1345,7 +1346,7 @@ var PBTypeClass;
|
|
|
1345
1346
|
* @public
|
|
1346
1347
|
*/ class PBFunctionTypeInfo extends PBTypeInfo {
|
|
1347
1348
|
constructor(name, returnType, argTypes){
|
|
1348
|
-
super(
|
|
1349
|
+
super(8, {
|
|
1349
1350
|
name,
|
|
1350
1351
|
returnType,
|
|
1351
1352
|
argTypes
|
|
@@ -1366,7 +1367,7 @@ var PBTypeClass;
|
|
|
1366
1367
|
/** @internal */ genTypeId() {
|
|
1367
1368
|
return `fn(${this.argHash}):${this.returnType.typeId}`;
|
|
1368
1369
|
}
|
|
1369
|
-
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(
|
|
1370
|
+
/** {@inheritDoc PBTypeInfo.toBufferLayout} */ toBufferLayout(_offset) {
|
|
1370
1371
|
return null;
|
|
1371
1372
|
}
|
|
1372
1373
|
/** @internal */ toTypeName() {
|
|
@@ -1539,8 +1540,8 @@ var PBTypeClass;
|
|
|
1539
1540
|
/** @internal */ const typeTexDepthCube = new PBTextureTypeInfo(PBTextureType.TEX_DEPTH_CUBE);
|
|
1540
1541
|
/** @internal */ const typeTexDepthCubeArray = new PBTextureTypeInfo(PBTextureType.TEX_DEPTH_CUBE_ARRAY);
|
|
1541
1542
|
/** @internal */ const typeTexDepthMultisampled2D = new PBTextureTypeInfo(PBTextureType.TEX_DEPTH_MULTISAMPLED_2D);
|
|
1542
|
-
/** @internal */ const typeSampler = new PBSamplerTypeInfo(
|
|
1543
|
-
/** @internal */ const typeSamplerComparison = new PBSamplerTypeInfo(
|
|
1543
|
+
/** @internal */ const typeSampler = new PBSamplerTypeInfo(1);
|
|
1544
|
+
/** @internal */ const typeSamplerComparison = new PBSamplerTypeInfo(2);
|
|
1544
1545
|
/** @internal */ const typeVoid = new PBVoidTypeInfo();
|
|
1545
1546
|
/** @internal */ const typeAny = new PBAnyTypeInfo();
|
|
1546
1547
|
/** @internal */ const typeFrexpResult = new PBStructTypeInfo('FrexpResult', 'default', [
|