@luma.gl/webgpu 9.0.0-alpha.35 → 9.0.0-alpha.37

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 (42) hide show
  1. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
  2. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -1
  3. package/dist/adapter/helpers/webgpu-parameters.js +2 -2
  4. package/dist/adapter/helpers/webgpu-parameters.js.map +1 -1
  5. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  6. package/dist/adapter/resources/webgpu-render-pass.js +23 -4
  7. package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
  8. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +3 -2
  9. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  10. package/dist/adapter/resources/webgpu-render-pipeline.js +11 -12
  11. package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
  12. package/dist/adapter/resources/webgpu-shader.js +1 -1
  13. package/dist/adapter/resources/webgpu-shader.js.map +1 -1
  14. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  15. package/dist/adapter/resources/webgpu-texture.js.map +1 -1
  16. package/dist/adapter/resources/webgpu-vertex-array.d.ts +26 -0
  17. package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -0
  18. package/dist/adapter/resources/webgpu-vertex-array.js +39 -0
  19. package/dist/adapter/resources/webgpu-vertex-array.js.map +1 -0
  20. package/dist/adapter/webgpu-canvas-context.d.ts +8 -2
  21. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  22. package/dist/adapter/webgpu-canvas-context.js +11 -10
  23. package/dist/adapter/webgpu-canvas-context.js.map +1 -1
  24. package/dist/adapter/webgpu-device.d.ts +4 -1
  25. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  26. package/dist/adapter/webgpu-device.js +10 -14
  27. package/dist/adapter/webgpu-device.js.map +1 -1
  28. package/dist/dist.dev.js +250 -110
  29. package/dist/index.cjs +130 -59
  30. package/dist.min.js +5 -5
  31. package/package.json +3 -3
  32. package/src/.DS_Store +0 -0
  33. package/src/adapter/.DS_Store +0 -0
  34. package/src/adapter/helpers/get-vertex-buffer-layout.ts +1 -0
  35. package/src/adapter/helpers/webgpu-parameters.ts +2 -2
  36. package/src/adapter/resources/webgpu-render-pass.ts +27 -4
  37. package/src/adapter/resources/webgpu-render-pipeline.ts +18 -15
  38. package/src/adapter/resources/webgpu-shader.ts +1 -1
  39. package/src/adapter/resources/webgpu-texture.ts +7 -0
  40. package/src/adapter/resources/webgpu-vertex-array.ts +73 -0
  41. package/src/adapter/webgpu-canvas-context.ts +36 -16
  42. package/src/adapter/webgpu-device.ts +21 -13
package/dist/index.cjs CHANGED
@@ -65,7 +65,7 @@ __export(src_exports, {
65
65
  module.exports = __toCommonJS(src_exports);
66
66
 
67
67
  // src/adapter/webgpu-device.ts
68
- var import_core14 = require("@luma.gl/core");
68
+ var import_core15 = require("@luma.gl/core");
69
69
 
70
70
  // src/adapter/resources/webgpu-buffer.ts
71
71
  var import_core = require("@luma.gl/core");
@@ -407,7 +407,7 @@ var WebGPUShader = class extends import_core5.Shader {
407
407
  createHandle() {
408
408
  const { source, stage } = this.props;
409
409
  let language = this.props.language;
410
- if (!language) {
410
+ if (language === "auto") {
411
411
  language = source.includes("->") ? "wgsl" : "glsl";
412
412
  }
413
413
  switch (language) {
@@ -443,8 +443,8 @@ function addDepthStencil(descriptor) {
443
443
  stencilFront: {},
444
444
  stencilBack: {},
445
445
  // TODO can this cause trouble? Should we set to WebGPU defaults? Are there defaults?
446
- depthWriteEnabled: void 0,
447
- depthCompare: void 0
446
+ depthWriteEnabled: false,
447
+ depthCompare: "less-equal"
448
448
  };
449
449
  return descriptor.depthStencil;
450
450
  }
@@ -770,23 +770,25 @@ var WebGPURenderPipeline = class extends import_core8.RenderPipeline {
770
770
  super(device, props);
771
771
  this.fs = null;
772
772
  this._indexBuffer = null;
773
+ // private _firstIndex: number;
774
+ // private _lastIndex: number;
775
+ /** For internal use to create BindGroups */
776
+ this._bindGroupLayout = null;
773
777
  this._bindGroup = null;
774
778
  this.device = device;
775
- this.handle = this.props.handle || this.createHandle();
779
+ this.handle = this.props.handle;
780
+ if (!this.handle) {
781
+ const descriptor = this._getRenderPipelineDescriptor();
782
+ import_core8.log.groupCollapsed(1, `new WebGPURenderPipeline(${this.id})`)();
783
+ import_core8.log.probe(1, JSON.stringify(descriptor, null, 2))();
784
+ import_core8.log.groupEnd(1)();
785
+ this.handle = this.device.handle.createRenderPipeline(descriptor);
786
+ }
776
787
  this.handle.label = this.props.id;
777
788
  this.vs = (0, import_core8.cast)(props.vs);
778
789
  this.fs = (0, import_core8.cast)(props.fs);
779
790
  this._bufferSlots = getBufferSlots(this.props.shaderLayout, this.props.bufferLayout);
780
791
  this._buffers = new Array(Object.keys(this._bufferSlots).length).fill(null);
781
- this._bindGroupLayout = this.handle.getBindGroupLayout(0);
782
- }
783
- createHandle() {
784
- const descriptor = this._getRenderPipelineDescriptor();
785
- const renderPipeline = this.device.handle.createRenderPipeline(descriptor);
786
- import_core8.log.groupCollapsed(1, `new WebGPRenderPipeline(${this.id})`)();
787
- import_core8.log.log(1, JSON.stringify(descriptor, null, 2))();
788
- import_core8.log.groupEnd(1)();
789
- return renderPipeline;
790
792
  }
791
793
  destroy() {
792
794
  }
@@ -811,6 +813,7 @@ var WebGPURenderPipeline = class extends import_core8.RenderPipeline {
811
813
  setBindings(bindings) {
812
814
  if (!(0, import_core8.isObjectEmpty)(this.props.bindings)) {
813
815
  Object.assign(this.props.bindings, bindings);
816
+ this._bindGroupLayout = this._bindGroupLayout || this.handle.getBindGroupLayout(0);
814
817
  this._bindGroup = getBindGroup(
815
818
  this.device.handle,
816
819
  this._bindGroupLayout,
@@ -831,7 +834,9 @@ var WebGPURenderPipeline = class extends import_core8.RenderPipeline {
831
834
  _getBindGroup() {
832
835
  return this._bindGroup;
833
836
  }
834
- /** Populate the complex WebGPU GPURenderPipelineDescriptor */
837
+ /**
838
+ * Populate the complex WebGPU GPURenderPipelineDescriptor
839
+ */
835
840
  _getRenderPipelineDescriptor() {
836
841
  var _a, _b;
837
842
  const vertex = {
@@ -888,8 +893,8 @@ var WebGPURenderPipeline = class extends import_core8.RenderPipeline {
888
893
  } else {
889
894
  webgpuRenderPass.handle.draw(
890
895
  options.vertexCount || 0,
891
- options.instanceCount,
892
- options.firstIndex,
896
+ options.instanceCount || 1,
897
+ // If 0, nothing will be drawn
893
898
  options.firstInstance
894
899
  );
895
900
  }
@@ -947,6 +952,9 @@ var WebGPURenderPass = class extends import_core10.RenderPass {
947
952
  this.device = device;
948
953
  const framebuffer = props.framebuffer || device.canvasContext.getCurrentFramebuffer();
949
954
  const renderPassDescriptor = this.getRenderPassDescriptor(framebuffer);
955
+ import_core10.log.groupCollapsed(1, `new WebGPURenderPass(${this.id})`)();
956
+ import_core10.log.probe(1, JSON.stringify(renderPassDescriptor, null, 2))();
957
+ import_core10.log.groupEnd(1)();
950
958
  this.handle = this.props.handle || device.commandEncoder.beginRenderPass(renderPassDescriptor);
951
959
  this.handle.label = this.props.id;
952
960
  }
@@ -986,7 +994,7 @@ var WebGPURenderPass = class extends import_core10.RenderPass {
986
994
  } else {
987
995
  this.handle.draw(
988
996
  options.vertexCount || 0,
989
- options.instanceCount,
997
+ options.instanceCount || 1,
990
998
  options.firstIndex,
991
999
  options.firstInstance
992
1000
  );
@@ -1042,16 +1050,31 @@ var WebGPURenderPass = class extends import_core10.RenderPass {
1042
1050
  };
1043
1051
  renderPassDescriptor.colorAttachments = framebuffer.colorAttachments.map((colorAttachment) => ({
1044
1052
  // clear values
1045
- loadOp: "clear",
1053
+ loadOp: this.props.clearColor !== false ? "clear" : "load",
1046
1054
  colorClearValue: this.props.clearColor || [0, 0, 0, 0],
1047
1055
  storeOp: this.props.discard ? "discard" : "store",
1048
1056
  // ...colorAttachment,
1049
1057
  view: colorAttachment.handle.createView()
1050
1058
  }));
1051
1059
  if (framebuffer.depthStencilAttachment) {
1052
- renderPassDescriptor.depthStencilAttachment = __spreadProps(__spreadValues({}, this.props), {
1060
+ renderPassDescriptor.depthStencilAttachment = {
1053
1061
  view: framebuffer.depthStencilAttachment.handle.createView()
1054
- });
1062
+ };
1063
+ const { depthStencilAttachment } = renderPassDescriptor;
1064
+ if (this.props.depthReadOnly) {
1065
+ depthStencilAttachment.depthReadOnly = true;
1066
+ }
1067
+ depthStencilAttachment.depthClearValue = this.props.clearDepth || 0;
1068
+ const hasDepthAspect = true;
1069
+ if (hasDepthAspect) {
1070
+ depthStencilAttachment.depthLoadOp = this.props.clearDepth !== false ? "clear" : "load";
1071
+ depthStencilAttachment.depthStoreOp = "store";
1072
+ }
1073
+ const hasStencilAspect = false;
1074
+ if (hasStencilAspect) {
1075
+ depthStencilAttachment.stencilLoadOp = this.props.clearStencil !== false ? "clear" : "load";
1076
+ depthStencilAttachment.stencilStoreOp = "store";
1077
+ }
1055
1078
  }
1056
1079
  return renderPassDescriptor;
1057
1080
  }
@@ -1116,12 +1139,58 @@ var WebGPUComputePass = class extends import_core11.ComputePass {
1116
1139
  // endPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
1117
1140
  };
1118
1141
 
1142
+ // src/adapter/resources/webgpu-vertex-array.ts
1143
+ var import_core12 = require("@luma.gl/core");
1144
+ var import_env = require("@probe.gl/env");
1145
+ var WebGPUVertexArray = class extends import_core12.VertexArray {
1146
+ // Create a VertexArray
1147
+ constructor(device, props) {
1148
+ super(device, props);
1149
+ this.device = device;
1150
+ }
1151
+ get [Symbol.toStringTag]() {
1152
+ return "WebGPUVertexArray";
1153
+ }
1154
+ /** * Attribute 0 can not be disable on most desktop OpenGL based browsers */
1155
+ static isConstantAttributeZeroSupported(device) {
1156
+ return device.info.type === "webgl2" || (0, import_env.getBrowser)() === "Chrome";
1157
+ }
1158
+ destroy() {
1159
+ }
1160
+ /**
1161
+ * Set an elements buffer, for indexed rendering.
1162
+ * Must be a Buffer bound to buffer with usage bit Buffer.INDEX set.
1163
+ */
1164
+ setIndexBuffer(buffer) {
1165
+ this.indexBuffer = buffer;
1166
+ }
1167
+ /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
1168
+ setBuffer(location, buffer) {
1169
+ this.attributes[location] = buffer;
1170
+ }
1171
+ /** Set a location in vertex attributes array to a constant value, disables the location */
1172
+ setConstant(location, value) {
1173
+ import_core12.log.warn(`${this.id} constant attributes not supported on WebGPU`);
1174
+ }
1175
+ bindBeforeRender(renderPass, firstIndex, indexCount) {
1176
+ const webgpuRenderPass = renderPass;
1177
+ const webgpuIndexBuffer = this.indexBuffer;
1178
+ webgpuRenderPass.handle.setIndexBuffer(webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle, webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.indexType);
1179
+ for (let location = 0; location < this.maxVertexAttributes; location++) {
1180
+ const webgpuBuffer = this.attributes[location];
1181
+ webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer.handle);
1182
+ }
1183
+ }
1184
+ unbindAfterRender(renderPass) {
1185
+ }
1186
+ };
1187
+
1119
1188
  // src/adapter/webgpu-canvas-context.ts
1120
- var import_core13 = require("@luma.gl/core");
1189
+ var import_core14 = require("@luma.gl/core");
1121
1190
 
1122
1191
  // src/adapter/resources/webgpu-framebuffer.ts
1123
- var import_core12 = require("@luma.gl/core");
1124
- var WebGPUFramebuffer = class extends import_core12.Framebuffer {
1192
+ var import_core13 = require("@luma.gl/core");
1193
+ var WebGPUFramebuffer = class extends import_core13.Framebuffer {
1125
1194
  constructor(device, props) {
1126
1195
  super(device, props);
1127
1196
  this.device = device;
@@ -1130,32 +1199,37 @@ var WebGPUFramebuffer = class extends import_core12.Framebuffer {
1130
1199
  };
1131
1200
 
1132
1201
  // src/adapter/webgpu-canvas-context.ts
1133
- var WebGPUCanvasContext = class extends import_core13.CanvasContext {
1202
+ var WebGPUCanvasContext = class extends import_core14.CanvasContext {
1134
1203
  constructor(device, adapter, props) {
1135
1204
  super(props);
1205
+ /** Format of returned textures: "bgra8unorm", "rgba8unorm", "rgba16float". */
1206
+ this.format = navigator.gpu.getPreferredCanvasFormat();
1207
+ /** Default stencil format for depth textures */
1136
1208
  this.depthStencilFormat = "depth24plus";
1137
- this.sampleCount = 1;
1138
1209
  this.depthStencilAttachment = null;
1139
1210
  this.device = device;
1140
1211
  this.width = -1;
1141
1212
  this.height = -1;
1142
1213
  this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
1143
1214
  this.gpuCanvasContext = this.canvas.getContext("webgpu");
1144
- this.format = this.gpuCanvasContext.getPreferredFormat(adapter);
1215
+ this.format = "bgra8unorm";
1145
1216
  }
1217
+ /** Destroy any textures produced while configured and remove the context configuration. */
1146
1218
  destroy() {
1147
1219
  this.gpuCanvasContext.unconfigure();
1148
1220
  }
1221
+ getCurrentTexture() {
1222
+ return this.device._createTexture({
1223
+ id: "default-render-target",
1224
+ handle: this.gpuCanvasContext.getCurrentTexture()
1225
+ });
1226
+ }
1149
1227
  /** Update framebuffer with properly resized "swap chain" texture views */
1150
1228
  getCurrentFramebuffer() {
1151
1229
  this.update();
1152
- const currentColorAttachment = this.device.createTexture({
1153
- id: "default-render-target",
1154
- handle: this.gpuCanvasContext.getCurrentTexture(),
1155
- format: this.format,
1156
- width: this.width,
1157
- height: this.height
1158
- });
1230
+ const currentColorAttachment = this.getCurrentTexture();
1231
+ this.width = currentColorAttachment.width;
1232
+ this.height = currentColorAttachment.height;
1159
1233
  this._createDepthStencilAttachment();
1160
1234
  return new WebGPUFramebuffer(this.device, {
1161
1235
  colorAttachments: [currentColorAttachment],
@@ -1176,11 +1250,12 @@ var WebGPUCanvasContext = class extends import_core13.CanvasContext {
1176
1250
  this.gpuCanvasContext.configure({
1177
1251
  device: this.device.handle,
1178
1252
  format: getWebGPUTextureFormat(this.format),
1179
- // size: [this.width, this.height],
1253
+ // Can be used to define e.g. -srgb views
1254
+ // viewFormats: [...]
1180
1255
  colorSpace: this.props.colorSpace,
1181
1256
  alphaMode: this.props.alphaMode
1182
1257
  });
1183
- import_core13.log.log(1, `Resized to ${this.width}x${this.height}px`)();
1258
+ import_core14.log.log(1, `Resized to ${this.width}x${this.height}px`)();
1184
1259
  }
1185
1260
  }
1186
1261
  resize(options) {
@@ -1202,9 +1277,9 @@ var WebGPUCanvasContext = class extends import_core13.CanvasContext {
1202
1277
  };
1203
1278
 
1204
1279
  // src/adapter/webgpu-device.ts
1205
- var _WebGPUDevice = class extends import_core14.Device {
1280
+ var _WebGPUDevice = class extends import_core15.Device {
1206
1281
  constructor(device, adapter, props) {
1207
- super(__spreadProps(__spreadValues({}, props), { id: props.id || (0, import_core14.uid)("webgpu-device") }));
1282
+ super(__spreadProps(__spreadValues({}, props), { id: props.id || (0, import_core15.uid)("webgpu-device") }));
1208
1283
  this.canvasContext = null;
1209
1284
  this.commandEncoder = null;
1210
1285
  this.renderPass = null;
@@ -1218,7 +1293,7 @@ var _WebGPUDevice = class extends import_core14.Device {
1218
1293
  version: "",
1219
1294
  gpu: "unknown",
1220
1295
  // 'nvidia' | 'amd' | 'intel' | 'apple' | 'unknown',
1221
- shadingLanguages: ["glsl", "wgsl"],
1296
+ shadingLanguages: ["wgsl"],
1222
1297
  shadingLanguageVersions: {
1223
1298
  glsl: "450",
1224
1299
  wgsl: "100"
@@ -1231,9 +1306,7 @@ var _WebGPUDevice = class extends import_core14.Device {
1231
1306
  this._isLost = true;
1232
1307
  resolve({ reason: "destroyed", message: lostInfo.message });
1233
1308
  }));
1234
- if (props.canvas) {
1235
- this.canvasContext = new WebGPUCanvasContext(this, this.adapter, { canvas: props.canvas });
1236
- }
1309
+ this.canvasContext = new WebGPUCanvasContext(this, this.adapter, { canvas: props.canvas });
1237
1310
  this.features = this._getFeatures();
1238
1311
  }
1239
1312
  /** Check if WebGPU is available */
@@ -1247,7 +1320,7 @@ var _WebGPUDevice = class extends import_core14.Device {
1247
1320
  "WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu"
1248
1321
  );
1249
1322
  }
1250
- import_core14.log.groupCollapsed(1, "WebGPUDevice created")();
1323
+ import_core15.log.groupCollapsed(1, "WebGPUDevice created")();
1251
1324
  const adapter = yield navigator.gpu.requestAdapter({
1252
1325
  powerPreference: "high-performance"
1253
1326
  // forceSoftware: false
@@ -1256,21 +1329,21 @@ var _WebGPUDevice = class extends import_core14.Device {
1256
1329
  throw new Error("Failed to request WebGPU adapter");
1257
1330
  }
1258
1331
  const adapterInfo = yield adapter.requestAdapterInfo();
1259
- import_core14.log.probe(1, "Adapter available", adapterInfo)();
1332
+ import_core15.log.probe(1, "Adapter available", adapterInfo)();
1260
1333
  const gpuDevice = yield adapter.requestDevice({
1261
1334
  requiredFeatures: adapter.features
1262
1335
  // TODO ensure we obtain best limits
1263
1336
  // requiredLimits: adapter.limits
1264
1337
  });
1265
- import_core14.log.probe(1, "GPUDevice available")();
1338
+ import_core15.log.probe(1, "GPUDevice available")();
1266
1339
  if (typeof props.canvas === "string") {
1267
- yield import_core14.CanvasContext.pageLoaded;
1268
- import_core14.log.probe(1, "DOM is loaded")();
1340
+ yield import_core15.CanvasContext.pageLoaded;
1341
+ import_core15.log.probe(1, "DOM is loaded")();
1269
1342
  }
1270
1343
  const device = new _WebGPUDevice(gpuDevice, adapter, props);
1271
- import_core14.log.probe(1, "Device created", device.info)();
1272
- import_core14.log.table(1, device.info)();
1273
- import_core14.log.groupEnd(1)();
1344
+ import_core15.log.probe(1, "Device created", device.info)();
1345
+ import_core15.log.table(1, device.info)();
1346
+ import_core15.log.groupEnd(1)();
1274
1347
  return device;
1275
1348
  });
1276
1349
  }
@@ -1326,6 +1399,9 @@ var _WebGPUDevice = class extends import_core14.Device {
1326
1399
  createComputePipeline(props) {
1327
1400
  return new WebGPUComputePipeline(this, props);
1328
1401
  }
1402
+ createVertexArray(props) {
1403
+ return new WebGPUVertexArray(this, props);
1404
+ }
1329
1405
  // WebGPU specifics
1330
1406
  /**
1331
1407
  * Allows a render pass to begin against a canvas context
@@ -1349,23 +1425,18 @@ var _WebGPUDevice = class extends import_core14.Device {
1349
1425
  * Gets default renderpass encoder.
1350
1426
  * Creates a new encoder against default canvasContext if not already created
1351
1427
  * @note Called internally by Model.
1428
+ * @deprecated Create explicit pass with device.beginRenderPass
1352
1429
  */
1353
1430
  getDefaultRenderPass() {
1354
- var _a;
1355
- this.renderPass = this.renderPass || this.beginRenderPass({
1356
- framebuffer: (_a = this.canvasContext) == null ? void 0 : _a.getCurrentFramebuffer()
1357
- });
1358
- return this.renderPass;
1431
+ throw new Error("a");
1359
1432
  }
1360
1433
  submit() {
1361
- var _a, _b;
1362
- (_a = this.renderPass) == null ? void 0 : _a.end();
1363
- const commandBuffer = (_b = this.commandEncoder) == null ? void 0 : _b.finish();
1434
+ var _a;
1435
+ const commandBuffer = (_a = this.commandEncoder) == null ? void 0 : _a.finish();
1364
1436
  if (commandBuffer) {
1365
1437
  this.handle.queue.submit([commandBuffer]);
1366
1438
  }
1367
1439
  this.commandEncoder = null;
1368
- this.renderPass = null;
1369
1440
  }
1370
1441
  _getFeatures() {
1371
1442
  const features = new Set(this.handle.features);