rusticl: core: stop using cl_prop from the api module

It's a layering violation and really the wrong tool for the job. Add a new fn to view a given slice
as a &[u8] instead of going though the clprop machinery which creates a new Vec.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23652>
This commit is contained in:
LingMan 2023-06-14 07:56:50 +02:00 committed by Marge Bot
parent 2755519142
commit f1461c5a77
2 changed files with 24 additions and 11 deletions

View file

@ -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<u16>>(&tex_formats));
input.extend_from_slice(&cl_prop::<&Vec<u16>>(&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<u16>>(&tex_orders));
input.extend_from_slice(&cl_prop::<&Vec<u16>>(&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]);

View file

@ -24,3 +24,15 @@ pub fn read_string(input: &mut &[u8], len: usize) -> Option<String> {
*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: &[T]) -> &[u8] {
let new_len = core::mem::size_of_val(t) / core::mem::size_of::<u8>();
unsafe { core::slice::from_raw_parts(t.as_ptr() as *const u8, new_len) }
}