rusticl/platform: make the initialization more explicit
authorKarol Herbst <kherbst@redhat.com>
Mon, 24 Apr 2023 11:01:42 +0000 (13:01 +0200)
committerMarge Bot <emma+marge@anholt.net>
Tue, 25 Apr 2023 04:27:57 +0000 (04:27 +0000)
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>

src/gallium/frontends/rusticl/api/platform.rs
src/gallium/frontends/rusticl/core/platform.rs

index dc448e0..7641ff3 100644 (file)
@@ -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
index 41e77a1..0a3e22e 100644 (file)
@@ -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 {