rusticl: drop Arc around PipeResource
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35812>
This commit is contained in:
Karol Herbst 2025-06-29 02:44:11 +02:00 committed by Marge Bot
parent 900dacb0ef
commit ec05d4b1fa
4 changed files with 29 additions and 38 deletions

View file

@ -142,7 +142,7 @@ impl Context {
copy: bool,
bda: bool,
res_type: ResourceType,
) -> CLResult<HashMap<&'static Device, Arc<PipeResource>>> {
) -> CLResult<HashMap<&'static Device, PipeResource>> {
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<HashMap<&'static Device, Arc<PipeResource>>> {
) -> CLResult<HashMap<&'static Device, PipeResource>> {
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<Option<Arc<PipeResource>>> {
) -> CLResult<Option<PipeResource>> {
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<HashMap<&'static Device, Arc<PipeResource>>> {
) -> CLResult<HashMap<&'static Device, PipeResource>> {
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)

View file

@ -23,7 +23,7 @@ use std::os::raw::c_void;
use std::ptr;
use std::sync::Arc;
type CLGLMappings = Option<HashMap<Arc<PipeResource>, Arc<PipeResource>>>;
type CLGLMappings = Option<HashMap<PipeResource, PipeResource>>;
pub struct XPlatManager {
#[cfg(glx)]
@ -426,9 +426,9 @@ pub struct GLObject {
}
pub fn create_shadow_slice(
cube_map: &HashMap<&'static Device, Arc<PipeResource>>,
cube_map: &HashMap<&'static Device, PipeResource>,
image_format: cl_image_format,
) -> CLResult<HashMap<&'static Device, Arc<PipeResource>>> {
) -> CLResult<HashMap<&'static Device, PipeResource>> {
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(())

View file

@ -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<Arc<PipeResource>>,
constant_buffer: Option<PipeResource>,
info: pipe_compute_state_object_info,
shared_size: u64,
printf_info: Option<NirPrintfInfo>,
@ -492,7 +491,7 @@ impl NirKernelBuild {
}
}
fn create_nir_constant_buffer(dev: &Device, nir: &NirShader) -> Option<Arc<PipeResource>> {
fn create_nir_constant_buffer(dev: &Device, nir: &NirShader) -> Option<PipeResource> {
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::<CLResult<_>>()?;
let svms_new = svms

View file

@ -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<PipeResource>>,
pub res: HashMap<&'static Device, PipeResource>,
valid_on: Mutex<Vec<ResourceValidityEntity>>,
// 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<PipeResource>> {
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<PipeResource>>,
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<PipeResource>> {
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<PipeResource>> {
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<PipeResource>> {
pub fn get_res_for_access(&self, ctx: &QueueContext, rw: RWFlags) -> CLResult<&PipeResource> {
self.alloc.get_res_for_access(ctx, rw)
}