rusticl/memory: assume minimum image_height of 1

But still report 0 for the slice_pitch when queried.

Fixes clCopyImage 1Dbuffer

Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29776>
(cherry picked from commit 45fc5c032e)
This commit is contained in:
Karol Herbst 2024-06-18 19:54:44 +02:00 committed by Eric Engestrom
parent ce2f8fa7b2
commit 6489f1c1c4
2 changed files with 9 additions and 5 deletions

View file

@ -24,7 +24,7 @@
"description": "rusticl/memory: assume minimum image_height of 1",
"nominated": true,
"nomination_type": 0,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View file

@ -21,6 +21,7 @@ use rusticl_proc_macros::cl_info_entrypoint;
use std::alloc;
use std::alloc::Layout;
use std::cmp;
use std::cmp::Ordering;
use std::mem::{self, MaybeUninit};
use std::os::raw::c_void;
@ -512,7 +513,7 @@ fn validate_image_desc(
desc.image_row_pitch = desc.image_width * elem_size;
}
if desc.image_slice_pitch == 0 {
desc.image_slice_pitch = desc.image_row_pitch * desc.image_height;
desc.image_slice_pitch = desc.image_row_pitch * cmp::max(1, desc.image_height);
}
if has_buf_parent && desc.image_type != CL_MEM_OBJECT_IMAGE1D_BUFFER {
@ -533,8 +534,7 @@ fn validate_image_desc(
}
if dims == 3 || array {
let valid_slice_pitch =
desc.image_row_pitch * if dims == 1 { 1 } else { desc.image_height };
let valid_slice_pitch = desc.image_row_pitch * cmp::max(1, desc.image_height);
if desc.image_slice_pitch == 0 {
desc.image_slice_pitch = valid_slice_pitch;
} else if desc.image_slice_pitch < valid_slice_pitch
@ -721,7 +721,11 @@ impl CLInfo<cl_image_info> for cl_mem {
CL_IMAGE_NUM_MIP_LEVELS => cl_prop::<cl_uint>(mem.image_desc.num_mip_levels),
CL_IMAGE_NUM_SAMPLES => cl_prop::<cl_uint>(mem.image_desc.num_samples),
CL_IMAGE_ROW_PITCH => cl_prop::<usize>(mem.image_desc.image_row_pitch),
CL_IMAGE_SLICE_PITCH => cl_prop::<usize>(mem.image_desc.image_slice_pitch),
CL_IMAGE_SLICE_PITCH => cl_prop::<usize>(if mem.image_desc.dims() == 1 {
0
} else {
mem.image_desc.image_slice_pitch
}),
CL_IMAGE_WIDTH => cl_prop::<usize>(mem.image_desc.image_width),
_ => return Err(CL_INVALID_VALUE),
})