[Beignet] [PATCH 2/2] Implement clEnqueueMapImage.

Dag Lem dag at nimrod.no
Fri May 17 09:06:14 PDT 2013


Signed-off-by: Dag Lem <dag at nimrod.no>
---
 src/cl_api.c   | 36 ++++++++++++++++++++++++++++++++++--
 src/cl_utils.h |  9 +++++++++
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/src/cl_api.c b/src/cl_api.c
index 3981554..daafbf0 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -1071,8 +1071,40 @@ clEnqueueMapImage(cl_command_queue   command_queue,
                   cl_event *         event,
                   cl_int *           errcode_ret)
 {
-  NOT_IMPLEMENTED;
-  return NULL;
+  void *ptr = NULL;
+  cl_int err = CL_SUCCESS;
+
+  CHECK_QUEUE(command_queue);
+  CHECK_IMAGE(image);
+  if (command_queue->ctx != image->ctx) {
+     err = CL_INVALID_CONTEXT;
+     goto error;
+  }
+
+  if (blocking_map != CL_TRUE)
+     NOT_IMPLEMENTED;
+
+  if (!origin || !region || origin[0] + region[0] > image->w || origin[1] + region[1] > image->h || origin[2] + region[2] > image->depth) {
+     err = CL_INVALID_VALUE;
+     goto error;
+  }
+
+  if (!image_row_pitch || (image->slice_pitch && !image_slice_pitch)) {
+     err = CL_INVALID_VALUE;
+     goto error;
+  }
+
+  *image_row_pitch = image->row_pitch;
+  if (image_slice_pitch)
+     *image_slice_pitch = image->slice_pitch;
+
+  size_t offset = origin[0]*image->bpp + origin[1]*image->row_pitch + origin[2]*image->slice_pitch;
+  ptr = (char*)cl_mem_map(image) + offset;
+
+error:
+  if (errcode_ret)
+     *errcode_ret = err;
+  return ptr;
 }
 
 cl_int
diff --git a/src/cl_utils.h b/src/cl_utils.h
index 4493858..dfb1369 100644
--- a/src/cl_utils.h
+++ b/src/cl_utils.h
@@ -130,6 +130,15 @@ do {                                                        \
   }                                                         \
 } while (0)
 
+#define CHECK_IMAGE(IMAGE)                                  \
+CHECK_MEM(image);                                           \
+do {                                                        \
+  if (UNLIKELY(!IMAGE->is_image)) {                         \
+    err = CL_INVALID_MEM_OBJECT;                            \
+    goto error;                                             \
+  }                                                         \
+} while (0)
+
 #define CHECK_SAMPLER(SAMPLER)                              \
 do {                                                        \
   if (UNLIKELY(SAMPLER == NULL)) {                          \
-- 
1.8.1.4



More information about the Beignet mailing list