@luma.gl/webgpu 9.1.9 → 9.2.0-alpha.2

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 (100) hide show
  1. package/dist/adapter/helpers/accessor-to-format.js +1 -0
  2. package/dist/adapter/helpers/accessor-to-format.js.map +1 -1
  3. package/dist/adapter/helpers/get-bind-group.d.ts +3 -1
  4. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
  5. package/dist/adapter/helpers/get-bind-group.js +28 -10
  6. package/dist/adapter/helpers/get-bind-group.js.map +1 -1
  7. package/dist/adapter/helpers/get-vertex-buffer-layout.js +5 -5
  8. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -1
  9. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  10. package/dist/adapter/helpers/webgpu-parameters.js +89 -75
  11. package/dist/adapter/helpers/webgpu-parameters.js.map +1 -1
  12. package/dist/adapter/resources/webgpu-buffer.d.ts +13 -16
  13. package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
  14. package/dist/adapter/resources/webgpu-buffer.js +132 -93
  15. package/dist/adapter/resources/webgpu-buffer.js.map +1 -1
  16. package/dist/adapter/resources/webgpu-command-buffer.d.ts +10 -0
  17. package/dist/adapter/resources/webgpu-command-buffer.d.ts.map +1 -0
  18. package/dist/adapter/resources/webgpu-command-buffer.js +18 -0
  19. package/dist/adapter/resources/webgpu-command-buffer.js.map +1 -0
  20. package/dist/adapter/resources/webgpu-command-encoder.d.ts +12 -5
  21. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  22. package/dist/adapter/resources/webgpu-command-encoder.js +28 -5
  23. package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -1
  24. package/dist/adapter/resources/webgpu-compute-pass.js +1 -1
  25. package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -1
  26. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +2 -2
  27. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  28. package/dist/adapter/resources/webgpu-compute-pipeline.js.map +1 -1
  29. package/dist/adapter/resources/webgpu-external-texture.d.ts +2 -2
  30. package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
  31. package/dist/adapter/resources/webgpu-external-texture.js.map +1 -1
  32. package/dist/adapter/resources/webgpu-framebuffer.d.ts +3 -2
  33. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  34. package/dist/adapter/resources/webgpu-framebuffer.js +1 -0
  35. package/dist/adapter/resources/webgpu-framebuffer.js.map +1 -1
  36. package/dist/adapter/resources/webgpu-pipeline-layout.d.ts +2 -2
  37. package/dist/adapter/resources/webgpu-pipeline-layout.d.ts.map +1 -1
  38. package/dist/adapter/resources/webgpu-pipeline-layout.js +5 -2
  39. package/dist/adapter/resources/webgpu-pipeline-layout.js.map +1 -1
  40. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  41. package/dist/adapter/resources/webgpu-render-pass.js +11 -6
  42. package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
  43. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +5 -4
  44. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  45. package/dist/adapter/resources/webgpu-render-pipeline.js +33 -20
  46. package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
  47. package/dist/adapter/resources/webgpu-sampler.js +1 -1
  48. package/dist/adapter/resources/webgpu-sampler.js.map +1 -1
  49. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  50. package/dist/adapter/resources/webgpu-shader.js +7 -8
  51. package/dist/adapter/resources/webgpu-shader.js.map +1 -1
  52. package/dist/adapter/resources/webgpu-texture-view.d.ts.map +1 -1
  53. package/dist/adapter/resources/webgpu-texture-view.js +15 -10
  54. package/dist/adapter/resources/webgpu-texture-view.js.map +1 -1
  55. package/dist/adapter/resources/webgpu-texture.d.ts +4 -37
  56. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  57. package/dist/adapter/resources/webgpu-texture.js +97 -126
  58. package/dist/adapter/resources/webgpu-texture.js.map +1 -1
  59. package/dist/adapter/resources/webgpu-vertex-array.d.ts +2 -2
  60. package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -1
  61. package/dist/adapter/resources/webgpu-vertex-array.js +2 -2
  62. package/dist/adapter/resources/webgpu-vertex-array.js.map +1 -1
  63. package/dist/adapter/webgpu-adapter.d.ts +2 -3
  64. package/dist/adapter/webgpu-adapter.d.ts.map +1 -1
  65. package/dist/adapter/webgpu-adapter.js +54 -43
  66. package/dist/adapter/webgpu-adapter.js.map +1 -1
  67. package/dist/adapter/webgpu-canvas-context.d.ts +7 -15
  68. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  69. package/dist/adapter/webgpu-canvas-context.js +50 -72
  70. package/dist/adapter/webgpu-canvas-context.js.map +1 -1
  71. package/dist/adapter/webgpu-device.d.ts +16 -27
  72. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  73. package/dist/adapter/webgpu-device.js +48 -65
  74. package/dist/adapter/webgpu-device.js.map +1 -1
  75. package/dist/dist.dev.js +1919 -1520
  76. package/dist/dist.min.js +6 -5
  77. package/dist/index.cjs +1749 -1397
  78. package/dist/index.cjs.map +4 -4
  79. package/package.json +3 -3
  80. package/src/adapter/helpers/get-bind-group.ts +31 -11
  81. package/src/adapter/helpers/get-vertex-buffer-layout.ts +5 -5
  82. package/src/adapter/helpers/webgpu-parameters.ts +114 -102
  83. package/src/adapter/resources/webgpu-buffer.ts +163 -102
  84. package/src/adapter/resources/webgpu-command-buffer.ts +24 -0
  85. package/src/adapter/resources/webgpu-command-encoder.ts +34 -4
  86. package/src/adapter/resources/webgpu-compute-pass.ts +1 -1
  87. package/src/adapter/resources/webgpu-compute-pipeline.ts +2 -2
  88. package/src/adapter/resources/webgpu-external-texture.ts +2 -2
  89. package/src/adapter/resources/webgpu-framebuffer.ts +3 -2
  90. package/src/adapter/resources/webgpu-pipeline-layout.ts +8 -3
  91. package/src/adapter/resources/webgpu-render-pass.ts +11 -6
  92. package/src/adapter/resources/webgpu-render-pipeline.ts +39 -24
  93. package/src/adapter/resources/webgpu-sampler.ts +1 -1
  94. package/src/adapter/resources/webgpu-shader.ts +11 -8
  95. package/src/adapter/resources/webgpu-texture-view.ts +14 -8
  96. package/src/adapter/resources/webgpu-texture.ts +106 -186
  97. package/src/adapter/resources/webgpu-vertex-array.ts +2 -2
  98. package/src/adapter/webgpu-adapter.ts +72 -58
  99. package/src/adapter/webgpu-canvas-context.ts +62 -82
  100. package/src/adapter/webgpu-device.ts +66 -105
@@ -2,11 +2,11 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
+ // prettier-ignore
5
6
  // / <reference types="@webgpu/types" />
6
7
 
7
- import type {Texture, TextureFormat, CanvasContextProps} from '@luma.gl/core';
8
- import {CanvasContext, log} from '@luma.gl/core';
9
- import {getWebGPUTextureFormat} from './helpers/convert-texture-format';
8
+ import type {TextureFormatDepthStencil, CanvasContextProps} from '@luma.gl/core';
9
+ import {CanvasContext, Texture, log} from '@luma.gl/core';
10
10
  import {WebGPUDevice} from './webgpu-device';
11
11
  import {WebGPUFramebuffer} from './resources/webgpu-framebuffer';
12
12
  import {WebGPUTexture} from './resources/webgpu-texture';
@@ -18,13 +18,9 @@ import {WebGPUTexture} from './resources/webgpu-texture';
18
18
  */
19
19
  export class WebGPUCanvasContext extends CanvasContext {
20
20
  readonly device: WebGPUDevice;
21
- readonly gpuCanvasContext: GPUCanvasContext;
22
- /** Format of returned textures: "bgra8unorm", "rgba8unorm", "rgba16float". */
23
- readonly format: TextureFormat = navigator.gpu.getPreferredCanvasFormat() as TextureFormat;
24
- /** Default stencil format for depth textures */
25
- readonly depthStencilFormat: TextureFormat = 'depth24plus';
21
+ readonly handle: GPUCanvasContext;
26
22
 
27
- private depthStencilAttachment: Texture | null = null;
23
+ private depthStencilAttachment: WebGPUTexture | null = null;
28
24
 
29
25
  get [Symbol.toStringTag](): string {
30
26
  return 'WebGPUCanvasContext';
@@ -32,45 +28,51 @@ export class WebGPUCanvasContext extends CanvasContext {
32
28
 
33
29
  constructor(device: WebGPUDevice, adapter: GPUAdapter, props: CanvasContextProps) {
34
30
  super(props);
31
+
32
+ const context = this.canvas.getContext('webgpu');
33
+ if (!context) {
34
+ throw new Error(`${this}: Failed to create WebGPU canvas context`);
35
+ }
35
36
  this.device = device;
36
- // TODO - ugly hack to trigger first resize
37
- this.width = -1;
38
- this.height = -1;
37
+ this.handle = context;
39
38
 
39
+ // Base class constructor cannot access derived methods/fields, so we need to call these functions in the subclass constructor
40
40
  this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
41
- // @ts-ignore TODO - we don't handle OffscreenRenderingContext.
42
- this.gpuCanvasContext = this.canvas.getContext('webgpu');
43
- // TODO this has been replaced
44
- // this.format = this.gpuCanvasContext.getPreferredFormat(adapter);
45
- this.format = 'bgra8unorm';
41
+ this._updateDevice();
46
42
  }
47
43
 
48
44
  /** Destroy any textures produced while configured and remove the context configuration. */
49
- destroy(): void {
50
- this.gpuCanvasContext.unconfigure();
45
+ override destroy(): void {
46
+ this.handle.unconfigure();
47
+ super.destroy();
51
48
  }
52
49
 
53
50
  /** Update framebuffer with properly resized "swap chain" texture views */
54
- getCurrentFramebuffer(): WebGPUFramebuffer {
55
- // Ensure the canvas context size is updated
56
- this.update();
57
-
58
- // Wrap the current canvas context texture in a luma.gl texture
59
- // const currentColorAttachment = this.device.createTexture({
60
- // id: 'default-render-target',
61
- // handle: this.gpuCanvasContext.getCurrentTexture(),
62
- // format: this.format,
63
- // width: this.width,
64
- // height: this.height
65
- // });
66
-
51
+ getCurrentFramebuffer(
52
+ options: {depthStencilFormat?: TextureFormatDepthStencil | false} = {
53
+ depthStencilFormat: 'depth24plus'
54
+ }
55
+ ): WebGPUFramebuffer {
67
56
  // Wrap the current canvas context texture in a luma.gl texture
68
57
  const currentColorAttachment = this.getCurrentTexture();
69
- this.width = currentColorAttachment.width;
70
- this.height = currentColorAttachment.height;
58
+ // TODO - temporary debug code
59
+ if (
60
+ currentColorAttachment.width !== this.drawingBufferWidth ||
61
+ currentColorAttachment.height !== this.drawingBufferHeight
62
+ ) {
63
+ const [oldWidth, oldHeight] = this.getDrawingBufferSize();
64
+ this.drawingBufferWidth = currentColorAttachment.width;
65
+ this.drawingBufferHeight = currentColorAttachment.height;
66
+ log.log(
67
+ 1,
68
+ `${this}: Resized to compensate for initial canvas size mismatch ${oldWidth}x${oldHeight} => ${this.drawingBufferWidth}x${this.drawingBufferHeight}px`
69
+ )();
70
+ }
71
71
 
72
72
  // Resize the depth stencil attachment
73
- this._createDepthStencilAttachment();
73
+ if (options?.depthStencilFormat) {
74
+ this._createDepthStencilAttachment(options?.depthStencilFormat);
75
+ }
74
76
 
75
77
  return new WebGPUFramebuffer(this.device, {
76
78
  colorAttachments: [currentColorAttachment],
@@ -78,69 +80,47 @@ export class WebGPUCanvasContext extends CanvasContext {
78
80
  });
79
81
  }
80
82
 
81
- /** Resizes and updates render targets if necessary */
82
- update() {
83
- const oldWidth = this.width;
84
- const oldHeight = this.height;
85
- const [newWidth, newHeight] = this.getPixelSize();
86
-
87
- const sizeChanged = newWidth !== oldWidth || newHeight !== oldHeight;
88
-
89
- if (sizeChanged) {
90
- this.width = newWidth;
91
- this.height = newHeight;
92
-
93
- if (this.depthStencilAttachment) {
94
- this.depthStencilAttachment.destroy();
95
- this.depthStencilAttachment = null;
96
- }
97
-
98
- // Reconfigure the canvas size.
99
- // https://www.w3.org/TR/webgpu/#canvas-configuration
100
- this.gpuCanvasContext.configure({
101
- device: this.device.handle,
102
- format: getWebGPUTextureFormat(this.format),
103
- // Can be used to define e.g. -srgb views
104
- // viewFormats: [...]
105
- colorSpace: this.props.colorSpace,
106
- alphaMode: this.props.alphaMode
107
- });
83
+ // IMPLEMENTATION OF ABSTRACT METHODS
108
84
 
109
- log.log(1, `${this} Resized ${oldWidth}x${oldHeight} => ${newWidth}x${newHeight}px`)();
85
+ _updateDevice(): void {
86
+ if (this.depthStencilAttachment) {
87
+ this.depthStencilAttachment.destroy();
88
+ this.depthStencilAttachment = null;
110
89
  }
111
- }
112
-
113
- resize(options?: {width?: number; height?: number; useDevicePixels?: boolean | number}): void {
114
- this.update();
115
90
 
116
- if (!this.device.handle) return;
117
-
118
- // Resize browser context .
119
- if (this.canvas) {
120
- const devicePixelRatio = this.getDevicePixelRatio(options?.useDevicePixels);
121
- this.setDevicePixelRatio(devicePixelRatio, options);
122
- return;
123
- }
91
+ // Reconfigure the canvas size.
92
+ // https://www.w3.org/TR/webgpu/#canvas-configuration
93
+ this.handle.configure({
94
+ device: this.device.handle,
95
+ format: this.device.preferredColorFormat,
96
+ // Can be used to define e.g. -srgb views
97
+ // viewFormats: [...]
98
+ colorSpace: this.props.colorSpace,
99
+ alphaMode: this.props.alphaMode
100
+ });
124
101
  }
125
102
 
126
103
  /** Wrap the current canvas context texture in a luma.gl texture */
127
104
  getCurrentTexture(): WebGPUTexture {
105
+ const handle = this.handle.getCurrentTexture();
128
106
  return this.device.createTexture({
129
107
  id: `${this.id}#color-texture`,
130
- handle: this.gpuCanvasContext.getCurrentTexture(),
131
- format: this.format
108
+ handle,
109
+ format: this.device.preferredColorFormat,
110
+ width: handle.width,
111
+ height: handle.height
132
112
  });
133
113
  }
134
114
 
135
115
  /** We build render targets on demand (i.e. not when size changes but when about to render) */
136
- _createDepthStencilAttachment() {
116
+ _createDepthStencilAttachment(depthStencilFormat: TextureFormatDepthStencil): WebGPUTexture {
137
117
  if (!this.depthStencilAttachment) {
138
118
  this.depthStencilAttachment = this.device.createTexture({
139
119
  id: `${this.id}#depth-stencil-texture`,
140
- format: this.depthStencilFormat,
141
- width: this.width,
142
- height: this.height,
143
- usage: GPUTextureUsage.RENDER_ATTACHMENT
120
+ usage: Texture.RENDER_ATTACHMENT,
121
+ format: depthStencilFormat,
122
+ width: this.drawingBufferWidth,
123
+ height: this.drawingBufferHeight
144
124
  });
145
125
  }
146
126
  return this.depthStencilAttachment;
@@ -10,25 +10,23 @@ import type {
10
10
  DeviceLimits,
11
11
  DeviceFeature,
12
12
  DeviceTextureFormatCapabilities,
13
+ VertexFormat,
13
14
  CanvasContextProps,
14
15
  BufferProps,
15
16
  SamplerProps,
16
17
  ShaderProps,
17
- Texture,
18
18
  TextureProps,
19
19
  ExternalTextureProps,
20
20
  FramebufferProps,
21
21
  RenderPipelineProps,
22
22
  ComputePipelineProps,
23
- RenderPassProps,
24
- ComputePassProps,
25
- // CommandEncoderProps,
26
23
  VertexArrayProps,
27
24
  TransformFeedback,
28
25
  TransformFeedbackProps,
29
26
  QuerySet,
30
27
  QuerySetProps,
31
28
  DeviceProps,
29
+ CommandEncoderProps,
32
30
  PipelineLayoutProps,
33
31
  } from '@luma.gl/core';
34
32
  import {Device, DeviceFeatures} from '@luma.gl/core';
@@ -40,20 +38,16 @@ import {WebGPUShader} from './resources/webgpu-shader';
40
38
  import {WebGPURenderPipeline} from './resources/webgpu-render-pipeline';
41
39
  import {WebGPUFramebuffer} from './resources/webgpu-framebuffer';
42
40
  import {WebGPUComputePipeline} from './resources/webgpu-compute-pipeline';
43
- import {WebGPURenderPass} from './resources/webgpu-render-pass';
44
- import {WebGPUComputePass} from './resources/webgpu-compute-pass';
45
- // import {WebGPUCommandEncoder} from './resources/webgpu-command-encoder';
46
41
  import {WebGPUVertexArray} from './resources/webgpu-vertex-array';
47
42
 
48
43
  import {WebGPUCanvasContext} from './webgpu-canvas-context';
44
+ import {WebGPUCommandEncoder} from './resources/webgpu-command-encoder';
45
+ import {WebGPUCommandBuffer} from './resources/webgpu-command-buffer';
49
46
  import {WebGPUQuerySet} from './resources/webgpu-query-set';
50
47
  import {WebGPUPipelineLayout} from './resources/webgpu-pipeline-layout';
51
48
 
52
49
  /** WebGPU Device implementation */
53
50
  export class WebGPUDevice extends Device {
54
- /** type of this device */
55
- readonly type = 'webgpu';
56
-
57
51
  /** The underlying WebGPU device */
58
52
  readonly handle: GPUDevice;
59
53
  /* The underlying WebGPU adapter */
@@ -61,16 +55,32 @@ export class WebGPUDevice extends Device {
61
55
  /* The underlying WebGPU adapter's info */
62
56
  readonly adapterInfo: GPUAdapterInfo;
63
57
 
58
+ /** type of this device */
59
+ readonly type = 'webgpu';
60
+
61
+ readonly preferredColorFormat = navigator.gpu.getPreferredCanvasFormat() as
62
+ | 'rgba8unorm'
63
+ | 'bgra8unorm';
64
+ readonly preferredDepthFormat = 'depth24plus';
65
+
64
66
  readonly features: DeviceFeatures;
65
67
  readonly info: DeviceInfo;
66
68
  readonly limits: DeviceLimits;
67
69
 
68
70
  readonly lost: Promise<{reason: 'destroyed'; message: string}>;
69
- canvasContext: WebGPUCanvasContext | null = null;
71
+
72
+ override canvasContext: WebGPUCanvasContext | null = null;
70
73
 
71
74
  private _isLost: boolean = false;
72
- commandEncoder: GPUCommandEncoder | null = null;
73
- renderPass: WebGPURenderPass | null = null;
75
+ commandEncoder: WebGPUCommandEncoder;
76
+
77
+ override get [Symbol.toStringTag](): string {
78
+ return 'WebGPUDevice';
79
+ }
80
+
81
+ override toString(): string {
82
+ return `WebGPUDevice(${this.id})`;
83
+ }
74
84
 
75
85
  constructor(
76
86
  props: DeviceProps,
@@ -89,15 +99,12 @@ export class WebGPUDevice extends Device {
89
99
 
90
100
  // Listen for uncaptured WebGPU errors
91
101
  device.addEventListener('uncapturederror', (event: Event) => {
102
+ event.preventDefault();
92
103
  // TODO is this the right way to make sure the error is an Error instance?
93
104
  const errorMessage =
94
105
  event instanceof GPUUncapturedErrorEvent ? event.error.message : 'Unknown WebGPU error';
95
- this.reportError(new Error(errorMessage));
96
- if (this.props.debug) {
97
- // eslint-disable-next-line no-debugger
98
- debugger;
99
- }
100
- event.preventDefault();
106
+ this.reportError(new Error(errorMessage), this)();
107
+ this.debug();
101
108
  });
102
109
 
103
110
  // "Context" loss handling
@@ -112,6 +119,8 @@ export class WebGPUDevice extends Device {
112
119
  if (canvasContextProps) {
113
120
  this.canvasContext = new WebGPUCanvasContext(this, this.adapter, canvasContextProps);
114
121
  }
122
+
123
+ this.commandEncoder = this.createCommandEncoder({});
115
124
  }
116
125
 
117
126
  // TODO
@@ -127,6 +136,15 @@ export class WebGPUDevice extends Device {
127
136
  return this._isLost;
128
137
  }
129
138
 
139
+ override isVertexFormatSupported(format: VertexFormat): boolean {
140
+ const info = this.getVertexFormatInfo(format);
141
+ return !info.webglOnly;
142
+ }
143
+
144
+ getTextureByteAlignment(): number {
145
+ return 1;
146
+ }
147
+
130
148
  createBuffer(props: BufferProps | ArrayBuffer | ArrayBufferView): WebGPUBuffer {
131
149
  const newProps = this._normalizeBufferProps(props);
132
150
  return new WebGPUBuffer(this, newProps);
@@ -164,25 +182,11 @@ export class WebGPUDevice extends Device {
164
182
  return new WebGPUVertexArray(this, props);
165
183
  }
166
184
 
167
- // WebGPU specifics
168
-
169
- /**
170
- * Allows a render pass to begin against a canvas context
171
- * @todo need to support a "Framebuffer" equivalent (aka preconfigured RenderPassDescriptors?).
172
- */
173
- beginRenderPass(props: RenderPassProps): WebGPURenderPass {
174
- this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();
175
- return new WebGPURenderPass(this, props);
185
+ override createCommandEncoder(props?: CommandEncoderProps): WebGPUCommandEncoder {
186
+ return new WebGPUCommandEncoder(this, props);
176
187
  }
177
188
 
178
- beginComputePass(props: ComputePassProps): WebGPUComputePass {
179
- this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();
180
- return new WebGPUComputePass(this, props);
181
- }
182
-
183
- // createCommandEncoder(props: CommandEncoderProps): WebGPUCommandEncoder {
184
- // return new WebGPUCommandEncoder(this, props);
185
- // }
189
+ // WebGPU specifics
186
190
 
187
191
  createTransformFeedback(props: TransformFeedbackProps): TransformFeedback {
188
192
  throw new Error('Transform feedback not supported in WebGPU');
@@ -200,17 +204,33 @@ export class WebGPUDevice extends Device {
200
204
  return new WebGPUPipelineLayout(this, props);
201
205
  }
202
206
 
203
- submit(): void {
204
- const commandBuffer = this.commandEncoder?.finish();
205
- if (commandBuffer) {
206
- this.handle.pushErrorScope('validation');
207
- this.handle.queue.submit([commandBuffer]);
208
- this.handle.popErrorScope().then((error: GPUError | null) => {
209
- if (error) {
210
- this.reportError(new Error(`WebGPU command submission failed: ${error.message}`));
211
- }
212
- });
207
+ submit(commandBuffer?: WebGPUCommandBuffer): void {
208
+ if (!commandBuffer) {
209
+ commandBuffer = this.commandEncoder.finish();
210
+ this.commandEncoder.destroy();
211
+ this.commandEncoder = this.createCommandEncoder({id: `${this.id}-default-encoder`});
213
212
  }
213
+
214
+ this.pushErrorScope('validation');
215
+ this.handle.queue.submit([commandBuffer.handle]);
216
+ this.popErrorScope((error: GPUError) => {
217
+ this.reportError(new Error(`${this} command submission: ${error.message}`), this)();
218
+ this.debug();
219
+ });
220
+ }
221
+
222
+ // WebGPU specific
223
+
224
+ pushErrorScope(scope: 'validation' | 'out-of-memory'): void {
225
+ this.handle.pushErrorScope(scope);
226
+ }
227
+
228
+ popErrorScope(handler: (error: GPUError) => void): void {
229
+ this.handle.popErrorScope().then((error: GPUError | null) => {
230
+ if (error) {
231
+ handler(error);
232
+ }
233
+ });
214
234
  }
215
235
 
216
236
  // PRIVATE METHODS
@@ -284,63 +304,4 @@ export class WebGPUDevice extends Device {
284
304
  }
285
305
  return capabilities;
286
306
  }
287
-
288
- // DEPRECATED METHODS
289
-
290
- // @deprecated
291
- copyExternalImageToTexture(options: {
292
- texture: Texture;
293
- mipLevel?: number;
294
- aspect?: 'all' | 'stencil-only' | 'depth-only';
295
- colorSpace?: 'display-p3' | 'srgb';
296
- premultipliedAlpha?: boolean;
297
-
298
- source: ImageBitmap | HTMLVideoElement | HTMLCanvasElement | OffscreenCanvas;
299
- sourceX?: number;
300
- sourceY?: number;
301
-
302
- width?: number;
303
- height?: number;
304
- depth?: number;
305
- }): void {
306
- const {
307
- source,
308
- sourceX = 0,
309
- sourceY = 0,
310
-
311
- texture,
312
- mipLevel = 0,
313
- aspect = 'all',
314
- colorSpace = 'display-p3',
315
- premultipliedAlpha = false,
316
- // destinationX,
317
- // destinationY,
318
- // desitnationZ,
319
-
320
- width = texture.width,
321
- height = texture.height,
322
- depth = 1
323
- } = options;
324
-
325
- const webGpuTexture = texture as WebGPUTexture;
326
-
327
- this.handle?.queue.copyExternalImageToTexture(
328
- // source: GPUImageCopyExternalImage
329
- {
330
- source,
331
- origin: [sourceX, sourceY]
332
- },
333
- // destination: GPUImageCopyTextureTagged
334
- {
335
- texture: webGpuTexture.handle,
336
- origin: [0, 0, 0], // [x, y, z],
337
- mipLevel,
338
- aspect,
339
- colorSpace,
340
- premultipliedAlpha
341
- },
342
- // copySize: GPUExtent3D
343
- [width, height, depth]
344
- );
345
- }
346
307
  }