Skip to content

feat(layers): add PathLayer analytic antialiasing - #10520

Merged
chrisgervang merged 13 commits into
chrisgervang/analytic-antialiasing-rfcfrom
claude/deckgl-path-aliasing-4tx9a3
Aug 21, 2026
Merged

chrisgervang merged 13 commits into
chrisgervang/analytic-antialiasing-rfcfrom
claude/deckgl-path-aliasing-4tx9a3

Conversation

@chrisgervang

@chrisgervang chrisgervang commented Aug 2, 2026 •

Copy link
Copy Markdown
Collaborator

Goal

Add opt-in analytic edge antialiasing to PathLayer for render targets where MSAA is unavailable.

Change List

  • Add PathLayer.antialiasing, defaulting to false; TripsLayer inherits it through PathLayer.
  • Compute a one-device-pixel coverage ramp in GLSL and WGSL from screen-space derivatives.
  • Cover straight stroke edges plus rounded joints and caps while leaving abutting segment edges hard.
  • Document the prop and its overlap/blending trade-offs in the PathLayer API reference.
  • Add uniform tests, isolated no-MSAA numerical coverage, a no-MSAA golden with includeAA, PathStyleExtension offset coverage, and WebGPU premultiplied-alpha coverage.

Validation

  • yarn lint
  • yarn build
  • Focused PathLayer headless, WebGL, and WebGPU tests
  • Isolated no-MSAA golden passes alongside normal shared-device PathLayer goldens

The 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.

PathLayer analytic antialiasing comparison


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 antialiasing on PathLayer (default false) 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 ANTIALIASING define. Vertices expand by half a pixel so the outer half of the ramp is rasterized; fragments compute fwidth before any discard. Toggling the prop rebuilds the model. TripsLayer now discards the time window at DECKGL_FILTER_COLOR so 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-antialiasing land with this.

Reviewed by Cursor Bugbot for commit ca063c5. Bugbot is set up for automated code reviews on this repo. Configure here.

@chrisgervang
chrisgervang marked this pull request as draft August 2, 2026 00:59
@coveralls

coveralls commented Aug 2, 2026 •

Copy link
Copy Markdown

Coverage Status

Coverage is 82.167% — claude/deckgl-path-aliasing-4tx9a3 into chrisgervang/analytic-antialiasing-rfc. No base build found for chrisgervang/analytic-antialiasing-rfc.

chrisgervang pushed a commit that referenced this pull request Aug 2, 2026
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
chrisgervang pushed a commit that referenced this pull request Aug 2, 2026
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
@Pessimistress

Copy link
Copy Markdown
Collaborator

There is a utility shader function smoothedge defined in https://github.com/visgl/deck.gl/blob/master/modules/core/src/shaderlib/misc/geometry.ts I believe scatterplot layer is using it.

@Pessimistress

Copy link
Copy Markdown
Collaborator

You should enable WebGPU render test for line layer. Right now it fails due to lack of antialiasing.

Copy link
Copy Markdown
Collaborator Author

Thanks — both addressed in 2d98227.

smoothedge — now used at all four coverage sites. I'd looked at it early and passed because SMOOTH_EDGE_RADIUS is a fixed 0.5 CSS pixels and not DPR-aware, but that objection belonged to an earlier implementation that carried the stroke half-width down as a varying. That's gone; coverage now comes from screen-space derivatives, so edgePixels is already a signed device-pixel distance and smoothedge(0.0, edgePixels) is exactly smoothstep(-0.5, 0.5, edgePixels). Units line up. Falloff goes from linear to cubic, the existing goldens absorb it, and both regression guards still fire.

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 antialiasing: true unconditionally dropped the WebGL match to 98.28%, since it layers analytic coverage on top of MSAA that's already there. So it's now set per device — on for WebGPU only. That way one golden serves both backends, and the WebGL case keeps covering the default configuration with its golden untouched.

What I couldn't verify is the WebGPU side, because WebGPU rasterizes nothing under the software renderer this suite runs on. line-lnglat comes back as a completely blank frame — and so does every path-layer case. The device is created, navigator.gpu is present, commands submit with no validation errors, and the output is pure white. The 84.32% match is that blank frame against the golden, and it's identical before and after this change, so antialiasing isn't what that number is measuring.

Since test-ci includes --project render and CI uses the same --use-angle=swiftshader --enable-unsafe-webgpu chromium, enabling it looked likely to red CI for a reason unrelated to this PR. If WebGPU does rasterize in your environment, it's a one-line uncomment and I'd expect it to pass now — happy to flip it if you confirm, or if you'd rather see the CI result I can enable it and we can judge from that.

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 _framebuffer also came back empty on WebGPU. I'd attributed that to the incomplete post-processing area of #9504, but blank-everything is the simpler explanation.


Generated by Claude Code

@ibgreen-openai

Copy link
Copy Markdown
Collaborator

@chrisgervang Very cool, this could have some potential.

For this technique I am thinking it might benefit from being done in premultiplied colors.
WebGPU shaders already return pre-multiplied colors but in most cases as a last step, they don't do blending math in premultiplied space, which could make this less effective than it could be

Copy link
Copy Markdown
Collaborator Author

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 cause

Viewports build projection matrices for the WebGL clip volume, -w ≤ z ≤ w. WebGPU's is 0 ≤ z ≤ w. A default OrthographicView projects to z/w = -0.998, so every primitive fell in the half of the range WebGPU clips, and nothing rasterized. Fixed in d7996ed by remapping depth where the clip position is assembled — the only place in WGSL where the convention differs. The GLSL path is a separate file and is untouched.

How it was isolated

probe result
Raw WebGPU — clear + readback, no luma [255,0,0,255] — rasterizes
luma Model triangle → offscreen FBO → readback [0,0,255,255] — draws
deck ScatterplotLayer / LineLayer blank
deck's own model, driven manually in a plain luma pass blank, with drawResult=true, pipelineErrored=false, validationError=null

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 w = 1, z/w ≈ -0.998 — outside WebGPU's clip volume.

Two things I chased that were dead ends, recorded so nobody repeats them:

  • Chromium flags. Adding --ignore-gpu-blocklist and --use-webgpu-adapter=swiftshader to match luma's set changed nothing. Reverted.
  • Uniform buffers reading back all-zero. An artifact — UniformStore allocates them UNIFORM | COPY_DST, and readAsync copies through a staging buffer needing COPY_SRC. The copy fails inside an error scope and the staging buffer stays zero. Uniform buffers can't be read back that way.

Result

Reading back an offscreen framebuffer, LineLayer, PathLayer and ScatterplotLayer all now paint on WebGPU within a few pixels of their WebGL counts, under both orthographic and lng/lat viewports:

webgl/line 450    webgpu/line 450
webgl/path 700    webgpu/path 700
webgl/scatterplot 1304    webgpu/scatterplot 1264   (WebGL's MSAA edges)

On enabling the LineLayer WebGPU render test

Still 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 antialiasing: deviceType === 'webgpu' wiring is committed and ready; the row just needs CI with hardware WebGPU. Comment and RFC updated to say this accurately.

Note the depth fix is @deck.gl/core and unrelated to antialiasing — happy to split d7996ed into its own PR if you'd prefer to review it separately.

Full render suite re-run: 168 passing, 4 pre-existing network failures (scenegraph duck ×2, terrain ×2), no goldens moved.


Generated by Claude Code

Copy link
Copy Markdown
Collaborator Author

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 deckgl_premultiplied_alpha in both layers (path-layer.wgsl.ts:278-284, line-layer.wgsl.ts:170-172 → :200), giving (rgb·a·c, a·c) — algebraically the same as scaling the premultiplied vec4 by coverage. Nothing defended that ordering though, so 2f6f0b6 adds a guard: renders on WebGPU into an offscreen framebuffer and asserts red tracks alpha at partial-coverage pixels. Moving the multiply after premultiplication takes the worst overshoot from 2 to 126.

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 discard-defined edges together. Written up in the RFC as parked, for three reasons: luma never maps sampleAlphaToCoverageEnabled on WebGL (declared in core/.../parameters.ts, no case in webgl/.../device-parameters.ts — silent no-op); on WebGPU it maps but needs sampleCount > 1, so it waits on luma.gl#2741; and the mask comes from fragment alpha while deck blends SRC_ALPHA, so coverage gets counted twice unless an explicit @builtin(sample_mask) separates it from opacity. Worth revisiting once #2741 lands.


Generated by Claude Code

@chrisgervang

chrisgervang commented Aug 5, 2026 •

Copy link
Copy Markdown
Collaborator Author

@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

@chrisgervang

Copy link
Copy Markdown
Collaborator Author

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

@chrisgervang
chrisgervang marked this pull request as ready for review August 5, 2026 17:14
@chrisgervang chrisgervang added this to the v9.4 milestone Aug 11, 2026
@chrisgervang
chrisgervang force-pushed the claude/deckgl-path-aliasing-4tx9a3 branch from 14434fe to 2d1f868 Compare August 14, 2026 00:38
@chrisgervang
chrisgervang changed the base branch from master to chrisgervang/analytic-antialiasing-rfc August 14, 2026 00:38
@chrisgervang chrisgervang changed the title feat(layers): analytic antialiasing for PathLayer and LineLayer feat(layers): add PathLayer analytic antialiasing Aug 14, 2026
@chrisgervang
chrisgervang force-pushed the claude/deckgl-path-aliasing-4tx9a3 branch from 2d1f868 to 75a312a Compare August 14, 2026 00:52
Comment thread test/modules/layers/index.ts Resolved
@chrisgervang

Copy link
Copy Markdown
Collaborator Author

Each layer now has one render spec containing shared goldens, isolated no-MSAA golden, WebGL numerical checks, and WebGPU premultiplication checks.

@chrisgervang
chrisgervang force-pushed the claude/deckgl-path-aliasing-4tx9a3 branch from eb0053c to 19f1ddd Compare August 20, 2026 01:10
@chrisgervang
chrisgervang force-pushed the claude/deckgl-path-aliasing-4tx9a3 branch from 3b27880 to b347b66 Compare August 20, 2026 05:36

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

@chrisgervang
chrisgervang force-pushed the claude/deckgl-path-aliasing-4tx9a3 branch from b347b66 to db57bee Compare August 20, 2026 05:47
@chrisgervang
chrisgervang force-pushed the claude/deckgl-path-aliasing-4tx9a3 branch 2 times, most recently from 804f642 to 5351c60 Compare August 20, 2026 18:45
@chrisgervang
chrisgervang force-pushed the claude/deckgl-path-aliasing-4tx9a3 branch from 5351c60 to 166d166 Compare August 20, 2026 23:01
@chrisgervang
chrisgervang force-pushed the claude/deckgl-path-aliasing-4tx9a3 branch from 0e2b4d5 to ca063c5 Compare August 20, 2026 23:33
@chrisgervang
chrisgervang merged commit 427df1b into master Aug 21, 2026
8 checks passed
@chrisgervang
chrisgervang deleted the claude/deckgl-path-aliasing-4tx9a3 branch August 21, 2026 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants