mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-04 22:49:13 +02:00
rusticl/icd: move get_ref_vec_from_arr into the Rusticl type
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27376>
This commit is contained in:
parent
46227bf44c
commit
7564b81749
2 changed files with 27 additions and 24 deletions
|
|
@ -286,28 +286,6 @@ pub trait ReferenceCountedAPIPointer<T, const ERR: i32> {
|
|||
Ok(res)
|
||||
}
|
||||
|
||||
fn get_ref_vec_from_arr<'a>(objs: *const Self, count: u32) -> CLResult<Vec<&'a T>>
|
||||
where
|
||||
Self: Sized + 'a,
|
||||
{
|
||||
// CL spec requires validation for obj arrays, both values have to make sense
|
||||
if objs.is_null() && count > 0 || !objs.is_null() && count == 0 {
|
||||
return Err(CL_INVALID_VALUE);
|
||||
}
|
||||
|
||||
let mut res = Vec::new();
|
||||
if objs.is_null() || count == 0 {
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
for i in 0..count as usize {
|
||||
unsafe {
|
||||
res.push((*objs.add(i)).get_ref()?);
|
||||
}
|
||||
}
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
fn retain(&self) -> CLResult<()> {
|
||||
unsafe {
|
||||
Arc::increment_strong_count(self.get_ptr()?);
|
||||
|
|
@ -327,6 +305,29 @@ pub trait ReferenceCountedAPIPointer<T, const ERR: i32> {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait CLObject<'a, const ERR: i32, CL: ReferenceCountedAPIPointer<Self, ERR> + 'a>:
|
||||
Sized
|
||||
{
|
||||
fn refs_from_arr(objs: *const CL, count: u32) -> CLResult<Vec<&'a Self>> {
|
||||
// CL spec requires validation for obj arrays, both values have to make sense
|
||||
if objs.is_null() && count > 0 || !objs.is_null() && count == 0 {
|
||||
return Err(CL_INVALID_VALUE);
|
||||
}
|
||||
|
||||
let mut res = Vec::new();
|
||||
if objs.is_null() || count == 0 {
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
for i in 0..count as usize {
|
||||
unsafe {
|
||||
res.push((*objs.add(i)).get_ref()?);
|
||||
}
|
||||
}
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_cl_type_trait {
|
||||
($cl: ident, $t: ident, $err: ident, $($field:ident).+) => {
|
||||
|
|
@ -360,6 +361,8 @@ macro_rules! impl_cl_type_trait {
|
|||
}
|
||||
}
|
||||
|
||||
impl $crate::api::icd::CLObject<'_, $err, $cl> for $t {}
|
||||
|
||||
// there are two reason to implement those traits for all objects
|
||||
// 1. it speeds up operations
|
||||
// 2. we want to check for real equality more explicit to stay conformant with the API
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ fn validate_devices<'a>(
|
|||
num_devices: cl_uint,
|
||||
default: &[&'a Device],
|
||||
) -> CLResult<Vec<&'a Device>> {
|
||||
let mut devs = cl_device_id::get_ref_vec_from_arr(device_list, num_devices)?;
|
||||
let mut devs = Device::refs_from_arr(device_list, num_devices)?;
|
||||
|
||||
// If device_list is a NULL value, the compile is performed for all devices associated with
|
||||
// program.
|
||||
|
|
@ -181,7 +181,7 @@ fn create_program_with_binary(
|
|||
binary_status: *mut cl_int,
|
||||
) -> CLResult<cl_program> {
|
||||
let c = context.get_arc()?;
|
||||
let devs = cl_device_id::get_ref_vec_from_arr(device_list, num_devices)?;
|
||||
let devs = Device::refs_from_arr(device_list, num_devices)?;
|
||||
|
||||
// CL_INVALID_VALUE if device_list is NULL or num_devices is zero.
|
||||
if devs.is_empty() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue