diff --git a/src/gallium/frontends/rusticl/core/kernel.rs b/src/gallium/frontends/rusticl/core/kernel.rs index c75daddd7b4..61f021cf036 100644 --- a/src/gallium/frontends/rusticl/core/kernel.rs +++ b/src/gallium/frontends/rusticl/core/kernel.rs @@ -1,5 +1,4 @@ use crate::api::icd::*; -use crate::api::util::cl_prop; use crate::core::device::*; use crate::core::event::*; use crate::core::format::*; @@ -1000,13 +999,15 @@ impl Kernel { } InternalKernelArgType::GlobalWorkOffsets => { if q.device.address_bits() == 64 { - input.extend_from_slice(&cl_prop::<[u64; 3]>(offsets)); + input.extend_from_slice(unsafe { as_byte_slice(&offsets) }); } else { - input.extend_from_slice(&cl_prop::<[u32; 3]>([ - offsets[0] as u32, - offsets[1] as u32, - offsets[2] as u32, - ])); + input.extend_from_slice(unsafe { + as_byte_slice(&[ + offsets[0] as u32, + offsets[1] as u32, + offsets[2] as u32, + ]) + }); } } InternalKernelArgType::PrintfBuffer => { @@ -1026,12 +1027,12 @@ impl Kernel { samplers.push(Sampler::cl_to_pipe(cl)); } InternalKernelArgType::FormatArray => { - input.extend_from_slice(&cl_prop::<&Vec>(&tex_formats)); - input.extend_from_slice(&cl_prop::<&Vec>(&img_formats)); + input.extend_from_slice(unsafe { as_byte_slice(&tex_formats) }); + input.extend_from_slice(unsafe { as_byte_slice(&img_formats) }); } InternalKernelArgType::OrderArray => { - input.extend_from_slice(&cl_prop::<&Vec>(&tex_orders)); - input.extend_from_slice(&cl_prop::<&Vec>(&img_orders)); + input.extend_from_slice(unsafe { as_byte_slice(&tex_orders) }); + input.extend_from_slice(unsafe { as_byte_slice(&img_orders) }); } InternalKernelArgType::WorkDim => { input.extend_from_slice(&[work_dim as u8; 1]); diff --git a/src/gallium/frontends/rusticl/util/serialize.rs b/src/gallium/frontends/rusticl/util/serialize.rs index 1c0afc0ef5f..ec5bd6da821 100644 --- a/src/gallium/frontends/rusticl/util/serialize.rs +++ b/src/gallium/frontends/rusticl/util/serialize.rs @@ -24,3 +24,15 @@ pub fn read_string(input: &mut &[u8], len: usize) -> Option { *input = rest; String::from_utf8(string_bytes.to_vec()).ok() } + +/// Casts a &[T] to a [&u8] without copying. +/// Inspired by cast_slice from the bytemuck crate. Drop this copy once external crates are supported. +/// +/// # Safety +/// +/// T must not contain any uninitialized bytes such as padding. +#[inline] +pub unsafe fn as_byte_slice(t: &[T]) -> &[u8] { + let new_len = core::mem::size_of_val(t) / core::mem::size_of::(); + unsafe { core::slice::from_raw_parts(t.as_ptr() as *const u8, new_len) } +}