From ff20cf8a0987946ef1fd508823b48f8aff672655 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Tue, 2 Jan 2024 10:20:45 -0800 Subject: [PATCH] wgpu-hal: Fix Mesa version check for version with suffix containing `.` On Pop!_OS we have versions like `Mesa 23.3.0-1pop0~1702935939~22.04~67e417a`. This failed to parse here since it tried to split at the `.` in the suffix. Not sure if other distros use a suffix with a `.`, but splitting from the left and comparing as a tuple instead of a float seems cleaner overall. --- wgpu-hal/src/vulkan/instance.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/wgpu-hal/src/vulkan/instance.rs b/wgpu-hal/src/vulkan/instance.rs index 7a52777430..e9ca3221ea 100644 --- a/wgpu-hal/src/vulkan/instance.rs +++ b/wgpu-hal/src/vulkan/instance.rs @@ -1,6 +1,7 @@ use std::{ ffi::{c_void, CStr, CString}, slice, + str::FromStr, sync::Arc, thread, }; @@ -855,11 +856,16 @@ impl crate::Instance for super::Instance { { // Check if mesa driver and version less than 21.2 if let Some(version) = exposed.info.driver_info.split_once("Mesa ").map(|s| { - s.1.rsplit_once('.') - .map(|v| v.0.parse::().unwrap_or_default()) - .unwrap_or_default() + let mut components = s.1.split('.'); + let major = components.next().and_then(|s| u8::from_str(s).ok()); + let minor = components.next().and_then(|s| u8::from_str(s).ok()); + if let (Some(major), Some(minor)) = (major, minor) { + (major, minor) + } else { + (0, 0) + } }) { - if version < 21.2 { + if version < (21, 2) { // See https://gitlab.freedesktop.org/mesa/mesa/-/issues/4688 log::warn!( "Disabling presentation on '{}' (id {:?}) due to NV Optimus and Intel Mesa < v21.2",