diff --git a/src/gallium/frontends/rusticl/api/context.rs b/src/gallium/frontends/rusticl/api/context.rs index c15054018e7..4ee018baf00 100644 --- a/src/gallium/frontends/rusticl/api/context.rs +++ b/src/gallium/frontends/rusticl/api/context.rs @@ -193,11 +193,7 @@ fn create_context( } } - Ok(cl_context::from_arc(Context::new( - devs, - props, - gl_ctx_manager, - ))) + Ok(Context::new(devs, props, gl_ctx_manager).into_cl()) } #[cl_entrypoint] diff --git a/src/gallium/frontends/rusticl/api/event.rs b/src/gallium/frontends/rusticl/api/event.rs index 19373d7aa0b..691992f7ce9 100644 --- a/src/gallium/frontends/rusticl/api/event.rs +++ b/src/gallium/frontends/rusticl/api/event.rs @@ -63,7 +63,7 @@ impl CLInfo for cl_event { #[cl_entrypoint] fn create_user_event(context: cl_context) -> CLResult { let c = context.get_arc()?; - Ok(cl_event::from_arc(Event::new_user(c))) + Ok(Event::new_user(c).into_cl()) } #[cl_entrypoint] @@ -165,7 +165,7 @@ pub fn create_and_queue( if !event.is_null() { // SAFETY: we check for null and valid API use is to pass in a valid pointer unsafe { - event.write(cl_event::from_arc(Arc::clone(&e))); + event.write(Arc::clone(&e).into_cl()); } } q.queue(e); diff --git a/src/gallium/frontends/rusticl/api/icd.rs b/src/gallium/frontends/rusticl/api/icd.rs index 3bc944d213e..db7c8b5b318 100644 --- a/src/gallium/frontends/rusticl/api/icd.rs +++ b/src/gallium/frontends/rusticl/api/icd.rs @@ -241,13 +241,6 @@ pub trait ReferenceCountedAPIPointer { Ok(Arc::from_raw(ptr)) } } - - fn from_arc(arc: Arc) -> Self - where - Self: Sized, - { - Self::from_ptr(Arc::into_raw(arc)) - } } pub trait CLObject<'a, const ERR: i32, CL: ReferenceCountedAPIPointer + 'a>: @@ -321,6 +314,10 @@ pub trait CLObject<'a, const ERR: i32, CL: ReferenceCountedAPIPointer unsafe { Arc::increment_strong_count(ptr) }; Ok(()) } + + fn into_cl(self: Arc) -> CL { + CL::from_ptr(Arc::into_raw(self)) + } } #[macro_export] diff --git a/src/gallium/frontends/rusticl/api/kernel.rs b/src/gallium/frontends/rusticl/api/kernel.rs index 48e4b7eb65f..96180a8f218 100644 --- a/src/gallium/frontends/rusticl/api/kernel.rs +++ b/src/gallium/frontends/rusticl/api/kernel.rs @@ -263,7 +263,7 @@ fn create_kernel( return Err(CL_INVALID_KERNEL_DEFINITION); } - Ok(cl_kernel::from_arc(Kernel::new(name, p))) + Ok(Kernel::new(name, p).into_cl()) } #[cl_entrypoint] @@ -311,7 +311,7 @@ fn create_kernels_in_program( unsafe { kernels .add(num_kernels as usize) - .write(cl_kernel::from_arc(Kernel::new(name, p.clone()))); + .write(Kernel::new(name, p.clone()).into_cl()); } } num_kernels += 1; @@ -645,5 +645,5 @@ fn enqueue_task( #[cl_entrypoint] fn clone_kernel(source_kernel: cl_kernel) -> CLResult { let k = Kernel::ref_from_raw(source_kernel)?; - Ok(cl_kernel::from_arc(Arc::new(k.clone()))) + Ok(Arc::new(k.clone()).into_cl()) } diff --git a/src/gallium/frontends/rusticl/api/memory.rs b/src/gallium/frontends/rusticl/api/memory.rs index 7f00f489aea..492fd44c564 100644 --- a/src/gallium/frontends/rusticl/api/memory.rs +++ b/src/gallium/frontends/rusticl/api/memory.rs @@ -280,9 +280,7 @@ fn create_buffer_with_properties( return Err(CL_INVALID_PROPERTY); } - Ok(cl_mem::from_arc(Mem::new_buffer( - c, flags, size, host_ptr, props, - )?)) + Ok(Mem::new_buffer(c, flags, size, host_ptr, props)?.into_cl()) } #[cl_entrypoint] @@ -341,9 +339,7 @@ fn create_sub_buffer( _ => return Err(CL_INVALID_VALUE), }; - Ok(cl_mem::from_arc(Mem::new_sub_buffer( - b, flags, offset, size, - ))) + Ok(Mem::new_sub_buffer(b, flags, offset, size).into_cl()) // TODO // CL_MISALIGNED_SUB_BUFFER_OFFSET if there are no devices in context associated with buffer for which the origin field of the cl_buffer_region structure passed in buffer_create_info is aligned to the CL_DEVICE_MEM_BASE_ADDR_ALIGN value. @@ -773,7 +769,7 @@ fn create_image_with_properties( return Err(CL_INVALID_PROPERTY); } - Ok(cl_mem::from_arc(Mem::new_image( + Ok(Mem::new_image( c, parent, desc.image_type, @@ -783,7 +779,8 @@ fn create_image_with_properties( elem_size, host_ptr, props, - )?)) + )? + .into_cl()) } #[cl_entrypoint] @@ -946,7 +943,7 @@ fn create_sampler_impl( filter_mode, props, ); - Ok(cl_sampler::from_arc(sampler)) + Ok(sampler.into_cl()) } #[cl_entrypoint] @@ -3008,11 +3005,7 @@ fn create_from_gl( let gl_export_manager = gl_ctx_manager.export_object(&c, target, flags as u32, miplevel, texture)?; - Ok(cl_mem::from_arc(Mem::from_gl( - c, - flags, - &gl_export_manager, - )?)) + Ok(Mem::from_gl(c, flags, &gl_export_manager)?.into_cl()) } else { Err(CL_INVALID_CONTEXT) } diff --git a/src/gallium/frontends/rusticl/api/program.rs b/src/gallium/frontends/rusticl/api/program.rs index 80767ab1345..c6878b19667 100644 --- a/src/gallium/frontends/rusticl/api/program.rs +++ b/src/gallium/frontends/rusticl/api/program.rs @@ -163,12 +163,13 @@ fn create_program_with_source( source.extend_from_slice(arr); } - Ok(cl_program::from_arc(Program::new( + Ok(Program::new( &c, &c.devs, // SAFETY: We've constructed `source` such that it contains no nul bytes. unsafe { CString::from_vec_unchecked(source) }, - ))) + ) + .into_cl()) } #[cl_entrypoint] @@ -228,7 +229,7 @@ fn create_program_with_binary( let prog = Program::from_bins(c, devs, &bins); - Ok(cl_program::from_arc(prog)) + Ok(prog.into_cl()) //• CL_INVALID_BINARY if an invalid program binary was encountered for any device. binary_status will return specific status for each device. } @@ -247,7 +248,7 @@ fn create_program_with_il( // SAFETY: according to API spec let spirv = unsafe { slice::from_raw_parts(il.cast(), length) }; - Ok(cl_program::from_arc(Program::from_spirv(c, spirv))) + Ok(Program::from_spirv(c, spirv).into_cl()) } #[cl_entrypoint] @@ -455,7 +456,7 @@ pub fn link_program( } debug_logging(&res, &devs); - Ok((cl_program::from_arc(res), code)) + Ok((res.into_cl(), code)) //• CL_INVALID_LINKER_OPTIONS if the linker options specified by options are invalid. //• CL_INVALID_OPERATION if the rules for devices containing compiled binaries or libraries as described in input_programs argument above are not followed. diff --git a/src/gallium/frontends/rusticl/api/queue.rs b/src/gallium/frontends/rusticl/api/queue.rs index d6dc637ff11..38499488443 100644 --- a/src/gallium/frontends/rusticl/api/queue.rs +++ b/src/gallium/frontends/rusticl/api/queue.rs @@ -93,12 +93,7 @@ pub fn create_command_queue_impl( return Err(CL_INVALID_QUEUE_PROPERTIES); } - Ok(cl_command_queue::from_arc(Queue::new( - c, - d, - properties, - properties_v2, - )?)) + Ok(Queue::new(c, d, properties, properties_v2)?.into_cl()) } #[cl_entrypoint]