mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 17:15:56 +00:00
GPU start: try the adapters that crashed an earlier start when no other is left
A start ended before its first frame leaves its adapter recorded as crashed in graphics-start.json, and the next start leaves that adapter out. A start ended from outside (a --control session terminated early) looks the same as a crash in the driver, so on a machine with one GPU, such as an Apple Silicon Mac, the next start had no adapter left and failed with "no graphics adapter can show the window". The selector now tries the adapters that crashed an earlier start again, with a warning in the log, when leaving them out would leave none. Adapters a restart left out after they failed in this run of the app stay left out, and with another adapter to try, the one that crashed is still left out. Fixes #9183
This commit is contained in:
@@ -398,6 +398,31 @@ pub fn adapter_order(
|
||||
order.into_iter().map(|(i, _)| i).collect()
|
||||
}
|
||||
|
||||
/// [`adapter_order`] without the adapters a restart left out after they failed (`skip`) and those
|
||||
/// that crashed an earlier start (`crashed`), and `true` when that left none and the ones that
|
||||
/// crashed are tried again. A crash record can't stop a start that has no other adapter to try:
|
||||
/// the record may be from a start ended from outside before its first frame (#9183), which looks
|
||||
/// the same as a crash in the driver. An adapter in `skip` failed in this run of the app and
|
||||
/// stays left out.
|
||||
pub fn order_leaving_out(
|
||||
candidates: &[Candidate],
|
||||
power: PowerPreference,
|
||||
displays: &[DisplayGpu],
|
||||
compositor: Option<(u32, u32)>,
|
||||
named: Option<&str>,
|
||||
skip: &[String],
|
||||
crashed: &[String],
|
||||
) -> (Vec<usize>, bool) {
|
||||
let left_out: Vec<String> = skip.iter().chain(crashed).cloned().collect();
|
||||
let order = adapter_order(candidates, power, displays, compositor, named, &left_out);
|
||||
if !order.is_empty() || crashed.is_empty() {
|
||||
return (order, false);
|
||||
}
|
||||
let again = adapter_order(candidates, power, displays, compositor, named, skip);
|
||||
let retried = !again.is_empty();
|
||||
(again, retried)
|
||||
}
|
||||
|
||||
/// wgpu's own ranking for a power preference: the preferred kind of GPU, the other kind, unknown,
|
||||
/// virtual, software.
|
||||
fn power_rank(t: DeviceType, power: PowerPreference) -> u8 {
|
||||
@@ -845,10 +870,9 @@ pub fn selector(
|
||||
) -> NativeAdapterSelectorMethod {
|
||||
let named = std::env::var(NAME_ENV).ok();
|
||||
let skip = skipped();
|
||||
let left_out: Vec<String> = skip.iter().chain(&crashed).cloned().collect();
|
||||
Arc::new(move |adapters, surface| {
|
||||
let candidates: Vec<Candidate> = adapters.iter().map(|a| Candidate::new(a, surface)).collect();
|
||||
let order = adapter_order(&candidates, power, &displays, compositor, named.as_deref(), &left_out);
|
||||
let (order, retried) = order_leaving_out(&candidates, power, &displays, compositor, named.as_deref(), &skip, &crashed);
|
||||
let listed: Vec<String> = candidates
|
||||
.iter()
|
||||
.map(|c| {
|
||||
@@ -872,6 +896,9 @@ pub fn selector(
|
||||
})
|
||||
.collect();
|
||||
log::info!("graphics adapters: {}", listed.join("; "));
|
||||
if retried {
|
||||
log::warn!("every graphics adapter that can show the window crashed an earlier start: trying them again");
|
||||
}
|
||||
let first = order.first().and_then(|&i| adapters.get(i).zip(candidates.get(i)));
|
||||
let Some((adapter, chosen)) = first else {
|
||||
startup.none_left();
|
||||
|
||||
@@ -827,3 +827,17 @@ fn pci_ids_reject_a_sign_in_the_hex_digits() {
|
||||
assert_eq!(pci_ids("PCI\\VEN_+10DE&DEV_2204"), None);
|
||||
assert_eq!(pci_ids("PCI\\VEN_10DE&DEV_+2204"), None);
|
||||
}
|
||||
|
||||
/// #9183: a Mac lists one adapter. A start ended from outside before its first frame left it
|
||||
/// recorded as crashed, and the next start left it out and had nothing to draw on. It is tried
|
||||
/// again when nothing else is left; an adapter a restart left out after it failed stays out, and
|
||||
/// with another adapter to try, the one that crashed is still left out.
|
||||
#[test]
|
||||
fn an_adapter_that_crashed_an_earlier_start_is_tried_again_when_no_other_is_left() {
|
||||
let mac = [gpu("Apple M6", Backend::Metal, DeviceType::IntegratedGpu)];
|
||||
let crashed = vec![mac[0].key.clone()];
|
||||
assert_eq!(order_leaving_out(&mac, PowerPreference::LowPower, &[], None, None, &[], &crashed), (vec![0], true));
|
||||
assert_eq!(order_leaving_out(&mac, PowerPreference::LowPower, &[], None, None, &crashed, &crashed), (vec![], false));
|
||||
let two = [gpu("Apple M6", Backend::Metal, DeviceType::IntegratedGpu), gpu("llvmpipe", Backend::Gl, DeviceType::Cpu)];
|
||||
assert_eq!(order_leaving_out(&two, PowerPreference::LowPower, &[], None, None, &[], &crashed), (vec![1], false));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user