rusticl/program: use write_len_only for CL_PROGRAM_BINARIES

This query would simply write back the same content, so skip it.

Reviewed-by: @LingMan
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32268>
This commit is contained in:
Karol Herbst
2024-11-27 09:35:02 +01:00
committed by Marge Bot
parent 45af2e45f3
commit aed4a7bf83
2 changed files with 12 additions and 12 deletions
+10 -5
View File
@@ -28,11 +28,16 @@ unsafe impl CLInfo<cl_program_info> for cl_program {
match q {
CL_PROGRAM_BINARIES => {
let input = v.input::<*mut u8>()?;
// SAFETY: Oer spec it contains an array of pointers to write the binaries to,
// so we can assume the entire slice to be initialized.
let input = unsafe { slice_assume_init_ref(input) };
let bins = prog.binaries(input)?;
v.write::<Vec<*mut u8>>(bins)
// This query is a bit weird. At least the CTS is. We need to return the proper size
// of the buffer to hold all pointers, but when actually doing the query, we'd just
// parse the pointers out and write to them.
if !input.is_empty() {
// SAFETY: Per spec it contains an array of pointers to write the binaries to,
// so we can assume the entire slice to be initialized.
let input = unsafe { slice_assume_init_ref(input) };
prog.binaries(input)?;
}
v.write_len_only::<&[*mut u8]>(prog.devs.len())
}
CL_PROGRAM_BINARY_SIZES => v.write::<Vec<usize>>(prog.bin_sizes()),
CL_PROGRAM_CONTEXT => {
@@ -477,12 +477,7 @@ impl Program {
res
}
pub fn binaries(&self, ptrs: &[*mut u8]) -> CLResult<Vec<*mut u8>> {
// if the application didn't provide any pointers, just return the length of devices
if ptrs.is_empty() {
return Ok(vec![std::ptr::null_mut(); self.devs.len()]);
}
pub fn binaries(&self, ptrs: &[*mut u8]) -> CLResult<()> {
// ptrs is an array of pointers where we should write the device binaries into
if ptrs.len() < self.devs.len() {
return Err(CL_INVALID_VALUE);
@@ -531,7 +526,7 @@ impl Program {
}
}
Ok(ptrs.to_vec())
Ok(())
}
// TODO: at the moment we do not support compiling programs with different signatures across