From b4b01498a67bf5386e457d5bf7d5a31b255f553f Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Wed, 27 Nov 2024 15:41:46 +0100 Subject: [PATCH] rusticl/util: add Properties::iter() Reviewed-by: @LingMan Part-of: --- src/gallium/frontends/rusticl/api/context.rs | 26 +++++++++---------- src/gallium/frontends/rusticl/api/memory.rs | 10 +++---- src/gallium/frontends/rusticl/api/queue.rs | 2 +- src/gallium/frontends/rusticl/api/util.rs | 2 +- .../frontends/rusticl/util/properties.rs | 4 +++ 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/gallium/frontends/rusticl/api/context.rs b/src/gallium/frontends/rusticl/api/context.rs index cd5349608e8..11fc50453e8 100644 --- a/src/gallium/frontends/rusticl/api/context.rs +++ b/src/gallium/frontends/rusticl/api/context.rs @@ -78,20 +78,20 @@ pub fn get_gl_context_info_khr( // CL_INVALID_PROPERTY [...] if the same property name is specified more than once. let props = Properties::from_ptr(properties).ok_or(CL_INVALID_PROPERTY)?; - for p in &props.props { - match p.0 as u32 { + for (&key, &val) in props.iter() { + match key as u32 { // CL_INVALID_PLATFORM [...] if platform value specified in properties is not a valid platform. CL_CONTEXT_PLATFORM => { - (p.1 as cl_platform_id).get_ref()?; + (val as cl_platform_id).get_ref()?; } CL_EGL_DISPLAY_KHR => { - egl_display = p.1 as *mut _; + egl_display = val as *mut _; } CL_GL_CONTEXT_KHR => { - gl_context = p.1 as *mut _; + gl_context = val as *mut _; } CL_GLX_DISPLAY_KHR => { - glx_display = p.1 as *mut _; + glx_display = val as *mut _; } // CL_INVALID_PROPERTY if context property name in properties is not a supported property name _ => return Err(CL_INVALID_PROPERTY), @@ -140,23 +140,23 @@ fn create_context( // CL_INVALID_PROPERTY [...] if the same property name is specified more than once. let props = Properties::from_ptr(properties).ok_or(CL_INVALID_PROPERTY)?; - for p in &props.props { - match p.0 as u32 { + for (&key, &val) in props.iter() { + match key as u32 { // CL_INVALID_PLATFORM [...] if platform value specified in properties is not a valid platform. CL_CONTEXT_PLATFORM => { - (p.1 as cl_platform_id).get_ref()?; + (val as cl_platform_id).get_ref()?; } CL_CONTEXT_INTEROP_USER_SYNC => { - check_cl_bool(p.1).ok_or(CL_INVALID_PROPERTY)?; + check_cl_bool(val).ok_or(CL_INVALID_PROPERTY)?; } CL_EGL_DISPLAY_KHR => { - egl_display = p.1 as *mut _; + egl_display = val as *mut _; } CL_GL_CONTEXT_KHR => { - gl_context = p.1 as *mut _; + gl_context = val as *mut _; } CL_GLX_DISPLAY_KHR => { - glx_display = p.1 as *mut _; + glx_display = val as *mut _; } // CL_INVALID_PROPERTY if context property name in properties is not a supported property name _ => return Err(CL_INVALID_PROPERTY), diff --git a/src/gallium/frontends/rusticl/api/memory.rs b/src/gallium/frontends/rusticl/api/memory.rs index ffddce54ccb..ee15d1e7b0f 100644 --- a/src/gallium/frontends/rusticl/api/memory.rs +++ b/src/gallium/frontends/rusticl/api/memory.rs @@ -1015,11 +1015,11 @@ fn create_sampler_with_properties( } else { let sampler_properties = Properties::from_ptr(sampler_properties).ok_or(CL_INVALID_VALUE)?; - for p in &sampler_properties.props { - match p.0 as u32 { - CL_SAMPLER_ADDRESSING_MODE => addressing_mode = p.1 as u32, - CL_SAMPLER_FILTER_MODE => filter_mode = p.1 as u32, - CL_SAMPLER_NORMALIZED_COORDS => normalized_coords = p.1 as u32, + 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), diff --git a/src/gallium/frontends/rusticl/api/queue.rs b/src/gallium/frontends/rusticl/api/queue.rs index 929f877336a..c410b07ec5a 100644 --- a/src/gallium/frontends/rusticl/api/queue.rs +++ b/src/gallium/frontends/rusticl/api/queue.rs @@ -134,7 +134,7 @@ fn create_command_queue_with_properties( } else { let properties = Properties::from_ptr(properties).ok_or(CL_INVALID_PROPERTY)?; - for (k, v) in &properties.props { + 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 diff --git a/src/gallium/frontends/rusticl/api/util.rs b/src/gallium/frontends/rusticl/api/util.rs index a490df7ed3a..237ba1294fb 100644 --- a/src/gallium/frontends/rusticl/api/util.rs +++ b/src/gallium/frontends/rusticl/api/util.rs @@ -408,7 +408,7 @@ where } fn write_to(&self, out: &mut [MaybeUninit]) { - for (idx, (k, v)) in self.props.iter().enumerate() { + for (idx, (k, v)) in self.iter().enumerate() { out[idx * 2].write(*k); out[idx * 2 + 1].write(*v); } diff --git a/src/gallium/frontends/rusticl/util/properties.rs b/src/gallium/frontends/rusticl/util/properties.rs index 044eb77872a..c579613c0f6 100644 --- a/src/gallium/frontends/rusticl/util/properties.rs +++ b/src/gallium/frontends/rusticl/util/properties.rs @@ -57,6 +57,10 @@ impl Properties { self.props.is_empty() } + pub fn iter(&self) -> impl Iterator { + self.props.iter().map(|(k, v)| (k, v)) + } + /// Returns the amount of key/value pairs available. pub fn len(&self) -> usize { self.props.len()