Skip to content

Commit

Permalink
fix(9.1): Minor fixes to unblock WebGPU in deck.gl (#2335)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen authored Feb 17, 2025
1 parent d6198ca commit 4a994a4
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion modules/core/src/adapter/canvas-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export abstract class CanvasContext {
const gl = this.device.gl;
if (!gl) {
// use default device pixel ratio
throw new Error('canvas size');
return this.getPixelSize();
}
return [gl.drawingBufferWidth, gl.drawingBufferHeight];
}
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/adapter/resources/vertex-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ export abstract class VertexArray extends Resource<VertexArrayProps> {

/** @deprecated Set constant attributes (WebGL only) */
setConstantWebGL(location: number, value: TypedArray | null): void {
throw new Error('constant attributes not supported');
this.device.reportError(new Error('constant attributes not supported'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ function getTestCasesFor(device, glslFunc) {
}

test('fp64#sum_fp64', async t => {
console.log('start');
console.log('device');

const glslFunc = 'sum_fp64';
const testCases = getTestCasesFor(webglDevice, glslFunc);
await runTests(webglDevice, {glslFunc, binary: true, op: (a, b) => a + b, testCases, t});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {
getGLParameters,
setGLParameters,
resetGLParameters,
WebGLStateTracker,
webgl2Adapter
WebGLStateTracker
} from '@luma.gl/webgl';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function getVertexBufferLayout(
let stepMode: 'vertex' | 'instance' = 'vertex';
let byteStride = 0;
// @ts-ignore
const format: VertexFormat = mapping.format;
let format: VertexFormat = mapping.format;

// interleaved mapping {..., attributes: [{...}, ...]}
if (mapping.attributes) {
Expand All @@ -48,12 +48,13 @@ export function getVertexBufferLayout(

// @ts-ignore
const location: number = attributeLayout?.location;
format = attributeMapping.format || mapping.format;

stepMode =
attributeLayout?.stepMode ||
(attributeLayout?.name.startsWith('instance') ? 'instance' : 'vertex');
vertexAttributes.push({
format: getWebGPUVertexFormat(attributeMapping.format || mapping.format),
format: getWebGPUVertexFormat(format),
offset: attributeMapping.byteOffset,
shaderLocation: location
});
Expand Down
11 changes: 7 additions & 4 deletions modules/webgpu/src/adapter/helpers/webgpu-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import {Parameters} from '@luma.gl/core';
import {Parameters, log} from '@luma.gl/core';

function addDepthStencil(descriptor: GPURenderPipelineDescriptor): GPUDepthStencilState {
descriptor.depthStencil = descriptor.depthStencil || {
Expand Down Expand Up @@ -297,19 +297,22 @@ function setParameters(
for (const [key, value] of Object.entries(parameters)) {
const setterFunction = PARAMETER_TABLE[key as keyof Parameters];
if (!setterFunction) {
throw new Error(`Illegal parameter ${key}`);
log.warn(`Illegal parameter ${key}`)();
continue;
}
setterFunction(key, value, pipelineDescriptor);
}
}

function addColorState(descriptor: GPURenderPipelineDescriptor): GPUColorTargetState[] {
// @ts-ignore
// @ts-ignore GPU types as iterator
descriptor.fragment.targets = descriptor.fragment?.targets || [];
if (!Array.isArray(descriptor.fragment?.targets)) {
throw new Error('colorstate');
log.warn('parameters: no targets array')();
}
// @ts-expect-error GPU types as iterator
if (descriptor.fragment?.targets?.length === 0) {
// @ts-expect-error GPU types as iterator
descriptor.fragment.targets?.push({});
}
return descriptor.fragment?.targets as GPUColorTargetState[];
Expand Down
10 changes: 8 additions & 2 deletions modules/webgpu/src/adapter/resources/webgpu-render-pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import type {TypedArray, NumberArray4} from '@math.gl/types';
import type {RenderPassProps, RenderPassParameters, Binding} from '@luma.gl/core';
import {Buffer, RenderPass, RenderPipeline, log} from '@luma.gl/core';
import {WebGPUDevice} from '../webgpu-device';
Expand Down Expand Up @@ -182,8 +183,9 @@ export class WebGPURenderPass extends RenderPass {
(colorAttachment, index) => ({
// clear values
loadOp: this.props.clearColor !== false ? 'clear' : 'load',
colorClearValue:
this.props.clearColors?.[index] || this.props.clearColor || RenderPass.defaultClearColor,
clearValue: convertColor(
this.props.clearColors?.[index] || this.props.clearColor || RenderPass.defaultClearColor
),
storeOp: this.props.discard ? 'discard' : 'store',
// ...colorAttachment,
view: colorAttachment.handle
Expand Down Expand Up @@ -226,3 +228,7 @@ export class WebGPURenderPass extends RenderPass {
return renderPassDescriptor;
}
}

function convertColor(color: TypedArray | NumberArray4): GPUColor {
return {r: color[0], g: color[1], b: color[2], a: color[3]};
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ export class WebGPURenderPipeline extends RenderPipeline {
layout: 'auto'
};

if (this.props.parameters.depthWriteEnabled && this.props.parameters.depthCompare) {
descriptor.depthStencil = {
format: 'depth24plus',
depthWriteEnabled: this.props.parameters.depthWriteEnabled,
depthCompare: this.props.parameters.depthCompare
};
}

// Set parameters on the descriptor
applyParametersToRenderPipelineDescriptor(descriptor, this.props.parameters);

Expand Down

0 comments on commit 4a994a4

Please sign in to comment.