From 2aec563acf63a8f5356e491d0edb89a98be0a358 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Fri, 23 Aug 2024 21:56:43 +0200 Subject: [PATCH] rusticl/image: fix clEnqueueFillImage for CL_DEPTH Part-of: --- src/gallium/frontends/rusticl/api/memory.rs | 17 +++++++++++++---- src/gallium/frontends/rusticl/core/memory.rs | 9 ++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/gallium/frontends/rusticl/api/memory.rs b/src/gallium/frontends/rusticl/api/memory.rs index ee7b7bf74f4..bf050b6481e 100644 --- a/src/gallium/frontends/rusticl/api/memory.rs +++ b/src/gallium/frontends/rusticl/api/memory.rs @@ -1967,16 +1967,25 @@ fn enqueue_fill_image( // description for origin and region. validate_image_bounds(&i, origin, region)?; - // we have to copy memory and it's always a 4 component int value - // TODO but not for CL_DEPTH - let fill_color = unsafe { slice::from_raw_parts(fill_color.cast(), 4).to_vec() }; + // The fill color is a single floating-point value if the channel order is CL_DEPTH. Otherwise, + // the fill color is a four component RGBA floating-point color value if the image channel data + // type is not an unnormalized signed or unsigned integer type, is a four component signed + // integer value if the image channel data type is an unnormalized signed integer type and is a + // four component unsigned integer value if the image channel data type is an unnormalized + // unsigned integer type. + let fill_color = if i.image_format.image_channel_order == CL_DEPTH { + [unsafe { fill_color.cast::().read() }, 0, 0, 0] + } else { + unsafe { fill_color.cast::<[u32; 4]>().read() } + }; + create_and_queue( q, CL_COMMAND_FILL_BUFFER, evs, event, false, - Box::new(move |q, ctx| i.fill(q, ctx, &fill_color, &origin, ®ion)), + Box::new(move |q, ctx| i.fill(q, ctx, fill_color, &origin, ®ion)), ) //• CL_INVALID_IMAGE_SIZE if image dimensions (image width, height, specified or compute row and/or slice pitch) for image are not supported by device associated with queue. diff --git a/src/gallium/frontends/rusticl/core/memory.rs b/src/gallium/frontends/rusticl/core/memory.rs index f15b0cbb0e3..672d2208a5a 100644 --- a/src/gallium/frontends/rusticl/core/memory.rs +++ b/src/gallium/frontends/rusticl/core/memory.rs @@ -1293,7 +1293,7 @@ impl Image { &self, q: &Queue, ctx: &PipeContext, - pattern: &[u32], + pattern: [u32; 4], origin: &CLVec, region: &CLVec, ) -> CLResult<()> { @@ -1301,19 +1301,14 @@ impl Image { // make sure we allocate multiples of 4 bytes so drivers don't read out of bounds or // unaligned. - // TODO: use div_ceil once it's available let pixel_size: usize = self.image_format.pixel_size().unwrap().into(); let mut new_pattern: Vec = vec![0; pixel_size.div_ceil(size_of::())]; - // we don't support CL_DEPTH for now - assert!(pattern.len() == 4); - // SAFETY: pointers have to be valid for read/writes of exactly one pixel of their // respective format. // `new_pattern` has the correct size due to the `size` above. // `pattern` is validated through the CL API and allows undefined behavior if not followed - // by CL API rules. It's expected to be a 4 component array of 32 bit values, except for - // CL_DEPTH where it's just one value. + // by CL API rules. unsafe { util_format_pack_rgba( self.pipe_format,