1 //
2 // Copyright 2021 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // CLEventCL.cpp: Implements the class methods for CLEventCL.
7 
8 #include "libANGLE/renderer/cl/CLEventCL.h"
9 
10 #include "libANGLE/CLEvent.h"
11 
12 namespace rx
13 {
14 
CLEventCL(const cl::Event & event,cl_event native)15 CLEventCL::CLEventCL(const cl::Event &event, cl_event native) : CLEventImpl(event), mNative(native)
16 {}
17 
~CLEventCL()18 CLEventCL::~CLEventCL()
19 {
20     if (mNative->getDispatch().clReleaseEvent(mNative) != CL_SUCCESS)
21     {
22         ERR() << "Error while releasing CL event";
23     }
24 }
25 
getCommandExecutionStatus(cl_int & executionStatus)26 cl_int CLEventCL::getCommandExecutionStatus(cl_int &executionStatus)
27 {
28     return mNative->getDispatch().clGetEventInfo(mNative, CL_EVENT_COMMAND_EXECUTION_STATUS,
29                                                  sizeof(executionStatus), &executionStatus,
30                                                  nullptr);
31 }
32 
setUserEventStatus(cl_int executionStatus)33 cl_int CLEventCL::setUserEventStatus(cl_int executionStatus)
34 {
35     return mNative->getDispatch().clSetUserEventStatus(mNative, executionStatus);
36 }
37 
setCallback(cl::Event & event,cl_int commandExecCallbackType)38 cl_int CLEventCL::setCallback(cl::Event &event, cl_int commandExecCallbackType)
39 {
40     return mNative->getDispatch().clSetEventCallback(mNative, commandExecCallbackType, Callback,
41                                                      &event);
42 }
43 
getProfilingInfo(cl::ProfilingInfo name,size_t valueSize,void * value,size_t * valueSizeRet)44 cl_int CLEventCL::getProfilingInfo(cl::ProfilingInfo name,
45                                    size_t valueSize,
46                                    void *value,
47                                    size_t *valueSizeRet)
48 {
49     return mNative->getDispatch().clGetEventProfilingInfo(mNative, cl::ToCLenum(name), valueSize,
50                                                           value, valueSizeRet);
51 }
52 
Cast(const cl::EventPtrs & events)53 std::vector<cl_event> CLEventCL::Cast(const cl::EventPtrs &events)
54 {
55     std::vector<cl_event> nativeEvents;
56     nativeEvents.reserve(events.size());
57     for (const cl::EventPtr &event : events)
58     {
59         nativeEvents.emplace_back(event->getImpl<CLEventCL>().getNative());
60     }
61     return nativeEvents;
62 }
63 
Callback(cl_event event,cl_int commandStatus,void * userData)64 void CLEventCL::Callback(cl_event event, cl_int commandStatus, void *userData)
65 {
66     static_cast<cl::Event *>(userData)->callback(commandStatus);
67 }
68 
69 }  // namespace rx
70