diff options
author | Yang Rong <rong.r.yang@intel.com> | 2017-08-08 17:32:14 +0800 |
---|---|---|
committer | Yang Rong <rong.r.yang@intel.com> | 2017-09-21 17:42:50 +0800 |
commit | 311695221756990b1b2ba9dce6f2336388a2c6f5 (patch) | |
tree | fd7775ac817bdbef3004f3dfb3c05e30eb579e2d | |
parent | 757ccf02d6eac0f0281f2feb08a8bf1be6c27dfe (diff) |
Runtime: implement clEnqueueAcquireGLObjects and clEnqueueReleaseGLObjects.
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>
Reviewed-by: Ruiling Song <ruiling.song@intel.com>
-rw-r--r-- | src/cl_gl_api.c | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/src/cl_gl_api.c b/src/cl_gl_api.c index 897edb4e..61b3ab80 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; } |