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>
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
}
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 }
}
}
}
}
+
+ 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 {