@luma.gl/webgpu 9.0.0-alpha.35 → 9.0.0-alpha.37

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.
Files changed (42) hide show
  1. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
  2. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -1
  3. package/dist/adapter/helpers/webgpu-parameters.js +2 -2
  4. package/dist/adapter/helpers/webgpu-parameters.js.map +1 -1
  5. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  6. package/dist/adapter/resources/webgpu-render-pass.js +23 -4
  7. package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
  8. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +3 -2
  9. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  10. package/dist/adapter/resources/webgpu-render-pipeline.js +11 -12
  11. package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
  12. package/dist/adapter/resources/webgpu-shader.js +1 -1
  13. package/dist/adapter/resources/webgpu-shader.js.map +1 -1
  14. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  15. package/dist/adapter/resources/webgpu-texture.js.map +1 -1
  16. package/dist/adapter/resources/webgpu-vertex-array.d.ts +26 -0
  17. package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -0
  18. package/dist/adapter/resources/webgpu-vertex-array.js +39 -0
  19. package/dist/adapter/resources/webgpu-vertex-array.js.map +1 -0
  20. package/dist/adapter/webgpu-canvas-context.d.ts +8 -2
  21. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  22. package/dist/adapter/webgpu-canvas-context.js +11 -10
  23. package/dist/adapter/webgpu-canvas-context.js.map +1 -1
  24. package/dist/adapter/webgpu-device.d.ts +4 -1
  25. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  26. package/dist/adapter/webgpu-device.js +10 -14
  27. package/dist/adapter/webgpu-device.js.map +1 -1
  28. package/dist/dist.dev.js +250 -110
  29. package/dist/index.cjs +130 -59
  30. package/dist.min.js +5 -5
  31. package/package.json +3 -3
  32. package/src/.DS_Store +0 -0
  33. package/src/adapter/.DS_Store +0 -0
  34. package/src/adapter/helpers/get-vertex-buffer-layout.ts +1 -0
  35. package/src/adapter/helpers/webgpu-parameters.ts +2 -2
  36. package/src/adapter/resources/webgpu-render-pass.ts +27 -4
  37. package/src/adapter/resources/webgpu-render-pipeline.ts +18 -15
  38. package/src/adapter/resources/webgpu-shader.ts +1 -1
  39. package/src/adapter/resources/webgpu-texture.ts +7 -0
  40. package/src/adapter/resources/webgpu-vertex-array.ts +73 -0
  41. package/src/adapter/webgpu-canvas-context.ts +36 -16
  42. package/src/adapter/webgpu-device.ts +21 -13
package/dist/dist.dev.js CHANGED
@@ -72,6 +72,36 @@ var __exports__ = (() => {
72
72
  var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "untranspiled source";
73
73
  var isBrowser2 = isBrowser();
74
74
 
75
+ // ../../node_modules/@probe.gl/env/dist/lib/get-browser.js
76
+ var window2 = globalThis;
77
+ function getBrowser(mockUserAgent) {
78
+ if (!mockUserAgent && !isBrowser()) {
79
+ return "Node";
80
+ }
81
+ if (isElectron(mockUserAgent)) {
82
+ return "Electron";
83
+ }
84
+ const userAgent = mockUserAgent || navigator_.userAgent || "";
85
+ if (userAgent.indexOf("Edge") > -1) {
86
+ return "Edge";
87
+ }
88
+ const isMSIE = userAgent.indexOf("MSIE ") !== -1;
89
+ const isTrident = userAgent.indexOf("Trident/") !== -1;
90
+ if (isMSIE || isTrident) {
91
+ return "IE";
92
+ }
93
+ if (window2.chrome) {
94
+ return "Chrome";
95
+ }
96
+ if (window2.safari) {
97
+ return "Safari";
98
+ }
99
+ if (window2.mozInnerScreenX) {
100
+ return "Firefox";
101
+ }
102
+ return "Unknown";
103
+ }
104
+
75
105
  // ../../node_modules/@probe.gl/log/dist/utils/local-storage.js
76
106
  function getStorage(type) {
77
107
  try {
@@ -1042,9 +1072,13 @@ var __exports__ = (() => {
1042
1072
  __publicField(Buffer2, "MAP_WRITE", 2);
1043
1073
  __publicField(Buffer2, "COPY_SRC", 4);
1044
1074
  __publicField(Buffer2, "COPY_DST", 8);
1075
+ /** Index buffer */
1045
1076
  __publicField(Buffer2, "INDEX", 16);
1077
+ /** Vertex buffer */
1046
1078
  __publicField(Buffer2, "VERTEX", 32);
1079
+ /** Uniform buffer */
1047
1080
  __publicField(Buffer2, "UNIFORM", 64);
1081
+ /** Storage buffer */
1048
1082
  __publicField(Buffer2, "STORAGE", 128);
1049
1083
  __publicField(Buffer2, "INDIRECT", 256);
1050
1084
  __publicField(Buffer2, "QUERY_RESOLVE", 512);
@@ -1135,6 +1169,7 @@ var __exports__ = (() => {
1135
1169
  createCommandEncoder(props = {}) {
1136
1170
  throw new Error("not implemented");
1137
1171
  }
1172
+ /** Create a vertex array */
1138
1173
  /** Create a RenderPass */
1139
1174
  /** Create a ComputePass */
1140
1175
  /** Get a renderpass that is set up to render to the primary CanvasContext */
@@ -1520,7 +1555,7 @@ var __exports__ = (() => {
1520
1555
  stage: "vertex",
1521
1556
  source: "",
1522
1557
  sourceMap: null,
1523
- language: "glsl",
1558
+ language: "auto",
1524
1559
  shaderType: 0
1525
1560
  });
1526
1561
 
@@ -1745,12 +1780,13 @@ var __exports__ = (() => {
1745
1780
  return "RenderPipeline";
1746
1781
  }
1747
1782
  hash = "";
1783
+ /** The merged layout */
1784
+ /** Buffer map describing buffer interleaving etc */
1748
1785
  constructor(device, props) {
1749
1786
  super(device, props, _RenderPipeline.defaultProps);
1787
+ this.shaderLayout = this.props.shaderLayout;
1788
+ this.bufferLayout = this.props.bufferLayout || [];
1750
1789
  }
1751
- /** Set attributes (stored on pipeline and set before each call) */
1752
- /** Set attributes (stored on pipeline and set before each call) */
1753
- /** Set constant attributes (WebGL only) */
1754
1790
  /** Set bindings (stored on pipeline and set before each call) */
1755
1791
  /** Uniforms
1756
1792
  * @deprecated Only supported on WebGL devices.
@@ -1776,8 +1812,6 @@ var __exports__ = (() => {
1776
1812
  parameters: {},
1777
1813
  vertexCount: 0,
1778
1814
  instanceCount: 0,
1779
- indices: null,
1780
- attributes: {},
1781
1815
  bindings: {},
1782
1816
  uniforms: {}
1783
1817
  });
@@ -1887,6 +1921,68 @@ var __exports__ = (() => {
1887
1921
  ...Resource.defaultProps
1888
1922
  });
1889
1923
 
1924
+ // ../core/src/adapter/type-utils/decode-attribute-type.ts
1925
+ function decodeShaderAttributeType(attributeType) {
1926
+ const [dataType, components] = TYPE_INFO[attributeType];
1927
+ const integer = dataType === "i32" || dataType === "u32";
1928
+ const signed = dataType !== "u32";
1929
+ const byteLength = TYPE_SIZES[dataType] * components;
1930
+ const defaultVertexFormat = getCompatibleVertexFormat(dataType, components);
1931
+ return {
1932
+ dataType,
1933
+ components,
1934
+ defaultVertexFormat,
1935
+ byteLength,
1936
+ integer,
1937
+ signed
1938
+ };
1939
+ }
1940
+ function getCompatibleVertexFormat(dataType, components) {
1941
+ let vertexType;
1942
+ switch (dataType) {
1943
+ case "f32":
1944
+ vertexType = "float32";
1945
+ break;
1946
+ case "i32":
1947
+ vertexType = "sint32";
1948
+ break;
1949
+ case "u32":
1950
+ vertexType = "uint32";
1951
+ break;
1952
+ case "f16":
1953
+ return components <= 2 ? "float16x2" : "float16x4";
1954
+ }
1955
+ if (components === 1) {
1956
+ return vertexType;
1957
+ }
1958
+ return `${vertexType}x${components}`;
1959
+ }
1960
+ var TYPE_INFO = {
1961
+ f32: ["f32", 1],
1962
+ "vec2<f32>": ["f32", 2],
1963
+ "vec3<f32>": ["f32", 3],
1964
+ "vec4<f32>": ["f32", 4],
1965
+ f16: ["f16", 1],
1966
+ "vec2<f16>": ["f16", 2],
1967
+ "vec3<f16>": ["f16", 3],
1968
+ "vec4<f16>": ["f16", 4],
1969
+ i32: ["i32", 1],
1970
+ "vec2<i32>": ["i32", 2],
1971
+ "vec3<i32>": ["i32", 3],
1972
+ "vec4<i32>": ["i32", 4],
1973
+ u32: ["u32", 1],
1974
+ "vec2<u32>": ["u32", 2],
1975
+ "vec3<u32>": ["u32", 3],
1976
+ "vec4<u32>": ["u32", 4]
1977
+ };
1978
+ var TYPE_SIZES = {
1979
+ f32: 4,
1980
+ f16: 2,
1981
+ i32: 4,
1982
+ u32: 4
1983
+ // 'bool-webgl': 4,
1984
+ };
1985
+
1890
1986
  // ../core/src/adapter/type-utils/decode-data-type.ts
1891
1987
  function decodeVertexType(type) {
1892
1988
  const dataType = TYPE_MAP[type];
@@ -1903,7 +1999,7 @@ var __exports__ = (() => {
1903
1999
  };
1904
2000
  }
1905
2001
  function getDataTypeBytes(type) {
1906
- const bytes = TYPE_SIZES[type];
2002
+ const bytes = TYPE_SIZES2[type];
1907
2003
  return bytes;
1908
2004
  }
1909
2005
  var TYPE_MAP = {
@@ -1920,7 +2016,7 @@ var __exports__ = (() => {
1920
2016
  uint32: "uint32",
1921
2017
  sint32: "sint32"
1922
2018
  };
1923
- var TYPE_SIZES = {
2019
+ var TYPE_SIZES2 = {
1924
2020
  uint8: 1,
1925
2021
  sint8: 1,
1926
2022
  uint16: 2,
@@ -1956,68 +2052,6 @@ var __exports__ = (() => {
1956
2052
  return result;
1957
2053
  }
1958
2054
 
1959
- // ../core/src/adapter/type-utils/decode-attribute-type.ts
1960
- function decodeShaderAttributeType(attributeType) {
1961
- const [dataType, components] = TYPE_INFO[attributeType];
1962
- const integer = dataType === "i32" || dataType === "u32";
1963
- const signed = dataType !== "u32";
1964
- const byteLength = TYPE_SIZES2[dataType] * components;
1965
- const defaultVertexFormat = getCompatibleVertexFormat(dataType, components);
1966
- return {
1967
- dataType,
1968
- components,
1969
- defaultVertexFormat,
1970
- byteLength,
1971
- integer,
1972
- signed
1973
- };
1974
- }
1975
- function getCompatibleVertexFormat(dataType, components) {
1976
- let vertexType;
1977
- switch (dataType) {
1978
- case "f32":
1979
- vertexType = "float32";
1980
- break;
1981
- case "i32":
1982
- vertexType = "sint32";
1983
- break;
1984
- case "u32":
1985
- vertexType = "uint32";
1986
- break;
1987
- case "f16":
1988
- return components <= 2 ? "float16x2" : "float16x4";
1989
- }
1990
- if (components === 1) {
1991
- return vertexType;
1992
- }
1993
- return `${vertexType}x${components}`;
1994
- }
1995
- var TYPE_INFO = {
1996
- f32: ["f32", 1],
1997
- "vec2<f32>": ["f32", 2],
1998
- "vec3<f32>": ["f32", 3],
1999
- "vec4<f32>": ["f32", 4],
2000
- f16: ["f16", 1],
2001
- "vec2<f16>": ["f16", 2],
2002
- "vec3<f16>": ["f16", 3],
2003
- "vec4<f16>": ["f16", 4],
2004
- i32: ["i32", 1],
2005
- "vec2<i32>": ["i32", 2],
2006
- "vec3<i32>": ["i32", 3],
2007
- "vec4<i32>": ["i32", 4],
2008
- u32: ["u32", 1],
2009
- "vec2<u32>": ["u32", 2],
2010
- "vec3<u32>": ["u32", 3],
2011
- "vec4<u32>": ["u32", 4]
2012
- };
2013
- var TYPE_SIZES2 = {
2014
- f32: 4,
2015
- f16: 2,
2016
- i32: 4,
2017
- u32: 4
2018
- // 'bool-webgl': 4,
2019
- };
2020
-
2021
2055
  // ../core/src/adapter/attribute-utils/get-attribute-from-layouts.ts
2022
2056
  function getAttributeInfosFromLayouts(shaderLayout, bufferLayout) {
2023
2057
  const attributeInfos = {};
@@ -2026,6 +2060,14 @@ var __exports__ = (() => {
2026
2060
  }
2027
2061
  return attributeInfos;
2028
2062
  }
2063
+ function getAttributeInfosByLocation(shaderLayout, bufferLayout, maxVertexAttributes = 16) {
2064
+ const attributeInfos = getAttributeInfosFromLayouts(shaderLayout, bufferLayout);
2065
+ const locationInfos = new Array(maxVertexAttributes).fill(null);
2066
+ for (const attributeInfo of Object.values(attributeInfos)) {
2067
+ locationInfos[attributeInfo.location] = attributeInfo;
2068
+ }
2069
+ return locationInfos;
2070
+ }
2029
2071
  function getAttributeInfoFromLayouts(shaderLayout, bufferLayout, name2) {
2030
2072
  const shaderDeclaration = getAttributeFromShaderLayout(shaderLayout, name2);
2031
2073
  const bufferMapping = getAttributeFromBufferLayout(bufferLayout, name2);
@@ -2121,6 +2163,30 @@ var __exports__ = (() => {
2121
2163
  return null;
2122
2164
  }
2123
2165
 
2166
+ // ../core/src/adapter/resources/vertex-array.ts
2167
+ var _VertexArray = class extends Resource {
2168
+ get [Symbol.toStringTag]() {
2169
+ return "VertexArray";
2170
+ }
2171
+ /** Max number of vertex attributes */
2172
+ /** Attribute infos indexed by location - TODO only needed by webgl module? */
2173
+ indexBuffer = null;
2174
+ constructor(device, props) {
2175
+ super(device, props, _VertexArray.defaultProps);
2176
+ this.maxVertexAttributes = device.limits.maxVertexAttributes;
2177
+ this.attributes = new Array(this.maxVertexAttributes).fill(null);
2178
+ this.attributeInfos = getAttributeInfosByLocation(props.renderPipeline.shaderLayout, props.renderPipeline.bufferLayout, this.maxVertexAttributes);
2179
+ }
2180
+ /** Set attributes (stored on pipeline and set before each call) */
2181
+ /** Set attributes (stored on pipeline and set before each call) */
2182
+ /** Set constant attributes (WebGL only) */
2183
+ };
2184
+ var VertexArray = _VertexArray;
2185
+ __publicField(VertexArray, "defaultProps", {
2186
+ ...Resource.defaultProps,
2187
+ renderPipeline: null
2188
+ });
2189
+
2124
2190
  // ../core/src/lib/utils/cast.ts
2125
2191
  function cast(value) {
2126
2192
  return value;
@@ -2449,7 +2515,7 @@ var __exports__ = (() => {
2449
2515
  stage
2450
2516
  } = this.props;
2451
2517
  let language = this.props.language;
2452
- if (!language) {
2518
+ if (language === "auto") {
2453
2519
  language = source.includes("->") ? "wgsl" : "glsl";
2454
2520
  }
2455
2521
  switch (language) {
@@ -2482,8 +2548,8 @@ var __exports__ = (() => {
2482
2548
  stencilFront: {},
2483
2549
  stencilBack: {},
2484
2550
  // TODO can this cause trouble? Should we set to WebGPU defaults? Are there defaults?
2485
- depthWriteEnabled: void 0,
2486
- depthCompare: void 0
2551
+ depthWriteEnabled: false,
2552
+ depthCompare: "less-equal"
2487
2553
  };
2488
2554
  return descriptor.depthStencil;
2489
2555
  }
@@ -2804,25 +2870,24 @@ var __exports__ = (() => {
2804
2870
  // private _firstIndex: number;
2805
2871
  // private _lastIndex: number;
2806
2872
  /** For internal use to create BindGroups */
2873
+ _bindGroupLayout = null;
2807
2874
  _bindGroup = null;
2808
2875
  constructor(device, props) {
2809
2876
  super(device, props);
2810
2877
  this.device = device;
2811
- this.handle = this.props.handle || this.createHandle();
2878
+ this.handle = this.props.handle;
2879
+ if (!this.handle) {
2880
+ const descriptor = this._getRenderPipelineDescriptor();
2881
+ log.groupCollapsed(1, `new WebGPURenderPipeline(${this.id})`)();
2882
+ log.probe(1, JSON.stringify(descriptor, null, 2))();
2883
+ log.groupEnd(1)();
2884
+ this.handle = this.device.handle.createRenderPipeline(descriptor);
2885
+ }
2812
2886
  this.handle.label = this.props.id;
2813
2887
  this.vs = cast(props.vs);
2814
2888
  this.fs = cast(props.fs);
2815
2889
  this._bufferSlots = getBufferSlots(this.props.shaderLayout, this.props.bufferLayout);
2816
2890
  this._buffers = new Array(Object.keys(this._bufferSlots).length).fill(null);
2817
- this._bindGroupLayout = this.handle.getBindGroupLayout(0);
2818
- }
2819
- createHandle() {
2820
- const descriptor = this._getRenderPipelineDescriptor();
2821
- const renderPipeline = this.device.handle.createRenderPipeline(descriptor);
2822
- log.groupCollapsed(1, `new WebGPRenderPipeline(${this.id})`)();
2823
- log.log(1, JSON.stringify(descriptor, null, 2))();
2824
- log.groupEnd(1)();
2825
- return renderPipeline;
2826
2891
  }
2827
2892
  destroy() {
2828
2893
  }
@@ -2845,6 +2910,7 @@ var __exports__ = (() => {
2845
2910
  setBindings(bindings) {
2846
2911
  if (!isObjectEmpty(this.props.bindings)) {
2847
2912
  Object.assign(this.props.bindings, bindings);
2913
+ this._bindGroupLayout = this._bindGroupLayout || this.handle.getBindGroupLayout(0);
2848
2914
  this._bindGroup = getBindGroup(this.device.handle, this._bindGroupLayout, this.props.shaderLayout, this.props.bindings);
2849
2915
  }
2850
2916
  }
@@ -2860,7 +2926,9 @@ var __exports__ = (() => {
2860
2926
  _getBindGroup() {
2861
2927
  return this._bindGroup;
2862
2928
  }
2863
- /** Populate the complex WebGPU GPURenderPipelineDescriptor */
2929
+ /**
2930
+ * Populate the complex WebGPU GPURenderPipelineDescriptor
2931
+ */
2864
2932
  _getRenderPipelineDescriptor() {
2865
2933
  const vertex = {
2866
2934
  module: cast(this.props.vs).handle,
@@ -2906,7 +2974,12 @@ var __exports__ = (() => {
2906
2974
  if (options.indexCount) {
2907
2975
  webgpuRenderPass.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
2908
2976
  } else {
2909
- webgpuRenderPass.handle.draw(options.vertexCount || 0, options.instanceCount, options.firstIndex, options.firstInstance);
2977
+ webgpuRenderPass.handle.draw(
2978
+ options.vertexCount || 0,
2979
+ options.instanceCount || 1,
2980
+ // If 0, nothing will be drawn
2981
+ options.firstInstance
2982
+ );
2910
2983
  }
2911
2984
  }
2912
2985
  _setAttributeBuffers(webgpuRenderPass) {
@@ -2956,6 +3029,9 @@ var __exports__ = (() => {
2956
3029
  this.device = device;
2957
3030
  const framebuffer = props.framebuffer || device.canvasContext.getCurrentFramebuffer();
2958
3031
  const renderPassDescriptor = this.getRenderPassDescriptor(framebuffer);
3032
+ log.groupCollapsed(1, `new WebGPURenderPass(${this.id})`)();
3033
+ log.probe(1, JSON.stringify(renderPassDescriptor, null, 2))();
3034
+ log.groupEnd(1)();
2959
3035
  this.handle = this.props.handle || device.commandEncoder.beginRenderPass(renderPassDescriptor);
2960
3036
  this.handle.label = this.props.id;
2961
3037
  }
@@ -2986,7 +3062,7 @@ var __exports__ = (() => {
2986
3062
  if (options.indexCount) {
2987
3063
  this.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
2988
3064
  } else {
2989
- this.handle.draw(options.vertexCount || 0, options.instanceCount, options.firstIndex, options.firstInstance);
3065
+ this.handle.draw(options.vertexCount || 0, options.instanceCount || 1, options.firstIndex, options.firstInstance);
2990
3066
  }
2991
3067
  }
2992
3068
  drawIndirect() {
@@ -3037,7 +3113,7 @@ var __exports__ = (() => {
3037
3113
  };
3038
3114
  renderPassDescriptor.colorAttachments = framebuffer.colorAttachments.map((colorAttachment) => ({
3039
3115
  // clear values
3040
- loadOp: "clear",
3116
+ loadOp: this.props.clearColor !== false ? "clear" : "load",
3041
3117
  colorClearValue: this.props.clearColor || [0, 0, 0, 0],
3042
3118
  storeOp: this.props.discard ? "discard" : "store",
3043
3119
  // ...colorAttachment,
@@ -3045,9 +3121,25 @@ var __exports__ = (() => {
3045
3121
  }));
3046
3122
  if (framebuffer.depthStencilAttachment) {
3047
3123
  renderPassDescriptor.depthStencilAttachment = {
3048
- ...this.props,
3049
3124
  view: framebuffer.depthStencilAttachment.handle.createView()
3050
3125
  };
3126
+ const {
3127
+ depthStencilAttachment
3128
+ } = renderPassDescriptor;
3129
+ if (this.props.depthReadOnly) {
3130
+ depthStencilAttachment.depthReadOnly = true;
3131
+ }
3132
+ depthStencilAttachment.depthClearValue = this.props.clearDepth || 0;
3133
+ const hasDepthAspect = true;
3134
+ if (hasDepthAspect) {
3135
+ depthStencilAttachment.depthLoadOp = this.props.clearDepth !== false ? "clear" : "load";
3136
+ depthStencilAttachment.depthStoreOp = "store";
3137
+ }
3138
+ const hasStencilAspect = false;
3139
+ if (hasStencilAspect) {
3140
+ depthStencilAttachment.stencilLoadOp = this.props.clearStencil !== false ? "clear" : "load";
3141
+ depthStencilAttachment.stencilStoreOp = "store";
3142
+ }
3051
3143
  }
3052
3144
  return renderPassDescriptor;
3053
3145
  }
@@ -3110,6 +3202,51 @@ var __exports__ = (() => {
3110
3202
  // endPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
3111
3203
  };
3112
3204
 
3205
+ // src/adapter/resources/webgpu-vertex-array.ts
3206
+ var WebGPUVertexArray = class extends VertexArray {
3207
+ get [Symbol.toStringTag]() {
3208
+ return "WebGPUVertexArray";
3209
+ }
3210
+ /** Vertex Array is a helper class under WebGPU */
3211
+ /** * Attribute 0 can not be disable on most desktop OpenGL based browsers */
3212
+ static isConstantAttributeZeroSupported(device) {
3213
+ return device.info.type === "webgl2" || getBrowser() === "Chrome";
3214
+ }
3215
+ // Create a VertexArray
3216
+ constructor(device, props) {
3217
+ super(device, props);
3218
+ this.device = device;
3219
+ }
3220
+ destroy() {
3221
+ }
3222
+ /**
3223
+ * Set an elements buffer, for indexed rendering.
3224
+ * Must be a Buffer bound to buffer with usage bit Buffer.INDEX set.
3225
+ */
3226
+ setIndexBuffer(buffer) {
3227
+ this.indexBuffer = buffer;
3228
+ }
3229
+ /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
3230
+ setBuffer(location, buffer) {
3231
+ this.attributes[location] = buffer;
3232
+ }
3233
+ /** Set a location in vertex attributes array to a constant value, disables the location */
3234
+ setConstant(location, value) {
3235
+ log.warn(`${this.id} constant attributes not supported on WebGPU`);
3236
+ }
3237
+ bindBeforeRender(renderPass, firstIndex, indexCount) {
3238
+ const webgpuRenderPass = renderPass;
3239
+ const webgpuIndexBuffer = this.indexBuffer;
3240
+ webgpuRenderPass.handle.setIndexBuffer(webgpuIndexBuffer?.handle, webgpuIndexBuffer?.indexType);
3241
+ for (let location = 0; location < this.maxVertexAttributes; location++) {
3242
+ const webgpuBuffer = this.attributes[location];
3243
+ webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer.handle);
3244
+ }
3245
+ }
3246
+ unbindAfterRender(renderPass) {
3247
+ }
3248
+ };
3249
+
3113
3250
  // src/adapter/resources/webgpu-framebuffer.ts
3114
3251
  var WebGPUFramebuffer = class extends Framebuffer {
3115
3252
  constructor(device, props) {
@@ -3121,8 +3258,10 @@ var __exports__ = (() => {
3121
3258
 
3122
3259
  // src/adapter/webgpu-canvas-context.ts
3123
3260
  var WebGPUCanvasContext = class extends CanvasContext {
3261
+ /** Format of returned textures: "bgra8unorm", "rgba8unorm", "rgba16float". */
3262
+ format = navigator.gpu.getPreferredCanvasFormat();
3263
+ /** Default stencil format for depth textures */
3124
3264
  depthStencilFormat = "depth24plus";
3125
- sampleCount = 1;
3126
3265
  depthStencilAttachment = null;
3127
3266
  constructor(device, adapter, props) {
3128
3267
  super(props);
@@ -3131,21 +3270,24 @@ var __exports__ = (() => {
3131
3270
  this.height = -1;
3132
3271
  this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
3133
3272
  this.gpuCanvasContext = this.canvas.getContext("webgpu");
3134
- this.format = this.gpuCanvasContext.getPreferredFormat(adapter);
3273
+ this.format = "bgra8unorm";
3135
3274
  }
3275
+ /** Destroy any textures produced while configured and remove the context configuration. */
3136
3276
  destroy() {
3137
3277
  this.gpuCanvasContext.unconfigure();
3138
3278
  }
3279
+ getCurrentTexture() {
3280
+ return this.device._createTexture({
3281
+ id: "default-render-target",
3282
+ handle: this.gpuCanvasContext.getCurrentTexture()
3283
+ });
3284
+ }
3139
3285
  /** Update framebuffer with properly resized "swap chain" texture views */
3140
3286
  getCurrentFramebuffer() {
3141
3287
  this.update();
3142
- const currentColorAttachment = this.device.createTexture({
3143
- id: "default-render-target",
3144
- handle: this.gpuCanvasContext.getCurrentTexture(),
3145
- format: this.format,
3146
- width: this.width,
3147
- height: this.height
3148
- });
3288
+ const currentColorAttachment = this.getCurrentTexture();
3289
+ this.width = currentColorAttachment.width;
3290
+ this.height = currentColorAttachment.height;
3149
3291
  this._createDepthStencilAttachment();
3150
3292
  return new WebGPUFramebuffer(this.device, {
3151
3293
  colorAttachments: [currentColorAttachment],
@@ -3166,7 +3308,8 @@ var __exports__ = (() => {
3166
3308
  this.gpuCanvasContext.configure({
3167
3309
  device: this.device.handle,
3168
3310
  format: getWebGPUTextureFormat(this.format),
3169
- // size: [this.width, this.height],
3311
+ // Can be used to define e.g. -srgb views
3312
+ // viewFormats: [...]
3170
3313
  colorSpace: this.props.colorSpace,
3171
3314
  alphaMode: this.props.alphaMode
3172
3315
  });
@@ -3245,7 +3388,7 @@ var __exports__ = (() => {
3245
3388
  version: "",
3246
3389
  gpu: "unknown",
3247
3390
  // 'nvidia' | 'amd' | 'intel' | 'apple' | 'unknown',
3248
- shadingLanguages: ["glsl", "wgsl"],
3391
+ shadingLanguages: ["wgsl"],
3249
3392
  shadingLanguageVersions: {
3250
3393
  glsl: "450",
3251
3394
  wgsl: "100"
@@ -3261,11 +3404,9 @@ var __exports__ = (() => {
3261
3404
  message: lostInfo.message
3262
3405
  });
3263
3406
  });
3264
- if (props.canvas) {
3265
- this.canvasContext = new WebGPUCanvasContext(this, this.adapter, {
3266
- canvas: props.canvas
3267
- });
3268
- }
3407
+ this.canvasContext = new WebGPUCanvasContext(this, this.adapter, {
3408
+ canvas: props.canvas
3409
+ });
3269
3410
  this.features = this._getFeatures();
3270
3411
  }
3271
3412
  // TODO
@@ -3320,6 +3461,9 @@ var __exports__ = (() => {
3320
3461
  createComputePipeline(props) {
3321
3462
  return new WebGPUComputePipeline(this, props);
3322
3463
  }
3464
+ createVertexArray(props) {
3465
+ return new WebGPUVertexArray(this, props);
3466
+ }
3323
3467
  // WebGPU specifics
3324
3468
  /**
3325
3469
  * Allows a render pass to begin against a canvas context
@@ -3343,21 +3487,17 @@ var __exports__ = (() => {
3343
3487
  * Gets default renderpass encoder.
3344
3488
  * Creates a new encoder against default canvasContext if not already created
3345
3489
  * @note Called internally by Model.
3490
+ * @deprecated Create explicit pass with device.beginRenderPass
3346
3491
  */
3347
3492
  getDefaultRenderPass() {
3348
- this.renderPass = this.renderPass || this.beginRenderPass({
3349
- framebuffer: this.canvasContext?.getCurrentFramebuffer()
3350
- });
3351
- return this.renderPass;
3493
+ throw new Error("a");
3352
3494
  }
3353
3495
  submit() {
3354
- this.renderPass?.end();
3355
3496
  const commandBuffer = this.commandEncoder?.finish();
3356
3497
  if (commandBuffer) {
3357
3498
  this.handle.queue.submit([commandBuffer]);
3358
3499
  }
3359
3500
  this.commandEncoder = null;
3360
- this.renderPass = null;
3361
3501
  }
3362
3502
  _getFeatures() {
3363
3503
  const features = new Set(this.handle.features);