@luma.gl/gltf 9.0.0-alpha.54 → 9.0.0-beta.1
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/dist.dev.js +3189 -111
- package/dist.min.js +112 -106
- package/package.json +8 -8
package/dist/dist.dev.js
CHANGED
|
@@ -1048,6 +1048,12 @@ var __exports__ = (() => {
|
|
|
1048
1048
|
createCommandEncoder(props = {}) {
|
|
1049
1049
|
throw new Error("not implemented");
|
|
1050
1050
|
}
|
|
1051
|
+
readPixelsToArrayWebGL(source, options) {
|
|
1052
|
+
throw new Error("not implemented");
|
|
1053
|
+
}
|
|
1054
|
+
readPixelsToBufferWebGL2(source, options) {
|
|
1055
|
+
throw new Error("not implemented");
|
|
1056
|
+
}
|
|
1051
1057
|
_getBufferProps(props) {
|
|
1052
1058
|
if (props instanceof ArrayBuffer || ArrayBuffer.isView(props)) {
|
|
1053
1059
|
props = {
|
|
@@ -1133,10 +1139,10 @@ var __exports__ = (() => {
|
|
|
1133
1139
|
return;
|
|
1134
1140
|
}
|
|
1135
1141
|
if (!props.canvas) {
|
|
1136
|
-
const
|
|
1142
|
+
const canvas2 = createCanvas(props);
|
|
1137
1143
|
const container = getContainer(props?.container || null);
|
|
1138
|
-
container.insertBefore(
|
|
1139
|
-
this.canvas =
|
|
1144
|
+
container.insertBefore(canvas2, container.firstChild);
|
|
1145
|
+
this.canvas = canvas2;
|
|
1140
1146
|
if (!props?.visible) {
|
|
1141
1147
|
this.canvas.style.visibility = "hidden";
|
|
1142
1148
|
}
|
|
@@ -1187,8 +1193,8 @@ var __exports__ = (() => {
|
|
|
1187
1193
|
return [this.canvas.width, this.canvas.height];
|
|
1188
1194
|
case "html-canvas":
|
|
1189
1195
|
const dpr = this.getDevicePixelRatio();
|
|
1190
|
-
const
|
|
1191
|
-
return
|
|
1196
|
+
const canvas2 = this.canvas;
|
|
1197
|
+
return canvas2.parentElement ? [canvas2.clientWidth * dpr, canvas2.clientHeight * dpr] : [this.canvas.width, this.canvas.height];
|
|
1192
1198
|
default:
|
|
1193
1199
|
throw new Error(this.type);
|
|
1194
1200
|
}
|
|
@@ -1282,14 +1288,14 @@ var __exports__ = (() => {
|
|
|
1282
1288
|
return document.body;
|
|
1283
1289
|
}
|
|
1284
1290
|
function getCanvasFromDOM(canvasId) {
|
|
1285
|
-
const
|
|
1286
|
-
if (!
|
|
1291
|
+
const canvas2 = document.getElementById(canvasId);
|
|
1292
|
+
if (!canvas2 && !isPageLoaded()) {
|
|
1287
1293
|
throw new Error(`Accessing '${canvasId}' before page was loaded`);
|
|
1288
1294
|
}
|
|
1289
|
-
if (!(
|
|
1295
|
+
if (!(canvas2 instanceof HTMLCanvasElement)) {
|
|
1290
1296
|
throw new Error("Object is not a canvas element");
|
|
1291
1297
|
}
|
|
1292
|
-
return
|
|
1298
|
+
return canvas2;
|
|
1293
1299
|
}
|
|
1294
1300
|
function createCanvas(props) {
|
|
1295
1301
|
const {
|
|
@@ -2152,9 +2158,9 @@ ${htmlLog}
|
|
|
2152
2158
|
}
|
|
2153
2159
|
return arrayBuffer;
|
|
2154
2160
|
}
|
|
2155
|
-
function getScratchArray(
|
|
2156
|
-
const scratchArrayBuffer = getScratchArrayBuffer(
|
|
2157
|
-
return new
|
|
2161
|
+
function getScratchArray(Type2, length4) {
|
|
2162
|
+
const scratchArrayBuffer = getScratchArrayBuffer(Type2.BYTES_PER_ELEMENT * length4);
|
|
2163
|
+
return new Type2(scratchArrayBuffer, 0, length4);
|
|
2158
2164
|
}
|
|
2159
2165
|
function fillArray(options) {
|
|
2160
2166
|
const {
|
|
@@ -2984,13 +2990,13 @@ ${htmlLog}
|
|
|
2984
2990
|
return image;
|
|
2985
2991
|
case "image":
|
|
2986
2992
|
case "imagebitmap":
|
|
2987
|
-
const
|
|
2988
|
-
const context =
|
|
2993
|
+
const canvas2 = document.createElement("canvas");
|
|
2994
|
+
const context = canvas2.getContext("2d");
|
|
2989
2995
|
if (!context) {
|
|
2990
2996
|
throw new Error("getImageData");
|
|
2991
2997
|
}
|
|
2992
|
-
|
|
2993
|
-
|
|
2998
|
+
canvas2.width = image.width;
|
|
2999
|
+
canvas2.height = image.height;
|
|
2994
3000
|
context.drawImage(image, 0, 0);
|
|
2995
3001
|
return context.getImageData(0, 0, image.width, image.height);
|
|
2996
3002
|
default:
|
|
@@ -4091,7 +4097,7 @@ ${moduleSource}
|
|
|
4091
4097
|
};
|
|
4092
4098
|
}
|
|
4093
4099
|
function getShaderName2(shader, defaultName = "unnamed") {
|
|
4094
|
-
const SHADER_NAME_REGEXP = /#define[\
|
|
4100
|
+
const SHADER_NAME_REGEXP = /#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/;
|
|
4095
4101
|
const match = SHADER_NAME_REGEXP.exec(shader);
|
|
4096
4102
|
return match ? match[1] : defaultName;
|
|
4097
4103
|
}
|
|
@@ -4391,82 +4397,2849 @@ ${getApplicationDefines(allDefines)}
|
|
|
4391
4397
|
if (typeof shader === "string") {
|
|
4392
4398
|
return shader;
|
|
4393
4399
|
}
|
|
4394
|
-
switch (platformInfo.type) {
|
|
4395
|
-
case "webgpu":
|
|
4396
|
-
if (shader?.wgsl) {
|
|
4397
|
-
return shader.wgsl;
|
|
4400
|
+
switch (platformInfo.type) {
|
|
4401
|
+
case "webgpu":
|
|
4402
|
+
if (shader?.wgsl) {
|
|
4403
|
+
return shader.wgsl;
|
|
4404
|
+
}
|
|
4405
|
+
throw new Error("WebGPU does not support GLSL shaders");
|
|
4406
|
+
default:
|
|
4407
|
+
if (shader?.glsl) {
|
|
4408
|
+
return shader.glsl;
|
|
4409
|
+
}
|
|
4410
|
+
throw new Error("WebGL does not support WGSL shaders");
|
|
4411
|
+
}
|
|
4412
|
+
}
|
|
4413
|
+
|
|
4414
|
+
// ../shadertools/src/lib/shader-assembler.ts
|
|
4415
|
+
var ShaderAssembler = class {
|
|
4416
|
+
_hookFunctions = [];
|
|
4417
|
+
_defaultModules = [];
|
|
4418
|
+
static getDefaultShaderAssembler() {
|
|
4419
|
+
ShaderAssembler.defaultShaderAssembler = ShaderAssembler.defaultShaderAssembler || new ShaderAssembler();
|
|
4420
|
+
return ShaderAssembler.defaultShaderAssembler;
|
|
4421
|
+
}
|
|
4422
|
+
addDefaultModule(module) {
|
|
4423
|
+
if (!this._defaultModules.find((m) => m.name === (typeof module === "string" ? module : module.name))) {
|
|
4424
|
+
this._defaultModules.push(module);
|
|
4425
|
+
}
|
|
4426
|
+
}
|
|
4427
|
+
removeDefaultModule(module) {
|
|
4428
|
+
const moduleName = typeof module === "string" ? module : module.name;
|
|
4429
|
+
this._defaultModules = this._defaultModules.filter((m) => m.name !== moduleName);
|
|
4430
|
+
}
|
|
4431
|
+
addShaderHook(hook, opts) {
|
|
4432
|
+
if (opts) {
|
|
4433
|
+
hook = Object.assign(opts, {
|
|
4434
|
+
hook
|
|
4435
|
+
});
|
|
4436
|
+
}
|
|
4437
|
+
this._hookFunctions.push(hook);
|
|
4438
|
+
}
|
|
4439
|
+
assembleShaders(props) {
|
|
4440
|
+
const modules = this._getModuleList(props.modules);
|
|
4441
|
+
const hookFunctions = this._hookFunctions;
|
|
4442
|
+
const options = selectShaders(props);
|
|
4443
|
+
const assembled = assembleShaders({
|
|
4444
|
+
platformInfo: props.platformInfo,
|
|
4445
|
+
...options,
|
|
4446
|
+
modules,
|
|
4447
|
+
hookFunctions
|
|
4448
|
+
});
|
|
4449
|
+
return {
|
|
4450
|
+
...assembled,
|
|
4451
|
+
modules
|
|
4452
|
+
};
|
|
4453
|
+
}
|
|
4454
|
+
_getModuleList(appModules = []) {
|
|
4455
|
+
const modules = new Array(this._defaultModules.length + appModules.length);
|
|
4456
|
+
const seen = {};
|
|
4457
|
+
let count = 0;
|
|
4458
|
+
for (let i = 0, len2 = this._defaultModules.length; i < len2; ++i) {
|
|
4459
|
+
const module = this._defaultModules[i];
|
|
4460
|
+
const name2 = module.name;
|
|
4461
|
+
modules[count++] = module;
|
|
4462
|
+
seen[name2] = true;
|
|
4463
|
+
}
|
|
4464
|
+
for (let i = 0, len2 = appModules.length; i < len2; ++i) {
|
|
4465
|
+
const module = appModules[i];
|
|
4466
|
+
const name2 = module.name;
|
|
4467
|
+
if (!seen[name2]) {
|
|
4468
|
+
modules[count++] = module;
|
|
4469
|
+
seen[name2] = true;
|
|
4470
|
+
}
|
|
4471
|
+
}
|
|
4472
|
+
modules.length = count;
|
|
4473
|
+
return ShaderModuleInstance.instantiateModules(modules);
|
|
4474
|
+
}
|
|
4475
|
+
};
|
|
4476
|
+
|
|
4477
|
+
// ../shadertools/src/libs/wgsl-reflect/wgsl_reflect.module.js
|
|
4478
|
+
var ParseContext = class {
|
|
4479
|
+
constructor() {
|
|
4480
|
+
this.constants = /* @__PURE__ */ new Map();
|
|
4481
|
+
this.aliases = /* @__PURE__ */ new Map();
|
|
4482
|
+
this.structs = /* @__PURE__ */ new Map();
|
|
4483
|
+
}
|
|
4484
|
+
};
|
|
4485
|
+
var Node = class {
|
|
4486
|
+
constructor() {
|
|
4487
|
+
}
|
|
4488
|
+
get isAstNode() {
|
|
4489
|
+
return true;
|
|
4490
|
+
}
|
|
4491
|
+
get astNodeType() {
|
|
4492
|
+
return "";
|
|
4493
|
+
}
|
|
4494
|
+
evaluate(context) {
|
|
4495
|
+
throw new Error("Cannot evaluate node");
|
|
4496
|
+
}
|
|
4497
|
+
evaluateString(context) {
|
|
4498
|
+
return this.evaluate(context).toString();
|
|
4499
|
+
}
|
|
4500
|
+
};
|
|
4501
|
+
var Statement = class extends Node {
|
|
4502
|
+
constructor() {
|
|
4503
|
+
super();
|
|
4504
|
+
}
|
|
4505
|
+
};
|
|
4506
|
+
var Function = class extends Statement {
|
|
4507
|
+
constructor(name2, args, returnType, body) {
|
|
4508
|
+
super();
|
|
4509
|
+
this.name = name2;
|
|
4510
|
+
this.args = args;
|
|
4511
|
+
this.returnType = returnType;
|
|
4512
|
+
this.body = body;
|
|
4513
|
+
}
|
|
4514
|
+
get astNodeType() {
|
|
4515
|
+
return "function";
|
|
4516
|
+
}
|
|
4517
|
+
};
|
|
4518
|
+
var StaticAssert = class extends Statement {
|
|
4519
|
+
constructor(expression) {
|
|
4520
|
+
super();
|
|
4521
|
+
this.expression = expression;
|
|
4522
|
+
}
|
|
4523
|
+
get astNodeType() {
|
|
4524
|
+
return "staticAssert";
|
|
4525
|
+
}
|
|
4526
|
+
};
|
|
4527
|
+
var While = class extends Statement {
|
|
4528
|
+
constructor(condition, body) {
|
|
4529
|
+
super();
|
|
4530
|
+
this.condition = condition;
|
|
4531
|
+
this.body = body;
|
|
4532
|
+
}
|
|
4533
|
+
get astNodeType() {
|
|
4534
|
+
return "while";
|
|
4535
|
+
}
|
|
4536
|
+
};
|
|
4537
|
+
var Continuing = class extends Statement {
|
|
4538
|
+
constructor(body) {
|
|
4539
|
+
super();
|
|
4540
|
+
this.body = body;
|
|
4541
|
+
}
|
|
4542
|
+
get astNodeType() {
|
|
4543
|
+
return "continuing";
|
|
4544
|
+
}
|
|
4545
|
+
};
|
|
4546
|
+
var For = class extends Statement {
|
|
4547
|
+
constructor(init, condition, increment, body) {
|
|
4548
|
+
super();
|
|
4549
|
+
this.init = init;
|
|
4550
|
+
this.condition = condition;
|
|
4551
|
+
this.increment = increment;
|
|
4552
|
+
this.body = body;
|
|
4553
|
+
}
|
|
4554
|
+
get astNodeType() {
|
|
4555
|
+
return "for";
|
|
4556
|
+
}
|
|
4557
|
+
};
|
|
4558
|
+
var Var = class extends Statement {
|
|
4559
|
+
constructor(name2, type, storage, access, value) {
|
|
4560
|
+
super();
|
|
4561
|
+
this.name = name2;
|
|
4562
|
+
this.type = type;
|
|
4563
|
+
this.storage = storage;
|
|
4564
|
+
this.access = access;
|
|
4565
|
+
this.value = value;
|
|
4566
|
+
}
|
|
4567
|
+
get astNodeType() {
|
|
4568
|
+
return "var";
|
|
4569
|
+
}
|
|
4570
|
+
};
|
|
4571
|
+
var Override = class extends Statement {
|
|
4572
|
+
constructor(name2, type, value) {
|
|
4573
|
+
super();
|
|
4574
|
+
this.name = name2;
|
|
4575
|
+
this.type = type;
|
|
4576
|
+
this.value = value;
|
|
4577
|
+
}
|
|
4578
|
+
get astNodeType() {
|
|
4579
|
+
return "override";
|
|
4580
|
+
}
|
|
4581
|
+
};
|
|
4582
|
+
var Let = class extends Statement {
|
|
4583
|
+
constructor(name2, type, storage, access, value) {
|
|
4584
|
+
super();
|
|
4585
|
+
this.name = name2;
|
|
4586
|
+
this.type = type;
|
|
4587
|
+
this.storage = storage;
|
|
4588
|
+
this.access = access;
|
|
4589
|
+
this.value = value;
|
|
4590
|
+
}
|
|
4591
|
+
get astNodeType() {
|
|
4592
|
+
return "let";
|
|
4593
|
+
}
|
|
4594
|
+
};
|
|
4595
|
+
var Const = class extends Statement {
|
|
4596
|
+
constructor(name2, type, storage, access, value) {
|
|
4597
|
+
super();
|
|
4598
|
+
this.name = name2;
|
|
4599
|
+
this.type = type;
|
|
4600
|
+
this.storage = storage;
|
|
4601
|
+
this.access = access;
|
|
4602
|
+
this.value = value;
|
|
4603
|
+
}
|
|
4604
|
+
get astNodeType() {
|
|
4605
|
+
return "const";
|
|
4606
|
+
}
|
|
4607
|
+
evaluate(context) {
|
|
4608
|
+
return this.value.evaluate(context);
|
|
4609
|
+
}
|
|
4610
|
+
};
|
|
4611
|
+
var IncrementOperator;
|
|
4612
|
+
(function(IncrementOperator2) {
|
|
4613
|
+
IncrementOperator2["increment"] = "++";
|
|
4614
|
+
IncrementOperator2["decrement"] = "--";
|
|
4615
|
+
})(IncrementOperator || (IncrementOperator = {}));
|
|
4616
|
+
(function(IncrementOperator2) {
|
|
4617
|
+
function parse(val) {
|
|
4618
|
+
const key = val;
|
|
4619
|
+
if (key == "parse")
|
|
4620
|
+
throw new Error("Invalid value for IncrementOperator");
|
|
4621
|
+
return IncrementOperator2[key];
|
|
4622
|
+
}
|
|
4623
|
+
IncrementOperator2.parse = parse;
|
|
4624
|
+
})(IncrementOperator || (IncrementOperator = {}));
|
|
4625
|
+
var Increment = class extends Statement {
|
|
4626
|
+
constructor(operator, variable) {
|
|
4627
|
+
super();
|
|
4628
|
+
this.operator = operator;
|
|
4629
|
+
this.variable = variable;
|
|
4630
|
+
}
|
|
4631
|
+
get astNodeType() {
|
|
4632
|
+
return "increment";
|
|
4633
|
+
}
|
|
4634
|
+
};
|
|
4635
|
+
var AssignOperator;
|
|
4636
|
+
(function(AssignOperator2) {
|
|
4637
|
+
AssignOperator2["assign"] = "=";
|
|
4638
|
+
AssignOperator2["addAssign"] = "+=";
|
|
4639
|
+
AssignOperator2["subtractAssin"] = "-=";
|
|
4640
|
+
AssignOperator2["multiplyAssign"] = "*=";
|
|
4641
|
+
AssignOperator2["divideAssign"] = "/=";
|
|
4642
|
+
AssignOperator2["moduloAssign"] = "%=";
|
|
4643
|
+
AssignOperator2["andAssign"] = "&=";
|
|
4644
|
+
AssignOperator2["orAssign"] = "|=";
|
|
4645
|
+
AssignOperator2["xorAssign"] = "^=";
|
|
4646
|
+
AssignOperator2["shiftLeftAssign"] = "<<=";
|
|
4647
|
+
AssignOperator2["shiftRightAssign"] = ">>=";
|
|
4648
|
+
})(AssignOperator || (AssignOperator = {}));
|
|
4649
|
+
(function(AssignOperator2) {
|
|
4650
|
+
function parse(val) {
|
|
4651
|
+
const key = val;
|
|
4652
|
+
if (key == "parse")
|
|
4653
|
+
throw new Error("Invalid value for AssignOperator");
|
|
4654
|
+
return AssignOperator2[key];
|
|
4655
|
+
}
|
|
4656
|
+
AssignOperator2.parse = parse;
|
|
4657
|
+
})(AssignOperator || (AssignOperator = {}));
|
|
4658
|
+
var Assign = class extends Statement {
|
|
4659
|
+
constructor(operator, variable, value) {
|
|
4660
|
+
super();
|
|
4661
|
+
this.operator = operator;
|
|
4662
|
+
this.variable = variable;
|
|
4663
|
+
this.value = value;
|
|
4664
|
+
}
|
|
4665
|
+
get astNodeType() {
|
|
4666
|
+
return "assign";
|
|
4667
|
+
}
|
|
4668
|
+
};
|
|
4669
|
+
var Call = class extends Statement {
|
|
4670
|
+
constructor(name2, args) {
|
|
4671
|
+
super();
|
|
4672
|
+
this.name = name2;
|
|
4673
|
+
this.args = args;
|
|
4674
|
+
}
|
|
4675
|
+
get astNodeType() {
|
|
4676
|
+
return "call";
|
|
4677
|
+
}
|
|
4678
|
+
};
|
|
4679
|
+
var Loop = class extends Statement {
|
|
4680
|
+
constructor(body, continuing) {
|
|
4681
|
+
super();
|
|
4682
|
+
this.body = body;
|
|
4683
|
+
this.continuing = continuing;
|
|
4684
|
+
}
|
|
4685
|
+
get astNodeType() {
|
|
4686
|
+
return "loop";
|
|
4687
|
+
}
|
|
4688
|
+
};
|
|
4689
|
+
var Switch = class extends Statement {
|
|
4690
|
+
constructor(condition, body) {
|
|
4691
|
+
super();
|
|
4692
|
+
this.condition = condition;
|
|
4693
|
+
this.body = body;
|
|
4694
|
+
}
|
|
4695
|
+
get astNodeType() {
|
|
4696
|
+
return "body";
|
|
4697
|
+
}
|
|
4698
|
+
};
|
|
4699
|
+
var If = class extends Statement {
|
|
4700
|
+
constructor(condition, body, elseif, _else) {
|
|
4701
|
+
super();
|
|
4702
|
+
this.condition = condition;
|
|
4703
|
+
this.body = body;
|
|
4704
|
+
this.elseif = elseif;
|
|
4705
|
+
this.else = _else;
|
|
4706
|
+
}
|
|
4707
|
+
get astNodeType() {
|
|
4708
|
+
return "if";
|
|
4709
|
+
}
|
|
4710
|
+
};
|
|
4711
|
+
var Return = class extends Statement {
|
|
4712
|
+
constructor(value) {
|
|
4713
|
+
super();
|
|
4714
|
+
this.value = value;
|
|
4715
|
+
}
|
|
4716
|
+
get astNodeType() {
|
|
4717
|
+
return "return";
|
|
4718
|
+
}
|
|
4719
|
+
};
|
|
4720
|
+
var Enable = class extends Statement {
|
|
4721
|
+
constructor(name2) {
|
|
4722
|
+
super();
|
|
4723
|
+
this.name = name2;
|
|
4724
|
+
}
|
|
4725
|
+
get astNodeType() {
|
|
4726
|
+
return "enable";
|
|
4727
|
+
}
|
|
4728
|
+
};
|
|
4729
|
+
var Alias = class extends Statement {
|
|
4730
|
+
constructor(name2, type) {
|
|
4731
|
+
super();
|
|
4732
|
+
this.name = name2;
|
|
4733
|
+
this.type = type;
|
|
4734
|
+
}
|
|
4735
|
+
get astNodeType() {
|
|
4736
|
+
return "alias";
|
|
4737
|
+
}
|
|
4738
|
+
};
|
|
4739
|
+
var Discard = class extends Statement {
|
|
4740
|
+
constructor() {
|
|
4741
|
+
super();
|
|
4742
|
+
}
|
|
4743
|
+
get astNodeType() {
|
|
4744
|
+
return "discard";
|
|
4745
|
+
}
|
|
4746
|
+
};
|
|
4747
|
+
var Break = class extends Statement {
|
|
4748
|
+
constructor() {
|
|
4749
|
+
super();
|
|
4750
|
+
}
|
|
4751
|
+
get astNodeType() {
|
|
4752
|
+
return "break";
|
|
4753
|
+
}
|
|
4754
|
+
};
|
|
4755
|
+
var Continue = class extends Statement {
|
|
4756
|
+
constructor() {
|
|
4757
|
+
super();
|
|
4758
|
+
}
|
|
4759
|
+
get astNodeType() {
|
|
4760
|
+
return "continue";
|
|
4761
|
+
}
|
|
4762
|
+
};
|
|
4763
|
+
var Type = class extends Statement {
|
|
4764
|
+
constructor(name2) {
|
|
4765
|
+
super();
|
|
4766
|
+
this.name = name2;
|
|
4767
|
+
}
|
|
4768
|
+
get astNodeType() {
|
|
4769
|
+
return "type";
|
|
4770
|
+
}
|
|
4771
|
+
get isStruct() {
|
|
4772
|
+
return false;
|
|
4773
|
+
}
|
|
4774
|
+
get isArray() {
|
|
4775
|
+
return false;
|
|
4776
|
+
}
|
|
4777
|
+
};
|
|
4778
|
+
var Struct = class extends Type {
|
|
4779
|
+
constructor(name2, members) {
|
|
4780
|
+
super(name2);
|
|
4781
|
+
this.members = members;
|
|
4782
|
+
}
|
|
4783
|
+
get astNodeType() {
|
|
4784
|
+
return "struct";
|
|
4785
|
+
}
|
|
4786
|
+
get isStruct() {
|
|
4787
|
+
return true;
|
|
4788
|
+
}
|
|
4789
|
+
getMemberIndex(name2) {
|
|
4790
|
+
for (let i = 0; i < this.members.length; i++) {
|
|
4791
|
+
if (this.members[i].name == name2)
|
|
4792
|
+
return i;
|
|
4793
|
+
}
|
|
4794
|
+
return -1;
|
|
4795
|
+
}
|
|
4796
|
+
};
|
|
4797
|
+
var TemplateType = class extends Type {
|
|
4798
|
+
constructor(name2, format, access) {
|
|
4799
|
+
super(name2);
|
|
4800
|
+
this.format = format;
|
|
4801
|
+
this.access = access;
|
|
4802
|
+
}
|
|
4803
|
+
get astNodeType() {
|
|
4804
|
+
return "template";
|
|
4805
|
+
}
|
|
4806
|
+
};
|
|
4807
|
+
var PointerType = class extends Type {
|
|
4808
|
+
constructor(name2, storage, type, access) {
|
|
4809
|
+
super(name2);
|
|
4810
|
+
this.storage = storage;
|
|
4811
|
+
this.type = type;
|
|
4812
|
+
this.access = access;
|
|
4813
|
+
}
|
|
4814
|
+
get astNodeType() {
|
|
4815
|
+
return "pointer";
|
|
4816
|
+
}
|
|
4817
|
+
};
|
|
4818
|
+
var ArrayType = class extends Type {
|
|
4819
|
+
constructor(name2, attributes, format, count) {
|
|
4820
|
+
super(name2);
|
|
4821
|
+
this.attributes = attributes;
|
|
4822
|
+
this.format = format;
|
|
4823
|
+
this.count = count;
|
|
4824
|
+
}
|
|
4825
|
+
get astNodeType() {
|
|
4826
|
+
return "array";
|
|
4827
|
+
}
|
|
4828
|
+
get isArray() {
|
|
4829
|
+
return true;
|
|
4830
|
+
}
|
|
4831
|
+
};
|
|
4832
|
+
var SamplerType = class extends Type {
|
|
4833
|
+
constructor(name2, format, access) {
|
|
4834
|
+
super(name2);
|
|
4835
|
+
this.format = format;
|
|
4836
|
+
this.access = access;
|
|
4837
|
+
}
|
|
4838
|
+
get astNodeType() {
|
|
4839
|
+
return "sampler";
|
|
4840
|
+
}
|
|
4841
|
+
};
|
|
4842
|
+
var Expression = class extends Node {
|
|
4843
|
+
constructor() {
|
|
4844
|
+
super();
|
|
4845
|
+
}
|
|
4846
|
+
};
|
|
4847
|
+
var StringExpr = class extends Expression {
|
|
4848
|
+
constructor(value) {
|
|
4849
|
+
super();
|
|
4850
|
+
this.value = value;
|
|
4851
|
+
}
|
|
4852
|
+
get astNodeType() {
|
|
4853
|
+
return "stringExpr";
|
|
4854
|
+
}
|
|
4855
|
+
toString() {
|
|
4856
|
+
return this.value;
|
|
4857
|
+
}
|
|
4858
|
+
evaluateString() {
|
|
4859
|
+
return this.value;
|
|
4860
|
+
}
|
|
4861
|
+
};
|
|
4862
|
+
var CreateExpr = class extends Expression {
|
|
4863
|
+
constructor(type, args) {
|
|
4864
|
+
super();
|
|
4865
|
+
this.type = type;
|
|
4866
|
+
this.args = args;
|
|
4867
|
+
}
|
|
4868
|
+
get astNodeType() {
|
|
4869
|
+
return "createExpr";
|
|
4870
|
+
}
|
|
4871
|
+
};
|
|
4872
|
+
var CallExpr = class extends Expression {
|
|
4873
|
+
constructor(name2, args) {
|
|
4874
|
+
super();
|
|
4875
|
+
this.name = name2;
|
|
4876
|
+
this.args = args;
|
|
4877
|
+
}
|
|
4878
|
+
get astNodeType() {
|
|
4879
|
+
return "callExpr";
|
|
4880
|
+
}
|
|
4881
|
+
evaluate(context) {
|
|
4882
|
+
switch (this.name) {
|
|
4883
|
+
case "abs":
|
|
4884
|
+
return Math.abs(this.args[0].evaluate(context));
|
|
4885
|
+
case "acos":
|
|
4886
|
+
return Math.acos(this.args[0].evaluate(context));
|
|
4887
|
+
case "acosh":
|
|
4888
|
+
return Math.acosh(this.args[0].evaluate(context));
|
|
4889
|
+
case "asin":
|
|
4890
|
+
return Math.asin(this.args[0].evaluate(context));
|
|
4891
|
+
case "asinh":
|
|
4892
|
+
return Math.asinh(this.args[0].evaluate(context));
|
|
4893
|
+
case "atan":
|
|
4894
|
+
return Math.atan(this.args[0].evaluate(context));
|
|
4895
|
+
case "atan2":
|
|
4896
|
+
return Math.atan2(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
4897
|
+
case "atanh":
|
|
4898
|
+
return Math.atanh(this.args[0].evaluate(context));
|
|
4899
|
+
case "ceil":
|
|
4900
|
+
return Math.ceil(this.args[0].evaluate(context));
|
|
4901
|
+
case "clamp":
|
|
4902
|
+
return Math.min(Math.max(this.args[0].evaluate(context), this.args[1].evaluate(context)), this.args[2].evaluate(context));
|
|
4903
|
+
case "cos":
|
|
4904
|
+
return Math.cos(this.args[0].evaluate(context));
|
|
4905
|
+
case "degrees":
|
|
4906
|
+
return this.args[0].evaluate(context) * 180 / Math.PI;
|
|
4907
|
+
case "distance":
|
|
4908
|
+
return Math.sqrt(Math.pow(this.args[0].evaluate(context) - this.args[1].evaluate(context), 2));
|
|
4909
|
+
case "dot":
|
|
4910
|
+
case "exp":
|
|
4911
|
+
return Math.exp(this.args[0].evaluate(context));
|
|
4912
|
+
case "exp2":
|
|
4913
|
+
return Math.pow(2, this.args[0].evaluate(context));
|
|
4914
|
+
case "floor":
|
|
4915
|
+
return Math.floor(this.args[0].evaluate(context));
|
|
4916
|
+
case "fma":
|
|
4917
|
+
return this.args[0].evaluate(context) * this.args[1].evaluate(context) + this.args[2].evaluate(context);
|
|
4918
|
+
case "fract":
|
|
4919
|
+
return this.args[0].evaluate(context) - Math.floor(this.args[0].evaluate(context));
|
|
4920
|
+
case "inverseSqrt":
|
|
4921
|
+
return 1 / Math.sqrt(this.args[0].evaluate(context));
|
|
4922
|
+
case "log":
|
|
4923
|
+
return Math.log(this.args[0].evaluate(context));
|
|
4924
|
+
case "log2":
|
|
4925
|
+
return Math.log2(this.args[0].evaluate(context));
|
|
4926
|
+
case "max":
|
|
4927
|
+
return Math.max(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
4928
|
+
case "min":
|
|
4929
|
+
return Math.min(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
4930
|
+
case "mix":
|
|
4931
|
+
return this.args[0].evaluate(context) * (1 - this.args[2].evaluate(context)) + this.args[1].evaluate(context) * this.args[2].evaluate(context);
|
|
4932
|
+
case "modf":
|
|
4933
|
+
return this.args[0].evaluate(context) - Math.floor(this.args[0].evaluate(context));
|
|
4934
|
+
case "pow":
|
|
4935
|
+
return Math.pow(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
4936
|
+
case "radians":
|
|
4937
|
+
return this.args[0].evaluate(context) * Math.PI / 180;
|
|
4938
|
+
case "round":
|
|
4939
|
+
return Math.round(this.args[0].evaluate(context));
|
|
4940
|
+
case "sign":
|
|
4941
|
+
return Math.sign(this.args[0].evaluate(context));
|
|
4942
|
+
case "sin":
|
|
4943
|
+
return Math.sin(this.args[0].evaluate(context));
|
|
4944
|
+
case "sinh":
|
|
4945
|
+
return Math.sinh(this.args[0].evaluate(context));
|
|
4946
|
+
case "saturate":
|
|
4947
|
+
return Math.min(Math.max(this.args[0].evaluate(context), 0), 1);
|
|
4948
|
+
case "smoothstep":
|
|
4949
|
+
return this.args[0].evaluate(context) * this.args[0].evaluate(context) * (3 - 2 * this.args[0].evaluate(context));
|
|
4950
|
+
case "sqrt":
|
|
4951
|
+
return Math.sqrt(this.args[0].evaluate(context));
|
|
4952
|
+
case "step":
|
|
4953
|
+
return this.args[0].evaluate(context) < this.args[1].evaluate(context) ? 0 : 1;
|
|
4954
|
+
case "tan":
|
|
4955
|
+
return Math.tan(this.args[0].evaluate(context));
|
|
4956
|
+
case "tanh":
|
|
4957
|
+
return Math.tanh(this.args[0].evaluate(context));
|
|
4958
|
+
case "trunc":
|
|
4959
|
+
return Math.trunc(this.args[0].evaluate(context));
|
|
4960
|
+
default:
|
|
4961
|
+
throw new Error("Non const function: " + this.name);
|
|
4962
|
+
}
|
|
4963
|
+
}
|
|
4964
|
+
};
|
|
4965
|
+
var VariableExpr = class extends Expression {
|
|
4966
|
+
constructor(name2) {
|
|
4967
|
+
super();
|
|
4968
|
+
this.name = name2;
|
|
4969
|
+
}
|
|
4970
|
+
get astNodeType() {
|
|
4971
|
+
return "varExpr";
|
|
4972
|
+
}
|
|
4973
|
+
};
|
|
4974
|
+
var ConstExpr = class extends Expression {
|
|
4975
|
+
constructor(name2, initializer) {
|
|
4976
|
+
super();
|
|
4977
|
+
this.name = name2;
|
|
4978
|
+
this.initializer = initializer;
|
|
4979
|
+
}
|
|
4980
|
+
get astNodeType() {
|
|
4981
|
+
return "constExpr";
|
|
4982
|
+
}
|
|
4983
|
+
evaluate(context) {
|
|
4984
|
+
var _a2, _b;
|
|
4985
|
+
if (this.initializer instanceof CreateExpr) {
|
|
4986
|
+
const property = (_a2 = this.postfix) === null || _a2 === void 0 ? void 0 : _a2.evaluateString(context);
|
|
4987
|
+
const type = (_b = this.initializer.type) === null || _b === void 0 ? void 0 : _b.name;
|
|
4988
|
+
const struct = context.structs.get(type);
|
|
4989
|
+
const memberIndex = struct === null || struct === void 0 ? void 0 : struct.getMemberIndex(property);
|
|
4990
|
+
if (memberIndex != -1) {
|
|
4991
|
+
const value = this.initializer.args[memberIndex].evaluate(context);
|
|
4992
|
+
return value;
|
|
4993
|
+
}
|
|
4994
|
+
console.log(memberIndex);
|
|
4995
|
+
}
|
|
4996
|
+
return this.initializer.evaluate(context);
|
|
4997
|
+
}
|
|
4998
|
+
};
|
|
4999
|
+
var LiteralExpr = class extends Expression {
|
|
5000
|
+
constructor(value) {
|
|
5001
|
+
super();
|
|
5002
|
+
this.value = value;
|
|
5003
|
+
}
|
|
5004
|
+
get astNodeType() {
|
|
5005
|
+
return "literalExpr";
|
|
5006
|
+
}
|
|
5007
|
+
evaluate() {
|
|
5008
|
+
return this.value;
|
|
5009
|
+
}
|
|
5010
|
+
};
|
|
5011
|
+
var BitcastExpr = class extends Expression {
|
|
5012
|
+
constructor(type, value) {
|
|
5013
|
+
super();
|
|
5014
|
+
this.type = type;
|
|
5015
|
+
this.value = value;
|
|
5016
|
+
}
|
|
5017
|
+
get astNodeType() {
|
|
5018
|
+
return "bitcastExpr";
|
|
5019
|
+
}
|
|
5020
|
+
};
|
|
5021
|
+
var TypecastExpr = class extends Expression {
|
|
5022
|
+
constructor(type, args) {
|
|
5023
|
+
super();
|
|
5024
|
+
this.type = type;
|
|
5025
|
+
this.args = args;
|
|
5026
|
+
}
|
|
5027
|
+
get astNodeType() {
|
|
5028
|
+
return "typecastExpr";
|
|
5029
|
+
}
|
|
5030
|
+
evaluate(context) {
|
|
5031
|
+
return this.args[0].evaluate(context);
|
|
5032
|
+
}
|
|
5033
|
+
};
|
|
5034
|
+
var GroupingExpr = class extends Expression {
|
|
5035
|
+
constructor(contents) {
|
|
5036
|
+
super();
|
|
5037
|
+
this.contents = contents;
|
|
5038
|
+
}
|
|
5039
|
+
get astNodeType() {
|
|
5040
|
+
return "groupExpr";
|
|
5041
|
+
}
|
|
5042
|
+
evaluate(context) {
|
|
5043
|
+
return this.contents[0].evaluate(context);
|
|
5044
|
+
}
|
|
5045
|
+
};
|
|
5046
|
+
var Operator = class extends Expression {
|
|
5047
|
+
constructor() {
|
|
5048
|
+
super();
|
|
5049
|
+
}
|
|
5050
|
+
};
|
|
5051
|
+
var UnaryOperator = class extends Operator {
|
|
5052
|
+
constructor(operator, right) {
|
|
5053
|
+
super();
|
|
5054
|
+
this.operator = operator;
|
|
5055
|
+
this.right = right;
|
|
5056
|
+
}
|
|
5057
|
+
get astNodeType() {
|
|
5058
|
+
return "unaryOp";
|
|
5059
|
+
}
|
|
5060
|
+
evaluate(context) {
|
|
5061
|
+
switch (this.operator) {
|
|
5062
|
+
case "+":
|
|
5063
|
+
return this.right.evaluate(context);
|
|
5064
|
+
case "-":
|
|
5065
|
+
return -this.right.evaluate(context);
|
|
5066
|
+
case "!":
|
|
5067
|
+
return this.right.evaluate(context) ? 0 : 1;
|
|
5068
|
+
case "~":
|
|
5069
|
+
return ~this.right.evaluate(context);
|
|
5070
|
+
default:
|
|
5071
|
+
throw new Error("Unknown unary operator: " + this.operator);
|
|
5072
|
+
}
|
|
5073
|
+
}
|
|
5074
|
+
};
|
|
5075
|
+
var BinaryOperator = class extends Operator {
|
|
5076
|
+
constructor(operator, left, right) {
|
|
5077
|
+
super();
|
|
5078
|
+
this.operator = operator;
|
|
5079
|
+
this.left = left;
|
|
5080
|
+
this.right = right;
|
|
5081
|
+
}
|
|
5082
|
+
get astNodeType() {
|
|
5083
|
+
return "binaryOp";
|
|
5084
|
+
}
|
|
5085
|
+
evaluate(context) {
|
|
5086
|
+
switch (this.operator) {
|
|
5087
|
+
case "+":
|
|
5088
|
+
return this.left.evaluate(context) + this.right.evaluate(context);
|
|
5089
|
+
case "-":
|
|
5090
|
+
return this.left.evaluate(context) - this.right.evaluate(context);
|
|
5091
|
+
case "*":
|
|
5092
|
+
return this.left.evaluate(context) * this.right.evaluate(context);
|
|
5093
|
+
case "/":
|
|
5094
|
+
return this.left.evaluate(context) / this.right.evaluate(context);
|
|
5095
|
+
case "%":
|
|
5096
|
+
return this.left.evaluate(context) % this.right.evaluate(context);
|
|
5097
|
+
case "==":
|
|
5098
|
+
return this.left.evaluate(context) == this.right.evaluate(context) ? 1 : 0;
|
|
5099
|
+
case "!=":
|
|
5100
|
+
return this.left.evaluate(context) != this.right.evaluate(context) ? 1 : 0;
|
|
5101
|
+
case "<":
|
|
5102
|
+
return this.left.evaluate(context) < this.right.evaluate(context) ? 1 : 0;
|
|
5103
|
+
case ">":
|
|
5104
|
+
return this.left.evaluate(context) > this.right.evaluate(context) ? 1 : 0;
|
|
5105
|
+
case "<=":
|
|
5106
|
+
return this.left.evaluate(context) <= this.right.evaluate(context) ? 1 : 0;
|
|
5107
|
+
case ">=":
|
|
5108
|
+
return this.left.evaluate(context) >= this.right.evaluate(context) ? 1 : 0;
|
|
5109
|
+
case "&&":
|
|
5110
|
+
return this.left.evaluate(context) && this.right.evaluate(context) ? 1 : 0;
|
|
5111
|
+
case "||":
|
|
5112
|
+
return this.left.evaluate(context) || this.right.evaluate(context) ? 1 : 0;
|
|
5113
|
+
default:
|
|
5114
|
+
throw new Error(`Unknown operator ${this.operator}`);
|
|
5115
|
+
}
|
|
5116
|
+
}
|
|
5117
|
+
};
|
|
5118
|
+
var SwitchCase = class extends Node {
|
|
5119
|
+
constructor() {
|
|
5120
|
+
super();
|
|
5121
|
+
}
|
|
5122
|
+
};
|
|
5123
|
+
var Case = class extends SwitchCase {
|
|
5124
|
+
constructor(selector, body) {
|
|
5125
|
+
super();
|
|
5126
|
+
this.selector = selector;
|
|
5127
|
+
this.body = body;
|
|
5128
|
+
}
|
|
5129
|
+
get astNodeType() {
|
|
5130
|
+
return "case";
|
|
5131
|
+
}
|
|
5132
|
+
};
|
|
5133
|
+
var Default = class extends SwitchCase {
|
|
5134
|
+
constructor(body) {
|
|
5135
|
+
super();
|
|
5136
|
+
this.body = body;
|
|
5137
|
+
}
|
|
5138
|
+
get astNodeType() {
|
|
5139
|
+
return "default";
|
|
5140
|
+
}
|
|
5141
|
+
};
|
|
5142
|
+
var Argument = class extends Node {
|
|
5143
|
+
constructor(name2, type, attributes) {
|
|
5144
|
+
super();
|
|
5145
|
+
this.name = name2;
|
|
5146
|
+
this.type = type;
|
|
5147
|
+
this.attributes = attributes;
|
|
5148
|
+
}
|
|
5149
|
+
get astNodeType() {
|
|
5150
|
+
return "argument";
|
|
5151
|
+
}
|
|
5152
|
+
};
|
|
5153
|
+
var ElseIf = class extends Node {
|
|
5154
|
+
constructor(condition, body) {
|
|
5155
|
+
super();
|
|
5156
|
+
this.condition = condition;
|
|
5157
|
+
this.body = body;
|
|
5158
|
+
}
|
|
5159
|
+
get astNodeType() {
|
|
5160
|
+
return "elseif";
|
|
5161
|
+
}
|
|
5162
|
+
};
|
|
5163
|
+
var Member = class extends Node {
|
|
5164
|
+
constructor(name2, type, attributes) {
|
|
5165
|
+
super();
|
|
5166
|
+
this.name = name2;
|
|
5167
|
+
this.type = type;
|
|
5168
|
+
this.attributes = attributes;
|
|
5169
|
+
}
|
|
5170
|
+
get astNodeType() {
|
|
5171
|
+
return "member";
|
|
5172
|
+
}
|
|
5173
|
+
};
|
|
5174
|
+
var Attribute = class extends Node {
|
|
5175
|
+
constructor(name2, value) {
|
|
5176
|
+
super();
|
|
5177
|
+
this.name = name2;
|
|
5178
|
+
this.value = value;
|
|
5179
|
+
}
|
|
5180
|
+
get astNodeType() {
|
|
5181
|
+
return "attribute";
|
|
5182
|
+
}
|
|
5183
|
+
};
|
|
5184
|
+
var _a;
|
|
5185
|
+
var TokenClass;
|
|
5186
|
+
(function(TokenClass2) {
|
|
5187
|
+
TokenClass2[TokenClass2["token"] = 0] = "token";
|
|
5188
|
+
TokenClass2[TokenClass2["keyword"] = 1] = "keyword";
|
|
5189
|
+
TokenClass2[TokenClass2["reserved"] = 2] = "reserved";
|
|
5190
|
+
})(TokenClass || (TokenClass = {}));
|
|
5191
|
+
var TokenType = class {
|
|
5192
|
+
constructor(name2, type, rule) {
|
|
5193
|
+
this.name = name2;
|
|
5194
|
+
this.type = type;
|
|
5195
|
+
this.rule = rule;
|
|
5196
|
+
}
|
|
5197
|
+
toString() {
|
|
5198
|
+
return this.name;
|
|
5199
|
+
}
|
|
5200
|
+
};
|
|
5201
|
+
var TokenTypes = class {
|
|
5202
|
+
};
|
|
5203
|
+
_a = TokenTypes;
|
|
5204
|
+
TokenTypes.none = new TokenType("", TokenClass.reserved, "");
|
|
5205
|
+
TokenTypes.eof = new TokenType("EOF", TokenClass.token, "");
|
|
5206
|
+
TokenTypes.reserved = {
|
|
5207
|
+
asm: new TokenType("asm", TokenClass.reserved, "asm"),
|
|
5208
|
+
bf16: new TokenType("bf16", TokenClass.reserved, "bf16"),
|
|
5209
|
+
do: new TokenType("do", TokenClass.reserved, "do"),
|
|
5210
|
+
enum: new TokenType("enum", TokenClass.reserved, "enum"),
|
|
5211
|
+
f16: new TokenType("f16", TokenClass.reserved, "f16"),
|
|
5212
|
+
f64: new TokenType("f64", TokenClass.reserved, "f64"),
|
|
5213
|
+
handle: new TokenType("handle", TokenClass.reserved, "handle"),
|
|
5214
|
+
i8: new TokenType("i8", TokenClass.reserved, "i8"),
|
|
5215
|
+
i16: new TokenType("i16", TokenClass.reserved, "i16"),
|
|
5216
|
+
i64: new TokenType("i64", TokenClass.reserved, "i64"),
|
|
5217
|
+
mat: new TokenType("mat", TokenClass.reserved, "mat"),
|
|
5218
|
+
premerge: new TokenType("premerge", TokenClass.reserved, "premerge"),
|
|
5219
|
+
regardless: new TokenType("regardless", TokenClass.reserved, "regardless"),
|
|
5220
|
+
typedef: new TokenType("typedef", TokenClass.reserved, "typedef"),
|
|
5221
|
+
u8: new TokenType("u8", TokenClass.reserved, "u8"),
|
|
5222
|
+
u16: new TokenType("u16", TokenClass.reserved, "u16"),
|
|
5223
|
+
u64: new TokenType("u64", TokenClass.reserved, "u64"),
|
|
5224
|
+
unless: new TokenType("unless", TokenClass.reserved, "unless"),
|
|
5225
|
+
using: new TokenType("using", TokenClass.reserved, "using"),
|
|
5226
|
+
vec: new TokenType("vec", TokenClass.reserved, "vec"),
|
|
5227
|
+
void: new TokenType("void", TokenClass.reserved, "void")
|
|
5228
|
+
};
|
|
5229
|
+
TokenTypes.keywords = {
|
|
5230
|
+
array: new TokenType("array", TokenClass.keyword, "array"),
|
|
5231
|
+
atomic: new TokenType("atomic", TokenClass.keyword, "atomic"),
|
|
5232
|
+
bool: new TokenType("bool", TokenClass.keyword, "bool"),
|
|
5233
|
+
f32: new TokenType("f32", TokenClass.keyword, "f32"),
|
|
5234
|
+
i32: new TokenType("i32", TokenClass.keyword, "i32"),
|
|
5235
|
+
mat2x2: new TokenType("mat2x2", TokenClass.keyword, "mat2x2"),
|
|
5236
|
+
mat2x3: new TokenType("mat2x3", TokenClass.keyword, "mat2x3"),
|
|
5237
|
+
mat2x4: new TokenType("mat2x4", TokenClass.keyword, "mat2x4"),
|
|
5238
|
+
mat3x2: new TokenType("mat3x2", TokenClass.keyword, "mat3x2"),
|
|
5239
|
+
mat3x3: new TokenType("mat3x3", TokenClass.keyword, "mat3x3"),
|
|
5240
|
+
mat3x4: new TokenType("mat3x4", TokenClass.keyword, "mat3x4"),
|
|
5241
|
+
mat4x2: new TokenType("mat4x2", TokenClass.keyword, "mat4x2"),
|
|
5242
|
+
mat4x3: new TokenType("mat4x3", TokenClass.keyword, "mat4x3"),
|
|
5243
|
+
mat4x4: new TokenType("mat4x4", TokenClass.keyword, "mat4x4"),
|
|
5244
|
+
ptr: new TokenType("ptr", TokenClass.keyword, "ptr"),
|
|
5245
|
+
sampler: new TokenType("sampler", TokenClass.keyword, "sampler"),
|
|
5246
|
+
sampler_comparison: new TokenType("sampler_comparison", TokenClass.keyword, "sampler_comparison"),
|
|
5247
|
+
struct: new TokenType("struct", TokenClass.keyword, "struct"),
|
|
5248
|
+
texture_1d: new TokenType("texture_1d", TokenClass.keyword, "texture_1d"),
|
|
5249
|
+
texture_2d: new TokenType("texture_2d", TokenClass.keyword, "texture_2d"),
|
|
5250
|
+
texture_2d_array: new TokenType("texture_2d_array", TokenClass.keyword, "texture_2d_array"),
|
|
5251
|
+
texture_3d: new TokenType("texture_3d", TokenClass.keyword, "texture_3d"),
|
|
5252
|
+
texture_cube: new TokenType("texture_cube", TokenClass.keyword, "texture_cube"),
|
|
5253
|
+
texture_cube_array: new TokenType("texture_cube_array", TokenClass.keyword, "texture_cube_array"),
|
|
5254
|
+
texture_multisampled_2d: new TokenType("texture_multisampled_2d", TokenClass.keyword, "texture_multisampled_2d"),
|
|
5255
|
+
texture_storage_1d: new TokenType("texture_storage_1d", TokenClass.keyword, "texture_storage_1d"),
|
|
5256
|
+
texture_storage_2d: new TokenType("texture_storage_2d", TokenClass.keyword, "texture_storage_2d"),
|
|
5257
|
+
texture_storage_2d_array: new TokenType("texture_storage_2d_array", TokenClass.keyword, "texture_storage_2d_array"),
|
|
5258
|
+
texture_storage_3d: new TokenType("texture_storage_3d", TokenClass.keyword, "texture_storage_3d"),
|
|
5259
|
+
texture_depth_2d: new TokenType("texture_depth_2d", TokenClass.keyword, "texture_depth_2d"),
|
|
5260
|
+
texture_depth_2d_array: new TokenType("texture_depth_2d_array", TokenClass.keyword, "texture_depth_2d_array"),
|
|
5261
|
+
texture_depth_cube: new TokenType("texture_depth_cube", TokenClass.keyword, "texture_depth_cube"),
|
|
5262
|
+
texture_depth_cube_array: new TokenType("texture_depth_cube_array", TokenClass.keyword, "texture_depth_cube_array"),
|
|
5263
|
+
texture_depth_multisampled_2d: new TokenType("texture_depth_multisampled_2d", TokenClass.keyword, "texture_depth_multisampled_2d"),
|
|
5264
|
+
texture_external: new TokenType("texture_external", TokenClass.keyword, "texture_external"),
|
|
5265
|
+
u32: new TokenType("u32", TokenClass.keyword, "u32"),
|
|
5266
|
+
vec2: new TokenType("vec2", TokenClass.keyword, "vec2"),
|
|
5267
|
+
vec3: new TokenType("vec3", TokenClass.keyword, "vec3"),
|
|
5268
|
+
vec4: new TokenType("vec4", TokenClass.keyword, "vec4"),
|
|
5269
|
+
bitcast: new TokenType("bitcast", TokenClass.keyword, "bitcast"),
|
|
5270
|
+
block: new TokenType("block", TokenClass.keyword, "block"),
|
|
5271
|
+
break: new TokenType("break", TokenClass.keyword, "break"),
|
|
5272
|
+
case: new TokenType("case", TokenClass.keyword, "case"),
|
|
5273
|
+
continue: new TokenType("continue", TokenClass.keyword, "continue"),
|
|
5274
|
+
continuing: new TokenType("continuing", TokenClass.keyword, "continuing"),
|
|
5275
|
+
default: new TokenType("default", TokenClass.keyword, "default"),
|
|
5276
|
+
discard: new TokenType("discard", TokenClass.keyword, "discard"),
|
|
5277
|
+
else: new TokenType("else", TokenClass.keyword, "else"),
|
|
5278
|
+
enable: new TokenType("enable", TokenClass.keyword, "enable"),
|
|
5279
|
+
fallthrough: new TokenType("fallthrough", TokenClass.keyword, "fallthrough"),
|
|
5280
|
+
false: new TokenType("false", TokenClass.keyword, "false"),
|
|
5281
|
+
fn: new TokenType("fn", TokenClass.keyword, "fn"),
|
|
5282
|
+
for: new TokenType("for", TokenClass.keyword, "for"),
|
|
5283
|
+
function: new TokenType("function", TokenClass.keyword, "function"),
|
|
5284
|
+
if: new TokenType("if", TokenClass.keyword, "if"),
|
|
5285
|
+
let: new TokenType("let", TokenClass.keyword, "let"),
|
|
5286
|
+
const: new TokenType("const", TokenClass.keyword, "const"),
|
|
5287
|
+
loop: new TokenType("loop", TokenClass.keyword, "loop"),
|
|
5288
|
+
while: new TokenType("while", TokenClass.keyword, "while"),
|
|
5289
|
+
private: new TokenType("private", TokenClass.keyword, "private"),
|
|
5290
|
+
read: new TokenType("read", TokenClass.keyword, "read"),
|
|
5291
|
+
read_write: new TokenType("read_write", TokenClass.keyword, "read_write"),
|
|
5292
|
+
return: new TokenType("return", TokenClass.keyword, "return"),
|
|
5293
|
+
storage: new TokenType("storage", TokenClass.keyword, "storage"),
|
|
5294
|
+
switch: new TokenType("switch", TokenClass.keyword, "switch"),
|
|
5295
|
+
true: new TokenType("true", TokenClass.keyword, "true"),
|
|
5296
|
+
alias: new TokenType("alias", TokenClass.keyword, "alias"),
|
|
5297
|
+
type: new TokenType("type", TokenClass.keyword, "type"),
|
|
5298
|
+
uniform: new TokenType("uniform", TokenClass.keyword, "uniform"),
|
|
5299
|
+
var: new TokenType("var", TokenClass.keyword, "var"),
|
|
5300
|
+
override: new TokenType("override", TokenClass.keyword, "override"),
|
|
5301
|
+
workgroup: new TokenType("workgroup", TokenClass.keyword, "workgroup"),
|
|
5302
|
+
write: new TokenType("write", TokenClass.keyword, "write"),
|
|
5303
|
+
r8unorm: new TokenType("r8unorm", TokenClass.keyword, "r8unorm"),
|
|
5304
|
+
r8snorm: new TokenType("r8snorm", TokenClass.keyword, "r8snorm"),
|
|
5305
|
+
r8uint: new TokenType("r8uint", TokenClass.keyword, "r8uint"),
|
|
5306
|
+
r8sint: new TokenType("r8sint", TokenClass.keyword, "r8sint"),
|
|
5307
|
+
r16uint: new TokenType("r16uint", TokenClass.keyword, "r16uint"),
|
|
5308
|
+
r16sint: new TokenType("r16sint", TokenClass.keyword, "r16sint"),
|
|
5309
|
+
r16float: new TokenType("r16float", TokenClass.keyword, "r16float"),
|
|
5310
|
+
rg8unorm: new TokenType("rg8unorm", TokenClass.keyword, "rg8unorm"),
|
|
5311
|
+
rg8snorm: new TokenType("rg8snorm", TokenClass.keyword, "rg8snorm"),
|
|
5312
|
+
rg8uint: new TokenType("rg8uint", TokenClass.keyword, "rg8uint"),
|
|
5313
|
+
rg8sint: new TokenType("rg8sint", TokenClass.keyword, "rg8sint"),
|
|
5314
|
+
r32uint: new TokenType("r32uint", TokenClass.keyword, "r32uint"),
|
|
5315
|
+
r32sint: new TokenType("r32sint", TokenClass.keyword, "r32sint"),
|
|
5316
|
+
r32float: new TokenType("r32float", TokenClass.keyword, "r32float"),
|
|
5317
|
+
rg16uint: new TokenType("rg16uint", TokenClass.keyword, "rg16uint"),
|
|
5318
|
+
rg16sint: new TokenType("rg16sint", TokenClass.keyword, "rg16sint"),
|
|
5319
|
+
rg16float: new TokenType("rg16float", TokenClass.keyword, "rg16float"),
|
|
5320
|
+
rgba8unorm: new TokenType("rgba8unorm", TokenClass.keyword, "rgba8unorm"),
|
|
5321
|
+
rgba8unorm_srgb: new TokenType("rgba8unorm_srgb", TokenClass.keyword, "rgba8unorm_srgb"),
|
|
5322
|
+
rgba8snorm: new TokenType("rgba8snorm", TokenClass.keyword, "rgba8snorm"),
|
|
5323
|
+
rgba8uint: new TokenType("rgba8uint", TokenClass.keyword, "rgba8uint"),
|
|
5324
|
+
rgba8sint: new TokenType("rgba8sint", TokenClass.keyword, "rgba8sint"),
|
|
5325
|
+
bgra8unorm: new TokenType("bgra8unorm", TokenClass.keyword, "bgra8unorm"),
|
|
5326
|
+
bgra8unorm_srgb: new TokenType("bgra8unorm_srgb", TokenClass.keyword, "bgra8unorm_srgb"),
|
|
5327
|
+
rgb10a2unorm: new TokenType("rgb10a2unorm", TokenClass.keyword, "rgb10a2unorm"),
|
|
5328
|
+
rg11b10float: new TokenType("rg11b10float", TokenClass.keyword, "rg11b10float"),
|
|
5329
|
+
rg32uint: new TokenType("rg32uint", TokenClass.keyword, "rg32uint"),
|
|
5330
|
+
rg32sint: new TokenType("rg32sint", TokenClass.keyword, "rg32sint"),
|
|
5331
|
+
rg32float: new TokenType("rg32float", TokenClass.keyword, "rg32float"),
|
|
5332
|
+
rgba16uint: new TokenType("rgba16uint", TokenClass.keyword, "rgba16uint"),
|
|
5333
|
+
rgba16sint: new TokenType("rgba16sint", TokenClass.keyword, "rgba16sint"),
|
|
5334
|
+
rgba16float: new TokenType("rgba16float", TokenClass.keyword, "rgba16float"),
|
|
5335
|
+
rgba32uint: new TokenType("rgba32uint", TokenClass.keyword, "rgba32uint"),
|
|
5336
|
+
rgba32sint: new TokenType("rgba32sint", TokenClass.keyword, "rgba32sint"),
|
|
5337
|
+
rgba32float: new TokenType("rgba32float", TokenClass.keyword, "rgba32float"),
|
|
5338
|
+
static_assert: new TokenType("static_assert", TokenClass.keyword, "static_assert")
|
|
5339
|
+
};
|
|
5340
|
+
TokenTypes.tokens = {
|
|
5341
|
+
decimal_float_literal: new TokenType("decimal_float_literal", TokenClass.token, /((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?f?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+f?)|([0-9]+f)/),
|
|
5342
|
+
hex_float_literal: new TokenType("hex_float_literal", TokenClass.token, /-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+f?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+f?))/),
|
|
5343
|
+
int_literal: new TokenType("int_literal", TokenClass.token, /-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),
|
|
5344
|
+
uint_literal: new TokenType("uint_literal", TokenClass.token, /0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),
|
|
5345
|
+
ident: new TokenType("ident", TokenClass.token, /[a-zA-Z][0-9a-zA-Z_]*/),
|
|
5346
|
+
and: new TokenType("and", TokenClass.token, "&"),
|
|
5347
|
+
and_and: new TokenType("and_and", TokenClass.token, "&&"),
|
|
5348
|
+
arrow: new TokenType("arrow ", TokenClass.token, "->"),
|
|
5349
|
+
attr: new TokenType("attr", TokenClass.token, "@"),
|
|
5350
|
+
attr_left: new TokenType("attr_left", TokenClass.token, "[["),
|
|
5351
|
+
attr_right: new TokenType("attr_right", TokenClass.token, "]]"),
|
|
5352
|
+
forward_slash: new TokenType("forward_slash", TokenClass.token, "/"),
|
|
5353
|
+
bang: new TokenType("bang", TokenClass.token, "!"),
|
|
5354
|
+
bracket_left: new TokenType("bracket_left", TokenClass.token, "["),
|
|
5355
|
+
bracket_right: new TokenType("bracket_right", TokenClass.token, "]"),
|
|
5356
|
+
brace_left: new TokenType("brace_left", TokenClass.token, "{"),
|
|
5357
|
+
brace_right: new TokenType("brace_right", TokenClass.token, "}"),
|
|
5358
|
+
colon: new TokenType("colon", TokenClass.token, ":"),
|
|
5359
|
+
comma: new TokenType("comma", TokenClass.token, ","),
|
|
5360
|
+
equal: new TokenType("equal", TokenClass.token, "="),
|
|
5361
|
+
equal_equal: new TokenType("equal_equal", TokenClass.token, "=="),
|
|
5362
|
+
not_equal: new TokenType("not_equal", TokenClass.token, "!="),
|
|
5363
|
+
greater_than: new TokenType("greater_than", TokenClass.token, ">"),
|
|
5364
|
+
greater_than_equal: new TokenType("greater_than_equal", TokenClass.token, ">="),
|
|
5365
|
+
shift_right: new TokenType("shift_right", TokenClass.token, ">>"),
|
|
5366
|
+
less_than: new TokenType("less_than", TokenClass.token, "<"),
|
|
5367
|
+
less_than_equal: new TokenType("less_than_equal", TokenClass.token, "<="),
|
|
5368
|
+
shift_left: new TokenType("shift_left", TokenClass.token, "<<"),
|
|
5369
|
+
modulo: new TokenType("modulo", TokenClass.token, "%"),
|
|
5370
|
+
minus: new TokenType("minus", TokenClass.token, "-"),
|
|
5371
|
+
minus_minus: new TokenType("minus_minus", TokenClass.token, "--"),
|
|
5372
|
+
period: new TokenType("period", TokenClass.token, "."),
|
|
5373
|
+
plus: new TokenType("plus", TokenClass.token, "+"),
|
|
5374
|
+
plus_plus: new TokenType("plus_plus", TokenClass.token, "++"),
|
|
5375
|
+
or: new TokenType("or", TokenClass.token, "|"),
|
|
5376
|
+
or_or: new TokenType("or_or", TokenClass.token, "||"),
|
|
5377
|
+
paren_left: new TokenType("paren_left", TokenClass.token, "("),
|
|
5378
|
+
paren_right: new TokenType("paren_right", TokenClass.token, ")"),
|
|
5379
|
+
semicolon: new TokenType("semicolon", TokenClass.token, ";"),
|
|
5380
|
+
star: new TokenType("star", TokenClass.token, "*"),
|
|
5381
|
+
tilde: new TokenType("tilde", TokenClass.token, "~"),
|
|
5382
|
+
underscore: new TokenType("underscore", TokenClass.token, "_"),
|
|
5383
|
+
xor: new TokenType("xor", TokenClass.token, "^"),
|
|
5384
|
+
plus_equal: new TokenType("plus_equal", TokenClass.token, "+="),
|
|
5385
|
+
minus_equal: new TokenType("minus_equal", TokenClass.token, "-="),
|
|
5386
|
+
times_equal: new TokenType("times_equal", TokenClass.token, "*="),
|
|
5387
|
+
division_equal: new TokenType("division_equal", TokenClass.token, "/="),
|
|
5388
|
+
modulo_equal: new TokenType("modulo_equal", TokenClass.token, "%="),
|
|
5389
|
+
and_equal: new TokenType("and_equal", TokenClass.token, "&="),
|
|
5390
|
+
or_equal: new TokenType("or_equal", TokenClass.token, "|="),
|
|
5391
|
+
xor_equal: new TokenType("xor_equal", TokenClass.token, "^="),
|
|
5392
|
+
shift_right_equal: new TokenType("shift_right_equal", TokenClass.token, ">>="),
|
|
5393
|
+
shift_left_equal: new TokenType("shift_left_equal", TokenClass.token, "<<=")
|
|
5394
|
+
};
|
|
5395
|
+
TokenTypes.storage_class = [_a.keywords.function, _a.keywords.private, _a.keywords.workgroup, _a.keywords.uniform, _a.keywords.storage];
|
|
5396
|
+
TokenTypes.access_mode = [_a.keywords.read, _a.keywords.write, _a.keywords.read_write];
|
|
5397
|
+
TokenTypes.sampler_type = [_a.keywords.sampler, _a.keywords.sampler_comparison];
|
|
5398
|
+
TokenTypes.sampled_texture_type = [_a.keywords.texture_1d, _a.keywords.texture_2d, _a.keywords.texture_2d_array, _a.keywords.texture_3d, _a.keywords.texture_cube, _a.keywords.texture_cube_array];
|
|
5399
|
+
TokenTypes.multisampled_texture_type = [_a.keywords.texture_multisampled_2d];
|
|
5400
|
+
TokenTypes.storage_texture_type = [_a.keywords.texture_storage_1d, _a.keywords.texture_storage_2d, _a.keywords.texture_storage_2d_array, _a.keywords.texture_storage_3d];
|
|
5401
|
+
TokenTypes.depth_texture_type = [_a.keywords.texture_depth_2d, _a.keywords.texture_depth_2d_array, _a.keywords.texture_depth_cube, _a.keywords.texture_depth_cube_array, _a.keywords.texture_depth_multisampled_2d];
|
|
5402
|
+
TokenTypes.texture_external_type = [_a.keywords.texture_external];
|
|
5403
|
+
TokenTypes.any_texture_type = [..._a.sampled_texture_type, ..._a.multisampled_texture_type, ..._a.storage_texture_type, ..._a.depth_texture_type, ..._a.texture_external_type];
|
|
5404
|
+
TokenTypes.texel_format = [_a.keywords.r8unorm, _a.keywords.r8snorm, _a.keywords.r8uint, _a.keywords.r8sint, _a.keywords.r16uint, _a.keywords.r16sint, _a.keywords.r16float, _a.keywords.rg8unorm, _a.keywords.rg8snorm, _a.keywords.rg8uint, _a.keywords.rg8sint, _a.keywords.r32uint, _a.keywords.r32sint, _a.keywords.r32float, _a.keywords.rg16uint, _a.keywords.rg16sint, _a.keywords.rg16float, _a.keywords.rgba8unorm, _a.keywords.rgba8unorm_srgb, _a.keywords.rgba8snorm, _a.keywords.rgba8uint, _a.keywords.rgba8sint, _a.keywords.bgra8unorm, _a.keywords.bgra8unorm_srgb, _a.keywords.rgb10a2unorm, _a.keywords.rg11b10float, _a.keywords.rg32uint, _a.keywords.rg32sint, _a.keywords.rg32float, _a.keywords.rgba16uint, _a.keywords.rgba16sint, _a.keywords.rgba16float, _a.keywords.rgba32uint, _a.keywords.rgba32sint, _a.keywords.rgba32float];
|
|
5405
|
+
TokenTypes.const_literal = [_a.tokens.int_literal, _a.tokens.uint_literal, _a.tokens.decimal_float_literal, _a.tokens.hex_float_literal, _a.keywords.true, _a.keywords.false];
|
|
5406
|
+
TokenTypes.literal_or_ident = [_a.tokens.ident, _a.tokens.int_literal, _a.tokens.uint_literal, _a.tokens.decimal_float_literal, _a.tokens.hex_float_literal];
|
|
5407
|
+
TokenTypes.element_count_expression = [_a.tokens.int_literal, _a.tokens.uint_literal, _a.tokens.ident];
|
|
5408
|
+
TokenTypes.template_types = [_a.keywords.vec2, _a.keywords.vec3, _a.keywords.vec4, _a.keywords.mat2x2, _a.keywords.mat2x3, _a.keywords.mat2x4, _a.keywords.mat3x2, _a.keywords.mat3x3, _a.keywords.mat3x4, _a.keywords.mat4x2, _a.keywords.mat4x3, _a.keywords.mat4x4, _a.keywords.atomic, _a.keywords.bitcast, ..._a.any_texture_type];
|
|
5409
|
+
TokenTypes.attribute_name = [_a.tokens.ident, _a.keywords.block];
|
|
5410
|
+
TokenTypes.assignment_operators = [_a.tokens.equal, _a.tokens.plus_equal, _a.tokens.minus_equal, _a.tokens.times_equal, _a.tokens.division_equal, _a.tokens.modulo_equal, _a.tokens.and_equal, _a.tokens.or_equal, _a.tokens.xor_equal, _a.tokens.shift_right_equal, _a.tokens.shift_left_equal];
|
|
5411
|
+
TokenTypes.increment_operators = [_a.tokens.plus_plus, _a.tokens.minus_minus];
|
|
5412
|
+
var Token = class {
|
|
5413
|
+
constructor(type, lexeme, line) {
|
|
5414
|
+
this.type = type;
|
|
5415
|
+
this.lexeme = lexeme;
|
|
5416
|
+
this.line = line;
|
|
5417
|
+
}
|
|
5418
|
+
toString() {
|
|
5419
|
+
return this.lexeme;
|
|
5420
|
+
}
|
|
5421
|
+
isTemplateType() {
|
|
5422
|
+
return TokenTypes.template_types.indexOf(this.type) != -1;
|
|
5423
|
+
}
|
|
5424
|
+
isArrayType() {
|
|
5425
|
+
return this.type == TokenTypes.keywords.array;
|
|
5426
|
+
}
|
|
5427
|
+
isArrayOrTemplateType() {
|
|
5428
|
+
return this.isArrayType() || this.isTemplateType();
|
|
5429
|
+
}
|
|
5430
|
+
};
|
|
5431
|
+
var WgslScanner = class {
|
|
5432
|
+
constructor(source) {
|
|
5433
|
+
this._tokens = [];
|
|
5434
|
+
this._start = 0;
|
|
5435
|
+
this._current = 0;
|
|
5436
|
+
this._line = 1;
|
|
5437
|
+
this._source = source !== null && source !== void 0 ? source : "";
|
|
5438
|
+
}
|
|
5439
|
+
scanTokens() {
|
|
5440
|
+
while (!this._isAtEnd()) {
|
|
5441
|
+
this._start = this._current;
|
|
5442
|
+
if (!this.scanToken())
|
|
5443
|
+
throw `Invalid syntax at line ${this._line}`;
|
|
5444
|
+
}
|
|
5445
|
+
this._tokens.push(new Token(TokenTypes.eof, "", this._line));
|
|
5446
|
+
return this._tokens;
|
|
5447
|
+
}
|
|
5448
|
+
scanToken() {
|
|
5449
|
+
let lexeme = this._advance();
|
|
5450
|
+
if (lexeme == "\n") {
|
|
5451
|
+
this._line++;
|
|
5452
|
+
return true;
|
|
5453
|
+
}
|
|
5454
|
+
if (this._isWhitespace(lexeme)) {
|
|
5455
|
+
return true;
|
|
5456
|
+
}
|
|
5457
|
+
if (lexeme == "/") {
|
|
5458
|
+
if (this._peekAhead() == "/") {
|
|
5459
|
+
while (lexeme != "\n") {
|
|
5460
|
+
if (this._isAtEnd())
|
|
5461
|
+
return true;
|
|
5462
|
+
lexeme = this._advance();
|
|
5463
|
+
}
|
|
5464
|
+
this._line++;
|
|
5465
|
+
return true;
|
|
5466
|
+
} else if (this._peekAhead() == "*") {
|
|
5467
|
+
this._advance();
|
|
5468
|
+
let commentLevel = 1;
|
|
5469
|
+
while (commentLevel > 0) {
|
|
5470
|
+
if (this._isAtEnd())
|
|
5471
|
+
return true;
|
|
5472
|
+
lexeme = this._advance();
|
|
5473
|
+
if (lexeme == "\n") {
|
|
5474
|
+
this._line++;
|
|
5475
|
+
} else if (lexeme == "*") {
|
|
5476
|
+
if (this._peekAhead() == "/") {
|
|
5477
|
+
this._advance();
|
|
5478
|
+
commentLevel--;
|
|
5479
|
+
if (commentLevel == 0) {
|
|
5480
|
+
return true;
|
|
5481
|
+
}
|
|
5482
|
+
}
|
|
5483
|
+
} else if (lexeme == "/") {
|
|
5484
|
+
if (this._peekAhead() == "*") {
|
|
5485
|
+
this._advance();
|
|
5486
|
+
commentLevel++;
|
|
5487
|
+
}
|
|
5488
|
+
}
|
|
5489
|
+
}
|
|
5490
|
+
return true;
|
|
5491
|
+
}
|
|
5492
|
+
}
|
|
5493
|
+
let matchType = TokenTypes.none;
|
|
5494
|
+
for (; ; ) {
|
|
5495
|
+
let matchedType = this._findType(lexeme);
|
|
5496
|
+
const nextLexeme = this._peekAhead();
|
|
5497
|
+
if (lexeme == ">" && (nextLexeme == ">" || nextLexeme == "=")) {
|
|
5498
|
+
let foundLessThan = false;
|
|
5499
|
+
let ti = this._tokens.length - 1;
|
|
5500
|
+
for (let count = 0; count < 5 && ti >= 0; ++count, --ti) {
|
|
5501
|
+
if (this._tokens[ti].type === TokenTypes.tokens.less_than) {
|
|
5502
|
+
if (ti > 0 && this._tokens[ti - 1].isArrayOrTemplateType()) {
|
|
5503
|
+
foundLessThan = true;
|
|
5504
|
+
}
|
|
5505
|
+
break;
|
|
5506
|
+
}
|
|
5507
|
+
}
|
|
5508
|
+
if (foundLessThan) {
|
|
5509
|
+
this._addToken(matchedType);
|
|
5510
|
+
return true;
|
|
5511
|
+
}
|
|
5512
|
+
}
|
|
5513
|
+
if (matchedType === TokenTypes.none) {
|
|
5514
|
+
let lookAheadLexeme = lexeme;
|
|
5515
|
+
let lookAhead = 0;
|
|
5516
|
+
const maxLookAhead = 2;
|
|
5517
|
+
for (let li = 0; li < maxLookAhead; ++li) {
|
|
5518
|
+
lookAheadLexeme += this._peekAhead(li);
|
|
5519
|
+
matchedType = this._findType(lookAheadLexeme);
|
|
5520
|
+
if (matchedType !== TokenTypes.none) {
|
|
5521
|
+
lookAhead = li;
|
|
5522
|
+
break;
|
|
5523
|
+
}
|
|
5524
|
+
}
|
|
5525
|
+
if (matchedType === TokenTypes.none) {
|
|
5526
|
+
if (matchType === TokenTypes.none)
|
|
5527
|
+
return false;
|
|
5528
|
+
this._current--;
|
|
5529
|
+
this._addToken(matchType);
|
|
5530
|
+
return true;
|
|
5531
|
+
}
|
|
5532
|
+
lexeme = lookAheadLexeme;
|
|
5533
|
+
this._current += lookAhead + 1;
|
|
5534
|
+
}
|
|
5535
|
+
matchType = matchedType;
|
|
5536
|
+
if (this._isAtEnd())
|
|
5537
|
+
break;
|
|
5538
|
+
lexeme += this._advance();
|
|
5539
|
+
}
|
|
5540
|
+
if (matchType === TokenTypes.none)
|
|
5541
|
+
return false;
|
|
5542
|
+
this._addToken(matchType);
|
|
5543
|
+
return true;
|
|
5544
|
+
}
|
|
5545
|
+
_findType(lexeme) {
|
|
5546
|
+
for (const name2 in TokenTypes.keywords) {
|
|
5547
|
+
const type = TokenTypes.keywords[name2];
|
|
5548
|
+
if (this._match(lexeme, type.rule)) {
|
|
5549
|
+
return type;
|
|
5550
|
+
}
|
|
5551
|
+
}
|
|
5552
|
+
for (const name2 in TokenTypes.tokens) {
|
|
5553
|
+
const type = TokenTypes.tokens[name2];
|
|
5554
|
+
if (this._match(lexeme, type.rule)) {
|
|
5555
|
+
return type;
|
|
5556
|
+
}
|
|
5557
|
+
}
|
|
5558
|
+
return TokenTypes.none;
|
|
5559
|
+
}
|
|
5560
|
+
_match(lexeme, rule) {
|
|
5561
|
+
if (typeof rule === "string") {
|
|
5562
|
+
if (rule == lexeme) {
|
|
5563
|
+
return true;
|
|
5564
|
+
}
|
|
5565
|
+
} else {
|
|
5566
|
+
const match = rule.exec(lexeme);
|
|
5567
|
+
if (match && match.index == 0 && match[0] == lexeme)
|
|
5568
|
+
return true;
|
|
5569
|
+
}
|
|
5570
|
+
return false;
|
|
5571
|
+
}
|
|
5572
|
+
_isAtEnd() {
|
|
5573
|
+
return this._current >= this._source.length;
|
|
5574
|
+
}
|
|
5575
|
+
_isWhitespace(c) {
|
|
5576
|
+
return c == " " || c == " " || c == "\r";
|
|
5577
|
+
}
|
|
5578
|
+
_advance(amount = 0) {
|
|
5579
|
+
let c = this._source[this._current];
|
|
5580
|
+
amount = amount || 0;
|
|
5581
|
+
amount++;
|
|
5582
|
+
this._current += amount;
|
|
5583
|
+
return c;
|
|
5584
|
+
}
|
|
5585
|
+
_peekAhead(offset = 0) {
|
|
5586
|
+
offset = offset || 0;
|
|
5587
|
+
if (this._current + offset >= this._source.length)
|
|
5588
|
+
return "\0";
|
|
5589
|
+
return this._source[this._current + offset];
|
|
5590
|
+
}
|
|
5591
|
+
_addToken(type) {
|
|
5592
|
+
const text = this._source.substring(this._start, this._current);
|
|
5593
|
+
this._tokens.push(new Token(type, text, this._line));
|
|
5594
|
+
}
|
|
5595
|
+
};
|
|
5596
|
+
var WgslParser = class {
|
|
5597
|
+
constructor() {
|
|
5598
|
+
this._tokens = [];
|
|
5599
|
+
this._current = 0;
|
|
5600
|
+
this._context = new ParseContext();
|
|
5601
|
+
}
|
|
5602
|
+
parse(tokensOrCode) {
|
|
5603
|
+
this._initialize(tokensOrCode);
|
|
5604
|
+
let statements = [];
|
|
5605
|
+
while (!this._isAtEnd()) {
|
|
5606
|
+
const statement = this._global_decl_or_directive();
|
|
5607
|
+
if (!statement)
|
|
5608
|
+
break;
|
|
5609
|
+
statements.push(statement);
|
|
5610
|
+
}
|
|
5611
|
+
return statements;
|
|
5612
|
+
}
|
|
5613
|
+
_initialize(tokensOrCode) {
|
|
5614
|
+
if (tokensOrCode) {
|
|
5615
|
+
if (typeof tokensOrCode == "string") {
|
|
5616
|
+
const scanner = new WgslScanner(tokensOrCode);
|
|
5617
|
+
this._tokens = scanner.scanTokens();
|
|
5618
|
+
} else {
|
|
5619
|
+
this._tokens = tokensOrCode;
|
|
5620
|
+
}
|
|
5621
|
+
} else {
|
|
5622
|
+
this._tokens = [];
|
|
5623
|
+
}
|
|
5624
|
+
this._current = 0;
|
|
5625
|
+
}
|
|
5626
|
+
_error(token, message2) {
|
|
5627
|
+
console.error(token, message2);
|
|
5628
|
+
return {
|
|
5629
|
+
token,
|
|
5630
|
+
message: message2,
|
|
5631
|
+
toString: function() {
|
|
5632
|
+
return `${message2}`;
|
|
5633
|
+
}
|
|
5634
|
+
};
|
|
5635
|
+
}
|
|
5636
|
+
_isAtEnd() {
|
|
5637
|
+
return this._current >= this._tokens.length || this._peek().type == TokenTypes.eof;
|
|
5638
|
+
}
|
|
5639
|
+
_match(types) {
|
|
5640
|
+
if (types instanceof TokenType) {
|
|
5641
|
+
if (this._check(types)) {
|
|
5642
|
+
this._advance();
|
|
5643
|
+
return true;
|
|
5644
|
+
}
|
|
5645
|
+
return false;
|
|
5646
|
+
}
|
|
5647
|
+
for (let i = 0, l = types.length; i < l; ++i) {
|
|
5648
|
+
const type = types[i];
|
|
5649
|
+
if (this._check(type)) {
|
|
5650
|
+
this._advance();
|
|
5651
|
+
return true;
|
|
5652
|
+
}
|
|
5653
|
+
}
|
|
5654
|
+
return false;
|
|
5655
|
+
}
|
|
5656
|
+
_consume(types, message2) {
|
|
5657
|
+
if (this._check(types))
|
|
5658
|
+
return this._advance();
|
|
5659
|
+
throw this._error(this._peek(), message2);
|
|
5660
|
+
}
|
|
5661
|
+
_check(types) {
|
|
5662
|
+
if (this._isAtEnd())
|
|
5663
|
+
return false;
|
|
5664
|
+
const tk = this._peek();
|
|
5665
|
+
if (types instanceof Array) {
|
|
5666
|
+
let t = tk.type;
|
|
5667
|
+
let index2 = types.indexOf(t);
|
|
5668
|
+
return index2 != -1;
|
|
5669
|
+
}
|
|
5670
|
+
return tk.type == types;
|
|
5671
|
+
}
|
|
5672
|
+
_advance() {
|
|
5673
|
+
if (!this._isAtEnd())
|
|
5674
|
+
this._current++;
|
|
5675
|
+
return this._previous();
|
|
5676
|
+
}
|
|
5677
|
+
_peek() {
|
|
5678
|
+
return this._tokens[this._current];
|
|
5679
|
+
}
|
|
5680
|
+
_previous() {
|
|
5681
|
+
return this._tokens[this._current - 1];
|
|
5682
|
+
}
|
|
5683
|
+
_global_decl_or_directive() {
|
|
5684
|
+
while (this._match(TokenTypes.tokens.semicolon) && !this._isAtEnd())
|
|
5685
|
+
;
|
|
5686
|
+
if (this._match(TokenTypes.keywords.alias)) {
|
|
5687
|
+
const type = this._type_alias();
|
|
5688
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
5689
|
+
return type;
|
|
5690
|
+
}
|
|
5691
|
+
if (this._match(TokenTypes.keywords.enable)) {
|
|
5692
|
+
const enable2 = this._enable_directive();
|
|
5693
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
5694
|
+
return enable2;
|
|
5695
|
+
}
|
|
5696
|
+
const attrs = this._attribute();
|
|
5697
|
+
if (this._check(TokenTypes.keywords.var)) {
|
|
5698
|
+
const _var = this._global_variable_decl();
|
|
5699
|
+
if (_var != null)
|
|
5700
|
+
_var.attributes = attrs;
|
|
5701
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
5702
|
+
return _var;
|
|
5703
|
+
}
|
|
5704
|
+
if (this._check(TokenTypes.keywords.override)) {
|
|
5705
|
+
const _override = this._override_variable_decl();
|
|
5706
|
+
if (_override != null)
|
|
5707
|
+
_override.attributes = attrs;
|
|
5708
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
5709
|
+
return _override;
|
|
5710
|
+
}
|
|
5711
|
+
if (this._check(TokenTypes.keywords.let)) {
|
|
5712
|
+
const _let = this._global_let_decl();
|
|
5713
|
+
if (_let != null)
|
|
5714
|
+
_let.attributes = attrs;
|
|
5715
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
5716
|
+
return _let;
|
|
5717
|
+
}
|
|
5718
|
+
if (this._check(TokenTypes.keywords.const)) {
|
|
5719
|
+
const _const = this._global_const_decl();
|
|
5720
|
+
if (_const != null)
|
|
5721
|
+
_const.attributes = attrs;
|
|
5722
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
5723
|
+
return _const;
|
|
5724
|
+
}
|
|
5725
|
+
if (this._check(TokenTypes.keywords.struct)) {
|
|
5726
|
+
const _struct = this._struct_decl();
|
|
5727
|
+
if (_struct != null)
|
|
5728
|
+
_struct.attributes = attrs;
|
|
5729
|
+
return _struct;
|
|
5730
|
+
}
|
|
5731
|
+
if (this._check(TokenTypes.keywords.fn)) {
|
|
5732
|
+
const _fn = this._function_decl();
|
|
5733
|
+
if (_fn != null)
|
|
5734
|
+
_fn.attributes = attrs;
|
|
5735
|
+
return _fn;
|
|
5736
|
+
}
|
|
5737
|
+
return null;
|
|
5738
|
+
}
|
|
5739
|
+
_function_decl() {
|
|
5740
|
+
if (!this._match(TokenTypes.keywords.fn))
|
|
5741
|
+
return null;
|
|
5742
|
+
const name2 = this._consume(TokenTypes.tokens.ident, "Expected function name.").toString();
|
|
5743
|
+
this._consume(TokenTypes.tokens.paren_left, "Expected '(' for function arguments.");
|
|
5744
|
+
const args = [];
|
|
5745
|
+
if (!this._check(TokenTypes.tokens.paren_right)) {
|
|
5746
|
+
do {
|
|
5747
|
+
if (this._check(TokenTypes.tokens.paren_right))
|
|
5748
|
+
break;
|
|
5749
|
+
const argAttrs = this._attribute();
|
|
5750
|
+
const name3 = this._consume(TokenTypes.tokens.ident, "Expected argument name.").toString();
|
|
5751
|
+
this._consume(TokenTypes.tokens.colon, "Expected ':' for argument type.");
|
|
5752
|
+
const typeAttrs = this._attribute();
|
|
5753
|
+
const type = this._type_decl();
|
|
5754
|
+
if (type != null) {
|
|
5755
|
+
type.attributes = typeAttrs;
|
|
5756
|
+
args.push(new Argument(name3, type, argAttrs));
|
|
5757
|
+
}
|
|
5758
|
+
} while (this._match(TokenTypes.tokens.comma));
|
|
5759
|
+
}
|
|
5760
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')' after function arguments.");
|
|
5761
|
+
let _return = null;
|
|
5762
|
+
if (this._match(TokenTypes.tokens.arrow)) {
|
|
5763
|
+
const attrs = this._attribute();
|
|
5764
|
+
_return = this._type_decl();
|
|
5765
|
+
if (_return != null)
|
|
5766
|
+
_return.attributes = attrs;
|
|
5767
|
+
}
|
|
5768
|
+
const body = this._compound_statement();
|
|
5769
|
+
return new Function(name2, args, _return, body);
|
|
5770
|
+
}
|
|
5771
|
+
_compound_statement() {
|
|
5772
|
+
const statements = [];
|
|
5773
|
+
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for block.");
|
|
5774
|
+
while (!this._check(TokenTypes.tokens.brace_right)) {
|
|
5775
|
+
const statement = this._statement();
|
|
5776
|
+
if (statement !== null)
|
|
5777
|
+
statements.push(statement);
|
|
5778
|
+
}
|
|
5779
|
+
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for block.");
|
|
5780
|
+
return statements;
|
|
5781
|
+
}
|
|
5782
|
+
_statement() {
|
|
5783
|
+
while (this._match(TokenTypes.tokens.semicolon) && !this._isAtEnd())
|
|
5784
|
+
;
|
|
5785
|
+
if (this._check(TokenTypes.keywords.if))
|
|
5786
|
+
return this._if_statement();
|
|
5787
|
+
if (this._check(TokenTypes.keywords.switch))
|
|
5788
|
+
return this._switch_statement();
|
|
5789
|
+
if (this._check(TokenTypes.keywords.loop))
|
|
5790
|
+
return this._loop_statement();
|
|
5791
|
+
if (this._check(TokenTypes.keywords.for))
|
|
5792
|
+
return this._for_statement();
|
|
5793
|
+
if (this._check(TokenTypes.keywords.while))
|
|
5794
|
+
return this._while_statement();
|
|
5795
|
+
if (this._check(TokenTypes.keywords.continuing))
|
|
5796
|
+
return this._continuing_statement();
|
|
5797
|
+
if (this._check(TokenTypes.keywords.static_assert))
|
|
5798
|
+
return this._static_assert_statement();
|
|
5799
|
+
if (this._check(TokenTypes.tokens.brace_left))
|
|
5800
|
+
return this._compound_statement();
|
|
5801
|
+
let result = null;
|
|
5802
|
+
if (this._check(TokenTypes.keywords.return))
|
|
5803
|
+
result = this._return_statement();
|
|
5804
|
+
else if (this._check([TokenTypes.keywords.var, TokenTypes.keywords.let, TokenTypes.keywords.const]))
|
|
5805
|
+
result = this._variable_statement();
|
|
5806
|
+
else if (this._match(TokenTypes.keywords.discard))
|
|
5807
|
+
result = new Discard();
|
|
5808
|
+
else if (this._match(TokenTypes.keywords.break))
|
|
5809
|
+
result = new Break();
|
|
5810
|
+
else if (this._match(TokenTypes.keywords.continue))
|
|
5811
|
+
result = new Continue();
|
|
5812
|
+
else
|
|
5813
|
+
result = this._increment_decrement_statement() || this._func_call_statement() || this._assignment_statement();
|
|
5814
|
+
if (result != null)
|
|
5815
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';' after statement.");
|
|
5816
|
+
return result;
|
|
5817
|
+
}
|
|
5818
|
+
_static_assert_statement() {
|
|
5819
|
+
if (!this._match(TokenTypes.keywords.static_assert))
|
|
5820
|
+
return null;
|
|
5821
|
+
let expression = this._optional_paren_expression();
|
|
5822
|
+
return new StaticAssert(expression);
|
|
5823
|
+
}
|
|
5824
|
+
_while_statement() {
|
|
5825
|
+
if (!this._match(TokenTypes.keywords.while))
|
|
5826
|
+
return null;
|
|
5827
|
+
let condition = this._optional_paren_expression();
|
|
5828
|
+
const block = this._compound_statement();
|
|
5829
|
+
return new While(condition, block);
|
|
5830
|
+
}
|
|
5831
|
+
_continuing_statement() {
|
|
5832
|
+
if (!this._match(TokenTypes.keywords.continuing))
|
|
5833
|
+
return null;
|
|
5834
|
+
const block = this._compound_statement();
|
|
5835
|
+
return new Continuing(block);
|
|
5836
|
+
}
|
|
5837
|
+
_for_statement() {
|
|
5838
|
+
if (!this._match(TokenTypes.keywords.for))
|
|
5839
|
+
return null;
|
|
5840
|
+
this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
|
|
5841
|
+
const init = !this._check(TokenTypes.tokens.semicolon) ? this._for_init() : null;
|
|
5842
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
5843
|
+
const condition = !this._check(TokenTypes.tokens.semicolon) ? this._short_circuit_or_expression() : null;
|
|
5844
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
5845
|
+
const increment = !this._check(TokenTypes.tokens.paren_right) ? this._for_increment() : null;
|
|
5846
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
|
|
5847
|
+
const body = this._compound_statement();
|
|
5848
|
+
return new For(init, condition, increment, body);
|
|
5849
|
+
}
|
|
5850
|
+
_for_init() {
|
|
5851
|
+
return this._variable_statement() || this._func_call_statement() || this._assignment_statement();
|
|
5852
|
+
}
|
|
5853
|
+
_for_increment() {
|
|
5854
|
+
return this._func_call_statement() || this._increment_decrement_statement() || this._assignment_statement();
|
|
5855
|
+
}
|
|
5856
|
+
_variable_statement() {
|
|
5857
|
+
if (this._check(TokenTypes.keywords.var)) {
|
|
5858
|
+
const _var = this._variable_decl();
|
|
5859
|
+
if (_var === null)
|
|
5860
|
+
throw this._error(this._peek(), "Variable declaration expected.");
|
|
5861
|
+
let value = null;
|
|
5862
|
+
if (this._match(TokenTypes.tokens.equal))
|
|
5863
|
+
value = this._short_circuit_or_expression();
|
|
5864
|
+
return new Var(_var.name, _var.type, _var.storage, _var.access, value);
|
|
5865
|
+
}
|
|
5866
|
+
if (this._match(TokenTypes.keywords.let)) {
|
|
5867
|
+
const name2 = this._consume(TokenTypes.tokens.ident, "Expected name for let.").toString();
|
|
5868
|
+
let type = null;
|
|
5869
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
5870
|
+
const typeAttrs = this._attribute();
|
|
5871
|
+
type = this._type_decl();
|
|
5872
|
+
if (type != null)
|
|
5873
|
+
type.attributes = typeAttrs;
|
|
5874
|
+
}
|
|
5875
|
+
this._consume(TokenTypes.tokens.equal, "Expected '=' for let.");
|
|
5876
|
+
const value = this._short_circuit_or_expression();
|
|
5877
|
+
return new Let(name2, type, null, null, value);
|
|
5878
|
+
}
|
|
5879
|
+
if (this._match(TokenTypes.keywords.const)) {
|
|
5880
|
+
const name2 = this._consume(TokenTypes.tokens.ident, "Expected name for const.").toString();
|
|
5881
|
+
let type = null;
|
|
5882
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
5883
|
+
const typeAttrs = this._attribute();
|
|
5884
|
+
type = this._type_decl();
|
|
5885
|
+
if (type != null)
|
|
5886
|
+
type.attributes = typeAttrs;
|
|
5887
|
+
}
|
|
5888
|
+
this._consume(TokenTypes.tokens.equal, "Expected '=' for const.");
|
|
5889
|
+
const value = this._short_circuit_or_expression();
|
|
5890
|
+
return new Const(name2, type, null, null, value);
|
|
5891
|
+
}
|
|
5892
|
+
return null;
|
|
5893
|
+
}
|
|
5894
|
+
_increment_decrement_statement() {
|
|
5895
|
+
const savedPos = this._current;
|
|
5896
|
+
const _var = this._unary_expression();
|
|
5897
|
+
if (_var == null)
|
|
5898
|
+
return null;
|
|
5899
|
+
if (!this._check(TokenTypes.increment_operators)) {
|
|
5900
|
+
this._current = savedPos;
|
|
5901
|
+
return null;
|
|
5902
|
+
}
|
|
5903
|
+
const token = this._consume(TokenTypes.increment_operators, "Expected increment operator");
|
|
5904
|
+
return new Increment(token.type === TokenTypes.tokens.plus_plus ? IncrementOperator.increment : IncrementOperator.decrement, _var);
|
|
5905
|
+
}
|
|
5906
|
+
_assignment_statement() {
|
|
5907
|
+
let _var = null;
|
|
5908
|
+
if (this._check(TokenTypes.tokens.brace_right))
|
|
5909
|
+
return null;
|
|
5910
|
+
let isUnderscore = this._match(TokenTypes.tokens.underscore);
|
|
5911
|
+
if (!isUnderscore)
|
|
5912
|
+
_var = this._unary_expression();
|
|
5913
|
+
if (!isUnderscore && _var == null)
|
|
5914
|
+
return null;
|
|
5915
|
+
const type = this._consume(TokenTypes.assignment_operators, "Expected assignment operator.");
|
|
5916
|
+
const value = this._short_circuit_or_expression();
|
|
5917
|
+
return new Assign(AssignOperator.parse(type.lexeme), _var, value);
|
|
5918
|
+
}
|
|
5919
|
+
_func_call_statement() {
|
|
5920
|
+
if (!this._check(TokenTypes.tokens.ident))
|
|
5921
|
+
return null;
|
|
5922
|
+
const savedPos = this._current;
|
|
5923
|
+
const name2 = this._consume(TokenTypes.tokens.ident, "Expected function name.");
|
|
5924
|
+
const args = this._argument_expression_list();
|
|
5925
|
+
if (args === null) {
|
|
5926
|
+
this._current = savedPos;
|
|
5927
|
+
return null;
|
|
5928
|
+
}
|
|
5929
|
+
return new Call(name2.lexeme, args);
|
|
5930
|
+
}
|
|
5931
|
+
_loop_statement() {
|
|
5932
|
+
if (!this._match(TokenTypes.keywords.loop))
|
|
5933
|
+
return null;
|
|
5934
|
+
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for loop.");
|
|
5935
|
+
const statements = [];
|
|
5936
|
+
let statement = this._statement();
|
|
5937
|
+
while (statement !== null) {
|
|
5938
|
+
if (Array.isArray(statement)) {
|
|
5939
|
+
for (let s of statement) {
|
|
5940
|
+
statements.push(s);
|
|
5941
|
+
}
|
|
5942
|
+
} else {
|
|
5943
|
+
statements.push(statement);
|
|
5944
|
+
}
|
|
5945
|
+
statement = this._statement();
|
|
5946
|
+
}
|
|
5947
|
+
let continuing = null;
|
|
5948
|
+
if (this._match(TokenTypes.keywords.continuing))
|
|
5949
|
+
continuing = this._compound_statement();
|
|
5950
|
+
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for loop.");
|
|
5951
|
+
return new Loop(statements, continuing);
|
|
5952
|
+
}
|
|
5953
|
+
_switch_statement() {
|
|
5954
|
+
if (!this._match(TokenTypes.keywords.switch))
|
|
5955
|
+
return null;
|
|
5956
|
+
const condition = this._optional_paren_expression();
|
|
5957
|
+
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for switch.");
|
|
5958
|
+
const body = this._switch_body();
|
|
5959
|
+
if (body == null || body.length == 0)
|
|
5960
|
+
throw this._error(this._previous(), "Expected 'case' or 'default'.");
|
|
5961
|
+
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for switch.");
|
|
5962
|
+
return new Switch(condition, body);
|
|
5963
|
+
}
|
|
5964
|
+
_switch_body() {
|
|
5965
|
+
const cases = [];
|
|
5966
|
+
if (this._match(TokenTypes.keywords.case)) {
|
|
5967
|
+
const selector = this._case_selectors();
|
|
5968
|
+
this._match(TokenTypes.tokens.colon);
|
|
5969
|
+
this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch case.");
|
|
5970
|
+
const body = this._case_body();
|
|
5971
|
+
this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch case.");
|
|
5972
|
+
cases.push(new Case(selector, body));
|
|
5973
|
+
}
|
|
5974
|
+
if (this._match(TokenTypes.keywords.default)) {
|
|
5975
|
+
this._match(TokenTypes.tokens.colon);
|
|
5976
|
+
this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch default.");
|
|
5977
|
+
const body = this._case_body();
|
|
5978
|
+
this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch default.");
|
|
5979
|
+
cases.push(new Default(body));
|
|
5980
|
+
}
|
|
5981
|
+
if (this._check([TokenTypes.keywords.default, TokenTypes.keywords.case])) {
|
|
5982
|
+
const _cases = this._switch_body();
|
|
5983
|
+
cases.push(_cases[0]);
|
|
5984
|
+
}
|
|
5985
|
+
return cases;
|
|
5986
|
+
}
|
|
5987
|
+
_case_selectors() {
|
|
5988
|
+
var _a2, _b, _c, _d;
|
|
5989
|
+
const selectors = [(_b = (_a2 = this._shift_expression()) === null || _a2 === void 0 ? void 0 : _a2.evaluate(this._context).toString()) !== null && _b !== void 0 ? _b : ""];
|
|
5990
|
+
while (this._match(TokenTypes.tokens.comma)) {
|
|
5991
|
+
selectors.push((_d = (_c = this._shift_expression()) === null || _c === void 0 ? void 0 : _c.evaluate(this._context).toString()) !== null && _d !== void 0 ? _d : "");
|
|
5992
|
+
}
|
|
5993
|
+
return selectors;
|
|
5994
|
+
}
|
|
5995
|
+
_case_body() {
|
|
5996
|
+
if (this._match(TokenTypes.keywords.fallthrough)) {
|
|
5997
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
5998
|
+
return [];
|
|
5999
|
+
}
|
|
6000
|
+
let statement = this._statement();
|
|
6001
|
+
if (statement == null)
|
|
6002
|
+
return [];
|
|
6003
|
+
if (!(statement instanceof Array)) {
|
|
6004
|
+
statement = [statement];
|
|
6005
|
+
}
|
|
6006
|
+
const nextStatement = this._case_body();
|
|
6007
|
+
if (nextStatement.length == 0)
|
|
6008
|
+
return statement;
|
|
6009
|
+
return [...statement, nextStatement[0]];
|
|
6010
|
+
}
|
|
6011
|
+
_if_statement() {
|
|
6012
|
+
if (!this._match(TokenTypes.keywords.if))
|
|
6013
|
+
return null;
|
|
6014
|
+
const condition = this._optional_paren_expression();
|
|
6015
|
+
const block = this._compound_statement();
|
|
6016
|
+
let elseif = [];
|
|
6017
|
+
if (this._match_elseif()) {
|
|
6018
|
+
elseif = this._elseif_statement(elseif);
|
|
6019
|
+
}
|
|
6020
|
+
let _else = null;
|
|
6021
|
+
if (this._match(TokenTypes.keywords.else))
|
|
6022
|
+
_else = this._compound_statement();
|
|
6023
|
+
return new If(condition, block, elseif, _else);
|
|
6024
|
+
}
|
|
6025
|
+
_match_elseif() {
|
|
6026
|
+
if (this._tokens[this._current].type === TokenTypes.keywords.else && this._tokens[this._current + 1].type === TokenTypes.keywords.if) {
|
|
6027
|
+
this._advance();
|
|
6028
|
+
this._advance();
|
|
6029
|
+
return true;
|
|
6030
|
+
}
|
|
6031
|
+
return false;
|
|
6032
|
+
}
|
|
6033
|
+
_elseif_statement(elseif = []) {
|
|
6034
|
+
const condition = this._optional_paren_expression();
|
|
6035
|
+
const block = this._compound_statement();
|
|
6036
|
+
elseif.push(new ElseIf(condition, block));
|
|
6037
|
+
if (this._match_elseif()) {
|
|
6038
|
+
this._elseif_statement(elseif);
|
|
6039
|
+
}
|
|
6040
|
+
return elseif;
|
|
6041
|
+
}
|
|
6042
|
+
_return_statement() {
|
|
6043
|
+
if (!this._match(TokenTypes.keywords.return))
|
|
6044
|
+
return null;
|
|
6045
|
+
const value = this._short_circuit_or_expression();
|
|
6046
|
+
return new Return(value);
|
|
6047
|
+
}
|
|
6048
|
+
_short_circuit_or_expression() {
|
|
6049
|
+
let expr = this._short_circuit_and_expr();
|
|
6050
|
+
while (this._match(TokenTypes.tokens.or_or)) {
|
|
6051
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._short_circuit_and_expr());
|
|
6052
|
+
}
|
|
6053
|
+
return expr;
|
|
6054
|
+
}
|
|
6055
|
+
_short_circuit_and_expr() {
|
|
6056
|
+
let expr = this._inclusive_or_expression();
|
|
6057
|
+
while (this._match(TokenTypes.tokens.and_and)) {
|
|
6058
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._inclusive_or_expression());
|
|
6059
|
+
}
|
|
6060
|
+
return expr;
|
|
6061
|
+
}
|
|
6062
|
+
_inclusive_or_expression() {
|
|
6063
|
+
let expr = this._exclusive_or_expression();
|
|
6064
|
+
while (this._match(TokenTypes.tokens.or)) {
|
|
6065
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._exclusive_or_expression());
|
|
6066
|
+
}
|
|
6067
|
+
return expr;
|
|
6068
|
+
}
|
|
6069
|
+
_exclusive_or_expression() {
|
|
6070
|
+
let expr = this._and_expression();
|
|
6071
|
+
while (this._match(TokenTypes.tokens.xor)) {
|
|
6072
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._and_expression());
|
|
6073
|
+
}
|
|
6074
|
+
return expr;
|
|
6075
|
+
}
|
|
6076
|
+
_and_expression() {
|
|
6077
|
+
let expr = this._equality_expression();
|
|
6078
|
+
while (this._match(TokenTypes.tokens.and)) {
|
|
6079
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._equality_expression());
|
|
6080
|
+
}
|
|
6081
|
+
return expr;
|
|
6082
|
+
}
|
|
6083
|
+
_equality_expression() {
|
|
6084
|
+
const expr = this._relational_expression();
|
|
6085
|
+
if (this._match([TokenTypes.tokens.equal_equal, TokenTypes.tokens.not_equal])) {
|
|
6086
|
+
return new BinaryOperator(this._previous().toString(), expr, this._relational_expression());
|
|
6087
|
+
}
|
|
6088
|
+
return expr;
|
|
6089
|
+
}
|
|
6090
|
+
_relational_expression() {
|
|
6091
|
+
let expr = this._shift_expression();
|
|
6092
|
+
while (this._match([TokenTypes.tokens.less_than, TokenTypes.tokens.greater_than, TokenTypes.tokens.less_than_equal, TokenTypes.tokens.greater_than_equal])) {
|
|
6093
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._shift_expression());
|
|
6094
|
+
}
|
|
6095
|
+
return expr;
|
|
6096
|
+
}
|
|
6097
|
+
_shift_expression() {
|
|
6098
|
+
let expr = this._additive_expression();
|
|
6099
|
+
while (this._match([TokenTypes.tokens.shift_left, TokenTypes.tokens.shift_right])) {
|
|
6100
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._additive_expression());
|
|
6101
|
+
}
|
|
6102
|
+
return expr;
|
|
6103
|
+
}
|
|
6104
|
+
_additive_expression() {
|
|
6105
|
+
let expr = this._multiplicative_expression();
|
|
6106
|
+
while (this._match([TokenTypes.tokens.plus, TokenTypes.tokens.minus])) {
|
|
6107
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._multiplicative_expression());
|
|
6108
|
+
}
|
|
6109
|
+
return expr;
|
|
6110
|
+
}
|
|
6111
|
+
_multiplicative_expression() {
|
|
6112
|
+
let expr = this._unary_expression();
|
|
6113
|
+
while (this._match([TokenTypes.tokens.star, TokenTypes.tokens.forward_slash, TokenTypes.tokens.modulo])) {
|
|
6114
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._unary_expression());
|
|
6115
|
+
}
|
|
6116
|
+
return expr;
|
|
6117
|
+
}
|
|
6118
|
+
_unary_expression() {
|
|
6119
|
+
if (this._match([TokenTypes.tokens.minus, TokenTypes.tokens.bang, TokenTypes.tokens.tilde, TokenTypes.tokens.star, TokenTypes.tokens.and])) {
|
|
6120
|
+
return new UnaryOperator(this._previous().toString(), this._unary_expression());
|
|
6121
|
+
}
|
|
6122
|
+
return this._singular_expression();
|
|
6123
|
+
}
|
|
6124
|
+
_singular_expression() {
|
|
6125
|
+
const expr = this._primary_expression();
|
|
6126
|
+
const p = this._postfix_expression();
|
|
6127
|
+
if (p)
|
|
6128
|
+
expr.postfix = p;
|
|
6129
|
+
return expr;
|
|
6130
|
+
}
|
|
6131
|
+
_postfix_expression() {
|
|
6132
|
+
if (this._match(TokenTypes.tokens.bracket_left)) {
|
|
6133
|
+
const expr = this._short_circuit_or_expression();
|
|
6134
|
+
this._consume(TokenTypes.tokens.bracket_right, "Expected ']'.");
|
|
6135
|
+
const p = this._postfix_expression();
|
|
6136
|
+
if (p)
|
|
6137
|
+
expr.postfix = p;
|
|
6138
|
+
return expr;
|
|
6139
|
+
}
|
|
6140
|
+
if (this._match(TokenTypes.tokens.period)) {
|
|
6141
|
+
const name2 = this._consume(TokenTypes.tokens.ident, "Expected member name.");
|
|
6142
|
+
const p = this._postfix_expression();
|
|
6143
|
+
const expr = new StringExpr(name2.lexeme);
|
|
6144
|
+
if (p)
|
|
6145
|
+
expr.postfix = p;
|
|
6146
|
+
return expr;
|
|
6147
|
+
}
|
|
6148
|
+
return null;
|
|
6149
|
+
}
|
|
6150
|
+
_getStruct(name2) {
|
|
6151
|
+
if (this._context.aliases.has(name2)) {
|
|
6152
|
+
const alias = this._context.aliases.get(name2).type;
|
|
6153
|
+
return alias;
|
|
6154
|
+
}
|
|
6155
|
+
if (this._context.structs.has(name2)) {
|
|
6156
|
+
const struct = this._context.structs.get(name2);
|
|
6157
|
+
return struct;
|
|
6158
|
+
}
|
|
6159
|
+
return null;
|
|
6160
|
+
}
|
|
6161
|
+
_primary_expression() {
|
|
6162
|
+
if (this._match(TokenTypes.tokens.ident)) {
|
|
6163
|
+
const name2 = this._previous().toString();
|
|
6164
|
+
if (this._check(TokenTypes.tokens.paren_left)) {
|
|
6165
|
+
const args2 = this._argument_expression_list();
|
|
6166
|
+
const struct = this._getStruct(name2);
|
|
6167
|
+
if (struct != null) {
|
|
6168
|
+
return new CreateExpr(struct, args2);
|
|
6169
|
+
}
|
|
6170
|
+
return new CallExpr(name2, args2);
|
|
6171
|
+
}
|
|
6172
|
+
if (this._context.constants.has(name2)) {
|
|
6173
|
+
const c = this._context.constants.get(name2);
|
|
6174
|
+
return new ConstExpr(name2, c.value);
|
|
6175
|
+
}
|
|
6176
|
+
return new VariableExpr(name2);
|
|
6177
|
+
}
|
|
6178
|
+
if (this._match(TokenTypes.const_literal)) {
|
|
6179
|
+
return new LiteralExpr(parseFloat(this._previous().toString()));
|
|
6180
|
+
}
|
|
6181
|
+
if (this._check(TokenTypes.tokens.paren_left)) {
|
|
6182
|
+
return this._paren_expression();
|
|
6183
|
+
}
|
|
6184
|
+
if (this._match(TokenTypes.keywords.bitcast)) {
|
|
6185
|
+
this._consume(TokenTypes.tokens.less_than, "Expected '<'.");
|
|
6186
|
+
const type2 = this._type_decl();
|
|
6187
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>'.");
|
|
6188
|
+
const value = this._paren_expression();
|
|
6189
|
+
return new BitcastExpr(type2, value);
|
|
6190
|
+
}
|
|
6191
|
+
const type = this._type_decl();
|
|
6192
|
+
const args = this._argument_expression_list();
|
|
6193
|
+
return new TypecastExpr(type, args);
|
|
6194
|
+
}
|
|
6195
|
+
_argument_expression_list() {
|
|
6196
|
+
if (!this._match(TokenTypes.tokens.paren_left))
|
|
6197
|
+
return null;
|
|
6198
|
+
const args = [];
|
|
6199
|
+
do {
|
|
6200
|
+
if (this._check(TokenTypes.tokens.paren_right))
|
|
6201
|
+
break;
|
|
6202
|
+
const arg = this._short_circuit_or_expression();
|
|
6203
|
+
args.push(arg);
|
|
6204
|
+
} while (this._match(TokenTypes.tokens.comma));
|
|
6205
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')' for agument list");
|
|
6206
|
+
return args;
|
|
6207
|
+
}
|
|
6208
|
+
_optional_paren_expression() {
|
|
6209
|
+
this._match(TokenTypes.tokens.paren_left);
|
|
6210
|
+
const expr = this._short_circuit_or_expression();
|
|
6211
|
+
this._match(TokenTypes.tokens.paren_right);
|
|
6212
|
+
return new GroupingExpr([expr]);
|
|
6213
|
+
}
|
|
6214
|
+
_paren_expression() {
|
|
6215
|
+
this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
|
|
6216
|
+
const expr = this._short_circuit_or_expression();
|
|
6217
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
|
|
6218
|
+
return new GroupingExpr([expr]);
|
|
6219
|
+
}
|
|
6220
|
+
_struct_decl() {
|
|
6221
|
+
if (!this._match(TokenTypes.keywords.struct))
|
|
6222
|
+
return null;
|
|
6223
|
+
const name2 = this._consume(TokenTypes.tokens.ident, "Expected name for struct.").toString();
|
|
6224
|
+
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for struct body.");
|
|
6225
|
+
const members = [];
|
|
6226
|
+
while (!this._check(TokenTypes.tokens.brace_right)) {
|
|
6227
|
+
const memberAttrs = this._attribute();
|
|
6228
|
+
const memberName = this._consume(TokenTypes.tokens.ident, "Expected variable name.").toString();
|
|
6229
|
+
this._consume(TokenTypes.tokens.colon, "Expected ':' for struct member type.");
|
|
6230
|
+
const typeAttrs = this._attribute();
|
|
6231
|
+
const memberType = this._type_decl();
|
|
6232
|
+
if (memberType != null)
|
|
6233
|
+
memberType.attributes = typeAttrs;
|
|
6234
|
+
if (!this._check(TokenTypes.tokens.brace_right))
|
|
6235
|
+
this._consume(TokenTypes.tokens.comma, "Expected ',' for struct member.");
|
|
6236
|
+
else
|
|
6237
|
+
this._match(TokenTypes.tokens.comma);
|
|
6238
|
+
members.push(new Member(memberName, memberType, memberAttrs));
|
|
6239
|
+
}
|
|
6240
|
+
this._consume(TokenTypes.tokens.brace_right, "Expected '}' after struct body.");
|
|
6241
|
+
const structNode = new Struct(name2, members);
|
|
6242
|
+
this._context.structs.set(name2, structNode);
|
|
6243
|
+
return structNode;
|
|
6244
|
+
}
|
|
6245
|
+
_global_variable_decl() {
|
|
6246
|
+
const _var = this._variable_decl();
|
|
6247
|
+
if (_var && this._match(TokenTypes.tokens.equal))
|
|
6248
|
+
_var.value = this._const_expression();
|
|
6249
|
+
return _var;
|
|
6250
|
+
}
|
|
6251
|
+
_override_variable_decl() {
|
|
6252
|
+
const _override = this._override_decl();
|
|
6253
|
+
if (_override && this._match(TokenTypes.tokens.equal))
|
|
6254
|
+
_override.value = this._const_expression();
|
|
6255
|
+
return _override;
|
|
6256
|
+
}
|
|
6257
|
+
_global_const_decl() {
|
|
6258
|
+
if (!this._match(TokenTypes.keywords.const))
|
|
6259
|
+
return null;
|
|
6260
|
+
const name2 = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
6261
|
+
let type = null;
|
|
6262
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
6263
|
+
const attrs = this._attribute();
|
|
6264
|
+
type = this._type_decl();
|
|
6265
|
+
if (type != null)
|
|
6266
|
+
type.attributes = attrs;
|
|
6267
|
+
}
|
|
6268
|
+
let value = null;
|
|
6269
|
+
if (this._match(TokenTypes.tokens.equal)) {
|
|
6270
|
+
const valueExpr = this._short_circuit_or_expression();
|
|
6271
|
+
if (valueExpr instanceof CreateExpr) {
|
|
6272
|
+
value = valueExpr;
|
|
6273
|
+
} else if (valueExpr instanceof ConstExpr && valueExpr.initializer instanceof CreateExpr) {
|
|
6274
|
+
value = valueExpr.initializer;
|
|
6275
|
+
} else {
|
|
6276
|
+
try {
|
|
6277
|
+
const constValue = valueExpr.evaluate(this._context);
|
|
6278
|
+
value = new LiteralExpr(constValue);
|
|
6279
|
+
} catch (_a2) {
|
|
6280
|
+
value = valueExpr;
|
|
6281
|
+
}
|
|
6282
|
+
}
|
|
6283
|
+
}
|
|
6284
|
+
const c = new Const(name2.toString(), type, "", "", value);
|
|
6285
|
+
this._context.constants.set(c.name, c);
|
|
6286
|
+
return c;
|
|
6287
|
+
}
|
|
6288
|
+
_global_let_decl() {
|
|
6289
|
+
if (!this._match(TokenTypes.keywords.let))
|
|
6290
|
+
return null;
|
|
6291
|
+
const name2 = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
6292
|
+
let type = null;
|
|
6293
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
6294
|
+
const attrs = this._attribute();
|
|
6295
|
+
type = this._type_decl();
|
|
6296
|
+
if (type != null)
|
|
6297
|
+
type.attributes = attrs;
|
|
6298
|
+
}
|
|
6299
|
+
let value = null;
|
|
6300
|
+
if (this._match(TokenTypes.tokens.equal)) {
|
|
6301
|
+
value = this._const_expression();
|
|
6302
|
+
}
|
|
6303
|
+
return new Let(name2.toString(), type, "", "", value);
|
|
6304
|
+
}
|
|
6305
|
+
_const_expression() {
|
|
6306
|
+
if (this._match(TokenTypes.const_literal))
|
|
6307
|
+
return new StringExpr(this._previous().toString());
|
|
6308
|
+
const type = this._type_decl();
|
|
6309
|
+
this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
|
|
6310
|
+
let args = [];
|
|
6311
|
+
while (!this._check(TokenTypes.tokens.paren_right)) {
|
|
6312
|
+
args.push(this._const_expression());
|
|
6313
|
+
if (!this._check(TokenTypes.tokens.comma))
|
|
6314
|
+
break;
|
|
6315
|
+
this._advance();
|
|
6316
|
+
}
|
|
6317
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
|
|
6318
|
+
return new CreateExpr(type, args);
|
|
6319
|
+
}
|
|
6320
|
+
_variable_decl() {
|
|
6321
|
+
if (!this._match(TokenTypes.keywords.var))
|
|
6322
|
+
return null;
|
|
6323
|
+
let storage = "";
|
|
6324
|
+
let access = "";
|
|
6325
|
+
if (this._match(TokenTypes.tokens.less_than)) {
|
|
6326
|
+
storage = this._consume(TokenTypes.storage_class, "Expected storage_class.").toString();
|
|
6327
|
+
if (this._match(TokenTypes.tokens.comma))
|
|
6328
|
+
access = this._consume(TokenTypes.access_mode, "Expected access_mode.").toString();
|
|
6329
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>'.");
|
|
6330
|
+
}
|
|
6331
|
+
const name2 = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
6332
|
+
let type = null;
|
|
6333
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
6334
|
+
const attrs = this._attribute();
|
|
6335
|
+
type = this._type_decl();
|
|
6336
|
+
if (type != null)
|
|
6337
|
+
type.attributes = attrs;
|
|
6338
|
+
}
|
|
6339
|
+
return new Var(name2.toString(), type, storage, access, null);
|
|
6340
|
+
}
|
|
6341
|
+
_override_decl() {
|
|
6342
|
+
if (!this._match(TokenTypes.keywords.override))
|
|
6343
|
+
return null;
|
|
6344
|
+
const name2 = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
6345
|
+
let type = null;
|
|
6346
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
6347
|
+
const attrs = this._attribute();
|
|
6348
|
+
type = this._type_decl();
|
|
6349
|
+
if (type != null)
|
|
6350
|
+
type.attributes = attrs;
|
|
6351
|
+
}
|
|
6352
|
+
return new Override(name2.toString(), type, null);
|
|
6353
|
+
}
|
|
6354
|
+
_enable_directive() {
|
|
6355
|
+
const name2 = this._consume(TokenTypes.tokens.ident, "identity expected.");
|
|
6356
|
+
return new Enable(name2.toString());
|
|
6357
|
+
}
|
|
6358
|
+
_type_alias() {
|
|
6359
|
+
const name2 = this._consume(TokenTypes.tokens.ident, "identity expected.");
|
|
6360
|
+
this._consume(TokenTypes.tokens.equal, "Expected '=' for type alias.");
|
|
6361
|
+
let aliasType = this._type_decl();
|
|
6362
|
+
if (aliasType === null) {
|
|
6363
|
+
throw this._error(this._peek(), "Expected Type for Alias.");
|
|
6364
|
+
}
|
|
6365
|
+
if (this._context.aliases.has(aliasType.name)) {
|
|
6366
|
+
aliasType = this._context.aliases.get(aliasType.name).type;
|
|
6367
|
+
}
|
|
6368
|
+
const aliasNode = new Alias(name2.toString(), aliasType);
|
|
6369
|
+
this._context.aliases.set(aliasNode.name, aliasNode);
|
|
6370
|
+
return aliasNode;
|
|
6371
|
+
}
|
|
6372
|
+
_type_decl() {
|
|
6373
|
+
if (this._check([TokenTypes.tokens.ident, ...TokenTypes.texel_format, TokenTypes.keywords.bool, TokenTypes.keywords.f32, TokenTypes.keywords.i32, TokenTypes.keywords.u32])) {
|
|
6374
|
+
const type2 = this._advance();
|
|
6375
|
+
const typeName = type2.toString();
|
|
6376
|
+
if (this._context.structs.has(typeName)) {
|
|
6377
|
+
return this._context.structs.get(typeName);
|
|
6378
|
+
}
|
|
6379
|
+
if (this._context.aliases.has(typeName)) {
|
|
6380
|
+
return this._context.aliases.get(typeName).type;
|
|
6381
|
+
}
|
|
6382
|
+
return new Type(type2.toString());
|
|
6383
|
+
}
|
|
6384
|
+
let type = this._texture_sampler_types();
|
|
6385
|
+
if (type)
|
|
6386
|
+
return type;
|
|
6387
|
+
if (this._check(TokenTypes.template_types)) {
|
|
6388
|
+
let type2 = this._advance().toString();
|
|
6389
|
+
let format = null;
|
|
6390
|
+
let access = null;
|
|
6391
|
+
if (this._match(TokenTypes.tokens.less_than)) {
|
|
6392
|
+
format = this._type_decl();
|
|
6393
|
+
access = null;
|
|
6394
|
+
if (this._match(TokenTypes.tokens.comma))
|
|
6395
|
+
access = this._consume(TokenTypes.access_mode, "Expected access_mode for pointer").toString();
|
|
6396
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for type.");
|
|
6397
|
+
}
|
|
6398
|
+
return new TemplateType(type2, format, access);
|
|
6399
|
+
}
|
|
6400
|
+
if (this._match(TokenTypes.keywords.ptr)) {
|
|
6401
|
+
let pointer = this._previous().toString();
|
|
6402
|
+
this._consume(TokenTypes.tokens.less_than, "Expected '<' for pointer.");
|
|
6403
|
+
const storage = this._consume(TokenTypes.storage_class, "Expected storage_class for pointer");
|
|
6404
|
+
this._consume(TokenTypes.tokens.comma, "Expected ',' for pointer.");
|
|
6405
|
+
const decl = this._type_decl();
|
|
6406
|
+
let access = null;
|
|
6407
|
+
if (this._match(TokenTypes.tokens.comma))
|
|
6408
|
+
access = this._consume(TokenTypes.access_mode, "Expected access_mode for pointer").toString();
|
|
6409
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for pointer.");
|
|
6410
|
+
return new PointerType(pointer, storage.toString(), decl, access);
|
|
6411
|
+
}
|
|
6412
|
+
const attrs = this._attribute();
|
|
6413
|
+
if (this._match(TokenTypes.keywords.array)) {
|
|
6414
|
+
let format = null;
|
|
6415
|
+
let countInt = -1;
|
|
6416
|
+
const array = this._previous();
|
|
6417
|
+
if (this._match(TokenTypes.tokens.less_than)) {
|
|
6418
|
+
format = this._type_decl();
|
|
6419
|
+
if (this._context.aliases.has(format.name)) {
|
|
6420
|
+
format = this._context.aliases.get(format.name).type;
|
|
6421
|
+
}
|
|
6422
|
+
let count = "";
|
|
6423
|
+
if (this._match(TokenTypes.tokens.comma)) {
|
|
6424
|
+
let c = this._shift_expression();
|
|
6425
|
+
count = c.evaluate(this._context).toString();
|
|
6426
|
+
}
|
|
6427
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for array.");
|
|
6428
|
+
countInt = count ? parseInt(count) : 0;
|
|
6429
|
+
}
|
|
6430
|
+
return new ArrayType(array.toString(), attrs, format, countInt);
|
|
6431
|
+
}
|
|
6432
|
+
return null;
|
|
6433
|
+
}
|
|
6434
|
+
_texture_sampler_types() {
|
|
6435
|
+
if (this._match(TokenTypes.sampler_type))
|
|
6436
|
+
return new SamplerType(this._previous().toString(), null, null);
|
|
6437
|
+
if (this._match(TokenTypes.depth_texture_type))
|
|
6438
|
+
return new SamplerType(this._previous().toString(), null, null);
|
|
6439
|
+
if (this._match(TokenTypes.sampled_texture_type) || this._match(TokenTypes.multisampled_texture_type)) {
|
|
6440
|
+
const sampler = this._previous();
|
|
6441
|
+
this._consume(TokenTypes.tokens.less_than, "Expected '<' for sampler type.");
|
|
6442
|
+
const format = this._type_decl();
|
|
6443
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for sampler type.");
|
|
6444
|
+
return new SamplerType(sampler.toString(), format, null);
|
|
6445
|
+
}
|
|
6446
|
+
if (this._match(TokenTypes.storage_texture_type)) {
|
|
6447
|
+
const sampler = this._previous();
|
|
6448
|
+
this._consume(TokenTypes.tokens.less_than, "Expected '<' for sampler type.");
|
|
6449
|
+
const format = this._consume(TokenTypes.texel_format, "Invalid texel format.").toString();
|
|
6450
|
+
this._consume(TokenTypes.tokens.comma, "Expected ',' after texel format.");
|
|
6451
|
+
const access = this._consume(TokenTypes.access_mode, "Expected access mode for storage texture type.").toString();
|
|
6452
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for sampler type.");
|
|
6453
|
+
return new SamplerType(sampler.toString(), format, access);
|
|
6454
|
+
}
|
|
6455
|
+
return null;
|
|
6456
|
+
}
|
|
6457
|
+
_attribute() {
|
|
6458
|
+
let attributes = [];
|
|
6459
|
+
while (this._match(TokenTypes.tokens.attr)) {
|
|
6460
|
+
const name2 = this._consume(TokenTypes.attribute_name, "Expected attribute name");
|
|
6461
|
+
const attr = new Attribute(name2.toString(), null);
|
|
6462
|
+
if (this._match(TokenTypes.tokens.paren_left)) {
|
|
6463
|
+
attr.value = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
|
|
6464
|
+
if (this._check(TokenTypes.tokens.comma)) {
|
|
6465
|
+
this._advance();
|
|
6466
|
+
do {
|
|
6467
|
+
const v = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
|
|
6468
|
+
if (!(attr.value instanceof Array)) {
|
|
6469
|
+
attr.value = [attr.value];
|
|
6470
|
+
}
|
|
6471
|
+
attr.value.push(v);
|
|
6472
|
+
} while (this._match(TokenTypes.tokens.comma));
|
|
6473
|
+
}
|
|
6474
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
|
|
6475
|
+
}
|
|
6476
|
+
attributes.push(attr);
|
|
6477
|
+
}
|
|
6478
|
+
while (this._match(TokenTypes.tokens.attr_left)) {
|
|
6479
|
+
if (!this._check(TokenTypes.tokens.attr_right)) {
|
|
6480
|
+
do {
|
|
6481
|
+
const name2 = this._consume(TokenTypes.attribute_name, "Expected attribute name");
|
|
6482
|
+
const attr = new Attribute(name2.toString(), null);
|
|
6483
|
+
if (this._match(TokenTypes.tokens.paren_left)) {
|
|
6484
|
+
attr.value = [this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString()];
|
|
6485
|
+
if (this._check(TokenTypes.tokens.comma)) {
|
|
6486
|
+
this._advance();
|
|
6487
|
+
do {
|
|
6488
|
+
const v = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
|
|
6489
|
+
attr.value.push(v);
|
|
6490
|
+
} while (this._match(TokenTypes.tokens.comma));
|
|
6491
|
+
}
|
|
6492
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
|
|
6493
|
+
}
|
|
6494
|
+
attributes.push(attr);
|
|
6495
|
+
} while (this._match(TokenTypes.tokens.comma));
|
|
6496
|
+
}
|
|
6497
|
+
this._consume(TokenTypes.tokens.attr_right, "Expected ']]' after attribute declarations");
|
|
6498
|
+
}
|
|
6499
|
+
if (attributes.length == 0)
|
|
6500
|
+
return null;
|
|
6501
|
+
return attributes;
|
|
6502
|
+
}
|
|
6503
|
+
};
|
|
6504
|
+
var TypeInfo = class {
|
|
6505
|
+
constructor(name2, attributes) {
|
|
6506
|
+
this.name = name2;
|
|
6507
|
+
this.attributes = attributes;
|
|
6508
|
+
this.size = 0;
|
|
6509
|
+
}
|
|
6510
|
+
get isArray() {
|
|
6511
|
+
return false;
|
|
6512
|
+
}
|
|
6513
|
+
get isStruct() {
|
|
6514
|
+
return false;
|
|
6515
|
+
}
|
|
6516
|
+
get isTemplate() {
|
|
6517
|
+
return false;
|
|
6518
|
+
}
|
|
6519
|
+
};
|
|
6520
|
+
var MemberInfo = class {
|
|
6521
|
+
constructor(name2, type, attributes) {
|
|
6522
|
+
this.name = name2;
|
|
6523
|
+
this.type = type;
|
|
6524
|
+
this.attributes = attributes;
|
|
6525
|
+
this.offset = 0;
|
|
6526
|
+
this.size = 0;
|
|
6527
|
+
}
|
|
6528
|
+
get isArray() {
|
|
6529
|
+
return this.type.isArray;
|
|
6530
|
+
}
|
|
6531
|
+
get isStruct() {
|
|
6532
|
+
return this.type.isStruct;
|
|
6533
|
+
}
|
|
6534
|
+
get isTemplate() {
|
|
6535
|
+
return this.type.isTemplate;
|
|
6536
|
+
}
|
|
6537
|
+
get align() {
|
|
6538
|
+
return this.type.isStruct ? this.type.align : 0;
|
|
6539
|
+
}
|
|
6540
|
+
get members() {
|
|
6541
|
+
return this.type.isStruct ? this.type.members : null;
|
|
6542
|
+
}
|
|
6543
|
+
get format() {
|
|
6544
|
+
return this.type.isArray ? this.type.format : this.type.isTemplate ? this.type.format : null;
|
|
6545
|
+
}
|
|
6546
|
+
get count() {
|
|
6547
|
+
return this.type.isArray ? this.type.count : 0;
|
|
6548
|
+
}
|
|
6549
|
+
get stride() {
|
|
6550
|
+
return this.type.isArray ? this.type.stride : this.size;
|
|
6551
|
+
}
|
|
6552
|
+
};
|
|
6553
|
+
var StructInfo = class extends TypeInfo {
|
|
6554
|
+
constructor(name2, attributes) {
|
|
6555
|
+
super(name2, attributes);
|
|
6556
|
+
this.members = [];
|
|
6557
|
+
this.align = 0;
|
|
6558
|
+
}
|
|
6559
|
+
get isStruct() {
|
|
6560
|
+
return true;
|
|
6561
|
+
}
|
|
6562
|
+
};
|
|
6563
|
+
var ArrayInfo = class extends TypeInfo {
|
|
6564
|
+
constructor(name2, attributes) {
|
|
6565
|
+
super(name2, attributes);
|
|
6566
|
+
this.count = 0;
|
|
6567
|
+
this.stride = 0;
|
|
6568
|
+
}
|
|
6569
|
+
get isArray() {
|
|
6570
|
+
return true;
|
|
6571
|
+
}
|
|
6572
|
+
};
|
|
6573
|
+
var TemplateInfo = class extends TypeInfo {
|
|
6574
|
+
constructor(name2, format, attributes, access) {
|
|
6575
|
+
super(name2, attributes);
|
|
6576
|
+
this.format = format;
|
|
6577
|
+
this.access = access;
|
|
6578
|
+
}
|
|
6579
|
+
get isTemplate() {
|
|
6580
|
+
return true;
|
|
6581
|
+
}
|
|
6582
|
+
};
|
|
6583
|
+
var ResourceType;
|
|
6584
|
+
(function(ResourceType2) {
|
|
6585
|
+
ResourceType2[ResourceType2["Uniform"] = 0] = "Uniform";
|
|
6586
|
+
ResourceType2[ResourceType2["Storage"] = 1] = "Storage";
|
|
6587
|
+
ResourceType2[ResourceType2["Texture"] = 2] = "Texture";
|
|
6588
|
+
ResourceType2[ResourceType2["Sampler"] = 3] = "Sampler";
|
|
6589
|
+
ResourceType2[ResourceType2["StorageTexture"] = 4] = "StorageTexture";
|
|
6590
|
+
})(ResourceType || (ResourceType = {}));
|
|
6591
|
+
var VariableInfo = class {
|
|
6592
|
+
constructor(name2, type, group, binding, attributes, resourceType, access) {
|
|
6593
|
+
this.name = name2;
|
|
6594
|
+
this.type = type;
|
|
6595
|
+
this.group = group;
|
|
6596
|
+
this.binding = binding;
|
|
6597
|
+
this.attributes = attributes;
|
|
6598
|
+
this.resourceType = resourceType;
|
|
6599
|
+
this.access = access;
|
|
6600
|
+
}
|
|
6601
|
+
get isArray() {
|
|
6602
|
+
return this.type.isArray;
|
|
6603
|
+
}
|
|
6604
|
+
get isStruct() {
|
|
6605
|
+
return this.type.isStruct;
|
|
6606
|
+
}
|
|
6607
|
+
get isTemplate() {
|
|
6608
|
+
return this.type.isTemplate;
|
|
6609
|
+
}
|
|
6610
|
+
get size() {
|
|
6611
|
+
return this.type.size;
|
|
6612
|
+
}
|
|
6613
|
+
get align() {
|
|
6614
|
+
return this.type.isStruct ? this.type.align : 0;
|
|
6615
|
+
}
|
|
6616
|
+
get members() {
|
|
6617
|
+
return this.type.isStruct ? this.type.members : null;
|
|
6618
|
+
}
|
|
6619
|
+
get format() {
|
|
6620
|
+
return this.type.isArray ? this.type.format : this.type.isTemplate ? this.type.format : null;
|
|
6621
|
+
}
|
|
6622
|
+
get count() {
|
|
6623
|
+
return this.type.isArray ? this.type.count : 0;
|
|
6624
|
+
}
|
|
6625
|
+
get stride() {
|
|
6626
|
+
return this.type.isArray ? this.type.stride : this.size;
|
|
6627
|
+
}
|
|
6628
|
+
};
|
|
6629
|
+
var AliasInfo = class {
|
|
6630
|
+
constructor(name2, type) {
|
|
6631
|
+
this.name = name2;
|
|
6632
|
+
this.type = type;
|
|
6633
|
+
}
|
|
6634
|
+
};
|
|
6635
|
+
var _TypeSize = class {
|
|
6636
|
+
constructor(align, size) {
|
|
6637
|
+
this.align = align;
|
|
6638
|
+
this.size = size;
|
|
6639
|
+
}
|
|
6640
|
+
};
|
|
6641
|
+
var InputInfo = class {
|
|
6642
|
+
constructor(name2, type, locationType, location) {
|
|
6643
|
+
this.name = name2;
|
|
6644
|
+
this.type = type;
|
|
6645
|
+
this.locationType = locationType;
|
|
6646
|
+
this.location = location;
|
|
6647
|
+
this.interpolation = null;
|
|
6648
|
+
}
|
|
6649
|
+
};
|
|
6650
|
+
var OutputInfo = class {
|
|
6651
|
+
constructor(name2, type, locationType, location) {
|
|
6652
|
+
this.name = name2;
|
|
6653
|
+
this.type = type;
|
|
6654
|
+
this.locationType = locationType;
|
|
6655
|
+
this.location = location;
|
|
6656
|
+
}
|
|
6657
|
+
};
|
|
6658
|
+
var FunctionInfo = class {
|
|
6659
|
+
constructor(name2, stage = null) {
|
|
6660
|
+
this.stage = null;
|
|
6661
|
+
this.inputs = [];
|
|
6662
|
+
this.outputs = [];
|
|
6663
|
+
this.name = name2;
|
|
6664
|
+
this.stage = stage;
|
|
6665
|
+
}
|
|
6666
|
+
};
|
|
6667
|
+
var EntryFunctions = class {
|
|
6668
|
+
constructor() {
|
|
6669
|
+
this.vertex = [];
|
|
6670
|
+
this.fragment = [];
|
|
6671
|
+
this.compute = [];
|
|
6672
|
+
}
|
|
6673
|
+
};
|
|
6674
|
+
var OverrideInfo = class {
|
|
6675
|
+
constructor(name2, type, attributes, id) {
|
|
6676
|
+
this.name = name2;
|
|
6677
|
+
this.type = type;
|
|
6678
|
+
this.attributes = attributes;
|
|
6679
|
+
this.id = id;
|
|
6680
|
+
}
|
|
6681
|
+
};
|
|
6682
|
+
var WgslReflect = class {
|
|
6683
|
+
constructor(code) {
|
|
6684
|
+
this.uniforms = [];
|
|
6685
|
+
this.storage = [];
|
|
6686
|
+
this.textures = [];
|
|
6687
|
+
this.samplers = [];
|
|
6688
|
+
this.aliases = [];
|
|
6689
|
+
this.overrides = [];
|
|
6690
|
+
this.structs = [];
|
|
6691
|
+
this.entry = new EntryFunctions();
|
|
6692
|
+
this._types = /* @__PURE__ */ new Map();
|
|
6693
|
+
if (code) {
|
|
6694
|
+
this.update(code);
|
|
6695
|
+
}
|
|
6696
|
+
}
|
|
6697
|
+
_isStorageTexture(type) {
|
|
6698
|
+
return type.name == "texture_storage_1d" || type.name == "texture_storage_2d" || type.name == "texture_storage_2d_array" || type.name == "texture_storage_3d";
|
|
6699
|
+
}
|
|
6700
|
+
update(code) {
|
|
6701
|
+
const parser = new WgslParser();
|
|
6702
|
+
const ast = parser.parse(code);
|
|
6703
|
+
for (const node of ast) {
|
|
6704
|
+
if (node instanceof Struct) {
|
|
6705
|
+
const info = this._getTypeInfo(node, null);
|
|
6706
|
+
if (info instanceof StructInfo) {
|
|
6707
|
+
this.structs.push(info);
|
|
6708
|
+
}
|
|
6709
|
+
continue;
|
|
6710
|
+
}
|
|
6711
|
+
if (node instanceof Alias) {
|
|
6712
|
+
this.aliases.push(this._getAliasInfo(node));
|
|
6713
|
+
continue;
|
|
6714
|
+
}
|
|
6715
|
+
if (node instanceof Override) {
|
|
6716
|
+
const v = node;
|
|
6717
|
+
const id = this._getAttributeNum(v.attributes, "id", 0);
|
|
6718
|
+
const type = v.type != null ? this._getTypeInfo(v.type, v.attributes) : null;
|
|
6719
|
+
this.overrides.push(new OverrideInfo(v.name, type, v.attributes, id));
|
|
6720
|
+
continue;
|
|
6721
|
+
}
|
|
6722
|
+
if (this._isUniformVar(node)) {
|
|
6723
|
+
const v = node;
|
|
6724
|
+
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
6725
|
+
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
6726
|
+
const type = this._getTypeInfo(v.type, v.attributes);
|
|
6727
|
+
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, ResourceType.Uniform, v.access);
|
|
6728
|
+
this.uniforms.push(varInfo);
|
|
6729
|
+
continue;
|
|
6730
|
+
}
|
|
6731
|
+
if (this._isStorageVar(node)) {
|
|
6732
|
+
const v = node;
|
|
6733
|
+
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
6734
|
+
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
6735
|
+
const type = this._getTypeInfo(v.type, v.attributes);
|
|
6736
|
+
const isStorageTexture = this._isStorageTexture(type);
|
|
6737
|
+
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, isStorageTexture ? ResourceType.StorageTexture : ResourceType.Storage, v.access);
|
|
6738
|
+
this.storage.push(varInfo);
|
|
6739
|
+
continue;
|
|
6740
|
+
}
|
|
6741
|
+
if (this._isTextureVar(node)) {
|
|
6742
|
+
const v = node;
|
|
6743
|
+
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
6744
|
+
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
6745
|
+
const type = this._getTypeInfo(v.type, v.attributes);
|
|
6746
|
+
const isStorageTexture = this._isStorageTexture(type);
|
|
6747
|
+
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, isStorageTexture ? ResourceType.StorageTexture : ResourceType.Texture, v.access);
|
|
6748
|
+
if (isStorageTexture) {
|
|
6749
|
+
this.storage.push(varInfo);
|
|
6750
|
+
} else {
|
|
6751
|
+
this.textures.push(varInfo);
|
|
6752
|
+
}
|
|
6753
|
+
continue;
|
|
6754
|
+
}
|
|
6755
|
+
if (this._isSamplerVar(node)) {
|
|
6756
|
+
const v = node;
|
|
6757
|
+
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
6758
|
+
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
6759
|
+
const type = this._getTypeInfo(v.type, v.attributes);
|
|
6760
|
+
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, ResourceType.Sampler, v.access);
|
|
6761
|
+
this.samplers.push(varInfo);
|
|
6762
|
+
continue;
|
|
6763
|
+
}
|
|
6764
|
+
if (node instanceof Function) {
|
|
6765
|
+
const vertexStage = this._getAttribute(node, "vertex");
|
|
6766
|
+
const fragmentStage = this._getAttribute(node, "fragment");
|
|
6767
|
+
const computeStage = this._getAttribute(node, "compute");
|
|
6768
|
+
const stage = vertexStage || fragmentStage || computeStage;
|
|
6769
|
+
if (stage) {
|
|
6770
|
+
const fn = new FunctionInfo(node.name, stage.name);
|
|
6771
|
+
fn.inputs = this._getInputs(node.args);
|
|
6772
|
+
fn.outputs = this._getOutputs(node.returnType);
|
|
6773
|
+
this.entry[stage.name].push(fn);
|
|
6774
|
+
}
|
|
6775
|
+
continue;
|
|
6776
|
+
}
|
|
6777
|
+
}
|
|
6778
|
+
}
|
|
6779
|
+
getBindGroups() {
|
|
6780
|
+
const groups = [];
|
|
6781
|
+
function _makeRoom(group, binding) {
|
|
6782
|
+
if (group >= groups.length)
|
|
6783
|
+
groups.length = group + 1;
|
|
6784
|
+
if (groups[group] === void 0)
|
|
6785
|
+
groups[group] = [];
|
|
6786
|
+
if (binding >= groups[group].length)
|
|
6787
|
+
groups[group].length = binding + 1;
|
|
6788
|
+
}
|
|
6789
|
+
for (const u of this.uniforms) {
|
|
6790
|
+
_makeRoom(u.group, u.binding);
|
|
6791
|
+
const group = groups[u.group];
|
|
6792
|
+
group[u.binding] = u;
|
|
6793
|
+
}
|
|
6794
|
+
for (const u of this.storage) {
|
|
6795
|
+
_makeRoom(u.group, u.binding);
|
|
6796
|
+
const group = groups[u.group];
|
|
6797
|
+
group[u.binding] = u;
|
|
6798
|
+
}
|
|
6799
|
+
for (const t of this.textures) {
|
|
6800
|
+
_makeRoom(t.group, t.binding);
|
|
6801
|
+
const group = groups[t.group];
|
|
6802
|
+
group[t.binding] = t;
|
|
6803
|
+
}
|
|
6804
|
+
for (const t of this.samplers) {
|
|
6805
|
+
_makeRoom(t.group, t.binding);
|
|
6806
|
+
const group = groups[t.group];
|
|
6807
|
+
group[t.binding] = t;
|
|
6808
|
+
}
|
|
6809
|
+
return groups;
|
|
6810
|
+
}
|
|
6811
|
+
_getOutputs(type, outputs = void 0) {
|
|
6812
|
+
if (outputs === void 0)
|
|
6813
|
+
outputs = [];
|
|
6814
|
+
if (type instanceof Struct) {
|
|
6815
|
+
this._getStructOutputs(type, outputs);
|
|
6816
|
+
} else {
|
|
6817
|
+
const output = this._getOutputInfo(type);
|
|
6818
|
+
if (output !== null)
|
|
6819
|
+
outputs.push(output);
|
|
6820
|
+
}
|
|
6821
|
+
return outputs;
|
|
6822
|
+
}
|
|
6823
|
+
_getStructOutputs(struct, outputs) {
|
|
6824
|
+
for (const m of struct.members) {
|
|
6825
|
+
if (m.type instanceof Struct) {
|
|
6826
|
+
this._getStructOutputs(m.type, outputs);
|
|
6827
|
+
} else {
|
|
6828
|
+
const location = this._getAttribute(m, "location") || this._getAttribute(m, "builtin");
|
|
6829
|
+
if (location !== null) {
|
|
6830
|
+
const typeInfo = this._getTypeInfo(m.type, m.type.attributes);
|
|
6831
|
+
const locationValue = this._parseInt(location.value);
|
|
6832
|
+
const info = new OutputInfo(m.name, typeInfo, location.name, locationValue);
|
|
6833
|
+
outputs.push(info);
|
|
6834
|
+
}
|
|
6835
|
+
}
|
|
6836
|
+
}
|
|
6837
|
+
}
|
|
6838
|
+
_getOutputInfo(type) {
|
|
6839
|
+
const location = this._getAttribute(type, "location") || this._getAttribute(type, "builtin");
|
|
6840
|
+
if (location !== null) {
|
|
6841
|
+
const typeInfo = this._getTypeInfo(type, type.attributes);
|
|
6842
|
+
const locationValue = this._parseInt(location.value);
|
|
6843
|
+
const info = new OutputInfo("", typeInfo, location.name, locationValue);
|
|
6844
|
+
return info;
|
|
6845
|
+
}
|
|
6846
|
+
return null;
|
|
6847
|
+
}
|
|
6848
|
+
_getInputs(args, inputs = void 0) {
|
|
6849
|
+
if (inputs === void 0)
|
|
6850
|
+
inputs = [];
|
|
6851
|
+
for (const arg of args) {
|
|
6852
|
+
if (arg.type instanceof Struct) {
|
|
6853
|
+
this._getStructInputs(arg.type, inputs);
|
|
6854
|
+
} else {
|
|
6855
|
+
const input = this._getInputInfo(arg);
|
|
6856
|
+
if (input !== null)
|
|
6857
|
+
inputs.push(input);
|
|
6858
|
+
}
|
|
6859
|
+
}
|
|
6860
|
+
return inputs;
|
|
6861
|
+
}
|
|
6862
|
+
_getStructInputs(struct, inputs) {
|
|
6863
|
+
for (const m of struct.members) {
|
|
6864
|
+
if (m.type instanceof Struct) {
|
|
6865
|
+
this._getStructInputs(m.type, inputs);
|
|
6866
|
+
} else {
|
|
6867
|
+
const input = this._getInputInfo(m);
|
|
6868
|
+
if (input !== null)
|
|
6869
|
+
inputs.push(input);
|
|
6870
|
+
}
|
|
6871
|
+
}
|
|
6872
|
+
}
|
|
6873
|
+
_getInputInfo(node) {
|
|
6874
|
+
const location = this._getAttribute(node, "location") || this._getAttribute(node, "builtin");
|
|
6875
|
+
if (location !== null) {
|
|
6876
|
+
const interpolation = this._getAttribute(node, "interpolation");
|
|
6877
|
+
const type = this._getTypeInfo(node.type, node.attributes);
|
|
6878
|
+
const locationValue = this._parseInt(location.value);
|
|
6879
|
+
const info = new InputInfo(node.name, type, location.name, locationValue);
|
|
6880
|
+
if (interpolation !== null) {
|
|
6881
|
+
info.interpolation = this._parseString(interpolation.value);
|
|
6882
|
+
}
|
|
6883
|
+
return info;
|
|
6884
|
+
}
|
|
6885
|
+
return null;
|
|
6886
|
+
}
|
|
6887
|
+
_parseString(s) {
|
|
6888
|
+
if (s instanceof Array) {
|
|
6889
|
+
s = s[0];
|
|
6890
|
+
}
|
|
6891
|
+
return s;
|
|
6892
|
+
}
|
|
6893
|
+
_parseInt(s) {
|
|
6894
|
+
if (s instanceof Array) {
|
|
6895
|
+
s = s[0];
|
|
6896
|
+
}
|
|
6897
|
+
const n = parseInt(s);
|
|
6898
|
+
return isNaN(n) ? s : n;
|
|
6899
|
+
}
|
|
6900
|
+
_getAlias(name2) {
|
|
6901
|
+
for (const a of this.aliases) {
|
|
6902
|
+
if (a.name == name2)
|
|
6903
|
+
return a.type;
|
|
6904
|
+
}
|
|
6905
|
+
return null;
|
|
6906
|
+
}
|
|
6907
|
+
_getAliasInfo(node) {
|
|
6908
|
+
return new AliasInfo(node.name, this._getTypeInfo(node.type, null));
|
|
6909
|
+
}
|
|
6910
|
+
_getTypeInfo(type, attributes) {
|
|
6911
|
+
if (this._types.has(type)) {
|
|
6912
|
+
return this._types.get(type);
|
|
6913
|
+
}
|
|
6914
|
+
if (type instanceof ArrayType) {
|
|
6915
|
+
const a = type;
|
|
6916
|
+
const t = this._getTypeInfo(a.format, a.attributes);
|
|
6917
|
+
const info2 = new ArrayInfo(a.name, attributes);
|
|
6918
|
+
info2.format = t;
|
|
6919
|
+
info2.count = a.count;
|
|
6920
|
+
this._types.set(type, info2);
|
|
6921
|
+
this._updateTypeInfo(info2);
|
|
6922
|
+
return info2;
|
|
6923
|
+
}
|
|
6924
|
+
if (type instanceof Struct) {
|
|
6925
|
+
const s = type;
|
|
6926
|
+
const info2 = new StructInfo(s.name, attributes);
|
|
6927
|
+
for (const m of s.members) {
|
|
6928
|
+
const t = this._getTypeInfo(m.type, m.attributes);
|
|
6929
|
+
info2.members.push(new MemberInfo(m.name, t, m.attributes));
|
|
4398
6930
|
}
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
6931
|
+
this._types.set(type, info2);
|
|
6932
|
+
this._updateTypeInfo(info2);
|
|
6933
|
+
return info2;
|
|
6934
|
+
}
|
|
6935
|
+
if (type instanceof SamplerType) {
|
|
6936
|
+
const s = type;
|
|
6937
|
+
const formatIsType = s.format instanceof Type;
|
|
6938
|
+
const format = s.format ? formatIsType ? this._getTypeInfo(s.format, null) : new TypeInfo(s.format, null) : null;
|
|
6939
|
+
const info2 = new TemplateInfo(s.name, format, attributes, s.access);
|
|
6940
|
+
this._types.set(type, info2);
|
|
6941
|
+
this._updateTypeInfo(info2);
|
|
6942
|
+
return info2;
|
|
6943
|
+
}
|
|
6944
|
+
if (type instanceof TemplateType) {
|
|
6945
|
+
const t = type;
|
|
6946
|
+
const format = t.format ? this._getTypeInfo(t.format, null) : null;
|
|
6947
|
+
const info2 = new TemplateInfo(t.name, format, attributes, t.access);
|
|
6948
|
+
this._types.set(type, info2);
|
|
6949
|
+
this._updateTypeInfo(info2);
|
|
6950
|
+
return info2;
|
|
6951
|
+
}
|
|
6952
|
+
const info = new TypeInfo(type.name, attributes);
|
|
6953
|
+
this._types.set(type, info);
|
|
6954
|
+
this._updateTypeInfo(info);
|
|
6955
|
+
return info;
|
|
6956
|
+
}
|
|
6957
|
+
_updateTypeInfo(type) {
|
|
6958
|
+
var _a2, _b;
|
|
6959
|
+
const typeSize = this._getTypeSize(type);
|
|
6960
|
+
type.size = (_a2 = typeSize === null || typeSize === void 0 ? void 0 : typeSize.size) !== null && _a2 !== void 0 ? _a2 : 0;
|
|
6961
|
+
if (type instanceof ArrayInfo) {
|
|
6962
|
+
const formatInfo = this._getTypeSize(type["format"]);
|
|
6963
|
+
type.stride = (_b = formatInfo === null || formatInfo === void 0 ? void 0 : formatInfo.size) !== null && _b !== void 0 ? _b : 0;
|
|
6964
|
+
this._updateTypeInfo(type["format"]);
|
|
6965
|
+
}
|
|
6966
|
+
if (type instanceof StructInfo) {
|
|
6967
|
+
this._updateStructInfo(type);
|
|
6968
|
+
}
|
|
6969
|
+
}
|
|
6970
|
+
_updateStructInfo(struct) {
|
|
6971
|
+
var _a2;
|
|
6972
|
+
let offset = 0;
|
|
6973
|
+
let lastSize = 0;
|
|
6974
|
+
let lastOffset = 0;
|
|
6975
|
+
let structAlign = 0;
|
|
6976
|
+
for (let mi = 0, ml = struct.members.length; mi < ml; ++mi) {
|
|
6977
|
+
const member = struct.members[mi];
|
|
6978
|
+
const sizeInfo = this._getTypeSize(member);
|
|
6979
|
+
if (!sizeInfo)
|
|
6980
|
+
continue;
|
|
6981
|
+
(_a2 = this._getAlias(member.type.name)) !== null && _a2 !== void 0 ? _a2 : member.type;
|
|
6982
|
+
const align = sizeInfo.align;
|
|
6983
|
+
const size = sizeInfo.size;
|
|
6984
|
+
offset = this._roundUp(align, offset + lastSize);
|
|
6985
|
+
lastSize = size;
|
|
6986
|
+
lastOffset = offset;
|
|
6987
|
+
structAlign = Math.max(structAlign, align);
|
|
6988
|
+
member.offset = offset;
|
|
6989
|
+
member.size = size;
|
|
6990
|
+
this._updateTypeInfo(member.type);
|
|
6991
|
+
}
|
|
6992
|
+
struct.size = this._roundUp(structAlign, lastOffset + lastSize);
|
|
6993
|
+
struct.align = structAlign;
|
|
6994
|
+
}
|
|
6995
|
+
_getTypeSize(type) {
|
|
6996
|
+
var _a2;
|
|
6997
|
+
if (type === null || type === void 0)
|
|
6998
|
+
return null;
|
|
6999
|
+
const explicitSize = this._getAttributeNum(type.attributes, "size", 0);
|
|
7000
|
+
const explicitAlign = this._getAttributeNum(type.attributes, "align", 0);
|
|
7001
|
+
if (type instanceof MemberInfo)
|
|
7002
|
+
type = type.type;
|
|
7003
|
+
if (type instanceof TypeInfo) {
|
|
7004
|
+
const alias = this._getAlias(type.name);
|
|
7005
|
+
if (alias !== null) {
|
|
7006
|
+
type = alias;
|
|
4403
7007
|
}
|
|
4404
|
-
|
|
7008
|
+
}
|
|
7009
|
+
{
|
|
7010
|
+
const info = WgslReflect._typeInfo[type.name];
|
|
7011
|
+
if (info !== void 0) {
|
|
7012
|
+
const divisor = type["format"] === "f16" ? 2 : 1;
|
|
7013
|
+
return new _TypeSize(Math.max(explicitAlign, info.align / divisor), Math.max(explicitSize, info.size / divisor));
|
|
7014
|
+
}
|
|
7015
|
+
}
|
|
7016
|
+
{
|
|
7017
|
+
const info = WgslReflect._typeInfo[type.name.substring(0, type.name.length - 1)];
|
|
7018
|
+
if (info) {
|
|
7019
|
+
const divisor = type.name[type.name.length - 1] === "h" ? 2 : 1;
|
|
7020
|
+
return new _TypeSize(Math.max(explicitAlign, info.align / divisor), Math.max(explicitSize, info.size / divisor));
|
|
7021
|
+
}
|
|
7022
|
+
}
|
|
7023
|
+
if (type instanceof ArrayInfo) {
|
|
7024
|
+
let arrayType = type;
|
|
7025
|
+
let align = 8;
|
|
7026
|
+
let size = 8;
|
|
7027
|
+
const E = this._getTypeSize(arrayType.format);
|
|
7028
|
+
if (E !== null) {
|
|
7029
|
+
size = E.size;
|
|
7030
|
+
align = E.align;
|
|
7031
|
+
}
|
|
7032
|
+
const N = arrayType.count;
|
|
7033
|
+
const stride = this._getAttributeNum((_a2 = type === null || type === void 0 ? void 0 : type.attributes) !== null && _a2 !== void 0 ? _a2 : null, "stride", this._roundUp(align, size));
|
|
7034
|
+
size = N * stride;
|
|
7035
|
+
if (explicitSize)
|
|
7036
|
+
size = explicitSize;
|
|
7037
|
+
return new _TypeSize(Math.max(explicitAlign, align), Math.max(explicitSize, size));
|
|
7038
|
+
}
|
|
7039
|
+
if (type instanceof StructInfo) {
|
|
7040
|
+
let align = 0;
|
|
7041
|
+
let size = 0;
|
|
7042
|
+
let offset = 0;
|
|
7043
|
+
let lastSize = 0;
|
|
7044
|
+
let lastOffset = 0;
|
|
7045
|
+
for (const m of type.members) {
|
|
7046
|
+
const mi = this._getTypeSize(m.type);
|
|
7047
|
+
if (mi !== null) {
|
|
7048
|
+
align = Math.max(mi.align, align);
|
|
7049
|
+
offset = this._roundUp(mi.align, offset + lastSize);
|
|
7050
|
+
lastSize = mi.size;
|
|
7051
|
+
lastOffset = offset;
|
|
7052
|
+
}
|
|
7053
|
+
}
|
|
7054
|
+
size = this._roundUp(align, lastOffset + lastSize);
|
|
7055
|
+
return new _TypeSize(Math.max(explicitAlign, align), Math.max(explicitSize, size));
|
|
7056
|
+
}
|
|
7057
|
+
return null;
|
|
4405
7058
|
}
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
// ../shadertools/src/lib/shader-assembler.ts
|
|
4409
|
-
var ShaderAssembler = class {
|
|
4410
|
-
_hookFunctions = [];
|
|
4411
|
-
_defaultModules = [];
|
|
4412
|
-
static getDefaultShaderAssembler() {
|
|
4413
|
-
ShaderAssembler.defaultShaderAssembler = ShaderAssembler.defaultShaderAssembler || new ShaderAssembler();
|
|
4414
|
-
return ShaderAssembler.defaultShaderAssembler;
|
|
7059
|
+
_isUniformVar(node) {
|
|
7060
|
+
return node instanceof Var && node.storage == "uniform";
|
|
4415
7061
|
}
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
7062
|
+
_isStorageVar(node) {
|
|
7063
|
+
return node instanceof Var && node.storage == "storage";
|
|
7064
|
+
}
|
|
7065
|
+
_isTextureVar(node) {
|
|
7066
|
+
return node instanceof Var && node.type !== null && WgslReflect._textureTypes.indexOf(node.type.name) != -1;
|
|
7067
|
+
}
|
|
7068
|
+
_isSamplerVar(node) {
|
|
7069
|
+
return node instanceof Var && node.type !== null && WgslReflect._samplerTypes.indexOf(node.type.name) != -1;
|
|
7070
|
+
}
|
|
7071
|
+
_getAttribute(node, name2) {
|
|
7072
|
+
const obj = node;
|
|
7073
|
+
if (!obj || !obj["attributes"])
|
|
7074
|
+
return null;
|
|
7075
|
+
const attrs = obj["attributes"];
|
|
7076
|
+
for (let a of attrs) {
|
|
7077
|
+
if (a.name == name2)
|
|
7078
|
+
return a;
|
|
4419
7079
|
}
|
|
7080
|
+
return null;
|
|
4420
7081
|
}
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
7082
|
+
_getAttributeNum(attributes, name2, defaultValue) {
|
|
7083
|
+
if (attributes === null)
|
|
7084
|
+
return defaultValue;
|
|
7085
|
+
for (let a of attributes) {
|
|
7086
|
+
if (a.name == name2) {
|
|
7087
|
+
let v = a !== null && a.value !== null ? a.value : defaultValue;
|
|
7088
|
+
if (v instanceof Array) {
|
|
7089
|
+
v = v[0];
|
|
7090
|
+
}
|
|
7091
|
+
if (typeof v === "number") {
|
|
7092
|
+
return v;
|
|
7093
|
+
}
|
|
7094
|
+
if (typeof v === "string") {
|
|
7095
|
+
return parseInt(v);
|
|
7096
|
+
}
|
|
7097
|
+
return defaultValue;
|
|
7098
|
+
}
|
|
7099
|
+
}
|
|
7100
|
+
return defaultValue;
|
|
4424
7101
|
}
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
7102
|
+
_roundUp(k, n) {
|
|
7103
|
+
return Math.ceil(n / k) * k;
|
|
7104
|
+
}
|
|
7105
|
+
};
|
|
7106
|
+
WgslReflect._typeInfo = {
|
|
7107
|
+
f16: {
|
|
7108
|
+
align: 2,
|
|
7109
|
+
size: 2
|
|
7110
|
+
},
|
|
7111
|
+
i32: {
|
|
7112
|
+
align: 4,
|
|
7113
|
+
size: 4
|
|
7114
|
+
},
|
|
7115
|
+
u32: {
|
|
7116
|
+
align: 4,
|
|
7117
|
+
size: 4
|
|
7118
|
+
},
|
|
7119
|
+
f32: {
|
|
7120
|
+
align: 4,
|
|
7121
|
+
size: 4
|
|
7122
|
+
},
|
|
7123
|
+
atomic: {
|
|
7124
|
+
align: 4,
|
|
7125
|
+
size: 4
|
|
7126
|
+
},
|
|
7127
|
+
vec2: {
|
|
7128
|
+
align: 8,
|
|
7129
|
+
size: 8
|
|
7130
|
+
},
|
|
7131
|
+
vec3: {
|
|
7132
|
+
align: 16,
|
|
7133
|
+
size: 12
|
|
7134
|
+
},
|
|
7135
|
+
vec4: {
|
|
7136
|
+
align: 16,
|
|
7137
|
+
size: 16
|
|
7138
|
+
},
|
|
7139
|
+
mat2x2: {
|
|
7140
|
+
align: 8,
|
|
7141
|
+
size: 16
|
|
7142
|
+
},
|
|
7143
|
+
mat3x2: {
|
|
7144
|
+
align: 8,
|
|
7145
|
+
size: 24
|
|
7146
|
+
},
|
|
7147
|
+
mat4x2: {
|
|
7148
|
+
align: 8,
|
|
7149
|
+
size: 32
|
|
7150
|
+
},
|
|
7151
|
+
mat2x3: {
|
|
7152
|
+
align: 16,
|
|
7153
|
+
size: 32
|
|
7154
|
+
},
|
|
7155
|
+
mat3x3: {
|
|
7156
|
+
align: 16,
|
|
7157
|
+
size: 48
|
|
7158
|
+
},
|
|
7159
|
+
mat4x3: {
|
|
7160
|
+
align: 16,
|
|
7161
|
+
size: 64
|
|
7162
|
+
},
|
|
7163
|
+
mat2x4: {
|
|
7164
|
+
align: 16,
|
|
7165
|
+
size: 32
|
|
7166
|
+
},
|
|
7167
|
+
mat3x4: {
|
|
7168
|
+
align: 16,
|
|
7169
|
+
size: 48
|
|
7170
|
+
},
|
|
7171
|
+
mat4x4: {
|
|
7172
|
+
align: 16,
|
|
7173
|
+
size: 64
|
|
7174
|
+
}
|
|
7175
|
+
};
|
|
7176
|
+
WgslReflect._textureTypes = TokenTypes.any_texture_type.map((t) => {
|
|
7177
|
+
return t.name;
|
|
7178
|
+
});
|
|
7179
|
+
WgslReflect._samplerTypes = TokenTypes.sampler_type.map((t) => {
|
|
7180
|
+
return t.name;
|
|
7181
|
+
});
|
|
7182
|
+
|
|
7183
|
+
// ../shadertools/src/lib/wgsl/get-shader-layout-wgsl.ts
|
|
7184
|
+
function getShaderLayoutFromWGSL(source) {
|
|
7185
|
+
const shaderLayout = {
|
|
7186
|
+
attributes: [],
|
|
7187
|
+
bindings: []
|
|
7188
|
+
};
|
|
7189
|
+
const parsedWGSL = parseWGSL(source);
|
|
7190
|
+
for (const uniform of parsedWGSL.uniforms) {
|
|
7191
|
+
const members = [];
|
|
7192
|
+
for (const member of uniform.type.members) {
|
|
7193
|
+
members.push({
|
|
7194
|
+
name: member.name,
|
|
7195
|
+
type: getType(member.type)
|
|
4429
7196
|
});
|
|
4430
7197
|
}
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
const assembled = assembleShaders({
|
|
4438
|
-
platformInfo: props.platformInfo,
|
|
4439
|
-
...options,
|
|
4440
|
-
modules,
|
|
4441
|
-
hookFunctions
|
|
7198
|
+
shaderLayout.bindings.push({
|
|
7199
|
+
type: "uniform",
|
|
7200
|
+
name: uniform.name,
|
|
7201
|
+
location: uniform.binding,
|
|
7202
|
+
group: uniform.group,
|
|
7203
|
+
members
|
|
4442
7204
|
});
|
|
4443
|
-
return {
|
|
4444
|
-
...assembled,
|
|
4445
|
-
modules
|
|
4446
|
-
};
|
|
4447
7205
|
}
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
const
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
7206
|
+
const vertex = parsedWGSL.entry.vertex[0];
|
|
7207
|
+
const attributeCount = vertex.inputs.length;
|
|
7208
|
+
for (let i = 0; i < attributeCount; i++) {
|
|
7209
|
+
const wgslAttribute = vertex.inputs[i];
|
|
7210
|
+
if (wgslAttribute.locationType === "location") {
|
|
7211
|
+
const type = getType(wgslAttribute.type);
|
|
7212
|
+
shaderLayout.attributes.push({
|
|
7213
|
+
name: wgslAttribute.name,
|
|
7214
|
+
location: wgslAttribute.location,
|
|
7215
|
+
type
|
|
7216
|
+
});
|
|
4457
7217
|
}
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
7218
|
+
}
|
|
7219
|
+
return shaderLayout;
|
|
7220
|
+
}
|
|
7221
|
+
function getType(type) {
|
|
7222
|
+
return type.format ? `${type.name}<${type.format.name}>` : type.name;
|
|
7223
|
+
}
|
|
7224
|
+
function parseWGSL(source) {
|
|
7225
|
+
try {
|
|
7226
|
+
return new WgslReflect(source);
|
|
7227
|
+
} catch (error2) {
|
|
7228
|
+
if (error2 instanceof Error) {
|
|
7229
|
+
throw error2;
|
|
4465
7230
|
}
|
|
4466
|
-
|
|
4467
|
-
|
|
7231
|
+
let message2 = "WGSL parse error";
|
|
7232
|
+
if (typeof error2 === "object" && error2?.message) {
|
|
7233
|
+
message2 += `: ${error2.message} `;
|
|
7234
|
+
}
|
|
7235
|
+
if (typeof error2 === "object" && error2?.token) {
|
|
7236
|
+
message2 += error2.token.line || "";
|
|
7237
|
+
}
|
|
7238
|
+
throw new Error(message2, {
|
|
7239
|
+
cause: error2
|
|
7240
|
+
});
|
|
4468
7241
|
}
|
|
4469
|
-
}
|
|
7242
|
+
}
|
|
4470
7243
|
|
|
4471
7244
|
// ../../node_modules/@math.gl/core/dist/lib/common.js
|
|
4472
7245
|
var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
|
|
@@ -7862,9 +10635,16 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
7862
10635
|
});
|
|
7863
10636
|
|
|
7864
10637
|
// ../engine/src/debug/debug-shader-layout.ts
|
|
7865
|
-
function getDebugTableForShaderLayout(layout, name2
|
|
10638
|
+
function getDebugTableForShaderLayout(layout, name2) {
|
|
7866
10639
|
const table = {};
|
|
7867
|
-
const header =
|
|
10640
|
+
const header = "Values";
|
|
10641
|
+
if (layout.attributes.length === 0 && !layout.varyings?.length) {
|
|
10642
|
+
return {
|
|
10643
|
+
"No attributes or varyings": {
|
|
10644
|
+
[header]: "N/A"
|
|
10645
|
+
}
|
|
10646
|
+
};
|
|
10647
|
+
}
|
|
7868
10648
|
for (const attributeDeclaration of layout.attributes) {
|
|
7869
10649
|
if (attributeDeclaration) {
|
|
7870
10650
|
const glslDeclaration = `${attributeDeclaration.location} ${attributeDeclaration.name}: ${attributeDeclaration.type}`;
|
|
@@ -7882,6 +10662,48 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
7882
10662
|
return table;
|
|
7883
10663
|
}
|
|
7884
10664
|
|
|
10665
|
+
// ../engine/src/debug/debug-framebuffer.ts
|
|
10666
|
+
var canvas = null;
|
|
10667
|
+
var ctx = null;
|
|
10668
|
+
function debugFramebuffer(fbo, {
|
|
10669
|
+
id,
|
|
10670
|
+
minimap,
|
|
10671
|
+
opaque,
|
|
10672
|
+
top = "0",
|
|
10673
|
+
left = "0",
|
|
10674
|
+
rgbaScale = 1
|
|
10675
|
+
}) {
|
|
10676
|
+
if (!canvas) {
|
|
10677
|
+
canvas = document.createElement("canvas");
|
|
10678
|
+
canvas.id = id;
|
|
10679
|
+
canvas.title = id;
|
|
10680
|
+
canvas.style.zIndex = "100";
|
|
10681
|
+
canvas.style.position = "absolute";
|
|
10682
|
+
canvas.style.top = top;
|
|
10683
|
+
canvas.style.left = left;
|
|
10684
|
+
canvas.style.border = "blue 1px solid";
|
|
10685
|
+
canvas.style.transform = "scaleY(-1)";
|
|
10686
|
+
document.body.appendChild(canvas);
|
|
10687
|
+
ctx = canvas.getContext("2d");
|
|
10688
|
+
}
|
|
10689
|
+
if (canvas.width !== fbo.width || canvas.height !== fbo.height) {
|
|
10690
|
+
canvas.width = fbo.width / 2;
|
|
10691
|
+
canvas.height = fbo.height / 2;
|
|
10692
|
+
canvas.style.width = "400px";
|
|
10693
|
+
canvas.style.height = "400px";
|
|
10694
|
+
}
|
|
10695
|
+
const color = fbo.device.readPixelsToArrayWebGL(fbo);
|
|
10696
|
+
const imageData = ctx.createImageData(fbo.width, fbo.height);
|
|
10697
|
+
const offset = 0;
|
|
10698
|
+
for (let i = 0; i < color.length; i += 4) {
|
|
10699
|
+
imageData.data[offset + i + 0] = color[i + 0] * rgbaScale;
|
|
10700
|
+
imageData.data[offset + i + 1] = color[i + 1] * rgbaScale;
|
|
10701
|
+
imageData.data[offset + i + 2] = color[i + 2] * rgbaScale;
|
|
10702
|
+
imageData.data[offset + i + 3] = opaque ? 255 : color[i + 3] * rgbaScale;
|
|
10703
|
+
}
|
|
10704
|
+
ctx.putImageData(imageData, 0, 0);
|
|
10705
|
+
}
|
|
10706
|
+
|
|
7885
10707
|
// ../engine/src/model/model.ts
|
|
7886
10708
|
var LOG_DRAW_PRIORITY = 2;
|
|
7887
10709
|
var LOG_DRAW_TIMEOUT = 1e4;
|
|
@@ -7908,6 +10730,17 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
7908
10730
|
Object.assign(this.userData, props.userData);
|
|
7909
10731
|
const moduleMap = Object.fromEntries(this.props.modules?.map((module) => [module.name, module]) || []);
|
|
7910
10732
|
this.setShaderInputs(props.shaderInputs || new ShaderInputs(moduleMap));
|
|
10733
|
+
const isWebGPU = this.device.info.type === "webgpu";
|
|
10734
|
+
if (this.props.source) {
|
|
10735
|
+
if (isWebGPU) {
|
|
10736
|
+
this.props.shaderLayout ||= getShaderLayoutFromWGSL(this.props.source);
|
|
10737
|
+
}
|
|
10738
|
+
this.props.fs = this.props.source;
|
|
10739
|
+
this.props.vs = this.props.source;
|
|
10740
|
+
}
|
|
10741
|
+
if (isWebGPU && typeof this.props.vs !== "string") {
|
|
10742
|
+
this.props.shaderLayout ||= getShaderLayoutFromWGSL(this.props.vs.wgsl);
|
|
10743
|
+
}
|
|
7911
10744
|
const platformInfo = getPlatformInfo(device);
|
|
7912
10745
|
const modules = (this.props.modules?.length > 0 ? this.props.modules : this.shaderInputs?.getModules()) || [];
|
|
7913
10746
|
const {
|
|
@@ -7995,6 +10828,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
7995
10828
|
} finally {
|
|
7996
10829
|
this._logDrawCallEnd();
|
|
7997
10830
|
}
|
|
10831
|
+
this._logFramebuffer(renderPass);
|
|
7998
10832
|
}
|
|
7999
10833
|
setGeometry(geometry) {
|
|
8000
10834
|
const gpuGeometry = geometry && makeGPUGeometry(this.device, geometry);
|
|
@@ -8006,9 +10840,18 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
8006
10840
|
return gpuGeometry;
|
|
8007
10841
|
}
|
|
8008
10842
|
_setGeometryAttributes(gpuGeometry) {
|
|
10843
|
+
const attributes = {
|
|
10844
|
+
...gpuGeometry.attributes
|
|
10845
|
+
};
|
|
10846
|
+
for (const [attributeName] of Object.entries(attributes)) {
|
|
10847
|
+
if (!this.pipeline.shaderLayout.attributes.find((layout) => layout.name === attributeName) && attributeName !== "positions") {
|
|
10848
|
+
delete attributes[attributeName];
|
|
10849
|
+
}
|
|
10850
|
+
}
|
|
8009
10851
|
this.vertexCount = gpuGeometry.vertexCount;
|
|
8010
|
-
this.setAttributes(gpuGeometry.attributes, "ignore-unknown");
|
|
8011
10852
|
this.setIndexBuffer(gpuGeometry.indices);
|
|
10853
|
+
this.setAttributes(gpuGeometry.attributes, "ignore-unknown");
|
|
10854
|
+
this.setAttributes(attributes);
|
|
8012
10855
|
}
|
|
8013
10856
|
setTopology(topology) {
|
|
8014
10857
|
if (topology !== this.topology) {
|
|
@@ -8047,6 +10890,18 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
8047
10890
|
this.bindings[`${moduleName}Uniforms`] = uniformBuffer;
|
|
8048
10891
|
}
|
|
8049
10892
|
}
|
|
10893
|
+
setShaderModuleProps(props) {
|
|
10894
|
+
const uniforms = this._getModuleUniforms(props);
|
|
10895
|
+
const keys = Object.keys(uniforms).filter((k) => {
|
|
10896
|
+
const uniform = uniforms[k];
|
|
10897
|
+
return !isNumberArray(uniform) && typeof uniform !== "number" && typeof uniform !== "boolean";
|
|
10898
|
+
});
|
|
10899
|
+
const bindings = {};
|
|
10900
|
+
for (const k of keys) {
|
|
10901
|
+
bindings[k] = uniforms[k];
|
|
10902
|
+
delete uniforms[k];
|
|
10903
|
+
}
|
|
10904
|
+
}
|
|
8050
10905
|
updateShaderInputs() {
|
|
8051
10906
|
this._uniformStore.setUniforms(this.shaderInputs.getUniformValues());
|
|
8052
10907
|
}
|
|
@@ -8115,21 +10970,23 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
8115
10970
|
log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
|
|
8116
10971
|
}
|
|
8117
10972
|
this._pipelineNeedsUpdate = false;
|
|
10973
|
+
const vs3 = this.device.createShader({
|
|
10974
|
+
id: `${this.id}-vertex`,
|
|
10975
|
+
stage: "vertex",
|
|
10976
|
+
source: this.vs
|
|
10977
|
+
});
|
|
10978
|
+
const fs3 = this.fs ? this.device.createShader({
|
|
10979
|
+
id: `${this.id}-fragment`,
|
|
10980
|
+
stage: "fragment",
|
|
10981
|
+
source: this.fs
|
|
10982
|
+
}) : null;
|
|
8118
10983
|
this.pipeline = this.device.createRenderPipeline({
|
|
8119
10984
|
...this.props,
|
|
8120
10985
|
bufferLayout: this.bufferLayout,
|
|
8121
10986
|
topology: this.topology,
|
|
8122
10987
|
parameters: this.parameters,
|
|
8123
|
-
vs:
|
|
8124
|
-
|
|
8125
|
-
stage: "vertex",
|
|
8126
|
-
source: this.vs
|
|
8127
|
-
}),
|
|
8128
|
-
fs: this.fs ? this.device.createShader({
|
|
8129
|
-
id: "{$this.id}-fragment",
|
|
8130
|
-
stage: "fragment",
|
|
8131
|
-
source: this.fs
|
|
8132
|
-
}) : null
|
|
10988
|
+
vs: vs3,
|
|
10989
|
+
fs: fs3
|
|
8133
10990
|
});
|
|
8134
10991
|
this._attributeInfos = getAttributeInfosFromLayouts(this.pipeline.shaderLayout, this.bufferLayout);
|
|
8135
10992
|
}
|
|
@@ -8139,8 +10996,8 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
8139
10996
|
_logOpen = false;
|
|
8140
10997
|
_logDrawCallStart() {
|
|
8141
10998
|
const logDrawTimeout = log.level > 3 ? 0 : LOG_DRAW_TIMEOUT;
|
|
8142
|
-
if (Date.now() - this._lastLogTime < logDrawTimeout) {
|
|
8143
|
-
return
|
|
10999
|
+
if (log.level < 2 || Date.now() - this._lastLogTime < logDrawTimeout) {
|
|
11000
|
+
return;
|
|
8144
11001
|
}
|
|
8145
11002
|
this._lastLogTime = Date.now();
|
|
8146
11003
|
this._logOpen = true;
|
|
@@ -8150,7 +11007,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
8150
11007
|
}
|
|
8151
11008
|
_logDrawCallEnd() {
|
|
8152
11009
|
if (this._logOpen) {
|
|
8153
|
-
const shaderLayoutTable = getDebugTableForShaderLayout(this.pipeline.shaderLayout);
|
|
11010
|
+
const shaderLayoutTable = getDebugTableForShaderLayout(this.pipeline.shaderLayout, this.id);
|
|
8154
11011
|
log.table(LOG_DRAW_PRIORITY, shaderLayoutTable)();
|
|
8155
11012
|
const uniformTable = this.shaderInputs.getDebugTable();
|
|
8156
11013
|
for (const [name2, value] of Object.entries(this.uniforms)) {
|
|
@@ -8166,6 +11023,21 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
8166
11023
|
this._logOpen = false;
|
|
8167
11024
|
}
|
|
8168
11025
|
}
|
|
11026
|
+
_drawCount = 0;
|
|
11027
|
+
_logFramebuffer(renderPass) {
|
|
11028
|
+
const debugFramebuffers = log.get("framebuffer");
|
|
11029
|
+
this._drawCount++;
|
|
11030
|
+
if (!debugFramebuffers || this._drawCount++ > 3 && this._drawCount % 60) {
|
|
11031
|
+
return;
|
|
11032
|
+
}
|
|
11033
|
+
const framebuffer = renderPass.props.framebuffer;
|
|
11034
|
+
if (framebuffer) {
|
|
11035
|
+
debugFramebuffer(framebuffer, {
|
|
11036
|
+
id: framebuffer.id,
|
|
11037
|
+
minimap: true
|
|
11038
|
+
});
|
|
11039
|
+
}
|
|
11040
|
+
}
|
|
8169
11041
|
_getAttributeDebugTable() {
|
|
8170
11042
|
const table = {};
|
|
8171
11043
|
for (const [name2, attributeInfo] of Object.entries(this._attributeInfos)) {
|
|
@@ -8197,6 +11069,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
8197
11069
|
var Model = _Model;
|
|
8198
11070
|
__publicField(Model, "defaultProps", {
|
|
8199
11071
|
...RenderPipeline.defaultProps,
|
|
11072
|
+
source: null,
|
|
8200
11073
|
vs: null,
|
|
8201
11074
|
fs: null,
|
|
8202
11075
|
id: "unnamed",
|
|
@@ -10514,14 +13387,14 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
10514
13387
|
onContextLost: () => console.error("WebGL context lost"),
|
|
10515
13388
|
onContextRestored: () => console.info("WebGL context restored")
|
|
10516
13389
|
};
|
|
10517
|
-
function createBrowserContext(
|
|
13390
|
+
function createBrowserContext(canvas2, props) {
|
|
10518
13391
|
props = {
|
|
10519
13392
|
...DEFAULT_CONTEXT_PROPS,
|
|
10520
13393
|
...props
|
|
10521
13394
|
};
|
|
10522
13395
|
let errorMessage = null;
|
|
10523
13396
|
const onCreateError = (error2) => errorMessage = error2.statusMessage || errorMessage;
|
|
10524
|
-
|
|
13397
|
+
canvas2.addEventListener("webglcontextcreationerror", onCreateError, false);
|
|
10525
13398
|
let gl = null;
|
|
10526
13399
|
if (props.type === "webgl2") {
|
|
10527
13400
|
props = {
|
|
@@ -10536,12 +13409,12 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
10536
13409
|
};
|
|
10537
13410
|
}
|
|
10538
13411
|
if (!gl && props.webgl2) {
|
|
10539
|
-
gl =
|
|
13412
|
+
gl = canvas2.getContext("webgl2", props);
|
|
10540
13413
|
}
|
|
10541
13414
|
if (!gl && props.webgl1) {
|
|
10542
|
-
gl =
|
|
13415
|
+
gl = canvas2.getContext("webgl", props);
|
|
10543
13416
|
}
|
|
10544
|
-
|
|
13417
|
+
canvas2.removeEventListener("webglcontextcreationerror", onCreateError, false);
|
|
10545
13418
|
if (!gl) {
|
|
10546
13419
|
throw new Error(`Failed to create ${props.webgl2 && !props.webgl1 ? "WebGL2" : "WebGL"} context: ${errorMessage || "Unknown error"}`);
|
|
10547
13420
|
}
|
|
@@ -10549,13 +13422,13 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
10549
13422
|
const {
|
|
10550
13423
|
onContextLost
|
|
10551
13424
|
} = props;
|
|
10552
|
-
|
|
13425
|
+
canvas2.addEventListener("webglcontextlost", (event) => onContextLost(event), false);
|
|
10553
13426
|
}
|
|
10554
13427
|
if (props.onContextRestored) {
|
|
10555
13428
|
const {
|
|
10556
13429
|
onContextRestored
|
|
10557
13430
|
} = props;
|
|
10558
|
-
|
|
13431
|
+
canvas2.addEventListener("webglcontextrestored", (event) => onContextRestored(event), false);
|
|
10559
13432
|
}
|
|
10560
13433
|
return gl;
|
|
10561
13434
|
}
|
|
@@ -13250,9 +16123,12 @@ void main(void) {}`;
|
|
|
13250
16123
|
const sizeChanged = size[0] !== this.presentationSize[0] || size[1] !== this.presentationSize[1];
|
|
13251
16124
|
if (sizeChanged) {
|
|
13252
16125
|
this.presentationSize = size;
|
|
16126
|
+
this.resize();
|
|
13253
16127
|
}
|
|
13254
16128
|
}
|
|
13255
16129
|
resize(options) {
|
|
16130
|
+
if (!this.device.gl)
|
|
16131
|
+
return;
|
|
13256
16132
|
if (this.canvas) {
|
|
13257
16133
|
const devicePixelRatio = this.getDevicePixelRatio(options?.useDevicePixels);
|
|
13258
16134
|
this.setDevicePixelRatio(devicePixelRatio, options);
|
|
@@ -13616,6 +16492,30 @@ ${source2}`;
|
|
|
13616
16492
|
};
|
|
13617
16493
|
|
|
13618
16494
|
// ../webgl/src/classic/typed-array-utils.ts
|
|
16495
|
+
var ERR_TYPE_DEDUCTION = "Failed to deduce GL constant from typed array";
|
|
16496
|
+
function getGLTypeFromTypedArray(arrayOrType) {
|
|
16497
|
+
const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
|
|
16498
|
+
switch (type) {
|
|
16499
|
+
case Float32Array:
|
|
16500
|
+
return GLEnum2.FLOAT;
|
|
16501
|
+
case Uint16Array:
|
|
16502
|
+
return GLEnum2.UNSIGNED_SHORT;
|
|
16503
|
+
case Uint32Array:
|
|
16504
|
+
return GLEnum2.UNSIGNED_INT;
|
|
16505
|
+
case Uint8Array:
|
|
16506
|
+
return GLEnum2.UNSIGNED_BYTE;
|
|
16507
|
+
case Uint8ClampedArray:
|
|
16508
|
+
return GLEnum2.UNSIGNED_BYTE;
|
|
16509
|
+
case Int8Array:
|
|
16510
|
+
return GLEnum2.BYTE;
|
|
16511
|
+
case Int16Array:
|
|
16512
|
+
return GLEnum2.SHORT;
|
|
16513
|
+
case Int32Array:
|
|
16514
|
+
return GLEnum2.INT;
|
|
16515
|
+
default:
|
|
16516
|
+
throw new Error(ERR_TYPE_DEDUCTION);
|
|
16517
|
+
}
|
|
16518
|
+
}
|
|
13619
16519
|
function getTypedArrayFromGLType(glType, options) {
|
|
13620
16520
|
const {
|
|
13621
16521
|
clamped = true
|
|
@@ -13661,13 +16561,13 @@ ${source2}`;
|
|
|
13661
16561
|
};
|
|
13662
16562
|
var Accessor = class {
|
|
13663
16563
|
static getBytesPerElement(accessor) {
|
|
13664
|
-
const
|
|
13665
|
-
return
|
|
16564
|
+
const ArrayType2 = getTypedArrayFromGLType(accessor.type || GLEnum2.FLOAT);
|
|
16565
|
+
return ArrayType2.BYTES_PER_ELEMENT;
|
|
13666
16566
|
}
|
|
13667
16567
|
static getBytesPerVertex(accessor) {
|
|
13668
16568
|
assert2(accessor.size);
|
|
13669
|
-
const
|
|
13670
|
-
return
|
|
16569
|
+
const ArrayType2 = getTypedArrayFromGLType(accessor.type || GLEnum2.FLOAT);
|
|
16570
|
+
return ArrayType2.BYTES_PER_ELEMENT * accessor.size;
|
|
13671
16571
|
}
|
|
13672
16572
|
static resolve(...accessors) {
|
|
13673
16573
|
return new Accessor(...[DEFAULT_ACCESSOR_VALUES, ...accessors]);
|
|
@@ -14214,6 +17114,13 @@ ${source2}`;
|
|
|
14214
17114
|
this._compileAndLink();
|
|
14215
17115
|
this.introspectedLayout = getShaderLayout(this.device.gl, this.handle);
|
|
14216
17116
|
this.shaderLayout = mergeShaderLayout(this.introspectedLayout, props.shaderLayout);
|
|
17117
|
+
switch (this.props.topology) {
|
|
17118
|
+
case "triangle-fan-webgl":
|
|
17119
|
+
case "line-loop-webgl":
|
|
17120
|
+
log.warn(`Primitive topology ${this.props.topology} is deprecated and will be removed in v9.1`);
|
|
17121
|
+
break;
|
|
17122
|
+
default:
|
|
17123
|
+
}
|
|
14217
17124
|
}
|
|
14218
17125
|
destroy() {
|
|
14219
17126
|
if (this.handle) {
|
|
@@ -14918,6 +17825,166 @@ ${source2}`;
|
|
|
14918
17825
|
return /^\d+$/.test(value);
|
|
14919
17826
|
}
|
|
14920
17827
|
|
|
17828
|
+
// ../webgl/src/classic/format-utils.ts
|
|
17829
|
+
function glFormatToComponents(format) {
|
|
17830
|
+
switch (format) {
|
|
17831
|
+
case GLEnum2.ALPHA:
|
|
17832
|
+
case GLEnum2.R32F:
|
|
17833
|
+
case GLEnum2.RED:
|
|
17834
|
+
return 1;
|
|
17835
|
+
case GLEnum2.RG32F:
|
|
17836
|
+
case GLEnum2.RG:
|
|
17837
|
+
return 2;
|
|
17838
|
+
case GLEnum2.RGB:
|
|
17839
|
+
case GLEnum2.RGB32F:
|
|
17840
|
+
return 3;
|
|
17841
|
+
case GLEnum2.RGBA:
|
|
17842
|
+
case GLEnum2.RGBA32F:
|
|
17843
|
+
return 4;
|
|
17844
|
+
default:
|
|
17845
|
+
assert2(false);
|
|
17846
|
+
return 0;
|
|
17847
|
+
}
|
|
17848
|
+
}
|
|
17849
|
+
function glTypeToBytes(type) {
|
|
17850
|
+
switch (type) {
|
|
17851
|
+
case GLEnum2.UNSIGNED_BYTE:
|
|
17852
|
+
return 1;
|
|
17853
|
+
case GLEnum2.UNSIGNED_SHORT_5_6_5:
|
|
17854
|
+
case GLEnum2.UNSIGNED_SHORT_4_4_4_4:
|
|
17855
|
+
case GLEnum2.UNSIGNED_SHORT_5_5_5_1:
|
|
17856
|
+
return 2;
|
|
17857
|
+
case GLEnum2.FLOAT:
|
|
17858
|
+
return 4;
|
|
17859
|
+
default:
|
|
17860
|
+
assert2(false);
|
|
17861
|
+
return 0;
|
|
17862
|
+
}
|
|
17863
|
+
}
|
|
17864
|
+
|
|
17865
|
+
// ../webgl/src/classic/copy-and-blit.ts
|
|
17866
|
+
function readPixelsToArray(source, options) {
|
|
17867
|
+
const {
|
|
17868
|
+
sourceX = 0,
|
|
17869
|
+
sourceY = 0,
|
|
17870
|
+
sourceFormat = GLEnum2.RGBA,
|
|
17871
|
+
sourceAttachment = GLEnum2.COLOR_ATTACHMENT0
|
|
17872
|
+
} = options || {};
|
|
17873
|
+
let {
|
|
17874
|
+
target = null,
|
|
17875
|
+
sourceWidth,
|
|
17876
|
+
sourceHeight,
|
|
17877
|
+
sourceType
|
|
17878
|
+
} = options || {};
|
|
17879
|
+
const {
|
|
17880
|
+
framebuffer,
|
|
17881
|
+
deleteFramebuffer
|
|
17882
|
+
} = getFramebuffer2(source);
|
|
17883
|
+
assert2(framebuffer);
|
|
17884
|
+
const {
|
|
17885
|
+
gl,
|
|
17886
|
+
handle
|
|
17887
|
+
} = framebuffer;
|
|
17888
|
+
sourceWidth = sourceWidth || framebuffer.width;
|
|
17889
|
+
sourceHeight = sourceHeight || framebuffer.height;
|
|
17890
|
+
const attachment = sourceAttachment - GLEnum2.COLOR_ATTACHMENT0;
|
|
17891
|
+
sourceType = sourceType || framebuffer.colorAttachments[attachment]?.type || GLEnum2.UNSIGNED_BYTE;
|
|
17892
|
+
target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
|
|
17893
|
+
sourceType = sourceType || getGLTypeFromTypedArray(target);
|
|
17894
|
+
const prevHandle = gl.bindFramebuffer(GLEnum2.FRAMEBUFFER, handle);
|
|
17895
|
+
gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
|
|
17896
|
+
gl.bindFramebuffer(GLEnum2.FRAMEBUFFER, prevHandle || null);
|
|
17897
|
+
if (deleteFramebuffer) {
|
|
17898
|
+
framebuffer.destroy();
|
|
17899
|
+
}
|
|
17900
|
+
return target;
|
|
17901
|
+
}
|
|
17902
|
+
function readPixelsToBuffer(source, options) {
|
|
17903
|
+
const {
|
|
17904
|
+
target,
|
|
17905
|
+
sourceX = 0,
|
|
17906
|
+
sourceY = 0,
|
|
17907
|
+
sourceFormat = GLEnum2.RGBA,
|
|
17908
|
+
targetByteOffset = 0
|
|
17909
|
+
} = options || {};
|
|
17910
|
+
let {
|
|
17911
|
+
sourceWidth,
|
|
17912
|
+
sourceHeight,
|
|
17913
|
+
sourceType
|
|
17914
|
+
} = options || {};
|
|
17915
|
+
const {
|
|
17916
|
+
framebuffer,
|
|
17917
|
+
deleteFramebuffer
|
|
17918
|
+
} = getFramebuffer2(source);
|
|
17919
|
+
assert2(framebuffer);
|
|
17920
|
+
sourceWidth = sourceWidth || framebuffer.width;
|
|
17921
|
+
sourceHeight = sourceHeight || framebuffer.height;
|
|
17922
|
+
const webglFramebuffer = framebuffer;
|
|
17923
|
+
sourceType = sourceType || GLEnum2.UNSIGNED_BYTE;
|
|
17924
|
+
let webglBufferTarget = target;
|
|
17925
|
+
if (!webglBufferTarget) {
|
|
17926
|
+
const components = glFormatToComponents(sourceFormat);
|
|
17927
|
+
const byteCount = glTypeToBytes(sourceType);
|
|
17928
|
+
const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
|
|
17929
|
+
webglBufferTarget = webglFramebuffer.device.createBuffer({
|
|
17930
|
+
byteLength
|
|
17931
|
+
});
|
|
17932
|
+
}
|
|
17933
|
+
const commandEncoder = source.device.createCommandEncoder();
|
|
17934
|
+
commandEncoder.copyTextureToBuffer({
|
|
17935
|
+
source,
|
|
17936
|
+
width: sourceWidth,
|
|
17937
|
+
height: sourceHeight,
|
|
17938
|
+
origin: [sourceX, sourceY],
|
|
17939
|
+
destination: webglBufferTarget,
|
|
17940
|
+
byteOffset: targetByteOffset
|
|
17941
|
+
});
|
|
17942
|
+
commandEncoder.destroy();
|
|
17943
|
+
if (deleteFramebuffer) {
|
|
17944
|
+
framebuffer.destroy();
|
|
17945
|
+
}
|
|
17946
|
+
return webglBufferTarget;
|
|
17947
|
+
}
|
|
17948
|
+
function getFramebuffer2(source) {
|
|
17949
|
+
if (!(source instanceof Framebuffer)) {
|
|
17950
|
+
return {
|
|
17951
|
+
framebuffer: toFramebuffer(source),
|
|
17952
|
+
deleteFramebuffer: true
|
|
17953
|
+
};
|
|
17954
|
+
}
|
|
17955
|
+
return {
|
|
17956
|
+
framebuffer: source,
|
|
17957
|
+
deleteFramebuffer: false
|
|
17958
|
+
};
|
|
17959
|
+
}
|
|
17960
|
+
function toFramebuffer(texture, props) {
|
|
17961
|
+
const {
|
|
17962
|
+
device,
|
|
17963
|
+
width,
|
|
17964
|
+
height,
|
|
17965
|
+
id
|
|
17966
|
+
} = texture;
|
|
17967
|
+
const framebuffer = device.createFramebuffer({
|
|
17968
|
+
...props,
|
|
17969
|
+
id: `framebuffer-for-${id}`,
|
|
17970
|
+
width,
|
|
17971
|
+
height,
|
|
17972
|
+
colorAttachments: [texture]
|
|
17973
|
+
});
|
|
17974
|
+
return framebuffer;
|
|
17975
|
+
}
|
|
17976
|
+
function getPixelArray(pixelArray, type, format, width, height) {
|
|
17977
|
+
if (pixelArray) {
|
|
17978
|
+
return pixelArray;
|
|
17979
|
+
}
|
|
17980
|
+
type = type || GLEnum2.UNSIGNED_BYTE;
|
|
17981
|
+
const ArrayType2 = getTypedArrayFromGLType(type, {
|
|
17982
|
+
clamped: false
|
|
17983
|
+
});
|
|
17984
|
+
const components = glFormatToComponents(format);
|
|
17985
|
+
return new ArrayType2(width * height * components);
|
|
17986
|
+
}
|
|
17987
|
+
|
|
14921
17988
|
// ../webgl/src/adapter/webgl-device.ts
|
|
14922
17989
|
var LOG_LEVEL2 = 1;
|
|
14923
17990
|
var _WebGLDevice = class extends Device {
|
|
@@ -14980,7 +18047,11 @@ ${source2}`;
|
|
|
14980
18047
|
if (device) {
|
|
14981
18048
|
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
14982
18049
|
}
|
|
14983
|
-
|
|
18050
|
+
const canvas2 = props.canvas || props.gl?.canvas;
|
|
18051
|
+
this.canvasContext = new WebGLCanvasContext(this, {
|
|
18052
|
+
...props,
|
|
18053
|
+
canvas: canvas2
|
|
18054
|
+
});
|
|
14984
18055
|
this.lost = new Promise((resolve) => {
|
|
14985
18056
|
this._resolveContextLost = resolve;
|
|
14986
18057
|
});
|
|
@@ -15005,6 +18076,7 @@ ${source2}`;
|
|
|
15005
18076
|
this.gl2 = this.gl;
|
|
15006
18077
|
this.isWebGL2 = isWebGL22(this.gl);
|
|
15007
18078
|
this.isWebGL1 = !this.isWebGL2;
|
|
18079
|
+
this.canvasContext.resize();
|
|
15008
18080
|
this.info = getDeviceInfo(this.gl);
|
|
15009
18081
|
this.gl.device = this;
|
|
15010
18082
|
this.gl._version = this.isWebGL2 ? 2 : 1;
|
|
@@ -15030,10 +18102,10 @@ ${source2}`;
|
|
|
15030
18102
|
log.warn("WebGL debug mode activated. Performance reduced.")();
|
|
15031
18103
|
}
|
|
15032
18104
|
if (isBrowser() && props.spector) {
|
|
15033
|
-
const
|
|
18105
|
+
const canvas3 = this.handle.canvas || props.canvas;
|
|
15034
18106
|
this.spector = initializeSpectorJS({
|
|
15035
18107
|
...this.props,
|
|
15036
|
-
canvas
|
|
18108
|
+
canvas: canvas3
|
|
15037
18109
|
});
|
|
15038
18110
|
}
|
|
15039
18111
|
}
|
|
@@ -15118,6 +18190,12 @@ ${source2}`;
|
|
|
15118
18190
|
this.renderPass?.end();
|
|
15119
18191
|
this.renderPass = null;
|
|
15120
18192
|
}
|
|
18193
|
+
readPixelsToArrayWebGL(source, options) {
|
|
18194
|
+
return readPixelsToArray(source, options);
|
|
18195
|
+
}
|
|
18196
|
+
readPixelsToBufferWebGL2(source, options) {
|
|
18197
|
+
return readPixelsToBuffer(source, options);
|
|
18198
|
+
}
|
|
15121
18199
|
gl2 = null;
|
|
15122
18200
|
debug = false;
|
|
15123
18201
|
_canvasSizeInfo = {
|
|
@@ -15321,14 +18399,14 @@ ${source2}`;
|
|
|
15321
18399
|
};
|
|
15322
18400
|
function accessorToJsArray(accessor) {
|
|
15323
18401
|
if (!accessor._animation) {
|
|
15324
|
-
const
|
|
18402
|
+
const ArrayType2 = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];
|
|
15325
18403
|
const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];
|
|
15326
18404
|
const length4 = components * accessor.count;
|
|
15327
18405
|
const {
|
|
15328
18406
|
buffer,
|
|
15329
18407
|
byteOffset
|
|
15330
18408
|
} = accessor.bufferView.data;
|
|
15331
|
-
const array = new
|
|
18409
|
+
const array = new ArrayType2(buffer, byteOffset + (accessor.byteOffset || 0), length4);
|
|
15332
18410
|
if (components === 1) {
|
|
15333
18411
|
accessor._animation = Array.from(array);
|
|
15334
18412
|
} else {
|