Skip to content

Commit adf4420

Browse files
authored
fix(graph): provide proper workaround for pixijs webgpu issue #1899 (#1949)
1 parent dc2c4dc commit adf4420

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

quartz/components/scripts/graph.inline.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,28 @@ type TweenNode = {
6868
stop: () => void
6969
}
7070

71+
// workaround for pixijs webgpu issue: https://github.com/pixijs/pixijs/issues/11389
7172
async function determineGraphicsAPI(): Promise<"webgpu" | "webgl"> {
7273
const adapter = await navigator.gpu?.requestAdapter().catch(() => null)
73-
if (!adapter) {
74+
const device = adapter && (await adapter.requestDevice().catch(() => null))
75+
if (!device) {
7476
return "webgl"
7577
}
76-
// Devices with WebGPU but no float32-blendable feature fail to render the graph
77-
return adapter.features.has("float32-blendable") ? "webgpu" : "webgl"
78+
79+
const canvas = document.createElement("canvas")
80+
const gl =
81+
(canvas.getContext("webgl2") as WebGL2RenderingContext | null) ??
82+
(canvas.getContext("webgl") as WebGLRenderingContext | null)
83+
84+
// we have to return webgl so pixijs automatically falls back to canvas
85+
if (!gl) {
86+
return "webgl"
87+
}
88+
89+
const webglMaxTextures = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS)
90+
const webgpuMaxTextures = device.limits.maxSampledTexturesPerShaderStage
91+
92+
return webglMaxTextures === webgpuMaxTextures ? "webgpu" : "webgl"
7893
}
7994

8095
async function renderGraph(graph: HTMLElement, fullSlug: FullSlug) {

0 commit comments

Comments
 (0)