mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 00:58:05 +02:00
rusticl/platform: move device initialization to the platform
Signed-off-by: Karol Herbst <kherbst@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22280>
This commit is contained in:
parent
53025688bb
commit
22808d542b
2 changed files with 30 additions and 18 deletions
|
|
@ -13,7 +13,6 @@ use std::ffi::CStr;
|
|||
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] = [
|
||||
|
|
@ -196,22 +195,8 @@ impl CLInfo<cl_device_info> for cl_device_id {
|
|||
}
|
||||
}
|
||||
|
||||
// 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>> {
|
||||
|
|
|
|||
|
|
@ -1,21 +1,29 @@
|
|||
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 {
|
||||
|
|
@ -24,7 +32,26 @@ 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue