diff --git a/crates/Cargo.lock b/crates/Cargo.lock index 333f17724..fe630d696 100644 --- a/crates/Cargo.lock +++ b/crates/Cargo.lock @@ -235,6 +235,15 @@ dependencies = [ "thiserror 2.0.18", ] +[[package]] +name = "android-build" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9fc9904ad2ad097c3c1cfe2eacaaf0fc24710936fa9ed941cb310b7c6ed2ab7" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "android-properties" version = "0.2.2" @@ -387,6 +396,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" +[[package]] +name = "ash" +version = "0.38.0+1.3.281" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb44936d800fea8f016d7f2311c6a4f97aebd5dc86f09906139ec848cf3a46f" +dependencies = [ + "libloading 0.8.9", +] + [[package]] name = "ashpd" version = "0.11.1" @@ -726,6 +744,21 @@ dependencies = [ "syn", ] +[[package]] +name = "bit-set" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" + [[package]] name = "bit_field" version = "0.10.3" @@ -1098,11 +1131,22 @@ dependencies = [ "bitflags 1.3.2", "block", "core-foundation 0.9.4", - "core-graphics-types", + "core-graphics-types 0.1.3", "libc", "objc", ] +[[package]] +name = "codespan-reporting" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe6d2e5af09e8c8ad56c969f2157a3d4238cebc7c55f0a517728c38f7b200f81" +dependencies = [ + "serde", + "termcolor", + "unicode-width", +] + [[package]] name = "color_quant" version = "1.1.0" @@ -1247,7 +1291,7 @@ checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" dependencies = [ "bitflags 1.3.2", "core-foundation 0.9.4", - "core-graphics-types", + "core-graphics-types 0.1.3", "foreign-types 0.3.2", "libc", ] @@ -1260,7 +1304,7 @@ checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" dependencies = [ "bitflags 1.3.2", "core-foundation 0.9.4", - "core-graphics-types", + "core-graphics-types 0.1.3", "foreign-types 0.5.0", "libc", ] @@ -1276,6 +1320,17 @@ dependencies = [ "libc", ] +[[package]] +name = "core-graphics-types" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d44a101f213f6c4cdc1853d4b78aef6db6bdfa3468798cc1d9912f4735013eb" +dependencies = [ + "bitflags 2.11.0", + "core-foundation 0.10.1", + "libc", +] + [[package]] name = "core_maths" version = "0.1.1" @@ -1947,7 +2002,7 @@ dependencies = [ "bitflags 2.11.0", "bytemuck", "fnv", - "glow", + "glow 0.17.0", "imgref", "itertools 0.14.0", "log", @@ -1956,6 +2011,7 @@ dependencies = [ "swash", "wasm-bindgen", "web-sys", + "wgpu", ] [[package]] @@ -2240,28 +2296,6 @@ dependencies = [ "slab", ] -[[package]] -name = "gbm" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce852e998d3ca5e4a97014fb31c940dc5ef344ec7d364984525fd11e8a547e6a" -dependencies = [ - "bitflags 2.11.0", - "drm", - "drm-fourcc", - "gbm-sys", - "libc", -] - -[[package]] -name = "gbm-sys" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c13a5f2acc785d8fb6bf6b7ab6bfb0ef5dad4f4d97e8e70bb8e470722312f76f" -dependencies = [ - "libc", -] - [[package]] name = "genawaiter" version = "0.99.1" @@ -2385,6 +2419,18 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" +[[package]] +name = "glow" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e5ea60d70410161c8bf5da3fdfeaa1c72ed2c15f8bbb9d19fe3a4fad085f08" +dependencies = [ + "js-sys", + "slotmap", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "glow" version = "0.17.0" @@ -2463,6 +2509,40 @@ dependencies = [ "gl_generator", ] +[[package]] +name = "gpu-allocator" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51255ea7cfaadb6c5f1528d43e92a82acb2b96c43365989a28b2d44ee38f8795" +dependencies = [ + "ash", + "hashbrown 0.16.1", + "log", + "presser", + "thiserror 2.0.18", + "windows 0.61.3", +] + +[[package]] +name = "gpu-descriptor" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b89c83349105e3732062a895becfc71a8f921bb71ecbbdd8ff99263e3b53a0ca" +dependencies = [ + "bitflags 2.11.0", + "gpu-descriptor-types", + "hashbrown 0.15.5", +] + +[[package]] +name = "gpu-descriptor-types" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdf242682df893b86f33a73828fb09ca4b2d3bb6cc95249707fc684d27484b91" +dependencies = [ + "bitflags 2.11.0", +] + [[package]] name = "grid" version = "1.0.1" @@ -2477,6 +2557,7 @@ checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b" dependencies = [ "cfg-if", "crunchy", + "num-traits", "zerocopy", ] @@ -2555,6 +2636,12 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hexf-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" + [[package]] name = "hkdf" version = "0.12.4" @@ -2703,6 +2790,19 @@ dependencies = [ "tracing", ] +[[package]] +name = "i-slint-backend-android-activity" +version = "1.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a318b5aebc2ad8e6fdbac8588984d9ea2e99a210449954717073d8a246e12fe7" +dependencies = [ + "android-build", + "i-slint-core", + "i-slint-renderer-skia", + "jni 0.22.4", + "raw-window-handle", +] + [[package]] name = "i-slint-backend-linuxkms" version = "1.16.1" @@ -2713,16 +2813,14 @@ dependencies = [ "calloop 0.14.4", "cfg_aliases", "drm", - "gbm", - "glutin", "i-slint-common", "i-slint-core", "i-slint-renderer-femtovg", + "i-slint-renderer-skia", "i-slint-renderer-software", "input", "memmap2", "nix 0.30.1", - "raw-window-handle", "xkbcommon", ] @@ -2739,6 +2837,7 @@ dependencies = [ "i-slint-core", "i-slint-core-macros", "i-slint-renderer-femtovg", + "i-slint-renderer-skia", ] [[package]] @@ -2880,6 +2979,7 @@ dependencies = [ "wasm-bindgen", "web-sys", "web-time", + "wgpu", ] [[package]] @@ -2903,7 +3003,7 @@ dependencies = [ "const-field-offset", "derive_more", "femtovg", - "glow", + "glow 0.17.0", "i-slint-common", "i-slint-core", "i-slint-core-macros", @@ -2913,6 +3013,7 @@ dependencies = [ "rgb", "wasm-bindgen", "web-sys", + "wgpu", ] [[package]] @@ -2921,18 +3022,21 @@ version = "1.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4030ff9eeb1b99fdf9b47472f3a7a582f3bcb57207c9bc07505dc6998abdcbc" dependencies = [ + "ash", "bytemuck", "cfg-if", "cfg_aliases", "clru", "const-field-offset", "derive_more", - "glow", + "foreign-types 0.5.0", + "glow 0.17.0", "glutin", "i-slint-common", "i-slint-core", "i-slint-core-macros", "lyon_path", + "metal 0.31.0", "objc2 0.6.4", "objc2-app-kit 0.3.2", "objc2-core-foundation", @@ -2946,9 +3050,12 @@ dependencies = [ "scoped-tls-hkt", "skia-safe", "softbuffer", + "spin_on", "unicode-segmentation", "vtable", + "wgpu", "windows 0.62.2", + "windows-core 0.62.2", "write-fonts", ] @@ -3508,6 +3615,17 @@ dependencies = [ "zeroize", ] +[[package]] +name = "khronos-egl" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aae1df220ece3c0ada96b8153459b67eebe9ae9212258bb0134ae60416fdf76" +dependencies = [ + "libc", + "libloading 0.8.9", + "pkg-config", +] + [[package]] name = "khronos_api" version = "3.1.0" @@ -3877,6 +3995,36 @@ dependencies = [ "autocfg", ] +[[package]] +name = "metal" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f569fb946490b5743ad69813cb19629130ce9374034abe31614a36402d18f99e" +dependencies = [ + "bitflags 2.11.0", + "block", + "core-graphics-types 0.1.3", + "foreign-types 0.5.0", + "log", + "objc", + "paste", +] + +[[package]] +name = "metal" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7047791b5bc903b8cd963014b355f71dc9864a9a0b727057676c1dcae5cbc15" +dependencies = [ + "bitflags 2.11.0", + "block", + "core-graphics-types 0.2.0", + "foreign-types 0.5.0", + "log", + "objc", + "paste", +] + [[package]] name = "microfft" version = "0.6.0" @@ -3957,6 +4105,32 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "naga" +version = "28.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "618f667225063219ddfc61251087db8a9aec3c3f0950c916b614e403486f1135" +dependencies = [ + "arrayvec", + "bit-set", + "bitflags 2.11.0", + "cfg-if", + "cfg_aliases", + "codespan-reporting", + "half", + "hashbrown 0.16.1", + "hexf-parse", + "indexmap", + "libm", + "log", + "num-traits", + "once_cell", + "rustc-hash 1.1.0", + "spirv", + "thiserror 2.0.18", + "unicode-ident", +] + [[package]] name = "natord" version = "1.0.9" @@ -4686,6 +4860,15 @@ dependencies = [ "libredox", ] +[[package]] +name = "ordered-float" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7d950ca161dc355eaf28f82b11345ed76c6e1f6eb1f4f4479e0323b9e2fbd0e" +dependencies = [ + "num-traits", +] + [[package]] name = "ordered-stream" version = "0.2.0" @@ -4991,6 +5174,12 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "presser" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa" + [[package]] name = "prettyplease" version = "0.2.37" @@ -5819,6 +6008,12 @@ dependencies = [ "rand 0.10.1", ] +[[package]] +name = "range-alloc" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca45419789ae5a7899559e9512e58ca889e41f04f1f2445e9f4b290ceccd1d08" + [[package]] name = "rav1e" version = "0.8.1" @@ -5996,6 +6191,12 @@ version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" +[[package]] +name = "renderdoc-sys" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832" + [[package]] name = "reqwest" version = "0.12.28" @@ -6687,6 +6888,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d46bc502cc6b113bfd1a7e9a0876532a9454ff4ee905afe09784eaa2ec3f3f33" dependencies = [ "const-field-offset", + "i-slint-backend-android-activity", "i-slint-backend-selector", "i-slint-common", "i-slint-core", @@ -6699,6 +6901,7 @@ dependencies = [ "slint-macros", "unicode-segmentation", "vtable", + "wgpu", ] [[package]] @@ -6872,6 +7075,7 @@ checksum = "aac18da81ebbf05109ab275b157c22a653bb3c12cf884450179942f81bcbf6c3" dependencies = [ "as-raw-xcb-connection", "bytemuck", + "drm", "fastrand", "js-sys", "memmap2", @@ -6943,6 +7147,15 @@ dependencies = [ "pin-utils", ] +[[package]] +name = "spirv" +version = "0.3.0+sdk-1.3.268.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eda41003dc44290527a59b13432d4a0379379fa074b70174882adfbdfd917844" +dependencies = [ + "bitflags 2.11.0", +] + [[package]] name = "ssdp-client" version = "2.1.0" @@ -7322,6 +7535,15 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "text-size" version = "1.1.1" @@ -8389,6 +8611,156 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88" +[[package]] +name = "wgpu" +version = "28.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9cb534d5ffd109c7d1135f34cdae29e60eab94855a625dcfe1705f8bc7ad79f" +dependencies = [ + "arrayvec", + "bitflags 2.11.0", + "bytemuck", + "cfg-if", + "cfg_aliases", + "document-features", + "hashbrown 0.16.1", + "js-sys", + "log", + "naga", + "parking_lot", + "portable-atomic", + "profiling", + "raw-window-handle", + "smallvec", + "static_assertions", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "wgpu-core", + "wgpu-hal", + "wgpu-types", +] + +[[package]] +name = "wgpu-core" +version = "28.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d23f4642f53f666adcfd2d3218ab174d1e6681101aef18696b90cbe64d1c10f9" +dependencies = [ + "arrayvec", + "bit-set", + "bit-vec", + "bitflags 2.11.0", + "bytemuck", + "cfg_aliases", + "document-features", + "hashbrown 0.16.1", + "indexmap", + "log", + "naga", + "once_cell", + "parking_lot", + "portable-atomic", + "profiling", + "raw-window-handle", + "rustc-hash 1.1.0", + "smallvec", + "thiserror 2.0.18", + "wgpu-core-deps-apple", + "wgpu-core-deps-emscripten", + "wgpu-core-deps-windows-linux-android", + "wgpu-hal", + "wgpu-types", +] + +[[package]] +name = "wgpu-core-deps-apple" +version = "28.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87b7b696b918f337c486bf93142454080a32a37832ba8a31e4f48221890047da" +dependencies = [ + "wgpu-hal", +] + +[[package]] +name = "wgpu-core-deps-emscripten" +version = "28.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34b251c331f84feac147de3c4aa3aa45112622a95dd7ee1b74384fa0458dbd79" +dependencies = [ + "wgpu-hal", +] + +[[package]] +name = "wgpu-core-deps-windows-linux-android" +version = "28.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ca976e72b2c9964eb243e281f6ce7f14a514e409920920dcda12ae40febaae" +dependencies = [ + "wgpu-hal", +] + +[[package]] +name = "wgpu-hal" +version = "28.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d6cb474beb218824dcc9e1ce679d973f719262789bfb27407da560cac20eeb" +dependencies = [ + "android_system_properties", + "arrayvec", + "ash", + "bit-set", + "bitflags 2.11.0", + "block", + "bytemuck", + "cfg-if", + "cfg_aliases", + "core-graphics-types 0.2.0", + "glow 0.16.0", + "glutin_wgl_sys", + "gpu-allocator", + "gpu-descriptor", + "hashbrown 0.16.1", + "js-sys", + "khronos-egl", + "libc", + "libloading 0.8.9", + "log", + "metal 0.33.0", + "naga", + "ndk-sys", + "objc", + "once_cell", + "ordered-float", + "parking_lot", + "portable-atomic", + "portable-atomic-util", + "profiling", + "range-alloc", + "raw-window-handle", + "renderdoc-sys", + "smallvec", + "thiserror 2.0.18", + "wasm-bindgen", + "web-sys", + "wgpu-types", + "windows 0.62.2", + "windows-core 0.62.2", +] + +[[package]] +name = "wgpu-types" +version = "28.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e18308757e594ed2cd27dddbb16a139c42a683819d32a2e0b1b0167552f5840c" +dependencies = [ + "bitflags 2.11.0", + "bytemuck", + "js-sys", + "log", + "web-sys", +] + [[package]] name = "which" version = "4.4.2" diff --git a/crates/qbz-slint/Cargo.toml b/crates/qbz-slint/Cargo.toml index 277ac1a75..79cd06285 100644 --- a/crates/qbz-slint/Cargo.toml +++ b/crates/qbz-slint/Cargo.toml @@ -11,16 +11,26 @@ name = "qbz-slint" path = "src/main.rs" [dependencies] -# femtovg renderer, pinned >=1.16 for the femtovg text-rendering fixes +# femtovg renderer, pinned =1.16.1 for the femtovg text-rendering fixes # (slint-ui/slint #5177 pixel-grid alignment + #11335 0.5px tearing / # inconsistent glyph spacing). Skia never received that treatment. -slint = { version = "1.16", default-features = false, features = [ +# +# WGPU UNDERLAY SPIKE (feature/wgpu-underlay-spike branch only): the renderer is +# swapped femtovg(GL) -> femtovg-wgpu so we can render WGSL fragment shaders into +# a wgpu texture composited under the ImmersiveView. femtovg-wgpu is the SAME +# femtovg rasterizer on a wgpu backend, so the text fixes above are KEPT. This is +# the one consequential, app-wide change being validated by the spike. The exact +# version is pinned to =1.16.1 because the wgpu_28 module / GraphicsAPI::WGPU28 / +# require_wgpu_28 are behind an `unstable-*` flag that may change on a minor bump. +# To A/B against the GL build: `git checkout slint-mvp`. +slint = { version = "=1.16.1", default-features = false, features = [ "std", "backend-winit", - "renderer-femtovg", + "renderer-femtovg-wgpu", "renderer-software", "accessibility", "compat-1-2", + "unstable-wgpu-28", ] } # Direct access to the winit backend for the system tray: WinitWindowAccessor # (hide/show the OS window without quitting the event loop) and, later, the diff --git a/crates/qbz-slint/src/main.rs b/crates/qbz-slint/src/main.rs index 382a418dc..307039571 100644 --- a/crates/qbz-slint/src/main.rs +++ b/crates/qbz-slint/src/main.rs @@ -88,6 +88,8 @@ mod recently; mod scrobble; mod scrobbler_settings; mod search; +// WGPU UNDERLAY SPIKE: GPU fragment-shader background for ImmersiveView. +mod shader_underlay; mod settings; mod share; mod sidebar; @@ -3941,6 +3943,17 @@ fn main() -> Result<(), Box> { let tokio_rt = tokio::runtime::Runtime::new()?; let _enter = tokio_rt.enter(); + // WGPU UNDERLAY SPIKE: select a wgpu-capable backend BEFORE the first window + // is created. require_wgpu_28 forces the winit backend (the only one that + // honours a graphics-API request) — which the app already uses, so the tray's + // WinitWindowAccessor stays valid. The renderer is femtovg-wgpu (Cargo.toml), + // so the femtovg text pipeline is preserved. Automatic config lets Slint init + // wgpu (downlevel-webgl2 limits — fine for fragment-only shaders). If this + // ever fails on the owner's GPU/driver, that failure IS the spike result. + slint::BackendSelector::new() + .require_wgpu_28(slint::wgpu_28::WGPUConfiguration::default()) + .select()?; + let window = AppWindow::new()?; // FONT TEST (slint-mvp): render with bundled Inter 18pt. Inter is a // clean, screen-tuned UI face; combined with the femtovg #5177/#11335 @@ -3976,6 +3989,31 @@ fn main() -> Result<(), Box> { // opens. Must run on the UI thread before window.run(). visualizer::install(&window, &app_runtime); + // WGPU UNDERLAY SPIKE: capture Slint's own wgpu Device/Queue at RenderingSetup + // so shader_underlay allocates its texture + submits on the SAME device Slint + // renders with (mandatory for Image::try_from). The render itself happens in + // the 30fps drain (visualizer.rs). Only one rendering notifier is allowed per + // window; the shader underlay owns it. Errors here are non-fatal — the shader + // just stays dark and the rest of the UI is unaffected. + if let Err(e) = window + .window() + .set_rendering_notifier(move |state, graphics_api| { + match state { + slint::RenderingState::RenderingSetup => { + if let slint::GraphicsAPI::WGPU28 { device, queue, .. } = graphics_api { + crate::shader_underlay::setup(device.clone(), queue.clone()); + } + } + slint::RenderingState::RenderingTeardown => { + crate::shader_underlay::teardown(); + } + _ => {} + } + }) + { + log::warn!("[shader] set_rendering_notifier failed: {e:?} — underlay disabled"); + } + // MusicBrainz cache — opens a SQLite store at // /qbz/cache/musicbrainz_cache.db so artist metadata // and relationships persist across sessions (matches Tauri's diff --git a/crates/qbz-slint/src/shader_underlay.rs b/crates/qbz-slint/src/shader_underlay.rs new file mode 100644 index 000000000..20a844ce7 --- /dev/null +++ b/crates/qbz-slint/src/shader_underlay.rs @@ -0,0 +1,244 @@ +//! WGPU UNDERLAY SPIKE — GPU fragment-shader background for the ImmersiveView. +//! +//! Validates the renderer-swap path (`renderer-femtovg` GL -> `renderer-femtovg-wgpu`) +//! by rendering a WGSL fragment shader into a wgpu texture and handing it back to +//! Slint as an `Image` (the texture-into-scene shape from Slint's upstream +//! `wgpu_texture` example). The texture is bound to an `Image` placed at the +//! bottom of `ImmersiveView`'s z-stack (see ui/immersive/ImmersiveView.slint). +//! +//! Lifecycle: +//! * `setup()` is called once by the rendering notifier in main.rs at +//! `RenderingState::RenderingSetup`, with Slint's OWN wgpu Device/Queue — +//! mandatory so `Image::try_from` operates on the same device Slint renders +//! with. It builds the pipeline + uniform buffer + bind group (persistent). +//! * `render_frame()` is called from the 30 fps drain in visualizer.rs while a +//! shader scene is active. It renders one frame into a FRESH texture (the +//! documented upstream pattern — avoids read-while-write aliasing) and +//! returns an `Image`. The caller sets it on `ImmersiveState.shader-texture`. +//! * `teardown()` clears the state at `RenderingState::RenderingTeardown`. +//! +//! All three run on the UI thread (notifier + Timer share it), so the state lives +//! in a `thread_local`. This file is downstream of the read-only visualizer feed +//! and touches NONE of the protected audio backend. + +use std::cell::RefCell; + +use slint::wgpu_28::wgpu; +use slint::Image; + +/// Offscreen render target size. The `Image` is shown with `image-fit: fill`, so +/// the immersive viewport stretches this to fit. A plasma is organic/soft, so a +/// fixed 720p target is plenty sharp for the spike (HiDPI-correct sizing is a +/// Phase-1 concern, not a spike gate). +const TEX_W: u32 = 1280; +const TEX_H: u32 = 720; +const TEX_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8Unorm; + +/// Mirrors the WGSL `Uniforms` struct (ui/shaders/plasma.wgsl). `#[repr(C)]` + +/// explicit padding keeps it vec4-aligned (32 bytes) for std140 uniform layout. +#[repr(C)] +#[derive(Clone, Copy)] +struct Uniforms { + time: f32, + energy0: f32, + transient: f32, + _pad0: f32, + res_x: f32, + res_y: f32, + _pad1: f32, + _pad2: f32, +} + +/// View `Uniforms` as raw bytes for `Queue::write_buffer`. Sound: `Uniforms` is +/// `#[repr(C)]`, all-`f32`, no padding holes with undefined values we read back — +/// every byte is part of a defined `f32` field. +fn uniforms_bytes(u: &Uniforms) -> &[u8] { + unsafe { + std::slice::from_raw_parts( + (u as *const Uniforms) as *const u8, + std::mem::size_of::(), + ) + } +} + +struct RenderState { + device: wgpu::Device, + queue: wgpu::Queue, + pipeline: wgpu::RenderPipeline, + uniform_buf: wgpu::Buffer, + bind_group: wgpu::BindGroup, + start: std::time::Instant, +} + +thread_local! { + static STATE: RefCell> = const { RefCell::new(None) }; +} + +/// Build the persistent pipeline from Slint's device/queue. Called once at +/// `RenderingSetup`. Idempotent-ish: a second call rebuilds (cheap; only happens +/// if the rendering surface is torn down and re-created). +pub fn setup(device: wgpu::Device, queue: wgpu::Queue) { + let module = device.create_shader_module(wgpu::ShaderModuleDescriptor { + label: Some("qbz-plasma-shader"), + source: wgpu::ShaderSource::Wgsl(include_str!("../ui/shaders/plasma.wgsl").into()), + }); + + let bgl = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + label: Some("qbz-shader-bgl"), + entries: &[wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: None, + }, + count: None, + }], + }); + + let uniform_buf = device.create_buffer(&wgpu::BufferDescriptor { + label: Some("qbz-shader-uniforms"), + size: std::mem::size_of::() as u64, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, + mapped_at_creation: false, + }); + + let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + label: Some("qbz-shader-bg"), + layout: &bgl, + entries: &[wgpu::BindGroupEntry { + binding: 0, + resource: uniform_buf.as_entire_binding(), + }], + }); + + let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: Some("qbz-shader-pl"), + bind_group_layouts: &[&bgl], + // wgpu 28.x: replaces `push_constant_ranges`. We use none. + immediate_size: 0, + }); + + let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("qbz-shader-pipeline"), + layout: Some(&pipeline_layout), + vertex: wgpu::VertexState { + module: &module, + entry_point: Some("vs_main"), + compilation_options: wgpu::PipelineCompilationOptions::default(), + buffers: &[], + }, + primitive: wgpu::PrimitiveState::default(), + depth_stencil: None, + multisample: wgpu::MultisampleState::default(), + fragment: Some(wgpu::FragmentState { + module: &module, + entry_point: Some("fs_main"), + compilation_options: wgpu::PipelineCompilationOptions::default(), + targets: &[Some(wgpu::ColorTargetState { + format: TEX_FORMAT, + blend: None, + write_mask: wgpu::ColorWrites::ALL, + })], + }), + multiview_mask: None, + cache: None, + }); + + STATE.with(|s| { + *s.borrow_mut() = Some(RenderState { + device, + queue, + pipeline, + uniform_buf, + bind_group, + start: std::time::Instant::now(), + }); + }); + log::info!("[shader] wgpu underlay pipeline ready ({TEX_W}x{TEX_H} {TEX_FORMAT:?})"); +} + +/// Drop the pipeline at surface teardown. +pub fn teardown() { + STATE.with(|s| *s.borrow_mut() = None); + log::info!("[shader] wgpu underlay torn down"); +} + +/// Render one frame into a fresh texture and return it as a Slint `Image`. +/// Returns `None` before `setup()` has run. Driven at 30 fps from visualizer.rs. +pub fn render_frame(energy0: f32, transient: f32) -> Option { + STATE.with(|s| { + let borrow = s.borrow(); + let st = borrow.as_ref()?; + + let uniforms = Uniforms { + time: st.start.elapsed().as_secs_f32(), + energy0, + transient, + _pad0: 0.0, + res_x: TEX_W as f32, + res_y: TEX_H as f32, + _pad1: 0.0, + _pad2: 0.0, + }; + st.queue + .write_buffer(&st.uniform_buf, 0, uniforms_bytes(&uniforms)); + + // Fresh target each frame. Image::try_from REQUIRES Rgba8Unorm/Srgb + + // TEXTURE_BINDING | RENDER_ATTACHMENT (Slint graphics/wgpu_28.rs). + let texture = st.device.create_texture(&wgpu::TextureDescriptor { + label: Some("qbz-shader-target"), + size: wgpu::Extent3d { + width: TEX_W, + height: TEX_H, + depth_or_array_layers: 1, + }, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: TEX_FORMAT, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::RENDER_ATTACHMENT, + view_formats: &[], + }); + let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); + + let mut encoder = st + .device + .create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("qbz-shader-encoder"), + }); + { + let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("qbz-shader-pass"), + color_attachments: &[Some(wgpu::RenderPassColorAttachment { + view: &view, + depth_slice: None, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), + store: wgpu::StoreOp::Store, + }, + })], + depth_stencil_attachment: None, + timestamp_writes: None, + occlusion_query_set: None, + // wgpu 28.x render passes also carry the multiview layer mask; + // we don't use multiview (single 2D target), so None. + multiview_mask: None, + }); + pass.set_pipeline(&st.pipeline); + pass.set_bind_group(0, &st.bind_group, &[]); + pass.draw(0..3, 0..1); + } + st.queue.submit(Some(encoder.finish())); + + match Image::try_from(texture) { + Ok(img) => Some(img), + Err(e) => { + log::warn!("[shader] Image::try_from failed: {e:?}"); + None + } + } + }) +} diff --git a/crates/qbz-slint/src/visualizer.rs b/crates/qbz-slint/src/visualizer.rs index 7b415bfa3..27fe5039d 100644 --- a/crates/qbz-slint/src/visualizer.rs +++ b/crates/qbz-slint/src/visualizer.rs @@ -25,7 +25,7 @@ use qbz_audio::visualizer::{spawn_visualizer_thread, VizFrame, VizSink}; use slint::{ComponentHandle, Model, ModelRc, VecModel}; use crate::adapter::SlintAdapter; -use crate::{AppWindow, VisualizerState}; +use crate::{AppWindow, ImmersiveState, VisualizerState}; /// Single-slot, latest-wins frame store shared with the FFT producer thread. /// Each cell holds at most the most recent frame for that stream; the UI drain @@ -102,6 +102,12 @@ pub fn install(window: &AppWindow, runtime: &Arc>) { // ~30 fps drain on the UI thread: copy the latest frames into the models. let weak = window.as_weak(); let timer = slint::Timer::default(); + // WGPU UNDERLAY SPIKE: latest sub-bass + transient kept across ticks so the + // shader animates smoothly (its own time accumulator) and only *reacts* at + // 30 fps. `last_tr` decays each tick so a one-frame transient produces a + // visible multi-frame flash (matching how SpectrumPanel decays it). + let mut last_e0 = 0.0f32; + let mut last_tr = 0.0f32; timer.start( slint::TimerMode::Repeated, std::time::Duration::from_millis(33), @@ -115,6 +121,7 @@ pub fn install(window: &AppWindow, runtime: &Arc>) { for (i, v) in b.iter().enumerate() { energy.set_row_data(i, *v); } + last_e0 = b[0]; } if let Some(b) = cells.spectral.lock().unwrap().take() { for (i, v) in b.iter().enumerate() { @@ -130,6 +137,22 @@ pub fn install(window: &AppWindow, runtime: &Arc>) { if let Some(w) = weak.upgrade() { w.global::().set_transient(x); } + last_tr = x.max(last_tr); + } + + // WGPU UNDERLAY SPIKE: render one GPU shader frame into the wgpu + // texture and hand it to ImmersiveState. Only runs while a shader + // scene is active (shader-mode > 0); otherwise zero GPU cost. The + // device/queue were captured by the rendering notifier (main.rs); + // render_frame is a no-op until that fires. + last_tr *= 0.85; + if let Some(w) = weak.upgrade() { + let imm = w.global::(); + if imm.get_shader_mode() > 0 { + if let Some(img) = crate::shader_underlay::render_frame(last_e0, last_tr) { + imm.set_shader_texture(img); + } + } } }, ); diff --git a/crates/qbz-slint/ui/immersive/ImmersiveView.slint b/crates/qbz-slint/ui/immersive/ImmersiveView.slint index b5e081ee2..d19169b4c 100644 --- a/crates/qbz-slint/ui/immersive/ImmersiveView.slint +++ b/crates/qbz-slint/ui/immersive/ImmersiveView.slint @@ -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; diff --git a/crates/qbz-slint/ui/shaders/plasma.wgsl b/crates/qbz-slint/ui/shaders/plasma.wgsl new file mode 100644 index 000000000..d189094f1 --- /dev/null +++ b/crates/qbz-slint/ui/shaders/plasma.wgsl @@ -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, + _pad1: vec2, +}; + +@group(0) @binding(0) var u: Uniforms; + +struct VsOut { + @builtin(position) clip: vec4, + @location(0) uv: vec2, +}; + +@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, 3>( + vec2(-1.0, -1.0), + vec2( 3.0, -1.0), + vec2(-1.0, 3.0), + ); + let p = verts[vid]; + var out: VsOut; + out.clip = vec4(p, 0.0, 1.0); + out.uv = p * 0.5 + vec2(0.5, 0.5); + return out; +} + +@fragment +fn fs_main(in: VsOut) -> @location(0) vec4 { + 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(r, g, b); + + // Bass lifts overall brightness; a transient adds a brief white flash. + col = col * (0.55 + bass * 0.85) + vec3(tr * 0.6); + col = clamp(col, vec3(0.0), vec3(1.0)); + return vec4(col, 1.0); +} diff --git a/crates/qbz-slint/ui/state.slint b/crates/qbz-slint/ui/state.slint index 691510b48..832dfcbab 100644 --- a/crates/qbz-slint/ui/state.slint +++ b/crates/qbz-slint/ui/state.slint @@ -2977,6 +2977,16 @@ export global ImmersiveState { // Defaults = the Svelte cyan -> purple until the art resolves. in property spectrum-primary: #00dcc8; in property 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 shader-texture; + in-out property shader-mode: 0; } // Now-playing / transport state. The Rust playback poll loop pushes the