From dbfb847f0351eee441a1394975de21ee3af4ecb2 Mon Sep 17 00:00:00 2001 From: austin62jake <340374338+austin62jake@users.noreply.github.com> Date: Sat, 31 Oct 2026 13:35:46 -0500 Subject: [PATCH] M3: on Windows, a GPU wgpu can only reach through OpenGL draws with eframe's OpenGL renderer (#4134) An Intel HD 2500 or 4000 (Ivy Bridge) has no Direct3D 12 driver, so wgpu picks its OpenGL backend. That backend fails in Surface::configure a few seconds after the window opens ("Failed to wait for GPU to come idle"), after the start-up retry with OpenGL can help, so the app closed with a white window (#519, #4134, #5553). eframe's own OpenGL renderer works on the same GPUs, which is the PDFCRAFT_RENDERER=gl workaround. The adapter selector now declines an adapter on wgpu's OpenGL backend on Windows, unless WGPU_BACKEND asked for it, so the existing start-up retry draws with eframe's OpenGL renderer instead. Co-Authored-By: Claude Opus 5.5 --- apps/pdfcraft/src/main.rs | 19 +++++++++++++++++++ apps/pdfcraft/src/tests.rs | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/apps/pdfcraft/src/main.rs b/apps/pdfcraft/src/main.rs index c374ea74f7..6ed77ff1be 100644 --- a/apps/pdfcraft/src/main.rs +++ b/apps/pdfcraft/src/main.rs @@ -796,6 +796,15 @@ fn configure_gpu(native: &mut eframe::NativeOptions) { }) .collect(); let picked = pick_adapter(&infos, &displays, compositor).and_then(|i| usable.get(i)).map(|a| (*a).clone()); + if let Some(a) = &picked + && !wgpu_draws_with(a.get_info().backend, cfg!(target_os = "windows"), std::env::var_os("WGPU_BACKEND").is_some()) + { + log::warn!( + "wgpu found no Direct3D 12 adapter for {}, only its OpenGL backend: drawing with eframe's OpenGL renderer instead", + a.get_info().name + ); + return Err("wgpu would draw through its OpenGL backend".to_string()); + } match &picked { // Which GPU draws is the first question when a window stays black (#8, #378, #445). Some(a) => { @@ -816,6 +825,16 @@ fn configure_gpu(native: &mut eframe::NativeOptions) { } } +/// Whether wgpu should draw with the adapter it picked on `backend`. On Windows (`windows`) wgpu +/// reaches its OpenGL backend only for a GPU with no Direct3D 12 driver, such as Intel's Ivy +/// Bridge, and there that backend fails in `Surface::configure` a few seconds after the window +/// opens: too late for the start-up retry with OpenGL, so the app closed (#519, #4134, #5553). +/// eframe's own OpenGL renderer works on the same GPUs, so wgpu declines and that retry takes over. +/// A backend asked for with `WGPU_BACKEND` (`backend_chosen`) is kept. +fn wgpu_draws_with(backend: eframe::wgpu::Backend, windows: bool, backend_chosen: bool) -> bool { + !(windows && backend == eframe::wgpu::Backend::Gl && !backend_chosen) +} + /// How Direct3D 12 presents on Windows: through a DirectComposition visual (issue #2738), unless /// `WGPU_DX12_PRESENTATION_SYSTEM` asked for something else (`asked`). fn dx12_presentation(asked: Option) -> eframe::wgpu::Dx12SwapchainKind { diff --git a/apps/pdfcraft/src/tests.rs b/apps/pdfcraft/src/tests.rs index 1bf079223b..5d813603fe 100644 --- a/apps/pdfcraft/src/tests.rs +++ b/apps/pdfcraft/src/tests.rs @@ -19,6 +19,20 @@ pub(crate) fn install_runtime(ctx: &egui::Context) { craft::ui::shell::embed::install(ctx, spec, &pdfcraft_ui_egui::fonts::ui_fonts(Lang::EN)).expect("the runtime installs on a fresh context"); } +#[test] +fn on_windows_wgpu_leaves_an_opengl_only_gpu_to_eframes_opengl_renderer() { + use eframe::wgpu::Backend; + // Issues #4134 and #5553: an Intel HD 4000 has no Direct3D 12 driver, so wgpu picks its + // OpenGL backend, which fails a few seconds after the window opens. + assert!(!super::wgpu_draws_with(Backend::Gl, true, false), "declined, so the start-up retry uses glow"); + // Everything else draws with wgpu as before. + assert!(super::wgpu_draws_with(Backend::Dx12, true, false)); + assert!(super::wgpu_draws_with(Backend::Gl, true, true), "WGPU_BACKEND asked for it"); + for backend in [Backend::Gl, Backend::Vulkan, Backend::Metal] { + assert!(super::wgpu_draws_with(backend, false, false), "{backend:?} off Windows"); + } +} + #[test] fn opengl_is_the_fallback_unless_a_renderer_was_chosen() { use super::{RendererChoice, native_options, renderer_choice, retry_with_gl};