rusticl/mesa: rename PipeResource to PipeResourceOwned

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36917>
This commit is contained in:
Karol Herbst
2025-08-21 11:36:14 +02:00
committed by Marge Bot
parent 443446aa82
commit 10b3dcdadf
8 changed files with 73 additions and 65 deletions
@@ -152,7 +152,7 @@ impl Context {
copy: bool,
bda: bool,
res_type: ResourceType,
) -> CLResult<HashMap<&'static Device, PipeResource>> {
) -> CLResult<HashMap<&'static Device, PipeResourceOwned>> {
let adj_size: u32 = size.try_into_with_err(CL_OUT_OF_HOST_MEMORY)?;
let mut res = HashMap::new();
let mut pipe_flags = 0;
@@ -208,7 +208,7 @@ impl Context {
user_ptr: *mut c_void,
copy: bool,
res_type: ResourceType,
) -> CLResult<HashMap<&'static Device, PipeResource>> {
) -> CLResult<HashMap<&'static Device, PipeResourceOwned>> {
let pipe_format = format.to_pipe_format().unwrap();
let width = desc.image_width.try_into_with_err(CL_OUT_OF_HOST_MEMORY)?;
@@ -420,7 +420,7 @@ impl Context {
&self,
ctx: &QueueContext,
ptr: usize,
) -> CLResult<Option<PipeResource>> {
) -> CLResult<Option<PipeResourceOwned>> {
let svm = self.svm.lock().unwrap();
let Some(alloc) = svm.svm_ptrs.find_alloc_precise(ptr) else {
@@ -631,7 +631,7 @@ impl Context {
gl_target: cl_GLenum,
format: cl_image_format,
gl_props: GLMemProps,
) -> CLResult<HashMap<&'static Device, PipeResource>> {
) -> CLResult<HashMap<&'static Device, PipeResourceOwned>> {
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 {
+8 -8
View File
@@ -128,7 +128,7 @@ pub trait HelperContextWrapper {
fn buffer_map(
&self,
res: &PipeResource,
res: &PipeResourceOwned,
offset: i32,
size: i32,
rw: RWFlags,
@@ -140,7 +140,7 @@ pub trait HelperContextWrapper {
fn map_buffer_unsynchronized(
&self,
res: &PipeResource,
res: &PipeResourceOwned,
offset: i32,
size: i32,
rw: RWFlags,
@@ -148,7 +148,7 @@ pub trait HelperContextWrapper {
fn map_texture_unsynchronized(
&self,
res: &PipeResource,
res: &PipeResourceOwned,
bx: &pipe_box,
rw: RWFlags,
) -> Option<PipeTransfer<'_>>;
@@ -164,7 +164,7 @@ pub struct HelperContext<'a> {
impl HelperContext<'_> {
pub fn buffer_subdata(
&self,
res: &PipeResource,
res: &PipeResourceOwned,
offset: c_uint,
data: *const c_void,
size: c_uint,
@@ -174,7 +174,7 @@ impl HelperContext<'_> {
pub fn texture_subdata(
&self,
res: &PipeResource,
res: &PipeResourceOwned,
bx: &pipe_box,
data: *const c_void,
stride: u32,
@@ -196,7 +196,7 @@ impl HelperContextWrapper for HelperContext<'_> {
fn buffer_map(
&self,
res: &PipeResource,
res: &PipeResourceOwned,
offset: i32,
size: i32,
rw: RWFlags,
@@ -222,7 +222,7 @@ impl HelperContextWrapper for HelperContext<'_> {
fn map_buffer_unsynchronized(
&self,
res: &PipeResource,
res: &PipeResourceOwned,
offset: i32,
size: i32,
rw: RWFlags,
@@ -237,7 +237,7 @@ impl HelperContextWrapper for HelperContext<'_> {
fn map_texture_unsynchronized(
&self,
res: &PipeResource,
res: &PipeResourceOwned,
bx: &pipe_box,
rw: RWFlags,
) -> Option<PipeTransfer<'_>> {
+3 -3
View File
@@ -27,7 +27,7 @@ use std::os::raw::c_void;
use std::ptr;
use std::sync::Arc;
type CLGLMappings = Option<HashMap<PipeResource, PipeResource>>;
type CLGLMappings = Option<HashMap<PipeResourceOwned, PipeResourceOwned>>;
pub struct XPlatManager {
#[cfg(glx)]
@@ -478,9 +478,9 @@ impl GLObject {
}
pub fn create_shadow_slice(
cube_map: &HashMap<&'static Device, PipeResource>,
cube_map: &HashMap<&'static Device, PipeResourceOwned>,
image_format: cl_image_format,
) -> CLResult<HashMap<&'static Device, PipeResource>> {
) -> CLResult<HashMap<&'static Device, PipeResourceOwned>> {
let mut slice = HashMap::new();
for (dev, imported_gl_res) in cube_map {
+4 -4
View File
@@ -456,7 +456,7 @@ impl NirKernelBuilds {
pub struct NirKernelBuild {
nir_or_cso: KernelDevStateVariant,
constant_buffer: Option<PipeResource>,
constant_buffer: Option<PipeResourceOwned>,
info: pipe_compute_state_object_info,
shared_size: u64,
printf_info: Option<NirPrintfInfo>,
@@ -494,7 +494,7 @@ impl NirKernelBuild {
}
}
fn create_nir_constant_buffer(dev: &Device, nir: &NirShader) -> Option<PipeResource> {
fn create_nir_constant_buffer(dev: &Device, nir: &NirShader) -> Option<PipeResourceOwned> {
let buf = nir.get_constant_buffer();
let len = buf.len() as u32;
@@ -1422,8 +1422,8 @@ impl Kernel {
fn add_global<'a>(
ctx: &QueueContext,
input: &mut Vec<u8>,
resource_info: &mut Vec<(&'a PipeResource, usize)>,
res: &'a PipeResource,
resource_info: &mut Vec<(&'a PipeResourceOwned, usize)>,
res: &'a PipeResourceOwned,
offset: usize,
) {
resource_info.push((res, input.len()));
+14 -6
View File
@@ -164,7 +164,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, PipeResource>,
pub res: HashMap<&'static Device, PipeResourceOwned>,
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.
@@ -216,7 +216,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<&PipeResource> {
fn get_res_for_access(&self, ctx: &QueueContext, rw: RWFlags) -> CLResult<&PipeResourceOwned> {
let dev = ctx.dev;
let dev_entity = ResourceValidityEntity::Device(dev);
let to_res = self.res.get(dev).ok_or(CL_OUT_OF_HOST_MEMORY)?;
@@ -445,7 +445,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, PipeResource>,
res: HashMap<&'static Device, PipeResourceOwned>,
offset: usize,
host_ptr: *mut c_void,
) -> Self {
@@ -511,12 +511,16 @@ impl Allocation {
}
/// Returns the resource associated with `dev` without any data migration.
fn get_res_of_dev(&self, dev: &Device) -> Option<&PipeResource> {
fn get_res_of_dev(&self, dev: &Device) -> Option<&PipeResourceOwned> {
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<&PipeResource> {
pub fn get_res_for_access(
&self,
ctx: &QueueContext,
rw: RWFlags,
) -> CLResult<&PipeResourceOwned> {
self.get_real_resource().get_res_for_access(ctx, rw)
}
@@ -1168,7 +1172,11 @@ impl MemBase {
&& bit_check(self.flags, CL_MEM_USE_HOST_PTR)
}
pub fn get_res_for_access(&self, ctx: &QueueContext, rw: RWFlags) -> CLResult<&PipeResource> {
pub fn get_res_for_access(
&self,
ctx: &QueueContext,
rw: RWFlags,
) -> CLResult<&PipeResourceOwned> {
self.alloc.get_res_for_access(ctx, rw)
}
@@ -77,7 +77,7 @@ impl PipeContext {
pub fn buffer_subdata(
&self,
res: &PipeResource,
res: &PipeResourceOwned,
offset: c_uint,
data: *const c_void,
size: c_uint,
@@ -96,7 +96,7 @@ impl PipeContext {
pub fn texture_subdata(
&self,
res: &PipeResource,
res: &PipeResourceOwned,
bx: &pipe_box,
data: *const c_void,
stride: u32,
@@ -116,7 +116,7 @@ impl PipeContext {
}
}
pub fn clear_buffer(&self, res: &PipeResource, pattern: &[u8], offset: u32, size: u32) {
pub fn clear_buffer(&self, res: &PipeResourceOwned, pattern: &[u8], offset: u32, size: u32) {
unsafe {
self.pipe
.as_ref()
@@ -134,7 +134,7 @@ impl PipeContext {
pub fn clear_image_buffer(
&self,
res: &PipeResource,
res: &PipeResourceOwned,
pattern: &[u32],
offset_bytes: u32,
region: &[usize; 3],
@@ -162,7 +162,7 @@ impl PipeContext {
}
}
pub fn clear_texture(&self, res: &PipeResource, pattern: &[u32], bx: &pipe_box) {
pub fn clear_texture(&self, res: &PipeResourceOwned, pattern: &[u32], bx: &pipe_box) {
unsafe {
let clear_texture = self
.pipe
@@ -181,8 +181,8 @@ impl PipeContext {
fn resource_copy_region(
&self,
src: &PipeResource,
dst: &PipeResource,
src: &PipeResourceOwned,
dst: &PipeResourceOwned,
dst_offset: &[u32; 3],
bx: &pipe_box,
) {
@@ -203,9 +203,9 @@ impl PipeContext {
pub fn resource_copy_buffer(
&self,
src: &PipeResource,
src: &PipeResourceOwned,
src_offset: i32,
dst: &PipeResource,
dst: &PipeResourceOwned,
dst_offset: u32,
width: i32,
) {
@@ -225,8 +225,8 @@ impl PipeContext {
pub fn resource_copy_texture(
&self,
src: &PipeResource,
dst: &PipeResource,
src: &PipeResourceOwned,
dst: &PipeResourceOwned,
dst_offset: &[u32; 3],
bx: &pipe_box,
) {
@@ -244,8 +244,8 @@ impl PipeContext {
/// ([Self::has_buffer_texture_copies]).
pub fn resource_copy_buffer_texture(
&self,
src: &PipeResource,
dst: &PipeResource,
src: &PipeResourceOwned,
dst: &PipeResourceOwned,
buffer_offset: u32,
bx: &pipe_box,
) {
@@ -267,7 +267,7 @@ impl PipeContext {
fn resource_map(
&self,
res: &PipeResource,
res: &PipeResourceOwned,
bx: &pipe_box,
flags: pipe_map_flags,
is_buffer: bool,
@@ -293,7 +293,7 @@ impl PipeContext {
pub fn buffer_map_flags(
&self,
res: &PipeResource,
res: &PipeResourceOwned,
offset: i32,
size: i32,
flags: pipe_map_flags,
@@ -311,7 +311,7 @@ impl PipeContext {
pub fn buffer_map(
&self,
res: &PipeResource,
res: &PipeResourceOwned,
offset: i32,
size: i32,
rw: RWFlags,
@@ -325,7 +325,7 @@ impl PipeContext {
pub fn texture_map_flags(
&self,
res: &PipeResource,
res: &PipeResourceOwned,
bx: &pipe_box,
flags: pipe_map_flags,
) -> Option<PipeTransfer<'_>> {
@@ -334,7 +334,7 @@ impl PipeContext {
pub fn texture_map(
&self,
res: &PipeResource,
res: &PipeResourceOwned,
bx: &pipe_box,
rw: RWFlags,
) -> Option<PipeTransfer<'_>> {
@@ -421,7 +421,7 @@ impl PipeContext {
unsafe { self.pipe.as_ref().delete_sampler_state.unwrap()(self.pipe.as_ptr(), ptr) }
}
pub fn bind_constant_buffer(&self, idx: u32, res: &PipeResource) {
pub fn bind_constant_buffer(&self, idx: u32, res: &PipeResourceOwned) {
let cb = pipe_constant_buffer {
buffer: res.pipe(),
buffer_offset: 0,
@@ -502,7 +502,7 @@ impl PipeContext {
block: [u32; 3],
grid: [u32; 3],
variable_local_mem: u32,
globals: &[&PipeResource],
globals: &[&PipeResourceOwned],
) {
let mut globals: Vec<*mut pipe_resource> = globals.iter().map(|res| res.pipe()).collect();
let info = pipe_grid_info {
@@ -517,8 +517,8 @@ impl PipeContext {
unsafe { self.pipe.as_ref().launch_grid.unwrap()(self.pipe.as_ptr(), &info) }
}
pub fn set_global_binding(&self, res: &[&PipeResource], out: &mut [*mut u32]) {
let mut res: Vec<_> = res.iter().copied().map(PipeResource::pipe).collect();
pub fn set_global_binding(&self, res: &[&PipeResourceOwned], out: &mut [*mut u32]) {
let mut res: Vec<_> = res.iter().copied().map(PipeResourceOwned::pipe).collect();
unsafe {
self.pipe.as_ref().set_global_binding.unwrap()(
self.pipe.as_ptr(),
@@ -14,15 +14,15 @@ use super::context::PipeContext;
#[derive(Debug, PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct PipeResource {
pub struct PipeResourceOwned {
pipe: NonNull<pipe_resource>,
}
const PIPE_RESOURCE_FLAG_RUSTICL_IS_USER: u32 = PIPE_RESOURCE_FLAG_FRONTEND_PRIV;
// SAFETY: pipe_resource is considered a thread safe type
unsafe impl Send for PipeResource {}
unsafe impl Sync for PipeResource {}
unsafe impl Send for PipeResourceOwned {}
unsafe impl Sync for PipeResourceOwned {}
/// A thread safe wrapper around [pipe_image_view]. It's purpose is to increase the reference count
/// on the [pipe_resource] this view belongs to.
@@ -74,7 +74,7 @@ impl AppImgInfo {
}
}
impl PipeResource {
impl PipeResourceOwned {
pub(super) fn new(res: *mut pipe_resource, is_user: bool) -> Option<Self> {
let mut res = NonNull::new(res)?;
@@ -298,7 +298,7 @@ impl PipeResource {
}
}
impl Drop for PipeResource {
impl Drop for PipeResourceOwned {
fn drop(&mut self) {
unsafe {
pipe_resource_reference(&mut self.pipe.as_ptr(), ptr::null_mut());
@@ -314,13 +314,13 @@ pub struct PipeSamplerView<'c, 'r> {
view: NonNull<pipe_sampler_view>,
// the pipe_sampler_view object references both a context and a resource.
_ctx: PhantomData<&'c PipeContext>,
_res: PhantomData<&'r PipeResource>,
_res: PhantomData<&'r PipeResourceOwned>,
}
impl<'c, 'r> PipeSamplerView<'c, 'r> {
pub fn new(
ctx: &'c PipeContext,
res: &'r PipeResource,
res: &'r PipeResourceOwned,
template: &pipe_sampler_view,
) -> Option<Self> {
let view = unsafe {
@@ -114,7 +114,7 @@ impl PipeScreen {
})
}
pub fn resource_assign_vma(&self, res: &PipeResource, address: u64) -> bool {
pub fn resource_assign_vma(&self, res: &PipeResourceOwned, address: u64) -> bool {
if let Some(resource_assign_vma) = self.screen().resource_assign_vma {
// Validate that we already acquired the vm range
if cfg!(debug_assertions) {
@@ -130,8 +130,8 @@ impl PipeScreen {
}
}
fn resource_create(&self, tmpl: &pipe_resource) -> Option<PipeResource> {
PipeResource::new(
fn resource_create(&self, tmpl: &pipe_resource) -> Option<PipeResourceOwned> {
PipeResourceOwned::new(
unsafe { self.screen().resource_create.unwrap()(self.screen.as_ptr(), tmpl) },
false,
)
@@ -141,8 +141,8 @@ impl PipeScreen {
&self,
tmpl: &pipe_resource,
mem: *mut c_void,
) -> Option<PipeResource> {
PipeResource::new(
) -> Option<PipeResourceOwned> {
PipeResourceOwned::new(
unsafe { self.screen().resource_from_user_memory?(self.screen.as_ptr(), tmpl, mem) },
true,
)
@@ -154,7 +154,7 @@ impl PipeScreen {
res_type: ResourceType,
pipe_bind: u32,
pipe_flags: u32,
) -> Option<PipeResource> {
) -> Option<PipeResourceOwned> {
let mut tmpl = pipe_resource::default();
tmpl.set_target(pipe_texture_target::PIPE_BUFFER);
@@ -176,7 +176,7 @@ impl PipeScreen {
mem: *mut c_void,
pipe_bind: u32,
pipe_flags: u32,
) -> Option<PipeResource> {
) -> Option<PipeResourceOwned> {
let mut tmpl = pipe_resource::default();
tmpl.set_target(pipe_texture_target::PIPE_BUFFER);
@@ -200,7 +200,7 @@ impl PipeScreen {
format: pipe_format,
res_type: ResourceType,
support_image: bool,
) -> Option<PipeResource> {
) -> Option<PipeResourceOwned> {
let mut tmpl = pipe_resource::default();
tmpl.set_target(target);
@@ -230,7 +230,7 @@ impl PipeScreen {
format: pipe_format,
mem: *mut c_void,
support_image: bool,
) -> Option<PipeResource> {
) -> Option<PipeResourceOwned> {
let mut tmpl = pipe_resource::default();
tmpl.set_target(target);
@@ -260,7 +260,7 @@ impl PipeScreen {
depth: u16,
array_size: u16,
support_image: bool,
) -> Option<PipeResource> {
) -> Option<PipeResourceOwned> {
let mut tmpl = pipe_resource::default();
let mut handle = winsys_handle {
type_: WINSYS_HANDLE_TYPE_FD,
@@ -288,7 +288,7 @@ impl PipeScreen {
}
unsafe {
PipeResource::new(
PipeResourceOwned::new(
self.screen().resource_from_handle.unwrap()(
self.screen.as_ptr(),
&tmpl,