From 900dacb0efaaa372468ba51e58b9182853812183 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Sun, 29 Jun 2025 02:40:34 +0200 Subject: [PATCH] rusticl/mesa: add PipeResource::new_ref pipe_resources are already ref counted, so we can simply make use of that. Part-of: --- src/gallium/frontends/rusticl/mesa/pipe/resource.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/gallium/frontends/rusticl/mesa/pipe/resource.rs b/src/gallium/frontends/rusticl/mesa/pipe/resource.rs index da8ec738b17..0ce8ae86450 100644 --- a/src/gallium/frontends/rusticl/mesa/pipe/resource.rs +++ b/src/gallium/frontends/rusticl/mesa/pipe/resource.rs @@ -84,6 +84,19 @@ impl PipeResource { Some(Self { pipe: res }) } + /// Creates a new reference to the underlying GPU resource + pub fn new_ref(&self) -> Self { + let mut ptr = ptr::null_mut(); + // SAFETY: pipe_resource_reference will copy the ptr from src to dest, therefore ptr can't + // be NULL. + unsafe { + pipe_resource_reference(&mut ptr, self.pipe.as_ptr()); + Self { + pipe: NonNull::new_unchecked(ptr), + } + } + } + pub(super) fn pipe(&self) -> *mut pipe_resource { self.pipe.as_ptr() }