Skip to content

refactor(liquidglass): share one WGSL optics source with the Qt module - #23

Merged
arcultus merged 1 commit into
mainfrom
refactor/liquidglass-single-wgsl-source
Nov 30, 2026
Merged

arcultus merged 1 commit into
mainfrom
refactor/liquidglass-single-wgsl-source

Conversation

@arcultus

Copy link
Copy Markdown
Contributor

What

  • One optics source. crates/liquidglass/shaders/optics.wgsl now holds the only copy of the Liquid Glass math (SDF, Snell bezel, dome, two-zone refraction, Cauchy dispersion, rim lighting, borders, shadow). build.rs splices it into liquidglass.wgsl (and kawase_common.wgsl into both Kawase passes) at // #include "…" lines, then naga emits WGSL, GLSL 330 core and GLSL ES 3.00.
  • Qt module shares it. naga also lowers optics.wgsl to the GLSL core that libs/liquidglass/shaders/liquidglass.frag inlines. The generated liquidglass_core.glsl is committed so the Qt module still builds without Rust; shaders::tests::qt_core_glsl_is_up_to_date fails while it is stale, and just liquidglass qt-core regenerates it. liquidglass.frag stays hand-written GLSL 440, so Qt's qt_TexCoord0 / UBO names are untouched.
  • Reflected GL names. gl_backend.rs binds uniform blocks and samplers by names taken from naga's ReflectionInfo (gl_reflection.rs, generated) instead of hardcoded mangled strings; the build asserts GL 330 and GLES 300 agree.
  • Fewer targets. SPIR-V, MSL and HLSL outputs (and naga's spv-out/msl-out/hlsl-out) are dropped: nothing used them, and wgpu lowers WGSL itself. This removes the public shaders::{spirv,msl,hlsl} modules.
  • New CTest LiquidGlassQsbReflection: checks that the baked .qsb still exposes qt_TexCoord0, source, qt_Matrix, qt_Opacity, itemSize, glassRect, edgeBend.
  • glass: qdbus6 org.kde.KWin /Effects org.kde.kwin.Effects.debug fluctusglass stats reports frames, glass passes and repaints by cause (pointer, fade, margin, backdrop, stale, update).
  • Tooling truth: just glass update no longer says it "reloaded" new code. KWin never unloads a plugin, so a new effect build runs only after logging out and back in. Noted in AGENTS.md (invariant 9), the root justfile and glass/README.md.
  • Docs: the 2026-11-30 run (3 × 40 s per scenario, untouched desktop) is recorded as the official resource usage in glass/docs/performance.md, summarized in glass/README.md and dock/README.md; raw data in glass/tools/bench/results/2026-11-30/.

Why

The optics were maintained twice in two languages, kept in step by hand. A Slang rewrite was evaluated first, but slangc cannot emit GLSL 330 core / GLES 300 (what KWin uses), so naga stays either way. Slang would only add a third compiler plus a build dependency in CI, the PKGBUILD and the flake. WGSL + naga removes the duplication with no new tools.

Investigating the benchmark's idle cost (+2.6% kwin CPU) with the new stats hook showed it is not the glass idling. A maximized window ending at the dock's top edge animated during the run, and the refraction samples into it, so each change redrew the glass. Shortening that window cut glass redraws from ~21/s to ~6/s. The same investigation exposed that just glass update never actually loaded new effect code.

How verified

  • just test: crate tests 7/7 (incl. GL reflection and the stale-core check, which was confirmed to fail on an edited optics.wgsl and on a missing core file), all CTest suites 7/7 incl. LiquidGlassQsbReflection.
  • just liquidglass test-gpu: headless wgpu optics invariants + Apple Tahoe parity pass.
  • just liquidglass lint: clippy clean.
  • just test-san: 7/7 under ASan + UBSan, no reports.
  • Independent review (Gemini 4 Neon): no critical findings; optics parity with the previous WGSL/GLSL confirmed field-by-field; its 5 small findings are fixed.
  • Live: after a re-login the session runs this build (the stats command answers); dock and glass render as before.

🤖 Generated with Claude Code

The glass optics lived twice, hand-synced: liquidglass.wgsl for the KWin
effect and liquidglass_core.glsl for the Kogical.LiquidGlass Qt module.

- shaders/optics.wgsl is now the single source. build.rs splices it (and
  kawase_common.wgsl) into the entry shaders and lowers everything with naga.
- naga also lowers optics.wgsl to the GLSL core the Qt module inlines. The
  module commits that file so it still builds without Rust; a cargo test
  fails while it is stale (`just liquidglass qt-core` regenerates it).
- GL uniform block and sampler names come from naga's reflection instead
  of hardcoded mangled names.
- Drop the unused SPIR-V, MSL and HLSL outputs and their naga features.
- Add a LiquidGlassQsbReflection CTest for the names Qt Quick binds.

Also:
- glass: `debug fluctusglass stats` reports glass repaints by cause.
- `just glass update` no longer claims to reload new code: KWin never
  unloads a plugin, so a new build runs only after logging out and back in
  (noted in AGENTS.md and the READMEs).
- docs: record the 2026-11-30 3 x 40 s benchmark as the official resource
  usage, and explain the idle cost (an animating window touching the dock).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@arcultus
arcultus merged commit e9025a9 into main Nov 30, 2026
2 checks passed
@arcultus
arcultus deleted the refactor/liquidglass-single-wgsl-source branch November 30, 2026 18:16
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.

1 participant