@luma.gl/webgpu 9.0.0-alpha.21 → 9.0.0-alpha.23

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 (37) hide show
  1. package/dist/adapter/resources/webgpu-command-encoder.d.ts +3 -11
  2. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  3. package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -1
  4. package/dist/adapter/resources/webgpu-framebuffer.d.ts +0 -17
  5. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  6. package/dist/adapter/resources/webgpu-framebuffer.js +2 -84
  7. package/dist/adapter/resources/webgpu-framebuffer.js.map +1 -1
  8. package/dist/adapter/resources/webgpu-render-pass.d.ts +6 -1
  9. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  10. package/dist/adapter/resources/webgpu-render-pass.js +19 -1
  11. package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
  12. package/dist/adapter/resources/webgpu-shader.js +3 -2
  13. package/dist/adapter/resources/webgpu-shader.js.map +1 -1
  14. package/dist/adapter/resources/webgpu-texture.d.ts +10 -2
  15. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  16. package/dist/adapter/resources/webgpu-texture.js +8 -1
  17. package/dist/adapter/resources/webgpu-texture.js.map +1 -1
  18. package/dist/adapter/webgpu-canvas-context.d.ts +1 -1
  19. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  20. package/dist/adapter/webgpu-canvas-context.js.map +1 -1
  21. package/dist/adapter/webgpu-device.d.ts +16 -2
  22. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  23. package/dist/adapter/webgpu-device.js +31 -2
  24. package/dist/adapter/webgpu-device.js.map +1 -1
  25. package/dist/dist.dev.js +384 -171
  26. package/dist/index.cjs +80 -87
  27. package/dist.min.js +4 -4
  28. package/package.json +3 -3
  29. package/src/adapter/resources/webgpu-command-encoder.ts +40 -21
  30. package/src/adapter/resources/webgpu-framebuffer.ts +6 -107
  31. package/src/adapter/resources/webgpu-render-pass.ts +34 -4
  32. package/src/adapter/resources/webgpu-shader.ts +2 -2
  33. package/src/adapter/resources/webgpu-texture.ts +8 -2
  34. package/src/adapter/webgpu-canvas-context.ts +2 -1
  35. package/src/adapter/webgpu-device.ts +71 -3
  36. package/src/.DS_Store +0 -0
  37. package/src/adapter/.DS_Store +0 -0
package/dist/index.cjs CHANGED
@@ -189,6 +189,8 @@ var WebGPUTexture = class extends import_api3.Texture {
189
189
  if (this.props.data) {
190
190
  this.setData({ data: this.props.data });
191
191
  }
192
+ this.width = this.handle.width;
193
+ this.height = this.handle.height;
192
194
  this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);
193
195
  this.view = this.handle.createView({
194
196
  // format: this.props.format,
@@ -273,7 +275,7 @@ var WebGPUTexture = class extends import_api3.Texture {
273
275
  depth
274
276
  ]
275
277
  );
276
- return this;
278
+ return { width, height };
277
279
  }
278
280
  /*
279
281
  async readPixels() {
@@ -403,7 +405,7 @@ var WebGPUShader = class extends import_api5.Shader {
403
405
  destroy() {
404
406
  }
405
407
  createHandle() {
406
- const { source } = this.props;
408
+ const { source, stage } = this.props;
407
409
  let language = this.props.language;
408
410
  if (!language) {
409
411
  language = source.includes("->") ? "wgsl" : "glsl";
@@ -415,7 +417,7 @@ var WebGPUShader = class extends import_api5.Shader {
415
417
  return this.device.handle.createShaderModule({
416
418
  code: source,
417
419
  // @ts-expect-error
418
- transform: (glsl) => this.device.glslang.compileGLSL(glsl, type)
420
+ transform: (glsl) => this.device.glslang.compileGLSL(glsl, stage)
419
421
  });
420
422
  default:
421
423
  throw new Error(language);
@@ -932,7 +934,7 @@ var WebGPURenderPass = class extends import_api10.RenderPass {
932
934
  this.pipeline = null;
933
935
  this.device = device;
934
936
  const framebuffer = props.framebuffer || device.canvasContext.getCurrentFramebuffer();
935
- const renderPassDescriptor = framebuffer.renderPassDescriptor;
937
+ const renderPassDescriptor = this.getRenderPassDescriptor(framebuffer);
936
938
  this.handle = this.props.handle || device.commandEncoder.beginRenderPass(renderPassDescriptor);
937
939
  this.handle.label = this.props.id;
938
940
  }
@@ -1017,6 +1019,30 @@ var WebGPURenderPass = class extends import_api10.RenderPass {
1017
1019
  // beginPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
1018
1020
  // endPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
1019
1021
  // executeBundles(bundles: Iterable<GPURenderBundle>): void;
1022
+ // INTERNAL
1023
+ /**
1024
+ * Partial render pass descriptor. Used by WebGPURenderPass.
1025
+ * @returns attachments fields of a renderpass descriptor.
1026
+ */
1027
+ getRenderPassDescriptor(framebuffer) {
1028
+ const renderPassDescriptor = {
1029
+ colorAttachments: []
1030
+ };
1031
+ renderPassDescriptor.colorAttachments = framebuffer.colorAttachments.map((colorAttachment) => ({
1032
+ // clear values
1033
+ loadOp: "clear",
1034
+ colorClearValue: this.props.clearColor || [0, 0, 0, 0],
1035
+ storeOp: this.props.discard ? "discard" : "store",
1036
+ // ...colorAttachment,
1037
+ view: colorAttachment.handle.createView()
1038
+ }));
1039
+ if (framebuffer.depthStencilAttachment) {
1040
+ renderPassDescriptor.depthStencilAttachment = __spreadProps(__spreadValues({}, this.props), {
1041
+ view: framebuffer.depthStencilAttachment.handle.createView()
1042
+ });
1043
+ }
1044
+ return renderPassDescriptor;
1045
+ }
1020
1046
  };
1021
1047
 
1022
1048
  // src/adapter/resources/webgpu-compute-pass.ts
@@ -1086,88 +1112,8 @@ var import_api12 = require("@luma.gl/api");
1086
1112
  var WebGPUFramebuffer = class extends import_api12.Framebuffer {
1087
1113
  constructor(device, props) {
1088
1114
  super(device, props);
1089
- this.colorAttachments = [];
1090
- this.depthStencilAttachment = null;
1091
- /** Partial render pass descriptor. Used by WebGPURenderPass */
1092
- this.renderPassDescriptor = {
1093
- colorAttachments: []
1094
- };
1095
1115
  this.device = device;
1096
- if (props.depthStencilAttachment) {
1097
- this.depthStencilAttachment = this.createDepthStencilTexture(props);
1098
- }
1099
- if (props.colorAttachments) {
1100
- this.colorAttachments = props.colorAttachments.map((colorAttachment) => this.createColorTexture(this.props, colorAttachment));
1101
- }
1102
- if (this.depthStencilAttachment) {
1103
- this.renderPassDescriptor.depthStencilAttachment = {
1104
- view: this.depthStencilAttachment.handle.createView(),
1105
- // Add default clear values
1106
- depthClearValue: 1,
1107
- depthStoreOp: "store",
1108
- stencilClearValue: 0,
1109
- stencilStoreOp: "store"
1110
- };
1111
- }
1112
- if (this.colorAttachments.length > 0) {
1113
- this.renderPassDescriptor.colorAttachments = this.colorAttachments.map((colorAttachment) => ({
1114
- view: colorAttachment.handle.createView(),
1115
- loadOp: "clear",
1116
- loadValue: [0, 0, 0, 0],
1117
- storeOp: "store"
1118
- }));
1119
- }
1120
- }
1121
- /** Create depth stencil texture */
1122
- createDepthStencilTexture(props) {
1123
- if (props.depthStencilAttachment instanceof WebGPUTexture) {
1124
- return props.depthStencilAttachment;
1125
- }
1126
- if (typeof props.depthStencilAttachment === "string") {
1127
- return this.device._createTexture({
1128
- id: "depth-stencil-attachment",
1129
- format: props.depthStencilAttachment,
1130
- width: props.width,
1131
- height: props.height,
1132
- usage: import_api12.Texture.RENDER_ATTACHMENT
1133
- });
1134
- }
1135
- throw new Error("type");
1136
- }
1137
- createColorTexture(props, texture) {
1138
- if (texture instanceof WebGPUTexture) {
1139
- return texture;
1140
- }
1141
- if (typeof texture === "string") {
1142
- return this.device._createTexture({
1143
- id: "color-attachment",
1144
- format: texture,
1145
- width: props.width,
1146
- height: props.height,
1147
- usage: import_api12.Texture.RENDER_ATTACHMENT
1148
- });
1149
- }
1150
- throw new Error("type");
1151
- }
1152
- /**
1153
- * Create new textures with correct size for all attachments.
1154
- * @note destroys existing textures.
1155
- */
1156
- _resizeAttachments(width, height) {
1157
- for (let i = 0; i < this.colorAttachments.length; ++i) {
1158
- if (this.colorAttachments[i]) {
1159
- const resizedTexture = this.device._createTexture(__spreadProps(__spreadValues({}, this.colorAttachments[i].props), { width, height }));
1160
- this.colorAttachments[i].destroy();
1161
- this.colorAttachments[i] = resizedTexture;
1162
- this.renderPassDescriptor.colorAttachments[i].view = resizedTexture.handle.createView();
1163
- }
1164
- }
1165
- if (this.depthStencilAttachment) {
1166
- const resizedTexture = this.device._createTexture(__spreadProps(__spreadValues({}, this.depthStencilAttachment.props), { width, height }));
1167
- this.depthStencilAttachment.destroy();
1168
- this.depthStencilAttachment = resizedTexture;
1169
- this.renderPassDescriptor.depthStencilAttachment.view = resizedTexture.handle.createView();
1170
- }
1116
+ this.autoCreateAttachmentTextures();
1171
1117
  }
1172
1118
  };
1173
1119
 
@@ -1342,8 +1288,9 @@ var _WebGPUDevice = class extends import_api14.Device {
1342
1288
  get isLost() {
1343
1289
  return this._isLost;
1344
1290
  }
1345
- _createBuffer(props) {
1346
- return new WebGPUBuffer(this, props);
1291
+ createBuffer(props) {
1292
+ const newProps = this._getBufferProps(props);
1293
+ return new WebGPUBuffer(this, newProps);
1347
1294
  }
1348
1295
  _createTexture(props) {
1349
1296
  return new WebGPUTexture(this, props);
@@ -1379,6 +1326,9 @@ var _WebGPUDevice = class extends import_api14.Device {
1379
1326
  this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();
1380
1327
  return new WebGPUComputePass(this, props);
1381
1328
  }
1329
+ // createCommandEncoder(props: CommandEncoderProps): WebGPUCommandEncoder {
1330
+ // return new WebGPUCommandEncoder(this, props);
1331
+ // }
1382
1332
  createCanvasContext(props) {
1383
1333
  return new WebGPUCanvasContext(this, this.adapter, props);
1384
1334
  }
@@ -1437,6 +1387,49 @@ var _WebGPUDevice = class extends import_api14.Device {
1437
1387
  features.add("glsl-texture-lod");
1438
1388
  return features;
1439
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
+ [
1427
+ width,
1428
+ height,
1429
+ depth
1430
+ ]
1431
+ );
1432
+ }
1440
1433
  };
1441
1434
  var WebGPUDevice = _WebGPUDevice;
1442
1435
  WebGPUDevice.type = "webgpu";