rusticl/mem: properly handle buffers

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/10505
Fixes: 2645003bdc ("rusticl: Create CL mem objects from GL")
Signed-off-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27385>
This commit is contained in:
Karol Herbst 2024-01-31 12:26:40 +01:00 committed by Marge Bot
parent 727cddd338
commit 117291332c
2 changed files with 11 additions and 2 deletions

View file

@ -333,6 +333,7 @@ pub struct GLMemProps {
pub height: u16,
pub depth: u16,
pub width: u32,
pub offset: u32,
pub array_size: u16,
pub pixel_size: u8,
pub stride: u32,
@ -356,7 +357,7 @@ pub struct GLExportManager {
impl GLExportManager {
pub fn get_gl_mem_props(&self) -> CLResult<GLMemProps> {
let pixel_size = if self.is_gl_buffer() {
0
1
} else {
format_from_gl(self.export_out.internal_format)
.ok_or(CL_OUT_OF_HOST_MEMORY)?
@ -368,6 +369,7 @@ impl GLExportManager {
let mut depth = self.export_out.depth as u16;
let mut width = self.export_out.width;
let mut array_size = 1;
let mut offset = 0;
// some fixups
match self.export_in.target {
@ -383,6 +385,7 @@ impl GLExportManager {
GL_ARRAY_BUFFER => {
array_size = 1;
width = self.export_out.buf_size as u32;
offset = self.export_out.buf_offset as u32;
height = 1;
depth = 1;
}
@ -396,6 +399,7 @@ impl GLExportManager {
height: height,
depth: depth,
width: width,
offset: offset,
array_size: array_size,
pixel_size: pixel_size,
stride: self.export_out.stride,

View file

@ -508,6 +508,11 @@ impl Mem {
..Default::default()
};
// it's kinda not supported, but we want to know if anything actually hits this as it's
// certainly not tested by the CL CTS.
if mem_type != CL_MEM_OBJECT_BUFFER {
assert_eq!(gl_mem_props.offset, 0);
}
Ok(Arc::new(Self {
base: CLObjectBase::new(),
context: context,
@ -515,7 +520,7 @@ impl Mem {
mem_type: mem_type,
flags: flags,
size: gl_mem_props.size(),
offset: 0,
offset: gl_mem_props.offset as usize,
host_ptr: ptr::null_mut(),
image_format: image_format,
pipe_format: pipe_format,