@luma.gl/webgpu 9.1.9 → 9.2.0-alpha.2

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