[V2] Runtime: implement clEnqueueAcquireGLObjects and clEnqueueReleaseGLObjects.

Submitted by Yang, Rong R on Aug. 8, 2017, 10:04 a.m.

Details

Message ID 1502186680-9961-1-git-send-email-rong.r.yang@intel.com
State New
Headers show
Series "Runtime: implement clEnqueueAcquireGLObjects and clEnqueueReleaseGLObjects." ( rev: 2 ) in Beignet

Not browsing as part of any series.

Commit Message

Yang, Rong R Aug. 8, 2017, 10:04 a.m.
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.

V2: V1 is wrong version, correct it.
Signed-off-by: Yang Rong <rong.r.yang@intel.com>
---
 src/cl_gl_api.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 150 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/cl_gl_api.c b/src/cl_gl_api.c
index 897edb4..61b3ab8 100644
--- a/src/cl_gl_api.c
+++ b/src/cl_gl_api.c
@@ -35,6 +35,8 @@ 
 #include "cl_sampler.h"
 #include "cl_alloc.h"
 #include "cl_utils.h"
+#include "cl_enqueue.h"
+#include "cl_event.h"
 
 #include "CL/cl.h"
 #include "CL/cl_gl.h"
@@ -134,6 +136,80 @@  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;
+    }
+
+    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 +222,79 @@  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;
+    }
+
+    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;
 }