diff --git a/src/gallium/frontends/rusticl/core/context.rs b/src/gallium/frontends/rusticl/core/context.rs index ddfa3354f17..7f58298fc45 100644 --- a/src/gallium/frontends/rusticl/core/context.rs +++ b/src/gallium/frontends/rusticl/core/context.rs @@ -142,7 +142,7 @@ impl Context { copy: bool, bda: bool, res_type: ResourceType, - ) -> CLResult>> { + ) -> CLResult> { let adj_size: u32 = size.try_into_with_err(CL_OUT_OF_HOST_MEMORY)?; let mut res = HashMap::new(); let mut pipe_flags = 0; @@ -173,7 +173,7 @@ impl Context { } let resource = resource.ok_or(CL_OUT_OF_RESOURCES); - res.insert(dev, Arc::new(resource?)); + res.insert(dev, resource?); } if !user_ptr.is_null() { @@ -196,7 +196,7 @@ impl Context { user_ptr: *mut c_void, copy: bool, res_type: ResourceType, - ) -> CLResult>> { + ) -> CLResult> { let pipe_format = format.to_pipe_format().unwrap(); let width = desc.image_width.try_into_with_err(CL_OUT_OF_HOST_MEMORY)?; @@ -241,7 +241,7 @@ impl Context { } let resource = resource.ok_or(CL_OUT_OF_RESOURCES); - res.insert(dev, Arc::new(resource?)); + res.insert(dev, resource?); } if !user_ptr.is_null() { @@ -387,7 +387,7 @@ impl Context { } } - buffers.insert(dev, Arc::new(res)); + buffers.insert(dev, res); } self.svm.lock().unwrap().svm_ptrs.insert( @@ -406,16 +406,16 @@ impl Context { &self, ctx: &QueueContext, ptr: usize, - ) -> CLResult>> { + ) -> CLResult> { let svm = self.svm.lock().unwrap(); let Some(alloc) = svm.svm_ptrs.find_alloc_precise(ptr) else { return Ok(None); }; - Ok(Some(Arc::clone( - alloc.alloc.get_res_for_access(ctx, RWFlags::RW)?, - ))) + Ok(Some( + alloc.alloc.get_res_for_access(ctx, RWFlags::RW)?.new_ref(), + )) } pub fn copy_svm_to_host( @@ -617,7 +617,7 @@ impl Context { gl_target: cl_GLenum, format: cl_image_format, gl_props: GLMemProps, - ) -> CLResult>> { + ) -> CLResult> { let mut res = HashMap::new(); let target = cl_mem_type_to_texture_target_gl(image_type, gl_target); let pipe_format = if image_type == CL_MEM_OBJECT_BUFFER { @@ -649,7 +649,7 @@ impl Context { ) .ok_or(CL_OUT_OF_RESOURCES)?; - res.insert(*dev, Arc::new(resource)); + res.insert(*dev, resource); } Ok(res) diff --git a/src/gallium/frontends/rusticl/core/gl.rs b/src/gallium/frontends/rusticl/core/gl.rs index b11cfbaf168..e474dccd412 100644 --- a/src/gallium/frontends/rusticl/core/gl.rs +++ b/src/gallium/frontends/rusticl/core/gl.rs @@ -23,7 +23,7 @@ use std::os::raw::c_void; use std::ptr; use std::sync::Arc; -type CLGLMappings = Option, Arc>>; +type CLGLMappings = Option>; pub struct XPlatManager { #[cfg(glx)] @@ -426,9 +426,9 @@ pub struct GLObject { } pub fn create_shadow_slice( - cube_map: &HashMap<&'static Device, Arc>, + cube_map: &HashMap<&'static Device, PipeResource>, image_format: cl_image_format, -) -> CLResult>> { +) -> CLResult> { let mut slice = HashMap::new(); for (dev, imported_gl_res) in cube_map { @@ -449,7 +449,7 @@ pub fn create_shadow_slice( ) .ok_or(CL_OUT_OF_HOST_MEMORY)?; - slice.insert(*dev, Arc::new(shadow)); + slice.insert(*dev, shadow); } Ok(slice) @@ -477,7 +477,7 @@ pub fn copy_cube_to_slice(ctx: &QueueContext, mem_objects: &[Mem]) -> CLResult<( let cl_res = image.get_res_for_access(ctx, RWFlags::WR)?; let gl_res = gl_obj.shadow_map.as_ref().unwrap().get(cl_res).unwrap(); - ctx.resource_copy_texture(gl_res.as_ref(), cl_res.as_ref(), &dst_offset, &src_bx); + ctx.resource_copy_texture(gl_res, cl_res, &dst_offset, &src_bx); } Ok(()) @@ -505,7 +505,7 @@ pub fn copy_slice_to_cube(ctx: &QueueContext, mem_objects: &[Mem]) -> CLResult<( let cl_res = image.get_res_for_access(ctx, RWFlags::WR)?; let gl_res = gl_obj.shadow_map.as_ref().unwrap().get(cl_res).unwrap(); - ctx.resource_copy_texture(cl_res.as_ref(), gl_res.as_ref(), &dst_offset, &src_bx); + ctx.resource_copy_texture(cl_res, gl_res, &dst_offset, &src_bx); } Ok(()) diff --git a/src/gallium/frontends/rusticl/core/kernel.rs b/src/gallium/frontends/rusticl/core/kernel.rs index 1d989145eab..bb901d7d777 100644 --- a/src/gallium/frontends/rusticl/core/kernel.rs +++ b/src/gallium/frontends/rusticl/core/kernel.rs @@ -27,7 +27,6 @@ use std::convert::TryInto; use std::ffi::CStr; use std::fmt::Debug; use std::fmt::Display; -use std::ops::Deref; use std::ops::Index; use std::ops::Not; use std::os::raw::c_void; @@ -454,7 +453,7 @@ impl NirKernelBuilds { pub struct NirKernelBuild { nir_or_cso: KernelDevStateVariant, - constant_buffer: Option>, + constant_buffer: Option, info: pipe_compute_state_object_info, shared_size: u64, printf_info: Option, @@ -492,7 +491,7 @@ impl NirKernelBuild { } } - fn create_nir_constant_buffer(dev: &Device, nir: &NirShader) -> Option> { + fn create_nir_constant_buffer(dev: &Device, nir: &NirShader) -> Option { let buf = nir.get_constant_buffer(); let len = buf.len() as u32; @@ -507,7 +506,7 @@ impl NirKernelBuild { .exec(|ctx| ctx.buffer_subdata(&res, 0, buf.as_ptr().cast(), len)) .wait(); - Some(Arc::new(res)) + Some(res) } else { None } @@ -1626,7 +1625,7 @@ impl Kernel { let mut bdas: Vec<_> = bdas .iter() - .map(|buffer| Ok(buffer.get_res_for_access(ctx, RWFlags::RW)?.deref())) + .map(|buffer| Ok(buffer.get_res_for_access(ctx, RWFlags::RW)?)) .collect::>()?; let svms_new = svms diff --git a/src/gallium/frontends/rusticl/core/memory.rs b/src/gallium/frontends/rusticl/core/memory.rs index 5f51add9fb9..bbb50836a2b 100644 --- a/src/gallium/frontends/rusticl/core/memory.rs +++ b/src/gallium/frontends/rusticl/core/memory.rs @@ -161,7 +161,7 @@ pub enum ResourceValidityEntity { /// Allocation with real GPU backing storage. Tracks on which device the content is valid on. pub struct ResourceAllocation { - pub res: HashMap<&'static Device, Arc>, + pub res: HashMap<&'static Device, PipeResource>, valid_on: Mutex>, // 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. @@ -213,7 +213,7 @@ impl ResourceAllocation { /// migrate the data to the GPU. /// TODO: add a map function to return a mapping to the resource of one device the data is valid /// on instead of migrating if the user would simply map the resource anyway. - fn get_res_for_access(&self, ctx: &QueueContext, rw: RWFlags) -> CLResult<&Arc> { + fn get_res_for_access(&self, ctx: &QueueContext, rw: RWFlags) -> CLResult<&PipeResource> { let dev = ctx.dev; let dev_entity = ResourceValidityEntity::Device(dev); let to_res = self.res.get(dev).ok_or(CL_OUT_OF_HOST_MEMORY)?; @@ -442,7 +442,7 @@ pub enum Allocation { impl Allocation { /// Creates a new allocation object assuming the initial data is valid on every device. pub fn new( - res: HashMap<&'static Device, Arc>, + res: HashMap<&'static Device, PipeResource>, offset: usize, host_ptr: *mut c_void, ) -> Self { @@ -508,16 +508,12 @@ impl Allocation { } /// Returns the resource associated with `dev` without any data migration. - fn get_res_of_dev(&self, dev: &Device) -> Option<&Arc> { + fn get_res_of_dev(&self, dev: &Device) -> Option<&PipeResource> { self.get_real_resource().res.get(dev) } /// Returns the resource associated with `ctx.dev` and transparently migrate the data. - pub fn get_res_for_access( - &self, - ctx: &QueueContext, - rw: RWFlags, - ) -> CLResult<&Arc> { + pub fn get_res_for_access(&self, ctx: &QueueContext, rw: RWFlags) -> CLResult<&PipeResource> { self.get_real_resource().get_res_for_access(ctx, rw) } @@ -1084,8 +1080,8 @@ impl MemBase { .iter() .map(|(dev, resource)| { ( - Arc::clone(resource), - Arc::clone(imported_gl_tex.get(dev).unwrap()), + resource.new_ref(), + imported_gl_tex.get(dev).unwrap().new_ref(), ) }) .collect(); @@ -1167,11 +1163,7 @@ impl MemBase { && bit_check(self.flags, CL_MEM_USE_HOST_PTR) } - pub fn get_res_for_access( - &self, - ctx: &QueueContext, - rw: RWFlags, - ) -> CLResult<&Arc> { + pub fn get_res_for_access(&self, ctx: &QueueContext, rw: RWFlags) -> CLResult<&PipeResource> { self.alloc.get_res_for_access(ctx, rw) }