@luma.gl/webgpu 9.1.0-beta.1 → 9.1.0-beta.12
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/get-bind-group.d.ts +1 -3
- package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
- package/dist/adapter/helpers/get-bind-group.js +3 -5
- package/dist/adapter/helpers/get-bind-group.js.map +1 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.js +2 -2
- package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts +0 -1
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js +6 -28
- package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
- package/dist/adapter/webgpu-adapter.d.ts.map +1 -1
- package/dist/adapter/webgpu-adapter.js +3 -1
- package/dist/adapter/webgpu-adapter.js.map +1 -1
- package/dist/adapter/webgpu-canvas-context.d.ts +9 -7
- package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgpu-canvas-context.js +62 -44
- package/dist/adapter/webgpu-canvas-context.js.map +1 -1
- package/dist/adapter/webgpu-device.d.ts +5 -7
- package/dist/adapter/webgpu-device.d.ts.map +1 -1
- package/dist/adapter/webgpu-device.js +8 -11
- package/dist/adapter/webgpu-device.js.map +1 -1
- package/dist/dist.dev.js +66 -83
- package/dist/dist.min.js +5 -5
- package/dist/index.cjs +67 -80
- package/dist/index.cjs.map +2 -2
- package/package.json +3 -3
- package/src/adapter/helpers/get-bind-group.ts +3 -6
- package/src/adapter/helpers/get-vertex-buffer-layout.ts +2 -2
- package/src/adapter/resources/webgpu-render-pipeline.ts +6 -31
- package/src/adapter/webgpu-adapter.ts +4 -1
- package/src/adapter/webgpu-canvas-context.ts +72 -55
- package/src/adapter/webgpu-device.ts +9 -15
package/dist/index.cjs
CHANGED
|
@@ -577,9 +577,9 @@ function getBindGroup(device, bindGroupLayout, shaderLayout, bindings) {
|
|
|
577
577
|
entries
|
|
578
578
|
});
|
|
579
579
|
}
|
|
580
|
-
function getShaderLayoutBinding(shaderLayout, bindingName
|
|
580
|
+
function getShaderLayoutBinding(shaderLayout, bindingName) {
|
|
581
581
|
const bindingLayout = shaderLayout.bindings.find((binding) => binding.name === bindingName || `${binding.name}uniforms` === bindingName.toLocaleLowerCase());
|
|
582
|
-
if (!bindingLayout
|
|
582
|
+
if (!bindingLayout) {
|
|
583
583
|
import_core7.log.warn(`Binding ${bindingName} not set: Not found in shader layout.`)();
|
|
584
584
|
}
|
|
585
585
|
return bindingLayout || null;
|
|
@@ -591,9 +591,7 @@ function getBindGroupEntries(bindings, shaderLayout) {
|
|
|
591
591
|
if (bindingLayout) {
|
|
592
592
|
entries.push(getBindGroupEntry(value, bindingLayout.location));
|
|
593
593
|
}
|
|
594
|
-
bindingLayout = getShaderLayoutBinding(shaderLayout, `${bindingName}Sampler
|
|
595
|
-
ignoreWarnings: true
|
|
596
|
-
});
|
|
594
|
+
bindingLayout = getShaderLayoutBinding(shaderLayout, `${bindingName}Sampler`);
|
|
597
595
|
if (bindingLayout) {
|
|
598
596
|
entries.push(getBindGroupEntry(value, bindingLayout.location, { sampler: true }));
|
|
599
597
|
}
|
|
@@ -698,11 +696,11 @@ function getVertexBufferLayout(shaderLayout, bufferLayout) {
|
|
|
698
696
|
function findAttributeLayout(shaderLayout, name, attributeNames) {
|
|
699
697
|
const attribute = shaderLayout.attributes.find((attribute_) => attribute_.name === name);
|
|
700
698
|
if (!attribute) {
|
|
701
|
-
import_core8.log.warn(`
|
|
699
|
+
import_core8.log.warn(`Unknown attribute ${name}`)();
|
|
702
700
|
return null;
|
|
703
701
|
}
|
|
704
702
|
if (attributeNames.has(name)) {
|
|
705
|
-
throw new Error(`
|
|
703
|
+
throw new Error(`Duplicate attribute ${name}`);
|
|
706
704
|
}
|
|
707
705
|
attributeNames.add(name);
|
|
708
706
|
return attribute;
|
|
@@ -718,9 +716,6 @@ var WebGPURenderPipeline = class extends import_core9.RenderPipeline {
|
|
|
718
716
|
_bindings;
|
|
719
717
|
_bindGroupLayout = null;
|
|
720
718
|
_bindGroup = null;
|
|
721
|
-
get [Symbol.toStringTag]() {
|
|
722
|
-
return "WebGPURenderPipeline";
|
|
723
|
-
}
|
|
724
719
|
constructor(device, props) {
|
|
725
720
|
super(device, props);
|
|
726
721
|
this.device = device;
|
|
@@ -753,11 +748,6 @@ var WebGPURenderPipeline = class extends import_core9.RenderPipeline {
|
|
|
753
748
|
* @todo Do we want to expose BindGroups in the API and remove this?
|
|
754
749
|
*/
|
|
755
750
|
setBindings(bindings) {
|
|
756
|
-
for (const [name, binding] of Object.entries(bindings)) {
|
|
757
|
-
if (this._bindings[name] !== binding) {
|
|
758
|
-
this._bindGroup = null;
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
751
|
Object.assign(this._bindings, bindings);
|
|
762
752
|
}
|
|
763
753
|
/** @todo - should this be moved to renderpass? */
|
|
@@ -807,18 +797,15 @@ var WebGPURenderPipeline = class extends import_core9.RenderPipeline {
|
|
|
807
797
|
entryPoint: this.props.vertexEntryPoint || "main",
|
|
808
798
|
buffers: getVertexBufferLayout(this.shaderLayout, this.props.bufferLayout)
|
|
809
799
|
};
|
|
810
|
-
const targets = [];
|
|
811
|
-
if (this.props.colorAttachmentFormats) {
|
|
812
|
-
for (const format of this.props.colorAttachmentFormats) {
|
|
813
|
-
targets.push(format ? { format: getWebGPUTextureFormat(format) } : null);
|
|
814
|
-
}
|
|
815
|
-
} else {
|
|
816
|
-
targets.push({ format: getWebGPUTextureFormat(this.device.preferredColorFormat) });
|
|
817
|
-
}
|
|
818
800
|
const fragment = {
|
|
819
801
|
module: this.props.fs.handle,
|
|
820
802
|
entryPoint: this.props.fragmentEntryPoint || "main",
|
|
821
|
-
targets
|
|
803
|
+
targets: [
|
|
804
|
+
{
|
|
805
|
+
// TODO exclamation mark hack!
|
|
806
|
+
format: getWebGPUTextureFormat(this.device.getCanvasContext().format)
|
|
807
|
+
}
|
|
808
|
+
]
|
|
822
809
|
};
|
|
823
810
|
const descriptor = {
|
|
824
811
|
vertex,
|
|
@@ -828,12 +815,6 @@ var WebGPURenderPipeline = class extends import_core9.RenderPipeline {
|
|
|
828
815
|
},
|
|
829
816
|
layout: "auto"
|
|
830
817
|
};
|
|
831
|
-
const depthFormat = this.props.depthStencilAttachmentFormat || this.device.preferredDepthFormat;
|
|
832
|
-
if (this.props.parameters.depthWriteEnabled) {
|
|
833
|
-
descriptor.depthStencil = {
|
|
834
|
-
format: getWebGPUTextureFormat(depthFormat)
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
818
|
applyParametersToRenderPipelineDescriptor(descriptor, this.props.parameters);
|
|
838
819
|
return descriptor;
|
|
839
820
|
}
|
|
@@ -1183,7 +1164,11 @@ var WebGPUVertexArray = class extends import_core14.VertexArray {
|
|
|
1183
1164
|
var import_core15 = require("@luma.gl/core");
|
|
1184
1165
|
var WebGPUCanvasContext = class extends import_core15.CanvasContext {
|
|
1185
1166
|
device;
|
|
1186
|
-
|
|
1167
|
+
gpuCanvasContext;
|
|
1168
|
+
/** Format of returned textures: "bgra8unorm", "rgba8unorm", "rgba16float". */
|
|
1169
|
+
format = navigator.gpu.getPreferredCanvasFormat();
|
|
1170
|
+
/** Default stencil format for depth textures */
|
|
1171
|
+
depthStencilFormat = "depth24plus";
|
|
1187
1172
|
depthStencilAttachment = null;
|
|
1188
1173
|
get [Symbol.toStringTag]() {
|
|
1189
1174
|
return "WebGPUCanvasContext";
|
|
@@ -1191,56 +1176,59 @@ var WebGPUCanvasContext = class extends import_core15.CanvasContext {
|
|
|
1191
1176
|
constructor(device, adapter, props) {
|
|
1192
1177
|
super(props);
|
|
1193
1178
|
this.device = device;
|
|
1179
|
+
this.width = -1;
|
|
1180
|
+
this.height = -1;
|
|
1194
1181
|
this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
|
|
1195
|
-
this.
|
|
1182
|
+
this.gpuCanvasContext = this.canvas.getContext("webgpu");
|
|
1183
|
+
this.format = "bgra8unorm";
|
|
1196
1184
|
}
|
|
1197
1185
|
/** Destroy any textures produced while configured and remove the context configuration. */
|
|
1198
1186
|
destroy() {
|
|
1199
|
-
this.
|
|
1187
|
+
this.gpuCanvasContext.unconfigure();
|
|
1200
1188
|
}
|
|
1201
1189
|
/** Update framebuffer with properly resized "swap chain" texture views */
|
|
1202
|
-
getCurrentFramebuffer(
|
|
1203
|
-
|
|
1204
|
-
}) {
|
|
1190
|
+
getCurrentFramebuffer() {
|
|
1191
|
+
this.update();
|
|
1205
1192
|
const currentColorAttachment = this.getCurrentTexture();
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
this.drawingBufferHeight = currentColorAttachment.height;
|
|
1210
|
-
import_core15.log.log(1, `${this}: Resized to compensate for initial canvas size mismatch ${oldWidth}x${oldHeight} => ${this.drawingBufferWidth}x${this.drawingBufferHeight}px`)();
|
|
1211
|
-
}
|
|
1212
|
-
if (options == null ? void 0 : options.depthStencilFormat) {
|
|
1213
|
-
this._createDepthStencilAttachment(options == null ? void 0 : options.depthStencilFormat);
|
|
1214
|
-
}
|
|
1193
|
+
this.width = currentColorAttachment.width;
|
|
1194
|
+
this.height = currentColorAttachment.height;
|
|
1195
|
+
this._createDepthStencilAttachment();
|
|
1215
1196
|
return new WebGPUFramebuffer(this.device, {
|
|
1216
1197
|
colorAttachments: [currentColorAttachment],
|
|
1217
1198
|
depthStencilAttachment: this.depthStencilAttachment
|
|
1218
1199
|
});
|
|
1219
1200
|
}
|
|
1220
1201
|
/** Resizes and updates render targets if necessary */
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1202
|
+
update() {
|
|
1203
|
+
const oldWidth = this.width;
|
|
1204
|
+
const oldHeight = this.height;
|
|
1205
|
+
const [newWidth, newHeight] = this.getPixelSize();
|
|
1206
|
+
const sizeChanged = newWidth !== oldWidth || newHeight !== oldHeight;
|
|
1207
|
+
if (sizeChanged) {
|
|
1208
|
+
this.width = newWidth;
|
|
1209
|
+
this.height = newHeight;
|
|
1210
|
+
if (this.depthStencilAttachment) {
|
|
1211
|
+
this.depthStencilAttachment.destroy();
|
|
1212
|
+
this.depthStencilAttachment = null;
|
|
1213
|
+
}
|
|
1214
|
+
this.gpuCanvasContext.configure({
|
|
1215
|
+
device: this.device.handle,
|
|
1216
|
+
format: getWebGPUTextureFormat(this.format),
|
|
1217
|
+
// Can be used to define e.g. -srgb views
|
|
1218
|
+
// viewFormats: [...]
|
|
1219
|
+
colorSpace: this.props.colorSpace,
|
|
1220
|
+
alphaMode: this.props.alphaMode
|
|
1221
|
+
});
|
|
1222
|
+
import_core15.log.log(1, `${this} Resized ${oldWidth}x${oldHeight} => ${newWidth}x${newHeight}px`)();
|
|
1225
1223
|
}
|
|
1226
|
-
this.handle.configure({
|
|
1227
|
-
device: this.device.handle,
|
|
1228
|
-
format: this.device.preferredColorFormat,
|
|
1229
|
-
// Can be used to define e.g. -srgb views
|
|
1230
|
-
// viewFormats: [...]
|
|
1231
|
-
colorSpace: this.props.colorSpace,
|
|
1232
|
-
alphaMode: this.props.alphaMode
|
|
1233
|
-
});
|
|
1234
1224
|
}
|
|
1235
1225
|
resize(options) {
|
|
1226
|
+
this.update();
|
|
1236
1227
|
if (!this.device.handle)
|
|
1237
1228
|
return;
|
|
1238
|
-
if (this.props.autoResize) {
|
|
1239
|
-
return;
|
|
1240
|
-
}
|
|
1241
1229
|
if (this.canvas) {
|
|
1242
1230
|
const devicePixelRatio = this.getDevicePixelRatio(options == null ? void 0 : options.useDevicePixels);
|
|
1243
|
-
this.
|
|
1231
|
+
this.setDevicePixelRatio(devicePixelRatio, options);
|
|
1244
1232
|
return;
|
|
1245
1233
|
}
|
|
1246
1234
|
}
|
|
@@ -1248,19 +1236,19 @@ var WebGPUCanvasContext = class extends import_core15.CanvasContext {
|
|
|
1248
1236
|
getCurrentTexture() {
|
|
1249
1237
|
return this.device.createTexture({
|
|
1250
1238
|
id: `${this.id}#color-texture`,
|
|
1251
|
-
handle: this.
|
|
1252
|
-
format: this.
|
|
1239
|
+
handle: this.gpuCanvasContext.getCurrentTexture(),
|
|
1240
|
+
format: this.format
|
|
1253
1241
|
});
|
|
1254
1242
|
}
|
|
1255
1243
|
/** We build render targets on demand (i.e. not when size changes but when about to render) */
|
|
1256
|
-
_createDepthStencilAttachment(
|
|
1244
|
+
_createDepthStencilAttachment() {
|
|
1257
1245
|
if (!this.depthStencilAttachment) {
|
|
1258
1246
|
this.depthStencilAttachment = this.device.createTexture({
|
|
1259
1247
|
id: `${this.id}#depth-stencil-texture`,
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1248
|
+
format: this.depthStencilFormat,
|
|
1249
|
+
width: this.width,
|
|
1250
|
+
height: this.height,
|
|
1251
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT
|
|
1264
1252
|
});
|
|
1265
1253
|
}
|
|
1266
1254
|
return this.depthStencilAttachment;
|
|
@@ -1290,25 +1278,22 @@ var WebGPUQuerySet = class extends import_core16.QuerySet {
|
|
|
1290
1278
|
|
|
1291
1279
|
// dist/adapter/webgpu-device.js
|
|
1292
1280
|
var WebGPUDevice = class extends import_core17.Device {
|
|
1293
|
-
/** The underlying WebGPU device */
|
|
1294
|
-
handle;
|
|
1295
1281
|
/** type of this device */
|
|
1296
1282
|
type = "webgpu";
|
|
1297
|
-
|
|
1298
|
-
|
|
1283
|
+
/** The underlying WebGPU device */
|
|
1284
|
+
handle;
|
|
1285
|
+
/* The underlying WebGPU adapter */
|
|
1286
|
+
adapter;
|
|
1287
|
+
/* The underlying WebGPU adapter's info */
|
|
1288
|
+
adapterInfo;
|
|
1299
1289
|
features;
|
|
1300
1290
|
info;
|
|
1301
1291
|
limits;
|
|
1302
1292
|
lost;
|
|
1303
|
-
|
|
1304
|
-
canvasContext;
|
|
1293
|
+
canvasContext = null;
|
|
1305
1294
|
_isLost = false;
|
|
1306
|
-
// canvasContext: WebGPUCanvasContext | null = null;
|
|
1307
1295
|
commandEncoder = null;
|
|
1308
|
-
|
|
1309
|
-
adapter;
|
|
1310
|
-
/* The underlying WebGPU adapter's info */
|
|
1311
|
-
adapterInfo;
|
|
1296
|
+
renderPass = null;
|
|
1312
1297
|
constructor(props, device, adapter, adapterInfo) {
|
|
1313
1298
|
super({ ...props, id: props.id || "webgpu-device" });
|
|
1314
1299
|
this.handle = device;
|
|
@@ -1521,6 +1506,7 @@ var WebGPUAdapter = class extends import_core18.Adapter {
|
|
|
1521
1506
|
return Boolean(typeof navigator !== "undefined" && navigator.gpu);
|
|
1522
1507
|
}
|
|
1523
1508
|
async create(props) {
|
|
1509
|
+
var _a;
|
|
1524
1510
|
if (!navigator.gpu) {
|
|
1525
1511
|
throw new Error("WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu");
|
|
1526
1512
|
}
|
|
@@ -1532,7 +1518,8 @@ var WebGPUAdapter = class extends import_core18.Adapter {
|
|
|
1532
1518
|
if (!adapter) {
|
|
1533
1519
|
throw new Error("Failed to request WebGPU adapter");
|
|
1534
1520
|
}
|
|
1535
|
-
const adapterInfo =
|
|
1521
|
+
const adapterInfo = adapter.info || // @ts-ignore Chrome has removed this function
|
|
1522
|
+
await ((_a = adapter.requestAdapterInfo) == null ? void 0 : _a.call(adapter));
|
|
1536
1523
|
import_core18.log.probe(2, "Adapter available", adapterInfo)();
|
|
1537
1524
|
const requiredFeatures = [];
|
|
1538
1525
|
const requiredLimits = {};
|