rusticl/mem: replace buffer_offset_size with CLVec::calc_offset_size
authorKarol Herbst <kherbst@redhat.com>
Wed, 12 Apr 2023 16:49:55 +0000 (18:49 +0200)
committerMarge Bot <emma+marge@anholt.net>
Thu, 13 Apr 2023 20:23:44 +0000 (20:23 +0000)
buffer_offset_size was almost correct, but didn't calculate the size
correctly.

Signed-off-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22449>

src/gallium/frontends/rusticl/core/memory.rs

index 6031d66..ea9edd5 100644 (file)
@@ -293,17 +293,6 @@ fn create_box(
     })
 }
 
-fn buffer_offset_size(
-    origin: &CLVec<usize>,
-    region: &CLVec<usize>,
-    row_pitch: usize,
-    slice_pitch: usize,
-    pixel_size: usize,
-) -> (usize, usize) {
-    let pitch = [pixel_size, row_pitch, slice_pitch];
-    (*origin * pitch, *region * pitch)
-}
-
 impl Mem {
     pub fn new_buffer(
         context: Arc<Context>,
@@ -878,12 +867,14 @@ impl Mem {
     ) -> CLResult<()> {
         if self.is_buffer() || self.is_image_from_buffer() {
             let pixel_size = self.pixel_size().unwrap();
-            let (offset, size) = buffer_offset_size(
+            let (offset, size) = CLVec::calc_offset_size(
                 dst_origin,
                 region,
-                dst_row_pitch,
-                dst_slice_pitch,
-                pixel_size.try_into().unwrap(),
+                [
+                    pixel_size.try_into().unwrap(),
+                    dst_row_pitch,
+                    dst_slice_pitch,
+                ],
             );
             let tx = self.tx(q, ctx, offset, size, RWFlags::WR)?;
 
@@ -944,12 +935,14 @@ impl Mem {
 
         if self.is_buffer() || self.is_image_from_buffer() {
             pixel_size = self.pixel_size().unwrap();
-            let (offset, size) = buffer_offset_size(
+            let (offset, size) = CLVec::calc_offset_size(
                 src_origin,
                 region,
-                src_row_pitch,
-                src_slice_pitch,
-                pixel_size.try_into().unwrap(),
+                [
+                    pixel_size.try_into().unwrap(),
+                    src_row_pitch,
+                    src_slice_pitch,
+                ],
             );
             tx = self.tx(q, ctx, offset, size, RWFlags::RD)?;
         } else {
@@ -996,11 +989,11 @@ impl Mem {
         assert!(dst.is_buffer());
 
         let (offset, size) =
-            buffer_offset_size(src_origin, region, src_row_pitch, src_slice_pitch, 1);
+            CLVec::calc_offset_size(src_origin, region, [1, src_row_pitch, src_slice_pitch]);
         let tx_src = self.tx(q, ctx, offset, size, RWFlags::RD)?;
 
         let (offset, size) =
-            buffer_offset_size(dst_origin, region, dst_row_pitch, dst_slice_pitch, 1);
+            CLVec::calc_offset_size(dst_origin, region, [1, dst_row_pitch, dst_slice_pitch]);
         let tx_dst = dst.tx(q, ctx, offset, size, RWFlags::WR)?;
 
         // TODO check to use hw accelerated paths (e.g. resource_copy_region or blits)