gsplat: WebGPU GPU-sort renderer flickers with a static camera (equal depth keys resolve in a different order every frame)
Description
With the WebGPU GPU-sort renderer (GSPLAT_RENDERER_RASTER_GPU_SORT, which GSPLAT_RENDERER_AUTO picks on WebGPU), splats that overlap on screen and share a sort key are blended in a different order every frame. With a static camera the image keeps changing (fine-grained shimmer across the whole scene). With on-demand rendering (app.autoRender = false) every re-render "pops". WebGL2, or app.scene.gsplat.renderer = GSPLAT_RENDERER_RASTER_CPU_SORT on WebGPU, is stable.
This is separate from #9493 (sort key precision, shipped in 2.22.4): 2.22.4 and current main still flicker.
Cause. compute-gsplat-projector.js compacts the splats that survive projection with two atomics: atomicAdd(&wgCount, 1u) for the slot inside the workgroup, and atomicAdd(&renderCounter[0], total) for the workgroup's output range. Both orders depend on GPU scheduling, so the sort input is permuted differently every frame. The radix sort is stable, so splats with equal keys keep that (effectively random) input order. Depth keys are clamp(round(log2(n / 4)), 10, 20) bits, so ties are common in dense scenes. The CPU worker sort gets its input in a fixed order, which is why WebGL2 does not flicker. The hybrid renderer also re-sorts every frame, even with a static camera, so the new order shows up on every frame.
Measurements. Static camera, headless Chrome, % of pixels whose largest channel difference is > 8/255 between screenshots taken 1–4 s apart:
| Scene | WebGPU, GPU sort | WebGL2 / CPU sort |
|---|---|---|
Repro below: 5,000 equal-depth splats, main @ 25b638c |
37–40% | 0% |
| Same repro, 2.22.4 from jsDelivr (exactly as below) | 39–40% | 0% |
4M-splat photogrammetry capture (2.22.3, 2.22.4, main) |
4.3–4.8% | 0% |
20M-splat capture (2.22.4, main) |
1.0% | 0% |
- Platform: macOS 26.6.2, Apple M4 Pro (Metal), Chrome 153.0.8010.53, WebGPU.
- The 4M/20M captures are private and can't be shared. The repro below shows the same mechanism in its purest form: every key is equal.
Steps to Reproduce
- Save this as
repro.htmland serve it fromhttp://localhost(e.g.npx serve). It uses playcanvas 2.22.4 from jsDelivr. - Open it in a WebGPU-capable browser. The camera is static, but the coloured square keeps shimmering.
- Open
repro.html?backend=webgl2: the image is stable.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>gsplat equal-depth flicker repro</title>
<style>html,body{margin:0;height:100%;background:#000;overflow:hidden}canvas{position:fixed;inset:0;width:100%;height:100%}</style>
</head>
<body>
<canvas id="c"></canvas>
<script type="module">
// 5,000 overlapping semi-transparent splats in the z = 0 plane, viewed head-on: every splat has the same depth, so the
// back-to-front order is decided entirely by how the sort breaks ties. ?backend=webgl2 forces the CPU-sort path.
import * as pc from 'https://cdn.jsdelivr.net/npm/[email protected]/build/playcanvas.mjs';
const q = new URLSearchParams(location.search);
const canvas = document.getElementById('c');
const device = await pc.createGraphicsDevice(canvas, {
deviceTypes: q.get('backend') === 'webgl2' ? [pc.DEVICETYPE_WEBGL2] : [pc.DEVICETYPE_WEBGPU, pc.DEVICETYPE_WEBGL2]
});
const app = new pc.AppBase(canvas);
const opts = new pc.AppOptions();
opts.graphicsDevice = device;
opts.componentSystems = [pc.CameraComponentSystem, pc.GSplatComponentSystem];
app.init(opts);
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
app.setCanvasResolution(pc.RESOLUTION_AUTO);
app.start();
const N = 5000;
const container = new pc.GSplatContainer(device, N, pc.GSplatFormat.createSimpleFormat(device));
const centerTex = container.getTexture('dataCenter');
const colorTex = container.getTexture('dataColor');
const center = centerTex.lock();
const color = colorTex.lock();
let seed = 1;
const rnd = () => (seed = (seed * 16807) % 2147483647) / 2147483647; // fixed seed: same scene every load
for (let i = 0; i < N; i++) {
const x = rnd() - 0.5, y = rnd() - 0.5;
center.set([x, y, 0, 0.03], i * 4); // x, y, z, size
color.set([rnd(), rnd(), rnd(), 0.5].map(pc.FloatPacking.float2Half), i * 4);
container.centers.set([x, y, 0], i * 3);
}
centerTex.unlock();
colorTex.unlock();
container.aabb = new pc.BoundingBox(new pc.Vec3(0, 0, 0), new pc.Vec3(0.6, 0.6, 0.1));
container.update(N);
const splat = new pc.Entity('splat');
splat.addComponent('gsplat', { unified: true });
splat.gsplat.resource = container;
app.root.addChild(splat);
const camera = new pc.Entity('camera');
camera.addComponent('camera', { clearColor: new pc.Color(0, 0, 0), fov: 45 });
camera.setPosition(0, 0, 1.6); // looking down -Z: all splats at identical depth
app.root.addChild(camera);
</script>
</body>
</html>Suggested fix
Rank survivors inside each workgroup by thread index (a survivor bitmask + popcount, as the radix reorder shader already does) instead of by the order of their atomicAdd. Then pack the projector workgroup index into spare low bits of the sort key, below the depth key. Ties then resolve the same way every frame. In our tests this makes frames bit-identical for about +0.25 ms of GPU time per frame at 4M–20M splats (sort + projector), with whole-frame time within run-to-run noise. I have a PR ready and will link it here.
Source: playcanvas/engine