[Beignet] [PATCH] Runtime: implement clEnqueueAcquireGLObjects and clEnqueueReleaseGLObjects.

Yang Rong rong.r.yang at intel.com
Tue Aug 8 09:43:35 UTC 2017


As the application is responsible for synchronizing access to shared
objects, before call clEnqueueAcquireGLObjects, GL's use has been
finished, so just set the event status. clEnqueueReleaseGLObjects is
same.

Signed-off-by: Yang Rong <rong.r.yang at intel.com>
---
 src/cl_gl_api.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 158 insertions(+)

diff --git a/src/cl_gl_api.c b/src/cl_gl_api.c
index 897edb4..54041cf 100644
--- a/src/cl_gl_api.c
+++ b/src/cl_gl_api.c
@@ -134,6 +134,85 @@ cl_int clEnqueueAcquireGLObjects (cl_command_queue command_queue,
                                   cl_event *event)
 {
   cl_int err = CL_SUCCESS;
+  cl_int e_status, i;
+  cl_event e = NULL;
+  enqueue_data *data = NULL;
+
+  do {
+    if (!CL_OBJECT_IS_COMMAND_QUEUE(command_queue)) {
+      err = CL_INVALID_COMMAND_QUEUE;
+      break;
+    }
+
+    if (UNLIKELY(command_queue->ctx->props.gl_type == CL_GL_NOSHARE)) {
+      err = CL_INVALID_CONTEXT;
+      break;
+    }
+
+    if ((num_objects == 0 && mem_objects != NULL) ||
+        (num_objects > 0 && mem_objects == NULL)) {
+      err = CL_INVALID_VALUE;
+      break;
+    }
+
+    if (!CL_OBJECT_IS_MEM(mem)) {
+      err = CL_INVALID_MEM_OBJECT;
+      break;
+    }
+
+    for (i == 0; i < num_objects; i++) {
+      if (!cl_mem_image(mem_objects[i])) {
+        err = CL_INVALID_MEM_OBJECT;
+        break;
+      }
+      if (!IS_GL_IMAGE(mem_objects[i])) {
+        err = CL_INVALID_GL_OBJECT;
+        break;
+      }
+    }
+    if (err != CL_SUCCESS) {
+      break;
+    }
+
+    err = cl_event_check_waitlist(num_events_in_wait_list, event_wait_list,
+                                  event, command_queue->ctx);
+    if (err != CL_SUCCESS) {
+      break;
+    }
+
+    e = cl_event_create(command_queue->ctx, command_queue, num_events_in_wait_list,
+                        event_wait_list, CL_COMMAND_ACQUIRE_GL_OBJECTS, &err);
+    if (err != CL_SUCCESS) {
+      break;
+    }
+
+    e_status = cl_event_is_ready(e);
+
+    data = &e->exec_data;
+    data->type = EnqueueReturnSuccesss;
+
+    if (e_status == CL_COMPLETE) {
+      // Sync mode, no need to queue event.
+      err = cl_event_exec(e, CL_COMPLETE, CL_FALSE);
+      if (err != CL_SUCCESS) {
+        break;
+      }
+    } else {
+      err = cl_event_exec(e, CL_SUBMITTED, CL_TRUE); // Submit to get the address.
+      if (err != CL_SUCCESS) {
+        break;
+      }
+
+      cl_command_queue_enqueue_event(command_queue, e);
+    }
+  } while (0);
+
+  if (err == CL_SUCCESS && event) {
+    *event = e;
+  } else {
+    cl_event_delete(e);
+  }
+
   return err;
 }
 
@@ -146,5 +225,84 @@ cl_int clEnqueueReleaseGLObjects (cl_command_queue command_queue,
                                   cl_event *event)
 {
   cl_int err = CL_SUCCESS;
+  cl_int e_status, i;
+  cl_event e = NULL;
+  enqueue_data *data = NULL;
+
+  do {
+    if (!CL_OBJECT_IS_COMMAND_QUEUE(command_queue)) {
+      err = CL_INVALID_COMMAND_QUEUE;
+      break;
+    }
+
+    if (UNLIKELY(command_queue->ctx->props.gl_type == CL_GL_NOSHARE)) {
+      err = CL_INVALID_CONTEXT;
+      break;
+    }
+
+    if ((num_objects == 0 && mem_objects != NULL) ||
+        (num_objects > 0 && mem_objects == NULL)) {
+      err = CL_INVALID_VALUE;
+      break;
+    }
+
+    if (!CL_OBJECT_IS_MEM(mem)) {
+      err = CL_INVALID_MEM_OBJECT;
+      break;
+    }
+
+    for (i == 0; i < num_objects; i++) {
+      if (!cl_mem_image(mem_objects[i])) {
+        err = CL_INVALID_MEM_OBJECT;
+        break;
+      }
+      if (!IS_GL_IMAGE(mem_objects[i])) {
+        err = CL_INVALID_GL_OBJECT;
+        break;
+      }
+    }
+    if (err != CL_SUCCESS) {
+      break;
+    }
+
+    err = cl_event_check_waitlist(num_events_in_wait_list, event_wait_list,
+                                  event, command_queue->ctx);
+    if (err != CL_SUCCESS) {
+      break;
+    }
+
+    e = cl_event_create(command_queue->ctx, command_queue, num_events_in_wait_list,
+                        event_wait_list, CL_COMMAND_ACQUIRE_GL_OBJECTS, &err);
+    if (err != CL_SUCCESS) {
+      break;
+    }
+
+    e_status = cl_event_is_ready(e);
+
+    data = &e->exec_data;
+    data->type = EnqueueReturnSuccesss;
+
+    if (e_status == CL_COMPLETE) {
+      // Sync mode, no need to queue event.
+      err = cl_event_exec(e, CL_COMPLETE, CL_FALSE);
+      if (err != CL_SUCCESS) {
+        break;
+      }
+    } else {
+      err = cl_event_exec(e, CL_SUBMITTED, CL_TRUE); // Submit to get the address.
+      if (err != CL_SUCCESS) {
+        break;
+      }
+
+      cl_command_queue_enqueue_event(command_queue, e);
+    }
+  } while (0);
+
+  if (err == CL_SUCCESS && event) {
+    *event = e;
+  } else {
+    cl_event_delete(e);
+  }
+
   return err;
 }
-- 
2.1.4



More information about the Beignet mailing list