From 53025688bba0d4b96fae39bdfc32f7ba64055739 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Tue, 4 Apr 2023 02:38:31 +0200 Subject: [PATCH] rusticl/platform: move getter into the type Signed-off-by: Karol Herbst Part-of: --- src/gallium/frontends/rusticl/api/device.rs | 2 +- src/gallium/frontends/rusticl/api/platform.rs | 2 +- src/gallium/frontends/rusticl/core/platform.rs | 14 ++++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/gallium/frontends/rusticl/api/device.rs b/src/gallium/frontends/rusticl/api/device.rs index 8a077f3..6eaa1b8 100644 --- a/src/gallium/frontends/rusticl/api/device.rs +++ b/src/gallium/frontends/rusticl/api/device.rs @@ -143,7 +143,7 @@ impl CLInfo for cl_device_id { CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS => cl_prop::(0), CL_DEVICE_PIPE_MAX_PACKET_SIZE => cl_prop::(0), CL_DEVICE_PIPE_SUPPORT => cl_prop::(false), - CL_DEVICE_PLATFORM => cl_prop::(get_platform()), + CL_DEVICE_PLATFORM => cl_prop::(Platform::get().as_ptr()), CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT => cl_prop::(0), CL_DEVICE_PREFERRED_INTEROP_USER_SYNC => cl_prop::(true), CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT => cl_prop::(0), diff --git a/src/gallium/frontends/rusticl/api/platform.rs b/src/gallium/frontends/rusticl/api/platform.rs index 4fff3e7..dc448e0 100644 --- a/src/gallium/frontends/rusticl/api/platform.rs +++ b/src/gallium/frontends/rusticl/api/platform.rs @@ -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. diff --git a/src/gallium/frontends/rusticl/core/platform.rs b/src/gallium/frontends/rusticl/core/platform.rs index b4d566e..4dc2c64 100644 --- a/src/gallium/frontends/rusticl/core/platform.rs +++ b/src/gallium/frontends/rusticl/core/platform.rs @@ -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) } -- 2.7.4