M3: of one GPU's adapters, the OpenGL one is picked last, whatever order wgpu lists them in (#4134)

pick_adapter ranked adapters without their backend, so a GPU that wgpu
offers through both Direct3D 12 and OpenGL got its Direct3D 12 adapter
only because wgpu lists it first. The backend is now the last part of the
ranking. An OpenGL-only GPU still beats the software adapter by kind, and
the selector then declines it so that glow starts on that GPU.

The test covers Direct3D 12, Vulkan, OpenGL and software adapters, in
both orders and with no display known (FredApps' review).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
austin62jakeandClaude Opus 5.5 authored and Codex committed 2026-11-30 13:14:09 +01:00
1 parent 548d0c005f
commit 3cc8358c35
2 files changed
+53 -12

No files matched your search

+14 -7
View File
@@ -791,11 +791,11 @@ fn configure_gpu(native: &mut eframe::NativeOptions) {
if !displays.is_empty() || compositor.is_some() || cfg!(target_os = "windows") {
setup.native_adapter_selector = Some(std::sync::Arc::new(move |adapters, surface| {
let usable: Vec<&eframe::wgpu::Adapter> = adapters.iter().filter(|a| surface.is_none_or(|s| a.is_surface_supported(s))).collect();
let infos: Vec<(u32, u32, eframe::wgpu::DeviceType)> = usable
let infos: Vec<(u32, u32, eframe::wgpu::DeviceType, eframe::wgpu::Backend)> = usable
.iter()
.map(|a| {
let info = a.get_info();
(info.vendor, info.device, info.device_type)
(info.vendor, info.device, info.device_type, info.backend)
})
.collect();
let picked = pick_adapter(&infos, &displays, compositor).and_then(|i| usable.get(i)).map(|a| (*a).clone());
@@ -964,15 +964,22 @@ fn linux_display_gpus(drm: &std::path::Path) -> Vec<DisplayGpu> {
/// PCI ids) first, then one that drives a display. Among several of those, the one driving the
/// primary display (a hybrid laptop's panel, #8; the primary display on Windows, #378), or else,
/// with no primary display known (a Linux desktop with a monitor on each GPU, #445), the discrete
/// one. Otherwise the most frugal kind: integrated, discrete, other, virtual, software.
fn pick_adapter(adapters: &[(u32, u32, eframe::wgpu::DeviceType)], displays: &[DisplayGpu], compositor: Option<(u32, u32)>) -> Option<usize> {
use eframe::wgpu::DeviceType;
/// one. Otherwise the most frugal kind: integrated, discrete, other, virtual, software. Of one
/// GPU's adapters, the one wgpu reaches through OpenGL comes last, whatever order wgpu lists them
/// in: on Windows wgpu offers a Direct3D 12 GPU through OpenGL too, and declines OpenGL there
/// (`wgpu_draws_with`).
fn pick_adapter(
adapters: &[(u32, u32, eframe::wgpu::DeviceType, eframe::wgpu::Backend)],
displays: &[DisplayGpu],
compositor: Option<(u32, u32)>,
) -> Option<usize> {
use eframe::wgpu::{Backend, DeviceType};
let display = |pci: (u32, u32)| displays.iter().find(|g| g.pci == pci);
let multi_gpu_desktop = displays.len() > 1 && !displays.iter().any(|g| g.primary);
adapters
.iter()
.enumerate()
.min_by_key(|(_, (vendor, device, kind))| {
.min_by_key(|(_, (vendor, device, kind, backend))| {
let shown = display((*vendor, *device));
let drives_display = shown.is_some();
let drives_primary = shown.is_some_and(|g| g.primary);
@@ -986,7 +993,7 @@ fn pick_adapter(adapters: &[(u32, u32, eframe::wgpu::DeviceType)], displays: &[D
DeviceType::VirtualGpu => 4,
DeviceType::Cpu => 5,
};
(compositor != Some((*vendor, *device)), !drives_display, !drives_primary, rank)
(compositor != Some((*vendor, *device)), !drives_display, !drives_primary, rank, *backend == Backend::Gl)
})
.map(|(i, _)| i)
}
+39 -5
View File
@@ -33,6 +33,32 @@ fn on_windows_wgpu_leaves_an_opengl_only_gpu_to_eframes_opengl_renderer() {
}
}
#[test]
fn pick_adapter_takes_a_gpus_opengl_adapter_last_and_an_opengl_only_gpu_over_software() {
use eframe::wgpu::{Backend, DeviceType};
// One GPU offered through OpenGL and through Direct3D 12 or Vulkan, in either order: never
// OpenGL, which `wgpu_draws_with` declines on Windows.
for other in [Backend::Dx12, Backend::Vulkan] {
let gl_first =
[(INTEL_IGPU.0, INTEL_IGPU.1, DeviceType::IntegratedGpu, Backend::Gl), (INTEL_IGPU.0, INTEL_IGPU.1, DeviceType::IntegratedGpu, other)];
assert_eq!(super::pick_adapter(&gl_first, &[panel(INTEL_IGPU)], None), Some(1), "{other:?}");
assert_eq!(super::pick_adapter(&[gl_first[1], gl_first[0]], &[panel(INTEL_IGPU)], None), Some(0), "{other:?}");
assert_eq!(super::pick_adapter(&gl_first, &[], None), Some(1), "{other:?} with no display known");
}
// Issue #4134: an Intel HD 4000 has only OpenGL, and the Microsoft Basic Render Driver (in
// software) has Direct3D 12. The GPU is still picked, by kind, with or without a known
// display, as over Remote Desktop; declining it then starts glow on that GPU.
const HD_4000: (u32, u32) = (0x8086, 0x0166);
let ivy_bridge = [(0x1414, 0x008c, DeviceType::Cpu, Backend::Dx12), (HD_4000.0, HD_4000.1, DeviceType::IntegratedGpu, Backend::Gl)];
assert_eq!(super::pick_adapter(&ivy_bridge, &[panel(HD_4000)], None), Some(1));
assert_eq!(super::pick_adapter(&ivy_bridge, &[], None), Some(1));
assert!(!super::wgpu_draws_with(Backend::Gl, true, false));
// Only OpenGL, or only software: that adapter.
assert_eq!(super::pick_adapter(&ivy_bridge[1..], &[], None), Some(0));
assert_eq!(super::pick_adapter(&ivy_bridge[..1], &[], None), Some(0));
assert_eq!(super::pick_adapter(&[], &[], None), None);
}
#[test]
fn opengl_is_the_fallback_unless_a_renderer_was_chosen() {
use super::{RendererChoice, native_options, renderer_choice, retry_with_gl};
@@ -336,9 +362,13 @@ const NVIDIA: (u32, u32) = (0x10de, 0x2684);
const NVIDIA_3090: (u32, u32) = (0x10de, 0x2204);
const AMD_IGPU: (u32, u32) = (0x1002, 0x164e);
fn adapters() -> Vec<(u32, u32, eframe::wgpu::DeviceType)> {
use eframe::wgpu::DeviceType;
vec![(NVIDIA.0, NVIDIA.1, DeviceType::DiscreteGpu), (AMD_IGPU.0, AMD_IGPU.1, DeviceType::IntegratedGpu), (0, 0, DeviceType::Cpu)]
fn adapters() -> Vec<(u32, u32, eframe::wgpu::DeviceType, eframe::wgpu::Backend)> {
use eframe::wgpu::{Backend, DeviceType};
vec![
(NVIDIA.0, NVIDIA.1, DeviceType::DiscreteGpu, Backend::Vulkan),
(AMD_IGPU.0, AMD_IGPU.1, DeviceType::IntegratedGpu, Backend::Vulkan),
(0, 0, DeviceType::Cpu, Backend::Vulkan),
]
}
const INTEL_IGPU: (u32, u32) = (0x8086, 0xa780);
@@ -405,8 +435,12 @@ fn pick_adapter_keeps_the_integrated_gpu_on_hybrid_laptops() {
#[test]
fn pick_adapter_prefers_the_discrete_gpu_on_desktops_with_a_monitor_on_each() {
// Issue #445: one monitor on the Intel iGPU, one on the NVIDIA card, no built-in panel.
use eframe::wgpu::DeviceType;
let desktop = [(INTEL_IGPU.0, INTEL_IGPU.1, DeviceType::IntegratedGpu), (NVIDIA.0, NVIDIA.1, DeviceType::DiscreteGpu), (0, 0, DeviceType::Cpu)];
use eframe::wgpu::{Backend, DeviceType};
let desktop = [
(INTEL_IGPU.0, INTEL_IGPU.1, DeviceType::IntegratedGpu, Backend::Vulkan),
(NVIDIA.0, NVIDIA.1, DeviceType::DiscreteGpu, Backend::Vulkan),
(0, 0, DeviceType::Cpu, Backend::Vulkan),
];
assert_eq!(super::pick_adapter(&desktop, &[monitor(INTEL_IGPU), monitor(NVIDIA)], None), Some(1));
assert_eq!(super::pick_adapter(&desktop, &[monitor(NVIDIA), monitor(INTEL_IGPU)], None), Some(1));
// A GPU driving no display still loses to one that does.