mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-06-07 16:58:20 +02:00
rusticl: return correct error from clCreateSubBuffer
From the OpenCL specification, `clCreateSubBuffer` should return: `CL_MISALIGNED_SUB_BUFFER_OFFSET` if there are no devices in `context` associated with `buffer` for which the `origin` field of the `cl_buffer_region` structure passed in `buffer_create_info` is aligned to the `CL_DEVICE_MEM_BASE_ADDR_ALIGN` value. This was previously unhandled in the entrypoint, marked as TODO. Add two functions to `Device` for querying the address alignment in both bits and bytes, for convenience. Properly retrieving the alignment value from the underlying device/screen is still marked as TODO. Signed-off-by: Ahmed Hesham <ahmed.hesham@arm.com> Reviewed-by: Karol Herbst <kherbst@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40726>
This commit is contained in:
parent
e98c4c59c7
commit
c8d7fad153
3 changed files with 23 additions and 5 deletions
|
|
@ -200,8 +200,7 @@ unsafe impl CLInfo<cl_device_info> for cl_device_id {
|
|||
CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS => v.write::<cl_uint>(dev.max_grid_dimensions()),
|
||||
CL_DEVICE_MAX_WORK_ITEM_SIZES => v.write::<&[usize]>(&dev.max_block_sizes()),
|
||||
CL_DEVICE_MAX_WRITE_IMAGE_ARGS => v.write::<cl_uint>(dev.caps.max_write_images),
|
||||
// TODO proper retrival from devices
|
||||
CL_DEVICE_MEM_BASE_ADDR_ALIGN => v.write::<cl_uint>(0x1000),
|
||||
CL_DEVICE_MEM_BASE_ADDR_ALIGN => v.write::<cl_uint>(dev.mem_base_addr_align_bits()),
|
||||
CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE => {
|
||||
v.write::<cl_uint>(16 * size_of::<cl_ulong>() as cl_uint)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -452,10 +452,19 @@ fn create_sub_buffer(
|
|||
_ => return Err(CL_INVALID_VALUE),
|
||||
};
|
||||
|
||||
Ok(MemBase::new_sub_buffer(b, flags, offset, size).into_cl())
|
||||
// CL_MISALIGNED_SUB_BUFFER_OFFSET if there are no devices in context associated with buffer for
|
||||
// which offset is aligned to CL_DEVICE_MEM_BASE_ADDR_ALIGN.
|
||||
let is_aligned_for_any_dev = b
|
||||
.context
|
||||
.devs
|
||||
.iter()
|
||||
.any(|&dev| offset % dev.mem_base_addr_align_bytes() == 0);
|
||||
|
||||
// TODO
|
||||
// CL_MISALIGNED_SUB_BUFFER_OFFSET if there are no devices in context associated with buffer for which the origin field of the cl_buffer_region structure passed in buffer_create_info is aligned to the CL_DEVICE_MEM_BASE_ADDR_ALIGN value.
|
||||
if !is_aligned_for_any_dev {
|
||||
return Err(CL_MISALIGNED_SUB_BUFFER_OFFSET);
|
||||
}
|
||||
|
||||
Ok(MemBase::new_sub_buffer(b, flags, offset, size).into_cl())
|
||||
}
|
||||
|
||||
#[cl_entrypoint(clSetMemObjectDestructorCallback)]
|
||||
|
|
|
|||
|
|
@ -1362,6 +1362,16 @@ impl DeviceBase {
|
|||
}
|
||||
|
||||
impl Device {
|
||||
pub fn mem_base_addr_align_bytes(&self) -> usize {
|
||||
// TODO: proper retrieval from the underlying device/screen
|
||||
0x200
|
||||
}
|
||||
|
||||
pub fn mem_base_addr_align_bits(&self) -> u32 {
|
||||
const BITS_PER_BYTE: u32 = 8;
|
||||
(self.mem_base_addr_align_bytes() as u32) * BITS_PER_BYTE
|
||||
}
|
||||
|
||||
fn new(screen: PipeScreenWithLdev) -> Option<Device> {
|
||||
if !Self::check_valid(&screen) {
|
||||
return None;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue