[Beignet] [PATCH] Apply image offset to read/write/map operations

Mark Thompson sw at jkqxz.net
Mon Aug 29 22:12:33 UTC 2016


---
Hi,

My use-case for this is to allow read/write/map on images created from buffers.  This is helpful for interoperability with VAAPI (i965) because the driver there wants an incoming image to be a single DRM object, even if it has multiple planes: making a single buffer and then creating images within that buffer satisfies this constraint, but without this patch planes with an offset from the start of the buffer do not work correctly.

I am somewhat dubious about this patch and would welcome thoughts about the use-case - it seems like what I have could interact badly with some other part of the system I'm not aware of, though it does work nicely for the specific case.

Tested and working on Haswell GT2 (4500U) and Skylake GT2 (6300).

Thanks,

- Mark


 src/cl_enqueue.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/cl_enqueue.c b/src/cl_enqueue.c
index 081ffce..54c0ffa 100644
--- a/src/cl_enqueue.c
+++ b/src/cl_enqueue.c
@@ -204,7 +204,7 @@ cl_int cl_enqueue_read_image(enqueue_data *data)
     goto error;
   }

-  size_t offset = image->bpp*origin[0] + image->row_pitch*origin[1] + image->slice_pitch*origin[2];
+  size_t offset = image->offset + image->bpp*origin[0] + image->row_pitch*origin[1] + image->slice_pitch*origin[2];
   src_ptr = (char*)src_ptr + offset;

   if (!origin[0] && region[0] == image->w && data->row_pitch == image->row_pitch &&
@@ -246,8 +246,8 @@ cl_int cl_enqueue_write_image(enqueue_data *data)
     err = CL_MAP_FAILURE;
     goto error;
   }
-  //dst need to add offset
-  cl_mem_copy_image_region(data->origin, data->region, dst_ptr,
+  cl_mem_copy_image_region(data->origin, data->region,
+                           dst_ptr + image->offset,
                            image->row_pitch, image->slice_pitch,
                            data->const_ptr, data->row_pitch,
                            data->slice_pitch, image, CL_TRUE, CL_FALSE);
@@ -311,7 +311,7 @@ cl_int cl_enqueue_map_image(enqueue_data *data)
     err = CL_MAP_FAILURE;
     goto error;
   }
-  data->ptr = ptr;
+  data->ptr = (char*)ptr + image->offset;
   if (image->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY)
     row_pitch = image->slice_pitch;
   else
-- 
2.9.3



More information about the Beignet mailing list