[Beignet] [PATCH] runtime: fix bug in cl_enqueue_read_buffer.

Zhigang Gong zhigang.gong at intel.com
Wed Nov 12 21:42:53 PST 2014


If the buffer is a userptr buffer, we should copy it directly.
Otherwise, it fails in libdrm. As drm_intel_gem_bo_subdata() refuses
to read a userptr buffer object.

Signed-off-by: Zhigang Gong <zhigang.gong at intel.com>
---
 src/cl_enqueue.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/cl_enqueue.c b/src/cl_enqueue.c
index fcffd05..5798e20 100644
--- a/src/cl_enqueue.c
+++ b/src/cl_enqueue.c
@@ -31,13 +31,18 @@
 
 cl_int cl_enqueue_read_buffer(enqueue_data* data)
 {
+  cl_int err = CL_SUCCESS;
   cl_mem mem = data->mem_obj;
   assert(mem->type == CL_MEM_BUFFER_TYPE ||
          mem->type == CL_MEM_SUBBUFFER_TYPE);
   struct _cl_mem_buffer* buffer = (struct _cl_mem_buffer*)mem;
-
-  return cl_buffer_get_subdata(mem->bo, data->offset + buffer->sub_offset,
-			       data->size, data->ptr);
+  if (!mem->is_userptr) {
+    if (cl_buffer_get_subdata(mem->bo, data->offset + buffer->sub_offset,
+			       data->size, data->ptr) != 0)
+      err = CL_MAP_FAILURE;
+  } else
+    memcpy(data->ptr, (char*)mem->host_ptr + data->offset + buffer->sub_offset, data->size);
+  return err;
 }
 
 cl_int cl_enqueue_read_buffer_rect(enqueue_data* data)
-- 
1.8.3.2



More information about the Beignet mailing list