@deck.gl/geo-layers 9.0.0-beta.1 → 9.0.0-beta.2
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 +2925 -49
- package/dist.min.js +68 -65
- package/package.json +5 -5
package/dist/dist.dev.js
CHANGED
|
@@ -4408,13 +4408,13 @@ var __exports__ = (() => {
|
|
|
4408
4408
|
return image;
|
|
4409
4409
|
case "image":
|
|
4410
4410
|
case "imagebitmap":
|
|
4411
|
-
const
|
|
4412
|
-
const context =
|
|
4411
|
+
const canvas2 = document.createElement("canvas");
|
|
4412
|
+
const context = canvas2.getContext("2d");
|
|
4413
4413
|
if (!context) {
|
|
4414
4414
|
throw new Error("getImageData");
|
|
4415
4415
|
}
|
|
4416
|
-
|
|
4417
|
-
|
|
4416
|
+
canvas2.width = image.width;
|
|
4417
|
+
canvas2.height = image.height;
|
|
4418
4418
|
context.drawImage(image, 0, 0);
|
|
4419
4419
|
return context.getImageData(0, 0, image.width, image.height);
|
|
4420
4420
|
default:
|
|
@@ -12814,7 +12814,7 @@ ${moduleSource}
|
|
|
12814
12814
|
}
|
|
12815
12815
|
function getShaderName(shader) {
|
|
12816
12816
|
let defaultName = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "unnamed";
|
|
12817
|
-
const SHADER_NAME_REGEXP = /#define[\
|
|
12817
|
+
const SHADER_NAME_REGEXP = /#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/;
|
|
12818
12818
|
const match = SHADER_NAME_REGEXP.exec(shader);
|
|
12819
12819
|
return match ? match[1] : defaultName;
|
|
12820
12820
|
}
|
|
@@ -13196,6 +13196,2779 @@ ${getApplicationDefines(allDefines)}
|
|
|
13196
13196
|
};
|
|
13197
13197
|
ShaderAssembler.defaultShaderAssembler = void 0;
|
|
13198
13198
|
|
|
13199
|
+
// ../../node_modules/@luma.gl/shadertools/dist/libs/wgsl-reflect/wgsl_reflect.module.js
|
|
13200
|
+
var ParseContext = class {
|
|
13201
|
+
constructor() {
|
|
13202
|
+
this.constants = /* @__PURE__ */ new Map();
|
|
13203
|
+
this.aliases = /* @__PURE__ */ new Map();
|
|
13204
|
+
this.structs = /* @__PURE__ */ new Map();
|
|
13205
|
+
}
|
|
13206
|
+
};
|
|
13207
|
+
var Node = class {
|
|
13208
|
+
constructor() {
|
|
13209
|
+
}
|
|
13210
|
+
get isAstNode() {
|
|
13211
|
+
return true;
|
|
13212
|
+
}
|
|
13213
|
+
get astNodeType() {
|
|
13214
|
+
return "";
|
|
13215
|
+
}
|
|
13216
|
+
evaluate(context) {
|
|
13217
|
+
throw new Error("Cannot evaluate node");
|
|
13218
|
+
}
|
|
13219
|
+
evaluateString(context) {
|
|
13220
|
+
return this.evaluate(context).toString();
|
|
13221
|
+
}
|
|
13222
|
+
};
|
|
13223
|
+
var Statement = class extends Node {
|
|
13224
|
+
constructor() {
|
|
13225
|
+
super();
|
|
13226
|
+
}
|
|
13227
|
+
};
|
|
13228
|
+
var Function = class extends Statement {
|
|
13229
|
+
constructor(name12, args, returnType, body) {
|
|
13230
|
+
super();
|
|
13231
|
+
this.name = name12;
|
|
13232
|
+
this.args = args;
|
|
13233
|
+
this.returnType = returnType;
|
|
13234
|
+
this.body = body;
|
|
13235
|
+
}
|
|
13236
|
+
get astNodeType() {
|
|
13237
|
+
return "function";
|
|
13238
|
+
}
|
|
13239
|
+
};
|
|
13240
|
+
var StaticAssert = class extends Statement {
|
|
13241
|
+
constructor(expression) {
|
|
13242
|
+
super();
|
|
13243
|
+
this.expression = expression;
|
|
13244
|
+
}
|
|
13245
|
+
get astNodeType() {
|
|
13246
|
+
return "staticAssert";
|
|
13247
|
+
}
|
|
13248
|
+
};
|
|
13249
|
+
var While = class extends Statement {
|
|
13250
|
+
constructor(condition, body) {
|
|
13251
|
+
super();
|
|
13252
|
+
this.condition = condition;
|
|
13253
|
+
this.body = body;
|
|
13254
|
+
}
|
|
13255
|
+
get astNodeType() {
|
|
13256
|
+
return "while";
|
|
13257
|
+
}
|
|
13258
|
+
};
|
|
13259
|
+
var Continuing = class extends Statement {
|
|
13260
|
+
constructor(body) {
|
|
13261
|
+
super();
|
|
13262
|
+
this.body = body;
|
|
13263
|
+
}
|
|
13264
|
+
get astNodeType() {
|
|
13265
|
+
return "continuing";
|
|
13266
|
+
}
|
|
13267
|
+
};
|
|
13268
|
+
var For = class extends Statement {
|
|
13269
|
+
constructor(init, condition, increment, body) {
|
|
13270
|
+
super();
|
|
13271
|
+
this.init = init;
|
|
13272
|
+
this.condition = condition;
|
|
13273
|
+
this.increment = increment;
|
|
13274
|
+
this.body = body;
|
|
13275
|
+
}
|
|
13276
|
+
get astNodeType() {
|
|
13277
|
+
return "for";
|
|
13278
|
+
}
|
|
13279
|
+
};
|
|
13280
|
+
var Var = class extends Statement {
|
|
13281
|
+
constructor(name12, type, storage, access, value) {
|
|
13282
|
+
super();
|
|
13283
|
+
this.name = name12;
|
|
13284
|
+
this.type = type;
|
|
13285
|
+
this.storage = storage;
|
|
13286
|
+
this.access = access;
|
|
13287
|
+
this.value = value;
|
|
13288
|
+
}
|
|
13289
|
+
get astNodeType() {
|
|
13290
|
+
return "var";
|
|
13291
|
+
}
|
|
13292
|
+
};
|
|
13293
|
+
var Override = class extends Statement {
|
|
13294
|
+
constructor(name12, type, value) {
|
|
13295
|
+
super();
|
|
13296
|
+
this.name = name12;
|
|
13297
|
+
this.type = type;
|
|
13298
|
+
this.value = value;
|
|
13299
|
+
}
|
|
13300
|
+
get astNodeType() {
|
|
13301
|
+
return "override";
|
|
13302
|
+
}
|
|
13303
|
+
};
|
|
13304
|
+
var Let = class extends Statement {
|
|
13305
|
+
constructor(name12, type, storage, access, value) {
|
|
13306
|
+
super();
|
|
13307
|
+
this.name = name12;
|
|
13308
|
+
this.type = type;
|
|
13309
|
+
this.storage = storage;
|
|
13310
|
+
this.access = access;
|
|
13311
|
+
this.value = value;
|
|
13312
|
+
}
|
|
13313
|
+
get astNodeType() {
|
|
13314
|
+
return "let";
|
|
13315
|
+
}
|
|
13316
|
+
};
|
|
13317
|
+
var Const = class extends Statement {
|
|
13318
|
+
constructor(name12, type, storage, access, value) {
|
|
13319
|
+
super();
|
|
13320
|
+
this.name = name12;
|
|
13321
|
+
this.type = type;
|
|
13322
|
+
this.storage = storage;
|
|
13323
|
+
this.access = access;
|
|
13324
|
+
this.value = value;
|
|
13325
|
+
}
|
|
13326
|
+
get astNodeType() {
|
|
13327
|
+
return "const";
|
|
13328
|
+
}
|
|
13329
|
+
evaluate(context) {
|
|
13330
|
+
return this.value.evaluate(context);
|
|
13331
|
+
}
|
|
13332
|
+
};
|
|
13333
|
+
var IncrementOperator;
|
|
13334
|
+
(function(IncrementOperator2) {
|
|
13335
|
+
IncrementOperator2["increment"] = "++";
|
|
13336
|
+
IncrementOperator2["decrement"] = "--";
|
|
13337
|
+
})(IncrementOperator || (IncrementOperator = {}));
|
|
13338
|
+
(function(IncrementOperator2) {
|
|
13339
|
+
function parse4(val2) {
|
|
13340
|
+
const key = val2;
|
|
13341
|
+
if (key == "parse")
|
|
13342
|
+
throw new Error("Invalid value for IncrementOperator");
|
|
13343
|
+
return IncrementOperator2[key];
|
|
13344
|
+
}
|
|
13345
|
+
IncrementOperator2.parse = parse4;
|
|
13346
|
+
})(IncrementOperator || (IncrementOperator = {}));
|
|
13347
|
+
var Increment = class extends Statement {
|
|
13348
|
+
constructor(operator, variable) {
|
|
13349
|
+
super();
|
|
13350
|
+
this.operator = operator;
|
|
13351
|
+
this.variable = variable;
|
|
13352
|
+
}
|
|
13353
|
+
get astNodeType() {
|
|
13354
|
+
return "increment";
|
|
13355
|
+
}
|
|
13356
|
+
};
|
|
13357
|
+
var AssignOperator;
|
|
13358
|
+
(function(AssignOperator2) {
|
|
13359
|
+
AssignOperator2["assign"] = "=";
|
|
13360
|
+
AssignOperator2["addAssign"] = "+=";
|
|
13361
|
+
AssignOperator2["subtractAssin"] = "-=";
|
|
13362
|
+
AssignOperator2["multiplyAssign"] = "*=";
|
|
13363
|
+
AssignOperator2["divideAssign"] = "/=";
|
|
13364
|
+
AssignOperator2["moduloAssign"] = "%=";
|
|
13365
|
+
AssignOperator2["andAssign"] = "&=";
|
|
13366
|
+
AssignOperator2["orAssign"] = "|=";
|
|
13367
|
+
AssignOperator2["xorAssign"] = "^=";
|
|
13368
|
+
AssignOperator2["shiftLeftAssign"] = "<<=";
|
|
13369
|
+
AssignOperator2["shiftRightAssign"] = ">>=";
|
|
13370
|
+
})(AssignOperator || (AssignOperator = {}));
|
|
13371
|
+
(function(AssignOperator2) {
|
|
13372
|
+
function parse4(val2) {
|
|
13373
|
+
const key = val2;
|
|
13374
|
+
if (key == "parse")
|
|
13375
|
+
throw new Error("Invalid value for AssignOperator");
|
|
13376
|
+
return AssignOperator2[key];
|
|
13377
|
+
}
|
|
13378
|
+
AssignOperator2.parse = parse4;
|
|
13379
|
+
})(AssignOperator || (AssignOperator = {}));
|
|
13380
|
+
var Assign = class extends Statement {
|
|
13381
|
+
constructor(operator, variable, value) {
|
|
13382
|
+
super();
|
|
13383
|
+
this.operator = operator;
|
|
13384
|
+
this.variable = variable;
|
|
13385
|
+
this.value = value;
|
|
13386
|
+
}
|
|
13387
|
+
get astNodeType() {
|
|
13388
|
+
return "assign";
|
|
13389
|
+
}
|
|
13390
|
+
};
|
|
13391
|
+
var Call = class extends Statement {
|
|
13392
|
+
constructor(name12, args) {
|
|
13393
|
+
super();
|
|
13394
|
+
this.name = name12;
|
|
13395
|
+
this.args = args;
|
|
13396
|
+
}
|
|
13397
|
+
get astNodeType() {
|
|
13398
|
+
return "call";
|
|
13399
|
+
}
|
|
13400
|
+
};
|
|
13401
|
+
var Loop = class extends Statement {
|
|
13402
|
+
constructor(body, continuing) {
|
|
13403
|
+
super();
|
|
13404
|
+
this.body = body;
|
|
13405
|
+
this.continuing = continuing;
|
|
13406
|
+
}
|
|
13407
|
+
get astNodeType() {
|
|
13408
|
+
return "loop";
|
|
13409
|
+
}
|
|
13410
|
+
};
|
|
13411
|
+
var Switch = class extends Statement {
|
|
13412
|
+
constructor(condition, body) {
|
|
13413
|
+
super();
|
|
13414
|
+
this.condition = condition;
|
|
13415
|
+
this.body = body;
|
|
13416
|
+
}
|
|
13417
|
+
get astNodeType() {
|
|
13418
|
+
return "body";
|
|
13419
|
+
}
|
|
13420
|
+
};
|
|
13421
|
+
var If = class extends Statement {
|
|
13422
|
+
constructor(condition, body, elseif, _else) {
|
|
13423
|
+
super();
|
|
13424
|
+
this.condition = condition;
|
|
13425
|
+
this.body = body;
|
|
13426
|
+
this.elseif = elseif;
|
|
13427
|
+
this.else = _else;
|
|
13428
|
+
}
|
|
13429
|
+
get astNodeType() {
|
|
13430
|
+
return "if";
|
|
13431
|
+
}
|
|
13432
|
+
};
|
|
13433
|
+
var Return = class extends Statement {
|
|
13434
|
+
constructor(value) {
|
|
13435
|
+
super();
|
|
13436
|
+
this.value = value;
|
|
13437
|
+
}
|
|
13438
|
+
get astNodeType() {
|
|
13439
|
+
return "return";
|
|
13440
|
+
}
|
|
13441
|
+
};
|
|
13442
|
+
var Enable = class extends Statement {
|
|
13443
|
+
constructor(name12) {
|
|
13444
|
+
super();
|
|
13445
|
+
this.name = name12;
|
|
13446
|
+
}
|
|
13447
|
+
get astNodeType() {
|
|
13448
|
+
return "enable";
|
|
13449
|
+
}
|
|
13450
|
+
};
|
|
13451
|
+
var Alias = class extends Statement {
|
|
13452
|
+
constructor(name12, type) {
|
|
13453
|
+
super();
|
|
13454
|
+
this.name = name12;
|
|
13455
|
+
this.type = type;
|
|
13456
|
+
}
|
|
13457
|
+
get astNodeType() {
|
|
13458
|
+
return "alias";
|
|
13459
|
+
}
|
|
13460
|
+
};
|
|
13461
|
+
var Discard = class extends Statement {
|
|
13462
|
+
constructor() {
|
|
13463
|
+
super();
|
|
13464
|
+
}
|
|
13465
|
+
get astNodeType() {
|
|
13466
|
+
return "discard";
|
|
13467
|
+
}
|
|
13468
|
+
};
|
|
13469
|
+
var Break = class extends Statement {
|
|
13470
|
+
constructor() {
|
|
13471
|
+
super();
|
|
13472
|
+
}
|
|
13473
|
+
get astNodeType() {
|
|
13474
|
+
return "break";
|
|
13475
|
+
}
|
|
13476
|
+
};
|
|
13477
|
+
var Continue = class extends Statement {
|
|
13478
|
+
constructor() {
|
|
13479
|
+
super();
|
|
13480
|
+
}
|
|
13481
|
+
get astNodeType() {
|
|
13482
|
+
return "continue";
|
|
13483
|
+
}
|
|
13484
|
+
};
|
|
13485
|
+
var Type = class extends Statement {
|
|
13486
|
+
constructor(name12) {
|
|
13487
|
+
super();
|
|
13488
|
+
this.name = name12;
|
|
13489
|
+
}
|
|
13490
|
+
get astNodeType() {
|
|
13491
|
+
return "type";
|
|
13492
|
+
}
|
|
13493
|
+
get isStruct() {
|
|
13494
|
+
return false;
|
|
13495
|
+
}
|
|
13496
|
+
get isArray() {
|
|
13497
|
+
return false;
|
|
13498
|
+
}
|
|
13499
|
+
};
|
|
13500
|
+
var Struct = class extends Type {
|
|
13501
|
+
constructor(name12, members) {
|
|
13502
|
+
super(name12);
|
|
13503
|
+
this.members = members;
|
|
13504
|
+
}
|
|
13505
|
+
get astNodeType() {
|
|
13506
|
+
return "struct";
|
|
13507
|
+
}
|
|
13508
|
+
get isStruct() {
|
|
13509
|
+
return true;
|
|
13510
|
+
}
|
|
13511
|
+
getMemberIndex(name12) {
|
|
13512
|
+
for (let i3 = 0; i3 < this.members.length; i3++) {
|
|
13513
|
+
if (this.members[i3].name == name12)
|
|
13514
|
+
return i3;
|
|
13515
|
+
}
|
|
13516
|
+
return -1;
|
|
13517
|
+
}
|
|
13518
|
+
};
|
|
13519
|
+
var TemplateType = class extends Type {
|
|
13520
|
+
constructor(name12, format, access) {
|
|
13521
|
+
super(name12);
|
|
13522
|
+
this.format = format;
|
|
13523
|
+
this.access = access;
|
|
13524
|
+
}
|
|
13525
|
+
get astNodeType() {
|
|
13526
|
+
return "template";
|
|
13527
|
+
}
|
|
13528
|
+
};
|
|
13529
|
+
var PointerType = class extends Type {
|
|
13530
|
+
constructor(name12, storage, type, access) {
|
|
13531
|
+
super(name12);
|
|
13532
|
+
this.storage = storage;
|
|
13533
|
+
this.type = type;
|
|
13534
|
+
this.access = access;
|
|
13535
|
+
}
|
|
13536
|
+
get astNodeType() {
|
|
13537
|
+
return "pointer";
|
|
13538
|
+
}
|
|
13539
|
+
};
|
|
13540
|
+
var ArrayType = class extends Type {
|
|
13541
|
+
constructor(name12, attributes, format, count) {
|
|
13542
|
+
super(name12);
|
|
13543
|
+
this.attributes = attributes;
|
|
13544
|
+
this.format = format;
|
|
13545
|
+
this.count = count;
|
|
13546
|
+
}
|
|
13547
|
+
get astNodeType() {
|
|
13548
|
+
return "array";
|
|
13549
|
+
}
|
|
13550
|
+
get isArray() {
|
|
13551
|
+
return true;
|
|
13552
|
+
}
|
|
13553
|
+
};
|
|
13554
|
+
var SamplerType = class extends Type {
|
|
13555
|
+
constructor(name12, format, access) {
|
|
13556
|
+
super(name12);
|
|
13557
|
+
this.format = format;
|
|
13558
|
+
this.access = access;
|
|
13559
|
+
}
|
|
13560
|
+
get astNodeType() {
|
|
13561
|
+
return "sampler";
|
|
13562
|
+
}
|
|
13563
|
+
};
|
|
13564
|
+
var Expression = class extends Node {
|
|
13565
|
+
constructor() {
|
|
13566
|
+
super();
|
|
13567
|
+
}
|
|
13568
|
+
};
|
|
13569
|
+
var StringExpr = class extends Expression {
|
|
13570
|
+
constructor(value) {
|
|
13571
|
+
super();
|
|
13572
|
+
this.value = value;
|
|
13573
|
+
}
|
|
13574
|
+
get astNodeType() {
|
|
13575
|
+
return "stringExpr";
|
|
13576
|
+
}
|
|
13577
|
+
toString() {
|
|
13578
|
+
return this.value;
|
|
13579
|
+
}
|
|
13580
|
+
evaluateString() {
|
|
13581
|
+
return this.value;
|
|
13582
|
+
}
|
|
13583
|
+
};
|
|
13584
|
+
var CreateExpr = class extends Expression {
|
|
13585
|
+
constructor(type, args) {
|
|
13586
|
+
super();
|
|
13587
|
+
this.type = type;
|
|
13588
|
+
this.args = args;
|
|
13589
|
+
}
|
|
13590
|
+
get astNodeType() {
|
|
13591
|
+
return "createExpr";
|
|
13592
|
+
}
|
|
13593
|
+
};
|
|
13594
|
+
var CallExpr = class extends Expression {
|
|
13595
|
+
constructor(name12, args) {
|
|
13596
|
+
super();
|
|
13597
|
+
this.name = name12;
|
|
13598
|
+
this.args = args;
|
|
13599
|
+
}
|
|
13600
|
+
get astNodeType() {
|
|
13601
|
+
return "callExpr";
|
|
13602
|
+
}
|
|
13603
|
+
evaluate(context) {
|
|
13604
|
+
switch (this.name) {
|
|
13605
|
+
case "abs":
|
|
13606
|
+
return Math.abs(this.args[0].evaluate(context));
|
|
13607
|
+
case "acos":
|
|
13608
|
+
return Math.acos(this.args[0].evaluate(context));
|
|
13609
|
+
case "acosh":
|
|
13610
|
+
return Math.acosh(this.args[0].evaluate(context));
|
|
13611
|
+
case "asin":
|
|
13612
|
+
return Math.asin(this.args[0].evaluate(context));
|
|
13613
|
+
case "asinh":
|
|
13614
|
+
return Math.asinh(this.args[0].evaluate(context));
|
|
13615
|
+
case "atan":
|
|
13616
|
+
return Math.atan(this.args[0].evaluate(context));
|
|
13617
|
+
case "atan2":
|
|
13618
|
+
return Math.atan2(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
13619
|
+
case "atanh":
|
|
13620
|
+
return Math.atanh(this.args[0].evaluate(context));
|
|
13621
|
+
case "ceil":
|
|
13622
|
+
return Math.ceil(this.args[0].evaluate(context));
|
|
13623
|
+
case "clamp":
|
|
13624
|
+
return Math.min(Math.max(this.args[0].evaluate(context), this.args[1].evaluate(context)), this.args[2].evaluate(context));
|
|
13625
|
+
case "cos":
|
|
13626
|
+
return Math.cos(this.args[0].evaluate(context));
|
|
13627
|
+
case "degrees":
|
|
13628
|
+
return this.args[0].evaluate(context) * 180 / Math.PI;
|
|
13629
|
+
case "distance":
|
|
13630
|
+
return Math.sqrt(Math.pow(this.args[0].evaluate(context) - this.args[1].evaluate(context), 2));
|
|
13631
|
+
case "dot":
|
|
13632
|
+
case "exp":
|
|
13633
|
+
return Math.exp(this.args[0].evaluate(context));
|
|
13634
|
+
case "exp2":
|
|
13635
|
+
return Math.pow(2, this.args[0].evaluate(context));
|
|
13636
|
+
case "floor":
|
|
13637
|
+
return Math.floor(this.args[0].evaluate(context));
|
|
13638
|
+
case "fma":
|
|
13639
|
+
return this.args[0].evaluate(context) * this.args[1].evaluate(context) + this.args[2].evaluate(context);
|
|
13640
|
+
case "fract":
|
|
13641
|
+
return this.args[0].evaluate(context) - Math.floor(this.args[0].evaluate(context));
|
|
13642
|
+
case "inverseSqrt":
|
|
13643
|
+
return 1 / Math.sqrt(this.args[0].evaluate(context));
|
|
13644
|
+
case "log":
|
|
13645
|
+
return Math.log(this.args[0].evaluate(context));
|
|
13646
|
+
case "log2":
|
|
13647
|
+
return Math.log2(this.args[0].evaluate(context));
|
|
13648
|
+
case "max":
|
|
13649
|
+
return Math.max(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
13650
|
+
case "min":
|
|
13651
|
+
return Math.min(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
13652
|
+
case "mix":
|
|
13653
|
+
return this.args[0].evaluate(context) * (1 - this.args[2].evaluate(context)) + this.args[1].evaluate(context) * this.args[2].evaluate(context);
|
|
13654
|
+
case "modf":
|
|
13655
|
+
return this.args[0].evaluate(context) - Math.floor(this.args[0].evaluate(context));
|
|
13656
|
+
case "pow":
|
|
13657
|
+
return Math.pow(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
13658
|
+
case "radians":
|
|
13659
|
+
return this.args[0].evaluate(context) * Math.PI / 180;
|
|
13660
|
+
case "round":
|
|
13661
|
+
return Math.round(this.args[0].evaluate(context));
|
|
13662
|
+
case "sign":
|
|
13663
|
+
return Math.sign(this.args[0].evaluate(context));
|
|
13664
|
+
case "sin":
|
|
13665
|
+
return Math.sin(this.args[0].evaluate(context));
|
|
13666
|
+
case "sinh":
|
|
13667
|
+
return Math.sinh(this.args[0].evaluate(context));
|
|
13668
|
+
case "saturate":
|
|
13669
|
+
return Math.min(Math.max(this.args[0].evaluate(context), 0), 1);
|
|
13670
|
+
case "smoothstep":
|
|
13671
|
+
return this.args[0].evaluate(context) * this.args[0].evaluate(context) * (3 - 2 * this.args[0].evaluate(context));
|
|
13672
|
+
case "sqrt":
|
|
13673
|
+
return Math.sqrt(this.args[0].evaluate(context));
|
|
13674
|
+
case "step":
|
|
13675
|
+
return this.args[0].evaluate(context) < this.args[1].evaluate(context) ? 0 : 1;
|
|
13676
|
+
case "tan":
|
|
13677
|
+
return Math.tan(this.args[0].evaluate(context));
|
|
13678
|
+
case "tanh":
|
|
13679
|
+
return Math.tanh(this.args[0].evaluate(context));
|
|
13680
|
+
case "trunc":
|
|
13681
|
+
return Math.trunc(this.args[0].evaluate(context));
|
|
13682
|
+
default:
|
|
13683
|
+
throw new Error("Non const function: " + this.name);
|
|
13684
|
+
}
|
|
13685
|
+
}
|
|
13686
|
+
};
|
|
13687
|
+
var VariableExpr = class extends Expression {
|
|
13688
|
+
constructor(name12) {
|
|
13689
|
+
super();
|
|
13690
|
+
this.name = name12;
|
|
13691
|
+
}
|
|
13692
|
+
get astNodeType() {
|
|
13693
|
+
return "varExpr";
|
|
13694
|
+
}
|
|
13695
|
+
};
|
|
13696
|
+
var ConstExpr = class extends Expression {
|
|
13697
|
+
constructor(name12, initializer) {
|
|
13698
|
+
super();
|
|
13699
|
+
this.name = name12;
|
|
13700
|
+
this.initializer = initializer;
|
|
13701
|
+
}
|
|
13702
|
+
get astNodeType() {
|
|
13703
|
+
return "constExpr";
|
|
13704
|
+
}
|
|
13705
|
+
evaluate(context) {
|
|
13706
|
+
var _a2, _b;
|
|
13707
|
+
if (this.initializer instanceof CreateExpr) {
|
|
13708
|
+
const property = (_a2 = this.postfix) === null || _a2 === void 0 ? void 0 : _a2.evaluateString(context);
|
|
13709
|
+
const type = (_b = this.initializer.type) === null || _b === void 0 ? void 0 : _b.name;
|
|
13710
|
+
const struct = context.structs.get(type);
|
|
13711
|
+
const memberIndex = struct === null || struct === void 0 ? void 0 : struct.getMemberIndex(property);
|
|
13712
|
+
if (memberIndex != -1) {
|
|
13713
|
+
const value = this.initializer.args[memberIndex].evaluate(context);
|
|
13714
|
+
return value;
|
|
13715
|
+
}
|
|
13716
|
+
console.log(memberIndex);
|
|
13717
|
+
}
|
|
13718
|
+
return this.initializer.evaluate(context);
|
|
13719
|
+
}
|
|
13720
|
+
};
|
|
13721
|
+
var LiteralExpr = class extends Expression {
|
|
13722
|
+
constructor(value) {
|
|
13723
|
+
super();
|
|
13724
|
+
this.value = value;
|
|
13725
|
+
}
|
|
13726
|
+
get astNodeType() {
|
|
13727
|
+
return "literalExpr";
|
|
13728
|
+
}
|
|
13729
|
+
evaluate() {
|
|
13730
|
+
return this.value;
|
|
13731
|
+
}
|
|
13732
|
+
};
|
|
13733
|
+
var BitcastExpr = class extends Expression {
|
|
13734
|
+
constructor(type, value) {
|
|
13735
|
+
super();
|
|
13736
|
+
this.type = type;
|
|
13737
|
+
this.value = value;
|
|
13738
|
+
}
|
|
13739
|
+
get astNodeType() {
|
|
13740
|
+
return "bitcastExpr";
|
|
13741
|
+
}
|
|
13742
|
+
};
|
|
13743
|
+
var TypecastExpr = class extends Expression {
|
|
13744
|
+
constructor(type, args) {
|
|
13745
|
+
super();
|
|
13746
|
+
this.type = type;
|
|
13747
|
+
this.args = args;
|
|
13748
|
+
}
|
|
13749
|
+
get astNodeType() {
|
|
13750
|
+
return "typecastExpr";
|
|
13751
|
+
}
|
|
13752
|
+
evaluate(context) {
|
|
13753
|
+
return this.args[0].evaluate(context);
|
|
13754
|
+
}
|
|
13755
|
+
};
|
|
13756
|
+
var GroupingExpr = class extends Expression {
|
|
13757
|
+
constructor(contents) {
|
|
13758
|
+
super();
|
|
13759
|
+
this.contents = contents;
|
|
13760
|
+
}
|
|
13761
|
+
get astNodeType() {
|
|
13762
|
+
return "groupExpr";
|
|
13763
|
+
}
|
|
13764
|
+
evaluate(context) {
|
|
13765
|
+
return this.contents[0].evaluate(context);
|
|
13766
|
+
}
|
|
13767
|
+
};
|
|
13768
|
+
var Operator = class extends Expression {
|
|
13769
|
+
constructor() {
|
|
13770
|
+
super();
|
|
13771
|
+
}
|
|
13772
|
+
};
|
|
13773
|
+
var UnaryOperator = class extends Operator {
|
|
13774
|
+
constructor(operator, right) {
|
|
13775
|
+
super();
|
|
13776
|
+
this.operator = operator;
|
|
13777
|
+
this.right = right;
|
|
13778
|
+
}
|
|
13779
|
+
get astNodeType() {
|
|
13780
|
+
return "unaryOp";
|
|
13781
|
+
}
|
|
13782
|
+
evaluate(context) {
|
|
13783
|
+
switch (this.operator) {
|
|
13784
|
+
case "+":
|
|
13785
|
+
return this.right.evaluate(context);
|
|
13786
|
+
case "-":
|
|
13787
|
+
return -this.right.evaluate(context);
|
|
13788
|
+
case "!":
|
|
13789
|
+
return this.right.evaluate(context) ? 0 : 1;
|
|
13790
|
+
case "~":
|
|
13791
|
+
return ~this.right.evaluate(context);
|
|
13792
|
+
default:
|
|
13793
|
+
throw new Error("Unknown unary operator: " + this.operator);
|
|
13794
|
+
}
|
|
13795
|
+
}
|
|
13796
|
+
};
|
|
13797
|
+
var BinaryOperator = class extends Operator {
|
|
13798
|
+
constructor(operator, left, right) {
|
|
13799
|
+
super();
|
|
13800
|
+
this.operator = operator;
|
|
13801
|
+
this.left = left;
|
|
13802
|
+
this.right = right;
|
|
13803
|
+
}
|
|
13804
|
+
get astNodeType() {
|
|
13805
|
+
return "binaryOp";
|
|
13806
|
+
}
|
|
13807
|
+
evaluate(context) {
|
|
13808
|
+
switch (this.operator) {
|
|
13809
|
+
case "+":
|
|
13810
|
+
return this.left.evaluate(context) + this.right.evaluate(context);
|
|
13811
|
+
case "-":
|
|
13812
|
+
return this.left.evaluate(context) - this.right.evaluate(context);
|
|
13813
|
+
case "*":
|
|
13814
|
+
return this.left.evaluate(context) * this.right.evaluate(context);
|
|
13815
|
+
case "/":
|
|
13816
|
+
return this.left.evaluate(context) / this.right.evaluate(context);
|
|
13817
|
+
case "%":
|
|
13818
|
+
return this.left.evaluate(context) % this.right.evaluate(context);
|
|
13819
|
+
case "==":
|
|
13820
|
+
return this.left.evaluate(context) == this.right.evaluate(context) ? 1 : 0;
|
|
13821
|
+
case "!=":
|
|
13822
|
+
return this.left.evaluate(context) != this.right.evaluate(context) ? 1 : 0;
|
|
13823
|
+
case "<":
|
|
13824
|
+
return this.left.evaluate(context) < this.right.evaluate(context) ? 1 : 0;
|
|
13825
|
+
case ">":
|
|
13826
|
+
return this.left.evaluate(context) > this.right.evaluate(context) ? 1 : 0;
|
|
13827
|
+
case "<=":
|
|
13828
|
+
return this.left.evaluate(context) <= this.right.evaluate(context) ? 1 : 0;
|
|
13829
|
+
case ">=":
|
|
13830
|
+
return this.left.evaluate(context) >= this.right.evaluate(context) ? 1 : 0;
|
|
13831
|
+
case "&&":
|
|
13832
|
+
return this.left.evaluate(context) && this.right.evaluate(context) ? 1 : 0;
|
|
13833
|
+
case "||":
|
|
13834
|
+
return this.left.evaluate(context) || this.right.evaluate(context) ? 1 : 0;
|
|
13835
|
+
default:
|
|
13836
|
+
throw new Error(`Unknown operator ${this.operator}`);
|
|
13837
|
+
}
|
|
13838
|
+
}
|
|
13839
|
+
};
|
|
13840
|
+
var SwitchCase = class extends Node {
|
|
13841
|
+
constructor() {
|
|
13842
|
+
super();
|
|
13843
|
+
}
|
|
13844
|
+
};
|
|
13845
|
+
var Case = class extends SwitchCase {
|
|
13846
|
+
constructor(selector, body) {
|
|
13847
|
+
super();
|
|
13848
|
+
this.selector = selector;
|
|
13849
|
+
this.body = body;
|
|
13850
|
+
}
|
|
13851
|
+
get astNodeType() {
|
|
13852
|
+
return "case";
|
|
13853
|
+
}
|
|
13854
|
+
};
|
|
13855
|
+
var Default = class extends SwitchCase {
|
|
13856
|
+
constructor(body) {
|
|
13857
|
+
super();
|
|
13858
|
+
this.body = body;
|
|
13859
|
+
}
|
|
13860
|
+
get astNodeType() {
|
|
13861
|
+
return "default";
|
|
13862
|
+
}
|
|
13863
|
+
};
|
|
13864
|
+
var Argument = class extends Node {
|
|
13865
|
+
constructor(name12, type, attributes) {
|
|
13866
|
+
super();
|
|
13867
|
+
this.name = name12;
|
|
13868
|
+
this.type = type;
|
|
13869
|
+
this.attributes = attributes;
|
|
13870
|
+
}
|
|
13871
|
+
get astNodeType() {
|
|
13872
|
+
return "argument";
|
|
13873
|
+
}
|
|
13874
|
+
};
|
|
13875
|
+
var ElseIf = class extends Node {
|
|
13876
|
+
constructor(condition, body) {
|
|
13877
|
+
super();
|
|
13878
|
+
this.condition = condition;
|
|
13879
|
+
this.body = body;
|
|
13880
|
+
}
|
|
13881
|
+
get astNodeType() {
|
|
13882
|
+
return "elseif";
|
|
13883
|
+
}
|
|
13884
|
+
};
|
|
13885
|
+
var Member = class extends Node {
|
|
13886
|
+
constructor(name12, type, attributes) {
|
|
13887
|
+
super();
|
|
13888
|
+
this.name = name12;
|
|
13889
|
+
this.type = type;
|
|
13890
|
+
this.attributes = attributes;
|
|
13891
|
+
}
|
|
13892
|
+
get astNodeType() {
|
|
13893
|
+
return "member";
|
|
13894
|
+
}
|
|
13895
|
+
};
|
|
13896
|
+
var Attribute = class extends Node {
|
|
13897
|
+
constructor(name12, value) {
|
|
13898
|
+
super();
|
|
13899
|
+
this.name = name12;
|
|
13900
|
+
this.value = value;
|
|
13901
|
+
}
|
|
13902
|
+
get astNodeType() {
|
|
13903
|
+
return "attribute";
|
|
13904
|
+
}
|
|
13905
|
+
};
|
|
13906
|
+
var _a;
|
|
13907
|
+
var TokenClass;
|
|
13908
|
+
(function(TokenClass2) {
|
|
13909
|
+
TokenClass2[TokenClass2["token"] = 0] = "token";
|
|
13910
|
+
TokenClass2[TokenClass2["keyword"] = 1] = "keyword";
|
|
13911
|
+
TokenClass2[TokenClass2["reserved"] = 2] = "reserved";
|
|
13912
|
+
})(TokenClass || (TokenClass = {}));
|
|
13913
|
+
var TokenType = class {
|
|
13914
|
+
constructor(name12, type, rule) {
|
|
13915
|
+
this.name = name12;
|
|
13916
|
+
this.type = type;
|
|
13917
|
+
this.rule = rule;
|
|
13918
|
+
}
|
|
13919
|
+
toString() {
|
|
13920
|
+
return this.name;
|
|
13921
|
+
}
|
|
13922
|
+
};
|
|
13923
|
+
var TokenTypes = class {
|
|
13924
|
+
};
|
|
13925
|
+
_a = TokenTypes;
|
|
13926
|
+
TokenTypes.none = new TokenType("", TokenClass.reserved, "");
|
|
13927
|
+
TokenTypes.eof = new TokenType("EOF", TokenClass.token, "");
|
|
13928
|
+
TokenTypes.reserved = {
|
|
13929
|
+
asm: new TokenType("asm", TokenClass.reserved, "asm"),
|
|
13930
|
+
bf16: new TokenType("bf16", TokenClass.reserved, "bf16"),
|
|
13931
|
+
do: new TokenType("do", TokenClass.reserved, "do"),
|
|
13932
|
+
enum: new TokenType("enum", TokenClass.reserved, "enum"),
|
|
13933
|
+
f16: new TokenType("f16", TokenClass.reserved, "f16"),
|
|
13934
|
+
f64: new TokenType("f64", TokenClass.reserved, "f64"),
|
|
13935
|
+
handle: new TokenType("handle", TokenClass.reserved, "handle"),
|
|
13936
|
+
i8: new TokenType("i8", TokenClass.reserved, "i8"),
|
|
13937
|
+
i16: new TokenType("i16", TokenClass.reserved, "i16"),
|
|
13938
|
+
i64: new TokenType("i64", TokenClass.reserved, "i64"),
|
|
13939
|
+
mat: new TokenType("mat", TokenClass.reserved, "mat"),
|
|
13940
|
+
premerge: new TokenType("premerge", TokenClass.reserved, "premerge"),
|
|
13941
|
+
regardless: new TokenType("regardless", TokenClass.reserved, "regardless"),
|
|
13942
|
+
typedef: new TokenType("typedef", TokenClass.reserved, "typedef"),
|
|
13943
|
+
u8: new TokenType("u8", TokenClass.reserved, "u8"),
|
|
13944
|
+
u16: new TokenType("u16", TokenClass.reserved, "u16"),
|
|
13945
|
+
u64: new TokenType("u64", TokenClass.reserved, "u64"),
|
|
13946
|
+
unless: new TokenType("unless", TokenClass.reserved, "unless"),
|
|
13947
|
+
using: new TokenType("using", TokenClass.reserved, "using"),
|
|
13948
|
+
vec: new TokenType("vec", TokenClass.reserved, "vec"),
|
|
13949
|
+
void: new TokenType("void", TokenClass.reserved, "void")
|
|
13950
|
+
};
|
|
13951
|
+
TokenTypes.keywords = {
|
|
13952
|
+
array: new TokenType("array", TokenClass.keyword, "array"),
|
|
13953
|
+
atomic: new TokenType("atomic", TokenClass.keyword, "atomic"),
|
|
13954
|
+
bool: new TokenType("bool", TokenClass.keyword, "bool"),
|
|
13955
|
+
f32: new TokenType("f32", TokenClass.keyword, "f32"),
|
|
13956
|
+
i32: new TokenType("i32", TokenClass.keyword, "i32"),
|
|
13957
|
+
mat2x2: new TokenType("mat2x2", TokenClass.keyword, "mat2x2"),
|
|
13958
|
+
mat2x3: new TokenType("mat2x3", TokenClass.keyword, "mat2x3"),
|
|
13959
|
+
mat2x4: new TokenType("mat2x4", TokenClass.keyword, "mat2x4"),
|
|
13960
|
+
mat3x2: new TokenType("mat3x2", TokenClass.keyword, "mat3x2"),
|
|
13961
|
+
mat3x3: new TokenType("mat3x3", TokenClass.keyword, "mat3x3"),
|
|
13962
|
+
mat3x4: new TokenType("mat3x4", TokenClass.keyword, "mat3x4"),
|
|
13963
|
+
mat4x2: new TokenType("mat4x2", TokenClass.keyword, "mat4x2"),
|
|
13964
|
+
mat4x3: new TokenType("mat4x3", TokenClass.keyword, "mat4x3"),
|
|
13965
|
+
mat4x4: new TokenType("mat4x4", TokenClass.keyword, "mat4x4"),
|
|
13966
|
+
ptr: new TokenType("ptr", TokenClass.keyword, "ptr"),
|
|
13967
|
+
sampler: new TokenType("sampler", TokenClass.keyword, "sampler"),
|
|
13968
|
+
sampler_comparison: new TokenType("sampler_comparison", TokenClass.keyword, "sampler_comparison"),
|
|
13969
|
+
struct: new TokenType("struct", TokenClass.keyword, "struct"),
|
|
13970
|
+
texture_1d: new TokenType("texture_1d", TokenClass.keyword, "texture_1d"),
|
|
13971
|
+
texture_2d: new TokenType("texture_2d", TokenClass.keyword, "texture_2d"),
|
|
13972
|
+
texture_2d_array: new TokenType("texture_2d_array", TokenClass.keyword, "texture_2d_array"),
|
|
13973
|
+
texture_3d: new TokenType("texture_3d", TokenClass.keyword, "texture_3d"),
|
|
13974
|
+
texture_cube: new TokenType("texture_cube", TokenClass.keyword, "texture_cube"),
|
|
13975
|
+
texture_cube_array: new TokenType("texture_cube_array", TokenClass.keyword, "texture_cube_array"),
|
|
13976
|
+
texture_multisampled_2d: new TokenType("texture_multisampled_2d", TokenClass.keyword, "texture_multisampled_2d"),
|
|
13977
|
+
texture_storage_1d: new TokenType("texture_storage_1d", TokenClass.keyword, "texture_storage_1d"),
|
|
13978
|
+
texture_storage_2d: new TokenType("texture_storage_2d", TokenClass.keyword, "texture_storage_2d"),
|
|
13979
|
+
texture_storage_2d_array: new TokenType("texture_storage_2d_array", TokenClass.keyword, "texture_storage_2d_array"),
|
|
13980
|
+
texture_storage_3d: new TokenType("texture_storage_3d", TokenClass.keyword, "texture_storage_3d"),
|
|
13981
|
+
texture_depth_2d: new TokenType("texture_depth_2d", TokenClass.keyword, "texture_depth_2d"),
|
|
13982
|
+
texture_depth_2d_array: new TokenType("texture_depth_2d_array", TokenClass.keyword, "texture_depth_2d_array"),
|
|
13983
|
+
texture_depth_cube: new TokenType("texture_depth_cube", TokenClass.keyword, "texture_depth_cube"),
|
|
13984
|
+
texture_depth_cube_array: new TokenType("texture_depth_cube_array", TokenClass.keyword, "texture_depth_cube_array"),
|
|
13985
|
+
texture_depth_multisampled_2d: new TokenType("texture_depth_multisampled_2d", TokenClass.keyword, "texture_depth_multisampled_2d"),
|
|
13986
|
+
texture_external: new TokenType("texture_external", TokenClass.keyword, "texture_external"),
|
|
13987
|
+
u32: new TokenType("u32", TokenClass.keyword, "u32"),
|
|
13988
|
+
vec2: new TokenType("vec2", TokenClass.keyword, "vec2"),
|
|
13989
|
+
vec3: new TokenType("vec3", TokenClass.keyword, "vec3"),
|
|
13990
|
+
vec4: new TokenType("vec4", TokenClass.keyword, "vec4"),
|
|
13991
|
+
bitcast: new TokenType("bitcast", TokenClass.keyword, "bitcast"),
|
|
13992
|
+
block: new TokenType("block", TokenClass.keyword, "block"),
|
|
13993
|
+
break: new TokenType("break", TokenClass.keyword, "break"),
|
|
13994
|
+
case: new TokenType("case", TokenClass.keyword, "case"),
|
|
13995
|
+
continue: new TokenType("continue", TokenClass.keyword, "continue"),
|
|
13996
|
+
continuing: new TokenType("continuing", TokenClass.keyword, "continuing"),
|
|
13997
|
+
default: new TokenType("default", TokenClass.keyword, "default"),
|
|
13998
|
+
discard: new TokenType("discard", TokenClass.keyword, "discard"),
|
|
13999
|
+
else: new TokenType("else", TokenClass.keyword, "else"),
|
|
14000
|
+
enable: new TokenType("enable", TokenClass.keyword, "enable"),
|
|
14001
|
+
fallthrough: new TokenType("fallthrough", TokenClass.keyword, "fallthrough"),
|
|
14002
|
+
false: new TokenType("false", TokenClass.keyword, "false"),
|
|
14003
|
+
fn: new TokenType("fn", TokenClass.keyword, "fn"),
|
|
14004
|
+
for: new TokenType("for", TokenClass.keyword, "for"),
|
|
14005
|
+
function: new TokenType("function", TokenClass.keyword, "function"),
|
|
14006
|
+
if: new TokenType("if", TokenClass.keyword, "if"),
|
|
14007
|
+
let: new TokenType("let", TokenClass.keyword, "let"),
|
|
14008
|
+
const: new TokenType("const", TokenClass.keyword, "const"),
|
|
14009
|
+
loop: new TokenType("loop", TokenClass.keyword, "loop"),
|
|
14010
|
+
while: new TokenType("while", TokenClass.keyword, "while"),
|
|
14011
|
+
private: new TokenType("private", TokenClass.keyword, "private"),
|
|
14012
|
+
read: new TokenType("read", TokenClass.keyword, "read"),
|
|
14013
|
+
read_write: new TokenType("read_write", TokenClass.keyword, "read_write"),
|
|
14014
|
+
return: new TokenType("return", TokenClass.keyword, "return"),
|
|
14015
|
+
storage: new TokenType("storage", TokenClass.keyword, "storage"),
|
|
14016
|
+
switch: new TokenType("switch", TokenClass.keyword, "switch"),
|
|
14017
|
+
true: new TokenType("true", TokenClass.keyword, "true"),
|
|
14018
|
+
alias: new TokenType("alias", TokenClass.keyword, "alias"),
|
|
14019
|
+
type: new TokenType("type", TokenClass.keyword, "type"),
|
|
14020
|
+
uniform: new TokenType("uniform", TokenClass.keyword, "uniform"),
|
|
14021
|
+
var: new TokenType("var", TokenClass.keyword, "var"),
|
|
14022
|
+
override: new TokenType("override", TokenClass.keyword, "override"),
|
|
14023
|
+
workgroup: new TokenType("workgroup", TokenClass.keyword, "workgroup"),
|
|
14024
|
+
write: new TokenType("write", TokenClass.keyword, "write"),
|
|
14025
|
+
r8unorm: new TokenType("r8unorm", TokenClass.keyword, "r8unorm"),
|
|
14026
|
+
r8snorm: new TokenType("r8snorm", TokenClass.keyword, "r8snorm"),
|
|
14027
|
+
r8uint: new TokenType("r8uint", TokenClass.keyword, "r8uint"),
|
|
14028
|
+
r8sint: new TokenType("r8sint", TokenClass.keyword, "r8sint"),
|
|
14029
|
+
r16uint: new TokenType("r16uint", TokenClass.keyword, "r16uint"),
|
|
14030
|
+
r16sint: new TokenType("r16sint", TokenClass.keyword, "r16sint"),
|
|
14031
|
+
r16float: new TokenType("r16float", TokenClass.keyword, "r16float"),
|
|
14032
|
+
rg8unorm: new TokenType("rg8unorm", TokenClass.keyword, "rg8unorm"),
|
|
14033
|
+
rg8snorm: new TokenType("rg8snorm", TokenClass.keyword, "rg8snorm"),
|
|
14034
|
+
rg8uint: new TokenType("rg8uint", TokenClass.keyword, "rg8uint"),
|
|
14035
|
+
rg8sint: new TokenType("rg8sint", TokenClass.keyword, "rg8sint"),
|
|
14036
|
+
r32uint: new TokenType("r32uint", TokenClass.keyword, "r32uint"),
|
|
14037
|
+
r32sint: new TokenType("r32sint", TokenClass.keyword, "r32sint"),
|
|
14038
|
+
r32float: new TokenType("r32float", TokenClass.keyword, "r32float"),
|
|
14039
|
+
rg16uint: new TokenType("rg16uint", TokenClass.keyword, "rg16uint"),
|
|
14040
|
+
rg16sint: new TokenType("rg16sint", TokenClass.keyword, "rg16sint"),
|
|
14041
|
+
rg16float: new TokenType("rg16float", TokenClass.keyword, "rg16float"),
|
|
14042
|
+
rgba8unorm: new TokenType("rgba8unorm", TokenClass.keyword, "rgba8unorm"),
|
|
14043
|
+
rgba8unorm_srgb: new TokenType("rgba8unorm_srgb", TokenClass.keyword, "rgba8unorm_srgb"),
|
|
14044
|
+
rgba8snorm: new TokenType("rgba8snorm", TokenClass.keyword, "rgba8snorm"),
|
|
14045
|
+
rgba8uint: new TokenType("rgba8uint", TokenClass.keyword, "rgba8uint"),
|
|
14046
|
+
rgba8sint: new TokenType("rgba8sint", TokenClass.keyword, "rgba8sint"),
|
|
14047
|
+
bgra8unorm: new TokenType("bgra8unorm", TokenClass.keyword, "bgra8unorm"),
|
|
14048
|
+
bgra8unorm_srgb: new TokenType("bgra8unorm_srgb", TokenClass.keyword, "bgra8unorm_srgb"),
|
|
14049
|
+
rgb10a2unorm: new TokenType("rgb10a2unorm", TokenClass.keyword, "rgb10a2unorm"),
|
|
14050
|
+
rg11b10float: new TokenType("rg11b10float", TokenClass.keyword, "rg11b10float"),
|
|
14051
|
+
rg32uint: new TokenType("rg32uint", TokenClass.keyword, "rg32uint"),
|
|
14052
|
+
rg32sint: new TokenType("rg32sint", TokenClass.keyword, "rg32sint"),
|
|
14053
|
+
rg32float: new TokenType("rg32float", TokenClass.keyword, "rg32float"),
|
|
14054
|
+
rgba16uint: new TokenType("rgba16uint", TokenClass.keyword, "rgba16uint"),
|
|
14055
|
+
rgba16sint: new TokenType("rgba16sint", TokenClass.keyword, "rgba16sint"),
|
|
14056
|
+
rgba16float: new TokenType("rgba16float", TokenClass.keyword, "rgba16float"),
|
|
14057
|
+
rgba32uint: new TokenType("rgba32uint", TokenClass.keyword, "rgba32uint"),
|
|
14058
|
+
rgba32sint: new TokenType("rgba32sint", TokenClass.keyword, "rgba32sint"),
|
|
14059
|
+
rgba32float: new TokenType("rgba32float", TokenClass.keyword, "rgba32float"),
|
|
14060
|
+
static_assert: new TokenType("static_assert", TokenClass.keyword, "static_assert")
|
|
14061
|
+
};
|
|
14062
|
+
TokenTypes.tokens = {
|
|
14063
|
+
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)/),
|
|
14064
|
+
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?))/),
|
|
14065
|
+
int_literal: new TokenType("int_literal", TokenClass.token, /-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),
|
|
14066
|
+
uint_literal: new TokenType("uint_literal", TokenClass.token, /0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),
|
|
14067
|
+
ident: new TokenType("ident", TokenClass.token, /[a-zA-Z][0-9a-zA-Z_]*/),
|
|
14068
|
+
and: new TokenType("and", TokenClass.token, "&"),
|
|
14069
|
+
and_and: new TokenType("and_and", TokenClass.token, "&&"),
|
|
14070
|
+
arrow: new TokenType("arrow ", TokenClass.token, "->"),
|
|
14071
|
+
attr: new TokenType("attr", TokenClass.token, "@"),
|
|
14072
|
+
attr_left: new TokenType("attr_left", TokenClass.token, "[["),
|
|
14073
|
+
attr_right: new TokenType("attr_right", TokenClass.token, "]]"),
|
|
14074
|
+
forward_slash: new TokenType("forward_slash", TokenClass.token, "/"),
|
|
14075
|
+
bang: new TokenType("bang", TokenClass.token, "!"),
|
|
14076
|
+
bracket_left: new TokenType("bracket_left", TokenClass.token, "["),
|
|
14077
|
+
bracket_right: new TokenType("bracket_right", TokenClass.token, "]"),
|
|
14078
|
+
brace_left: new TokenType("brace_left", TokenClass.token, "{"),
|
|
14079
|
+
brace_right: new TokenType("brace_right", TokenClass.token, "}"),
|
|
14080
|
+
colon: new TokenType("colon", TokenClass.token, ":"),
|
|
14081
|
+
comma: new TokenType("comma", TokenClass.token, ","),
|
|
14082
|
+
equal: new TokenType("equal", TokenClass.token, "="),
|
|
14083
|
+
equal_equal: new TokenType("equal_equal", TokenClass.token, "=="),
|
|
14084
|
+
not_equal: new TokenType("not_equal", TokenClass.token, "!="),
|
|
14085
|
+
greater_than: new TokenType("greater_than", TokenClass.token, ">"),
|
|
14086
|
+
greater_than_equal: new TokenType("greater_than_equal", TokenClass.token, ">="),
|
|
14087
|
+
shift_right: new TokenType("shift_right", TokenClass.token, ">>"),
|
|
14088
|
+
less_than: new TokenType("less_than", TokenClass.token, "<"),
|
|
14089
|
+
less_than_equal: new TokenType("less_than_equal", TokenClass.token, "<="),
|
|
14090
|
+
shift_left: new TokenType("shift_left", TokenClass.token, "<<"),
|
|
14091
|
+
modulo: new TokenType("modulo", TokenClass.token, "%"),
|
|
14092
|
+
minus: new TokenType("minus", TokenClass.token, "-"),
|
|
14093
|
+
minus_minus: new TokenType("minus_minus", TokenClass.token, "--"),
|
|
14094
|
+
period: new TokenType("period", TokenClass.token, "."),
|
|
14095
|
+
plus: new TokenType("plus", TokenClass.token, "+"),
|
|
14096
|
+
plus_plus: new TokenType("plus_plus", TokenClass.token, "++"),
|
|
14097
|
+
or: new TokenType("or", TokenClass.token, "|"),
|
|
14098
|
+
or_or: new TokenType("or_or", TokenClass.token, "||"),
|
|
14099
|
+
paren_left: new TokenType("paren_left", TokenClass.token, "("),
|
|
14100
|
+
paren_right: new TokenType("paren_right", TokenClass.token, ")"),
|
|
14101
|
+
semicolon: new TokenType("semicolon", TokenClass.token, ";"),
|
|
14102
|
+
star: new TokenType("star", TokenClass.token, "*"),
|
|
14103
|
+
tilde: new TokenType("tilde", TokenClass.token, "~"),
|
|
14104
|
+
underscore: new TokenType("underscore", TokenClass.token, "_"),
|
|
14105
|
+
xor: new TokenType("xor", TokenClass.token, "^"),
|
|
14106
|
+
plus_equal: new TokenType("plus_equal", TokenClass.token, "+="),
|
|
14107
|
+
minus_equal: new TokenType("minus_equal", TokenClass.token, "-="),
|
|
14108
|
+
times_equal: new TokenType("times_equal", TokenClass.token, "*="),
|
|
14109
|
+
division_equal: new TokenType("division_equal", TokenClass.token, "/="),
|
|
14110
|
+
modulo_equal: new TokenType("modulo_equal", TokenClass.token, "%="),
|
|
14111
|
+
and_equal: new TokenType("and_equal", TokenClass.token, "&="),
|
|
14112
|
+
or_equal: new TokenType("or_equal", TokenClass.token, "|="),
|
|
14113
|
+
xor_equal: new TokenType("xor_equal", TokenClass.token, "^="),
|
|
14114
|
+
shift_right_equal: new TokenType("shift_right_equal", TokenClass.token, ">>="),
|
|
14115
|
+
shift_left_equal: new TokenType("shift_left_equal", TokenClass.token, "<<=")
|
|
14116
|
+
};
|
|
14117
|
+
TokenTypes.storage_class = [_a.keywords.function, _a.keywords.private, _a.keywords.workgroup, _a.keywords.uniform, _a.keywords.storage];
|
|
14118
|
+
TokenTypes.access_mode = [_a.keywords.read, _a.keywords.write, _a.keywords.read_write];
|
|
14119
|
+
TokenTypes.sampler_type = [_a.keywords.sampler, _a.keywords.sampler_comparison];
|
|
14120
|
+
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];
|
|
14121
|
+
TokenTypes.multisampled_texture_type = [_a.keywords.texture_multisampled_2d];
|
|
14122
|
+
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];
|
|
14123
|
+
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];
|
|
14124
|
+
TokenTypes.texture_external_type = [_a.keywords.texture_external];
|
|
14125
|
+
TokenTypes.any_texture_type = [..._a.sampled_texture_type, ..._a.multisampled_texture_type, ..._a.storage_texture_type, ..._a.depth_texture_type, ..._a.texture_external_type];
|
|
14126
|
+
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];
|
|
14127
|
+
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];
|
|
14128
|
+
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];
|
|
14129
|
+
TokenTypes.element_count_expression = [_a.tokens.int_literal, _a.tokens.uint_literal, _a.tokens.ident];
|
|
14130
|
+
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];
|
|
14131
|
+
TokenTypes.attribute_name = [_a.tokens.ident, _a.keywords.block];
|
|
14132
|
+
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];
|
|
14133
|
+
TokenTypes.increment_operators = [_a.tokens.plus_plus, _a.tokens.minus_minus];
|
|
14134
|
+
var Token = class {
|
|
14135
|
+
constructor(type, lexeme, line) {
|
|
14136
|
+
this.type = type;
|
|
14137
|
+
this.lexeme = lexeme;
|
|
14138
|
+
this.line = line;
|
|
14139
|
+
}
|
|
14140
|
+
toString() {
|
|
14141
|
+
return this.lexeme;
|
|
14142
|
+
}
|
|
14143
|
+
isTemplateType() {
|
|
14144
|
+
return TokenTypes.template_types.indexOf(this.type) != -1;
|
|
14145
|
+
}
|
|
14146
|
+
isArrayType() {
|
|
14147
|
+
return this.type == TokenTypes.keywords.array;
|
|
14148
|
+
}
|
|
14149
|
+
isArrayOrTemplateType() {
|
|
14150
|
+
return this.isArrayType() || this.isTemplateType();
|
|
14151
|
+
}
|
|
14152
|
+
};
|
|
14153
|
+
var WgslScanner = class {
|
|
14154
|
+
constructor(source) {
|
|
14155
|
+
this._tokens = [];
|
|
14156
|
+
this._start = 0;
|
|
14157
|
+
this._current = 0;
|
|
14158
|
+
this._line = 1;
|
|
14159
|
+
this._source = source !== null && source !== void 0 ? source : "";
|
|
14160
|
+
}
|
|
14161
|
+
scanTokens() {
|
|
14162
|
+
while (!this._isAtEnd()) {
|
|
14163
|
+
this._start = this._current;
|
|
14164
|
+
if (!this.scanToken())
|
|
14165
|
+
throw `Invalid syntax at line ${this._line}`;
|
|
14166
|
+
}
|
|
14167
|
+
this._tokens.push(new Token(TokenTypes.eof, "", this._line));
|
|
14168
|
+
return this._tokens;
|
|
14169
|
+
}
|
|
14170
|
+
scanToken() {
|
|
14171
|
+
let lexeme = this._advance();
|
|
14172
|
+
if (lexeme == "\n") {
|
|
14173
|
+
this._line++;
|
|
14174
|
+
return true;
|
|
14175
|
+
}
|
|
14176
|
+
if (this._isWhitespace(lexeme)) {
|
|
14177
|
+
return true;
|
|
14178
|
+
}
|
|
14179
|
+
if (lexeme == "/") {
|
|
14180
|
+
if (this._peekAhead() == "/") {
|
|
14181
|
+
while (lexeme != "\n") {
|
|
14182
|
+
if (this._isAtEnd())
|
|
14183
|
+
return true;
|
|
14184
|
+
lexeme = this._advance();
|
|
14185
|
+
}
|
|
14186
|
+
this._line++;
|
|
14187
|
+
return true;
|
|
14188
|
+
} else if (this._peekAhead() == "*") {
|
|
14189
|
+
this._advance();
|
|
14190
|
+
let commentLevel = 1;
|
|
14191
|
+
while (commentLevel > 0) {
|
|
14192
|
+
if (this._isAtEnd())
|
|
14193
|
+
return true;
|
|
14194
|
+
lexeme = this._advance();
|
|
14195
|
+
if (lexeme == "\n") {
|
|
14196
|
+
this._line++;
|
|
14197
|
+
} else if (lexeme == "*") {
|
|
14198
|
+
if (this._peekAhead() == "/") {
|
|
14199
|
+
this._advance();
|
|
14200
|
+
commentLevel--;
|
|
14201
|
+
if (commentLevel == 0) {
|
|
14202
|
+
return true;
|
|
14203
|
+
}
|
|
14204
|
+
}
|
|
14205
|
+
} else if (lexeme == "/") {
|
|
14206
|
+
if (this._peekAhead() == "*") {
|
|
14207
|
+
this._advance();
|
|
14208
|
+
commentLevel++;
|
|
14209
|
+
}
|
|
14210
|
+
}
|
|
14211
|
+
}
|
|
14212
|
+
return true;
|
|
14213
|
+
}
|
|
14214
|
+
}
|
|
14215
|
+
let matchType = TokenTypes.none;
|
|
14216
|
+
for (; ; ) {
|
|
14217
|
+
let matchedType = this._findType(lexeme);
|
|
14218
|
+
const nextLexeme = this._peekAhead();
|
|
14219
|
+
if (lexeme == ">" && (nextLexeme == ">" || nextLexeme == "=")) {
|
|
14220
|
+
let foundLessThan = false;
|
|
14221
|
+
let ti = this._tokens.length - 1;
|
|
14222
|
+
for (let count = 0; count < 5 && ti >= 0; ++count, --ti) {
|
|
14223
|
+
if (this._tokens[ti].type === TokenTypes.tokens.less_than) {
|
|
14224
|
+
if (ti > 0 && this._tokens[ti - 1].isArrayOrTemplateType()) {
|
|
14225
|
+
foundLessThan = true;
|
|
14226
|
+
}
|
|
14227
|
+
break;
|
|
14228
|
+
}
|
|
14229
|
+
}
|
|
14230
|
+
if (foundLessThan) {
|
|
14231
|
+
this._addToken(matchedType);
|
|
14232
|
+
return true;
|
|
14233
|
+
}
|
|
14234
|
+
}
|
|
14235
|
+
if (matchedType === TokenTypes.none) {
|
|
14236
|
+
let lookAheadLexeme = lexeme;
|
|
14237
|
+
let lookAhead = 0;
|
|
14238
|
+
const maxLookAhead = 2;
|
|
14239
|
+
for (let li = 0; li < maxLookAhead; ++li) {
|
|
14240
|
+
lookAheadLexeme += this._peekAhead(li);
|
|
14241
|
+
matchedType = this._findType(lookAheadLexeme);
|
|
14242
|
+
if (matchedType !== TokenTypes.none) {
|
|
14243
|
+
lookAhead = li;
|
|
14244
|
+
break;
|
|
14245
|
+
}
|
|
14246
|
+
}
|
|
14247
|
+
if (matchedType === TokenTypes.none) {
|
|
14248
|
+
if (matchType === TokenTypes.none)
|
|
14249
|
+
return false;
|
|
14250
|
+
this._current--;
|
|
14251
|
+
this._addToken(matchType);
|
|
14252
|
+
return true;
|
|
14253
|
+
}
|
|
14254
|
+
lexeme = lookAheadLexeme;
|
|
14255
|
+
this._current += lookAhead + 1;
|
|
14256
|
+
}
|
|
14257
|
+
matchType = matchedType;
|
|
14258
|
+
if (this._isAtEnd())
|
|
14259
|
+
break;
|
|
14260
|
+
lexeme += this._advance();
|
|
14261
|
+
}
|
|
14262
|
+
if (matchType === TokenTypes.none)
|
|
14263
|
+
return false;
|
|
14264
|
+
this._addToken(matchType);
|
|
14265
|
+
return true;
|
|
14266
|
+
}
|
|
14267
|
+
_findType(lexeme) {
|
|
14268
|
+
for (const name12 in TokenTypes.keywords) {
|
|
14269
|
+
const type = TokenTypes.keywords[name12];
|
|
14270
|
+
if (this._match(lexeme, type.rule)) {
|
|
14271
|
+
return type;
|
|
14272
|
+
}
|
|
14273
|
+
}
|
|
14274
|
+
for (const name12 in TokenTypes.tokens) {
|
|
14275
|
+
const type = TokenTypes.tokens[name12];
|
|
14276
|
+
if (this._match(lexeme, type.rule)) {
|
|
14277
|
+
return type;
|
|
14278
|
+
}
|
|
14279
|
+
}
|
|
14280
|
+
return TokenTypes.none;
|
|
14281
|
+
}
|
|
14282
|
+
_match(lexeme, rule) {
|
|
14283
|
+
if (typeof rule === "string") {
|
|
14284
|
+
if (rule == lexeme) {
|
|
14285
|
+
return true;
|
|
14286
|
+
}
|
|
14287
|
+
} else {
|
|
14288
|
+
const match = rule.exec(lexeme);
|
|
14289
|
+
if (match && match.index == 0 && match[0] == lexeme)
|
|
14290
|
+
return true;
|
|
14291
|
+
}
|
|
14292
|
+
return false;
|
|
14293
|
+
}
|
|
14294
|
+
_isAtEnd() {
|
|
14295
|
+
return this._current >= this._source.length;
|
|
14296
|
+
}
|
|
14297
|
+
_isWhitespace(c) {
|
|
14298
|
+
return c == " " || c == " " || c == "\r";
|
|
14299
|
+
}
|
|
14300
|
+
_advance() {
|
|
14301
|
+
let amount = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
|
|
14302
|
+
let c = this._source[this._current];
|
|
14303
|
+
amount = amount || 0;
|
|
14304
|
+
amount++;
|
|
14305
|
+
this._current += amount;
|
|
14306
|
+
return c;
|
|
14307
|
+
}
|
|
14308
|
+
_peekAhead() {
|
|
14309
|
+
let offset = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
|
|
14310
|
+
offset = offset || 0;
|
|
14311
|
+
if (this._current + offset >= this._source.length)
|
|
14312
|
+
return "\0";
|
|
14313
|
+
return this._source[this._current + offset];
|
|
14314
|
+
}
|
|
14315
|
+
_addToken(type) {
|
|
14316
|
+
const text = this._source.substring(this._start, this._current);
|
|
14317
|
+
this._tokens.push(new Token(type, text, this._line));
|
|
14318
|
+
}
|
|
14319
|
+
};
|
|
14320
|
+
var WgslParser = class {
|
|
14321
|
+
constructor() {
|
|
14322
|
+
this._tokens = [];
|
|
14323
|
+
this._current = 0;
|
|
14324
|
+
this._context = new ParseContext();
|
|
14325
|
+
}
|
|
14326
|
+
parse(tokensOrCode) {
|
|
14327
|
+
this._initialize(tokensOrCode);
|
|
14328
|
+
let statements = [];
|
|
14329
|
+
while (!this._isAtEnd()) {
|
|
14330
|
+
const statement = this._global_decl_or_directive();
|
|
14331
|
+
if (!statement)
|
|
14332
|
+
break;
|
|
14333
|
+
statements.push(statement);
|
|
14334
|
+
}
|
|
14335
|
+
return statements;
|
|
14336
|
+
}
|
|
14337
|
+
_initialize(tokensOrCode) {
|
|
14338
|
+
if (tokensOrCode) {
|
|
14339
|
+
if (typeof tokensOrCode == "string") {
|
|
14340
|
+
const scanner = new WgslScanner(tokensOrCode);
|
|
14341
|
+
this._tokens = scanner.scanTokens();
|
|
14342
|
+
} else {
|
|
14343
|
+
this._tokens = tokensOrCode;
|
|
14344
|
+
}
|
|
14345
|
+
} else {
|
|
14346
|
+
this._tokens = [];
|
|
14347
|
+
}
|
|
14348
|
+
this._current = 0;
|
|
14349
|
+
}
|
|
14350
|
+
_error(token, message) {
|
|
14351
|
+
console.error(token, message);
|
|
14352
|
+
return {
|
|
14353
|
+
token,
|
|
14354
|
+
message,
|
|
14355
|
+
toString: function() {
|
|
14356
|
+
return `${message}`;
|
|
14357
|
+
}
|
|
14358
|
+
};
|
|
14359
|
+
}
|
|
14360
|
+
_isAtEnd() {
|
|
14361
|
+
return this._current >= this._tokens.length || this._peek().type == TokenTypes.eof;
|
|
14362
|
+
}
|
|
14363
|
+
_match(types) {
|
|
14364
|
+
if (types instanceof TokenType) {
|
|
14365
|
+
if (this._check(types)) {
|
|
14366
|
+
this._advance();
|
|
14367
|
+
return true;
|
|
14368
|
+
}
|
|
14369
|
+
return false;
|
|
14370
|
+
}
|
|
14371
|
+
for (let i3 = 0, l2 = types.length; i3 < l2; ++i3) {
|
|
14372
|
+
const type = types[i3];
|
|
14373
|
+
if (this._check(type)) {
|
|
14374
|
+
this._advance();
|
|
14375
|
+
return true;
|
|
14376
|
+
}
|
|
14377
|
+
}
|
|
14378
|
+
return false;
|
|
14379
|
+
}
|
|
14380
|
+
_consume(types, message) {
|
|
14381
|
+
if (this._check(types))
|
|
14382
|
+
return this._advance();
|
|
14383
|
+
throw this._error(this._peek(), message);
|
|
14384
|
+
}
|
|
14385
|
+
_check(types) {
|
|
14386
|
+
if (this._isAtEnd())
|
|
14387
|
+
return false;
|
|
14388
|
+
const tk = this._peek();
|
|
14389
|
+
if (types instanceof Array) {
|
|
14390
|
+
let t2 = tk.type;
|
|
14391
|
+
let index2 = types.indexOf(t2);
|
|
14392
|
+
return index2 != -1;
|
|
14393
|
+
}
|
|
14394
|
+
return tk.type == types;
|
|
14395
|
+
}
|
|
14396
|
+
_advance() {
|
|
14397
|
+
if (!this._isAtEnd())
|
|
14398
|
+
this._current++;
|
|
14399
|
+
return this._previous();
|
|
14400
|
+
}
|
|
14401
|
+
_peek() {
|
|
14402
|
+
return this._tokens[this._current];
|
|
14403
|
+
}
|
|
14404
|
+
_previous() {
|
|
14405
|
+
return this._tokens[this._current - 1];
|
|
14406
|
+
}
|
|
14407
|
+
_global_decl_or_directive() {
|
|
14408
|
+
while (this._match(TokenTypes.tokens.semicolon) && !this._isAtEnd())
|
|
14409
|
+
;
|
|
14410
|
+
if (this._match(TokenTypes.keywords.alias)) {
|
|
14411
|
+
const type = this._type_alias();
|
|
14412
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
14413
|
+
return type;
|
|
14414
|
+
}
|
|
14415
|
+
if (this._match(TokenTypes.keywords.enable)) {
|
|
14416
|
+
const enable = this._enable_directive();
|
|
14417
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
14418
|
+
return enable;
|
|
14419
|
+
}
|
|
14420
|
+
const attrs = this._attribute();
|
|
14421
|
+
if (this._check(TokenTypes.keywords.var)) {
|
|
14422
|
+
const _var = this._global_variable_decl();
|
|
14423
|
+
if (_var != null)
|
|
14424
|
+
_var.attributes = attrs;
|
|
14425
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
14426
|
+
return _var;
|
|
14427
|
+
}
|
|
14428
|
+
if (this._check(TokenTypes.keywords.override)) {
|
|
14429
|
+
const _override = this._override_variable_decl();
|
|
14430
|
+
if (_override != null)
|
|
14431
|
+
_override.attributes = attrs;
|
|
14432
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
14433
|
+
return _override;
|
|
14434
|
+
}
|
|
14435
|
+
if (this._check(TokenTypes.keywords.let)) {
|
|
14436
|
+
const _let = this._global_let_decl();
|
|
14437
|
+
if (_let != null)
|
|
14438
|
+
_let.attributes = attrs;
|
|
14439
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
14440
|
+
return _let;
|
|
14441
|
+
}
|
|
14442
|
+
if (this._check(TokenTypes.keywords.const)) {
|
|
14443
|
+
const _const = this._global_const_decl();
|
|
14444
|
+
if (_const != null)
|
|
14445
|
+
_const.attributes = attrs;
|
|
14446
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
14447
|
+
return _const;
|
|
14448
|
+
}
|
|
14449
|
+
if (this._check(TokenTypes.keywords.struct)) {
|
|
14450
|
+
const _struct = this._struct_decl();
|
|
14451
|
+
if (_struct != null)
|
|
14452
|
+
_struct.attributes = attrs;
|
|
14453
|
+
return _struct;
|
|
14454
|
+
}
|
|
14455
|
+
if (this._check(TokenTypes.keywords.fn)) {
|
|
14456
|
+
const _fn = this._function_decl();
|
|
14457
|
+
if (_fn != null)
|
|
14458
|
+
_fn.attributes = attrs;
|
|
14459
|
+
return _fn;
|
|
14460
|
+
}
|
|
14461
|
+
return null;
|
|
14462
|
+
}
|
|
14463
|
+
_function_decl() {
|
|
14464
|
+
if (!this._match(TokenTypes.keywords.fn))
|
|
14465
|
+
return null;
|
|
14466
|
+
const name12 = this._consume(TokenTypes.tokens.ident, "Expected function name.").toString();
|
|
14467
|
+
this._consume(TokenTypes.tokens.paren_left, "Expected '(' for function arguments.");
|
|
14468
|
+
const args = [];
|
|
14469
|
+
if (!this._check(TokenTypes.tokens.paren_right)) {
|
|
14470
|
+
do {
|
|
14471
|
+
if (this._check(TokenTypes.tokens.paren_right))
|
|
14472
|
+
break;
|
|
14473
|
+
const argAttrs = this._attribute();
|
|
14474
|
+
const name13 = this._consume(TokenTypes.tokens.ident, "Expected argument name.").toString();
|
|
14475
|
+
this._consume(TokenTypes.tokens.colon, "Expected ':' for argument type.");
|
|
14476
|
+
const typeAttrs = this._attribute();
|
|
14477
|
+
const type = this._type_decl();
|
|
14478
|
+
if (type != null) {
|
|
14479
|
+
type.attributes = typeAttrs;
|
|
14480
|
+
args.push(new Argument(name13, type, argAttrs));
|
|
14481
|
+
}
|
|
14482
|
+
} while (this._match(TokenTypes.tokens.comma));
|
|
14483
|
+
}
|
|
14484
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')' after function arguments.");
|
|
14485
|
+
let _return = null;
|
|
14486
|
+
if (this._match(TokenTypes.tokens.arrow)) {
|
|
14487
|
+
const attrs = this._attribute();
|
|
14488
|
+
_return = this._type_decl();
|
|
14489
|
+
if (_return != null)
|
|
14490
|
+
_return.attributes = attrs;
|
|
14491
|
+
}
|
|
14492
|
+
const body = this._compound_statement();
|
|
14493
|
+
return new Function(name12, args, _return, body);
|
|
14494
|
+
}
|
|
14495
|
+
_compound_statement() {
|
|
14496
|
+
const statements = [];
|
|
14497
|
+
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for block.");
|
|
14498
|
+
while (!this._check(TokenTypes.tokens.brace_right)) {
|
|
14499
|
+
const statement = this._statement();
|
|
14500
|
+
if (statement !== null)
|
|
14501
|
+
statements.push(statement);
|
|
14502
|
+
}
|
|
14503
|
+
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for block.");
|
|
14504
|
+
return statements;
|
|
14505
|
+
}
|
|
14506
|
+
_statement() {
|
|
14507
|
+
while (this._match(TokenTypes.tokens.semicolon) && !this._isAtEnd())
|
|
14508
|
+
;
|
|
14509
|
+
if (this._check(TokenTypes.keywords.if))
|
|
14510
|
+
return this._if_statement();
|
|
14511
|
+
if (this._check(TokenTypes.keywords.switch))
|
|
14512
|
+
return this._switch_statement();
|
|
14513
|
+
if (this._check(TokenTypes.keywords.loop))
|
|
14514
|
+
return this._loop_statement();
|
|
14515
|
+
if (this._check(TokenTypes.keywords.for))
|
|
14516
|
+
return this._for_statement();
|
|
14517
|
+
if (this._check(TokenTypes.keywords.while))
|
|
14518
|
+
return this._while_statement();
|
|
14519
|
+
if (this._check(TokenTypes.keywords.continuing))
|
|
14520
|
+
return this._continuing_statement();
|
|
14521
|
+
if (this._check(TokenTypes.keywords.static_assert))
|
|
14522
|
+
return this._static_assert_statement();
|
|
14523
|
+
if (this._check(TokenTypes.tokens.brace_left))
|
|
14524
|
+
return this._compound_statement();
|
|
14525
|
+
let result = null;
|
|
14526
|
+
if (this._check(TokenTypes.keywords.return))
|
|
14527
|
+
result = this._return_statement();
|
|
14528
|
+
else if (this._check([TokenTypes.keywords.var, TokenTypes.keywords.let, TokenTypes.keywords.const]))
|
|
14529
|
+
result = this._variable_statement();
|
|
14530
|
+
else if (this._match(TokenTypes.keywords.discard))
|
|
14531
|
+
result = new Discard();
|
|
14532
|
+
else if (this._match(TokenTypes.keywords.break))
|
|
14533
|
+
result = new Break();
|
|
14534
|
+
else if (this._match(TokenTypes.keywords.continue))
|
|
14535
|
+
result = new Continue();
|
|
14536
|
+
else
|
|
14537
|
+
result = this._increment_decrement_statement() || this._func_call_statement() || this._assignment_statement();
|
|
14538
|
+
if (result != null)
|
|
14539
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';' after statement.");
|
|
14540
|
+
return result;
|
|
14541
|
+
}
|
|
14542
|
+
_static_assert_statement() {
|
|
14543
|
+
if (!this._match(TokenTypes.keywords.static_assert))
|
|
14544
|
+
return null;
|
|
14545
|
+
let expression = this._optional_paren_expression();
|
|
14546
|
+
return new StaticAssert(expression);
|
|
14547
|
+
}
|
|
14548
|
+
_while_statement() {
|
|
14549
|
+
if (!this._match(TokenTypes.keywords.while))
|
|
14550
|
+
return null;
|
|
14551
|
+
let condition = this._optional_paren_expression();
|
|
14552
|
+
const block = this._compound_statement();
|
|
14553
|
+
return new While(condition, block);
|
|
14554
|
+
}
|
|
14555
|
+
_continuing_statement() {
|
|
14556
|
+
if (!this._match(TokenTypes.keywords.continuing))
|
|
14557
|
+
return null;
|
|
14558
|
+
const block = this._compound_statement();
|
|
14559
|
+
return new Continuing(block);
|
|
14560
|
+
}
|
|
14561
|
+
_for_statement() {
|
|
14562
|
+
if (!this._match(TokenTypes.keywords.for))
|
|
14563
|
+
return null;
|
|
14564
|
+
this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
|
|
14565
|
+
const init = !this._check(TokenTypes.tokens.semicolon) ? this._for_init() : null;
|
|
14566
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
14567
|
+
const condition = !this._check(TokenTypes.tokens.semicolon) ? this._short_circuit_or_expression() : null;
|
|
14568
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
14569
|
+
const increment = !this._check(TokenTypes.tokens.paren_right) ? this._for_increment() : null;
|
|
14570
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
|
|
14571
|
+
const body = this._compound_statement();
|
|
14572
|
+
return new For(init, condition, increment, body);
|
|
14573
|
+
}
|
|
14574
|
+
_for_init() {
|
|
14575
|
+
return this._variable_statement() || this._func_call_statement() || this._assignment_statement();
|
|
14576
|
+
}
|
|
14577
|
+
_for_increment() {
|
|
14578
|
+
return this._func_call_statement() || this._increment_decrement_statement() || this._assignment_statement();
|
|
14579
|
+
}
|
|
14580
|
+
_variable_statement() {
|
|
14581
|
+
if (this._check(TokenTypes.keywords.var)) {
|
|
14582
|
+
const _var = this._variable_decl();
|
|
14583
|
+
if (_var === null)
|
|
14584
|
+
throw this._error(this._peek(), "Variable declaration expected.");
|
|
14585
|
+
let value = null;
|
|
14586
|
+
if (this._match(TokenTypes.tokens.equal))
|
|
14587
|
+
value = this._short_circuit_or_expression();
|
|
14588
|
+
return new Var(_var.name, _var.type, _var.storage, _var.access, value);
|
|
14589
|
+
}
|
|
14590
|
+
if (this._match(TokenTypes.keywords.let)) {
|
|
14591
|
+
const name12 = this._consume(TokenTypes.tokens.ident, "Expected name for let.").toString();
|
|
14592
|
+
let type = null;
|
|
14593
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
14594
|
+
const typeAttrs = this._attribute();
|
|
14595
|
+
type = this._type_decl();
|
|
14596
|
+
if (type != null)
|
|
14597
|
+
type.attributes = typeAttrs;
|
|
14598
|
+
}
|
|
14599
|
+
this._consume(TokenTypes.tokens.equal, "Expected '=' for let.");
|
|
14600
|
+
const value = this._short_circuit_or_expression();
|
|
14601
|
+
return new Let(name12, type, null, null, value);
|
|
14602
|
+
}
|
|
14603
|
+
if (this._match(TokenTypes.keywords.const)) {
|
|
14604
|
+
const name12 = this._consume(TokenTypes.tokens.ident, "Expected name for const.").toString();
|
|
14605
|
+
let type = null;
|
|
14606
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
14607
|
+
const typeAttrs = this._attribute();
|
|
14608
|
+
type = this._type_decl();
|
|
14609
|
+
if (type != null)
|
|
14610
|
+
type.attributes = typeAttrs;
|
|
14611
|
+
}
|
|
14612
|
+
this._consume(TokenTypes.tokens.equal, "Expected '=' for const.");
|
|
14613
|
+
const value = this._short_circuit_or_expression();
|
|
14614
|
+
return new Const(name12, type, null, null, value);
|
|
14615
|
+
}
|
|
14616
|
+
return null;
|
|
14617
|
+
}
|
|
14618
|
+
_increment_decrement_statement() {
|
|
14619
|
+
const savedPos = this._current;
|
|
14620
|
+
const _var = this._unary_expression();
|
|
14621
|
+
if (_var == null)
|
|
14622
|
+
return null;
|
|
14623
|
+
if (!this._check(TokenTypes.increment_operators)) {
|
|
14624
|
+
this._current = savedPos;
|
|
14625
|
+
return null;
|
|
14626
|
+
}
|
|
14627
|
+
const token = this._consume(TokenTypes.increment_operators, "Expected increment operator");
|
|
14628
|
+
return new Increment(token.type === TokenTypes.tokens.plus_plus ? IncrementOperator.increment : IncrementOperator.decrement, _var);
|
|
14629
|
+
}
|
|
14630
|
+
_assignment_statement() {
|
|
14631
|
+
let _var = null;
|
|
14632
|
+
if (this._check(TokenTypes.tokens.brace_right))
|
|
14633
|
+
return null;
|
|
14634
|
+
let isUnderscore = this._match(TokenTypes.tokens.underscore);
|
|
14635
|
+
if (!isUnderscore)
|
|
14636
|
+
_var = this._unary_expression();
|
|
14637
|
+
if (!isUnderscore && _var == null)
|
|
14638
|
+
return null;
|
|
14639
|
+
const type = this._consume(TokenTypes.assignment_operators, "Expected assignment operator.");
|
|
14640
|
+
const value = this._short_circuit_or_expression();
|
|
14641
|
+
return new Assign(AssignOperator.parse(type.lexeme), _var, value);
|
|
14642
|
+
}
|
|
14643
|
+
_func_call_statement() {
|
|
14644
|
+
if (!this._check(TokenTypes.tokens.ident))
|
|
14645
|
+
return null;
|
|
14646
|
+
const savedPos = this._current;
|
|
14647
|
+
const name12 = this._consume(TokenTypes.tokens.ident, "Expected function name.");
|
|
14648
|
+
const args = this._argument_expression_list();
|
|
14649
|
+
if (args === null) {
|
|
14650
|
+
this._current = savedPos;
|
|
14651
|
+
return null;
|
|
14652
|
+
}
|
|
14653
|
+
return new Call(name12.lexeme, args);
|
|
14654
|
+
}
|
|
14655
|
+
_loop_statement() {
|
|
14656
|
+
if (!this._match(TokenTypes.keywords.loop))
|
|
14657
|
+
return null;
|
|
14658
|
+
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for loop.");
|
|
14659
|
+
const statements = [];
|
|
14660
|
+
let statement = this._statement();
|
|
14661
|
+
while (statement !== null) {
|
|
14662
|
+
if (Array.isArray(statement)) {
|
|
14663
|
+
for (let s2 of statement) {
|
|
14664
|
+
statements.push(s2);
|
|
14665
|
+
}
|
|
14666
|
+
} else {
|
|
14667
|
+
statements.push(statement);
|
|
14668
|
+
}
|
|
14669
|
+
statement = this._statement();
|
|
14670
|
+
}
|
|
14671
|
+
let continuing = null;
|
|
14672
|
+
if (this._match(TokenTypes.keywords.continuing))
|
|
14673
|
+
continuing = this._compound_statement();
|
|
14674
|
+
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for loop.");
|
|
14675
|
+
return new Loop(statements, continuing);
|
|
14676
|
+
}
|
|
14677
|
+
_switch_statement() {
|
|
14678
|
+
if (!this._match(TokenTypes.keywords.switch))
|
|
14679
|
+
return null;
|
|
14680
|
+
const condition = this._optional_paren_expression();
|
|
14681
|
+
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for switch.");
|
|
14682
|
+
const body = this._switch_body();
|
|
14683
|
+
if (body == null || body.length == 0)
|
|
14684
|
+
throw this._error(this._previous(), "Expected 'case' or 'default'.");
|
|
14685
|
+
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for switch.");
|
|
14686
|
+
return new Switch(condition, body);
|
|
14687
|
+
}
|
|
14688
|
+
_switch_body() {
|
|
14689
|
+
const cases = [];
|
|
14690
|
+
if (this._match(TokenTypes.keywords.case)) {
|
|
14691
|
+
const selector = this._case_selectors();
|
|
14692
|
+
this._match(TokenTypes.tokens.colon);
|
|
14693
|
+
this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch case.");
|
|
14694
|
+
const body = this._case_body();
|
|
14695
|
+
this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch case.");
|
|
14696
|
+
cases.push(new Case(selector, body));
|
|
14697
|
+
}
|
|
14698
|
+
if (this._match(TokenTypes.keywords.default)) {
|
|
14699
|
+
this._match(TokenTypes.tokens.colon);
|
|
14700
|
+
this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch default.");
|
|
14701
|
+
const body = this._case_body();
|
|
14702
|
+
this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch default.");
|
|
14703
|
+
cases.push(new Default(body));
|
|
14704
|
+
}
|
|
14705
|
+
if (this._check([TokenTypes.keywords.default, TokenTypes.keywords.case])) {
|
|
14706
|
+
const _cases = this._switch_body();
|
|
14707
|
+
cases.push(_cases[0]);
|
|
14708
|
+
}
|
|
14709
|
+
return cases;
|
|
14710
|
+
}
|
|
14711
|
+
_case_selectors() {
|
|
14712
|
+
var _a2, _b, _c, _d;
|
|
14713
|
+
const selectors = [(_b = (_a2 = this._shift_expression()) === null || _a2 === void 0 ? void 0 : _a2.evaluate(this._context).toString()) !== null && _b !== void 0 ? _b : ""];
|
|
14714
|
+
while (this._match(TokenTypes.tokens.comma)) {
|
|
14715
|
+
selectors.push((_d = (_c = this._shift_expression()) === null || _c === void 0 ? void 0 : _c.evaluate(this._context).toString()) !== null && _d !== void 0 ? _d : "");
|
|
14716
|
+
}
|
|
14717
|
+
return selectors;
|
|
14718
|
+
}
|
|
14719
|
+
_case_body() {
|
|
14720
|
+
if (this._match(TokenTypes.keywords.fallthrough)) {
|
|
14721
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
14722
|
+
return [];
|
|
14723
|
+
}
|
|
14724
|
+
let statement = this._statement();
|
|
14725
|
+
if (statement == null)
|
|
14726
|
+
return [];
|
|
14727
|
+
if (!(statement instanceof Array)) {
|
|
14728
|
+
statement = [statement];
|
|
14729
|
+
}
|
|
14730
|
+
const nextStatement = this._case_body();
|
|
14731
|
+
if (nextStatement.length == 0)
|
|
14732
|
+
return statement;
|
|
14733
|
+
return [...statement, nextStatement[0]];
|
|
14734
|
+
}
|
|
14735
|
+
_if_statement() {
|
|
14736
|
+
if (!this._match(TokenTypes.keywords.if))
|
|
14737
|
+
return null;
|
|
14738
|
+
const condition = this._optional_paren_expression();
|
|
14739
|
+
const block = this._compound_statement();
|
|
14740
|
+
let elseif = [];
|
|
14741
|
+
if (this._match_elseif()) {
|
|
14742
|
+
elseif = this._elseif_statement(elseif);
|
|
14743
|
+
}
|
|
14744
|
+
let _else = null;
|
|
14745
|
+
if (this._match(TokenTypes.keywords.else))
|
|
14746
|
+
_else = this._compound_statement();
|
|
14747
|
+
return new If(condition, block, elseif, _else);
|
|
14748
|
+
}
|
|
14749
|
+
_match_elseif() {
|
|
14750
|
+
if (this._tokens[this._current].type === TokenTypes.keywords.else && this._tokens[this._current + 1].type === TokenTypes.keywords.if) {
|
|
14751
|
+
this._advance();
|
|
14752
|
+
this._advance();
|
|
14753
|
+
return true;
|
|
14754
|
+
}
|
|
14755
|
+
return false;
|
|
14756
|
+
}
|
|
14757
|
+
_elseif_statement() {
|
|
14758
|
+
let elseif = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
|
14759
|
+
const condition = this._optional_paren_expression();
|
|
14760
|
+
const block = this._compound_statement();
|
|
14761
|
+
elseif.push(new ElseIf(condition, block));
|
|
14762
|
+
if (this._match_elseif()) {
|
|
14763
|
+
this._elseif_statement(elseif);
|
|
14764
|
+
}
|
|
14765
|
+
return elseif;
|
|
14766
|
+
}
|
|
14767
|
+
_return_statement() {
|
|
14768
|
+
if (!this._match(TokenTypes.keywords.return))
|
|
14769
|
+
return null;
|
|
14770
|
+
const value = this._short_circuit_or_expression();
|
|
14771
|
+
return new Return(value);
|
|
14772
|
+
}
|
|
14773
|
+
_short_circuit_or_expression() {
|
|
14774
|
+
let expr = this._short_circuit_and_expr();
|
|
14775
|
+
while (this._match(TokenTypes.tokens.or_or)) {
|
|
14776
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._short_circuit_and_expr());
|
|
14777
|
+
}
|
|
14778
|
+
return expr;
|
|
14779
|
+
}
|
|
14780
|
+
_short_circuit_and_expr() {
|
|
14781
|
+
let expr = this._inclusive_or_expression();
|
|
14782
|
+
while (this._match(TokenTypes.tokens.and_and)) {
|
|
14783
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._inclusive_or_expression());
|
|
14784
|
+
}
|
|
14785
|
+
return expr;
|
|
14786
|
+
}
|
|
14787
|
+
_inclusive_or_expression() {
|
|
14788
|
+
let expr = this._exclusive_or_expression();
|
|
14789
|
+
while (this._match(TokenTypes.tokens.or)) {
|
|
14790
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._exclusive_or_expression());
|
|
14791
|
+
}
|
|
14792
|
+
return expr;
|
|
14793
|
+
}
|
|
14794
|
+
_exclusive_or_expression() {
|
|
14795
|
+
let expr = this._and_expression();
|
|
14796
|
+
while (this._match(TokenTypes.tokens.xor)) {
|
|
14797
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._and_expression());
|
|
14798
|
+
}
|
|
14799
|
+
return expr;
|
|
14800
|
+
}
|
|
14801
|
+
_and_expression() {
|
|
14802
|
+
let expr = this._equality_expression();
|
|
14803
|
+
while (this._match(TokenTypes.tokens.and)) {
|
|
14804
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._equality_expression());
|
|
14805
|
+
}
|
|
14806
|
+
return expr;
|
|
14807
|
+
}
|
|
14808
|
+
_equality_expression() {
|
|
14809
|
+
const expr = this._relational_expression();
|
|
14810
|
+
if (this._match([TokenTypes.tokens.equal_equal, TokenTypes.tokens.not_equal])) {
|
|
14811
|
+
return new BinaryOperator(this._previous().toString(), expr, this._relational_expression());
|
|
14812
|
+
}
|
|
14813
|
+
return expr;
|
|
14814
|
+
}
|
|
14815
|
+
_relational_expression() {
|
|
14816
|
+
let expr = this._shift_expression();
|
|
14817
|
+
while (this._match([TokenTypes.tokens.less_than, TokenTypes.tokens.greater_than, TokenTypes.tokens.less_than_equal, TokenTypes.tokens.greater_than_equal])) {
|
|
14818
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._shift_expression());
|
|
14819
|
+
}
|
|
14820
|
+
return expr;
|
|
14821
|
+
}
|
|
14822
|
+
_shift_expression() {
|
|
14823
|
+
let expr = this._additive_expression();
|
|
14824
|
+
while (this._match([TokenTypes.tokens.shift_left, TokenTypes.tokens.shift_right])) {
|
|
14825
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._additive_expression());
|
|
14826
|
+
}
|
|
14827
|
+
return expr;
|
|
14828
|
+
}
|
|
14829
|
+
_additive_expression() {
|
|
14830
|
+
let expr = this._multiplicative_expression();
|
|
14831
|
+
while (this._match([TokenTypes.tokens.plus, TokenTypes.tokens.minus])) {
|
|
14832
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._multiplicative_expression());
|
|
14833
|
+
}
|
|
14834
|
+
return expr;
|
|
14835
|
+
}
|
|
14836
|
+
_multiplicative_expression() {
|
|
14837
|
+
let expr = this._unary_expression();
|
|
14838
|
+
while (this._match([TokenTypes.tokens.star, TokenTypes.tokens.forward_slash, TokenTypes.tokens.modulo])) {
|
|
14839
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._unary_expression());
|
|
14840
|
+
}
|
|
14841
|
+
return expr;
|
|
14842
|
+
}
|
|
14843
|
+
_unary_expression() {
|
|
14844
|
+
if (this._match([TokenTypes.tokens.minus, TokenTypes.tokens.bang, TokenTypes.tokens.tilde, TokenTypes.tokens.star, TokenTypes.tokens.and])) {
|
|
14845
|
+
return new UnaryOperator(this._previous().toString(), this._unary_expression());
|
|
14846
|
+
}
|
|
14847
|
+
return this._singular_expression();
|
|
14848
|
+
}
|
|
14849
|
+
_singular_expression() {
|
|
14850
|
+
const expr = this._primary_expression();
|
|
14851
|
+
const p2 = this._postfix_expression();
|
|
14852
|
+
if (p2)
|
|
14853
|
+
expr.postfix = p2;
|
|
14854
|
+
return expr;
|
|
14855
|
+
}
|
|
14856
|
+
_postfix_expression() {
|
|
14857
|
+
if (this._match(TokenTypes.tokens.bracket_left)) {
|
|
14858
|
+
const expr = this._short_circuit_or_expression();
|
|
14859
|
+
this._consume(TokenTypes.tokens.bracket_right, "Expected ']'.");
|
|
14860
|
+
const p2 = this._postfix_expression();
|
|
14861
|
+
if (p2)
|
|
14862
|
+
expr.postfix = p2;
|
|
14863
|
+
return expr;
|
|
14864
|
+
}
|
|
14865
|
+
if (this._match(TokenTypes.tokens.period)) {
|
|
14866
|
+
const name12 = this._consume(TokenTypes.tokens.ident, "Expected member name.");
|
|
14867
|
+
const p2 = this._postfix_expression();
|
|
14868
|
+
const expr = new StringExpr(name12.lexeme);
|
|
14869
|
+
if (p2)
|
|
14870
|
+
expr.postfix = p2;
|
|
14871
|
+
return expr;
|
|
14872
|
+
}
|
|
14873
|
+
return null;
|
|
14874
|
+
}
|
|
14875
|
+
_getStruct(name12) {
|
|
14876
|
+
if (this._context.aliases.has(name12)) {
|
|
14877
|
+
const alias = this._context.aliases.get(name12).type;
|
|
14878
|
+
return alias;
|
|
14879
|
+
}
|
|
14880
|
+
if (this._context.structs.has(name12)) {
|
|
14881
|
+
const struct = this._context.structs.get(name12);
|
|
14882
|
+
return struct;
|
|
14883
|
+
}
|
|
14884
|
+
return null;
|
|
14885
|
+
}
|
|
14886
|
+
_primary_expression() {
|
|
14887
|
+
if (this._match(TokenTypes.tokens.ident)) {
|
|
14888
|
+
const name12 = this._previous().toString();
|
|
14889
|
+
if (this._check(TokenTypes.tokens.paren_left)) {
|
|
14890
|
+
const args2 = this._argument_expression_list();
|
|
14891
|
+
const struct = this._getStruct(name12);
|
|
14892
|
+
if (struct != null) {
|
|
14893
|
+
return new CreateExpr(struct, args2);
|
|
14894
|
+
}
|
|
14895
|
+
return new CallExpr(name12, args2);
|
|
14896
|
+
}
|
|
14897
|
+
if (this._context.constants.has(name12)) {
|
|
14898
|
+
const c = this._context.constants.get(name12);
|
|
14899
|
+
return new ConstExpr(name12, c.value);
|
|
14900
|
+
}
|
|
14901
|
+
return new VariableExpr(name12);
|
|
14902
|
+
}
|
|
14903
|
+
if (this._match(TokenTypes.const_literal)) {
|
|
14904
|
+
return new LiteralExpr(parseFloat(this._previous().toString()));
|
|
14905
|
+
}
|
|
14906
|
+
if (this._check(TokenTypes.tokens.paren_left)) {
|
|
14907
|
+
return this._paren_expression();
|
|
14908
|
+
}
|
|
14909
|
+
if (this._match(TokenTypes.keywords.bitcast)) {
|
|
14910
|
+
this._consume(TokenTypes.tokens.less_than, "Expected '<'.");
|
|
14911
|
+
const type2 = this._type_decl();
|
|
14912
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>'.");
|
|
14913
|
+
const value = this._paren_expression();
|
|
14914
|
+
return new BitcastExpr(type2, value);
|
|
14915
|
+
}
|
|
14916
|
+
const type = this._type_decl();
|
|
14917
|
+
const args = this._argument_expression_list();
|
|
14918
|
+
return new TypecastExpr(type, args);
|
|
14919
|
+
}
|
|
14920
|
+
_argument_expression_list() {
|
|
14921
|
+
if (!this._match(TokenTypes.tokens.paren_left))
|
|
14922
|
+
return null;
|
|
14923
|
+
const args = [];
|
|
14924
|
+
do {
|
|
14925
|
+
if (this._check(TokenTypes.tokens.paren_right))
|
|
14926
|
+
break;
|
|
14927
|
+
const arg = this._short_circuit_or_expression();
|
|
14928
|
+
args.push(arg);
|
|
14929
|
+
} while (this._match(TokenTypes.tokens.comma));
|
|
14930
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')' for agument list");
|
|
14931
|
+
return args;
|
|
14932
|
+
}
|
|
14933
|
+
_optional_paren_expression() {
|
|
14934
|
+
this._match(TokenTypes.tokens.paren_left);
|
|
14935
|
+
const expr = this._short_circuit_or_expression();
|
|
14936
|
+
this._match(TokenTypes.tokens.paren_right);
|
|
14937
|
+
return new GroupingExpr([expr]);
|
|
14938
|
+
}
|
|
14939
|
+
_paren_expression() {
|
|
14940
|
+
this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
|
|
14941
|
+
const expr = this._short_circuit_or_expression();
|
|
14942
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
|
|
14943
|
+
return new GroupingExpr([expr]);
|
|
14944
|
+
}
|
|
14945
|
+
_struct_decl() {
|
|
14946
|
+
if (!this._match(TokenTypes.keywords.struct))
|
|
14947
|
+
return null;
|
|
14948
|
+
const name12 = this._consume(TokenTypes.tokens.ident, "Expected name for struct.").toString();
|
|
14949
|
+
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for struct body.");
|
|
14950
|
+
const members = [];
|
|
14951
|
+
while (!this._check(TokenTypes.tokens.brace_right)) {
|
|
14952
|
+
const memberAttrs = this._attribute();
|
|
14953
|
+
const memberName = this._consume(TokenTypes.tokens.ident, "Expected variable name.").toString();
|
|
14954
|
+
this._consume(TokenTypes.tokens.colon, "Expected ':' for struct member type.");
|
|
14955
|
+
const typeAttrs = this._attribute();
|
|
14956
|
+
const memberType = this._type_decl();
|
|
14957
|
+
if (memberType != null)
|
|
14958
|
+
memberType.attributes = typeAttrs;
|
|
14959
|
+
if (!this._check(TokenTypes.tokens.brace_right))
|
|
14960
|
+
this._consume(TokenTypes.tokens.comma, "Expected ',' for struct member.");
|
|
14961
|
+
else
|
|
14962
|
+
this._match(TokenTypes.tokens.comma);
|
|
14963
|
+
members.push(new Member(memberName, memberType, memberAttrs));
|
|
14964
|
+
}
|
|
14965
|
+
this._consume(TokenTypes.tokens.brace_right, "Expected '}' after struct body.");
|
|
14966
|
+
const structNode = new Struct(name12, members);
|
|
14967
|
+
this._context.structs.set(name12, structNode);
|
|
14968
|
+
return structNode;
|
|
14969
|
+
}
|
|
14970
|
+
_global_variable_decl() {
|
|
14971
|
+
const _var = this._variable_decl();
|
|
14972
|
+
if (_var && this._match(TokenTypes.tokens.equal))
|
|
14973
|
+
_var.value = this._const_expression();
|
|
14974
|
+
return _var;
|
|
14975
|
+
}
|
|
14976
|
+
_override_variable_decl() {
|
|
14977
|
+
const _override = this._override_decl();
|
|
14978
|
+
if (_override && this._match(TokenTypes.tokens.equal))
|
|
14979
|
+
_override.value = this._const_expression();
|
|
14980
|
+
return _override;
|
|
14981
|
+
}
|
|
14982
|
+
_global_const_decl() {
|
|
14983
|
+
if (!this._match(TokenTypes.keywords.const))
|
|
14984
|
+
return null;
|
|
14985
|
+
const name12 = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
14986
|
+
let type = null;
|
|
14987
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
14988
|
+
const attrs = this._attribute();
|
|
14989
|
+
type = this._type_decl();
|
|
14990
|
+
if (type != null)
|
|
14991
|
+
type.attributes = attrs;
|
|
14992
|
+
}
|
|
14993
|
+
let value = null;
|
|
14994
|
+
if (this._match(TokenTypes.tokens.equal)) {
|
|
14995
|
+
const valueExpr = this._short_circuit_or_expression();
|
|
14996
|
+
if (valueExpr instanceof CreateExpr) {
|
|
14997
|
+
value = valueExpr;
|
|
14998
|
+
} else if (valueExpr instanceof ConstExpr && valueExpr.initializer instanceof CreateExpr) {
|
|
14999
|
+
value = valueExpr.initializer;
|
|
15000
|
+
} else {
|
|
15001
|
+
try {
|
|
15002
|
+
const constValue = valueExpr.evaluate(this._context);
|
|
15003
|
+
value = new LiteralExpr(constValue);
|
|
15004
|
+
} catch (_a2) {
|
|
15005
|
+
value = valueExpr;
|
|
15006
|
+
}
|
|
15007
|
+
}
|
|
15008
|
+
}
|
|
15009
|
+
const c = new Const(name12.toString(), type, "", "", value);
|
|
15010
|
+
this._context.constants.set(c.name, c);
|
|
15011
|
+
return c;
|
|
15012
|
+
}
|
|
15013
|
+
_global_let_decl() {
|
|
15014
|
+
if (!this._match(TokenTypes.keywords.let))
|
|
15015
|
+
return null;
|
|
15016
|
+
const name12 = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
15017
|
+
let type = null;
|
|
15018
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
15019
|
+
const attrs = this._attribute();
|
|
15020
|
+
type = this._type_decl();
|
|
15021
|
+
if (type != null)
|
|
15022
|
+
type.attributes = attrs;
|
|
15023
|
+
}
|
|
15024
|
+
let value = null;
|
|
15025
|
+
if (this._match(TokenTypes.tokens.equal)) {
|
|
15026
|
+
value = this._const_expression();
|
|
15027
|
+
}
|
|
15028
|
+
return new Let(name12.toString(), type, "", "", value);
|
|
15029
|
+
}
|
|
15030
|
+
_const_expression() {
|
|
15031
|
+
if (this._match(TokenTypes.const_literal))
|
|
15032
|
+
return new StringExpr(this._previous().toString());
|
|
15033
|
+
const type = this._type_decl();
|
|
15034
|
+
this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
|
|
15035
|
+
let args = [];
|
|
15036
|
+
while (!this._check(TokenTypes.tokens.paren_right)) {
|
|
15037
|
+
args.push(this._const_expression());
|
|
15038
|
+
if (!this._check(TokenTypes.tokens.comma))
|
|
15039
|
+
break;
|
|
15040
|
+
this._advance();
|
|
15041
|
+
}
|
|
15042
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
|
|
15043
|
+
return new CreateExpr(type, args);
|
|
15044
|
+
}
|
|
15045
|
+
_variable_decl() {
|
|
15046
|
+
if (!this._match(TokenTypes.keywords.var))
|
|
15047
|
+
return null;
|
|
15048
|
+
let storage = "";
|
|
15049
|
+
let access = "";
|
|
15050
|
+
if (this._match(TokenTypes.tokens.less_than)) {
|
|
15051
|
+
storage = this._consume(TokenTypes.storage_class, "Expected storage_class.").toString();
|
|
15052
|
+
if (this._match(TokenTypes.tokens.comma))
|
|
15053
|
+
access = this._consume(TokenTypes.access_mode, "Expected access_mode.").toString();
|
|
15054
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>'.");
|
|
15055
|
+
}
|
|
15056
|
+
const name12 = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
15057
|
+
let type = null;
|
|
15058
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
15059
|
+
const attrs = this._attribute();
|
|
15060
|
+
type = this._type_decl();
|
|
15061
|
+
if (type != null)
|
|
15062
|
+
type.attributes = attrs;
|
|
15063
|
+
}
|
|
15064
|
+
return new Var(name12.toString(), type, storage, access, null);
|
|
15065
|
+
}
|
|
15066
|
+
_override_decl() {
|
|
15067
|
+
if (!this._match(TokenTypes.keywords.override))
|
|
15068
|
+
return null;
|
|
15069
|
+
const name12 = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
15070
|
+
let type = null;
|
|
15071
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
15072
|
+
const attrs = this._attribute();
|
|
15073
|
+
type = this._type_decl();
|
|
15074
|
+
if (type != null)
|
|
15075
|
+
type.attributes = attrs;
|
|
15076
|
+
}
|
|
15077
|
+
return new Override(name12.toString(), type, null);
|
|
15078
|
+
}
|
|
15079
|
+
_enable_directive() {
|
|
15080
|
+
const name12 = this._consume(TokenTypes.tokens.ident, "identity expected.");
|
|
15081
|
+
return new Enable(name12.toString());
|
|
15082
|
+
}
|
|
15083
|
+
_type_alias() {
|
|
15084
|
+
const name12 = this._consume(TokenTypes.tokens.ident, "identity expected.");
|
|
15085
|
+
this._consume(TokenTypes.tokens.equal, "Expected '=' for type alias.");
|
|
15086
|
+
let aliasType = this._type_decl();
|
|
15087
|
+
if (aliasType === null) {
|
|
15088
|
+
throw this._error(this._peek(), "Expected Type for Alias.");
|
|
15089
|
+
}
|
|
15090
|
+
if (this._context.aliases.has(aliasType.name)) {
|
|
15091
|
+
aliasType = this._context.aliases.get(aliasType.name).type;
|
|
15092
|
+
}
|
|
15093
|
+
const aliasNode = new Alias(name12.toString(), aliasType);
|
|
15094
|
+
this._context.aliases.set(aliasNode.name, aliasNode);
|
|
15095
|
+
return aliasNode;
|
|
15096
|
+
}
|
|
15097
|
+
_type_decl() {
|
|
15098
|
+
if (this._check([TokenTypes.tokens.ident, ...TokenTypes.texel_format, TokenTypes.keywords.bool, TokenTypes.keywords.f32, TokenTypes.keywords.i32, TokenTypes.keywords.u32])) {
|
|
15099
|
+
const type2 = this._advance();
|
|
15100
|
+
const typeName = type2.toString();
|
|
15101
|
+
if (this._context.structs.has(typeName)) {
|
|
15102
|
+
return this._context.structs.get(typeName);
|
|
15103
|
+
}
|
|
15104
|
+
if (this._context.aliases.has(typeName)) {
|
|
15105
|
+
return this._context.aliases.get(typeName).type;
|
|
15106
|
+
}
|
|
15107
|
+
return new Type(type2.toString());
|
|
15108
|
+
}
|
|
15109
|
+
let type = this._texture_sampler_types();
|
|
15110
|
+
if (type)
|
|
15111
|
+
return type;
|
|
15112
|
+
if (this._check(TokenTypes.template_types)) {
|
|
15113
|
+
let type2 = this._advance().toString();
|
|
15114
|
+
let format = null;
|
|
15115
|
+
let access = null;
|
|
15116
|
+
if (this._match(TokenTypes.tokens.less_than)) {
|
|
15117
|
+
format = this._type_decl();
|
|
15118
|
+
access = null;
|
|
15119
|
+
if (this._match(TokenTypes.tokens.comma))
|
|
15120
|
+
access = this._consume(TokenTypes.access_mode, "Expected access_mode for pointer").toString();
|
|
15121
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for type.");
|
|
15122
|
+
}
|
|
15123
|
+
return new TemplateType(type2, format, access);
|
|
15124
|
+
}
|
|
15125
|
+
if (this._match(TokenTypes.keywords.ptr)) {
|
|
15126
|
+
let pointer = this._previous().toString();
|
|
15127
|
+
this._consume(TokenTypes.tokens.less_than, "Expected '<' for pointer.");
|
|
15128
|
+
const storage = this._consume(TokenTypes.storage_class, "Expected storage_class for pointer");
|
|
15129
|
+
this._consume(TokenTypes.tokens.comma, "Expected ',' for pointer.");
|
|
15130
|
+
const decl = this._type_decl();
|
|
15131
|
+
let access = null;
|
|
15132
|
+
if (this._match(TokenTypes.tokens.comma))
|
|
15133
|
+
access = this._consume(TokenTypes.access_mode, "Expected access_mode for pointer").toString();
|
|
15134
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for pointer.");
|
|
15135
|
+
return new PointerType(pointer, storage.toString(), decl, access);
|
|
15136
|
+
}
|
|
15137
|
+
const attrs = this._attribute();
|
|
15138
|
+
if (this._match(TokenTypes.keywords.array)) {
|
|
15139
|
+
let format = null;
|
|
15140
|
+
let countInt = -1;
|
|
15141
|
+
const array = this._previous();
|
|
15142
|
+
if (this._match(TokenTypes.tokens.less_than)) {
|
|
15143
|
+
format = this._type_decl();
|
|
15144
|
+
if (this._context.aliases.has(format.name)) {
|
|
15145
|
+
format = this._context.aliases.get(format.name).type;
|
|
15146
|
+
}
|
|
15147
|
+
let count = "";
|
|
15148
|
+
if (this._match(TokenTypes.tokens.comma)) {
|
|
15149
|
+
let c = this._shift_expression();
|
|
15150
|
+
count = c.evaluate(this._context).toString();
|
|
15151
|
+
}
|
|
15152
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for array.");
|
|
15153
|
+
countInt = count ? parseInt(count) : 0;
|
|
15154
|
+
}
|
|
15155
|
+
return new ArrayType(array.toString(), attrs, format, countInt);
|
|
15156
|
+
}
|
|
15157
|
+
return null;
|
|
15158
|
+
}
|
|
15159
|
+
_texture_sampler_types() {
|
|
15160
|
+
if (this._match(TokenTypes.sampler_type))
|
|
15161
|
+
return new SamplerType(this._previous().toString(), null, null);
|
|
15162
|
+
if (this._match(TokenTypes.depth_texture_type))
|
|
15163
|
+
return new SamplerType(this._previous().toString(), null, null);
|
|
15164
|
+
if (this._match(TokenTypes.sampled_texture_type) || this._match(TokenTypes.multisampled_texture_type)) {
|
|
15165
|
+
const sampler = this._previous();
|
|
15166
|
+
this._consume(TokenTypes.tokens.less_than, "Expected '<' for sampler type.");
|
|
15167
|
+
const format = this._type_decl();
|
|
15168
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for sampler type.");
|
|
15169
|
+
return new SamplerType(sampler.toString(), format, null);
|
|
15170
|
+
}
|
|
15171
|
+
if (this._match(TokenTypes.storage_texture_type)) {
|
|
15172
|
+
const sampler = this._previous();
|
|
15173
|
+
this._consume(TokenTypes.tokens.less_than, "Expected '<' for sampler type.");
|
|
15174
|
+
const format = this._consume(TokenTypes.texel_format, "Invalid texel format.").toString();
|
|
15175
|
+
this._consume(TokenTypes.tokens.comma, "Expected ',' after texel format.");
|
|
15176
|
+
const access = this._consume(TokenTypes.access_mode, "Expected access mode for storage texture type.").toString();
|
|
15177
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for sampler type.");
|
|
15178
|
+
return new SamplerType(sampler.toString(), format, access);
|
|
15179
|
+
}
|
|
15180
|
+
return null;
|
|
15181
|
+
}
|
|
15182
|
+
_attribute() {
|
|
15183
|
+
let attributes = [];
|
|
15184
|
+
while (this._match(TokenTypes.tokens.attr)) {
|
|
15185
|
+
const name12 = this._consume(TokenTypes.attribute_name, "Expected attribute name");
|
|
15186
|
+
const attr = new Attribute(name12.toString(), null);
|
|
15187
|
+
if (this._match(TokenTypes.tokens.paren_left)) {
|
|
15188
|
+
attr.value = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
|
|
15189
|
+
if (this._check(TokenTypes.tokens.comma)) {
|
|
15190
|
+
this._advance();
|
|
15191
|
+
do {
|
|
15192
|
+
const v = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
|
|
15193
|
+
if (!(attr.value instanceof Array)) {
|
|
15194
|
+
attr.value = [attr.value];
|
|
15195
|
+
}
|
|
15196
|
+
attr.value.push(v);
|
|
15197
|
+
} while (this._match(TokenTypes.tokens.comma));
|
|
15198
|
+
}
|
|
15199
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
|
|
15200
|
+
}
|
|
15201
|
+
attributes.push(attr);
|
|
15202
|
+
}
|
|
15203
|
+
while (this._match(TokenTypes.tokens.attr_left)) {
|
|
15204
|
+
if (!this._check(TokenTypes.tokens.attr_right)) {
|
|
15205
|
+
do {
|
|
15206
|
+
const name12 = this._consume(TokenTypes.attribute_name, "Expected attribute name");
|
|
15207
|
+
const attr = new Attribute(name12.toString(), null);
|
|
15208
|
+
if (this._match(TokenTypes.tokens.paren_left)) {
|
|
15209
|
+
attr.value = [this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString()];
|
|
15210
|
+
if (this._check(TokenTypes.tokens.comma)) {
|
|
15211
|
+
this._advance();
|
|
15212
|
+
do {
|
|
15213
|
+
const v = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
|
|
15214
|
+
attr.value.push(v);
|
|
15215
|
+
} while (this._match(TokenTypes.tokens.comma));
|
|
15216
|
+
}
|
|
15217
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
|
|
15218
|
+
}
|
|
15219
|
+
attributes.push(attr);
|
|
15220
|
+
} while (this._match(TokenTypes.tokens.comma));
|
|
15221
|
+
}
|
|
15222
|
+
this._consume(TokenTypes.tokens.attr_right, "Expected ']]' after attribute declarations");
|
|
15223
|
+
}
|
|
15224
|
+
if (attributes.length == 0)
|
|
15225
|
+
return null;
|
|
15226
|
+
return attributes;
|
|
15227
|
+
}
|
|
15228
|
+
};
|
|
15229
|
+
var TypeInfo = class {
|
|
15230
|
+
constructor(name12, attributes) {
|
|
15231
|
+
this.name = name12;
|
|
15232
|
+
this.attributes = attributes;
|
|
15233
|
+
this.size = 0;
|
|
15234
|
+
}
|
|
15235
|
+
get isArray() {
|
|
15236
|
+
return false;
|
|
15237
|
+
}
|
|
15238
|
+
get isStruct() {
|
|
15239
|
+
return false;
|
|
15240
|
+
}
|
|
15241
|
+
get isTemplate() {
|
|
15242
|
+
return false;
|
|
15243
|
+
}
|
|
15244
|
+
};
|
|
15245
|
+
var MemberInfo = class {
|
|
15246
|
+
constructor(name12, type, attributes) {
|
|
15247
|
+
this.name = name12;
|
|
15248
|
+
this.type = type;
|
|
15249
|
+
this.attributes = attributes;
|
|
15250
|
+
this.offset = 0;
|
|
15251
|
+
this.size = 0;
|
|
15252
|
+
}
|
|
15253
|
+
get isArray() {
|
|
15254
|
+
return this.type.isArray;
|
|
15255
|
+
}
|
|
15256
|
+
get isStruct() {
|
|
15257
|
+
return this.type.isStruct;
|
|
15258
|
+
}
|
|
15259
|
+
get isTemplate() {
|
|
15260
|
+
return this.type.isTemplate;
|
|
15261
|
+
}
|
|
15262
|
+
get align() {
|
|
15263
|
+
return this.type.isStruct ? this.type.align : 0;
|
|
15264
|
+
}
|
|
15265
|
+
get members() {
|
|
15266
|
+
return this.type.isStruct ? this.type.members : null;
|
|
15267
|
+
}
|
|
15268
|
+
get format() {
|
|
15269
|
+
return this.type.isArray ? this.type.format : this.type.isTemplate ? this.type.format : null;
|
|
15270
|
+
}
|
|
15271
|
+
get count() {
|
|
15272
|
+
return this.type.isArray ? this.type.count : 0;
|
|
15273
|
+
}
|
|
15274
|
+
get stride() {
|
|
15275
|
+
return this.type.isArray ? this.type.stride : this.size;
|
|
15276
|
+
}
|
|
15277
|
+
};
|
|
15278
|
+
var StructInfo = class extends TypeInfo {
|
|
15279
|
+
constructor(name12, attributes) {
|
|
15280
|
+
super(name12, attributes);
|
|
15281
|
+
this.members = [];
|
|
15282
|
+
this.align = 0;
|
|
15283
|
+
}
|
|
15284
|
+
get isStruct() {
|
|
15285
|
+
return true;
|
|
15286
|
+
}
|
|
15287
|
+
};
|
|
15288
|
+
var ArrayInfo = class extends TypeInfo {
|
|
15289
|
+
constructor(name12, attributes) {
|
|
15290
|
+
super(name12, attributes);
|
|
15291
|
+
this.count = 0;
|
|
15292
|
+
this.stride = 0;
|
|
15293
|
+
}
|
|
15294
|
+
get isArray() {
|
|
15295
|
+
return true;
|
|
15296
|
+
}
|
|
15297
|
+
};
|
|
15298
|
+
var TemplateInfo = class extends TypeInfo {
|
|
15299
|
+
constructor(name12, format, attributes, access) {
|
|
15300
|
+
super(name12, attributes);
|
|
15301
|
+
this.format = format;
|
|
15302
|
+
this.access = access;
|
|
15303
|
+
}
|
|
15304
|
+
get isTemplate() {
|
|
15305
|
+
return true;
|
|
15306
|
+
}
|
|
15307
|
+
};
|
|
15308
|
+
var ResourceType;
|
|
15309
|
+
(function(ResourceType2) {
|
|
15310
|
+
ResourceType2[ResourceType2["Uniform"] = 0] = "Uniform";
|
|
15311
|
+
ResourceType2[ResourceType2["Storage"] = 1] = "Storage";
|
|
15312
|
+
ResourceType2[ResourceType2["Texture"] = 2] = "Texture";
|
|
15313
|
+
ResourceType2[ResourceType2["Sampler"] = 3] = "Sampler";
|
|
15314
|
+
ResourceType2[ResourceType2["StorageTexture"] = 4] = "StorageTexture";
|
|
15315
|
+
})(ResourceType || (ResourceType = {}));
|
|
15316
|
+
var VariableInfo = class {
|
|
15317
|
+
constructor(name12, type, group, binding, attributes, resourceType, access) {
|
|
15318
|
+
this.name = name12;
|
|
15319
|
+
this.type = type;
|
|
15320
|
+
this.group = group;
|
|
15321
|
+
this.binding = binding;
|
|
15322
|
+
this.attributes = attributes;
|
|
15323
|
+
this.resourceType = resourceType;
|
|
15324
|
+
this.access = access;
|
|
15325
|
+
}
|
|
15326
|
+
get isArray() {
|
|
15327
|
+
return this.type.isArray;
|
|
15328
|
+
}
|
|
15329
|
+
get isStruct() {
|
|
15330
|
+
return this.type.isStruct;
|
|
15331
|
+
}
|
|
15332
|
+
get isTemplate() {
|
|
15333
|
+
return this.type.isTemplate;
|
|
15334
|
+
}
|
|
15335
|
+
get size() {
|
|
15336
|
+
return this.type.size;
|
|
15337
|
+
}
|
|
15338
|
+
get align() {
|
|
15339
|
+
return this.type.isStruct ? this.type.align : 0;
|
|
15340
|
+
}
|
|
15341
|
+
get members() {
|
|
15342
|
+
return this.type.isStruct ? this.type.members : null;
|
|
15343
|
+
}
|
|
15344
|
+
get format() {
|
|
15345
|
+
return this.type.isArray ? this.type.format : this.type.isTemplate ? this.type.format : null;
|
|
15346
|
+
}
|
|
15347
|
+
get count() {
|
|
15348
|
+
return this.type.isArray ? this.type.count : 0;
|
|
15349
|
+
}
|
|
15350
|
+
get stride() {
|
|
15351
|
+
return this.type.isArray ? this.type.stride : this.size;
|
|
15352
|
+
}
|
|
15353
|
+
};
|
|
15354
|
+
var AliasInfo = class {
|
|
15355
|
+
constructor(name12, type) {
|
|
15356
|
+
this.name = name12;
|
|
15357
|
+
this.type = type;
|
|
15358
|
+
}
|
|
15359
|
+
};
|
|
15360
|
+
var _TypeSize = class {
|
|
15361
|
+
constructor(align, size) {
|
|
15362
|
+
this.align = align;
|
|
15363
|
+
this.size = size;
|
|
15364
|
+
}
|
|
15365
|
+
};
|
|
15366
|
+
var InputInfo = class {
|
|
15367
|
+
constructor(name12, type, locationType, location) {
|
|
15368
|
+
this.name = name12;
|
|
15369
|
+
this.type = type;
|
|
15370
|
+
this.locationType = locationType;
|
|
15371
|
+
this.location = location;
|
|
15372
|
+
this.interpolation = null;
|
|
15373
|
+
}
|
|
15374
|
+
};
|
|
15375
|
+
var OutputInfo = class {
|
|
15376
|
+
constructor(name12, type, locationType, location) {
|
|
15377
|
+
this.name = name12;
|
|
15378
|
+
this.type = type;
|
|
15379
|
+
this.locationType = locationType;
|
|
15380
|
+
this.location = location;
|
|
15381
|
+
}
|
|
15382
|
+
};
|
|
15383
|
+
var FunctionInfo = class {
|
|
15384
|
+
constructor(name12) {
|
|
15385
|
+
let stage = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
|
|
15386
|
+
this.stage = null;
|
|
15387
|
+
this.inputs = [];
|
|
15388
|
+
this.outputs = [];
|
|
15389
|
+
this.name = name12;
|
|
15390
|
+
this.stage = stage;
|
|
15391
|
+
}
|
|
15392
|
+
};
|
|
15393
|
+
var EntryFunctions = class {
|
|
15394
|
+
constructor() {
|
|
15395
|
+
this.vertex = [];
|
|
15396
|
+
this.fragment = [];
|
|
15397
|
+
this.compute = [];
|
|
15398
|
+
}
|
|
15399
|
+
};
|
|
15400
|
+
var OverrideInfo = class {
|
|
15401
|
+
constructor(name12, type, attributes, id) {
|
|
15402
|
+
this.name = name12;
|
|
15403
|
+
this.type = type;
|
|
15404
|
+
this.attributes = attributes;
|
|
15405
|
+
this.id = id;
|
|
15406
|
+
}
|
|
15407
|
+
};
|
|
15408
|
+
var WgslReflect = class {
|
|
15409
|
+
constructor(code) {
|
|
15410
|
+
this.uniforms = [];
|
|
15411
|
+
this.storage = [];
|
|
15412
|
+
this.textures = [];
|
|
15413
|
+
this.samplers = [];
|
|
15414
|
+
this.aliases = [];
|
|
15415
|
+
this.overrides = [];
|
|
15416
|
+
this.structs = [];
|
|
15417
|
+
this.entry = new EntryFunctions();
|
|
15418
|
+
this._types = /* @__PURE__ */ new Map();
|
|
15419
|
+
if (code) {
|
|
15420
|
+
this.update(code);
|
|
15421
|
+
}
|
|
15422
|
+
}
|
|
15423
|
+
_isStorageTexture(type) {
|
|
15424
|
+
return type.name == "texture_storage_1d" || type.name == "texture_storage_2d" || type.name == "texture_storage_2d_array" || type.name == "texture_storage_3d";
|
|
15425
|
+
}
|
|
15426
|
+
update(code) {
|
|
15427
|
+
const parser = new WgslParser();
|
|
15428
|
+
const ast = parser.parse(code);
|
|
15429
|
+
for (const node2 of ast) {
|
|
15430
|
+
if (node2 instanceof Struct) {
|
|
15431
|
+
const info = this._getTypeInfo(node2, null);
|
|
15432
|
+
if (info instanceof StructInfo) {
|
|
15433
|
+
this.structs.push(info);
|
|
15434
|
+
}
|
|
15435
|
+
continue;
|
|
15436
|
+
}
|
|
15437
|
+
if (node2 instanceof Alias) {
|
|
15438
|
+
this.aliases.push(this._getAliasInfo(node2));
|
|
15439
|
+
continue;
|
|
15440
|
+
}
|
|
15441
|
+
if (node2 instanceof Override) {
|
|
15442
|
+
const v = node2;
|
|
15443
|
+
const id = this._getAttributeNum(v.attributes, "id", 0);
|
|
15444
|
+
const type = v.type != null ? this._getTypeInfo(v.type, v.attributes) : null;
|
|
15445
|
+
this.overrides.push(new OverrideInfo(v.name, type, v.attributes, id));
|
|
15446
|
+
continue;
|
|
15447
|
+
}
|
|
15448
|
+
if (this._isUniformVar(node2)) {
|
|
15449
|
+
const v = node2;
|
|
15450
|
+
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
15451
|
+
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
15452
|
+
const type = this._getTypeInfo(v.type, v.attributes);
|
|
15453
|
+
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, ResourceType.Uniform, v.access);
|
|
15454
|
+
this.uniforms.push(varInfo);
|
|
15455
|
+
continue;
|
|
15456
|
+
}
|
|
15457
|
+
if (this._isStorageVar(node2)) {
|
|
15458
|
+
const v = node2;
|
|
15459
|
+
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
15460
|
+
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
15461
|
+
const type = this._getTypeInfo(v.type, v.attributes);
|
|
15462
|
+
const isStorageTexture = this._isStorageTexture(type);
|
|
15463
|
+
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, isStorageTexture ? ResourceType.StorageTexture : ResourceType.Storage, v.access);
|
|
15464
|
+
this.storage.push(varInfo);
|
|
15465
|
+
continue;
|
|
15466
|
+
}
|
|
15467
|
+
if (this._isTextureVar(node2)) {
|
|
15468
|
+
const v = node2;
|
|
15469
|
+
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
15470
|
+
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
15471
|
+
const type = this._getTypeInfo(v.type, v.attributes);
|
|
15472
|
+
const isStorageTexture = this._isStorageTexture(type);
|
|
15473
|
+
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, isStorageTexture ? ResourceType.StorageTexture : ResourceType.Texture, v.access);
|
|
15474
|
+
if (isStorageTexture) {
|
|
15475
|
+
this.storage.push(varInfo);
|
|
15476
|
+
} else {
|
|
15477
|
+
this.textures.push(varInfo);
|
|
15478
|
+
}
|
|
15479
|
+
continue;
|
|
15480
|
+
}
|
|
15481
|
+
if (this._isSamplerVar(node2)) {
|
|
15482
|
+
const v = node2;
|
|
15483
|
+
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
15484
|
+
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
15485
|
+
const type = this._getTypeInfo(v.type, v.attributes);
|
|
15486
|
+
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, ResourceType.Sampler, v.access);
|
|
15487
|
+
this.samplers.push(varInfo);
|
|
15488
|
+
continue;
|
|
15489
|
+
}
|
|
15490
|
+
if (node2 instanceof Function) {
|
|
15491
|
+
const vertexStage = this._getAttribute(node2, "vertex");
|
|
15492
|
+
const fragmentStage = this._getAttribute(node2, "fragment");
|
|
15493
|
+
const computeStage = this._getAttribute(node2, "compute");
|
|
15494
|
+
const stage = vertexStage || fragmentStage || computeStage;
|
|
15495
|
+
if (stage) {
|
|
15496
|
+
const fn = new FunctionInfo(node2.name, stage.name);
|
|
15497
|
+
fn.inputs = this._getInputs(node2.args);
|
|
15498
|
+
fn.outputs = this._getOutputs(node2.returnType);
|
|
15499
|
+
this.entry[stage.name].push(fn);
|
|
15500
|
+
}
|
|
15501
|
+
continue;
|
|
15502
|
+
}
|
|
15503
|
+
}
|
|
15504
|
+
}
|
|
15505
|
+
getBindGroups() {
|
|
15506
|
+
const groups = [];
|
|
15507
|
+
function _makeRoom(group, binding) {
|
|
15508
|
+
if (group >= groups.length)
|
|
15509
|
+
groups.length = group + 1;
|
|
15510
|
+
if (groups[group] === void 0)
|
|
15511
|
+
groups[group] = [];
|
|
15512
|
+
if (binding >= groups[group].length)
|
|
15513
|
+
groups[group].length = binding + 1;
|
|
15514
|
+
}
|
|
15515
|
+
for (const u of this.uniforms) {
|
|
15516
|
+
_makeRoom(u.group, u.binding);
|
|
15517
|
+
const group = groups[u.group];
|
|
15518
|
+
group[u.binding] = u;
|
|
15519
|
+
}
|
|
15520
|
+
for (const u of this.storage) {
|
|
15521
|
+
_makeRoom(u.group, u.binding);
|
|
15522
|
+
const group = groups[u.group];
|
|
15523
|
+
group[u.binding] = u;
|
|
15524
|
+
}
|
|
15525
|
+
for (const t2 of this.textures) {
|
|
15526
|
+
_makeRoom(t2.group, t2.binding);
|
|
15527
|
+
const group = groups[t2.group];
|
|
15528
|
+
group[t2.binding] = t2;
|
|
15529
|
+
}
|
|
15530
|
+
for (const t2 of this.samplers) {
|
|
15531
|
+
_makeRoom(t2.group, t2.binding);
|
|
15532
|
+
const group = groups[t2.group];
|
|
15533
|
+
group[t2.binding] = t2;
|
|
15534
|
+
}
|
|
15535
|
+
return groups;
|
|
15536
|
+
}
|
|
15537
|
+
_getOutputs(type) {
|
|
15538
|
+
let outputs = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : void 0;
|
|
15539
|
+
if (outputs === void 0)
|
|
15540
|
+
outputs = [];
|
|
15541
|
+
if (type instanceof Struct) {
|
|
15542
|
+
this._getStructOutputs(type, outputs);
|
|
15543
|
+
} else {
|
|
15544
|
+
const output = this._getOutputInfo(type);
|
|
15545
|
+
if (output !== null)
|
|
15546
|
+
outputs.push(output);
|
|
15547
|
+
}
|
|
15548
|
+
return outputs;
|
|
15549
|
+
}
|
|
15550
|
+
_getStructOutputs(struct, outputs) {
|
|
15551
|
+
for (const m of struct.members) {
|
|
15552
|
+
if (m.type instanceof Struct) {
|
|
15553
|
+
this._getStructOutputs(m.type, outputs);
|
|
15554
|
+
} else {
|
|
15555
|
+
const location = this._getAttribute(m, "location") || this._getAttribute(m, "builtin");
|
|
15556
|
+
if (location !== null) {
|
|
15557
|
+
const typeInfo = this._getTypeInfo(m.type, m.type.attributes);
|
|
15558
|
+
const locationValue = this._parseInt(location.value);
|
|
15559
|
+
const info = new OutputInfo(m.name, typeInfo, location.name, locationValue);
|
|
15560
|
+
outputs.push(info);
|
|
15561
|
+
}
|
|
15562
|
+
}
|
|
15563
|
+
}
|
|
15564
|
+
}
|
|
15565
|
+
_getOutputInfo(type) {
|
|
15566
|
+
const location = this._getAttribute(type, "location") || this._getAttribute(type, "builtin");
|
|
15567
|
+
if (location !== null) {
|
|
15568
|
+
const typeInfo = this._getTypeInfo(type, type.attributes);
|
|
15569
|
+
const locationValue = this._parseInt(location.value);
|
|
15570
|
+
const info = new OutputInfo("", typeInfo, location.name, locationValue);
|
|
15571
|
+
return info;
|
|
15572
|
+
}
|
|
15573
|
+
return null;
|
|
15574
|
+
}
|
|
15575
|
+
_getInputs(args) {
|
|
15576
|
+
let inputs = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : void 0;
|
|
15577
|
+
if (inputs === void 0)
|
|
15578
|
+
inputs = [];
|
|
15579
|
+
for (const arg of args) {
|
|
15580
|
+
if (arg.type instanceof Struct) {
|
|
15581
|
+
this._getStructInputs(arg.type, inputs);
|
|
15582
|
+
} else {
|
|
15583
|
+
const input = this._getInputInfo(arg);
|
|
15584
|
+
if (input !== null)
|
|
15585
|
+
inputs.push(input);
|
|
15586
|
+
}
|
|
15587
|
+
}
|
|
15588
|
+
return inputs;
|
|
15589
|
+
}
|
|
15590
|
+
_getStructInputs(struct, inputs) {
|
|
15591
|
+
for (const m of struct.members) {
|
|
15592
|
+
if (m.type instanceof Struct) {
|
|
15593
|
+
this._getStructInputs(m.type, inputs);
|
|
15594
|
+
} else {
|
|
15595
|
+
const input = this._getInputInfo(m);
|
|
15596
|
+
if (input !== null)
|
|
15597
|
+
inputs.push(input);
|
|
15598
|
+
}
|
|
15599
|
+
}
|
|
15600
|
+
}
|
|
15601
|
+
_getInputInfo(node2) {
|
|
15602
|
+
const location = this._getAttribute(node2, "location") || this._getAttribute(node2, "builtin");
|
|
15603
|
+
if (location !== null) {
|
|
15604
|
+
const interpolation = this._getAttribute(node2, "interpolation");
|
|
15605
|
+
const type = this._getTypeInfo(node2.type, node2.attributes);
|
|
15606
|
+
const locationValue = this._parseInt(location.value);
|
|
15607
|
+
const info = new InputInfo(node2.name, type, location.name, locationValue);
|
|
15608
|
+
if (interpolation !== null) {
|
|
15609
|
+
info.interpolation = this._parseString(interpolation.value);
|
|
15610
|
+
}
|
|
15611
|
+
return info;
|
|
15612
|
+
}
|
|
15613
|
+
return null;
|
|
15614
|
+
}
|
|
15615
|
+
_parseString(s2) {
|
|
15616
|
+
if (s2 instanceof Array) {
|
|
15617
|
+
s2 = s2[0];
|
|
15618
|
+
}
|
|
15619
|
+
return s2;
|
|
15620
|
+
}
|
|
15621
|
+
_parseInt(s2) {
|
|
15622
|
+
if (s2 instanceof Array) {
|
|
15623
|
+
s2 = s2[0];
|
|
15624
|
+
}
|
|
15625
|
+
const n2 = parseInt(s2);
|
|
15626
|
+
return isNaN(n2) ? s2 : n2;
|
|
15627
|
+
}
|
|
15628
|
+
_getAlias(name12) {
|
|
15629
|
+
for (const a2 of this.aliases) {
|
|
15630
|
+
if (a2.name == name12)
|
|
15631
|
+
return a2.type;
|
|
15632
|
+
}
|
|
15633
|
+
return null;
|
|
15634
|
+
}
|
|
15635
|
+
_getAliasInfo(node2) {
|
|
15636
|
+
return new AliasInfo(node2.name, this._getTypeInfo(node2.type, null));
|
|
15637
|
+
}
|
|
15638
|
+
_getTypeInfo(type, attributes) {
|
|
15639
|
+
if (this._types.has(type)) {
|
|
15640
|
+
return this._types.get(type);
|
|
15641
|
+
}
|
|
15642
|
+
if (type instanceof ArrayType) {
|
|
15643
|
+
const a2 = type;
|
|
15644
|
+
const t2 = this._getTypeInfo(a2.format, a2.attributes);
|
|
15645
|
+
const info2 = new ArrayInfo(a2.name, attributes);
|
|
15646
|
+
info2.format = t2;
|
|
15647
|
+
info2.count = a2.count;
|
|
15648
|
+
this._types.set(type, info2);
|
|
15649
|
+
this._updateTypeInfo(info2);
|
|
15650
|
+
return info2;
|
|
15651
|
+
}
|
|
15652
|
+
if (type instanceof Struct) {
|
|
15653
|
+
const s2 = type;
|
|
15654
|
+
const info2 = new StructInfo(s2.name, attributes);
|
|
15655
|
+
for (const m of s2.members) {
|
|
15656
|
+
const t2 = this._getTypeInfo(m.type, m.attributes);
|
|
15657
|
+
info2.members.push(new MemberInfo(m.name, t2, m.attributes));
|
|
15658
|
+
}
|
|
15659
|
+
this._types.set(type, info2);
|
|
15660
|
+
this._updateTypeInfo(info2);
|
|
15661
|
+
return info2;
|
|
15662
|
+
}
|
|
15663
|
+
if (type instanceof SamplerType) {
|
|
15664
|
+
const s2 = type;
|
|
15665
|
+
const formatIsType = s2.format instanceof Type;
|
|
15666
|
+
const format = s2.format ? formatIsType ? this._getTypeInfo(s2.format, null) : new TypeInfo(s2.format, null) : null;
|
|
15667
|
+
const info2 = new TemplateInfo(s2.name, format, attributes, s2.access);
|
|
15668
|
+
this._types.set(type, info2);
|
|
15669
|
+
this._updateTypeInfo(info2);
|
|
15670
|
+
return info2;
|
|
15671
|
+
}
|
|
15672
|
+
if (type instanceof TemplateType) {
|
|
15673
|
+
const t2 = type;
|
|
15674
|
+
const format = t2.format ? this._getTypeInfo(t2.format, null) : null;
|
|
15675
|
+
const info2 = new TemplateInfo(t2.name, format, attributes, t2.access);
|
|
15676
|
+
this._types.set(type, info2);
|
|
15677
|
+
this._updateTypeInfo(info2);
|
|
15678
|
+
return info2;
|
|
15679
|
+
}
|
|
15680
|
+
const info = new TypeInfo(type.name, attributes);
|
|
15681
|
+
this._types.set(type, info);
|
|
15682
|
+
this._updateTypeInfo(info);
|
|
15683
|
+
return info;
|
|
15684
|
+
}
|
|
15685
|
+
_updateTypeInfo(type) {
|
|
15686
|
+
var _a2, _b;
|
|
15687
|
+
const typeSize = this._getTypeSize(type);
|
|
15688
|
+
type.size = (_a2 = typeSize === null || typeSize === void 0 ? void 0 : typeSize.size) !== null && _a2 !== void 0 ? _a2 : 0;
|
|
15689
|
+
if (type instanceof ArrayInfo) {
|
|
15690
|
+
const formatInfo = this._getTypeSize(type["format"]);
|
|
15691
|
+
type.stride = (_b = formatInfo === null || formatInfo === void 0 ? void 0 : formatInfo.size) !== null && _b !== void 0 ? _b : 0;
|
|
15692
|
+
this._updateTypeInfo(type["format"]);
|
|
15693
|
+
}
|
|
15694
|
+
if (type instanceof StructInfo) {
|
|
15695
|
+
this._updateStructInfo(type);
|
|
15696
|
+
}
|
|
15697
|
+
}
|
|
15698
|
+
_updateStructInfo(struct) {
|
|
15699
|
+
var _a2;
|
|
15700
|
+
let offset = 0;
|
|
15701
|
+
let lastSize = 0;
|
|
15702
|
+
let lastOffset = 0;
|
|
15703
|
+
let structAlign = 0;
|
|
15704
|
+
for (let mi = 0, ml = struct.members.length; mi < ml; ++mi) {
|
|
15705
|
+
const member = struct.members[mi];
|
|
15706
|
+
const sizeInfo = this._getTypeSize(member);
|
|
15707
|
+
if (!sizeInfo)
|
|
15708
|
+
continue;
|
|
15709
|
+
(_a2 = this._getAlias(member.type.name)) !== null && _a2 !== void 0 ? _a2 : member.type;
|
|
15710
|
+
const align = sizeInfo.align;
|
|
15711
|
+
const size = sizeInfo.size;
|
|
15712
|
+
offset = this._roundUp(align, offset + lastSize);
|
|
15713
|
+
lastSize = size;
|
|
15714
|
+
lastOffset = offset;
|
|
15715
|
+
structAlign = Math.max(structAlign, align);
|
|
15716
|
+
member.offset = offset;
|
|
15717
|
+
member.size = size;
|
|
15718
|
+
this._updateTypeInfo(member.type);
|
|
15719
|
+
}
|
|
15720
|
+
struct.size = this._roundUp(structAlign, lastOffset + lastSize);
|
|
15721
|
+
struct.align = structAlign;
|
|
15722
|
+
}
|
|
15723
|
+
_getTypeSize(type) {
|
|
15724
|
+
var _a2;
|
|
15725
|
+
if (type === null || type === void 0)
|
|
15726
|
+
return null;
|
|
15727
|
+
const explicitSize = this._getAttributeNum(type.attributes, "size", 0);
|
|
15728
|
+
const explicitAlign = this._getAttributeNum(type.attributes, "align", 0);
|
|
15729
|
+
if (type instanceof MemberInfo)
|
|
15730
|
+
type = type.type;
|
|
15731
|
+
if (type instanceof TypeInfo) {
|
|
15732
|
+
const alias = this._getAlias(type.name);
|
|
15733
|
+
if (alias !== null) {
|
|
15734
|
+
type = alias;
|
|
15735
|
+
}
|
|
15736
|
+
}
|
|
15737
|
+
{
|
|
15738
|
+
const info = WgslReflect._typeInfo[type.name];
|
|
15739
|
+
if (info !== void 0) {
|
|
15740
|
+
const divisor = type["format"] === "f16" ? 2 : 1;
|
|
15741
|
+
return new _TypeSize(Math.max(explicitAlign, info.align / divisor), Math.max(explicitSize, info.size / divisor));
|
|
15742
|
+
}
|
|
15743
|
+
}
|
|
15744
|
+
{
|
|
15745
|
+
const info = WgslReflect._typeInfo[type.name.substring(0, type.name.length - 1)];
|
|
15746
|
+
if (info) {
|
|
15747
|
+
const divisor = type.name[type.name.length - 1] === "h" ? 2 : 1;
|
|
15748
|
+
return new _TypeSize(Math.max(explicitAlign, info.align / divisor), Math.max(explicitSize, info.size / divisor));
|
|
15749
|
+
}
|
|
15750
|
+
}
|
|
15751
|
+
if (type instanceof ArrayInfo) {
|
|
15752
|
+
let arrayType = type;
|
|
15753
|
+
let align = 8;
|
|
15754
|
+
let size = 8;
|
|
15755
|
+
const E = this._getTypeSize(arrayType.format);
|
|
15756
|
+
if (E !== null) {
|
|
15757
|
+
size = E.size;
|
|
15758
|
+
align = E.align;
|
|
15759
|
+
}
|
|
15760
|
+
const N = arrayType.count;
|
|
15761
|
+
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));
|
|
15762
|
+
size = N * stride;
|
|
15763
|
+
if (explicitSize)
|
|
15764
|
+
size = explicitSize;
|
|
15765
|
+
return new _TypeSize(Math.max(explicitAlign, align), Math.max(explicitSize, size));
|
|
15766
|
+
}
|
|
15767
|
+
if (type instanceof StructInfo) {
|
|
15768
|
+
let align = 0;
|
|
15769
|
+
let size = 0;
|
|
15770
|
+
let offset = 0;
|
|
15771
|
+
let lastSize = 0;
|
|
15772
|
+
let lastOffset = 0;
|
|
15773
|
+
for (const m of type.members) {
|
|
15774
|
+
const mi = this._getTypeSize(m.type);
|
|
15775
|
+
if (mi !== null) {
|
|
15776
|
+
align = Math.max(mi.align, align);
|
|
15777
|
+
offset = this._roundUp(mi.align, offset + lastSize);
|
|
15778
|
+
lastSize = mi.size;
|
|
15779
|
+
lastOffset = offset;
|
|
15780
|
+
}
|
|
15781
|
+
}
|
|
15782
|
+
size = this._roundUp(align, lastOffset + lastSize);
|
|
15783
|
+
return new _TypeSize(Math.max(explicitAlign, align), Math.max(explicitSize, size));
|
|
15784
|
+
}
|
|
15785
|
+
return null;
|
|
15786
|
+
}
|
|
15787
|
+
_isUniformVar(node2) {
|
|
15788
|
+
return node2 instanceof Var && node2.storage == "uniform";
|
|
15789
|
+
}
|
|
15790
|
+
_isStorageVar(node2) {
|
|
15791
|
+
return node2 instanceof Var && node2.storage == "storage";
|
|
15792
|
+
}
|
|
15793
|
+
_isTextureVar(node2) {
|
|
15794
|
+
return node2 instanceof Var && node2.type !== null && WgslReflect._textureTypes.indexOf(node2.type.name) != -1;
|
|
15795
|
+
}
|
|
15796
|
+
_isSamplerVar(node2) {
|
|
15797
|
+
return node2 instanceof Var && node2.type !== null && WgslReflect._samplerTypes.indexOf(node2.type.name) != -1;
|
|
15798
|
+
}
|
|
15799
|
+
_getAttribute(node2, name12) {
|
|
15800
|
+
const obj = node2;
|
|
15801
|
+
if (!obj || !obj["attributes"])
|
|
15802
|
+
return null;
|
|
15803
|
+
const attrs = obj["attributes"];
|
|
15804
|
+
for (let a2 of attrs) {
|
|
15805
|
+
if (a2.name == name12)
|
|
15806
|
+
return a2;
|
|
15807
|
+
}
|
|
15808
|
+
return null;
|
|
15809
|
+
}
|
|
15810
|
+
_getAttributeNum(attributes, name12, defaultValue2) {
|
|
15811
|
+
if (attributes === null)
|
|
15812
|
+
return defaultValue2;
|
|
15813
|
+
for (let a2 of attributes) {
|
|
15814
|
+
if (a2.name == name12) {
|
|
15815
|
+
let v = a2 !== null && a2.value !== null ? a2.value : defaultValue2;
|
|
15816
|
+
if (v instanceof Array) {
|
|
15817
|
+
v = v[0];
|
|
15818
|
+
}
|
|
15819
|
+
if (typeof v === "number") {
|
|
15820
|
+
return v;
|
|
15821
|
+
}
|
|
15822
|
+
if (typeof v === "string") {
|
|
15823
|
+
return parseInt(v);
|
|
15824
|
+
}
|
|
15825
|
+
return defaultValue2;
|
|
15826
|
+
}
|
|
15827
|
+
}
|
|
15828
|
+
return defaultValue2;
|
|
15829
|
+
}
|
|
15830
|
+
_roundUp(k, n2) {
|
|
15831
|
+
return Math.ceil(n2 / k) * k;
|
|
15832
|
+
}
|
|
15833
|
+
};
|
|
15834
|
+
WgslReflect._typeInfo = {
|
|
15835
|
+
f16: {
|
|
15836
|
+
align: 2,
|
|
15837
|
+
size: 2
|
|
15838
|
+
},
|
|
15839
|
+
i32: {
|
|
15840
|
+
align: 4,
|
|
15841
|
+
size: 4
|
|
15842
|
+
},
|
|
15843
|
+
u32: {
|
|
15844
|
+
align: 4,
|
|
15845
|
+
size: 4
|
|
15846
|
+
},
|
|
15847
|
+
f32: {
|
|
15848
|
+
align: 4,
|
|
15849
|
+
size: 4
|
|
15850
|
+
},
|
|
15851
|
+
atomic: {
|
|
15852
|
+
align: 4,
|
|
15853
|
+
size: 4
|
|
15854
|
+
},
|
|
15855
|
+
vec2: {
|
|
15856
|
+
align: 8,
|
|
15857
|
+
size: 8
|
|
15858
|
+
},
|
|
15859
|
+
vec3: {
|
|
15860
|
+
align: 16,
|
|
15861
|
+
size: 12
|
|
15862
|
+
},
|
|
15863
|
+
vec4: {
|
|
15864
|
+
align: 16,
|
|
15865
|
+
size: 16
|
|
15866
|
+
},
|
|
15867
|
+
mat2x2: {
|
|
15868
|
+
align: 8,
|
|
15869
|
+
size: 16
|
|
15870
|
+
},
|
|
15871
|
+
mat3x2: {
|
|
15872
|
+
align: 8,
|
|
15873
|
+
size: 24
|
|
15874
|
+
},
|
|
15875
|
+
mat4x2: {
|
|
15876
|
+
align: 8,
|
|
15877
|
+
size: 32
|
|
15878
|
+
},
|
|
15879
|
+
mat2x3: {
|
|
15880
|
+
align: 16,
|
|
15881
|
+
size: 32
|
|
15882
|
+
},
|
|
15883
|
+
mat3x3: {
|
|
15884
|
+
align: 16,
|
|
15885
|
+
size: 48
|
|
15886
|
+
},
|
|
15887
|
+
mat4x3: {
|
|
15888
|
+
align: 16,
|
|
15889
|
+
size: 64
|
|
15890
|
+
},
|
|
15891
|
+
mat2x4: {
|
|
15892
|
+
align: 16,
|
|
15893
|
+
size: 32
|
|
15894
|
+
},
|
|
15895
|
+
mat3x4: {
|
|
15896
|
+
align: 16,
|
|
15897
|
+
size: 48
|
|
15898
|
+
},
|
|
15899
|
+
mat4x4: {
|
|
15900
|
+
align: 16,
|
|
15901
|
+
size: 64
|
|
15902
|
+
}
|
|
15903
|
+
};
|
|
15904
|
+
WgslReflect._textureTypes = TokenTypes.any_texture_type.map((t2) => {
|
|
15905
|
+
return t2.name;
|
|
15906
|
+
});
|
|
15907
|
+
WgslReflect._samplerTypes = TokenTypes.sampler_type.map((t2) => {
|
|
15908
|
+
return t2.name;
|
|
15909
|
+
});
|
|
15910
|
+
|
|
15911
|
+
// ../../node_modules/@luma.gl/shadertools/dist/lib/wgsl/get-shader-layout-wgsl.js
|
|
15912
|
+
function getShaderLayoutFromWGSL(source) {
|
|
15913
|
+
const shaderLayout = {
|
|
15914
|
+
attributes: [],
|
|
15915
|
+
bindings: []
|
|
15916
|
+
};
|
|
15917
|
+
const parsedWGSL = parseWGSL(source);
|
|
15918
|
+
for (const uniform of parsedWGSL.uniforms) {
|
|
15919
|
+
const members = [];
|
|
15920
|
+
for (const member of uniform.type.members) {
|
|
15921
|
+
members.push({
|
|
15922
|
+
name: member.name,
|
|
15923
|
+
type: getType(member.type)
|
|
15924
|
+
});
|
|
15925
|
+
}
|
|
15926
|
+
shaderLayout.bindings.push({
|
|
15927
|
+
type: "uniform",
|
|
15928
|
+
name: uniform.name,
|
|
15929
|
+
location: uniform.binding,
|
|
15930
|
+
group: uniform.group,
|
|
15931
|
+
members
|
|
15932
|
+
});
|
|
15933
|
+
}
|
|
15934
|
+
const vertex = parsedWGSL.entry.vertex[0];
|
|
15935
|
+
const attributeCount = vertex.inputs.length;
|
|
15936
|
+
for (let i3 = 0; i3 < attributeCount; i3++) {
|
|
15937
|
+
const wgslAttribute = vertex.inputs[i3];
|
|
15938
|
+
if (wgslAttribute.locationType === "location") {
|
|
15939
|
+
const type = getType(wgslAttribute.type);
|
|
15940
|
+
shaderLayout.attributes.push({
|
|
15941
|
+
name: wgslAttribute.name,
|
|
15942
|
+
location: wgslAttribute.location,
|
|
15943
|
+
type
|
|
15944
|
+
});
|
|
15945
|
+
}
|
|
15946
|
+
}
|
|
15947
|
+
return shaderLayout;
|
|
15948
|
+
}
|
|
15949
|
+
function getType(type) {
|
|
15950
|
+
return type.format ? `${type.name}<${type.format.name}>` : type.name;
|
|
15951
|
+
}
|
|
15952
|
+
function parseWGSL(source) {
|
|
15953
|
+
try {
|
|
15954
|
+
return new WgslReflect(source);
|
|
15955
|
+
} catch (error) {
|
|
15956
|
+
if (error instanceof Error) {
|
|
15957
|
+
throw error;
|
|
15958
|
+
}
|
|
15959
|
+
let message = "WGSL parse error";
|
|
15960
|
+
if (typeof error === "object" && error !== null && error !== void 0 && error.message) {
|
|
15961
|
+
message += `: ${error.message} `;
|
|
15962
|
+
}
|
|
15963
|
+
if (typeof error === "object" && error !== null && error !== void 0 && error.token) {
|
|
15964
|
+
message += error.token.line || "";
|
|
15965
|
+
}
|
|
15966
|
+
throw new Error(message, {
|
|
15967
|
+
cause: error
|
|
15968
|
+
});
|
|
15969
|
+
}
|
|
15970
|
+
}
|
|
15971
|
+
|
|
13199
15972
|
// ../../node_modules/@luma.gl/shadertools/dist/modules-webgl1/lighting/lights/lights.glsl.js
|
|
13200
15973
|
var lightingShader = glsl`\
|
|
13201
15974
|
#if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
@@ -14056,10 +16829,17 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
14056
16829
|
};
|
|
14057
16830
|
|
|
14058
16831
|
// ../../node_modules/@luma.gl/engine/dist/debug/debug-shader-layout.js
|
|
14059
|
-
function getDebugTableForShaderLayout(layout) {
|
|
14060
|
-
|
|
16832
|
+
function getDebugTableForShaderLayout(layout, name12) {
|
|
16833
|
+
var _layout$varyings;
|
|
14061
16834
|
const table = {};
|
|
14062
|
-
const header =
|
|
16835
|
+
const header = "Values";
|
|
16836
|
+
if (layout.attributes.length === 0 && !((_layout$varyings = layout.varyings) !== null && _layout$varyings !== void 0 && _layout$varyings.length)) {
|
|
16837
|
+
return {
|
|
16838
|
+
"No attributes or varyings": {
|
|
16839
|
+
[header]: "N/A"
|
|
16840
|
+
}
|
|
16841
|
+
};
|
|
16842
|
+
}
|
|
14063
16843
|
for (const attributeDeclaration of layout.attributes) {
|
|
14064
16844
|
if (attributeDeclaration) {
|
|
14065
16845
|
const glslDeclaration = `${attributeDeclaration.location} ${attributeDeclaration.name}: ${attributeDeclaration.type}`;
|
|
@@ -14077,6 +16857,49 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
14077
16857
|
return table;
|
|
14078
16858
|
}
|
|
14079
16859
|
|
|
16860
|
+
// ../../node_modules/@luma.gl/engine/dist/debug/debug-framebuffer.js
|
|
16861
|
+
var canvas = null;
|
|
16862
|
+
var ctx = null;
|
|
16863
|
+
function debugFramebuffer(fbo, _ref) {
|
|
16864
|
+
let {
|
|
16865
|
+
id,
|
|
16866
|
+
minimap,
|
|
16867
|
+
opaque,
|
|
16868
|
+
top = "0",
|
|
16869
|
+
left = "0",
|
|
16870
|
+
rgbaScale = 1
|
|
16871
|
+
} = _ref;
|
|
16872
|
+
if (!canvas) {
|
|
16873
|
+
canvas = document.createElement("canvas");
|
|
16874
|
+
canvas.id = id;
|
|
16875
|
+
canvas.title = id;
|
|
16876
|
+
canvas.style.zIndex = "100";
|
|
16877
|
+
canvas.style.position = "absolute";
|
|
16878
|
+
canvas.style.top = top;
|
|
16879
|
+
canvas.style.left = left;
|
|
16880
|
+
canvas.style.border = "blue 1px solid";
|
|
16881
|
+
canvas.style.transform = "scaleY(-1)";
|
|
16882
|
+
document.body.appendChild(canvas);
|
|
16883
|
+
ctx = canvas.getContext("2d");
|
|
16884
|
+
}
|
|
16885
|
+
if (canvas.width !== fbo.width || canvas.height !== fbo.height) {
|
|
16886
|
+
canvas.width = fbo.width / 2;
|
|
16887
|
+
canvas.height = fbo.height / 2;
|
|
16888
|
+
canvas.style.width = "400px";
|
|
16889
|
+
canvas.style.height = "400px";
|
|
16890
|
+
}
|
|
16891
|
+
const color = fbo.device.readPixelsToArrayWebGL(fbo);
|
|
16892
|
+
const imageData = ctx.createImageData(fbo.width, fbo.height);
|
|
16893
|
+
const offset = 0;
|
|
16894
|
+
for (let i3 = 0; i3 < color.length; i3 += 4) {
|
|
16895
|
+
imageData.data[offset + i3 + 0] = color[i3 + 0] * rgbaScale;
|
|
16896
|
+
imageData.data[offset + i3 + 1] = color[i3 + 1] * rgbaScale;
|
|
16897
|
+
imageData.data[offset + i3 + 2] = color[i3 + 2] * rgbaScale;
|
|
16898
|
+
imageData.data[offset + i3 + 3] = opaque ? 255 : color[i3 + 3] * rgbaScale;
|
|
16899
|
+
}
|
|
16900
|
+
ctx.putImageData(imageData, 0, 0);
|
|
16901
|
+
}
|
|
16902
|
+
|
|
14080
16903
|
// ../../node_modules/@luma.gl/engine/dist/model/model.js
|
|
14081
16904
|
var LOG_DRAW_PRIORITY = 2;
|
|
14082
16905
|
var LOG_DRAW_TIMEOUT = 1e4;
|
|
@@ -14111,6 +16934,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
14111
16934
|
this.props = void 0;
|
|
14112
16935
|
this._lastLogTime = 0;
|
|
14113
16936
|
this._logOpen = false;
|
|
16937
|
+
this._drawCount = 0;
|
|
14114
16938
|
this.props = {
|
|
14115
16939
|
...Model.defaultProps,
|
|
14116
16940
|
...props
|
|
@@ -14121,6 +16945,19 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
14121
16945
|
Object.assign(this.userData, props.userData);
|
|
14122
16946
|
const moduleMap = Object.fromEntries(((_this$props$modules = this.props.modules) === null || _this$props$modules === void 0 ? void 0 : _this$props$modules.map((module) => [module.name, module])) || []);
|
|
14123
16947
|
this.setShaderInputs(props.shaderInputs || new ShaderInputs(moduleMap));
|
|
16948
|
+
const isWebGPU = this.device.info.type === "webgpu";
|
|
16949
|
+
if (this.props.source) {
|
|
16950
|
+
if (isWebGPU) {
|
|
16951
|
+
var _this$props;
|
|
16952
|
+
(_this$props = this.props).shaderLayout || (_this$props.shaderLayout = getShaderLayoutFromWGSL(this.props.source));
|
|
16953
|
+
}
|
|
16954
|
+
this.props.fs = this.props.source;
|
|
16955
|
+
this.props.vs = this.props.source;
|
|
16956
|
+
}
|
|
16957
|
+
if (isWebGPU && typeof this.props.vs !== "string") {
|
|
16958
|
+
var _this$props2;
|
|
16959
|
+
(_this$props2 = this.props).shaderLayout || (_this$props2.shaderLayout = getShaderLayoutFromWGSL(this.props.vs.wgsl));
|
|
16960
|
+
}
|
|
14124
16961
|
const platformInfo = getPlatformInfo(device);
|
|
14125
16962
|
const modules = (((_this$props$modules2 = this.props.modules) === null || _this$props$modules2 === void 0 ? void 0 : _this$props$modules2.length) > 0 ? this.props.modules : (_this$shaderInputs = this.shaderInputs) === null || _this$shaderInputs === void 0 ? void 0 : _this$shaderInputs.getModules()) || [];
|
|
14126
16963
|
const {
|
|
@@ -14208,6 +17045,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
14208
17045
|
} finally {
|
|
14209
17046
|
this._logDrawCallEnd();
|
|
14210
17047
|
}
|
|
17048
|
+
this._logFramebuffer(renderPass);
|
|
14211
17049
|
}
|
|
14212
17050
|
setGeometry(geometry) {
|
|
14213
17051
|
const gpuGeometry = geometry && makeGPUGeometry(this.device, geometry);
|
|
@@ -14219,9 +17057,18 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
14219
17057
|
return gpuGeometry;
|
|
14220
17058
|
}
|
|
14221
17059
|
_setGeometryAttributes(gpuGeometry) {
|
|
17060
|
+
const attributes = {
|
|
17061
|
+
...gpuGeometry.attributes
|
|
17062
|
+
};
|
|
17063
|
+
for (const [attributeName] of Object.entries(attributes)) {
|
|
17064
|
+
if (!this.pipeline.shaderLayout.attributes.find((layout) => layout.name === attributeName) && attributeName !== "positions") {
|
|
17065
|
+
delete attributes[attributeName];
|
|
17066
|
+
}
|
|
17067
|
+
}
|
|
14222
17068
|
this.vertexCount = gpuGeometry.vertexCount;
|
|
14223
|
-
this.setAttributes(gpuGeometry.attributes, "ignore-unknown");
|
|
14224
17069
|
this.setIndexBuffer(gpuGeometry.indices);
|
|
17070
|
+
this.setAttributes(gpuGeometry.attributes, "ignore-unknown");
|
|
17071
|
+
this.setAttributes(attributes);
|
|
14225
17072
|
}
|
|
14226
17073
|
setTopology(topology) {
|
|
14227
17074
|
if (topology !== this.topology) {
|
|
@@ -14260,6 +17107,18 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
14260
17107
|
this.bindings[`${moduleName}Uniforms`] = uniformBuffer;
|
|
14261
17108
|
}
|
|
14262
17109
|
}
|
|
17110
|
+
setShaderModuleProps(props) {
|
|
17111
|
+
const uniforms = this._getModuleUniforms(props);
|
|
17112
|
+
const keys = Object.keys(uniforms).filter((k) => {
|
|
17113
|
+
const uniform = uniforms[k];
|
|
17114
|
+
return !(0, import_core22.isNumberArray)(uniform) && typeof uniform !== "number" && typeof uniform !== "boolean";
|
|
17115
|
+
});
|
|
17116
|
+
const bindings = {};
|
|
17117
|
+
for (const k of keys) {
|
|
17118
|
+
bindings[k] = uniforms[k];
|
|
17119
|
+
delete uniforms[k];
|
|
17120
|
+
}
|
|
17121
|
+
}
|
|
14263
17122
|
updateShaderInputs() {
|
|
14264
17123
|
this._uniformStore.setUniforms(this.shaderInputs.getUniformValues());
|
|
14265
17124
|
}
|
|
@@ -14328,21 +17187,23 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
14328
17187
|
import_core22.log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
|
|
14329
17188
|
}
|
|
14330
17189
|
this._pipelineNeedsUpdate = false;
|
|
17190
|
+
const vs2 = this.device.createShader({
|
|
17191
|
+
id: `${this.id}-vertex`,
|
|
17192
|
+
stage: "vertex",
|
|
17193
|
+
source: this.vs
|
|
17194
|
+
});
|
|
17195
|
+
const fs2 = this.fs ? this.device.createShader({
|
|
17196
|
+
id: `${this.id}-fragment`,
|
|
17197
|
+
stage: "fragment",
|
|
17198
|
+
source: this.fs
|
|
17199
|
+
}) : null;
|
|
14331
17200
|
this.pipeline = this.device.createRenderPipeline({
|
|
14332
17201
|
...this.props,
|
|
14333
17202
|
bufferLayout: this.bufferLayout,
|
|
14334
17203
|
topology: this.topology,
|
|
14335
17204
|
parameters: this.parameters,
|
|
14336
|
-
vs:
|
|
14337
|
-
|
|
14338
|
-
stage: "vertex",
|
|
14339
|
-
source: this.vs
|
|
14340
|
-
}),
|
|
14341
|
-
fs: this.fs ? this.device.createShader({
|
|
14342
|
-
id: "{$this.id}-fragment",
|
|
14343
|
-
stage: "fragment",
|
|
14344
|
-
source: this.fs
|
|
14345
|
-
}) : null
|
|
17205
|
+
vs: vs2,
|
|
17206
|
+
fs: fs2
|
|
14346
17207
|
});
|
|
14347
17208
|
this._attributeInfos = (0, import_core23.getAttributeInfosFromLayouts)(this.pipeline.shaderLayout, this.bufferLayout);
|
|
14348
17209
|
}
|
|
@@ -14350,8 +17211,8 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
14350
17211
|
}
|
|
14351
17212
|
_logDrawCallStart() {
|
|
14352
17213
|
const logDrawTimeout = import_core22.log.level > 3 ? 0 : LOG_DRAW_TIMEOUT;
|
|
14353
|
-
if (Date.now() - this._lastLogTime < logDrawTimeout) {
|
|
14354
|
-
return
|
|
17214
|
+
if (import_core22.log.level < 2 || Date.now() - this._lastLogTime < logDrawTimeout) {
|
|
17215
|
+
return;
|
|
14355
17216
|
}
|
|
14356
17217
|
this._lastLogTime = Date.now();
|
|
14357
17218
|
this._logOpen = true;
|
|
@@ -14361,7 +17222,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
14361
17222
|
}
|
|
14362
17223
|
_logDrawCallEnd() {
|
|
14363
17224
|
if (this._logOpen) {
|
|
14364
|
-
const shaderLayoutTable = getDebugTableForShaderLayout(this.pipeline.shaderLayout);
|
|
17225
|
+
const shaderLayoutTable = getDebugTableForShaderLayout(this.pipeline.shaderLayout, this.id);
|
|
14365
17226
|
import_core22.log.table(LOG_DRAW_PRIORITY, shaderLayoutTable)();
|
|
14366
17227
|
const uniformTable = this.shaderInputs.getDebugTable();
|
|
14367
17228
|
for (const [name12, value] of Object.entries(this.uniforms)) {
|
|
@@ -14377,6 +17238,20 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
14377
17238
|
this._logOpen = false;
|
|
14378
17239
|
}
|
|
14379
17240
|
}
|
|
17241
|
+
_logFramebuffer(renderPass) {
|
|
17242
|
+
const debugFramebuffers = import_core22.log.get("framebuffer");
|
|
17243
|
+
this._drawCount++;
|
|
17244
|
+
if (!debugFramebuffers || this._drawCount++ > 3 && this._drawCount % 60) {
|
|
17245
|
+
return;
|
|
17246
|
+
}
|
|
17247
|
+
const framebuffer = renderPass.props.framebuffer;
|
|
17248
|
+
if (framebuffer) {
|
|
17249
|
+
debugFramebuffer(framebuffer, {
|
|
17250
|
+
id: framebuffer.id,
|
|
17251
|
+
minimap: true
|
|
17252
|
+
});
|
|
17253
|
+
}
|
|
17254
|
+
}
|
|
14380
17255
|
_getAttributeDebugTable() {
|
|
14381
17256
|
const table = {};
|
|
14382
17257
|
for (const [name12, attributeInfo] of Object.entries(this._attributeInfos)) {
|
|
@@ -14407,6 +17282,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
14407
17282
|
};
|
|
14408
17283
|
Model.defaultProps = {
|
|
14409
17284
|
...import_core21.RenderPipeline.defaultProps,
|
|
17285
|
+
source: null,
|
|
14410
17286
|
vs: null,
|
|
14411
17287
|
fs: null,
|
|
14412
17288
|
id: "unnamed",
|
|
@@ -14865,8 +17741,8 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
14865
17741
|
}
|
|
14866
17742
|
function getWebGLContext() {
|
|
14867
17743
|
try {
|
|
14868
|
-
const
|
|
14869
|
-
return
|
|
17744
|
+
const canvas2 = document.createElement("canvas");
|
|
17745
|
+
return canvas2.getContext("webgl");
|
|
14870
17746
|
} catch (error) {
|
|
14871
17747
|
return null;
|
|
14872
17748
|
}
|
|
@@ -18687,8 +21563,8 @@ void main(void) {
|
|
|
18687
21563
|
static fromTypedArray(arrayOrType) {
|
|
18688
21564
|
arrayOrType = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
|
|
18689
21565
|
for (const glType in GL_TYPE_TO_ARRAY_TYPE) {
|
|
18690
|
-
const
|
|
18691
|
-
if (
|
|
21566
|
+
const ArrayType2 = GL_TYPE_TO_ARRAY_TYPE[glType];
|
|
21567
|
+
if (ArrayType2 === arrayOrType) {
|
|
18692
21568
|
return glType;
|
|
18693
21569
|
}
|
|
18694
21570
|
}
|
|
@@ -18708,16 +21584,16 @@ void main(void) {
|
|
|
18708
21584
|
case GL_TYPE.UNSIGNED_SHORT_5_5_5_1:
|
|
18709
21585
|
return Uint16Array;
|
|
18710
21586
|
default:
|
|
18711
|
-
const
|
|
18712
|
-
if (!
|
|
21587
|
+
const ArrayType2 = GL_TYPE_TO_ARRAY_TYPE[glType];
|
|
21588
|
+
if (!ArrayType2) {
|
|
18713
21589
|
throw new Error(ERR_TYPE_CONVERSION);
|
|
18714
21590
|
}
|
|
18715
|
-
return
|
|
21591
|
+
return ArrayType2;
|
|
18716
21592
|
}
|
|
18717
21593
|
}
|
|
18718
21594
|
static getByteSize(glType) {
|
|
18719
|
-
const
|
|
18720
|
-
return
|
|
21595
|
+
const ArrayType2 = GLType.getArrayType(glType);
|
|
21596
|
+
return ArrayType2.BYTES_PER_ELEMENT;
|
|
18721
21597
|
}
|
|
18722
21598
|
static validate(glType) {
|
|
18723
21599
|
return Boolean(GLType.getArrayType(glType));
|
|
@@ -18728,8 +21604,8 @@ void main(void) {
|
|
|
18728
21604
|
if (length5 === void 0) {
|
|
18729
21605
|
length5 = (buffer.byteLength - byteOffset) / GLType.getByteSize(glType);
|
|
18730
21606
|
}
|
|
18731
|
-
const
|
|
18732
|
-
return new
|
|
21607
|
+
const ArrayType2 = GLType.getArrayType(glType);
|
|
21608
|
+
return new ArrayType2(buffer, byteOffset, length5);
|
|
18733
21609
|
}
|
|
18734
21610
|
};
|
|
18735
21611
|
|
|
@@ -19849,7 +22725,7 @@ void main(void) {
|
|
|
19849
22725
|
return componentType;
|
|
19850
22726
|
}
|
|
19851
22727
|
function getAccessorArrayTypeAndLength(accessor, bufferView) {
|
|
19852
|
-
const
|
|
22728
|
+
const ArrayType2 = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];
|
|
19853
22729
|
const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];
|
|
19854
22730
|
const bytesPerComponent = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[accessor.componentType];
|
|
19855
22731
|
const length5 = accessor.count * components;
|
|
@@ -19858,7 +22734,7 @@ void main(void) {
|
|
|
19858
22734
|
const componentByteSize = BYTES[accessor.componentType];
|
|
19859
22735
|
const numberOfComponentsInElement = COMPONENTS[accessor.type];
|
|
19860
22736
|
return {
|
|
19861
|
-
ArrayType,
|
|
22737
|
+
ArrayType: ArrayType2,
|
|
19862
22738
|
length: length5,
|
|
19863
22739
|
byteLength,
|
|
19864
22740
|
componentByteSize,
|
|
@@ -19911,7 +22787,7 @@ void main(void) {
|
|
|
19911
22787
|
} = buffers[bufferView.buffer];
|
|
19912
22788
|
const byteOffset = (bufferByteOffset || 0) + (gltfAccessor.byteOffset || 0) + (bufferView.byteOffset || 0);
|
|
19913
22789
|
const {
|
|
19914
|
-
ArrayType,
|
|
22790
|
+
ArrayType: ArrayType2,
|
|
19915
22791
|
length: length5,
|
|
19916
22792
|
componentByteSize,
|
|
19917
22793
|
numberOfComponentsInElement
|
|
@@ -19919,12 +22795,12 @@ void main(void) {
|
|
|
19919
22795
|
const elementByteSize = componentByteSize * numberOfComponentsInElement;
|
|
19920
22796
|
const elementAddressScale = bufferView.byteStride || elementByteSize;
|
|
19921
22797
|
if (typeof bufferView.byteStride === "undefined" || bufferView.byteStride === elementByteSize) {
|
|
19922
|
-
const result2 = new
|
|
22798
|
+
const result2 = new ArrayType2(arrayBuffer, byteOffset, length5);
|
|
19923
22799
|
return result2;
|
|
19924
22800
|
}
|
|
19925
|
-
const result = new
|
|
22801
|
+
const result = new ArrayType2(length5);
|
|
19926
22802
|
for (let i3 = 0; i3 < gltfAccessor.count; i3++) {
|
|
19927
|
-
const values = new
|
|
22803
|
+
const values = new ArrayType2(arrayBuffer, byteOffset + i3 * elementAddressScale, numberOfComponentsInElement);
|
|
19928
22804
|
result.set(values, i3 * numberOfComponentsInElement);
|
|
19929
22805
|
}
|
|
19930
22806
|
return result;
|
|
@@ -20430,7 +23306,7 @@ void main(void) {
|
|
|
20430
23306
|
function convertRawBufferToMetadataArray(data, attributeType, componentType) {
|
|
20431
23307
|
let elementCount = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 1;
|
|
20432
23308
|
const numberOfComponents = ATTRIBUTE_TYPE_TO_COMPONENTS2[attributeType];
|
|
20433
|
-
const
|
|
23309
|
+
const ArrayType2 = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY2[componentType];
|
|
20434
23310
|
const size = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE2[componentType];
|
|
20435
23311
|
const length5 = elementCount * numberOfComponents;
|
|
20436
23312
|
const byteLength = length5 * size;
|
|
@@ -20441,7 +23317,7 @@ void main(void) {
|
|
|
20441
23317
|
buffer = bufferArray.slice(offset, offset + byteLength).buffer;
|
|
20442
23318
|
offset = 0;
|
|
20443
23319
|
}
|
|
20444
|
-
return new
|
|
23320
|
+
return new ArrayType2(buffer, offset, length5);
|
|
20445
23321
|
}
|
|
20446
23322
|
function getPrimitiveTextureData(scenegraph, textureInfo, primitive) {
|
|
20447
23323
|
var _json$textures, _json$textures$textur;
|
|
@@ -21453,16 +24329,16 @@ void main(void) {
|
|
|
21453
24329
|
count
|
|
21454
24330
|
};
|
|
21455
24331
|
}
|
|
21456
|
-
function toTypedArray(array,
|
|
24332
|
+
function toTypedArray(array, ArrayType2) {
|
|
21457
24333
|
let convertTypedArrays = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
|
|
21458
24334
|
if (!array) {
|
|
21459
24335
|
return null;
|
|
21460
24336
|
}
|
|
21461
24337
|
if (Array.isArray(array)) {
|
|
21462
|
-
return new
|
|
24338
|
+
return new ArrayType2(array);
|
|
21463
24339
|
}
|
|
21464
|
-
if (convertTypedArrays && !(array instanceof
|
|
21465
|
-
return new
|
|
24340
|
+
if (convertTypedArrays && !(array instanceof ArrayType2)) {
|
|
24341
|
+
return new ArrayType2(array);
|
|
21466
24342
|
}
|
|
21467
24343
|
return array;
|
|
21468
24344
|
}
|
|
@@ -21683,7 +24559,7 @@ void main(void) {
|
|
|
21683
24559
|
} = gltfData.buffers[bufferView.buffer];
|
|
21684
24560
|
const byteOffset = (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);
|
|
21685
24561
|
const {
|
|
21686
|
-
ArrayType,
|
|
24562
|
+
ArrayType: ArrayType2,
|
|
21687
24563
|
length: length5
|
|
21688
24564
|
} = getAccessorArrayTypeAndLength(accessor, bufferView);
|
|
21689
24565
|
const bytes = BYTES[accessor.componentType];
|
|
@@ -21691,7 +24567,7 @@ void main(void) {
|
|
|
21691
24567
|
const elementAddressScale = bufferView.byteStride || bytes * components;
|
|
21692
24568
|
const result = new Float32Array(length5);
|
|
21693
24569
|
for (let i3 = 0; i3 < accessor.count; i3++) {
|
|
21694
|
-
const uv = new
|
|
24570
|
+
const uv = new ArrayType2(arrayBuffer, byteOffset + i3 * elementAddressScale, 2);
|
|
21695
24571
|
scratchVector13.set(uv[0], uv[1], 1);
|
|
21696
24572
|
scratchVector13.transformByMatrix3(matrix);
|
|
21697
24573
|
result.set([scratchVector13[0], scratchVector13[1]], i3 * components);
|
|
@@ -22647,7 +25523,7 @@ void main(void) {
|
|
|
22647
25523
|
if (accessor.bufferView) {
|
|
22648
25524
|
const buffer = accessor.bufferView.buffer;
|
|
22649
25525
|
const {
|
|
22650
|
-
ArrayType,
|
|
25526
|
+
ArrayType: ArrayType2,
|
|
22651
25527
|
byteLength
|
|
22652
25528
|
} = getAccessorArrayTypeAndLength(accessor, accessor.bufferView);
|
|
22653
25529
|
const byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;
|
|
@@ -22655,7 +25531,7 @@ void main(void) {
|
|
|
22655
25531
|
if (accessor.bufferView.byteStride) {
|
|
22656
25532
|
cutBuffer = this._getValueFromInterleavedBuffer(buffer, byteOffset, accessor.bufferView.byteStride, accessor.bytesPerElement, accessor.count);
|
|
22657
25533
|
}
|
|
22658
|
-
accessor.value = new
|
|
25534
|
+
accessor.value = new ArrayType2(cutBuffer);
|
|
22659
25535
|
}
|
|
22660
25536
|
return accessor;
|
|
22661
25537
|
}
|