@luma.gl/engine 9.0.0-alpha.30 → 9.0.0-alpha.31

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
@@ -12,8 +12,8 @@ var __exports__ = (() => {
12
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
13
13
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
14
  var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
15
+ for (var name2 in all)
16
+ __defProp(target, name2, { get: all[name2], enumerable: true });
17
17
  };
18
18
  var __copyProps = (to, from, except, desc) => {
19
19
  if (from && typeof from === "object" || typeof from === "function") {
@@ -423,7 +423,7 @@ var __exports__ = (() => {
423
423
  for (const key of propNames) {
424
424
  const value = object[key];
425
425
  if (typeof value === "function") {
426
- if (!predefined.find((name) => key === name)) {
426
+ if (!predefined.find((name2) => key === name2)) {
427
427
  object[key] = value.bind(obj);
428
428
  }
429
429
  }
@@ -812,7 +812,7 @@ var __exports__ = (() => {
812
812
 
813
813
  // ../../node_modules/@probe.gl/stats/dist/lib/stat.js
814
814
  var Stat = class {
815
- constructor(name, type) {
815
+ constructor(name2, type) {
816
816
  this.name = void 0;
817
817
  this.type = void 0;
818
818
  this.sampleSize = 1;
@@ -827,7 +827,7 @@ var __exports__ = (() => {
827
827
  this._samples = 0;
828
828
  this._startTime = 0;
829
829
  this._timerPending = false;
830
- this.name = name;
830
+ this.name = name2;
831
831
  this.type = type;
832
832
  this.reset();
833
833
  }
@@ -932,10 +932,10 @@ var __exports__ = (() => {
932
932
  this._initializeStats(options.stats);
933
933
  Object.seal(this);
934
934
  }
935
- get(name) {
935
+ get(name2) {
936
936
  let type = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "count";
937
937
  return this._getOrCreate({
938
- name,
938
+ name: name2,
939
939
  type
940
940
  });
941
941
  }
@@ -971,17 +971,17 @@ var __exports__ = (() => {
971
971
  }
972
972
  _getOrCreate(stat) {
973
973
  const {
974
- name,
974
+ name: name2,
975
975
  type
976
976
  } = stat;
977
- let result = this.stats[name];
977
+ let result = this.stats[name2];
978
978
  if (!result) {
979
979
  if (stat instanceof Stat) {
980
980
  result = stat;
981
981
  } else {
982
- result = new Stat(name, type);
982
+ result = new Stat(name2, type);
983
983
  }
984
- this.stats[name] = result;
984
+ this.stats[name2] = result;
985
985
  }
986
986
  return result;
987
987
  }
@@ -990,16 +990,16 @@ var __exports__ = (() => {
990
990
  // ../core/src/lib/utils/stats-manager.ts
991
991
  var StatsManager = class {
992
992
  stats = /* @__PURE__ */ new Map();
993
- getStats(name) {
994
- return this.get(name);
993
+ getStats(name2) {
994
+ return this.get(name2);
995
995
  }
996
- get(name) {
997
- if (!this.stats.has(name)) {
998
- this.stats.set(name, new Stats({
999
- id: name
996
+ get(name2) {
997
+ if (!this.stats.has(name2)) {
998
+ this.stats.set(name2, new Stats({
999
+ id: name2
1000
1000
  }));
1001
1001
  }
1002
- return this.stats.get(name);
1002
+ return this.stats.get(name2);
1003
1003
  }
1004
1004
  };
1005
1005
  var lumaStats = new StatsManager();
@@ -1048,11 +1048,6 @@ var __exports__ = (() => {
1048
1048
  }
1049
1049
 
1050
1050
  // ../core/src/adapter/resources/resource.ts
1051
- var DEFAULT_RESOURCE_PROPS = {
1052
- id: "undefined",
1053
- handle: void 0,
1054
- userData: void 0
1055
- };
1056
1051
  var Resource = class {
1057
1052
  /** props.id, for debugging. */
1058
1053
  userData = {};
@@ -1137,34 +1132,38 @@ var __exports__ = (() => {
1137
1132
  /** Called by .destroy() to track object destruction. Subclass must call if overriding destroy() */
1138
1133
  removeStats() {
1139
1134
  const stats = this._device.statsManager.getStats("Resource Counts");
1140
- const name = this[Symbol.toStringTag];
1141
- stats.get(`${name}s Active`).decrementCount();
1135
+ const name2 = this[Symbol.toStringTag];
1136
+ stats.get(`${name2}s Active`).decrementCount();
1142
1137
  }
1143
1138
  /** Called by subclass to track memory allocations */
1144
- trackAllocatedMemory(bytes, name = this[Symbol.toStringTag]) {
1139
+ trackAllocatedMemory(bytes, name2 = this[Symbol.toStringTag]) {
1145
1140
  const stats = this._device.statsManager.getStats("Resource Counts");
1146
1141
  stats.get("GPU Memory").addCount(bytes);
1147
- stats.get(`${name} Memory`).addCount(bytes);
1142
+ stats.get(`${name2} Memory`).addCount(bytes);
1148
1143
  this.allocatedBytes = bytes;
1149
1144
  }
1150
1145
  /** Called by subclass to track memory deallocations */
1151
- trackDeallocatedMemory(name = this[Symbol.toStringTag]) {
1146
+ trackDeallocatedMemory(name2 = this[Symbol.toStringTag]) {
1152
1147
  const stats = this._device.statsManager.getStats("Resource Counts");
1153
1148
  stats.get("GPU Memory").subtractCount(this.allocatedBytes);
1154
- stats.get(`${name} Memory`).subtractCount(this.allocatedBytes);
1149
+ stats.get(`${name2} Memory`).subtractCount(this.allocatedBytes);
1155
1150
  this.allocatedBytes = 0;
1156
1151
  }
1157
1152
  /** Called by resource constructor to track object creation */
1158
1153
  addStats() {
1159
1154
  const stats = this._device.statsManager.getStats("Resource Counts");
1160
- const name = this[Symbol.toStringTag];
1155
+ const name2 = this[Symbol.toStringTag];
1161
1156
  stats.get("Resources Created").incrementCount();
1162
- stats.get(`${name}s Created`).incrementCount();
1163
- stats.get(`${name}s Active`).incrementCount();
1157
+ stats.get(`${name2}s Created`).incrementCount();
1158
+ stats.get(`${name2}s Active`).incrementCount();
1164
1159
  }
1165
1160
  };
1166
1161
  /** Default properties for resource */
1167
- __publicField(Resource, "defaultProps", DEFAULT_RESOURCE_PROPS);
1162
+ __publicField(Resource, "defaultProps", {
1163
+ id: "undefined",
1164
+ handle: void 0,
1165
+ userData: void 0
1166
+ });
1168
1167
  function selectivelyMerge(props, defaultProps) {
1169
1168
  const mergedProps = {
1170
1169
  ...defaultProps
@@ -1178,16 +1177,6 @@ var __exports__ = (() => {
1178
1177
  }
1179
1178
 
1180
1179
  // ../core/src/adapter/resources/buffer.ts
1181
- var DEFAULT_BUFFER_PROPS = {
1182
- ...DEFAULT_RESOURCE_PROPS,
1183
- usage: 0,
1184
- // Buffer.COPY_DST | Buffer.COPY_SRC
1185
- byteLength: 0,
1186
- byteOffset: 0,
1187
- data: null,
1188
- indexType: "uint16",
1189
- mappedAtCreation: false
1190
- };
1191
1180
  var _Buffer = class extends Resource {
1192
1181
  get [Symbol.toStringTag]() {
1193
1182
  return "Buffer";
@@ -1204,7 +1193,7 @@ var __exports__ = (() => {
1204
1193
  deducedProps.indexType = "uint16";
1205
1194
  }
1206
1195
  }
1207
- super(device, deducedProps, DEFAULT_BUFFER_PROPS);
1196
+ super(device, deducedProps, _Buffer.defaultProps);
1208
1197
  }
1209
1198
  write(data, byteOffset) {
1210
1199
  throw new Error("not implemented");
@@ -1262,6 +1251,16 @@ var __exports__ = (() => {
1262
1251
  // abstract unmap(): void;
1263
1252
  };
1264
1253
  var Buffer2 = _Buffer;
1254
+ __publicField(Buffer2, "defaultProps", {
1255
+ ...Resource.defaultProps,
1256
+ usage: 0,
1257
+ // Buffer.COPY_DST | Buffer.COPY_SRC
1258
+ byteLength: 0,
1259
+ byteOffset: 0,
1260
+ data: null,
1261
+ indexType: "uint16",
1262
+ mappedAtCreation: false
1263
+ });
1265
1264
  // Usage Flags
1266
1265
  __publicField(Buffer2, "MAP_READ", 1);
1267
1266
  __publicField(Buffer2, "MAP_WRITE", 2);
@@ -1311,8 +1310,14 @@ var __exports__ = (() => {
1311
1310
  };
1312
1311
  this.id = this.props.id || uid(this[Symbol.toStringTag].toLowerCase());
1313
1312
  }
1313
+ /** id of this device, primarily for debugging */
1314
+ /** stats */
1314
1315
  statsManager = lumaStats;
1316
+ /** A copy of the device props */
1317
+ /** Available for the application to store data on the device */
1315
1318
  userData = {};
1319
+ /** Used by other luma.gl modules to store data on the device */
1320
+ _lumaData = {};
1316
1321
  // Capabilities
1317
1322
  /** Information about the device (vendor, versions etc) */
1318
1323
  /** Optional capability discovery */
@@ -1717,25 +1722,7 @@ var __exports__ = (() => {
1717
1722
  }
1718
1723
 
1719
1724
  // ../core/src/adapter/resources/texture.ts
1720
- var DEFAULT_TEXTURE_PROPS = {
1721
- ...DEFAULT_RESOURCE_PROPS,
1722
- data: null,
1723
- dimension: "2d",
1724
- format: "rgba8unorm",
1725
- width: void 0,
1726
- height: void 0,
1727
- depth: 1,
1728
- mipmaps: true,
1729
- sampler: {},
1730
- // type: undefined,
1731
- compressed: false,
1732
- // mipLevels: 1,
1733
- usage: 0,
1734
- mipLevels: void 0,
1735
- samples: void 0,
1736
- type: void 0
1737
- };
1738
- var Texture = class extends Resource {
1725
+ var _Texture = class extends Resource {
1739
1726
  get [Symbol.toStringTag]() {
1740
1727
  return "Texture";
1741
1728
  }
@@ -1745,7 +1732,7 @@ var __exports__ = (() => {
1745
1732
  /** height in pixels of this texture */
1746
1733
  /** depth of this texture */
1747
1734
  /** Default sampler for this texture */
1748
- constructor(device, props, defaultProps = DEFAULT_TEXTURE_PROPS) {
1735
+ constructor(device, props, defaultProps = _Texture.defaultProps) {
1749
1736
  super(device, props, defaultProps);
1750
1737
  this.dimension = this.props.dimension;
1751
1738
  this.format = this.props.format;
@@ -1754,6 +1741,26 @@ var __exports__ = (() => {
1754
1741
  this.depth = this.props.depth;
1755
1742
  }
1756
1743
  };
1744
+ var Texture = _Texture;
1745
+ __publicField(Texture, "defaultProps", {
1746
+ ...Resource.defaultProps,
1747
+ data: null,
1748
+ dimension: "2d",
1749
+ format: "rgba8unorm",
1750
+ width: void 0,
1751
+ height: void 0,
1752
+ depth: 1,
1753
+ mipmaps: true,
1754
+ sampler: {},
1755
+ // type: undefined,
1756
+ compressed: false,
1757
+ // mipLevels: 1,
1758
+ usage: 0,
1759
+ // usage: GPUTextureUsage.COPY_DST
1760
+ mipLevels: void 0,
1761
+ samples: void 0,
1762
+ type: void 0
1763
+ });
1757
1764
  __publicField(Texture, "COPY_SRC", 1);
1758
1765
  __publicField(Texture, "COPY_DST", 2);
1759
1766
  __publicField(Texture, "TEXTURE_BINDING", 4);
@@ -1761,28 +1768,38 @@ var __exports__ = (() => {
1761
1768
  __publicField(Texture, "RENDER_ATTACHMENT", 16);
1762
1769
 
1763
1770
  // ../core/src/adapter/resources/shader.ts
1764
- var DEFAULT_SHADER_PROPS = {
1765
- ...DEFAULT_RESOURCE_PROPS,
1766
- stage: "vertex",
1767
- source: "",
1768
- sourceMap: null,
1769
- language: "glsl",
1770
- shaderType: 0
1771
- };
1772
- var Shader = class extends Resource {
1771
+ var _Shader = class extends Resource {
1773
1772
  get [Symbol.toStringTag]() {
1774
1773
  return "Shader";
1775
1774
  }
1776
1775
  constructor(device, props) {
1777
- super(device, props, DEFAULT_SHADER_PROPS);
1776
+ super(device, props, _Shader.defaultProps);
1778
1777
  this.stage = this.props.stage;
1779
1778
  this.source = this.props.source;
1780
1779
  }
1781
1780
  };
1781
+ var Shader = _Shader;
1782
+ __publicField(Shader, "defaultProps", {
1783
+ ...Resource.defaultProps,
1784
+ stage: "vertex",
1785
+ source: "",
1786
+ sourceMap: null,
1787
+ language: "glsl",
1788
+ shaderType: 0
1789
+ });
1782
1790
 
1783
1791
  // ../core/src/adapter/resources/sampler.ts
1784
- var DEFAULT_SAMPLER_PROPS = {
1785
- ...DEFAULT_RESOURCE_PROPS,
1792
+ var _Sampler = class extends Resource {
1793
+ get [Symbol.toStringTag]() {
1794
+ return "Sampler";
1795
+ }
1796
+ constructor(device, props) {
1797
+ super(device, props, _Sampler.defaultProps);
1798
+ }
1799
+ };
1800
+ var Sampler = _Sampler;
1801
+ __publicField(Sampler, "defaultProps", {
1802
+ ...Resource.defaultProps,
1786
1803
  type: "color-sampler",
1787
1804
  addressModeU: "clamp-to-edge",
1788
1805
  addressModeV: "clamp-to-edge",
@@ -1795,27 +1812,10 @@ var __exports__ = (() => {
1795
1812
  // Per WebGPU spec
1796
1813
  compare: "less-equal",
1797
1814
  maxAnisotropy: 1
1798
- };
1799
- var Sampler = class extends Resource {
1800
- get [Symbol.toStringTag]() {
1801
- return "Sampler";
1802
- }
1803
- constructor(device, props) {
1804
- super(device, props, DEFAULT_SAMPLER_PROPS);
1805
- }
1806
- };
1815
+ });
1807
1816
 
1808
1817
  // ../core/src/adapter/resources/framebuffer.ts
1809
- var DEFAULT_FRAMEBUFFER_PROPS = {
1810
- ...DEFAULT_RESOURCE_PROPS,
1811
- width: 1,
1812
- height: 1,
1813
- colorAttachments: [],
1814
- // ['rgba8unorm-unsized'],
1815
- depthStencilAttachment: null
1816
- // 'depth24plus-stencil8'
1817
- };
1818
- var Framebuffer = class extends Resource {
1818
+ var _Framebuffer = class extends Resource {
1819
1819
  get [Symbol.toStringTag]() {
1820
1820
  return "Framebuffer";
1821
1821
  }
@@ -1826,7 +1826,7 @@ var __exports__ = (() => {
1826
1826
  /** Depth-stencil attachment, if provided */
1827
1827
  depthStencilAttachment = null;
1828
1828
  constructor(device, props = {}) {
1829
- super(device, props, DEFAULT_FRAMEBUFFER_PROPS);
1829
+ super(device, props, _Framebuffer.defaultProps);
1830
1830
  this.width = this.props.width;
1831
1831
  this.height = this.props.height;
1832
1832
  }
@@ -1992,10 +1992,36 @@ var __exports__ = (() => {
1992
1992
  }
1993
1993
  */
1994
1994
  };
1995
+ var Framebuffer = _Framebuffer;
1996
+ __publicField(Framebuffer, "defaultProps", {
1997
+ ...Resource.defaultProps,
1998
+ width: 1,
1999
+ height: 1,
2000
+ colorAttachments: [],
2001
+ // ['rgba8unorm-unsized'],
2002
+ depthStencilAttachment: null
2003
+ // 'depth24plus-stencil8'
2004
+ });
1995
2005
 
1996
2006
  // ../core/src/adapter/resources/render-pipeline.ts
1997
- var DEFAULT_RENDER_PIPELINE_PROPS = {
1998
- ...DEFAULT_RESOURCE_PROPS,
2007
+ var _RenderPipeline = class extends Resource {
2008
+ get [Symbol.toStringTag]() {
2009
+ return "RenderPipeline";
2010
+ }
2011
+ hash = "";
2012
+ constructor(device, props) {
2013
+ super(device, props, _RenderPipeline.defaultProps);
2014
+ }
2015
+ /** Set attributes (stored on pipeline and set before each call) */
2016
+ /** Set attributes (stored on pipeline and set before each call) */
2017
+ /** Set constant attributes (WebGL only) */
2018
+ /** Set bindings (stored on pipeline and set before each call) */
2019
+ /** Uniforms (only supported on WebGL devices. Reset before each call to enable pipeline sharing) */
2020
+ /** Draw call */
2021
+ };
2022
+ var RenderPipeline = _RenderPipeline;
2023
+ __publicField(RenderPipeline, "defaultProps", {
2024
+ ...Resource.defaultProps,
1999
2025
  vs: null,
2000
2026
  vsEntryPoint: "",
2001
2027
  // main
@@ -2004,36 +2030,17 @@ var __exports__ = (() => {
2004
2030
  fsEntryPoint: "",
2005
2031
  // main
2006
2032
  fsConstants: {},
2007
- layout: null,
2008
- // {attributes: [], bindings: []},
2033
+ shaderLayout: null,
2034
+ bufferLayout: [],
2009
2035
  topology: "triangle-list",
2010
- // targets:
2011
2036
  parameters: {},
2012
- bufferMap: [],
2013
2037
  vertexCount: 0,
2014
2038
  instanceCount: 0,
2015
2039
  indices: null,
2016
2040
  attributes: {},
2017
2041
  bindings: {},
2018
2042
  uniforms: {}
2019
- };
2020
- var RenderPipeline = class extends Resource {
2021
- get [Symbol.toStringTag]() {
2022
- return "RenderPipeline";
2023
- }
2024
- hash = "";
2025
- constructor(device, props) {
2026
- super(device, props, DEFAULT_RENDER_PIPELINE_PROPS);
2027
- }
2028
- };
2029
- /** Set attributes (stored on pipeline and set before each call) */
2030
- /** Set attributes (stored on pipeline and set before each call) */
2031
- /** Set constant attributes (WebGL only) */
2032
- /** Set bindings (stored on pipeline and set before each call) */
2033
- /** Uniforms (only supported on WebGL devices. Reset before each call to enable pipeline sharing) */
2034
- /** Draw call */
2035
- /** Private "export" for Model class */
2036
- __publicField(RenderPipeline, "_DEFAULT_PROPS", DEFAULT_RENDER_PIPELINE_PROPS);
2043
+ });
2037
2044
 
2038
2045
  // ../core/src/adapter/resources/render-pass.ts
2039
2046
  var _RenderPass = class extends Resource {
@@ -2093,15 +2100,12 @@ var __exports__ = (() => {
2093
2100
  });
2094
2101
 
2095
2102
  // ../core/src/adapter/resources/command-encoder.ts
2096
- var DEFAULT_COMMAND_ENCODER_PROPS = {
2097
- ...DEFAULT_RESOURCE_PROPS
2098
- };
2099
- var CommandEncoder = class extends Resource {
2103
+ var _CommandEncoder = class extends Resource {
2100
2104
  get [Symbol.toStringTag]() {
2101
2105
  return "CommandEncoder";
2102
2106
  }
2103
- constructor(props) {
2104
- super(props, DEFAULT_COMMAND_ENCODER_PROPS);
2107
+ constructor(device, props) {
2108
+ super(device, props, _CommandEncoder.defaultProps);
2105
2109
  }
2106
2110
  // TODO - return the CommandBuffer?
2107
2111
  // beginRenderPass(GPURenderPassDescriptor descriptor): GPURenderPassEncoder;
@@ -2122,19 +2126,25 @@ var __exports__ = (() => {
2122
2126
  // destinationOffset?: number;
2123
2127
  // }): void;
2124
2128
  };
2129
+ var CommandEncoder = _CommandEncoder;
2130
+ __publicField(CommandEncoder, "defaultProps", {
2131
+ ...Resource.defaultProps,
2132
+ measureExecutionTime: void 0
2133
+ });
2125
2134
 
2126
2135
  // ../core/src/adapter/resources/command-buffer.ts
2127
- var DEFAULT_COMMAND_ENCODER_PROPS2 = {
2128
- ...DEFAULT_RESOURCE_PROPS
2129
- };
2130
- var CommandBuffer = class extends Resource {
2136
+ var _CommandBuffer = class extends Resource {
2131
2137
  get [Symbol.toStringTag]() {
2132
2138
  return "CommandBuffer";
2133
2139
  }
2134
2140
  constructor(props) {
2135
- super(props, DEFAULT_COMMAND_ENCODER_PROPS2);
2141
+ super(props, _CommandBuffer.defaultProps);
2136
2142
  }
2137
2143
  };
2144
+ var CommandBuffer = _CommandBuffer;
2145
+ __publicField(CommandBuffer, "defaultProps", {
2146
+ ...Resource.defaultProps
2147
+ });
2138
2148
 
2139
2149
  // ../core/src/lib/utils/assert.ts
2140
2150
  function assert2(condition, message2) {
@@ -2143,7 +2153,7 @@ var __exports__ = (() => {
2143
2153
  }
2144
2154
  }
2145
2155
 
2146
- // ../core/src/adapter/utils/decode-data-type.ts
2156
+ // ../core/src/adapter/type-utils/decode-data-type.ts
2147
2157
  function decodeVertexType(type) {
2148
2158
  const dataType = TYPE_MAP[type];
2149
2159
  const bytes = getDataTypeBytes(dataType);
@@ -2187,7 +2197,7 @@ var __exports__ = (() => {
2187
2197
  sint32: 4
2188
2198
  };
2189
2199
 
2190
- // ../core/src/adapter/utils/decode-vertex-format.ts
2200
+ // ../core/src/adapter/type-utils/decode-vertex-format.ts
2191
2201
  function decodeVertexFormat(format) {
2192
2202
  let webglOnly;
2193
2203
  if (format.endsWith("-webgl")) {
@@ -2212,7 +2222,7 @@ var __exports__ = (() => {
2212
2222
  return result;
2213
2223
  }
2214
2224
 
2215
- // ../core/src/adapter/utils/decode-texture-format.ts
2225
+ // ../core/src/adapter/type-utils/decode-texture-format.ts
2216
2226
  var REGEX = /^(rg?b?a?)([0-9]*)([a-z]*)(-srgb)?(-webgl|-unsized)?$/;
2217
2227
  function decodeTextureFormat(format) {
2218
2228
  const matches = REGEX.exec(format);
@@ -2318,6 +2328,68 @@ var __exports__ = (() => {
2318
2328
  };
2319
2329
  }
2320
2330
 
2331
+ // ../core/src/adapter/type-utils/decode-attribute-type.ts
2332
+ function decodeShaderAttributeType(attributeType) {
2333
+ const [dataType, components] = TYPE_INFO[attributeType];
2334
+ const integer = dataType === "i32" || dataType === "u32";
2335
+ const signed = dataType !== "u32";
2336
+ const byteLength = TYPE_SIZES2[dataType] * components;
2337
+ const defaultVertexFormat = getCompatibleVertexFormat(dataType, components);
2338
+ return {
2339
+ dataType,
2340
+ components,
2341
+ defaultVertexFormat,
2342
+ byteLength,
2343
+ integer,
2344
+ signed
2345
+ };
2346
+ }
2347
+ function getCompatibleVertexFormat(dataType, components) {
2348
+ let vertexType;
2349
+ switch (dataType) {
2350
+ case "f32":
2351
+ vertexType = "float32";
2352
+ break;
2353
+ case "i32":
2354
+ vertexType = "sint32";
2355
+ break;
2356
+ case "u32":
2357
+ vertexType = "uint32";
2358
+ break;
2359
+ case "f16":
2360
+ return components <= 2 ? "float16x2" : "float16x4";
2361
+ }
2362
+ if (components === 1) {
2363
+ return vertexType;
2364
+ }
2365
+ return `${vertexType}x${components}`;
2366
+ }
2367
+ var TYPE_INFO = {
2368
+ f32: ["f32", 1],
2369
+ "vec2<f32>": ["f32", 2],
2370
+ "vec3<f32>": ["f32", 3],
2371
+ "vec4<f32>": ["f32", 4],
2372
+ f16: ["f16", 1],
2373
+ "vec2<f16>": ["f16", 2],
2374
+ "vec3<f16>": ["f16", 3],
2375
+ "vec4<f16>": ["f16", 4],
2376
+ i32: ["i32", 1],
2377
+ "vec2<i32>": ["i32", 2],
2378
+ "vec3<i32>": ["i32", 3],
2379
+ "vec4<i32>": ["i32", 4],
2380
+ u32: ["u32", 1],
2381
+ "vec2<u32>": ["u32", 2],
2382
+ "vec3<u32>": ["u32", 3],
2383
+ "vec4<u32>": ["u32", 4]
2384
+ };
2385
+ var TYPE_SIZES2 = {
2386
+ f32: 4,
2387
+ f16: 2,
2388
+ i32: 4,
2389
+ u32: 4
2390
+ // 'bool-webgl': 4,
2391
+ };
2392
+
2321
2393
  // ../core/src/lib/compiler-log/format-compiler-log.ts
2322
2394
  function formatCompilerLog(shaderLog, source, options) {
2323
2395
  const lines = source.split(/\r?\n/);
@@ -2358,6 +2430,102 @@ var __exports__ = (() => {
2358
2430
  return result + string;
2359
2431
  }
2360
2432
 
2433
+ // ../core/src/adapter/attribute-utils/get-attribute-from-layouts.ts
2434
+ function getAttributeInfosFromLayouts(shaderLayout, bufferLayout) {
2435
+ const attributeInfos = {};
2436
+ for (const attribute of shaderLayout.attributes) {
2437
+ attributeInfos[attribute.name] = getAttributeInfoFromLayouts(shaderLayout, bufferLayout, attribute.name);
2438
+ }
2439
+ return attributeInfos;
2440
+ }
2441
+ function getAttributeInfoFromLayouts(shaderLayout, bufferLayout, name2) {
2442
+ const shaderDeclaration = getAttributeFromShaderLayout(shaderLayout, name2);
2443
+ const bufferMapping = getAttributeFromBufferLayout(bufferLayout, name2);
2444
+ if (!shaderDeclaration) {
2445
+ return null;
2446
+ }
2447
+ const attributeTypeInfo = decodeShaderAttributeType(shaderDeclaration.type);
2448
+ const vertexFormat = bufferMapping?.vertexFormat || attributeTypeInfo.defaultVertexFormat;
2449
+ const vertexFormatInfo = decodeVertexFormat(vertexFormat);
2450
+ return {
2451
+ name: name2,
2452
+ bufferName: bufferMapping?.name || name2,
2453
+ location: shaderDeclaration.location,
2454
+ shaderType: shaderDeclaration.type,
2455
+ shaderDataType: attributeTypeInfo.dataType,
2456
+ shaderComponents: attributeTypeInfo.components,
2457
+ vertexFormat,
2458
+ bufferDataType: vertexFormatInfo.type,
2459
+ bufferComponents: vertexFormatInfo.components,
2460
+ // normalized is a property of the buffer's vertex format
2461
+ normalized: vertexFormatInfo.normalized,
2462
+ // integer is a property of the shader declaration
2463
+ integer: attributeTypeInfo.integer,
2464
+ stepMode: bufferMapping?.stepMode || shaderDeclaration.stepMode,
2465
+ byteOffset: bufferMapping?.byteOffset || 0,
2466
+ byteStride: bufferMapping?.byteStride || 0
2467
+ };
2468
+ }
2469
+ function getAttributeFromShaderLayout(shaderLayout, name2) {
2470
+ const attribute = shaderLayout.attributes.find((attr) => attr.name === name2);
2471
+ if (!attribute) {
2472
+ log.warn(`shader layout attribute "${name2}" not present in shader`);
2473
+ }
2474
+ return attribute || null;
2475
+ }
2476
+ function getAttributeFromBufferLayout(bufferLayout, name2) {
2477
+ for (const bufferMapping of bufferLayout) {
2478
+ if (bufferMapping.name === name2) {
2479
+ return {
2480
+ name: bufferMapping.name,
2481
+ bufferName: name2,
2482
+ vertexFormat: bufferMapping.format,
2483
+ byteOffset: bufferMapping.byteOffset || 0,
2484
+ byteStride: bufferMapping.byteStride || 0
2485
+ };
2486
+ }
2487
+ let nextByteOffset = bufferMapping.byteOffset || 0;
2488
+ let byteStride = 0;
2489
+ for (const interleavedMapping of bufferMapping.attributes || []) {
2490
+ const info = decodeVertexFormat(interleavedMapping.format);
2491
+ byteStride += info.byteLength;
2492
+ }
2493
+ for (const interleavedMapping of bufferMapping.attributes || []) {
2494
+ const byteOffset = nextByteOffset;
2495
+ nextByteOffset += interleavedMapping?.byteStrideOffset || decodeVertexFormat(interleavedMapping.format).byteLength;
2496
+ if (interleavedMapping.name === name2) {
2497
+ return {
2498
+ name: bufferMapping.name,
2499
+ bufferName: name2,
2500
+ vertexFormat: interleavedMapping.format,
2501
+ byteOffset,
2502
+ byteStride: bufferMapping.byteStride || byteStride
2503
+ };
2504
+ }
2505
+ }
2506
+ }
2507
+ log.warn(`layout for attribute "${name2}" not present in buffer layout`);
2508
+ return null;
2509
+ }
2510
+ function mergeShaderLayout(baseLayout, overrideLayout) {
2511
+ const mergedLayout = {
2512
+ ...baseLayout,
2513
+ attributes: baseLayout.attributes.map((attribute) => ({
2514
+ ...attribute
2515
+ }))
2516
+ };
2517
+ for (const attribute of overrideLayout?.attributes || []) {
2518
+ const baseAttribute = mergedLayout.attributes.find((attr) => attr.name === attribute.name);
2519
+ if (!baseAttribute) {
2520
+ log.warn(`shader layout attribute ${attribute.name} not present in shader`);
2521
+ } else {
2522
+ baseAttribute.type = attribute.type || baseAttribute.type;
2523
+ baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
2524
+ }
2525
+ }
2526
+ return mergedLayout;
2527
+ }
2528
+
2361
2529
  // ../core/src/lib/utils/cast.ts
2362
2530
  function cast(value) {
2363
2531
  return value;
@@ -2918,8 +3086,8 @@ var __exports__ = (() => {
2918
3086
  }
2919
3087
  function getAttributeBuffersFromGeometry(device, geometry) {
2920
3088
  const buffers = {};
2921
- for (const [name, attribute] of Object.entries(geometry.attributes)) {
2922
- const remappedName = mapAttributeName(name);
3089
+ for (const [name2, attribute] of Object.entries(geometry.attributes)) {
3090
+ const remappedName = mapAttributeName(name2);
2923
3091
  if (attribute?.constant) {
2924
3092
  throw new Error("constant attributes not supported");
2925
3093
  } else {
@@ -2932,8 +3100,8 @@ var __exports__ = (() => {
2932
3100
  }
2933
3101
  return buffers;
2934
3102
  }
2935
- function mapAttributeName(name) {
2936
- return GLTF_TO_LUMA_ATTRIBUTE_MAP[name] || name;
3103
+ function mapAttributeName(name2) {
3104
+ return GLTF_TO_LUMA_ATTRIBUTE_MAP[name2] || name2;
2937
3105
  }
2938
3106
 
2939
3107
  // ../shadertools/src/lib/glsl-utils/highlight.ts
@@ -2963,8 +3131,8 @@ var __exports__ = (() => {
2963
3131
  };
2964
3132
  function makePropValidators(propTypes) {
2965
3133
  const propValidators = {};
2966
- for (const [name, propType] of Object.entries(propTypes)) {
2967
- propValidators[name] = makePropValidator(propType);
3134
+ for (const [name2, propType] of Object.entries(propTypes)) {
3135
+ propValidators[name2] = makePropValidator(propType);
2968
3136
  }
2969
3137
  return propValidators;
2970
3138
  }
@@ -3045,7 +3213,7 @@ var __exports__ = (() => {
3045
3213
  }
3046
3214
  constructor(props) {
3047
3215
  const {
3048
- name,
3216
+ name: name2,
3049
3217
  vs,
3050
3218
  fs,
3051
3219
  dependencies = [],
@@ -3055,8 +3223,8 @@ var __exports__ = (() => {
3055
3223
  defines = {},
3056
3224
  inject = {}
3057
3225
  } = props;
3058
- assert3(typeof name === "string");
3059
- this.name = name;
3226
+ assert3(typeof name2 === "string");
3227
+ this.name = name2;
3060
3228
  this.vs = vs;
3061
3229
  this.fs = fs;
3062
3230
  this.getModuleUniforms = getUniforms;
@@ -3172,7 +3340,7 @@ ${moduleSource}// END MODULE_${this.name}
3172
3340
  moduleMap,
3173
3341
  moduleDepth
3174
3342
  });
3175
- return Object.keys(moduleDepth).sort((a, b) => moduleDepth[b] - moduleDepth[a]).map((name) => moduleMap[name]);
3343
+ return Object.keys(moduleDepth).sort((a, b) => moduleDepth[b] - moduleDepth[a]).map((name2) => moduleMap[name2]);
3176
3344
  }
3177
3345
  function getDependencyGraph(options) {
3178
3346
  const {
@@ -3571,9 +3739,9 @@ ${isVertex ? "" : FRAGMENT_SHADER_PROLOGUE}
3571
3739
  const match = /^(v|f)s:(#)?([\w-]+)$/.exec(key);
3572
3740
  if (match) {
3573
3741
  const hash = match[2];
3574
- const name = match[3];
3742
+ const name2 = match[3];
3575
3743
  if (hash) {
3576
- if (name === "decl") {
3744
+ if (name2 === "decl") {
3577
3745
  declInjections[key] = [injection];
3578
3746
  } else {
3579
3747
  mainInjections[key] = [injection];
@@ -3595,8 +3763,8 @@ ${isVertex ? "" : FRAGMENT_SHADER_PROLOGUE}
3595
3763
  for (const key in injections) {
3596
3764
  const match = /^(v|f)s:#([\w-]+)$/.exec(key);
3597
3765
  if (match) {
3598
- const name = match[2];
3599
- const injectionType = name === "decl" ? declInjections : mainInjections;
3766
+ const name2 = match[2];
3767
+ const injectionType = name2 === "decl" ? declInjections : mainInjections;
3600
3768
  injectionType[key] = injectionType[key] || [];
3601
3769
  injectionType[key].push(injections[key]);
3602
3770
  } else {
@@ -3700,11 +3868,11 @@ ${isVertex ? "" : FRAGMENT_SHADER_PROLOGUE}
3700
3868
  }
3701
3869
  hook = hook.trim();
3702
3870
  const [stage, signature] = hook.split(":");
3703
- const name = hook.replace(/\(.+/, "");
3871
+ const name2 = hook.replace(/\(.+/, "");
3704
3872
  if (stage !== "vs" && stage !== "fs") {
3705
3873
  throw new Error(stage);
3706
3874
  }
3707
- result[stage][name] = Object.assign(opts, {
3875
+ result[stage][name2] = Object.assign(opts, {
3708
3876
  signature
3709
3877
  });
3710
3878
  });
@@ -5690,7 +5858,7 @@ void main() {
5690
5858
  defines: {},
5691
5859
  inject: {},
5692
5860
  transpileToGLSL100: false,
5693
- layout: null,
5861
+ shaderLayout: null,
5694
5862
  varyings: [],
5695
5863
  bufferMode: 35981,
5696
5864
  // // varyings/bufferMode for xform feedback, 0x8c8d: SEPARATE_ATTRIBS
@@ -5848,16 +6016,16 @@ void main() {
5848
6016
  let count = 0;
5849
6017
  for (let i = 0, len = this._defaultModules.length; i < len; ++i) {
5850
6018
  const module = this._defaultModules[i];
5851
- const name = module.name;
6019
+ const name2 = module.name;
5852
6020
  modules[count++] = module;
5853
- seen[name] = true;
6021
+ seen[name2] = true;
5854
6022
  }
5855
6023
  for (let i = 0, len = appModules.length; i < len; ++i) {
5856
6024
  const module = appModules[i];
5857
- const name = module.name;
5858
- if (!seen[name]) {
6025
+ const name2 = module.name;
6026
+ if (!seen[name2]) {
5859
6027
  modules[count++] = module;
5860
- seen[name] = true;
6028
+ seen[name2] = true;
5861
6029
  }
5862
6030
  }
5863
6031
  modules.length = count;
@@ -5867,7 +6035,7 @@ void main() {
5867
6035
 
5868
6036
  // src/model/model.ts
5869
6037
  var DEFAULT_MODEL_PROPS = {
5870
- ...RenderPipeline._DEFAULT_PROPS,
6038
+ ...RenderPipeline.defaultProps,
5871
6039
  vs: null,
5872
6040
  fs: null,
5873
6041
  id: "unnamed",
@@ -5877,7 +6045,9 @@ void main() {
5877
6045
  modules: [],
5878
6046
  moduleSettings: {},
5879
6047
  geometry: null,
5880
- pipelineFactory: void 0
6048
+ pipelineFactory: void 0,
6049
+ vertexCount: 0,
6050
+ instanceCount: 0
5881
6051
  };
5882
6052
  var Model = class {
5883
6053
  fs = null;
@@ -5928,7 +6098,7 @@ void main() {
5928
6098
  topology: this.topology,
5929
6099
  defines: props.defines,
5930
6100
  parameters: props.parameters,
5931
- layout: props.layout
6101
+ shaderLayout: props.shaderLayout
5932
6102
  });
5933
6103
  this.pipeline = pipeline;
5934
6104
  this._getModuleUniforms = getUniforms;
@@ -6974,12 +7144,12 @@ void main() {
6974
7144
  return list;
6975
7145
  };
6976
7146
  const original_getExtension = gl.getExtension;
6977
- gl.getExtension = function getExtension(name) {
6978
- const ext = original_getExtension.call(this, name);
7147
+ gl.getExtension = function getExtension(name2) {
7148
+ const ext = original_getExtension.call(this, name2);
6979
7149
  if (ext) {
6980
7150
  return ext;
6981
7151
  }
6982
- if (name !== "OES_vertex_array_object") {
7152
+ if (name2 !== "OES_vertex_array_object") {
6983
7153
  return null;
6984
7154
  }
6985
7155
  if (!gl.__OESVertexArrayObject) {
@@ -8166,6 +8336,37 @@ void main() {
8166
8336
  return isMSIE || isTrident;
8167
8337
  }
8168
8338
 
8339
+ // ../webgl/src/adapter/converters/vertex-formats.ts
8340
+ function getGLFromVertexType(dataType) {
8341
+ switch (dataType) {
8342
+ case "uint8":
8343
+ return GL.UNSIGNED_BYTE;
8344
+ case "sint8":
8345
+ return GL.BYTE;
8346
+ case "unorm8":
8347
+ return GL.UNSIGNED_BYTE;
8348
+ case "snorm8":
8349
+ return GL.BYTE;
8350
+ case "uint16":
8351
+ return GL.UNSIGNED_SHORT;
8352
+ case "sint16":
8353
+ return GL.SHORT;
8354
+ case "unorm16":
8355
+ return GL.UNSIGNED_SHORT;
8356
+ case "snorm16":
8357
+ return GL.SHORT;
8358
+ case "uint32":
8359
+ return GL.UNSIGNED_INT;
8360
+ case "sint32":
8361
+ return GL.INT;
8362
+ case "float16":
8363
+ return GL.HALF_FLOAT;
8364
+ case "float32":
8365
+ return GL.FLOAT;
8366
+ }
8367
+ throw new Error(String(dataType));
8368
+ }
8369
+
8169
8370
  // ../webgl/src/adapter/converters/texture-formats.ts
8170
8371
  var texture_compression_bc = "texture-compression-bc";
8171
8372
  var texture_compression_astc = "texture-compression-astc";
@@ -8947,7 +9148,7 @@ void main() {
8947
9148
  [GL.LUMINANCE]: 1,
8948
9149
  [GL.LUMINANCE_ALPHA]: 2
8949
9150
  };
8950
- var TYPE_SIZES2 = {
9151
+ var TYPE_SIZES3 = {
8951
9152
  [GL.FLOAT]: 4,
8952
9153
  [GL.UNSIGNED_INT]: 4,
8953
9154
  [GL.INT]: 4,
@@ -9031,7 +9232,8 @@ void main() {
9031
9232
  return {
9032
9233
  format: webglFormat,
9033
9234
  dataFormat: getWebGLPixelDataFormat(decoded.format, decoded.integer, decoded.normalized, webglFormat),
9034
- type: getWebGLDataType(decoded.dataType),
9235
+ // depth formats don't have a type
9236
+ type: decoded.dataType ? getGLFromVertexType(decoded.dataType) : GL.UNSIGNED_BYTE,
9035
9237
  // @ts-expect-error
9036
9238
  compressed: decoded.compressed
9037
9239
  };
@@ -9070,7 +9272,7 @@ void main() {
9070
9272
  const format = convertGLToTextureFormat(formatOrGL);
9071
9273
  const params = getWebGLTextureParameters(format, isWebGL23);
9072
9274
  const channels = DATA_FORMAT_CHANNELS[params.dataFormat] || 4;
9073
- const channelSize = TYPE_SIZES2[params.type] || 1;
9275
+ const channelSize = TYPE_SIZES3[params.type] || 1;
9074
9276
  return channels * channelSize;
9075
9277
  }
9076
9278
  function getWebGLPixelDataFormat(dataFormat, integer, normalized, format) {
@@ -9090,28 +9292,6 @@ void main() {
9090
9292
  return GL.RGBA;
9091
9293
  }
9092
9294
  }
9093
- function getWebGLDataType(dataType) {
9094
- switch (dataType) {
9095
- case "uint8":
9096
- return GL.UNSIGNED_BYTE;
9097
- case "sint8":
9098
- return GL.BYTE;
9099
- case "uint16":
9100
- return GL.UNSIGNED_SHORT;
9101
- case "sint16":
9102
- return GL.SHORT;
9103
- case "uint32":
9104
- return GL.UNSIGNED_INT;
9105
- case "sint32":
9106
- return GL.INT;
9107
- case "float16":
9108
- return GL.HALF_FLOAT;
9109
- case "float32":
9110
- return GL.FLOAT;
9111
- default:
9112
- return GL.UNSIGNED_BYTE;
9113
- }
9114
- }
9115
9295
 
9116
9296
  // ../webgl/src/adapter/device-helpers/device-features.ts
9117
9297
  function getDeviceFeatures(gl) {
@@ -10547,17 +10727,17 @@ void main(void) {}`;
10547
10727
  }
10548
10728
 
10549
10729
  // ../webgl/src/adapter/objects/constants-to-keys.ts
10550
- function getKeyValue(gl, name) {
10551
- if (typeof name !== "string") {
10552
- return name;
10730
+ function getKeyValue(gl, name2) {
10731
+ if (typeof name2 !== "string") {
10732
+ return name2;
10553
10733
  }
10554
- const number = Number(name);
10734
+ const number = Number(name2);
10555
10735
  if (!isNaN(number)) {
10556
10736
  return number;
10557
10737
  }
10558
- name = name.replace(/^.*\./, "");
10559
- const value = gl[name];
10560
- assert2(value !== void 0, `Accessing undefined constant GL.${name}`);
10738
+ name2 = name2.replace(/^.*\./, "");
10739
+ const value = gl[name2];
10740
+ assert2(value !== void 0, `Accessing undefined constant GL.${name2}`);
10561
10741
  return value;
10562
10742
  }
10563
10743
 
@@ -11984,7 +12164,7 @@ ${formattedLog}`)();
11984
12164
  // });
11985
12165
  };
11986
12166
 
11987
- // ../webgl/src/adapter/helpers/uniforms.ts
12167
+ // ../webgl/src/adapter/helpers/decode-webgl-types.ts
11988
12168
  function isSamplerUniform(type) {
11989
12169
  return SAMPLER_TYPES.includes(type);
11990
12170
  }
@@ -12002,10 +12182,11 @@ ${formattedLog}`)();
12002
12182
  [GL.UNSIGNED_INT_VEC2]: [GL.UNSIGNED_INT, 2, "uvec2", "vec2<u32>", "uint32x2"],
12003
12183
  [GL.UNSIGNED_INT_VEC3]: [GL.UNSIGNED_INT, 3, "uvec3", "vec3<u32>", "uint32x3"],
12004
12184
  [GL.UNSIGNED_INT_VEC4]: [GL.UNSIGNED_INT, 4, "uvec4", "vec4<u32>", "uint32x4"],
12005
- [GL.BOOL]: [GL.FLOAT, 1, "bool", "f32", "float32x2"],
12006
- [GL.BOOL_VEC2]: [GL.FLOAT, 2, "bvec2", "vec2<f32>"],
12007
- [GL.BOOL_VEC3]: [GL.FLOAT, 3, "bvec3", "vec3<f32>"],
12008
- [GL.BOOL_VEC4]: [GL.FLOAT, 4, "bvec4", "vec4<f32>"],
12185
+ [GL.BOOL]: [GL.FLOAT, 1, "bool", "f32", "float32"],
12186
+ [GL.BOOL_VEC2]: [GL.FLOAT, 2, "bvec2", "vec2<f32>", "float32x2"],
12187
+ [GL.BOOL_VEC3]: [GL.FLOAT, 3, "bvec3", "vec3<f32>", "float32x3"],
12188
+ [GL.BOOL_VEC4]: [GL.FLOAT, 4, "bvec4", "vec4<f32>", "float32x4"],
12189
+ // TODO - are sizes/components below correct?
12009
12190
  [GL.FLOAT_MAT2]: [GL.FLOAT, 8, "mat2", "mat2x2<f32>"],
12010
12191
  // 4
12011
12192
  [GL.FLOAT_MAT2x3]: [GL.FLOAT, 8, "mat2x3", "mat2x3<f32>"],
@@ -12025,8 +12206,8 @@ ${formattedLog}`)();
12025
12206
  [GL.FLOAT_MAT4]: [GL.FLOAT, 16, "mat4", "mat4x4<f32>"]
12026
12207
  // 16
12027
12208
  };
12028
- function decodeUniformType(uniformType) {
12029
- const typeAndSize = COMPOSITE_GL_TYPES[uniformType];
12209
+ function decodeGLUniformType(glUniformType) {
12210
+ const typeAndSize = COMPOSITE_GL_TYPES[glUniformType];
12030
12211
  if (!typeAndSize) {
12031
12212
  throw new Error("uniform");
12032
12213
  }
@@ -12037,68 +12218,27 @@ ${formattedLog}`)();
12037
12218
  glType
12038
12219
  };
12039
12220
  }
12040
- function decodeAttributeType(attributeType) {
12041
- const typeAndSize = COMPOSITE_GL_TYPES[attributeType];
12221
+ function decodeGLAttributeType(glAttributeType) {
12222
+ const typeAndSize = COMPOSITE_GL_TYPES[glAttributeType];
12042
12223
  if (!typeAndSize) {
12043
12224
  throw new Error("attribute");
12044
12225
  }
12045
- const [glType, components, , , format] = typeAndSize;
12226
+ const [, components, , shaderType, vertexFormat] = typeAndSize;
12227
+ const attributeType = shaderType;
12046
12228
  return {
12047
- format,
12048
- components,
12049
- glType
12229
+ attributeType,
12230
+ vertexFormat,
12231
+ components
12050
12232
  };
12051
12233
  }
12052
12234
 
12053
- // ../webgl/src/adapter/converters/vertex-formats.ts
12054
- function getVertexFormat(type, components) {
12055
- const base = getDataFormat(type);
12056
- switch (components) {
12057
- case 1:
12058
- return base;
12059
- case 2:
12060
- return `${base}x2`;
12061
- case 3:
12062
- return `${base}x3`;
12063
- case 4:
12064
- return `${base}x4`;
12065
- default:
12066
- throw new Error(String(components));
12067
- }
12068
- }
12069
- function getDataFormat(type) {
12070
- switch (type) {
12071
- case GL.INT:
12072
- return "sint32";
12073
- case GL.UNSIGNED_INT:
12074
- return "uint32";
12075
- case GL.FLOAT:
12076
- return "float32";
12077
- default:
12078
- throw new Error(String(type));
12079
- }
12080
- }
12081
-
12082
12235
  // ../webgl/src/adapter/helpers/get-shader-layout.ts
12083
12236
  function getShaderLayout(gl, program) {
12084
12237
  const shaderLayout = {
12085
12238
  attributes: [],
12086
12239
  bindings: []
12087
12240
  };
12088
- const attributes = readAttributeBindings(gl, program);
12089
- for (const attribute of attributes) {
12090
- const size = Math.min(attribute.accessor.size, 4);
12091
- const format = (
12092
- // attribute.accessor.format ||
12093
- getVertexFormat(attribute.accessor.type || GL.FLOAT, size)
12094
- );
12095
- shaderLayout.attributes.push({
12096
- name: attribute.name,
12097
- location: attribute.location,
12098
- format,
12099
- stepMode: attribute.accessor.divisor === 1 ? "instance" : "vertex"
12100
- });
12101
- }
12241
+ shaderLayout.attributes = readAttributeDeclarations(gl, program);
12102
12242
  const uniformBlocks = readUniformBlocks(gl, program);
12103
12243
  for (const uniformBlock of uniformBlocks) {
12104
12244
  const uniforms2 = uniformBlock.uniforms.map((uniform) => ({
@@ -12145,58 +12285,7 @@ ${formattedLog}`)();
12145
12285
  }
12146
12286
  return shaderLayout;
12147
12287
  }
12148
- function mergeShaderLayout(baseLayout, overrideLayout) {
12149
- const mergedLayout = {
12150
- ...baseLayout,
12151
- attributes: baseLayout.attributes.map((attribute) => ({
12152
- ...attribute
12153
- }))
12154
- };
12155
- for (const attribute of overrideLayout?.attributes || []) {
12156
- const baseAttribute = mergedLayout.attributes.find((attr) => attr.name === attribute.name);
12157
- if (!baseAttribute) {
12158
- log.warn(`shader layout attribute ${attribute.name} not present in shader`);
12159
- } else {
12160
- baseAttribute.format = attribute.format || baseAttribute.format;
12161
- baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
12162
- }
12163
- }
12164
- return mergedLayout;
12165
- }
12166
- function mergeBufferMap(baseLayout, bufferMap) {
12167
- const mergedLayout = {
12168
- ...baseLayout,
12169
- attributes: baseLayout.attributes.map((attribute) => ({
12170
- ...attribute
12171
- }))
12172
- };
12173
- for (const bufferMapping of bufferMap) {
12174
- switch (bufferMapping.type) {
12175
- case "interleave":
12176
- for (const attributeOverride of bufferMapping.attributes) {
12177
- overrideShaderLayoutAttribute(mergedLayout, attributeOverride);
12178
- }
12179
- break;
12180
- default:
12181
- overrideShaderLayoutAttribute(mergedLayout, bufferMapping);
12182
- }
12183
- }
12184
- return mergedLayout;
12185
- }
12186
- function overrideShaderLayoutAttribute(layout, attributeOverride) {
12187
- const attribute = getAttributeFromLayout(layout, attributeOverride.name);
12188
- if (attribute && attributeOverride.format) {
12189
- attribute.format = attributeOverride.format;
12190
- }
12191
- }
12192
- function getAttributeFromLayout(shaderLayout, name) {
12193
- const attribute = shaderLayout.attributes.find((attr) => attr.name === name);
12194
- if (!attribute) {
12195
- log.warn(`shader layout attribute "${name}" not present in shader`);
12196
- }
12197
- return attribute || null;
12198
- }
12199
- function readAttributeBindings(gl, program) {
12288
+ function readAttributeDeclarations(gl, program) {
12200
12289
  const attributes = [];
12201
12290
  const count = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
12202
12291
  for (let index = 0; index < count; index++) {
@@ -12205,29 +12294,23 @@ ${formattedLog}`)();
12205
12294
  throw new Error("activeInfo");
12206
12295
  }
12207
12296
  const {
12208
- name,
12209
- type: compositeType,
12210
- size
12297
+ name: name2,
12298
+ type: compositeType
12299
+ /* , size*/
12211
12300
  } = activeInfo;
12212
- const location = gl.getAttribLocation(program, name);
12301
+ const location = gl.getAttribLocation(program, name2);
12213
12302
  if (location >= 0) {
12214
12303
  const {
12215
- glType,
12216
- components
12217
- } = decodeAttributeType(compositeType);
12218
- const accessor = {
12219
- type: glType,
12220
- size: size * components
12221
- };
12222
- if (/instance/i.test(name)) {
12223
- accessor.divisor = 1;
12224
- }
12225
- const attributeInfo = {
12304
+ attributeType
12305
+ } = decodeGLAttributeType(compositeType);
12306
+ const stepMode = /instance/i.test(name2) ? "instance" : "vertex";
12307
+ attributes.push({
12308
+ name: name2,
12226
12309
  location,
12227
- name,
12228
- accessor: new Accessor(accessor)
12229
- };
12230
- attributes.push(attributeInfo);
12310
+ stepMode,
12311
+ type: attributeType
12312
+ // size - for arrays, size is the number of elements in the array
12313
+ });
12231
12314
  }
12232
12315
  }
12233
12316
  attributes.sort((a, b) => a.location - b.location);
@@ -12246,21 +12329,21 @@ ${formattedLog}`)();
12246
12329
  throw new Error("activeInfo");
12247
12330
  }
12248
12331
  const {
12249
- name,
12332
+ name: name2,
12250
12333
  type: compositeType,
12251
12334
  size
12252
12335
  } = activeInfo;
12253
12336
  const {
12254
12337
  glType,
12255
12338
  components
12256
- } = decodeUniformType(compositeType);
12339
+ } = decodeGLUniformType(compositeType);
12257
12340
  const accessor = new Accessor({
12258
12341
  type: glType,
12259
12342
  size: size * components
12260
12343
  });
12261
12344
  const varying = {
12262
12345
  location,
12263
- name,
12346
+ name: name2,
12264
12347
  accessor
12265
12348
  };
12266
12349
  varyings.push(varying);
@@ -12282,14 +12365,14 @@ ${formattedLog}`)();
12282
12365
  type
12283
12366
  } = activeInfo;
12284
12367
  const {
12285
- name,
12368
+ name: name2,
12286
12369
  isArray: isArray3
12287
12370
  } = parseUniformName(rawName);
12288
- let webglLocation = gl.getUniformLocation(program, name);
12371
+ let webglLocation = gl.getUniformLocation(program, name2);
12289
12372
  const uniformInfo = {
12290
12373
  // WebGL locations are uniquely typed but just numbers
12291
12374
  location: webglLocation,
12292
- name,
12375
+ name: name2,
12293
12376
  size,
12294
12377
  type,
12295
12378
  isArray: isArray3
@@ -12297,7 +12380,7 @@ ${formattedLog}`)();
12297
12380
  uniforms.push(uniformInfo);
12298
12381
  if (uniformInfo.size > 1) {
12299
12382
  for (let j = 0; j < uniformInfo.size; j++) {
12300
- const elementName = `${name}[${j}]`;
12383
+ const elementName = `${name2}[${j}]`;
12301
12384
  webglLocation = gl.getUniformLocation(program, elementName);
12302
12385
  const arrayElementUniformInfo = {
12303
12386
  ...uniformInfo,
@@ -12340,7 +12423,7 @@ ${formattedLog}`)();
12340
12423
  }
12341
12424
  blockInfo.uniforms.push({
12342
12425
  name: activeInfo.name,
12343
- format: decodeUniformType(uniformType[i]).format,
12426
+ format: decodeGLUniformType(uniformType[i]).format,
12344
12427
  type: uniformType[i],
12345
12428
  arrayLength: uniformArrayLength[i],
12346
12429
  byteOffset: uniformOffset[i],
@@ -12382,18 +12465,18 @@ ${formattedLog}`)();
12382
12465
  sampleType
12383
12466
  };
12384
12467
  }
12385
- function parseUniformName(name) {
12386
- if (name[name.length - 1] !== "]") {
12468
+ function parseUniformName(name2) {
12469
+ if (name2[name2.length - 1] !== "]") {
12387
12470
  return {
12388
- name,
12471
+ name: name2,
12389
12472
  length: 1,
12390
12473
  isArray: false
12391
12474
  };
12392
12475
  }
12393
12476
  const UNIFORM_NAME_REGEXP = /([^[]*)(\[[0-9]+\])?/;
12394
- const matches = UNIFORM_NAME_REGEXP.exec(name);
12477
+ const matches = UNIFORM_NAME_REGEXP.exec(name2);
12395
12478
  if (!matches || matches.length < 2) {
12396
- throw new Error(`Failed to parse GLSL uniform name ${name}`);
12479
+ throw new Error(`Failed to parse GLSL uniform name ${name2}`);
12397
12480
  }
12398
12481
  return {
12399
12482
  name: matches[1],
@@ -12684,8 +12767,8 @@ ${formattedLog}`)();
12684
12767
  /** Handle to underlying WebGL program */
12685
12768
  /** vertex shader */
12686
12769
  /** fragment shader */
12687
- /** The merged layout */
12688
12770
  /** The layout extracted from shader by WebGL introspection APIs */
12771
+ /** The merged layout */
12689
12772
  /** Buffer map describing buffer interleaving etc */
12690
12773
  /** Uniforms set on this model */
12691
12774
  uniforms = {};
@@ -12722,9 +12805,8 @@ ${formattedLog}`)();
12722
12805
  }
12723
12806
  this._compileAndLink();
12724
12807
  this.introspectedLayout = getShaderLayout(this.device.gl, this.handle);
12725
- this.layout = mergeShaderLayout(this.introspectedLayout, props.layout);
12726
- this.bufferMap = props.bufferMap || [];
12727
- this.layout = mergeBufferMap(this.layout, this.bufferMap);
12808
+ this.shaderLayout = mergeShaderLayout(this.introspectedLayout, props.shaderLayout);
12809
+ this.bufferLayout = props.bufferLayout || [];
12728
12810
  this.vertexArrayObject = new WEBGLVertexArrayObject(this.device);
12729
12811
  }
12730
12812
  destroy() {
@@ -12739,70 +12821,75 @@ ${formattedLog}`)();
12739
12821
  this._indexBuffer = webglBuffer;
12740
12822
  }
12741
12823
  /** @todo needed for portable model */
12742
- setAttributes(attributes) {
12743
- for (const [name, buffer] of Object.entries(attributes)) {
12744
- const webglBuffer = cast(buffer);
12745
- const attribute = getAttributeLayout(this.layout, name);
12746
- if (!attribute) {
12747
- log.warn(`Ignoring buffer supplied for unknown attribute "${name}" in pipeline "${this.id}" (buffer "${buffer.id}")`)();
12748
- continue;
12824
+ setAttributes(buffers) {
12825
+ const attributeInfos = getAttributeInfosFromLayouts(this.shaderLayout, this.bufferLayout);
12826
+ for (const [bufferName, buffer] of Object.entries(buffers)) {
12827
+ let set = false;
12828
+ for (const attributeInfo of Object.values(attributeInfos)) {
12829
+ if (attributeInfo.bufferName !== bufferName) {
12830
+ continue;
12831
+ }
12832
+ const webglBuffer = cast(buffer);
12833
+ const glType = getGLFromVertexType(attributeInfo.bufferDataType);
12834
+ log.log(1, {
12835
+ setAttribute: attributeInfo.name,
12836
+ toBuffer: bufferName,
12837
+ size: attributeInfo.bufferComponents,
12838
+ type: glType,
12839
+ stride: attributeInfo.byteStride,
12840
+ offset: attributeInfo.byteOffset,
12841
+ normalized: attributeInfo.normalized,
12842
+ // it is the shader attribute declaration, not the vertex memory format,
12843
+ // that determines if the data in the buffer will be treated as integers.
12844
+ // /
12845
+ // Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
12846
+ // but as far as we can tell, WebGPU does not.
12847
+ integer: attributeInfo.integer,
12848
+ divisor: attributeInfo.stepMode === "instance" ? 1 : 0
12849
+ })();
12850
+ this.vertexArrayObject.setBuffer(attributeInfo.location, webglBuffer, {
12851
+ size: attributeInfo.bufferComponents,
12852
+ type: glType,
12853
+ stride: attributeInfo.byteStride,
12854
+ offset: attributeInfo.byteOffset,
12855
+ normalized: attributeInfo.normalized,
12856
+ // it is the shader attribute declaration, not the vertex memory format,
12857
+ // that determines if the data in the buffer will be treated as integers.
12858
+ // /
12859
+ // Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
12860
+ // but as far as we can tell, WebGPU does not.
12861
+ integer: attributeInfo.integer,
12862
+ divisor: attributeInfo.stepMode === "instance" ? 1 : 0
12863
+ });
12864
+ set = true;
12865
+ }
12866
+ if (!set) {
12867
+ log.warn(`setAttributes(): Ignoring (buffer "${buffer.id}" for unknown attribute "${name}" in pipeline "${this.id}"`)();
12749
12868
  }
12750
- const decoded = decodeVertexFormat(attribute.format);
12751
- const {
12752
- type: typeString,
12753
- components: size,
12754
- byteLength: stride,
12755
- normalized
12756
- /* , integer*/
12757
- } = decoded;
12758
- const divisor = attribute.stepMode === "instance" ? 1 : 0;
12759
- const type = getWebGLDataType(typeString);
12760
- this.vertexArrayObject.setBuffer(attribute.location, webglBuffer, {
12761
- size,
12762
- type,
12763
- stride,
12764
- offset: 0,
12765
- normalized,
12766
- // it is the shader attribute declaration, not the vertex memory format,
12767
- // that determines if the data in the buffer will be treated as integers.
12768
- // /
12769
- // Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
12770
- // but as far as we can tell, WebGPU does not.
12771
- integer: false,
12772
- divisor
12773
- });
12774
12869
  }
12775
12870
  }
12776
12871
  /**
12777
12872
  * Constant attributes are only supported in WebGL, not in WebGPU
12778
12873
  * Any attribute that is disabled in the current vertex array object
12779
12874
  * is read from the context's global constant value for that attribute location.
12780
- * @param attributes
12875
+ * @param attributes
12781
12876
  */
12782
12877
  setConstantAttributes(attributes) {
12783
- for (const [name, value] of Object.entries(attributes)) {
12784
- const attribute = getAttributeLayout(this.layout, name);
12785
- if (!attribute) {
12786
- log.warn(`Ignoring constant value supplied for unknown attribute "${name}" in pipeline "${this.id}"`)();
12787
- continue;
12788
- }
12789
- this.vertexArrayObject.setConstant(attribute.location, value);
12790
- }
12791
12878
  Object.assign(this.constantAttributes, attributes);
12792
12879
  }
12793
- /**
12880
+ /**
12794
12881
  * Bindings include: textures, samplers and uniform buffers
12795
- * @todo needed for portable model
12882
+ * @todo needed for portable model
12796
12883
  */
12797
12884
  setBindings(bindings) {
12798
- for (const [name, value] of Object.entries(bindings)) {
12799
- const binding = this.layout.bindings.find((binding2) => binding2.name === name);
12885
+ for (const [name2, value] of Object.entries(bindings)) {
12886
+ const binding = this.shaderLayout.bindings.find((binding2) => binding2.name === name2);
12800
12887
  if (!binding) {
12801
- log.warn(`Unknown binding ${name} in render pipeline ${this.id}`)();
12888
+ log.warn(`Unknown binding ${name2} in render pipeline ${this.id}`)();
12802
12889
  continue;
12803
12890
  }
12804
12891
  if (!value) {
12805
- log.warn(`Unsetting binding ${name} in render pipeline ${this.id}`)();
12892
+ log.warn(`Unsetting binding ${name2} in render pipeline ${this.id}`)();
12806
12893
  }
12807
12894
  switch (binding.type) {
12808
12895
  case "uniform":
@@ -12816,12 +12903,12 @@ ${formattedLog}`)();
12816
12903
  }
12817
12904
  break;
12818
12905
  case "sampler":
12819
- log.warn(`Ignoring sampler ${name}`)();
12906
+ log.warn(`Ignoring sampler ${name2}`)();
12820
12907
  break;
12821
12908
  default:
12822
12909
  throw new Error(binding.type);
12823
12910
  }
12824
- this.bindings[name] = value;
12911
+ this.bindings[name2] = value;
12825
12912
  }
12826
12913
  }
12827
12914
  setUniforms(uniforms) {
@@ -12842,7 +12929,7 @@ ${formattedLog}`)();
12842
12929
  // firstInstance,
12843
12930
  // baseVertex
12844
12931
  } = options;
12845
- const drawMode = getDrawMode(this.props.topology);
12932
+ const drawMode = getGLDrawMode(this.props.topology);
12846
12933
  const isIndexed = Boolean(this._indexBuffer);
12847
12934
  const indexType = this._indexBuffer?.glIndexType;
12848
12935
  const isInstanced = Number(options.instanceCount) > 0;
@@ -12928,7 +13015,24 @@ ${formattedLog}`)();
12928
13015
  }
12929
13016
  return texturesRenderable;
12930
13017
  }
12931
- /** Apply any bindings */
13018
+ /**
13019
+ * Constant attributes need to be reset before every draw call
13020
+ * Any attribute that is disabled in the current vertex array object
13021
+ * is read from the context's global constant value for that attribute location.
13022
+ * @note Constant attributes are only supported in WebGL, not in WebGPU
13023
+ */
13024
+ _applyConstantAttributes() {
13025
+ const attributeInfos = getAttributeInfosFromLayouts(this.shaderLayout, this.bufferLayout);
13026
+ for (const [name2, value] of Object.entries(this.constantAttributes)) {
13027
+ const attributeInfo = attributeInfos[name2];
13028
+ if (!attributeInfo) {
13029
+ log.warn(`Ignoring constant value supplied for unknown attribute "${name2}" in pipeline "${this.id}"`)();
13030
+ continue;
13031
+ }
13032
+ this.vertexArrayObject.setConstant(attributeInfo.location, value);
13033
+ }
13034
+ }
13035
+ /** Apply any bindings (before each draw call) */
12932
13036
  _applyBindings() {
12933
13037
  this.device.gl.useProgram(this.handle);
12934
13038
  const {
@@ -12939,7 +13043,7 @@ ${formattedLog}`)();
12939
13043
  }
12940
13044
  let textureUnit = 0;
12941
13045
  let uniformBufferIndex = 0;
12942
- for (const binding of this.layout.bindings) {
13046
+ for (const binding of this.shaderLayout.bindings) {
12943
13047
  const value = this.bindings[binding.name];
12944
13048
  if (!value) {
12945
13049
  throw new Error(`No value for binding ${binding.name} in ${this.id}`);
@@ -12947,11 +13051,11 @@ ${formattedLog}`)();
12947
13051
  switch (binding.type) {
12948
13052
  case "uniform":
12949
13053
  const {
12950
- name
13054
+ name: name2
12951
13055
  } = binding;
12952
- const location = gl2.getUniformBlockIndex(this.handle, name);
13056
+ const location = gl2.getUniformBlockIndex(this.handle, name2);
12953
13057
  if (location === GL.INVALID_INDEX) {
12954
- throw new Error(`Invalid uniform block name ${name}`);
13058
+ throw new Error(`Invalid uniform block name ${name2}`);
12955
13059
  }
12956
13060
  gl2.uniformBlockBinding(this.handle, uniformBufferIndex, location);
12957
13061
  if (value instanceof WEBGLBuffer) {
@@ -12978,37 +13082,26 @@ ${formattedLog}`)();
12978
13082
  }
12979
13083
  }
12980
13084
  }
13085
+ /**
13086
+ * Due to program sharing, uniforms need to be reset before every draw call
13087
+ * (though caching will avoid redundant WebGL calls)
13088
+ */
12981
13089
  _applyUniforms() {
12982
- for (const uniformLayout of this.layout.uniforms || []) {
13090
+ for (const uniformLayout of this.shaderLayout.uniforms || []) {
12983
13091
  const {
12984
- name,
13092
+ name: name2,
12985
13093
  location,
12986
13094
  type,
12987
13095
  textureUnit
12988
13096
  } = uniformLayout;
12989
- const value = this.uniforms[name] ?? textureUnit;
13097
+ const value = this.uniforms[name2] ?? textureUnit;
12990
13098
  if (value !== void 0) {
12991
13099
  setUniform(this.device.gl, location, type, value);
12992
13100
  }
12993
13101
  }
12994
13102
  }
12995
- /**
12996
- * Constant attributes are only supported in WebGL, not in WebGPU
12997
- * Any attribute that is disabled in the current vertex array object
12998
- * is read from the context's global constant value for that attribute location.
12999
- */
13000
- _applyConstantAttributes() {
13001
- for (const [name, value] of Object.entries(this.constantAttributes)) {
13002
- const attribute = getAttributeLayout(this.layout, name);
13003
- if (!attribute) {
13004
- log.warn(`Ignoring constant value supplied for unknown attribute "${name}" in pipeline "${this.id}"`)();
13005
- continue;
13006
- }
13007
- this.vertexArrayObject.setConstant(attribute.location, value);
13008
- }
13009
- }
13010
13103
  };
13011
- function getDrawMode(topology) {
13104
+ function getGLDrawMode(topology) {
13012
13105
  switch (topology) {
13013
13106
  case "point-list":
13014
13107
  return GL.POINTS;
@@ -13048,9 +13141,6 @@ ${formattedLog}`)();
13048
13141
  throw new Error(topology);
13049
13142
  }
13050
13143
  }
13051
- function getAttributeLayout(layout, name) {
13052
- return layout.attributes.find((binding) => binding.name === name) || null;
13053
- }
13054
13144
 
13055
13145
  // ../webgl/src/adapter/resources/webgl-command-buffer.ts
13056
13146
  function cast2(value) {
@@ -13251,7 +13341,7 @@ ${formattedLog}`)();
13251
13341
  // ../webgl/src/adapter/resources/webgl-command-encoder.ts
13252
13342
  var WEBGLCommandEncoder = class extends CommandEncoder {
13253
13343
  constructor(device, props) {
13254
- super(props);
13344
+ super(device, props);
13255
13345
  this.device = device;
13256
13346
  this.commandBuffer = new WEBGLCommandBuffer(device);
13257
13347
  }