FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
ui: detect software rasterizers and say GPU acceleration is unavailable
Mario Podolan7123e1fc46d9
diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex 8d15cde2a..0d932ca57 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -2940,6 +2940,7 @@File Name & Location Nombre y ubicación del archivoQuick Export: {path} Exportación rápida: {path}Graphics problem: switched to software compositing Problema de gráficos: se ha cambiado a la composición por software+ GPU acceleration is unavailable; preview renders on the CPU La aceleración por GPU no está disponible; la vista previa se renderiza en la CPUExporting ExportandoClick to select, or click in empty space and drag to marquee select. Use Shift, Opt, and Cmd for other options. Haz clic para seleccionar, o haz clic en un espacio vacío y arrastra para seleccionar con un marco. Usa Mayús, Opción y Cmd para otras opciones.Click to select all clips to the right in all tracks. Shift-click for a single track. Haz clic para seleccionar todos los clips a la derecha en todas las pistas. Mayús+clic para una sola pista.diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex aa86c493d..4bf45a801 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -3501,3 +3501,4 @@Solid べた塗りClear Transition トランジションを消去Set Transition Duration トランジションのデュレーションを設定+ GPU acceleration is unavailable; preview renders on the CPU GPU アクセラレーションを利用できません。プレビューは CPU でレンダリングされますdiff --git a/crates/ui-egui/src/i18n/zh-cn.tsv b/crates/ui-egui/src/i18n/zh-cn.tsvindex 476c4159b..a4e113714 100644--- a/crates/ui-egui/src/i18n/zh-cn.tsv+++ b/crates/ui-egui/src/i18n/zh-cn.tsv@@ -3490,3 +3490,4 @@Sync with system 跟随系统Clear Transition 清除过渡Set Transition Duration 设置过渡持续时间+ GPU acceleration is unavailable; preview renders on the CPU GPU 加速不可用;预览在 CPU 上渲染diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex d5437e972..7b7bfc8fe 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -330,12 +330,31 @@ fn plan_side(plan: &filmcraft_render::plan::FramePlan) -> usize {plan.max_side()}+/// A software rasterizer (llvmpipe, SwiftShader, softpipe — VMs and containers without GPU device+/// access, missing or broken drivers) runs wgpu entirely on the CPU. Compositing through one is+/// slower than the native CPU compositor and hides the cause: GPU usage stays at 0 % while the+/// CPU saturates. Returns a description when the adapter is one.+pub fn software_rasterizer(info: &eframe::wgpu::AdapterInfo) -> Option<String> {+ rasterizer_reason(&info.name, info.device_type)+}++fn rasterizer_reason(name: &str, device_type: eframe::wgpu::DeviceType) -> Option<String> {+ let lower = name.to_ascii_lowercase();+ if device_type == eframe::wgpu::DeviceType::Cpu || ["llvmpipe", "swiftshader", "softpipe"].iter().any(|s| lower.contains(s)) {+ return Some(format!("software rasterizer ({name}, {device_type:?})"));+ }+ None+}+/// Whether the GPU compositor can run on this adapter: it renders and blends Rgba16Float/// targets and uploads whole frames as textures. Older or OpenGL-backed GPUs (some Intel Macs,/// VMs, Linux without Vulkan, WebGL) can't; those use the CPU compositor, which renders the same/// frames. Returns the reason when unsupported.pub fn gpu_compositor_unsupported(adapter: &eframe::wgpu::Adapter) -> Option<String> {use eframe::wgpu::{TextureFormat, TextureFormatFeatureFlags as F, TextureUsages as U};+ if let Some(why) = software_rasterizer(&adapter.get_info()) {+ return Some(why);+ }let f = adapter.get_texture_format_features(TextureFormat::Rgba16Float);if !f.allowed_usages.contains(U::RENDER_ATTACHMENT | U::TEXTURE_BINDING) {return Some("Rgba16Float is not renderable".into());@@ -355,6 +374,9 @@ impl FilmcraftApp {pub fn set_wgpu(&mut self, rs: eframe::egui_wgpu::RenderState) {if let Some(why) = gpu_compositor_unsupported(&rs.adapter) {log::warn!("GPU compositor disabled ({why}); compositing on the CPU");+ // Say so instead of letting the preview quietly crawl: "GPU 0 %, CPU 100 %" with no+ // explanation read like a renderer bug when the machine simply has no GPU access.+ self.ui.status = format!("{} ({why})", tl!("GPU acceleration is unavailable; preview renders on the CPU"));return;}// wgpu's default reaction to a validation error or lost device is to panic, which closed@@ -1903,6 +1925,20 @@ mod clipboard_key_tests {mod gpu_fallback_tests {use filmcraft_render::plan::{FramePlan, PlanLayer};+ /// Software rasterizers must not be treated as a GPU compositor: the preview crawled while+ /// "GPU" usage read 0 % because wgpu had silently fallen back to llvmpipe.+ #[test]+ fn software_rasterizers_are_detected() {+ use eframe::wgpu::DeviceType as D;+ let r = super::rasterizer_reason;+ assert!(r("llvmpipe (LLVM 23.1.1, 256 bits)", D::Cpu).is_some());+ assert!(r("NVIDIA GeForce RTX 4080", D::Cpu).is_some());+ assert!(r("SwiftShader Device", D::Other).is_some());+ assert!(r("softpipe", D::Cpu).is_some());+ assert!(r("AMD Radeon RX 5700 XT", D::DiscreteGpu).is_none());+ assert!(r("Apple M3 Pro", D::IntegratedGpu).is_none());+ }+#[test]fn plan_side_covers_output_and_every_layer() {let frame = |w: u32, h: u32| std::sync::Arc::new(filmcraft_frame::VideoFrame::rgba_f32(w, h, vec![0.0; (w * h * 4) as usize]));