LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Issue #136: a GPU start lost to an off/on switch is retried
OneSlips8541131cd846
diff --git a/crates/gpu/src/lib.rs b/crates/gpu/src/lib.rsindex 58aa1d967..84aad52ea 100644--- a/crates/gpu/src/lib.rs+++ b/crates/gpu/src/lib.rs@@ -317,10 +317,19 @@ pub fn warm_up() {return;}let spawned = std::thread::Builder::new().name("lc-gpu-init".into()).spawn(|| {- let _ = device();- // turned off before the thread ran (nothing created): a later call may start again- if GPU.get().is_none() {- STARTED.store(false, Ordering::Release);+ loop {+ let _ = device();+ if GPU.get().is_some() || shutting_down() || env_disabled() {+ break;+ }+ // turned off before the thread ran (nothing created): a later call may start+ // again. Released first, then the preference read again: a call made while this+ // thread still held the flag (turned back on meanwhile) returned without starting+ // one, so this thread tries again itself rather than leave "starting" for good.+ STARTED.store(false, Ordering::SeqCst);+ if !ENABLED.load(Ordering::SeqCst) || STARTED.swap(true, Ordering::SeqCst) {+ break;+ }}});if spawned.is_err() {diff --git a/crates/ui-egui/src/panels/settings.rs b/crates/ui-egui/src/panels/settings.rsindex 555aa349c..111b37a28 100644--- a/crates/ui-egui/src/panels/settings.rs+++ b/crates/ui-egui/src/panels/settings.rs@@ -588,7 +588,10 @@ fn performance_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {check(ui, "settings.gpu", &mut app.ui.settings.gpu, "Use the GPU for rendering");// `available` would wait for a device still being created (issue #136)let status = if gpu::enabled() && !gpu::ready() {- // the device is created on another thread, which doesn't wake the UI when it's done+ // the device is created on another thread, which doesn't wake the UI when it's done;+ // make sure that thread runs (cheap and idempotent: a start lost to an off/on switch+ // can't leave "starting" for good)+ gpu::warm_up();ui.ctx().request_repaint_after(std::time::Duration::from_millis(250));"GPU: starting…".to_string()} else if !gpu::available() {