mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-09 06:48:06 +02: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 {
|
if res {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
if Platform::get().debug.program {
|
if Platform::dbg().program {
|
||||||
for dev in &devs {
|
for dev in &devs {
|
||||||
eprintln!("{}", p.log(dev));
|
eprintln!("{}", p.log(dev));
|
||||||
}
|
}
|
||||||
|
|
@ -370,7 +370,7 @@ pub fn compile_program(
|
||||||
if res {
|
if res {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
if Platform::get().debug.program {
|
if Platform::dbg().program {
|
||||||
for dev in &devs {
|
for dev in &devs {
|
||||||
eprintln!("{}", p.log(dev));
|
eprintln!("{}", p.log(dev));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,15 @@ pub struct Platform {
|
||||||
dispatch: &'static cl_icd_dispatch,
|
dispatch: &'static cl_icd_dispatch,
|
||||||
pub extensions: [cl_name_version; 2],
|
pub extensions: [cl_name_version; 2],
|
||||||
pub devs: Vec<Arc<Device>>,
|
pub devs: Vec<Arc<Device>>,
|
||||||
pub debug: PlatformDebug,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PlatformDebug {
|
pub struct PlatformDebug {
|
||||||
pub program: bool,
|
pub program: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PLATFORM_ENV_ONCE: Once = Once::new();
|
||||||
static PLATFORM_ONCE: Once = Once::new();
|
static PLATFORM_ONCE: Once = Once::new();
|
||||||
|
|
||||||
static mut PLATFORM: Platform = Platform {
|
static mut PLATFORM: Platform = Platform {
|
||||||
dispatch: &DISPATCH,
|
dispatch: &DISPATCH,
|
||||||
extensions: [
|
extensions: [
|
||||||
|
|
@ -30,8 +31,20 @@ static mut PLATFORM: Platform = Platform {
|
||||||
mk_cl_version_ext(1, 0, 0, "cl_khr_il_program"),
|
mk_cl_version_ext(1, 0, 0, "cl_khr_il_program"),
|
||||||
],
|
],
|
||||||
devs: Vec::new(),
|
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 {
|
impl Platform {
|
||||||
pub fn as_ptr(&self) -> cl_platform_id {
|
pub fn as_ptr(&self) -> cl_platform_id {
|
||||||
|
|
@ -44,23 +57,21 @@ impl Platform {
|
||||||
unsafe { &PLATFORM }
|
unsafe { &PLATFORM }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn dbg() -> &'static PlatformDebug {
|
||||||
|
debug_assert!(PLATFORM_ENV_ONCE.is_completed());
|
||||||
|
unsafe { &PLATFORM_DBG }
|
||||||
|
}
|
||||||
|
|
||||||
fn init(&mut self) {
|
fn init(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
glsl_type_singleton_init_or_ref();
|
glsl_type_singleton_init_or_ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
self.devs.extend(Device::all());
|
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() {
|
pub fn init_once() {
|
||||||
|
PLATFORM_ENV_ONCE.call_once(load_env);
|
||||||
// SAFETY: no concurrent static mut access due to std::Once
|
// SAFETY: no concurrent static mut access due to std::Once
|
||||||
PLATFORM_ONCE.call_once(|| unsafe { PLATFORM.init() });
|
PLATFORM_ONCE.call_once(|| unsafe { PLATFORM.init() });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -569,7 +569,7 @@ impl Program {
|
||||||
let info = Self::dev_build_info(&mut lock, d);
|
let info = Self::dev_build_info(&mut lock, d);
|
||||||
assert_eq!(info.status, CL_BUILD_SUCCESS as cl_build_status);
|
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(
|
let nir = info.spirv.as_ref().unwrap().to_nir(
|
||||||
kernel,
|
kernel,
|
||||||
d.screen
|
d.screen
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue