cl/runtime: fixup 1D array image region and origins.
authorZhigang Gong <zhigang.gong@intel.com>
Wed, 18 Jun 2014 06:53:06 +0000 (14:53 +0800)
committerZhigang Gong <zhigang.gong@intel.com>
Fri, 20 Jun 2014 07:53:25 +0000 (15:53 +0800)
As we treat 1D array image as a 2d array image with height 1
internally, we need to fixup region and origins passed in
from external APIs.

Signed-off-by: Zhigang Gong <zhigang.gong@intel.com>
Reviewed-by: He Junyan <junyan.he@inbox.com>
src/cl_api.c
src/cl_utils.h

index c4a8730..3b118a8 100644 (file)
@@ -2065,8 +2065,8 @@ cl_int
 clEnqueueReadImage(cl_command_queue      command_queue,
                    cl_mem                mem,
                    cl_bool               blocking_read,
-                   const size_t *        origin,
-                   const size_t *        region,
+                   const size_t *        porigin,
+                   const size_t *        pregion,
                    size_t                row_pitch,
                    size_t                slice_pitch,
                    void *                ptr,
@@ -2079,6 +2079,8 @@ clEnqueueReadImage(cl_command_queue      command_queue,
 
   CHECK_QUEUE(command_queue);
   CHECK_IMAGE(mem, image);
+  FIXUP_IMAGE_REGION(image, pregion, region);
+  FIXUP_IMAGE_ORIGIN(image, porigin, origin);
   if (command_queue->ctx != mem->ctx) {
      err = CL_INVALID_CONTEXT;
      goto error;
@@ -2144,8 +2146,8 @@ cl_int
 clEnqueueWriteImage(cl_command_queue     command_queue,
                     cl_mem               mem,
                     cl_bool              blocking_write,
-                    const size_t *       origin,
-                    const size_t *       region,
+                    const size_t *       porigin,
+                    const size_t *       pregion,
                     size_t               row_pitch,
                     size_t               slice_pitch,
                     const void *         ptr,
@@ -2158,6 +2160,8 @@ clEnqueueWriteImage(cl_command_queue     command_queue,
 
   CHECK_QUEUE(command_queue);
   CHECK_IMAGE(mem, image);
+  FIXUP_IMAGE_REGION(image, pregion, region);
+  FIXUP_IMAGE_ORIGIN(image, porigin, origin);
   if (command_queue->ctx != mem->ctx) {
     err = CL_INVALID_CONTEXT;
     goto error;
@@ -2223,9 +2227,9 @@ cl_int
 clEnqueueCopyImage(cl_command_queue      command_queue,
                    cl_mem                src_mem,
                    cl_mem                dst_mem,
-                   const size_t *        src_origin,
-                   const size_t *        dst_origin,
-                   const size_t *        region,
+                   const size_t *        psrc_origin,
+                   const size_t *        pdst_origin,
+                   const size_t *        pregion,
                    cl_uint               num_events_in_wait_list,
                    const cl_event *      event_wait_list,
                    cl_event *            event)
@@ -2238,6 +2242,9 @@ clEnqueueCopyImage(cl_command_queue      command_queue,
   CHECK_QUEUE(command_queue);
   CHECK_IMAGE(src_mem, src_image);
   CHECK_IMAGE(dst_mem, dst_image);
+  FIXUP_IMAGE_REGION(src_image, pregion, region);
+  FIXUP_IMAGE_ORIGIN(src_image, psrc_origin, src_origin);
+  FIXUP_IMAGE_ORIGIN(dst_image, pdst_origin, dst_origin);
   if (command_queue->ctx != src_mem->ctx ||
       command_queue->ctx != dst_mem->ctx) {
     err = CL_INVALID_CONTEXT;
@@ -2307,8 +2314,8 @@ cl_int
 clEnqueueCopyImageToBuffer(cl_command_queue  command_queue,
                            cl_mem            src_mem,
                            cl_mem            dst_buffer,
-                           const size_t *    src_origin,
-                           const size_t *    region,
+                           const size_t *    psrc_origin,
+                           const size_t *    pregion,
                            size_t            dst_offset,
                            cl_uint           num_events_in_wait_list,
                            const cl_event *  event_wait_list,
@@ -2320,6 +2327,8 @@ clEnqueueCopyImageToBuffer(cl_command_queue  command_queue,
   CHECK_QUEUE(command_queue);
   CHECK_IMAGE(src_mem, src_image);
   CHECK_MEM(dst_buffer);
+  FIXUP_IMAGE_REGION(src_image, pregion, region);
+  FIXUP_IMAGE_ORIGIN(src_image, psrc_origin, src_origin);
   if (command_queue->ctx != src_mem->ctx ||
       command_queue->ctx != dst_buffer->ctx) {
     err = CL_INVALID_CONTEXT;
@@ -2372,8 +2381,8 @@ clEnqueueCopyBufferToImage(cl_command_queue  command_queue,
                            cl_mem            src_buffer,
                            cl_mem            dst_mem,
                            size_t            src_offset,
-                           const size_t *    dst_origin,
-                           const size_t *    region,
+                           const size_t *    pdst_origin,
+                           const size_t *    pregion,
                            cl_uint           num_events_in_wait_list,
                            const cl_event *  event_wait_list,
                            cl_event *        event)
@@ -2384,6 +2393,8 @@ clEnqueueCopyBufferToImage(cl_command_queue  command_queue,
   CHECK_QUEUE(command_queue);
   CHECK_MEM(src_buffer);
   CHECK_IMAGE(dst_mem, dst_image);
+  FIXUP_IMAGE_REGION(dst_image, pregion, region);
+  FIXUP_IMAGE_ORIGIN(dst_image, pdst_origin, dst_origin);
   if (command_queue->ctx != src_buffer->ctx ||
       command_queue->ctx != dst_mem->ctx) {
     err = CL_INVALID_CONTEXT;
@@ -2575,8 +2586,8 @@ clEnqueueMapImage(cl_command_queue   command_queue,
                   cl_mem             mem,
                   cl_bool            blocking_map,
                   cl_map_flags       map_flags,
-                  const size_t *     origin,
-                  const size_t *     region,
+                  const size_t *     porigin,
+                  const size_t *     pregion,
                   size_t *           image_row_pitch,
                   size_t *           image_slice_pitch,
                   cl_uint            num_events_in_wait_list,
@@ -2591,6 +2602,8 @@ clEnqueueMapImage(cl_command_queue   command_queue,
 
   CHECK_QUEUE(command_queue);
   CHECK_IMAGE(mem, image);
+  FIXUP_IMAGE_REGION(image, pregion, region);
+  FIXUP_IMAGE_ORIGIN(image, porigin, origin);
   if (command_queue->ctx != mem->ctx) {
     err = CL_INVALID_CONTEXT;
     goto error;
index fa900a7..26cf329 100644 (file)
@@ -149,6 +149,35 @@ do {                                                        \
 struct _cl_mem_image *IMAGE;                                \
 IMAGE = cl_mem_image(MEM);                                  \
 
+#define FIXUP_IMAGE_REGION(IMAGE, PREGION, REGION)          \
+const size_t *REGION;                                       \
+size_t REGION ##_REC[3];                                    \
+do {                                                        \
+  if (IMAGE->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY) {   \
+    REGION ##_REC[0] = PREGION[0];                          \
+    REGION ##_REC[1] = 1;                                   \
+    REGION ##_REC[2] = PREGION[1];                          \
+    REGION = REGION ##_REC;                                 \
+  } else {                                                  \
+    REGION = PREGION;                                       \
+  }                                                         \
+} while(0)
+
+#define FIXUP_IMAGE_ORIGIN(IMAGE, PREGION, REGION)          \
+const size_t *REGION;                                       \
+size_t REGION ##_REC[3];                                    \
+do {                                                        \
+  if (IMAGE->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY) {   \
+    REGION ##_REC[0] = PREGION[0];                          \
+    REGION ##_REC[1] = 0;                                   \
+    REGION ##_REC[2] = PREGION[1];                          \
+    REGION = REGION ##_REC;                                 \
+  } else {                                                  \
+    REGION = PREGION;                                       \
+  }                                                         \
+} while(0)
+
+
 #define CHECK_EVENT(EVENT)                                    \
   do {                                                        \
     if (UNLIKELY(EVENT == NULL)) {                            \