@luma.gl/webgpu 9.1.1 → 9.1.3

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.
@@ -37,7 +37,7 @@ export function getVertexBufferLayout(
37
37
  let stepMode: 'vertex' | 'instance' = 'vertex';
38
38
  let byteStride = 0;
39
39
  // @ts-ignore
40
- const format: VertexFormat = mapping.format;
40
+ let format: VertexFormat = mapping.format;
41
41
 
42
42
  // interleaved mapping {..., attributes: [{...}, ...]}
43
43
  if (mapping.attributes) {
@@ -48,12 +48,13 @@ export function getVertexBufferLayout(
48
48
 
49
49
  // @ts-ignore
50
50
  const location: number = attributeLayout?.location;
51
+ format = attributeMapping.format || mapping.format;
51
52
 
52
53
  stepMode =
53
54
  attributeLayout?.stepMode ||
54
55
  (attributeLayout?.name.startsWith('instance') ? 'instance' : 'vertex');
55
56
  vertexAttributes.push({
56
- format: getWebGPUVertexFormat(attributeMapping.format || mapping.format),
57
+ format: getWebGPUVertexFormat(format),
57
58
  offset: attributeMapping.byteOffset,
58
59
  shaderLocation: location
59
60
  });
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {Parameters} from '@luma.gl/core';
5
+ import {Parameters, log} from '@luma.gl/core';
6
6
 
7
7
  function addDepthStencil(descriptor: GPURenderPipelineDescriptor): GPUDepthStencilState {
8
8
  descriptor.depthStencil = descriptor.depthStencil || {
@@ -297,19 +297,22 @@ function setParameters(
297
297
  for (const [key, value] of Object.entries(parameters)) {
298
298
  const setterFunction = PARAMETER_TABLE[key as keyof Parameters];
299
299
  if (!setterFunction) {
300
- throw new Error(`Illegal parameter ${key}`);
300
+ log.warn(`Illegal parameter ${key}`)();
301
+ continue;
301
302
  }
302
303
  setterFunction(key, value, pipelineDescriptor);
303
304
  }
304
305
  }
305
306
 
306
307
  function addColorState(descriptor: GPURenderPipelineDescriptor): GPUColorTargetState[] {
307
- // @ts-ignore
308
+ // @ts-ignore GPU types as iterator
308
309
  descriptor.fragment.targets = descriptor.fragment?.targets || [];
309
310
  if (!Array.isArray(descriptor.fragment?.targets)) {
310
- throw new Error('colorstate');
311
+ log.warn('parameters: no targets array')();
311
312
  }
313
+ // @ts-expect-error GPU types as iterator
312
314
  if (descriptor.fragment?.targets?.length === 0) {
315
+ // @ts-expect-error GPU types as iterator
313
316
  descriptor.fragment.targets?.push({});
314
317
  }
315
318
  return descriptor.fragment?.targets as GPUColorTargetState[];
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
+ import type {TypedArray, NumberArray4} from '@math.gl/types';
5
6
  import type {RenderPassProps, RenderPassParameters, Binding} from '@luma.gl/core';
6
7
  import {Buffer, RenderPass, RenderPipeline, log} from '@luma.gl/core';
7
8
  import {WebGPUDevice} from '../webgpu-device';
@@ -182,8 +183,9 @@ export class WebGPURenderPass extends RenderPass {
182
183
  (colorAttachment, index) => ({
183
184
  // clear values
184
185
  loadOp: this.props.clearColor !== false ? 'clear' : 'load',
185
- colorClearValue:
186
- this.props.clearColors?.[index] || this.props.clearColor || RenderPass.defaultClearColor,
186
+ clearValue: convertColor(
187
+ this.props.clearColors?.[index] || this.props.clearColor || RenderPass.defaultClearColor
188
+ ),
187
189
  storeOp: this.props.discard ? 'discard' : 'store',
188
190
  // ...colorAttachment,
189
191
  view: colorAttachment.handle
@@ -226,3 +228,7 @@ export class WebGPURenderPass extends RenderPass {
226
228
  return renderPassDescriptor;
227
229
  }
228
230
  }
231
+
232
+ function convertColor(color: TypedArray | NumberArray4): GPUColor {
233
+ return {r: color[0], g: color[1], b: color[2], a: color[3]};
234
+ }
@@ -178,6 +178,14 @@ export class WebGPURenderPipeline extends RenderPipeline {
178
178
  layout: 'auto'
179
179
  };
180
180
 
181
+ if (this.props.parameters.depthWriteEnabled && this.props.parameters.depthCompare) {
182
+ descriptor.depthStencil = {
183
+ format: 'depth24plus',
184
+ depthWriteEnabled: this.props.parameters.depthWriteEnabled,
185
+ depthCompare: this.props.parameters.depthCompare
186
+ };
187
+ }
188
+
181
189
  // Set parameters on the descriptor
182
190
  applyParametersToRenderPipelineDescriptor(descriptor, this.props.parameters);
183
191
 
@@ -106,9 +106,8 @@ export class WebGPUDevice extends Device {
106
106
  });
107
107
 
108
108
  // Note: WebGPU devices can be created without a canvas, for compute shader purposes
109
- if (props.createCanvasContext) {
110
- const canvasContextProps =
111
- props.createCanvasContext === true ? {} : props.createCanvasContext;
109
+ const canvasContextProps = Device._getCanvasContextProps(props);
110
+ if (canvasContextProps) {
112
111
  this.canvasContext = new WebGPUCanvasContext(this, this.adapter, canvasContextProps);
113
112
  }
114
113
  }