Skip to content

fix: blur a region with one clipped node instead of one per rectangle - #7

Merged
mirkobrombin merged 2 commits into
singularityos-lab:singularityfrom
jp-vernooy:fix/blur-clip-region
Nov 13, 2026
Merged

mirkobrombin merged 2 commits into
singularityos-lab:singularityfrom
jp-vernooy:fix/blur-clip-region

Conversation

@jp-vernooy

@jp-vernooy jp-vernooy commented Nov 10, 2026 •

Copy link
Copy Markdown

Description

Been testing Singularity Desktop on my M4 Pro MacBook with Aurora Silicon and found a performance issue when turning on blur or glass effects.

Blur regions from clients are rounded, and pixman stores a rounded region as one rectangle per scanline of each corner. background-effect.c created one SceneFX blur node per rectangle, and SceneFX runs the full multi-pass blur once per node. A surface with four rounded panels (radius 16) becomes 76 rectangles, so 76 complete blur passes per frame. On the above-mentioned system, the desktop with blurred panels and dock dropped to about 12 fps while moving a window, with about 250 GPU jobs per frame.

This PR blurs each region with one node clipped to the region:

  1. feat: add a clip region to SceneFX blur nodes
    • Carries subprojects/packagefiles/scenefx-blur-clip-region.patch, which adds wlr_scene_blur_set_clip_region().
    • The clip is intersected into the node's visible region, so rendering, damage tracking and the blur's damage expansion stay inside it.
    • Without a clip, nodes behave exactly as before.
  2. fix: blur a region with one clipped node instead of one per rectangle
    • The non-liquid path creates one node over the region's extents and clips it to the region.
    • Liquid blur keeps its per-shape nodes.

The result matches the per-rectangle nodes, needs no shape detection, and works for any client: zsingularity_blur_v1 with a corner radius, or plain ext-background-effect-v1 regions.

Related: singularityos-lab/singularity-desktop#271 ("blur bounds", "reported lag").

How has it been tested?

All on the M4 Pro, Aurora kernel 7.3.0-26, Mesa 26.3.0.

1. Standalone blur client in a nested labwc

A small Wayland client with no toolkit (blurbench, about 300 lines of C, shm only):

  • a wlr-layer-shell background surface redraws a moving colour pattern on every frame callback, so the blur is re-rendered every frame;
  • a translucent xdg_toplevel above it draws N rounded panels and requests blur behind them;
  • the region is built the way GTK/sit rasterises a rounded box: one rectangle per corner scanline plus one for the straight middle;
  • it requests blur either over zsingularity_blur_v1 (mode blur/glass/liquid, strength 100, corner radius) or over ext-background-effect-v1 (region only).

Setup: labwc runs nested (WLR_BACKENDS=wayland, 1280×720, -d), with blurbench as its only client. 8 s per run, 2 rounds, builds alternating.

Metrics:

  • frames: uprobe on wlr_scene_output_build_state;
  • GPU time: the compositor's DRM fdinfo (drm-engine-*);
  • CPU: /proc/PID/stat;
  • node count: labwc's debug log.
Case (region rectangles) singularity @ 5aa79d4 this PR
blur, 4 panels r16 (76) 76 nodes, 12 fps, 8.3 ms GPU, 49 ms CPU per frame 1 node, 116–119 fps, 0.39–0.45 ms GPU, 1.4 ms CPU
glass, 4 panels r16 (76) 76 nodes, 12 fps, 7.7–7.8 ms GPU 1 node, 119 fps, 0.41–0.43 ms GPU
liquid, 4 panels r16 (76) 4 nodes, 103–108 fps, 1.29 ms GPU 4 nodes, 100–104 fps, 1.29–1.31 ms GPU (path unchanged)
ext-background-effect, no radius (76) 76 nodes, 12 fps 1 node, 118–119 fps
blur, 8 panels r24 (232) 232 nodes, 4 fps, 22 ms GPU, 150 ms CPU 1 node, 119 fps, 0.39–0.41 ms GPU

The nested output is paced by the host at 120 Hz.

Rendering: with the backdrop frozen, screenshots of both builds were compared pixel by pixel.

  • liquid: identical;
  • blur, glass and ext: differ by at most 19/255, only inside the area that was re-rendered between the two captures. That fits the blur's per-render noise dither.

2. As the session compositor

The same change was applied to the labwc tree in use on this machine and run as the session compositor (120 Hz panel). The test: Super+drag of a translucent window in circles, counting dcp:iomfb_swap_submit (displayed frames) and asahi_g17_doorbell (GPU jobs) system-wide.

Mode Before This PR
blur about 12 fps, about 250 GPU jobs per frame 111 fps, 13.8 jobs per frame
glass — 119 fps, 19.0 jobs per frame
liquid — 108.5 fps, 21.4 jobs per frame

Window corners are clean: the blur follows the rounded edge with no square spill.

3. Build

  • A clean meson setup applies the three SceneFX patches in order.
  • No new warnings in the changed files.
  • scripts/checkpatch.pl --strict reports nothing new for src/background-effect.c.

Not yet done: testing on non-Apple GPUs (don't currently have access to x86 hosts running Singularity)

Generative AI assistance

AI assistance: disclosed

Both commits carry Assisted-by and AI-Scope trailers (see AGENTS.md).

SceneFX runs the whole multi-pass blur once per wlr_scene_blur node, over
the node's visible area expanded by the blur size. A compositor that
wants to blur an arbitrary region therefore has to create one node per
rectangle of that region, and a rounded region is stored as one
rectangle per scanline of its corners.

Carry a patch that adds wlr_scene_blur_set_clip_region(). The clip is
intersected into the node's visible region, so rendering, damage
tracking and the blur's damage expansion all stay inside it, and one
node can blur any shape. Without a clip the node behaves as before.

Assisted-by: Claude Code:claude-opus-5-5
AI-Scope: Wrote the SceneFX clip-region patch from a prompt to cut per-rectangle blur cost.
Rounded blur regions from clients arrive as one pixman rectangle per
scanline of each corner. Creating one SceneFX blur node per rectangle
ran the full blur pipeline dozens of times per surface: a single Files
window needed 15 nodes, and a desktop with blurred panels dropped to
about 12 fps on Apple M4 (hundreds of GPU jobs per frame).

Blur the region's extents with a single node clipped to the region.
The result is pixel-identical to the per-rectangle nodes, needs no
shape detection, and also covers clients that send no corner radius.
Liquid blur keeps its per-shape nodes.

Assisted-by: Claude Code:claude-opus-5-5
AI-Scope: Wrote the background-effect.c change and its benchmark from the same prompt.
@jp-vernooy
jp-vernooy marked this pull request as ready for review November 10, 2026 20:38
@mirkobrombin

Copy link
Copy Markdown
Member

Thanks a lot!

@mirkobrombin
mirkobrombin merged commit acf5bf7 into singularityos-lab:singularity Nov 13, 2026
3 checks passed
@jp-vernooy
jp-vernooy deleted the fix/blur-clip-region branch November 13, 2026 21:04
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.

2 participants