mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-31 09:50:08 +01:00
rusticl/platform: extract env variable parsing from Platform::init
In our platform initialization code we might want to access the parsed env variables already. So do this in separate steps. Signed-off-by: Karol Herbst <kherbst@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22649>
This commit is contained in:
parent
2283e9d155
commit
389a199993
3 changed files with 24 additions and 13 deletions
|
|
@ -291,7 +291,7 @@ pub fn build_program(
|
|||
if res {
|
||||
Ok(())
|
||||
} else {
|
||||
if Platform::get().debug.program {
|
||||
if Platform::dbg().program {
|
||||
for dev in &devs {
|
||||
eprintln!("{}", p.log(dev));
|
||||
}
|
||||
|
|
@ -370,7 +370,7 @@ pub fn compile_program(
|
|||
if res {
|
||||
Ok(())
|
||||
} else {
|
||||
if Platform::get().debug.program {
|
||||
if Platform::dbg().program {
|
||||
for dev in &devs {
|
||||
eprintln!("{}", p.log(dev));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,14 +15,15 @@ pub struct Platform {
|
|||
dispatch: &'static cl_icd_dispatch,
|
||||
pub extensions: [cl_name_version; 2],
|
||||
pub devs: Vec<Arc<Device>>,
|
||||
pub debug: PlatformDebug,
|
||||
}
|
||||
|
||||
pub struct PlatformDebug {
|
||||
pub program: bool,
|
||||
}
|
||||
|
||||
static PLATFORM_ENV_ONCE: Once = Once::new();
|
||||
static PLATFORM_ONCE: Once = Once::new();
|
||||
|
||||
static mut PLATFORM: Platform = Platform {
|
||||
dispatch: &DISPATCH,
|
||||
extensions: [
|
||||
|
|
@ -30,8 +31,20 @@ static mut PLATFORM: Platform = Platform {
|
|||
mk_cl_version_ext(1, 0, 0, "cl_khr_il_program"),
|
||||
],
|
||||
devs: Vec::new(),
|
||||
debug: PlatformDebug { program: false },
|
||||
};
|
||||
static mut PLATFORM_DBG: PlatformDebug = PlatformDebug { program: false };
|
||||
|
||||
fn load_env() {
|
||||
let debug = unsafe { &mut PLATFORM_DBG };
|
||||
if let Ok(debug_flags) = env::var("RUSTICL_DEBUG") {
|
||||
for flag in debug_flags.split(',') {
|
||||
match flag {
|
||||
"program" => debug.program = true,
|
||||
_ => eprintln!("Unknown RUSTICL_DEBUG flag found: {}", flag),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Platform {
|
||||
pub fn as_ptr(&self) -> cl_platform_id {
|
||||
|
|
@ -44,23 +57,21 @@ impl Platform {
|
|||
unsafe { &PLATFORM }
|
||||
}
|
||||
|
||||
pub fn dbg() -> &'static PlatformDebug {
|
||||
debug_assert!(PLATFORM_ENV_ONCE.is_completed());
|
||||
unsafe { &PLATFORM_DBG }
|
||||
}
|
||||
|
||||
fn init(&mut self) {
|
||||
unsafe {
|
||||
glsl_type_singleton_init_or_ref();
|
||||
}
|
||||
|
||||
self.devs.extend(Device::all());
|
||||
if let Ok(debug_flags) = env::var("RUSTICL_DEBUG") {
|
||||
for flag in debug_flags.split(',') {
|
||||
match flag {
|
||||
"program" => self.debug.program = true,
|
||||
_ => eprintln!("Unknown RUSTICL_DEBUG flag found: {}", flag),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init_once() {
|
||||
PLATFORM_ENV_ONCE.call_once(load_env);
|
||||
// SAFETY: no concurrent static mut access due to std::Once
|
||||
PLATFORM_ONCE.call_once(|| unsafe { PLATFORM.init() });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -569,7 +569,7 @@ impl Program {
|
|||
let info = Self::dev_build_info(&mut lock, d);
|
||||
assert_eq!(info.status, CL_BUILD_SUCCESS as cl_build_status);
|
||||
|
||||
let mut log = Platform::get().debug.program.then(Vec::new);
|
||||
let mut log = Platform::dbg().program.then(Vec::new);
|
||||
let nir = info.spirv.as_ref().unwrap().to_nir(
|
||||
kernel,
|
||||
d.screen
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue