From 944f47f10346fda5f6705dba4738bf606352a9e8 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Fri, 6 Dec 2024 12:42:13 +0100 Subject: [PATCH] rusticl/mem: reimplement has_same_parent and rename it to backing_memory_eq We actually want to know if the backing memory is the same, it's also easier to implement than checking on the parent memory object. This will also allow for more flexibility if more memory types are supported, e.g. proper SVM allocations. Part-of: --- src/gallium/frontends/rusticl/api/memory.rs | 4 ++-- src/gallium/frontends/rusticl/core/memory.rs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/gallium/frontends/rusticl/api/memory.rs b/src/gallium/frontends/rusticl/api/memory.rs index fa2d471bd05..30a68d77a3f 100644 --- a/src/gallium/frontends/rusticl/api/memory.rs +++ b/src/gallium/frontends/rusticl/api/memory.rs @@ -1165,7 +1165,7 @@ fn enqueue_copy_buffer( // and the source and destination regions overlap or if src_buffer and dst_buffer are different // sub-buffers of the same associated buffer object and they overlap. The regions overlap if // src_offset ≤ dst_offset ≤ src_offset + size - 1 or if dst_offset ≤ src_offset ≤ dst_offset + size - 1. - if src.has_same_parent(&dst) { + if src.backing_memory_eq(&dst) { let src_offset = src_offset + src.offset(); let dst_offset = dst_offset + dst.offset(); @@ -1520,7 +1520,7 @@ fn enqueue_copy_buffer_rect( // CL_MEM_COPY_OVERLAP if src_buffer and dst_buffer are the same buffer or sub-buffer object and // the source and destination regions overlap or if src_buffer and dst_buffer are different // sub-buffers of the same associated buffer object and they overlap. - if src.has_same_parent(&dst) + if src.backing_memory_eq(&dst) && check_copy_overlap( &src_ori, src.offset(), diff --git a/src/gallium/frontends/rusticl/core/memory.rs b/src/gallium/frontends/rusticl/core/memory.rs index 1019d749a29..16700295cba 100644 --- a/src/gallium/frontends/rusticl/core/memory.rs +++ b/src/gallium/frontends/rusticl/core/memory.rs @@ -1030,8 +1030,9 @@ impl MemBase { self.mem_type == CL_MEM_OBJECT_BUFFER } - pub fn has_same_parent(&self, other: &Self) -> bool { - ptr::eq(self.get_parent(), other.get_parent()) + /// Checks if the backing memory is actually the same memory object. + pub fn backing_memory_eq(&self, other: &Self) -> bool { + self.alloc.backing_resource_eq(&other.alloc) } // this is kinda bogus, because that won't work with system SVM, but the spec wants us to