rusticl/platform: make the initialization more explicit

It's not a lazy loaded type so doing the Once::call_once in every
Platform::get gives us a pointless atomic, which might be slow on some
platforms.

Every application has to call clGetPlatformIDs so we only need to do it
there.

Signed-off-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22649>
This commit is contained in:
Karol Herbst
2023-04-24 13:01:42 +02:00
committed by Marge Bot
parent 400847a990
commit 2283e9d155
2 changed files with 9 additions and 2 deletions
@@ -44,6 +44,9 @@ pub fn get_platform_ids(
return Err(CL_INVALID_VALUE);
}
// run initialization code once
Platform::init_once();
// platforms returns a list of OpenCL platforms available for access through the Khronos ICD Loader.
// The cl_platform_id values returned in platforms are ICD compatible and can be used to identify a
// specific OpenCL platform. If the platforms argument is NULL, then this argument is ignored. The
@@ -39,8 +39,7 @@ impl Platform {
}
pub fn get() -> &'static Self {
// SAFETY: no concurrent static mut access due to std::Once
PLATFORM_ONCE.call_once(|| unsafe { PLATFORM.init() });
debug_assert!(PLATFORM_ONCE.is_completed());
// SAFETY: no mut references exist at this point
unsafe { &PLATFORM }
}
@@ -60,6 +59,11 @@ impl Platform {
}
}
}
pub fn init_once() {
// SAFETY: no concurrent static mut access due to std::Once
PLATFORM_ONCE.call_once(|| unsafe { PLATFORM.init() });
}
}
impl Drop for Platform {