feat(slint): wgpu fragment-shader underlay spike for ImmersiveView

Swap the winit renderer femtovg(GL) -> femtovg-wgpu (+ unstable-wgpu-28,
slint pinned =1.16.1) and render a WGSL plasma fragment shader into a wgpu
texture composited under ImmersiveView. The shader is fed by the existing
30fps visualizer drain (sub-bass energy + decayed transient) and toggled
in-view with the 'g' key via ImmersiveState.shader-mode; when active it
replaces the atmosphere + mode panels as the bottom layer, chrome stays on
top. Device/queue captured from Slint's rendering notifier so Image::try_from
shares Slint's wgpu device.

Phase 0 spike: validates the app-wide renderer swap with no font/UI/tray
regression. Pending macOS Metal smoke before the swap lands on slint-mvp.

cc
This commit is contained in:
vicrodh committed 2026-06-14 10:59:56 -06:00
1 parent b03c8fcb5c
commit e46e85546a
8 files changed
+835 -41

No files matched your search

@@ -566,6 +566,15 @@ export component ImmersiveView inherits Rectangle {
VisualizerState.set-enabled(false);
return accept;
}
// WGPU UNDERLAY SPIKE: 'g' (GPU) toggles the shader scene on/off in
// place so the owner can A/B the shader vs the existing atmosphere /
// panels in a single run. Remove (or repurpose to a real picker)
// once the spike is validated.
if (event.text == "g" || event.text == "G") {
ImmersiveState.shader-mode = ImmersiveState.shader-mode > 0 ? 0 : 1;
root.wake();
return accept;
}
return reject;
}
focus-timer := Timer {
@@ -593,8 +602,23 @@ export component ImmersiveView inherits Rectangle {
changed mouse-y => { root.wake(); }
}
// (1) Bottom: moving blurred-art atmosphere.
ImmersiveAtmosphere {
// (0) WGPU UNDERLAY SPIKE: the GPU fragment-shader texture, the bottom-most
// layer when a shader scene is active. ADR-010 conditional mount. When
// shader-mode > 0 it REPLACES the atmosphere (layer 1) and the mode panels
// (layer 2) so the shader is the visible background; the chrome below stays
// on top. Driven at ~30 fps from src/visualizer.rs -> shader_underlay.
if ImmersiveState.shader-mode > 0: Image {
x: 0px;
y: 0px;
width: 100%;
height: 100%;
image-fit: fill;
source: ImmersiveState.shader-texture;
}
// (1) Bottom: moving blurred-art atmosphere. Hidden while a shader scene is
// active (the shader owns the background layer instead).
if ImmersiveState.shader-mode == 0: ImmersiveAtmosphere {
source-image: ImmersiveState.bg-image;
fallback-image: NowPlayingState.artwork-large.width > 0
? NowPlayingState.artwork-large
@@ -606,7 +630,7 @@ export component ImmersiveView inherits Rectangle {
// (ADR-010). Mode 0 = Album Reactive (the only real foreground this
// session). Modes 1/2/3 mount NO foreground — the atmosphere is the
// explicit placeholder until those sessions land.
if ImmersiveState.mode == 0: AlbumReactivePanel {
if ImmersiveState.shader-mode == 0 && ImmersiveState.mode == 0: AlbumReactivePanel {
x: 0px;
y: 0px;
viewport-width: root.width;
@@ -614,7 +638,7 @@ export component ImmersiveView inherits Rectangle {
}
// (2b) Static mode foreground (mode == 1) — calm centered now-playing
// card over the atmosphere. Same conditional-mount pattern (ADR-010).
if ImmersiveState.mode == 1: StaticPanel {
if ImmersiveState.shader-mode == 0 && ImmersiveState.mode == 1: StaticPanel {
x: 0px;
y: 0px;
viewport-width: root.width;
@@ -626,7 +650,7 @@ export component ImmersiveView inherits Rectangle {
// click, no 3D / reflection / gradient / 500ms reflow). True-3D rotateY/
// perspective remains deferred to a wgpu/Skia session. Same conditional-mount
// + viewport-prop contract as the siblings (ADR-010).
if ImmersiveState.mode == 2: CoverflowPanel {
if ImmersiveState.shader-mode == 0 && ImmersiveState.mode == 2: CoverflowPanel {
x: 0px;
y: 0px;
viewport-width: root.width;
@@ -639,7 +663,7 @@ export component ImmersiveView inherits Rectangle {
// ALREADY driven on open (the mode-0 AlbumReactivePanel reads
// VisualizerState.energy from the same enabled tap). Same conditional-mount +
// viewport-prop contract as the siblings (ADR-010).
if ImmersiveState.mode == 3: SpectrumPanel {
if ImmersiveState.shader-mode == 0 && ImmersiveState.mode == 3: SpectrumPanel {
x: 0px;
y: 0px;
viewport-width: root.width;
+73
View File
@@ -0,0 +1,73 @@
// WGPU UNDERLAY SPIKE — plasma fragment shader.
//
// One fullscreen-triangle pass. The fragment stage is a classic sin-field
// plasma, audio-reactive via the sub-bass energy (u.energy0) and a decayed
// transient (u.transient). This shader's only job is to prove the GPU
// fragment-shader path works end to end (renderer swap -> wgpu texture ->
// Slint Image), NOT to be a final look. The Neon/Audio-Cube catalog replaces
// it once the spike is validated.
//
// CPU side: src/shader_underlay.rs. Uniform layout must stay in lockstep with
// the `Uniforms` #[repr(C)] struct there (vec4-aligned, 32 bytes).
struct Uniforms {
time: f32,
energy0: f32,
transient: f32,
_pad0: f32,
resolution: vec2<f32>,
_pad1: vec2<f32>,
};
@group(0) @binding(0) var<uniform> u: Uniforms;
struct VsOut {
@builtin(position) clip: vec4<f32>,
@location(0) uv: vec2<f32>,
};
@vertex
fn vs_main(@builtin(vertex_index) vid: u32) -> VsOut {
// Oversized triangle covering the whole clip space (the classic
// fullscreen-triangle trick — no vertex buffer needed).
var verts = array<vec2<f32>, 3>(
vec2<f32>(-1.0, -1.0),
vec2<f32>( 3.0, -1.0),
vec2<f32>(-1.0, 3.0),
);
let p = verts[vid];
var out: VsOut;
out.clip = vec4<f32>(p, 0.0, 1.0);
out.uv = p * 0.5 + vec2<f32>(0.5, 0.5);
return out;
}
@fragment
fn fs_main(in: VsOut) -> @location(0) vec4<f32> {
let t = u.time;
let bass = clamp(u.energy0, 0.0, 1.0);
let tr = clamp(u.transient, 0.0, 1.0);
// Plasma field: bass widens the spatial frequency so the pattern "breathes".
let scale = 3.0 + bass * 6.0;
let p = in.uv * scale;
var v = 0.0;
v += sin(p.x * 3.0 + t);
v += sin((p.y * 3.0 + t) * 0.7);
v += sin((p.x + p.y) * 2.0 + t * 1.3);
let cx = p.x + 0.5 * sin(t * 0.4);
let cy = p.y + 0.5 * cos(t * 0.6);
v += sin(sqrt(cx * cx + cy * cy) * 6.0 + t);
v = v * 0.25;
let pi = 3.14159265;
let r = sin(v * pi + 0.0) * 0.5 + 0.5;
let g = sin(v * pi + 2.094) * 0.5 + 0.5;
let b = sin(v * pi + 4.188) * 0.5 + 0.5;
var col = vec3<f32>(r, g, b);
// Bass lifts overall brightness; a transient adds a brief white flash.
col = col * (0.55 + bass * 0.85) + vec3<f32>(tr * 0.6);
col = clamp(col, vec3<f32>(0.0), vec3<f32>(1.0));
return vec4<f32>(col, 1.0);
}
+10
View File
@@ -2977,6 +2977,16 @@ export global ImmersiveState {
// Defaults = the Svelte cyan -> purple until the art resolves.
in property <color> spectrum-primary: #00dcc8;
in property <color> spectrum-secondary: #9632ff;
// WGPU UNDERLAY SPIKE: a GPU fragment shader rendered into a wgpu texture by
// src/shader_underlay.rs and handed back here each drain tick. `shader-mode`
// selects the scene: 0 = OFF (use the existing atmosphere + panels), >0 = a
// shader scene (1 = plasma spike). When >0 the atmosphere + the mode panels
// are hidden so the shader is the visible background; the auto-hide chrome
// (mode picker + compact player) stays on top. Toggle in-view with the 'g'
// key during the spike.
in property <image> shader-texture;
in-out property <int> shader-mode: 0;
}
// Now-playing / transport state. The Rust playback poll loop pushes the