mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-28 06:00:10 +01:00
rusticl/icd: move refcnt() and get rid of needless atomic ops
The old impl used `get_arc` which internally calls into `Arc::increment_strong_count` in order to protect against Arc::drop deallocating our objects. We could also just not do that :) Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27376>
This commit is contained in:
parent
7564b81749
commit
45b9fdb4e5
7 changed files with 17 additions and 11 deletions
|
|
@ -34,7 +34,7 @@ impl CLInfo<cl_context_info> for cl_context {
|
|||
),
|
||||
CL_CONTEXT_NUM_DEVICES => cl_prop::<cl_uint>(ctx.devs.len() as u32),
|
||||
CL_CONTEXT_PROPERTIES => cl_prop::<&Properties<cl_context_properties>>(&ctx.properties),
|
||||
CL_CONTEXT_REFERENCE_COUNT => cl_prop::<cl_uint>(self.refcnt()?),
|
||||
CL_CONTEXT_REFERENCE_COUNT => cl_prop::<cl_uint>(Context::refcnt(*self)?),
|
||||
// CL_INVALID_VALUE if param_name is not one of the supported values
|
||||
_ => return Err(CL_INVALID_VALUE),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ impl CLInfo<cl_event_info> for cl_event {
|
|||
};
|
||||
cl_prop::<cl_command_queue>(cl_command_queue::from_ptr(ptr))
|
||||
}
|
||||
CL_EVENT_REFERENCE_COUNT => cl_prop::<cl_uint>(self.refcnt()?),
|
||||
CL_EVENT_REFERENCE_COUNT => cl_prop::<cl_uint>(Event::refcnt(*self)?),
|
||||
CL_EVENT_COMMAND_TYPE => cl_prop::<cl_command_type>(event.cmd_type),
|
||||
_ => return Err(CL_INVALID_VALUE),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -299,15 +299,21 @@ pub trait ReferenceCountedAPIPointer<T, const ERR: i32> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn refcnt(&self) -> CLResult<u32> {
|
||||
Ok((Arc::strong_count(&self.get_arc()?) - 1) as u32)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait CLObject<'a, const ERR: i32, CL: ReferenceCountedAPIPointer<Self, ERR> + 'a>:
|
||||
Sized
|
||||
{
|
||||
fn refcnt(ptr: CL) -> CLResult<u32> {
|
||||
let ptr = ptr.get_ptr()?;
|
||||
// SAFETY: `get_ptr` already checks if it's one of our pointers.
|
||||
let arc = unsafe { Arc::from_raw(ptr) };
|
||||
let res = Arc::strong_count(&arc);
|
||||
// leak the arc again, so we don't reduce the refcount by dropping `arc`
|
||||
let _ = Arc::into_raw(arc);
|
||||
Ok(res as u32)
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ impl CLInfo<cl_kernel_info> for cl_kernel {
|
|||
let ptr = Arc::as_ptr(&kernel.prog);
|
||||
cl_prop::<cl_program>(cl_program::from_ptr(ptr))
|
||||
}
|
||||
CL_KERNEL_REFERENCE_COUNT => cl_prop::<cl_uint>(self.refcnt()?),
|
||||
CL_KERNEL_REFERENCE_COUNT => cl_prop::<cl_uint>(Kernel::refcnt(*self)?),
|
||||
// CL_INVALID_VALUE if param_name is not one of the supported values
|
||||
_ => return Err(CL_INVALID_VALUE),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ impl CLInfo<cl_mem_info> for cl_mem {
|
|||
CL_MEM_HOST_PTR => cl_prop::<*mut c_void>(mem.host_ptr),
|
||||
CL_MEM_OFFSET => cl_prop::<usize>(mem.offset),
|
||||
CL_MEM_PROPERTIES => cl_prop::<&Vec<cl_mem_properties>>(&mem.props),
|
||||
CL_MEM_REFERENCE_COUNT => cl_prop::<cl_uint>(self.refcnt()?),
|
||||
CL_MEM_REFERENCE_COUNT => cl_prop::<cl_uint>(Mem::refcnt(*self)?),
|
||||
CL_MEM_SIZE => cl_prop::<usize>(mem.size),
|
||||
CL_MEM_TYPE => cl_prop::<cl_mem_object_type>(mem.mem_type),
|
||||
CL_MEM_USES_SVM_POINTER | CL_MEM_USES_SVM_POINTER_ARM => {
|
||||
|
|
@ -908,7 +908,7 @@ impl CLInfo<cl_sampler_info> for cl_sampler {
|
|||
}
|
||||
CL_SAMPLER_FILTER_MODE => cl_prop::<cl_filter_mode>(sampler.filter_mode),
|
||||
CL_SAMPLER_NORMALIZED_COORDS => cl_prop::<bool>(sampler.normalized_coords),
|
||||
CL_SAMPLER_REFERENCE_COUNT => cl_prop::<cl_uint>(self.refcnt()?),
|
||||
CL_SAMPLER_REFERENCE_COUNT => cl_prop::<cl_uint>(Sampler::refcnt(*self)?),
|
||||
CL_SAMPLER_PROPERTIES => {
|
||||
cl_prop::<&Option<Properties<cl_sampler_properties>>>(&sampler.props)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ impl CLInfo<cl_program_info> for cl_program {
|
|||
CL_PROGRAM_KERNEL_NAMES => cl_prop::<&str>(&*prog.kernels().join(";")),
|
||||
CL_PROGRAM_NUM_DEVICES => cl_prop::<cl_uint>(prog.devs.len() as cl_uint),
|
||||
CL_PROGRAM_NUM_KERNELS => cl_prop::<usize>(prog.kernels().len()),
|
||||
CL_PROGRAM_REFERENCE_COUNT => cl_prop::<cl_uint>(self.refcnt()?),
|
||||
CL_PROGRAM_REFERENCE_COUNT => cl_prop::<cl_uint>(Program::refcnt(*self)?),
|
||||
CL_PROGRAM_SCOPE_GLOBAL_CTORS_PRESENT => cl_prop::<cl_bool>(CL_FALSE),
|
||||
CL_PROGRAM_SCOPE_GLOBAL_DTORS_PRESENT => cl_prop::<cl_bool>(CL_FALSE),
|
||||
CL_PROGRAM_SOURCE => match &prog.src {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ impl CLInfo<cl_command_queue_info> for cl_command_queue {
|
|||
CL_QUEUE_PROPERTIES_ARRAY => {
|
||||
cl_prop::<&Option<Properties<cl_queue_properties>>>(&queue.props_v2)
|
||||
}
|
||||
CL_QUEUE_REFERENCE_COUNT => cl_prop::<cl_uint>(self.refcnt()?),
|
||||
CL_QUEUE_REFERENCE_COUNT => cl_prop::<cl_uint>(Queue::refcnt(*self)?),
|
||||
// clGetCommandQueueInfo, passing CL_QUEUE_SIZE Returns CL_INVALID_COMMAND_QUEUE since
|
||||
// command_queue cannot be a valid device command-queue.
|
||||
CL_QUEUE_SIZE => return Err(CL_INVALID_COMMAND_QUEUE),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue