From d791135df117ba8d4730a97e0f6be547cff865a8 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Wed, 27 Nov 2024 14:24:39 +0100 Subject: [PATCH] rusticl/api: remove Option around Properties It already has the right semantics we are looking for. Reviewed-by: @LingMan Part-of: --- src/gallium/frontends/rusticl/api/memory.rs | 37 ++++++++------------ src/gallium/frontends/rusticl/api/queue.rs | 32 +++++++---------- src/gallium/frontends/rusticl/core/memory.rs | 4 +-- src/gallium/frontends/rusticl/core/queue.rs | 4 +-- 4 files changed, 32 insertions(+), 45 deletions(-) diff --git a/src/gallium/frontends/rusticl/api/memory.rs b/src/gallium/frontends/rusticl/api/memory.rs index 8b53376f86c..85859e0aec0 100644 --- a/src/gallium/frontends/rusticl/api/memory.rs +++ b/src/gallium/frontends/rusticl/api/memory.rs @@ -948,9 +948,7 @@ unsafe impl CLInfo for cl_sampler { CL_SAMPLER_FILTER_MODE => v.write::(sampler.filter_mode), CL_SAMPLER_NORMALIZED_COORDS => v.write::(sampler.normalized_coords), CL_SAMPLER_REFERENCE_COUNT => v.write::(Sampler::refcnt(*self)?), - CL_SAMPLER_PROPERTIES => { - v.write::>>(sampler.props.as_ref()) - } + CL_SAMPLER_PROPERTIES => v.write::<&Properties>(&sampler.props), // CL_INVALID_VALUE if param_name is not one of the supported values _ => Err(CL_INVALID_VALUE), } @@ -962,7 +960,7 @@ fn create_sampler_impl( normalized_coords: cl_bool, addressing_mode: cl_addressing_mode, filter_mode: cl_filter_mode, - props: Option>, + props: Properties, ) -> CLResult { let c = Context::arc_from_raw(context)?; @@ -1000,7 +998,7 @@ fn create_sampler( normalized_coords, addressing_mode, filter_mode, - None, + Properties::default(), ) } @@ -1014,24 +1012,19 @@ fn create_sampler_with_properties( let mut filter_mode = CL_FILTER_NEAREST; // CL_INVALID_VALUE if the same property name is specified more than once. - let sampler_properties = if sampler_properties.is_null() { - None - } else { - // SAFETY: sampler_properties is a 0 terminated array by spec. - let sampler_properties = - unsafe { Properties::from_ptr(sampler_properties) }.ok_or(CL_INVALID_VALUE)?; - for (&key, &val) in sampler_properties.iter() { - match key as u32 { - CL_SAMPLER_ADDRESSING_MODE => addressing_mode = val as u32, - CL_SAMPLER_FILTER_MODE => filter_mode = val as u32, - CL_SAMPLER_NORMALIZED_COORDS => normalized_coords = val as u32, - // CL_INVALID_VALUE if the property name in sampler_properties is not a supported - // property name - _ => return Err(CL_INVALID_VALUE), - } + // SAFETY: sampler_properties is a 0 terminated array by spec. + let sampler_properties = + unsafe { Properties::from_ptr(sampler_properties) }.ok_or(CL_INVALID_VALUE)?; + for (&key, &val) in sampler_properties.iter() { + match key as u32 { + CL_SAMPLER_ADDRESSING_MODE => addressing_mode = val as u32, + CL_SAMPLER_FILTER_MODE => filter_mode = val as u32, + CL_SAMPLER_NORMALIZED_COORDS => normalized_coords = val as u32, + // CL_INVALID_VALUE if the property name in sampler_properties is not a supported + // property name + _ => return Err(CL_INVALID_VALUE), } - Some(sampler_properties) - }; + } create_sampler_impl( context, diff --git a/src/gallium/frontends/rusticl/api/queue.rs b/src/gallium/frontends/rusticl/api/queue.rs index d2c35a5ca7d..3455fde742a 100644 --- a/src/gallium/frontends/rusticl/api/queue.rs +++ b/src/gallium/frontends/rusticl/api/queue.rs @@ -28,7 +28,7 @@ unsafe impl CLInfo for cl_command_queue { CL_QUEUE_DEVICE_DEFAULT => v.write::(ptr::null_mut()), CL_QUEUE_PROPERTIES => v.write::(queue.props), CL_QUEUE_PROPERTIES_ARRAY => { - v.write::>>(queue.props_v2.as_ref()) + v.write::<&Properties>(&queue.props_v2) } CL_QUEUE_REFERENCE_COUNT => v.write::(Queue::refcnt(*self)?), // clGetCommandQueueInfo, passing CL_QUEUE_SIZE Returns CL_INVALID_COMMAND_QUEUE since @@ -88,7 +88,7 @@ pub fn create_command_queue_impl( context: cl_context, device: cl_device_id, properties: cl_command_queue_properties, - properties_v2: Option>, + properties_v2: Properties, ) -> CLResult { let c = Context::arc_from_raw(context)?; let d = Device::ref_from_raw(device)? @@ -119,7 +119,7 @@ fn create_command_queue( device: cl_device_id, properties: cl_command_queue_properties, ) -> CLResult { - create_command_queue_impl(context, device, properties, None) + create_command_queue_impl(context, device, properties, Properties::default()) } #[cl_entrypoint(clCreateCommandQueueWithProperties)] @@ -129,24 +129,18 @@ fn create_command_queue_with_properties( properties: *const cl_queue_properties, ) -> CLResult { let mut queue_properties = cl_command_queue_properties::default(); - let properties = if properties.is_null() { - None - } else { - // SAFETY: properties is a 0 terminated array by spec. - let properties = unsafe { Properties::from_ptr(properties) }.ok_or(CL_INVALID_PROPERTY)?; - for (k, v) in properties.iter() { - match *k as cl_uint { - CL_QUEUE_PROPERTIES => queue_properties = *v, - // CL_INVALID_QUEUE_PROPERTIES if values specified in properties are valid but are not - // supported by the device. - CL_QUEUE_SIZE => return Err(CL_INVALID_QUEUE_PROPERTIES), - _ => return Err(CL_INVALID_PROPERTY), - } + // SAFETY: properties is a 0 terminated array by spec. + let properties = unsafe { Properties::from_ptr(properties) }.ok_or(CL_INVALID_PROPERTY)?; + for (k, v) in properties.iter() { + match *k as cl_uint { + CL_QUEUE_PROPERTIES => queue_properties = *v, + // CL_INVALID_QUEUE_PROPERTIES if values specified in properties are valid but are not + // supported by the device. + CL_QUEUE_SIZE => return Err(CL_INVALID_QUEUE_PROPERTIES), + _ => return Err(CL_INVALID_PROPERTY), } - - Some(properties) - }; + } create_command_queue_impl(context, device, queue_properties, properties) } diff --git a/src/gallium/frontends/rusticl/core/memory.rs b/src/gallium/frontends/rusticl/core/memory.rs index 0455733860e..582e2fada6e 100644 --- a/src/gallium/frontends/rusticl/core/memory.rs +++ b/src/gallium/frontends/rusticl/core/memory.rs @@ -1615,7 +1615,7 @@ pub struct Sampler { pub normalized_coords: bool, pub addressing_mode: cl_addressing_mode, pub filter_mode: cl_filter_mode, - pub props: Option>, + pub props: Properties, } impl_cl_type_trait!(cl_sampler, Sampler, CL_INVALID_SAMPLER); @@ -1626,7 +1626,7 @@ impl Sampler { normalized_coords: bool, addressing_mode: cl_addressing_mode, filter_mode: cl_filter_mode, - props: Option>, + props: Properties, ) -> Arc { Arc::new(Self { base: CLObjectBase::new(RusticlTypes::Sampler), diff --git a/src/gallium/frontends/rusticl/core/queue.rs b/src/gallium/frontends/rusticl/core/queue.rs index af59d113016..ed239aa90e5 100644 --- a/src/gallium/frontends/rusticl/core/queue.rs +++ b/src/gallium/frontends/rusticl/core/queue.rs @@ -86,7 +86,7 @@ pub struct Queue { pub context: Arc, pub device: &'static Device, pub props: cl_command_queue_properties, - pub props_v2: Option>, + pub props_v2: Properties, state: Mutex, _thrd: JoinHandle<()>, } @@ -105,7 +105,7 @@ impl Queue { context: Arc, device: &'static Device, props: cl_command_queue_properties, - props_v2: Option>, + props_v2: Properties, ) -> CLResult> { // we assume that memory allocation is the only possible failure. Any other failure reason // should be detected earlier (e.g.: checking for CAPs).