@luma.gl/webgpu 9.0.0-alpha.9 → 9.0.0-beta.10

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 (142) hide show
  1. package/LICENSE +3 -1
  2. package/dist/adapter/helpers/accessor-to-format.js +102 -1
  3. package/dist/adapter/helpers/convert-texture-format.d.ts +2 -2
  4. package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -1
  5. package/dist/adapter/helpers/convert-texture-format.js +8 -6
  6. package/dist/adapter/helpers/get-bind-group.d.ts +4 -4
  7. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
  8. package/dist/adapter/helpers/get-bind-group.js +61 -52
  9. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +5 -5
  10. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
  11. package/dist/adapter/helpers/get-vertex-buffer-layout.js +123 -90
  12. package/dist/adapter/helpers/webgpu-parameters.d.ts +2 -2
  13. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  14. package/dist/adapter/helpers/webgpu-parameters.js +184 -130
  15. package/dist/adapter/resources/webgpu-buffer.d.ts +14 -5
  16. package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
  17. package/dist/adapter/resources/webgpu-buffer.js +117 -70
  18. package/dist/adapter/resources/webgpu-command-encoder.d.ts +13 -14
  19. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  20. package/dist/adapter/resources/webgpu-command-encoder.js +83 -65
  21. package/dist/adapter/resources/webgpu-compute-pass.d.ts +19 -13
  22. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  23. package/dist/adapter/resources/webgpu-compute-pass.js +78 -57
  24. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +16 -6
  25. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  26. package/dist/adapter/resources/webgpu-compute-pipeline.js +48 -26
  27. package/dist/adapter/resources/webgpu-external-texture.d.ts +5 -5
  28. package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
  29. package/dist/adapter/resources/webgpu-external-texture.js +38 -29
  30. package/dist/adapter/resources/webgpu-framebuffer.d.ts +4 -21
  31. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  32. package/dist/adapter/resources/webgpu-framebuffer.js +15 -109
  33. package/dist/adapter/resources/webgpu-query-set.d.ts +17 -0
  34. package/dist/adapter/resources/webgpu-query-set.d.ts.map +1 -0
  35. package/dist/adapter/resources/webgpu-query-set.js +27 -0
  36. package/dist/adapter/resources/webgpu-render-pass.d.ts +14 -7
  37. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  38. package/dist/adapter/resources/webgpu-render-pass.js +136 -91
  39. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +63 -23
  40. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  41. package/dist/adapter/resources/webgpu-render-pipeline.js +151 -148
  42. package/dist/adapter/resources/webgpu-sampler.d.ts +5 -5
  43. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
  44. package/dist/adapter/resources/webgpu-sampler.js +23 -23
  45. package/dist/adapter/resources/webgpu-shader.d.ts +9 -12
  46. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  47. package/dist/adapter/resources/webgpu-shader.js +47 -60
  48. package/dist/adapter/resources/webgpu-texture-view.d.ts +20 -0
  49. package/dist/adapter/resources/webgpu-texture-view.d.ts.map +1 -0
  50. package/dist/adapter/resources/webgpu-texture-view.js +35 -0
  51. package/dist/adapter/resources/webgpu-texture.d.ts +20 -10
  52. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  53. package/dist/adapter/resources/webgpu-texture.js +133 -105
  54. package/dist/adapter/resources/webgpu-vertex-array.d.ts +27 -0
  55. package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -0
  56. package/dist/adapter/resources/webgpu-vertex-array.js +66 -0
  57. package/dist/adapter/webgpu-canvas-context.d.ts +17 -12
  58. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  59. package/dist/adapter/webgpu-canvas-context.js +105 -92
  60. package/dist/adapter/webgpu-device.d.ts +45 -30
  61. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  62. package/dist/adapter/webgpu-device.js +266 -241
  63. package/dist/dist.dev.js +1664 -0
  64. package/dist/dist.min.js +9 -0
  65. package/dist/index.cjs +1432 -0
  66. package/dist/index.cjs.map +7 -0
  67. package/dist/index.d.ts +5 -7
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +10 -8
  70. package/dist.min.js +9 -0
  71. package/package.json +22 -11
  72. package/src/adapter/helpers/accessor-to-format.ts +6 -3
  73. package/src/adapter/helpers/convert-texture-format.ts +5 -2
  74. package/src/adapter/helpers/get-bind-group.ts +30 -14
  75. package/src/adapter/helpers/get-vertex-buffer-layout.ts +73 -39
  76. package/src/adapter/helpers/webgpu-parameters.ts +99 -29
  77. package/src/adapter/resources/webgpu-buffer.ts +85 -17
  78. package/src/adapter/resources/webgpu-command-encoder.ts +93 -58
  79. package/src/adapter/resources/webgpu-compute-pass.ts +56 -32
  80. package/src/adapter/resources/webgpu-compute-pipeline.ts +51 -18
  81. package/src/adapter/resources/webgpu-external-texture.ts +19 -11
  82. package/src/adapter/resources/webgpu-framebuffer.ts +11 -108
  83. package/src/adapter/resources/webgpu-query-set.ts +37 -0
  84. package/src/adapter/resources/webgpu-render-pass.ts +95 -19
  85. package/src/adapter/resources/webgpu-render-pipeline.ts +139 -159
  86. package/src/adapter/resources/webgpu-sampler.ts +10 -7
  87. package/src/adapter/resources/webgpu-shader.ts +30 -35
  88. package/src/adapter/resources/webgpu-texture-view.ts +46 -0
  89. package/src/adapter/resources/webgpu-texture.ts +75 -41
  90. package/src/adapter/resources/webgpu-vertex-array.ts +91 -0
  91. package/src/adapter/webgpu-canvas-context.ts +60 -29
  92. package/src/adapter/webgpu-device.ts +219 -120
  93. package/src/index.ts +8 -9
  94. package/dist/adapter/helpers/accessor-to-format.js.map +0 -1
  95. package/dist/adapter/helpers/convert-texture-format.js.map +0 -1
  96. package/dist/adapter/helpers/generate-mipmaps.d.ts +0 -10
  97. package/dist/adapter/helpers/generate-mipmaps.d.ts.map +0 -1
  98. package/dist/adapter/helpers/generate-mipmaps.js +0 -95
  99. package/dist/adapter/helpers/generate-mipmaps.js.map +0 -1
  100. package/dist/adapter/helpers/get-bind-group.js.map +0 -1
  101. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +0 -1
  102. package/dist/adapter/helpers/webgpu-parameters.js.map +0 -1
  103. package/dist/adapter/resources/webgpu-buffer.js.map +0 -1
  104. package/dist/adapter/resources/webgpu-command-encoder.js.map +0 -1
  105. package/dist/adapter/resources/webgpu-compute-pass.js.map +0 -1
  106. package/dist/adapter/resources/webgpu-compute-pipeline.js.map +0 -1
  107. package/dist/adapter/resources/webgpu-external-texture.js.map +0 -1
  108. package/dist/adapter/resources/webgpu-framebuffer.js.map +0 -1
  109. package/dist/adapter/resources/webgpu-query.d.ts +0 -1
  110. package/dist/adapter/resources/webgpu-query.d.ts.map +0 -1
  111. package/dist/adapter/resources/webgpu-query.js +0 -2
  112. package/dist/adapter/resources/webgpu-query.js.map +0 -1
  113. package/dist/adapter/resources/webgpu-render-pass.js.map +0 -1
  114. package/dist/adapter/resources/webgpu-render-pipeline.js.map +0 -1
  115. package/dist/adapter/resources/webgpu-sampler.js.map +0 -1
  116. package/dist/adapter/resources/webgpu-shader.js.map +0 -1
  117. package/dist/adapter/resources/webgpu-texture.js.map +0 -1
  118. package/dist/adapter/webgpu-canvas-context.js.map +0 -1
  119. package/dist/adapter/webgpu-device.js.map +0 -1
  120. package/dist/adapter/webgpu-types.d.ts +0 -1
  121. package/dist/adapter/webgpu-types.d.ts.map +0 -1
  122. package/dist/adapter/webgpu-types.js +0 -2
  123. package/dist/adapter/webgpu-types.js.map +0 -1
  124. package/dist/bundle.d.ts +0 -2
  125. package/dist/bundle.d.ts.map +0 -1
  126. package/dist/bundle.js +0 -5
  127. package/dist/bundle.js.map +0 -1
  128. package/dist/glsl/glsllang.d.ts +0 -3
  129. package/dist/glsl/glsllang.d.ts.map +0 -1
  130. package/dist/glsl/glsllang.js +0 -10
  131. package/dist/glsl/glsllang.js.map +0 -1
  132. package/dist/index.js.map +0 -1
  133. package/dist/init.d.ts +0 -2
  134. package/dist/init.d.ts.map +0 -1
  135. package/dist/init.js +0 -4
  136. package/dist/init.js.map +0 -1
  137. package/src/adapter/helpers/generate-mipmaps.ts +0 -107
  138. package/src/adapter/resources/webgpu-query.ts +0 -43
  139. package/src/adapter/webgpu-types.ts +0 -0
  140. package/src/bundle.ts +0 -4
  141. package/src/glsl/glsllang.ts +0 -14
  142. package/src/init.ts +0 -4
package/dist/index.cjs ADDED
@@ -0,0 +1,1432 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __publicField = (obj, key, value) => {
20
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+ return value;
22
+ };
23
+
24
+ // dist/index.js
25
+ var dist_exports = {};
26
+ __export(dist_exports, {
27
+ WebGPUBuffer: () => WebGPUBuffer,
28
+ WebGPUDevice: () => WebGPUDevice,
29
+ WebGPUSampler: () => WebGPUSampler,
30
+ WebGPUShader: () => WebGPUShader,
31
+ WebGPUTexture: () => WebGPUTexture
32
+ });
33
+ module.exports = __toCommonJS(dist_exports);
34
+
35
+ // dist/adapter/webgpu-device.js
36
+ var import_core17 = require("@luma.gl/core");
37
+
38
+ // dist/adapter/resources/webgpu-buffer.js
39
+ var import_core = require("@luma.gl/core");
40
+ function getByteLength(props) {
41
+ var _a;
42
+ return props.byteLength || ((_a = props.data) == null ? void 0 : _a.byteLength) || 0;
43
+ }
44
+ var WebGPUBuffer = class extends import_core.Buffer {
45
+ device;
46
+ handle;
47
+ byteLength;
48
+ constructor(device, props) {
49
+ super(device, props);
50
+ this.device = device;
51
+ this.byteLength = getByteLength(props);
52
+ const mapBuffer = Boolean(props.data);
53
+ const size = Math.ceil(this.byteLength / 4) * 4;
54
+ this.handle = this.props.handle || this.device.handle.createBuffer({
55
+ size,
56
+ // usage defaults to vertex
57
+ usage: this.props.usage || GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
58
+ mappedAtCreation: this.props.mappedAtCreation || mapBuffer,
59
+ label: this.props.id
60
+ });
61
+ if (props.data) {
62
+ this._writeMapped(props.data);
63
+ }
64
+ if (mapBuffer && !props.mappedAtCreation) {
65
+ this.handle.unmap();
66
+ }
67
+ }
68
+ destroy() {
69
+ var _a;
70
+ (_a = this.handle) == null ? void 0 : _a.destroy();
71
+ this.handle = null;
72
+ }
73
+ // WebGPU provides multiple ways to write a buffer...
74
+ write(data, byteOffset = 0) {
75
+ this.device.handle.queue.writeBuffer(this.handle, byteOffset, data.buffer, data.byteOffset, data.byteLength);
76
+ }
77
+ async readAsync(byteOffset = 0, byteLength = this.byteLength) {
78
+ const tempBuffer = new WebGPUBuffer(this.device, {
79
+ usage: import_core.Buffer.MAP_READ | import_core.Buffer.COPY_DST,
80
+ byteLength
81
+ });
82
+ const commandEncoder = this.device.handle.createCommandEncoder();
83
+ commandEncoder.copyBufferToBuffer(this.handle, byteOffset, tempBuffer.handle, 0, byteLength);
84
+ this.device.handle.queue.submit([commandEncoder.finish()]);
85
+ await tempBuffer.handle.mapAsync(GPUMapMode.READ, byteOffset, byteLength);
86
+ const arrayBuffer = tempBuffer.handle.getMappedRange().slice(0);
87
+ tempBuffer.handle.unmap();
88
+ tempBuffer.destroy();
89
+ return new Uint8Array(arrayBuffer);
90
+ }
91
+ _writeMapped(typedArray) {
92
+ const arrayBuffer = this.handle.getMappedRange();
93
+ new typedArray.constructor(arrayBuffer).set(typedArray);
94
+ }
95
+ // WEBGPU API
96
+ mapAsync(mode, offset = 0, size) {
97
+ return this.handle.mapAsync(mode, offset, size);
98
+ }
99
+ getMappedRange(offset = 0, size) {
100
+ return this.handle.getMappedRange(offset, size);
101
+ }
102
+ unmap() {
103
+ this.handle.unmap();
104
+ }
105
+ };
106
+
107
+ // dist/adapter/resources/webgpu-texture.js
108
+ var import_core4 = require("@luma.gl/core");
109
+
110
+ // dist/adapter/helpers/convert-texture-format.js
111
+ function getWebGPUTextureFormat(format) {
112
+ if (format.includes("webgl")) {
113
+ throw new Error("webgl-only format");
114
+ }
115
+ return format;
116
+ }
117
+
118
+ // dist/adapter/resources/webgpu-sampler.js
119
+ var import_core2 = require("@luma.gl/core");
120
+ var WebGPUSampler = class extends import_core2.Sampler {
121
+ device;
122
+ handle;
123
+ constructor(device, props) {
124
+ super(device, props);
125
+ this.device = device;
126
+ const samplerProps = { ...this.props };
127
+ if (samplerProps.type !== "comparison-sampler") {
128
+ delete samplerProps.compare;
129
+ }
130
+ this.handle = this.handle || this.device.handle.createSampler(samplerProps);
131
+ this.handle.label = this.props.id;
132
+ }
133
+ destroy() {
134
+ this.handle = null;
135
+ }
136
+ };
137
+
138
+ // dist/adapter/resources/webgpu-texture-view.js
139
+ var import_core3 = require("@luma.gl/core");
140
+ var WebGPUTextureView = class extends import_core3.TextureView {
141
+ device;
142
+ handle;
143
+ texture;
144
+ constructor(device, props) {
145
+ super(device, props);
146
+ this.device = device;
147
+ this.texture = props.texture;
148
+ this.handle = this.handle || this.texture.handle.createView({
149
+ format: props.format || this.texture.format,
150
+ dimension: props.dimension || this.texture.dimension,
151
+ aspect: props.aspect,
152
+ baseMipLevel: props.baseMipLevel,
153
+ mipLevelCount: props.mipLevelCount,
154
+ // GPUIntegerCoordinate;
155
+ baseArrayLayer: props.baseArrayLayer,
156
+ // GPUIntegerCoordinate;
157
+ arrayLayerCount: props.arrayLayerCount
158
+ // GPUIntegerCoordinate;
159
+ });
160
+ this.handle.label = this.props.id;
161
+ }
162
+ destroy() {
163
+ this.handle = null;
164
+ }
165
+ };
166
+
167
+ // dist/adapter/resources/webgpu-texture.js
168
+ var BASE_DIMENSIONS = {
169
+ "1d": "1d",
170
+ "2d": "2d",
171
+ "2d-array": "2d",
172
+ cube: "2d",
173
+ "cube-array": "2d",
174
+ "3d": "3d"
175
+ };
176
+ var WebGPUTexture = class extends import_core4.Texture {
177
+ device;
178
+ handle;
179
+ height = 1;
180
+ width = 1;
181
+ sampler;
182
+ view;
183
+ // static async createFromImageURL(src, usage = 0) {
184
+ // const img = document.createElement('img');
185
+ // img.src = src;
186
+ // await img.decode();
187
+ // return WebGPUTexture(img, usage);
188
+ // }
189
+ constructor(device, props) {
190
+ super(device, props);
191
+ this.device = device;
192
+ if (props.data instanceof Promise) {
193
+ props.data.then((resolvedImageData) => {
194
+ this.props = { ...props, data: resolvedImageData };
195
+ this.initialize(this.props);
196
+ });
197
+ return;
198
+ }
199
+ this.initialize(props);
200
+ }
201
+ destroy() {
202
+ var _a;
203
+ (_a = this.handle) == null ? void 0 : _a.destroy();
204
+ this.handle = null;
205
+ }
206
+ createView(props) {
207
+ return new WebGPUTextureView(this.device, { ...props, texture: this });
208
+ }
209
+ initialize(props) {
210
+ this.handle = this.props.handle || this.createHandle();
211
+ this.handle.label ||= this.id;
212
+ if (this.props.data) {
213
+ this.setData({ data: this.props.data });
214
+ }
215
+ this.width = this.handle.width;
216
+ this.height = this.handle.height;
217
+ this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);
218
+ this.view = new WebGPUTextureView(this.device, { ...this.props, texture: this });
219
+ }
220
+ createHandle() {
221
+ var _a, _b;
222
+ const width = this.props.width || ((_a = this.props.data) == null ? void 0 : _a.width) || 1;
223
+ const height = this.props.height || ((_b = this.props.data) == null ? void 0 : _b.height) || 1;
224
+ return this.device.handle.createTexture({
225
+ label: this.id,
226
+ size: {
227
+ width,
228
+ height,
229
+ depthOrArrayLayers: this.props.depth
230
+ },
231
+ dimension: BASE_DIMENSIONS[this.props.dimension],
232
+ format: getWebGPUTextureFormat(this.props.format),
233
+ usage: this.props.usage,
234
+ mipLevelCount: this.props.mipLevels,
235
+ sampleCount: this.props.samples
236
+ });
237
+ }
238
+ /**
239
+ * Set default sampler
240
+ * Accept a sampler instance or set of props;
241
+ */
242
+ setSampler(sampler) {
243
+ this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
244
+ return this;
245
+ }
246
+ setData(options) {
247
+ return this.setImage({ source: options.data });
248
+ }
249
+ /** Set image */
250
+ setImage(options) {
251
+ const { source, width = options.source.width, height = options.source.height, depth = 1, sourceX = 0, sourceY = 0, mipLevel = 0, x = 0, y = 0, z = 0, aspect = "all", colorSpace = "srgb", premultipliedAlpha = false } = options;
252
+ this.device.handle.queue.copyExternalImageToTexture(
253
+ // source: GPUImageCopyExternalImage
254
+ {
255
+ source,
256
+ origin: [sourceX, sourceY]
257
+ },
258
+ // destination: GPUImageCopyTextureTagged
259
+ {
260
+ texture: this.handle,
261
+ origin: [x, y, z],
262
+ mipLevel,
263
+ aspect,
264
+ colorSpace,
265
+ premultipliedAlpha
266
+ },
267
+ // copySize: GPUExtent3D
268
+ [width, height, depth]
269
+ );
270
+ return { width, height };
271
+ }
272
+ };
273
+
274
+ // dist/adapter/resources/webgpu-external-texture.js
275
+ var import_core5 = require("@luma.gl/core");
276
+ var WebGPUExternalTexture = class extends import_core5.ExternalTexture {
277
+ device;
278
+ handle;
279
+ sampler;
280
+ constructor(device, props) {
281
+ super(device, props);
282
+ this.device = device;
283
+ this.handle = this.props.handle || this.device.handle.importExternalTexture({
284
+ source: props.source,
285
+ colorSpace: props.colorSpace
286
+ });
287
+ this.sampler = null;
288
+ }
289
+ destroy() {
290
+ this.handle = null;
291
+ }
292
+ /** Set default sampler */
293
+ setSampler(sampler) {
294
+ this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
295
+ return this;
296
+ }
297
+ };
298
+
299
+ // dist/adapter/resources/webgpu-shader.js
300
+ var import_core6 = require("@luma.gl/core");
301
+ var WebGPUShader = class extends import_core6.Shader {
302
+ device;
303
+ handle;
304
+ constructor(device, props) {
305
+ super(device, props);
306
+ this.device = device;
307
+ this.device.handle.pushErrorScope("validation");
308
+ this.handle = this.props.handle || this.createHandle();
309
+ this.handle.label = this.props.id;
310
+ this._checkCompilationError(this.device.handle.popErrorScope());
311
+ }
312
+ async _checkCompilationError(errorScope) {
313
+ const error = await errorScope;
314
+ if (error) {
315
+ this.debugShader();
316
+ const shaderLog = await this.getCompilationInfo();
317
+ import_core6.log.error(`Shader compilation error: ${error.message}`, shaderLog)();
318
+ throw new Error(`Shader compilation error: ${error.message}`);
319
+ }
320
+ }
321
+ destroy() {
322
+ this.handle = null;
323
+ }
324
+ /** Returns compilation info for this shader */
325
+ async getCompilationInfo() {
326
+ const compilationInfo = await this.handle.getCompilationInfo();
327
+ return compilationInfo.messages;
328
+ }
329
+ // PRIVATE METHODS
330
+ createHandle() {
331
+ const { source } = this.props;
332
+ const isGLSL = source.includes("#version");
333
+ if (this.props.language === "glsl" || isGLSL) {
334
+ throw new Error("GLSL shaders are not supported in WebGPU");
335
+ }
336
+ return this.device.handle.createShaderModule({ code: source });
337
+ }
338
+ };
339
+
340
+ // dist/adapter/resources/webgpu-render-pipeline.js
341
+ var import_core9 = require("@luma.gl/core");
342
+
343
+ // dist/adapter/helpers/webgpu-parameters.js
344
+ function addDepthStencil(descriptor) {
345
+ descriptor.depthStencil = descriptor.depthStencil || {
346
+ // required, set something
347
+ format: "depth24plus",
348
+ stencilFront: {},
349
+ stencilBack: {},
350
+ // TODO can this cause trouble? Should we set to WebGPU defaults? Are there defaults?
351
+ depthWriteEnabled: false,
352
+ depthCompare: "less-equal"
353
+ };
354
+ return descriptor.depthStencil;
355
+ }
356
+ var PARAMETER_TABLE = {
357
+ // RASTERIZATION PARAMETERS
358
+ cullMode: (parameter, value, descriptor) => {
359
+ descriptor.primitive = descriptor.primitive || {};
360
+ descriptor.primitive.cullMode = value;
361
+ },
362
+ frontFace: (parameter, value, descriptor) => {
363
+ descriptor.primitive = descriptor.primitive || {};
364
+ descriptor.primitive.frontFace = value;
365
+ },
366
+ // DEPTH
367
+ depthWriteEnabled: (parameter, value, descriptor) => {
368
+ const depthStencil = addDepthStencil(descriptor);
369
+ depthStencil.depthWriteEnabled = value;
370
+ },
371
+ depthCompare: (parameter, value, descriptor) => {
372
+ const depthStencil = addDepthStencil(descriptor);
373
+ depthStencil.depthCompare = value;
374
+ },
375
+ depthFormat: (parameter, value, descriptor) => {
376
+ const depthStencil = addDepthStencil(descriptor);
377
+ depthStencil.format = value;
378
+ },
379
+ depthBias: (parameter, value, descriptor) => {
380
+ const depthStencil = addDepthStencil(descriptor);
381
+ depthStencil.depthBias = value;
382
+ },
383
+ depthBiasSlopeScale: (parameter, value, descriptor) => {
384
+ const depthStencil = addDepthStencil(descriptor);
385
+ depthStencil.depthBiasSlopeScale = value;
386
+ },
387
+ depthBiasClamp: (parameter, value, descriptor) => {
388
+ const depthStencil = addDepthStencil(descriptor);
389
+ depthStencil.depthBiasClamp = value;
390
+ },
391
+ // STENCIL
392
+ stencilReadMask: (parameter, value, descriptor) => {
393
+ const depthStencil = addDepthStencil(descriptor);
394
+ depthStencil.stencilReadMask = value;
395
+ },
396
+ stencilWriteMask: (parameter, value, descriptor) => {
397
+ const depthStencil = addDepthStencil(descriptor);
398
+ depthStencil.stencilWriteMask = value;
399
+ },
400
+ stencilCompare: (parameter, value, descriptor) => {
401
+ const depthStencil = addDepthStencil(descriptor);
402
+ depthStencil.stencilFront.compare = value;
403
+ depthStencil.stencilBack.compare = value;
404
+ },
405
+ stencilPassOperation: (parameter, value, descriptor) => {
406
+ const depthStencil = addDepthStencil(descriptor);
407
+ depthStencil.stencilFront.passOp = value;
408
+ depthStencil.stencilBack.passOp = value;
409
+ },
410
+ stencilFailOperation: (parameter, value, descriptor) => {
411
+ const depthStencil = addDepthStencil(descriptor);
412
+ depthStencil.stencilFront.failOp = value;
413
+ depthStencil.stencilBack.failOp = value;
414
+ },
415
+ stencilDepthFailOperation: (parameter, value, descriptor) => {
416
+ const depthStencil = addDepthStencil(descriptor);
417
+ depthStencil.stencilFront.depthFailOp = value;
418
+ depthStencil.stencilBack.depthFailOp = value;
419
+ },
420
+ // MULTISAMPLE
421
+ sampleCount: (parameter, value, descriptor) => {
422
+ descriptor.multisample = descriptor.multisample || {};
423
+ descriptor.multisample.count = value;
424
+ },
425
+ sampleMask: (parameter, value, descriptor) => {
426
+ descriptor.multisample = descriptor.multisample || {};
427
+ descriptor.multisample.mask = value;
428
+ },
429
+ sampleAlphaToCoverageEnabled: (parameter, value, descriptor) => {
430
+ descriptor.multisample = descriptor.multisample || {};
431
+ descriptor.multisample.alphaToCoverageEnabled = value;
432
+ },
433
+ // COLOR
434
+ colorMask: (parameter, value, descriptor) => {
435
+ const targets = addColorState(descriptor);
436
+ targets[0].writeMask = value;
437
+ },
438
+ blendColorOperation: (parameter, value, descriptor) => {
439
+ addColorState(descriptor);
440
+ }
441
+ /*
442
+ blendColorSrcTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
443
+ addColorState(descriptor);
444
+ targets[0].blend = targets[0].blend || {};
445
+ targets[0].blend.color = targets[0].blend.color || {};
446
+ targets[0].blend.color.srcTarget = value;
447
+ },
448
+
449
+ blendColorDstTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
450
+ addColorState(descriptor);
451
+ targets[0].blend = targets[0].blend || {};
452
+ targets[0].blend.color = targets[0].blend.color || {};
453
+ targets[0].blend.color.dstTarget = value;
454
+ },
455
+
456
+ blendAlphaOperation: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
457
+ addColorState(descriptor);
458
+ targets[0].blend = targets[0].blend || {};
459
+ targets[0].blend.alpha = targets[0].blend.alpha || {};
460
+ targets[0].blend.alpha.operation = value;
461
+ },
462
+
463
+ blendAlphaSrcTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
464
+ addColorState(descriptor);
465
+ targets[0].blend = targets[0].blend || {};
466
+ targets[0].blend.alpha = targets[0].blend.alpha || {};
467
+ targets[0].blend.alpha.srcTarget = value;
468
+ },
469
+
470
+ blendAlphaDstTarget: (parameter, value, descriptor: GPURenderPipelineDescriptor) => {
471
+ addColorState(descriptor);
472
+ targets[0].blend = targets[0].blend || {};
473
+ targets[0].blend.alpha = targets[0].blend.alpha || {};
474
+ targets[0].blend.alpha.dstTarget = value;
475
+ },
476
+ */
477
+ };
478
+ var DEFAULT_PIPELINE_DESCRIPTOR = {
479
+ // depthStencil: {
480
+ // stencilFront: {},
481
+ // stencilBack: {},
482
+ // // depthWriteEnabled: true,
483
+ // // depthCompare: 'less',
484
+ // // format: 'depth24plus-stencil8',
485
+ // },
486
+ primitive: {
487
+ cullMode: "back",
488
+ topology: "triangle-list"
489
+ },
490
+ vertex: {
491
+ module: void 0,
492
+ entryPoint: "main"
493
+ },
494
+ fragment: {
495
+ module: void 0,
496
+ entryPoint: "main",
497
+ targets: [
498
+ // { format: props.color0Format || 'bgra8unorm' }
499
+ ]
500
+ },
501
+ layout: "auto"
502
+ };
503
+ function applyParametersToRenderPipelineDescriptor(pipelineDescriptor, parameters = {}) {
504
+ Object.assign(pipelineDescriptor, { ...DEFAULT_PIPELINE_DESCRIPTOR, ...pipelineDescriptor });
505
+ setParameters(pipelineDescriptor, parameters);
506
+ }
507
+ function setParameters(pipelineDescriptor, parameters) {
508
+ for (const [key, value] of Object.entries(parameters)) {
509
+ const setterFunction = PARAMETER_TABLE[key];
510
+ if (!setterFunction) {
511
+ throw new Error(`Illegal parameter ${key}`);
512
+ }
513
+ setterFunction(key, value, pipelineDescriptor);
514
+ }
515
+ }
516
+ function addColorState(descriptor) {
517
+ var _a, _b, _c, _d, _e, _f;
518
+ descriptor.fragment.targets = ((_a = descriptor.fragment) == null ? void 0 : _a.targets) || [];
519
+ if (!Array.isArray((_b = descriptor.fragment) == null ? void 0 : _b.targets)) {
520
+ throw new Error("colorstate");
521
+ }
522
+ if (((_d = (_c = descriptor.fragment) == null ? void 0 : _c.targets) == null ? void 0 : _d.length) === 0) {
523
+ (_e = descriptor.fragment.targets) == null ? void 0 : _e.push({});
524
+ }
525
+ return (_f = descriptor.fragment) == null ? void 0 : _f.targets;
526
+ }
527
+
528
+ // dist/adapter/helpers/get-bind-group.js
529
+ var import_core7 = require("@luma.gl/core");
530
+ function getBindGroup(device, bindGroupLayout, shaderLayout, bindings) {
531
+ const entries = getBindGroupEntries(bindings, shaderLayout);
532
+ return device.createBindGroup({
533
+ layout: bindGroupLayout,
534
+ entries
535
+ });
536
+ }
537
+ function getShaderLayoutBinding(shaderLayout, bindingName) {
538
+ const bindingLayout = shaderLayout.bindings.find((binding) => binding.name === bindingName || `${binding.name}uniforms` === bindingName.toLocaleLowerCase());
539
+ if (!bindingLayout) {
540
+ import_core7.log.warn(`Binding ${bindingName} not set: Not found in shader layout.`)();
541
+ }
542
+ return bindingLayout;
543
+ }
544
+ function getBindGroupEntries(bindings, shaderLayout) {
545
+ const entries = [];
546
+ for (const [bindingName, value] of Object.entries(bindings)) {
547
+ const bindingLayout = getShaderLayoutBinding(shaderLayout, bindingName);
548
+ if (bindingLayout) {
549
+ entries.push(getBindGroupEntry(value, bindingLayout.location));
550
+ }
551
+ }
552
+ return entries;
553
+ }
554
+ function getBindGroupEntry(binding, index) {
555
+ if (binding instanceof import_core7.Buffer) {
556
+ return {
557
+ binding: index,
558
+ resource: {
559
+ buffer: (0, import_core7.cast)(binding).handle
560
+ }
561
+ };
562
+ }
563
+ if (binding instanceof import_core7.Sampler) {
564
+ return {
565
+ binding: index,
566
+ resource: (0, import_core7.cast)(binding).handle
567
+ };
568
+ } else if (binding instanceof import_core7.Texture) {
569
+ return {
570
+ binding: index,
571
+ resource: (0, import_core7.cast)(binding).handle.createView({ label: "bind-group-auto-created" })
572
+ };
573
+ }
574
+ throw new Error("invalid binding");
575
+ }
576
+
577
+ // dist/adapter/helpers/get-vertex-buffer-layout.js
578
+ var import_core8 = require("@luma.gl/core");
579
+ function getWebGPUVertexFormat(format) {
580
+ if (format.endsWith("-webgl")) {
581
+ throw new Error(`WebGPU does not support vertex format ${format}`);
582
+ }
583
+ return format;
584
+ }
585
+ function getVertexBufferLayout(shaderLayout, bufferLayout) {
586
+ const vertexBufferLayouts = [];
587
+ const usedAttributes = /* @__PURE__ */ new Set();
588
+ for (const mapping of bufferLayout) {
589
+ const vertexAttributes = [];
590
+ let stepMode = "vertex";
591
+ let byteStride = 0;
592
+ if (mapping.attributes) {
593
+ for (const attributeMapping of mapping.attributes) {
594
+ const attributeName = attributeMapping.attribute;
595
+ const attributeLayout = findAttributeLayout(shaderLayout, attributeName, usedAttributes);
596
+ stepMode = attributeLayout.stepMode || (attributeLayout.name.startsWith("instance") ? "instance" : "vertex");
597
+ vertexAttributes.push({
598
+ format: getWebGPUVertexFormat(attributeMapping.format || mapping.format),
599
+ offset: attributeMapping.byteOffset,
600
+ shaderLocation: attributeLayout.location
601
+ });
602
+ byteStride += (0, import_core8.decodeVertexFormat)(mapping.format).byteLength;
603
+ }
604
+ } else {
605
+ const attributeLayout = findAttributeLayout(shaderLayout, mapping.name, usedAttributes);
606
+ if (!attributeLayout) {
607
+ continue;
608
+ }
609
+ byteStride = (0, import_core8.decodeVertexFormat)(mapping.format).byteLength;
610
+ stepMode = attributeLayout.stepMode || (attributeLayout.name.startsWith("instance") ? "instance" : "vertex");
611
+ vertexAttributes.push({
612
+ format: getWebGPUVertexFormat(mapping.format),
613
+ // We only support 0 offset for non-interleaved buffer layouts
614
+ offset: 0,
615
+ shaderLocation: attributeLayout.location
616
+ });
617
+ }
618
+ vertexBufferLayouts.push({
619
+ arrayStride: mapping.byteStride || byteStride,
620
+ stepMode,
621
+ attributes: vertexAttributes
622
+ });
623
+ }
624
+ for (const attribute of shaderLayout.attributes) {
625
+ if (!usedAttributes.has(attribute.name)) {
626
+ vertexBufferLayouts.push({
627
+ arrayStride: (0, import_core8.decodeVertexFormat)("float32x3").byteLength,
628
+ stepMode: attribute.stepMode || (attribute.name.startsWith("instance") ? "instance" : "vertex"),
629
+ attributes: [
630
+ {
631
+ format: getWebGPUVertexFormat("float32x3"),
632
+ offset: 0,
633
+ shaderLocation: attribute.location
634
+ }
635
+ ]
636
+ });
637
+ }
638
+ }
639
+ return vertexBufferLayouts;
640
+ }
641
+ function findAttributeLayout(shaderLayout, name, attributeNames) {
642
+ const attribute = shaderLayout.attributes.find((attribute2) => attribute2.name === name);
643
+ if (!attribute) {
644
+ import_core8.log.warn(`Unknown attribute ${name}`)();
645
+ return null;
646
+ }
647
+ if (attributeNames.has(name)) {
648
+ throw new Error(`Duplicate attribute ${name}`);
649
+ }
650
+ attributeNames.add(name);
651
+ return attribute;
652
+ }
653
+
654
+ // dist/adapter/resources/webgpu-render-pipeline.js
655
+ var WebGPURenderPipeline = class extends import_core9.RenderPipeline {
656
+ device;
657
+ handle;
658
+ vs;
659
+ fs = null;
660
+ /** For internal use to create BindGroups */
661
+ _bindings;
662
+ _bindGroupLayout = null;
663
+ _bindGroup = null;
664
+ constructor(device, props) {
665
+ super(device, props);
666
+ this.device = device;
667
+ this.handle = this.props.handle;
668
+ if (!this.handle) {
669
+ const descriptor = this._getRenderPipelineDescriptor();
670
+ import_core9.log.groupCollapsed(1, `new WebGPURenderPipeline(${this.id})`)();
671
+ import_core9.log.probe(1, JSON.stringify(descriptor, null, 2))();
672
+ import_core9.log.groupEnd(1)();
673
+ this.handle = this.device.handle.createRenderPipeline(descriptor);
674
+ }
675
+ this.handle.label = this.props.id;
676
+ this.vs = (0, import_core9.cast)(props.vs);
677
+ this.fs = (0, import_core9.cast)(props.fs);
678
+ this._bindings = { ...this.props.bindings };
679
+ }
680
+ destroy() {
681
+ this.handle = null;
682
+ }
683
+ /**
684
+ * @todo Use renderpass.setBindings() ?
685
+ * @todo Do we want to expose BindGroups in the API and remove this?
686
+ */
687
+ setBindings(bindings) {
688
+ Object.assign(this._bindings, bindings);
689
+ }
690
+ /** @todo - should this be moved to renderpass? */
691
+ draw(options) {
692
+ const webgpuRenderPass = options.renderPass;
693
+ webgpuRenderPass.handle.setPipeline(this.handle);
694
+ const bindGroup = this._getBindGroup();
695
+ if (bindGroup) {
696
+ webgpuRenderPass.handle.setBindGroup(0, bindGroup);
697
+ }
698
+ options.vertexArray.bindBeforeRender(options.renderPass);
699
+ if (options.indexCount) {
700
+ webgpuRenderPass.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
701
+ } else {
702
+ webgpuRenderPass.handle.draw(
703
+ options.vertexCount || 0,
704
+ options.instanceCount || 1,
705
+ // If 0, nothing will be drawn
706
+ options.firstInstance
707
+ );
708
+ }
709
+ options.vertexArray.unbindAfterRender(options.renderPass);
710
+ return true;
711
+ }
712
+ /** Return a bind group created by setBindings */
713
+ _getBindGroup() {
714
+ if (this.props.shaderLayout.bindings.length === 0) {
715
+ return null;
716
+ }
717
+ this._bindGroupLayout = this._bindGroupLayout || this.handle.getBindGroupLayout(0);
718
+ this._bindGroup = this._bindGroup || getBindGroup(this.device.handle, this._bindGroupLayout, this.props.shaderLayout, this._bindings);
719
+ return this._bindGroup;
720
+ }
721
+ /**
722
+ * Populate the complex WebGPU GPURenderPipelineDescriptor
723
+ */
724
+ _getRenderPipelineDescriptor() {
725
+ var _a, _b;
726
+ const vertex = {
727
+ module: (0, import_core9.cast)(this.props.vs).handle,
728
+ entryPoint: this.props.vertexEntryPoint || "main",
729
+ buffers: getVertexBufferLayout(this.props.shaderLayout, this.props.bufferLayout)
730
+ };
731
+ const fragment = {
732
+ module: (0, import_core9.cast)(this.props.fs).handle,
733
+ entryPoint: this.props.fragmentEntryPoint || "main",
734
+ targets: [
735
+ {
736
+ // TODO exclamation mark hack!
737
+ format: getWebGPUTextureFormat((_b = (_a = this.device) == null ? void 0 : _a.canvasContext) == null ? void 0 : _b.format)
738
+ }
739
+ ]
740
+ };
741
+ switch (this.props.topology) {
742
+ case "triangle-fan-webgl":
743
+ case "line-loop-webgl":
744
+ throw new Error(`WebGPU does not support primitive topology ${this.props.topology}`);
745
+ default:
746
+ }
747
+ const descriptor = {
748
+ vertex,
749
+ fragment,
750
+ primitive: {
751
+ topology: this.props.topology
752
+ },
753
+ layout: "auto"
754
+ };
755
+ applyParametersToRenderPipelineDescriptor(descriptor, this.props.parameters);
756
+ return descriptor;
757
+ }
758
+ };
759
+
760
+ // dist/adapter/resources/webgpu-framebuffer.js
761
+ var import_core10 = require("@luma.gl/core");
762
+ var WebGPUFramebuffer = class extends import_core10.Framebuffer {
763
+ device;
764
+ constructor(device, props) {
765
+ super(device, props);
766
+ this.device = device;
767
+ this.autoCreateAttachmentTextures();
768
+ }
769
+ };
770
+
771
+ // dist/adapter/resources/webgpu-compute-pipeline.js
772
+ var import_core11 = require("@luma.gl/core");
773
+ var WebGPUComputePipeline = class extends import_core11.ComputePipeline {
774
+ device;
775
+ handle;
776
+ /** For internal use to create BindGroups */
777
+ _bindGroupLayout = null;
778
+ _bindGroup = null;
779
+ /** For internal use to create BindGroups */
780
+ _bindings = {};
781
+ constructor(device, props) {
782
+ super(device, props);
783
+ this.device = device;
784
+ const webgpuShader = this.props.shader;
785
+ this.handle = this.props.handle || this.device.handle.createComputePipeline({
786
+ label: this.props.id,
787
+ compute: {
788
+ module: webgpuShader.handle,
789
+ entryPoint: this.props.entryPoint,
790
+ constants: this.props.constants
791
+ },
792
+ layout: "auto"
793
+ });
794
+ }
795
+ /**
796
+ * @todo Use renderpass.setBindings() ?
797
+ * @todo Do we want to expose BindGroups in the API and remove this?
798
+ */
799
+ setBindings(bindings) {
800
+ Object.assign(this._bindings, bindings);
801
+ }
802
+ /** Return a bind group created by setBindings */
803
+ _getBindGroup() {
804
+ this._bindGroupLayout = this._bindGroupLayout || this.handle.getBindGroupLayout(0);
805
+ this._bindGroup = this._bindGroup || getBindGroup(this.device.handle, this._bindGroupLayout, this.props.shaderLayout, this._bindings);
806
+ return this._bindGroup;
807
+ }
808
+ };
809
+
810
+ // dist/adapter/resources/webgpu-render-pass.js
811
+ var import_core12 = require("@luma.gl/core");
812
+ var WebGPURenderPass = class extends import_core12.RenderPass {
813
+ device;
814
+ handle;
815
+ /** Active pipeline */
816
+ pipeline = null;
817
+ constructor(device, props = {}) {
818
+ super(device, props);
819
+ this.device = device;
820
+ const framebuffer = props.framebuffer || device.canvasContext.getCurrentFramebuffer();
821
+ const renderPassDescriptor = this.getRenderPassDescriptor(framebuffer);
822
+ const webgpuQuerySet = props.timestampQuerySet;
823
+ if (webgpuQuerySet) {
824
+ renderPassDescriptor.occlusionQuerySet = webgpuQuerySet.handle;
825
+ }
826
+ if (device.features.has("timestamp-query")) {
827
+ const webgpuQuerySet2 = props.timestampQuerySet;
828
+ renderPassDescriptor.timestampWrites = webgpuQuerySet2 ? {
829
+ querySet: webgpuQuerySet2.handle,
830
+ beginningOfPassWriteIndex: props.beginTimestampIndex,
831
+ endOfPassWriteIndex: props.endTimestampIndex
832
+ } : void 0;
833
+ }
834
+ this.handle = this.props.handle || device.commandEncoder.beginRenderPass(renderPassDescriptor);
835
+ this.handle.label = this.props.id;
836
+ import_core12.log.groupCollapsed(3, `new WebGPURenderPass(${this.id})`)();
837
+ import_core12.log.probe(3, JSON.stringify(renderPassDescriptor, null, 2))();
838
+ import_core12.log.groupEnd(3)();
839
+ }
840
+ destroy() {
841
+ }
842
+ end() {
843
+ this.handle.end();
844
+ }
845
+ setPipeline(pipeline) {
846
+ this.pipeline = (0, import_core12.cast)(pipeline);
847
+ this.handle.setPipeline(this.pipeline.handle);
848
+ }
849
+ /** Sets an array of bindings (uniform buffers, samplers, textures, ...) */
850
+ setBindings(bindings) {
851
+ var _a, _b;
852
+ (_a = this.pipeline) == null ? void 0 : _a.setBindings(bindings);
853
+ const bindGroup = (_b = this.pipeline) == null ? void 0 : _b._getBindGroup();
854
+ if (bindGroup) {
855
+ this.handle.setBindGroup(0, bindGroup);
856
+ }
857
+ }
858
+ setIndexBuffer(buffer, indexFormat, offset = 0, size) {
859
+ this.handle.setIndexBuffer((0, import_core12.cast)(buffer).handle, indexFormat, offset, size);
860
+ }
861
+ setVertexBuffer(slot, buffer, offset = 0) {
862
+ this.handle.setVertexBuffer(slot, (0, import_core12.cast)(buffer).handle, offset);
863
+ }
864
+ draw(options) {
865
+ if (options.indexCount) {
866
+ this.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
867
+ } else {
868
+ this.handle.draw(options.vertexCount || 0, options.instanceCount || 1, options.firstIndex, options.firstInstance);
869
+ }
870
+ }
871
+ drawIndirect() {
872
+ }
873
+ setParameters(parameters) {
874
+ const { blendConstant, stencilReference, scissorRect, viewport } = parameters;
875
+ if (blendConstant) {
876
+ this.handle.setBlendConstant(blendConstant);
877
+ }
878
+ if (stencilReference) {
879
+ this.handle.setStencilReference(stencilReference);
880
+ }
881
+ if (scissorRect) {
882
+ this.handle.setScissorRect(scissorRect[0], scissorRect[1], scissorRect[2], scissorRect[3]);
883
+ }
884
+ if (viewport) {
885
+ this.handle.setViewport(viewport[0], viewport[1], viewport[2], viewport[3], viewport[4], viewport[5]);
886
+ }
887
+ }
888
+ pushDebugGroup(groupLabel) {
889
+ this.handle.pushDebugGroup(groupLabel);
890
+ }
891
+ popDebugGroup() {
892
+ this.handle.popDebugGroup();
893
+ }
894
+ insertDebugMarker(markerLabel) {
895
+ this.handle.insertDebugMarker(markerLabel);
896
+ }
897
+ beginOcclusionQuery(queryIndex) {
898
+ this.handle.beginOcclusionQuery(queryIndex);
899
+ }
900
+ endOcclusionQuery() {
901
+ this.handle.endOcclusionQuery();
902
+ }
903
+ // executeBundles(bundles: Iterable<GPURenderBundle>): void;
904
+ // INTERNAL
905
+ /**
906
+ * Partial render pass descriptor. Used by WebGPURenderPass.
907
+ * @returns attachments fields of a renderpass descriptor.
908
+ */
909
+ getRenderPassDescriptor(framebuffer) {
910
+ const renderPassDescriptor = {
911
+ colorAttachments: []
912
+ };
913
+ renderPassDescriptor.colorAttachments = framebuffer.colorAttachments.map((colorAttachment) => ({
914
+ // clear values
915
+ loadOp: this.props.clearColor !== false ? "clear" : "load",
916
+ colorClearValue: this.props.clearColor || [0, 0, 0, 0],
917
+ storeOp: this.props.discard ? "discard" : "store",
918
+ // ...colorAttachment,
919
+ view: colorAttachment.handle
920
+ }));
921
+ if (framebuffer.depthStencilAttachment) {
922
+ renderPassDescriptor.depthStencilAttachment = {
923
+ view: framebuffer.depthStencilAttachment.handle
924
+ };
925
+ const { depthStencilAttachment } = renderPassDescriptor;
926
+ if (this.props.depthReadOnly) {
927
+ depthStencilAttachment.depthReadOnly = true;
928
+ }
929
+ depthStencilAttachment.depthClearValue = this.props.clearDepth || 0;
930
+ const hasDepthAspect = true;
931
+ if (hasDepthAspect) {
932
+ depthStencilAttachment.depthLoadOp = this.props.clearDepth !== false ? "clear" : "load";
933
+ depthStencilAttachment.depthStoreOp = "store";
934
+ }
935
+ const hasStencilAspect = false;
936
+ if (hasStencilAspect) {
937
+ depthStencilAttachment.stencilLoadOp = this.props.clearStencil !== false ? "clear" : "load";
938
+ depthStencilAttachment.stencilStoreOp = "store";
939
+ }
940
+ }
941
+ return renderPassDescriptor;
942
+ }
943
+ };
944
+
945
+ // dist/adapter/resources/webgpu-compute-pass.js
946
+ var import_core13 = require("@luma.gl/core");
947
+ var WebGPUComputePass = class extends import_core13.ComputePass {
948
+ device;
949
+ handle;
950
+ _webgpuPipeline = null;
951
+ constructor(device, props) {
952
+ var _a;
953
+ super(device, props);
954
+ this.device = device;
955
+ let timestampWrites;
956
+ if (device.features.has("timestamp-query")) {
957
+ const webgpuQuerySet = props.timestampQuerySet;
958
+ if (webgpuQuerySet) {
959
+ timestampWrites = {
960
+ querySet: webgpuQuerySet.handle,
961
+ beginningOfPassWriteIndex: props.beginTimestampIndex,
962
+ endOfPassWriteIndex: props.endTimestampIndex
963
+ };
964
+ }
965
+ }
966
+ this.handle = this.props.handle || ((_a = device.commandEncoder) == null ? void 0 : _a.beginComputePass({
967
+ label: this.props.id,
968
+ timestampWrites
969
+ }));
970
+ }
971
+ /** @note no WebGPU destroy method, just gc */
972
+ destroy() {
973
+ }
974
+ end() {
975
+ this.handle.end();
976
+ }
977
+ setPipeline(pipeline) {
978
+ const wgpuPipeline = pipeline;
979
+ this.handle.setPipeline(wgpuPipeline.handle);
980
+ this._webgpuPipeline = wgpuPipeline;
981
+ this.setBindings([]);
982
+ }
983
+ /**
984
+ * Sets an array of bindings (uniform buffers, samplers, textures, ...)
985
+ * TODO - still some API confusion - does this method go here or on the pipeline?
986
+ */
987
+ setBindings(bindings) {
988
+ const bindGroup = this._webgpuPipeline._getBindGroup();
989
+ this.handle.setBindGroup(0, bindGroup);
990
+ }
991
+ /**
992
+ * Dispatch work to be performed with the current ComputePipeline.
993
+ * @param x X dimension of the grid of work groups to dispatch.
994
+ * @param y Y dimension of the grid of work groups to dispatch.
995
+ * @param z Z dimension of the grid of work groups to dispatch.
996
+ */
997
+ dispatch(x, y, z) {
998
+ this.handle.dispatchWorkgroups(x, y, z);
999
+ }
1000
+ /**
1001
+ * Dispatch work to be performed with the current ComputePipeline.
1002
+ *
1003
+ * 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()
1004
+ * @param indirectBuffer
1005
+ * @param indirectOffset offset in buffer to the beginning of the dispatch data.
1006
+ */
1007
+ dispatchIndirect(indirectBuffer, indirectByteOffset = 0) {
1008
+ const webgpuBuffer = indirectBuffer;
1009
+ this.handle.dispatchWorkgroupsIndirect(webgpuBuffer.handle, indirectByteOffset);
1010
+ }
1011
+ pushDebugGroup(groupLabel) {
1012
+ this.handle.pushDebugGroup(groupLabel);
1013
+ }
1014
+ popDebugGroup() {
1015
+ this.handle.popDebugGroup();
1016
+ }
1017
+ insertDebugMarker(markerLabel) {
1018
+ this.handle.insertDebugMarker(markerLabel);
1019
+ }
1020
+ };
1021
+
1022
+ // dist/adapter/resources/webgpu-vertex-array.js
1023
+ var import_core14 = require("@luma.gl/core");
1024
+ var import_env = require("@probe.gl/env");
1025
+ var WebGPUVertexArray = class extends import_core14.VertexArray {
1026
+ get [Symbol.toStringTag]() {
1027
+ return "WebGPUVertexArray";
1028
+ }
1029
+ device;
1030
+ /** Vertex Array is a helper class under WebGPU */
1031
+ handle;
1032
+ // Create a VertexArray
1033
+ constructor(device, props) {
1034
+ super(device, props);
1035
+ this.device = device;
1036
+ }
1037
+ destroy() {
1038
+ }
1039
+ /**
1040
+ * Set an elements buffer, for indexed rendering.
1041
+ * Must be a Buffer bound to buffer with usage bit Buffer.INDEX set.
1042
+ */
1043
+ setIndexBuffer(buffer) {
1044
+ this.indexBuffer = buffer;
1045
+ }
1046
+ /** Set a bufferSlot in vertex attributes array to a buffer, enables the bufferSlot, sets divisor */
1047
+ setBuffer(bufferSlot, buffer) {
1048
+ this.attributes[bufferSlot] = buffer;
1049
+ }
1050
+ bindBeforeRender(renderPass, firstIndex, indexCount) {
1051
+ const webgpuRenderPass = renderPass;
1052
+ const webgpuIndexBuffer = this.indexBuffer;
1053
+ if (webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle) {
1054
+ import_core14.log.warn("setting index buffer", webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle, webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.indexType)();
1055
+ webgpuRenderPass.handle.setIndexBuffer(webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle, webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.indexType);
1056
+ }
1057
+ for (let location = 0; location < this.maxVertexAttributes; location++) {
1058
+ const webgpuBuffer = this.attributes[location];
1059
+ if (webgpuBuffer == null ? void 0 : webgpuBuffer.handle) {
1060
+ import_core14.log.warn(`setting vertex buffer ${location}`, webgpuBuffer == null ? void 0 : webgpuBuffer.handle)();
1061
+ webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer == null ? void 0 : webgpuBuffer.handle);
1062
+ }
1063
+ }
1064
+ }
1065
+ unbindAfterRender(renderPass) {
1066
+ }
1067
+ // DEPRECATED METHODS
1068
+ /**
1069
+ * @deprecated is this even an issue for WebGPU?
1070
+ * Attribute 0 can not be disable on most desktop OpenGL based browsers
1071
+ */
1072
+ static isConstantAttributeZeroSupported(device) {
1073
+ return (0, import_env.getBrowser)() === "Chrome";
1074
+ }
1075
+ };
1076
+
1077
+ // dist/adapter/webgpu-canvas-context.js
1078
+ var import_core15 = require("@luma.gl/core");
1079
+ var WebGPUCanvasContext = class extends import_core15.CanvasContext {
1080
+ device;
1081
+ gpuCanvasContext;
1082
+ /** Format of returned textures: "bgra8unorm", "rgba8unorm", "rgba16float". */
1083
+ format = navigator.gpu.getPreferredCanvasFormat();
1084
+ /** Default stencil format for depth textures */
1085
+ depthStencilFormat = "depth24plus";
1086
+ depthStencilAttachment = null;
1087
+ constructor(device, adapter, props) {
1088
+ super(props);
1089
+ this.device = device;
1090
+ this.width = -1;
1091
+ this.height = -1;
1092
+ this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
1093
+ this.gpuCanvasContext = this.canvas.getContext("webgpu");
1094
+ this.format = "bgra8unorm";
1095
+ }
1096
+ /** Destroy any textures produced while configured and remove the context configuration. */
1097
+ destroy() {
1098
+ this.gpuCanvasContext.unconfigure();
1099
+ }
1100
+ /** Update framebuffer with properly resized "swap chain" texture views */
1101
+ getCurrentFramebuffer() {
1102
+ this.update();
1103
+ const currentColorAttachment = this.getCurrentTexture();
1104
+ this.width = currentColorAttachment.width;
1105
+ this.height = currentColorAttachment.height;
1106
+ this._createDepthStencilAttachment();
1107
+ return new WebGPUFramebuffer(this.device, {
1108
+ colorAttachments: [currentColorAttachment],
1109
+ depthStencilAttachment: this.depthStencilAttachment
1110
+ });
1111
+ }
1112
+ /** Resizes and updates render targets if necessary */
1113
+ update() {
1114
+ const [width, height] = this.getPixelSize();
1115
+ const sizeChanged = width !== this.width || height !== this.height;
1116
+ if (sizeChanged) {
1117
+ this.width = width;
1118
+ this.height = height;
1119
+ if (this.depthStencilAttachment) {
1120
+ this.depthStencilAttachment.destroy();
1121
+ this.depthStencilAttachment = null;
1122
+ }
1123
+ this.gpuCanvasContext.configure({
1124
+ device: this.device.handle,
1125
+ format: getWebGPUTextureFormat(this.format),
1126
+ // Can be used to define e.g. -srgb views
1127
+ // viewFormats: [...]
1128
+ colorSpace: this.props.colorSpace,
1129
+ alphaMode: this.props.alphaMode
1130
+ });
1131
+ import_core15.log.log(1, `Resized to ${this.width}x${this.height}px`)();
1132
+ }
1133
+ }
1134
+ resize(options) {
1135
+ this.update();
1136
+ }
1137
+ /** Wrap the current canvas context texture in a luma.gl texture */
1138
+ getCurrentTexture() {
1139
+ return this.device._createTexture({
1140
+ id: `${this.id}#color-texture`,
1141
+ handle: this.gpuCanvasContext.getCurrentTexture(),
1142
+ format: this.format
1143
+ });
1144
+ }
1145
+ /** We build render targets on demand (i.e. not when size changes but when about to render) */
1146
+ _createDepthStencilAttachment() {
1147
+ if (!this.depthStencilAttachment) {
1148
+ this.depthStencilAttachment = this.device.createTexture({
1149
+ id: `${this.id}#depth-stencil-texture`,
1150
+ format: this.depthStencilFormat,
1151
+ width: this.width,
1152
+ height: this.height,
1153
+ usage: GPUTextureUsage.RENDER_ATTACHMENT
1154
+ });
1155
+ }
1156
+ return this.depthStencilAttachment;
1157
+ }
1158
+ };
1159
+
1160
+ // dist/adapter/resources/webgpu-query-set.js
1161
+ var import_core16 = require("@luma.gl/core");
1162
+ var WebGPUQuerySet = class extends import_core16.QuerySet {
1163
+ device;
1164
+ handle;
1165
+ constructor(device, props) {
1166
+ super(device, props);
1167
+ this.device = device;
1168
+ this.handle = this.props.handle || this.device.handle.createQuerySet({
1169
+ type: this.props.type,
1170
+ count: this.props.count
1171
+ });
1172
+ this.handle.label = this.props.id;
1173
+ }
1174
+ destroy() {
1175
+ var _a;
1176
+ (_a = this.handle) == null ? void 0 : _a.destroy();
1177
+ this.handle = null;
1178
+ }
1179
+ };
1180
+
1181
+ // dist/adapter/webgpu-device.js
1182
+ var _WebGPUDevice = class extends import_core17.Device {
1183
+ /** type of this device */
1184
+ type = "webgpu";
1185
+ /** The underlying WebGPU device */
1186
+ handle;
1187
+ /* The underlying WebGPU adapter */
1188
+ adapter;
1189
+ /* The underlying WebGPU adapter's info */
1190
+ adapterInfo;
1191
+ features;
1192
+ info;
1193
+ limits;
1194
+ lost;
1195
+ canvasContext = null;
1196
+ _isLost = false;
1197
+ commandEncoder = null;
1198
+ renderPass = null;
1199
+ /** Check if WebGPU is available */
1200
+ static isSupported() {
1201
+ return Boolean(typeof navigator !== "undefined" && navigator.gpu);
1202
+ }
1203
+ static async create(props) {
1204
+ if (!navigator.gpu) {
1205
+ throw new Error("WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu");
1206
+ }
1207
+ import_core17.log.groupCollapsed(1, "WebGPUDevice created")();
1208
+ const adapter = await navigator.gpu.requestAdapter({
1209
+ powerPreference: "high-performance"
1210
+ // forceSoftware: false
1211
+ });
1212
+ if (!adapter) {
1213
+ throw new Error("Failed to request WebGPU adapter");
1214
+ }
1215
+ const adapterInfo = await adapter.requestAdapterInfo();
1216
+ import_core17.log.probe(2, "Adapter available", adapterInfo)();
1217
+ const requiredFeatures = [];
1218
+ const requiredLimits = {};
1219
+ if (props.requestMaxLimits) {
1220
+ requiredFeatures.push(...Array.from(adapter.features));
1221
+ for (const key in adapter.limits) {
1222
+ requiredLimits[key] = adapter.limits[key];
1223
+ }
1224
+ delete requiredLimits.minSubgroupSize;
1225
+ delete requiredLimits.maxSubgroupSize;
1226
+ }
1227
+ const gpuDevice = await adapter.requestDevice({
1228
+ requiredFeatures,
1229
+ requiredLimits
1230
+ });
1231
+ import_core17.log.probe(1, "GPUDevice available")();
1232
+ if (typeof props.canvas === "string") {
1233
+ await import_core17.CanvasContext.pageLoaded;
1234
+ import_core17.log.probe(1, "DOM is loaded")();
1235
+ }
1236
+ const device = new _WebGPUDevice(gpuDevice, adapter, adapterInfo, props);
1237
+ import_core17.log.probe(1, "Device created. For more info, set chrome://flags/#enable-webgpu-developer-features")();
1238
+ import_core17.log.table(1, device.info)();
1239
+ import_core17.log.groupEnd(1)();
1240
+ return device;
1241
+ }
1242
+ constructor(device, adapter, adapterInfo, props) {
1243
+ super({ ...props, id: props.id || (0, import_core17.uid)("webgpu-device") });
1244
+ this.handle = device;
1245
+ this.adapter = adapter;
1246
+ this.adapterInfo = adapterInfo;
1247
+ this.info = this._getInfo();
1248
+ this.features = this._getFeatures();
1249
+ this.limits = this.handle.limits;
1250
+ this.lost = new Promise(async (resolve) => {
1251
+ const lostInfo = await this.handle.lost;
1252
+ this._isLost = true;
1253
+ resolve({ reason: "destroyed", message: lostInfo.message });
1254
+ });
1255
+ this.canvasContext = new WebGPUCanvasContext(this, this.adapter, {
1256
+ canvas: props.canvas,
1257
+ height: props.height,
1258
+ width: props.width,
1259
+ container: props.container
1260
+ });
1261
+ }
1262
+ // TODO
1263
+ // Load the glslang module now so that it is available synchronously when compiling shaders
1264
+ // const {glsl = true} = props;
1265
+ // this.glslang = glsl && await loadGlslangModule();
1266
+ destroy() {
1267
+ this.handle.destroy();
1268
+ }
1269
+ isTextureFormatSupported(format) {
1270
+ return !format.includes("webgl");
1271
+ }
1272
+ /** @todo implement proper check? */
1273
+ isTextureFormatFilterable(format) {
1274
+ return this.isTextureFormatSupported(format) && !format.startsWith("depth") && !format.startsWith("stencil");
1275
+ }
1276
+ /** @todo implement proper check? */
1277
+ isTextureFormatRenderable(format) {
1278
+ return this.isTextureFormatSupported(format);
1279
+ }
1280
+ get isLost() {
1281
+ return this._isLost;
1282
+ }
1283
+ createBuffer(props) {
1284
+ const newProps = this._getBufferProps(props);
1285
+ return new WebGPUBuffer(this, newProps);
1286
+ }
1287
+ _createTexture(props) {
1288
+ return new WebGPUTexture(this, props);
1289
+ }
1290
+ createExternalTexture(props) {
1291
+ return new WebGPUExternalTexture(this, props);
1292
+ }
1293
+ createShader(props) {
1294
+ return new WebGPUShader(this, props);
1295
+ }
1296
+ createSampler(props) {
1297
+ return new WebGPUSampler(this, props);
1298
+ }
1299
+ createRenderPipeline(props) {
1300
+ return new WebGPURenderPipeline(this, props);
1301
+ }
1302
+ createFramebuffer(props) {
1303
+ return new WebGPUFramebuffer(this, props);
1304
+ }
1305
+ createComputePipeline(props) {
1306
+ return new WebGPUComputePipeline(this, props);
1307
+ }
1308
+ createVertexArray(props) {
1309
+ return new WebGPUVertexArray(this, props);
1310
+ }
1311
+ // WebGPU specifics
1312
+ /**
1313
+ * Allows a render pass to begin against a canvas context
1314
+ * @todo need to support a "Framebuffer" equivalent (aka preconfigured RenderPassDescriptors?).
1315
+ */
1316
+ beginRenderPass(props) {
1317
+ this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();
1318
+ return new WebGPURenderPass(this, props);
1319
+ }
1320
+ beginComputePass(props) {
1321
+ this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();
1322
+ return new WebGPUComputePass(this, props);
1323
+ }
1324
+ // createCommandEncoder(props: CommandEncoderProps): WebGPUCommandEncoder {
1325
+ // return new WebGPUCommandEncoder(this, props);
1326
+ // }
1327
+ createTransformFeedback(props) {
1328
+ throw new Error("Transform feedback not supported in WebGPU");
1329
+ }
1330
+ createQuerySet(props) {
1331
+ return new WebGPUQuerySet(this, props);
1332
+ }
1333
+ createCanvasContext(props) {
1334
+ return new WebGPUCanvasContext(this, this.adapter, props);
1335
+ }
1336
+ submit() {
1337
+ var _a;
1338
+ const commandBuffer = (_a = this.commandEncoder) == null ? void 0 : _a.finish();
1339
+ if (commandBuffer) {
1340
+ this.handle.queue.submit([commandBuffer]);
1341
+ }
1342
+ this.commandEncoder = null;
1343
+ }
1344
+ // PRIVATE METHODS
1345
+ _getInfo() {
1346
+ const [driver, driverVersion] = (this.adapterInfo.driver || "").split(" Version ");
1347
+ const vendor = this.adapterInfo.vendor || this.adapter.__brand || "unknown";
1348
+ const renderer = driver || "";
1349
+ const version = driverVersion || "";
1350
+ const gpu = vendor === "apple" ? "apple" : "unknown";
1351
+ const gpuArchitecture = this.adapterInfo.architecture || "unknown";
1352
+ const gpuBackend = this.adapterInfo.backend || "unknown";
1353
+ const gpuType = (this.adapterInfo.type || "").split(" ")[0].toLowerCase() || "unknown";
1354
+ return {
1355
+ type: "webgpu",
1356
+ vendor,
1357
+ renderer,
1358
+ version,
1359
+ gpu,
1360
+ gpuType,
1361
+ gpuBackend,
1362
+ gpuArchitecture,
1363
+ shadingLanguage: "wgsl",
1364
+ shadingLanguageVersion: 100
1365
+ };
1366
+ }
1367
+ _getFeatures() {
1368
+ const features = new Set(this.handle.features);
1369
+ if (features.has("depth-clamping")) {
1370
+ features.delete("depth-clamping");
1371
+ features.add("depth-clip-control");
1372
+ }
1373
+ if (features.has("texture-compression-bc")) {
1374
+ features.add("texture-compression-bc5-webgl");
1375
+ }
1376
+ const WEBGPU_ALWAYS_FEATURES = [
1377
+ "timer-query-webgl",
1378
+ "compilation-status-async-webgl",
1379
+ "float32-renderable-webgl",
1380
+ "float16-renderable-webgl",
1381
+ "norm16-renderable-webgl",
1382
+ "texture-filterable-anisotropic-webgl",
1383
+ "shader-noperspective-interpolation-webgl"
1384
+ ];
1385
+ for (const feature of WEBGPU_ALWAYS_FEATURES) {
1386
+ features.add(feature);
1387
+ }
1388
+ return new import_core17.DeviceFeatures(Array.from(features), this.props.disabledFeatures);
1389
+ }
1390
+ copyExternalImageToTexture(options) {
1391
+ var _a;
1392
+ const {
1393
+ source,
1394
+ sourceX = 0,
1395
+ sourceY = 0,
1396
+ texture,
1397
+ mipLevel = 0,
1398
+ aspect = "all",
1399
+ colorSpace = "display-p3",
1400
+ premultipliedAlpha = false,
1401
+ // destinationX,
1402
+ // destinationY,
1403
+ // desitnationZ,
1404
+ width = texture.width,
1405
+ height = texture.height,
1406
+ depth = 1
1407
+ } = options;
1408
+ const webGpuTexture = texture;
1409
+ (_a = this.handle) == null ? void 0 : _a.queue.copyExternalImageToTexture(
1410
+ // source: GPUImageCopyExternalImage
1411
+ {
1412
+ source,
1413
+ origin: [sourceX, sourceY]
1414
+ },
1415
+ // destination: GPUImageCopyTextureTagged
1416
+ {
1417
+ texture: webGpuTexture.handle,
1418
+ origin: [0, 0, 0],
1419
+ // [x, y, z],
1420
+ mipLevel,
1421
+ aspect,
1422
+ colorSpace,
1423
+ premultipliedAlpha
1424
+ },
1425
+ // copySize: GPUExtent3D
1426
+ [width, height, depth]
1427
+ );
1428
+ }
1429
+ };
1430
+ var WebGPUDevice = _WebGPUDevice;
1431
+ __publicField(WebGPUDevice, "type", "webgpu");
1432
+ //# sourceMappingURL=index.cjs.map