Module: Mesa Branch: main Commit: 2283e9d155c6ed665d667dbd2e69477eace11162 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=2283e9d155c6ed665d667dbd2e69477eace11162
Author: Karol Herbst <[email protected]> Date: Mon Apr 24 13:01:42 2023 +0200 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 <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22649> --- src/gallium/frontends/rusticl/api/platform.rs | 3 +++ src/gallium/frontends/rusticl/core/platform.rs | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gallium/frontends/rusticl/api/platform.rs b/src/gallium/frontends/rusticl/api/platform.rs index dc448e01b6b..7641ff33279 100644 --- a/src/gallium/frontends/rusticl/api/platform.rs +++ b/src/gallium/frontends/rusticl/api/platform.rs @@ -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 diff --git a/src/gallium/frontends/rusticl/core/platform.rs b/src/gallium/frontends/rusticl/core/platform.rs index 41e77a15239..0a3e22e8af5 100644 --- a/src/gallium/frontends/rusticl/core/platform.rs +++ b/src/gallium/frontends/rusticl/core/platform.rs @@ -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 {
