@deck.gl/arcgis 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 +3139 -53
- package/dist.min.js +45 -42
- package/package.json +4 -4
package/dist/dist.dev.js
CHANGED
|
@@ -966,7 +966,7 @@ ${moduleSource}
|
|
|
966
966
|
}
|
|
967
967
|
function getShaderName(shader) {
|
|
968
968
|
let defaultName = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "unnamed";
|
|
969
|
-
const SHADER_NAME_REGEXP = /#define[\
|
|
969
|
+
const SHADER_NAME_REGEXP = /#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/;
|
|
970
970
|
const match = SHADER_NAME_REGEXP.exec(shader);
|
|
971
971
|
return match ? match[1] : defaultName;
|
|
972
972
|
}
|
|
@@ -1348,6 +1348,2779 @@ ${getApplicationDefines(allDefines)}
|
|
|
1348
1348
|
};
|
|
1349
1349
|
ShaderAssembler.defaultShaderAssembler = void 0;
|
|
1350
1350
|
|
|
1351
|
+
// ../../node_modules/@luma.gl/shadertools/dist/libs/wgsl-reflect/wgsl_reflect.module.js
|
|
1352
|
+
var ParseContext = class {
|
|
1353
|
+
constructor() {
|
|
1354
|
+
this.constants = /* @__PURE__ */ new Map();
|
|
1355
|
+
this.aliases = /* @__PURE__ */ new Map();
|
|
1356
|
+
this.structs = /* @__PURE__ */ new Map();
|
|
1357
|
+
}
|
|
1358
|
+
};
|
|
1359
|
+
var Node = class {
|
|
1360
|
+
constructor() {
|
|
1361
|
+
}
|
|
1362
|
+
get isAstNode() {
|
|
1363
|
+
return true;
|
|
1364
|
+
}
|
|
1365
|
+
get astNodeType() {
|
|
1366
|
+
return "";
|
|
1367
|
+
}
|
|
1368
|
+
evaluate(context) {
|
|
1369
|
+
throw new Error("Cannot evaluate node");
|
|
1370
|
+
}
|
|
1371
|
+
evaluateString(context) {
|
|
1372
|
+
return this.evaluate(context).toString();
|
|
1373
|
+
}
|
|
1374
|
+
};
|
|
1375
|
+
var Statement = class extends Node {
|
|
1376
|
+
constructor() {
|
|
1377
|
+
super();
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
var Function = class extends Statement {
|
|
1381
|
+
constructor(name, args, returnType, body) {
|
|
1382
|
+
super();
|
|
1383
|
+
this.name = name;
|
|
1384
|
+
this.args = args;
|
|
1385
|
+
this.returnType = returnType;
|
|
1386
|
+
this.body = body;
|
|
1387
|
+
}
|
|
1388
|
+
get astNodeType() {
|
|
1389
|
+
return "function";
|
|
1390
|
+
}
|
|
1391
|
+
};
|
|
1392
|
+
var StaticAssert = class extends Statement {
|
|
1393
|
+
constructor(expression) {
|
|
1394
|
+
super();
|
|
1395
|
+
this.expression = expression;
|
|
1396
|
+
}
|
|
1397
|
+
get astNodeType() {
|
|
1398
|
+
return "staticAssert";
|
|
1399
|
+
}
|
|
1400
|
+
};
|
|
1401
|
+
var While = class extends Statement {
|
|
1402
|
+
constructor(condition, body) {
|
|
1403
|
+
super();
|
|
1404
|
+
this.condition = condition;
|
|
1405
|
+
this.body = body;
|
|
1406
|
+
}
|
|
1407
|
+
get astNodeType() {
|
|
1408
|
+
return "while";
|
|
1409
|
+
}
|
|
1410
|
+
};
|
|
1411
|
+
var Continuing = class extends Statement {
|
|
1412
|
+
constructor(body) {
|
|
1413
|
+
super();
|
|
1414
|
+
this.body = body;
|
|
1415
|
+
}
|
|
1416
|
+
get astNodeType() {
|
|
1417
|
+
return "continuing";
|
|
1418
|
+
}
|
|
1419
|
+
};
|
|
1420
|
+
var For = class extends Statement {
|
|
1421
|
+
constructor(init, condition, increment, body) {
|
|
1422
|
+
super();
|
|
1423
|
+
this.init = init;
|
|
1424
|
+
this.condition = condition;
|
|
1425
|
+
this.increment = increment;
|
|
1426
|
+
this.body = body;
|
|
1427
|
+
}
|
|
1428
|
+
get astNodeType() {
|
|
1429
|
+
return "for";
|
|
1430
|
+
}
|
|
1431
|
+
};
|
|
1432
|
+
var Var = class extends Statement {
|
|
1433
|
+
constructor(name, type, storage, access, value) {
|
|
1434
|
+
super();
|
|
1435
|
+
this.name = name;
|
|
1436
|
+
this.type = type;
|
|
1437
|
+
this.storage = storage;
|
|
1438
|
+
this.access = access;
|
|
1439
|
+
this.value = value;
|
|
1440
|
+
}
|
|
1441
|
+
get astNodeType() {
|
|
1442
|
+
return "var";
|
|
1443
|
+
}
|
|
1444
|
+
};
|
|
1445
|
+
var Override = class extends Statement {
|
|
1446
|
+
constructor(name, type, value) {
|
|
1447
|
+
super();
|
|
1448
|
+
this.name = name;
|
|
1449
|
+
this.type = type;
|
|
1450
|
+
this.value = value;
|
|
1451
|
+
}
|
|
1452
|
+
get astNodeType() {
|
|
1453
|
+
return "override";
|
|
1454
|
+
}
|
|
1455
|
+
};
|
|
1456
|
+
var Let = class extends Statement {
|
|
1457
|
+
constructor(name, type, storage, access, value) {
|
|
1458
|
+
super();
|
|
1459
|
+
this.name = name;
|
|
1460
|
+
this.type = type;
|
|
1461
|
+
this.storage = storage;
|
|
1462
|
+
this.access = access;
|
|
1463
|
+
this.value = value;
|
|
1464
|
+
}
|
|
1465
|
+
get astNodeType() {
|
|
1466
|
+
return "let";
|
|
1467
|
+
}
|
|
1468
|
+
};
|
|
1469
|
+
var Const = class extends Statement {
|
|
1470
|
+
constructor(name, type, storage, access, value) {
|
|
1471
|
+
super();
|
|
1472
|
+
this.name = name;
|
|
1473
|
+
this.type = type;
|
|
1474
|
+
this.storage = storage;
|
|
1475
|
+
this.access = access;
|
|
1476
|
+
this.value = value;
|
|
1477
|
+
}
|
|
1478
|
+
get astNodeType() {
|
|
1479
|
+
return "const";
|
|
1480
|
+
}
|
|
1481
|
+
evaluate(context) {
|
|
1482
|
+
return this.value.evaluate(context);
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1485
|
+
var IncrementOperator;
|
|
1486
|
+
(function(IncrementOperator2) {
|
|
1487
|
+
IncrementOperator2["increment"] = "++";
|
|
1488
|
+
IncrementOperator2["decrement"] = "--";
|
|
1489
|
+
})(IncrementOperator || (IncrementOperator = {}));
|
|
1490
|
+
(function(IncrementOperator2) {
|
|
1491
|
+
function parse(val) {
|
|
1492
|
+
const key = val;
|
|
1493
|
+
if (key == "parse")
|
|
1494
|
+
throw new Error("Invalid value for IncrementOperator");
|
|
1495
|
+
return IncrementOperator2[key];
|
|
1496
|
+
}
|
|
1497
|
+
IncrementOperator2.parse = parse;
|
|
1498
|
+
})(IncrementOperator || (IncrementOperator = {}));
|
|
1499
|
+
var Increment = class extends Statement {
|
|
1500
|
+
constructor(operator, variable) {
|
|
1501
|
+
super();
|
|
1502
|
+
this.operator = operator;
|
|
1503
|
+
this.variable = variable;
|
|
1504
|
+
}
|
|
1505
|
+
get astNodeType() {
|
|
1506
|
+
return "increment";
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
var AssignOperator;
|
|
1510
|
+
(function(AssignOperator2) {
|
|
1511
|
+
AssignOperator2["assign"] = "=";
|
|
1512
|
+
AssignOperator2["addAssign"] = "+=";
|
|
1513
|
+
AssignOperator2["subtractAssin"] = "-=";
|
|
1514
|
+
AssignOperator2["multiplyAssign"] = "*=";
|
|
1515
|
+
AssignOperator2["divideAssign"] = "/=";
|
|
1516
|
+
AssignOperator2["moduloAssign"] = "%=";
|
|
1517
|
+
AssignOperator2["andAssign"] = "&=";
|
|
1518
|
+
AssignOperator2["orAssign"] = "|=";
|
|
1519
|
+
AssignOperator2["xorAssign"] = "^=";
|
|
1520
|
+
AssignOperator2["shiftLeftAssign"] = "<<=";
|
|
1521
|
+
AssignOperator2["shiftRightAssign"] = ">>=";
|
|
1522
|
+
})(AssignOperator || (AssignOperator = {}));
|
|
1523
|
+
(function(AssignOperator2) {
|
|
1524
|
+
function parse(val) {
|
|
1525
|
+
const key = val;
|
|
1526
|
+
if (key == "parse")
|
|
1527
|
+
throw new Error("Invalid value for AssignOperator");
|
|
1528
|
+
return AssignOperator2[key];
|
|
1529
|
+
}
|
|
1530
|
+
AssignOperator2.parse = parse;
|
|
1531
|
+
})(AssignOperator || (AssignOperator = {}));
|
|
1532
|
+
var Assign = class extends Statement {
|
|
1533
|
+
constructor(operator, variable, value) {
|
|
1534
|
+
super();
|
|
1535
|
+
this.operator = operator;
|
|
1536
|
+
this.variable = variable;
|
|
1537
|
+
this.value = value;
|
|
1538
|
+
}
|
|
1539
|
+
get astNodeType() {
|
|
1540
|
+
return "assign";
|
|
1541
|
+
}
|
|
1542
|
+
};
|
|
1543
|
+
var Call = class extends Statement {
|
|
1544
|
+
constructor(name, args) {
|
|
1545
|
+
super();
|
|
1546
|
+
this.name = name;
|
|
1547
|
+
this.args = args;
|
|
1548
|
+
}
|
|
1549
|
+
get astNodeType() {
|
|
1550
|
+
return "call";
|
|
1551
|
+
}
|
|
1552
|
+
};
|
|
1553
|
+
var Loop = class extends Statement {
|
|
1554
|
+
constructor(body, continuing) {
|
|
1555
|
+
super();
|
|
1556
|
+
this.body = body;
|
|
1557
|
+
this.continuing = continuing;
|
|
1558
|
+
}
|
|
1559
|
+
get astNodeType() {
|
|
1560
|
+
return "loop";
|
|
1561
|
+
}
|
|
1562
|
+
};
|
|
1563
|
+
var Switch = class extends Statement {
|
|
1564
|
+
constructor(condition, body) {
|
|
1565
|
+
super();
|
|
1566
|
+
this.condition = condition;
|
|
1567
|
+
this.body = body;
|
|
1568
|
+
}
|
|
1569
|
+
get astNodeType() {
|
|
1570
|
+
return "body";
|
|
1571
|
+
}
|
|
1572
|
+
};
|
|
1573
|
+
var If = class extends Statement {
|
|
1574
|
+
constructor(condition, body, elseif, _else) {
|
|
1575
|
+
super();
|
|
1576
|
+
this.condition = condition;
|
|
1577
|
+
this.body = body;
|
|
1578
|
+
this.elseif = elseif;
|
|
1579
|
+
this.else = _else;
|
|
1580
|
+
}
|
|
1581
|
+
get astNodeType() {
|
|
1582
|
+
return "if";
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
var Return = class extends Statement {
|
|
1586
|
+
constructor(value) {
|
|
1587
|
+
super();
|
|
1588
|
+
this.value = value;
|
|
1589
|
+
}
|
|
1590
|
+
get astNodeType() {
|
|
1591
|
+
return "return";
|
|
1592
|
+
}
|
|
1593
|
+
};
|
|
1594
|
+
var Enable = class extends Statement {
|
|
1595
|
+
constructor(name) {
|
|
1596
|
+
super();
|
|
1597
|
+
this.name = name;
|
|
1598
|
+
}
|
|
1599
|
+
get astNodeType() {
|
|
1600
|
+
return "enable";
|
|
1601
|
+
}
|
|
1602
|
+
};
|
|
1603
|
+
var Alias = class extends Statement {
|
|
1604
|
+
constructor(name, type) {
|
|
1605
|
+
super();
|
|
1606
|
+
this.name = name;
|
|
1607
|
+
this.type = type;
|
|
1608
|
+
}
|
|
1609
|
+
get astNodeType() {
|
|
1610
|
+
return "alias";
|
|
1611
|
+
}
|
|
1612
|
+
};
|
|
1613
|
+
var Discard = class extends Statement {
|
|
1614
|
+
constructor() {
|
|
1615
|
+
super();
|
|
1616
|
+
}
|
|
1617
|
+
get astNodeType() {
|
|
1618
|
+
return "discard";
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1621
|
+
var Break = class extends Statement {
|
|
1622
|
+
constructor() {
|
|
1623
|
+
super();
|
|
1624
|
+
}
|
|
1625
|
+
get astNodeType() {
|
|
1626
|
+
return "break";
|
|
1627
|
+
}
|
|
1628
|
+
};
|
|
1629
|
+
var Continue = class extends Statement {
|
|
1630
|
+
constructor() {
|
|
1631
|
+
super();
|
|
1632
|
+
}
|
|
1633
|
+
get astNodeType() {
|
|
1634
|
+
return "continue";
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
var Type = class extends Statement {
|
|
1638
|
+
constructor(name) {
|
|
1639
|
+
super();
|
|
1640
|
+
this.name = name;
|
|
1641
|
+
}
|
|
1642
|
+
get astNodeType() {
|
|
1643
|
+
return "type";
|
|
1644
|
+
}
|
|
1645
|
+
get isStruct() {
|
|
1646
|
+
return false;
|
|
1647
|
+
}
|
|
1648
|
+
get isArray() {
|
|
1649
|
+
return false;
|
|
1650
|
+
}
|
|
1651
|
+
};
|
|
1652
|
+
var Struct = class extends Type {
|
|
1653
|
+
constructor(name, members) {
|
|
1654
|
+
super(name);
|
|
1655
|
+
this.members = members;
|
|
1656
|
+
}
|
|
1657
|
+
get astNodeType() {
|
|
1658
|
+
return "struct";
|
|
1659
|
+
}
|
|
1660
|
+
get isStruct() {
|
|
1661
|
+
return true;
|
|
1662
|
+
}
|
|
1663
|
+
getMemberIndex(name) {
|
|
1664
|
+
for (let i = 0; i < this.members.length; i++) {
|
|
1665
|
+
if (this.members[i].name == name)
|
|
1666
|
+
return i;
|
|
1667
|
+
}
|
|
1668
|
+
return -1;
|
|
1669
|
+
}
|
|
1670
|
+
};
|
|
1671
|
+
var TemplateType = class extends Type {
|
|
1672
|
+
constructor(name, format, access) {
|
|
1673
|
+
super(name);
|
|
1674
|
+
this.format = format;
|
|
1675
|
+
this.access = access;
|
|
1676
|
+
}
|
|
1677
|
+
get astNodeType() {
|
|
1678
|
+
return "template";
|
|
1679
|
+
}
|
|
1680
|
+
};
|
|
1681
|
+
var PointerType = class extends Type {
|
|
1682
|
+
constructor(name, storage, type, access) {
|
|
1683
|
+
super(name);
|
|
1684
|
+
this.storage = storage;
|
|
1685
|
+
this.type = type;
|
|
1686
|
+
this.access = access;
|
|
1687
|
+
}
|
|
1688
|
+
get astNodeType() {
|
|
1689
|
+
return "pointer";
|
|
1690
|
+
}
|
|
1691
|
+
};
|
|
1692
|
+
var ArrayType = class extends Type {
|
|
1693
|
+
constructor(name, attributes, format, count) {
|
|
1694
|
+
super(name);
|
|
1695
|
+
this.attributes = attributes;
|
|
1696
|
+
this.format = format;
|
|
1697
|
+
this.count = count;
|
|
1698
|
+
}
|
|
1699
|
+
get astNodeType() {
|
|
1700
|
+
return "array";
|
|
1701
|
+
}
|
|
1702
|
+
get isArray() {
|
|
1703
|
+
return true;
|
|
1704
|
+
}
|
|
1705
|
+
};
|
|
1706
|
+
var SamplerType = class extends Type {
|
|
1707
|
+
constructor(name, format, access) {
|
|
1708
|
+
super(name);
|
|
1709
|
+
this.format = format;
|
|
1710
|
+
this.access = access;
|
|
1711
|
+
}
|
|
1712
|
+
get astNodeType() {
|
|
1713
|
+
return "sampler";
|
|
1714
|
+
}
|
|
1715
|
+
};
|
|
1716
|
+
var Expression = class extends Node {
|
|
1717
|
+
constructor() {
|
|
1718
|
+
super();
|
|
1719
|
+
}
|
|
1720
|
+
};
|
|
1721
|
+
var StringExpr = class extends Expression {
|
|
1722
|
+
constructor(value) {
|
|
1723
|
+
super();
|
|
1724
|
+
this.value = value;
|
|
1725
|
+
}
|
|
1726
|
+
get astNodeType() {
|
|
1727
|
+
return "stringExpr";
|
|
1728
|
+
}
|
|
1729
|
+
toString() {
|
|
1730
|
+
return this.value;
|
|
1731
|
+
}
|
|
1732
|
+
evaluateString() {
|
|
1733
|
+
return this.value;
|
|
1734
|
+
}
|
|
1735
|
+
};
|
|
1736
|
+
var CreateExpr = class extends Expression {
|
|
1737
|
+
constructor(type, args) {
|
|
1738
|
+
super();
|
|
1739
|
+
this.type = type;
|
|
1740
|
+
this.args = args;
|
|
1741
|
+
}
|
|
1742
|
+
get astNodeType() {
|
|
1743
|
+
return "createExpr";
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
var CallExpr = class extends Expression {
|
|
1747
|
+
constructor(name, args) {
|
|
1748
|
+
super();
|
|
1749
|
+
this.name = name;
|
|
1750
|
+
this.args = args;
|
|
1751
|
+
}
|
|
1752
|
+
get astNodeType() {
|
|
1753
|
+
return "callExpr";
|
|
1754
|
+
}
|
|
1755
|
+
evaluate(context) {
|
|
1756
|
+
switch (this.name) {
|
|
1757
|
+
case "abs":
|
|
1758
|
+
return Math.abs(this.args[0].evaluate(context));
|
|
1759
|
+
case "acos":
|
|
1760
|
+
return Math.acos(this.args[0].evaluate(context));
|
|
1761
|
+
case "acosh":
|
|
1762
|
+
return Math.acosh(this.args[0].evaluate(context));
|
|
1763
|
+
case "asin":
|
|
1764
|
+
return Math.asin(this.args[0].evaluate(context));
|
|
1765
|
+
case "asinh":
|
|
1766
|
+
return Math.asinh(this.args[0].evaluate(context));
|
|
1767
|
+
case "atan":
|
|
1768
|
+
return Math.atan(this.args[0].evaluate(context));
|
|
1769
|
+
case "atan2":
|
|
1770
|
+
return Math.atan2(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
1771
|
+
case "atanh":
|
|
1772
|
+
return Math.atanh(this.args[0].evaluate(context));
|
|
1773
|
+
case "ceil":
|
|
1774
|
+
return Math.ceil(this.args[0].evaluate(context));
|
|
1775
|
+
case "clamp":
|
|
1776
|
+
return Math.min(Math.max(this.args[0].evaluate(context), this.args[1].evaluate(context)), this.args[2].evaluate(context));
|
|
1777
|
+
case "cos":
|
|
1778
|
+
return Math.cos(this.args[0].evaluate(context));
|
|
1779
|
+
case "degrees":
|
|
1780
|
+
return this.args[0].evaluate(context) * 180 / Math.PI;
|
|
1781
|
+
case "distance":
|
|
1782
|
+
return Math.sqrt(Math.pow(this.args[0].evaluate(context) - this.args[1].evaluate(context), 2));
|
|
1783
|
+
case "dot":
|
|
1784
|
+
case "exp":
|
|
1785
|
+
return Math.exp(this.args[0].evaluate(context));
|
|
1786
|
+
case "exp2":
|
|
1787
|
+
return Math.pow(2, this.args[0].evaluate(context));
|
|
1788
|
+
case "floor":
|
|
1789
|
+
return Math.floor(this.args[0].evaluate(context));
|
|
1790
|
+
case "fma":
|
|
1791
|
+
return this.args[0].evaluate(context) * this.args[1].evaluate(context) + this.args[2].evaluate(context);
|
|
1792
|
+
case "fract":
|
|
1793
|
+
return this.args[0].evaluate(context) - Math.floor(this.args[0].evaluate(context));
|
|
1794
|
+
case "inverseSqrt":
|
|
1795
|
+
return 1 / Math.sqrt(this.args[0].evaluate(context));
|
|
1796
|
+
case "log":
|
|
1797
|
+
return Math.log(this.args[0].evaluate(context));
|
|
1798
|
+
case "log2":
|
|
1799
|
+
return Math.log2(this.args[0].evaluate(context));
|
|
1800
|
+
case "max":
|
|
1801
|
+
return Math.max(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
1802
|
+
case "min":
|
|
1803
|
+
return Math.min(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
1804
|
+
case "mix":
|
|
1805
|
+
return this.args[0].evaluate(context) * (1 - this.args[2].evaluate(context)) + this.args[1].evaluate(context) * this.args[2].evaluate(context);
|
|
1806
|
+
case "modf":
|
|
1807
|
+
return this.args[0].evaluate(context) - Math.floor(this.args[0].evaluate(context));
|
|
1808
|
+
case "pow":
|
|
1809
|
+
return Math.pow(this.args[0].evaluate(context), this.args[1].evaluate(context));
|
|
1810
|
+
case "radians":
|
|
1811
|
+
return this.args[0].evaluate(context) * Math.PI / 180;
|
|
1812
|
+
case "round":
|
|
1813
|
+
return Math.round(this.args[0].evaluate(context));
|
|
1814
|
+
case "sign":
|
|
1815
|
+
return Math.sign(this.args[0].evaluate(context));
|
|
1816
|
+
case "sin":
|
|
1817
|
+
return Math.sin(this.args[0].evaluate(context));
|
|
1818
|
+
case "sinh":
|
|
1819
|
+
return Math.sinh(this.args[0].evaluate(context));
|
|
1820
|
+
case "saturate":
|
|
1821
|
+
return Math.min(Math.max(this.args[0].evaluate(context), 0), 1);
|
|
1822
|
+
case "smoothstep":
|
|
1823
|
+
return this.args[0].evaluate(context) * this.args[0].evaluate(context) * (3 - 2 * this.args[0].evaluate(context));
|
|
1824
|
+
case "sqrt":
|
|
1825
|
+
return Math.sqrt(this.args[0].evaluate(context));
|
|
1826
|
+
case "step":
|
|
1827
|
+
return this.args[0].evaluate(context) < this.args[1].evaluate(context) ? 0 : 1;
|
|
1828
|
+
case "tan":
|
|
1829
|
+
return Math.tan(this.args[0].evaluate(context));
|
|
1830
|
+
case "tanh":
|
|
1831
|
+
return Math.tanh(this.args[0].evaluate(context));
|
|
1832
|
+
case "trunc":
|
|
1833
|
+
return Math.trunc(this.args[0].evaluate(context));
|
|
1834
|
+
default:
|
|
1835
|
+
throw new Error("Non const function: " + this.name);
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
};
|
|
1839
|
+
var VariableExpr = class extends Expression {
|
|
1840
|
+
constructor(name) {
|
|
1841
|
+
super();
|
|
1842
|
+
this.name = name;
|
|
1843
|
+
}
|
|
1844
|
+
get astNodeType() {
|
|
1845
|
+
return "varExpr";
|
|
1846
|
+
}
|
|
1847
|
+
};
|
|
1848
|
+
var ConstExpr = class extends Expression {
|
|
1849
|
+
constructor(name, initializer) {
|
|
1850
|
+
super();
|
|
1851
|
+
this.name = name;
|
|
1852
|
+
this.initializer = initializer;
|
|
1853
|
+
}
|
|
1854
|
+
get astNodeType() {
|
|
1855
|
+
return "constExpr";
|
|
1856
|
+
}
|
|
1857
|
+
evaluate(context) {
|
|
1858
|
+
var _a2, _b;
|
|
1859
|
+
if (this.initializer instanceof CreateExpr) {
|
|
1860
|
+
const property = (_a2 = this.postfix) === null || _a2 === void 0 ? void 0 : _a2.evaluateString(context);
|
|
1861
|
+
const type = (_b = this.initializer.type) === null || _b === void 0 ? void 0 : _b.name;
|
|
1862
|
+
const struct = context.structs.get(type);
|
|
1863
|
+
const memberIndex = struct === null || struct === void 0 ? void 0 : struct.getMemberIndex(property);
|
|
1864
|
+
if (memberIndex != -1) {
|
|
1865
|
+
const value = this.initializer.args[memberIndex].evaluate(context);
|
|
1866
|
+
return value;
|
|
1867
|
+
}
|
|
1868
|
+
console.log(memberIndex);
|
|
1869
|
+
}
|
|
1870
|
+
return this.initializer.evaluate(context);
|
|
1871
|
+
}
|
|
1872
|
+
};
|
|
1873
|
+
var LiteralExpr = class extends Expression {
|
|
1874
|
+
constructor(value) {
|
|
1875
|
+
super();
|
|
1876
|
+
this.value = value;
|
|
1877
|
+
}
|
|
1878
|
+
get astNodeType() {
|
|
1879
|
+
return "literalExpr";
|
|
1880
|
+
}
|
|
1881
|
+
evaluate() {
|
|
1882
|
+
return this.value;
|
|
1883
|
+
}
|
|
1884
|
+
};
|
|
1885
|
+
var BitcastExpr = class extends Expression {
|
|
1886
|
+
constructor(type, value) {
|
|
1887
|
+
super();
|
|
1888
|
+
this.type = type;
|
|
1889
|
+
this.value = value;
|
|
1890
|
+
}
|
|
1891
|
+
get astNodeType() {
|
|
1892
|
+
return "bitcastExpr";
|
|
1893
|
+
}
|
|
1894
|
+
};
|
|
1895
|
+
var TypecastExpr = class extends Expression {
|
|
1896
|
+
constructor(type, args) {
|
|
1897
|
+
super();
|
|
1898
|
+
this.type = type;
|
|
1899
|
+
this.args = args;
|
|
1900
|
+
}
|
|
1901
|
+
get astNodeType() {
|
|
1902
|
+
return "typecastExpr";
|
|
1903
|
+
}
|
|
1904
|
+
evaluate(context) {
|
|
1905
|
+
return this.args[0].evaluate(context);
|
|
1906
|
+
}
|
|
1907
|
+
};
|
|
1908
|
+
var GroupingExpr = class extends Expression {
|
|
1909
|
+
constructor(contents) {
|
|
1910
|
+
super();
|
|
1911
|
+
this.contents = contents;
|
|
1912
|
+
}
|
|
1913
|
+
get astNodeType() {
|
|
1914
|
+
return "groupExpr";
|
|
1915
|
+
}
|
|
1916
|
+
evaluate(context) {
|
|
1917
|
+
return this.contents[0].evaluate(context);
|
|
1918
|
+
}
|
|
1919
|
+
};
|
|
1920
|
+
var Operator = class extends Expression {
|
|
1921
|
+
constructor() {
|
|
1922
|
+
super();
|
|
1923
|
+
}
|
|
1924
|
+
};
|
|
1925
|
+
var UnaryOperator = class extends Operator {
|
|
1926
|
+
constructor(operator, right) {
|
|
1927
|
+
super();
|
|
1928
|
+
this.operator = operator;
|
|
1929
|
+
this.right = right;
|
|
1930
|
+
}
|
|
1931
|
+
get astNodeType() {
|
|
1932
|
+
return "unaryOp";
|
|
1933
|
+
}
|
|
1934
|
+
evaluate(context) {
|
|
1935
|
+
switch (this.operator) {
|
|
1936
|
+
case "+":
|
|
1937
|
+
return this.right.evaluate(context);
|
|
1938
|
+
case "-":
|
|
1939
|
+
return -this.right.evaluate(context);
|
|
1940
|
+
case "!":
|
|
1941
|
+
return this.right.evaluate(context) ? 0 : 1;
|
|
1942
|
+
case "~":
|
|
1943
|
+
return ~this.right.evaluate(context);
|
|
1944
|
+
default:
|
|
1945
|
+
throw new Error("Unknown unary operator: " + this.operator);
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
};
|
|
1949
|
+
var BinaryOperator = class extends Operator {
|
|
1950
|
+
constructor(operator, left, right) {
|
|
1951
|
+
super();
|
|
1952
|
+
this.operator = operator;
|
|
1953
|
+
this.left = left;
|
|
1954
|
+
this.right = right;
|
|
1955
|
+
}
|
|
1956
|
+
get astNodeType() {
|
|
1957
|
+
return "binaryOp";
|
|
1958
|
+
}
|
|
1959
|
+
evaluate(context) {
|
|
1960
|
+
switch (this.operator) {
|
|
1961
|
+
case "+":
|
|
1962
|
+
return this.left.evaluate(context) + this.right.evaluate(context);
|
|
1963
|
+
case "-":
|
|
1964
|
+
return this.left.evaluate(context) - this.right.evaluate(context);
|
|
1965
|
+
case "*":
|
|
1966
|
+
return this.left.evaluate(context) * this.right.evaluate(context);
|
|
1967
|
+
case "/":
|
|
1968
|
+
return this.left.evaluate(context) / this.right.evaluate(context);
|
|
1969
|
+
case "%":
|
|
1970
|
+
return this.left.evaluate(context) % this.right.evaluate(context);
|
|
1971
|
+
case "==":
|
|
1972
|
+
return this.left.evaluate(context) == this.right.evaluate(context) ? 1 : 0;
|
|
1973
|
+
case "!=":
|
|
1974
|
+
return this.left.evaluate(context) != this.right.evaluate(context) ? 1 : 0;
|
|
1975
|
+
case "<":
|
|
1976
|
+
return this.left.evaluate(context) < this.right.evaluate(context) ? 1 : 0;
|
|
1977
|
+
case ">":
|
|
1978
|
+
return this.left.evaluate(context) > this.right.evaluate(context) ? 1 : 0;
|
|
1979
|
+
case "<=":
|
|
1980
|
+
return this.left.evaluate(context) <= this.right.evaluate(context) ? 1 : 0;
|
|
1981
|
+
case ">=":
|
|
1982
|
+
return this.left.evaluate(context) >= this.right.evaluate(context) ? 1 : 0;
|
|
1983
|
+
case "&&":
|
|
1984
|
+
return this.left.evaluate(context) && this.right.evaluate(context) ? 1 : 0;
|
|
1985
|
+
case "||":
|
|
1986
|
+
return this.left.evaluate(context) || this.right.evaluate(context) ? 1 : 0;
|
|
1987
|
+
default:
|
|
1988
|
+
throw new Error(`Unknown operator ${this.operator}`);
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
};
|
|
1992
|
+
var SwitchCase = class extends Node {
|
|
1993
|
+
constructor() {
|
|
1994
|
+
super();
|
|
1995
|
+
}
|
|
1996
|
+
};
|
|
1997
|
+
var Case = class extends SwitchCase {
|
|
1998
|
+
constructor(selector, body) {
|
|
1999
|
+
super();
|
|
2000
|
+
this.selector = selector;
|
|
2001
|
+
this.body = body;
|
|
2002
|
+
}
|
|
2003
|
+
get astNodeType() {
|
|
2004
|
+
return "case";
|
|
2005
|
+
}
|
|
2006
|
+
};
|
|
2007
|
+
var Default = class extends SwitchCase {
|
|
2008
|
+
constructor(body) {
|
|
2009
|
+
super();
|
|
2010
|
+
this.body = body;
|
|
2011
|
+
}
|
|
2012
|
+
get astNodeType() {
|
|
2013
|
+
return "default";
|
|
2014
|
+
}
|
|
2015
|
+
};
|
|
2016
|
+
var Argument = class extends Node {
|
|
2017
|
+
constructor(name, type, attributes) {
|
|
2018
|
+
super();
|
|
2019
|
+
this.name = name;
|
|
2020
|
+
this.type = type;
|
|
2021
|
+
this.attributes = attributes;
|
|
2022
|
+
}
|
|
2023
|
+
get astNodeType() {
|
|
2024
|
+
return "argument";
|
|
2025
|
+
}
|
|
2026
|
+
};
|
|
2027
|
+
var ElseIf = class extends Node {
|
|
2028
|
+
constructor(condition, body) {
|
|
2029
|
+
super();
|
|
2030
|
+
this.condition = condition;
|
|
2031
|
+
this.body = body;
|
|
2032
|
+
}
|
|
2033
|
+
get astNodeType() {
|
|
2034
|
+
return "elseif";
|
|
2035
|
+
}
|
|
2036
|
+
};
|
|
2037
|
+
var Member = class extends Node {
|
|
2038
|
+
constructor(name, type, attributes) {
|
|
2039
|
+
super();
|
|
2040
|
+
this.name = name;
|
|
2041
|
+
this.type = type;
|
|
2042
|
+
this.attributes = attributes;
|
|
2043
|
+
}
|
|
2044
|
+
get astNodeType() {
|
|
2045
|
+
return "member";
|
|
2046
|
+
}
|
|
2047
|
+
};
|
|
2048
|
+
var Attribute = class extends Node {
|
|
2049
|
+
constructor(name, value) {
|
|
2050
|
+
super();
|
|
2051
|
+
this.name = name;
|
|
2052
|
+
this.value = value;
|
|
2053
|
+
}
|
|
2054
|
+
get astNodeType() {
|
|
2055
|
+
return "attribute";
|
|
2056
|
+
}
|
|
2057
|
+
};
|
|
2058
|
+
var _a;
|
|
2059
|
+
var TokenClass;
|
|
2060
|
+
(function(TokenClass2) {
|
|
2061
|
+
TokenClass2[TokenClass2["token"] = 0] = "token";
|
|
2062
|
+
TokenClass2[TokenClass2["keyword"] = 1] = "keyword";
|
|
2063
|
+
TokenClass2[TokenClass2["reserved"] = 2] = "reserved";
|
|
2064
|
+
})(TokenClass || (TokenClass = {}));
|
|
2065
|
+
var TokenType = class {
|
|
2066
|
+
constructor(name, type, rule) {
|
|
2067
|
+
this.name = name;
|
|
2068
|
+
this.type = type;
|
|
2069
|
+
this.rule = rule;
|
|
2070
|
+
}
|
|
2071
|
+
toString() {
|
|
2072
|
+
return this.name;
|
|
2073
|
+
}
|
|
2074
|
+
};
|
|
2075
|
+
var TokenTypes = class {
|
|
2076
|
+
};
|
|
2077
|
+
_a = TokenTypes;
|
|
2078
|
+
TokenTypes.none = new TokenType("", TokenClass.reserved, "");
|
|
2079
|
+
TokenTypes.eof = new TokenType("EOF", TokenClass.token, "");
|
|
2080
|
+
TokenTypes.reserved = {
|
|
2081
|
+
asm: new TokenType("asm", TokenClass.reserved, "asm"),
|
|
2082
|
+
bf16: new TokenType("bf16", TokenClass.reserved, "bf16"),
|
|
2083
|
+
do: new TokenType("do", TokenClass.reserved, "do"),
|
|
2084
|
+
enum: new TokenType("enum", TokenClass.reserved, "enum"),
|
|
2085
|
+
f16: new TokenType("f16", TokenClass.reserved, "f16"),
|
|
2086
|
+
f64: new TokenType("f64", TokenClass.reserved, "f64"),
|
|
2087
|
+
handle: new TokenType("handle", TokenClass.reserved, "handle"),
|
|
2088
|
+
i8: new TokenType("i8", TokenClass.reserved, "i8"),
|
|
2089
|
+
i16: new TokenType("i16", TokenClass.reserved, "i16"),
|
|
2090
|
+
i64: new TokenType("i64", TokenClass.reserved, "i64"),
|
|
2091
|
+
mat: new TokenType("mat", TokenClass.reserved, "mat"),
|
|
2092
|
+
premerge: new TokenType("premerge", TokenClass.reserved, "premerge"),
|
|
2093
|
+
regardless: new TokenType("regardless", TokenClass.reserved, "regardless"),
|
|
2094
|
+
typedef: new TokenType("typedef", TokenClass.reserved, "typedef"),
|
|
2095
|
+
u8: new TokenType("u8", TokenClass.reserved, "u8"),
|
|
2096
|
+
u16: new TokenType("u16", TokenClass.reserved, "u16"),
|
|
2097
|
+
u64: new TokenType("u64", TokenClass.reserved, "u64"),
|
|
2098
|
+
unless: new TokenType("unless", TokenClass.reserved, "unless"),
|
|
2099
|
+
using: new TokenType("using", TokenClass.reserved, "using"),
|
|
2100
|
+
vec: new TokenType("vec", TokenClass.reserved, "vec"),
|
|
2101
|
+
void: new TokenType("void", TokenClass.reserved, "void")
|
|
2102
|
+
};
|
|
2103
|
+
TokenTypes.keywords = {
|
|
2104
|
+
array: new TokenType("array", TokenClass.keyword, "array"),
|
|
2105
|
+
atomic: new TokenType("atomic", TokenClass.keyword, "atomic"),
|
|
2106
|
+
bool: new TokenType("bool", TokenClass.keyword, "bool"),
|
|
2107
|
+
f32: new TokenType("f32", TokenClass.keyword, "f32"),
|
|
2108
|
+
i32: new TokenType("i32", TokenClass.keyword, "i32"),
|
|
2109
|
+
mat2x2: new TokenType("mat2x2", TokenClass.keyword, "mat2x2"),
|
|
2110
|
+
mat2x3: new TokenType("mat2x3", TokenClass.keyword, "mat2x3"),
|
|
2111
|
+
mat2x4: new TokenType("mat2x4", TokenClass.keyword, "mat2x4"),
|
|
2112
|
+
mat3x2: new TokenType("mat3x2", TokenClass.keyword, "mat3x2"),
|
|
2113
|
+
mat3x3: new TokenType("mat3x3", TokenClass.keyword, "mat3x3"),
|
|
2114
|
+
mat3x4: new TokenType("mat3x4", TokenClass.keyword, "mat3x4"),
|
|
2115
|
+
mat4x2: new TokenType("mat4x2", TokenClass.keyword, "mat4x2"),
|
|
2116
|
+
mat4x3: new TokenType("mat4x3", TokenClass.keyword, "mat4x3"),
|
|
2117
|
+
mat4x4: new TokenType("mat4x4", TokenClass.keyword, "mat4x4"),
|
|
2118
|
+
ptr: new TokenType("ptr", TokenClass.keyword, "ptr"),
|
|
2119
|
+
sampler: new TokenType("sampler", TokenClass.keyword, "sampler"),
|
|
2120
|
+
sampler_comparison: new TokenType("sampler_comparison", TokenClass.keyword, "sampler_comparison"),
|
|
2121
|
+
struct: new TokenType("struct", TokenClass.keyword, "struct"),
|
|
2122
|
+
texture_1d: new TokenType("texture_1d", TokenClass.keyword, "texture_1d"),
|
|
2123
|
+
texture_2d: new TokenType("texture_2d", TokenClass.keyword, "texture_2d"),
|
|
2124
|
+
texture_2d_array: new TokenType("texture_2d_array", TokenClass.keyword, "texture_2d_array"),
|
|
2125
|
+
texture_3d: new TokenType("texture_3d", TokenClass.keyword, "texture_3d"),
|
|
2126
|
+
texture_cube: new TokenType("texture_cube", TokenClass.keyword, "texture_cube"),
|
|
2127
|
+
texture_cube_array: new TokenType("texture_cube_array", TokenClass.keyword, "texture_cube_array"),
|
|
2128
|
+
texture_multisampled_2d: new TokenType("texture_multisampled_2d", TokenClass.keyword, "texture_multisampled_2d"),
|
|
2129
|
+
texture_storage_1d: new TokenType("texture_storage_1d", TokenClass.keyword, "texture_storage_1d"),
|
|
2130
|
+
texture_storage_2d: new TokenType("texture_storage_2d", TokenClass.keyword, "texture_storage_2d"),
|
|
2131
|
+
texture_storage_2d_array: new TokenType("texture_storage_2d_array", TokenClass.keyword, "texture_storage_2d_array"),
|
|
2132
|
+
texture_storage_3d: new TokenType("texture_storage_3d", TokenClass.keyword, "texture_storage_3d"),
|
|
2133
|
+
texture_depth_2d: new TokenType("texture_depth_2d", TokenClass.keyword, "texture_depth_2d"),
|
|
2134
|
+
texture_depth_2d_array: new TokenType("texture_depth_2d_array", TokenClass.keyword, "texture_depth_2d_array"),
|
|
2135
|
+
texture_depth_cube: new TokenType("texture_depth_cube", TokenClass.keyword, "texture_depth_cube"),
|
|
2136
|
+
texture_depth_cube_array: new TokenType("texture_depth_cube_array", TokenClass.keyword, "texture_depth_cube_array"),
|
|
2137
|
+
texture_depth_multisampled_2d: new TokenType("texture_depth_multisampled_2d", TokenClass.keyword, "texture_depth_multisampled_2d"),
|
|
2138
|
+
texture_external: new TokenType("texture_external", TokenClass.keyword, "texture_external"),
|
|
2139
|
+
u32: new TokenType("u32", TokenClass.keyword, "u32"),
|
|
2140
|
+
vec2: new TokenType("vec2", TokenClass.keyword, "vec2"),
|
|
2141
|
+
vec3: new TokenType("vec3", TokenClass.keyword, "vec3"),
|
|
2142
|
+
vec4: new TokenType("vec4", TokenClass.keyword, "vec4"),
|
|
2143
|
+
bitcast: new TokenType("bitcast", TokenClass.keyword, "bitcast"),
|
|
2144
|
+
block: new TokenType("block", TokenClass.keyword, "block"),
|
|
2145
|
+
break: new TokenType("break", TokenClass.keyword, "break"),
|
|
2146
|
+
case: new TokenType("case", TokenClass.keyword, "case"),
|
|
2147
|
+
continue: new TokenType("continue", TokenClass.keyword, "continue"),
|
|
2148
|
+
continuing: new TokenType("continuing", TokenClass.keyword, "continuing"),
|
|
2149
|
+
default: new TokenType("default", TokenClass.keyword, "default"),
|
|
2150
|
+
discard: new TokenType("discard", TokenClass.keyword, "discard"),
|
|
2151
|
+
else: new TokenType("else", TokenClass.keyword, "else"),
|
|
2152
|
+
enable: new TokenType("enable", TokenClass.keyword, "enable"),
|
|
2153
|
+
fallthrough: new TokenType("fallthrough", TokenClass.keyword, "fallthrough"),
|
|
2154
|
+
false: new TokenType("false", TokenClass.keyword, "false"),
|
|
2155
|
+
fn: new TokenType("fn", TokenClass.keyword, "fn"),
|
|
2156
|
+
for: new TokenType("for", TokenClass.keyword, "for"),
|
|
2157
|
+
function: new TokenType("function", TokenClass.keyword, "function"),
|
|
2158
|
+
if: new TokenType("if", TokenClass.keyword, "if"),
|
|
2159
|
+
let: new TokenType("let", TokenClass.keyword, "let"),
|
|
2160
|
+
const: new TokenType("const", TokenClass.keyword, "const"),
|
|
2161
|
+
loop: new TokenType("loop", TokenClass.keyword, "loop"),
|
|
2162
|
+
while: new TokenType("while", TokenClass.keyword, "while"),
|
|
2163
|
+
private: new TokenType("private", TokenClass.keyword, "private"),
|
|
2164
|
+
read: new TokenType("read", TokenClass.keyword, "read"),
|
|
2165
|
+
read_write: new TokenType("read_write", TokenClass.keyword, "read_write"),
|
|
2166
|
+
return: new TokenType("return", TokenClass.keyword, "return"),
|
|
2167
|
+
storage: new TokenType("storage", TokenClass.keyword, "storage"),
|
|
2168
|
+
switch: new TokenType("switch", TokenClass.keyword, "switch"),
|
|
2169
|
+
true: new TokenType("true", TokenClass.keyword, "true"),
|
|
2170
|
+
alias: new TokenType("alias", TokenClass.keyword, "alias"),
|
|
2171
|
+
type: new TokenType("type", TokenClass.keyword, "type"),
|
|
2172
|
+
uniform: new TokenType("uniform", TokenClass.keyword, "uniform"),
|
|
2173
|
+
var: new TokenType("var", TokenClass.keyword, "var"),
|
|
2174
|
+
override: new TokenType("override", TokenClass.keyword, "override"),
|
|
2175
|
+
workgroup: new TokenType("workgroup", TokenClass.keyword, "workgroup"),
|
|
2176
|
+
write: new TokenType("write", TokenClass.keyword, "write"),
|
|
2177
|
+
r8unorm: new TokenType("r8unorm", TokenClass.keyword, "r8unorm"),
|
|
2178
|
+
r8snorm: new TokenType("r8snorm", TokenClass.keyword, "r8snorm"),
|
|
2179
|
+
r8uint: new TokenType("r8uint", TokenClass.keyword, "r8uint"),
|
|
2180
|
+
r8sint: new TokenType("r8sint", TokenClass.keyword, "r8sint"),
|
|
2181
|
+
r16uint: new TokenType("r16uint", TokenClass.keyword, "r16uint"),
|
|
2182
|
+
r16sint: new TokenType("r16sint", TokenClass.keyword, "r16sint"),
|
|
2183
|
+
r16float: new TokenType("r16float", TokenClass.keyword, "r16float"),
|
|
2184
|
+
rg8unorm: new TokenType("rg8unorm", TokenClass.keyword, "rg8unorm"),
|
|
2185
|
+
rg8snorm: new TokenType("rg8snorm", TokenClass.keyword, "rg8snorm"),
|
|
2186
|
+
rg8uint: new TokenType("rg8uint", TokenClass.keyword, "rg8uint"),
|
|
2187
|
+
rg8sint: new TokenType("rg8sint", TokenClass.keyword, "rg8sint"),
|
|
2188
|
+
r32uint: new TokenType("r32uint", TokenClass.keyword, "r32uint"),
|
|
2189
|
+
r32sint: new TokenType("r32sint", TokenClass.keyword, "r32sint"),
|
|
2190
|
+
r32float: new TokenType("r32float", TokenClass.keyword, "r32float"),
|
|
2191
|
+
rg16uint: new TokenType("rg16uint", TokenClass.keyword, "rg16uint"),
|
|
2192
|
+
rg16sint: new TokenType("rg16sint", TokenClass.keyword, "rg16sint"),
|
|
2193
|
+
rg16float: new TokenType("rg16float", TokenClass.keyword, "rg16float"),
|
|
2194
|
+
rgba8unorm: new TokenType("rgba8unorm", TokenClass.keyword, "rgba8unorm"),
|
|
2195
|
+
rgba8unorm_srgb: new TokenType("rgba8unorm_srgb", TokenClass.keyword, "rgba8unorm_srgb"),
|
|
2196
|
+
rgba8snorm: new TokenType("rgba8snorm", TokenClass.keyword, "rgba8snorm"),
|
|
2197
|
+
rgba8uint: new TokenType("rgba8uint", TokenClass.keyword, "rgba8uint"),
|
|
2198
|
+
rgba8sint: new TokenType("rgba8sint", TokenClass.keyword, "rgba8sint"),
|
|
2199
|
+
bgra8unorm: new TokenType("bgra8unorm", TokenClass.keyword, "bgra8unorm"),
|
|
2200
|
+
bgra8unorm_srgb: new TokenType("bgra8unorm_srgb", TokenClass.keyword, "bgra8unorm_srgb"),
|
|
2201
|
+
rgb10a2unorm: new TokenType("rgb10a2unorm", TokenClass.keyword, "rgb10a2unorm"),
|
|
2202
|
+
rg11b10float: new TokenType("rg11b10float", TokenClass.keyword, "rg11b10float"),
|
|
2203
|
+
rg32uint: new TokenType("rg32uint", TokenClass.keyword, "rg32uint"),
|
|
2204
|
+
rg32sint: new TokenType("rg32sint", TokenClass.keyword, "rg32sint"),
|
|
2205
|
+
rg32float: new TokenType("rg32float", TokenClass.keyword, "rg32float"),
|
|
2206
|
+
rgba16uint: new TokenType("rgba16uint", TokenClass.keyword, "rgba16uint"),
|
|
2207
|
+
rgba16sint: new TokenType("rgba16sint", TokenClass.keyword, "rgba16sint"),
|
|
2208
|
+
rgba16float: new TokenType("rgba16float", TokenClass.keyword, "rgba16float"),
|
|
2209
|
+
rgba32uint: new TokenType("rgba32uint", TokenClass.keyword, "rgba32uint"),
|
|
2210
|
+
rgba32sint: new TokenType("rgba32sint", TokenClass.keyword, "rgba32sint"),
|
|
2211
|
+
rgba32float: new TokenType("rgba32float", TokenClass.keyword, "rgba32float"),
|
|
2212
|
+
static_assert: new TokenType("static_assert", TokenClass.keyword, "static_assert")
|
|
2213
|
+
};
|
|
2214
|
+
TokenTypes.tokens = {
|
|
2215
|
+
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)/),
|
|
2216
|
+
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?))/),
|
|
2217
|
+
int_literal: new TokenType("int_literal", TokenClass.token, /-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),
|
|
2218
|
+
uint_literal: new TokenType("uint_literal", TokenClass.token, /0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),
|
|
2219
|
+
ident: new TokenType("ident", TokenClass.token, /[a-zA-Z][0-9a-zA-Z_]*/),
|
|
2220
|
+
and: new TokenType("and", TokenClass.token, "&"),
|
|
2221
|
+
and_and: new TokenType("and_and", TokenClass.token, "&&"),
|
|
2222
|
+
arrow: new TokenType("arrow ", TokenClass.token, "->"),
|
|
2223
|
+
attr: new TokenType("attr", TokenClass.token, "@"),
|
|
2224
|
+
attr_left: new TokenType("attr_left", TokenClass.token, "[["),
|
|
2225
|
+
attr_right: new TokenType("attr_right", TokenClass.token, "]]"),
|
|
2226
|
+
forward_slash: new TokenType("forward_slash", TokenClass.token, "/"),
|
|
2227
|
+
bang: new TokenType("bang", TokenClass.token, "!"),
|
|
2228
|
+
bracket_left: new TokenType("bracket_left", TokenClass.token, "["),
|
|
2229
|
+
bracket_right: new TokenType("bracket_right", TokenClass.token, "]"),
|
|
2230
|
+
brace_left: new TokenType("brace_left", TokenClass.token, "{"),
|
|
2231
|
+
brace_right: new TokenType("brace_right", TokenClass.token, "}"),
|
|
2232
|
+
colon: new TokenType("colon", TokenClass.token, ":"),
|
|
2233
|
+
comma: new TokenType("comma", TokenClass.token, ","),
|
|
2234
|
+
equal: new TokenType("equal", TokenClass.token, "="),
|
|
2235
|
+
equal_equal: new TokenType("equal_equal", TokenClass.token, "=="),
|
|
2236
|
+
not_equal: new TokenType("not_equal", TokenClass.token, "!="),
|
|
2237
|
+
greater_than: new TokenType("greater_than", TokenClass.token, ">"),
|
|
2238
|
+
greater_than_equal: new TokenType("greater_than_equal", TokenClass.token, ">="),
|
|
2239
|
+
shift_right: new TokenType("shift_right", TokenClass.token, ">>"),
|
|
2240
|
+
less_than: new TokenType("less_than", TokenClass.token, "<"),
|
|
2241
|
+
less_than_equal: new TokenType("less_than_equal", TokenClass.token, "<="),
|
|
2242
|
+
shift_left: new TokenType("shift_left", TokenClass.token, "<<"),
|
|
2243
|
+
modulo: new TokenType("modulo", TokenClass.token, "%"),
|
|
2244
|
+
minus: new TokenType("minus", TokenClass.token, "-"),
|
|
2245
|
+
minus_minus: new TokenType("minus_minus", TokenClass.token, "--"),
|
|
2246
|
+
period: new TokenType("period", TokenClass.token, "."),
|
|
2247
|
+
plus: new TokenType("plus", TokenClass.token, "+"),
|
|
2248
|
+
plus_plus: new TokenType("plus_plus", TokenClass.token, "++"),
|
|
2249
|
+
or: new TokenType("or", TokenClass.token, "|"),
|
|
2250
|
+
or_or: new TokenType("or_or", TokenClass.token, "||"),
|
|
2251
|
+
paren_left: new TokenType("paren_left", TokenClass.token, "("),
|
|
2252
|
+
paren_right: new TokenType("paren_right", TokenClass.token, ")"),
|
|
2253
|
+
semicolon: new TokenType("semicolon", TokenClass.token, ";"),
|
|
2254
|
+
star: new TokenType("star", TokenClass.token, "*"),
|
|
2255
|
+
tilde: new TokenType("tilde", TokenClass.token, "~"),
|
|
2256
|
+
underscore: new TokenType("underscore", TokenClass.token, "_"),
|
|
2257
|
+
xor: new TokenType("xor", TokenClass.token, "^"),
|
|
2258
|
+
plus_equal: new TokenType("plus_equal", TokenClass.token, "+="),
|
|
2259
|
+
minus_equal: new TokenType("minus_equal", TokenClass.token, "-="),
|
|
2260
|
+
times_equal: new TokenType("times_equal", TokenClass.token, "*="),
|
|
2261
|
+
division_equal: new TokenType("division_equal", TokenClass.token, "/="),
|
|
2262
|
+
modulo_equal: new TokenType("modulo_equal", TokenClass.token, "%="),
|
|
2263
|
+
and_equal: new TokenType("and_equal", TokenClass.token, "&="),
|
|
2264
|
+
or_equal: new TokenType("or_equal", TokenClass.token, "|="),
|
|
2265
|
+
xor_equal: new TokenType("xor_equal", TokenClass.token, "^="),
|
|
2266
|
+
shift_right_equal: new TokenType("shift_right_equal", TokenClass.token, ">>="),
|
|
2267
|
+
shift_left_equal: new TokenType("shift_left_equal", TokenClass.token, "<<=")
|
|
2268
|
+
};
|
|
2269
|
+
TokenTypes.storage_class = [_a.keywords.function, _a.keywords.private, _a.keywords.workgroup, _a.keywords.uniform, _a.keywords.storage];
|
|
2270
|
+
TokenTypes.access_mode = [_a.keywords.read, _a.keywords.write, _a.keywords.read_write];
|
|
2271
|
+
TokenTypes.sampler_type = [_a.keywords.sampler, _a.keywords.sampler_comparison];
|
|
2272
|
+
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];
|
|
2273
|
+
TokenTypes.multisampled_texture_type = [_a.keywords.texture_multisampled_2d];
|
|
2274
|
+
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];
|
|
2275
|
+
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];
|
|
2276
|
+
TokenTypes.texture_external_type = [_a.keywords.texture_external];
|
|
2277
|
+
TokenTypes.any_texture_type = [..._a.sampled_texture_type, ..._a.multisampled_texture_type, ..._a.storage_texture_type, ..._a.depth_texture_type, ..._a.texture_external_type];
|
|
2278
|
+
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];
|
|
2279
|
+
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];
|
|
2280
|
+
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];
|
|
2281
|
+
TokenTypes.element_count_expression = [_a.tokens.int_literal, _a.tokens.uint_literal, _a.tokens.ident];
|
|
2282
|
+
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];
|
|
2283
|
+
TokenTypes.attribute_name = [_a.tokens.ident, _a.keywords.block];
|
|
2284
|
+
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];
|
|
2285
|
+
TokenTypes.increment_operators = [_a.tokens.plus_plus, _a.tokens.minus_minus];
|
|
2286
|
+
var Token = class {
|
|
2287
|
+
constructor(type, lexeme, line) {
|
|
2288
|
+
this.type = type;
|
|
2289
|
+
this.lexeme = lexeme;
|
|
2290
|
+
this.line = line;
|
|
2291
|
+
}
|
|
2292
|
+
toString() {
|
|
2293
|
+
return this.lexeme;
|
|
2294
|
+
}
|
|
2295
|
+
isTemplateType() {
|
|
2296
|
+
return TokenTypes.template_types.indexOf(this.type) != -1;
|
|
2297
|
+
}
|
|
2298
|
+
isArrayType() {
|
|
2299
|
+
return this.type == TokenTypes.keywords.array;
|
|
2300
|
+
}
|
|
2301
|
+
isArrayOrTemplateType() {
|
|
2302
|
+
return this.isArrayType() || this.isTemplateType();
|
|
2303
|
+
}
|
|
2304
|
+
};
|
|
2305
|
+
var WgslScanner = class {
|
|
2306
|
+
constructor(source) {
|
|
2307
|
+
this._tokens = [];
|
|
2308
|
+
this._start = 0;
|
|
2309
|
+
this._current = 0;
|
|
2310
|
+
this._line = 1;
|
|
2311
|
+
this._source = source !== null && source !== void 0 ? source : "";
|
|
2312
|
+
}
|
|
2313
|
+
scanTokens() {
|
|
2314
|
+
while (!this._isAtEnd()) {
|
|
2315
|
+
this._start = this._current;
|
|
2316
|
+
if (!this.scanToken())
|
|
2317
|
+
throw `Invalid syntax at line ${this._line}`;
|
|
2318
|
+
}
|
|
2319
|
+
this._tokens.push(new Token(TokenTypes.eof, "", this._line));
|
|
2320
|
+
return this._tokens;
|
|
2321
|
+
}
|
|
2322
|
+
scanToken() {
|
|
2323
|
+
let lexeme = this._advance();
|
|
2324
|
+
if (lexeme == "\n") {
|
|
2325
|
+
this._line++;
|
|
2326
|
+
return true;
|
|
2327
|
+
}
|
|
2328
|
+
if (this._isWhitespace(lexeme)) {
|
|
2329
|
+
return true;
|
|
2330
|
+
}
|
|
2331
|
+
if (lexeme == "/") {
|
|
2332
|
+
if (this._peekAhead() == "/") {
|
|
2333
|
+
while (lexeme != "\n") {
|
|
2334
|
+
if (this._isAtEnd())
|
|
2335
|
+
return true;
|
|
2336
|
+
lexeme = this._advance();
|
|
2337
|
+
}
|
|
2338
|
+
this._line++;
|
|
2339
|
+
return true;
|
|
2340
|
+
} else if (this._peekAhead() == "*") {
|
|
2341
|
+
this._advance();
|
|
2342
|
+
let commentLevel = 1;
|
|
2343
|
+
while (commentLevel > 0) {
|
|
2344
|
+
if (this._isAtEnd())
|
|
2345
|
+
return true;
|
|
2346
|
+
lexeme = this._advance();
|
|
2347
|
+
if (lexeme == "\n") {
|
|
2348
|
+
this._line++;
|
|
2349
|
+
} else if (lexeme == "*") {
|
|
2350
|
+
if (this._peekAhead() == "/") {
|
|
2351
|
+
this._advance();
|
|
2352
|
+
commentLevel--;
|
|
2353
|
+
if (commentLevel == 0) {
|
|
2354
|
+
return true;
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
} else if (lexeme == "/") {
|
|
2358
|
+
if (this._peekAhead() == "*") {
|
|
2359
|
+
this._advance();
|
|
2360
|
+
commentLevel++;
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
return true;
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
let matchType = TokenTypes.none;
|
|
2368
|
+
for (; ; ) {
|
|
2369
|
+
let matchedType = this._findType(lexeme);
|
|
2370
|
+
const nextLexeme = this._peekAhead();
|
|
2371
|
+
if (lexeme == ">" && (nextLexeme == ">" || nextLexeme == "=")) {
|
|
2372
|
+
let foundLessThan = false;
|
|
2373
|
+
let ti = this._tokens.length - 1;
|
|
2374
|
+
for (let count = 0; count < 5 && ti >= 0; ++count, --ti) {
|
|
2375
|
+
if (this._tokens[ti].type === TokenTypes.tokens.less_than) {
|
|
2376
|
+
if (ti > 0 && this._tokens[ti - 1].isArrayOrTemplateType()) {
|
|
2377
|
+
foundLessThan = true;
|
|
2378
|
+
}
|
|
2379
|
+
break;
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
if (foundLessThan) {
|
|
2383
|
+
this._addToken(matchedType);
|
|
2384
|
+
return true;
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
if (matchedType === TokenTypes.none) {
|
|
2388
|
+
let lookAheadLexeme = lexeme;
|
|
2389
|
+
let lookAhead = 0;
|
|
2390
|
+
const maxLookAhead = 2;
|
|
2391
|
+
for (let li = 0; li < maxLookAhead; ++li) {
|
|
2392
|
+
lookAheadLexeme += this._peekAhead(li);
|
|
2393
|
+
matchedType = this._findType(lookAheadLexeme);
|
|
2394
|
+
if (matchedType !== TokenTypes.none) {
|
|
2395
|
+
lookAhead = li;
|
|
2396
|
+
break;
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
if (matchedType === TokenTypes.none) {
|
|
2400
|
+
if (matchType === TokenTypes.none)
|
|
2401
|
+
return false;
|
|
2402
|
+
this._current--;
|
|
2403
|
+
this._addToken(matchType);
|
|
2404
|
+
return true;
|
|
2405
|
+
}
|
|
2406
|
+
lexeme = lookAheadLexeme;
|
|
2407
|
+
this._current += lookAhead + 1;
|
|
2408
|
+
}
|
|
2409
|
+
matchType = matchedType;
|
|
2410
|
+
if (this._isAtEnd())
|
|
2411
|
+
break;
|
|
2412
|
+
lexeme += this._advance();
|
|
2413
|
+
}
|
|
2414
|
+
if (matchType === TokenTypes.none)
|
|
2415
|
+
return false;
|
|
2416
|
+
this._addToken(matchType);
|
|
2417
|
+
return true;
|
|
2418
|
+
}
|
|
2419
|
+
_findType(lexeme) {
|
|
2420
|
+
for (const name in TokenTypes.keywords) {
|
|
2421
|
+
const type = TokenTypes.keywords[name];
|
|
2422
|
+
if (this._match(lexeme, type.rule)) {
|
|
2423
|
+
return type;
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
for (const name in TokenTypes.tokens) {
|
|
2427
|
+
const type = TokenTypes.tokens[name];
|
|
2428
|
+
if (this._match(lexeme, type.rule)) {
|
|
2429
|
+
return type;
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
return TokenTypes.none;
|
|
2433
|
+
}
|
|
2434
|
+
_match(lexeme, rule) {
|
|
2435
|
+
if (typeof rule === "string") {
|
|
2436
|
+
if (rule == lexeme) {
|
|
2437
|
+
return true;
|
|
2438
|
+
}
|
|
2439
|
+
} else {
|
|
2440
|
+
const match = rule.exec(lexeme);
|
|
2441
|
+
if (match && match.index == 0 && match[0] == lexeme)
|
|
2442
|
+
return true;
|
|
2443
|
+
}
|
|
2444
|
+
return false;
|
|
2445
|
+
}
|
|
2446
|
+
_isAtEnd() {
|
|
2447
|
+
return this._current >= this._source.length;
|
|
2448
|
+
}
|
|
2449
|
+
_isWhitespace(c) {
|
|
2450
|
+
return c == " " || c == " " || c == "\r";
|
|
2451
|
+
}
|
|
2452
|
+
_advance() {
|
|
2453
|
+
let amount = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
|
|
2454
|
+
let c = this._source[this._current];
|
|
2455
|
+
amount = amount || 0;
|
|
2456
|
+
amount++;
|
|
2457
|
+
this._current += amount;
|
|
2458
|
+
return c;
|
|
2459
|
+
}
|
|
2460
|
+
_peekAhead() {
|
|
2461
|
+
let offset = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
|
|
2462
|
+
offset = offset || 0;
|
|
2463
|
+
if (this._current + offset >= this._source.length)
|
|
2464
|
+
return "\0";
|
|
2465
|
+
return this._source[this._current + offset];
|
|
2466
|
+
}
|
|
2467
|
+
_addToken(type) {
|
|
2468
|
+
const text = this._source.substring(this._start, this._current);
|
|
2469
|
+
this._tokens.push(new Token(type, text, this._line));
|
|
2470
|
+
}
|
|
2471
|
+
};
|
|
2472
|
+
var WgslParser = class {
|
|
2473
|
+
constructor() {
|
|
2474
|
+
this._tokens = [];
|
|
2475
|
+
this._current = 0;
|
|
2476
|
+
this._context = new ParseContext();
|
|
2477
|
+
}
|
|
2478
|
+
parse(tokensOrCode) {
|
|
2479
|
+
this._initialize(tokensOrCode);
|
|
2480
|
+
let statements = [];
|
|
2481
|
+
while (!this._isAtEnd()) {
|
|
2482
|
+
const statement = this._global_decl_or_directive();
|
|
2483
|
+
if (!statement)
|
|
2484
|
+
break;
|
|
2485
|
+
statements.push(statement);
|
|
2486
|
+
}
|
|
2487
|
+
return statements;
|
|
2488
|
+
}
|
|
2489
|
+
_initialize(tokensOrCode) {
|
|
2490
|
+
if (tokensOrCode) {
|
|
2491
|
+
if (typeof tokensOrCode == "string") {
|
|
2492
|
+
const scanner = new WgslScanner(tokensOrCode);
|
|
2493
|
+
this._tokens = scanner.scanTokens();
|
|
2494
|
+
} else {
|
|
2495
|
+
this._tokens = tokensOrCode;
|
|
2496
|
+
}
|
|
2497
|
+
} else {
|
|
2498
|
+
this._tokens = [];
|
|
2499
|
+
}
|
|
2500
|
+
this._current = 0;
|
|
2501
|
+
}
|
|
2502
|
+
_error(token, message2) {
|
|
2503
|
+
console.error(token, message2);
|
|
2504
|
+
return {
|
|
2505
|
+
token,
|
|
2506
|
+
message: message2,
|
|
2507
|
+
toString: function() {
|
|
2508
|
+
return `${message2}`;
|
|
2509
|
+
}
|
|
2510
|
+
};
|
|
2511
|
+
}
|
|
2512
|
+
_isAtEnd() {
|
|
2513
|
+
return this._current >= this._tokens.length || this._peek().type == TokenTypes.eof;
|
|
2514
|
+
}
|
|
2515
|
+
_match(types) {
|
|
2516
|
+
if (types instanceof TokenType) {
|
|
2517
|
+
if (this._check(types)) {
|
|
2518
|
+
this._advance();
|
|
2519
|
+
return true;
|
|
2520
|
+
}
|
|
2521
|
+
return false;
|
|
2522
|
+
}
|
|
2523
|
+
for (let i = 0, l = types.length; i < l; ++i) {
|
|
2524
|
+
const type = types[i];
|
|
2525
|
+
if (this._check(type)) {
|
|
2526
|
+
this._advance();
|
|
2527
|
+
return true;
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
return false;
|
|
2531
|
+
}
|
|
2532
|
+
_consume(types, message2) {
|
|
2533
|
+
if (this._check(types))
|
|
2534
|
+
return this._advance();
|
|
2535
|
+
throw this._error(this._peek(), message2);
|
|
2536
|
+
}
|
|
2537
|
+
_check(types) {
|
|
2538
|
+
if (this._isAtEnd())
|
|
2539
|
+
return false;
|
|
2540
|
+
const tk = this._peek();
|
|
2541
|
+
if (types instanceof Array) {
|
|
2542
|
+
let t = tk.type;
|
|
2543
|
+
let index2 = types.indexOf(t);
|
|
2544
|
+
return index2 != -1;
|
|
2545
|
+
}
|
|
2546
|
+
return tk.type == types;
|
|
2547
|
+
}
|
|
2548
|
+
_advance() {
|
|
2549
|
+
if (!this._isAtEnd())
|
|
2550
|
+
this._current++;
|
|
2551
|
+
return this._previous();
|
|
2552
|
+
}
|
|
2553
|
+
_peek() {
|
|
2554
|
+
return this._tokens[this._current];
|
|
2555
|
+
}
|
|
2556
|
+
_previous() {
|
|
2557
|
+
return this._tokens[this._current - 1];
|
|
2558
|
+
}
|
|
2559
|
+
_global_decl_or_directive() {
|
|
2560
|
+
while (this._match(TokenTypes.tokens.semicolon) && !this._isAtEnd())
|
|
2561
|
+
;
|
|
2562
|
+
if (this._match(TokenTypes.keywords.alias)) {
|
|
2563
|
+
const type = this._type_alias();
|
|
2564
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
2565
|
+
return type;
|
|
2566
|
+
}
|
|
2567
|
+
if (this._match(TokenTypes.keywords.enable)) {
|
|
2568
|
+
const enable2 = this._enable_directive();
|
|
2569
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
2570
|
+
return enable2;
|
|
2571
|
+
}
|
|
2572
|
+
const attrs = this._attribute();
|
|
2573
|
+
if (this._check(TokenTypes.keywords.var)) {
|
|
2574
|
+
const _var = this._global_variable_decl();
|
|
2575
|
+
if (_var != null)
|
|
2576
|
+
_var.attributes = attrs;
|
|
2577
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
2578
|
+
return _var;
|
|
2579
|
+
}
|
|
2580
|
+
if (this._check(TokenTypes.keywords.override)) {
|
|
2581
|
+
const _override = this._override_variable_decl();
|
|
2582
|
+
if (_override != null)
|
|
2583
|
+
_override.attributes = attrs;
|
|
2584
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
2585
|
+
return _override;
|
|
2586
|
+
}
|
|
2587
|
+
if (this._check(TokenTypes.keywords.let)) {
|
|
2588
|
+
const _let = this._global_let_decl();
|
|
2589
|
+
if (_let != null)
|
|
2590
|
+
_let.attributes = attrs;
|
|
2591
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
2592
|
+
return _let;
|
|
2593
|
+
}
|
|
2594
|
+
if (this._check(TokenTypes.keywords.const)) {
|
|
2595
|
+
const _const = this._global_const_decl();
|
|
2596
|
+
if (_const != null)
|
|
2597
|
+
_const.attributes = attrs;
|
|
2598
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
2599
|
+
return _const;
|
|
2600
|
+
}
|
|
2601
|
+
if (this._check(TokenTypes.keywords.struct)) {
|
|
2602
|
+
const _struct = this._struct_decl();
|
|
2603
|
+
if (_struct != null)
|
|
2604
|
+
_struct.attributes = attrs;
|
|
2605
|
+
return _struct;
|
|
2606
|
+
}
|
|
2607
|
+
if (this._check(TokenTypes.keywords.fn)) {
|
|
2608
|
+
const _fn = this._function_decl();
|
|
2609
|
+
if (_fn != null)
|
|
2610
|
+
_fn.attributes = attrs;
|
|
2611
|
+
return _fn;
|
|
2612
|
+
}
|
|
2613
|
+
return null;
|
|
2614
|
+
}
|
|
2615
|
+
_function_decl() {
|
|
2616
|
+
if (!this._match(TokenTypes.keywords.fn))
|
|
2617
|
+
return null;
|
|
2618
|
+
const name = this._consume(TokenTypes.tokens.ident, "Expected function name.").toString();
|
|
2619
|
+
this._consume(TokenTypes.tokens.paren_left, "Expected '(' for function arguments.");
|
|
2620
|
+
const args = [];
|
|
2621
|
+
if (!this._check(TokenTypes.tokens.paren_right)) {
|
|
2622
|
+
do {
|
|
2623
|
+
if (this._check(TokenTypes.tokens.paren_right))
|
|
2624
|
+
break;
|
|
2625
|
+
const argAttrs = this._attribute();
|
|
2626
|
+
const name2 = this._consume(TokenTypes.tokens.ident, "Expected argument name.").toString();
|
|
2627
|
+
this._consume(TokenTypes.tokens.colon, "Expected ':' for argument type.");
|
|
2628
|
+
const typeAttrs = this._attribute();
|
|
2629
|
+
const type = this._type_decl();
|
|
2630
|
+
if (type != null) {
|
|
2631
|
+
type.attributes = typeAttrs;
|
|
2632
|
+
args.push(new Argument(name2, type, argAttrs));
|
|
2633
|
+
}
|
|
2634
|
+
} while (this._match(TokenTypes.tokens.comma));
|
|
2635
|
+
}
|
|
2636
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')' after function arguments.");
|
|
2637
|
+
let _return = null;
|
|
2638
|
+
if (this._match(TokenTypes.tokens.arrow)) {
|
|
2639
|
+
const attrs = this._attribute();
|
|
2640
|
+
_return = this._type_decl();
|
|
2641
|
+
if (_return != null)
|
|
2642
|
+
_return.attributes = attrs;
|
|
2643
|
+
}
|
|
2644
|
+
const body = this._compound_statement();
|
|
2645
|
+
return new Function(name, args, _return, body);
|
|
2646
|
+
}
|
|
2647
|
+
_compound_statement() {
|
|
2648
|
+
const statements = [];
|
|
2649
|
+
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for block.");
|
|
2650
|
+
while (!this._check(TokenTypes.tokens.brace_right)) {
|
|
2651
|
+
const statement = this._statement();
|
|
2652
|
+
if (statement !== null)
|
|
2653
|
+
statements.push(statement);
|
|
2654
|
+
}
|
|
2655
|
+
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for block.");
|
|
2656
|
+
return statements;
|
|
2657
|
+
}
|
|
2658
|
+
_statement() {
|
|
2659
|
+
while (this._match(TokenTypes.tokens.semicolon) && !this._isAtEnd())
|
|
2660
|
+
;
|
|
2661
|
+
if (this._check(TokenTypes.keywords.if))
|
|
2662
|
+
return this._if_statement();
|
|
2663
|
+
if (this._check(TokenTypes.keywords.switch))
|
|
2664
|
+
return this._switch_statement();
|
|
2665
|
+
if (this._check(TokenTypes.keywords.loop))
|
|
2666
|
+
return this._loop_statement();
|
|
2667
|
+
if (this._check(TokenTypes.keywords.for))
|
|
2668
|
+
return this._for_statement();
|
|
2669
|
+
if (this._check(TokenTypes.keywords.while))
|
|
2670
|
+
return this._while_statement();
|
|
2671
|
+
if (this._check(TokenTypes.keywords.continuing))
|
|
2672
|
+
return this._continuing_statement();
|
|
2673
|
+
if (this._check(TokenTypes.keywords.static_assert))
|
|
2674
|
+
return this._static_assert_statement();
|
|
2675
|
+
if (this._check(TokenTypes.tokens.brace_left))
|
|
2676
|
+
return this._compound_statement();
|
|
2677
|
+
let result = null;
|
|
2678
|
+
if (this._check(TokenTypes.keywords.return))
|
|
2679
|
+
result = this._return_statement();
|
|
2680
|
+
else if (this._check([TokenTypes.keywords.var, TokenTypes.keywords.let, TokenTypes.keywords.const]))
|
|
2681
|
+
result = this._variable_statement();
|
|
2682
|
+
else if (this._match(TokenTypes.keywords.discard))
|
|
2683
|
+
result = new Discard();
|
|
2684
|
+
else if (this._match(TokenTypes.keywords.break))
|
|
2685
|
+
result = new Break();
|
|
2686
|
+
else if (this._match(TokenTypes.keywords.continue))
|
|
2687
|
+
result = new Continue();
|
|
2688
|
+
else
|
|
2689
|
+
result = this._increment_decrement_statement() || this._func_call_statement() || this._assignment_statement();
|
|
2690
|
+
if (result != null)
|
|
2691
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';' after statement.");
|
|
2692
|
+
return result;
|
|
2693
|
+
}
|
|
2694
|
+
_static_assert_statement() {
|
|
2695
|
+
if (!this._match(TokenTypes.keywords.static_assert))
|
|
2696
|
+
return null;
|
|
2697
|
+
let expression = this._optional_paren_expression();
|
|
2698
|
+
return new StaticAssert(expression);
|
|
2699
|
+
}
|
|
2700
|
+
_while_statement() {
|
|
2701
|
+
if (!this._match(TokenTypes.keywords.while))
|
|
2702
|
+
return null;
|
|
2703
|
+
let condition = this._optional_paren_expression();
|
|
2704
|
+
const block = this._compound_statement();
|
|
2705
|
+
return new While(condition, block);
|
|
2706
|
+
}
|
|
2707
|
+
_continuing_statement() {
|
|
2708
|
+
if (!this._match(TokenTypes.keywords.continuing))
|
|
2709
|
+
return null;
|
|
2710
|
+
const block = this._compound_statement();
|
|
2711
|
+
return new Continuing(block);
|
|
2712
|
+
}
|
|
2713
|
+
_for_statement() {
|
|
2714
|
+
if (!this._match(TokenTypes.keywords.for))
|
|
2715
|
+
return null;
|
|
2716
|
+
this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
|
|
2717
|
+
const init = !this._check(TokenTypes.tokens.semicolon) ? this._for_init() : null;
|
|
2718
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
2719
|
+
const condition = !this._check(TokenTypes.tokens.semicolon) ? this._short_circuit_or_expression() : null;
|
|
2720
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
|
|
2721
|
+
const increment = !this._check(TokenTypes.tokens.paren_right) ? this._for_increment() : null;
|
|
2722
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
|
|
2723
|
+
const body = this._compound_statement();
|
|
2724
|
+
return new For(init, condition, increment, body);
|
|
2725
|
+
}
|
|
2726
|
+
_for_init() {
|
|
2727
|
+
return this._variable_statement() || this._func_call_statement() || this._assignment_statement();
|
|
2728
|
+
}
|
|
2729
|
+
_for_increment() {
|
|
2730
|
+
return this._func_call_statement() || this._increment_decrement_statement() || this._assignment_statement();
|
|
2731
|
+
}
|
|
2732
|
+
_variable_statement() {
|
|
2733
|
+
if (this._check(TokenTypes.keywords.var)) {
|
|
2734
|
+
const _var = this._variable_decl();
|
|
2735
|
+
if (_var === null)
|
|
2736
|
+
throw this._error(this._peek(), "Variable declaration expected.");
|
|
2737
|
+
let value = null;
|
|
2738
|
+
if (this._match(TokenTypes.tokens.equal))
|
|
2739
|
+
value = this._short_circuit_or_expression();
|
|
2740
|
+
return new Var(_var.name, _var.type, _var.storage, _var.access, value);
|
|
2741
|
+
}
|
|
2742
|
+
if (this._match(TokenTypes.keywords.let)) {
|
|
2743
|
+
const name = this._consume(TokenTypes.tokens.ident, "Expected name for let.").toString();
|
|
2744
|
+
let type = null;
|
|
2745
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
2746
|
+
const typeAttrs = this._attribute();
|
|
2747
|
+
type = this._type_decl();
|
|
2748
|
+
if (type != null)
|
|
2749
|
+
type.attributes = typeAttrs;
|
|
2750
|
+
}
|
|
2751
|
+
this._consume(TokenTypes.tokens.equal, "Expected '=' for let.");
|
|
2752
|
+
const value = this._short_circuit_or_expression();
|
|
2753
|
+
return new Let(name, type, null, null, value);
|
|
2754
|
+
}
|
|
2755
|
+
if (this._match(TokenTypes.keywords.const)) {
|
|
2756
|
+
const name = this._consume(TokenTypes.tokens.ident, "Expected name for const.").toString();
|
|
2757
|
+
let type = null;
|
|
2758
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
2759
|
+
const typeAttrs = this._attribute();
|
|
2760
|
+
type = this._type_decl();
|
|
2761
|
+
if (type != null)
|
|
2762
|
+
type.attributes = typeAttrs;
|
|
2763
|
+
}
|
|
2764
|
+
this._consume(TokenTypes.tokens.equal, "Expected '=' for const.");
|
|
2765
|
+
const value = this._short_circuit_or_expression();
|
|
2766
|
+
return new Const(name, type, null, null, value);
|
|
2767
|
+
}
|
|
2768
|
+
return null;
|
|
2769
|
+
}
|
|
2770
|
+
_increment_decrement_statement() {
|
|
2771
|
+
const savedPos = this._current;
|
|
2772
|
+
const _var = this._unary_expression();
|
|
2773
|
+
if (_var == null)
|
|
2774
|
+
return null;
|
|
2775
|
+
if (!this._check(TokenTypes.increment_operators)) {
|
|
2776
|
+
this._current = savedPos;
|
|
2777
|
+
return null;
|
|
2778
|
+
}
|
|
2779
|
+
const token = this._consume(TokenTypes.increment_operators, "Expected increment operator");
|
|
2780
|
+
return new Increment(token.type === TokenTypes.tokens.plus_plus ? IncrementOperator.increment : IncrementOperator.decrement, _var);
|
|
2781
|
+
}
|
|
2782
|
+
_assignment_statement() {
|
|
2783
|
+
let _var = null;
|
|
2784
|
+
if (this._check(TokenTypes.tokens.brace_right))
|
|
2785
|
+
return null;
|
|
2786
|
+
let isUnderscore = this._match(TokenTypes.tokens.underscore);
|
|
2787
|
+
if (!isUnderscore)
|
|
2788
|
+
_var = this._unary_expression();
|
|
2789
|
+
if (!isUnderscore && _var == null)
|
|
2790
|
+
return null;
|
|
2791
|
+
const type = this._consume(TokenTypes.assignment_operators, "Expected assignment operator.");
|
|
2792
|
+
const value = this._short_circuit_or_expression();
|
|
2793
|
+
return new Assign(AssignOperator.parse(type.lexeme), _var, value);
|
|
2794
|
+
}
|
|
2795
|
+
_func_call_statement() {
|
|
2796
|
+
if (!this._check(TokenTypes.tokens.ident))
|
|
2797
|
+
return null;
|
|
2798
|
+
const savedPos = this._current;
|
|
2799
|
+
const name = this._consume(TokenTypes.tokens.ident, "Expected function name.");
|
|
2800
|
+
const args = this._argument_expression_list();
|
|
2801
|
+
if (args === null) {
|
|
2802
|
+
this._current = savedPos;
|
|
2803
|
+
return null;
|
|
2804
|
+
}
|
|
2805
|
+
return new Call(name.lexeme, args);
|
|
2806
|
+
}
|
|
2807
|
+
_loop_statement() {
|
|
2808
|
+
if (!this._match(TokenTypes.keywords.loop))
|
|
2809
|
+
return null;
|
|
2810
|
+
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for loop.");
|
|
2811
|
+
const statements = [];
|
|
2812
|
+
let statement = this._statement();
|
|
2813
|
+
while (statement !== null) {
|
|
2814
|
+
if (Array.isArray(statement)) {
|
|
2815
|
+
for (let s of statement) {
|
|
2816
|
+
statements.push(s);
|
|
2817
|
+
}
|
|
2818
|
+
} else {
|
|
2819
|
+
statements.push(statement);
|
|
2820
|
+
}
|
|
2821
|
+
statement = this._statement();
|
|
2822
|
+
}
|
|
2823
|
+
let continuing = null;
|
|
2824
|
+
if (this._match(TokenTypes.keywords.continuing))
|
|
2825
|
+
continuing = this._compound_statement();
|
|
2826
|
+
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for loop.");
|
|
2827
|
+
return new Loop(statements, continuing);
|
|
2828
|
+
}
|
|
2829
|
+
_switch_statement() {
|
|
2830
|
+
if (!this._match(TokenTypes.keywords.switch))
|
|
2831
|
+
return null;
|
|
2832
|
+
const condition = this._optional_paren_expression();
|
|
2833
|
+
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for switch.");
|
|
2834
|
+
const body = this._switch_body();
|
|
2835
|
+
if (body == null || body.length == 0)
|
|
2836
|
+
throw this._error(this._previous(), "Expected 'case' or 'default'.");
|
|
2837
|
+
this._consume(TokenTypes.tokens.brace_right, "Expected '}' for switch.");
|
|
2838
|
+
return new Switch(condition, body);
|
|
2839
|
+
}
|
|
2840
|
+
_switch_body() {
|
|
2841
|
+
const cases = [];
|
|
2842
|
+
if (this._match(TokenTypes.keywords.case)) {
|
|
2843
|
+
const selector = this._case_selectors();
|
|
2844
|
+
this._match(TokenTypes.tokens.colon);
|
|
2845
|
+
this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch case.");
|
|
2846
|
+
const body = this._case_body();
|
|
2847
|
+
this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch case.");
|
|
2848
|
+
cases.push(new Case(selector, body));
|
|
2849
|
+
}
|
|
2850
|
+
if (this._match(TokenTypes.keywords.default)) {
|
|
2851
|
+
this._match(TokenTypes.tokens.colon);
|
|
2852
|
+
this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch default.");
|
|
2853
|
+
const body = this._case_body();
|
|
2854
|
+
this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch default.");
|
|
2855
|
+
cases.push(new Default(body));
|
|
2856
|
+
}
|
|
2857
|
+
if (this._check([TokenTypes.keywords.default, TokenTypes.keywords.case])) {
|
|
2858
|
+
const _cases = this._switch_body();
|
|
2859
|
+
cases.push(_cases[0]);
|
|
2860
|
+
}
|
|
2861
|
+
return cases;
|
|
2862
|
+
}
|
|
2863
|
+
_case_selectors() {
|
|
2864
|
+
var _a2, _b, _c, _d;
|
|
2865
|
+
const selectors = [(_b = (_a2 = this._shift_expression()) === null || _a2 === void 0 ? void 0 : _a2.evaluate(this._context).toString()) !== null && _b !== void 0 ? _b : ""];
|
|
2866
|
+
while (this._match(TokenTypes.tokens.comma)) {
|
|
2867
|
+
selectors.push((_d = (_c = this._shift_expression()) === null || _c === void 0 ? void 0 : _c.evaluate(this._context).toString()) !== null && _d !== void 0 ? _d : "");
|
|
2868
|
+
}
|
|
2869
|
+
return selectors;
|
|
2870
|
+
}
|
|
2871
|
+
_case_body() {
|
|
2872
|
+
if (this._match(TokenTypes.keywords.fallthrough)) {
|
|
2873
|
+
this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
|
|
2874
|
+
return [];
|
|
2875
|
+
}
|
|
2876
|
+
let statement = this._statement();
|
|
2877
|
+
if (statement == null)
|
|
2878
|
+
return [];
|
|
2879
|
+
if (!(statement instanceof Array)) {
|
|
2880
|
+
statement = [statement];
|
|
2881
|
+
}
|
|
2882
|
+
const nextStatement = this._case_body();
|
|
2883
|
+
if (nextStatement.length == 0)
|
|
2884
|
+
return statement;
|
|
2885
|
+
return [...statement, nextStatement[0]];
|
|
2886
|
+
}
|
|
2887
|
+
_if_statement() {
|
|
2888
|
+
if (!this._match(TokenTypes.keywords.if))
|
|
2889
|
+
return null;
|
|
2890
|
+
const condition = this._optional_paren_expression();
|
|
2891
|
+
const block = this._compound_statement();
|
|
2892
|
+
let elseif = [];
|
|
2893
|
+
if (this._match_elseif()) {
|
|
2894
|
+
elseif = this._elseif_statement(elseif);
|
|
2895
|
+
}
|
|
2896
|
+
let _else = null;
|
|
2897
|
+
if (this._match(TokenTypes.keywords.else))
|
|
2898
|
+
_else = this._compound_statement();
|
|
2899
|
+
return new If(condition, block, elseif, _else);
|
|
2900
|
+
}
|
|
2901
|
+
_match_elseif() {
|
|
2902
|
+
if (this._tokens[this._current].type === TokenTypes.keywords.else && this._tokens[this._current + 1].type === TokenTypes.keywords.if) {
|
|
2903
|
+
this._advance();
|
|
2904
|
+
this._advance();
|
|
2905
|
+
return true;
|
|
2906
|
+
}
|
|
2907
|
+
return false;
|
|
2908
|
+
}
|
|
2909
|
+
_elseif_statement() {
|
|
2910
|
+
let elseif = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
|
2911
|
+
const condition = this._optional_paren_expression();
|
|
2912
|
+
const block = this._compound_statement();
|
|
2913
|
+
elseif.push(new ElseIf(condition, block));
|
|
2914
|
+
if (this._match_elseif()) {
|
|
2915
|
+
this._elseif_statement(elseif);
|
|
2916
|
+
}
|
|
2917
|
+
return elseif;
|
|
2918
|
+
}
|
|
2919
|
+
_return_statement() {
|
|
2920
|
+
if (!this._match(TokenTypes.keywords.return))
|
|
2921
|
+
return null;
|
|
2922
|
+
const value = this._short_circuit_or_expression();
|
|
2923
|
+
return new Return(value);
|
|
2924
|
+
}
|
|
2925
|
+
_short_circuit_or_expression() {
|
|
2926
|
+
let expr = this._short_circuit_and_expr();
|
|
2927
|
+
while (this._match(TokenTypes.tokens.or_or)) {
|
|
2928
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._short_circuit_and_expr());
|
|
2929
|
+
}
|
|
2930
|
+
return expr;
|
|
2931
|
+
}
|
|
2932
|
+
_short_circuit_and_expr() {
|
|
2933
|
+
let expr = this._inclusive_or_expression();
|
|
2934
|
+
while (this._match(TokenTypes.tokens.and_and)) {
|
|
2935
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._inclusive_or_expression());
|
|
2936
|
+
}
|
|
2937
|
+
return expr;
|
|
2938
|
+
}
|
|
2939
|
+
_inclusive_or_expression() {
|
|
2940
|
+
let expr = this._exclusive_or_expression();
|
|
2941
|
+
while (this._match(TokenTypes.tokens.or)) {
|
|
2942
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._exclusive_or_expression());
|
|
2943
|
+
}
|
|
2944
|
+
return expr;
|
|
2945
|
+
}
|
|
2946
|
+
_exclusive_or_expression() {
|
|
2947
|
+
let expr = this._and_expression();
|
|
2948
|
+
while (this._match(TokenTypes.tokens.xor)) {
|
|
2949
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._and_expression());
|
|
2950
|
+
}
|
|
2951
|
+
return expr;
|
|
2952
|
+
}
|
|
2953
|
+
_and_expression() {
|
|
2954
|
+
let expr = this._equality_expression();
|
|
2955
|
+
while (this._match(TokenTypes.tokens.and)) {
|
|
2956
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._equality_expression());
|
|
2957
|
+
}
|
|
2958
|
+
return expr;
|
|
2959
|
+
}
|
|
2960
|
+
_equality_expression() {
|
|
2961
|
+
const expr = this._relational_expression();
|
|
2962
|
+
if (this._match([TokenTypes.tokens.equal_equal, TokenTypes.tokens.not_equal])) {
|
|
2963
|
+
return new BinaryOperator(this._previous().toString(), expr, this._relational_expression());
|
|
2964
|
+
}
|
|
2965
|
+
return expr;
|
|
2966
|
+
}
|
|
2967
|
+
_relational_expression() {
|
|
2968
|
+
let expr = this._shift_expression();
|
|
2969
|
+
while (this._match([TokenTypes.tokens.less_than, TokenTypes.tokens.greater_than, TokenTypes.tokens.less_than_equal, TokenTypes.tokens.greater_than_equal])) {
|
|
2970
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._shift_expression());
|
|
2971
|
+
}
|
|
2972
|
+
return expr;
|
|
2973
|
+
}
|
|
2974
|
+
_shift_expression() {
|
|
2975
|
+
let expr = this._additive_expression();
|
|
2976
|
+
while (this._match([TokenTypes.tokens.shift_left, TokenTypes.tokens.shift_right])) {
|
|
2977
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._additive_expression());
|
|
2978
|
+
}
|
|
2979
|
+
return expr;
|
|
2980
|
+
}
|
|
2981
|
+
_additive_expression() {
|
|
2982
|
+
let expr = this._multiplicative_expression();
|
|
2983
|
+
while (this._match([TokenTypes.tokens.plus, TokenTypes.tokens.minus])) {
|
|
2984
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._multiplicative_expression());
|
|
2985
|
+
}
|
|
2986
|
+
return expr;
|
|
2987
|
+
}
|
|
2988
|
+
_multiplicative_expression() {
|
|
2989
|
+
let expr = this._unary_expression();
|
|
2990
|
+
while (this._match([TokenTypes.tokens.star, TokenTypes.tokens.forward_slash, TokenTypes.tokens.modulo])) {
|
|
2991
|
+
expr = new BinaryOperator(this._previous().toString(), expr, this._unary_expression());
|
|
2992
|
+
}
|
|
2993
|
+
return expr;
|
|
2994
|
+
}
|
|
2995
|
+
_unary_expression() {
|
|
2996
|
+
if (this._match([TokenTypes.tokens.minus, TokenTypes.tokens.bang, TokenTypes.tokens.tilde, TokenTypes.tokens.star, TokenTypes.tokens.and])) {
|
|
2997
|
+
return new UnaryOperator(this._previous().toString(), this._unary_expression());
|
|
2998
|
+
}
|
|
2999
|
+
return this._singular_expression();
|
|
3000
|
+
}
|
|
3001
|
+
_singular_expression() {
|
|
3002
|
+
const expr = this._primary_expression();
|
|
3003
|
+
const p = this._postfix_expression();
|
|
3004
|
+
if (p)
|
|
3005
|
+
expr.postfix = p;
|
|
3006
|
+
return expr;
|
|
3007
|
+
}
|
|
3008
|
+
_postfix_expression() {
|
|
3009
|
+
if (this._match(TokenTypes.tokens.bracket_left)) {
|
|
3010
|
+
const expr = this._short_circuit_or_expression();
|
|
3011
|
+
this._consume(TokenTypes.tokens.bracket_right, "Expected ']'.");
|
|
3012
|
+
const p = this._postfix_expression();
|
|
3013
|
+
if (p)
|
|
3014
|
+
expr.postfix = p;
|
|
3015
|
+
return expr;
|
|
3016
|
+
}
|
|
3017
|
+
if (this._match(TokenTypes.tokens.period)) {
|
|
3018
|
+
const name = this._consume(TokenTypes.tokens.ident, "Expected member name.");
|
|
3019
|
+
const p = this._postfix_expression();
|
|
3020
|
+
const expr = new StringExpr(name.lexeme);
|
|
3021
|
+
if (p)
|
|
3022
|
+
expr.postfix = p;
|
|
3023
|
+
return expr;
|
|
3024
|
+
}
|
|
3025
|
+
return null;
|
|
3026
|
+
}
|
|
3027
|
+
_getStruct(name) {
|
|
3028
|
+
if (this._context.aliases.has(name)) {
|
|
3029
|
+
const alias = this._context.aliases.get(name).type;
|
|
3030
|
+
return alias;
|
|
3031
|
+
}
|
|
3032
|
+
if (this._context.structs.has(name)) {
|
|
3033
|
+
const struct = this._context.structs.get(name);
|
|
3034
|
+
return struct;
|
|
3035
|
+
}
|
|
3036
|
+
return null;
|
|
3037
|
+
}
|
|
3038
|
+
_primary_expression() {
|
|
3039
|
+
if (this._match(TokenTypes.tokens.ident)) {
|
|
3040
|
+
const name = this._previous().toString();
|
|
3041
|
+
if (this._check(TokenTypes.tokens.paren_left)) {
|
|
3042
|
+
const args2 = this._argument_expression_list();
|
|
3043
|
+
const struct = this._getStruct(name);
|
|
3044
|
+
if (struct != null) {
|
|
3045
|
+
return new CreateExpr(struct, args2);
|
|
3046
|
+
}
|
|
3047
|
+
return new CallExpr(name, args2);
|
|
3048
|
+
}
|
|
3049
|
+
if (this._context.constants.has(name)) {
|
|
3050
|
+
const c = this._context.constants.get(name);
|
|
3051
|
+
return new ConstExpr(name, c.value);
|
|
3052
|
+
}
|
|
3053
|
+
return new VariableExpr(name);
|
|
3054
|
+
}
|
|
3055
|
+
if (this._match(TokenTypes.const_literal)) {
|
|
3056
|
+
return new LiteralExpr(parseFloat(this._previous().toString()));
|
|
3057
|
+
}
|
|
3058
|
+
if (this._check(TokenTypes.tokens.paren_left)) {
|
|
3059
|
+
return this._paren_expression();
|
|
3060
|
+
}
|
|
3061
|
+
if (this._match(TokenTypes.keywords.bitcast)) {
|
|
3062
|
+
this._consume(TokenTypes.tokens.less_than, "Expected '<'.");
|
|
3063
|
+
const type2 = this._type_decl();
|
|
3064
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>'.");
|
|
3065
|
+
const value = this._paren_expression();
|
|
3066
|
+
return new BitcastExpr(type2, value);
|
|
3067
|
+
}
|
|
3068
|
+
const type = this._type_decl();
|
|
3069
|
+
const args = this._argument_expression_list();
|
|
3070
|
+
return new TypecastExpr(type, args);
|
|
3071
|
+
}
|
|
3072
|
+
_argument_expression_list() {
|
|
3073
|
+
if (!this._match(TokenTypes.tokens.paren_left))
|
|
3074
|
+
return null;
|
|
3075
|
+
const args = [];
|
|
3076
|
+
do {
|
|
3077
|
+
if (this._check(TokenTypes.tokens.paren_right))
|
|
3078
|
+
break;
|
|
3079
|
+
const arg = this._short_circuit_or_expression();
|
|
3080
|
+
args.push(arg);
|
|
3081
|
+
} while (this._match(TokenTypes.tokens.comma));
|
|
3082
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')' for agument list");
|
|
3083
|
+
return args;
|
|
3084
|
+
}
|
|
3085
|
+
_optional_paren_expression() {
|
|
3086
|
+
this._match(TokenTypes.tokens.paren_left);
|
|
3087
|
+
const expr = this._short_circuit_or_expression();
|
|
3088
|
+
this._match(TokenTypes.tokens.paren_right);
|
|
3089
|
+
return new GroupingExpr([expr]);
|
|
3090
|
+
}
|
|
3091
|
+
_paren_expression() {
|
|
3092
|
+
this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
|
|
3093
|
+
const expr = this._short_circuit_or_expression();
|
|
3094
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
|
|
3095
|
+
return new GroupingExpr([expr]);
|
|
3096
|
+
}
|
|
3097
|
+
_struct_decl() {
|
|
3098
|
+
if (!this._match(TokenTypes.keywords.struct))
|
|
3099
|
+
return null;
|
|
3100
|
+
const name = this._consume(TokenTypes.tokens.ident, "Expected name for struct.").toString();
|
|
3101
|
+
this._consume(TokenTypes.tokens.brace_left, "Expected '{' for struct body.");
|
|
3102
|
+
const members = [];
|
|
3103
|
+
while (!this._check(TokenTypes.tokens.brace_right)) {
|
|
3104
|
+
const memberAttrs = this._attribute();
|
|
3105
|
+
const memberName = this._consume(TokenTypes.tokens.ident, "Expected variable name.").toString();
|
|
3106
|
+
this._consume(TokenTypes.tokens.colon, "Expected ':' for struct member type.");
|
|
3107
|
+
const typeAttrs = this._attribute();
|
|
3108
|
+
const memberType = this._type_decl();
|
|
3109
|
+
if (memberType != null)
|
|
3110
|
+
memberType.attributes = typeAttrs;
|
|
3111
|
+
if (!this._check(TokenTypes.tokens.brace_right))
|
|
3112
|
+
this._consume(TokenTypes.tokens.comma, "Expected ',' for struct member.");
|
|
3113
|
+
else
|
|
3114
|
+
this._match(TokenTypes.tokens.comma);
|
|
3115
|
+
members.push(new Member(memberName, memberType, memberAttrs));
|
|
3116
|
+
}
|
|
3117
|
+
this._consume(TokenTypes.tokens.brace_right, "Expected '}' after struct body.");
|
|
3118
|
+
const structNode = new Struct(name, members);
|
|
3119
|
+
this._context.structs.set(name, structNode);
|
|
3120
|
+
return structNode;
|
|
3121
|
+
}
|
|
3122
|
+
_global_variable_decl() {
|
|
3123
|
+
const _var = this._variable_decl();
|
|
3124
|
+
if (_var && this._match(TokenTypes.tokens.equal))
|
|
3125
|
+
_var.value = this._const_expression();
|
|
3126
|
+
return _var;
|
|
3127
|
+
}
|
|
3128
|
+
_override_variable_decl() {
|
|
3129
|
+
const _override = this._override_decl();
|
|
3130
|
+
if (_override && this._match(TokenTypes.tokens.equal))
|
|
3131
|
+
_override.value = this._const_expression();
|
|
3132
|
+
return _override;
|
|
3133
|
+
}
|
|
3134
|
+
_global_const_decl() {
|
|
3135
|
+
if (!this._match(TokenTypes.keywords.const))
|
|
3136
|
+
return null;
|
|
3137
|
+
const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
3138
|
+
let type = null;
|
|
3139
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
3140
|
+
const attrs = this._attribute();
|
|
3141
|
+
type = this._type_decl();
|
|
3142
|
+
if (type != null)
|
|
3143
|
+
type.attributes = attrs;
|
|
3144
|
+
}
|
|
3145
|
+
let value = null;
|
|
3146
|
+
if (this._match(TokenTypes.tokens.equal)) {
|
|
3147
|
+
const valueExpr = this._short_circuit_or_expression();
|
|
3148
|
+
if (valueExpr instanceof CreateExpr) {
|
|
3149
|
+
value = valueExpr;
|
|
3150
|
+
} else if (valueExpr instanceof ConstExpr && valueExpr.initializer instanceof CreateExpr) {
|
|
3151
|
+
value = valueExpr.initializer;
|
|
3152
|
+
} else {
|
|
3153
|
+
try {
|
|
3154
|
+
const constValue = valueExpr.evaluate(this._context);
|
|
3155
|
+
value = new LiteralExpr(constValue);
|
|
3156
|
+
} catch (_a2) {
|
|
3157
|
+
value = valueExpr;
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
const c = new Const(name.toString(), type, "", "", value);
|
|
3162
|
+
this._context.constants.set(c.name, c);
|
|
3163
|
+
return c;
|
|
3164
|
+
}
|
|
3165
|
+
_global_let_decl() {
|
|
3166
|
+
if (!this._match(TokenTypes.keywords.let))
|
|
3167
|
+
return null;
|
|
3168
|
+
const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
3169
|
+
let type = null;
|
|
3170
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
3171
|
+
const attrs = this._attribute();
|
|
3172
|
+
type = this._type_decl();
|
|
3173
|
+
if (type != null)
|
|
3174
|
+
type.attributes = attrs;
|
|
3175
|
+
}
|
|
3176
|
+
let value = null;
|
|
3177
|
+
if (this._match(TokenTypes.tokens.equal)) {
|
|
3178
|
+
value = this._const_expression();
|
|
3179
|
+
}
|
|
3180
|
+
return new Let(name.toString(), type, "", "", value);
|
|
3181
|
+
}
|
|
3182
|
+
_const_expression() {
|
|
3183
|
+
if (this._match(TokenTypes.const_literal))
|
|
3184
|
+
return new StringExpr(this._previous().toString());
|
|
3185
|
+
const type = this._type_decl();
|
|
3186
|
+
this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
|
|
3187
|
+
let args = [];
|
|
3188
|
+
while (!this._check(TokenTypes.tokens.paren_right)) {
|
|
3189
|
+
args.push(this._const_expression());
|
|
3190
|
+
if (!this._check(TokenTypes.tokens.comma))
|
|
3191
|
+
break;
|
|
3192
|
+
this._advance();
|
|
3193
|
+
}
|
|
3194
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
|
|
3195
|
+
return new CreateExpr(type, args);
|
|
3196
|
+
}
|
|
3197
|
+
_variable_decl() {
|
|
3198
|
+
if (!this._match(TokenTypes.keywords.var))
|
|
3199
|
+
return null;
|
|
3200
|
+
let storage = "";
|
|
3201
|
+
let access = "";
|
|
3202
|
+
if (this._match(TokenTypes.tokens.less_than)) {
|
|
3203
|
+
storage = this._consume(TokenTypes.storage_class, "Expected storage_class.").toString();
|
|
3204
|
+
if (this._match(TokenTypes.tokens.comma))
|
|
3205
|
+
access = this._consume(TokenTypes.access_mode, "Expected access_mode.").toString();
|
|
3206
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>'.");
|
|
3207
|
+
}
|
|
3208
|
+
const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
3209
|
+
let type = null;
|
|
3210
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
3211
|
+
const attrs = this._attribute();
|
|
3212
|
+
type = this._type_decl();
|
|
3213
|
+
if (type != null)
|
|
3214
|
+
type.attributes = attrs;
|
|
3215
|
+
}
|
|
3216
|
+
return new Var(name.toString(), type, storage, access, null);
|
|
3217
|
+
}
|
|
3218
|
+
_override_decl() {
|
|
3219
|
+
if (!this._match(TokenTypes.keywords.override))
|
|
3220
|
+
return null;
|
|
3221
|
+
const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
|
|
3222
|
+
let type = null;
|
|
3223
|
+
if (this._match(TokenTypes.tokens.colon)) {
|
|
3224
|
+
const attrs = this._attribute();
|
|
3225
|
+
type = this._type_decl();
|
|
3226
|
+
if (type != null)
|
|
3227
|
+
type.attributes = attrs;
|
|
3228
|
+
}
|
|
3229
|
+
return new Override(name.toString(), type, null);
|
|
3230
|
+
}
|
|
3231
|
+
_enable_directive() {
|
|
3232
|
+
const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
|
|
3233
|
+
return new Enable(name.toString());
|
|
3234
|
+
}
|
|
3235
|
+
_type_alias() {
|
|
3236
|
+
const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
|
|
3237
|
+
this._consume(TokenTypes.tokens.equal, "Expected '=' for type alias.");
|
|
3238
|
+
let aliasType = this._type_decl();
|
|
3239
|
+
if (aliasType === null) {
|
|
3240
|
+
throw this._error(this._peek(), "Expected Type for Alias.");
|
|
3241
|
+
}
|
|
3242
|
+
if (this._context.aliases.has(aliasType.name)) {
|
|
3243
|
+
aliasType = this._context.aliases.get(aliasType.name).type;
|
|
3244
|
+
}
|
|
3245
|
+
const aliasNode = new Alias(name.toString(), aliasType);
|
|
3246
|
+
this._context.aliases.set(aliasNode.name, aliasNode);
|
|
3247
|
+
return aliasNode;
|
|
3248
|
+
}
|
|
3249
|
+
_type_decl() {
|
|
3250
|
+
if (this._check([TokenTypes.tokens.ident, ...TokenTypes.texel_format, TokenTypes.keywords.bool, TokenTypes.keywords.f32, TokenTypes.keywords.i32, TokenTypes.keywords.u32])) {
|
|
3251
|
+
const type2 = this._advance();
|
|
3252
|
+
const typeName = type2.toString();
|
|
3253
|
+
if (this._context.structs.has(typeName)) {
|
|
3254
|
+
return this._context.structs.get(typeName);
|
|
3255
|
+
}
|
|
3256
|
+
if (this._context.aliases.has(typeName)) {
|
|
3257
|
+
return this._context.aliases.get(typeName).type;
|
|
3258
|
+
}
|
|
3259
|
+
return new Type(type2.toString());
|
|
3260
|
+
}
|
|
3261
|
+
let type = this._texture_sampler_types();
|
|
3262
|
+
if (type)
|
|
3263
|
+
return type;
|
|
3264
|
+
if (this._check(TokenTypes.template_types)) {
|
|
3265
|
+
let type2 = this._advance().toString();
|
|
3266
|
+
let format = null;
|
|
3267
|
+
let access = null;
|
|
3268
|
+
if (this._match(TokenTypes.tokens.less_than)) {
|
|
3269
|
+
format = this._type_decl();
|
|
3270
|
+
access = null;
|
|
3271
|
+
if (this._match(TokenTypes.tokens.comma))
|
|
3272
|
+
access = this._consume(TokenTypes.access_mode, "Expected access_mode for pointer").toString();
|
|
3273
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for type.");
|
|
3274
|
+
}
|
|
3275
|
+
return new TemplateType(type2, format, access);
|
|
3276
|
+
}
|
|
3277
|
+
if (this._match(TokenTypes.keywords.ptr)) {
|
|
3278
|
+
let pointer = this._previous().toString();
|
|
3279
|
+
this._consume(TokenTypes.tokens.less_than, "Expected '<' for pointer.");
|
|
3280
|
+
const storage = this._consume(TokenTypes.storage_class, "Expected storage_class for pointer");
|
|
3281
|
+
this._consume(TokenTypes.tokens.comma, "Expected ',' for pointer.");
|
|
3282
|
+
const decl = this._type_decl();
|
|
3283
|
+
let access = null;
|
|
3284
|
+
if (this._match(TokenTypes.tokens.comma))
|
|
3285
|
+
access = this._consume(TokenTypes.access_mode, "Expected access_mode for pointer").toString();
|
|
3286
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for pointer.");
|
|
3287
|
+
return new PointerType(pointer, storage.toString(), decl, access);
|
|
3288
|
+
}
|
|
3289
|
+
const attrs = this._attribute();
|
|
3290
|
+
if (this._match(TokenTypes.keywords.array)) {
|
|
3291
|
+
let format = null;
|
|
3292
|
+
let countInt = -1;
|
|
3293
|
+
const array = this._previous();
|
|
3294
|
+
if (this._match(TokenTypes.tokens.less_than)) {
|
|
3295
|
+
format = this._type_decl();
|
|
3296
|
+
if (this._context.aliases.has(format.name)) {
|
|
3297
|
+
format = this._context.aliases.get(format.name).type;
|
|
3298
|
+
}
|
|
3299
|
+
let count = "";
|
|
3300
|
+
if (this._match(TokenTypes.tokens.comma)) {
|
|
3301
|
+
let c = this._shift_expression();
|
|
3302
|
+
count = c.evaluate(this._context).toString();
|
|
3303
|
+
}
|
|
3304
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for array.");
|
|
3305
|
+
countInt = count ? parseInt(count) : 0;
|
|
3306
|
+
}
|
|
3307
|
+
return new ArrayType(array.toString(), attrs, format, countInt);
|
|
3308
|
+
}
|
|
3309
|
+
return null;
|
|
3310
|
+
}
|
|
3311
|
+
_texture_sampler_types() {
|
|
3312
|
+
if (this._match(TokenTypes.sampler_type))
|
|
3313
|
+
return new SamplerType(this._previous().toString(), null, null);
|
|
3314
|
+
if (this._match(TokenTypes.depth_texture_type))
|
|
3315
|
+
return new SamplerType(this._previous().toString(), null, null);
|
|
3316
|
+
if (this._match(TokenTypes.sampled_texture_type) || this._match(TokenTypes.multisampled_texture_type)) {
|
|
3317
|
+
const sampler = this._previous();
|
|
3318
|
+
this._consume(TokenTypes.tokens.less_than, "Expected '<' for sampler type.");
|
|
3319
|
+
const format = this._type_decl();
|
|
3320
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for sampler type.");
|
|
3321
|
+
return new SamplerType(sampler.toString(), format, null);
|
|
3322
|
+
}
|
|
3323
|
+
if (this._match(TokenTypes.storage_texture_type)) {
|
|
3324
|
+
const sampler = this._previous();
|
|
3325
|
+
this._consume(TokenTypes.tokens.less_than, "Expected '<' for sampler type.");
|
|
3326
|
+
const format = this._consume(TokenTypes.texel_format, "Invalid texel format.").toString();
|
|
3327
|
+
this._consume(TokenTypes.tokens.comma, "Expected ',' after texel format.");
|
|
3328
|
+
const access = this._consume(TokenTypes.access_mode, "Expected access mode for storage texture type.").toString();
|
|
3329
|
+
this._consume(TokenTypes.tokens.greater_than, "Expected '>' for sampler type.");
|
|
3330
|
+
return new SamplerType(sampler.toString(), format, access);
|
|
3331
|
+
}
|
|
3332
|
+
return null;
|
|
3333
|
+
}
|
|
3334
|
+
_attribute() {
|
|
3335
|
+
let attributes = [];
|
|
3336
|
+
while (this._match(TokenTypes.tokens.attr)) {
|
|
3337
|
+
const name = this._consume(TokenTypes.attribute_name, "Expected attribute name");
|
|
3338
|
+
const attr = new Attribute(name.toString(), null);
|
|
3339
|
+
if (this._match(TokenTypes.tokens.paren_left)) {
|
|
3340
|
+
attr.value = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
|
|
3341
|
+
if (this._check(TokenTypes.tokens.comma)) {
|
|
3342
|
+
this._advance();
|
|
3343
|
+
do {
|
|
3344
|
+
const v = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
|
|
3345
|
+
if (!(attr.value instanceof Array)) {
|
|
3346
|
+
attr.value = [attr.value];
|
|
3347
|
+
}
|
|
3348
|
+
attr.value.push(v);
|
|
3349
|
+
} while (this._match(TokenTypes.tokens.comma));
|
|
3350
|
+
}
|
|
3351
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
|
|
3352
|
+
}
|
|
3353
|
+
attributes.push(attr);
|
|
3354
|
+
}
|
|
3355
|
+
while (this._match(TokenTypes.tokens.attr_left)) {
|
|
3356
|
+
if (!this._check(TokenTypes.tokens.attr_right)) {
|
|
3357
|
+
do {
|
|
3358
|
+
const name = this._consume(TokenTypes.attribute_name, "Expected attribute name");
|
|
3359
|
+
const attr = new Attribute(name.toString(), null);
|
|
3360
|
+
if (this._match(TokenTypes.tokens.paren_left)) {
|
|
3361
|
+
attr.value = [this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString()];
|
|
3362
|
+
if (this._check(TokenTypes.tokens.comma)) {
|
|
3363
|
+
this._advance();
|
|
3364
|
+
do {
|
|
3365
|
+
const v = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
|
|
3366
|
+
attr.value.push(v);
|
|
3367
|
+
} while (this._match(TokenTypes.tokens.comma));
|
|
3368
|
+
}
|
|
3369
|
+
this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
|
|
3370
|
+
}
|
|
3371
|
+
attributes.push(attr);
|
|
3372
|
+
} while (this._match(TokenTypes.tokens.comma));
|
|
3373
|
+
}
|
|
3374
|
+
this._consume(TokenTypes.tokens.attr_right, "Expected ']]' after attribute declarations");
|
|
3375
|
+
}
|
|
3376
|
+
if (attributes.length == 0)
|
|
3377
|
+
return null;
|
|
3378
|
+
return attributes;
|
|
3379
|
+
}
|
|
3380
|
+
};
|
|
3381
|
+
var TypeInfo = class {
|
|
3382
|
+
constructor(name, attributes) {
|
|
3383
|
+
this.name = name;
|
|
3384
|
+
this.attributes = attributes;
|
|
3385
|
+
this.size = 0;
|
|
3386
|
+
}
|
|
3387
|
+
get isArray() {
|
|
3388
|
+
return false;
|
|
3389
|
+
}
|
|
3390
|
+
get isStruct() {
|
|
3391
|
+
return false;
|
|
3392
|
+
}
|
|
3393
|
+
get isTemplate() {
|
|
3394
|
+
return false;
|
|
3395
|
+
}
|
|
3396
|
+
};
|
|
3397
|
+
var MemberInfo = class {
|
|
3398
|
+
constructor(name, type, attributes) {
|
|
3399
|
+
this.name = name;
|
|
3400
|
+
this.type = type;
|
|
3401
|
+
this.attributes = attributes;
|
|
3402
|
+
this.offset = 0;
|
|
3403
|
+
this.size = 0;
|
|
3404
|
+
}
|
|
3405
|
+
get isArray() {
|
|
3406
|
+
return this.type.isArray;
|
|
3407
|
+
}
|
|
3408
|
+
get isStruct() {
|
|
3409
|
+
return this.type.isStruct;
|
|
3410
|
+
}
|
|
3411
|
+
get isTemplate() {
|
|
3412
|
+
return this.type.isTemplate;
|
|
3413
|
+
}
|
|
3414
|
+
get align() {
|
|
3415
|
+
return this.type.isStruct ? this.type.align : 0;
|
|
3416
|
+
}
|
|
3417
|
+
get members() {
|
|
3418
|
+
return this.type.isStruct ? this.type.members : null;
|
|
3419
|
+
}
|
|
3420
|
+
get format() {
|
|
3421
|
+
return this.type.isArray ? this.type.format : this.type.isTemplate ? this.type.format : null;
|
|
3422
|
+
}
|
|
3423
|
+
get count() {
|
|
3424
|
+
return this.type.isArray ? this.type.count : 0;
|
|
3425
|
+
}
|
|
3426
|
+
get stride() {
|
|
3427
|
+
return this.type.isArray ? this.type.stride : this.size;
|
|
3428
|
+
}
|
|
3429
|
+
};
|
|
3430
|
+
var StructInfo = class extends TypeInfo {
|
|
3431
|
+
constructor(name, attributes) {
|
|
3432
|
+
super(name, attributes);
|
|
3433
|
+
this.members = [];
|
|
3434
|
+
this.align = 0;
|
|
3435
|
+
}
|
|
3436
|
+
get isStruct() {
|
|
3437
|
+
return true;
|
|
3438
|
+
}
|
|
3439
|
+
};
|
|
3440
|
+
var ArrayInfo = class extends TypeInfo {
|
|
3441
|
+
constructor(name, attributes) {
|
|
3442
|
+
super(name, attributes);
|
|
3443
|
+
this.count = 0;
|
|
3444
|
+
this.stride = 0;
|
|
3445
|
+
}
|
|
3446
|
+
get isArray() {
|
|
3447
|
+
return true;
|
|
3448
|
+
}
|
|
3449
|
+
};
|
|
3450
|
+
var TemplateInfo = class extends TypeInfo {
|
|
3451
|
+
constructor(name, format, attributes, access) {
|
|
3452
|
+
super(name, attributes);
|
|
3453
|
+
this.format = format;
|
|
3454
|
+
this.access = access;
|
|
3455
|
+
}
|
|
3456
|
+
get isTemplate() {
|
|
3457
|
+
return true;
|
|
3458
|
+
}
|
|
3459
|
+
};
|
|
3460
|
+
var ResourceType;
|
|
3461
|
+
(function(ResourceType2) {
|
|
3462
|
+
ResourceType2[ResourceType2["Uniform"] = 0] = "Uniform";
|
|
3463
|
+
ResourceType2[ResourceType2["Storage"] = 1] = "Storage";
|
|
3464
|
+
ResourceType2[ResourceType2["Texture"] = 2] = "Texture";
|
|
3465
|
+
ResourceType2[ResourceType2["Sampler"] = 3] = "Sampler";
|
|
3466
|
+
ResourceType2[ResourceType2["StorageTexture"] = 4] = "StorageTexture";
|
|
3467
|
+
})(ResourceType || (ResourceType = {}));
|
|
3468
|
+
var VariableInfo = class {
|
|
3469
|
+
constructor(name, type, group, binding, attributes, resourceType, access) {
|
|
3470
|
+
this.name = name;
|
|
3471
|
+
this.type = type;
|
|
3472
|
+
this.group = group;
|
|
3473
|
+
this.binding = binding;
|
|
3474
|
+
this.attributes = attributes;
|
|
3475
|
+
this.resourceType = resourceType;
|
|
3476
|
+
this.access = access;
|
|
3477
|
+
}
|
|
3478
|
+
get isArray() {
|
|
3479
|
+
return this.type.isArray;
|
|
3480
|
+
}
|
|
3481
|
+
get isStruct() {
|
|
3482
|
+
return this.type.isStruct;
|
|
3483
|
+
}
|
|
3484
|
+
get isTemplate() {
|
|
3485
|
+
return this.type.isTemplate;
|
|
3486
|
+
}
|
|
3487
|
+
get size() {
|
|
3488
|
+
return this.type.size;
|
|
3489
|
+
}
|
|
3490
|
+
get align() {
|
|
3491
|
+
return this.type.isStruct ? this.type.align : 0;
|
|
3492
|
+
}
|
|
3493
|
+
get members() {
|
|
3494
|
+
return this.type.isStruct ? this.type.members : null;
|
|
3495
|
+
}
|
|
3496
|
+
get format() {
|
|
3497
|
+
return this.type.isArray ? this.type.format : this.type.isTemplate ? this.type.format : null;
|
|
3498
|
+
}
|
|
3499
|
+
get count() {
|
|
3500
|
+
return this.type.isArray ? this.type.count : 0;
|
|
3501
|
+
}
|
|
3502
|
+
get stride() {
|
|
3503
|
+
return this.type.isArray ? this.type.stride : this.size;
|
|
3504
|
+
}
|
|
3505
|
+
};
|
|
3506
|
+
var AliasInfo = class {
|
|
3507
|
+
constructor(name, type) {
|
|
3508
|
+
this.name = name;
|
|
3509
|
+
this.type = type;
|
|
3510
|
+
}
|
|
3511
|
+
};
|
|
3512
|
+
var _TypeSize = class {
|
|
3513
|
+
constructor(align, size) {
|
|
3514
|
+
this.align = align;
|
|
3515
|
+
this.size = size;
|
|
3516
|
+
}
|
|
3517
|
+
};
|
|
3518
|
+
var InputInfo = class {
|
|
3519
|
+
constructor(name, type, locationType, location) {
|
|
3520
|
+
this.name = name;
|
|
3521
|
+
this.type = type;
|
|
3522
|
+
this.locationType = locationType;
|
|
3523
|
+
this.location = location;
|
|
3524
|
+
this.interpolation = null;
|
|
3525
|
+
}
|
|
3526
|
+
};
|
|
3527
|
+
var OutputInfo = class {
|
|
3528
|
+
constructor(name, type, locationType, location) {
|
|
3529
|
+
this.name = name;
|
|
3530
|
+
this.type = type;
|
|
3531
|
+
this.locationType = locationType;
|
|
3532
|
+
this.location = location;
|
|
3533
|
+
}
|
|
3534
|
+
};
|
|
3535
|
+
var FunctionInfo = class {
|
|
3536
|
+
constructor(name) {
|
|
3537
|
+
let stage = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
|
|
3538
|
+
this.stage = null;
|
|
3539
|
+
this.inputs = [];
|
|
3540
|
+
this.outputs = [];
|
|
3541
|
+
this.name = name;
|
|
3542
|
+
this.stage = stage;
|
|
3543
|
+
}
|
|
3544
|
+
};
|
|
3545
|
+
var EntryFunctions = class {
|
|
3546
|
+
constructor() {
|
|
3547
|
+
this.vertex = [];
|
|
3548
|
+
this.fragment = [];
|
|
3549
|
+
this.compute = [];
|
|
3550
|
+
}
|
|
3551
|
+
};
|
|
3552
|
+
var OverrideInfo = class {
|
|
3553
|
+
constructor(name, type, attributes, id) {
|
|
3554
|
+
this.name = name;
|
|
3555
|
+
this.type = type;
|
|
3556
|
+
this.attributes = attributes;
|
|
3557
|
+
this.id = id;
|
|
3558
|
+
}
|
|
3559
|
+
};
|
|
3560
|
+
var WgslReflect = class {
|
|
3561
|
+
constructor(code) {
|
|
3562
|
+
this.uniforms = [];
|
|
3563
|
+
this.storage = [];
|
|
3564
|
+
this.textures = [];
|
|
3565
|
+
this.samplers = [];
|
|
3566
|
+
this.aliases = [];
|
|
3567
|
+
this.overrides = [];
|
|
3568
|
+
this.structs = [];
|
|
3569
|
+
this.entry = new EntryFunctions();
|
|
3570
|
+
this._types = /* @__PURE__ */ new Map();
|
|
3571
|
+
if (code) {
|
|
3572
|
+
this.update(code);
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
3575
|
+
_isStorageTexture(type) {
|
|
3576
|
+
return type.name == "texture_storage_1d" || type.name == "texture_storage_2d" || type.name == "texture_storage_2d_array" || type.name == "texture_storage_3d";
|
|
3577
|
+
}
|
|
3578
|
+
update(code) {
|
|
3579
|
+
const parser = new WgslParser();
|
|
3580
|
+
const ast = parser.parse(code);
|
|
3581
|
+
for (const node of ast) {
|
|
3582
|
+
if (node instanceof Struct) {
|
|
3583
|
+
const info = this._getTypeInfo(node, null);
|
|
3584
|
+
if (info instanceof StructInfo) {
|
|
3585
|
+
this.structs.push(info);
|
|
3586
|
+
}
|
|
3587
|
+
continue;
|
|
3588
|
+
}
|
|
3589
|
+
if (node instanceof Alias) {
|
|
3590
|
+
this.aliases.push(this._getAliasInfo(node));
|
|
3591
|
+
continue;
|
|
3592
|
+
}
|
|
3593
|
+
if (node instanceof Override) {
|
|
3594
|
+
const v = node;
|
|
3595
|
+
const id = this._getAttributeNum(v.attributes, "id", 0);
|
|
3596
|
+
const type = v.type != null ? this._getTypeInfo(v.type, v.attributes) : null;
|
|
3597
|
+
this.overrides.push(new OverrideInfo(v.name, type, v.attributes, id));
|
|
3598
|
+
continue;
|
|
3599
|
+
}
|
|
3600
|
+
if (this._isUniformVar(node)) {
|
|
3601
|
+
const v = node;
|
|
3602
|
+
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
3603
|
+
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
3604
|
+
const type = this._getTypeInfo(v.type, v.attributes);
|
|
3605
|
+
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, ResourceType.Uniform, v.access);
|
|
3606
|
+
this.uniforms.push(varInfo);
|
|
3607
|
+
continue;
|
|
3608
|
+
}
|
|
3609
|
+
if (this._isStorageVar(node)) {
|
|
3610
|
+
const v = node;
|
|
3611
|
+
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
3612
|
+
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
3613
|
+
const type = this._getTypeInfo(v.type, v.attributes);
|
|
3614
|
+
const isStorageTexture = this._isStorageTexture(type);
|
|
3615
|
+
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, isStorageTexture ? ResourceType.StorageTexture : ResourceType.Storage, v.access);
|
|
3616
|
+
this.storage.push(varInfo);
|
|
3617
|
+
continue;
|
|
3618
|
+
}
|
|
3619
|
+
if (this._isTextureVar(node)) {
|
|
3620
|
+
const v = node;
|
|
3621
|
+
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
3622
|
+
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
3623
|
+
const type = this._getTypeInfo(v.type, v.attributes);
|
|
3624
|
+
const isStorageTexture = this._isStorageTexture(type);
|
|
3625
|
+
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, isStorageTexture ? ResourceType.StorageTexture : ResourceType.Texture, v.access);
|
|
3626
|
+
if (isStorageTexture) {
|
|
3627
|
+
this.storage.push(varInfo);
|
|
3628
|
+
} else {
|
|
3629
|
+
this.textures.push(varInfo);
|
|
3630
|
+
}
|
|
3631
|
+
continue;
|
|
3632
|
+
}
|
|
3633
|
+
if (this._isSamplerVar(node)) {
|
|
3634
|
+
const v = node;
|
|
3635
|
+
const g = this._getAttributeNum(v.attributes, "group", 0);
|
|
3636
|
+
const b = this._getAttributeNum(v.attributes, "binding", 0);
|
|
3637
|
+
const type = this._getTypeInfo(v.type, v.attributes);
|
|
3638
|
+
const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, ResourceType.Sampler, v.access);
|
|
3639
|
+
this.samplers.push(varInfo);
|
|
3640
|
+
continue;
|
|
3641
|
+
}
|
|
3642
|
+
if (node instanceof Function) {
|
|
3643
|
+
const vertexStage = this._getAttribute(node, "vertex");
|
|
3644
|
+
const fragmentStage = this._getAttribute(node, "fragment");
|
|
3645
|
+
const computeStage = this._getAttribute(node, "compute");
|
|
3646
|
+
const stage = vertexStage || fragmentStage || computeStage;
|
|
3647
|
+
if (stage) {
|
|
3648
|
+
const fn = new FunctionInfo(node.name, stage.name);
|
|
3649
|
+
fn.inputs = this._getInputs(node.args);
|
|
3650
|
+
fn.outputs = this._getOutputs(node.returnType);
|
|
3651
|
+
this.entry[stage.name].push(fn);
|
|
3652
|
+
}
|
|
3653
|
+
continue;
|
|
3654
|
+
}
|
|
3655
|
+
}
|
|
3656
|
+
}
|
|
3657
|
+
getBindGroups() {
|
|
3658
|
+
const groups = [];
|
|
3659
|
+
function _makeRoom(group, binding) {
|
|
3660
|
+
if (group >= groups.length)
|
|
3661
|
+
groups.length = group + 1;
|
|
3662
|
+
if (groups[group] === void 0)
|
|
3663
|
+
groups[group] = [];
|
|
3664
|
+
if (binding >= groups[group].length)
|
|
3665
|
+
groups[group].length = binding + 1;
|
|
3666
|
+
}
|
|
3667
|
+
for (const u of this.uniforms) {
|
|
3668
|
+
_makeRoom(u.group, u.binding);
|
|
3669
|
+
const group = groups[u.group];
|
|
3670
|
+
group[u.binding] = u;
|
|
3671
|
+
}
|
|
3672
|
+
for (const u of this.storage) {
|
|
3673
|
+
_makeRoom(u.group, u.binding);
|
|
3674
|
+
const group = groups[u.group];
|
|
3675
|
+
group[u.binding] = u;
|
|
3676
|
+
}
|
|
3677
|
+
for (const t of this.textures) {
|
|
3678
|
+
_makeRoom(t.group, t.binding);
|
|
3679
|
+
const group = groups[t.group];
|
|
3680
|
+
group[t.binding] = t;
|
|
3681
|
+
}
|
|
3682
|
+
for (const t of this.samplers) {
|
|
3683
|
+
_makeRoom(t.group, t.binding);
|
|
3684
|
+
const group = groups[t.group];
|
|
3685
|
+
group[t.binding] = t;
|
|
3686
|
+
}
|
|
3687
|
+
return groups;
|
|
3688
|
+
}
|
|
3689
|
+
_getOutputs(type) {
|
|
3690
|
+
let outputs = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : void 0;
|
|
3691
|
+
if (outputs === void 0)
|
|
3692
|
+
outputs = [];
|
|
3693
|
+
if (type instanceof Struct) {
|
|
3694
|
+
this._getStructOutputs(type, outputs);
|
|
3695
|
+
} else {
|
|
3696
|
+
const output = this._getOutputInfo(type);
|
|
3697
|
+
if (output !== null)
|
|
3698
|
+
outputs.push(output);
|
|
3699
|
+
}
|
|
3700
|
+
return outputs;
|
|
3701
|
+
}
|
|
3702
|
+
_getStructOutputs(struct, outputs) {
|
|
3703
|
+
for (const m of struct.members) {
|
|
3704
|
+
if (m.type instanceof Struct) {
|
|
3705
|
+
this._getStructOutputs(m.type, outputs);
|
|
3706
|
+
} else {
|
|
3707
|
+
const location = this._getAttribute(m, "location") || this._getAttribute(m, "builtin");
|
|
3708
|
+
if (location !== null) {
|
|
3709
|
+
const typeInfo = this._getTypeInfo(m.type, m.type.attributes);
|
|
3710
|
+
const locationValue = this._parseInt(location.value);
|
|
3711
|
+
const info = new OutputInfo(m.name, typeInfo, location.name, locationValue);
|
|
3712
|
+
outputs.push(info);
|
|
3713
|
+
}
|
|
3714
|
+
}
|
|
3715
|
+
}
|
|
3716
|
+
}
|
|
3717
|
+
_getOutputInfo(type) {
|
|
3718
|
+
const location = this._getAttribute(type, "location") || this._getAttribute(type, "builtin");
|
|
3719
|
+
if (location !== null) {
|
|
3720
|
+
const typeInfo = this._getTypeInfo(type, type.attributes);
|
|
3721
|
+
const locationValue = this._parseInt(location.value);
|
|
3722
|
+
const info = new OutputInfo("", typeInfo, location.name, locationValue);
|
|
3723
|
+
return info;
|
|
3724
|
+
}
|
|
3725
|
+
return null;
|
|
3726
|
+
}
|
|
3727
|
+
_getInputs(args) {
|
|
3728
|
+
let inputs = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : void 0;
|
|
3729
|
+
if (inputs === void 0)
|
|
3730
|
+
inputs = [];
|
|
3731
|
+
for (const arg of args) {
|
|
3732
|
+
if (arg.type instanceof Struct) {
|
|
3733
|
+
this._getStructInputs(arg.type, inputs);
|
|
3734
|
+
} else {
|
|
3735
|
+
const input = this._getInputInfo(arg);
|
|
3736
|
+
if (input !== null)
|
|
3737
|
+
inputs.push(input);
|
|
3738
|
+
}
|
|
3739
|
+
}
|
|
3740
|
+
return inputs;
|
|
3741
|
+
}
|
|
3742
|
+
_getStructInputs(struct, inputs) {
|
|
3743
|
+
for (const m of struct.members) {
|
|
3744
|
+
if (m.type instanceof Struct) {
|
|
3745
|
+
this._getStructInputs(m.type, inputs);
|
|
3746
|
+
} else {
|
|
3747
|
+
const input = this._getInputInfo(m);
|
|
3748
|
+
if (input !== null)
|
|
3749
|
+
inputs.push(input);
|
|
3750
|
+
}
|
|
3751
|
+
}
|
|
3752
|
+
}
|
|
3753
|
+
_getInputInfo(node) {
|
|
3754
|
+
const location = this._getAttribute(node, "location") || this._getAttribute(node, "builtin");
|
|
3755
|
+
if (location !== null) {
|
|
3756
|
+
const interpolation = this._getAttribute(node, "interpolation");
|
|
3757
|
+
const type = this._getTypeInfo(node.type, node.attributes);
|
|
3758
|
+
const locationValue = this._parseInt(location.value);
|
|
3759
|
+
const info = new InputInfo(node.name, type, location.name, locationValue);
|
|
3760
|
+
if (interpolation !== null) {
|
|
3761
|
+
info.interpolation = this._parseString(interpolation.value);
|
|
3762
|
+
}
|
|
3763
|
+
return info;
|
|
3764
|
+
}
|
|
3765
|
+
return null;
|
|
3766
|
+
}
|
|
3767
|
+
_parseString(s) {
|
|
3768
|
+
if (s instanceof Array) {
|
|
3769
|
+
s = s[0];
|
|
3770
|
+
}
|
|
3771
|
+
return s;
|
|
3772
|
+
}
|
|
3773
|
+
_parseInt(s) {
|
|
3774
|
+
if (s instanceof Array) {
|
|
3775
|
+
s = s[0];
|
|
3776
|
+
}
|
|
3777
|
+
const n = parseInt(s);
|
|
3778
|
+
return isNaN(n) ? s : n;
|
|
3779
|
+
}
|
|
3780
|
+
_getAlias(name) {
|
|
3781
|
+
for (const a of this.aliases) {
|
|
3782
|
+
if (a.name == name)
|
|
3783
|
+
return a.type;
|
|
3784
|
+
}
|
|
3785
|
+
return null;
|
|
3786
|
+
}
|
|
3787
|
+
_getAliasInfo(node) {
|
|
3788
|
+
return new AliasInfo(node.name, this._getTypeInfo(node.type, null));
|
|
3789
|
+
}
|
|
3790
|
+
_getTypeInfo(type, attributes) {
|
|
3791
|
+
if (this._types.has(type)) {
|
|
3792
|
+
return this._types.get(type);
|
|
3793
|
+
}
|
|
3794
|
+
if (type instanceof ArrayType) {
|
|
3795
|
+
const a = type;
|
|
3796
|
+
const t = this._getTypeInfo(a.format, a.attributes);
|
|
3797
|
+
const info2 = new ArrayInfo(a.name, attributes);
|
|
3798
|
+
info2.format = t;
|
|
3799
|
+
info2.count = a.count;
|
|
3800
|
+
this._types.set(type, info2);
|
|
3801
|
+
this._updateTypeInfo(info2);
|
|
3802
|
+
return info2;
|
|
3803
|
+
}
|
|
3804
|
+
if (type instanceof Struct) {
|
|
3805
|
+
const s = type;
|
|
3806
|
+
const info2 = new StructInfo(s.name, attributes);
|
|
3807
|
+
for (const m of s.members) {
|
|
3808
|
+
const t = this._getTypeInfo(m.type, m.attributes);
|
|
3809
|
+
info2.members.push(new MemberInfo(m.name, t, m.attributes));
|
|
3810
|
+
}
|
|
3811
|
+
this._types.set(type, info2);
|
|
3812
|
+
this._updateTypeInfo(info2);
|
|
3813
|
+
return info2;
|
|
3814
|
+
}
|
|
3815
|
+
if (type instanceof SamplerType) {
|
|
3816
|
+
const s = type;
|
|
3817
|
+
const formatIsType = s.format instanceof Type;
|
|
3818
|
+
const format = s.format ? formatIsType ? this._getTypeInfo(s.format, null) : new TypeInfo(s.format, null) : null;
|
|
3819
|
+
const info2 = new TemplateInfo(s.name, format, attributes, s.access);
|
|
3820
|
+
this._types.set(type, info2);
|
|
3821
|
+
this._updateTypeInfo(info2);
|
|
3822
|
+
return info2;
|
|
3823
|
+
}
|
|
3824
|
+
if (type instanceof TemplateType) {
|
|
3825
|
+
const t = type;
|
|
3826
|
+
const format = t.format ? this._getTypeInfo(t.format, null) : null;
|
|
3827
|
+
const info2 = new TemplateInfo(t.name, format, attributes, t.access);
|
|
3828
|
+
this._types.set(type, info2);
|
|
3829
|
+
this._updateTypeInfo(info2);
|
|
3830
|
+
return info2;
|
|
3831
|
+
}
|
|
3832
|
+
const info = new TypeInfo(type.name, attributes);
|
|
3833
|
+
this._types.set(type, info);
|
|
3834
|
+
this._updateTypeInfo(info);
|
|
3835
|
+
return info;
|
|
3836
|
+
}
|
|
3837
|
+
_updateTypeInfo(type) {
|
|
3838
|
+
var _a2, _b;
|
|
3839
|
+
const typeSize = this._getTypeSize(type);
|
|
3840
|
+
type.size = (_a2 = typeSize === null || typeSize === void 0 ? void 0 : typeSize.size) !== null && _a2 !== void 0 ? _a2 : 0;
|
|
3841
|
+
if (type instanceof ArrayInfo) {
|
|
3842
|
+
const formatInfo = this._getTypeSize(type["format"]);
|
|
3843
|
+
type.stride = (_b = formatInfo === null || formatInfo === void 0 ? void 0 : formatInfo.size) !== null && _b !== void 0 ? _b : 0;
|
|
3844
|
+
this._updateTypeInfo(type["format"]);
|
|
3845
|
+
}
|
|
3846
|
+
if (type instanceof StructInfo) {
|
|
3847
|
+
this._updateStructInfo(type);
|
|
3848
|
+
}
|
|
3849
|
+
}
|
|
3850
|
+
_updateStructInfo(struct) {
|
|
3851
|
+
var _a2;
|
|
3852
|
+
let offset = 0;
|
|
3853
|
+
let lastSize = 0;
|
|
3854
|
+
let lastOffset = 0;
|
|
3855
|
+
let structAlign = 0;
|
|
3856
|
+
for (let mi = 0, ml = struct.members.length; mi < ml; ++mi) {
|
|
3857
|
+
const member = struct.members[mi];
|
|
3858
|
+
const sizeInfo = this._getTypeSize(member);
|
|
3859
|
+
if (!sizeInfo)
|
|
3860
|
+
continue;
|
|
3861
|
+
(_a2 = this._getAlias(member.type.name)) !== null && _a2 !== void 0 ? _a2 : member.type;
|
|
3862
|
+
const align = sizeInfo.align;
|
|
3863
|
+
const size = sizeInfo.size;
|
|
3864
|
+
offset = this._roundUp(align, offset + lastSize);
|
|
3865
|
+
lastSize = size;
|
|
3866
|
+
lastOffset = offset;
|
|
3867
|
+
structAlign = Math.max(structAlign, align);
|
|
3868
|
+
member.offset = offset;
|
|
3869
|
+
member.size = size;
|
|
3870
|
+
this._updateTypeInfo(member.type);
|
|
3871
|
+
}
|
|
3872
|
+
struct.size = this._roundUp(structAlign, lastOffset + lastSize);
|
|
3873
|
+
struct.align = structAlign;
|
|
3874
|
+
}
|
|
3875
|
+
_getTypeSize(type) {
|
|
3876
|
+
var _a2;
|
|
3877
|
+
if (type === null || type === void 0)
|
|
3878
|
+
return null;
|
|
3879
|
+
const explicitSize = this._getAttributeNum(type.attributes, "size", 0);
|
|
3880
|
+
const explicitAlign = this._getAttributeNum(type.attributes, "align", 0);
|
|
3881
|
+
if (type instanceof MemberInfo)
|
|
3882
|
+
type = type.type;
|
|
3883
|
+
if (type instanceof TypeInfo) {
|
|
3884
|
+
const alias = this._getAlias(type.name);
|
|
3885
|
+
if (alias !== null) {
|
|
3886
|
+
type = alias;
|
|
3887
|
+
}
|
|
3888
|
+
}
|
|
3889
|
+
{
|
|
3890
|
+
const info = WgslReflect._typeInfo[type.name];
|
|
3891
|
+
if (info !== void 0) {
|
|
3892
|
+
const divisor = type["format"] === "f16" ? 2 : 1;
|
|
3893
|
+
return new _TypeSize(Math.max(explicitAlign, info.align / divisor), Math.max(explicitSize, info.size / divisor));
|
|
3894
|
+
}
|
|
3895
|
+
}
|
|
3896
|
+
{
|
|
3897
|
+
const info = WgslReflect._typeInfo[type.name.substring(0, type.name.length - 1)];
|
|
3898
|
+
if (info) {
|
|
3899
|
+
const divisor = type.name[type.name.length - 1] === "h" ? 2 : 1;
|
|
3900
|
+
return new _TypeSize(Math.max(explicitAlign, info.align / divisor), Math.max(explicitSize, info.size / divisor));
|
|
3901
|
+
}
|
|
3902
|
+
}
|
|
3903
|
+
if (type instanceof ArrayInfo) {
|
|
3904
|
+
let arrayType = type;
|
|
3905
|
+
let align = 8;
|
|
3906
|
+
let size = 8;
|
|
3907
|
+
const E = this._getTypeSize(arrayType.format);
|
|
3908
|
+
if (E !== null) {
|
|
3909
|
+
size = E.size;
|
|
3910
|
+
align = E.align;
|
|
3911
|
+
}
|
|
3912
|
+
const N = arrayType.count;
|
|
3913
|
+
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));
|
|
3914
|
+
size = N * stride;
|
|
3915
|
+
if (explicitSize)
|
|
3916
|
+
size = explicitSize;
|
|
3917
|
+
return new _TypeSize(Math.max(explicitAlign, align), Math.max(explicitSize, size));
|
|
3918
|
+
}
|
|
3919
|
+
if (type instanceof StructInfo) {
|
|
3920
|
+
let align = 0;
|
|
3921
|
+
let size = 0;
|
|
3922
|
+
let offset = 0;
|
|
3923
|
+
let lastSize = 0;
|
|
3924
|
+
let lastOffset = 0;
|
|
3925
|
+
for (const m of type.members) {
|
|
3926
|
+
const mi = this._getTypeSize(m.type);
|
|
3927
|
+
if (mi !== null) {
|
|
3928
|
+
align = Math.max(mi.align, align);
|
|
3929
|
+
offset = this._roundUp(mi.align, offset + lastSize);
|
|
3930
|
+
lastSize = mi.size;
|
|
3931
|
+
lastOffset = offset;
|
|
3932
|
+
}
|
|
3933
|
+
}
|
|
3934
|
+
size = this._roundUp(align, lastOffset + lastSize);
|
|
3935
|
+
return new _TypeSize(Math.max(explicitAlign, align), Math.max(explicitSize, size));
|
|
3936
|
+
}
|
|
3937
|
+
return null;
|
|
3938
|
+
}
|
|
3939
|
+
_isUniformVar(node) {
|
|
3940
|
+
return node instanceof Var && node.storage == "uniform";
|
|
3941
|
+
}
|
|
3942
|
+
_isStorageVar(node) {
|
|
3943
|
+
return node instanceof Var && node.storage == "storage";
|
|
3944
|
+
}
|
|
3945
|
+
_isTextureVar(node) {
|
|
3946
|
+
return node instanceof Var && node.type !== null && WgslReflect._textureTypes.indexOf(node.type.name) != -1;
|
|
3947
|
+
}
|
|
3948
|
+
_isSamplerVar(node) {
|
|
3949
|
+
return node instanceof Var && node.type !== null && WgslReflect._samplerTypes.indexOf(node.type.name) != -1;
|
|
3950
|
+
}
|
|
3951
|
+
_getAttribute(node, name) {
|
|
3952
|
+
const obj = node;
|
|
3953
|
+
if (!obj || !obj["attributes"])
|
|
3954
|
+
return null;
|
|
3955
|
+
const attrs = obj["attributes"];
|
|
3956
|
+
for (let a of attrs) {
|
|
3957
|
+
if (a.name == name)
|
|
3958
|
+
return a;
|
|
3959
|
+
}
|
|
3960
|
+
return null;
|
|
3961
|
+
}
|
|
3962
|
+
_getAttributeNum(attributes, name, defaultValue) {
|
|
3963
|
+
if (attributes === null)
|
|
3964
|
+
return defaultValue;
|
|
3965
|
+
for (let a of attributes) {
|
|
3966
|
+
if (a.name == name) {
|
|
3967
|
+
let v = a !== null && a.value !== null ? a.value : defaultValue;
|
|
3968
|
+
if (v instanceof Array) {
|
|
3969
|
+
v = v[0];
|
|
3970
|
+
}
|
|
3971
|
+
if (typeof v === "number") {
|
|
3972
|
+
return v;
|
|
3973
|
+
}
|
|
3974
|
+
if (typeof v === "string") {
|
|
3975
|
+
return parseInt(v);
|
|
3976
|
+
}
|
|
3977
|
+
return defaultValue;
|
|
3978
|
+
}
|
|
3979
|
+
}
|
|
3980
|
+
return defaultValue;
|
|
3981
|
+
}
|
|
3982
|
+
_roundUp(k, n) {
|
|
3983
|
+
return Math.ceil(n / k) * k;
|
|
3984
|
+
}
|
|
3985
|
+
};
|
|
3986
|
+
WgslReflect._typeInfo = {
|
|
3987
|
+
f16: {
|
|
3988
|
+
align: 2,
|
|
3989
|
+
size: 2
|
|
3990
|
+
},
|
|
3991
|
+
i32: {
|
|
3992
|
+
align: 4,
|
|
3993
|
+
size: 4
|
|
3994
|
+
},
|
|
3995
|
+
u32: {
|
|
3996
|
+
align: 4,
|
|
3997
|
+
size: 4
|
|
3998
|
+
},
|
|
3999
|
+
f32: {
|
|
4000
|
+
align: 4,
|
|
4001
|
+
size: 4
|
|
4002
|
+
},
|
|
4003
|
+
atomic: {
|
|
4004
|
+
align: 4,
|
|
4005
|
+
size: 4
|
|
4006
|
+
},
|
|
4007
|
+
vec2: {
|
|
4008
|
+
align: 8,
|
|
4009
|
+
size: 8
|
|
4010
|
+
},
|
|
4011
|
+
vec3: {
|
|
4012
|
+
align: 16,
|
|
4013
|
+
size: 12
|
|
4014
|
+
},
|
|
4015
|
+
vec4: {
|
|
4016
|
+
align: 16,
|
|
4017
|
+
size: 16
|
|
4018
|
+
},
|
|
4019
|
+
mat2x2: {
|
|
4020
|
+
align: 8,
|
|
4021
|
+
size: 16
|
|
4022
|
+
},
|
|
4023
|
+
mat3x2: {
|
|
4024
|
+
align: 8,
|
|
4025
|
+
size: 24
|
|
4026
|
+
},
|
|
4027
|
+
mat4x2: {
|
|
4028
|
+
align: 8,
|
|
4029
|
+
size: 32
|
|
4030
|
+
},
|
|
4031
|
+
mat2x3: {
|
|
4032
|
+
align: 16,
|
|
4033
|
+
size: 32
|
|
4034
|
+
},
|
|
4035
|
+
mat3x3: {
|
|
4036
|
+
align: 16,
|
|
4037
|
+
size: 48
|
|
4038
|
+
},
|
|
4039
|
+
mat4x3: {
|
|
4040
|
+
align: 16,
|
|
4041
|
+
size: 64
|
|
4042
|
+
},
|
|
4043
|
+
mat2x4: {
|
|
4044
|
+
align: 16,
|
|
4045
|
+
size: 32
|
|
4046
|
+
},
|
|
4047
|
+
mat3x4: {
|
|
4048
|
+
align: 16,
|
|
4049
|
+
size: 48
|
|
4050
|
+
},
|
|
4051
|
+
mat4x4: {
|
|
4052
|
+
align: 16,
|
|
4053
|
+
size: 64
|
|
4054
|
+
}
|
|
4055
|
+
};
|
|
4056
|
+
WgslReflect._textureTypes = TokenTypes.any_texture_type.map((t) => {
|
|
4057
|
+
return t.name;
|
|
4058
|
+
});
|
|
4059
|
+
WgslReflect._samplerTypes = TokenTypes.sampler_type.map((t) => {
|
|
4060
|
+
return t.name;
|
|
4061
|
+
});
|
|
4062
|
+
|
|
4063
|
+
// ../../node_modules/@luma.gl/shadertools/dist/lib/wgsl/get-shader-layout-wgsl.js
|
|
4064
|
+
function getShaderLayoutFromWGSL(source) {
|
|
4065
|
+
const shaderLayout = {
|
|
4066
|
+
attributes: [],
|
|
4067
|
+
bindings: []
|
|
4068
|
+
};
|
|
4069
|
+
const parsedWGSL = parseWGSL(source);
|
|
4070
|
+
for (const uniform of parsedWGSL.uniforms) {
|
|
4071
|
+
const members = [];
|
|
4072
|
+
for (const member of uniform.type.members) {
|
|
4073
|
+
members.push({
|
|
4074
|
+
name: member.name,
|
|
4075
|
+
type: getType(member.type)
|
|
4076
|
+
});
|
|
4077
|
+
}
|
|
4078
|
+
shaderLayout.bindings.push({
|
|
4079
|
+
type: "uniform",
|
|
4080
|
+
name: uniform.name,
|
|
4081
|
+
location: uniform.binding,
|
|
4082
|
+
group: uniform.group,
|
|
4083
|
+
members
|
|
4084
|
+
});
|
|
4085
|
+
}
|
|
4086
|
+
const vertex = parsedWGSL.entry.vertex[0];
|
|
4087
|
+
const attributeCount = vertex.inputs.length;
|
|
4088
|
+
for (let i = 0; i < attributeCount; i++) {
|
|
4089
|
+
const wgslAttribute = vertex.inputs[i];
|
|
4090
|
+
if (wgslAttribute.locationType === "location") {
|
|
4091
|
+
const type = getType(wgslAttribute.type);
|
|
4092
|
+
shaderLayout.attributes.push({
|
|
4093
|
+
name: wgslAttribute.name,
|
|
4094
|
+
location: wgslAttribute.location,
|
|
4095
|
+
type
|
|
4096
|
+
});
|
|
4097
|
+
}
|
|
4098
|
+
}
|
|
4099
|
+
return shaderLayout;
|
|
4100
|
+
}
|
|
4101
|
+
function getType(type) {
|
|
4102
|
+
return type.format ? `${type.name}<${type.format.name}>` : type.name;
|
|
4103
|
+
}
|
|
4104
|
+
function parseWGSL(source) {
|
|
4105
|
+
try {
|
|
4106
|
+
return new WgslReflect(source);
|
|
4107
|
+
} catch (error2) {
|
|
4108
|
+
if (error2 instanceof Error) {
|
|
4109
|
+
throw error2;
|
|
4110
|
+
}
|
|
4111
|
+
let message2 = "WGSL parse error";
|
|
4112
|
+
if (typeof error2 === "object" && error2 !== null && error2 !== void 0 && error2.message) {
|
|
4113
|
+
message2 += `: ${error2.message} `;
|
|
4114
|
+
}
|
|
4115
|
+
if (typeof error2 === "object" && error2 !== null && error2 !== void 0 && error2.token) {
|
|
4116
|
+
message2 += error2.token.line || "";
|
|
4117
|
+
}
|
|
4118
|
+
throw new Error(message2, {
|
|
4119
|
+
cause: error2
|
|
4120
|
+
});
|
|
4121
|
+
}
|
|
4122
|
+
}
|
|
4123
|
+
|
|
1351
4124
|
// ../../node_modules/@luma.gl/engine/dist/shader-inputs.js
|
|
1352
4125
|
var import_core2 = __toESM(require_core2(), 1);
|
|
1353
4126
|
var ShaderInputs = class {
|
|
@@ -1621,10 +4394,17 @@ ${getApplicationDefines(allDefines)}
|
|
|
1621
4394
|
};
|
|
1622
4395
|
|
|
1623
4396
|
// ../../node_modules/@luma.gl/engine/dist/debug/debug-shader-layout.js
|
|
1624
|
-
function getDebugTableForShaderLayout(layout) {
|
|
1625
|
-
|
|
4397
|
+
function getDebugTableForShaderLayout(layout, name) {
|
|
4398
|
+
var _layout$varyings;
|
|
1626
4399
|
const table = {};
|
|
1627
|
-
const header =
|
|
4400
|
+
const header = "Values";
|
|
4401
|
+
if (layout.attributes.length === 0 && !((_layout$varyings = layout.varyings) !== null && _layout$varyings !== void 0 && _layout$varyings.length)) {
|
|
4402
|
+
return {
|
|
4403
|
+
"No attributes or varyings": {
|
|
4404
|
+
[header]: "N/A"
|
|
4405
|
+
}
|
|
4406
|
+
};
|
|
4407
|
+
}
|
|
1628
4408
|
for (const attributeDeclaration of layout.attributes) {
|
|
1629
4409
|
if (attributeDeclaration) {
|
|
1630
4410
|
const glslDeclaration = `${attributeDeclaration.location} ${attributeDeclaration.name}: ${attributeDeclaration.type}`;
|
|
@@ -1642,6 +4422,49 @@ ${getApplicationDefines(allDefines)}
|
|
|
1642
4422
|
return table;
|
|
1643
4423
|
}
|
|
1644
4424
|
|
|
4425
|
+
// ../../node_modules/@luma.gl/engine/dist/debug/debug-framebuffer.js
|
|
4426
|
+
var canvas = null;
|
|
4427
|
+
var ctx = null;
|
|
4428
|
+
function debugFramebuffer(fbo, _ref) {
|
|
4429
|
+
let {
|
|
4430
|
+
id,
|
|
4431
|
+
minimap,
|
|
4432
|
+
opaque,
|
|
4433
|
+
top = "0",
|
|
4434
|
+
left = "0",
|
|
4435
|
+
rgbaScale = 1
|
|
4436
|
+
} = _ref;
|
|
4437
|
+
if (!canvas) {
|
|
4438
|
+
canvas = document.createElement("canvas");
|
|
4439
|
+
canvas.id = id;
|
|
4440
|
+
canvas.title = id;
|
|
4441
|
+
canvas.style.zIndex = "100";
|
|
4442
|
+
canvas.style.position = "absolute";
|
|
4443
|
+
canvas.style.top = top;
|
|
4444
|
+
canvas.style.left = left;
|
|
4445
|
+
canvas.style.border = "blue 1px solid";
|
|
4446
|
+
canvas.style.transform = "scaleY(-1)";
|
|
4447
|
+
document.body.appendChild(canvas);
|
|
4448
|
+
ctx = canvas.getContext("2d");
|
|
4449
|
+
}
|
|
4450
|
+
if (canvas.width !== fbo.width || canvas.height !== fbo.height) {
|
|
4451
|
+
canvas.width = fbo.width / 2;
|
|
4452
|
+
canvas.height = fbo.height / 2;
|
|
4453
|
+
canvas.style.width = "400px";
|
|
4454
|
+
canvas.style.height = "400px";
|
|
4455
|
+
}
|
|
4456
|
+
const color = fbo.device.readPixelsToArrayWebGL(fbo);
|
|
4457
|
+
const imageData = ctx.createImageData(fbo.width, fbo.height);
|
|
4458
|
+
const offset = 0;
|
|
4459
|
+
for (let i = 0; i < color.length; i += 4) {
|
|
4460
|
+
imageData.data[offset + i + 0] = color[i + 0] * rgbaScale;
|
|
4461
|
+
imageData.data[offset + i + 1] = color[i + 1] * rgbaScale;
|
|
4462
|
+
imageData.data[offset + i + 2] = color[i + 2] * rgbaScale;
|
|
4463
|
+
imageData.data[offset + i + 3] = opaque ? 255 : color[i + 3] * rgbaScale;
|
|
4464
|
+
}
|
|
4465
|
+
ctx.putImageData(imageData, 0, 0);
|
|
4466
|
+
}
|
|
4467
|
+
|
|
1645
4468
|
// ../../node_modules/@luma.gl/engine/dist/model/model.js
|
|
1646
4469
|
var LOG_DRAW_PRIORITY = 2;
|
|
1647
4470
|
var LOG_DRAW_TIMEOUT = 1e4;
|
|
@@ -1676,6 +4499,7 @@ ${getApplicationDefines(allDefines)}
|
|
|
1676
4499
|
this.props = void 0;
|
|
1677
4500
|
this._lastLogTime = 0;
|
|
1678
4501
|
this._logOpen = false;
|
|
4502
|
+
this._drawCount = 0;
|
|
1679
4503
|
this.props = {
|
|
1680
4504
|
...Model.defaultProps,
|
|
1681
4505
|
...props
|
|
@@ -1686,6 +4510,19 @@ ${getApplicationDefines(allDefines)}
|
|
|
1686
4510
|
Object.assign(this.userData, props.userData);
|
|
1687
4511
|
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])) || []);
|
|
1688
4512
|
this.setShaderInputs(props.shaderInputs || new ShaderInputs(moduleMap));
|
|
4513
|
+
const isWebGPU = this.device.info.type === "webgpu";
|
|
4514
|
+
if (this.props.source) {
|
|
4515
|
+
if (isWebGPU) {
|
|
4516
|
+
var _this$props;
|
|
4517
|
+
(_this$props = this.props).shaderLayout || (_this$props.shaderLayout = getShaderLayoutFromWGSL(this.props.source));
|
|
4518
|
+
}
|
|
4519
|
+
this.props.fs = this.props.source;
|
|
4520
|
+
this.props.vs = this.props.source;
|
|
4521
|
+
}
|
|
4522
|
+
if (isWebGPU && typeof this.props.vs !== "string") {
|
|
4523
|
+
var _this$props2;
|
|
4524
|
+
(_this$props2 = this.props).shaderLayout || (_this$props2.shaderLayout = getShaderLayoutFromWGSL(this.props.vs.wgsl));
|
|
4525
|
+
}
|
|
1689
4526
|
const platformInfo = getPlatformInfo(device);
|
|
1690
4527
|
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()) || [];
|
|
1691
4528
|
const {
|
|
@@ -1773,6 +4610,7 @@ ${getApplicationDefines(allDefines)}
|
|
|
1773
4610
|
} finally {
|
|
1774
4611
|
this._logDrawCallEnd();
|
|
1775
4612
|
}
|
|
4613
|
+
this._logFramebuffer(renderPass);
|
|
1776
4614
|
}
|
|
1777
4615
|
setGeometry(geometry) {
|
|
1778
4616
|
const gpuGeometry = geometry && makeGPUGeometry(this.device, geometry);
|
|
@@ -1784,9 +4622,18 @@ ${getApplicationDefines(allDefines)}
|
|
|
1784
4622
|
return gpuGeometry;
|
|
1785
4623
|
}
|
|
1786
4624
|
_setGeometryAttributes(gpuGeometry) {
|
|
4625
|
+
const attributes = {
|
|
4626
|
+
...gpuGeometry.attributes
|
|
4627
|
+
};
|
|
4628
|
+
for (const [attributeName] of Object.entries(attributes)) {
|
|
4629
|
+
if (!this.pipeline.shaderLayout.attributes.find((layout) => layout.name === attributeName) && attributeName !== "positions") {
|
|
4630
|
+
delete attributes[attributeName];
|
|
4631
|
+
}
|
|
4632
|
+
}
|
|
1787
4633
|
this.vertexCount = gpuGeometry.vertexCount;
|
|
1788
|
-
this.setAttributes(gpuGeometry.attributes, "ignore-unknown");
|
|
1789
4634
|
this.setIndexBuffer(gpuGeometry.indices);
|
|
4635
|
+
this.setAttributes(gpuGeometry.attributes, "ignore-unknown");
|
|
4636
|
+
this.setAttributes(attributes);
|
|
1790
4637
|
}
|
|
1791
4638
|
setTopology(topology) {
|
|
1792
4639
|
if (topology !== this.topology) {
|
|
@@ -1825,6 +4672,18 @@ ${getApplicationDefines(allDefines)}
|
|
|
1825
4672
|
this.bindings[`${moduleName}Uniforms`] = uniformBuffer;
|
|
1826
4673
|
}
|
|
1827
4674
|
}
|
|
4675
|
+
setShaderModuleProps(props) {
|
|
4676
|
+
const uniforms = this._getModuleUniforms(props);
|
|
4677
|
+
const keys = Object.keys(uniforms).filter((k) => {
|
|
4678
|
+
const uniform = uniforms[k];
|
|
4679
|
+
return !(0, import_core6.isNumberArray)(uniform) && typeof uniform !== "number" && typeof uniform !== "boolean";
|
|
4680
|
+
});
|
|
4681
|
+
const bindings = {};
|
|
4682
|
+
for (const k of keys) {
|
|
4683
|
+
bindings[k] = uniforms[k];
|
|
4684
|
+
delete uniforms[k];
|
|
4685
|
+
}
|
|
4686
|
+
}
|
|
1828
4687
|
updateShaderInputs() {
|
|
1829
4688
|
this._uniformStore.setUniforms(this.shaderInputs.getUniformValues());
|
|
1830
4689
|
}
|
|
@@ -1893,21 +4752,23 @@ ${getApplicationDefines(allDefines)}
|
|
|
1893
4752
|
import_core6.log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
|
|
1894
4753
|
}
|
|
1895
4754
|
this._pipelineNeedsUpdate = false;
|
|
4755
|
+
const vs = this.device.createShader({
|
|
4756
|
+
id: `${this.id}-vertex`,
|
|
4757
|
+
stage: "vertex",
|
|
4758
|
+
source: this.vs
|
|
4759
|
+
});
|
|
4760
|
+
const fs = this.fs ? this.device.createShader({
|
|
4761
|
+
id: `${this.id}-fragment`,
|
|
4762
|
+
stage: "fragment",
|
|
4763
|
+
source: this.fs
|
|
4764
|
+
}) : null;
|
|
1896
4765
|
this.pipeline = this.device.createRenderPipeline({
|
|
1897
4766
|
...this.props,
|
|
1898
4767
|
bufferLayout: this.bufferLayout,
|
|
1899
4768
|
topology: this.topology,
|
|
1900
4769
|
parameters: this.parameters,
|
|
1901
|
-
vs
|
|
1902
|
-
|
|
1903
|
-
stage: "vertex",
|
|
1904
|
-
source: this.vs
|
|
1905
|
-
}),
|
|
1906
|
-
fs: this.fs ? this.device.createShader({
|
|
1907
|
-
id: "{$this.id}-fragment",
|
|
1908
|
-
stage: "fragment",
|
|
1909
|
-
source: this.fs
|
|
1910
|
-
}) : null
|
|
4770
|
+
vs,
|
|
4771
|
+
fs
|
|
1911
4772
|
});
|
|
1912
4773
|
this._attributeInfos = (0, import_core7.getAttributeInfosFromLayouts)(this.pipeline.shaderLayout, this.bufferLayout);
|
|
1913
4774
|
}
|
|
@@ -1915,8 +4776,8 @@ ${getApplicationDefines(allDefines)}
|
|
|
1915
4776
|
}
|
|
1916
4777
|
_logDrawCallStart() {
|
|
1917
4778
|
const logDrawTimeout = import_core6.log.level > 3 ? 0 : LOG_DRAW_TIMEOUT;
|
|
1918
|
-
if (Date.now() - this._lastLogTime < logDrawTimeout) {
|
|
1919
|
-
return
|
|
4779
|
+
if (import_core6.log.level < 2 || Date.now() - this._lastLogTime < logDrawTimeout) {
|
|
4780
|
+
return;
|
|
1920
4781
|
}
|
|
1921
4782
|
this._lastLogTime = Date.now();
|
|
1922
4783
|
this._logOpen = true;
|
|
@@ -1926,7 +4787,7 @@ ${getApplicationDefines(allDefines)}
|
|
|
1926
4787
|
}
|
|
1927
4788
|
_logDrawCallEnd() {
|
|
1928
4789
|
if (this._logOpen) {
|
|
1929
|
-
const shaderLayoutTable = getDebugTableForShaderLayout(this.pipeline.shaderLayout);
|
|
4790
|
+
const shaderLayoutTable = getDebugTableForShaderLayout(this.pipeline.shaderLayout, this.id);
|
|
1930
4791
|
import_core6.log.table(LOG_DRAW_PRIORITY, shaderLayoutTable)();
|
|
1931
4792
|
const uniformTable = this.shaderInputs.getDebugTable();
|
|
1932
4793
|
for (const [name, value] of Object.entries(this.uniforms)) {
|
|
@@ -1942,6 +4803,20 @@ ${getApplicationDefines(allDefines)}
|
|
|
1942
4803
|
this._logOpen = false;
|
|
1943
4804
|
}
|
|
1944
4805
|
}
|
|
4806
|
+
_logFramebuffer(renderPass) {
|
|
4807
|
+
const debugFramebuffers = import_core6.log.get("framebuffer");
|
|
4808
|
+
this._drawCount++;
|
|
4809
|
+
if (!debugFramebuffers || this._drawCount++ > 3 && this._drawCount % 60) {
|
|
4810
|
+
return;
|
|
4811
|
+
}
|
|
4812
|
+
const framebuffer = renderPass.props.framebuffer;
|
|
4813
|
+
if (framebuffer) {
|
|
4814
|
+
debugFramebuffer(framebuffer, {
|
|
4815
|
+
id: framebuffer.id,
|
|
4816
|
+
minimap: true
|
|
4817
|
+
});
|
|
4818
|
+
}
|
|
4819
|
+
}
|
|
1945
4820
|
_getAttributeDebugTable() {
|
|
1946
4821
|
const table = {};
|
|
1947
4822
|
for (const [name, attributeInfo] of Object.entries(this._attributeInfos)) {
|
|
@@ -1972,6 +4847,7 @@ ${getApplicationDefines(allDefines)}
|
|
|
1972
4847
|
};
|
|
1973
4848
|
Model.defaultProps = {
|
|
1974
4849
|
...import_core5.RenderPipeline.defaultProps,
|
|
4850
|
+
source: null,
|
|
1975
4851
|
vs: null,
|
|
1976
4852
|
fs: null,
|
|
1977
4853
|
id: "unnamed",
|
|
@@ -2721,7 +5597,7 @@ ${getApplicationDefines(allDefines)}
|
|
|
2721
5597
|
}
|
|
2722
5598
|
|
|
2723
5599
|
// ../../node_modules/@luma.gl/webgl/dist/adapter/webgl-device.js
|
|
2724
|
-
var
|
|
5600
|
+
var import_core35 = __toESM(require_core2(), 1);
|
|
2725
5601
|
|
|
2726
5602
|
// ../../node_modules/@probe.gl/env/dist/lib/is-electron.js
|
|
2727
5603
|
function isElectron(mockUserAgent) {
|
|
@@ -4058,14 +6934,14 @@ ${getApplicationDefines(allDefines)}
|
|
|
4058
6934
|
onContextLost: () => console.error("WebGL context lost"),
|
|
4059
6935
|
onContextRestored: () => console.info("WebGL context restored")
|
|
4060
6936
|
};
|
|
4061
|
-
function createBrowserContext(
|
|
6937
|
+
function createBrowserContext(canvas2, props) {
|
|
4062
6938
|
props = {
|
|
4063
6939
|
...DEFAULT_CONTEXT_PROPS,
|
|
4064
6940
|
...props
|
|
4065
6941
|
};
|
|
4066
6942
|
let errorMessage = null;
|
|
4067
6943
|
const onCreateError = (error2) => errorMessage = error2.statusMessage || errorMessage;
|
|
4068
|
-
|
|
6944
|
+
canvas2.addEventListener("webglcontextcreationerror", onCreateError, false);
|
|
4069
6945
|
let gl = null;
|
|
4070
6946
|
if (props.type === "webgl2") {
|
|
4071
6947
|
props = {
|
|
@@ -4080,12 +6956,12 @@ ${getApplicationDefines(allDefines)}
|
|
|
4080
6956
|
};
|
|
4081
6957
|
}
|
|
4082
6958
|
if (!gl && props.webgl2) {
|
|
4083
|
-
gl =
|
|
6959
|
+
gl = canvas2.getContext("webgl2", props);
|
|
4084
6960
|
}
|
|
4085
6961
|
if (!gl && props.webgl1) {
|
|
4086
|
-
gl =
|
|
6962
|
+
gl = canvas2.getContext("webgl", props);
|
|
4087
6963
|
}
|
|
4088
|
-
|
|
6964
|
+
canvas2.removeEventListener("webglcontextcreationerror", onCreateError, false);
|
|
4089
6965
|
if (!gl) {
|
|
4090
6966
|
throw new Error(`Failed to create ${props.webgl2 && !props.webgl1 ? "WebGL2" : "WebGL"} context: ${errorMessage || "Unknown error"}`);
|
|
4091
6967
|
}
|
|
@@ -4093,13 +6969,13 @@ ${getApplicationDefines(allDefines)}
|
|
|
4093
6969
|
const {
|
|
4094
6970
|
onContextLost
|
|
4095
6971
|
} = props;
|
|
4096
|
-
|
|
6972
|
+
canvas2.addEventListener("webglcontextlost", (event) => onContextLost(event), false);
|
|
4097
6973
|
}
|
|
4098
6974
|
if (props.onContextRestored) {
|
|
4099
6975
|
const {
|
|
4100
6976
|
onContextRestored
|
|
4101
6977
|
} = props;
|
|
4102
|
-
|
|
6978
|
+
canvas2.addEventListener("webglcontextrestored", (event) => onContextRestored(event), false);
|
|
4103
6979
|
}
|
|
4104
6980
|
return gl;
|
|
4105
6981
|
}
|
|
@@ -6876,9 +9752,12 @@ void main(void) {}`;
|
|
|
6876
9752
|
const sizeChanged = size[0] !== this.presentationSize[0] || size[1] !== this.presentationSize[1];
|
|
6877
9753
|
if (sizeChanged) {
|
|
6878
9754
|
this.presentationSize = size;
|
|
9755
|
+
this.resize();
|
|
6879
9756
|
}
|
|
6880
9757
|
}
|
|
6881
9758
|
resize(options) {
|
|
9759
|
+
if (!this.device.gl)
|
|
9760
|
+
return;
|
|
6882
9761
|
if (this.canvas) {
|
|
6883
9762
|
const devicePixelRatio = this.getDevicePixelRatio(options === null || options === void 0 ? void 0 : options.useDevicePixels);
|
|
6884
9763
|
this.setDevicePixelRatio(devicePixelRatio, options);
|
|
@@ -7268,6 +10147,30 @@ ${source2}`;
|
|
|
7268
10147
|
var import_core26 = __toESM(require_core2(), 1);
|
|
7269
10148
|
|
|
7270
10149
|
// ../../node_modules/@luma.gl/webgl/dist/classic/typed-array-utils.js
|
|
10150
|
+
var ERR_TYPE_DEDUCTION = "Failed to deduce GL constant from typed array";
|
|
10151
|
+
function getGLTypeFromTypedArray(arrayOrType) {
|
|
10152
|
+
const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
|
|
10153
|
+
switch (type) {
|
|
10154
|
+
case Float32Array:
|
|
10155
|
+
return 5126;
|
|
10156
|
+
case Uint16Array:
|
|
10157
|
+
return 5123;
|
|
10158
|
+
case Uint32Array:
|
|
10159
|
+
return 5125;
|
|
10160
|
+
case Uint8Array:
|
|
10161
|
+
return 5121;
|
|
10162
|
+
case Uint8ClampedArray:
|
|
10163
|
+
return 5121;
|
|
10164
|
+
case Int8Array:
|
|
10165
|
+
return 5120;
|
|
10166
|
+
case Int16Array:
|
|
10167
|
+
return 5122;
|
|
10168
|
+
case Int32Array:
|
|
10169
|
+
return 5124;
|
|
10170
|
+
default:
|
|
10171
|
+
throw new Error(ERR_TYPE_DEDUCTION);
|
|
10172
|
+
}
|
|
10173
|
+
}
|
|
7271
10174
|
function getTypedArrayFromGLType(glType, options) {
|
|
7272
10175
|
const {
|
|
7273
10176
|
clamped = true
|
|
@@ -7313,13 +10216,13 @@ ${source2}`;
|
|
|
7313
10216
|
};
|
|
7314
10217
|
var Accessor = class {
|
|
7315
10218
|
static getBytesPerElement(accessor) {
|
|
7316
|
-
const
|
|
7317
|
-
return
|
|
10219
|
+
const ArrayType2 = getTypedArrayFromGLType(accessor.type || 5126);
|
|
10220
|
+
return ArrayType2.BYTES_PER_ELEMENT;
|
|
7318
10221
|
}
|
|
7319
10222
|
static getBytesPerVertex(accessor) {
|
|
7320
10223
|
(0, import_core26.assert)(accessor.size);
|
|
7321
|
-
const
|
|
7322
|
-
return
|
|
10224
|
+
const ArrayType2 = getTypedArrayFromGLType(accessor.type || 5126);
|
|
10225
|
+
return ArrayType2.BYTES_PER_ELEMENT * accessor.size;
|
|
7323
10226
|
}
|
|
7324
10227
|
static resolve() {
|
|
7325
10228
|
for (var _len = arguments.length, accessors = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -7888,6 +10791,13 @@ ${source2}`;
|
|
|
7888
10791
|
this._compileAndLink();
|
|
7889
10792
|
this.introspectedLayout = getShaderLayout(this.device.gl, this.handle);
|
|
7890
10793
|
this.shaderLayout = (0, import_core28.mergeShaderLayout)(this.introspectedLayout, props.shaderLayout);
|
|
10794
|
+
switch (this.props.topology) {
|
|
10795
|
+
case "triangle-fan-webgl":
|
|
10796
|
+
case "line-loop-webgl":
|
|
10797
|
+
import_core27.log.warn(`Primitive topology ${this.props.topology} is deprecated and will be removed in v9.1`);
|
|
10798
|
+
break;
|
|
10799
|
+
default:
|
|
10800
|
+
}
|
|
7891
10801
|
}
|
|
7892
10802
|
destroy() {
|
|
7893
10803
|
if (this.handle) {
|
|
@@ -8621,9 +11531,174 @@ ${source2}`;
|
|
|
8621
11531
|
return /^\d+$/.test(value);
|
|
8622
11532
|
}
|
|
8623
11533
|
|
|
11534
|
+
// ../../node_modules/@luma.gl/webgl/dist/classic/copy-and-blit.js
|
|
11535
|
+
var import_core34 = __toESM(require_core2(), 1);
|
|
11536
|
+
|
|
11537
|
+
// ../../node_modules/@luma.gl/webgl/dist/classic/format-utils.js
|
|
11538
|
+
var import_core33 = __toESM(require_core2(), 1);
|
|
11539
|
+
function glFormatToComponents(format) {
|
|
11540
|
+
switch (format) {
|
|
11541
|
+
case 6406:
|
|
11542
|
+
case 33326:
|
|
11543
|
+
case 6403:
|
|
11544
|
+
return 1;
|
|
11545
|
+
case 33328:
|
|
11546
|
+
case 33319:
|
|
11547
|
+
return 2;
|
|
11548
|
+
case 6407:
|
|
11549
|
+
case 34837:
|
|
11550
|
+
return 3;
|
|
11551
|
+
case 6408:
|
|
11552
|
+
case 34836:
|
|
11553
|
+
return 4;
|
|
11554
|
+
default:
|
|
11555
|
+
(0, import_core33.assert)(false);
|
|
11556
|
+
return 0;
|
|
11557
|
+
}
|
|
11558
|
+
}
|
|
11559
|
+
function glTypeToBytes(type) {
|
|
11560
|
+
switch (type) {
|
|
11561
|
+
case 5121:
|
|
11562
|
+
return 1;
|
|
11563
|
+
case 33635:
|
|
11564
|
+
case 32819:
|
|
11565
|
+
case 32820:
|
|
11566
|
+
return 2;
|
|
11567
|
+
case 5126:
|
|
11568
|
+
return 4;
|
|
11569
|
+
default:
|
|
11570
|
+
(0, import_core33.assert)(false);
|
|
11571
|
+
return 0;
|
|
11572
|
+
}
|
|
11573
|
+
}
|
|
11574
|
+
|
|
11575
|
+
// ../../node_modules/@luma.gl/webgl/dist/classic/copy-and-blit.js
|
|
11576
|
+
function readPixelsToArray(source, options) {
|
|
11577
|
+
var _framebuffer$colorAtt;
|
|
11578
|
+
const {
|
|
11579
|
+
sourceX = 0,
|
|
11580
|
+
sourceY = 0,
|
|
11581
|
+
sourceFormat = 6408,
|
|
11582
|
+
sourceAttachment = 36064
|
|
11583
|
+
} = options || {};
|
|
11584
|
+
let {
|
|
11585
|
+
target = null,
|
|
11586
|
+
sourceWidth,
|
|
11587
|
+
sourceHeight,
|
|
11588
|
+
sourceType
|
|
11589
|
+
} = options || {};
|
|
11590
|
+
const {
|
|
11591
|
+
framebuffer,
|
|
11592
|
+
deleteFramebuffer
|
|
11593
|
+
} = getFramebuffer2(source);
|
|
11594
|
+
(0, import_core34.assert)(framebuffer);
|
|
11595
|
+
const {
|
|
11596
|
+
gl,
|
|
11597
|
+
handle
|
|
11598
|
+
} = framebuffer;
|
|
11599
|
+
sourceWidth = sourceWidth || framebuffer.width;
|
|
11600
|
+
sourceHeight = sourceHeight || framebuffer.height;
|
|
11601
|
+
const attachment = sourceAttachment - 36064;
|
|
11602
|
+
sourceType = sourceType || ((_framebuffer$colorAtt = framebuffer.colorAttachments[attachment]) === null || _framebuffer$colorAtt === void 0 ? void 0 : _framebuffer$colorAtt.type) || 5121;
|
|
11603
|
+
target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
|
|
11604
|
+
sourceType = sourceType || getGLTypeFromTypedArray(target);
|
|
11605
|
+
const prevHandle = gl.bindFramebuffer(36160, handle);
|
|
11606
|
+
gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
|
|
11607
|
+
gl.bindFramebuffer(36160, prevHandle || null);
|
|
11608
|
+
if (deleteFramebuffer) {
|
|
11609
|
+
framebuffer.destroy();
|
|
11610
|
+
}
|
|
11611
|
+
return target;
|
|
11612
|
+
}
|
|
11613
|
+
function readPixelsToBuffer(source, options) {
|
|
11614
|
+
const {
|
|
11615
|
+
target,
|
|
11616
|
+
sourceX = 0,
|
|
11617
|
+
sourceY = 0,
|
|
11618
|
+
sourceFormat = 6408,
|
|
11619
|
+
targetByteOffset = 0
|
|
11620
|
+
} = options || {};
|
|
11621
|
+
let {
|
|
11622
|
+
sourceWidth,
|
|
11623
|
+
sourceHeight,
|
|
11624
|
+
sourceType
|
|
11625
|
+
} = options || {};
|
|
11626
|
+
const {
|
|
11627
|
+
framebuffer,
|
|
11628
|
+
deleteFramebuffer
|
|
11629
|
+
} = getFramebuffer2(source);
|
|
11630
|
+
(0, import_core34.assert)(framebuffer);
|
|
11631
|
+
sourceWidth = sourceWidth || framebuffer.width;
|
|
11632
|
+
sourceHeight = sourceHeight || framebuffer.height;
|
|
11633
|
+
const webglFramebuffer = framebuffer;
|
|
11634
|
+
sourceType = sourceType || 5121;
|
|
11635
|
+
let webglBufferTarget = target;
|
|
11636
|
+
if (!webglBufferTarget) {
|
|
11637
|
+
const components = glFormatToComponents(sourceFormat);
|
|
11638
|
+
const byteCount = glTypeToBytes(sourceType);
|
|
11639
|
+
const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
|
|
11640
|
+
webglBufferTarget = webglFramebuffer.device.createBuffer({
|
|
11641
|
+
byteLength
|
|
11642
|
+
});
|
|
11643
|
+
}
|
|
11644
|
+
const commandEncoder = source.device.createCommandEncoder();
|
|
11645
|
+
commandEncoder.copyTextureToBuffer({
|
|
11646
|
+
source,
|
|
11647
|
+
width: sourceWidth,
|
|
11648
|
+
height: sourceHeight,
|
|
11649
|
+
origin: [sourceX, sourceY],
|
|
11650
|
+
destination: webglBufferTarget,
|
|
11651
|
+
byteOffset: targetByteOffset
|
|
11652
|
+
});
|
|
11653
|
+
commandEncoder.destroy();
|
|
11654
|
+
if (deleteFramebuffer) {
|
|
11655
|
+
framebuffer.destroy();
|
|
11656
|
+
}
|
|
11657
|
+
return webglBufferTarget;
|
|
11658
|
+
}
|
|
11659
|
+
function getFramebuffer2(source) {
|
|
11660
|
+
if (!(source instanceof import_core34.Framebuffer)) {
|
|
11661
|
+
return {
|
|
11662
|
+
framebuffer: toFramebuffer(source),
|
|
11663
|
+
deleteFramebuffer: true
|
|
11664
|
+
};
|
|
11665
|
+
}
|
|
11666
|
+
return {
|
|
11667
|
+
framebuffer: source,
|
|
11668
|
+
deleteFramebuffer: false
|
|
11669
|
+
};
|
|
11670
|
+
}
|
|
11671
|
+
function toFramebuffer(texture, props) {
|
|
11672
|
+
const {
|
|
11673
|
+
device,
|
|
11674
|
+
width,
|
|
11675
|
+
height,
|
|
11676
|
+
id
|
|
11677
|
+
} = texture;
|
|
11678
|
+
const framebuffer = device.createFramebuffer({
|
|
11679
|
+
...props,
|
|
11680
|
+
id: `framebuffer-for-${id}`,
|
|
11681
|
+
width,
|
|
11682
|
+
height,
|
|
11683
|
+
colorAttachments: [texture]
|
|
11684
|
+
});
|
|
11685
|
+
return framebuffer;
|
|
11686
|
+
}
|
|
11687
|
+
function getPixelArray(pixelArray, type, format, width, height) {
|
|
11688
|
+
if (pixelArray) {
|
|
11689
|
+
return pixelArray;
|
|
11690
|
+
}
|
|
11691
|
+
type = type || 5121;
|
|
11692
|
+
const ArrayType2 = getTypedArrayFromGLType(type, {
|
|
11693
|
+
clamped: false
|
|
11694
|
+
});
|
|
11695
|
+
const components = glFormatToComponents(format);
|
|
11696
|
+
return new ArrayType2(width * height * components);
|
|
11697
|
+
}
|
|
11698
|
+
|
|
8624
11699
|
// ../../node_modules/@luma.gl/webgl/dist/adapter/webgl-device.js
|
|
8625
11700
|
var LOG_LEVEL2 = 1;
|
|
8626
|
-
var WebGLDevice = class extends
|
|
11701
|
+
var WebGLDevice = class extends import_core35.Device {
|
|
8627
11702
|
static isSupported() {
|
|
8628
11703
|
return typeof WebGLRenderingContext !== "undefined" || isHeadlessGLRegistered();
|
|
8629
11704
|
}
|
|
@@ -8639,7 +11714,7 @@ ${source2}`;
|
|
|
8639
11714
|
if (gl instanceof WebGLDevice) {
|
|
8640
11715
|
return gl;
|
|
8641
11716
|
}
|
|
8642
|
-
if ((gl === null || gl === void 0 ? void 0 : gl.device) instanceof
|
|
11717
|
+
if ((gl === null || gl === void 0 ? void 0 : gl.device) instanceof import_core35.Device) {
|
|
8643
11718
|
return gl.device;
|
|
8644
11719
|
}
|
|
8645
11720
|
if (!isWebGL3(gl)) {
|
|
@@ -8651,35 +11726,35 @@ ${source2}`;
|
|
|
8651
11726
|
}
|
|
8652
11727
|
static async create() {
|
|
8653
11728
|
let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
8654
|
-
|
|
11729
|
+
import_core35.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
|
|
8655
11730
|
if (typeof props.canvas === "string") {
|
|
8656
|
-
await
|
|
11731
|
+
await import_core35.CanvasContext.pageLoaded;
|
|
8657
11732
|
}
|
|
8658
|
-
if (
|
|
11733
|
+
if (import_core35.log.get("debug") || props.debug) {
|
|
8659
11734
|
await loadWebGLDeveloperTools();
|
|
8660
11735
|
}
|
|
8661
11736
|
const {
|
|
8662
11737
|
spector: spector2
|
|
8663
11738
|
} = props;
|
|
8664
|
-
if (
|
|
11739
|
+
if (import_core35.log.get("spector") || spector2) {
|
|
8665
11740
|
await loadSpectorJS();
|
|
8666
11741
|
}
|
|
8667
|
-
|
|
11742
|
+
import_core35.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
|
|
8668
11743
|
if (props.gl && props.gl.device) {
|
|
8669
11744
|
return WebGLDevice.attach(props.gl);
|
|
8670
11745
|
}
|
|
8671
11746
|
const device = new WebGLDevice(props);
|
|
8672
11747
|
const message2 = `Created ${device.info.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
|
|
8673
|
-
|
|
8674
|
-
|
|
8675
|
-
|
|
11748
|
+
import_core35.log.probe(LOG_LEVEL2, message2)();
|
|
11749
|
+
import_core35.log.table(LOG_LEVEL2, device.info)();
|
|
11750
|
+
import_core35.log.groupEnd(LOG_LEVEL2)();
|
|
8676
11751
|
return device;
|
|
8677
11752
|
}
|
|
8678
11753
|
constructor(props) {
|
|
8679
|
-
var _props$gl;
|
|
11754
|
+
var _props$gl, _props$gl2;
|
|
8680
11755
|
super({
|
|
8681
11756
|
...props,
|
|
8682
|
-
id: props.id || (0,
|
|
11757
|
+
id: props.id || (0, import_core35.uid)("webgl-device")
|
|
8683
11758
|
});
|
|
8684
11759
|
this.info = void 0;
|
|
8685
11760
|
this.canvasContext = void 0;
|
|
@@ -8708,7 +11783,11 @@ ${source2}`;
|
|
|
8708
11783
|
if (device) {
|
|
8709
11784
|
throw new Error(`WebGL context already attached to device ${device.id}`);
|
|
8710
11785
|
}
|
|
8711
|
-
|
|
11786
|
+
const canvas2 = props.canvas || ((_props$gl2 = props.gl) === null || _props$gl2 === void 0 ? void 0 : _props$gl2.canvas);
|
|
11787
|
+
this.canvasContext = new WebGLCanvasContext(this, {
|
|
11788
|
+
...props,
|
|
11789
|
+
canvas: canvas2
|
|
11790
|
+
});
|
|
8712
11791
|
this.lost = new Promise((resolve) => {
|
|
8713
11792
|
this._resolveContextLost = resolve;
|
|
8714
11793
|
});
|
|
@@ -8736,6 +11815,7 @@ ${source2}`;
|
|
|
8736
11815
|
this.gl2 = this.gl;
|
|
8737
11816
|
this.isWebGL2 = isWebGL22(this.gl);
|
|
8738
11817
|
this.isWebGL1 = !this.isWebGL2;
|
|
11818
|
+
this.canvasContext.resize();
|
|
8739
11819
|
this.info = getDeviceInfo(this.gl);
|
|
8740
11820
|
this.gl.device = this;
|
|
8741
11821
|
this.gl._version = this.isWebGL2 ? 2 : 1;
|
|
@@ -8751,7 +11831,7 @@ ${source2}`;
|
|
|
8751
11831
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
8752
11832
|
args[_key] = arguments[_key];
|
|
8753
11833
|
}
|
|
8754
|
-
return
|
|
11834
|
+
return import_core35.log.log(1, ...args)();
|
|
8755
11835
|
}
|
|
8756
11836
|
});
|
|
8757
11837
|
if (isBrowser() && props.debug) {
|
|
@@ -8762,14 +11842,14 @@ ${source2}`;
|
|
|
8762
11842
|
});
|
|
8763
11843
|
this.gl2 = this.gl;
|
|
8764
11844
|
this.debug = true;
|
|
8765
|
-
|
|
8766
|
-
|
|
11845
|
+
import_core35.log.level = Math.max(import_core35.log.level, 1);
|
|
11846
|
+
import_core35.log.warn("WebGL debug mode activated. Performance reduced.")();
|
|
8767
11847
|
}
|
|
8768
11848
|
if (isBrowser() && props.spector) {
|
|
8769
|
-
const
|
|
11849
|
+
const canvas3 = this.handle.canvas || props.canvas;
|
|
8770
11850
|
this.spector = initializeSpectorJS({
|
|
8771
11851
|
...this.props,
|
|
8772
|
-
canvas
|
|
11852
|
+
canvas: canvas3
|
|
8773
11853
|
});
|
|
8774
11854
|
}
|
|
8775
11855
|
}
|
|
@@ -8854,6 +11934,12 @@ ${source2}`;
|
|
|
8854
11934
|
(_this$renderPass = this.renderPass) === null || _this$renderPass === void 0 ? void 0 : _this$renderPass.end();
|
|
8855
11935
|
this.renderPass = null;
|
|
8856
11936
|
}
|
|
11937
|
+
readPixelsToArrayWebGL(source, options) {
|
|
11938
|
+
return readPixelsToArray(source, options);
|
|
11939
|
+
}
|
|
11940
|
+
readPixelsToBufferWebGL2(source, options) {
|
|
11941
|
+
return readPixelsToBuffer(source, options);
|
|
11942
|
+
}
|
|
8857
11943
|
get webglLimits() {
|
|
8858
11944
|
this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);
|
|
8859
11945
|
return this._webglLimits;
|
|
@@ -8895,7 +11981,7 @@ ${source2}`;
|
|
|
8895
11981
|
this._constants = this._constants || new Array(this.limits.maxVertexAttributes).fill(null);
|
|
8896
11982
|
const currentConstant = this._constants[location];
|
|
8897
11983
|
if (currentConstant && compareConstantArrayValues2(currentConstant, constant)) {
|
|
8898
|
-
|
|
11984
|
+
import_core35.log.info(1, `setConstantAttribute(${location}) could have been skipped, value unchanged`)();
|
|
8899
11985
|
}
|
|
8900
11986
|
this._constants[location] = constant;
|
|
8901
11987
|
switch (constant.constructor) {
|
|
@@ -8909,7 +11995,7 @@ ${source2}`;
|
|
|
8909
11995
|
setConstantUintArray(this, location, constant);
|
|
8910
11996
|
break;
|
|
8911
11997
|
default:
|
|
8912
|
-
(0,
|
|
11998
|
+
(0, import_core35.assert)(false);
|
|
8913
11999
|
}
|
|
8914
12000
|
}
|
|
8915
12001
|
};
|
|
@@ -8944,7 +12030,7 @@ ${source2}`;
|
|
|
8944
12030
|
device.gl.vertexAttrib4fv(location, array);
|
|
8945
12031
|
break;
|
|
8946
12032
|
default:
|
|
8947
|
-
(0,
|
|
12033
|
+
(0, import_core35.assert)(false);
|
|
8948
12034
|
}
|
|
8949
12035
|
}
|
|
8950
12036
|
function setConstantIntArray(device, location, array) {
|
|
@@ -8970,7 +12056,7 @@ ${source2}`;
|
|
|
8970
12056
|
}
|
|
8971
12057
|
|
|
8972
12058
|
// src/commons.ts
|
|
8973
|
-
var
|
|
12059
|
+
var import_core36 = __toESM(require_core());
|
|
8974
12060
|
function initializeResources(device) {
|
|
8975
12061
|
this.buffer = device.createBuffer(new Int8Array([-1, -1, 1, -1, -1, 1, 1, 1]));
|
|
8976
12062
|
this.model = new Model(device, {
|
|
@@ -9003,7 +12089,7 @@ void main(void) {
|
|
|
9003
12089
|
width: 1,
|
|
9004
12090
|
height: 1
|
|
9005
12091
|
});
|
|
9006
|
-
this.deckInstance = new
|
|
12092
|
+
this.deckInstance = new import_core36.Deck({
|
|
9007
12093
|
viewState: {},
|
|
9008
12094
|
controller: false,
|
|
9009
12095
|
gl: device.gl,
|