rusticl/platform: move getter into the type
authorKarol Herbst <kherbst@redhat.com>
Tue, 4 Apr 2023 00:38:31 +0000 (02:38 +0200)
committerMarge Bot <emma+marge@anholt.net>
Thu, 13 Apr 2023 02:54:21 +0000 (02:54 +0000)
Signed-off-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22280>

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

index 8a077f3..6eaa1b8 100644 (file)
@@ -143,7 +143,7 @@ impl CLInfo<cl_device_info> for cl_device_id {
             CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS => cl_prop::<cl_uint>(0),
             CL_DEVICE_PIPE_MAX_PACKET_SIZE => cl_prop::<cl_uint>(0),
             CL_DEVICE_PIPE_SUPPORT => cl_prop::<bool>(false),
-            CL_DEVICE_PLATFORM => cl_prop::<cl_platform_id>(get_platform()),
+            CL_DEVICE_PLATFORM => cl_prop::<cl_platform_id>(Platform::get().as_ptr()),
             CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT => cl_prop::<cl_uint>(0),
             CL_DEVICE_PREFERRED_INTEROP_USER_SYNC => cl_prop::<bool>(true),
             CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT => cl_prop::<cl_uint>(0),
index 4fff3e7..dc448e0 100644 (file)
@@ -49,7 +49,7 @@ pub fn get_platform_ids(
     // specific OpenCL platform. If the platforms argument is NULL, then this argument is ignored. The
     // number of OpenCL platforms returned is the minimum of the value specified by num_entries or the
     // number of OpenCL platforms available.
-    platforms.write_checked(get_platform());
+    platforms.write_checked(Platform::get().as_ptr());
 
     // num_platforms returns the number of OpenCL platforms available. If num_platforms is NULL, then
     // this argument is ignored.
index b4d566e..4dc2c64 100644 (file)
@@ -18,8 +18,14 @@ static PLATFORM: Platform = Platform {
     ],
 };
 
-pub fn get_platform() -> cl_platform_id {
-    &PLATFORM as *const Platform as *mut _cl_platform_id
+impl Platform {
+    pub fn as_ptr(&self) -> cl_platform_id {
+        (self as *const Self) as cl_platform_id
+    }
+
+    pub fn get() -> &'static Self {
+        &PLATFORM
+    }
 }
 
 pub trait GetPlatformRef {
@@ -28,8 +34,8 @@ pub trait GetPlatformRef {
 
 impl GetPlatformRef for cl_platform_id {
     fn get_ref(&self) -> CLResult<&'static Platform> {
-        if !self.is_null() && *self == get_platform() {
-            Ok(&PLATFORM)
+        if !self.is_null() && *self == Platform::get().as_ptr() {
+            Ok(Platform::get())
         } else {
             Err(CL_INVALID_PLATFORM)
         }