From df84c89d969e25e2d3c34956b528434d14d3626e Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Wed, 28 Sep 2022 00:49:00 +0200 Subject: [PATCH] rusticl/mem: fix image OOB checks The CL API puts the array layer on the height, where gallium puts it on the depth. This is taken into account everywhere else, except for API validation. Fixes: 8b9a5adf8be ("rusticl/mem: return errors for OOB accesses") Signed-off-by: Karol Herbst Part-of: --- src/gallium/frontends/rusticl/api/memory.rs | 2 +- src/gallium/frontends/rusticl/core/memory.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gallium/frontends/rusticl/api/memory.rs b/src/gallium/frontends/rusticl/api/memory.rs index 80d7955..f06e133 100644 --- a/src/gallium/frontends/rusticl/api/memory.rs +++ b/src/gallium/frontends/rusticl/api/memory.rs @@ -510,7 +510,7 @@ fn validate_image_desc( fn validate_image_bounds(i: &Mem, origin: CLVec, region: CLVec) -> CLResult<()> { let bound = region + origin; - if bound > i.image_desc.size() { + if bound > i.image_desc.api_size() { return Err(CL_INVALID_VALUE); } Ok(()) diff --git a/src/gallium/frontends/rusticl/core/memory.rs b/src/gallium/frontends/rusticl/core/memory.rs index 4d428f2..91dd70f 100644 --- a/src/gallium/frontends/rusticl/core/memory.rs +++ b/src/gallium/frontends/rusticl/core/memory.rs @@ -66,6 +66,7 @@ pub trait CLImageDescInfo { fn row_pitch(&self) -> CLResult; fn slice_pitch(&self) -> CLResult; fn size(&self) -> CLVec; + fn api_size(&self) -> CLVec; fn dims(&self) -> u8 { self.type_info().0 @@ -124,6 +125,17 @@ impl CLImageDescInfo for cl_image_desc { CLVec::new([self.image_width, height, depth]) } + fn api_size(&self) -> CLVec { + let mut size = self.size(); + + if self.is_array() && self.dims() == 1 { + size[1] = size[2]; + size[2] = 1; + } + + size + } + fn bx(&self) -> CLResult { let size = self.size(); -- 2.7.4