@deck.gl/extensions 9.0.0-alpha.7 → 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 CHANGED
@@ -281,7 +281,7 @@ var __exports__ = (() => {
281
281
  }
282
282
 
283
283
  // ../../node_modules/@luma.gl/webgl/dist/adapter/webgl-device.js
284
- var import_core29 = __toESM(require_core2(), 1);
284
+ var import_core31 = __toESM(require_core2(), 1);
285
285
 
286
286
  // ../../node_modules/@probe.gl/env/dist/lib/is-electron.js
287
287
  function isElectron(mockUserAgent) {
@@ -1618,14 +1618,14 @@ var __exports__ = (() => {
1618
1618
  onContextLost: () => console.error("WebGL context lost"),
1619
1619
  onContextRestored: () => console.info("WebGL context restored")
1620
1620
  };
1621
- function createBrowserContext(canvas, props) {
1621
+ function createBrowserContext(canvas2, props) {
1622
1622
  props = {
1623
1623
  ...DEFAULT_CONTEXT_PROPS,
1624
1624
  ...props
1625
1625
  };
1626
1626
  let errorMessage = null;
1627
1627
  const onCreateError = (error2) => errorMessage = error2.statusMessage || errorMessage;
1628
- canvas.addEventListener("webglcontextcreationerror", onCreateError, false);
1628
+ canvas2.addEventListener("webglcontextcreationerror", onCreateError, false);
1629
1629
  let gl = null;
1630
1630
  if (props.type === "webgl2") {
1631
1631
  props = {
@@ -1640,12 +1640,12 @@ var __exports__ = (() => {
1640
1640
  };
1641
1641
  }
1642
1642
  if (!gl && props.webgl2) {
1643
- gl = canvas.getContext("webgl2", props);
1643
+ gl = canvas2.getContext("webgl2", props);
1644
1644
  }
1645
1645
  if (!gl && props.webgl1) {
1646
- gl = canvas.getContext("webgl", props);
1646
+ gl = canvas2.getContext("webgl", props);
1647
1647
  }
1648
- canvas.removeEventListener("webglcontextcreationerror", onCreateError, false);
1648
+ canvas2.removeEventListener("webglcontextcreationerror", onCreateError, false);
1649
1649
  if (!gl) {
1650
1650
  throw new Error(`Failed to create ${props.webgl2 && !props.webgl1 ? "WebGL2" : "WebGL"} context: ${errorMessage || "Unknown error"}`);
1651
1651
  }
@@ -1653,13 +1653,13 @@ var __exports__ = (() => {
1653
1653
  const {
1654
1654
  onContextLost
1655
1655
  } = props;
1656
- canvas.addEventListener("webglcontextlost", (event) => onContextLost(event), false);
1656
+ canvas2.addEventListener("webglcontextlost", (event) => onContextLost(event), false);
1657
1657
  }
1658
1658
  if (props.onContextRestored) {
1659
1659
  const {
1660
1660
  onContextRestored
1661
1661
  } = props;
1662
- canvas.addEventListener("webglcontextrestored", (event) => onContextRestored(event), false);
1662
+ canvas2.addEventListener("webglcontextrestored", (event) => onContextRestored(event), false);
1663
1663
  }
1664
1664
  return gl;
1665
1665
  }
@@ -3121,7 +3121,6 @@ void main(void) {}`;
3121
3121
 
3122
3122
  // ../../node_modules/@luma.gl/webgl/dist/adapter/resources/webgl-buffer.js
3123
3123
  var import_core10 = __toESM(require_core2(), 1);
3124
- var DEBUG_DATA_LENGTH = 10;
3125
3124
  var WEBGLBuffer = class extends import_core10.Buffer {
3126
3125
  constructor(device) {
3127
3126
  let props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
@@ -3135,7 +3134,6 @@ void main(void) {}`;
3135
3134
  this.glIndexType = 5123;
3136
3135
  this.byteLength = void 0;
3137
3136
  this.bytesUsed = void 0;
3138
- this.debugData = null;
3139
3137
  this.device = device;
3140
3138
  this.gl = this.device.gl;
3141
3139
  this.gl2 = this.device.gl2;
@@ -3148,7 +3146,6 @@ void main(void) {}`;
3148
3146
  this.glTarget = getWebGLTarget(this.props.usage);
3149
3147
  this.glUsage = getWebGLUsage(this.props.usage);
3150
3148
  this.glIndexType = this.props.indexType === "uint32" ? 5125 : 5123;
3151
- this.debugData = null;
3152
3149
  if (props.data) {
3153
3150
  this._initWithData(props.data, props.byteOffset, props.byteLength);
3154
3151
  } else {
@@ -3158,17 +3155,15 @@ void main(void) {}`;
3158
3155
  _initWithData(data) {
3159
3156
  let byteOffset = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
3160
3157
  let byteLength = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : data.byteLength + byteOffset;
3161
- (0, import_core10.assert)(ArrayBuffer.isView(data));
3162
- const glTarget = this._getWriteTarget();
3158
+ const glTarget = this.glTarget;
3163
3159
  this.gl.bindBuffer(glTarget, this.handle);
3164
3160
  this.gl.bufferData(glTarget, byteLength, this.glUsage);
3165
3161
  this.gl.bufferSubData(glTarget, byteOffset, data);
3166
3162
  this.gl.bindBuffer(glTarget, null);
3167
- this.debugData = data.slice(0, DEBUG_DATA_LENGTH);
3168
3163
  this.bytesUsed = byteLength;
3169
3164
  this.byteLength = byteLength;
3165
+ this._setDebugData(data, byteOffset, byteLength);
3170
3166
  this.trackAllocatedMemory(byteLength);
3171
- return this;
3172
3167
  }
3173
3168
  _initWithByteLength(byteLength) {
3174
3169
  (0, import_core10.assert)(byteLength >= 0);
@@ -3176,13 +3171,14 @@ void main(void) {}`;
3176
3171
  if (byteLength === 0) {
3177
3172
  data = new Float32Array(0);
3178
3173
  }
3179
- const glTarget = this._getWriteTarget();
3174
+ const glTarget = this.glTarget;
3180
3175
  this.gl.bindBuffer(glTarget, this.handle);
3181
3176
  this.gl.bufferData(glTarget, data, this.glUsage);
3182
3177
  this.gl.bindBuffer(glTarget, null);
3183
- this.debugData = null;
3184
3178
  this.bytesUsed = byteLength;
3185
3179
  this.byteLength = byteLength;
3180
+ this._setDebugData(null, 0, byteLength);
3181
+ this.trackAllocatedMemory(byteLength);
3186
3182
  return this;
3187
3183
  }
3188
3184
  destroy() {
@@ -3207,29 +3203,27 @@ void main(void) {}`;
3207
3203
  this.gl.bufferSubData(glTarget, byteOffset, data);
3208
3204
  }
3209
3205
  this.gl.bindBuffer(glTarget, null);
3206
+ this._setDebugData(data, byteOffset, data.byteLength);
3210
3207
  }
3211
3208
  async readAsync() {
3209
+ let byteOffset = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
3210
+ let byteLength = arguments.length > 1 ? arguments[1] : void 0;
3211
+ return this.readSyncWebGL2(byteOffset, byteLength);
3212
+ }
3213
+ readSyncWebGL2() {
3212
3214
  var _byteLength;
3213
3215
  let byteOffset = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
3214
3216
  let byteLength = arguments.length > 1 ? arguments[1] : void 0;
3215
3217
  this.device.assertWebGL2();
3216
- byteLength = (_byteLength = byteLength) !== null && _byteLength !== void 0 ? _byteLength : this.byteLength;
3218
+ byteLength = (_byteLength = byteLength) !== null && _byteLength !== void 0 ? _byteLength : this.byteLength - byteOffset;
3217
3219
  const data = new Uint8Array(byteLength);
3218
3220
  const dstOffset = 0;
3219
3221
  this.gl.bindBuffer(36662, this.handle);
3220
3222
  this.gl2.getBufferSubData(36662, byteOffset, data, dstOffset, byteLength);
3221
3223
  this.gl.bindBuffer(36662, null);
3224
+ this._setDebugData(data, byteOffset, byteLength);
3222
3225
  return data;
3223
3226
  }
3224
- _invalidateDebugData() {
3225
- this.debugData = null;
3226
- }
3227
- _getWriteTarget() {
3228
- return this.glTarget;
3229
- }
3230
- _getReadTarget() {
3231
- return this.glTarget;
3232
- }
3233
3227
  };
3234
3228
  function getWebGLTarget(usage) {
3235
3229
  if (usage & import_core10.Buffer.INDEX) {
@@ -4442,9 +4436,12 @@ void main(void) {}`;
4442
4436
  const sizeChanged = size[0] !== this.presentationSize[0] || size[1] !== this.presentationSize[1];
4443
4437
  if (sizeChanged) {
4444
4438
  this.presentationSize = size;
4439
+ this.resize();
4445
4440
  }
4446
4441
  }
4447
4442
  resize(options) {
4443
+ if (!this.device.gl)
4444
+ return;
4448
4445
  if (this.canvas) {
4449
4446
  const devicePixelRatio = this.getDevicePixelRatio(options === null || options === void 0 ? void 0 : options.useDevicePixels);
4450
4447
  this.setDevicePixelRatio(devicePixelRatio, options);
@@ -5572,13 +5569,13 @@ ${source2}`;
5572
5569
  };
5573
5570
  var Accessor = class {
5574
5571
  static getBytesPerElement(accessor) {
5575
- const ArrayType = getTypedArrayFromGLType(accessor.type || 5126);
5576
- return ArrayType.BYTES_PER_ELEMENT;
5572
+ const ArrayType2 = getTypedArrayFromGLType(accessor.type || 5126);
5573
+ return ArrayType2.BYTES_PER_ELEMENT;
5577
5574
  }
5578
5575
  static getBytesPerVertex(accessor) {
5579
5576
  (0, import_core22.assert)(accessor.size);
5580
- const ArrayType = getTypedArrayFromGLType(accessor.type || 5126);
5581
- return ArrayType.BYTES_PER_ELEMENT * accessor.size;
5577
+ const ArrayType2 = getTypedArrayFromGLType(accessor.type || 5126);
5578
+ return ArrayType2.BYTES_PER_ELEMENT * accessor.size;
5582
5579
  }
5583
5580
  static resolve() {
5584
5581
  for (var _len = arguments.length, accessors = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -6147,6 +6144,13 @@ ${source2}`;
6147
6144
  this._compileAndLink();
6148
6145
  this.introspectedLayout = getShaderLayout(this.device.gl, this.handle);
6149
6146
  this.shaderLayout = (0, import_core24.mergeShaderLayout)(this.introspectedLayout, props.shaderLayout);
6147
+ switch (this.props.topology) {
6148
+ case "triangle-fan-webgl":
6149
+ case "line-loop-webgl":
6150
+ import_core23.log.warn(`Primitive topology ${this.props.topology} is deprecated and will be removed in v9.1`);
6151
+ break;
6152
+ default:
6153
+ }
6150
6154
  }
6151
6155
  destroy() {
6152
6156
  if (this.handle) {
@@ -6880,9 +6884,174 @@ ${source2}`;
6880
6884
  return /^\d+$/.test(value);
6881
6885
  }
6882
6886
 
6887
+ // ../../node_modules/@luma.gl/webgl/dist/classic/copy-and-blit.js
6888
+ var import_core30 = __toESM(require_core2(), 1);
6889
+
6890
+ // ../../node_modules/@luma.gl/webgl/dist/classic/format-utils.js
6891
+ var import_core29 = __toESM(require_core2(), 1);
6892
+ function glFormatToComponents(format) {
6893
+ switch (format) {
6894
+ case 6406:
6895
+ case 33326:
6896
+ case 6403:
6897
+ return 1;
6898
+ case 33328:
6899
+ case 33319:
6900
+ return 2;
6901
+ case 6407:
6902
+ case 34837:
6903
+ return 3;
6904
+ case 6408:
6905
+ case 34836:
6906
+ return 4;
6907
+ default:
6908
+ (0, import_core29.assert)(false);
6909
+ return 0;
6910
+ }
6911
+ }
6912
+ function glTypeToBytes(type) {
6913
+ switch (type) {
6914
+ case 5121:
6915
+ return 1;
6916
+ case 33635:
6917
+ case 32819:
6918
+ case 32820:
6919
+ return 2;
6920
+ case 5126:
6921
+ return 4;
6922
+ default:
6923
+ (0, import_core29.assert)(false);
6924
+ return 0;
6925
+ }
6926
+ }
6927
+
6928
+ // ../../node_modules/@luma.gl/webgl/dist/classic/copy-and-blit.js
6929
+ function readPixelsToArray(source, options) {
6930
+ var _framebuffer$colorAtt;
6931
+ const {
6932
+ sourceX = 0,
6933
+ sourceY = 0,
6934
+ sourceFormat = 6408,
6935
+ sourceAttachment = 36064
6936
+ } = options || {};
6937
+ let {
6938
+ target = null,
6939
+ sourceWidth,
6940
+ sourceHeight,
6941
+ sourceType
6942
+ } = options || {};
6943
+ const {
6944
+ framebuffer,
6945
+ deleteFramebuffer
6946
+ } = getFramebuffer2(source);
6947
+ (0, import_core30.assert)(framebuffer);
6948
+ const {
6949
+ gl,
6950
+ handle
6951
+ } = framebuffer;
6952
+ sourceWidth = sourceWidth || framebuffer.width;
6953
+ sourceHeight = sourceHeight || framebuffer.height;
6954
+ const attachment = sourceAttachment - 36064;
6955
+ sourceType = sourceType || ((_framebuffer$colorAtt = framebuffer.colorAttachments[attachment]) === null || _framebuffer$colorAtt === void 0 ? void 0 : _framebuffer$colorAtt.type) || 5121;
6956
+ target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
6957
+ sourceType = sourceType || getGLTypeFromTypedArray(target);
6958
+ const prevHandle = gl.bindFramebuffer(36160, handle);
6959
+ gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
6960
+ gl.bindFramebuffer(36160, prevHandle || null);
6961
+ if (deleteFramebuffer) {
6962
+ framebuffer.destroy();
6963
+ }
6964
+ return target;
6965
+ }
6966
+ function readPixelsToBuffer(source, options) {
6967
+ const {
6968
+ target,
6969
+ sourceX = 0,
6970
+ sourceY = 0,
6971
+ sourceFormat = 6408,
6972
+ targetByteOffset = 0
6973
+ } = options || {};
6974
+ let {
6975
+ sourceWidth,
6976
+ sourceHeight,
6977
+ sourceType
6978
+ } = options || {};
6979
+ const {
6980
+ framebuffer,
6981
+ deleteFramebuffer
6982
+ } = getFramebuffer2(source);
6983
+ (0, import_core30.assert)(framebuffer);
6984
+ sourceWidth = sourceWidth || framebuffer.width;
6985
+ sourceHeight = sourceHeight || framebuffer.height;
6986
+ const webglFramebuffer = framebuffer;
6987
+ sourceType = sourceType || 5121;
6988
+ let webglBufferTarget = target;
6989
+ if (!webglBufferTarget) {
6990
+ const components = glFormatToComponents(sourceFormat);
6991
+ const byteCount = glTypeToBytes(sourceType);
6992
+ const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
6993
+ webglBufferTarget = webglFramebuffer.device.createBuffer({
6994
+ byteLength
6995
+ });
6996
+ }
6997
+ const commandEncoder = source.device.createCommandEncoder();
6998
+ commandEncoder.copyTextureToBuffer({
6999
+ source,
7000
+ width: sourceWidth,
7001
+ height: sourceHeight,
7002
+ origin: [sourceX, sourceY],
7003
+ destination: webglBufferTarget,
7004
+ byteOffset: targetByteOffset
7005
+ });
7006
+ commandEncoder.destroy();
7007
+ if (deleteFramebuffer) {
7008
+ framebuffer.destroy();
7009
+ }
7010
+ return webglBufferTarget;
7011
+ }
7012
+ function getFramebuffer2(source) {
7013
+ if (!(source instanceof import_core30.Framebuffer)) {
7014
+ return {
7015
+ framebuffer: toFramebuffer(source),
7016
+ deleteFramebuffer: true
7017
+ };
7018
+ }
7019
+ return {
7020
+ framebuffer: source,
7021
+ deleteFramebuffer: false
7022
+ };
7023
+ }
7024
+ function toFramebuffer(texture, props) {
7025
+ const {
7026
+ device,
7027
+ width,
7028
+ height,
7029
+ id
7030
+ } = texture;
7031
+ const framebuffer = device.createFramebuffer({
7032
+ ...props,
7033
+ id: `framebuffer-for-${id}`,
7034
+ width,
7035
+ height,
7036
+ colorAttachments: [texture]
7037
+ });
7038
+ return framebuffer;
7039
+ }
7040
+ function getPixelArray(pixelArray, type, format, width, height) {
7041
+ if (pixelArray) {
7042
+ return pixelArray;
7043
+ }
7044
+ type = type || 5121;
7045
+ const ArrayType2 = getTypedArrayFromGLType(type, {
7046
+ clamped: false
7047
+ });
7048
+ const components = glFormatToComponents(format);
7049
+ return new ArrayType2(width * height * components);
7050
+ }
7051
+
6883
7052
  // ../../node_modules/@luma.gl/webgl/dist/adapter/webgl-device.js
6884
7053
  var LOG_LEVEL2 = 1;
6885
- var WebGLDevice = class extends import_core29.Device {
7054
+ var WebGLDevice = class extends import_core31.Device {
6886
7055
  static isSupported() {
6887
7056
  return typeof WebGLRenderingContext !== "undefined" || isHeadlessGLRegistered();
6888
7057
  }
@@ -6898,7 +7067,7 @@ ${source2}`;
6898
7067
  if (gl instanceof WebGLDevice) {
6899
7068
  return gl;
6900
7069
  }
6901
- if ((gl === null || gl === void 0 ? void 0 : gl.device) instanceof import_core29.Device) {
7070
+ if ((gl === null || gl === void 0 ? void 0 : gl.device) instanceof import_core31.Device) {
6902
7071
  return gl.device;
6903
7072
  }
6904
7073
  if (!isWebGL3(gl)) {
@@ -6910,35 +7079,35 @@ ${source2}`;
6910
7079
  }
6911
7080
  static async create() {
6912
7081
  let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
6913
- import_core29.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
7082
+ import_core31.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
6914
7083
  if (typeof props.canvas === "string") {
6915
- await import_core29.CanvasContext.pageLoaded;
7084
+ await import_core31.CanvasContext.pageLoaded;
6916
7085
  }
6917
- if (import_core29.log.get("debug") || props.debug) {
7086
+ if (import_core31.log.get("debug") || props.debug) {
6918
7087
  await loadWebGLDeveloperTools();
6919
7088
  }
6920
7089
  const {
6921
7090
  spector: spector2
6922
7091
  } = props;
6923
- if (import_core29.log.get("spector") || spector2) {
7092
+ if (import_core31.log.get("spector") || spector2) {
6924
7093
  await loadSpectorJS();
6925
7094
  }
6926
- import_core29.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
7095
+ import_core31.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
6927
7096
  if (props.gl && props.gl.device) {
6928
7097
  return WebGLDevice.attach(props.gl);
6929
7098
  }
6930
7099
  const device = new WebGLDevice(props);
6931
7100
  const message2 = `Created ${device.info.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
6932
- import_core29.log.probe(LOG_LEVEL2, message2)();
6933
- import_core29.log.table(LOG_LEVEL2, device.info)();
6934
- import_core29.log.groupEnd(LOG_LEVEL2)();
7101
+ import_core31.log.probe(LOG_LEVEL2, message2)();
7102
+ import_core31.log.table(LOG_LEVEL2, device.info)();
7103
+ import_core31.log.groupEnd(LOG_LEVEL2)();
6935
7104
  return device;
6936
7105
  }
6937
7106
  constructor(props) {
6938
- var _props$gl;
7107
+ var _props$gl, _props$gl2;
6939
7108
  super({
6940
7109
  ...props,
6941
- id: props.id || (0, import_core29.uid)("webgl-device")
7110
+ id: props.id || (0, import_core31.uid)("webgl-device")
6942
7111
  });
6943
7112
  this.info = void 0;
6944
7113
  this.canvasContext = void 0;
@@ -6967,7 +7136,11 @@ ${source2}`;
6967
7136
  if (device) {
6968
7137
  throw new Error(`WebGL context already attached to device ${device.id}`);
6969
7138
  }
6970
- this.canvasContext = new WebGLCanvasContext(this, props);
7139
+ const canvas2 = props.canvas || ((_props$gl2 = props.gl) === null || _props$gl2 === void 0 ? void 0 : _props$gl2.canvas);
7140
+ this.canvasContext = new WebGLCanvasContext(this, {
7141
+ ...props,
7142
+ canvas: canvas2
7143
+ });
6971
7144
  this.lost = new Promise((resolve) => {
6972
7145
  this._resolveContextLost = resolve;
6973
7146
  });
@@ -6995,6 +7168,7 @@ ${source2}`;
6995
7168
  this.gl2 = this.gl;
6996
7169
  this.isWebGL2 = isWebGL22(this.gl);
6997
7170
  this.isWebGL1 = !this.isWebGL2;
7171
+ this.canvasContext.resize();
6998
7172
  this.info = getDeviceInfo(this.gl);
6999
7173
  this.gl.device = this;
7000
7174
  this.gl._version = this.isWebGL2 ? 2 : 1;
@@ -7010,7 +7184,7 @@ ${source2}`;
7010
7184
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
7011
7185
  args[_key] = arguments[_key];
7012
7186
  }
7013
- return import_core29.log.log(1, ...args)();
7187
+ return import_core31.log.log(1, ...args)();
7014
7188
  }
7015
7189
  });
7016
7190
  if (isBrowser() && props.debug) {
@@ -7021,14 +7195,14 @@ ${source2}`;
7021
7195
  });
7022
7196
  this.gl2 = this.gl;
7023
7197
  this.debug = true;
7024
- import_core29.log.level = Math.max(import_core29.log.level, 1);
7025
- import_core29.log.warn("WebGL debug mode activated. Performance reduced.")();
7198
+ import_core31.log.level = Math.max(import_core31.log.level, 1);
7199
+ import_core31.log.warn("WebGL debug mode activated. Performance reduced.")();
7026
7200
  }
7027
7201
  if (isBrowser() && props.spector) {
7028
- const canvas = this.handle.canvas || props.canvas;
7202
+ const canvas3 = this.handle.canvas || props.canvas;
7029
7203
  this.spector = initializeSpectorJS({
7030
7204
  ...this.props,
7031
- canvas
7205
+ canvas: canvas3
7032
7206
  });
7033
7207
  }
7034
7208
  }
@@ -7113,6 +7287,12 @@ ${source2}`;
7113
7287
  (_this$renderPass = this.renderPass) === null || _this$renderPass === void 0 ? void 0 : _this$renderPass.end();
7114
7288
  this.renderPass = null;
7115
7289
  }
7290
+ readPixelsToArrayWebGL(source, options) {
7291
+ return readPixelsToArray(source, options);
7292
+ }
7293
+ readPixelsToBufferWebGL2(source, options) {
7294
+ return readPixelsToBuffer(source, options);
7295
+ }
7116
7296
  get webglLimits() {
7117
7297
  this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);
7118
7298
  return this._webglLimits;
@@ -7154,7 +7334,7 @@ ${source2}`;
7154
7334
  this._constants = this._constants || new Array(this.limits.maxVertexAttributes).fill(null);
7155
7335
  const currentConstant = this._constants[location];
7156
7336
  if (currentConstant && compareConstantArrayValues2(currentConstant, constant)) {
7157
- import_core29.log.info(1, `setConstantAttribute(${location}) could have been skipped, value unchanged`)();
7337
+ import_core31.log.info(1, `setConstantAttribute(${location}) could have been skipped, value unchanged`)();
7158
7338
  }
7159
7339
  this._constants[location] = constant;
7160
7340
  switch (constant.constructor) {
@@ -7168,7 +7348,7 @@ ${source2}`;
7168
7348
  setConstantUintArray(this, location, constant);
7169
7349
  break;
7170
7350
  default:
7171
- (0, import_core29.assert)(false);
7351
+ (0, import_core31.assert)(false);
7172
7352
  }
7173
7353
  }
7174
7354
  };
@@ -7203,7 +7383,7 @@ ${source2}`;
7203
7383
  device.gl.vertexAttrib4fv(location, array);
7204
7384
  break;
7205
7385
  default:
7206
- (0, import_core29.assert)(false);
7386
+ (0, import_core31.assert)(false);
7207
7387
  }
7208
7388
  }
7209
7389
  function setConstantIntArray(device, location, array) {
@@ -7229,7 +7409,7 @@ ${source2}`;
7229
7409
  }
7230
7410
 
7231
7411
  // ../../node_modules/@luma.gl/webgl/dist/classic/clear.js
7232
- var import_core30 = __toESM(require_core2(), 1);
7412
+ var import_core32 = __toESM(require_core2(), 1);
7233
7413
  var GL_DEPTH_BUFFER_BIT2 = 256;
7234
7414
  var GL_STENCIL_BUFFER_BIT2 = 1024;
7235
7415
  var GL_COLOR_BUFFER_BIT2 = 16384;
@@ -7265,184 +7445,80 @@ ${source2}`;
7265
7445
  parameters2.clearStencil = depth;
7266
7446
  }
7267
7447
  }
7268
- (0, import_core30.assert)(clearFlags !== 0, ERR_ARGUMENTS);
7448
+ (0, import_core32.assert)(clearFlags !== 0, ERR_ARGUMENTS);
7269
7449
  withGLParameters(device.gl, parameters2, () => {
7270
7450
  device.gl.clear(clearFlags);
7271
7451
  });
7272
7452
  }
7273
7453
 
7274
- // ../../node_modules/@luma.gl/webgl/dist/classic/copy-and-blit.js
7275
- var import_core32 = __toESM(require_core2(), 1);
7454
+ // src/data-filter/data-filter-extension.ts
7455
+ var import_core39 = __toESM(require_core());
7276
7456
 
7277
- // ../../node_modules/@luma.gl/webgl/dist/classic/format-utils.js
7278
- var import_core31 = __toESM(require_core2(), 1);
7279
- function glFormatToComponents(format) {
7280
- switch (format) {
7281
- case 6406:
7282
- case 33326:
7283
- case 6403:
7284
- return 1;
7285
- case 33328:
7286
- case 33319:
7287
- return 2;
7288
- case 6407:
7289
- case 34837:
7290
- return 3;
7291
- case 6408:
7292
- case 34836:
7293
- return 4;
7294
- default:
7295
- (0, import_core31.assert)(false);
7296
- return 0;
7457
+ // src/data-filter/shader-module.ts
7458
+ var vs2 = `
7459
+ uniform DATAFILTER_TYPE filter_min;
7460
+ uniform DATAFILTER_TYPE filter_softMin;
7461
+ uniform DATAFILTER_TYPE filter_softMax;
7462
+ uniform DATAFILTER_TYPE filter_max;
7463
+ uniform bool filter_useSoftMargin;
7464
+ uniform bool filter_enabled;
7465
+ uniform bool filter_transformSize;
7466
+
7467
+ #ifdef NON_INSTANCED_MODEL
7468
+ #define DATAFILTER_ATTRIB filterValues
7469
+ #define DATAFILTER_ATTRIB_64LOW filterValues64Low
7470
+ #else
7471
+ #define DATAFILTER_ATTRIB instanceFilterValues
7472
+ #define DATAFILTER_ATTRIB_64LOW instanceFilterValues64Low
7473
+ #endif
7474
+
7475
+ in DATAFILTER_TYPE DATAFILTER_ATTRIB;
7476
+ #ifdef DATAFILTER_DOUBLE
7477
+ in DATAFILTER_TYPE DATAFILTER_ATTRIB_64LOW;
7478
+
7479
+ uniform DATAFILTER_TYPE filter_min64High;
7480
+ uniform DATAFILTER_TYPE filter_max64High;
7481
+ #endif
7482
+
7483
+ out float dataFilter_value;
7484
+
7485
+ float dataFilter_reduceValue(float value) {
7486
+ return value;
7487
+ }
7488
+ float dataFilter_reduceValue(vec2 value) {
7489
+ return min(value.x, value.y);
7490
+ }
7491
+ float dataFilter_reduceValue(vec3 value) {
7492
+ return min(min(value.x, value.y), value.z);
7493
+ }
7494
+ float dataFilter_reduceValue(vec4 value) {
7495
+ return min(min(value.x, value.y), min(value.z, value.w));
7496
+ }
7497
+ void dataFilter_setValue(DATAFILTER_TYPE valueFromMin, DATAFILTER_TYPE valueFromMax) {
7498
+ if (filter_enabled) {
7499
+ if (filter_useSoftMargin) {
7500
+ dataFilter_value = dataFilter_reduceValue(
7501
+ smoothstep(filter_min, filter_softMin, valueFromMin) *
7502
+ (1.0 - smoothstep(filter_softMax, filter_max, valueFromMax))
7503
+ );
7504
+ } else {
7505
+ dataFilter_value = dataFilter_reduceValue(
7506
+ step(filter_min, valueFromMin) * step(valueFromMax, filter_max)
7507
+ );
7297
7508
  }
7509
+ } else {
7510
+ dataFilter_value = 1.0;
7298
7511
  }
7299
-
7300
- // ../../node_modules/@luma.gl/webgl/dist/classic/copy-and-blit.js
7301
- function readPixelsToArray(source, options) {
7302
- var _framebuffer$colorAtt;
7303
- const {
7304
- sourceX = 0,
7305
- sourceY = 0,
7306
- sourceFormat = 6408,
7307
- sourceAttachment = 36064
7308
- } = options || {};
7309
- let {
7310
- target = null,
7311
- sourceWidth,
7312
- sourceHeight,
7313
- sourceType
7314
- } = options || {};
7315
- const {
7316
- framebuffer,
7317
- deleteFramebuffer
7318
- } = getFramebuffer2(source);
7319
- (0, import_core32.assert)(framebuffer);
7320
- const {
7321
- gl,
7322
- handle
7323
- } = framebuffer;
7324
- sourceWidth = sourceWidth || framebuffer.width;
7325
- sourceHeight = sourceHeight || framebuffer.height;
7326
- const attachment = sourceAttachment - 36064;
7327
- sourceType = sourceType || ((_framebuffer$colorAtt = framebuffer.colorAttachments[attachment]) === null || _framebuffer$colorAtt === void 0 ? void 0 : _framebuffer$colorAtt.type) || 5121;
7328
- target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
7329
- sourceType = sourceType || getGLTypeFromTypedArray(target);
7330
- const prevHandle = gl.bindFramebuffer(36160, handle);
7331
- gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
7332
- gl.bindFramebuffer(36160, prevHandle || null);
7333
- if (deleteFramebuffer) {
7334
- framebuffer.destroy();
7335
- }
7336
- return target;
7337
- }
7338
- function getFramebuffer2(source) {
7339
- if (!(source instanceof import_core32.Framebuffer)) {
7340
- return {
7341
- framebuffer: toFramebuffer(source),
7342
- deleteFramebuffer: true
7343
- };
7344
- }
7345
- return {
7346
- framebuffer: source,
7347
- deleteFramebuffer: false
7348
- };
7349
- }
7350
- function toFramebuffer(texture, props) {
7351
- const {
7352
- device,
7353
- width,
7354
- height,
7355
- id
7356
- } = texture;
7357
- const framebuffer = device.createFramebuffer({
7358
- ...props,
7359
- id: `framebuffer-for-${id}`,
7360
- width,
7361
- height,
7362
- colorAttachments: [texture]
7363
- });
7364
- return framebuffer;
7365
- }
7366
- function getPixelArray(pixelArray, type, format, width, height) {
7367
- if (pixelArray) {
7368
- return pixelArray;
7369
- }
7370
- type = type || 5121;
7371
- const ArrayType = getTypedArrayFromGLType(type, {
7372
- clamped: false
7373
- });
7374
- const components = glFormatToComponents(format);
7375
- return new ArrayType(width * height * components);
7376
- }
7377
-
7378
- // src/data-filter/data-filter-extension.ts
7379
- var import_core39 = __toESM(require_core());
7380
-
7381
- // src/data-filter/shader-module.ts
7382
- var vs2 = `
7383
- uniform DATAFILTER_TYPE filter_min;
7384
- uniform DATAFILTER_TYPE filter_softMin;
7385
- uniform DATAFILTER_TYPE filter_softMax;
7386
- uniform DATAFILTER_TYPE filter_max;
7387
- uniform bool filter_useSoftMargin;
7388
- uniform bool filter_enabled;
7389
- uniform bool filter_transformSize;
7390
-
7391
- #ifdef NON_INSTANCED_MODEL
7392
- #define DATAFILTER_ATTRIB filterValues
7393
- #define DATAFILTER_ATTRIB_64LOW filterValues64Low
7394
- #else
7395
- #define DATAFILTER_ATTRIB instanceFilterValues
7396
- #define DATAFILTER_ATTRIB_64LOW instanceFilterValues64Low
7397
- #endif
7398
-
7399
- in DATAFILTER_TYPE DATAFILTER_ATTRIB;
7400
- #ifdef DATAFILTER_DOUBLE
7401
- in DATAFILTER_TYPE DATAFILTER_ATTRIB_64LOW;
7402
-
7403
- uniform DATAFILTER_TYPE filter_min64High;
7404
- uniform DATAFILTER_TYPE filter_max64High;
7405
- #endif
7406
-
7407
- out float dataFilter_value;
7408
-
7409
- float dataFilter_reduceValue(float value) {
7410
- return value;
7411
- }
7412
- float dataFilter_reduceValue(vec2 value) {
7413
- return min(value.x, value.y);
7414
- }
7415
- float dataFilter_reduceValue(vec3 value) {
7416
- return min(min(value.x, value.y), value.z);
7417
- }
7418
- float dataFilter_reduceValue(vec4 value) {
7419
- return min(min(value.x, value.y), min(value.z, value.w));
7420
- }
7421
- void dataFilter_setValue(DATAFILTER_TYPE valueFromMin, DATAFILTER_TYPE valueFromMax) {
7422
- if (filter_enabled) {
7423
- if (filter_useSoftMargin) {
7424
- dataFilter_value = dataFilter_reduceValue(
7425
- smoothstep(filter_min, filter_softMin, valueFromMin) *
7426
- (1.0 - smoothstep(filter_softMax, filter_max, valueFromMax))
7427
- );
7428
- } else {
7429
- dataFilter_value = dataFilter_reduceValue(
7430
- step(filter_min, valueFromMin) * step(valueFromMax, filter_max)
7431
- );
7432
- }
7433
- } else {
7434
- dataFilter_value = 1.0;
7435
- }
7436
- }
7437
- `;
7438
- var fs2 = `
7439
- uniform bool filter_transformColor;
7440
- in float dataFilter_value;
7441
- `;
7442
- function getUniforms(opts) {
7443
- if (!opts || !("extensions" in opts)) {
7444
- return {};
7445
- }
7512
+ }
7513
+ `;
7514
+ var fs2 = `
7515
+ uniform bool filter_transformColor;
7516
+ in float dataFilter_value;
7517
+ `;
7518
+ function getUniforms(opts) {
7519
+ if (!opts || !("extensions" in opts)) {
7520
+ return {};
7521
+ }
7446
7522
  const {
7447
7523
  filterRange = [-1, 1],
7448
7524
  filterEnabled = true,
@@ -8156,7 +8232,7 @@ ${moduleSource}
8156
8232
  }
8157
8233
  function getShaderName(shader) {
8158
8234
  let defaultName = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "unnamed";
8159
- const SHADER_NAME_REGEXP = /#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/;
8235
+ const SHADER_NAME_REGEXP = /#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/;
8160
8236
  const match = SHADER_NAME_REGEXP.exec(shader);
8161
8237
  return match ? match[1] : defaultName;
8162
8238
  }
@@ -8365,178 +8441,2951 @@ ${getApplicationDefines(allDefines)}
8365
8441
  mainInjections[key] = [injection];
8366
8442
  }
8367
8443
  } else {
8368
- hookInjections[key] = [injection];
8444
+ hookInjections[key] = [injection];
8445
+ }
8446
+ } else {
8447
+ mainInjections[key] = [injection];
8448
+ }
8449
+ }
8450
+ for (const module of modules) {
8451
+ if (log14) {
8452
+ module.checkDeprecations(coreSource, log14);
8453
+ }
8454
+ const moduleSource = module.getModuleSource(stage);
8455
+ assembledSource += moduleSource;
8456
+ const injections = module.injections[stage];
8457
+ for (const key in injections) {
8458
+ const match = /^(v|f)s:#([\w-]+)$/.exec(key);
8459
+ if (match) {
8460
+ const name = match[2];
8461
+ const injectionType = name === "decl" ? declInjections : mainInjections;
8462
+ injectionType[key] = injectionType[key] || [];
8463
+ injectionType[key].push(injections[key]);
8464
+ } else {
8465
+ hookInjections[key] = hookInjections[key] || [];
8466
+ hookInjections[key].push(injections[key]);
8467
+ }
8468
+ }
8469
+ }
8470
+ assembledSource += "// ----- MAIN SHADER SOURCE -------------------------";
8471
+ assembledSource += INJECT_SHADER_DECLARATIONS;
8472
+ assembledSource = injectShader(assembledSource, stage, declInjections);
8473
+ assembledSource += getShaderHooks(hookFunctionMap[stage], hookInjections);
8474
+ assembledSource += coreSource;
8475
+ assembledSource = injectShader(assembledSource, stage, mainInjections);
8476
+ if (language === "glsl" && sourceVersion !== targetVersion) {
8477
+ assembledSource = transpileGLSLShader(assembledSource, targetVersion, stage);
8478
+ }
8479
+ return assembledSource.trim();
8480
+ }
8481
+ function assembleGetUniforms(modules) {
8482
+ return function getUniforms4(opts) {
8483
+ const uniforms = {};
8484
+ for (const module of modules) {
8485
+ const moduleUniforms = module.getUniforms(opts, uniforms);
8486
+ Object.assign(uniforms, moduleUniforms);
8487
+ }
8488
+ return uniforms;
8489
+ };
8490
+ }
8491
+ function getShaderNameDefine(options) {
8492
+ const {
8493
+ id,
8494
+ source,
8495
+ stage
8496
+ } = options;
8497
+ const injectShaderName = id && source.indexOf("SHADER_NAME") === -1;
8498
+ return injectShaderName ? `
8499
+ #define SHADER_NAME ${id}_${stage}
8500
+
8501
+ ` : "";
8502
+ }
8503
+ function getApplicationDefines() {
8504
+ let defines = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
8505
+ let sourceText = "";
8506
+ for (const define in defines) {
8507
+ const value = defines[define];
8508
+ if (value || Number.isFinite(value)) {
8509
+ sourceText += `#define ${define.toUpperCase()} ${defines[define]}
8510
+ `;
8511
+ }
8512
+ }
8513
+ return sourceText;
8514
+ }
8515
+
8516
+ // ../../node_modules/@luma.gl/shadertools/dist/lib/shader-assembly/select-shaders.js
8517
+ function selectShaders(props) {
8518
+ if (!props.vs) {
8519
+ throw new Error("no vertex shader");
8520
+ }
8521
+ const vs5 = getShaderSource(props.platformInfo, props.vs);
8522
+ let fs4;
8523
+ if (props.fs) {
8524
+ fs4 = getShaderSource(props.platformInfo, props.fs);
8525
+ }
8526
+ return {
8527
+ ...props,
8528
+ vs: vs5,
8529
+ fs: fs4
8530
+ };
8531
+ }
8532
+ function getShaderSource(platformInfo, shader) {
8533
+ if (typeof shader === "string") {
8534
+ return shader;
8535
+ }
8536
+ switch (platformInfo.type) {
8537
+ case "webgpu":
8538
+ if (shader !== null && shader !== void 0 && shader.wgsl) {
8539
+ return shader.wgsl;
8540
+ }
8541
+ throw new Error("WebGPU does not support GLSL shaders");
8542
+ default:
8543
+ if (shader !== null && shader !== void 0 && shader.glsl) {
8544
+ return shader.glsl;
8545
+ }
8546
+ throw new Error("WebGL does not support WGSL shaders");
8547
+ }
8548
+ }
8549
+
8550
+ // ../../node_modules/@luma.gl/shadertools/dist/lib/shader-assembler.js
8551
+ var ShaderAssembler = class {
8552
+ constructor() {
8553
+ this._hookFunctions = [];
8554
+ this._defaultModules = [];
8555
+ }
8556
+ static getDefaultShaderAssembler() {
8557
+ ShaderAssembler.defaultShaderAssembler = ShaderAssembler.defaultShaderAssembler || new ShaderAssembler();
8558
+ return ShaderAssembler.defaultShaderAssembler;
8559
+ }
8560
+ addDefaultModule(module) {
8561
+ if (!this._defaultModules.find((m) => m.name === (typeof module === "string" ? module : module.name))) {
8562
+ this._defaultModules.push(module);
8563
+ }
8564
+ }
8565
+ removeDefaultModule(module) {
8566
+ const moduleName = typeof module === "string" ? module : module.name;
8567
+ this._defaultModules = this._defaultModules.filter((m) => m.name !== moduleName);
8568
+ }
8569
+ addShaderHook(hook, opts) {
8570
+ if (opts) {
8571
+ hook = Object.assign(opts, {
8572
+ hook
8573
+ });
8574
+ }
8575
+ this._hookFunctions.push(hook);
8576
+ }
8577
+ assembleShaders(props) {
8578
+ const modules = this._getModuleList(props.modules);
8579
+ const hookFunctions = this._hookFunctions;
8580
+ const options = selectShaders(props);
8581
+ const assembled = assembleShaders({
8582
+ platformInfo: props.platformInfo,
8583
+ ...options,
8584
+ modules,
8585
+ hookFunctions
8586
+ });
8587
+ return {
8588
+ ...assembled,
8589
+ modules
8590
+ };
8591
+ }
8592
+ _getModuleList() {
8593
+ let appModules = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
8594
+ const modules = new Array(this._defaultModules.length + appModules.length);
8595
+ const seen = {};
8596
+ let count = 0;
8597
+ for (let i = 0, len2 = this._defaultModules.length; i < len2; ++i) {
8598
+ const module = this._defaultModules[i];
8599
+ const name = module.name;
8600
+ modules[count++] = module;
8601
+ seen[name] = true;
8602
+ }
8603
+ for (let i = 0, len2 = appModules.length; i < len2; ++i) {
8604
+ const module = appModules[i];
8605
+ const name = module.name;
8606
+ if (!seen[name]) {
8607
+ modules[count++] = module;
8608
+ seen[name] = true;
8609
+ }
8610
+ }
8611
+ modules.length = count;
8612
+ return ShaderModuleInstance.instantiateModules(modules);
8613
+ }
8614
+ };
8615
+ ShaderAssembler.defaultShaderAssembler = void 0;
8616
+
8617
+ // ../../node_modules/@luma.gl/shadertools/dist/libs/wgsl-reflect/wgsl_reflect.module.js
8618
+ var ParseContext = class {
8619
+ constructor() {
8620
+ this.constants = /* @__PURE__ */ new Map();
8621
+ this.aliases = /* @__PURE__ */ new Map();
8622
+ this.structs = /* @__PURE__ */ new Map();
8623
+ }
8624
+ };
8625
+ var Node = class {
8626
+ constructor() {
8627
+ }
8628
+ get isAstNode() {
8629
+ return true;
8630
+ }
8631
+ get astNodeType() {
8632
+ return "";
8633
+ }
8634
+ evaluate(context) {
8635
+ throw new Error("Cannot evaluate node");
8636
+ }
8637
+ evaluateString(context) {
8638
+ return this.evaluate(context).toString();
8639
+ }
8640
+ };
8641
+ var Statement = class extends Node {
8642
+ constructor() {
8643
+ super();
8644
+ }
8645
+ };
8646
+ var Function = class extends Statement {
8647
+ constructor(name, args, returnType, body) {
8648
+ super();
8649
+ this.name = name;
8650
+ this.args = args;
8651
+ this.returnType = returnType;
8652
+ this.body = body;
8653
+ }
8654
+ get astNodeType() {
8655
+ return "function";
8656
+ }
8657
+ };
8658
+ var StaticAssert = class extends Statement {
8659
+ constructor(expression) {
8660
+ super();
8661
+ this.expression = expression;
8662
+ }
8663
+ get astNodeType() {
8664
+ return "staticAssert";
8665
+ }
8666
+ };
8667
+ var While = class extends Statement {
8668
+ constructor(condition, body) {
8669
+ super();
8670
+ this.condition = condition;
8671
+ this.body = body;
8672
+ }
8673
+ get astNodeType() {
8674
+ return "while";
8675
+ }
8676
+ };
8677
+ var Continuing = class extends Statement {
8678
+ constructor(body) {
8679
+ super();
8680
+ this.body = body;
8681
+ }
8682
+ get astNodeType() {
8683
+ return "continuing";
8684
+ }
8685
+ };
8686
+ var For = class extends Statement {
8687
+ constructor(init, condition, increment, body) {
8688
+ super();
8689
+ this.init = init;
8690
+ this.condition = condition;
8691
+ this.increment = increment;
8692
+ this.body = body;
8693
+ }
8694
+ get astNodeType() {
8695
+ return "for";
8696
+ }
8697
+ };
8698
+ var Var = class extends Statement {
8699
+ constructor(name, type, storage, access, value) {
8700
+ super();
8701
+ this.name = name;
8702
+ this.type = type;
8703
+ this.storage = storage;
8704
+ this.access = access;
8705
+ this.value = value;
8706
+ }
8707
+ get astNodeType() {
8708
+ return "var";
8709
+ }
8710
+ };
8711
+ var Override = class extends Statement {
8712
+ constructor(name, type, value) {
8713
+ super();
8714
+ this.name = name;
8715
+ this.type = type;
8716
+ this.value = value;
8717
+ }
8718
+ get astNodeType() {
8719
+ return "override";
8720
+ }
8721
+ };
8722
+ var Let = class extends Statement {
8723
+ constructor(name, type, storage, access, value) {
8724
+ super();
8725
+ this.name = name;
8726
+ this.type = type;
8727
+ this.storage = storage;
8728
+ this.access = access;
8729
+ this.value = value;
8730
+ }
8731
+ get astNodeType() {
8732
+ return "let";
8733
+ }
8734
+ };
8735
+ var Const = class extends Statement {
8736
+ constructor(name, type, storage, access, value) {
8737
+ super();
8738
+ this.name = name;
8739
+ this.type = type;
8740
+ this.storage = storage;
8741
+ this.access = access;
8742
+ this.value = value;
8743
+ }
8744
+ get astNodeType() {
8745
+ return "const";
8746
+ }
8747
+ evaluate(context) {
8748
+ return this.value.evaluate(context);
8749
+ }
8750
+ };
8751
+ var IncrementOperator;
8752
+ (function(IncrementOperator2) {
8753
+ IncrementOperator2["increment"] = "++";
8754
+ IncrementOperator2["decrement"] = "--";
8755
+ })(IncrementOperator || (IncrementOperator = {}));
8756
+ (function(IncrementOperator2) {
8757
+ function parse(val) {
8758
+ const key = val;
8759
+ if (key == "parse")
8760
+ throw new Error("Invalid value for IncrementOperator");
8761
+ return IncrementOperator2[key];
8762
+ }
8763
+ IncrementOperator2.parse = parse;
8764
+ })(IncrementOperator || (IncrementOperator = {}));
8765
+ var Increment = class extends Statement {
8766
+ constructor(operator, variable) {
8767
+ super();
8768
+ this.operator = operator;
8769
+ this.variable = variable;
8770
+ }
8771
+ get astNodeType() {
8772
+ return "increment";
8773
+ }
8774
+ };
8775
+ var AssignOperator;
8776
+ (function(AssignOperator2) {
8777
+ AssignOperator2["assign"] = "=";
8778
+ AssignOperator2["addAssign"] = "+=";
8779
+ AssignOperator2["subtractAssin"] = "-=";
8780
+ AssignOperator2["multiplyAssign"] = "*=";
8781
+ AssignOperator2["divideAssign"] = "/=";
8782
+ AssignOperator2["moduloAssign"] = "%=";
8783
+ AssignOperator2["andAssign"] = "&=";
8784
+ AssignOperator2["orAssign"] = "|=";
8785
+ AssignOperator2["xorAssign"] = "^=";
8786
+ AssignOperator2["shiftLeftAssign"] = "<<=";
8787
+ AssignOperator2["shiftRightAssign"] = ">>=";
8788
+ })(AssignOperator || (AssignOperator = {}));
8789
+ (function(AssignOperator2) {
8790
+ function parse(val) {
8791
+ const key = val;
8792
+ if (key == "parse")
8793
+ throw new Error("Invalid value for AssignOperator");
8794
+ return AssignOperator2[key];
8795
+ }
8796
+ AssignOperator2.parse = parse;
8797
+ })(AssignOperator || (AssignOperator = {}));
8798
+ var Assign = class extends Statement {
8799
+ constructor(operator, variable, value) {
8800
+ super();
8801
+ this.operator = operator;
8802
+ this.variable = variable;
8803
+ this.value = value;
8804
+ }
8805
+ get astNodeType() {
8806
+ return "assign";
8807
+ }
8808
+ };
8809
+ var Call = class extends Statement {
8810
+ constructor(name, args) {
8811
+ super();
8812
+ this.name = name;
8813
+ this.args = args;
8814
+ }
8815
+ get astNodeType() {
8816
+ return "call";
8817
+ }
8818
+ };
8819
+ var Loop = class extends Statement {
8820
+ constructor(body, continuing) {
8821
+ super();
8822
+ this.body = body;
8823
+ this.continuing = continuing;
8824
+ }
8825
+ get astNodeType() {
8826
+ return "loop";
8827
+ }
8828
+ };
8829
+ var Switch = class extends Statement {
8830
+ constructor(condition, body) {
8831
+ super();
8832
+ this.condition = condition;
8833
+ this.body = body;
8834
+ }
8835
+ get astNodeType() {
8836
+ return "body";
8837
+ }
8838
+ };
8839
+ var If = class extends Statement {
8840
+ constructor(condition, body, elseif, _else) {
8841
+ super();
8842
+ this.condition = condition;
8843
+ this.body = body;
8844
+ this.elseif = elseif;
8845
+ this.else = _else;
8846
+ }
8847
+ get astNodeType() {
8848
+ return "if";
8849
+ }
8850
+ };
8851
+ var Return = class extends Statement {
8852
+ constructor(value) {
8853
+ super();
8854
+ this.value = value;
8855
+ }
8856
+ get astNodeType() {
8857
+ return "return";
8858
+ }
8859
+ };
8860
+ var Enable = class extends Statement {
8861
+ constructor(name) {
8862
+ super();
8863
+ this.name = name;
8864
+ }
8865
+ get astNodeType() {
8866
+ return "enable";
8867
+ }
8868
+ };
8869
+ var Alias = class extends Statement {
8870
+ constructor(name, type) {
8871
+ super();
8872
+ this.name = name;
8873
+ this.type = type;
8874
+ }
8875
+ get astNodeType() {
8876
+ return "alias";
8877
+ }
8878
+ };
8879
+ var Discard = class extends Statement {
8880
+ constructor() {
8881
+ super();
8882
+ }
8883
+ get astNodeType() {
8884
+ return "discard";
8885
+ }
8886
+ };
8887
+ var Break = class extends Statement {
8888
+ constructor() {
8889
+ super();
8890
+ }
8891
+ get astNodeType() {
8892
+ return "break";
8893
+ }
8894
+ };
8895
+ var Continue = class extends Statement {
8896
+ constructor() {
8897
+ super();
8898
+ }
8899
+ get astNodeType() {
8900
+ return "continue";
8901
+ }
8902
+ };
8903
+ var Type = class extends Statement {
8904
+ constructor(name) {
8905
+ super();
8906
+ this.name = name;
8907
+ }
8908
+ get astNodeType() {
8909
+ return "type";
8910
+ }
8911
+ get isStruct() {
8912
+ return false;
8913
+ }
8914
+ get isArray() {
8915
+ return false;
8916
+ }
8917
+ };
8918
+ var Struct = class extends Type {
8919
+ constructor(name, members) {
8920
+ super(name);
8921
+ this.members = members;
8922
+ }
8923
+ get astNodeType() {
8924
+ return "struct";
8925
+ }
8926
+ get isStruct() {
8927
+ return true;
8928
+ }
8929
+ getMemberIndex(name) {
8930
+ for (let i = 0; i < this.members.length; i++) {
8931
+ if (this.members[i].name == name)
8932
+ return i;
8933
+ }
8934
+ return -1;
8935
+ }
8936
+ };
8937
+ var TemplateType = class extends Type {
8938
+ constructor(name, format, access) {
8939
+ super(name);
8940
+ this.format = format;
8941
+ this.access = access;
8942
+ }
8943
+ get astNodeType() {
8944
+ return "template";
8945
+ }
8946
+ };
8947
+ var PointerType = class extends Type {
8948
+ constructor(name, storage, type, access) {
8949
+ super(name);
8950
+ this.storage = storage;
8951
+ this.type = type;
8952
+ this.access = access;
8953
+ }
8954
+ get astNodeType() {
8955
+ return "pointer";
8956
+ }
8957
+ };
8958
+ var ArrayType = class extends Type {
8959
+ constructor(name, attributes, format, count) {
8960
+ super(name);
8961
+ this.attributes = attributes;
8962
+ this.format = format;
8963
+ this.count = count;
8964
+ }
8965
+ get astNodeType() {
8966
+ return "array";
8967
+ }
8968
+ get isArray() {
8969
+ return true;
8970
+ }
8971
+ };
8972
+ var SamplerType = class extends Type {
8973
+ constructor(name, format, access) {
8974
+ super(name);
8975
+ this.format = format;
8976
+ this.access = access;
8977
+ }
8978
+ get astNodeType() {
8979
+ return "sampler";
8980
+ }
8981
+ };
8982
+ var Expression = class extends Node {
8983
+ constructor() {
8984
+ super();
8985
+ }
8986
+ };
8987
+ var StringExpr = class extends Expression {
8988
+ constructor(value) {
8989
+ super();
8990
+ this.value = value;
8991
+ }
8992
+ get astNodeType() {
8993
+ return "stringExpr";
8994
+ }
8995
+ toString() {
8996
+ return this.value;
8997
+ }
8998
+ evaluateString() {
8999
+ return this.value;
9000
+ }
9001
+ };
9002
+ var CreateExpr = class extends Expression {
9003
+ constructor(type, args) {
9004
+ super();
9005
+ this.type = type;
9006
+ this.args = args;
9007
+ }
9008
+ get astNodeType() {
9009
+ return "createExpr";
9010
+ }
9011
+ };
9012
+ var CallExpr = class extends Expression {
9013
+ constructor(name, args) {
9014
+ super();
9015
+ this.name = name;
9016
+ this.args = args;
9017
+ }
9018
+ get astNodeType() {
9019
+ return "callExpr";
9020
+ }
9021
+ evaluate(context) {
9022
+ switch (this.name) {
9023
+ case "abs":
9024
+ return Math.abs(this.args[0].evaluate(context));
9025
+ case "acos":
9026
+ return Math.acos(this.args[0].evaluate(context));
9027
+ case "acosh":
9028
+ return Math.acosh(this.args[0].evaluate(context));
9029
+ case "asin":
9030
+ return Math.asin(this.args[0].evaluate(context));
9031
+ case "asinh":
9032
+ return Math.asinh(this.args[0].evaluate(context));
9033
+ case "atan":
9034
+ return Math.atan(this.args[0].evaluate(context));
9035
+ case "atan2":
9036
+ return Math.atan2(this.args[0].evaluate(context), this.args[1].evaluate(context));
9037
+ case "atanh":
9038
+ return Math.atanh(this.args[0].evaluate(context));
9039
+ case "ceil":
9040
+ return Math.ceil(this.args[0].evaluate(context));
9041
+ case "clamp":
9042
+ return Math.min(Math.max(this.args[0].evaluate(context), this.args[1].evaluate(context)), this.args[2].evaluate(context));
9043
+ case "cos":
9044
+ return Math.cos(this.args[0].evaluate(context));
9045
+ case "degrees":
9046
+ return this.args[0].evaluate(context) * 180 / Math.PI;
9047
+ case "distance":
9048
+ return Math.sqrt(Math.pow(this.args[0].evaluate(context) - this.args[1].evaluate(context), 2));
9049
+ case "dot":
9050
+ case "exp":
9051
+ return Math.exp(this.args[0].evaluate(context));
9052
+ case "exp2":
9053
+ return Math.pow(2, this.args[0].evaluate(context));
9054
+ case "floor":
9055
+ return Math.floor(this.args[0].evaluate(context));
9056
+ case "fma":
9057
+ return this.args[0].evaluate(context) * this.args[1].evaluate(context) + this.args[2].evaluate(context);
9058
+ case "fract":
9059
+ return this.args[0].evaluate(context) - Math.floor(this.args[0].evaluate(context));
9060
+ case "inverseSqrt":
9061
+ return 1 / Math.sqrt(this.args[0].evaluate(context));
9062
+ case "log":
9063
+ return Math.log(this.args[0].evaluate(context));
9064
+ case "log2":
9065
+ return Math.log2(this.args[0].evaluate(context));
9066
+ case "max":
9067
+ return Math.max(this.args[0].evaluate(context), this.args[1].evaluate(context));
9068
+ case "min":
9069
+ return Math.min(this.args[0].evaluate(context), this.args[1].evaluate(context));
9070
+ case "mix":
9071
+ return this.args[0].evaluate(context) * (1 - this.args[2].evaluate(context)) + this.args[1].evaluate(context) * this.args[2].evaluate(context);
9072
+ case "modf":
9073
+ return this.args[0].evaluate(context) - Math.floor(this.args[0].evaluate(context));
9074
+ case "pow":
9075
+ return Math.pow(this.args[0].evaluate(context), this.args[1].evaluate(context));
9076
+ case "radians":
9077
+ return this.args[0].evaluate(context) * Math.PI / 180;
9078
+ case "round":
9079
+ return Math.round(this.args[0].evaluate(context));
9080
+ case "sign":
9081
+ return Math.sign(this.args[0].evaluate(context));
9082
+ case "sin":
9083
+ return Math.sin(this.args[0].evaluate(context));
9084
+ case "sinh":
9085
+ return Math.sinh(this.args[0].evaluate(context));
9086
+ case "saturate":
9087
+ return Math.min(Math.max(this.args[0].evaluate(context), 0), 1);
9088
+ case "smoothstep":
9089
+ return this.args[0].evaluate(context) * this.args[0].evaluate(context) * (3 - 2 * this.args[0].evaluate(context));
9090
+ case "sqrt":
9091
+ return Math.sqrt(this.args[0].evaluate(context));
9092
+ case "step":
9093
+ return this.args[0].evaluate(context) < this.args[1].evaluate(context) ? 0 : 1;
9094
+ case "tan":
9095
+ return Math.tan(this.args[0].evaluate(context));
9096
+ case "tanh":
9097
+ return Math.tanh(this.args[0].evaluate(context));
9098
+ case "trunc":
9099
+ return Math.trunc(this.args[0].evaluate(context));
9100
+ default:
9101
+ throw new Error("Non const function: " + this.name);
9102
+ }
9103
+ }
9104
+ };
9105
+ var VariableExpr = class extends Expression {
9106
+ constructor(name) {
9107
+ super();
9108
+ this.name = name;
9109
+ }
9110
+ get astNodeType() {
9111
+ return "varExpr";
9112
+ }
9113
+ };
9114
+ var ConstExpr = class extends Expression {
9115
+ constructor(name, initializer) {
9116
+ super();
9117
+ this.name = name;
9118
+ this.initializer = initializer;
9119
+ }
9120
+ get astNodeType() {
9121
+ return "constExpr";
9122
+ }
9123
+ evaluate(context) {
9124
+ var _a2, _b;
9125
+ if (this.initializer instanceof CreateExpr) {
9126
+ const property = (_a2 = this.postfix) === null || _a2 === void 0 ? void 0 : _a2.evaluateString(context);
9127
+ const type = (_b = this.initializer.type) === null || _b === void 0 ? void 0 : _b.name;
9128
+ const struct = context.structs.get(type);
9129
+ const memberIndex = struct === null || struct === void 0 ? void 0 : struct.getMemberIndex(property);
9130
+ if (memberIndex != -1) {
9131
+ const value = this.initializer.args[memberIndex].evaluate(context);
9132
+ return value;
9133
+ }
9134
+ console.log(memberIndex);
9135
+ }
9136
+ return this.initializer.evaluate(context);
9137
+ }
9138
+ };
9139
+ var LiteralExpr = class extends Expression {
9140
+ constructor(value) {
9141
+ super();
9142
+ this.value = value;
9143
+ }
9144
+ get astNodeType() {
9145
+ return "literalExpr";
9146
+ }
9147
+ evaluate() {
9148
+ return this.value;
9149
+ }
9150
+ };
9151
+ var BitcastExpr = class extends Expression {
9152
+ constructor(type, value) {
9153
+ super();
9154
+ this.type = type;
9155
+ this.value = value;
9156
+ }
9157
+ get astNodeType() {
9158
+ return "bitcastExpr";
9159
+ }
9160
+ };
9161
+ var TypecastExpr = class extends Expression {
9162
+ constructor(type, args) {
9163
+ super();
9164
+ this.type = type;
9165
+ this.args = args;
9166
+ }
9167
+ get astNodeType() {
9168
+ return "typecastExpr";
9169
+ }
9170
+ evaluate(context) {
9171
+ return this.args[0].evaluate(context);
9172
+ }
9173
+ };
9174
+ var GroupingExpr = class extends Expression {
9175
+ constructor(contents) {
9176
+ super();
9177
+ this.contents = contents;
9178
+ }
9179
+ get astNodeType() {
9180
+ return "groupExpr";
9181
+ }
9182
+ evaluate(context) {
9183
+ return this.contents[0].evaluate(context);
9184
+ }
9185
+ };
9186
+ var Operator = class extends Expression {
9187
+ constructor() {
9188
+ super();
9189
+ }
9190
+ };
9191
+ var UnaryOperator = class extends Operator {
9192
+ constructor(operator, right) {
9193
+ super();
9194
+ this.operator = operator;
9195
+ this.right = right;
9196
+ }
9197
+ get astNodeType() {
9198
+ return "unaryOp";
9199
+ }
9200
+ evaluate(context) {
9201
+ switch (this.operator) {
9202
+ case "+":
9203
+ return this.right.evaluate(context);
9204
+ case "-":
9205
+ return -this.right.evaluate(context);
9206
+ case "!":
9207
+ return this.right.evaluate(context) ? 0 : 1;
9208
+ case "~":
9209
+ return ~this.right.evaluate(context);
9210
+ default:
9211
+ throw new Error("Unknown unary operator: " + this.operator);
9212
+ }
9213
+ }
9214
+ };
9215
+ var BinaryOperator = class extends Operator {
9216
+ constructor(operator, left, right) {
9217
+ super();
9218
+ this.operator = operator;
9219
+ this.left = left;
9220
+ this.right = right;
9221
+ }
9222
+ get astNodeType() {
9223
+ return "binaryOp";
9224
+ }
9225
+ evaluate(context) {
9226
+ switch (this.operator) {
9227
+ case "+":
9228
+ return this.left.evaluate(context) + this.right.evaluate(context);
9229
+ case "-":
9230
+ return this.left.evaluate(context) - this.right.evaluate(context);
9231
+ case "*":
9232
+ return this.left.evaluate(context) * this.right.evaluate(context);
9233
+ case "/":
9234
+ return this.left.evaluate(context) / this.right.evaluate(context);
9235
+ case "%":
9236
+ return this.left.evaluate(context) % this.right.evaluate(context);
9237
+ case "==":
9238
+ return this.left.evaluate(context) == this.right.evaluate(context) ? 1 : 0;
9239
+ case "!=":
9240
+ return this.left.evaluate(context) != this.right.evaluate(context) ? 1 : 0;
9241
+ case "<":
9242
+ return this.left.evaluate(context) < this.right.evaluate(context) ? 1 : 0;
9243
+ case ">":
9244
+ return this.left.evaluate(context) > this.right.evaluate(context) ? 1 : 0;
9245
+ case "<=":
9246
+ return this.left.evaluate(context) <= this.right.evaluate(context) ? 1 : 0;
9247
+ case ">=":
9248
+ return this.left.evaluate(context) >= this.right.evaluate(context) ? 1 : 0;
9249
+ case "&&":
9250
+ return this.left.evaluate(context) && this.right.evaluate(context) ? 1 : 0;
9251
+ case "||":
9252
+ return this.left.evaluate(context) || this.right.evaluate(context) ? 1 : 0;
9253
+ default:
9254
+ throw new Error(`Unknown operator ${this.operator}`);
9255
+ }
9256
+ }
9257
+ };
9258
+ var SwitchCase = class extends Node {
9259
+ constructor() {
9260
+ super();
9261
+ }
9262
+ };
9263
+ var Case = class extends SwitchCase {
9264
+ constructor(selector, body) {
9265
+ super();
9266
+ this.selector = selector;
9267
+ this.body = body;
9268
+ }
9269
+ get astNodeType() {
9270
+ return "case";
9271
+ }
9272
+ };
9273
+ var Default = class extends SwitchCase {
9274
+ constructor(body) {
9275
+ super();
9276
+ this.body = body;
9277
+ }
9278
+ get astNodeType() {
9279
+ return "default";
9280
+ }
9281
+ };
9282
+ var Argument = class extends Node {
9283
+ constructor(name, type, attributes) {
9284
+ super();
9285
+ this.name = name;
9286
+ this.type = type;
9287
+ this.attributes = attributes;
9288
+ }
9289
+ get astNodeType() {
9290
+ return "argument";
9291
+ }
9292
+ };
9293
+ var ElseIf = class extends Node {
9294
+ constructor(condition, body) {
9295
+ super();
9296
+ this.condition = condition;
9297
+ this.body = body;
9298
+ }
9299
+ get astNodeType() {
9300
+ return "elseif";
9301
+ }
9302
+ };
9303
+ var Member = class extends Node {
9304
+ constructor(name, type, attributes) {
9305
+ super();
9306
+ this.name = name;
9307
+ this.type = type;
9308
+ this.attributes = attributes;
9309
+ }
9310
+ get astNodeType() {
9311
+ return "member";
9312
+ }
9313
+ };
9314
+ var Attribute = class extends Node {
9315
+ constructor(name, value) {
9316
+ super();
9317
+ this.name = name;
9318
+ this.value = value;
9319
+ }
9320
+ get astNodeType() {
9321
+ return "attribute";
9322
+ }
9323
+ };
9324
+ var _a;
9325
+ var TokenClass;
9326
+ (function(TokenClass2) {
9327
+ TokenClass2[TokenClass2["token"] = 0] = "token";
9328
+ TokenClass2[TokenClass2["keyword"] = 1] = "keyword";
9329
+ TokenClass2[TokenClass2["reserved"] = 2] = "reserved";
9330
+ })(TokenClass || (TokenClass = {}));
9331
+ var TokenType = class {
9332
+ constructor(name, type, rule) {
9333
+ this.name = name;
9334
+ this.type = type;
9335
+ this.rule = rule;
9336
+ }
9337
+ toString() {
9338
+ return this.name;
9339
+ }
9340
+ };
9341
+ var TokenTypes = class {
9342
+ };
9343
+ _a = TokenTypes;
9344
+ TokenTypes.none = new TokenType("", TokenClass.reserved, "");
9345
+ TokenTypes.eof = new TokenType("EOF", TokenClass.token, "");
9346
+ TokenTypes.reserved = {
9347
+ asm: new TokenType("asm", TokenClass.reserved, "asm"),
9348
+ bf16: new TokenType("bf16", TokenClass.reserved, "bf16"),
9349
+ do: new TokenType("do", TokenClass.reserved, "do"),
9350
+ enum: new TokenType("enum", TokenClass.reserved, "enum"),
9351
+ f16: new TokenType("f16", TokenClass.reserved, "f16"),
9352
+ f64: new TokenType("f64", TokenClass.reserved, "f64"),
9353
+ handle: new TokenType("handle", TokenClass.reserved, "handle"),
9354
+ i8: new TokenType("i8", TokenClass.reserved, "i8"),
9355
+ i16: new TokenType("i16", TokenClass.reserved, "i16"),
9356
+ i64: new TokenType("i64", TokenClass.reserved, "i64"),
9357
+ mat: new TokenType("mat", TokenClass.reserved, "mat"),
9358
+ premerge: new TokenType("premerge", TokenClass.reserved, "premerge"),
9359
+ regardless: new TokenType("regardless", TokenClass.reserved, "regardless"),
9360
+ typedef: new TokenType("typedef", TokenClass.reserved, "typedef"),
9361
+ u8: new TokenType("u8", TokenClass.reserved, "u8"),
9362
+ u16: new TokenType("u16", TokenClass.reserved, "u16"),
9363
+ u64: new TokenType("u64", TokenClass.reserved, "u64"),
9364
+ unless: new TokenType("unless", TokenClass.reserved, "unless"),
9365
+ using: new TokenType("using", TokenClass.reserved, "using"),
9366
+ vec: new TokenType("vec", TokenClass.reserved, "vec"),
9367
+ void: new TokenType("void", TokenClass.reserved, "void")
9368
+ };
9369
+ TokenTypes.keywords = {
9370
+ array: new TokenType("array", TokenClass.keyword, "array"),
9371
+ atomic: new TokenType("atomic", TokenClass.keyword, "atomic"),
9372
+ bool: new TokenType("bool", TokenClass.keyword, "bool"),
9373
+ f32: new TokenType("f32", TokenClass.keyword, "f32"),
9374
+ i32: new TokenType("i32", TokenClass.keyword, "i32"),
9375
+ mat2x2: new TokenType("mat2x2", TokenClass.keyword, "mat2x2"),
9376
+ mat2x3: new TokenType("mat2x3", TokenClass.keyword, "mat2x3"),
9377
+ mat2x4: new TokenType("mat2x4", TokenClass.keyword, "mat2x4"),
9378
+ mat3x2: new TokenType("mat3x2", TokenClass.keyword, "mat3x2"),
9379
+ mat3x3: new TokenType("mat3x3", TokenClass.keyword, "mat3x3"),
9380
+ mat3x4: new TokenType("mat3x4", TokenClass.keyword, "mat3x4"),
9381
+ mat4x2: new TokenType("mat4x2", TokenClass.keyword, "mat4x2"),
9382
+ mat4x3: new TokenType("mat4x3", TokenClass.keyword, "mat4x3"),
9383
+ mat4x4: new TokenType("mat4x4", TokenClass.keyword, "mat4x4"),
9384
+ ptr: new TokenType("ptr", TokenClass.keyword, "ptr"),
9385
+ sampler: new TokenType("sampler", TokenClass.keyword, "sampler"),
9386
+ sampler_comparison: new TokenType("sampler_comparison", TokenClass.keyword, "sampler_comparison"),
9387
+ struct: new TokenType("struct", TokenClass.keyword, "struct"),
9388
+ texture_1d: new TokenType("texture_1d", TokenClass.keyword, "texture_1d"),
9389
+ texture_2d: new TokenType("texture_2d", TokenClass.keyword, "texture_2d"),
9390
+ texture_2d_array: new TokenType("texture_2d_array", TokenClass.keyword, "texture_2d_array"),
9391
+ texture_3d: new TokenType("texture_3d", TokenClass.keyword, "texture_3d"),
9392
+ texture_cube: new TokenType("texture_cube", TokenClass.keyword, "texture_cube"),
9393
+ texture_cube_array: new TokenType("texture_cube_array", TokenClass.keyword, "texture_cube_array"),
9394
+ texture_multisampled_2d: new TokenType("texture_multisampled_2d", TokenClass.keyword, "texture_multisampled_2d"),
9395
+ texture_storage_1d: new TokenType("texture_storage_1d", TokenClass.keyword, "texture_storage_1d"),
9396
+ texture_storage_2d: new TokenType("texture_storage_2d", TokenClass.keyword, "texture_storage_2d"),
9397
+ texture_storage_2d_array: new TokenType("texture_storage_2d_array", TokenClass.keyword, "texture_storage_2d_array"),
9398
+ texture_storage_3d: new TokenType("texture_storage_3d", TokenClass.keyword, "texture_storage_3d"),
9399
+ texture_depth_2d: new TokenType("texture_depth_2d", TokenClass.keyword, "texture_depth_2d"),
9400
+ texture_depth_2d_array: new TokenType("texture_depth_2d_array", TokenClass.keyword, "texture_depth_2d_array"),
9401
+ texture_depth_cube: new TokenType("texture_depth_cube", TokenClass.keyword, "texture_depth_cube"),
9402
+ texture_depth_cube_array: new TokenType("texture_depth_cube_array", TokenClass.keyword, "texture_depth_cube_array"),
9403
+ texture_depth_multisampled_2d: new TokenType("texture_depth_multisampled_2d", TokenClass.keyword, "texture_depth_multisampled_2d"),
9404
+ texture_external: new TokenType("texture_external", TokenClass.keyword, "texture_external"),
9405
+ u32: new TokenType("u32", TokenClass.keyword, "u32"),
9406
+ vec2: new TokenType("vec2", TokenClass.keyword, "vec2"),
9407
+ vec3: new TokenType("vec3", TokenClass.keyword, "vec3"),
9408
+ vec4: new TokenType("vec4", TokenClass.keyword, "vec4"),
9409
+ bitcast: new TokenType("bitcast", TokenClass.keyword, "bitcast"),
9410
+ block: new TokenType("block", TokenClass.keyword, "block"),
9411
+ break: new TokenType("break", TokenClass.keyword, "break"),
9412
+ case: new TokenType("case", TokenClass.keyword, "case"),
9413
+ continue: new TokenType("continue", TokenClass.keyword, "continue"),
9414
+ continuing: new TokenType("continuing", TokenClass.keyword, "continuing"),
9415
+ default: new TokenType("default", TokenClass.keyword, "default"),
9416
+ discard: new TokenType("discard", TokenClass.keyword, "discard"),
9417
+ else: new TokenType("else", TokenClass.keyword, "else"),
9418
+ enable: new TokenType("enable", TokenClass.keyword, "enable"),
9419
+ fallthrough: new TokenType("fallthrough", TokenClass.keyword, "fallthrough"),
9420
+ false: new TokenType("false", TokenClass.keyword, "false"),
9421
+ fn: new TokenType("fn", TokenClass.keyword, "fn"),
9422
+ for: new TokenType("for", TokenClass.keyword, "for"),
9423
+ function: new TokenType("function", TokenClass.keyword, "function"),
9424
+ if: new TokenType("if", TokenClass.keyword, "if"),
9425
+ let: new TokenType("let", TokenClass.keyword, "let"),
9426
+ const: new TokenType("const", TokenClass.keyword, "const"),
9427
+ loop: new TokenType("loop", TokenClass.keyword, "loop"),
9428
+ while: new TokenType("while", TokenClass.keyword, "while"),
9429
+ private: new TokenType("private", TokenClass.keyword, "private"),
9430
+ read: new TokenType("read", TokenClass.keyword, "read"),
9431
+ read_write: new TokenType("read_write", TokenClass.keyword, "read_write"),
9432
+ return: new TokenType("return", TokenClass.keyword, "return"),
9433
+ storage: new TokenType("storage", TokenClass.keyword, "storage"),
9434
+ switch: new TokenType("switch", TokenClass.keyword, "switch"),
9435
+ true: new TokenType("true", TokenClass.keyword, "true"),
9436
+ alias: new TokenType("alias", TokenClass.keyword, "alias"),
9437
+ type: new TokenType("type", TokenClass.keyword, "type"),
9438
+ uniform: new TokenType("uniform", TokenClass.keyword, "uniform"),
9439
+ var: new TokenType("var", TokenClass.keyword, "var"),
9440
+ override: new TokenType("override", TokenClass.keyword, "override"),
9441
+ workgroup: new TokenType("workgroup", TokenClass.keyword, "workgroup"),
9442
+ write: new TokenType("write", TokenClass.keyword, "write"),
9443
+ r8unorm: new TokenType("r8unorm", TokenClass.keyword, "r8unorm"),
9444
+ r8snorm: new TokenType("r8snorm", TokenClass.keyword, "r8snorm"),
9445
+ r8uint: new TokenType("r8uint", TokenClass.keyword, "r8uint"),
9446
+ r8sint: new TokenType("r8sint", TokenClass.keyword, "r8sint"),
9447
+ r16uint: new TokenType("r16uint", TokenClass.keyword, "r16uint"),
9448
+ r16sint: new TokenType("r16sint", TokenClass.keyword, "r16sint"),
9449
+ r16float: new TokenType("r16float", TokenClass.keyword, "r16float"),
9450
+ rg8unorm: new TokenType("rg8unorm", TokenClass.keyword, "rg8unorm"),
9451
+ rg8snorm: new TokenType("rg8snorm", TokenClass.keyword, "rg8snorm"),
9452
+ rg8uint: new TokenType("rg8uint", TokenClass.keyword, "rg8uint"),
9453
+ rg8sint: new TokenType("rg8sint", TokenClass.keyword, "rg8sint"),
9454
+ r32uint: new TokenType("r32uint", TokenClass.keyword, "r32uint"),
9455
+ r32sint: new TokenType("r32sint", TokenClass.keyword, "r32sint"),
9456
+ r32float: new TokenType("r32float", TokenClass.keyword, "r32float"),
9457
+ rg16uint: new TokenType("rg16uint", TokenClass.keyword, "rg16uint"),
9458
+ rg16sint: new TokenType("rg16sint", TokenClass.keyword, "rg16sint"),
9459
+ rg16float: new TokenType("rg16float", TokenClass.keyword, "rg16float"),
9460
+ rgba8unorm: new TokenType("rgba8unorm", TokenClass.keyword, "rgba8unorm"),
9461
+ rgba8unorm_srgb: new TokenType("rgba8unorm_srgb", TokenClass.keyword, "rgba8unorm_srgb"),
9462
+ rgba8snorm: new TokenType("rgba8snorm", TokenClass.keyword, "rgba8snorm"),
9463
+ rgba8uint: new TokenType("rgba8uint", TokenClass.keyword, "rgba8uint"),
9464
+ rgba8sint: new TokenType("rgba8sint", TokenClass.keyword, "rgba8sint"),
9465
+ bgra8unorm: new TokenType("bgra8unorm", TokenClass.keyword, "bgra8unorm"),
9466
+ bgra8unorm_srgb: new TokenType("bgra8unorm_srgb", TokenClass.keyword, "bgra8unorm_srgb"),
9467
+ rgb10a2unorm: new TokenType("rgb10a2unorm", TokenClass.keyword, "rgb10a2unorm"),
9468
+ rg11b10float: new TokenType("rg11b10float", TokenClass.keyword, "rg11b10float"),
9469
+ rg32uint: new TokenType("rg32uint", TokenClass.keyword, "rg32uint"),
9470
+ rg32sint: new TokenType("rg32sint", TokenClass.keyword, "rg32sint"),
9471
+ rg32float: new TokenType("rg32float", TokenClass.keyword, "rg32float"),
9472
+ rgba16uint: new TokenType("rgba16uint", TokenClass.keyword, "rgba16uint"),
9473
+ rgba16sint: new TokenType("rgba16sint", TokenClass.keyword, "rgba16sint"),
9474
+ rgba16float: new TokenType("rgba16float", TokenClass.keyword, "rgba16float"),
9475
+ rgba32uint: new TokenType("rgba32uint", TokenClass.keyword, "rgba32uint"),
9476
+ rgba32sint: new TokenType("rgba32sint", TokenClass.keyword, "rgba32sint"),
9477
+ rgba32float: new TokenType("rgba32float", TokenClass.keyword, "rgba32float"),
9478
+ static_assert: new TokenType("static_assert", TokenClass.keyword, "static_assert")
9479
+ };
9480
+ TokenTypes.tokens = {
9481
+ 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)/),
9482
+ 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?))/),
9483
+ int_literal: new TokenType("int_literal", TokenClass.token, /-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),
9484
+ uint_literal: new TokenType("uint_literal", TokenClass.token, /0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),
9485
+ ident: new TokenType("ident", TokenClass.token, /[a-zA-Z][0-9a-zA-Z_]*/),
9486
+ and: new TokenType("and", TokenClass.token, "&"),
9487
+ and_and: new TokenType("and_and", TokenClass.token, "&&"),
9488
+ arrow: new TokenType("arrow ", TokenClass.token, "->"),
9489
+ attr: new TokenType("attr", TokenClass.token, "@"),
9490
+ attr_left: new TokenType("attr_left", TokenClass.token, "[["),
9491
+ attr_right: new TokenType("attr_right", TokenClass.token, "]]"),
9492
+ forward_slash: new TokenType("forward_slash", TokenClass.token, "/"),
9493
+ bang: new TokenType("bang", TokenClass.token, "!"),
9494
+ bracket_left: new TokenType("bracket_left", TokenClass.token, "["),
9495
+ bracket_right: new TokenType("bracket_right", TokenClass.token, "]"),
9496
+ brace_left: new TokenType("brace_left", TokenClass.token, "{"),
9497
+ brace_right: new TokenType("brace_right", TokenClass.token, "}"),
9498
+ colon: new TokenType("colon", TokenClass.token, ":"),
9499
+ comma: new TokenType("comma", TokenClass.token, ","),
9500
+ equal: new TokenType("equal", TokenClass.token, "="),
9501
+ equal_equal: new TokenType("equal_equal", TokenClass.token, "=="),
9502
+ not_equal: new TokenType("not_equal", TokenClass.token, "!="),
9503
+ greater_than: new TokenType("greater_than", TokenClass.token, ">"),
9504
+ greater_than_equal: new TokenType("greater_than_equal", TokenClass.token, ">="),
9505
+ shift_right: new TokenType("shift_right", TokenClass.token, ">>"),
9506
+ less_than: new TokenType("less_than", TokenClass.token, "<"),
9507
+ less_than_equal: new TokenType("less_than_equal", TokenClass.token, "<="),
9508
+ shift_left: new TokenType("shift_left", TokenClass.token, "<<"),
9509
+ modulo: new TokenType("modulo", TokenClass.token, "%"),
9510
+ minus: new TokenType("minus", TokenClass.token, "-"),
9511
+ minus_minus: new TokenType("minus_minus", TokenClass.token, "--"),
9512
+ period: new TokenType("period", TokenClass.token, "."),
9513
+ plus: new TokenType("plus", TokenClass.token, "+"),
9514
+ plus_plus: new TokenType("plus_plus", TokenClass.token, "++"),
9515
+ or: new TokenType("or", TokenClass.token, "|"),
9516
+ or_or: new TokenType("or_or", TokenClass.token, "||"),
9517
+ paren_left: new TokenType("paren_left", TokenClass.token, "("),
9518
+ paren_right: new TokenType("paren_right", TokenClass.token, ")"),
9519
+ semicolon: new TokenType("semicolon", TokenClass.token, ";"),
9520
+ star: new TokenType("star", TokenClass.token, "*"),
9521
+ tilde: new TokenType("tilde", TokenClass.token, "~"),
9522
+ underscore: new TokenType("underscore", TokenClass.token, "_"),
9523
+ xor: new TokenType("xor", TokenClass.token, "^"),
9524
+ plus_equal: new TokenType("plus_equal", TokenClass.token, "+="),
9525
+ minus_equal: new TokenType("minus_equal", TokenClass.token, "-="),
9526
+ times_equal: new TokenType("times_equal", TokenClass.token, "*="),
9527
+ division_equal: new TokenType("division_equal", TokenClass.token, "/="),
9528
+ modulo_equal: new TokenType("modulo_equal", TokenClass.token, "%="),
9529
+ and_equal: new TokenType("and_equal", TokenClass.token, "&="),
9530
+ or_equal: new TokenType("or_equal", TokenClass.token, "|="),
9531
+ xor_equal: new TokenType("xor_equal", TokenClass.token, "^="),
9532
+ shift_right_equal: new TokenType("shift_right_equal", TokenClass.token, ">>="),
9533
+ shift_left_equal: new TokenType("shift_left_equal", TokenClass.token, "<<=")
9534
+ };
9535
+ TokenTypes.storage_class = [_a.keywords.function, _a.keywords.private, _a.keywords.workgroup, _a.keywords.uniform, _a.keywords.storage];
9536
+ TokenTypes.access_mode = [_a.keywords.read, _a.keywords.write, _a.keywords.read_write];
9537
+ TokenTypes.sampler_type = [_a.keywords.sampler, _a.keywords.sampler_comparison];
9538
+ 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];
9539
+ TokenTypes.multisampled_texture_type = [_a.keywords.texture_multisampled_2d];
9540
+ 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];
9541
+ 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];
9542
+ TokenTypes.texture_external_type = [_a.keywords.texture_external];
9543
+ TokenTypes.any_texture_type = [..._a.sampled_texture_type, ..._a.multisampled_texture_type, ..._a.storage_texture_type, ..._a.depth_texture_type, ..._a.texture_external_type];
9544
+ 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];
9545
+ 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];
9546
+ 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];
9547
+ TokenTypes.element_count_expression = [_a.tokens.int_literal, _a.tokens.uint_literal, _a.tokens.ident];
9548
+ 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];
9549
+ TokenTypes.attribute_name = [_a.tokens.ident, _a.keywords.block];
9550
+ 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];
9551
+ TokenTypes.increment_operators = [_a.tokens.plus_plus, _a.tokens.minus_minus];
9552
+ var Token = class {
9553
+ constructor(type, lexeme, line) {
9554
+ this.type = type;
9555
+ this.lexeme = lexeme;
9556
+ this.line = line;
9557
+ }
9558
+ toString() {
9559
+ return this.lexeme;
9560
+ }
9561
+ isTemplateType() {
9562
+ return TokenTypes.template_types.indexOf(this.type) != -1;
9563
+ }
9564
+ isArrayType() {
9565
+ return this.type == TokenTypes.keywords.array;
9566
+ }
9567
+ isArrayOrTemplateType() {
9568
+ return this.isArrayType() || this.isTemplateType();
9569
+ }
9570
+ };
9571
+ var WgslScanner = class {
9572
+ constructor(source) {
9573
+ this._tokens = [];
9574
+ this._start = 0;
9575
+ this._current = 0;
9576
+ this._line = 1;
9577
+ this._source = source !== null && source !== void 0 ? source : "";
9578
+ }
9579
+ scanTokens() {
9580
+ while (!this._isAtEnd()) {
9581
+ this._start = this._current;
9582
+ if (!this.scanToken())
9583
+ throw `Invalid syntax at line ${this._line}`;
9584
+ }
9585
+ this._tokens.push(new Token(TokenTypes.eof, "", this._line));
9586
+ return this._tokens;
9587
+ }
9588
+ scanToken() {
9589
+ let lexeme = this._advance();
9590
+ if (lexeme == "\n") {
9591
+ this._line++;
9592
+ return true;
9593
+ }
9594
+ if (this._isWhitespace(lexeme)) {
9595
+ return true;
9596
+ }
9597
+ if (lexeme == "/") {
9598
+ if (this._peekAhead() == "/") {
9599
+ while (lexeme != "\n") {
9600
+ if (this._isAtEnd())
9601
+ return true;
9602
+ lexeme = this._advance();
9603
+ }
9604
+ this._line++;
9605
+ return true;
9606
+ } else if (this._peekAhead() == "*") {
9607
+ this._advance();
9608
+ let commentLevel = 1;
9609
+ while (commentLevel > 0) {
9610
+ if (this._isAtEnd())
9611
+ return true;
9612
+ lexeme = this._advance();
9613
+ if (lexeme == "\n") {
9614
+ this._line++;
9615
+ } else if (lexeme == "*") {
9616
+ if (this._peekAhead() == "/") {
9617
+ this._advance();
9618
+ commentLevel--;
9619
+ if (commentLevel == 0) {
9620
+ return true;
9621
+ }
9622
+ }
9623
+ } else if (lexeme == "/") {
9624
+ if (this._peekAhead() == "*") {
9625
+ this._advance();
9626
+ commentLevel++;
9627
+ }
9628
+ }
9629
+ }
9630
+ return true;
9631
+ }
9632
+ }
9633
+ let matchType = TokenTypes.none;
9634
+ for (; ; ) {
9635
+ let matchedType = this._findType(lexeme);
9636
+ const nextLexeme = this._peekAhead();
9637
+ if (lexeme == ">" && (nextLexeme == ">" || nextLexeme == "=")) {
9638
+ let foundLessThan = false;
9639
+ let ti = this._tokens.length - 1;
9640
+ for (let count = 0; count < 5 && ti >= 0; ++count, --ti) {
9641
+ if (this._tokens[ti].type === TokenTypes.tokens.less_than) {
9642
+ if (ti > 0 && this._tokens[ti - 1].isArrayOrTemplateType()) {
9643
+ foundLessThan = true;
9644
+ }
9645
+ break;
9646
+ }
9647
+ }
9648
+ if (foundLessThan) {
9649
+ this._addToken(matchedType);
9650
+ return true;
9651
+ }
9652
+ }
9653
+ if (matchedType === TokenTypes.none) {
9654
+ let lookAheadLexeme = lexeme;
9655
+ let lookAhead = 0;
9656
+ const maxLookAhead = 2;
9657
+ for (let li = 0; li < maxLookAhead; ++li) {
9658
+ lookAheadLexeme += this._peekAhead(li);
9659
+ matchedType = this._findType(lookAheadLexeme);
9660
+ if (matchedType !== TokenTypes.none) {
9661
+ lookAhead = li;
9662
+ break;
9663
+ }
9664
+ }
9665
+ if (matchedType === TokenTypes.none) {
9666
+ if (matchType === TokenTypes.none)
9667
+ return false;
9668
+ this._current--;
9669
+ this._addToken(matchType);
9670
+ return true;
9671
+ }
9672
+ lexeme = lookAheadLexeme;
9673
+ this._current += lookAhead + 1;
9674
+ }
9675
+ matchType = matchedType;
9676
+ if (this._isAtEnd())
9677
+ break;
9678
+ lexeme += this._advance();
9679
+ }
9680
+ if (matchType === TokenTypes.none)
9681
+ return false;
9682
+ this._addToken(matchType);
9683
+ return true;
9684
+ }
9685
+ _findType(lexeme) {
9686
+ for (const name in TokenTypes.keywords) {
9687
+ const type = TokenTypes.keywords[name];
9688
+ if (this._match(lexeme, type.rule)) {
9689
+ return type;
9690
+ }
9691
+ }
9692
+ for (const name in TokenTypes.tokens) {
9693
+ const type = TokenTypes.tokens[name];
9694
+ if (this._match(lexeme, type.rule)) {
9695
+ return type;
9696
+ }
9697
+ }
9698
+ return TokenTypes.none;
9699
+ }
9700
+ _match(lexeme, rule) {
9701
+ if (typeof rule === "string") {
9702
+ if (rule == lexeme) {
9703
+ return true;
9704
+ }
9705
+ } else {
9706
+ const match = rule.exec(lexeme);
9707
+ if (match && match.index == 0 && match[0] == lexeme)
9708
+ return true;
9709
+ }
9710
+ return false;
9711
+ }
9712
+ _isAtEnd() {
9713
+ return this._current >= this._source.length;
9714
+ }
9715
+ _isWhitespace(c) {
9716
+ return c == " " || c == " " || c == "\r";
9717
+ }
9718
+ _advance() {
9719
+ let amount = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
9720
+ let c = this._source[this._current];
9721
+ amount = amount || 0;
9722
+ amount++;
9723
+ this._current += amount;
9724
+ return c;
9725
+ }
9726
+ _peekAhead() {
9727
+ let offset = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
9728
+ offset = offset || 0;
9729
+ if (this._current + offset >= this._source.length)
9730
+ return "\0";
9731
+ return this._source[this._current + offset];
9732
+ }
9733
+ _addToken(type) {
9734
+ const text = this._source.substring(this._start, this._current);
9735
+ this._tokens.push(new Token(type, text, this._line));
9736
+ }
9737
+ };
9738
+ var WgslParser = class {
9739
+ constructor() {
9740
+ this._tokens = [];
9741
+ this._current = 0;
9742
+ this._context = new ParseContext();
9743
+ }
9744
+ parse(tokensOrCode) {
9745
+ this._initialize(tokensOrCode);
9746
+ let statements = [];
9747
+ while (!this._isAtEnd()) {
9748
+ const statement = this._global_decl_or_directive();
9749
+ if (!statement)
9750
+ break;
9751
+ statements.push(statement);
9752
+ }
9753
+ return statements;
9754
+ }
9755
+ _initialize(tokensOrCode) {
9756
+ if (tokensOrCode) {
9757
+ if (typeof tokensOrCode == "string") {
9758
+ const scanner = new WgslScanner(tokensOrCode);
9759
+ this._tokens = scanner.scanTokens();
9760
+ } else {
9761
+ this._tokens = tokensOrCode;
9762
+ }
9763
+ } else {
9764
+ this._tokens = [];
9765
+ }
9766
+ this._current = 0;
9767
+ }
9768
+ _error(token, message2) {
9769
+ console.error(token, message2);
9770
+ return {
9771
+ token,
9772
+ message: message2,
9773
+ toString: function() {
9774
+ return `${message2}`;
9775
+ }
9776
+ };
9777
+ }
9778
+ _isAtEnd() {
9779
+ return this._current >= this._tokens.length || this._peek().type == TokenTypes.eof;
9780
+ }
9781
+ _match(types) {
9782
+ if (types instanceof TokenType) {
9783
+ if (this._check(types)) {
9784
+ this._advance();
9785
+ return true;
9786
+ }
9787
+ return false;
9788
+ }
9789
+ for (let i = 0, l = types.length; i < l; ++i) {
9790
+ const type = types[i];
9791
+ if (this._check(type)) {
9792
+ this._advance();
9793
+ return true;
9794
+ }
9795
+ }
9796
+ return false;
9797
+ }
9798
+ _consume(types, message2) {
9799
+ if (this._check(types))
9800
+ return this._advance();
9801
+ throw this._error(this._peek(), message2);
9802
+ }
9803
+ _check(types) {
9804
+ if (this._isAtEnd())
9805
+ return false;
9806
+ const tk = this._peek();
9807
+ if (types instanceof Array) {
9808
+ let t = tk.type;
9809
+ let index2 = types.indexOf(t);
9810
+ return index2 != -1;
9811
+ }
9812
+ return tk.type == types;
9813
+ }
9814
+ _advance() {
9815
+ if (!this._isAtEnd())
9816
+ this._current++;
9817
+ return this._previous();
9818
+ }
9819
+ _peek() {
9820
+ return this._tokens[this._current];
9821
+ }
9822
+ _previous() {
9823
+ return this._tokens[this._current - 1];
9824
+ }
9825
+ _global_decl_or_directive() {
9826
+ while (this._match(TokenTypes.tokens.semicolon) && !this._isAtEnd())
9827
+ ;
9828
+ if (this._match(TokenTypes.keywords.alias)) {
9829
+ const type = this._type_alias();
9830
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
9831
+ return type;
9832
+ }
9833
+ if (this._match(TokenTypes.keywords.enable)) {
9834
+ const enable2 = this._enable_directive();
9835
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
9836
+ return enable2;
9837
+ }
9838
+ const attrs = this._attribute();
9839
+ if (this._check(TokenTypes.keywords.var)) {
9840
+ const _var = this._global_variable_decl();
9841
+ if (_var != null)
9842
+ _var.attributes = attrs;
9843
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
9844
+ return _var;
9845
+ }
9846
+ if (this._check(TokenTypes.keywords.override)) {
9847
+ const _override = this._override_variable_decl();
9848
+ if (_override != null)
9849
+ _override.attributes = attrs;
9850
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
9851
+ return _override;
9852
+ }
9853
+ if (this._check(TokenTypes.keywords.let)) {
9854
+ const _let = this._global_let_decl();
9855
+ if (_let != null)
9856
+ _let.attributes = attrs;
9857
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
9858
+ return _let;
9859
+ }
9860
+ if (this._check(TokenTypes.keywords.const)) {
9861
+ const _const = this._global_const_decl();
9862
+ if (_const != null)
9863
+ _const.attributes = attrs;
9864
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
9865
+ return _const;
9866
+ }
9867
+ if (this._check(TokenTypes.keywords.struct)) {
9868
+ const _struct = this._struct_decl();
9869
+ if (_struct != null)
9870
+ _struct.attributes = attrs;
9871
+ return _struct;
9872
+ }
9873
+ if (this._check(TokenTypes.keywords.fn)) {
9874
+ const _fn = this._function_decl();
9875
+ if (_fn != null)
9876
+ _fn.attributes = attrs;
9877
+ return _fn;
9878
+ }
9879
+ return null;
9880
+ }
9881
+ _function_decl() {
9882
+ if (!this._match(TokenTypes.keywords.fn))
9883
+ return null;
9884
+ const name = this._consume(TokenTypes.tokens.ident, "Expected function name.").toString();
9885
+ this._consume(TokenTypes.tokens.paren_left, "Expected '(' for function arguments.");
9886
+ const args = [];
9887
+ if (!this._check(TokenTypes.tokens.paren_right)) {
9888
+ do {
9889
+ if (this._check(TokenTypes.tokens.paren_right))
9890
+ break;
9891
+ const argAttrs = this._attribute();
9892
+ const name2 = this._consume(TokenTypes.tokens.ident, "Expected argument name.").toString();
9893
+ this._consume(TokenTypes.tokens.colon, "Expected ':' for argument type.");
9894
+ const typeAttrs = this._attribute();
9895
+ const type = this._type_decl();
9896
+ if (type != null) {
9897
+ type.attributes = typeAttrs;
9898
+ args.push(new Argument(name2, type, argAttrs));
9899
+ }
9900
+ } while (this._match(TokenTypes.tokens.comma));
9901
+ }
9902
+ this._consume(TokenTypes.tokens.paren_right, "Expected ')' after function arguments.");
9903
+ let _return = null;
9904
+ if (this._match(TokenTypes.tokens.arrow)) {
9905
+ const attrs = this._attribute();
9906
+ _return = this._type_decl();
9907
+ if (_return != null)
9908
+ _return.attributes = attrs;
9909
+ }
9910
+ const body = this._compound_statement();
9911
+ return new Function(name, args, _return, body);
9912
+ }
9913
+ _compound_statement() {
9914
+ const statements = [];
9915
+ this._consume(TokenTypes.tokens.brace_left, "Expected '{' for block.");
9916
+ while (!this._check(TokenTypes.tokens.brace_right)) {
9917
+ const statement = this._statement();
9918
+ if (statement !== null)
9919
+ statements.push(statement);
9920
+ }
9921
+ this._consume(TokenTypes.tokens.brace_right, "Expected '}' for block.");
9922
+ return statements;
9923
+ }
9924
+ _statement() {
9925
+ while (this._match(TokenTypes.tokens.semicolon) && !this._isAtEnd())
9926
+ ;
9927
+ if (this._check(TokenTypes.keywords.if))
9928
+ return this._if_statement();
9929
+ if (this._check(TokenTypes.keywords.switch))
9930
+ return this._switch_statement();
9931
+ if (this._check(TokenTypes.keywords.loop))
9932
+ return this._loop_statement();
9933
+ if (this._check(TokenTypes.keywords.for))
9934
+ return this._for_statement();
9935
+ if (this._check(TokenTypes.keywords.while))
9936
+ return this._while_statement();
9937
+ if (this._check(TokenTypes.keywords.continuing))
9938
+ return this._continuing_statement();
9939
+ if (this._check(TokenTypes.keywords.static_assert))
9940
+ return this._static_assert_statement();
9941
+ if (this._check(TokenTypes.tokens.brace_left))
9942
+ return this._compound_statement();
9943
+ let result = null;
9944
+ if (this._check(TokenTypes.keywords.return))
9945
+ result = this._return_statement();
9946
+ else if (this._check([TokenTypes.keywords.var, TokenTypes.keywords.let, TokenTypes.keywords.const]))
9947
+ result = this._variable_statement();
9948
+ else if (this._match(TokenTypes.keywords.discard))
9949
+ result = new Discard();
9950
+ else if (this._match(TokenTypes.keywords.break))
9951
+ result = new Break();
9952
+ else if (this._match(TokenTypes.keywords.continue))
9953
+ result = new Continue();
9954
+ else
9955
+ result = this._increment_decrement_statement() || this._func_call_statement() || this._assignment_statement();
9956
+ if (result != null)
9957
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';' after statement.");
9958
+ return result;
9959
+ }
9960
+ _static_assert_statement() {
9961
+ if (!this._match(TokenTypes.keywords.static_assert))
9962
+ return null;
9963
+ let expression = this._optional_paren_expression();
9964
+ return new StaticAssert(expression);
9965
+ }
9966
+ _while_statement() {
9967
+ if (!this._match(TokenTypes.keywords.while))
9968
+ return null;
9969
+ let condition = this._optional_paren_expression();
9970
+ const block = this._compound_statement();
9971
+ return new While(condition, block);
9972
+ }
9973
+ _continuing_statement() {
9974
+ if (!this._match(TokenTypes.keywords.continuing))
9975
+ return null;
9976
+ const block = this._compound_statement();
9977
+ return new Continuing(block);
9978
+ }
9979
+ _for_statement() {
9980
+ if (!this._match(TokenTypes.keywords.for))
9981
+ return null;
9982
+ this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
9983
+ const init = !this._check(TokenTypes.tokens.semicolon) ? this._for_init() : null;
9984
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
9985
+ const condition = !this._check(TokenTypes.tokens.semicolon) ? this._short_circuit_or_expression() : null;
9986
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
9987
+ const increment = !this._check(TokenTypes.tokens.paren_right) ? this._for_increment() : null;
9988
+ this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
9989
+ const body = this._compound_statement();
9990
+ return new For(init, condition, increment, body);
9991
+ }
9992
+ _for_init() {
9993
+ return this._variable_statement() || this._func_call_statement() || this._assignment_statement();
9994
+ }
9995
+ _for_increment() {
9996
+ return this._func_call_statement() || this._increment_decrement_statement() || this._assignment_statement();
9997
+ }
9998
+ _variable_statement() {
9999
+ if (this._check(TokenTypes.keywords.var)) {
10000
+ const _var = this._variable_decl();
10001
+ if (_var === null)
10002
+ throw this._error(this._peek(), "Variable declaration expected.");
10003
+ let value = null;
10004
+ if (this._match(TokenTypes.tokens.equal))
10005
+ value = this._short_circuit_or_expression();
10006
+ return new Var(_var.name, _var.type, _var.storage, _var.access, value);
10007
+ }
10008
+ if (this._match(TokenTypes.keywords.let)) {
10009
+ const name = this._consume(TokenTypes.tokens.ident, "Expected name for let.").toString();
10010
+ let type = null;
10011
+ if (this._match(TokenTypes.tokens.colon)) {
10012
+ const typeAttrs = this._attribute();
10013
+ type = this._type_decl();
10014
+ if (type != null)
10015
+ type.attributes = typeAttrs;
10016
+ }
10017
+ this._consume(TokenTypes.tokens.equal, "Expected '=' for let.");
10018
+ const value = this._short_circuit_or_expression();
10019
+ return new Let(name, type, null, null, value);
10020
+ }
10021
+ if (this._match(TokenTypes.keywords.const)) {
10022
+ const name = this._consume(TokenTypes.tokens.ident, "Expected name for const.").toString();
10023
+ let type = null;
10024
+ if (this._match(TokenTypes.tokens.colon)) {
10025
+ const typeAttrs = this._attribute();
10026
+ type = this._type_decl();
10027
+ if (type != null)
10028
+ type.attributes = typeAttrs;
10029
+ }
10030
+ this._consume(TokenTypes.tokens.equal, "Expected '=' for const.");
10031
+ const value = this._short_circuit_or_expression();
10032
+ return new Const(name, type, null, null, value);
10033
+ }
10034
+ return null;
10035
+ }
10036
+ _increment_decrement_statement() {
10037
+ const savedPos = this._current;
10038
+ const _var = this._unary_expression();
10039
+ if (_var == null)
10040
+ return null;
10041
+ if (!this._check(TokenTypes.increment_operators)) {
10042
+ this._current = savedPos;
10043
+ return null;
10044
+ }
10045
+ const token = this._consume(TokenTypes.increment_operators, "Expected increment operator");
10046
+ return new Increment(token.type === TokenTypes.tokens.plus_plus ? IncrementOperator.increment : IncrementOperator.decrement, _var);
10047
+ }
10048
+ _assignment_statement() {
10049
+ let _var = null;
10050
+ if (this._check(TokenTypes.tokens.brace_right))
10051
+ return null;
10052
+ let isUnderscore = this._match(TokenTypes.tokens.underscore);
10053
+ if (!isUnderscore)
10054
+ _var = this._unary_expression();
10055
+ if (!isUnderscore && _var == null)
10056
+ return null;
10057
+ const type = this._consume(TokenTypes.assignment_operators, "Expected assignment operator.");
10058
+ const value = this._short_circuit_or_expression();
10059
+ return new Assign(AssignOperator.parse(type.lexeme), _var, value);
10060
+ }
10061
+ _func_call_statement() {
10062
+ if (!this._check(TokenTypes.tokens.ident))
10063
+ return null;
10064
+ const savedPos = this._current;
10065
+ const name = this._consume(TokenTypes.tokens.ident, "Expected function name.");
10066
+ const args = this._argument_expression_list();
10067
+ if (args === null) {
10068
+ this._current = savedPos;
10069
+ return null;
10070
+ }
10071
+ return new Call(name.lexeme, args);
10072
+ }
10073
+ _loop_statement() {
10074
+ if (!this._match(TokenTypes.keywords.loop))
10075
+ return null;
10076
+ this._consume(TokenTypes.tokens.brace_left, "Expected '{' for loop.");
10077
+ const statements = [];
10078
+ let statement = this._statement();
10079
+ while (statement !== null) {
10080
+ if (Array.isArray(statement)) {
10081
+ for (let s of statement) {
10082
+ statements.push(s);
10083
+ }
10084
+ } else {
10085
+ statements.push(statement);
10086
+ }
10087
+ statement = this._statement();
10088
+ }
10089
+ let continuing = null;
10090
+ if (this._match(TokenTypes.keywords.continuing))
10091
+ continuing = this._compound_statement();
10092
+ this._consume(TokenTypes.tokens.brace_right, "Expected '}' for loop.");
10093
+ return new Loop(statements, continuing);
10094
+ }
10095
+ _switch_statement() {
10096
+ if (!this._match(TokenTypes.keywords.switch))
10097
+ return null;
10098
+ const condition = this._optional_paren_expression();
10099
+ this._consume(TokenTypes.tokens.brace_left, "Expected '{' for switch.");
10100
+ const body = this._switch_body();
10101
+ if (body == null || body.length == 0)
10102
+ throw this._error(this._previous(), "Expected 'case' or 'default'.");
10103
+ this._consume(TokenTypes.tokens.brace_right, "Expected '}' for switch.");
10104
+ return new Switch(condition, body);
10105
+ }
10106
+ _switch_body() {
10107
+ const cases = [];
10108
+ if (this._match(TokenTypes.keywords.case)) {
10109
+ const selector = this._case_selectors();
10110
+ this._match(TokenTypes.tokens.colon);
10111
+ this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch case.");
10112
+ const body = this._case_body();
10113
+ this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch case.");
10114
+ cases.push(new Case(selector, body));
10115
+ }
10116
+ if (this._match(TokenTypes.keywords.default)) {
10117
+ this._match(TokenTypes.tokens.colon);
10118
+ this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch default.");
10119
+ const body = this._case_body();
10120
+ this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch default.");
10121
+ cases.push(new Default(body));
10122
+ }
10123
+ if (this._check([TokenTypes.keywords.default, TokenTypes.keywords.case])) {
10124
+ const _cases = this._switch_body();
10125
+ cases.push(_cases[0]);
10126
+ }
10127
+ return cases;
10128
+ }
10129
+ _case_selectors() {
10130
+ var _a2, _b, _c, _d;
10131
+ const selectors = [(_b = (_a2 = this._shift_expression()) === null || _a2 === void 0 ? void 0 : _a2.evaluate(this._context).toString()) !== null && _b !== void 0 ? _b : ""];
10132
+ while (this._match(TokenTypes.tokens.comma)) {
10133
+ selectors.push((_d = (_c = this._shift_expression()) === null || _c === void 0 ? void 0 : _c.evaluate(this._context).toString()) !== null && _d !== void 0 ? _d : "");
10134
+ }
10135
+ return selectors;
10136
+ }
10137
+ _case_body() {
10138
+ if (this._match(TokenTypes.keywords.fallthrough)) {
10139
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
10140
+ return [];
10141
+ }
10142
+ let statement = this._statement();
10143
+ if (statement == null)
10144
+ return [];
10145
+ if (!(statement instanceof Array)) {
10146
+ statement = [statement];
10147
+ }
10148
+ const nextStatement = this._case_body();
10149
+ if (nextStatement.length == 0)
10150
+ return statement;
10151
+ return [...statement, nextStatement[0]];
10152
+ }
10153
+ _if_statement() {
10154
+ if (!this._match(TokenTypes.keywords.if))
10155
+ return null;
10156
+ const condition = this._optional_paren_expression();
10157
+ const block = this._compound_statement();
10158
+ let elseif = [];
10159
+ if (this._match_elseif()) {
10160
+ elseif = this._elseif_statement(elseif);
10161
+ }
10162
+ let _else = null;
10163
+ if (this._match(TokenTypes.keywords.else))
10164
+ _else = this._compound_statement();
10165
+ return new If(condition, block, elseif, _else);
10166
+ }
10167
+ _match_elseif() {
10168
+ if (this._tokens[this._current].type === TokenTypes.keywords.else && this._tokens[this._current + 1].type === TokenTypes.keywords.if) {
10169
+ this._advance();
10170
+ this._advance();
10171
+ return true;
10172
+ }
10173
+ return false;
10174
+ }
10175
+ _elseif_statement() {
10176
+ let elseif = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
10177
+ const condition = this._optional_paren_expression();
10178
+ const block = this._compound_statement();
10179
+ elseif.push(new ElseIf(condition, block));
10180
+ if (this._match_elseif()) {
10181
+ this._elseif_statement(elseif);
10182
+ }
10183
+ return elseif;
10184
+ }
10185
+ _return_statement() {
10186
+ if (!this._match(TokenTypes.keywords.return))
10187
+ return null;
10188
+ const value = this._short_circuit_or_expression();
10189
+ return new Return(value);
10190
+ }
10191
+ _short_circuit_or_expression() {
10192
+ let expr = this._short_circuit_and_expr();
10193
+ while (this._match(TokenTypes.tokens.or_or)) {
10194
+ expr = new BinaryOperator(this._previous().toString(), expr, this._short_circuit_and_expr());
10195
+ }
10196
+ return expr;
10197
+ }
10198
+ _short_circuit_and_expr() {
10199
+ let expr = this._inclusive_or_expression();
10200
+ while (this._match(TokenTypes.tokens.and_and)) {
10201
+ expr = new BinaryOperator(this._previous().toString(), expr, this._inclusive_or_expression());
10202
+ }
10203
+ return expr;
10204
+ }
10205
+ _inclusive_or_expression() {
10206
+ let expr = this._exclusive_or_expression();
10207
+ while (this._match(TokenTypes.tokens.or)) {
10208
+ expr = new BinaryOperator(this._previous().toString(), expr, this._exclusive_or_expression());
10209
+ }
10210
+ return expr;
10211
+ }
10212
+ _exclusive_or_expression() {
10213
+ let expr = this._and_expression();
10214
+ while (this._match(TokenTypes.tokens.xor)) {
10215
+ expr = new BinaryOperator(this._previous().toString(), expr, this._and_expression());
10216
+ }
10217
+ return expr;
10218
+ }
10219
+ _and_expression() {
10220
+ let expr = this._equality_expression();
10221
+ while (this._match(TokenTypes.tokens.and)) {
10222
+ expr = new BinaryOperator(this._previous().toString(), expr, this._equality_expression());
10223
+ }
10224
+ return expr;
10225
+ }
10226
+ _equality_expression() {
10227
+ const expr = this._relational_expression();
10228
+ if (this._match([TokenTypes.tokens.equal_equal, TokenTypes.tokens.not_equal])) {
10229
+ return new BinaryOperator(this._previous().toString(), expr, this._relational_expression());
10230
+ }
10231
+ return expr;
10232
+ }
10233
+ _relational_expression() {
10234
+ let expr = this._shift_expression();
10235
+ while (this._match([TokenTypes.tokens.less_than, TokenTypes.tokens.greater_than, TokenTypes.tokens.less_than_equal, TokenTypes.tokens.greater_than_equal])) {
10236
+ expr = new BinaryOperator(this._previous().toString(), expr, this._shift_expression());
10237
+ }
10238
+ return expr;
10239
+ }
10240
+ _shift_expression() {
10241
+ let expr = this._additive_expression();
10242
+ while (this._match([TokenTypes.tokens.shift_left, TokenTypes.tokens.shift_right])) {
10243
+ expr = new BinaryOperator(this._previous().toString(), expr, this._additive_expression());
10244
+ }
10245
+ return expr;
10246
+ }
10247
+ _additive_expression() {
10248
+ let expr = this._multiplicative_expression();
10249
+ while (this._match([TokenTypes.tokens.plus, TokenTypes.tokens.minus])) {
10250
+ expr = new BinaryOperator(this._previous().toString(), expr, this._multiplicative_expression());
10251
+ }
10252
+ return expr;
10253
+ }
10254
+ _multiplicative_expression() {
10255
+ let expr = this._unary_expression();
10256
+ while (this._match([TokenTypes.tokens.star, TokenTypes.tokens.forward_slash, TokenTypes.tokens.modulo])) {
10257
+ expr = new BinaryOperator(this._previous().toString(), expr, this._unary_expression());
10258
+ }
10259
+ return expr;
10260
+ }
10261
+ _unary_expression() {
10262
+ if (this._match([TokenTypes.tokens.minus, TokenTypes.tokens.bang, TokenTypes.tokens.tilde, TokenTypes.tokens.star, TokenTypes.tokens.and])) {
10263
+ return new UnaryOperator(this._previous().toString(), this._unary_expression());
10264
+ }
10265
+ return this._singular_expression();
10266
+ }
10267
+ _singular_expression() {
10268
+ const expr = this._primary_expression();
10269
+ const p = this._postfix_expression();
10270
+ if (p)
10271
+ expr.postfix = p;
10272
+ return expr;
10273
+ }
10274
+ _postfix_expression() {
10275
+ if (this._match(TokenTypes.tokens.bracket_left)) {
10276
+ const expr = this._short_circuit_or_expression();
10277
+ this._consume(TokenTypes.tokens.bracket_right, "Expected ']'.");
10278
+ const p = this._postfix_expression();
10279
+ if (p)
10280
+ expr.postfix = p;
10281
+ return expr;
10282
+ }
10283
+ if (this._match(TokenTypes.tokens.period)) {
10284
+ const name = this._consume(TokenTypes.tokens.ident, "Expected member name.");
10285
+ const p = this._postfix_expression();
10286
+ const expr = new StringExpr(name.lexeme);
10287
+ if (p)
10288
+ expr.postfix = p;
10289
+ return expr;
10290
+ }
10291
+ return null;
10292
+ }
10293
+ _getStruct(name) {
10294
+ if (this._context.aliases.has(name)) {
10295
+ const alias = this._context.aliases.get(name).type;
10296
+ return alias;
10297
+ }
10298
+ if (this._context.structs.has(name)) {
10299
+ const struct = this._context.structs.get(name);
10300
+ return struct;
10301
+ }
10302
+ return null;
10303
+ }
10304
+ _primary_expression() {
10305
+ if (this._match(TokenTypes.tokens.ident)) {
10306
+ const name = this._previous().toString();
10307
+ if (this._check(TokenTypes.tokens.paren_left)) {
10308
+ const args2 = this._argument_expression_list();
10309
+ const struct = this._getStruct(name);
10310
+ if (struct != null) {
10311
+ return new CreateExpr(struct, args2);
10312
+ }
10313
+ return new CallExpr(name, args2);
10314
+ }
10315
+ if (this._context.constants.has(name)) {
10316
+ const c = this._context.constants.get(name);
10317
+ return new ConstExpr(name, c.value);
10318
+ }
10319
+ return new VariableExpr(name);
10320
+ }
10321
+ if (this._match(TokenTypes.const_literal)) {
10322
+ return new LiteralExpr(parseFloat(this._previous().toString()));
10323
+ }
10324
+ if (this._check(TokenTypes.tokens.paren_left)) {
10325
+ return this._paren_expression();
10326
+ }
10327
+ if (this._match(TokenTypes.keywords.bitcast)) {
10328
+ this._consume(TokenTypes.tokens.less_than, "Expected '<'.");
10329
+ const type2 = this._type_decl();
10330
+ this._consume(TokenTypes.tokens.greater_than, "Expected '>'.");
10331
+ const value = this._paren_expression();
10332
+ return new BitcastExpr(type2, value);
10333
+ }
10334
+ const type = this._type_decl();
10335
+ const args = this._argument_expression_list();
10336
+ return new TypecastExpr(type, args);
10337
+ }
10338
+ _argument_expression_list() {
10339
+ if (!this._match(TokenTypes.tokens.paren_left))
10340
+ return null;
10341
+ const args = [];
10342
+ do {
10343
+ if (this._check(TokenTypes.tokens.paren_right))
10344
+ break;
10345
+ const arg = this._short_circuit_or_expression();
10346
+ args.push(arg);
10347
+ } while (this._match(TokenTypes.tokens.comma));
10348
+ this._consume(TokenTypes.tokens.paren_right, "Expected ')' for agument list");
10349
+ return args;
10350
+ }
10351
+ _optional_paren_expression() {
10352
+ this._match(TokenTypes.tokens.paren_left);
10353
+ const expr = this._short_circuit_or_expression();
10354
+ this._match(TokenTypes.tokens.paren_right);
10355
+ return new GroupingExpr([expr]);
10356
+ }
10357
+ _paren_expression() {
10358
+ this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
10359
+ const expr = this._short_circuit_or_expression();
10360
+ this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
10361
+ return new GroupingExpr([expr]);
10362
+ }
10363
+ _struct_decl() {
10364
+ if (!this._match(TokenTypes.keywords.struct))
10365
+ return null;
10366
+ const name = this._consume(TokenTypes.tokens.ident, "Expected name for struct.").toString();
10367
+ this._consume(TokenTypes.tokens.brace_left, "Expected '{' for struct body.");
10368
+ const members = [];
10369
+ while (!this._check(TokenTypes.tokens.brace_right)) {
10370
+ const memberAttrs = this._attribute();
10371
+ const memberName = this._consume(TokenTypes.tokens.ident, "Expected variable name.").toString();
10372
+ this._consume(TokenTypes.tokens.colon, "Expected ':' for struct member type.");
10373
+ const typeAttrs = this._attribute();
10374
+ const memberType = this._type_decl();
10375
+ if (memberType != null)
10376
+ memberType.attributes = typeAttrs;
10377
+ if (!this._check(TokenTypes.tokens.brace_right))
10378
+ this._consume(TokenTypes.tokens.comma, "Expected ',' for struct member.");
10379
+ else
10380
+ this._match(TokenTypes.tokens.comma);
10381
+ members.push(new Member(memberName, memberType, memberAttrs));
10382
+ }
10383
+ this._consume(TokenTypes.tokens.brace_right, "Expected '}' after struct body.");
10384
+ const structNode = new Struct(name, members);
10385
+ this._context.structs.set(name, structNode);
10386
+ return structNode;
10387
+ }
10388
+ _global_variable_decl() {
10389
+ const _var = this._variable_decl();
10390
+ if (_var && this._match(TokenTypes.tokens.equal))
10391
+ _var.value = this._const_expression();
10392
+ return _var;
10393
+ }
10394
+ _override_variable_decl() {
10395
+ const _override = this._override_decl();
10396
+ if (_override && this._match(TokenTypes.tokens.equal))
10397
+ _override.value = this._const_expression();
10398
+ return _override;
10399
+ }
10400
+ _global_const_decl() {
10401
+ if (!this._match(TokenTypes.keywords.const))
10402
+ return null;
10403
+ const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
10404
+ let type = null;
10405
+ if (this._match(TokenTypes.tokens.colon)) {
10406
+ const attrs = this._attribute();
10407
+ type = this._type_decl();
10408
+ if (type != null)
10409
+ type.attributes = attrs;
10410
+ }
10411
+ let value = null;
10412
+ if (this._match(TokenTypes.tokens.equal)) {
10413
+ const valueExpr = this._short_circuit_or_expression();
10414
+ if (valueExpr instanceof CreateExpr) {
10415
+ value = valueExpr;
10416
+ } else if (valueExpr instanceof ConstExpr && valueExpr.initializer instanceof CreateExpr) {
10417
+ value = valueExpr.initializer;
10418
+ } else {
10419
+ try {
10420
+ const constValue = valueExpr.evaluate(this._context);
10421
+ value = new LiteralExpr(constValue);
10422
+ } catch (_a2) {
10423
+ value = valueExpr;
10424
+ }
10425
+ }
10426
+ }
10427
+ const c = new Const(name.toString(), type, "", "", value);
10428
+ this._context.constants.set(c.name, c);
10429
+ return c;
10430
+ }
10431
+ _global_let_decl() {
10432
+ if (!this._match(TokenTypes.keywords.let))
10433
+ return null;
10434
+ const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
10435
+ let type = null;
10436
+ if (this._match(TokenTypes.tokens.colon)) {
10437
+ const attrs = this._attribute();
10438
+ type = this._type_decl();
10439
+ if (type != null)
10440
+ type.attributes = attrs;
10441
+ }
10442
+ let value = null;
10443
+ if (this._match(TokenTypes.tokens.equal)) {
10444
+ value = this._const_expression();
10445
+ }
10446
+ return new Let(name.toString(), type, "", "", value);
10447
+ }
10448
+ _const_expression() {
10449
+ if (this._match(TokenTypes.const_literal))
10450
+ return new StringExpr(this._previous().toString());
10451
+ const type = this._type_decl();
10452
+ this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
10453
+ let args = [];
10454
+ while (!this._check(TokenTypes.tokens.paren_right)) {
10455
+ args.push(this._const_expression());
10456
+ if (!this._check(TokenTypes.tokens.comma))
10457
+ break;
10458
+ this._advance();
10459
+ }
10460
+ this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
10461
+ return new CreateExpr(type, args);
10462
+ }
10463
+ _variable_decl() {
10464
+ if (!this._match(TokenTypes.keywords.var))
10465
+ return null;
10466
+ let storage = "";
10467
+ let access = "";
10468
+ if (this._match(TokenTypes.tokens.less_than)) {
10469
+ storage = this._consume(TokenTypes.storage_class, "Expected storage_class.").toString();
10470
+ if (this._match(TokenTypes.tokens.comma))
10471
+ access = this._consume(TokenTypes.access_mode, "Expected access_mode.").toString();
10472
+ this._consume(TokenTypes.tokens.greater_than, "Expected '>'.");
10473
+ }
10474
+ const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
10475
+ let type = null;
10476
+ if (this._match(TokenTypes.tokens.colon)) {
10477
+ const attrs = this._attribute();
10478
+ type = this._type_decl();
10479
+ if (type != null)
10480
+ type.attributes = attrs;
10481
+ }
10482
+ return new Var(name.toString(), type, storage, access, null);
10483
+ }
10484
+ _override_decl() {
10485
+ if (!this._match(TokenTypes.keywords.override))
10486
+ return null;
10487
+ const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
10488
+ let type = null;
10489
+ if (this._match(TokenTypes.tokens.colon)) {
10490
+ const attrs = this._attribute();
10491
+ type = this._type_decl();
10492
+ if (type != null)
10493
+ type.attributes = attrs;
10494
+ }
10495
+ return new Override(name.toString(), type, null);
10496
+ }
10497
+ _enable_directive() {
10498
+ const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
10499
+ return new Enable(name.toString());
10500
+ }
10501
+ _type_alias() {
10502
+ const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
10503
+ this._consume(TokenTypes.tokens.equal, "Expected '=' for type alias.");
10504
+ let aliasType = this._type_decl();
10505
+ if (aliasType === null) {
10506
+ throw this._error(this._peek(), "Expected Type for Alias.");
10507
+ }
10508
+ if (this._context.aliases.has(aliasType.name)) {
10509
+ aliasType = this._context.aliases.get(aliasType.name).type;
10510
+ }
10511
+ const aliasNode = new Alias(name.toString(), aliasType);
10512
+ this._context.aliases.set(aliasNode.name, aliasNode);
10513
+ return aliasNode;
10514
+ }
10515
+ _type_decl() {
10516
+ if (this._check([TokenTypes.tokens.ident, ...TokenTypes.texel_format, TokenTypes.keywords.bool, TokenTypes.keywords.f32, TokenTypes.keywords.i32, TokenTypes.keywords.u32])) {
10517
+ const type2 = this._advance();
10518
+ const typeName = type2.toString();
10519
+ if (this._context.structs.has(typeName)) {
10520
+ return this._context.structs.get(typeName);
10521
+ }
10522
+ if (this._context.aliases.has(typeName)) {
10523
+ return this._context.aliases.get(typeName).type;
10524
+ }
10525
+ return new Type(type2.toString());
10526
+ }
10527
+ let type = this._texture_sampler_types();
10528
+ if (type)
10529
+ return type;
10530
+ if (this._check(TokenTypes.template_types)) {
10531
+ let type2 = this._advance().toString();
10532
+ let format = null;
10533
+ let access = null;
10534
+ if (this._match(TokenTypes.tokens.less_than)) {
10535
+ format = this._type_decl();
10536
+ access = null;
10537
+ if (this._match(TokenTypes.tokens.comma))
10538
+ access = this._consume(TokenTypes.access_mode, "Expected access_mode for pointer").toString();
10539
+ this._consume(TokenTypes.tokens.greater_than, "Expected '>' for type.");
10540
+ }
10541
+ return new TemplateType(type2, format, access);
10542
+ }
10543
+ if (this._match(TokenTypes.keywords.ptr)) {
10544
+ let pointer = this._previous().toString();
10545
+ this._consume(TokenTypes.tokens.less_than, "Expected '<' for pointer.");
10546
+ const storage = this._consume(TokenTypes.storage_class, "Expected storage_class for pointer");
10547
+ this._consume(TokenTypes.tokens.comma, "Expected ',' for pointer.");
10548
+ const decl = this._type_decl();
10549
+ let access = null;
10550
+ if (this._match(TokenTypes.tokens.comma))
10551
+ access = this._consume(TokenTypes.access_mode, "Expected access_mode for pointer").toString();
10552
+ this._consume(TokenTypes.tokens.greater_than, "Expected '>' for pointer.");
10553
+ return new PointerType(pointer, storage.toString(), decl, access);
10554
+ }
10555
+ const attrs = this._attribute();
10556
+ if (this._match(TokenTypes.keywords.array)) {
10557
+ let format = null;
10558
+ let countInt = -1;
10559
+ const array = this._previous();
10560
+ if (this._match(TokenTypes.tokens.less_than)) {
10561
+ format = this._type_decl();
10562
+ if (this._context.aliases.has(format.name)) {
10563
+ format = this._context.aliases.get(format.name).type;
10564
+ }
10565
+ let count = "";
10566
+ if (this._match(TokenTypes.tokens.comma)) {
10567
+ let c = this._shift_expression();
10568
+ count = c.evaluate(this._context).toString();
10569
+ }
10570
+ this._consume(TokenTypes.tokens.greater_than, "Expected '>' for array.");
10571
+ countInt = count ? parseInt(count) : 0;
10572
+ }
10573
+ return new ArrayType(array.toString(), attrs, format, countInt);
10574
+ }
10575
+ return null;
10576
+ }
10577
+ _texture_sampler_types() {
10578
+ if (this._match(TokenTypes.sampler_type))
10579
+ return new SamplerType(this._previous().toString(), null, null);
10580
+ if (this._match(TokenTypes.depth_texture_type))
10581
+ return new SamplerType(this._previous().toString(), null, null);
10582
+ if (this._match(TokenTypes.sampled_texture_type) || this._match(TokenTypes.multisampled_texture_type)) {
10583
+ const sampler = this._previous();
10584
+ this._consume(TokenTypes.tokens.less_than, "Expected '<' for sampler type.");
10585
+ const format = this._type_decl();
10586
+ this._consume(TokenTypes.tokens.greater_than, "Expected '>' for sampler type.");
10587
+ return new SamplerType(sampler.toString(), format, null);
10588
+ }
10589
+ if (this._match(TokenTypes.storage_texture_type)) {
10590
+ const sampler = this._previous();
10591
+ this._consume(TokenTypes.tokens.less_than, "Expected '<' for sampler type.");
10592
+ const format = this._consume(TokenTypes.texel_format, "Invalid texel format.").toString();
10593
+ this._consume(TokenTypes.tokens.comma, "Expected ',' after texel format.");
10594
+ const access = this._consume(TokenTypes.access_mode, "Expected access mode for storage texture type.").toString();
10595
+ this._consume(TokenTypes.tokens.greater_than, "Expected '>' for sampler type.");
10596
+ return new SamplerType(sampler.toString(), format, access);
10597
+ }
10598
+ return null;
10599
+ }
10600
+ _attribute() {
10601
+ let attributes = [];
10602
+ while (this._match(TokenTypes.tokens.attr)) {
10603
+ const name = this._consume(TokenTypes.attribute_name, "Expected attribute name");
10604
+ const attr = new Attribute(name.toString(), null);
10605
+ if (this._match(TokenTypes.tokens.paren_left)) {
10606
+ attr.value = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
10607
+ if (this._check(TokenTypes.tokens.comma)) {
10608
+ this._advance();
10609
+ do {
10610
+ const v = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
10611
+ if (!(attr.value instanceof Array)) {
10612
+ attr.value = [attr.value];
10613
+ }
10614
+ attr.value.push(v);
10615
+ } while (this._match(TokenTypes.tokens.comma));
10616
+ }
10617
+ this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
10618
+ }
10619
+ attributes.push(attr);
10620
+ }
10621
+ while (this._match(TokenTypes.tokens.attr_left)) {
10622
+ if (!this._check(TokenTypes.tokens.attr_right)) {
10623
+ do {
10624
+ const name = this._consume(TokenTypes.attribute_name, "Expected attribute name");
10625
+ const attr = new Attribute(name.toString(), null);
10626
+ if (this._match(TokenTypes.tokens.paren_left)) {
10627
+ attr.value = [this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString()];
10628
+ if (this._check(TokenTypes.tokens.comma)) {
10629
+ this._advance();
10630
+ do {
10631
+ const v = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
10632
+ attr.value.push(v);
10633
+ } while (this._match(TokenTypes.tokens.comma));
10634
+ }
10635
+ this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
10636
+ }
10637
+ attributes.push(attr);
10638
+ } while (this._match(TokenTypes.tokens.comma));
10639
+ }
10640
+ this._consume(TokenTypes.tokens.attr_right, "Expected ']]' after attribute declarations");
10641
+ }
10642
+ if (attributes.length == 0)
10643
+ return null;
10644
+ return attributes;
10645
+ }
10646
+ };
10647
+ var TypeInfo = class {
10648
+ constructor(name, attributes) {
10649
+ this.name = name;
10650
+ this.attributes = attributes;
10651
+ this.size = 0;
10652
+ }
10653
+ get isArray() {
10654
+ return false;
10655
+ }
10656
+ get isStruct() {
10657
+ return false;
10658
+ }
10659
+ get isTemplate() {
10660
+ return false;
10661
+ }
10662
+ };
10663
+ var MemberInfo = class {
10664
+ constructor(name, type, attributes) {
10665
+ this.name = name;
10666
+ this.type = type;
10667
+ this.attributes = attributes;
10668
+ this.offset = 0;
10669
+ this.size = 0;
10670
+ }
10671
+ get isArray() {
10672
+ return this.type.isArray;
10673
+ }
10674
+ get isStruct() {
10675
+ return this.type.isStruct;
10676
+ }
10677
+ get isTemplate() {
10678
+ return this.type.isTemplate;
10679
+ }
10680
+ get align() {
10681
+ return this.type.isStruct ? this.type.align : 0;
10682
+ }
10683
+ get members() {
10684
+ return this.type.isStruct ? this.type.members : null;
10685
+ }
10686
+ get format() {
10687
+ return this.type.isArray ? this.type.format : this.type.isTemplate ? this.type.format : null;
10688
+ }
10689
+ get count() {
10690
+ return this.type.isArray ? this.type.count : 0;
10691
+ }
10692
+ get stride() {
10693
+ return this.type.isArray ? this.type.stride : this.size;
10694
+ }
10695
+ };
10696
+ var StructInfo = class extends TypeInfo {
10697
+ constructor(name, attributes) {
10698
+ super(name, attributes);
10699
+ this.members = [];
10700
+ this.align = 0;
10701
+ }
10702
+ get isStruct() {
10703
+ return true;
10704
+ }
10705
+ };
10706
+ var ArrayInfo = class extends TypeInfo {
10707
+ constructor(name, attributes) {
10708
+ super(name, attributes);
10709
+ this.count = 0;
10710
+ this.stride = 0;
10711
+ }
10712
+ get isArray() {
10713
+ return true;
10714
+ }
10715
+ };
10716
+ var TemplateInfo = class extends TypeInfo {
10717
+ constructor(name, format, attributes, access) {
10718
+ super(name, attributes);
10719
+ this.format = format;
10720
+ this.access = access;
10721
+ }
10722
+ get isTemplate() {
10723
+ return true;
10724
+ }
10725
+ };
10726
+ var ResourceType;
10727
+ (function(ResourceType2) {
10728
+ ResourceType2[ResourceType2["Uniform"] = 0] = "Uniform";
10729
+ ResourceType2[ResourceType2["Storage"] = 1] = "Storage";
10730
+ ResourceType2[ResourceType2["Texture"] = 2] = "Texture";
10731
+ ResourceType2[ResourceType2["Sampler"] = 3] = "Sampler";
10732
+ ResourceType2[ResourceType2["StorageTexture"] = 4] = "StorageTexture";
10733
+ })(ResourceType || (ResourceType = {}));
10734
+ var VariableInfo = class {
10735
+ constructor(name, type, group, binding, attributes, resourceType, access) {
10736
+ this.name = name;
10737
+ this.type = type;
10738
+ this.group = group;
10739
+ this.binding = binding;
10740
+ this.attributes = attributes;
10741
+ this.resourceType = resourceType;
10742
+ this.access = access;
10743
+ }
10744
+ get isArray() {
10745
+ return this.type.isArray;
10746
+ }
10747
+ get isStruct() {
10748
+ return this.type.isStruct;
10749
+ }
10750
+ get isTemplate() {
10751
+ return this.type.isTemplate;
10752
+ }
10753
+ get size() {
10754
+ return this.type.size;
10755
+ }
10756
+ get align() {
10757
+ return this.type.isStruct ? this.type.align : 0;
10758
+ }
10759
+ get members() {
10760
+ return this.type.isStruct ? this.type.members : null;
10761
+ }
10762
+ get format() {
10763
+ return this.type.isArray ? this.type.format : this.type.isTemplate ? this.type.format : null;
10764
+ }
10765
+ get count() {
10766
+ return this.type.isArray ? this.type.count : 0;
10767
+ }
10768
+ get stride() {
10769
+ return this.type.isArray ? this.type.stride : this.size;
10770
+ }
10771
+ };
10772
+ var AliasInfo = class {
10773
+ constructor(name, type) {
10774
+ this.name = name;
10775
+ this.type = type;
10776
+ }
10777
+ };
10778
+ var _TypeSize = class {
10779
+ constructor(align, size) {
10780
+ this.align = align;
10781
+ this.size = size;
10782
+ }
10783
+ };
10784
+ var InputInfo = class {
10785
+ constructor(name, type, locationType, location) {
10786
+ this.name = name;
10787
+ this.type = type;
10788
+ this.locationType = locationType;
10789
+ this.location = location;
10790
+ this.interpolation = null;
10791
+ }
10792
+ };
10793
+ var OutputInfo = class {
10794
+ constructor(name, type, locationType, location) {
10795
+ this.name = name;
10796
+ this.type = type;
10797
+ this.locationType = locationType;
10798
+ this.location = location;
10799
+ }
10800
+ };
10801
+ var FunctionInfo = class {
10802
+ constructor(name) {
10803
+ let stage = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
10804
+ this.stage = null;
10805
+ this.inputs = [];
10806
+ this.outputs = [];
10807
+ this.name = name;
10808
+ this.stage = stage;
10809
+ }
10810
+ };
10811
+ var EntryFunctions = class {
10812
+ constructor() {
10813
+ this.vertex = [];
10814
+ this.fragment = [];
10815
+ this.compute = [];
10816
+ }
10817
+ };
10818
+ var OverrideInfo = class {
10819
+ constructor(name, type, attributes, id) {
10820
+ this.name = name;
10821
+ this.type = type;
10822
+ this.attributes = attributes;
10823
+ this.id = id;
10824
+ }
10825
+ };
10826
+ var WgslReflect = class {
10827
+ constructor(code) {
10828
+ this.uniforms = [];
10829
+ this.storage = [];
10830
+ this.textures = [];
10831
+ this.samplers = [];
10832
+ this.aliases = [];
10833
+ this.overrides = [];
10834
+ this.structs = [];
10835
+ this.entry = new EntryFunctions();
10836
+ this._types = /* @__PURE__ */ new Map();
10837
+ if (code) {
10838
+ this.update(code);
10839
+ }
10840
+ }
10841
+ _isStorageTexture(type) {
10842
+ return type.name == "texture_storage_1d" || type.name == "texture_storage_2d" || type.name == "texture_storage_2d_array" || type.name == "texture_storage_3d";
10843
+ }
10844
+ update(code) {
10845
+ const parser = new WgslParser();
10846
+ const ast = parser.parse(code);
10847
+ for (const node of ast) {
10848
+ if (node instanceof Struct) {
10849
+ const info = this._getTypeInfo(node, null);
10850
+ if (info instanceof StructInfo) {
10851
+ this.structs.push(info);
10852
+ }
10853
+ continue;
10854
+ }
10855
+ if (node instanceof Alias) {
10856
+ this.aliases.push(this._getAliasInfo(node));
10857
+ continue;
10858
+ }
10859
+ if (node instanceof Override) {
10860
+ const v = node;
10861
+ const id = this._getAttributeNum(v.attributes, "id", 0);
10862
+ const type = v.type != null ? this._getTypeInfo(v.type, v.attributes) : null;
10863
+ this.overrides.push(new OverrideInfo(v.name, type, v.attributes, id));
10864
+ continue;
10865
+ }
10866
+ if (this._isUniformVar(node)) {
10867
+ const v = node;
10868
+ const g = this._getAttributeNum(v.attributes, "group", 0);
10869
+ const b = this._getAttributeNum(v.attributes, "binding", 0);
10870
+ const type = this._getTypeInfo(v.type, v.attributes);
10871
+ const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, ResourceType.Uniform, v.access);
10872
+ this.uniforms.push(varInfo);
10873
+ continue;
10874
+ }
10875
+ if (this._isStorageVar(node)) {
10876
+ const v = node;
10877
+ const g = this._getAttributeNum(v.attributes, "group", 0);
10878
+ const b = this._getAttributeNum(v.attributes, "binding", 0);
10879
+ const type = this._getTypeInfo(v.type, v.attributes);
10880
+ const isStorageTexture = this._isStorageTexture(type);
10881
+ const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, isStorageTexture ? ResourceType.StorageTexture : ResourceType.Storage, v.access);
10882
+ this.storage.push(varInfo);
10883
+ continue;
10884
+ }
10885
+ if (this._isTextureVar(node)) {
10886
+ const v = node;
10887
+ const g = this._getAttributeNum(v.attributes, "group", 0);
10888
+ const b = this._getAttributeNum(v.attributes, "binding", 0);
10889
+ const type = this._getTypeInfo(v.type, v.attributes);
10890
+ const isStorageTexture = this._isStorageTexture(type);
10891
+ const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, isStorageTexture ? ResourceType.StorageTexture : ResourceType.Texture, v.access);
10892
+ if (isStorageTexture) {
10893
+ this.storage.push(varInfo);
10894
+ } else {
10895
+ this.textures.push(varInfo);
10896
+ }
10897
+ continue;
10898
+ }
10899
+ if (this._isSamplerVar(node)) {
10900
+ const v = node;
10901
+ const g = this._getAttributeNum(v.attributes, "group", 0);
10902
+ const b = this._getAttributeNum(v.attributes, "binding", 0);
10903
+ const type = this._getTypeInfo(v.type, v.attributes);
10904
+ const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, ResourceType.Sampler, v.access);
10905
+ this.samplers.push(varInfo);
10906
+ continue;
10907
+ }
10908
+ if (node instanceof Function) {
10909
+ const vertexStage = this._getAttribute(node, "vertex");
10910
+ const fragmentStage = this._getAttribute(node, "fragment");
10911
+ const computeStage = this._getAttribute(node, "compute");
10912
+ const stage = vertexStage || fragmentStage || computeStage;
10913
+ if (stage) {
10914
+ const fn = new FunctionInfo(node.name, stage.name);
10915
+ fn.inputs = this._getInputs(node.args);
10916
+ fn.outputs = this._getOutputs(node.returnType);
10917
+ this.entry[stage.name].push(fn);
10918
+ }
10919
+ continue;
10920
+ }
10921
+ }
10922
+ }
10923
+ getBindGroups() {
10924
+ const groups = [];
10925
+ function _makeRoom(group, binding) {
10926
+ if (group >= groups.length)
10927
+ groups.length = group + 1;
10928
+ if (groups[group] === void 0)
10929
+ groups[group] = [];
10930
+ if (binding >= groups[group].length)
10931
+ groups[group].length = binding + 1;
10932
+ }
10933
+ for (const u of this.uniforms) {
10934
+ _makeRoom(u.group, u.binding);
10935
+ const group = groups[u.group];
10936
+ group[u.binding] = u;
10937
+ }
10938
+ for (const u of this.storage) {
10939
+ _makeRoom(u.group, u.binding);
10940
+ const group = groups[u.group];
10941
+ group[u.binding] = u;
10942
+ }
10943
+ for (const t of this.textures) {
10944
+ _makeRoom(t.group, t.binding);
10945
+ const group = groups[t.group];
10946
+ group[t.binding] = t;
10947
+ }
10948
+ for (const t of this.samplers) {
10949
+ _makeRoom(t.group, t.binding);
10950
+ const group = groups[t.group];
10951
+ group[t.binding] = t;
10952
+ }
10953
+ return groups;
10954
+ }
10955
+ _getOutputs(type) {
10956
+ let outputs = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : void 0;
10957
+ if (outputs === void 0)
10958
+ outputs = [];
10959
+ if (type instanceof Struct) {
10960
+ this._getStructOutputs(type, outputs);
10961
+ } else {
10962
+ const output = this._getOutputInfo(type);
10963
+ if (output !== null)
10964
+ outputs.push(output);
10965
+ }
10966
+ return outputs;
10967
+ }
10968
+ _getStructOutputs(struct, outputs) {
10969
+ for (const m of struct.members) {
10970
+ if (m.type instanceof Struct) {
10971
+ this._getStructOutputs(m.type, outputs);
10972
+ } else {
10973
+ const location = this._getAttribute(m, "location") || this._getAttribute(m, "builtin");
10974
+ if (location !== null) {
10975
+ const typeInfo = this._getTypeInfo(m.type, m.type.attributes);
10976
+ const locationValue = this._parseInt(location.value);
10977
+ const info = new OutputInfo(m.name, typeInfo, location.name, locationValue);
10978
+ outputs.push(info);
10979
+ }
10980
+ }
10981
+ }
10982
+ }
10983
+ _getOutputInfo(type) {
10984
+ const location = this._getAttribute(type, "location") || this._getAttribute(type, "builtin");
10985
+ if (location !== null) {
10986
+ const typeInfo = this._getTypeInfo(type, type.attributes);
10987
+ const locationValue = this._parseInt(location.value);
10988
+ const info = new OutputInfo("", typeInfo, location.name, locationValue);
10989
+ return info;
10990
+ }
10991
+ return null;
10992
+ }
10993
+ _getInputs(args) {
10994
+ let inputs = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : void 0;
10995
+ if (inputs === void 0)
10996
+ inputs = [];
10997
+ for (const arg of args) {
10998
+ if (arg.type instanceof Struct) {
10999
+ this._getStructInputs(arg.type, inputs);
11000
+ } else {
11001
+ const input = this._getInputInfo(arg);
11002
+ if (input !== null)
11003
+ inputs.push(input);
8369
11004
  }
8370
- } else {
8371
- mainInjections[key] = [injection];
8372
11005
  }
11006
+ return inputs;
8373
11007
  }
8374
- for (const module of modules) {
8375
- if (log14) {
8376
- module.checkDeprecations(coreSource, log14);
8377
- }
8378
- const moduleSource = module.getModuleSource(stage);
8379
- assembledSource += moduleSource;
8380
- const injections = module.injections[stage];
8381
- for (const key in injections) {
8382
- const match = /^(v|f)s:#([\w-]+)$/.exec(key);
8383
- if (match) {
8384
- const name = match[2];
8385
- const injectionType = name === "decl" ? declInjections : mainInjections;
8386
- injectionType[key] = injectionType[key] || [];
8387
- injectionType[key].push(injections[key]);
11008
+ _getStructInputs(struct, inputs) {
11009
+ for (const m of struct.members) {
11010
+ if (m.type instanceof Struct) {
11011
+ this._getStructInputs(m.type, inputs);
8388
11012
  } else {
8389
- hookInjections[key] = hookInjections[key] || [];
8390
- hookInjections[key].push(injections[key]);
11013
+ const input = this._getInputInfo(m);
11014
+ if (input !== null)
11015
+ inputs.push(input);
8391
11016
  }
8392
11017
  }
8393
11018
  }
8394
- assembledSource += "// ----- MAIN SHADER SOURCE -------------------------";
8395
- assembledSource += INJECT_SHADER_DECLARATIONS;
8396
- assembledSource = injectShader(assembledSource, stage, declInjections);
8397
- assembledSource += getShaderHooks(hookFunctionMap[stage], hookInjections);
8398
- assembledSource += coreSource;
8399
- assembledSource = injectShader(assembledSource, stage, mainInjections);
8400
- if (language === "glsl" && sourceVersion !== targetVersion) {
8401
- assembledSource = transpileGLSLShader(assembledSource, targetVersion, stage);
11019
+ _getInputInfo(node) {
11020
+ const location = this._getAttribute(node, "location") || this._getAttribute(node, "builtin");
11021
+ if (location !== null) {
11022
+ const interpolation = this._getAttribute(node, "interpolation");
11023
+ const type = this._getTypeInfo(node.type, node.attributes);
11024
+ const locationValue = this._parseInt(location.value);
11025
+ const info = new InputInfo(node.name, type, location.name, locationValue);
11026
+ if (interpolation !== null) {
11027
+ info.interpolation = this._parseString(interpolation.value);
11028
+ }
11029
+ return info;
11030
+ }
11031
+ return null;
8402
11032
  }
8403
- return assembledSource.trim();
8404
- }
8405
- function assembleGetUniforms(modules) {
8406
- return function getUniforms4(opts) {
8407
- const uniforms = {};
8408
- for (const module of modules) {
8409
- const moduleUniforms = module.getUniforms(opts, uniforms);
8410
- Object.assign(uniforms, moduleUniforms);
11033
+ _parseString(s) {
11034
+ if (s instanceof Array) {
11035
+ s = s[0];
8411
11036
  }
8412
- return uniforms;
8413
- };
8414
- }
8415
- function getShaderNameDefine(options) {
8416
- const {
8417
- id,
8418
- source,
8419
- stage
8420
- } = options;
8421
- const injectShaderName = id && source.indexOf("SHADER_NAME") === -1;
8422
- return injectShaderName ? `
8423
- #define SHADER_NAME ${id}_${stage}
8424
-
8425
- ` : "";
8426
- }
8427
- function getApplicationDefines() {
8428
- let defines = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
8429
- let sourceText = "";
8430
- for (const define in defines) {
8431
- const value = defines[define];
8432
- if (value || Number.isFinite(value)) {
8433
- sourceText += `#define ${define.toUpperCase()} ${defines[define]}
8434
- `;
11037
+ return s;
11038
+ }
11039
+ _parseInt(s) {
11040
+ if (s instanceof Array) {
11041
+ s = s[0];
8435
11042
  }
11043
+ const n = parseInt(s);
11044
+ return isNaN(n) ? s : n;
8436
11045
  }
8437
- return sourceText;
8438
- }
8439
-
8440
- // ../../node_modules/@luma.gl/shadertools/dist/lib/shader-assembly/select-shaders.js
8441
- function selectShaders(props) {
8442
- if (!props.vs) {
8443
- throw new Error("no vertex shader");
11046
+ _getAlias(name) {
11047
+ for (const a of this.aliases) {
11048
+ if (a.name == name)
11049
+ return a.type;
11050
+ }
11051
+ return null;
8444
11052
  }
8445
- const vs5 = getShaderSource(props.platformInfo, props.vs);
8446
- let fs4;
8447
- if (props.fs) {
8448
- fs4 = getShaderSource(props.platformInfo, props.fs);
11053
+ _getAliasInfo(node) {
11054
+ return new AliasInfo(node.name, this._getTypeInfo(node.type, null));
11055
+ }
11056
+ _getTypeInfo(type, attributes) {
11057
+ if (this._types.has(type)) {
11058
+ return this._types.get(type);
11059
+ }
11060
+ if (type instanceof ArrayType) {
11061
+ const a = type;
11062
+ const t = this._getTypeInfo(a.format, a.attributes);
11063
+ const info2 = new ArrayInfo(a.name, attributes);
11064
+ info2.format = t;
11065
+ info2.count = a.count;
11066
+ this._types.set(type, info2);
11067
+ this._updateTypeInfo(info2);
11068
+ return info2;
11069
+ }
11070
+ if (type instanceof Struct) {
11071
+ const s = type;
11072
+ const info2 = new StructInfo(s.name, attributes);
11073
+ for (const m of s.members) {
11074
+ const t = this._getTypeInfo(m.type, m.attributes);
11075
+ info2.members.push(new MemberInfo(m.name, t, m.attributes));
11076
+ }
11077
+ this._types.set(type, info2);
11078
+ this._updateTypeInfo(info2);
11079
+ return info2;
11080
+ }
11081
+ if (type instanceof SamplerType) {
11082
+ const s = type;
11083
+ const formatIsType = s.format instanceof Type;
11084
+ const format = s.format ? formatIsType ? this._getTypeInfo(s.format, null) : new TypeInfo(s.format, null) : null;
11085
+ const info2 = new TemplateInfo(s.name, format, attributes, s.access);
11086
+ this._types.set(type, info2);
11087
+ this._updateTypeInfo(info2);
11088
+ return info2;
11089
+ }
11090
+ if (type instanceof TemplateType) {
11091
+ const t = type;
11092
+ const format = t.format ? this._getTypeInfo(t.format, null) : null;
11093
+ const info2 = new TemplateInfo(t.name, format, attributes, t.access);
11094
+ this._types.set(type, info2);
11095
+ this._updateTypeInfo(info2);
11096
+ return info2;
11097
+ }
11098
+ const info = new TypeInfo(type.name, attributes);
11099
+ this._types.set(type, info);
11100
+ this._updateTypeInfo(info);
11101
+ return info;
11102
+ }
11103
+ _updateTypeInfo(type) {
11104
+ var _a2, _b;
11105
+ const typeSize = this._getTypeSize(type);
11106
+ type.size = (_a2 = typeSize === null || typeSize === void 0 ? void 0 : typeSize.size) !== null && _a2 !== void 0 ? _a2 : 0;
11107
+ if (type instanceof ArrayInfo) {
11108
+ const formatInfo = this._getTypeSize(type["format"]);
11109
+ type.stride = (_b = formatInfo === null || formatInfo === void 0 ? void 0 : formatInfo.size) !== null && _b !== void 0 ? _b : 0;
11110
+ this._updateTypeInfo(type["format"]);
11111
+ }
11112
+ if (type instanceof StructInfo) {
11113
+ this._updateStructInfo(type);
11114
+ }
11115
+ }
11116
+ _updateStructInfo(struct) {
11117
+ var _a2;
11118
+ let offset = 0;
11119
+ let lastSize = 0;
11120
+ let lastOffset = 0;
11121
+ let structAlign = 0;
11122
+ for (let mi = 0, ml = struct.members.length; mi < ml; ++mi) {
11123
+ const member = struct.members[mi];
11124
+ const sizeInfo = this._getTypeSize(member);
11125
+ if (!sizeInfo)
11126
+ continue;
11127
+ (_a2 = this._getAlias(member.type.name)) !== null && _a2 !== void 0 ? _a2 : member.type;
11128
+ const align = sizeInfo.align;
11129
+ const size = sizeInfo.size;
11130
+ offset = this._roundUp(align, offset + lastSize);
11131
+ lastSize = size;
11132
+ lastOffset = offset;
11133
+ structAlign = Math.max(structAlign, align);
11134
+ member.offset = offset;
11135
+ member.size = size;
11136
+ this._updateTypeInfo(member.type);
11137
+ }
11138
+ struct.size = this._roundUp(structAlign, lastOffset + lastSize);
11139
+ struct.align = structAlign;
11140
+ }
11141
+ _getTypeSize(type) {
11142
+ var _a2;
11143
+ if (type === null || type === void 0)
11144
+ return null;
11145
+ const explicitSize = this._getAttributeNum(type.attributes, "size", 0);
11146
+ const explicitAlign = this._getAttributeNum(type.attributes, "align", 0);
11147
+ if (type instanceof MemberInfo)
11148
+ type = type.type;
11149
+ if (type instanceof TypeInfo) {
11150
+ const alias = this._getAlias(type.name);
11151
+ if (alias !== null) {
11152
+ type = alias;
11153
+ }
11154
+ }
11155
+ {
11156
+ const info = WgslReflect._typeInfo[type.name];
11157
+ if (info !== void 0) {
11158
+ const divisor = type["format"] === "f16" ? 2 : 1;
11159
+ return new _TypeSize(Math.max(explicitAlign, info.align / divisor), Math.max(explicitSize, info.size / divisor));
11160
+ }
11161
+ }
11162
+ {
11163
+ const info = WgslReflect._typeInfo[type.name.substring(0, type.name.length - 1)];
11164
+ if (info) {
11165
+ const divisor = type.name[type.name.length - 1] === "h" ? 2 : 1;
11166
+ return new _TypeSize(Math.max(explicitAlign, info.align / divisor), Math.max(explicitSize, info.size / divisor));
11167
+ }
11168
+ }
11169
+ if (type instanceof ArrayInfo) {
11170
+ let arrayType = type;
11171
+ let align = 8;
11172
+ let size = 8;
11173
+ const E = this._getTypeSize(arrayType.format);
11174
+ if (E !== null) {
11175
+ size = E.size;
11176
+ align = E.align;
11177
+ }
11178
+ const N = arrayType.count;
11179
+ 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));
11180
+ size = N * stride;
11181
+ if (explicitSize)
11182
+ size = explicitSize;
11183
+ return new _TypeSize(Math.max(explicitAlign, align), Math.max(explicitSize, size));
11184
+ }
11185
+ if (type instanceof StructInfo) {
11186
+ let align = 0;
11187
+ let size = 0;
11188
+ let offset = 0;
11189
+ let lastSize = 0;
11190
+ let lastOffset = 0;
11191
+ for (const m of type.members) {
11192
+ const mi = this._getTypeSize(m.type);
11193
+ if (mi !== null) {
11194
+ align = Math.max(mi.align, align);
11195
+ offset = this._roundUp(mi.align, offset + lastSize);
11196
+ lastSize = mi.size;
11197
+ lastOffset = offset;
11198
+ }
11199
+ }
11200
+ size = this._roundUp(align, lastOffset + lastSize);
11201
+ return new _TypeSize(Math.max(explicitAlign, align), Math.max(explicitSize, size));
11202
+ }
11203
+ return null;
8449
11204
  }
8450
- return {
8451
- ...props,
8452
- vs: vs5,
8453
- fs: fs4
8454
- };
8455
- }
8456
- function getShaderSource(platformInfo, shader) {
8457
- if (typeof shader === "string") {
8458
- return shader;
11205
+ _isUniformVar(node) {
11206
+ return node instanceof Var && node.storage == "uniform";
8459
11207
  }
8460
- switch (platformInfo.type) {
8461
- case "webgpu":
8462
- if (shader !== null && shader !== void 0 && shader.wgsl) {
8463
- return shader.wgsl;
8464
- }
8465
- throw new Error("WebGPU does not support GLSL shaders");
8466
- default:
8467
- if (shader !== null && shader !== void 0 && shader.glsl) {
8468
- return shader.glsl;
8469
- }
8470
- throw new Error("WebGL does not support WGSL shaders");
11208
+ _isStorageVar(node) {
11209
+ return node instanceof Var && node.storage == "storage";
8471
11210
  }
8472
- }
8473
-
8474
- // ../../node_modules/@luma.gl/shadertools/dist/lib/shader-assembler.js
8475
- var ShaderAssembler = class {
8476
- constructor() {
8477
- this._hookFunctions = [];
8478
- this._defaultModules = [];
11211
+ _isTextureVar(node) {
11212
+ return node instanceof Var && node.type !== null && WgslReflect._textureTypes.indexOf(node.type.name) != -1;
8479
11213
  }
8480
- static getDefaultShaderAssembler() {
8481
- ShaderAssembler.defaultShaderAssembler = ShaderAssembler.defaultShaderAssembler || new ShaderAssembler();
8482
- return ShaderAssembler.defaultShaderAssembler;
11214
+ _isSamplerVar(node) {
11215
+ return node instanceof Var && node.type !== null && WgslReflect._samplerTypes.indexOf(node.type.name) != -1;
8483
11216
  }
8484
- addDefaultModule(module) {
8485
- if (!this._defaultModules.find((m) => m.name === (typeof module === "string" ? module : module.name))) {
8486
- this._defaultModules.push(module);
11217
+ _getAttribute(node, name) {
11218
+ const obj = node;
11219
+ if (!obj || !obj["attributes"])
11220
+ return null;
11221
+ const attrs = obj["attributes"];
11222
+ for (let a of attrs) {
11223
+ if (a.name == name)
11224
+ return a;
8487
11225
  }
11226
+ return null;
8488
11227
  }
8489
- removeDefaultModule(module) {
8490
- const moduleName = typeof module === "string" ? module : module.name;
8491
- this._defaultModules = this._defaultModules.filter((m) => m.name !== moduleName);
11228
+ _getAttributeNum(attributes, name, defaultValue) {
11229
+ if (attributes === null)
11230
+ return defaultValue;
11231
+ for (let a of attributes) {
11232
+ if (a.name == name) {
11233
+ let v = a !== null && a.value !== null ? a.value : defaultValue;
11234
+ if (v instanceof Array) {
11235
+ v = v[0];
11236
+ }
11237
+ if (typeof v === "number") {
11238
+ return v;
11239
+ }
11240
+ if (typeof v === "string") {
11241
+ return parseInt(v);
11242
+ }
11243
+ return defaultValue;
11244
+ }
11245
+ }
11246
+ return defaultValue;
8492
11247
  }
8493
- addShaderHook(hook, opts) {
8494
- if (opts) {
8495
- hook = Object.assign(opts, {
8496
- hook
11248
+ _roundUp(k, n) {
11249
+ return Math.ceil(n / k) * k;
11250
+ }
11251
+ };
11252
+ WgslReflect._typeInfo = {
11253
+ f16: {
11254
+ align: 2,
11255
+ size: 2
11256
+ },
11257
+ i32: {
11258
+ align: 4,
11259
+ size: 4
11260
+ },
11261
+ u32: {
11262
+ align: 4,
11263
+ size: 4
11264
+ },
11265
+ f32: {
11266
+ align: 4,
11267
+ size: 4
11268
+ },
11269
+ atomic: {
11270
+ align: 4,
11271
+ size: 4
11272
+ },
11273
+ vec2: {
11274
+ align: 8,
11275
+ size: 8
11276
+ },
11277
+ vec3: {
11278
+ align: 16,
11279
+ size: 12
11280
+ },
11281
+ vec4: {
11282
+ align: 16,
11283
+ size: 16
11284
+ },
11285
+ mat2x2: {
11286
+ align: 8,
11287
+ size: 16
11288
+ },
11289
+ mat3x2: {
11290
+ align: 8,
11291
+ size: 24
11292
+ },
11293
+ mat4x2: {
11294
+ align: 8,
11295
+ size: 32
11296
+ },
11297
+ mat2x3: {
11298
+ align: 16,
11299
+ size: 32
11300
+ },
11301
+ mat3x3: {
11302
+ align: 16,
11303
+ size: 48
11304
+ },
11305
+ mat4x3: {
11306
+ align: 16,
11307
+ size: 64
11308
+ },
11309
+ mat2x4: {
11310
+ align: 16,
11311
+ size: 32
11312
+ },
11313
+ mat3x4: {
11314
+ align: 16,
11315
+ size: 48
11316
+ },
11317
+ mat4x4: {
11318
+ align: 16,
11319
+ size: 64
11320
+ }
11321
+ };
11322
+ WgslReflect._textureTypes = TokenTypes.any_texture_type.map((t) => {
11323
+ return t.name;
11324
+ });
11325
+ WgslReflect._samplerTypes = TokenTypes.sampler_type.map((t) => {
11326
+ return t.name;
11327
+ });
11328
+
11329
+ // ../../node_modules/@luma.gl/shadertools/dist/lib/wgsl/get-shader-layout-wgsl.js
11330
+ function getShaderLayoutFromWGSL(source) {
11331
+ const shaderLayout = {
11332
+ attributes: [],
11333
+ bindings: []
11334
+ };
11335
+ const parsedWGSL = parseWGSL(source);
11336
+ for (const uniform of parsedWGSL.uniforms) {
11337
+ const members = [];
11338
+ for (const member of uniform.type.members) {
11339
+ members.push({
11340
+ name: member.name,
11341
+ type: getType(member.type)
8497
11342
  });
8498
11343
  }
8499
- this._hookFunctions.push(hook);
8500
- }
8501
- assembleShaders(props) {
8502
- const modules = this._getModuleList(props.modules);
8503
- const hookFunctions = this._hookFunctions;
8504
- const options = selectShaders(props);
8505
- const assembled = assembleShaders({
8506
- platformInfo: props.platformInfo,
8507
- ...options,
8508
- modules,
8509
- hookFunctions
11344
+ shaderLayout.bindings.push({
11345
+ type: "uniform",
11346
+ name: uniform.name,
11347
+ location: uniform.binding,
11348
+ group: uniform.group,
11349
+ members
8510
11350
  });
8511
- return {
8512
- ...assembled,
8513
- modules
8514
- };
8515
11351
  }
8516
- _getModuleList() {
8517
- let appModules = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
8518
- const modules = new Array(this._defaultModules.length + appModules.length);
8519
- const seen = {};
8520
- let count = 0;
8521
- for (let i = 0, len2 = this._defaultModules.length; i < len2; ++i) {
8522
- const module = this._defaultModules[i];
8523
- const name = module.name;
8524
- modules[count++] = module;
8525
- seen[name] = true;
11352
+ const vertex = parsedWGSL.entry.vertex[0];
11353
+ const attributeCount = vertex.inputs.length;
11354
+ for (let i = 0; i < attributeCount; i++) {
11355
+ const wgslAttribute = vertex.inputs[i];
11356
+ if (wgslAttribute.locationType === "location") {
11357
+ const type = getType(wgslAttribute.type);
11358
+ shaderLayout.attributes.push({
11359
+ name: wgslAttribute.name,
11360
+ location: wgslAttribute.location,
11361
+ type
11362
+ });
8526
11363
  }
8527
- for (let i = 0, len2 = appModules.length; i < len2; ++i) {
8528
- const module = appModules[i];
8529
- const name = module.name;
8530
- if (!seen[name]) {
8531
- modules[count++] = module;
8532
- seen[name] = true;
8533
- }
11364
+ }
11365
+ return shaderLayout;
11366
+ }
11367
+ function getType(type) {
11368
+ return type.format ? `${type.name}<${type.format.name}>` : type.name;
11369
+ }
11370
+ function parseWGSL(source) {
11371
+ try {
11372
+ return new WgslReflect(source);
11373
+ } catch (error2) {
11374
+ if (error2 instanceof Error) {
11375
+ throw error2;
8534
11376
  }
8535
- modules.length = count;
8536
- return ShaderModuleInstance.instantiateModules(modules);
11377
+ let message2 = "WGSL parse error";
11378
+ if (typeof error2 === "object" && error2 !== null && error2 !== void 0 && error2.message) {
11379
+ message2 += `: ${error2.message} `;
11380
+ }
11381
+ if (typeof error2 === "object" && error2 !== null && error2 !== void 0 && error2.token) {
11382
+ message2 += error2.token.line || "";
11383
+ }
11384
+ throw new Error(message2, {
11385
+ cause: error2
11386
+ });
8537
11387
  }
8538
- };
8539
- ShaderAssembler.defaultShaderAssembler = void 0;
11388
+ }
8540
11389
 
8541
11390
  // ../../node_modules/@luma.gl/shadertools/dist/modules-webgl1/math/fp64/fp64-utils.js
8542
11391
  function fp64ify(a) {
@@ -10195,10 +13044,17 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
10195
13044
  };
10196
13045
 
10197
13046
  // ../../node_modules/@luma.gl/engine/dist/debug/debug-shader-layout.js
10198
- function getDebugTableForShaderLayout(layout) {
10199
- let name = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
13047
+ function getDebugTableForShaderLayout(layout, name) {
13048
+ var _layout$varyings;
10200
13049
  const table = {};
10201
- const header = `Shader Layout for ${name}`;
13050
+ const header = "Values";
13051
+ if (layout.attributes.length === 0 && !((_layout$varyings = layout.varyings) !== null && _layout$varyings !== void 0 && _layout$varyings.length)) {
13052
+ return {
13053
+ "No attributes or varyings": {
13054
+ [header]: "N/A"
13055
+ }
13056
+ };
13057
+ }
10202
13058
  for (const attributeDeclaration of layout.attributes) {
10203
13059
  if (attributeDeclaration) {
10204
13060
  const glslDeclaration = `${attributeDeclaration.location} ${attributeDeclaration.name}: ${attributeDeclaration.type}`;
@@ -10216,6 +13072,49 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
10216
13072
  return table;
10217
13073
  }
10218
13074
 
13075
+ // ../../node_modules/@luma.gl/engine/dist/debug/debug-framebuffer.js
13076
+ var canvas = null;
13077
+ var ctx = null;
13078
+ function debugFramebuffer(fbo, _ref) {
13079
+ let {
13080
+ id,
13081
+ minimap,
13082
+ opaque,
13083
+ top = "0",
13084
+ left = "0",
13085
+ rgbaScale = 1
13086
+ } = _ref;
13087
+ if (!canvas) {
13088
+ canvas = document.createElement("canvas");
13089
+ canvas.id = id;
13090
+ canvas.title = id;
13091
+ canvas.style.zIndex = "100";
13092
+ canvas.style.position = "absolute";
13093
+ canvas.style.top = top;
13094
+ canvas.style.left = left;
13095
+ canvas.style.border = "blue 1px solid";
13096
+ canvas.style.transform = "scaleY(-1)";
13097
+ document.body.appendChild(canvas);
13098
+ ctx = canvas.getContext("2d");
13099
+ }
13100
+ if (canvas.width !== fbo.width || canvas.height !== fbo.height) {
13101
+ canvas.width = fbo.width / 2;
13102
+ canvas.height = fbo.height / 2;
13103
+ canvas.style.width = "400px";
13104
+ canvas.style.height = "400px";
13105
+ }
13106
+ const color = fbo.device.readPixelsToArrayWebGL(fbo);
13107
+ const imageData = ctx.createImageData(fbo.width, fbo.height);
13108
+ const offset = 0;
13109
+ for (let i = 0; i < color.length; i += 4) {
13110
+ imageData.data[offset + i + 0] = color[i + 0] * rgbaScale;
13111
+ imageData.data[offset + i + 1] = color[i + 1] * rgbaScale;
13112
+ imageData.data[offset + i + 2] = color[i + 2] * rgbaScale;
13113
+ imageData.data[offset + i + 3] = opaque ? 255 : color[i + 3] * rgbaScale;
13114
+ }
13115
+ ctx.putImageData(imageData, 0, 0);
13116
+ }
13117
+
10219
13118
  // ../../node_modules/@luma.gl/engine/dist/model/model.js
10220
13119
  var LOG_DRAW_PRIORITY = 2;
10221
13120
  var LOG_DRAW_TIMEOUT = 1e4;
@@ -10250,6 +13149,7 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
10250
13149
  this.props = void 0;
10251
13150
  this._lastLogTime = 0;
10252
13151
  this._logOpen = false;
13152
+ this._drawCount = 0;
10253
13153
  this.props = {
10254
13154
  ...Model.defaultProps,
10255
13155
  ...props
@@ -10260,6 +13160,19 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
10260
13160
  Object.assign(this.userData, props.userData);
10261
13161
  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])) || []);
10262
13162
  this.setShaderInputs(props.shaderInputs || new ShaderInputs(moduleMap));
13163
+ const isWebGPU = this.device.info.type === "webgpu";
13164
+ if (this.props.source) {
13165
+ if (isWebGPU) {
13166
+ var _this$props;
13167
+ (_this$props = this.props).shaderLayout || (_this$props.shaderLayout = getShaderLayoutFromWGSL(this.props.source));
13168
+ }
13169
+ this.props.fs = this.props.source;
13170
+ this.props.vs = this.props.source;
13171
+ }
13172
+ if (isWebGPU && typeof this.props.vs !== "string") {
13173
+ var _this$props2;
13174
+ (_this$props2 = this.props).shaderLayout || (_this$props2.shaderLayout = getShaderLayoutFromWGSL(this.props.vs.wgsl));
13175
+ }
10263
13176
  const platformInfo = getPlatformInfo(device);
10264
13177
  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()) || [];
10265
13178
  const {
@@ -10347,6 +13260,7 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
10347
13260
  } finally {
10348
13261
  this._logDrawCallEnd();
10349
13262
  }
13263
+ this._logFramebuffer(renderPass);
10350
13264
  }
10351
13265
  setGeometry(geometry) {
10352
13266
  const gpuGeometry = geometry && makeGPUGeometry(this.device, geometry);
@@ -10358,9 +13272,18 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
10358
13272
  return gpuGeometry;
10359
13273
  }
10360
13274
  _setGeometryAttributes(gpuGeometry) {
13275
+ const attributes = {
13276
+ ...gpuGeometry.attributes
13277
+ };
13278
+ for (const [attributeName] of Object.entries(attributes)) {
13279
+ if (!this.pipeline.shaderLayout.attributes.find((layout) => layout.name === attributeName) && attributeName !== "positions") {
13280
+ delete attributes[attributeName];
13281
+ }
13282
+ }
10361
13283
  this.vertexCount = gpuGeometry.vertexCount;
10362
- this.setAttributes(gpuGeometry.attributes, "ignore-unknown");
10363
13284
  this.setIndexBuffer(gpuGeometry.indices);
13285
+ this.setAttributes(gpuGeometry.attributes, "ignore-unknown");
13286
+ this.setAttributes(attributes);
10364
13287
  }
10365
13288
  setTopology(topology) {
10366
13289
  if (topology !== this.topology) {
@@ -10399,6 +13322,18 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
10399
13322
  this.bindings[`${moduleName}Uniforms`] = uniformBuffer;
10400
13323
  }
10401
13324
  }
13325
+ setShaderModuleProps(props) {
13326
+ const uniforms = this._getModuleUniforms(props);
13327
+ const keys = Object.keys(uniforms).filter((k) => {
13328
+ const uniform = uniforms[k];
13329
+ return !(0, import_core37.isNumberArray)(uniform) && typeof uniform !== "number" && typeof uniform !== "boolean";
13330
+ });
13331
+ const bindings = {};
13332
+ for (const k of keys) {
13333
+ bindings[k] = uniforms[k];
13334
+ delete uniforms[k];
13335
+ }
13336
+ }
10402
13337
  updateShaderInputs() {
10403
13338
  this._uniformStore.setUniforms(this.shaderInputs.getUniformValues());
10404
13339
  }
@@ -10429,13 +13364,12 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
10429
13364
  import_core37.log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)();
10430
13365
  }
10431
13366
  for (const [bufferName, buffer] of Object.entries(buffers)) {
10432
- var _bufferLayout$attribu;
10433
- const bufferLayout = this.bufferLayout.find((layout) => layout.name === bufferName);
13367
+ const bufferLayout = this.bufferLayout.find((layout) => getAttributeNames(layout).includes(bufferName));
10434
13368
  if (!bufferLayout) {
10435
13369
  import_core37.log.warn(`Model(${this.id}): Missing layout for buffer "${bufferName}".`)();
10436
13370
  continue;
10437
13371
  }
10438
- const attributeNames = bufferLayout.attributes ? (_bufferLayout$attribu = bufferLayout.attributes) === null || _bufferLayout$attribu === void 0 ? void 0 : _bufferLayout$attribu.map((layout) => layout.attribute) : [bufferLayout.name];
13372
+ const attributeNames = getAttributeNames(bufferLayout);
10439
13373
  let set2 = false;
10440
13374
  for (const attributeName of attributeNames) {
10441
13375
  const attributeInfo = this._attributeInfos[attributeName];
@@ -10468,21 +13402,23 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
10468
13402
  import_core37.log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
10469
13403
  }
10470
13404
  this._pipelineNeedsUpdate = false;
13405
+ const vs5 = this.device.createShader({
13406
+ id: `${this.id}-vertex`,
13407
+ stage: "vertex",
13408
+ source: this.vs
13409
+ });
13410
+ const fs4 = this.fs ? this.device.createShader({
13411
+ id: `${this.id}-fragment`,
13412
+ stage: "fragment",
13413
+ source: this.fs
13414
+ }) : null;
10471
13415
  this.pipeline = this.device.createRenderPipeline({
10472
13416
  ...this.props,
10473
13417
  bufferLayout: this.bufferLayout,
10474
13418
  topology: this.topology,
10475
13419
  parameters: this.parameters,
10476
- vs: this.device.createShader({
10477
- id: "{$this.id}-vertex",
10478
- stage: "vertex",
10479
- source: this.vs
10480
- }),
10481
- fs: this.fs ? this.device.createShader({
10482
- id: "{$this.id}-fragment",
10483
- stage: "fragment",
10484
- source: this.fs
10485
- }) : null
13420
+ vs: vs5,
13421
+ fs: fs4
10486
13422
  });
10487
13423
  this._attributeInfos = (0, import_core38.getAttributeInfosFromLayouts)(this.pipeline.shaderLayout, this.bufferLayout);
10488
13424
  }
@@ -10490,8 +13426,8 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
10490
13426
  }
10491
13427
  _logDrawCallStart() {
10492
13428
  const logDrawTimeout = import_core37.log.level > 3 ? 0 : LOG_DRAW_TIMEOUT;
10493
- if (Date.now() - this._lastLogTime < logDrawTimeout) {
10494
- return void 0;
13429
+ if (import_core37.log.level < 2 || Date.now() - this._lastLogTime < logDrawTimeout) {
13430
+ return;
10495
13431
  }
10496
13432
  this._lastLogTime = Date.now();
10497
13433
  this._logOpen = true;
@@ -10501,7 +13437,7 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
10501
13437
  }
10502
13438
  _logDrawCallEnd() {
10503
13439
  if (this._logOpen) {
10504
- const shaderLayoutTable = getDebugTableForShaderLayout(this.pipeline.shaderLayout);
13440
+ const shaderLayoutTable = getDebugTableForShaderLayout(this.pipeline.shaderLayout, this.id);
10505
13441
  import_core37.log.table(LOG_DRAW_PRIORITY, shaderLayoutTable)();
10506
13442
  const uniformTable = this.shaderInputs.getDebugTable();
10507
13443
  for (const [name, value] of Object.entries(this.uniforms)) {
@@ -10510,13 +13446,58 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
10510
13446
  };
10511
13447
  }
10512
13448
  import_core37.log.table(LOG_DRAW_PRIORITY, uniformTable)();
13449
+ const attributeTable = this._getAttributeDebugTable();
13450
+ import_core37.log.table(LOG_DRAW_PRIORITY, this._attributeInfos)();
13451
+ import_core37.log.table(LOG_DRAW_PRIORITY, attributeTable)();
10513
13452
  import_core37.log.groupEnd(LOG_DRAW_PRIORITY)();
10514
13453
  this._logOpen = false;
10515
13454
  }
10516
13455
  }
13456
+ _logFramebuffer(renderPass) {
13457
+ const debugFramebuffers = import_core37.log.get("framebuffer");
13458
+ this._drawCount++;
13459
+ if (!debugFramebuffers || this._drawCount++ > 3 && this._drawCount % 60) {
13460
+ return;
13461
+ }
13462
+ const framebuffer = renderPass.props.framebuffer;
13463
+ if (framebuffer) {
13464
+ debugFramebuffer(framebuffer, {
13465
+ id: framebuffer.id,
13466
+ minimap: true
13467
+ });
13468
+ }
13469
+ }
13470
+ _getAttributeDebugTable() {
13471
+ const table = {};
13472
+ for (const [name, attributeInfo] of Object.entries(this._attributeInfos)) {
13473
+ table[attributeInfo.location] = {
13474
+ name,
13475
+ type: attributeInfo.shaderType,
13476
+ values: this._getBufferOrConstantValues(this.vertexArray.attributes[attributeInfo.location], attributeInfo.bufferDataType)
13477
+ };
13478
+ }
13479
+ if (this.vertexArray.indexBuffer) {
13480
+ const {
13481
+ indexBuffer
13482
+ } = this.vertexArray;
13483
+ const values = indexBuffer.indexType === "uint32" ? new Uint32Array(indexBuffer.debugData) : new Uint16Array(indexBuffer.debugData);
13484
+ table.indices = {
13485
+ name: "indices",
13486
+ type: indexBuffer.indexType,
13487
+ values: values.toString()
13488
+ };
13489
+ }
13490
+ return table;
13491
+ }
13492
+ _getBufferOrConstantValues(attribute, dataType) {
13493
+ const TypedArrayConstructor = (0, import_core36.getTypedArrayFromDataType)(dataType);
13494
+ const typedArray = attribute instanceof import_core36.Buffer ? new TypedArrayConstructor(attribute.debugData) : attribute;
13495
+ return typedArray.toString();
13496
+ }
10517
13497
  };
10518
13498
  Model.defaultProps = {
10519
13499
  ...import_core36.RenderPipeline.defaultProps,
13500
+ source: null,
10520
13501
  vs: null,
10521
13502
  fs: null,
10522
13503
  id: "unnamed",
@@ -10556,6 +13537,10 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
10556
13537
  features: device.features
10557
13538
  };
10558
13539
  }
13540
+ function getAttributeNames(bufferLayout) {
13541
+ var _bufferLayout$attribu;
13542
+ return bufferLayout.attributes ? (_bufferLayout$attribu = bufferLayout.attributes) === null || _bufferLayout$attribu === void 0 ? void 0 : _bufferLayout$attribu.map((layout) => layout.attribute) : [bufferLayout.name];
13543
+ }
10559
13544
 
10560
13545
  // src/data-filter/aggregator.ts
10561
13546
  var AGGREGATE_VS = `#version 300 es
@@ -11621,8 +14606,10 @@ float collision_isVisible(vec2 texCoords, vec3 pickingColor) {
11621
14606
  getModuleParameters() {
11622
14607
  return {
11623
14608
  drawToCollisionMap: true,
11624
- pickingActive: 1,
11625
- pickingAttribute: false,
14609
+ picking: {
14610
+ isActive: 1,
14611
+ isAttribute: false
14612
+ },
11626
14613
  lightSources: {}
11627
14614
  };
11628
14615
  }
@@ -12515,7 +15502,7 @@ if ((terrain_mode == TERRAIN_MODE_USE_COVER) || (terrain_mode == TERRAIN_MODE_US
12515
15502
  sampler = heightMap;
12516
15503
  bounds = heightMapBounds;
12517
15504
  } else if (terrainCover) {
12518
- const isPicking = opts.pickingActive;
15505
+ const isPicking = opts.picking?.isActive;
12519
15506
  sampler = isPicking ? terrainCover.getPickingFramebuffer() : terrainCover.getRenderFramebuffer();
12520
15507
  if (isPicking) {
12521
15508
  mode = TERRAIN_MODE.SKIP;