xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/cl/CLEventCL.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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 #include "libANGLE/cl_utils.h"
12 
13 namespace rx
14 {
15 
CLEventCL(const cl::Event & event,cl_event native)16 CLEventCL::CLEventCL(const cl::Event &event, cl_event native) : CLEventImpl(event), mNative(native)
17 {}
18 
~CLEventCL()19 CLEventCL::~CLEventCL()
20 {
21     if (mNative->getDispatch().clReleaseEvent(mNative) != CL_SUCCESS)
22     {
23         ERR() << "Error while releasing CL event";
24     }
25 }
26 
getCommandExecutionStatus(cl_int & executionStatus)27 angle::Result CLEventCL::getCommandExecutionStatus(cl_int &executionStatus)
28 {
29     ANGLE_CL_TRY(mNative->getDispatch().clGetEventInfo(mNative, CL_EVENT_COMMAND_EXECUTION_STATUS,
30                                                        sizeof(executionStatus), &executionStatus,
31                                                        nullptr));
32     return angle::Result::Continue;
33 }
34 
setUserEventStatus(cl_int executionStatus)35 angle::Result CLEventCL::setUserEventStatus(cl_int executionStatus)
36 {
37     ANGLE_CL_TRY(mNative->getDispatch().clSetUserEventStatus(mNative, executionStatus));
38     return angle::Result::Continue;
39 }
40 
setCallback(cl::Event & event,cl_int commandExecCallbackType)41 angle::Result CLEventCL::setCallback(cl::Event &event, cl_int commandExecCallbackType)
42 {
43     ANGLE_CL_TRY(mNative->getDispatch().clSetEventCallback(mNative, commandExecCallbackType,
44                                                            Callback, &event));
45     return angle::Result::Continue;
46 }
47 
getProfilingInfo(cl::ProfilingInfo name,size_t valueSize,void * value,size_t * valueSizeRet)48 angle::Result CLEventCL::getProfilingInfo(cl::ProfilingInfo name,
49                                           size_t valueSize,
50                                           void *value,
51                                           size_t *valueSizeRet)
52 {
53     ANGLE_CL_TRY(mNative->getDispatch().clGetEventProfilingInfo(mNative, cl::ToCLenum(name),
54                                                                 valueSize, value, valueSizeRet));
55     return angle::Result::Continue;
56 }
57 
Cast(const cl::EventPtrs & events)58 std::vector<cl_event> CLEventCL::Cast(const cl::EventPtrs &events)
59 {
60     std::vector<cl_event> nativeEvents;
61     nativeEvents.reserve(events.size());
62     for (const cl::EventPtr &event : events)
63     {
64         nativeEvents.emplace_back(event->getImpl<CLEventCL>().getNative());
65     }
66     return nativeEvents;
67 }
68 
Callback(cl_event event,cl_int commandStatus,void * userData)69 void CLEventCL::Callback(cl_event event, cl_int commandStatus, void *userData)
70 {
71     static_cast<cl::Event *>(userData)->callback(commandStatus);
72 }
73 
74 }  // namespace rx
75