@luma.gl/webgpu 9.0.0-beta.4 → 9.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/helpers/accessor-to-format.js +102 -1
- package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -1
- package/dist/adapter/helpers/convert-texture-format.js +8 -5
- package/dist/adapter/helpers/generate-mipmaps.d.ts.map +1 -1
- package/dist/adapter/helpers/generate-mipmaps.js +85 -82
- package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
- package/dist/adapter/helpers/get-bind-group.js +57 -41
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.js +117 -80
- package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
- package/dist/adapter/helpers/webgpu-parameters.js +185 -125
- package/dist/adapter/resources/webgpu-buffer.d.ts +1 -1
- package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-buffer.js +117 -62
- package/dist/adapter/resources/webgpu-command-encoder.d.ts +7 -1
- package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.js +81 -49
- package/dist/adapter/resources/webgpu-compute-pass.d.ts +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.js +71 -41
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.js +28 -19
- package/dist/adapter/resources/webgpu-external-texture.d.ts +2 -2
- package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-external-texture.js +33 -18
- package/dist/adapter/resources/webgpu-framebuffer.d.ts +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.js +14 -7
- package/dist/adapter/resources/webgpu-query-set.d.ts +17 -0
- package/dist/adapter/resources/webgpu-query-set.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-query-set.js +25 -0
- package/dist/adapter/resources/webgpu-query.js +42 -1
- package/dist/adapter/resources/webgpu-render-pass.d.ts +4 -2
- package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.js +133 -105
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts +3 -4
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js +137 -80
- package/dist/adapter/resources/webgpu-sampler.d.ts +1 -1
- package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-sampler.js +18 -15
- package/dist/adapter/resources/webgpu-shader.d.ts +1 -1
- package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-shader.js +56 -45
- package/dist/adapter/resources/webgpu-texture-view.d.ts +20 -0
- package/dist/adapter/resources/webgpu-texture-view.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-texture-view.js +32 -0
- package/dist/adapter/resources/webgpu-texture.d.ts +5 -4
- package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-texture.js +130 -107
- package/dist/adapter/resources/webgpu-vertex-array.d.ts +7 -6
- package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-vertex-array.js +60 -39
- package/dist/adapter/webgpu-canvas-context.d.ts +3 -3
- package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgpu-canvas-context.js +100 -67
- package/dist/adapter/webgpu-device.d.ts +24 -21
- package/dist/adapter/webgpu-device.d.ts.map +1 -1
- package/dist/adapter/webgpu-device.js +264 -220
- package/dist/adapter/webgpu-types.js +0 -2
- package/dist/dist.dev.js +782 -2222
- package/dist/glsl/glsllang.js +9 -6
- package/dist/index.cjs +279 -388
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist.min.js +1 -22
- package/package.json +9 -7
- package/src/adapter/helpers/accessor-to-format.ts +5 -1
- package/src/adapter/helpers/convert-texture-format.ts +4 -1
- package/src/adapter/helpers/generate-mipmaps.ts +37 -26
- package/src/adapter/helpers/get-bind-group.ts +8 -2
- package/src/adapter/helpers/get-vertex-buffer-layout.ts +12 -4
- package/src/adapter/helpers/webgpu-parameters.ts +79 -15
- package/src/adapter/resources/webgpu-buffer.ts +21 -10
- package/src/adapter/resources/webgpu-command-encoder.ts +24 -9
- package/src/adapter/resources/webgpu-compute-pass.ts +26 -8
- package/src/adapter/resources/webgpu-compute-pipeline.ts +15 -10
- package/src/adapter/resources/webgpu-external-texture.ts +12 -6
- package/src/adapter/resources/webgpu-framebuffer.ts +4 -0
- package/src/adapter/resources/webgpu-query-set.ts +35 -0
- package/src/adapter/resources/webgpu-render-pass.ts +37 -14
- package/src/adapter/resources/webgpu-render-pipeline.ts +30 -41
- package/src/adapter/resources/webgpu-sampler.ts +1 -1
- package/src/adapter/resources/webgpu-shader.ts +5 -4
- package/src/adapter/resources/webgpu-texture-view.ts +43 -0
- package/src/adapter/resources/webgpu-texture.ts +23 -19
- package/src/adapter/resources/webgpu-vertex-array.ts +25 -17
- package/src/adapter/webgpu-canvas-context.ts +8 -3
- package/src/adapter/webgpu-device.ts +100 -88
- package/src/index.ts +2 -1
- package/dist/adapter/helpers/accessor-to-format.js.map +0 -1
- package/dist/adapter/helpers/convert-texture-format.js.map +0 -1
- package/dist/adapter/helpers/generate-mipmaps.js.map +0 -1
- package/dist/adapter/helpers/get-bind-group.js.map +0 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +0 -1
- package/dist/adapter/helpers/webgpu-parameters.js.map +0 -1
- package/dist/adapter/resources/webgpu-buffer.js.map +0 -1
- package/dist/adapter/resources/webgpu-command-encoder.js.map +0 -1
- package/dist/adapter/resources/webgpu-compute-pass.js.map +0 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.js.map +0 -1
- package/dist/adapter/resources/webgpu-external-texture.js.map +0 -1
- package/dist/adapter/resources/webgpu-framebuffer.js.map +0 -1
- package/dist/adapter/resources/webgpu-query.js.map +0 -1
- package/dist/adapter/resources/webgpu-render-pass.js.map +0 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js.map +0 -1
- package/dist/adapter/resources/webgpu-sampler.js.map +0 -1
- package/dist/adapter/resources/webgpu-shader.js.map +0 -1
- package/dist/adapter/resources/webgpu-texture.js.map +0 -1
- package/dist/adapter/resources/webgpu-vertex-array.js.map +0 -1
- package/dist/adapter/webgpu-canvas-context.js.map +0 -1
- package/dist/adapter/webgpu-device.js.map +0 -1
- package/dist/adapter/webgpu-types.js.map +0 -1
- package/dist/glsl/glsllang.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/src/adapter/resources/webgpu-query.ts +0 -43
- package/src/adapter/webgpu-types.ts +0 -0
- package/src/glsl/glsllang.ts +0 -14
package/dist/index.cjs
CHANGED
|
@@ -21,21 +21,21 @@ var __publicField = (obj, key, value) => {
|
|
|
21
21
|
return value;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
//
|
|
25
|
-
var
|
|
26
|
-
__export(
|
|
24
|
+
// dist/index.js
|
|
25
|
+
var dist_exports = {};
|
|
26
|
+
__export(dist_exports, {
|
|
27
27
|
WebGPUBuffer: () => WebGPUBuffer,
|
|
28
28
|
WebGPUDevice: () => WebGPUDevice,
|
|
29
29
|
WebGPUSampler: () => WebGPUSampler,
|
|
30
30
|
WebGPUShader: () => WebGPUShader,
|
|
31
31
|
WebGPUTexture: () => WebGPUTexture
|
|
32
32
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
33
|
+
module.exports = __toCommonJS(dist_exports);
|
|
34
34
|
|
|
35
|
-
//
|
|
36
|
-
var
|
|
35
|
+
// dist/adapter/webgpu-device.js
|
|
36
|
+
var import_core17 = require("@luma.gl/core");
|
|
37
37
|
|
|
38
|
-
//
|
|
38
|
+
// dist/adapter/resources/webgpu-buffer.js
|
|
39
39
|
var import_core = require("@luma.gl/core");
|
|
40
40
|
function getByteLength(props) {
|
|
41
41
|
var _a;
|
|
@@ -70,16 +70,13 @@ var WebGPUBuffer = class extends import_core.Buffer {
|
|
|
70
70
|
}
|
|
71
71
|
// WebGPU provides multiple ways to write a buffer...
|
|
72
72
|
write(data, byteOffset = 0) {
|
|
73
|
-
this.device.handle.queue.writeBuffer(
|
|
74
|
-
this.handle,
|
|
75
|
-
byteOffset,
|
|
76
|
-
data.buffer,
|
|
77
|
-
data.byteOffset,
|
|
78
|
-
data.byteLength
|
|
79
|
-
);
|
|
73
|
+
this.device.handle.queue.writeBuffer(this.handle, byteOffset, data.buffer, data.byteOffset, data.byteLength);
|
|
80
74
|
}
|
|
81
75
|
async readAsync(byteOffset = 0, byteLength = this.byteLength) {
|
|
82
|
-
const tempBuffer = new WebGPUBuffer(this.device, {
|
|
76
|
+
const tempBuffer = new WebGPUBuffer(this.device, {
|
|
77
|
+
usage: import_core.Buffer.MAP_READ | import_core.Buffer.COPY_DST,
|
|
78
|
+
byteLength
|
|
79
|
+
});
|
|
83
80
|
const commandEncoder = this.device.handle.createCommandEncoder();
|
|
84
81
|
commandEncoder.copyBufferToBuffer(this.handle, byteOffset, tempBuffer.handle, 0, byteLength);
|
|
85
82
|
this.device.handle.queue.submit([commandEncoder.finish()]);
|
|
@@ -105,10 +102,10 @@ var WebGPUBuffer = class extends import_core.Buffer {
|
|
|
105
102
|
}
|
|
106
103
|
};
|
|
107
104
|
|
|
108
|
-
//
|
|
109
|
-
var
|
|
105
|
+
// dist/adapter/resources/webgpu-texture.js
|
|
106
|
+
var import_core4 = require("@luma.gl/core");
|
|
110
107
|
|
|
111
|
-
//
|
|
108
|
+
// dist/adapter/helpers/convert-texture-format.js
|
|
112
109
|
function getWebGPUTextureFormat(format) {
|
|
113
110
|
if (format.includes("webgl")) {
|
|
114
111
|
throw new Error("webgl-only format");
|
|
@@ -116,7 +113,7 @@ function getWebGPUTextureFormat(format) {
|
|
|
116
113
|
return format;
|
|
117
114
|
}
|
|
118
115
|
|
|
119
|
-
//
|
|
116
|
+
// dist/adapter/resources/webgpu-sampler.js
|
|
120
117
|
var import_core2 = require("@luma.gl/core");
|
|
121
118
|
var WebGPUSampler = class extends import_core2.Sampler {
|
|
122
119
|
device;
|
|
@@ -135,22 +132,50 @@ var WebGPUSampler = class extends import_core2.Sampler {
|
|
|
135
132
|
}
|
|
136
133
|
};
|
|
137
134
|
|
|
138
|
-
//
|
|
135
|
+
// dist/adapter/resources/webgpu-texture-view.js
|
|
136
|
+
var import_core3 = require("@luma.gl/core");
|
|
137
|
+
var WebGPUTextureView = class extends import_core3.TextureView {
|
|
138
|
+
device;
|
|
139
|
+
handle;
|
|
140
|
+
texture;
|
|
141
|
+
constructor(device, props) {
|
|
142
|
+
super(device, props);
|
|
143
|
+
this.device = device;
|
|
144
|
+
this.texture = props.texture;
|
|
145
|
+
this.handle = this.handle || this.texture.handle.createView({
|
|
146
|
+
format: props.format || this.texture.format,
|
|
147
|
+
dimension: props.dimension || this.texture.dimension,
|
|
148
|
+
aspect: props.aspect,
|
|
149
|
+
baseMipLevel: props.baseMipLevel,
|
|
150
|
+
mipLevelCount: props.mipLevelCount,
|
|
151
|
+
// GPUIntegerCoordinate;
|
|
152
|
+
baseArrayLayer: props.baseArrayLayer,
|
|
153
|
+
// GPUIntegerCoordinate;
|
|
154
|
+
arrayLayerCount: props.arrayLayerCount
|
|
155
|
+
// GPUIntegerCoordinate;
|
|
156
|
+
});
|
|
157
|
+
this.handle.label = this.props.id;
|
|
158
|
+
}
|
|
159
|
+
destroy() {
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// dist/adapter/resources/webgpu-texture.js
|
|
139
164
|
var BASE_DIMENSIONS = {
|
|
140
165
|
"1d": "1d",
|
|
141
166
|
"2d": "2d",
|
|
142
167
|
"2d-array": "2d",
|
|
143
|
-
|
|
168
|
+
cube: "2d",
|
|
144
169
|
"cube-array": "2d",
|
|
145
170
|
"3d": "3d"
|
|
146
171
|
};
|
|
147
|
-
var WebGPUTexture = class extends
|
|
172
|
+
var WebGPUTexture = class extends import_core4.Texture {
|
|
148
173
|
device;
|
|
149
174
|
handle;
|
|
150
|
-
view;
|
|
151
|
-
sampler;
|
|
152
175
|
height = 1;
|
|
153
176
|
width = 1;
|
|
177
|
+
sampler;
|
|
178
|
+
view;
|
|
154
179
|
// static async createFromImageURL(src, usage = 0) {
|
|
155
180
|
// const img = document.createElement('img');
|
|
156
181
|
// img.src = src;
|
|
@@ -178,7 +203,7 @@ var WebGPUTexture = class extends import_core3.Texture {
|
|
|
178
203
|
this.width = this.handle.width;
|
|
179
204
|
this.height = this.handle.height;
|
|
180
205
|
this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);
|
|
181
|
-
this.view = this.
|
|
206
|
+
this.view = new WebGPUTextureView(this.device, { ...this.props, texture: this });
|
|
182
207
|
}
|
|
183
208
|
createHandle() {
|
|
184
209
|
var _a, _b;
|
|
@@ -214,21 +239,7 @@ var WebGPUTexture = class extends import_core3.Texture {
|
|
|
214
239
|
}
|
|
215
240
|
/** Set image */
|
|
216
241
|
setImage(options) {
|
|
217
|
-
const {
|
|
218
|
-
source,
|
|
219
|
-
width = options.source.width,
|
|
220
|
-
height = options.source.height,
|
|
221
|
-
depth = 1,
|
|
222
|
-
sourceX = 0,
|
|
223
|
-
sourceY = 0,
|
|
224
|
-
mipLevel = 0,
|
|
225
|
-
x = 0,
|
|
226
|
-
y = 0,
|
|
227
|
-
z = 0,
|
|
228
|
-
aspect = "all",
|
|
229
|
-
colorSpace = "srgb",
|
|
230
|
-
premultipliedAlpha = false
|
|
231
|
-
} = options;
|
|
242
|
+
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;
|
|
232
243
|
this.device.handle.queue.copyExternalImageToTexture(
|
|
233
244
|
// source: GPUImageCopyExternalImage
|
|
234
245
|
{
|
|
@@ -245,105 +256,20 @@ var WebGPUTexture = class extends import_core3.Texture {
|
|
|
245
256
|
premultipliedAlpha
|
|
246
257
|
},
|
|
247
258
|
// copySize: GPUExtent3D
|
|
248
|
-
[
|
|
249
|
-
width,
|
|
250
|
-
height,
|
|
251
|
-
depth
|
|
252
|
-
]
|
|
259
|
+
[width, height, depth]
|
|
253
260
|
);
|
|
254
261
|
return { width, height };
|
|
255
262
|
}
|
|
256
|
-
// WebGPU specific
|
|
263
|
+
// WebGPU specific
|
|
257
264
|
/** TODO - intention is to expose TextureViews in the public API */
|
|
258
265
|
createView() {
|
|
259
266
|
return this.handle.createView({ label: this.id });
|
|
260
267
|
}
|
|
261
|
-
/*
|
|
262
|
-
async readPixels() {
|
|
263
|
-
const readbackBuffer = device.createBuffer({
|
|
264
|
-
usage: Buffer.COPY_DST | Buffer.MAP_READ,
|
|
265
|
-
size: 4 * textureWidth * textureHeight,
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
// Copy data from the texture to the buffer.
|
|
269
|
-
const encoder = device.createCommandEncoder();
|
|
270
|
-
encoder.copyTextureToBuffer(
|
|
271
|
-
{ texture },
|
|
272
|
-
{ buffer, rowPitch: textureWidth * 4 },
|
|
273
|
-
[textureWidth, textureHeight],
|
|
274
|
-
);
|
|
275
|
-
device.submit([encoder.finish()]);
|
|
276
|
-
|
|
277
|
-
// Get the data on the CPU.
|
|
278
|
-
await buffer.mapAsync(GPUMapMode.READ);
|
|
279
|
-
saveScreenshot(buffer.getMappedRange());
|
|
280
|
-
buffer.unmap();
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
setImageData(imageData, usage): this {
|
|
284
|
-
let data = null;
|
|
285
|
-
|
|
286
|
-
const bytesPerRow = Math.ceil((img.width * 4) / 256) * 256;
|
|
287
|
-
if (bytesPerRow == img.width * 4) {
|
|
288
|
-
data = imageData.data;
|
|
289
|
-
} else {
|
|
290
|
-
data = new Uint8Array(bytesPerRow * img.height);
|
|
291
|
-
let imagePixelIndex = 0;
|
|
292
|
-
for (let y = 0; y < img.height; ++y) {
|
|
293
|
-
for (let x = 0; x < img.width; ++x) {
|
|
294
|
-
const i = x * 4 + y * bytesPerRow;
|
|
295
|
-
data[i] = imageData.data[imagePixelIndex];
|
|
296
|
-
data[i + 1] = imageData.data[imagePixelIndex + 1];
|
|
297
|
-
data[i + 2] = imageData.data[imagePixelIndex + 2];
|
|
298
|
-
data[i + 3] = imageData.data[imagePixelIndex + 3];
|
|
299
|
-
imagePixelIndex += 4;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
return this;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
setData(data): this {
|
|
307
|
-
const textureDataBuffer = this.device.handle.createBuffer({
|
|
308
|
-
size: data.byteLength,
|
|
309
|
-
usage: Buffer.COPY_DST | Buffer.COPY_SRC,
|
|
310
|
-
mappedAtCreation: true
|
|
311
|
-
});
|
|
312
|
-
new Uint8Array(textureDataBuffer.getMappedRange()).set(data);
|
|
313
|
-
textureDataBuffer.unmap();
|
|
314
|
-
|
|
315
|
-
this.setBuffer(textureDataBuffer);
|
|
316
|
-
|
|
317
|
-
textureDataBuffer.destroy();
|
|
318
|
-
return this;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
setBuffer(textureDataBuffer, {bytesPerRow}): this {
|
|
322
|
-
const commandEncoder = this.device.handle.createCommandEncoder();
|
|
323
|
-
commandEncoder.copyBufferToTexture(
|
|
324
|
-
{
|
|
325
|
-
buffer: textureDataBuffer,
|
|
326
|
-
bytesPerRow
|
|
327
|
-
},
|
|
328
|
-
{
|
|
329
|
-
texture: this.handle
|
|
330
|
-
},
|
|
331
|
-
{
|
|
332
|
-
width,
|
|
333
|
-
height,
|
|
334
|
-
depth
|
|
335
|
-
}
|
|
336
|
-
);
|
|
337
|
-
|
|
338
|
-
this.device.handle.defaultQueue.submit([commandEncoder.finish()]);
|
|
339
|
-
return this;
|
|
340
|
-
}
|
|
341
|
-
*/
|
|
342
268
|
};
|
|
343
269
|
|
|
344
|
-
//
|
|
345
|
-
var
|
|
346
|
-
var WebGPUExternalTexture = class extends
|
|
270
|
+
// dist/adapter/resources/webgpu-external-texture.js
|
|
271
|
+
var import_core5 = require("@luma.gl/core");
|
|
272
|
+
var WebGPUExternalTexture = class extends import_core5.ExternalTexture {
|
|
347
273
|
device;
|
|
348
274
|
handle;
|
|
349
275
|
sampler;
|
|
@@ -365,9 +291,9 @@ var WebGPUExternalTexture = class extends import_core4.ExternalTexture {
|
|
|
365
291
|
}
|
|
366
292
|
};
|
|
367
293
|
|
|
368
|
-
//
|
|
369
|
-
var
|
|
370
|
-
var WebGPUShader = class extends
|
|
294
|
+
// dist/adapter/resources/webgpu-shader.js
|
|
295
|
+
var import_core6 = require("@luma.gl/core");
|
|
296
|
+
var WebGPUShader = class extends import_core6.Shader {
|
|
371
297
|
device;
|
|
372
298
|
handle;
|
|
373
299
|
constructor(device, props) {
|
|
@@ -383,7 +309,7 @@ var WebGPUShader = class extends import_core5.Shader {
|
|
|
383
309
|
if (error) {
|
|
384
310
|
this.debugShader();
|
|
385
311
|
const shaderLog = await this.getCompilationInfo();
|
|
386
|
-
|
|
312
|
+
import_core6.log.error(`Shader compilation error: ${error.message}`, shaderLog)();
|
|
387
313
|
throw new Error(`Shader compilation error: ${error.message}`);
|
|
388
314
|
}
|
|
389
315
|
}
|
|
@@ -416,10 +342,10 @@ var WebGPUShader = class extends import_core5.Shader {
|
|
|
416
342
|
}
|
|
417
343
|
};
|
|
418
344
|
|
|
419
|
-
//
|
|
420
|
-
var
|
|
345
|
+
// dist/adapter/resources/webgpu-render-pipeline.js
|
|
346
|
+
var import_core9 = require("@luma.gl/core");
|
|
421
347
|
|
|
422
|
-
//
|
|
348
|
+
// dist/adapter/helpers/webgpu-parameters.js
|
|
423
349
|
function addDepthStencil(descriptor) {
|
|
424
350
|
descriptor.depthStencil = descriptor.depthStencil || {
|
|
425
351
|
// required, set something
|
|
@@ -604,8 +530,8 @@ function addColorState(descriptor) {
|
|
|
604
530
|
return (_f = descriptor.fragment) == null ? void 0 : _f.targets;
|
|
605
531
|
}
|
|
606
532
|
|
|
607
|
-
//
|
|
608
|
-
var
|
|
533
|
+
// dist/adapter/helpers/get-bind-group.js
|
|
534
|
+
var import_core7 = require("@luma.gl/core");
|
|
609
535
|
function getBindGroup(device, bindGroupLayout, shaderLayout, bindings) {
|
|
610
536
|
const entries = getBindGroupEntries(bindings, shaderLayout);
|
|
611
537
|
return device.createBindGroup({
|
|
@@ -616,7 +542,7 @@ function getBindGroup(device, bindGroupLayout, shaderLayout, bindings) {
|
|
|
616
542
|
function getShaderLayoutBinding(shaderLayout, bindingName) {
|
|
617
543
|
const bindingLayout = shaderLayout.bindings.find((binding) => binding.name === bindingName || `${binding.name}uniforms` === bindingName.toLocaleLowerCase());
|
|
618
544
|
if (!bindingLayout) {
|
|
619
|
-
|
|
545
|
+
import_core7.log.warn(`Binding ${bindingName} not set: Not found in shader layout.`)();
|
|
620
546
|
}
|
|
621
547
|
return bindingLayout;
|
|
622
548
|
}
|
|
@@ -631,30 +557,30 @@ function getBindGroupEntries(bindings, shaderLayout) {
|
|
|
631
557
|
return entries;
|
|
632
558
|
}
|
|
633
559
|
function getBindGroupEntry(binding, index) {
|
|
634
|
-
if (binding instanceof
|
|
560
|
+
if (binding instanceof import_core7.Buffer) {
|
|
635
561
|
return {
|
|
636
562
|
binding: index,
|
|
637
563
|
resource: {
|
|
638
|
-
buffer: (0,
|
|
564
|
+
buffer: (0, import_core7.cast)(binding).handle
|
|
639
565
|
}
|
|
640
566
|
};
|
|
641
567
|
}
|
|
642
|
-
if (binding instanceof
|
|
568
|
+
if (binding instanceof import_core7.Sampler) {
|
|
643
569
|
return {
|
|
644
570
|
binding: index,
|
|
645
|
-
resource: (0,
|
|
571
|
+
resource: (0, import_core7.cast)(binding).handle
|
|
646
572
|
};
|
|
647
|
-
} else if (binding instanceof
|
|
573
|
+
} else if (binding instanceof import_core7.Texture) {
|
|
648
574
|
return {
|
|
649
575
|
binding: index,
|
|
650
|
-
resource: (0,
|
|
576
|
+
resource: (0, import_core7.cast)(binding).handle.createView({ label: "bind-group-auto-created" })
|
|
651
577
|
};
|
|
652
578
|
}
|
|
653
579
|
throw new Error("invalid binding");
|
|
654
580
|
}
|
|
655
581
|
|
|
656
|
-
//
|
|
657
|
-
var
|
|
582
|
+
// dist/adapter/helpers/get-vertex-buffer-layout.js
|
|
583
|
+
var import_core8 = require("@luma.gl/core");
|
|
658
584
|
function getWebGPUVertexFormat(format) {
|
|
659
585
|
if (format.endsWith("-webgl")) {
|
|
660
586
|
throw new Error(`WebGPU does not support vertex format ${format}`);
|
|
@@ -678,14 +604,14 @@ function getVertexBufferLayout(shaderLayout, bufferLayout) {
|
|
|
678
604
|
offset: attributeMapping.byteOffset,
|
|
679
605
|
shaderLocation: attributeLayout.location
|
|
680
606
|
});
|
|
681
|
-
byteStride += (0,
|
|
607
|
+
byteStride += (0, import_core8.decodeVertexFormat)(mapping.format).byteLength;
|
|
682
608
|
}
|
|
683
609
|
} else {
|
|
684
610
|
const attributeLayout = findAttributeLayout(shaderLayout, mapping.name, usedAttributes);
|
|
685
611
|
if (!attributeLayout) {
|
|
686
612
|
continue;
|
|
687
613
|
}
|
|
688
|
-
byteStride = (0,
|
|
614
|
+
byteStride = (0, import_core8.decodeVertexFormat)(mapping.format).byteLength;
|
|
689
615
|
stepMode = attributeLayout.stepMode || (attributeLayout.name.startsWith("instance") ? "instance" : "vertex");
|
|
690
616
|
vertexAttributes.push({
|
|
691
617
|
format: getWebGPUVertexFormat(mapping.format),
|
|
@@ -703,7 +629,7 @@ function getVertexBufferLayout(shaderLayout, bufferLayout) {
|
|
|
703
629
|
for (const attribute of shaderLayout.attributes) {
|
|
704
630
|
if (!usedAttributes.has(attribute.name)) {
|
|
705
631
|
vertexBufferLayouts.push({
|
|
706
|
-
arrayStride: (0,
|
|
632
|
+
arrayStride: (0, import_core8.decodeVertexFormat)("float32x3").byteLength,
|
|
707
633
|
stepMode: attribute.stepMode || (attribute.name.startsWith("instance") ? "instance" : "vertex"),
|
|
708
634
|
attributes: [
|
|
709
635
|
{
|
|
@@ -720,7 +646,7 @@ function getVertexBufferLayout(shaderLayout, bufferLayout) {
|
|
|
720
646
|
function findAttributeLayout(shaderLayout, name, attributeNames) {
|
|
721
647
|
const attribute = shaderLayout.attributes.find((attribute2) => attribute2.name === name);
|
|
722
648
|
if (!attribute) {
|
|
723
|
-
|
|
649
|
+
import_core8.log.warn(`Unknown attribute ${name}`)();
|
|
724
650
|
return null;
|
|
725
651
|
}
|
|
726
652
|
if (attributeNames.has(name)) {
|
|
@@ -730,8 +656,8 @@ function findAttributeLayout(shaderLayout, name, attributeNames) {
|
|
|
730
656
|
return attribute;
|
|
731
657
|
}
|
|
732
658
|
|
|
733
|
-
//
|
|
734
|
-
var WebGPURenderPipeline = class extends
|
|
659
|
+
// dist/adapter/resources/webgpu-render-pipeline.js
|
|
660
|
+
var WebGPURenderPipeline = class extends import_core9.RenderPipeline {
|
|
735
661
|
device;
|
|
736
662
|
handle;
|
|
737
663
|
vs;
|
|
@@ -749,53 +675,43 @@ var WebGPURenderPipeline = class extends import_core8.RenderPipeline {
|
|
|
749
675
|
this.handle = this.props.handle;
|
|
750
676
|
if (!this.handle) {
|
|
751
677
|
const descriptor = this._getRenderPipelineDescriptor();
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
678
|
+
import_core9.log.groupCollapsed(1, `new WebGPURenderPipeline(${this.id})`)();
|
|
679
|
+
import_core9.log.probe(1, JSON.stringify(descriptor, null, 2))();
|
|
680
|
+
import_core9.log.groupEnd(1)();
|
|
755
681
|
this.handle = this.device.handle.createRenderPipeline(descriptor);
|
|
756
682
|
}
|
|
757
683
|
this.handle.label = this.props.id;
|
|
758
|
-
this.vs = (0,
|
|
759
|
-
this.fs = (0,
|
|
684
|
+
this.vs = (0, import_core9.cast)(props.vs);
|
|
685
|
+
this.fs = (0, import_core9.cast)(props.fs);
|
|
760
686
|
}
|
|
761
687
|
destroy() {
|
|
762
688
|
}
|
|
763
689
|
// setIndexBuffer(indexBuffer: Buffer): void {
|
|
764
690
|
// this._indexBuffer = cast<WebGPUBuffer>(indexBuffer);
|
|
765
691
|
// }
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
// }
|
|
784
|
-
}
|
|
785
|
-
*/
|
|
786
|
-
// setConstantAttributes(attributes: Record<string, TypedArray>): void {
|
|
787
|
-
// throw new Error('not implemented');
|
|
692
|
+
// setAttributes(attributes: Record<string, Buffer>): void {
|
|
693
|
+
// for (const [name, buffer] of Object.entries(attributes)) {
|
|
694
|
+
// const bufferIndex = this._bufferSlots[name];
|
|
695
|
+
// if (bufferIndex >= 0) {
|
|
696
|
+
// this._buffers[bufferIndex] = buffer;
|
|
697
|
+
// } else {
|
|
698
|
+
// throw new Error(
|
|
699
|
+
// `Setting attribute '${name}' not listed in shader layout for program ${this.id}`
|
|
700
|
+
// );
|
|
701
|
+
// }
|
|
702
|
+
// }
|
|
703
|
+
// // for (let i = 0; i < this._bufferSlots.length; ++i) {
|
|
704
|
+
// // const bufferName = this._bufferSlots[i];
|
|
705
|
+
// // if (attributes[bufferName]) {
|
|
706
|
+
// // this.handle
|
|
707
|
+
// // }
|
|
708
|
+
// // }
|
|
788
709
|
// }
|
|
789
710
|
setBindings(bindings) {
|
|
790
711
|
Object.assign(this.props.bindings, bindings);
|
|
791
712
|
}
|
|
792
|
-
setUniforms(uniforms) {
|
|
793
|
-
if (!(0, import_core8.isObjectEmpty)(uniforms)) {
|
|
794
|
-
throw new Error("WebGPU does not support uniforms");
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
713
|
draw(options) {
|
|
798
|
-
const webgpuRenderPass = (0,
|
|
714
|
+
const webgpuRenderPass = (0, import_core9.cast)(options.renderPass) || this.device.getDefaultRenderPass();
|
|
799
715
|
webgpuRenderPass.handle.setPipeline(this.handle);
|
|
800
716
|
const bindGroup = this._getBindGroup();
|
|
801
717
|
if (bindGroup) {
|
|
@@ -803,13 +719,7 @@ var WebGPURenderPipeline = class extends import_core8.RenderPipeline {
|
|
|
803
719
|
}
|
|
804
720
|
options.vertexArray.bindBeforeRender(options.renderPass);
|
|
805
721
|
if (options.indexCount) {
|
|
806
|
-
webgpuRenderPass.handle.drawIndexed(
|
|
807
|
-
options.indexCount,
|
|
808
|
-
options.instanceCount,
|
|
809
|
-
options.firstIndex,
|
|
810
|
-
options.baseVertex,
|
|
811
|
-
options.firstInstance
|
|
812
|
-
);
|
|
722
|
+
webgpuRenderPass.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
|
|
813
723
|
} else {
|
|
814
724
|
webgpuRenderPass.handle.draw(
|
|
815
725
|
options.vertexCount || 0,
|
|
@@ -826,28 +736,23 @@ var WebGPURenderPipeline = class extends import_core8.RenderPipeline {
|
|
|
826
736
|
/** Return a bind group created by setBindings */
|
|
827
737
|
_getBindGroup() {
|
|
828
738
|
this._bindGroupLayout = this._bindGroupLayout || this.handle.getBindGroupLayout(0);
|
|
829
|
-
this._bindGroup = this._bindGroup || getBindGroup(
|
|
830
|
-
this.device.handle,
|
|
831
|
-
this._bindGroupLayout,
|
|
832
|
-
this.props.shaderLayout,
|
|
833
|
-
this.props.bindings
|
|
834
|
-
);
|
|
739
|
+
this._bindGroup = this._bindGroup || getBindGroup(this.device.handle, this._bindGroupLayout, this.props.shaderLayout, this.props.bindings);
|
|
835
740
|
return this._bindGroup;
|
|
836
741
|
}
|
|
837
|
-
/**
|
|
838
|
-
* Populate the complex WebGPU GPURenderPipelineDescriptor
|
|
742
|
+
/**
|
|
743
|
+
* Populate the complex WebGPU GPURenderPipelineDescriptor
|
|
839
744
|
*/
|
|
840
745
|
_getRenderPipelineDescriptor() {
|
|
841
746
|
var _a, _b;
|
|
842
747
|
const vertex = {
|
|
843
|
-
module: (0,
|
|
748
|
+
module: (0, import_core9.cast)(this.props.vs).handle,
|
|
844
749
|
entryPoint: this.props.vsEntryPoint || "main",
|
|
845
750
|
buffers: getVertexBufferLayout(this.props.shaderLayout, this.props.bufferLayout)
|
|
846
751
|
};
|
|
847
752
|
let fragment;
|
|
848
753
|
if (this.props.fs) {
|
|
849
754
|
fragment = {
|
|
850
|
-
module: (0,
|
|
755
|
+
module: (0, import_core9.cast)(this.props.fs).handle,
|
|
851
756
|
entryPoint: this.props.fsEntryPoint || "main",
|
|
852
757
|
targets: [
|
|
853
758
|
{
|
|
@@ -874,53 +779,11 @@ var WebGPURenderPipeline = class extends import_core8.RenderPipeline {
|
|
|
874
779
|
applyParametersToRenderPipelineDescriptor(descriptor, this.props.parameters);
|
|
875
780
|
return descriptor;
|
|
876
781
|
}
|
|
877
|
-
/**
|
|
878
|
-
_setAttributeBuffers(webgpuRenderPass: WebGPURenderPass) {
|
|
879
|
-
if (this._indexBuffer) {
|
|
880
|
-
webgpuRenderPass.handle.setIndexBuffer(this._indexBuffer.handle, this._indexBuffer.props.indexType);
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
const buffers = this._getBuffers();
|
|
884
|
-
for (let i = 0; i < buffers.length; ++i) {
|
|
885
|
-
const buffer = cast<WebGPUBuffer>(buffers[i]);
|
|
886
|
-
if (!buffer) {
|
|
887
|
-
const attribute = this.props.shaderLayout.attributes.find(
|
|
888
|
-
(attribute) => attribute.location === i
|
|
889
|
-
);
|
|
890
|
-
throw new Error(
|
|
891
|
-
`No buffer provided for attribute '${attribute?.name || ''}' in Model '${this.props.id}'`
|
|
892
|
-
);
|
|
893
|
-
}
|
|
894
|
-
webgpuRenderPass.handle.setVertexBuffer(i, buffer.handle);
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
// TODO - HANDLE buffer maps
|
|
898
|
-
/*
|
|
899
|
-
for (const [bufferName, attributeMapping] of Object.entries(this.props.bufferLayout)) {
|
|
900
|
-
const buffer = cast<WebGPUBuffer>(this.props.attributes[bufferName]);
|
|
901
|
-
if (!buffer) {
|
|
902
|
-
log.warn(`Missing buffer for buffer map ${bufferName}`)();
|
|
903
|
-
continue;
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
if ('location' in attributeMapping) {
|
|
907
|
-
// @ts-expect-error TODO model must not depend on webgpu
|
|
908
|
-
renderPass.handle.setVertexBuffer(layout.location, buffer.handle);
|
|
909
|
-
} else {
|
|
910
|
-
for (const [bufferName, mapping] of Object.entries(attributeMapping)) {
|
|
911
|
-
// @ts-expect-error TODO model must not depend on webgpu
|
|
912
|
-
renderPass.handle.setVertexBuffer(field.location, buffer.handle);
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
*
|
|
917
|
-
}
|
|
918
|
-
*/
|
|
919
782
|
};
|
|
920
783
|
|
|
921
|
-
//
|
|
922
|
-
var
|
|
923
|
-
var WebGPUComputePipeline = class extends
|
|
784
|
+
// dist/adapter/resources/webgpu-compute-pipeline.js
|
|
785
|
+
var import_core10 = require("@luma.gl/core");
|
|
786
|
+
var WebGPUComputePipeline = class extends import_core10.ComputePipeline {
|
|
924
787
|
device;
|
|
925
788
|
handle;
|
|
926
789
|
constructor(device, props) {
|
|
@@ -943,9 +806,9 @@ var WebGPUComputePipeline = class extends import_core9.ComputePipeline {
|
|
|
943
806
|
}
|
|
944
807
|
};
|
|
945
808
|
|
|
946
|
-
//
|
|
947
|
-
var
|
|
948
|
-
var WebGPURenderPass = class extends
|
|
809
|
+
// dist/adapter/resources/webgpu-render-pass.js
|
|
810
|
+
var import_core11 = require("@luma.gl/core");
|
|
811
|
+
var WebGPURenderPass = class extends import_core11.RenderPass {
|
|
949
812
|
device;
|
|
950
813
|
handle;
|
|
951
814
|
/** Active pipeline */
|
|
@@ -955,11 +818,23 @@ var WebGPURenderPass = class extends import_core10.RenderPass {
|
|
|
955
818
|
this.device = device;
|
|
956
819
|
const framebuffer = props.framebuffer || device.canvasContext.getCurrentFramebuffer();
|
|
957
820
|
const renderPassDescriptor = this.getRenderPassDescriptor(framebuffer);
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
821
|
+
const webgpuQuerySet = props.timestampQuerySet;
|
|
822
|
+
if (webgpuQuerySet) {
|
|
823
|
+
renderPassDescriptor.occlusionQuerySet = webgpuQuerySet.handle;
|
|
824
|
+
}
|
|
825
|
+
if (device.features.has("timestamp-query")) {
|
|
826
|
+
const webgpuQuerySet2 = props.timestampQuerySet;
|
|
827
|
+
renderPassDescriptor.timestampWrites = webgpuQuerySet2 ? {
|
|
828
|
+
querySet: webgpuQuerySet2.handle,
|
|
829
|
+
beginningOfPassWriteIndex: props.beginTimestampIndex,
|
|
830
|
+
endOfPassWriteIndex: props.endTimestampIndex
|
|
831
|
+
} : void 0;
|
|
832
|
+
}
|
|
961
833
|
this.handle = this.props.handle || device.commandEncoder.beginRenderPass(renderPassDescriptor);
|
|
962
834
|
this.handle.label = this.props.id;
|
|
835
|
+
import_core11.log.groupCollapsed(3, `new WebGPURenderPass(${this.id})`)();
|
|
836
|
+
import_core11.log.probe(3, JSON.stringify(renderPassDescriptor, null, 2))();
|
|
837
|
+
import_core11.log.groupEnd(3)();
|
|
963
838
|
}
|
|
964
839
|
destroy() {
|
|
965
840
|
}
|
|
@@ -967,7 +842,7 @@ var WebGPURenderPass = class extends import_core10.RenderPass {
|
|
|
967
842
|
this.handle.end();
|
|
968
843
|
}
|
|
969
844
|
setPipeline(pipeline) {
|
|
970
|
-
this.pipeline = (0,
|
|
845
|
+
this.pipeline = (0, import_core11.cast)(pipeline);
|
|
971
846
|
this.handle.setPipeline(this.pipeline.handle);
|
|
972
847
|
}
|
|
973
848
|
/** Sets an array of bindings (uniform buffers, samplers, textures, ...) */
|
|
@@ -980,27 +855,16 @@ var WebGPURenderPass = class extends import_core10.RenderPass {
|
|
|
980
855
|
}
|
|
981
856
|
}
|
|
982
857
|
setIndexBuffer(buffer, indexFormat, offset = 0, size) {
|
|
983
|
-
this.handle.setIndexBuffer((0,
|
|
858
|
+
this.handle.setIndexBuffer((0, import_core11.cast)(buffer).handle, indexFormat, offset, size);
|
|
984
859
|
}
|
|
985
860
|
setVertexBuffer(slot, buffer, offset = 0) {
|
|
986
|
-
this.handle.setVertexBuffer(slot, (0,
|
|
861
|
+
this.handle.setVertexBuffer(slot, (0, import_core11.cast)(buffer).handle, offset);
|
|
987
862
|
}
|
|
988
863
|
draw(options) {
|
|
989
864
|
if (options.indexCount) {
|
|
990
|
-
this.handle.drawIndexed(
|
|
991
|
-
options.indexCount,
|
|
992
|
-
options.instanceCount,
|
|
993
|
-
options.firstIndex,
|
|
994
|
-
options.baseVertex,
|
|
995
|
-
options.firstInstance
|
|
996
|
-
);
|
|
865
|
+
this.handle.drawIndexed(options.indexCount, options.instanceCount, options.firstIndex, options.baseVertex, options.firstInstance);
|
|
997
866
|
} else {
|
|
998
|
-
this.handle.draw(
|
|
999
|
-
options.vertexCount || 0,
|
|
1000
|
-
options.instanceCount || 1,
|
|
1001
|
-
options.firstIndex,
|
|
1002
|
-
options.firstInstance
|
|
1003
|
-
);
|
|
867
|
+
this.handle.draw(options.vertexCount || 0, options.instanceCount || 1, options.firstIndex, options.firstInstance);
|
|
1004
868
|
}
|
|
1005
869
|
}
|
|
1006
870
|
drawIndirect() {
|
|
@@ -1017,14 +881,7 @@ var WebGPURenderPass = class extends import_core10.RenderPass {
|
|
|
1017
881
|
this.handle.setScissorRect(scissorRect[0], scissorRect[1], scissorRect[2], scissorRect[3]);
|
|
1018
882
|
}
|
|
1019
883
|
if (viewport) {
|
|
1020
|
-
this.handle.setViewport(
|
|
1021
|
-
viewport[0],
|
|
1022
|
-
viewport[1],
|
|
1023
|
-
viewport[2],
|
|
1024
|
-
viewport[3],
|
|
1025
|
-
viewport[4],
|
|
1026
|
-
viewport[5]
|
|
1027
|
-
);
|
|
884
|
+
this.handle.setViewport(viewport[0], viewport[1], viewport[2], viewport[3], viewport[4], viewport[5]);
|
|
1028
885
|
}
|
|
1029
886
|
}
|
|
1030
887
|
pushDebugGroup(groupLabel) {
|
|
@@ -1036,16 +893,17 @@ var WebGPURenderPass = class extends import_core10.RenderPass {
|
|
|
1036
893
|
insertDebugMarker(markerLabel) {
|
|
1037
894
|
this.handle.insertDebugMarker(markerLabel);
|
|
1038
895
|
}
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
896
|
+
beginOcclusionQuery(queryIndex) {
|
|
897
|
+
this.handle.beginOcclusionQuery(queryIndex);
|
|
898
|
+
}
|
|
899
|
+
endOcclusionQuery() {
|
|
900
|
+
this.handle.endOcclusionQuery();
|
|
901
|
+
}
|
|
1044
902
|
// executeBundles(bundles: Iterable<GPURenderBundle>): void;
|
|
1045
903
|
// INTERNAL
|
|
1046
|
-
/**
|
|
904
|
+
/**
|
|
1047
905
|
* Partial render pass descriptor. Used by WebGPURenderPass.
|
|
1048
|
-
* @returns attachments fields of a renderpass descriptor.
|
|
906
|
+
* @returns attachments fields of a renderpass descriptor.
|
|
1049
907
|
*/
|
|
1050
908
|
getRenderPassDescriptor(framebuffer) {
|
|
1051
909
|
const renderPassDescriptor = {
|
|
@@ -1057,11 +915,11 @@ var WebGPURenderPass = class extends import_core10.RenderPass {
|
|
|
1057
915
|
colorClearValue: this.props.clearColor || [0, 0, 0, 0],
|
|
1058
916
|
storeOp: this.props.discard ? "discard" : "store",
|
|
1059
917
|
// ...colorAttachment,
|
|
1060
|
-
view: colorAttachment.
|
|
918
|
+
view: colorAttachment.handle
|
|
1061
919
|
}));
|
|
1062
920
|
if (framebuffer.depthStencilAttachment) {
|
|
1063
921
|
renderPassDescriptor.depthStencilAttachment = {
|
|
1064
|
-
view: framebuffer.depthStencilAttachment.
|
|
922
|
+
view: framebuffer.depthStencilAttachment.handle
|
|
1065
923
|
};
|
|
1066
924
|
const { depthStencilAttachment } = renderPassDescriptor;
|
|
1067
925
|
if (this.props.depthReadOnly) {
|
|
@@ -1083,9 +941,9 @@ var WebGPURenderPass = class extends import_core10.RenderPass {
|
|
|
1083
941
|
}
|
|
1084
942
|
};
|
|
1085
943
|
|
|
1086
|
-
//
|
|
1087
|
-
var
|
|
1088
|
-
var WebGPUComputePass = class extends
|
|
944
|
+
// dist/adapter/resources/webgpu-compute-pass.js
|
|
945
|
+
var import_core12 = require("@luma.gl/core");
|
|
946
|
+
var WebGPUComputePass = class extends import_core12.ComputePass {
|
|
1089
947
|
device;
|
|
1090
948
|
handle;
|
|
1091
949
|
_bindGroupLayout = null;
|
|
@@ -1093,9 +951,20 @@ var WebGPUComputePass = class extends import_core11.ComputePass {
|
|
|
1093
951
|
var _a;
|
|
1094
952
|
super(device, props);
|
|
1095
953
|
this.device = device;
|
|
954
|
+
let timestampWrites;
|
|
955
|
+
if (device.features.has("timestamp-query")) {
|
|
956
|
+
const webgpuQuerySet = props.timestampQuerySet;
|
|
957
|
+
if (webgpuQuerySet) {
|
|
958
|
+
timestampWrites = {
|
|
959
|
+
querySet: webgpuQuerySet.handle,
|
|
960
|
+
beginningOfPassWriteIndex: props.beginTimestampIndex,
|
|
961
|
+
endOfPassWriteIndex: props.endTimestampIndex
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
}
|
|
1096
965
|
this.handle = this.props.handle || ((_a = device.commandEncoder) == null ? void 0 : _a.beginComputePass({
|
|
1097
|
-
label: this.props.id
|
|
1098
|
-
|
|
966
|
+
label: this.props.id,
|
|
967
|
+
timestampWrites
|
|
1099
968
|
}));
|
|
1100
969
|
}
|
|
1101
970
|
/** @note no WebGPU destroy method, just gc */
|
|
@@ -1140,25 +1009,18 @@ var WebGPUComputePass = class extends import_core11.ComputePass {
|
|
|
1140
1009
|
insertDebugMarker(markerLabel) {
|
|
1141
1010
|
this.handle.insertDebugMarker(markerLabel);
|
|
1142
1011
|
}
|
|
1143
|
-
// writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;
|
|
1144
|
-
// beginPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
|
|
1145
|
-
// endPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
|
|
1146
1012
|
};
|
|
1147
1013
|
|
|
1148
|
-
//
|
|
1149
|
-
var
|
|
1014
|
+
// dist/adapter/resources/webgpu-vertex-array.js
|
|
1015
|
+
var import_core13 = require("@luma.gl/core");
|
|
1150
1016
|
var import_env = require("@probe.gl/env");
|
|
1151
|
-
var WebGPUVertexArray = class extends
|
|
1017
|
+
var WebGPUVertexArray = class extends import_core13.VertexArray {
|
|
1152
1018
|
get [Symbol.toStringTag]() {
|
|
1153
1019
|
return "WebGPUVertexArray";
|
|
1154
1020
|
}
|
|
1155
1021
|
device;
|
|
1156
1022
|
/** Vertex Array is a helper class under WebGPU */
|
|
1157
1023
|
handle;
|
|
1158
|
-
/** * Attribute 0 can not be disable on most desktop OpenGL based browsers */
|
|
1159
|
-
static isConstantAttributeZeroSupported(device) {
|
|
1160
|
-
return device.info.type === "webgl2" || (0, import_env.getBrowser)() === "Chrome";
|
|
1161
|
-
}
|
|
1162
1024
|
// Create a VertexArray
|
|
1163
1025
|
constructor(device, props) {
|
|
1164
1026
|
super(device, props);
|
|
@@ -1168,7 +1030,7 @@ var WebGPUVertexArray = class extends import_core12.VertexArray {
|
|
|
1168
1030
|
}
|
|
1169
1031
|
/**
|
|
1170
1032
|
* Set an elements buffer, for indexed rendering.
|
|
1171
|
-
* Must be a Buffer bound to buffer with usage bit Buffer.INDEX set.
|
|
1033
|
+
* Must be a Buffer bound to buffer with usage bit Buffer.INDEX set.
|
|
1172
1034
|
*/
|
|
1173
1035
|
setIndexBuffer(buffer) {
|
|
1174
1036
|
this.indexBuffer = buffer;
|
|
@@ -1177,35 +1039,39 @@ var WebGPUVertexArray = class extends import_core12.VertexArray {
|
|
|
1177
1039
|
setBuffer(bufferSlot, buffer) {
|
|
1178
1040
|
this.attributes[bufferSlot] = buffer;
|
|
1179
1041
|
}
|
|
1180
|
-
/** Set a location in vertex attributes array to a constant value, disables the location */
|
|
1181
|
-
setConstant(location, value) {
|
|
1182
|
-
import_core12.log.warn(`${this.id} constant attributes not supported on WebGPU`);
|
|
1183
|
-
}
|
|
1184
1042
|
bindBeforeRender(renderPass, firstIndex, indexCount) {
|
|
1185
1043
|
const webgpuRenderPass = renderPass;
|
|
1186
1044
|
const webgpuIndexBuffer = this.indexBuffer;
|
|
1187
1045
|
if (webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle) {
|
|
1188
|
-
|
|
1046
|
+
import_core13.log.warn("setting index buffer", webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle, webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.indexType)();
|
|
1189
1047
|
webgpuRenderPass.handle.setIndexBuffer(webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle, webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.indexType);
|
|
1190
1048
|
}
|
|
1191
1049
|
for (let location = 0; location < this.maxVertexAttributes; location++) {
|
|
1192
1050
|
const webgpuBuffer = this.attributes[location];
|
|
1193
1051
|
if (webgpuBuffer == null ? void 0 : webgpuBuffer.handle) {
|
|
1194
|
-
|
|
1052
|
+
import_core13.log.warn(`setting vertex buffer ${location}`, webgpuBuffer == null ? void 0 : webgpuBuffer.handle)();
|
|
1195
1053
|
webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer == null ? void 0 : webgpuBuffer.handle);
|
|
1196
1054
|
}
|
|
1197
1055
|
}
|
|
1198
1056
|
}
|
|
1199
1057
|
unbindAfterRender(renderPass) {
|
|
1200
1058
|
}
|
|
1059
|
+
// DEPRECATED METHODS
|
|
1060
|
+
/**
|
|
1061
|
+
* @deprecated is this even an issue for WebGPU?
|
|
1062
|
+
* Attribute 0 can not be disable on most desktop OpenGL based browsers
|
|
1063
|
+
*/
|
|
1064
|
+
static isConstantAttributeZeroSupported(device) {
|
|
1065
|
+
return (0, import_env.getBrowser)() === "Chrome";
|
|
1066
|
+
}
|
|
1201
1067
|
};
|
|
1202
1068
|
|
|
1203
|
-
//
|
|
1204
|
-
var
|
|
1069
|
+
// dist/adapter/webgpu-canvas-context.js
|
|
1070
|
+
var import_core15 = require("@luma.gl/core");
|
|
1205
1071
|
|
|
1206
|
-
//
|
|
1207
|
-
var
|
|
1208
|
-
var WebGPUFramebuffer = class extends
|
|
1072
|
+
// dist/adapter/resources/webgpu-framebuffer.js
|
|
1073
|
+
var import_core14 = require("@luma.gl/core");
|
|
1074
|
+
var WebGPUFramebuffer = class extends import_core14.Framebuffer {
|
|
1209
1075
|
device;
|
|
1210
1076
|
constructor(device, props) {
|
|
1211
1077
|
super(device, props);
|
|
@@ -1214,8 +1080,8 @@ var WebGPUFramebuffer = class extends import_core13.Framebuffer {
|
|
|
1214
1080
|
}
|
|
1215
1081
|
};
|
|
1216
1082
|
|
|
1217
|
-
//
|
|
1218
|
-
var WebGPUCanvasContext = class extends
|
|
1083
|
+
// dist/adapter/webgpu-canvas-context.js
|
|
1084
|
+
var WebGPUCanvasContext = class extends import_core15.CanvasContext {
|
|
1219
1085
|
device;
|
|
1220
1086
|
gpuCanvasContext;
|
|
1221
1087
|
/** Format of returned textures: "bgra8unorm", "rgba8unorm", "rgba16float". */
|
|
@@ -1267,7 +1133,7 @@ var WebGPUCanvasContext = class extends import_core14.CanvasContext {
|
|
|
1267
1133
|
colorSpace: this.props.colorSpace,
|
|
1268
1134
|
alphaMode: this.props.alphaMode
|
|
1269
1135
|
});
|
|
1270
|
-
|
|
1136
|
+
import_core15.log.log(1, `Resized to ${this.width}x${this.height}px`)();
|
|
1271
1137
|
}
|
|
1272
1138
|
}
|
|
1273
1139
|
resize(options) {
|
|
@@ -1295,27 +1161,50 @@ var WebGPUCanvasContext = class extends import_core14.CanvasContext {
|
|
|
1295
1161
|
}
|
|
1296
1162
|
};
|
|
1297
1163
|
|
|
1298
|
-
//
|
|
1299
|
-
var
|
|
1164
|
+
// dist/adapter/resources/webgpu-query-set.js
|
|
1165
|
+
var import_core16 = require("@luma.gl/core");
|
|
1166
|
+
var WebGPUQuerySet = class extends import_core16.QuerySet {
|
|
1167
|
+
device;
|
|
1168
|
+
handle;
|
|
1169
|
+
constructor(device, props) {
|
|
1170
|
+
super(device, props);
|
|
1171
|
+
this.device = device;
|
|
1172
|
+
this.handle = this.props.handle || this.device.handle.createQuerySet({
|
|
1173
|
+
type: this.props.type,
|
|
1174
|
+
count: this.props.count
|
|
1175
|
+
});
|
|
1176
|
+
this.handle.label = this.props.id;
|
|
1177
|
+
}
|
|
1178
|
+
destroy() {
|
|
1179
|
+
this.handle.destroy();
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
|
|
1183
|
+
// dist/adapter/webgpu-device.js
|
|
1184
|
+
var _WebGPUDevice = class extends import_core17.Device {
|
|
1185
|
+
/** The underlying WebGPU device */
|
|
1300
1186
|
handle;
|
|
1187
|
+
/* The underlying WebGPU adapter */
|
|
1301
1188
|
adapter;
|
|
1189
|
+
/* The underlying WebGPU adapter's info */
|
|
1190
|
+
adapterInfo;
|
|
1191
|
+
features;
|
|
1192
|
+
info;
|
|
1193
|
+
limits;
|
|
1302
1194
|
lost;
|
|
1303
1195
|
canvasContext = null;
|
|
1196
|
+
_isLost = false;
|
|
1304
1197
|
commandEncoder = null;
|
|
1305
1198
|
renderPass = null;
|
|
1306
|
-
_info;
|
|
1307
|
-
_isLost = false;
|
|
1308
1199
|
/** Check if WebGPU is available */
|
|
1309
1200
|
static isSupported() {
|
|
1310
1201
|
return Boolean(typeof navigator !== "undefined" && navigator.gpu);
|
|
1311
1202
|
}
|
|
1312
1203
|
static async create(props) {
|
|
1313
1204
|
if (!navigator.gpu) {
|
|
1314
|
-
throw new Error(
|
|
1315
|
-
"WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu"
|
|
1316
|
-
);
|
|
1205
|
+
throw new Error("WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu");
|
|
1317
1206
|
}
|
|
1318
|
-
|
|
1207
|
+
import_core17.log.groupCollapsed(1, "WebGPUDevice created")();
|
|
1319
1208
|
const adapter = await navigator.gpu.requestAdapter({
|
|
1320
1209
|
powerPreference: "high-performance"
|
|
1321
1210
|
// forceSoftware: false
|
|
@@ -1324,47 +1213,40 @@ var _WebGPUDevice = class extends import_core15.Device {
|
|
|
1324
1213
|
throw new Error("Failed to request WebGPU adapter");
|
|
1325
1214
|
}
|
|
1326
1215
|
const adapterInfo = await adapter.requestAdapterInfo();
|
|
1327
|
-
|
|
1216
|
+
import_core17.log.probe(2, "Adapter available", adapterInfo)();
|
|
1217
|
+
const requiredFeatures = [];
|
|
1218
|
+
const requiredLimits = {};
|
|
1219
|
+
if (props.requestMaximalLimits) {
|
|
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
|
+
}
|
|
1328
1227
|
const gpuDevice = await adapter.requestDevice({
|
|
1329
|
-
requiredFeatures
|
|
1330
|
-
|
|
1331
|
-
// requiredLimits: adapter.limits
|
|
1228
|
+
requiredFeatures,
|
|
1229
|
+
requiredLimits
|
|
1332
1230
|
});
|
|
1333
|
-
|
|
1231
|
+
import_core17.log.probe(1, "GPUDevice available")();
|
|
1334
1232
|
if (typeof props.canvas === "string") {
|
|
1335
|
-
await
|
|
1336
|
-
|
|
1233
|
+
await import_core17.CanvasContext.pageLoaded;
|
|
1234
|
+
import_core17.log.probe(1, "DOM is loaded")();
|
|
1337
1235
|
}
|
|
1338
1236
|
const device = new _WebGPUDevice(gpuDevice, adapter, adapterInfo, props);
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
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)();
|
|
1342
1240
|
return device;
|
|
1343
1241
|
}
|
|
1344
1242
|
constructor(device, adapter, adapterInfo, props) {
|
|
1345
|
-
super({ ...props, id: props.id || (0,
|
|
1243
|
+
super({ ...props, id: props.id || (0, import_core17.uid)("webgpu-device") });
|
|
1346
1244
|
this.handle = device;
|
|
1347
1245
|
this.adapter = adapter;
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
const gpu = vendor === "apple" ? "apple" : "unknown";
|
|
1353
|
-
const gpuArchitecture = adapterInfo.architecture || "unknown";
|
|
1354
|
-
const gpuBackend = adapterInfo.backend || "unknown";
|
|
1355
|
-
const gpuType = (adapterInfo.type || "").split(" ")[0].toLowerCase() || "unknown";
|
|
1356
|
-
this._info = {
|
|
1357
|
-
type: "webgpu",
|
|
1358
|
-
vendor,
|
|
1359
|
-
renderer,
|
|
1360
|
-
version,
|
|
1361
|
-
gpu,
|
|
1362
|
-
gpuType,
|
|
1363
|
-
gpuBackend,
|
|
1364
|
-
gpuArchitecture,
|
|
1365
|
-
shadingLanguage: "wgsl",
|
|
1366
|
-
shadingLanguageVersion: 100
|
|
1367
|
-
};
|
|
1246
|
+
this.adapterInfo = adapterInfo;
|
|
1247
|
+
this.info = this._getInfo();
|
|
1248
|
+
this.features = this._getFeatures();
|
|
1249
|
+
this.limits = this.handle.limits;
|
|
1368
1250
|
this.lost = new Promise(async (resolve) => {
|
|
1369
1251
|
const lostInfo = await this.handle.lost;
|
|
1370
1252
|
this._isLost = true;
|
|
@@ -1376,7 +1258,6 @@ var _WebGPUDevice = class extends import_core15.Device {
|
|
|
1376
1258
|
width: props.width,
|
|
1377
1259
|
container: props.container
|
|
1378
1260
|
});
|
|
1379
|
-
this.features = this._getFeatures();
|
|
1380
1261
|
}
|
|
1381
1262
|
// TODO
|
|
1382
1263
|
// Load the glslang module now so that it is available synchronously when compiling shaders
|
|
@@ -1385,13 +1266,6 @@ var _WebGPUDevice = class extends import_core15.Device {
|
|
|
1385
1266
|
destroy() {
|
|
1386
1267
|
this.handle.destroy();
|
|
1387
1268
|
}
|
|
1388
|
-
get info() {
|
|
1389
|
-
return this._info;
|
|
1390
|
-
}
|
|
1391
|
-
features;
|
|
1392
|
-
get limits() {
|
|
1393
|
-
return this.handle.limits;
|
|
1394
|
-
}
|
|
1395
1269
|
isTextureFormatSupported(format) {
|
|
1396
1270
|
return !format.includes("webgl");
|
|
1397
1271
|
}
|
|
@@ -1453,6 +1327,9 @@ var _WebGPUDevice = class extends import_core15.Device {
|
|
|
1453
1327
|
createTransformFeedback(props) {
|
|
1454
1328
|
throw new Error("Transform feedback not supported in WebGPU");
|
|
1455
1329
|
}
|
|
1330
|
+
createQuerySet(props) {
|
|
1331
|
+
return new WebGPUQuerySet(this, props);
|
|
1332
|
+
}
|
|
1456
1333
|
createCanvasContext(props) {
|
|
1457
1334
|
return new WebGPUCanvasContext(this, this.adapter, props);
|
|
1458
1335
|
}
|
|
@@ -1473,6 +1350,29 @@ var _WebGPUDevice = class extends import_core15.Device {
|
|
|
1473
1350
|
}
|
|
1474
1351
|
this.commandEncoder = null;
|
|
1475
1352
|
}
|
|
1353
|
+
// PRIVATE METHODS
|
|
1354
|
+
_getInfo() {
|
|
1355
|
+
const [driver, driverVersion] = (this.adapterInfo.driver || "").split(" Version ");
|
|
1356
|
+
const vendor = this.adapterInfo.vendor || this.adapter.__brand || "unknown";
|
|
1357
|
+
const renderer = driver || "";
|
|
1358
|
+
const version = driverVersion || "";
|
|
1359
|
+
const gpu = vendor === "apple" ? "apple" : "unknown";
|
|
1360
|
+
const gpuArchitecture = this.adapterInfo.architecture || "unknown";
|
|
1361
|
+
const gpuBackend = this.adapterInfo.backend || "unknown";
|
|
1362
|
+
const gpuType = (this.adapterInfo.type || "").split(" ")[0].toLowerCase() || "unknown";
|
|
1363
|
+
return {
|
|
1364
|
+
type: "webgpu",
|
|
1365
|
+
vendor,
|
|
1366
|
+
renderer,
|
|
1367
|
+
version,
|
|
1368
|
+
gpu,
|
|
1369
|
+
gpuType,
|
|
1370
|
+
gpuBackend,
|
|
1371
|
+
gpuArchitecture,
|
|
1372
|
+
shadingLanguage: "wgsl",
|
|
1373
|
+
shadingLanguageVersion: 100
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1476
1376
|
_getFeatures() {
|
|
1477
1377
|
const features = new Set(this.handle.features);
|
|
1478
1378
|
if (features.has("depth-clamping")) {
|
|
@@ -1482,29 +1382,19 @@ var _WebGPUDevice = class extends import_core15.Device {
|
|
|
1482
1382
|
if (features.has("texture-compression-bc")) {
|
|
1483
1383
|
features.add("texture-compression-bc5-webgl");
|
|
1484
1384
|
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
features.add("texture-filter-linear-float16-webgl");
|
|
1499
|
-
features.add("texture-filter-anisotropic-webgl");
|
|
1500
|
-
features.add("texture-renderable-rgba32float-webgl");
|
|
1501
|
-
features.add("texture-renderable-float32-webgl");
|
|
1502
|
-
features.add("texture-renderable-float16-webgl");
|
|
1503
|
-
features.add("glsl-frag-data");
|
|
1504
|
-
features.add("glsl-frag-depth");
|
|
1505
|
-
features.add("glsl-derivatives");
|
|
1506
|
-
features.add("glsl-texture-lod");
|
|
1507
|
-
return features;
|
|
1385
|
+
const WEBGPU_ALWAYS_FEATURES = [
|
|
1386
|
+
"timer-query-webgl",
|
|
1387
|
+
"compilation-status-async-webgl",
|
|
1388
|
+
"float32-renderable-webgl",
|
|
1389
|
+
"float16-renderable-webgl",
|
|
1390
|
+
"norm16-renderable-webgl",
|
|
1391
|
+
"texture-filterable-anisotropic-webgl",
|
|
1392
|
+
"shader-noperspective-interpolation-webgl"
|
|
1393
|
+
];
|
|
1394
|
+
for (const feature of WEBGPU_ALWAYS_FEATURES) {
|
|
1395
|
+
features.add(feature);
|
|
1396
|
+
}
|
|
1397
|
+
return new import_core17.DeviceFeatures(Array.from(features));
|
|
1508
1398
|
}
|
|
1509
1399
|
copyExternalImageToTexture(options) {
|
|
1510
1400
|
var _a;
|
|
@@ -1548,3 +1438,4 @@ var _WebGPUDevice = class extends import_core15.Device {
|
|
|
1548
1438
|
};
|
|
1549
1439
|
var WebGPUDevice = _WebGPUDevice;
|
|
1550
1440
|
__publicField(WebGPUDevice, "type", "webgpu");
|
|
1441
|
+
//# sourceMappingURL=index.cjs.map
|