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

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 (41) 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-sampler.d.ts +1 -1
  13. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
  14. package/dist/adapter/resources/webgpu-shader.d.ts +1 -1
  15. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  16. package/dist/adapter/resources/webgpu-shader.js +3 -2
  17. package/dist/adapter/resources/webgpu-shader.js.map +1 -1
  18. package/dist/adapter/resources/webgpu-texture.d.ts +10 -3
  19. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  20. package/dist/adapter/resources/webgpu-texture.js +8 -1
  21. package/dist/adapter/resources/webgpu-texture.js.map +1 -1
  22. package/dist/adapter/webgpu-canvas-context.d.ts +1 -1
  23. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  24. package/dist/adapter/webgpu-canvas-context.js.map +1 -1
  25. package/dist/adapter/webgpu-device.d.ts +15 -2
  26. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  27. package/dist/adapter/webgpu-device.js +33 -3
  28. package/dist/adapter/webgpu-device.js.map +1 -1
  29. package/dist/dist.dev.js +386 -172
  30. package/dist/index.cjs +82 -88
  31. package/dist.min.js +4 -4
  32. package/package.json +4 -4
  33. package/src/adapter/resources/webgpu-command-encoder.ts +40 -21
  34. package/src/adapter/resources/webgpu-framebuffer.ts +6 -107
  35. package/src/adapter/resources/webgpu-render-pass.ts +34 -4
  36. package/src/adapter/resources/webgpu-shader.ts +2 -2
  37. package/src/adapter/resources/webgpu-texture.ts +8 -2
  38. package/src/adapter/webgpu-canvas-context.ts +2 -1
  39. package/src/adapter/webgpu-device.ts +73 -4
  40. package/src/.DS_Store +0 -0
  41. package/src/adapter/.DS_Store +0 -0
@@ -1,120 +1,19 @@
1
- import type {FramebufferProps, ColorTextureFormat} from '@luma.gl/api';
2
- import {Framebuffer, Texture} from '@luma.gl/api';
1
+ import type {FramebufferProps} from '@luma.gl/api';
2
+ import {Framebuffer} from '@luma.gl/api';
3
3
  import {WebGPUDevice} from '../webgpu-device';
4
- // import {WebGPUCanvasContext} from '../webgpu-canvas-context';
5
- import {WebGPUTexture} from './webgpu-texture';
6
-
7
- // const DEFAULT_DEPTH_STENCIL_FORMAT: DepthStencilTextureFormat = 'depth24plus';
8
-
9
- // const MAX_COLOR_ATTACHMENTS = 8;
10
4
 
11
5
  /**
12
- * Create new textures with correct size for all attachments.
13
- * @note resize() destroys existing textures (if size has changed).
6
+ * Create new textures with correct size for all attachments.
7
+ * @note resize() destroys existing textures (if size has changed).
14
8
  */
15
9
  export class WebGPUFramebuffer extends Framebuffer {
16
10
  readonly device: WebGPUDevice;
17
11
 
18
- colorAttachments: WebGPUTexture[] = [];
19
- depthStencilAttachment: WebGPUTexture | null = null;
20
-
21
- /** Partial render pass descriptor. Used by WebGPURenderPass */
22
- renderPassDescriptor: {
23
- colorAttachments: GPURenderPassColorAttachment[];
24
- depthStencilAttachment?: GPURenderPassDepthStencilAttachment;
25
- } = {
26
- colorAttachments: []
27
- };
28
-
29
12
  constructor(device: WebGPUDevice, props: FramebufferProps) {
30
13
  super(device, props);
31
14
  this.device = device;
32
15
 
33
- if (props.depthStencilAttachment) {
34
- this.depthStencilAttachment = this.createDepthStencilTexture(props);
35
- }
36
-
37
- if (props.colorAttachments) {
38
- this.colorAttachments = props.colorAttachments.map(colorAttachment => this.createColorTexture(this.props, colorAttachment));
39
- }
40
-
41
- if (this.depthStencilAttachment) {
42
- this.renderPassDescriptor.depthStencilAttachment = {
43
- view: this.depthStencilAttachment.handle.createView(),
44
- // Add default clear values
45
- depthClearValue: 1.0,
46
- depthStoreOp: 'store',
47
- stencilClearValue: 0,
48
- stencilStoreOp: 'store',
49
- }
50
- }
51
-
52
- if (this.colorAttachments.length > 0) {
53
- this.renderPassDescriptor.colorAttachments = this.colorAttachments.map(colorAttachment => ({
54
- view: colorAttachment.handle.createView(),
55
- loadOp: 'clear',
56
- loadValue: [0.0, 0.0, 0.0, 0.0],
57
- storeOp: 'store'
58
- }));
59
- }
60
- }
61
-
62
- /** Create depth stencil texture */
63
- private createDepthStencilTexture(props: FramebufferProps): WebGPUTexture {
64
- if (props.depthStencilAttachment instanceof WebGPUTexture) {
65
- return props.depthStencilAttachment;
66
- }
67
-
68
- if (typeof props.depthStencilAttachment === 'string') {
69
- return this.device._createTexture({
70
- id: 'depth-stencil-attachment',
71
- format: props.depthStencilAttachment,
72
- width: props.width,
73
- height: props.height,
74
- usage: Texture.RENDER_ATTACHMENT
75
- });
76
- }
77
-
78
- throw new Error('type');
79
- }
80
-
81
- private createColorTexture(props: FramebufferProps, texture: Texture | ColorTextureFormat): WebGPUTexture {
82
- if (texture instanceof WebGPUTexture) {
83
- return texture;
84
- }
85
-
86
- if (typeof texture === 'string') {
87
- return this.device._createTexture({
88
- id: 'color-attachment',
89
- format: texture,
90
- width: props.width,
91
- height: props.height,
92
- usage: Texture.RENDER_ATTACHMENT
93
- });
94
- }
95
-
96
- throw new Error('type');
97
- }
98
-
99
- /**
100
- * Create new textures with correct size for all attachments.
101
- * @note destroys existing textures.
102
- */
103
- protected _resizeAttachments(width: number, height: number): void {
104
- for (let i = 0; i < this.colorAttachments.length; ++i) {
105
- if (this.colorAttachments[i]) {
106
- const resizedTexture = this.device._createTexture({...this.colorAttachments[i].props, width, height})
107
- this.colorAttachments[i].destroy();
108
- this.colorAttachments[i] = resizedTexture;
109
- this.renderPassDescriptor.colorAttachments[i].view = resizedTexture.handle.createView();
110
- }
111
- }
112
-
113
- if (this.depthStencilAttachment) {
114
- const resizedTexture = this.device._createTexture({...this.depthStencilAttachment.props, width, height})
115
- this.depthStencilAttachment.destroy();
116
- this.depthStencilAttachment = resizedTexture;
117
- this.renderPassDescriptor.depthStencilAttachment.view = resizedTexture.handle.createView();
118
- }
16
+ // Auto create textures for attachments if needed
17
+ this.autoCreateAttachmentTextures();
119
18
  }
120
19
  }
@@ -1,7 +1,8 @@
1
- import type {RenderPassProps, RenderPassParameters, Binding} from '@luma.gl/api';
1
+ import type {RenderPassProps, RenderPassParameters, Binding, Framebuffer} from '@luma.gl/api';
2
2
  import {Buffer, RenderPass, RenderPipeline, cast} from '@luma.gl/api';
3
3
  import {WebGPUDevice} from '../webgpu-device';
4
4
  import {WebGPUBuffer} from './webgpu-buffer';
5
+ import {WebGPUTexture} from './webgpu-texture';
5
6
  // import {WebGPUCommandEncoder} from './webgpu-command-encoder';
6
7
  import {WebGPURenderPipeline} from './webgpu-render-pipeline';
7
8
 
@@ -15,9 +16,8 @@ export class WebGPURenderPass extends RenderPass {
15
16
  constructor(device: WebGPUDevice, props: RenderPassProps = {}) {
16
17
  super(device, props);
17
18
  this.device = device;
18
- const framebuffer = props.framebuffer || device.canvasContext.getCurrentFramebuffer();
19
- // @ts-expect-error
20
- const renderPassDescriptor = framebuffer.renderPassDescriptor;
19
+ const framebuffer = props.framebuffer || device.canvasContext.getCurrentFramebuffer() ;
20
+ const renderPassDescriptor = this.getRenderPassDescriptor(framebuffer);
21
21
  this.handle = this.props.handle || device.commandEncoder.beginRenderPass(renderPassDescriptor);
22
22
  this.handle.label = this.props.id;
23
23
  }
@@ -128,4 +128,34 @@ export class WebGPURenderPass extends RenderPass {
128
128
  // endPipelineStatisticsQuery(querySet: GPUQuerySet, queryIndex: number): void;
129
129
 
130
130
  // executeBundles(bundles: Iterable<GPURenderBundle>): void;
131
+
132
+ // INTERNAL
133
+
134
+ /**
135
+ * Partial render pass descriptor. Used by WebGPURenderPass.
136
+ * @returns attachments fields of a renderpass descriptor.
137
+ */
138
+ protected getRenderPassDescriptor(framebuffer: Framebuffer): GPURenderPassDescriptor {
139
+ const renderPassDescriptor: GPURenderPassDescriptor = {
140
+ colorAttachments: []
141
+ };
142
+
143
+ renderPassDescriptor.colorAttachments = framebuffer.colorAttachments.map(colorAttachment => ({
144
+ // clear values
145
+ loadOp: 'clear',
146
+ colorClearValue: this.props.clearColor || [0, 0, 0, 0],
147
+ storeOp: this.props.discard? 'discard': 'store',
148
+ // ...colorAttachment,
149
+ view: (colorAttachment as WebGPUTexture).handle.createView()
150
+ }));
151
+
152
+ if (framebuffer.depthStencilAttachment) {
153
+ renderPassDescriptor.depthStencilAttachment = {
154
+ ...this.props,
155
+ view: (framebuffer.depthStencilAttachment as WebGPUTexture).handle.createView()
156
+ };
157
+ }
158
+
159
+ return renderPassDescriptor;
160
+ }
131
161
  }
@@ -43,7 +43,7 @@ export class WebGPUShader extends Shader {
43
43
  }
44
44
 
45
45
  protected createHandle(): GPUShaderModule {
46
- const {source} = this.props;
46
+ const {source, stage} = this.props;
47
47
 
48
48
  let language = this.props.language;
49
49
  // Compile from src
@@ -59,7 +59,7 @@ export class WebGPUShader extends Shader {
59
59
  return this.device.handle.createShaderModule({
60
60
  code: source,
61
61
  // @ts-expect-error
62
- transform: (glsl) => this.device.glslang.compileGLSL(glsl, type)
62
+ transform: (glsl) => this.device.glslang.compileGLSL(glsl, stage)
63
63
  });
64
64
  default:
65
65
  throw new Error(language);
@@ -19,6 +19,9 @@ export class WebGPUTexture extends Texture {
19
19
  readonly view: GPUTextureView;
20
20
  sampler: WebGPUSampler;
21
21
 
22
+ override height: number;
23
+ override width: number;
24
+
22
25
  // static async createFromImageURL(src, usage = 0) {
23
26
  // const img = document.createElement('img');
24
27
  // img.src = src;
@@ -40,6 +43,9 @@ export class WebGPUTexture extends Texture {
40
43
  this.setData({data: this.props.data} );
41
44
  }
42
45
 
46
+ this.width = this.handle.width;
47
+ this.height = this.handle.height;
48
+
43
49
  // Create a default sampler. This mimics the WebGL1 API where sampler props are stored on the texture
44
50
  // this.setSampler(props.sampler);
45
51
  this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);
@@ -116,7 +122,7 @@ export class WebGPUTexture extends Texture {
116
122
  aspect?: 'all' | 'stencil-only' | 'depth-only';
117
123
  colorSpace?: 'srgb';
118
124
  premultipliedAlpha?: boolean;
119
- }): this {
125
+ }): {width: number, height: number} {
120
126
  const {
121
127
  source,
122
128
  width = options.source.width,
@@ -157,7 +163,7 @@ export class WebGPUTexture extends Texture {
157
163
  depth
158
164
  ]
159
165
  );
160
- return this;
166
+ return {width, height};
161
167
  }
162
168
 
163
169
  /*
@@ -24,7 +24,8 @@ export class WebGPUCanvasContext extends CanvasContext {
24
24
  this.height = -1;
25
25
 
26
26
  this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
27
- this.gpuCanvasContext = this.canvas.getContext('webgpu') as GPUCanvasContext;
27
+ // @ts-ignore TODO - we don't handle OffscreenRenderingContext.
28
+ this.gpuCanvasContext = this.canvas.getContext('webgpu') ;
28
29
  // @ts-expect-error TODO this has been replaced
29
30
  this.format = this.gpuCanvasContext.getPreferredFormat(adapter);
30
31
  }
@@ -10,6 +10,7 @@ import type {
10
10
  BufferProps,
11
11
  SamplerProps,
12
12
  ShaderProps,
13
+ Texture,
13
14
  TextureProps,
14
15
  TextureFormat,
15
16
  ExternalTextureProps,
@@ -17,7 +18,8 @@ import type {
17
18
  RenderPipelineProps,
18
19
  ComputePipelineProps,
19
20
  RenderPassProps,
20
- ComputePassProps
21
+ ComputePassProps,
22
+ // CommandEncoderProps
21
23
  } from '@luma.gl/api';
22
24
  import {Device, CanvasContext, log, uid} from '@luma.gl/api';
23
25
  import {WebGPUBuffer} from './resources/webgpu-buffer';
@@ -30,6 +32,7 @@ import {WebGPUFramebuffer} from './resources/webgpu-framebuffer';
30
32
  import {WebGPUComputePipeline} from './resources/webgpu-compute-pipeline';
31
33
  import {WebGPURenderPass} from './resources/webgpu-render-pass';
32
34
  import {WebGPUComputePass} from './resources/webgpu-compute-pass';
35
+ // import {WebGPUCommandEncoder} from './resources/webgpu-command-encoder';
33
36
 
34
37
  import {WebGPUCanvasContext} from './webgpu-canvas-context';
35
38
  // import {loadGlslangModule} from '../glsl/glslang';
@@ -69,7 +72,8 @@ export class WebGPUDevice extends Device {
69
72
  throw new Error('Failed to request WebGPU adapter');
70
73
  }
71
74
 
72
- log.probe(1, 'Adapter available')();
75
+ const adapterInfo = await adapter.requestAdapterInfo();
76
+ log.probe(1, 'Adapter available', adapterInfo)();
73
77
 
74
78
  const gpuDevice = await adapter.requestDevice({
75
79
  requiredFeatures: adapter.features as ReadonlySet<GPUFeatureName>
@@ -162,8 +166,9 @@ export class WebGPUDevice extends Device {
162
166
  return this._isLost;
163
167
  }
164
168
 
165
- _createBuffer(props: BufferProps): WebGPUBuffer {
166
- return new WebGPUBuffer(this, props);
169
+ createBuffer(props: BufferProps | ArrayBuffer | ArrayBufferView): WebGPUBuffer {
170
+ const newProps = this._getBufferProps(props);
171
+ return new WebGPUBuffer(this, newProps);
167
172
  }
168
173
 
169
174
  _createTexture(props: TextureProps): WebGPUTexture {
@@ -210,6 +215,10 @@ export class WebGPUDevice extends Device {
210
215
  return new WebGPUComputePass(this, props);
211
216
  }
212
217
 
218
+ // createCommandEncoder(props: CommandEncoderProps): WebGPUCommandEncoder {
219
+ // return new WebGPUCommandEncoder(this, props);
220
+ // }
221
+
213
222
  createCanvasContext(props: CanvasContextProps): WebGPUCanvasContext {
214
223
  return new WebGPUCanvasContext(this, this.adapter, props);
215
224
  }
@@ -292,4 +301,64 @@ export class WebGPUDevice extends Device {
292
301
 
293
302
  return features;
294
303
  }
304
+
305
+ copyExternalImageToTexture(options: {
306
+ texture: Texture;
307
+ mipLevel?: number;
308
+ aspect?: 'all' | 'stencil-only' | 'depth-only';
309
+ colorSpace?: 'display-p3' | 'srgb';
310
+ premultipliedAlpha?: boolean;
311
+
312
+ source: ImageBitmap | HTMLVideoElement | HTMLCanvasElement | OffscreenCanvas;
313
+ sourceX?: number;
314
+ sourceY?: number;
315
+
316
+ width?: number;
317
+ height?: number;
318
+ depth?: number;
319
+ }): void {
320
+ const {
321
+ source,
322
+ sourceX = 0,
323
+ sourceY = 0,
324
+
325
+ texture,
326
+ mipLevel = 0,
327
+ aspect = 'all',
328
+ colorSpace = 'display-p3',
329
+ premultipliedAlpha = false,
330
+ // destinationX,
331
+ // destinationY,
332
+ // desitnationZ,
333
+
334
+ width = texture.width,
335
+ height = texture.height,
336
+ depth = 1
337
+ } = options;
338
+
339
+ const webGpuTexture = texture as WebGPUTexture;
340
+
341
+ this.handle?.queue.copyExternalImageToTexture(
342
+ // source: GPUImageCopyExternalImage
343
+ {
344
+ source,
345
+ origin: [sourceX, sourceY]
346
+ },
347
+ // destination: GPUImageCopyTextureTagged
348
+ {
349
+ texture: webGpuTexture.handle,
350
+ origin: [0, 0, 0], // [x, y, z],
351
+ mipLevel,
352
+ aspect,
353
+ colorSpace,
354
+ premultipliedAlpha
355
+ },
356
+ // copySize: GPUExtent3D
357
+ [
358
+ width,
359
+ height,
360
+ depth
361
+ ]
362
+ )
363
+ }
295
364
  }
package/src/.DS_Store DELETED
Binary file
Binary file