From 1aab6820fb50b3115bb8e56018323051914b5f7c Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Wed, 12 Apr 2023 18:49:55 +0200 Subject: [PATCH] rusticl/mem: replace buffer_offset_size with CLVec::calc_offset_size buffer_offset_size was almost correct, but didn't calculate the size correctly. Signed-off-by: Karol Herbst Part-of: --- src/gallium/frontends/rusticl/core/memory.rs | 35 ++++++++------------ 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/gallium/frontends/rusticl/core/memory.rs b/src/gallium/frontends/rusticl/core/memory.rs index 6031d6696a4..ea9edd544a2 100644 --- a/src/gallium/frontends/rusticl/core/memory.rs +++ b/src/gallium/frontends/rusticl/core/memory.rs @@ -293,17 +293,6 @@ fn create_box( }) } -fn buffer_offset_size( - origin: &CLVec, - region: &CLVec, - 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, @@ -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)