rusticl/api: use Properties for 0 terminated arrays consistently

Now that the semantics of Properties match exactly what we need here,
let's use it for all queries with 0 terminated arrays.

Reviewed-by: @LingMan
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32268>
This commit is contained in:
Karol Herbst 2024-11-27 14:15:35 +01:00 committed by Marge Bot
parent 976dd83a7a
commit 86453fe053
3 changed files with 16 additions and 33 deletions

View file

@ -241,7 +241,7 @@ unsafe impl CLInfo<cl_mem_info> for cl_mem {
} else {
0
}),
CL_MEM_PROPERTIES => v.write::<&[cl_mem_properties]>(&mem.props),
CL_MEM_PROPERTIES => v.write::<&Properties<cl_mem_properties>>(&mem.props),
CL_MEM_REFERENCE_COUNT => v.write::<cl_uint>(if mem.is_buffer() {
Buffer::refcnt(*self)?
} else {
@ -295,12 +295,14 @@ fn create_buffer_with_properties(
}
}
let props = Properties::from_ptr_raw(properties);
// CL_INVALID_PROPERTY [...] if the same property name is specified more than once.
let props = Properties::from_ptr(properties).ok_or(CL_INVALID_PROPERTY)?;
// CL_INVALID_PROPERTY if a property name in properties is not a supported property name, if
// the value specified for a supported property name is not valid, or if the same property name
// is specified more than once.
if props.len() > 1 {
// we don't support any properties besides the 0 property
if !props.is_empty() {
// we don't support any properties
return Err(CL_INVALID_PROPERTY);
}
@ -798,12 +800,14 @@ fn create_image_with_properties(
.find(|f| *f & filtered_flags == filtered_flags)
.ok_or(CL_IMAGE_FORMAT_NOT_SUPPORTED)?;
let props = Properties::from_ptr_raw(properties);
// CL_INVALID_PROPERTY [...] if the same property name is specified more than once.
let props = Properties::from_ptr(properties).ok_or(CL_INVALID_PROPERTY)?;
// CL_INVALID_PROPERTY if a property name in properties is not a supported property name, if
// the value specified for a supported property name is not valid, or if the same property name
// is specified more than once.
if props.len() > 1 {
// we don't support any properties besides the 0 property
if !props.is_empty() {
// we don't support any properties
return Err(CL_INVALID_PROPERTY);
}

View file

@ -204,7 +204,7 @@ pub struct MemBase {
// it's a bit hacky, but storing the pointer as `usize` gives us `Send` and `Sync`. The
// application is required to ensure no data races exist on the memory anyway.
pub host_ptr: usize,
pub props: Vec<cl_mem_properties>,
pub props: Properties<cl_mem_properties>,
pub cbs: Mutex<Vec<MemCB>>,
pub gl_obj: Option<GLObject>,
res: Option<HashMap<&'static Device, Arc<PipeResource>>>,
@ -396,7 +396,7 @@ impl MemBase {
flags: cl_mem_flags,
size: usize,
host_ptr: *mut c_void,
props: Vec<cl_mem_properties>,
props: Properties<cl_mem_properties>,
) -> CLResult<Arc<Buffer>> {
let res_type = if bit_check(flags, CL_MEM_ALLOC_HOST_PTR) {
ResourceType::Staging
@ -457,7 +457,7 @@ impl MemBase {
flags: flags,
size: size,
host_ptr: host_ptr,
props: Vec::new(),
props: Properties::default(),
gl_obj: None,
cbs: Mutex::new(Vec::new()),
res: None,
@ -476,7 +476,7 @@ impl MemBase {
mut image_desc: cl_image_desc,
image_elem_size: u8,
host_ptr: *mut c_void,
props: Vec<cl_mem_properties>,
props: Properties<cl_mem_properties>,
) -> CLResult<Arc<Image>> {
// we have to sanitize the image_desc a little for internal use
let api_image_desc = image_desc;
@ -641,7 +641,7 @@ impl MemBase {
flags: flags,
size: gl_mem_props.size(),
host_ptr: 0,
props: Vec::new(),
props: Properties::default(),
gl_obj: Some(GLObject {
gl_object_target: gl_export_manager.export_in.target,
gl_object_type: gl_object_type,

View file

@ -5,27 +5,6 @@ pub struct Properties<T> {
/// This encapsulates a C property array, where the list is 0 terminated.
impl<T> Properties<T> {
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn from_ptr_raw(mut p: *const T) -> Vec<T>
where
T: Copy + Default + PartialEq,
{
let mut res: Vec<T> = Vec::new();
if !p.is_null() {
unsafe {
while *p != T::default() {
res.push(*p);
res.push(*p.add(1));
p = p.add(2);
}
}
res.push(T::default());
}
res
}
/// Creates a Properties object copying from the supplied pointer.
///
/// It returns `None` if any property is found twice.