From 1e41c73cf5a7fd1f7ea4f8e26bfd803a79e6f166 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Thu, 4 Jun 2026 14:42:34 +0200 Subject: [PATCH] rusticl/program: construct __OPENCL_VERSION__ inside CompileOptions::get_clang_args Reviewed-by: @LingMan Part-of: --- src/gallium/frontends/rusticl/core/program.rs | 9 +++++---- src/gallium/frontends/rusticl/core/version.rs | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/gallium/frontends/rusticl/core/program.rs b/src/gallium/frontends/rusticl/core/program.rs index 956bd2e683b..3174246a653 100644 --- a/src/gallium/frontends/rusticl/core/program.rs +++ b/src/gallium/frontends/rusticl/core/program.rs @@ -14,6 +14,7 @@ use mesa_rust::compiler::clc::*; use mesa_rust::compiler::nir::*; use mesa_rust::util::disk_cache::*; use mesa_rust_gen::*; +use mesa_rust_util::string::CStrExt; use mesa_rust_util::string::CStringExt; use mesa_rust_util::string::Join; use rusticl_llvm_gen::*; @@ -311,8 +312,6 @@ impl CompileOptions { options.push_str(" -cl-std=CL"); options.push_str(dev.clc_version.api_str()); } - options.push_str(" -D__OPENCL_VERSION__="); - options.push_str(dev.cl_version.clc_str()); let mut res = Vec::new(); @@ -366,8 +365,10 @@ impl CompileOptions { } } - fn get_clang_args(&self, _dev: &Device) -> Vec { - self.clang_args.clone() + fn get_clang_args(&self, dev: &Device) -> Vec { + let mut args = self.clang_args.clone(); + args.push(c"-D__OPENCL_VERSION__=".concat(dev.cl_version.clc_str())); + args } } diff --git a/src/gallium/frontends/rusticl/core/version.rs b/src/gallium/frontends/rusticl/core/version.rs index c2554529bc6..7c19c2c91ff 100644 --- a/src/gallium/frontends/rusticl/core/version.rs +++ b/src/gallium/frontends/rusticl/core/version.rs @@ -4,6 +4,7 @@ use rusticl_opencl_gen::*; use std::convert::TryFrom; +use std::ffi::CStr; use std::os::raw::c_char; pub const CL1_0_VER: cl_version = mk_cl_version(1, 0, 0); @@ -64,16 +65,16 @@ impl CLVersion { } } - pub fn clc_str(&self) -> &'static str { + pub fn clc_str(&self) -> &'static CStr { match self { - CLVersion::Cl1_0 => "100", - CLVersion::Cl1_1 => "110", - CLVersion::Cl1_2 => "120", - CLVersion::Cl2_0 => "200", - CLVersion::Cl2_1 => "210", - CLVersion::Cl2_2 => "220", - CLVersion::Cl3_0 => "300", - CLVersion::Cl3_1 => "310", + CLVersion::Cl1_0 => c"100", + CLVersion::Cl1_1 => c"110", + CLVersion::Cl1_2 => c"120", + CLVersion::Cl2_0 => c"200", + CLVersion::Cl2_1 => c"210", + CLVersion::Cl2_2 => c"220", + CLVersion::Cl3_0 => c"300", + CLVersion::Cl3_1 => c"310", } } }