@luma.gl/webgpu 9.1.0-beta.8 → 9.2.0-alpha.1

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 (71) hide show
  1. package/dist/adapter/helpers/accessor-to-format.js +1 -0
  2. package/dist/adapter/helpers/accessor-to-format.js.map +1 -1
  3. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
  4. package/dist/adapter/helpers/get-bind-group.js +26 -10
  5. package/dist/adapter/helpers/get-bind-group.js.map +1 -1
  6. package/dist/adapter/helpers/get-vertex-buffer-layout.js +4 -4
  7. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -1
  8. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  9. package/dist/adapter/helpers/webgpu-parameters.js +66 -68
  10. package/dist/adapter/helpers/webgpu-parameters.js.map +1 -1
  11. package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
  12. package/dist/adapter/resources/webgpu-buffer.js +12 -0
  13. package/dist/adapter/resources/webgpu-buffer.js.map +1 -1
  14. package/dist/adapter/resources/webgpu-command-buffer.d.ts +10 -0
  15. package/dist/adapter/resources/webgpu-command-buffer.d.ts.map +1 -0
  16. package/dist/adapter/resources/webgpu-command-buffer.js +18 -0
  17. package/dist/adapter/resources/webgpu-command-buffer.js.map +1 -0
  18. package/dist/adapter/resources/webgpu-command-encoder.d.ts +12 -5
  19. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  20. package/dist/adapter/resources/webgpu-command-encoder.js +21 -5
  21. package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -1
  22. package/dist/adapter/resources/webgpu-compute-pass.js +1 -1
  23. package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -1
  24. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  25. package/dist/adapter/resources/webgpu-render-pass.js +2 -1
  26. package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
  27. package/dist/adapter/resources/webgpu-sampler.js +1 -1
  28. package/dist/adapter/resources/webgpu-sampler.js.map +1 -1
  29. package/dist/adapter/resources/webgpu-texture-view.d.ts.map +1 -1
  30. package/dist/adapter/resources/webgpu-texture-view.js +16 -10
  31. package/dist/adapter/resources/webgpu-texture-view.js.map +1 -1
  32. package/dist/adapter/resources/webgpu-texture.d.ts +4 -37
  33. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  34. package/dist/adapter/resources/webgpu-texture.js +98 -124
  35. package/dist/adapter/resources/webgpu-texture.js.map +1 -1
  36. package/dist/adapter/resources/webgpu-vertex-array.d.ts +2 -2
  37. package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -1
  38. package/dist/adapter/resources/webgpu-vertex-array.js +2 -2
  39. package/dist/adapter/resources/webgpu-vertex-array.js.map +1 -1
  40. package/dist/adapter/webgpu-adapter.d.ts +2 -3
  41. package/dist/adapter/webgpu-adapter.d.ts.map +1 -1
  42. package/dist/adapter/webgpu-adapter.js +19 -10
  43. package/dist/adapter/webgpu-adapter.js.map +1 -1
  44. package/dist/adapter/webgpu-canvas-context.d.ts +1 -7
  45. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  46. package/dist/adapter/webgpu-canvas-context.js +13 -18
  47. package/dist/adapter/webgpu-canvas-context.js.map +1 -1
  48. package/dist/adapter/webgpu-device.d.ts +8 -25
  49. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  50. package/dist/adapter/webgpu-device.js +31 -61
  51. package/dist/adapter/webgpu-device.js.map +1 -1
  52. package/dist/dist.dev.js +1657 -1389
  53. package/dist/dist.min.js +4 -4
  54. package/dist/index.cjs +1510 -1270
  55. package/dist/index.cjs.map +4 -4
  56. package/package.json +3 -3
  57. package/src/adapter/helpers/get-bind-group.ts +28 -11
  58. package/src/adapter/helpers/get-vertex-buffer-layout.ts +4 -4
  59. package/src/adapter/helpers/webgpu-parameters.ts +88 -97
  60. package/src/adapter/resources/webgpu-buffer.ts +12 -0
  61. package/src/adapter/resources/webgpu-command-buffer.ts +24 -0
  62. package/src/adapter/resources/webgpu-command-encoder.ts +27 -4
  63. package/src/adapter/resources/webgpu-compute-pass.ts +1 -1
  64. package/src/adapter/resources/webgpu-render-pass.ts +2 -1
  65. package/src/adapter/resources/webgpu-sampler.ts +1 -1
  66. package/src/adapter/resources/webgpu-texture-view.ts +15 -8
  67. package/src/adapter/resources/webgpu-texture.ts +106 -184
  68. package/src/adapter/resources/webgpu-vertex-array.ts +2 -2
  69. package/src/adapter/webgpu-adapter.ts +27 -14
  70. package/src/adapter/webgpu-canvas-context.ts +16 -20
  71. package/src/adapter/webgpu-device.ts +38 -99
package/dist/index.cjs CHANGED
@@ -1,10 +1,14 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __esm = (fn, res) => function __init() {
7
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
8
+ };
5
9
  var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
10
+ for (var name2 in all)
11
+ __defProp(target, name2, { get: all[name2], enumerable: true });
8
12
  };
9
13
  var __copyProps = (to, from, except, desc) => {
10
14
  if (from && typeof from === "object" || typeof from === "function") {
@@ -16,95 +20,92 @@ var __copyProps = (to, from, except, desc) => {
16
20
  };
17
21
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
22
 
19
- // dist/index.js
20
- var dist_exports = {};
21
- __export(dist_exports, {
22
- WebGPUBuffer: () => WebGPUBuffer,
23
- WebGPUDevice: () => WebGPUDevice,
24
- WebGPUSampler: () => WebGPUSampler,
25
- WebGPUShader: () => WebGPUShader,
26
- WebGPUTexture: () => WebGPUTexture,
27
- webgpuAdapter: () => webgpuAdapter
28
- });
29
- module.exports = __toCommonJS(dist_exports);
30
-
31
- // dist/adapter/webgpu-adapter.js
32
- var import_core18 = require("@luma.gl/core");
33
-
34
- // dist/adapter/webgpu-device.js
35
- var import_core17 = require("@luma.gl/core");
36
-
37
23
  // dist/adapter/resources/webgpu-buffer.js
38
- var import_core = require("@luma.gl/core");
39
24
  function getByteLength(props) {
40
25
  var _a;
41
26
  return props.byteLength || ((_a = props.data) == null ? void 0 : _a.byteLength) || 0;
42
27
  }
43
- var WebGPUBuffer = class extends import_core.Buffer {
44
- device;
45
- handle;
46
- byteLength;
47
- constructor(device, props) {
48
- super(device, props);
49
- this.device = device;
50
- this.byteLength = getByteLength(props);
51
- const mapBuffer = Boolean(props.data);
52
- const size = Math.ceil(this.byteLength / 4) * 4;
53
- this.handle = this.props.handle || this.device.handle.createBuffer({
54
- size,
55
- // usage defaults to vertex
56
- usage: this.props.usage || GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
57
- mappedAtCreation: this.props.mappedAtCreation || mapBuffer,
58
- label: this.props.id
59
- });
60
- if (props.data) {
61
- this._writeMapped(props.data);
62
- }
63
- if (mapBuffer && !props.mappedAtCreation) {
64
- this.handle.unmap();
65
- }
66
- }
67
- destroy() {
68
- var _a;
69
- (_a = this.handle) == null ? void 0 : _a.destroy();
70
- this.handle = null;
71
- }
72
- // WebGPU provides multiple ways to write a buffer...
73
- write(data, byteOffset = 0) {
74
- this.device.handle.queue.writeBuffer(this.handle, byteOffset, data.buffer, data.byteOffset, data.byteLength);
75
- }
76
- async readAsync(byteOffset = 0, byteLength = this.byteLength) {
77
- const tempBuffer = new WebGPUBuffer(this.device, {
78
- usage: import_core.Buffer.MAP_READ | import_core.Buffer.COPY_DST,
79
- byteLength
80
- });
81
- const commandEncoder = this.device.handle.createCommandEncoder();
82
- commandEncoder.copyBufferToBuffer(this.handle, byteOffset, tempBuffer.handle, 0, byteLength);
83
- this.device.handle.queue.submit([commandEncoder.finish()]);
84
- await tempBuffer.handle.mapAsync(GPUMapMode.READ, byteOffset, byteLength);
85
- const arrayBuffer = tempBuffer.handle.getMappedRange().slice(0);
86
- tempBuffer.handle.unmap();
87
- tempBuffer.destroy();
88
- return new Uint8Array(arrayBuffer);
89
- }
90
- _writeMapped(typedArray) {
91
- const arrayBuffer = this.handle.getMappedRange();
92
- new typedArray.constructor(arrayBuffer).set(typedArray);
93
- }
94
- // WEBGPU API
95
- mapAsync(mode, offset = 0, size) {
96
- return this.handle.mapAsync(mode, offset, size);
97
- }
98
- getMappedRange(offset = 0, size) {
99
- return this.handle.getMappedRange(offset, size);
100
- }
101
- unmap() {
102
- this.handle.unmap();
28
+ var import_core, WebGPUBuffer;
29
+ var init_webgpu_buffer = __esm({
30
+ "dist/adapter/resources/webgpu-buffer.js"() {
31
+ "use strict";
32
+ import_core = require("@luma.gl/core");
33
+ WebGPUBuffer = class extends import_core.Buffer {
34
+ device;
35
+ handle;
36
+ byteLength;
37
+ constructor(device, props) {
38
+ super(device, props);
39
+ this.device = device;
40
+ this.byteLength = getByteLength(props);
41
+ const mapBuffer = Boolean(props.data);
42
+ const size = Math.ceil(this.byteLength / 4) * 4;
43
+ this.device.handle.pushErrorScope("out-of-memory");
44
+ this.device.handle.pushErrorScope("validation");
45
+ this.handle = this.props.handle || this.device.handle.createBuffer({
46
+ size,
47
+ // usage defaults to vertex
48
+ usage: this.props.usage || GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
49
+ mappedAtCreation: this.props.mappedAtCreation || mapBuffer,
50
+ label: this.props.id
51
+ });
52
+ this.device.handle.popErrorScope().then((error) => {
53
+ if (error) {
54
+ this.device.reportError(new Error(`Buffer validation failed: ${error.message}`), this);
55
+ }
56
+ });
57
+ this.device.handle.popErrorScope().then((error) => {
58
+ if (error) {
59
+ this.device.reportError(new Error(`Buffer out of memory: ${error.message}`), this);
60
+ }
61
+ });
62
+ if (props.data) {
63
+ this._writeMapped(props.data);
64
+ }
65
+ if (mapBuffer && !props.mappedAtCreation) {
66
+ this.handle.unmap();
67
+ }
68
+ }
69
+ destroy() {
70
+ var _a;
71
+ (_a = this.handle) == null ? void 0 : _a.destroy();
72
+ this.handle = null;
73
+ }
74
+ // WebGPU provides multiple ways to write a buffer...
75
+ write(data, byteOffset = 0) {
76
+ this.device.handle.queue.writeBuffer(this.handle, byteOffset, data.buffer, data.byteOffset, data.byteLength);
77
+ }
78
+ async readAsync(byteOffset = 0, byteLength = this.byteLength) {
79
+ const tempBuffer = new WebGPUBuffer(this.device, {
80
+ usage: import_core.Buffer.MAP_READ | import_core.Buffer.COPY_DST,
81
+ byteLength
82
+ });
83
+ const commandEncoder = this.device.handle.createCommandEncoder();
84
+ commandEncoder.copyBufferToBuffer(this.handle, byteOffset, tempBuffer.handle, 0, byteLength);
85
+ this.device.handle.queue.submit([commandEncoder.finish()]);
86
+ await tempBuffer.handle.mapAsync(GPUMapMode.READ, byteOffset, byteLength);
87
+ const arrayBuffer = tempBuffer.handle.getMappedRange().slice(0);
88
+ tempBuffer.handle.unmap();
89
+ tempBuffer.destroy();
90
+ return new Uint8Array(arrayBuffer);
91
+ }
92
+ _writeMapped(typedArray) {
93
+ const arrayBuffer = this.handle.getMappedRange();
94
+ new typedArray.constructor(arrayBuffer).set(typedArray);
95
+ }
96
+ // WEBGPU API
97
+ mapAsync(mode, offset = 0, size) {
98
+ return this.handle.mapAsync(mode, offset, size);
99
+ }
100
+ getMappedRange(offset = 0, size) {
101
+ return this.handle.getMappedRange(offset, size);
102
+ }
103
+ unmap() {
104
+ this.handle.unmap();
105
+ }
106
+ };
103
107
  }
104
- };
105
-
106
- // dist/adapter/resources/webgpu-texture.js
107
- var import_core4 = require("@luma.gl/core");
108
+ });
108
109
 
109
110
  // dist/adapter/helpers/convert-texture-format.js
110
111
  function getWebGPUTextureFormat(format) {
@@ -113,263 +114,299 @@ function getWebGPUTextureFormat(format) {
113
114
  }
114
115
  return format;
115
116
  }
117
+ var init_convert_texture_format = __esm({
118
+ "dist/adapter/helpers/convert-texture-format.js"() {
119
+ "use strict";
120
+ }
121
+ });
116
122
 
117
123
  // dist/adapter/resources/webgpu-sampler.js
118
- var import_core2 = require("@luma.gl/core");
119
- var WebGPUSampler = class extends import_core2.Sampler {
120
- device;
121
- handle;
122
- constructor(device, props) {
123
- super(device, props);
124
- this.device = device;
125
- const samplerDescriptor = {
126
- ...this.props,
127
- mipmapFilter: void 0
124
+ var import_core2, WebGPUSampler;
125
+ var init_webgpu_sampler = __esm({
126
+ "dist/adapter/resources/webgpu-sampler.js"() {
127
+ "use strict";
128
+ import_core2 = require("@luma.gl/core");
129
+ WebGPUSampler = class extends import_core2.Sampler {
130
+ device;
131
+ handle;
132
+ constructor(device, props) {
133
+ super(device, props);
134
+ this.device = device;
135
+ const samplerDescriptor = {
136
+ ...this.props,
137
+ mipmapFilter: void 0
138
+ };
139
+ if (props.type !== "comparison-sampler") {
140
+ delete samplerDescriptor.compare;
141
+ }
142
+ if (props.mipmapFilter && props.mipmapFilter !== "none") {
143
+ samplerDescriptor.mipmapFilter = props.mipmapFilter;
144
+ }
145
+ this.handle = props.handle || this.device.handle.createSampler(samplerDescriptor);
146
+ this.handle.label = this.props.id;
147
+ }
148
+ destroy() {
149
+ this.handle = null;
150
+ }
128
151
  };
129
- if (props.type !== "comparison-sampler") {
130
- delete samplerDescriptor.compare;
131
- }
132
- if (props.mipmapFilter && props.mipmapFilter !== "none") {
133
- samplerDescriptor.mipmapFilter = props.mipmapFilter;
134
- }
135
- this.handle = this.handle || this.device.handle.createSampler(samplerDescriptor);
136
- this.handle.label = this.props.id;
137
152
  }
138
- destroy() {
139
- this.handle = null;
140
- }
141
- };
153
+ });
142
154
 
143
155
  // dist/adapter/resources/webgpu-texture-view.js
144
- var import_core3 = require("@luma.gl/core");
145
- var WebGPUTextureView = class extends import_core3.TextureView {
146
- device;
147
- handle;
148
- texture;
149
- constructor(device, props) {
150
- super(device, props);
151
- this.device = device;
152
- this.texture = props.texture;
153
- this.handle = this.handle || this.texture.handle.createView({
154
- format: props.format || this.texture.format,
155
- dimension: props.dimension || this.texture.dimension,
156
- aspect: props.aspect,
157
- baseMipLevel: props.baseMipLevel,
158
- mipLevelCount: props.mipLevelCount,
159
- // GPUIntegerCoordinate;
160
- baseArrayLayer: props.baseArrayLayer,
161
- // GPUIntegerCoordinate;
162
- arrayLayerCount: props.arrayLayerCount
163
- // GPUIntegerCoordinate;
164
- });
165
- this.handle.label = this.props.id;
166
- }
167
- destroy() {
168
- this.handle = null;
156
+ var import_core3, WebGPUTextureView;
157
+ var init_webgpu_texture_view = __esm({
158
+ "dist/adapter/resources/webgpu-texture-view.js"() {
159
+ "use strict";
160
+ import_core3 = require("@luma.gl/core");
161
+ WebGPUTextureView = class extends import_core3.TextureView {
162
+ device;
163
+ handle;
164
+ texture;
165
+ constructor(device, props) {
166
+ super(device, props);
167
+ this.device = device;
168
+ this.texture = props.texture;
169
+ this.device.pushErrorScope("validation");
170
+ this.handle = // props.handle ||
171
+ this.texture.handle.createView({
172
+ format: this.props.format || this.texture.format,
173
+ dimension: this.props.dimension || this.texture.dimension,
174
+ aspect: this.props.aspect,
175
+ baseMipLevel: this.props.baseMipLevel,
176
+ mipLevelCount: this.props.mipLevelCount,
177
+ baseArrayLayer: this.props.baseArrayLayer,
178
+ arrayLayerCount: this.props.arrayLayerCount
179
+ });
180
+ this.device.handle.popErrorScope().then((error) => {
181
+ if (error) {
182
+ this.device.reportError(new Error(`TextureView validation failed: ${error.message}`), this);
183
+ }
184
+ });
185
+ this.handle.label = this.props.id;
186
+ }
187
+ destroy() {
188
+ this.handle = null;
189
+ }
190
+ };
169
191
  }
170
- };
192
+ });
171
193
 
172
194
  // dist/adapter/resources/webgpu-texture.js
173
- var BASE_DIMENSIONS = {
174
- "1d": "1d",
175
- "2d": "2d",
176
- "2d-array": "2d",
177
- cube: "2d",
178
- "cube-array": "2d",
179
- "3d": "3d"
180
- };
181
- var WebGPUTexture = class extends import_core4.Texture {
182
- device;
183
- handle;
184
- sampler;
185
- view;
186
- constructor(device, props) {
187
- super(device, props);
188
- this.device = device;
189
- const propsWithData = { ...this.props };
190
- if (props.data) {
191
- propsWithData.data = props.data;
192
- }
193
- this.initialize(propsWithData);
194
- }
195
- destroy() {
196
- var _a;
197
- (_a = this.handle) == null ? void 0 : _a.destroy();
198
- this.handle = null;
199
- }
200
- createView(props) {
201
- return new WebGPUTextureView(this.device, { ...props, texture: this });
202
- }
203
- initialize(props) {
204
- this.handle = this.props.handle || this.createHandle();
205
- this.handle.label ||= this.id;
206
- if (this.props.data) {
207
- if (import_core4.Texture.isExternalImage(this.props.data)) {
208
- this.copyExternalImage({ image: this.props.data });
209
- } else {
210
- this.setData({ data: this.props.data });
195
+ var import_core4, WebGPUTexture;
196
+ var init_webgpu_texture = __esm({
197
+ "dist/adapter/resources/webgpu-texture.js"() {
198
+ "use strict";
199
+ import_core4 = require("@luma.gl/core");
200
+ init_convert_texture_format();
201
+ init_webgpu_sampler();
202
+ init_webgpu_texture_view();
203
+ WebGPUTexture = class extends import_core4.Texture {
204
+ device;
205
+ handle;
206
+ sampler;
207
+ view;
208
+ constructor(device, props) {
209
+ super(device, props);
210
+ this.device = device;
211
+ if (this.dimension === "cube") {
212
+ this.depth = 6;
213
+ }
214
+ this.device.handle.pushErrorScope("out-of-memory");
215
+ this.device.handle.pushErrorScope("validation");
216
+ this.handle = this.props.handle || this.device.handle.createTexture({
217
+ label: this.id,
218
+ size: {
219
+ width: this.width,
220
+ height: this.height,
221
+ depthOrArrayLayers: this.depth
222
+ },
223
+ usage: this.props.usage || import_core4.Texture.TEXTURE | import_core4.Texture.COPY_DST,
224
+ dimension: this.baseDimension,
225
+ format: getWebGPUTextureFormat(this.format),
226
+ mipLevelCount: this.mipLevels,
227
+ sampleCount: this.props.samples
228
+ });
229
+ this.device.handle.popErrorScope().then((error) => {
230
+ if (error) {
231
+ this.device.reportError(new Error(`Texture validation failed: ${error.message}`), this);
232
+ }
233
+ });
234
+ this.device.handle.popErrorScope().then((error) => {
235
+ if (error) {
236
+ this.device.reportError(new Error(`Texture out of memory: ${error.message}`), this);
237
+ }
238
+ });
239
+ if (this.props.handle) {
240
+ this.handle.label ||= this.id;
241
+ this.width = this.handle.width;
242
+ this.height = this.handle.height;
243
+ }
244
+ this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler || {});
245
+ this.view = new WebGPUTextureView(this.device, {
246
+ ...this.props,
247
+ texture: this,
248
+ mipLevelCount: this.mipLevels,
249
+ arrayLayerCount: this.depth
250
+ });
251
+ this._initializeData(props.data);
211
252
  }
212
- }
213
- this.width = this.handle.width;
214
- this.height = this.handle.height;
215
- this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler || {});
216
- this.view = new WebGPUTextureView(this.device, { ...this.props, texture: this });
217
- }
218
- createHandle() {
219
- var _a, _b;
220
- const width = this.props.width || ((_a = this.props.data) == null ? void 0 : _a.width) || 1;
221
- const height = this.props.height || ((_b = this.props.data) == null ? void 0 : _b.height) || 1;
222
- return this.device.handle.createTexture({
223
- label: this.id,
224
- size: {
225
- width,
226
- height,
227
- depthOrArrayLayers: this.depth
228
- },
229
- usage: this.props.usage || import_core4.Texture.TEXTURE | import_core4.Texture.COPY_DST,
230
- dimension: BASE_DIMENSIONS[this.dimension],
231
- format: getWebGPUTextureFormat(this.format),
232
- mipLevelCount: this.mipLevels,
233
- sampleCount: this.props.samples
234
- });
235
- }
236
- /** @deprecated - intention is to use the createView public API */
237
- createGPUTextureView() {
238
- return this.handle.createView({ label: this.id });
239
- }
240
- /**
241
- * Set default sampler
242
- * Accept a sampler instance or set of props;
243
- */
244
- setSampler(sampler) {
245
- this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
246
- return this;
247
- }
248
- setTexture1DData(data) {
249
- throw new Error("not implemented");
250
- }
251
- setTexture2DData(lodData, depth, target) {
252
- throw new Error("not implemented");
253
- }
254
- setTexture3DData(lodData, depth, target) {
255
- throw new Error("not implemented");
256
- }
257
- setTextureCubeData(data, depth) {
258
- throw new Error("not implemented");
259
- }
260
- setTextureArrayData(data) {
261
- throw new Error("not implemented");
262
- }
263
- setTextureCubeArrayData(data) {
264
- throw new Error("not implemented");
265
- }
266
- setData(options) {
267
- if (ArrayBuffer.isView(options.data)) {
268
- const clampedArray = new Uint8ClampedArray(options.data.buffer);
269
- const image = new ImageData(clampedArray, this.width, this.height);
270
- return this.copyExternalImage({ image });
271
- }
272
- throw new Error("Texture.setData: Use CommandEncoder to upload data to texture in WebGPU");
273
- }
274
- copyExternalImage(options) {
275
- const size = import_core4.Texture.getExternalImageSize(options.image);
276
- const opts = { ...import_core4.Texture.defaultCopyExternalImageOptions, ...size, ...options };
277
- const { image, sourceX, sourceY, width, height, depth, mipLevel, x, y, z, aspect, colorSpace, premultipliedAlpha, flipY } = opts;
278
- this.device.handle.queue.copyExternalImageToTexture(
279
- // source: GPUImageCopyExternalImage
280
- {
281
- source: image,
282
- origin: [sourceX, sourceY],
283
- flipY
284
- },
285
- // destination: GPUImageCopyTextureTagged
286
- {
287
- texture: this.handle,
288
- origin: [x, y, z],
289
- mipLevel,
290
- aspect,
291
- colorSpace,
292
- premultipliedAlpha
293
- },
294
- // copySize: GPUExtent3D
295
- [width, height, depth]
296
- );
297
- return { width, height };
253
+ destroy() {
254
+ var _a;
255
+ (_a = this.handle) == null ? void 0 : _a.destroy();
256
+ this.handle = null;
257
+ }
258
+ createView(props) {
259
+ return new WebGPUTextureView(this.device, { ...props, texture: this });
260
+ }
261
+ copyImageData(options_) {
262
+ const { width, height, depth } = this;
263
+ const options = this._normalizeCopyImageDataOptions(options_);
264
+ this.device.handle.pushErrorScope("validation");
265
+ this.device.handle.queue.writeTexture(
266
+ // destination: GPUImageCopyTexture
267
+ {
268
+ // texture subresource
269
+ texture: this.handle,
270
+ mipLevel: options.mipLevel,
271
+ aspect: options.aspect,
272
+ // origin to write to
273
+ origin: [options.x, options.y, options.z]
274
+ },
275
+ // data
276
+ options.data,
277
+ // dataLayout: GPUImageDataLayout
278
+ {
279
+ offset: options.byteOffset,
280
+ bytesPerRow: options.bytesPerRow,
281
+ rowsPerImage: options.rowsPerImage
282
+ },
283
+ // size: GPUExtent3D - extents of the content to write
284
+ [width, height, depth]
285
+ );
286
+ this.device.handle.popErrorScope().then((error) => {
287
+ if (error) {
288
+ this.device.reportError(new Error(`copyImageData validation failed: ${error.message}`));
289
+ }
290
+ });
291
+ }
292
+ copyExternalImage(options_) {
293
+ const options = this._normalizeCopyExternalImageOptions(options_);
294
+ this.device.handle.pushErrorScope("validation");
295
+ this.device.handle.queue.copyExternalImageToTexture(
296
+ // source: GPUImageCopyExternalImage
297
+ {
298
+ source: options.image,
299
+ origin: [options.sourceX, options.sourceY],
300
+ flipY: options.flipY
301
+ },
302
+ // destination: GPUImageCopyTextureTagged
303
+ {
304
+ texture: this.handle,
305
+ origin: [options.x, options.y, options.depth],
306
+ mipLevel: options.mipLevel,
307
+ aspect: options.aspect,
308
+ colorSpace: options.colorSpace,
309
+ premultipliedAlpha: options.premultipliedAlpha
310
+ },
311
+ // copySize: GPUExtent3D
312
+ [options.width, options.height, 1]
313
+ );
314
+ this.device.handle.popErrorScope().then((error) => {
315
+ if (error) {
316
+ this.device.reportError(new Error(`copyExternalImage validation failed: ${error.message}`));
317
+ }
318
+ });
319
+ return { width: options.width, height: options.height };
320
+ }
321
+ generateMipmapsWebGL() {
322
+ import_core4.log.warn(`${this}: generateMipmaps not supported in WebGPU`)();
323
+ }
324
+ };
298
325
  }
299
- };
326
+ });
300
327
 
301
328
  // dist/adapter/resources/webgpu-external-texture.js
302
- var import_core5 = require("@luma.gl/core");
303
- var WebGPUExternalTexture = class extends import_core5.ExternalTexture {
304
- device;
305
- handle;
306
- sampler;
307
- constructor(device, props) {
308
- super(device, props);
309
- this.device = device;
310
- this.handle = this.props.handle || this.device.handle.importExternalTexture({
311
- source: props.source,
312
- colorSpace: props.colorSpace
313
- });
314
- this.sampler = null;
315
- }
316
- destroy() {
317
- this.handle = null;
318
- }
319
- /** Set default sampler */
320
- setSampler(sampler) {
321
- this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
322
- return this;
329
+ var import_core5, WebGPUExternalTexture;
330
+ var init_webgpu_external_texture = __esm({
331
+ "dist/adapter/resources/webgpu-external-texture.js"() {
332
+ "use strict";
333
+ import_core5 = require("@luma.gl/core");
334
+ init_webgpu_sampler();
335
+ WebGPUExternalTexture = class extends import_core5.ExternalTexture {
336
+ device;
337
+ handle;
338
+ sampler;
339
+ constructor(device, props) {
340
+ super(device, props);
341
+ this.device = device;
342
+ this.handle = this.props.handle || this.device.handle.importExternalTexture({
343
+ source: props.source,
344
+ colorSpace: props.colorSpace
345
+ });
346
+ this.sampler = null;
347
+ }
348
+ destroy() {
349
+ this.handle = null;
350
+ }
351
+ /** Set default sampler */
352
+ setSampler(sampler) {
353
+ this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
354
+ return this;
355
+ }
356
+ };
323
357
  }
324
- };
358
+ });
325
359
 
326
360
  // dist/adapter/resources/webgpu-shader.js
327
- var import_core6 = require("@luma.gl/core");
328
- var WebGPUShader = class extends import_core6.Shader {
329
- device;
330
- handle;
331
- constructor(device, props) {
332
- super(device, props);
333
- this.device = device;
334
- const isGLSL = props.source.includes("#version");
335
- if (this.props.language === "glsl" || isGLSL) {
336
- throw new Error("GLSL shaders are not supported in WebGPU");
337
- }
338
- this.device.handle.pushErrorScope("validation");
339
- this.handle = this.props.handle || this.device.handle.createShaderModule({ code: props.source });
340
- this.device.handle.popErrorScope().then((error) => {
341
- if (error) {
342
- import_core6.log.error(`${this} creation failed:
361
+ var import_core6, WebGPUShader;
362
+ var init_webgpu_shader = __esm({
363
+ "dist/adapter/resources/webgpu-shader.js"() {
364
+ "use strict";
365
+ import_core6 = require("@luma.gl/core");
366
+ WebGPUShader = class extends import_core6.Shader {
367
+ device;
368
+ handle;
369
+ constructor(device, props) {
370
+ super(device, props);
371
+ this.device = device;
372
+ const isGLSL = props.source.includes("#version");
373
+ if (this.props.language === "glsl" || isGLSL) {
374
+ throw new Error("GLSL shaders are not supported in WebGPU");
375
+ }
376
+ this.device.handle.pushErrorScope("validation");
377
+ this.handle = this.props.handle || this.device.handle.createShaderModule({ code: props.source });
378
+ this.device.handle.popErrorScope().then((error) => {
379
+ if (error) {
380
+ import_core6.log.error(`${this} creation failed:
343
381
  "${error.message}"`, this, this.props.source)();
382
+ }
383
+ });
384
+ this.handle.label = this.props.id;
385
+ this._checkCompilationError();
344
386
  }
345
- });
346
- this.handle.label = this.props.id;
347
- this._checkCompilationError();
348
- }
349
- get asyncCompilationStatus() {
350
- return this.getCompilationInfo().then(() => this.compilationStatus);
351
- }
352
- async _checkCompilationError() {
353
- const shaderLog = await this.getCompilationInfo();
354
- const hasErrors = Boolean(shaderLog.find((msg) => msg.type === "error"));
355
- this.compilationStatus = hasErrors ? "error" : "success";
356
- this.debugShader();
357
- if (this.compilationStatus === "error") {
358
- import_core6.log.error(`Shader compilation error`, shaderLog)();
359
- }
360
- }
361
- destroy() {
362
- this.handle = null;
363
- }
364
- /** Returns compilation info for this shader */
365
- async getCompilationInfo() {
366
- const compilationInfo = await this.handle.getCompilationInfo();
367
- return compilationInfo.messages;
387
+ get asyncCompilationStatus() {
388
+ return this.getCompilationInfo().then(() => this.compilationStatus);
389
+ }
390
+ async _checkCompilationError() {
391
+ const shaderLog = await this.getCompilationInfo();
392
+ const hasErrors = Boolean(shaderLog.find((msg) => msg.type === "error"));
393
+ this.compilationStatus = hasErrors ? "error" : "success";
394
+ this.debugShader();
395
+ if (this.compilationStatus === "error") {
396
+ import_core6.log.error(`Shader compilation error`, shaderLog)();
397
+ }
398
+ }
399
+ destroy() {
400
+ this.handle = null;
401
+ }
402
+ /** Returns compilation info for this shader */
403
+ async getCompilationInfo() {
404
+ const compilationInfo = await this.handle.getCompilationInfo();
405
+ return compilationInfo.messages;
406
+ }
407
+ };
368
408
  }
369
- };
370
-
371
- // dist/adapter/resources/webgpu-render-pipeline.js
372
- var import_core9 = require("@luma.gl/core");
409
+ });
373
410
 
374
411
  // dist/adapter/helpers/webgpu-parameters.js
375
412
  function addDepthStencil(descriptor) {
@@ -392,157 +429,6 @@ function addDepthStencilBack(descriptor) {
392
429
  const depthStencil = addDepthStencil(descriptor);
393
430
  return depthStencil.stencilBack;
394
431
  }
395
- var PARAMETER_TABLE = {
396
- // RASTERIZATION PARAMETERS
397
- cullMode: (parameter, value, descriptor) => {
398
- descriptor.primitive = descriptor.primitive || {};
399
- descriptor.primitive.cullMode = value;
400
- },
401
- frontFace: (parameter, value, descriptor) => {
402
- descriptor.primitive = descriptor.primitive || {};
403
- descriptor.primitive.frontFace = value;
404
- },
405
- // DEPTH
406
- depthWriteEnabled: (parameter, value, descriptor) => {
407
- const depthStencil = addDepthStencil(descriptor);
408
- depthStencil.depthWriteEnabled = value;
409
- },
410
- depthCompare: (parameter, value, descriptor) => {
411
- const depthStencil = addDepthStencil(descriptor);
412
- depthStencil.depthCompare = value;
413
- },
414
- depthFormat: (parameter, value, descriptor) => {
415
- const depthStencil = addDepthStencil(descriptor);
416
- depthStencil.format = value;
417
- },
418
- depthBias: (parameter, value, descriptor) => {
419
- const depthStencil = addDepthStencil(descriptor);
420
- depthStencil.depthBias = value;
421
- },
422
- depthBiasSlopeScale: (parameter, value, descriptor) => {
423
- const depthStencil = addDepthStencil(descriptor);
424
- depthStencil.depthBiasSlopeScale = value;
425
- },
426
- depthBiasClamp: (parameter, value, descriptor) => {
427
- const depthStencil = addDepthStencil(descriptor);
428
- depthStencil.depthBiasClamp = value;
429
- },
430
- // STENCIL
431
- stencilReadMask: (parameter, value, descriptor) => {
432
- const depthStencil = addDepthStencil(descriptor);
433
- depthStencil.stencilReadMask = value;
434
- },
435
- stencilWriteMask: (parameter, value, descriptor) => {
436
- const depthStencil = addDepthStencil(descriptor);
437
- depthStencil.stencilWriteMask = value;
438
- },
439
- stencilCompare: (parameter, value, descriptor) => {
440
- const stencilFront = addDepthStencilFront(descriptor);
441
- const stencilBack = addDepthStencilBack(descriptor);
442
- stencilFront.compare = value;
443
- stencilBack.compare = value;
444
- },
445
- stencilPassOperation: (parameter, value, descriptor) => {
446
- const stencilFront = addDepthStencilFront(descriptor);
447
- const stencilBack = addDepthStencilBack(descriptor);
448
- stencilFront.passOp = value;
449
- stencilBack.passOp = value;
450
- },
451
- stencilFailOperation: (parameter, value, descriptor) => {
452
- const stencilFront = addDepthStencilFront(descriptor);
453
- const stencilBack = addDepthStencilBack(descriptor);
454
- stencilFront.failOp = value;
455
- stencilBack.failOp = value;
456
- },
457
- stencilDepthFailOperation: (parameter, value, descriptor) => {
458
- const stencilFront = addDepthStencilFront(descriptor);
459
- const stencilBack = addDepthStencilBack(descriptor);
460
- stencilFront.depthFailOp = value;
461
- stencilBack.depthFailOp = value;
462
- },
463
- // MULTISAMPLE
464
- sampleCount: (parameter, value, descriptor) => {
465
- descriptor.multisample = descriptor.multisample || {};
466
- descriptor.multisample.count = value;
467
- },
468
- sampleMask: (parameter, value, descriptor) => {
469
- descriptor.multisample = descriptor.multisample || {};
470
- descriptor.multisample.mask = value;
471
- },
472
- sampleAlphaToCoverageEnabled: (parameter, value, descriptor) => {
473
- descriptor.multisample = descriptor.multisample || {};
474
- descriptor.multisample.alphaToCoverageEnabled = value;
475
- },
476
- // COLOR
477
- colorMask: (parameter, value, descriptor) => {
478
- const targets = addColorState(descriptor);
479
- targets[0].writeMask = value;
480
- },
481
- blendColorOperation: (parameter, value, descriptor) => {
482
- addColorState(descriptor);
483
- }
484
- /*
485
- blendColorSrcTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
486
- addColorState(descriptor);
487
- targets[0].blend = targets[0].blend || {};
488
- targets[0].blend.color = targets[0].blend.color || {};
489
- targets[0].blend.color.srcTarget = value;
490
- },
491
-
492
- blendColorDstTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
493
- addColorState(descriptor);
494
- targets[0].blend = targets[0].blend || {};
495
- targets[0].blend.color = targets[0].blend.color || {};
496
- targets[0].blend.color.dstTarget = value;
497
- },
498
-
499
- blendAlphaOperation: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
500
- addColorState(descriptor);
501
- targets[0].blend = targets[0].blend || {};
502
- targets[0].blend.alpha = targets[0].blend.alpha || {};
503
- targets[0].blend.alpha.operation = value;
504
- },
505
-
506
- blendAlphaSrcTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
507
- addColorState(descriptor);
508
- targets[0].blend = targets[0].blend || {};
509
- targets[0].blend.alpha = targets[0].blend.alpha || {};
510
- targets[0].blend.alpha.srcTarget = value;
511
- },
512
-
513
- blendAlphaDstTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
514
- addColorState(descriptor);
515
- targets[0].blend = targets[0].blend || {};
516
- targets[0].blend.alpha = targets[0].blend.alpha || {};
517
- targets[0].blend.alpha.dstTarget = value;
518
- },
519
- */
520
- };
521
- var DEFAULT_PIPELINE_DESCRIPTOR = {
522
- // depthStencil: {
523
- // stencilFront: {},
524
- // stencilBack: {},
525
- // // depthWriteEnabled: true,
526
- // // depthCompare: 'less',
527
- // // format: 'depth24plus-stencil8',
528
- // },
529
- primitive: {
530
- cullMode: "back",
531
- topology: "triangle-list"
532
- },
533
- vertex: {
534
- module: void 0,
535
- entryPoint: "main"
536
- },
537
- fragment: {
538
- module: void 0,
539
- entryPoint: "main",
540
- targets: [
541
- // { format: props.color0Format || 'bgra8unorm' }
542
- ]
543
- },
544
- layout: "auto"
545
- };
546
432
  function applyParametersToRenderPipelineDescriptor(pipelineDescriptor, parameters = {}) {
547
433
  Object.assign(pipelineDescriptor, { ...DEFAULT_PIPELINE_DESCRIPTOR, ...pipelineDescriptor });
548
434
  setParameters(pipelineDescriptor, parameters);
@@ -556,7 +442,7 @@ function setParameters(pipelineDescriptor, parameters) {
556
442
  setterFunction(key, value, pipelineDescriptor);
557
443
  }
558
444
  }
559
- function addColorState(descriptor) {
445
+ function addColorState(descriptor, attachment) {
560
446
  var _a, _b, _c, _d, _e, _f;
561
447
  descriptor.fragment.targets = ((_a = descriptor.fragment) == null ? void 0 : _a.targets) || [];
562
448
  if (!Array.isArray((_b = descriptor.fragment) == null ? void 0 : _b.targets)) {
@@ -565,17 +451,182 @@ function addColorState(descriptor) {
565
451
  if (((_d = (_c = descriptor.fragment) == null ? void 0 : _c.targets) == null ? void 0 : _d.length) === 0) {
566
452
  (_e = descriptor.fragment.targets) == null ? void 0 : _e.push({});
567
453
  }
568
- return (_f = descriptor.fragment) == null ? void 0 : _f.targets;
454
+ return (_f = descriptor.fragment) == null ? void 0 : _f.targets[0];
569
455
  }
456
+ function addBlendState(descriptor, attachment) {
457
+ const target = addColorState(descriptor, attachment);
458
+ target.blend = target.blend || { color: {}, alpha: {} };
459
+ return target.blend;
460
+ }
461
+ var PARAMETER_TABLE, DEFAULT_PIPELINE_DESCRIPTOR;
462
+ var init_webgpu_parameters = __esm({
463
+ "dist/adapter/helpers/webgpu-parameters.js"() {
464
+ "use strict";
465
+ PARAMETER_TABLE = {
466
+ // RASTERIZATION PARAMETERS
467
+ cullMode: (_, value, descriptor) => {
468
+ descriptor.primitive = descriptor.primitive || {};
469
+ descriptor.primitive.cullMode = value;
470
+ },
471
+ frontFace: (_, value, descriptor) => {
472
+ descriptor.primitive = descriptor.primitive || {};
473
+ descriptor.primitive.frontFace = value;
474
+ },
475
+ // DEPTH
476
+ depthWriteEnabled: (_, value, descriptor) => {
477
+ if (value) {
478
+ const depthStencil = addDepthStencil(descriptor);
479
+ depthStencil.depthWriteEnabled = value;
480
+ }
481
+ },
482
+ depthCompare: (_, value, descriptor) => {
483
+ const depthStencil = addDepthStencil(descriptor);
484
+ depthStencil.depthCompare = value;
485
+ },
486
+ depthFormat: (_, value, descriptor) => {
487
+ const depthStencil = addDepthStencil(descriptor);
488
+ depthStencil.format = value;
489
+ },
490
+ depthBias: (_, value, descriptor) => {
491
+ const depthStencil = addDepthStencil(descriptor);
492
+ depthStencil.depthBias = value;
493
+ },
494
+ depthBiasSlopeScale: (_, value, descriptor) => {
495
+ const depthStencil = addDepthStencil(descriptor);
496
+ depthStencil.depthBiasSlopeScale = value;
497
+ },
498
+ depthBiasClamp: (_, value, descriptor) => {
499
+ const depthStencil = addDepthStencil(descriptor);
500
+ depthStencil.depthBiasClamp = value;
501
+ },
502
+ // STENCIL
503
+ stencilReadMask: (_, value, descriptor) => {
504
+ const depthStencil = addDepthStencil(descriptor);
505
+ depthStencil.stencilReadMask = value;
506
+ },
507
+ stencilWriteMask: (_, value, descriptor) => {
508
+ const depthStencil = addDepthStencil(descriptor);
509
+ depthStencil.stencilWriteMask = value;
510
+ },
511
+ stencilCompare: (_, value, descriptor) => {
512
+ const stencilFront = addDepthStencilFront(descriptor);
513
+ const stencilBack = addDepthStencilBack(descriptor);
514
+ stencilFront.compare = value;
515
+ stencilBack.compare = value;
516
+ },
517
+ stencilPassOperation: (_, value, descriptor) => {
518
+ const stencilFront = addDepthStencilFront(descriptor);
519
+ const stencilBack = addDepthStencilBack(descriptor);
520
+ stencilFront.passOp = value;
521
+ stencilBack.passOp = value;
522
+ },
523
+ stencilFailOperation: (_, value, descriptor) => {
524
+ const stencilFront = addDepthStencilFront(descriptor);
525
+ const stencilBack = addDepthStencilBack(descriptor);
526
+ stencilFront.failOp = value;
527
+ stencilBack.failOp = value;
528
+ },
529
+ stencilDepthFailOperation: (_, value, descriptor) => {
530
+ const stencilFront = addDepthStencilFront(descriptor);
531
+ const stencilBack = addDepthStencilBack(descriptor);
532
+ stencilFront.depthFailOp = value;
533
+ stencilBack.depthFailOp = value;
534
+ },
535
+ // MULTISAMPLE
536
+ sampleCount: (_, value, descriptor) => {
537
+ descriptor.multisample = descriptor.multisample || {};
538
+ descriptor.multisample.count = value;
539
+ },
540
+ sampleMask: (_, value, descriptor) => {
541
+ descriptor.multisample = descriptor.multisample || {};
542
+ descriptor.multisample.mask = value;
543
+ },
544
+ sampleAlphaToCoverageEnabled: (_, value, descriptor) => {
545
+ descriptor.multisample = descriptor.multisample || {};
546
+ descriptor.multisample.alphaToCoverageEnabled = value;
547
+ },
548
+ // COLOR
549
+ colorMask: (_, value, descriptor) => {
550
+ const target = addColorState(descriptor, 0);
551
+ target.writeMask = value;
552
+ },
553
+ blend: (_, value, descriptor) => {
554
+ if (value) {
555
+ addBlendState(descriptor, 0);
556
+ }
557
+ },
558
+ blendColorOperation: (_, value, descriptor) => {
559
+ const blend = addBlendState(descriptor, 0);
560
+ blend.color = blend.color || {};
561
+ blend.color.operation = value;
562
+ },
563
+ blendColorSrcFactor: (_, value, descriptor) => {
564
+ const blend = addBlendState(descriptor, 0);
565
+ blend.color = blend.color || {};
566
+ blend.color.srcFactor = value;
567
+ },
568
+ blendColorDstFactor: (_, value, descriptor) => {
569
+ const blend = addBlendState(descriptor, 0);
570
+ blend.color.dstFactor = value;
571
+ },
572
+ blendAlphaOperation: (_, value, descriptor) => {
573
+ const blend = addBlendState(descriptor, 0);
574
+ blend.alpha = blend.alpha || {};
575
+ blend.alpha.operation = value;
576
+ },
577
+ blendAlphaSrcFactor: (_, value, descriptor) => {
578
+ const blend = addBlendState(descriptor, 0);
579
+ blend.alpha = blend.alpha || {};
580
+ blend.alpha.srcFactor = value;
581
+ },
582
+ blendAlphaDstFactor: (_, value, descriptor) => {
583
+ const blend = addBlendState(descriptor, 0);
584
+ blend.alpha = blend.alpha || {};
585
+ blend.alpha.dstFactor = value;
586
+ }
587
+ };
588
+ DEFAULT_PIPELINE_DESCRIPTOR = {
589
+ // depthStencil: {
590
+ // stencilFront: {},
591
+ // stencilBack: {},
592
+ // // depthWriteEnabled: true,
593
+ // // depthCompare: 'less',
594
+ // // format: 'depth24plus-stencil8',
595
+ // },
596
+ primitive: {
597
+ cullMode: "back",
598
+ topology: "triangle-list"
599
+ },
600
+ vertex: {
601
+ module: void 0,
602
+ entryPoint: "main"
603
+ },
604
+ fragment: {
605
+ module: void 0,
606
+ entryPoint: "main",
607
+ targets: [
608
+ // { format: props.color0Format || 'bgra8unorm' }
609
+ ]
610
+ },
611
+ layout: "auto"
612
+ };
613
+ }
614
+ });
570
615
 
571
616
  // dist/adapter/helpers/get-bind-group.js
572
- var import_core7 = require("@luma.gl/core");
573
617
  function getBindGroup(device, bindGroupLayout, shaderLayout, bindings) {
574
618
  const entries = getBindGroupEntries(bindings, shaderLayout);
575
- return device.createBindGroup({
619
+ device.pushErrorScope("validation");
620
+ const bindGroup = device.createBindGroup({
576
621
  layout: bindGroupLayout,
577
622
  entries
578
623
  });
624
+ device.popErrorScope().then((error) => {
625
+ if (error) {
626
+ import_core7.log.error(`createBindGroup validation failed: ${error.message}`)();
627
+ }
628
+ });
629
+ return bindGroup;
579
630
  }
580
631
  function getShaderLayoutBinding(shaderLayout, bindingName, options) {
581
632
  const bindingLayout = shaderLayout.bindings.find((binding) => binding.name === bindingName || `${binding.name}uniforms` === bindingName.toLocaleLowerCase());
@@ -589,13 +640,21 @@ function getBindGroupEntries(bindings, shaderLayout) {
589
640
  for (const [bindingName, value] of Object.entries(bindings)) {
590
641
  let bindingLayout = getShaderLayoutBinding(shaderLayout, bindingName);
591
642
  if (bindingLayout) {
592
- entries.push(getBindGroupEntry(value, bindingLayout.location));
643
+ const entry = getBindGroupEntry(value, bindingLayout.location);
644
+ if (entry) {
645
+ entries.push(entry);
646
+ }
593
647
  }
594
- bindingLayout = getShaderLayoutBinding(shaderLayout, `${bindingName}Sampler`, {
595
- ignoreWarnings: true
596
- });
597
- if (bindingLayout) {
598
- entries.push(getBindGroupEntry(value, bindingLayout.location, { sampler: true }));
648
+ if (value instanceof import_core7.Texture) {
649
+ bindingLayout = getShaderLayoutBinding(shaderLayout, `${bindingName}Sampler`, {
650
+ ignoreWarnings: true
651
+ });
652
+ if (bindingLayout) {
653
+ const entry = getBindGroupEntry(value, bindingLayout.location, { sampler: true });
654
+ if (entry) {
655
+ entries.push(entry);
656
+ }
657
+ }
599
658
  }
600
659
  }
601
660
  return entries;
@@ -614,7 +673,8 @@ function getBindGroupEntry(binding, index, options) {
614
673
  binding: index,
615
674
  resource: binding.handle
616
675
  };
617
- } else if (binding instanceof import_core7.Texture) {
676
+ }
677
+ if (binding instanceof import_core7.Texture) {
618
678
  if (options == null ? void 0 : options.sampler) {
619
679
  return {
620
680
  binding: index,
@@ -623,14 +683,21 @@ function getBindGroupEntry(binding, index, options) {
623
683
  }
624
684
  return {
625
685
  binding: index,
626
- resource: binding.handle.createView({ label: "bind-group-auto-created" })
686
+ resource: binding.view.handle
627
687
  };
628
688
  }
629
- throw new Error("invalid binding");
689
+ import_core7.log.warn(`invalid binding ${name}`, binding);
690
+ return null;
630
691
  }
692
+ var import_core7;
693
+ var init_get_bind_group = __esm({
694
+ "dist/adapter/helpers/get-bind-group.js"() {
695
+ "use strict";
696
+ import_core7 = require("@luma.gl/core");
697
+ }
698
+ });
631
699
 
632
700
  // dist/adapter/helpers/get-vertex-buffer-layout.js
633
- var import_core8 = require("@luma.gl/core");
634
701
  function getWebGPUVertexFormat(format) {
635
702
  if (format.endsWith("-webgl")) {
636
703
  throw new Error(`WebGPU does not support vertex format ${format}`);
@@ -656,14 +723,14 @@ function getVertexBufferLayout(shaderLayout, bufferLayout) {
656
723
  offset: attributeMapping.byteOffset,
657
724
  shaderLocation: location
658
725
  });
659
- byteStride += (0, import_core8.decodeVertexFormat)(format).byteLength;
726
+ byteStride += (0, import_core8.getVertexFormatInfo)(format).byteLength;
660
727
  }
661
728
  } else {
662
729
  const attributeLayout = findAttributeLayout(shaderLayout, mapping.name, usedAttributes);
663
730
  if (!attributeLayout) {
664
731
  continue;
665
732
  }
666
- byteStride = (0, import_core8.decodeVertexFormat)(format).byteLength;
733
+ byteStride = (0, import_core8.getVertexFormatInfo)(format).byteLength;
667
734
  stepMode = attributeLayout.stepMode || (attributeLayout.name.startsWith("instance") ? "instance" : "vertex");
668
735
  vertexAttributes.push({
669
736
  format: getWebGPUVertexFormat(format),
@@ -681,7 +748,7 @@ function getVertexBufferLayout(shaderLayout, bufferLayout) {
681
748
  for (const attribute of shaderLayout.attributes) {
682
749
  if (!usedAttributes.has(attribute.name)) {
683
750
  vertexBufferLayouts.push({
684
- arrayStride: (0, import_core8.decodeVertexFormat)("float32x3").byteLength,
751
+ arrayStride: (0, import_core8.getVertexFormatInfo)("float32x3").byteLength,
685
752
  stepMode: attribute.stepMode || (attribute.name.startsWith("instance") ? "instance" : "vertex"),
686
753
  attributes: [
687
754
  {
@@ -695,836 +762,1000 @@ function getVertexBufferLayout(shaderLayout, bufferLayout) {
695
762
  }
696
763
  return vertexBufferLayouts;
697
764
  }
698
- function findAttributeLayout(shaderLayout, name, attributeNames) {
699
- const attribute = shaderLayout.attributes.find((attribute_) => attribute_.name === name);
765
+ function findAttributeLayout(shaderLayout, name2, attributeNames) {
766
+ const attribute = shaderLayout.attributes.find((attribute_) => attribute_.name === name2);
700
767
  if (!attribute) {
701
- import_core8.log.warn(`Supplied attribute not present in shader layout: ${name}`)();
768
+ import_core8.log.warn(`Supplied attribute not present in shader layout: ${name2}`)();
702
769
  return null;
703
770
  }
704
- if (attributeNames.has(name)) {
705
- throw new Error(`Found multiple entries for attribute: ${name}`);
771
+ if (attributeNames.has(name2)) {
772
+ throw new Error(`Found multiple entries for attribute: ${name2}`);
706
773
  }
707
- attributeNames.add(name);
774
+ attributeNames.add(name2);
708
775
  return attribute;
709
776
  }
777
+ var import_core8;
778
+ var init_get_vertex_buffer_layout = __esm({
779
+ "dist/adapter/helpers/get-vertex-buffer-layout.js"() {
780
+ "use strict";
781
+ import_core8 = require("@luma.gl/core");
782
+ }
783
+ });
710
784
 
711
785
  // dist/adapter/resources/webgpu-render-pipeline.js
712
- var WebGPURenderPipeline = class extends import_core9.RenderPipeline {
713
- device;
714
- handle;
715
- vs;
716
- fs = null;
717
- /** For internal use to create BindGroups */
718
- _bindings;
719
- _bindGroupLayout = null;
720
- _bindGroup = null;
721
- get [Symbol.toStringTag]() {
722
- return "WebGPURenderPipeline";
723
- }
724
- constructor(device, props) {
725
- super(device, props);
726
- this.device = device;
727
- this.handle = this.props.handle;
728
- if (!this.handle) {
729
- const descriptor = this._getRenderPipelineDescriptor();
730
- import_core9.log.groupCollapsed(1, `new WebGPURenderPipeline(${this.id})`)();
731
- import_core9.log.probe(1, JSON.stringify(descriptor, null, 2))();
732
- import_core9.log.groupEnd(1)();
733
- this.device.handle.pushErrorScope("validation");
734
- this.handle = this.device.handle.createRenderPipeline(descriptor);
735
- this.device.handle.popErrorScope().then((error) => {
736
- var _a;
737
- if (error) {
738
- import_core9.log.error(`${this} creation failed:
786
+ var import_core9, WebGPURenderPipeline;
787
+ var init_webgpu_render_pipeline = __esm({
788
+ "dist/adapter/resources/webgpu-render-pipeline.js"() {
789
+ "use strict";
790
+ import_core9 = require("@luma.gl/core");
791
+ init_webgpu_parameters();
792
+ init_convert_texture_format();
793
+ init_get_bind_group();
794
+ init_get_vertex_buffer_layout();
795
+ WebGPURenderPipeline = class extends import_core9.RenderPipeline {
796
+ device;
797
+ handle;
798
+ vs;
799
+ fs = null;
800
+ /** For internal use to create BindGroups */
801
+ _bindings;
802
+ _bindGroupLayout = null;
803
+ _bindGroup = null;
804
+ get [Symbol.toStringTag]() {
805
+ return "WebGPURenderPipeline";
806
+ }
807
+ constructor(device, props) {
808
+ super(device, props);
809
+ this.device = device;
810
+ this.handle = this.props.handle;
811
+ if (!this.handle) {
812
+ const descriptor = this._getRenderPipelineDescriptor();
813
+ import_core9.log.groupCollapsed(1, `new WebGPURenderPipeline(${this.id})`)();
814
+ import_core9.log.probe(1, JSON.stringify(descriptor, null, 2))();
815
+ import_core9.log.groupEnd(1)();
816
+ this.device.handle.pushErrorScope("validation");
817
+ this.handle = this.device.handle.createRenderPipeline(descriptor);
818
+ this.device.handle.popErrorScope().then((error) => {
819
+ var _a;
820
+ if (error) {
821
+ import_core9.log.error(`${this} creation failed:
739
822
  "${error.message}"`, this, (_a = this.props.vs) == null ? void 0 : _a.source)();
823
+ }
824
+ });
740
825
  }
741
- });
742
- }
743
- this.handle.label = this.props.id;
744
- this.vs = props.vs;
745
- this.fs = props.fs;
746
- this._bindings = { ...this.props.bindings };
747
- }
748
- destroy() {
749
- this.handle = null;
750
- }
751
- /**
752
- * @todo Use renderpass.setBindings() ?
753
- * @todo Do we want to expose BindGroups in the API and remove this?
754
- */
755
- setBindings(bindings) {
756
- for (const [name, binding] of Object.entries(bindings)) {
757
- if (this._bindings[name] !== binding) {
758
- this._bindGroup = null;
826
+ this.handle.label = this.props.id;
827
+ this.vs = props.vs;
828
+ this.fs = props.fs;
829
+ this._bindings = { ...this.props.bindings };
759
830
  }
760
- }
761
- Object.assign(this._bindings, bindings);
762
- }
763
- /** @todo - should this be moved to renderpass? */
764
- draw(options) {
765
- const webgpuRenderPass = options.renderPass;
766
- this.device.handle.pushErrorScope("validation");
767
- webgpuRenderPass.handle.setPipeline(this.handle);
768
- this.device.handle.popErrorScope().then((error) => {
769
- if (error) {
770
- import_core9.log.error(`${this} setPipeline failed:
831
+ destroy() {
832
+ this.handle = null;
833
+ }
834
+ /**
835
+ * @todo Use renderpass.setBindings() ?
836
+ * @todo Do we want to expose BindGroups in the API and remove this?
837
+ */
838
+ setBindings(bindings) {
839
+ for (const [name2, binding] of Object.entries(bindings)) {
840
+ if (this._bindings[name2] !== binding) {
841
+ this._bindGroup = null;
842
+ }
843
+ }
844
+ Object.assign(this._bindings, bindings);
845
+ }
846
+ /** @todo - should this be moved to renderpass? */
847
+ draw(options) {
848
+ const webgpuRenderPass = options.renderPass;
849
+ this.device.handle.pushErrorScope("validation");
850
+ webgpuRenderPass.handle.setPipeline(this.handle);
851
+ this.device.handle.popErrorScope().then((error) => {
852
+ if (error) {
853
+ import_core9.log.error(`${this} setPipeline failed:
771
854
  "${error.message}"`, this)();
855
+ }
856
+ });
857
+ const bindGroup = this._getBindGroup();
858
+ if (bindGroup) {
859
+ webgpuRenderPass.handle.setBindGroup(0, bindGroup);
860
+ }
861
+ options.vertexArray.bindBeforeRender(options.renderPass);
862
+ if (options.indexCount) {
863
+ webgpuRenderPass.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
864
+ } else {
865
+ webgpuRenderPass.handle.draw(
866
+ options.vertexCount || 0,
867
+ options.instanceCount || 1,
868
+ // If 0, nothing will be drawn
869
+ options.firstInstance
870
+ );
871
+ }
872
+ options.vertexArray.unbindAfterRender(options.renderPass);
873
+ return true;
772
874
  }
773
- });
774
- const bindGroup = this._getBindGroup();
775
- if (bindGroup) {
776
- webgpuRenderPass.handle.setBindGroup(0, bindGroup);
777
- }
778
- options.vertexArray.bindBeforeRender(options.renderPass);
779
- if (options.indexCount) {
780
- webgpuRenderPass.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
781
- } else {
782
- webgpuRenderPass.handle.draw(
783
- options.vertexCount || 0,
784
- options.instanceCount || 1,
785
- // If 0, nothing will be drawn
786
- options.firstInstance
787
- );
788
- }
789
- options.vertexArray.unbindAfterRender(options.renderPass);
790
- return true;
791
- }
792
- /** Return a bind group created by setBindings */
793
- _getBindGroup() {
794
- if (this.shaderLayout.bindings.length === 0) {
795
- return null;
796
- }
797
- this._bindGroupLayout = this._bindGroupLayout || this.handle.getBindGroupLayout(0);
798
- this._bindGroup = this._bindGroup || getBindGroup(this.device.handle, this._bindGroupLayout, this.shaderLayout, this._bindings);
799
- return this._bindGroup;
800
- }
801
- /**
802
- * Populate the complex WebGPU GPURenderPipelineDescriptor
803
- */
804
- _getRenderPipelineDescriptor() {
805
- const vertex = {
806
- module: this.props.vs.handle,
807
- entryPoint: this.props.vertexEntryPoint || "main",
808
- buffers: getVertexBufferLayout(this.shaderLayout, this.props.bufferLayout)
809
- };
810
- const targets = [];
811
- if (this.props.colorAttachmentFormats) {
812
- for (const format of this.props.colorAttachmentFormats) {
813
- targets.push(format ? { format: getWebGPUTextureFormat(format) } : null);
875
+ /** Return a bind group created by setBindings */
876
+ _getBindGroup() {
877
+ if (this.shaderLayout.bindings.length === 0) {
878
+ return null;
879
+ }
880
+ this._bindGroupLayout = this._bindGroupLayout || this.handle.getBindGroupLayout(0);
881
+ this._bindGroup = this._bindGroup || getBindGroup(this.device.handle, this._bindGroupLayout, this.shaderLayout, this._bindings);
882
+ return this._bindGroup;
883
+ }
884
+ /**
885
+ * Populate the complex WebGPU GPURenderPipelineDescriptor
886
+ */
887
+ _getRenderPipelineDescriptor() {
888
+ const vertex = {
889
+ module: this.props.vs.handle,
890
+ entryPoint: this.props.vertexEntryPoint || "main",
891
+ buffers: getVertexBufferLayout(this.shaderLayout, this.props.bufferLayout)
892
+ };
893
+ const targets = [];
894
+ if (this.props.colorAttachmentFormats) {
895
+ for (const format of this.props.colorAttachmentFormats) {
896
+ targets.push(format ? { format: getWebGPUTextureFormat(format) } : null);
897
+ }
898
+ } else {
899
+ targets.push({ format: getWebGPUTextureFormat(this.device.preferredColorFormat) });
900
+ }
901
+ const fragment = {
902
+ module: this.props.fs.handle,
903
+ entryPoint: this.props.fragmentEntryPoint || "main",
904
+ targets
905
+ };
906
+ const descriptor = {
907
+ vertex,
908
+ fragment,
909
+ primitive: {
910
+ topology: this.props.topology
911
+ },
912
+ layout: "auto"
913
+ };
914
+ const depthFormat = this.props.depthStencilAttachmentFormat || this.device.preferredDepthFormat;
915
+ if (this.props.parameters.depthWriteEnabled) {
916
+ descriptor.depthStencil = {
917
+ format: getWebGPUTextureFormat(depthFormat)
918
+ };
919
+ }
920
+ applyParametersToRenderPipelineDescriptor(descriptor, this.props.parameters);
921
+ return descriptor;
814
922
  }
815
- } else {
816
- targets.push({ format: getWebGPUTextureFormat(this.device.preferredColorFormat) });
817
- }
818
- const fragment = {
819
- module: this.props.fs.handle,
820
- entryPoint: this.props.fragmentEntryPoint || "main",
821
- targets
822
- };
823
- const descriptor = {
824
- vertex,
825
- fragment,
826
- primitive: {
827
- topology: this.props.topology
828
- },
829
- layout: "auto"
830
923
  };
831
- const depthFormat = this.props.depthStencilAttachmentFormat || this.device.preferredDepthFormat;
832
- if (this.props.parameters.depthWriteEnabled) {
833
- descriptor.depthStencil = {
834
- format: getWebGPUTextureFormat(depthFormat)
835
- };
836
- }
837
- applyParametersToRenderPipelineDescriptor(descriptor, this.props.parameters);
838
- return descriptor;
839
924
  }
840
- };
925
+ });
841
926
 
842
927
  // dist/adapter/resources/webgpu-framebuffer.js
843
- var import_core10 = require("@luma.gl/core");
844
- var WebGPUFramebuffer = class extends import_core10.Framebuffer {
845
- device;
846
- colorAttachments = [];
847
- depthStencilAttachment = null;
848
- constructor(device, props) {
849
- super(device, props);
850
- this.device = device;
851
- this.autoCreateAttachmentTextures();
852
- }
853
- updateAttachments() {
928
+ var import_core10, WebGPUFramebuffer;
929
+ var init_webgpu_framebuffer = __esm({
930
+ "dist/adapter/resources/webgpu-framebuffer.js"() {
931
+ "use strict";
932
+ import_core10 = require("@luma.gl/core");
933
+ WebGPUFramebuffer = class extends import_core10.Framebuffer {
934
+ device;
935
+ colorAttachments = [];
936
+ depthStencilAttachment = null;
937
+ constructor(device, props) {
938
+ super(device, props);
939
+ this.device = device;
940
+ this.autoCreateAttachmentTextures();
941
+ }
942
+ updateAttachments() {
943
+ }
944
+ };
854
945
  }
855
- };
946
+ });
856
947
 
857
948
  // dist/adapter/resources/webgpu-compute-pipeline.js
858
- var import_core11 = require("@luma.gl/core");
859
- var WebGPUComputePipeline = class extends import_core11.ComputePipeline {
860
- device;
861
- handle;
862
- /** For internal use to create BindGroups */
863
- _bindGroupLayout = null;
864
- _bindGroup = null;
865
- /** For internal use to create BindGroups */
866
- _bindings = {};
867
- constructor(device, props) {
868
- super(device, props);
869
- this.device = device;
870
- const webgpuShader = this.props.shader;
871
- this.handle = this.props.handle || this.device.handle.createComputePipeline({
872
- label: this.props.id,
873
- compute: {
874
- module: webgpuShader.handle,
875
- entryPoint: this.props.entryPoint,
876
- constants: this.props.constants
877
- },
878
- layout: "auto"
879
- });
949
+ var import_core11, WebGPUComputePipeline;
950
+ var init_webgpu_compute_pipeline = __esm({
951
+ "dist/adapter/resources/webgpu-compute-pipeline.js"() {
952
+ "use strict";
953
+ import_core11 = require("@luma.gl/core");
954
+ init_get_bind_group();
955
+ WebGPUComputePipeline = class extends import_core11.ComputePipeline {
956
+ device;
957
+ handle;
958
+ /** For internal use to create BindGroups */
959
+ _bindGroupLayout = null;
960
+ _bindGroup = null;
961
+ /** For internal use to create BindGroups */
962
+ _bindings = {};
963
+ constructor(device, props) {
964
+ super(device, props);
965
+ this.device = device;
966
+ const webgpuShader = this.props.shader;
967
+ this.handle = this.props.handle || this.device.handle.createComputePipeline({
968
+ label: this.props.id,
969
+ compute: {
970
+ module: webgpuShader.handle,
971
+ entryPoint: this.props.entryPoint,
972
+ constants: this.props.constants
973
+ },
974
+ layout: "auto"
975
+ });
976
+ }
977
+ /**
978
+ * @todo Use renderpass.setBindings() ?
979
+ * @todo Do we want to expose BindGroups in the API and remove this?
980
+ */
981
+ setBindings(bindings) {
982
+ Object.assign(this._bindings, bindings);
983
+ }
984
+ /** Return a bind group created by setBindings */
985
+ _getBindGroup() {
986
+ this._bindGroupLayout = this._bindGroupLayout || this.handle.getBindGroupLayout(0);
987
+ this._bindGroup = this._bindGroup || getBindGroup(this.device.handle, this._bindGroupLayout, this.shaderLayout, this._bindings);
988
+ return this._bindGroup;
989
+ }
990
+ };
880
991
  }
881
- /**
882
- * @todo Use renderpass.setBindings() ?
883
- * @todo Do we want to expose BindGroups in the API and remove this?
884
- */
885
- setBindings(bindings) {
886
- Object.assign(this._bindings, bindings);
992
+ });
993
+
994
+ // dist/adapter/resources/webgpu-vertex-array.js
995
+ var import_core12, import_env, WebGPUVertexArray;
996
+ var init_webgpu_vertex_array = __esm({
997
+ "dist/adapter/resources/webgpu-vertex-array.js"() {
998
+ "use strict";
999
+ import_core12 = require("@luma.gl/core");
1000
+ import_env = require("@probe.gl/env");
1001
+ WebGPUVertexArray = class extends import_core12.VertexArray {
1002
+ get [Symbol.toStringTag]() {
1003
+ return "WebGPUVertexArray";
1004
+ }
1005
+ device;
1006
+ /** Vertex Array is just a helper class under WebGPU */
1007
+ handle = null;
1008
+ // Create a VertexArray
1009
+ constructor(device, props) {
1010
+ super(device, props);
1011
+ this.device = device;
1012
+ }
1013
+ destroy() {
1014
+ }
1015
+ /**
1016
+ * Set an elements buffer, for indexed rendering.
1017
+ * Must be a Buffer bound to buffer with usage bit Buffer.INDEX set.
1018
+ */
1019
+ setIndexBuffer(buffer) {
1020
+ this.indexBuffer = buffer;
1021
+ }
1022
+ /** Set a bufferSlot in vertex attributes array to a buffer, enables the bufferSlot, sets divisor */
1023
+ setBuffer(bufferSlot, buffer) {
1024
+ this.attributes[bufferSlot] = buffer;
1025
+ }
1026
+ bindBeforeRender(renderPass, firstIndex, indexCount) {
1027
+ const webgpuRenderPass = renderPass;
1028
+ const webgpuIndexBuffer = this.indexBuffer;
1029
+ if (webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle) {
1030
+ import_core12.log.info(3, "setting index buffer", webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle, webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.indexType)();
1031
+ webgpuRenderPass.handle.setIndexBuffer(
1032
+ webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle,
1033
+ // @ts-expect-error TODO - we must enforce type
1034
+ webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.indexType
1035
+ );
1036
+ }
1037
+ for (let location = 0; location < this.maxVertexAttributes; location++) {
1038
+ const webgpuBuffer = this.attributes[location];
1039
+ if (webgpuBuffer == null ? void 0 : webgpuBuffer.handle) {
1040
+ import_core12.log.info(3, `setting vertex buffer ${location}`, webgpuBuffer == null ? void 0 : webgpuBuffer.handle)();
1041
+ webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer == null ? void 0 : webgpuBuffer.handle);
1042
+ }
1043
+ }
1044
+ }
1045
+ unbindAfterRender(renderPass) {
1046
+ }
1047
+ // DEPRECATED METHODS
1048
+ /**
1049
+ * @deprecated is this even an issue for WebGPU?
1050
+ * Attribute 0 can not be disable on most desktop OpenGL based browsers
1051
+ */
1052
+ static isConstantAttributeZeroSupported(device) {
1053
+ return (0, import_env.getBrowser)() === "Chrome";
1054
+ }
1055
+ };
887
1056
  }
888
- /** Return a bind group created by setBindings */
889
- _getBindGroup() {
890
- this._bindGroupLayout = this._bindGroupLayout || this.handle.getBindGroupLayout(0);
891
- this._bindGroup = this._bindGroup || getBindGroup(this.device.handle, this._bindGroupLayout, this.shaderLayout, this._bindings);
892
- return this._bindGroup;
1057
+ });
1058
+
1059
+ // dist/adapter/webgpu-canvas-context.js
1060
+ var import_core13, WebGPUCanvasContext;
1061
+ var init_webgpu_canvas_context = __esm({
1062
+ "dist/adapter/webgpu-canvas-context.js"() {
1063
+ "use strict";
1064
+ import_core13 = require("@luma.gl/core");
1065
+ init_webgpu_framebuffer();
1066
+ WebGPUCanvasContext = class extends import_core13.CanvasContext {
1067
+ device;
1068
+ handle;
1069
+ depthStencilAttachment = null;
1070
+ get [Symbol.toStringTag]() {
1071
+ return "WebGPUCanvasContext";
1072
+ }
1073
+ constructor(device, adapter, props) {
1074
+ super(props);
1075
+ const context = this.canvas.getContext("webgpu");
1076
+ if (!context) {
1077
+ throw new Error(`${this}: Failed to create WebGPU canvas context`);
1078
+ }
1079
+ this.device = device;
1080
+ this.handle = context;
1081
+ this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
1082
+ this._updateDevice();
1083
+ }
1084
+ /** Destroy any textures produced while configured and remove the context configuration. */
1085
+ destroy() {
1086
+ this.handle.unconfigure();
1087
+ }
1088
+ /** Update framebuffer with properly resized "swap chain" texture views */
1089
+ getCurrentFramebuffer(options = {
1090
+ depthStencilFormat: "depth24plus"
1091
+ }) {
1092
+ const currentColorAttachment = this.getCurrentTexture();
1093
+ if (currentColorAttachment.width !== this.drawingBufferWidth || currentColorAttachment.height !== this.drawingBufferHeight) {
1094
+ const [oldWidth, oldHeight] = this.getDrawingBufferSize();
1095
+ this.drawingBufferWidth = currentColorAttachment.width;
1096
+ this.drawingBufferHeight = currentColorAttachment.height;
1097
+ import_core13.log.log(1, `${this}: Resized to compensate for initial canvas size mismatch ${oldWidth}x${oldHeight} => ${this.drawingBufferWidth}x${this.drawingBufferHeight}px`)();
1098
+ }
1099
+ if (options == null ? void 0 : options.depthStencilFormat) {
1100
+ this._createDepthStencilAttachment(options == null ? void 0 : options.depthStencilFormat);
1101
+ }
1102
+ return new WebGPUFramebuffer(this.device, {
1103
+ colorAttachments: [currentColorAttachment],
1104
+ depthStencilAttachment: this.depthStencilAttachment
1105
+ });
1106
+ }
1107
+ // IMPLEMENTATION OF ABSTRACT METHODS
1108
+ _updateDevice() {
1109
+ if (this.depthStencilAttachment) {
1110
+ this.depthStencilAttachment.destroy();
1111
+ this.depthStencilAttachment = null;
1112
+ }
1113
+ this.handle.configure({
1114
+ device: this.device.handle,
1115
+ format: this.device.preferredColorFormat,
1116
+ // Can be used to define e.g. -srgb views
1117
+ // viewFormats: [...]
1118
+ colorSpace: this.props.colorSpace,
1119
+ alphaMode: this.props.alphaMode
1120
+ });
1121
+ }
1122
+ /** Wrap the current canvas context texture in a luma.gl texture */
1123
+ getCurrentTexture() {
1124
+ const handle = this.handle.getCurrentTexture();
1125
+ return this.device.createTexture({
1126
+ id: `${this.id}#color-texture`,
1127
+ handle,
1128
+ format: this.device.preferredColorFormat,
1129
+ width: handle.width,
1130
+ height: handle.height
1131
+ });
1132
+ }
1133
+ /** We build render targets on demand (i.e. not when size changes but when about to render) */
1134
+ _createDepthStencilAttachment(depthStencilFormat) {
1135
+ if (!this.depthStencilAttachment) {
1136
+ this.depthStencilAttachment = this.device.createTexture({
1137
+ id: `${this.id}#depth-stencil-texture`,
1138
+ usage: import_core13.Texture.RENDER_ATTACHMENT,
1139
+ format: depthStencilFormat,
1140
+ width: this.drawingBufferWidth,
1141
+ height: this.drawingBufferHeight
1142
+ });
1143
+ }
1144
+ return this.depthStencilAttachment;
1145
+ }
1146
+ };
893
1147
  }
894
- };
1148
+ });
1149
+
1150
+ // dist/adapter/resources/webgpu-command-buffer.js
1151
+ var import_core14, WebGPUCommandBuffer;
1152
+ var init_webgpu_command_buffer = __esm({
1153
+ "dist/adapter/resources/webgpu-command-buffer.js"() {
1154
+ "use strict";
1155
+ import_core14 = require("@luma.gl/core");
1156
+ WebGPUCommandBuffer = class extends import_core14.CommandBuffer {
1157
+ device;
1158
+ handle;
1159
+ constructor(commandEncoder, props) {
1160
+ super(commandEncoder.device, {});
1161
+ this.device = commandEncoder.device;
1162
+ this.handle = this.props.handle || commandEncoder.handle.finish({
1163
+ label: (props == null ? void 0 : props.id) || "unnamed-command-buffer"
1164
+ });
1165
+ }
1166
+ };
1167
+ }
1168
+ });
895
1169
 
896
1170
  // dist/adapter/resources/webgpu-render-pass.js
897
- var import_core12 = require("@luma.gl/core");
898
- var WebGPURenderPass = class extends import_core12.RenderPass {
899
- device;
900
- handle;
901
- /** Active pipeline */
902
- pipeline = null;
903
- constructor(device, props = {}) {
904
- super(device, props);
905
- this.device = device;
906
- const framebuffer = props.framebuffer || device.getCanvasContext().getCurrentFramebuffer();
907
- const renderPassDescriptor = this.getRenderPassDescriptor(framebuffer);
908
- const webgpuQuerySet = props.timestampQuerySet;
909
- if (webgpuQuerySet) {
910
- renderPassDescriptor.occlusionQuerySet = webgpuQuerySet.handle;
911
- }
912
- if (device.features.has("timestamp-query")) {
913
- const webgpuTSQuerySet = props.timestampQuerySet;
914
- renderPassDescriptor.timestampWrites = webgpuTSQuerySet ? {
915
- querySet: webgpuTSQuerySet.handle,
916
- beginningOfPassWriteIndex: props.beginTimestampIndex,
917
- endOfPassWriteIndex: props.endTimestampIndex
918
- } : void 0;
919
- }
920
- if (!device.commandEncoder) {
921
- throw new Error("commandEncoder not available");
922
- }
923
- this.device.handle.pushErrorScope("validation");
924
- this.handle = this.props.handle || device.commandEncoder.beginRenderPass(renderPassDescriptor);
925
- this.device.handle.popErrorScope().then((error) => {
926
- if (error) {
927
- import_core12.log.error(`${this} creation failed:
1171
+ var import_core15, WebGPURenderPass;
1172
+ var init_webgpu_render_pass = __esm({
1173
+ "dist/adapter/resources/webgpu-render-pass.js"() {
1174
+ "use strict";
1175
+ import_core15 = require("@luma.gl/core");
1176
+ WebGPURenderPass = class extends import_core15.RenderPass {
1177
+ device;
1178
+ handle;
1179
+ /** Active pipeline */
1180
+ pipeline = null;
1181
+ constructor(device, props = {}) {
1182
+ super(device, props);
1183
+ this.device = device;
1184
+ const framebuffer = props.framebuffer || device.getCanvasContext().getCurrentFramebuffer();
1185
+ const renderPassDescriptor = this.getRenderPassDescriptor(framebuffer);
1186
+ const webgpuQuerySet = props.timestampQuerySet;
1187
+ if (webgpuQuerySet) {
1188
+ renderPassDescriptor.occlusionQuerySet = webgpuQuerySet.handle;
1189
+ }
1190
+ if (device.features.has("timestamp-query")) {
1191
+ const webgpuTSQuerySet = props.timestampQuerySet;
1192
+ renderPassDescriptor.timestampWrites = webgpuTSQuerySet ? {
1193
+ querySet: webgpuTSQuerySet.handle,
1194
+ beginningOfPassWriteIndex: props.beginTimestampIndex,
1195
+ endOfPassWriteIndex: props.endTimestampIndex
1196
+ } : void 0;
1197
+ }
1198
+ if (!device.commandEncoder) {
1199
+ throw new Error("commandEncoder not available");
1200
+ }
1201
+ this.device.handle.pushErrorScope("validation");
1202
+ this.handle = this.props.handle || device.commandEncoder.handle.beginRenderPass(renderPassDescriptor);
1203
+ this.device.handle.popErrorScope().then((error) => {
1204
+ if (error) {
1205
+ import_core15.log.error(`${this} creation failed:
928
1206
  "${error.message}"`, this)();
1207
+ }
1208
+ });
1209
+ this.handle.label = this.props.id;
1210
+ import_core15.log.groupCollapsed(3, `new WebGPURenderPass(${this.id})`)();
1211
+ import_core15.log.probe(3, JSON.stringify(renderPassDescriptor, null, 2))();
1212
+ import_core15.log.groupEnd(3)();
929
1213
  }
930
- });
931
- this.handle.label = this.props.id;
932
- import_core12.log.groupCollapsed(3, `new WebGPURenderPass(${this.id})`)();
933
- import_core12.log.probe(3, JSON.stringify(renderPassDescriptor, null, 2))();
934
- import_core12.log.groupEnd(3)();
935
- }
936
- destroy() {
937
- }
938
- end() {
939
- this.handle.end();
940
- }
941
- setPipeline(pipeline) {
942
- this.pipeline = pipeline;
943
- this.handle.setPipeline(this.pipeline.handle);
944
- }
945
- /** Sets an array of bindings (uniform buffers, samplers, textures, ...) */
946
- setBindings(bindings) {
947
- var _a, _b;
948
- (_a = this.pipeline) == null ? void 0 : _a.setBindings(bindings);
949
- const bindGroup = (_b = this.pipeline) == null ? void 0 : _b._getBindGroup();
950
- if (bindGroup) {
951
- this.handle.setBindGroup(0, bindGroup);
952
- }
953
- }
954
- setIndexBuffer(buffer, indexFormat, offset = 0, size) {
955
- this.handle.setIndexBuffer(buffer.handle, indexFormat, offset, size);
956
- }
957
- setVertexBuffer(slot, buffer, offset = 0) {
958
- this.handle.setVertexBuffer(slot, buffer.handle, offset);
959
- }
960
- draw(options) {
961
- if (options.indexCount) {
962
- this.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
963
- } else {
964
- this.handle.draw(options.vertexCount || 0, options.instanceCount || 1, options.firstIndex, options.firstInstance);
965
- }
966
- }
967
- drawIndirect() {
968
- }
969
- setParameters(parameters) {
970
- const { blendConstant, stencilReference, scissorRect, viewport } = parameters;
971
- if (blendConstant) {
972
- this.handle.setBlendConstant(blendConstant);
973
- }
974
- if (stencilReference) {
975
- this.handle.setStencilReference(stencilReference);
976
- }
977
- if (scissorRect) {
978
- this.handle.setScissorRect(scissorRect[0], scissorRect[1], scissorRect[2], scissorRect[3]);
979
- }
980
- if (viewport) {
981
- this.handle.setViewport(viewport[0], viewport[1], viewport[2], viewport[3], viewport[4], viewport[5]);
982
- }
983
- }
984
- pushDebugGroup(groupLabel) {
985
- this.handle.pushDebugGroup(groupLabel);
986
- }
987
- popDebugGroup() {
988
- this.handle.popDebugGroup();
989
- }
990
- insertDebugMarker(markerLabel) {
991
- this.handle.insertDebugMarker(markerLabel);
992
- }
993
- beginOcclusionQuery(queryIndex) {
994
- this.handle.beginOcclusionQuery(queryIndex);
995
- }
996
- endOcclusionQuery() {
997
- this.handle.endOcclusionQuery();
998
- }
999
- // executeBundles(bundles: Iterable<GPURenderBundle>): void;
1000
- // INTERNAL
1001
- /**
1002
- * Partial render pass descriptor. Used by WebGPURenderPass.
1003
- * @returns attachments fields of a renderpass descriptor.
1004
- */
1005
- getRenderPassDescriptor(framebuffer) {
1006
- const renderPassDescriptor = {
1007
- colorAttachments: []
1008
- };
1009
- renderPassDescriptor.colorAttachments = framebuffer.colorAttachments.map((colorAttachment, index) => {
1010
- var _a;
1011
- return {
1012
- // clear values
1013
- loadOp: this.props.clearColor !== false ? "clear" : "load",
1014
- colorClearValue: ((_a = this.props.clearColors) == null ? void 0 : _a[index]) || this.props.clearColor || import_core12.RenderPass.defaultClearColor,
1015
- storeOp: this.props.discard ? "discard" : "store",
1016
- // ...colorAttachment,
1017
- view: colorAttachment.handle
1018
- };
1019
- });
1020
- if (framebuffer.depthStencilAttachment) {
1021
- renderPassDescriptor.depthStencilAttachment = {
1022
- view: framebuffer.depthStencilAttachment.handle
1023
- };
1024
- const { depthStencilAttachment } = renderPassDescriptor;
1025
- if (this.props.depthReadOnly) {
1026
- depthStencilAttachment.depthReadOnly = true;
1214
+ destroy() {
1027
1215
  }
1028
- if (this.props.clearDepth !== false) {
1029
- depthStencilAttachment.depthClearValue = this.props.clearDepth;
1216
+ end() {
1217
+ this.handle.end();
1030
1218
  }
1031
- const hasDepthAspect = true;
1032
- if (hasDepthAspect) {
1033
- depthStencilAttachment.depthLoadOp = this.props.clearDepth !== false ? "clear" : "load";
1034
- depthStencilAttachment.depthStoreOp = "store";
1219
+ setPipeline(pipeline) {
1220
+ this.pipeline = pipeline;
1221
+ this.handle.setPipeline(this.pipeline.handle);
1035
1222
  }
1036
- const hasStencilAspect = false;
1037
- if (hasStencilAspect) {
1038
- depthStencilAttachment.stencilLoadOp = this.props.clearStencil !== false ? "clear" : "load";
1039
- depthStencilAttachment.stencilStoreOp = "store";
1223
+ /** Sets an array of bindings (uniform buffers, samplers, textures, ...) */
1224
+ setBindings(bindings) {
1225
+ var _a, _b;
1226
+ (_a = this.pipeline) == null ? void 0 : _a.setBindings(bindings);
1227
+ const bindGroup = (_b = this.pipeline) == null ? void 0 : _b._getBindGroup();
1228
+ if (bindGroup) {
1229
+ this.handle.setBindGroup(0, bindGroup);
1230
+ }
1040
1231
  }
1041
- }
1042
- return renderPassDescriptor;
1043
- }
1044
- };
1045
-
1046
- // dist/adapter/resources/webgpu-compute-pass.js
1047
- var import_core13 = require("@luma.gl/core");
1048
- var WebGPUComputePass = class extends import_core13.ComputePass {
1049
- device;
1050
- handle;
1051
- _webgpuPipeline = null;
1052
- constructor(device, props) {
1053
- var _a;
1054
- super(device, props);
1055
- this.device = device;
1056
- let timestampWrites;
1057
- if (device.features.has("timestamp-query")) {
1058
- const webgpuQuerySet = props.timestampQuerySet;
1059
- if (webgpuQuerySet) {
1060
- timestampWrites = {
1061
- querySet: webgpuQuerySet.handle,
1062
- beginningOfPassWriteIndex: props.beginTimestampIndex,
1063
- endOfPassWriteIndex: props.endTimestampIndex
1232
+ setIndexBuffer(buffer, indexFormat, offset = 0, size) {
1233
+ this.handle.setIndexBuffer(buffer.handle, indexFormat, offset, size);
1234
+ }
1235
+ setVertexBuffer(slot, buffer, offset = 0) {
1236
+ this.handle.setVertexBuffer(slot, buffer.handle, offset);
1237
+ }
1238
+ draw(options) {
1239
+ if (options.indexCount) {
1240
+ this.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
1241
+ } else {
1242
+ this.handle.draw(options.vertexCount || 0, options.instanceCount || 1, options.firstIndex, options.firstInstance);
1243
+ }
1244
+ }
1245
+ drawIndirect() {
1246
+ }
1247
+ setParameters(parameters) {
1248
+ const { blendConstant, stencilReference, scissorRect, viewport } = parameters;
1249
+ if (blendConstant) {
1250
+ this.handle.setBlendConstant(blendConstant);
1251
+ }
1252
+ if (stencilReference) {
1253
+ this.handle.setStencilReference(stencilReference);
1254
+ }
1255
+ if (scissorRect) {
1256
+ this.handle.setScissorRect(scissorRect[0], scissorRect[1], scissorRect[2], scissorRect[3]);
1257
+ }
1258
+ if (viewport) {
1259
+ this.handle.setViewport(viewport[0], viewport[1], viewport[2], viewport[3], viewport[4], viewport[5]);
1260
+ }
1261
+ }
1262
+ pushDebugGroup(groupLabel) {
1263
+ this.handle.pushDebugGroup(groupLabel);
1264
+ }
1265
+ popDebugGroup() {
1266
+ this.handle.popDebugGroup();
1267
+ }
1268
+ insertDebugMarker(markerLabel) {
1269
+ this.handle.insertDebugMarker(markerLabel);
1270
+ }
1271
+ beginOcclusionQuery(queryIndex) {
1272
+ this.handle.beginOcclusionQuery(queryIndex);
1273
+ }
1274
+ endOcclusionQuery() {
1275
+ this.handle.endOcclusionQuery();
1276
+ }
1277
+ // executeBundles(bundles: Iterable<GPURenderBundle>): void;
1278
+ // INTERNAL
1279
+ /**
1280
+ * Partial render pass descriptor. Used by WebGPURenderPass.
1281
+ * @returns attachments fields of a renderpass descriptor.
1282
+ */
1283
+ getRenderPassDescriptor(framebuffer) {
1284
+ const renderPassDescriptor = {
1285
+ colorAttachments: []
1064
1286
  };
1287
+ renderPassDescriptor.colorAttachments = framebuffer.colorAttachments.map((colorAttachment, index) => {
1288
+ var _a;
1289
+ return {
1290
+ // clear values
1291
+ loadOp: this.props.clearColor !== false ? "clear" : "load",
1292
+ colorClearValue: ((_a = this.props.clearColors) == null ? void 0 : _a[index]) || this.props.clearColor || import_core15.RenderPass.defaultClearColor,
1293
+ storeOp: this.props.discard ? "discard" : "store",
1294
+ // ...colorAttachment,
1295
+ view: colorAttachment.handle
1296
+ };
1297
+ });
1298
+ if (framebuffer.depthStencilAttachment) {
1299
+ renderPassDescriptor.depthStencilAttachment = {
1300
+ view: framebuffer.depthStencilAttachment.handle
1301
+ };
1302
+ const { depthStencilAttachment } = renderPassDescriptor;
1303
+ if (this.props.depthReadOnly) {
1304
+ depthStencilAttachment.depthReadOnly = true;
1305
+ }
1306
+ if (this.props.clearDepth !== false) {
1307
+ depthStencilAttachment.depthClearValue = this.props.clearDepth;
1308
+ }
1309
+ const hasDepthAspect = true;
1310
+ if (hasDepthAspect) {
1311
+ depthStencilAttachment.depthLoadOp = this.props.clearDepth !== false ? "clear" : "load";
1312
+ depthStencilAttachment.depthStoreOp = "store";
1313
+ }
1314
+ const hasStencilAspect = false;
1315
+ if (hasStencilAspect) {
1316
+ depthStencilAttachment.stencilLoadOp = this.props.clearStencil !== false ? "clear" : "load";
1317
+ depthStencilAttachment.stencilStoreOp = "store";
1318
+ }
1319
+ }
1320
+ return renderPassDescriptor;
1065
1321
  }
1066
- }
1067
- this.handle = this.props.handle || ((_a = device.commandEncoder) == null ? void 0 : _a.beginComputePass({
1068
- label: this.props.id,
1069
- timestampWrites
1070
- }));
1071
- }
1072
- /** @note no WebGPU destroy method, just gc */
1073
- destroy() {
1074
- }
1075
- end() {
1076
- this.handle.end();
1077
- }
1078
- setPipeline(pipeline) {
1079
- const wgpuPipeline = pipeline;
1080
- this.handle.setPipeline(wgpuPipeline.handle);
1081
- this._webgpuPipeline = wgpuPipeline;
1082
- this.setBindings([]);
1083
- }
1084
- /**
1085
- * Sets an array of bindings (uniform buffers, samplers, textures, ...)
1086
- * TODO - still some API confusion - does this method go here or on the pipeline?
1087
- */
1088
- setBindings(bindings) {
1089
- const bindGroup = this._webgpuPipeline._getBindGroup();
1090
- this.handle.setBindGroup(0, bindGroup);
1091
- }
1092
- /**
1093
- * Dispatch work to be performed with the current ComputePipeline.
1094
- * @param x X dimension of the grid of work groups to dispatch.
1095
- * @param y Y dimension of the grid of work groups to dispatch.
1096
- * @param z Z dimension of the grid of work groups to dispatch.
1097
- */
1098
- dispatch(x, y, z) {
1099
- this.handle.dispatchWorkgroups(x, y, z);
1100
- }
1101
- /**
1102
- * Dispatch work to be performed with the current ComputePipeline.
1103
- *
1104
- * Buffer must be a tightly packed block of three 32-bit unsigned integer values (12 bytes total), given in the same order as the arguments for dispatch()
1105
- * @param indirectBuffer
1106
- * @param indirectOffset offset in buffer to the beginning of the dispatch data.
1107
- */
1108
- dispatchIndirect(indirectBuffer, indirectByteOffset = 0) {
1109
- const webgpuBuffer = indirectBuffer;
1110
- this.handle.dispatchWorkgroupsIndirect(webgpuBuffer.handle, indirectByteOffset);
1111
- }
1112
- pushDebugGroup(groupLabel) {
1113
- this.handle.pushDebugGroup(groupLabel);
1114
- }
1115
- popDebugGroup() {
1116
- this.handle.popDebugGroup();
1117
- }
1118
- insertDebugMarker(markerLabel) {
1119
- this.handle.insertDebugMarker(markerLabel);
1322
+ };
1120
1323
  }
1121
- };
1324
+ });
1122
1325
 
1123
- // dist/adapter/resources/webgpu-vertex-array.js
1124
- var import_core14 = require("@luma.gl/core");
1125
- var import_env = require("@probe.gl/env");
1126
- var WebGPUVertexArray = class extends import_core14.VertexArray {
1127
- get [Symbol.toStringTag]() {
1128
- return "WebGPUVertexArray";
1129
- }
1130
- device;
1131
- /** Vertex Array is a helper class under WebGPU */
1132
- handle;
1133
- // Create a VertexArray
1134
- constructor(device, props) {
1135
- super(device, props);
1136
- this.device = device;
1137
- }
1138
- destroy() {
1139
- }
1140
- /**
1141
- * Set an elements buffer, for indexed rendering.
1142
- * Must be a Buffer bound to buffer with usage bit Buffer.INDEX set.
1143
- */
1144
- setIndexBuffer(buffer) {
1145
- this.indexBuffer = buffer;
1146
- }
1147
- /** Set a bufferSlot in vertex attributes array to a buffer, enables the bufferSlot, sets divisor */
1148
- setBuffer(bufferSlot, buffer) {
1149
- this.attributes[bufferSlot] = buffer;
1150
- }
1151
- bindBeforeRender(renderPass, firstIndex, indexCount) {
1152
- const webgpuRenderPass = renderPass;
1153
- const webgpuIndexBuffer = this.indexBuffer;
1154
- if (webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle) {
1155
- import_core14.log.info(3, "setting index buffer", webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle, webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.indexType)();
1156
- webgpuRenderPass.handle.setIndexBuffer(
1157
- webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle,
1158
- // @ts-expect-error TODO - we must enforce type
1159
- webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.indexType
1160
- );
1161
- }
1162
- for (let location = 0; location < this.maxVertexAttributes; location++) {
1163
- const webgpuBuffer = this.attributes[location];
1164
- if (webgpuBuffer == null ? void 0 : webgpuBuffer.handle) {
1165
- import_core14.log.info(3, `setting vertex buffer ${location}`, webgpuBuffer == null ? void 0 : webgpuBuffer.handle)();
1166
- webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer == null ? void 0 : webgpuBuffer.handle);
1326
+ // dist/adapter/resources/webgpu-compute-pass.js
1327
+ var import_core16, WebGPUComputePass;
1328
+ var init_webgpu_compute_pass = __esm({
1329
+ "dist/adapter/resources/webgpu-compute-pass.js"() {
1330
+ "use strict";
1331
+ import_core16 = require("@luma.gl/core");
1332
+ WebGPUComputePass = class extends import_core16.ComputePass {
1333
+ device;
1334
+ handle;
1335
+ _webgpuPipeline = null;
1336
+ constructor(device, props) {
1337
+ super(device, props);
1338
+ this.device = device;
1339
+ let timestampWrites;
1340
+ if (device.features.has("timestamp-query")) {
1341
+ const webgpuQuerySet = props.timestampQuerySet;
1342
+ if (webgpuQuerySet) {
1343
+ timestampWrites = {
1344
+ querySet: webgpuQuerySet.handle,
1345
+ beginningOfPassWriteIndex: props.beginTimestampIndex,
1346
+ endOfPassWriteIndex: props.endTimestampIndex
1347
+ };
1348
+ }
1349
+ }
1350
+ this.handle = this.props.handle || device.commandEncoder.handle.beginComputePass({
1351
+ label: this.props.id,
1352
+ timestampWrites
1353
+ });
1167
1354
  }
1168
- }
1169
- }
1170
- unbindAfterRender(renderPass) {
1171
- }
1172
- // DEPRECATED METHODS
1173
- /**
1174
- * @deprecated is this even an issue for WebGPU?
1175
- * Attribute 0 can not be disable on most desktop OpenGL based browsers
1176
- */
1177
- static isConstantAttributeZeroSupported(device) {
1178
- return (0, import_env.getBrowser)() === "Chrome";
1355
+ /** @note no WebGPU destroy method, just gc */
1356
+ destroy() {
1357
+ }
1358
+ end() {
1359
+ this.handle.end();
1360
+ }
1361
+ setPipeline(pipeline) {
1362
+ const wgpuPipeline = pipeline;
1363
+ this.handle.setPipeline(wgpuPipeline.handle);
1364
+ this._webgpuPipeline = wgpuPipeline;
1365
+ this.setBindings([]);
1366
+ }
1367
+ /**
1368
+ * Sets an array of bindings (uniform buffers, samplers, textures, ...)
1369
+ * TODO - still some API confusion - does this method go here or on the pipeline?
1370
+ */
1371
+ setBindings(bindings) {
1372
+ const bindGroup = this._webgpuPipeline._getBindGroup();
1373
+ this.handle.setBindGroup(0, bindGroup);
1374
+ }
1375
+ /**
1376
+ * Dispatch work to be performed with the current ComputePipeline.
1377
+ * @param x X dimension of the grid of work groups to dispatch.
1378
+ * @param y Y dimension of the grid of work groups to dispatch.
1379
+ * @param z Z dimension of the grid of work groups to dispatch.
1380
+ */
1381
+ dispatch(x, y, z) {
1382
+ this.handle.dispatchWorkgroups(x, y, z);
1383
+ }
1384
+ /**
1385
+ * Dispatch work to be performed with the current ComputePipeline.
1386
+ *
1387
+ * Buffer must be a tightly packed block of three 32-bit unsigned integer values (12 bytes total), given in the same order as the arguments for dispatch()
1388
+ * @param indirectBuffer
1389
+ * @param indirectOffset offset in buffer to the beginning of the dispatch data.
1390
+ */
1391
+ dispatchIndirect(indirectBuffer, indirectByteOffset = 0) {
1392
+ const webgpuBuffer = indirectBuffer;
1393
+ this.handle.dispatchWorkgroupsIndirect(webgpuBuffer.handle, indirectByteOffset);
1394
+ }
1395
+ pushDebugGroup(groupLabel) {
1396
+ this.handle.pushDebugGroup(groupLabel);
1397
+ }
1398
+ popDebugGroup() {
1399
+ this.handle.popDebugGroup();
1400
+ }
1401
+ insertDebugMarker(markerLabel) {
1402
+ this.handle.insertDebugMarker(markerLabel);
1403
+ }
1404
+ };
1179
1405
  }
1180
- };
1406
+ });
1181
1407
 
1182
- // dist/adapter/webgpu-canvas-context.js
1183
- var import_core15 = require("@luma.gl/core");
1184
- var WebGPUCanvasContext = class extends import_core15.CanvasContext {
1185
- device;
1186
- handle;
1187
- depthStencilAttachment = null;
1188
- get [Symbol.toStringTag]() {
1189
- return "WebGPUCanvasContext";
1190
- }
1191
- constructor(device, adapter, props) {
1192
- super(props);
1193
- this.device = device;
1194
- this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
1195
- this.updateSize([this.drawingBufferWidth, this.drawingBufferHeight]);
1196
- }
1197
- /** Destroy any textures produced while configured and remove the context configuration. */
1198
- destroy() {
1199
- this.handle.unconfigure();
1200
- }
1201
- /** Update framebuffer with properly resized "swap chain" texture views */
1202
- getCurrentFramebuffer(options = {
1203
- depthStencilFormat: "depth24plus"
1204
- }) {
1205
- const currentColorAttachment = this.getCurrentTexture();
1206
- if (currentColorAttachment.width !== this.drawingBufferWidth || currentColorAttachment.height !== this.drawingBufferHeight) {
1207
- const [oldWidth, oldHeight] = this.getDrawingBufferSize();
1208
- this.drawingBufferWidth = currentColorAttachment.width;
1209
- this.drawingBufferHeight = currentColorAttachment.height;
1210
- import_core15.log.log(1, `${this}: Resized to compensate for initial canvas size mismatch ${oldWidth}x${oldHeight} => ${this.drawingBufferWidth}x${this.drawingBufferHeight}px`)();
1211
- }
1212
- if (options == null ? void 0 : options.depthStencilFormat) {
1213
- this._createDepthStencilAttachment(options == null ? void 0 : options.depthStencilFormat);
1214
- }
1215
- return new WebGPUFramebuffer(this.device, {
1216
- colorAttachments: [currentColorAttachment],
1217
- depthStencilAttachment: this.depthStencilAttachment
1218
- });
1219
- }
1220
- /** Resizes and updates render targets if necessary */
1221
- updateSize(size) {
1222
- if (this.depthStencilAttachment) {
1223
- this.depthStencilAttachment.destroy();
1224
- this.depthStencilAttachment = null;
1225
- }
1226
- this.handle.configure({
1227
- device: this.device.handle,
1228
- format: this.device.preferredColorFormat,
1229
- // Can be used to define e.g. -srgb views
1230
- // viewFormats: [...]
1231
- colorSpace: this.props.colorSpace,
1232
- alphaMode: this.props.alphaMode
1233
- });
1234
- }
1235
- resize(options) {
1236
- if (!this.device.handle)
1237
- return;
1238
- if (this.props.autoResize) {
1239
- return;
1240
- }
1241
- if (this.canvas) {
1242
- const devicePixelRatio = this.getDevicePixelRatio(options == null ? void 0 : options.useDevicePixels);
1243
- this._setDevicePixelRatio(devicePixelRatio, options);
1244
- return;
1245
- }
1246
- }
1247
- /** Wrap the current canvas context texture in a luma.gl texture */
1248
- getCurrentTexture() {
1249
- return this.device.createTexture({
1250
- id: `${this.id}#color-texture`,
1251
- handle: this.handle.getCurrentTexture(),
1252
- format: this.device.preferredColorFormat
1253
- });
1254
- }
1255
- /** We build render targets on demand (i.e. not when size changes but when about to render) */
1256
- _createDepthStencilAttachment(depthStencilFormat) {
1257
- if (!this.depthStencilAttachment) {
1258
- this.depthStencilAttachment = this.device.createTexture({
1259
- id: `${this.id}#depth-stencil-texture`,
1260
- usage: import_core15.Texture.RENDER_ATTACHMENT,
1261
- format: depthStencilFormat,
1262
- width: this.drawingBufferWidth,
1263
- height: this.drawingBufferHeight
1264
- });
1265
- }
1266
- return this.depthStencilAttachment;
1408
+ // dist/adapter/resources/webgpu-command-encoder.js
1409
+ var import_core17, WebGPUCommandEncoder;
1410
+ var init_webgpu_command_encoder = __esm({
1411
+ "dist/adapter/resources/webgpu-command-encoder.js"() {
1412
+ "use strict";
1413
+ import_core17 = require("@luma.gl/core");
1414
+ init_webgpu_command_buffer();
1415
+ init_webgpu_render_pass();
1416
+ init_webgpu_compute_pass();
1417
+ WebGPUCommandEncoder = class extends import_core17.CommandEncoder {
1418
+ device;
1419
+ handle;
1420
+ constructor(device, props = {}) {
1421
+ super(device, props);
1422
+ this.device = device;
1423
+ this.handle = props.handle || this.device.handle.createCommandEncoder({
1424
+ label: this.props.id
1425
+ // TODO was this removed in standard?
1426
+ // measureExecutionTime: this.props.measureExecutionTime
1427
+ });
1428
+ this.handle.label = this.props.id;
1429
+ }
1430
+ destroy() {
1431
+ }
1432
+ finish(props) {
1433
+ return new WebGPUCommandBuffer(this, {
1434
+ id: (props == null ? void 0 : props.id) || "unnamed-command-buffer"
1435
+ });
1436
+ }
1437
+ /**
1438
+ * Allows a render pass to begin against a canvas context
1439
+ * @todo need to support a "Framebuffer" equivalent (aka preconfigured RenderPassDescriptors?).
1440
+ */
1441
+ beginRenderPass(props) {
1442
+ return new WebGPURenderPass(this.device, props);
1443
+ }
1444
+ beginComputePass(props) {
1445
+ return new WebGPUComputePass(this.device, props);
1446
+ }
1447
+ // beginRenderPass(GPURenderPassDescriptor descriptor): GPURenderPassEncoder;
1448
+ // beginComputePass(optional GPUComputePassDescriptor descriptor = {}): GPUComputePassEncoder;
1449
+ copyBufferToBuffer(options) {
1450
+ const webgpuSourceBuffer = options.sourceBuffer;
1451
+ const WebGPUDestinationBuffer = options.destinationBuffer;
1452
+ this.handle.copyBufferToBuffer(webgpuSourceBuffer.handle, options.sourceOffset ?? 0, WebGPUDestinationBuffer.handle, options.destinationOffset ?? 0, options.size ?? 0);
1453
+ }
1454
+ copyBufferToTexture(options) {
1455
+ var _a, _b, _c;
1456
+ const webgpuSourceBuffer = options.sourceBuffer;
1457
+ const WebGPUDestinationTexture = options.destinationTexture;
1458
+ this.handle.copyBufferToTexture({
1459
+ buffer: webgpuSourceBuffer.handle,
1460
+ offset: options.offset ?? 0,
1461
+ bytesPerRow: options.bytesPerRow,
1462
+ rowsPerImage: options.rowsPerImage
1463
+ }, {
1464
+ texture: WebGPUDestinationTexture.handle,
1465
+ mipLevel: options.mipLevel ?? 0,
1466
+ origin: options.origin ?? {}
1467
+ // aspect: options.aspect
1468
+ }, {
1469
+ // @ts-ignore
1470
+ width: (_a = options.extent) == null ? void 0 : _a[0],
1471
+ height: (_b = options.extent) == null ? void 0 : _b[1],
1472
+ depthOrArrayLayers: (_c = options.extent) == null ? void 0 : _c[2]
1473
+ });
1474
+ }
1475
+ copyTextureToBuffer(options) {
1476
+ }
1477
+ copyTextureToTexture(options) {
1478
+ }
1479
+ pushDebugGroup(groupLabel) {
1480
+ this.handle.pushDebugGroup(groupLabel);
1481
+ }
1482
+ popDebugGroup() {
1483
+ this.handle.popDebugGroup();
1484
+ }
1485
+ insertDebugMarker(markerLabel) {
1486
+ this.handle.insertDebugMarker(markerLabel);
1487
+ }
1488
+ resolveQuerySet(querySet, destination, options) {
1489
+ const webgpuQuerySet = querySet;
1490
+ const webgpuBuffer = destination;
1491
+ this.handle.resolveQuerySet(webgpuQuerySet.handle, (options == null ? void 0 : options.firstQuery) || 0, (options == null ? void 0 : options.queryCount) || querySet.props.count - ((options == null ? void 0 : options.firstQuery) || 0), webgpuBuffer.handle, (options == null ? void 0 : options.destinationOffset) || 0);
1492
+ }
1493
+ };
1267
1494
  }
1268
- };
1495
+ });
1269
1496
 
1270
1497
  // dist/adapter/resources/webgpu-query-set.js
1271
- var import_core16 = require("@luma.gl/core");
1272
- var WebGPUQuerySet = class extends import_core16.QuerySet {
1273
- device;
1274
- handle;
1275
- constructor(device, props) {
1276
- super(device, props);
1277
- this.device = device;
1278
- this.handle = this.props.handle || this.device.handle.createQuerySet({
1279
- type: this.props.type,
1280
- count: this.props.count
1281
- });
1282
- this.handle.label = this.props.id;
1283
- }
1284
- destroy() {
1285
- var _a;
1286
- (_a = this.handle) == null ? void 0 : _a.destroy();
1287
- this.handle = null;
1498
+ var import_core18, WebGPUQuerySet;
1499
+ var init_webgpu_query_set = __esm({
1500
+ "dist/adapter/resources/webgpu-query-set.js"() {
1501
+ "use strict";
1502
+ import_core18 = require("@luma.gl/core");
1503
+ WebGPUQuerySet = class extends import_core18.QuerySet {
1504
+ device;
1505
+ handle;
1506
+ constructor(device, props) {
1507
+ super(device, props);
1508
+ this.device = device;
1509
+ this.handle = this.props.handle || this.device.handle.createQuerySet({
1510
+ type: this.props.type,
1511
+ count: this.props.count
1512
+ });
1513
+ this.handle.label = this.props.id;
1514
+ }
1515
+ destroy() {
1516
+ var _a;
1517
+ (_a = this.handle) == null ? void 0 : _a.destroy();
1518
+ this.handle = null;
1519
+ }
1520
+ };
1288
1521
  }
1289
- };
1522
+ });
1290
1523
 
1291
1524
  // dist/adapter/webgpu-device.js
1292
- var WebGPUDevice = class extends import_core17.Device {
1293
- /** The underlying WebGPU device */
1294
- handle;
1295
- /** type of this device */
1296
- type = "webgpu";
1297
- preferredColorFormat = navigator.gpu.getPreferredCanvasFormat();
1298
- preferredDepthFormat = "depth24plus";
1299
- features;
1300
- info;
1301
- limits;
1302
- lost;
1303
- renderPass = null;
1304
- canvasContext;
1305
- _isLost = false;
1306
- // canvasContext: WebGPUCanvasContext | null = null;
1307
- commandEncoder = null;
1308
- /* The underlying WebGPU adapter */
1309
- adapter;
1310
- /* The underlying WebGPU adapter's info */
1311
- adapterInfo;
1312
- constructor(props, device, adapter, adapterInfo) {
1313
- super({ ...props, id: props.id || "webgpu-device" });
1314
- this.handle = device;
1315
- this.adapter = adapter;
1316
- this.adapterInfo = adapterInfo;
1317
- this.info = this._getInfo();
1318
- this.features = this._getFeatures();
1319
- this.limits = this.handle.limits;
1320
- device.addEventListener("uncapturederror", (event) => {
1321
- const errorMessage = event instanceof GPUUncapturedErrorEvent ? event.error.message : "Unknown WebGPU error";
1322
- this.reportError(new Error(errorMessage));
1323
- if (this.props.debug) {
1324
- debugger;
1325
- }
1326
- event.preventDefault();
1327
- });
1328
- this.lost = new Promise(async (resolve) => {
1329
- const lostInfo = await this.handle.lost;
1330
- this._isLost = true;
1331
- resolve({ reason: "destroyed", message: lostInfo.message });
1332
- });
1333
- if (props.createCanvasContext) {
1334
- const canvasContextProps = props.createCanvasContext === true ? {} : props.createCanvasContext;
1335
- this.canvasContext = new WebGPUCanvasContext(this, this.adapter, canvasContextProps);
1336
- }
1337
- }
1338
- // TODO
1339
- // Load the glslang module now so that it is available synchronously when compiling shaders
1340
- // const {glsl = true} = props;
1341
- // this.glslang = glsl && await loadGlslangModule();
1342
- destroy() {
1343
- this.handle.destroy();
1344
- }
1345
- get isLost() {
1346
- return this._isLost;
1347
- }
1348
- createBuffer(props) {
1349
- const newProps = this._normalizeBufferProps(props);
1350
- return new WebGPUBuffer(this, newProps);
1351
- }
1352
- createTexture(props) {
1353
- return new WebGPUTexture(this, props);
1354
- }
1355
- createExternalTexture(props) {
1356
- return new WebGPUExternalTexture(this, props);
1357
- }
1358
- createShader(props) {
1359
- return new WebGPUShader(this, props);
1360
- }
1361
- createSampler(props) {
1362
- return new WebGPUSampler(this, props);
1363
- }
1364
- createRenderPipeline(props) {
1365
- return new WebGPURenderPipeline(this, props);
1366
- }
1367
- createFramebuffer(props) {
1368
- return new WebGPUFramebuffer(this, props);
1369
- }
1370
- createComputePipeline(props) {
1371
- return new WebGPUComputePipeline(this, props);
1372
- }
1373
- createVertexArray(props) {
1374
- return new WebGPUVertexArray(this, props);
1375
- }
1376
- // WebGPU specifics
1377
- /**
1378
- * Allows a render pass to begin against a canvas context
1379
- * @todo need to support a "Framebuffer" equivalent (aka preconfigured RenderPassDescriptors?).
1380
- */
1381
- beginRenderPass(props) {
1382
- this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();
1383
- return new WebGPURenderPass(this, props);
1384
- }
1385
- beginComputePass(props) {
1386
- this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();
1387
- return new WebGPUComputePass(this, props);
1388
- }
1389
- // createCommandEncoder(props: CommandEncoderProps): WebGPUCommandEncoder {
1390
- // return new WebGPUCommandEncoder(this, props);
1391
- // }
1392
- createTransformFeedback(props) {
1393
- throw new Error("Transform feedback not supported in WebGPU");
1394
- }
1395
- createQuerySet(props) {
1396
- return new WebGPUQuerySet(this, props);
1397
- }
1398
- createCanvasContext(props) {
1399
- return new WebGPUCanvasContext(this, this.adapter, props);
1400
- }
1401
- submit() {
1402
- var _a;
1403
- const commandBuffer = (_a = this.commandEncoder) == null ? void 0 : _a.finish();
1404
- if (commandBuffer) {
1405
- this.handle.pushErrorScope("validation");
1406
- this.handle.queue.submit([commandBuffer]);
1407
- this.handle.popErrorScope().then((error) => {
1408
- if (error) {
1409
- this.reportError(new Error(`WebGPU command submission failed: ${error.message}`));
1525
+ var webgpu_device_exports = {};
1526
+ __export(webgpu_device_exports, {
1527
+ WebGPUDevice: () => WebGPUDevice
1528
+ });
1529
+ var import_core19, WebGPUDevice;
1530
+ var init_webgpu_device = __esm({
1531
+ "dist/adapter/webgpu-device.js"() {
1532
+ "use strict";
1533
+ import_core19 = require("@luma.gl/core");
1534
+ init_webgpu_buffer();
1535
+ init_webgpu_texture();
1536
+ init_webgpu_external_texture();
1537
+ init_webgpu_sampler();
1538
+ init_webgpu_shader();
1539
+ init_webgpu_render_pipeline();
1540
+ init_webgpu_framebuffer();
1541
+ init_webgpu_compute_pipeline();
1542
+ init_webgpu_vertex_array();
1543
+ init_webgpu_canvas_context();
1544
+ init_webgpu_command_encoder();
1545
+ init_webgpu_query_set();
1546
+ WebGPUDevice = class extends import_core19.Device {
1547
+ /** The underlying WebGPU device */
1548
+ handle;
1549
+ /** type of this device */
1550
+ type = "webgpu";
1551
+ preferredColorFormat = navigator.gpu.getPreferredCanvasFormat();
1552
+ preferredDepthFormat = "depth24plus";
1553
+ features;
1554
+ info;
1555
+ limits;
1556
+ lost;
1557
+ canvasContext = null;
1558
+ _isLost = false;
1559
+ commandEncoder;
1560
+ /* The underlying WebGPU adapter */
1561
+ adapter;
1562
+ /* The underlying WebGPU adapter's info */
1563
+ adapterInfo;
1564
+ constructor(props, device, adapter, adapterInfo) {
1565
+ super({ ...props, id: props.id || "webgpu-device" });
1566
+ this.handle = device;
1567
+ this.adapter = adapter;
1568
+ this.adapterInfo = adapterInfo;
1569
+ this.info = this._getInfo();
1570
+ this.features = this._getFeatures();
1571
+ this.limits = this.handle.limits;
1572
+ device.addEventListener("uncapturederror", (event) => {
1573
+ event.preventDefault();
1574
+ const errorMessage = event instanceof GPUUncapturedErrorEvent ? event.error.message : "Unknown WebGPU error";
1575
+ this.reportError(new Error(errorMessage));
1576
+ if (this.props.debug) {
1577
+ debugger;
1578
+ }
1579
+ });
1580
+ this.lost = new Promise(async (resolve) => {
1581
+ const lostInfo = await this.handle.lost;
1582
+ this._isLost = true;
1583
+ resolve({ reason: "destroyed", message: lostInfo.message });
1584
+ });
1585
+ if (props.createCanvasContext) {
1586
+ const canvasContextProps = props.createCanvasContext === true ? {} : props.createCanvasContext;
1587
+ this.canvasContext = new WebGPUCanvasContext(this, this.adapter, canvasContextProps);
1410
1588
  }
1411
- });
1412
- }
1413
- this.commandEncoder = null;
1414
- }
1415
- // PRIVATE METHODS
1416
- _getInfo() {
1417
- const [driver, driverVersion] = (this.adapterInfo.driver || "").split(" Version ");
1418
- const vendor = this.adapterInfo.vendor || this.adapter.__brand || "unknown";
1419
- const renderer = driver || "";
1420
- const version = driverVersion || "";
1421
- const gpu = vendor === "apple" ? "apple" : "unknown";
1422
- const gpuArchitecture = this.adapterInfo.architecture || "unknown";
1423
- const gpuBackend = this.adapterInfo.backend || "unknown";
1424
- const gpuType = (this.adapterInfo.type || "").split(" ")[0].toLowerCase() || "unknown";
1425
- return {
1426
- type: "webgpu",
1427
- vendor,
1428
- renderer,
1429
- version,
1430
- gpu,
1431
- gpuType,
1432
- gpuBackend,
1433
- gpuArchitecture,
1434
- shadingLanguage: "wgsl",
1435
- shadingLanguageVersion: 100
1589
+ this.commandEncoder = this.createCommandEncoder({});
1590
+ }
1591
+ // TODO
1592
+ // Load the glslang module now so that it is available synchronously when compiling shaders
1593
+ // const {glsl = true} = props;
1594
+ // this.glslang = glsl && await loadGlslangModule();
1595
+ destroy() {
1596
+ this.handle.destroy();
1597
+ }
1598
+ get isLost() {
1599
+ return this._isLost;
1600
+ }
1601
+ createBuffer(props) {
1602
+ const newProps = this._normalizeBufferProps(props);
1603
+ return new WebGPUBuffer(this, newProps);
1604
+ }
1605
+ createTexture(props) {
1606
+ return new WebGPUTexture(this, props);
1607
+ }
1608
+ createExternalTexture(props) {
1609
+ return new WebGPUExternalTexture(this, props);
1610
+ }
1611
+ createShader(props) {
1612
+ return new WebGPUShader(this, props);
1613
+ }
1614
+ createSampler(props) {
1615
+ return new WebGPUSampler(this, props);
1616
+ }
1617
+ createRenderPipeline(props) {
1618
+ return new WebGPURenderPipeline(this, props);
1619
+ }
1620
+ createFramebuffer(props) {
1621
+ return new WebGPUFramebuffer(this, props);
1622
+ }
1623
+ createComputePipeline(props) {
1624
+ return new WebGPUComputePipeline(this, props);
1625
+ }
1626
+ createVertexArray(props) {
1627
+ return new WebGPUVertexArray(this, props);
1628
+ }
1629
+ createCommandEncoder(props) {
1630
+ return new WebGPUCommandEncoder(this, props);
1631
+ }
1632
+ // WebGPU specifics
1633
+ createTransformFeedback(props) {
1634
+ throw new Error("Transform feedback not supported in WebGPU");
1635
+ }
1636
+ createQuerySet(props) {
1637
+ return new WebGPUQuerySet(this, props);
1638
+ }
1639
+ createCanvasContext(props) {
1640
+ return new WebGPUCanvasContext(this, this.adapter, props);
1641
+ }
1642
+ submit(commandBuffer) {
1643
+ if (!commandBuffer) {
1644
+ commandBuffer = this.commandEncoder.finish();
1645
+ this.commandEncoder.destroy();
1646
+ this.commandEncoder = this.createCommandEncoder({ id: `${this.id}-default-encoder` });
1647
+ }
1648
+ this.handle.pushErrorScope("validation");
1649
+ this.handle.queue.submit([commandBuffer.handle]);
1650
+ this.handle.popErrorScope().then((error) => {
1651
+ if (error) {
1652
+ this.reportError(new Error(`WebGPU command submission failed: ${error.message}`));
1653
+ }
1654
+ });
1655
+ }
1656
+ // WebGPU specific
1657
+ pushErrorScope(scope) {
1658
+ this.handle.pushErrorScope(scope);
1659
+ }
1660
+ popErrorScope(handler) {
1661
+ this.handle.popErrorScope().then((error) => {
1662
+ if (error) {
1663
+ handler(error.message);
1664
+ }
1665
+ });
1666
+ }
1667
+ // PRIVATE METHODS
1668
+ _getInfo() {
1669
+ const [driver, driverVersion] = (this.adapterInfo.driver || "").split(" Version ");
1670
+ const vendor = this.adapterInfo.vendor || this.adapter.__brand || "unknown";
1671
+ const renderer = driver || "";
1672
+ const version = driverVersion || "";
1673
+ const gpu = vendor === "apple" ? "apple" : "unknown";
1674
+ const gpuArchitecture = this.adapterInfo.architecture || "unknown";
1675
+ const gpuBackend = this.adapterInfo.backend || "unknown";
1676
+ const gpuType = (this.adapterInfo.type || "").split(" ")[0].toLowerCase() || "unknown";
1677
+ return {
1678
+ type: "webgpu",
1679
+ vendor,
1680
+ renderer,
1681
+ version,
1682
+ gpu,
1683
+ gpuType,
1684
+ gpuBackend,
1685
+ gpuArchitecture,
1686
+ shadingLanguage: "wgsl",
1687
+ shadingLanguageVersion: 100
1688
+ };
1689
+ }
1690
+ _getFeatures() {
1691
+ const features = new Set(this.handle.features);
1692
+ if (features.has("depth-clamping")) {
1693
+ features.delete("depth-clamping");
1694
+ features.add("depth-clip-control");
1695
+ }
1696
+ if (features.has("texture-compression-bc")) {
1697
+ features.add("texture-compression-bc5-webgl");
1698
+ }
1699
+ const WEBGPU_ALWAYS_FEATURES = [
1700
+ "timer-query-webgl",
1701
+ "compilation-status-async-webgl",
1702
+ "float32-renderable-webgl",
1703
+ "float16-renderable-webgl",
1704
+ "norm16-renderable-webgl",
1705
+ "texture-filterable-anisotropic-webgl",
1706
+ "shader-noperspective-interpolation-webgl"
1707
+ ];
1708
+ for (const feature of WEBGPU_ALWAYS_FEATURES) {
1709
+ features.add(feature);
1710
+ }
1711
+ return new import_core19.DeviceFeatures(Array.from(features), this.props._disabledFeatures);
1712
+ }
1713
+ _getDeviceSpecificTextureFormatCapabilities(capabilities) {
1714
+ const { format } = capabilities;
1715
+ if (format.includes("webgl")) {
1716
+ return { format, create: false, render: false, filter: false, blend: false, store: false };
1717
+ }
1718
+ return capabilities;
1719
+ }
1436
1720
  };
1437
1721
  }
1438
- _getFeatures() {
1439
- const features = new Set(this.handle.features);
1440
- if (features.has("depth-clamping")) {
1441
- features.delete("depth-clamping");
1442
- features.add("depth-clip-control");
1443
- }
1444
- if (features.has("texture-compression-bc")) {
1445
- features.add("texture-compression-bc5-webgl");
1446
- }
1447
- const WEBGPU_ALWAYS_FEATURES = [
1448
- "timer-query-webgl",
1449
- "compilation-status-async-webgl",
1450
- "float32-renderable-webgl",
1451
- "float16-renderable-webgl",
1452
- "norm16-renderable-webgl",
1453
- "texture-filterable-anisotropic-webgl",
1454
- "shader-noperspective-interpolation-webgl"
1455
- ];
1456
- for (const feature of WEBGPU_ALWAYS_FEATURES) {
1457
- features.add(feature);
1458
- }
1459
- return new import_core17.DeviceFeatures(Array.from(features), this.props._disabledFeatures);
1460
- }
1461
- _getDeviceSpecificTextureFormatCapabilities(capabilities) {
1462
- const { format } = capabilities;
1463
- if (format.includes("webgl")) {
1464
- return { format, create: false, render: false, filter: false, blend: false, store: false };
1465
- }
1466
- return capabilities;
1467
- }
1468
- // DEPRECATED METHODS
1469
- // @deprecated
1470
- copyExternalImageToTexture(options) {
1471
- var _a;
1472
- const {
1473
- source,
1474
- sourceX = 0,
1475
- sourceY = 0,
1476
- texture,
1477
- mipLevel = 0,
1478
- aspect = "all",
1479
- colorSpace = "display-p3",
1480
- premultipliedAlpha = false,
1481
- // destinationX,
1482
- // destinationY,
1483
- // desitnationZ,
1484
- width = texture.width,
1485
- height = texture.height,
1486
- depth = 1
1487
- } = options;
1488
- const webGpuTexture = texture;
1489
- (_a = this.handle) == null ? void 0 : _a.queue.copyExternalImageToTexture(
1490
- // source: GPUImageCopyExternalImage
1491
- {
1492
- source,
1493
- origin: [sourceX, sourceY]
1494
- },
1495
- // destination: GPUImageCopyTextureTagged
1496
- {
1497
- texture: webGpuTexture.handle,
1498
- origin: [0, 0, 0],
1499
- // [x, y, z],
1500
- mipLevel,
1501
- aspect,
1502
- colorSpace,
1503
- premultipliedAlpha
1504
- },
1505
- // copySize: GPUExtent3D
1506
- [width, height, depth]
1507
- );
1508
- }
1509
- };
1722
+ });
1723
+
1724
+ // dist/index.js
1725
+ var dist_exports = {};
1726
+ __export(dist_exports, {
1727
+ WebGPUBuffer: () => WebGPUBuffer,
1728
+ WebGPUDevice: () => WebGPUDevice,
1729
+ WebGPUSampler: () => WebGPUSampler,
1730
+ WebGPUShader: () => WebGPUShader,
1731
+ WebGPUTexture: () => WebGPUTexture,
1732
+ webgpuAdapter: () => webgpuAdapter
1733
+ });
1734
+ module.exports = __toCommonJS(dist_exports);
1510
1735
 
1511
1736
  // dist/adapter/webgpu-adapter.js
1512
- var WebGPUAdapter = class extends import_core18.Adapter {
1737
+ var import_core20 = require("@luma.gl/core");
1738
+ var WebGPUAdapter = class extends import_core20.Adapter {
1513
1739
  /** type of device's created by this adapter */
1514
1740
  type = "webgpu";
1515
- constructor() {
1516
- super();
1517
- WebGPUDevice.adapter = this;
1518
- }
1519
- /** Check if WebGPU is available */
1520
1741
  isSupported() {
1521
1742
  return Boolean(typeof navigator !== "undefined" && navigator.gpu);
1522
1743
  }
1744
+ isDeviceHandle(handle) {
1745
+ if (typeof GPUDevice !== "undefined" && handle instanceof GPUDevice) {
1746
+ return true;
1747
+ }
1748
+ if (handle == null ? void 0 : handle.queue) {
1749
+ return true;
1750
+ }
1751
+ return false;
1752
+ }
1523
1753
  async create(props) {
1754
+ var _a;
1524
1755
  if (!navigator.gpu) {
1525
- throw new Error("WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu");
1756
+ throw new Error("WebGPU not available. Recent Chrome browsers should work.");
1526
1757
  }
1527
- import_core18.log.groupCollapsed(1, "WebGPUDevice created")();
1758
+ import_core20.log.groupCollapsed(1, "WebGPUDevice created")();
1528
1759
  const adapter = await navigator.gpu.requestAdapter({
1529
1760
  powerPreference: "high-performance"
1530
1761
  // forceSoftware: false
@@ -1532,8 +1763,9 @@ var WebGPUAdapter = class extends import_core18.Adapter {
1532
1763
  if (!adapter) {
1533
1764
  throw new Error("Failed to request WebGPU adapter");
1534
1765
  }
1535
- const adapterInfo = await adapter.requestAdapterInfo();
1536
- import_core18.log.probe(2, "Adapter available", adapterInfo)();
1766
+ const adapterInfo = adapter.info || // @ts-ignore
1767
+ await ((_a = adapter.requestAdapterInfo) == null ? void 0 : _a.call(adapter));
1768
+ import_core20.log.probe(2, "Adapter available", adapterInfo)();
1537
1769
  const requiredFeatures = [];
1538
1770
  const requiredLimits = {};
1539
1771
  if (props._requestMaxLimits) {
@@ -1551,11 +1783,12 @@ var WebGPUAdapter = class extends import_core18.Adapter {
1551
1783
  requiredFeatures,
1552
1784
  requiredLimits
1553
1785
  });
1554
- import_core18.log.probe(1, "GPUDevice available")();
1555
- const device = new WebGPUDevice(props, gpuDevice, adapter, adapterInfo);
1556
- import_core18.log.probe(1, "Device created. For more info, set chrome://flags/#enable-webgpu-developer-features")();
1557
- import_core18.log.table(1, device.info)();
1558
- import_core18.log.groupEnd(1)();
1786
+ import_core20.log.probe(1, "GPUDevice available")();
1787
+ const { WebGPUDevice: WebGPUDevice2 } = await Promise.resolve().then(() => (init_webgpu_device(), webgpu_device_exports));
1788
+ const device = new WebGPUDevice2(props, gpuDevice, adapter, adapterInfo);
1789
+ import_core20.log.probe(1, "Device created. For more info, set chrome://flags/#enable-webgpu-developer-features")();
1790
+ import_core20.log.table(1, device.info)();
1791
+ import_core20.log.groupEnd(1)();
1559
1792
  return device;
1560
1793
  }
1561
1794
  async attach(handle) {
@@ -1563,4 +1796,11 @@ var WebGPUAdapter = class extends import_core18.Adapter {
1563
1796
  }
1564
1797
  };
1565
1798
  var webgpuAdapter = new WebGPUAdapter();
1799
+
1800
+ // dist/index.js
1801
+ init_webgpu_device();
1802
+ init_webgpu_buffer();
1803
+ init_webgpu_texture();
1804
+ init_webgpu_sampler();
1805
+ init_webgpu_shader();
1566
1806
  //# sourceMappingURL=index.cjs.map