From 17a52774dbf83b47a3d3852f103283e17ae24dc2 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Tue, 4 Jun 2024 00:18:25 +0200 Subject: [PATCH] rusticl/kernel/launch: get rid of Arc clones for global resources Part-of: --- src/gallium/frontends/rusticl/core/kernel.rs | 25 ++++++++----------- .../frontends/rusticl/mesa/pipe/context.rs | 4 +-- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/gallium/frontends/rusticl/core/kernel.rs b/src/gallium/frontends/rusticl/core/kernel.rs index aba910061c4..e11bdee223d 100644 --- a/src/gallium/frontends/rusticl/core/kernel.rs +++ b/src/gallium/frontends/rusticl/core/kernel.rs @@ -1001,7 +1001,7 @@ impl Kernel { let offset: u32 = buffer.offset as u32; input.extend_from_slice(&offset.to_ne_bytes()); } - resource_info.push((res.clone(), arg.offset)); + resource_info.push((res.as_ref(), arg.offset)); } KernelArgValue::Image(image) => { let res = image.get_res_of_dev(q.device)?; @@ -1084,16 +1084,11 @@ impl Kernel { let mut printf_buf = None; if nir_kernel_build.printf_info.is_some() { - let buf = Arc::new( - q.device - .screen - .resource_create_buffer( - printf_size, - ResourceType::Staging, - PIPE_BIND_GLOBAL, - ) - .unwrap(), - ); + let buf = q + .device + .screen + .resource_create_buffer(printf_size, ResourceType::Staging, PIPE_BIND_GLOBAL) + .unwrap(); let init_data: [u8; 1] = [4]; ctx.buffer_subdata(&buf, 0, init_data.as_ptr().cast(), init_data.len() as u32); @@ -1110,7 +1105,7 @@ impl Kernel { assert!(nir_kernel_build.constant_buffer.is_some()); input.extend_from_slice(null_ptr); resource_info.push(( - nir_kernel_build.constant_buffer.clone().unwrap(), + &nir_kernel_build.constant_buffer.as_ref().unwrap(), arg.offset, )); } @@ -1123,7 +1118,7 @@ impl Kernel { } InternalKernelArgType::PrintfBuffer => { input.extend_from_slice(null_ptr); - resource_info.push((printf_buf.as_ref().unwrap().clone(), arg.offset)); + resource_info.push((printf_buf.as_ref().unwrap(), arg.offset)); } InternalKernelArgType::InlineSampler(cl) => { samplers.push(Sampler::cl_to_pipe(cl)); @@ -1158,9 +1153,9 @@ impl Kernel { let mut resources = Vec::with_capacity(resource_info.len()); let mut globals: Vec<*mut u32> = Vec::with_capacity(resource_info.len()); - for (res, offset) in &resource_info { + for (res, offset) in resource_info { resources.push(res); - globals.push(unsafe { input.as_mut_ptr().add(*offset) }.cast()); + globals.push(unsafe { input.as_mut_ptr().add(offset) }.cast()); } let temp_cso; diff --git a/src/gallium/frontends/rusticl/mesa/pipe/context.rs b/src/gallium/frontends/rusticl/mesa/pipe/context.rs index 29f15905ca7..d9956137545 100644 --- a/src/gallium/frontends/rusticl/mesa/pipe/context.rs +++ b/src/gallium/frontends/rusticl/mesa/pipe/context.rs @@ -475,8 +475,8 @@ impl PipeContext { unsafe { self.pipe.as_ref().launch_grid.unwrap()(self.pipe.as_ptr(), &info) } } - pub fn set_global_binding(&self, res: &[&Arc], out: &mut [*mut u32]) { - let mut res: Vec<_> = res.iter().map(|r| r.pipe()).collect(); + pub fn set_global_binding(&self, res: &[&PipeResource], out: &mut [*mut u32]) { + let mut res: Vec<_> = res.iter().copied().map(PipeResource::pipe).collect(); unsafe { self.pipe.as_ref().set_global_binding.unwrap()( self.pipe.as_ptr(),