Repository navigation
feat(layers): add PathLayer analytic antialiasing - #10520
chrisgervang merged 13 commits into
Conversation
Derivatives are computed per 2x2 quad and are undefined once any invocation in the quad has been discarded. The GLSL shader took fwidth after the rounded joint/cap and miter-trim discards, so coverage at exactly those silhouettes was undefined on WebGL. The WGSL shader already hoisted the same math for this reason; this brings GLSL in line. Both now compute the coverage inside a branch on path.antialiasing, ahead of the discards. That uniform is the same for every invocation, so the branch keeps control flow uniform across the quad while also keeping the two derivatives off the default path when the feature is off. Reported by Cursor Bugbot on #10520. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01H96ePpLZEY1tUcTM9bWSoG
Dashes were resolved with one comparison per fragment, which aliases as soon as a dash period approaches a pixel: the stroke breaks into moire, and because the result depends on where the phase happens to land, its apparent density is wrong too. Zooming out far enough turned a dashed line into noise or into a solid line. Coverage is now the integral of the dash square wave over the fragment footprint, which is the closed form of what MapLibre's mipmapped LineAtlas SDF texture approximates, without needing a texture. Measured on a 10px stroke with an even duty cycle, sampling the interior of each strip: period before (mean alpha / stdev) after 40.0px 127.5 / 127.5 127.5 / 127.5 10.0px 127.5 / 127.5 127.5 / 127.5 4.0px 127.5 / 127.5 127.5 / 127.5 1.5px 114.8 / 126.9 127.4 / 51.8 0.6px 132.8 / 127.4 127.5 / 20.8 0.2px 107.7 / 125.9 127.5 / 0.5 Mean alpha should be 127.5 everywhere, since every pattern is half solid. Before, it drifted by up to 16% once the period went sub-pixel, and the stroke stayed full of binary noise at every scale. Now it is exact at every scale and the noise falls away as the period shrinks, so the stroke fades to a uniformly lighter line instead of tearing. Resolvable periods are unaffected apart from antialiased dash ends. Rounded caps resolve the 2D distance to the nearer solid end with smoothstep rather than a hard threshold, then fade to the duty cycle over the same range, since a per-end test stops meaning anything once a whole period fits in a pixel. Picking deliberately stays a hard in-or-out test: a blended picking colour decodes to the wrong index, and dashGapPickable is defined in terms of whole gaps rather than coverage. Fragments below 0.4% coverage are still discarded so they do not write depth and occlude what is behind them. Note the dash edge is produced by discard, which kills every sample of a fragment, so no amount of framebuffer MSAA smooths it. The render device has multisampling on, and these dash ends were still hard staircases before this change. Testing this needed care, and the first attempt did not work. pixelmatch drops antialiased pixels from the mismatch count unless includeAA is set, and TestCase.imageDiffOptions never threaded it through - so a golden diff was blind to precisely the pixels this feature creates. With the whole change reverted, only 2 of 22 goldens noticed. Two things fix that: - imageDiffOptions now carries includeAA, and honours tolerance, which was declared but ignored. Every dash case sets includeAA. (#10520 makes the same harness change for the same reason; whichever lands second should drop its copy.) - A new path-dash-diagonal case. Every other case draws horizontal strips, where a dash end is a vertical line landing on an exact pixel column and there is no partial coverage to produce at all. It is deliberately dense: one dash end perturbs only a handful of pixels, so a sparse case stays under the 1% mismatch the threshold requires and passes with the feature deleted. Reverting the change now fails 4 goldens, path-dash-diagonal among them at 97.80%. Also adds path-dash-subpixel-square and path-dash-subpixel-rounded, which sweep the dash period from 40px down to 0.2px. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014GipN1niYRgRuLVat2wujw
|
There is a utility shader function |
|
You should enable WebGPU render test for line layer. Right now it fails due to lack of antialiasing. |
|
Thanks — both addressed in 2d98227.
LineLayer WebGPU — the case is prepared but the suite entry is still commented out, and I want to be transparent about why rather than quietly not doing it. Setting What I couldn't verify is the WebGPU side, because WebGPU rasterizes nothing under the software renderer this suite runs on. Since Same root cause, for what it's worth, explains a dead end I hit earlier trying to assert on WGSL coverage directly: rendering deck layers into an app-supplied Generated by Claude Code |
|
@chrisgervang Very cool, this could have some potential.
For this technique I am thinking it might benefit from being done in premultiplied colors. |
|
Correcting myself: my earlier comment said WebGPU "rasterizes nothing under the software renderer." That was wrong, and it was hiding a real deck bug. Root causeViewports build projection matrices for the WebGL clip volume, How it was isolated
A valid pipeline issuing a valid draw and producing nothing. From there: CPU-side uniform bytes are byte-identical between backends; all attributes arrive (verified by encoding them into fragment color); a clip-space triangle bypassing the projection renders fine. Encoding the computed clip position as color gave Two things I chased that were dead ends, recorded so nobody repeats them:
ResultReading back an offscreen framebuffer, On enabling the LineLayer WebGPU render testStill can't, but for a different and narrower reason: the WebGPU canvas does not present under the headless software renderer, so the screenshot this suite diffs comes back blank no matter what deck draws. That reproduces with a plain luma triangle and no deck involved, and readback of the same content from an offscreen texture is correct. The Note the depth fix is Full render suite re-run: 168 passing, 4 pre-existing network failures (scenegraph duck ×2, terrain ×2), no goldens moved. Generated by Claude Code |
|
Thanks @ibgreen-openai — the guide is a better home for the taxonomy than this RFC, so the RFC and both layer docs now link out to it instead of restating it. On premultiplied: coverage already lands before Alpha-to-coverage was the most useful thing in the guide — I hadn't considered it. Per-sample masks would fix the flat-cap and self-overlap limitations and the Generated by Claude Code |
|
@Pessimistress I've enabled the line render tests so we can see where we're at - they render but don't match yet Also, I had to jump through some configuration hoops to make canvas-based headless WebGPU renders work. Rendering to offscreen textures was easy, but getting the entire pipeline to work requires a virtual display. I recorded findings and options in the linked luma issue |
|
I advocate for adding this prop in 9.4 to fix long standing WebGL issues like #7647, but also want to hear if there are any concerns. I'd land this PR with WebGPU render tests functional but disabled to keep CI green |
14434fe to
2d1f868
Compare
2d1f868 to
75a312a
Compare
|
Each layer now has one render spec containing shared goldens, isolated no-MSAA golden, WebGL numerical checks, and WebGPU premultiplication checks. |
eb0053c to
19f1ddd
Compare
3b27880 to
b347b66
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b347b66. Configure here.
b347b66 to
db57bee
Compare
804f642 to
5351c60
Compare
5351c60 to
166d166
Compare
0e2b4d5 to
ca063c5
Compare

Goal
Add opt-in analytic edge antialiasing to PathLayer for render targets where MSAA is unavailable.
Change List
PathLayer.antialiasing, defaulting tofalse; TripsLayer inherits it through PathLayer.includeAA, PathStyleExtension offset coverage, and WebGPU premultiplied-alpha coverage.Validation
yarn lintyarn buildThe previously combined LineLayer, composite-layer, RFC, and integration-doc changes now have their own PRs in this native GitHub stack.
Performance benchmark
Introduces
yarn bench-antialiasing, a 3840×2160 hardware GPU timestamp benchmark with 20 warmup draws and 100 measured draws per variant. AA-off and AA-on order alternates on each iteration to reduce ordering and thermal bias. The PathLayer workloads cover sparse thin strokes, heavy overdraw, and picking; representative results are recorded in the RFC.Visual comparison
The render-test device has framebuffer MSAA disabled. Left:
antialiasing: false. Right:antialiasing: true.Note
Medium Risk
Touches PathLayer GLSL/WGSL geometry and fragment coverage, including discard order used by TripsLayer. Default remains off, so existing MSAA paths are unchanged, but shader correctness and self-overlap blending need review.
Overview
Adds opt-in
antialiasingonPathLayer(defaultfalse) so strokes can feather edges in the shader when the render target has no MSAA (e.g. MapLibre/Mapbox). Coverage is a one-device-pixel ramp from screen-space derivatives, applied along stroke width and rounded joints/caps; abutting segment ends stay hard. Self-overlap can still artifact.GLSL and WGSL share an
ANTIALIASINGdefine. Vertices expand by half a pixel so the outer half of the ramp is rasterized; fragments computefwidthbefore any discard. Toggling the prop rebuilds the model.TripsLayernow discards the time window atDECKGL_FILTER_COLORso those discards run after coverage derivatives.Docs, shader-variant tests, no-MSAA coverage/golden tests, PathStyleExtension offset coverage, WebGPU premultiplied-alpha checks, and
yarn bench-antialiasingland with this.Reviewed by Cursor Bugbot for commit ca063c5. Bugbot is set up for automated code reviews on this repo. Configure here.