rusticl/util: add Properties::iter()

Reviewed-by: @LingMan
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32268>
This commit is contained in:
Karol Herbst
2024-11-27 15:41:46 +01:00
committed by Marge Bot
parent da5cf9414e
commit b4b01498a6
5 changed files with 24 additions and 20 deletions
+13 -13
View File
@@ -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),
+5 -5
View File
@@ -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),
+1 -1
View File
@@ -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
+1 -1
View File
@@ -408,7 +408,7 @@ where
}
fn write_to(&self, out: &mut [MaybeUninit<T>]) {
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);
}
@@ -57,6 +57,10 @@ impl<T: Copy + Default> Properties<T> {
self.props.is_empty()
}
pub fn iter(&self) -> impl Iterator<Item = (&T, &T)> {
self.props.iter().map(|(k, v)| (k, v))
}
/// Returns the amount of key/value pairs available.
pub fn len(&self) -> usize {
self.props.len()