From 63c501809e1bc3e97013e49144985243249a13d5 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Mon, 15 May 2023 22:12:15 +0200 Subject: rusticl/platform: generate extension constants via macro Signed-off-by: Karol Herbst Reviewed-by: Nora Allen Part-of: --- src/gallium/frontends/rusticl/core/platform.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/gallium/frontends/rusticl/core/platform.rs b/src/gallium/frontends/rusticl/core/platform.rs index 666c475a9bf..c6b627ac697 100644 --- a/src/gallium/frontends/rusticl/core/platform.rs +++ b/src/gallium/frontends/rusticl/core/platform.rs @@ -26,12 +26,26 @@ pub struct PlatformFeatures { static PLATFORM_ENV_ONCE: Once = Once::new(); static PLATFORM_ONCE: Once = Once::new(); -pub static PLATFORM_EXTENSIONS: [cl_name_version; 3] = [ - mk_cl_version_ext(1, 0, 0, "cl_khr_byte_addressable_store"), - mk_cl_version_ext(1, 0, 0, "cl_khr_icd"), - mk_cl_version_ext(1, 0, 0, "cl_khr_il_program"), -]; -pub static PLATFORM_EXTENSION_STR: &str = "cl_khr_byte_addressable_store cl_khr_icd cl_khr_il_program"; + +macro_rules! gen_cl_exts { + (@COUNT $e:expr) => { 1 }; + (@COUNT $e:expr, $($es:expr),+) => { 1 + gen_cl_exts!(@COUNT $($es),*) }; + + (@CONCAT $e:tt) => { $e }; + (@CONCAT $e:tt, $($es:tt),+) => { concat!($e, ' ', gen_cl_exts!(@CONCAT $($es),*)) }; + + ([$(($major:expr, $minor:expr, $patch:expr, $ext:tt)$(,)?)+]) => { + pub static PLATFORM_EXTENSION_STR: &str = concat!(gen_cl_exts!(@CONCAT $($ext),*)); + pub static PLATFORM_EXTENSIONS: [cl_name_version; gen_cl_exts!(@COUNT $($ext),*)] = [ + $(mk_cl_version_ext($major, $minor, $patch, $ext)),+ + ]; + } +} +gen_cl_exts!([ + (1, 0, 0, "cl_khr_byte_addressable_store"), + (1, 0, 0, "cl_khr_icd"), + (1, 0, 0, "cl_khr_il_program"), +]); static mut PLATFORM: Platform = Platform { dispatch: &DISPATCH, -- cgit v1.2.1