use std::mem::size_of;
use std::ptr;
use std::sync::Arc;
-use std::sync::Once;
const SPIRV_SUPPORT_STRING: &str = "SPIR-V_1.0 SPIR-V_1.1 SPIR-V_1.2 SPIR-V_1.3 SPIR-V_1.4";
const SPIRV_SUPPORT: [cl_name_version; 5] = [
}
}
-// TODO replace with const new container
-static mut DEVICES: Vec<Arc<Device>> = Vec::new();
-static INIT: Once = Once::new();
-
-fn load_devices() {
- unsafe {
- glsl_type_singleton_init_or_ref();
- }
- Device::all()
- .into_iter()
- .for_each(|d| unsafe { DEVICES.push(d) });
-}
-
fn devs() -> &'static Vec<Arc<Device>> {
- INIT.call_once(load_devices);
- unsafe { &DEVICES }
+ &Platform::get().devs
}
pub fn get_devs_for_type(device_type: cl_device_type) -> Vec<&'static Arc<Device>> {
use crate::api::icd::CLResult;
use crate::api::icd::DISPATCH;
+use crate::core::device::*;
use crate::core::version::*;
+use mesa_rust_gen::*;
use rusticl_opencl_gen::*;
+use std::sync::Arc;
+use std::sync::Once;
+
#[repr(C)]
pub struct Platform {
dispatch: &'static cl_icd_dispatch,
pub extensions: [cl_name_version; 2],
+ pub devs: Vec<Arc<Device>>,
}
-static PLATFORM: Platform = Platform {
+static PLATFORM_ONCE: Once = Once::new();
+static mut PLATFORM: Platform = Platform {
dispatch: &DISPATCH,
extensions: [
mk_cl_version_ext(1, 0, 0, "cl_khr_icd"),
mk_cl_version_ext(1, 0, 0, "cl_khr_il_program"),
],
+ devs: Vec::new(),
};
impl Platform {
}
pub fn get() -> &'static Self {
- &PLATFORM
+ // SAFETY: no concurrent static mut access due to std::Once
+ PLATFORM_ONCE.call_once(|| unsafe { PLATFORM.init() });
+ // SAFETY: no mut references exist at this point
+ unsafe { &PLATFORM }
+ }
+
+ fn init(&mut self) {
+ unsafe {
+ glsl_type_singleton_init_or_ref();
+ }
+
+ self.devs.extend(Device::all());
+ }
+}
+
+impl Drop for Platform {
+ fn drop(&mut self) {
+ unsafe {
+ glsl_type_singleton_decref();
+ }
}
}