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

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 (114) hide show
  1. package/LICENSE +32 -0
  2. package/dist/adapter/helpers/accessor-to-format.js.map +1 -1
  3. package/dist/adapter/helpers/convert-texture-format.d.ts +1 -1
  4. package/dist/adapter/helpers/convert-texture-format.js +0 -1
  5. package/dist/adapter/helpers/convert-texture-format.js.map +1 -1
  6. package/dist/adapter/helpers/generate-mipmaps.d.ts +1 -1
  7. package/dist/adapter/helpers/generate-mipmaps.js +1 -8
  8. package/dist/adapter/helpers/generate-mipmaps.js.map +1 -1
  9. package/dist/adapter/helpers/get-bind-group.d.ts +1 -1
  10. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
  11. package/dist/adapter/helpers/get-bind-group.js +0 -9
  12. package/dist/adapter/helpers/get-bind-group.js.map +1 -1
  13. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +1 -1
  14. package/dist/adapter/helpers/get-vertex-buffer-layout.js +3 -17
  15. package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -1
  16. package/dist/adapter/helpers/webgpu-parameters.d.ts +1 -1
  17. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  18. package/dist/adapter/helpers/webgpu-parameters.js +50 -47
  19. package/dist/adapter/helpers/webgpu-parameters.js.map +1 -1
  20. package/dist/adapter/resources/webgpu-buffer.d.ts +3 -4
  21. package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
  22. package/dist/adapter/resources/webgpu-buffer.js +12 -26
  23. package/dist/adapter/resources/webgpu-buffer.js.map +1 -1
  24. package/dist/adapter/resources/webgpu-command-encoder.d.ts +3 -4
  25. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  26. package/dist/adapter/resources/webgpu-command-encoder.js +7 -24
  27. package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -1
  28. package/dist/adapter/resources/webgpu-compute-pass.d.ts +5 -5
  29. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  30. package/dist/adapter/resources/webgpu-compute-pass.js +11 -23
  31. package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -1
  32. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +3 -3
  33. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  34. package/dist/adapter/resources/webgpu-compute-pipeline.js +3 -7
  35. package/dist/adapter/resources/webgpu-compute-pipeline.js.map +1 -1
  36. package/dist/adapter/resources/webgpu-external-texture.d.ts +4 -4
  37. package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
  38. package/dist/adapter/resources/webgpu-external-texture.js +2 -9
  39. package/dist/adapter/resources/webgpu-external-texture.js.map +1 -1
  40. package/dist/adapter/resources/webgpu-framebuffer.d.ts +5 -5
  41. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  42. package/dist/adapter/resources/webgpu-framebuffer.js +12 -30
  43. package/dist/adapter/resources/webgpu-framebuffer.js.map +1 -1
  44. package/dist/adapter/resources/webgpu-query.js.map +1 -1
  45. package/dist/adapter/resources/webgpu-render-pass.d.ts +5 -5
  46. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  47. package/dist/adapter/resources/webgpu-render-pass.js +17 -30
  48. package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
  49. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +7 -4
  50. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  51. package/dist/adapter/resources/webgpu-render-pipeline.js +25 -43
  52. package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
  53. package/dist/adapter/resources/webgpu-sampler.d.ts +3 -3
  54. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
  55. package/dist/adapter/resources/webgpu-sampler.js +8 -7
  56. package/dist/adapter/resources/webgpu-sampler.js.map +1 -1
  57. package/dist/adapter/resources/webgpu-shader.d.ts +4 -4
  58. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  59. package/dist/adapter/resources/webgpu-shader.js +2 -16
  60. package/dist/adapter/resources/webgpu-shader.js.map +1 -1
  61. package/dist/adapter/resources/webgpu-texture.d.ts +4 -4
  62. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  63. package/dist/adapter/resources/webgpu-texture.js +4 -20
  64. package/dist/adapter/resources/webgpu-texture.js.map +1 -1
  65. package/dist/adapter/webgpu-canvas-context.d.ts +5 -7
  66. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  67. package/dist/adapter/webgpu-canvas-context.js +10 -31
  68. package/dist/adapter/webgpu-canvas-context.js.map +1 -1
  69. package/dist/adapter/webgpu-device.d.ts +19 -19
  70. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  71. package/dist/adapter/webgpu-device.js +42 -71
  72. package/dist/adapter/webgpu-device.js.map +1 -1
  73. package/dist/adapter/webgpu-types.js.map +1 -1
  74. package/dist/dist.dev.js +3060 -0
  75. package/dist/glsl/glsllang.js +0 -1
  76. package/dist/glsl/glsllang.js.map +1 -1
  77. package/dist/index.cjs +1442 -0
  78. package/dist/index.d.ts +5 -7
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +5 -7
  81. package/dist/index.js.map +1 -1
  82. package/dist.min.js +17 -0
  83. package/package.json +18 -9
  84. package/src/.DS_Store +0 -0
  85. package/src/adapter/.DS_Store +0 -0
  86. package/src/adapter/helpers/generate-mipmaps.ts +1 -1
  87. package/src/adapter/helpers/get-bind-group.ts +4 -4
  88. package/src/adapter/helpers/get-vertex-buffer-layout.ts +3 -3
  89. package/src/adapter/helpers/webgpu-parameters.ts +55 -46
  90. package/src/adapter/resources/webgpu-buffer.ts +6 -10
  91. package/src/adapter/resources/webgpu-command-encoder.ts +22 -20
  92. package/src/adapter/resources/webgpu-compute-pass.ts +12 -12
  93. package/src/adapter/resources/webgpu-compute-pipeline.ts +5 -4
  94. package/src/adapter/resources/webgpu-external-texture.ts +4 -4
  95. package/src/adapter/resources/webgpu-framebuffer.ts +18 -18
  96. package/src/adapter/resources/webgpu-query.ts +2 -2
  97. package/src/adapter/resources/webgpu-render-pass.ts +15 -12
  98. package/src/adapter/resources/webgpu-render-pipeline.ts +32 -15
  99. package/src/adapter/resources/webgpu-sampler.ts +11 -4
  100. package/src/adapter/resources/webgpu-shader.ts +7 -5
  101. package/src/adapter/resources/webgpu-texture.ts +7 -6
  102. package/src/adapter/webgpu-canvas-context.ts +16 -12
  103. package/src/adapter/webgpu-device.ts +63 -50
  104. package/src/index.ts +6 -9
  105. package/dist/bundle.d.ts +0 -2
  106. package/dist/bundle.d.ts.map +0 -1
  107. package/dist/bundle.js +0 -5
  108. package/dist/bundle.js.map +0 -1
  109. package/dist/init.d.ts +0 -2
  110. package/dist/init.d.ts.map +0 -1
  111. package/dist/init.js +0 -4
  112. package/dist/init.js.map +0 -1
  113. package/src/bundle.ts +0 -4
  114. package/src/init.ts +0 -4
@@ -1,26 +1,23 @@
1
- import {CommandEncoder, CommandEncoderProps, RenderPipeline, Buffer, Texture, cast} from '@luma.gl/api';
2
- import WebGPUDevice from '../webgpu-device';
3
- import WEBGPUBuffer from './webgpu-buffer';
4
- import WebGPUTexture from './webgpu-texture';
1
+ import {CommandEncoder, CommandEncoderProps, Buffer, Texture, cast} from '@luma.gl/api';
2
+ import {WebGPUDevice} from '../webgpu-device';
3
+ import {WebGPUBuffer} from './webgpu-buffer';
4
+ import {WebGPUTexture} from './webgpu-texture';
5
5
 
6
- export default class WebGPUCommandEncoder extends CommandEncoder {
6
+ export class WebGPUCommandEncoder extends CommandEncoder {
7
7
  readonly device: WebGPUDevice;
8
8
  readonly handle: GPUCommandEncoder;
9
9
 
10
10
  constructor(device: WebGPUDevice, props: CommandEncoderProps) {
11
11
  super(props);
12
12
  this.device = device;
13
- this.handle = this.handle || this.createHandle();
14
- this.handle.label = this.props.id;
15
- }
16
-
17
- protected createHandle(): GPUCommandEncoder {
18
- return this.device.handle.createCommandEncoder({
19
- measureExecutionTime: this.props.measureExecutionTime
13
+ this.handle = props.handle || this.device.handle.createCommandEncoder({
14
+ // TODO was this removed in standard?
15
+ // measureExecutionTime: this.props.measureExecutionTime
20
16
  });
17
+ this.handle.label = this.props.id;
21
18
  }
22
19
 
23
- destroy() {}
20
+ override destroy(): void {}
24
21
 
25
22
  finish(options?: {id?: string}): GPUCommandBuffer {
26
23
  return this.finish(options);
@@ -37,9 +34,9 @@ export default class WebGPUCommandEncoder extends CommandEncoder {
37
34
  size?: number
38
35
  }): void {
39
36
  this.handle.copyBufferToBuffer(
40
- cast<WEBGPUBuffer>(options.source).handle,
37
+ cast<WebGPUBuffer>(options.source).handle,
41
38
  options.sourceOffset ?? 0,
42
- cast<WEBGPUBuffer>(options.destination).handle,
39
+ cast<WebGPUBuffer>(options.destination).handle,
43
40
  options.destinationOffset ?? 0,
44
41
  options.size ?? 0
45
42
  );
@@ -60,7 +57,7 @@ export default class WebGPUCommandEncoder extends CommandEncoder {
60
57
  }): void {
61
58
  this.handle.copyBufferToTexture(
62
59
  {
63
- buffer: cast<WEBGPUBuffer>(options.source).handle,
60
+ buffer: cast<WebGPUBuffer>(options.source).handle,
64
61
  offset: options.offset ?? 0,
65
62
  bytesPerRow: options.bytesPerRow,
66
63
  rowsPerImage: options.rowsPerImage,
@@ -71,7 +68,12 @@ export default class WebGPUCommandEncoder extends CommandEncoder {
71
68
  origin: options.origin ?? {},
72
69
  // aspect: options.aspect
73
70
  },
74
- options.extent // default depth?
71
+ {
72
+ // TODO exclamation mark hack
73
+ width: options.extent[0],
74
+ height: options.extent[1],
75
+ depthOrArrayLayers: options.extent[2]
76
+ }
75
77
  );
76
78
  }
77
79
 
@@ -87,15 +89,15 @@ export default class WebGPUCommandEncoder extends CommandEncoder {
87
89
  copySize: GPUExtent3D
88
90
  }): void {}
89
91
 
90
- pushDebugGroup(groupLabel: string): void {
92
+ override pushDebugGroup(groupLabel: string): void {
91
93
  this.handle.pushDebugGroup(groupLabel);
92
94
  }
93
95
 
94
- popDebugGroup(): void {
96
+ override popDebugGroup(): void {
95
97
  this.handle.popDebugGroup();
96
98
  }
97
99
 
98
- insertDebugMarker(markerLabel: string): void {
100
+ override insertDebugMarker(markerLabel: string): void {
99
101
  this.handle.insertDebugMarker(markerLabel);
100
102
  }
101
103
 
@@ -1,29 +1,29 @@
1
1
  import {ComputePass, ComputePassProps, ComputePipeline, Buffer, Binding, cast} from '@luma.gl/api';
2
- import WebGPUDevice from '../webgpu-device';
3
- import WebGPUBuffer from './webgpu-buffer';
4
- // import WebGPUCommandEncoder from './webgpu-command-encoder';
5
- import WebGPUComputePipeline from './webgpu-compute-pipeline';
2
+ import {WebGPUDevice} from '../webgpu-device';
3
+ import {WebGPUBuffer} from './webgpu-buffer';
4
+ // import {WebGPUCommandEncoder} from './webgpu-command-encoder';
5
+ import {WebGPUComputePipeline} from './webgpu-compute-pipeline';
6
6
 
7
- export default class WebGPUComputePass extends ComputePass {
7
+ export class WebGPUComputePass extends ComputePass {
8
8
  readonly device: WebGPUDevice;
9
9
  readonly handle: GPUComputePassEncoder;
10
- _bindGroupLayout: GPUBindGroupLayout;
10
+ _bindGroupLayout: GPUBindGroupLayout | null = null;
11
11
 
12
12
  constructor(device: WebGPUDevice, props: ComputePassProps) {
13
13
  super(device, props);
14
14
  this.device = device;
15
15
 
16
- this.handle = this.props.handle || device.commandEncoder.beginComputePass({
16
+ this.handle = this.props.handle || device.commandEncoder?.beginComputePass({
17
17
  label: this.props.id,
18
18
  // timestampWrites?: GPUComputePassTimestampWrites;
19
19
  });
20
20
  }
21
21
 
22
22
  /** @note no WebGPU destroy method, just gc */
23
- destroy() {}
23
+ override destroy(): void {}
24
24
 
25
- endPass(): void {
26
- this.handle.endPass();
25
+ end(): void {
26
+ this.handle.end();
27
27
  }
28
28
 
29
29
  setPipeline(pipeline: ComputePipeline): void {
@@ -46,7 +46,7 @@ export default class WebGPUComputePass extends ComputePass {
46
46
  * @param z Z dimension of the grid of workgroups to dispatch.
47
47
  */
48
48
  dispatch(x: number, y?: number, z?: number): void {
49
- this.handle.dispatch(x, y, z);
49
+ this.handle.dispatchWorkgroups(x, y, z);
50
50
  }
51
51
 
52
52
  /**
@@ -55,7 +55,7 @@ export default class WebGPUComputePass extends ComputePass {
55
55
  * @param indirectOffset
56
56
  */
57
57
  dispatchIndirect(indirectBuffer: Buffer, indirectOffset: number = 0): void {
58
- this.handle.dispatchIndirect(cast<WebGPUBuffer>(indirectBuffer).handle, indirectOffset);
58
+ this.handle.dispatchWorkgroupsIndirect(cast<WebGPUBuffer>(indirectBuffer).handle, indirectOffset);
59
59
  }
60
60
 
61
61
  pushDebugGroup(groupLabel: string): void {
@@ -1,13 +1,13 @@
1
1
  // prettier-ignore
2
2
  import {ComputePipeline, ComputePipelineProps, cast} from '@luma.gl/api';
3
3
 
4
- import WebGPUDevice from '../webgpu-device';
5
- import WebGPUShader from './webgpu-shader';
4
+ import {WebGPUDevice} from '../webgpu-device';
5
+ import {WebGPUShader} from './webgpu-shader';
6
6
 
7
7
  // COMPUTE PIPELINE
8
8
 
9
9
  /** Creates a new compute pipeline when parameters change */
10
- export default class WebGPUComputePipeline extends ComputePipeline {
10
+ export class WebGPUComputePipeline extends ComputePipeline {
11
11
  device: WebGPUDevice;
12
12
  handle: GPUComputePipeline;
13
13
 
@@ -22,7 +22,8 @@ export default class WebGPUComputePipeline extends ComputePipeline {
22
22
  module,
23
23
  entryPoint: this.props.csEntryPoint,
24
24
  // constants: this.props.csConstants
25
- }
25
+ },
26
+ layout: 'auto'
26
27
  });
27
28
  }
28
29
 
@@ -1,13 +1,13 @@
1
1
  // luma.gl, MIT license
2
2
  import {ExternalTexture, ExternalTextureProps, Sampler, SamplerProps} from '@luma.gl/api';
3
- import type WebGPUDevice from '../webgpu-device';
4
- import WebGPUSampler from './webgpu-sampler';
3
+ import type {WebGPUDevice} from '../webgpu-device';
4
+ import {WebGPUSampler} from './webgpu-sampler';
5
5
 
6
6
  /**
7
7
  * Cheap, temporary texture view for videos
8
8
  * Only valid within same callback, destroyed automatically as a microtask.
9
9
  */
10
- export default class WebGPUExternalTexture extends ExternalTexture {
10
+ export class WebGPUExternalTexture extends ExternalTexture {
11
11
  readonly device: WebGPUDevice;
12
12
  readonly handle: GPUExternalTexture;
13
13
  sampler: WebGPUSampler;
@@ -22,7 +22,7 @@ export default class WebGPUExternalTexture extends ExternalTexture {
22
22
  this.sampler = null;
23
23
  }
24
24
 
25
- destroy(): void {
25
+ override destroy(): void {
26
26
  // External textures are destroyed automatically,
27
27
  // as a microtask, instead of manually or upon garbage collection like other resources.
28
28
  // this.handle.destroy();
@@ -1,23 +1,22 @@
1
1
  import type {FramebufferProps, ColorTextureFormat} from '@luma.gl/api';
2
2
  import {Framebuffer, Texture} from '@luma.gl/api';
3
- import WebGPUDevice from '../webgpu-device';
4
- // import WebGPUCanvasContext from '../webgpu-canvas-context';
5
- import WEBGPUTexture from './webgpu-texture';
6
- import WebGPUTexture from './webgpu-texture';
3
+ import {WebGPUDevice} from '../webgpu-device';
4
+ // import {WebGPUCanvasContext} from '../webgpu-canvas-context';
5
+ import {WebGPUTexture} from './webgpu-texture';
7
6
 
8
7
  // const DEFAULT_DEPTH_STENCIL_FORMAT: DepthStencilTextureFormat = 'depth24plus';
9
8
 
10
- const MAX_COLOR_ATTACHMENTS = 8;
9
+ // const MAX_COLOR_ATTACHMENTS = 8;
11
10
 
12
11
  /**
13
12
  * Create new textures with correct size for all attachments.
14
13
  * @note resize() destroys existing textures (if size has changed).
15
14
  */
16
- export default class WebGPUFramebuffer extends Framebuffer {
15
+ export class WebGPUFramebuffer extends Framebuffer {
17
16
  readonly device: WebGPUDevice;
18
17
 
19
18
  colorAttachments: WebGPUTexture[] = [];
20
- depthStencilAttachment: WebGPUTexture;
19
+ depthStencilAttachment: WebGPUTexture | null = null;
21
20
 
22
21
  /** Partial render pass descriptor. Used by WebGPURenderPass */
23
22
  renderPassDescriptor: {
@@ -43,9 +42,9 @@ export default class WebGPUFramebuffer extends Framebuffer {
43
42
  this.renderPassDescriptor.depthStencilAttachment = {
44
43
  view: this.depthStencilAttachment.handle.createView(),
45
44
  // Add default clear values
46
- depthLoadValue: 1.0,
45
+ depthClearValue: 1.0,
47
46
  depthStoreOp: 'store',
48
- stencilLoadValue: 0,
47
+ stencilClearValue: 0,
49
48
  stencilStoreOp: 'store',
50
49
  }
51
50
  }
@@ -53,6 +52,7 @@ export default class WebGPUFramebuffer extends Framebuffer {
53
52
  if (this.colorAttachments.length > 0) {
54
53
  this.renderPassDescriptor.colorAttachments = this.colorAttachments.map(colorAttachment => ({
55
54
  view: colorAttachment.handle.createView(),
55
+ loadOp: 'clear',
56
56
  loadValue: [0.0, 0.0, 0.0, 0.0],
57
57
  storeOp: 'store'
58
58
  }));
@@ -60,8 +60,8 @@ export default class WebGPUFramebuffer extends Framebuffer {
60
60
  }
61
61
 
62
62
  /** Create depth stencil texture */
63
- private createDepthStencilTexture(props: FramebufferProps): WEBGPUTexture {
64
- if (props.depthStencilAttachment instanceof WEBGPUTexture) {
63
+ private createDepthStencilTexture(props: FramebufferProps): WebGPUTexture {
64
+ if (props.depthStencilAttachment instanceof WebGPUTexture) {
65
65
  return props.depthStencilAttachment;
66
66
  }
67
67
 
@@ -78,8 +78,8 @@ export default class WebGPUFramebuffer extends Framebuffer {
78
78
  throw new Error('type');
79
79
  }
80
80
 
81
- private createColorTexture(props: FramebufferProps, texture: Texture | ColorTextureFormat): WEBGPUTexture {
82
- if (texture instanceof WEBGPUTexture) {
81
+ private createColorTexture(props: FramebufferProps, texture: Texture | ColorTextureFormat): WebGPUTexture {
82
+ if (texture instanceof WebGPUTexture) {
83
83
  return texture;
84
84
  }
85
85
 
@@ -100,7 +100,7 @@ export default class WebGPUFramebuffer extends Framebuffer {
100
100
  * Create new textures with correct size for all attachments.
101
101
  * @note destroys existing textures.
102
102
  */
103
- protected _resizeAttachments(width: number, height: number): void {
103
+ protected _resizeAttachments(width: number, height: number): void {
104
104
  for (let i = 0; i < this.colorAttachments.length; ++i) {
105
105
  if (this.colorAttachments[i]) {
106
106
  const resizedTexture = this.device._createTexture({...this.colorAttachments[i].props, width, height})
@@ -111,10 +111,10 @@ export default class WebGPUFramebuffer extends Framebuffer {
111
111
  }
112
112
 
113
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();
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
118
  }
119
119
  }
120
120
  }
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  import {Resource, Query, QueryProps} from '@luma.gl/api';
3
- import WebGPUDevice from '../webgpu-device';
3
+ import {WebGPUDevice} from '../webgpu-device';
4
4
 
5
5
  export type WebGPUQueryProps = QueryProps & {
6
6
  handle?: any;
@@ -36,7 +36,7 @@ class WebGPUQuery extends Resource<WebGPUQueryProps> implements Query {
36
36
  });
37
37
  }
38
38
 
39
- destroy() {
39
+ override destroy(): void {
40
40
  this.handle.destroy();
41
41
  }
42
42
  }
@@ -1,11 +1,11 @@
1
1
  import type {RenderPassProps, RenderPassParameters, Binding} from '@luma.gl/api';
2
- import {Buffer, RenderPass, RenderPipeline, cast, log} from '@luma.gl/api';
3
- import WebGPUDevice from '../webgpu-device';
4
- import WebGPUBuffer from './webgpu-buffer';
5
- // import WebGPUCommandEncoder from './webgpu-command-encoder';
6
- import WebGPURenderPipeline from './webgpu-render-pipeline';
2
+ import {Buffer, RenderPass, RenderPipeline, cast} from '@luma.gl/api';
3
+ import {WebGPUDevice} from '../webgpu-device';
4
+ import {WebGPUBuffer} from './webgpu-buffer';
5
+ // import {WebGPUCommandEncoder} from './webgpu-command-encoder';
6
+ import {WebGPURenderPipeline} from './webgpu-render-pipeline';
7
7
 
8
- export default class WebGPURenderPass extends RenderPass {
8
+ export class WebGPURenderPass extends RenderPass {
9
9
  readonly device: WebGPUDevice;
10
10
  readonly handle: GPURenderPassEncoder;
11
11
 
@@ -22,10 +22,10 @@ export default class WebGPURenderPass extends RenderPass {
22
22
  this.handle.label = this.props.id;
23
23
  }
24
24
 
25
- destroy() {}
25
+ override destroy(): void {}
26
26
 
27
- endPass(): void {
28
- this.handle.endPass();
27
+ end(): void {
28
+ this.handle.end();
29
29
  }
30
30
 
31
31
  setPipeline(pipeline: RenderPipeline): void {
@@ -35,8 +35,11 @@ export default class WebGPURenderPass extends RenderPass {
35
35
 
36
36
  /** Sets an array of bindings (uniform buffers, samplers, textures, ...) */
37
37
  setBindings(bindings: Record<string, Binding>): void {
38
- this.pipeline.setBindings(bindings);
39
- this.handle.setBindGroup(0, this.pipeline._getBindGroup());
38
+ this.pipeline?.setBindings(bindings);
39
+ const bindGroup = this.pipeline?._getBindGroup();
40
+ if (bindGroup) {
41
+ this.handle.setBindGroup(0, bindGroup);
42
+ }
40
43
  }
41
44
 
42
45
  setIndexBuffer(
@@ -71,7 +74,7 @@ export default class WebGPURenderPass extends RenderPass {
71
74
  );
72
75
  } else {
73
76
  this.handle.draw(
74
- options.vertexCount,
77
+ options.vertexCount || 0,
75
78
  options.instanceCount,
76
79
  options.firstIndex,
77
80
  options.firstInstance
@@ -8,27 +8,30 @@ import {getVertexBufferLayout, getBufferSlots} from '../helpers/get-vertex-buffe
8
8
  // import {mapAccessorToWebGPUFormat} from './helpers/accessor-to-format';
9
9
  // import type {BufferAccessors} from './webgpu-pipeline';
10
10
 
11
- import type WebGPUDevice from '../webgpu-device';
12
- import type WebGPUBuffer from './webgpu-buffer';
13
- import type WebGPUShader from './webgpu-shader';
14
- import type WebGPURenderPass from './webgpu-render-pass';
11
+ import type {WebGPUDevice} from '../webgpu-device';
12
+ import type {WebGPUBuffer} from './webgpu-buffer';
13
+ import type {WebGPUShader} from './webgpu-shader';
14
+ import type {WebGPURenderPass} from './webgpu-render-pass';
15
15
 
16
16
  // RENDER PIPELINE
17
17
 
18
18
  /** Creates a new render pipeline when parameters change */
19
- export default class WebGPURenderPipeline extends RenderPipeline {
19
+ export class WebGPURenderPipeline extends RenderPipeline {
20
20
  device: WebGPUDevice;
21
21
  handle: GPURenderPipeline;
22
22
 
23
+ vs: WebGPUShader;
24
+ fs: WebGPUShader | null = null;
25
+
23
26
  private _bufferSlots: Record<string, number>;
24
27
  private _buffers: Buffer[];
25
- private _indexBuffer: WebGPUBuffer;
28
+ private _indexBuffer: WebGPUBuffer | null = null;
26
29
  // private _firstIndex: number;
27
30
  // private _lastIndex: number;
28
31
 
29
32
  /** For internal use to create BindGroups */
30
33
  private _bindGroupLayout: GPUBindGroupLayout;
31
- private _bindGroup: GPUBindGroup = null;
34
+ private _bindGroup: GPUBindGroup | null = null;
32
35
 
33
36
  constructor(device: WebGPUDevice, props: RenderPipelineProps) {
34
37
  super(device, props);
@@ -36,6 +39,9 @@ export default class WebGPURenderPipeline extends RenderPipeline {
36
39
  this.handle = (this.props.handle as GPURenderPipeline) || this.createHandle();
37
40
  this.handle.label = this.props.id;
38
41
 
42
+ this.vs = cast<WebGPUShader>(props.vs);
43
+ this.fs = cast<WebGPUShader>(props.fs);
44
+
39
45
  this._bufferSlots = getBufferSlots(this.props.layout, this.props.bufferMap);
40
46
  this._buffers = new Array<Buffer>(Object.keys(this._bufferSlots).length).fill(null);
41
47
  this._bindGroupLayout = this.handle.getBindGroupLayout(0);
@@ -50,7 +56,7 @@ export default class WebGPURenderPipeline extends RenderPipeline {
50
56
  return renderPipeline;
51
57
  }
52
58
 
53
- destroy() {
59
+ override destroy(): void {
54
60
  // WebGPURenderPipeline has no destroy method.
55
61
  }
56
62
 
@@ -124,19 +130,29 @@ export default class WebGPURenderPipeline extends RenderPipeline {
124
130
  entryPoint: this.props.fsEntryPoint || 'main',
125
131
  targets: [
126
132
  {
127
- format: getWebGPUTextureFormat(this.device.canvasContext.format)
133
+ // TODO exclamation mark hack!
134
+ format: getWebGPUTextureFormat(this.device?.canvasContext?.format)
128
135
  }
129
136
  ]
130
137
  };
131
138
  }
132
139
 
140
+ // WebGPU has more restrictive topology support than WebGL
141
+ switch (this.props.topology) {
142
+ case 'triangle-fan':
143
+ case 'line-loop':
144
+ throw new Error(`WebGPU does not support primitive topology ${this.props.topology}`);
145
+ default:
146
+ }
147
+
133
148
  // Create a partially populated descriptor
134
- let descriptor: GPURenderPipelineDescriptor = {
149
+ const descriptor: GPURenderPipelineDescriptor = {
135
150
  vertex,
136
151
  fragment,
137
152
  primitive: {
138
153
  topology: this.props.topology
139
- }
154
+ },
155
+ layout: 'auto'
140
156
  };
141
157
 
142
158
  // Set parameters on the descriptor
@@ -155,15 +171,16 @@ export default class WebGPURenderPipeline extends RenderPipeline {
155
171
  firstInstance?: number;
156
172
  baseVertex?: number;
157
173
  }): void {
158
- const webgpuRenderPass =
174
+ const webgpuRenderPass: WebGPURenderPass =
159
175
  cast<WebGPURenderPass>(options.renderPass) || this.device.getDefaultRenderPass();
160
176
 
161
177
  // Set pipeline
162
178
  webgpuRenderPass.handle.setPipeline(this.handle);
163
179
 
164
180
  // Set bindings (uniform buffers, textures etc)
165
- if (this._getBindGroup()) {
166
- webgpuRenderPass.handle.setBindGroup(0, this._getBindGroup());
181
+ const bindGroup = this._getBindGroup();
182
+ if (bindGroup) {
183
+ webgpuRenderPass.handle.setBindGroup(0, bindGroup);
167
184
  }
168
185
 
169
186
  // Set attributes
@@ -180,7 +197,7 @@ export default class WebGPURenderPipeline extends RenderPipeline {
180
197
  );
181
198
  } else {
182
199
  webgpuRenderPass.handle.draw(
183
- options.vertexCount,
200
+ options.vertexCount || 0,
184
201
  options.instanceCount,
185
202
  options.firstIndex,
186
203
  options.firstInstance
@@ -1,5 +1,5 @@
1
1
  import {Sampler, SamplerProps} from '@luma.gl/api';
2
- import type WebGPUDevice from '../webgpu-device';
2
+ import type {WebGPUDevice} from '../webgpu-device';
3
3
 
4
4
  export type WebGPUSamplerProps = SamplerProps & {
5
5
  handle?: GPUSampler;
@@ -8,18 +8,25 @@ export type WebGPUSamplerProps = SamplerProps & {
8
8
  /**
9
9
  *
10
10
  */
11
- export default class WebGPUSampler extends Sampler {
11
+ export class WebGPUSampler extends Sampler {
12
12
  readonly device: WebGPUDevice;
13
13
  readonly handle: GPUSampler;
14
14
 
15
15
  constructor(device: WebGPUDevice, props: WebGPUSamplerProps) {
16
16
  super(device, props);
17
17
  this.device = device;
18
- this.handle = this.handle || this.device.handle.createSampler(this.props);
18
+
19
+ // Prepare sampler props
20
+ const samplerProps: Partial<WebGPUSamplerProps> = {...this.props};
21
+ if (samplerProps.type !== 'comparison-sampler') {
22
+ delete samplerProps.compare;
23
+ }
24
+
25
+ this.handle = this.handle || this.device.handle.createSampler(samplerProps);
19
26
  this.handle.label = this.props.id;
20
27
  }
21
28
 
22
- destroy(): void {
29
+ override destroy(): void {
23
30
  // this.handle.destroy();
24
31
  }
25
32
  }
@@ -1,6 +1,8 @@
1
+ // luma.gl, MIT license
2
+
1
3
  import type {ShaderProps, CompilerMessage} from '@luma.gl/api';
2
4
  import {Shader, log} from '@luma.gl/api';
3
- import type WebGPUDevice from '../webgpu-device';
5
+ import type {WebGPUDevice} from '../webgpu-device';
4
6
 
5
7
  export type WebGPUShaderProps = ShaderProps & {
6
8
  handle?: GPUShaderModule;
@@ -9,7 +11,7 @@ export type WebGPUShaderProps = ShaderProps & {
9
11
  /**
10
12
  * Immutable shader
11
13
  */
12
- export default class WebGPUShader extends Shader {
14
+ export class WebGPUShader extends Shader {
13
15
  readonly device: WebGPUDevice;
14
16
  readonly handle: GPUShaderModule;
15
17
 
@@ -25,7 +27,7 @@ export default class WebGPUShader extends Shader {
25
27
  this._checkCompilationError(this.device.handle.popErrorScope());
26
28
  }
27
29
 
28
- async _checkCompilationError(errorScope: Promise<GPUError>): Promise<void> {
30
+ async _checkCompilationError(errorScope: Promise<GPUError | null>): Promise<void> {
29
31
  const error = await errorScope as GPUValidationError;
30
32
  if (error) {
31
33
  const shaderLog = await this.compilationInfo();
@@ -36,7 +38,7 @@ export default class WebGPUShader extends Shader {
36
38
  }
37
39
  }
38
40
 
39
- destroy() {
41
+ override destroy(): void {
40
42
  // this.handle.destroy();
41
43
  }
42
44
 
@@ -66,7 +68,7 @@ export default class WebGPUShader extends Shader {
66
68
 
67
69
  /** Returns compilation info for this shader */
68
70
  async compilationInfo(): Promise<readonly CompilerMessage[]> {
69
- const compilationInfo = await this.handle.compilationInfo();
71
+ const compilationInfo = await this.handle.getCompilationInfo();
70
72
  return compilationInfo.messages;
71
73
  }
72
74
  }
@@ -1,8 +1,8 @@
1
1
  // luma.gl, MIT license
2
- import {Texture, TextureProps, Sampler, SamplerProps, assert} from '@luma.gl/api';
2
+ import {Texture, TextureProps, Sampler, SamplerProps} from '@luma.gl/api';
3
3
  import {getWebGPUTextureFormat} from '../helpers/convert-texture-format';
4
- import type WebGPUDevice from '../webgpu-device';
5
- import WebGPUSampler from './webgpu-sampler';
4
+ import type {WebGPUDevice} from '../webgpu-device';
5
+ import {WebGPUSampler} from './webgpu-sampler';
6
6
 
7
7
  const BASE_DIMENSIONS: Record<string, '1d' | '2d' | '3d'> = {
8
8
  '1d': '1d',
@@ -13,7 +13,7 @@ const BASE_DIMENSIONS: Record<string, '1d' | '2d' | '3d'> = {
13
13
  '3d': '3d'
14
14
  };
15
15
 
16
- export default class WebGPUTexture extends Texture {
16
+ export class WebGPUTexture extends Texture {
17
17
  readonly device: WebGPUDevice;
18
18
  readonly handle: GPUTexture;
19
19
  readonly view: GPUTextureView;
@@ -41,7 +41,8 @@ export default class WebGPUTexture extends Texture {
41
41
  }
42
42
 
43
43
  // Create a default sampler. This mimics the WebGL1 API where sampler props are stored on the texture
44
- this.setSampler(props.sampler);
44
+ // this.setSampler(props.sampler);
45
+ this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);
45
46
 
46
47
  // TODO - To support texture arrays we need to create custom views...
47
48
  // But we are not ready to expose TextureViews to the public API.
@@ -81,7 +82,7 @@ export default class WebGPUTexture extends Texture {
81
82
  });
82
83
  }
83
84
 
84
- destroy(): void {
85
+ override destroy(): void {
85
86
  this.handle.destroy();
86
87
  }
87
88