From 1301d61de41e4c12c0767ab75d8a2cabe977509e Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Mon, 16 Sep 2024 13:29:29 +0200 Subject: [PATCH] rusticl: allow devices to be enabled by default Reviewed-by: David Heidelberg Acked-by: Eric Engestrom Reviewed-by: Alyssa Rosenzweig Part-of: --- meson_options.txt | 8 +++ .../frontends/rusticl/mesa/pipe/device.rs | 69 ++++++++++--------- src/gallium/frontends/rusticl/meson.build | 7 ++ 3 files changed, 51 insertions(+), 33 deletions(-) diff --git a/meson_options.txt b/meson_options.txt index 82324617884..18a4b01b324 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -160,6 +160,14 @@ option( description : 'build gallium "rusticl" OpenCL frontend.', ) +option( + 'gallium-rusticl-enable-drivers', + type : 'array', + value : ['auto'], + description : 'List of gallium drivers for which rusticl will be enabled ' + + 'by default', +) + option( 'gallium-wgl-dll-name', type : 'string', diff --git a/src/gallium/frontends/rusticl/mesa/pipe/device.rs b/src/gallium/frontends/rusticl/mesa/pipe/device.rs index e41ca59dc9a..010943c9ea9 100644 --- a/src/gallium/frontends/rusticl/mesa/pipe/device.rs +++ b/src/gallium/frontends/rusticl/mesa/pipe/device.rs @@ -55,45 +55,48 @@ fn load_devs() -> impl Iterator { fn get_enabled_devs() -> HashMap { let mut res = HashMap::new(); - if let Ok(enabled_devs) = env::var("RUSTICL_ENABLE") { - let mut last_driver = None; - for driver_str in enabled_devs.split(',') { - if driver_str.is_empty() { - continue; - } + // we require the type here as this list can be empty depending on the build options + let default_devs: &[&str] = &[]; - // if the string parses to a number, just updated the device bitset - if let Ok(dev_id) = driver_str.parse::() { - if let Some(last_driver) = last_driver { - *res.get_mut(last_driver).unwrap() |= 1 << dev_id; - } - continue; - } else { - let driver_str: Vec<_> = driver_str.split(':').collect(); - let mut devices = 0; - - if driver_str.len() == 1 { - devices = !0; - } else if let Ok(dev_id) = driver_str[1].parse::() { - devices |= 1 << dev_id; - } - - let driver_str = match driver_str[0] { - "llvmpipe" | "lp" => "swrast", - "freedreno" => "msm", - a => a, - }; - - res.insert(driver_str.to_owned(), devices); - last_driver = Some(driver_str); - } + // I wished we could use different iterators, but that's not really working out. + let enabled_devs = env::var("RUSTICL_ENABLE").unwrap_or(default_devs.join(",")); + let mut last_driver = None; + for driver_str in enabled_devs.split(',') { + if driver_str.is_empty() { + continue; } - if res.contains_key("panfrost") { - res.insert("panthor".to_owned(), res["panfrost"]); + // if the string parses to a number, just updated the device bitset + if let Ok(dev_id) = driver_str.parse::() { + if let Some(last_driver) = last_driver { + *res.get_mut(last_driver).unwrap() |= 1 << dev_id; + } + continue; + } else { + let driver_str: Vec<_> = driver_str.split(':').collect(); + let mut devices = 0; + + if driver_str.len() == 1 { + devices = !0; + } else if let Ok(dev_id) = driver_str[1].parse::() { + devices |= 1 << dev_id; + } + + let driver_str = match driver_str[0] { + "llvmpipe" | "lp" => "swrast", + "freedreno" => "msm", + a => a, + }; + + res.insert(driver_str.to_owned(), devices); + last_driver = Some(driver_str); } } + if res.contains_key("panfrost") { + res.insert("panthor".to_owned(), res["panfrost"]); + } + res } diff --git a/src/gallium/frontends/rusticl/meson.build b/src/gallium/frontends/rusticl/meson.build index 1fe75a61144..cba6bb7ae00 100644 --- a/src/gallium/frontends/rusticl/meson.build +++ b/src/gallium/frontends/rusticl/meson.build @@ -75,6 +75,13 @@ rusticl_args = [ '-Aclippy::type_complexity', ] +rusticl_drivers_enable = get_option('gallium-rusticl-enable-drivers') +foreach driver : rusticl_drivers_enable + rusticl_args += [ + '--cfg', 'rusticl_enable_' + driver, + ] +endforeach + if with_platform_x11 rusticl_args += [ '--cfg', 'glx',