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 // CLEvent.h: Defines the cl::Event class, which can be used to track the execution status of an
7 // OpenCL command.
8
9 #ifndef LIBANGLE_CLEVENT_H_
10 #define LIBANGLE_CLEVENT_H_
11
12 #include "libANGLE/CLObject.h"
13 #include "libANGLE/renderer/CLEventImpl.h"
14
15 #include "common/SynchronizedValue.h"
16
17 #include <array>
18
19 namespace cl
20 {
21
22 class Event final : public _cl_event, public Object
23 {
24 public:
25 // Front end entry functions, only called from OpenCL entry points
26
27 angle::Result setUserEventStatus(cl_int executionStatus);
28
29 angle::Result getInfo(EventInfo name,
30 size_t valueSize,
31 void *value,
32 size_t *valueSizeRet) const;
33
34 angle::Result setCallback(cl_int commandExecCallbackType, EventCB pfnNotify, void *userData);
35
36 angle::Result getProfilingInfo(ProfilingInfo name,
37 size_t valueSize,
38 void *value,
39 size_t *valueSizeRet);
40
41 public:
42 ~Event() override;
43
44 Context &getContext();
45 const Context &getContext() const;
46 const CommandQueuePtr &getCommandQueue() const;
47 cl_command_type getCommandType() const;
48 bool wasStatusChanged() const;
49
50 template <typename T = rx::CLEventImpl>
51 T &getImpl() const;
52
53 void callback(cl_int commandStatus);
54
55 static EventPtrs Cast(cl_uint numEvents, const cl_event *eventList);
56
57 private:
58 using CallbackData = std::pair<EventCB, void *>;
59 using Callbacks = std::vector<CallbackData>;
60
61 Event(Context &context);
62
63 Event(CommandQueue &queue,
64 cl_command_type commandType,
65 const rx::CLEventImpl::CreateFunc &createFunc);
66
67 const ContextPtr mContext;
68 const CommandQueuePtr mCommandQueue;
69 const cl_command_type mCommandType;
70 rx::CLEventImpl::Ptr mImpl;
71
72 bool mStatusWasChanged = false;
73
74 // Create separate storage for each possible callback type.
75 static_assert(CL_COMPLETE == 0 && CL_RUNNING == 1 && CL_SUBMITTED == 2,
76 "OpenCL command execution status values are not as assumed");
77 angle::SynchronizedValue<std::array<Callbacks, 3u>> mCallbacks;
78
79 friend class Object;
80 };
81
getContext()82 inline Context &Event::getContext()
83 {
84 return *mContext;
85 }
86
getContext()87 inline const Context &Event::getContext() const
88 {
89 return *mContext;
90 }
91
getCommandQueue()92 inline const CommandQueuePtr &Event::getCommandQueue() const
93 {
94 return mCommandQueue;
95 }
96
getCommandType()97 inline cl_command_type Event::getCommandType() const
98 {
99 return mCommandType;
100 }
101
wasStatusChanged()102 inline bool Event::wasStatusChanged() const
103 {
104 return mStatusWasChanged;
105 }
106
107 template <typename T>
getImpl()108 inline T &Event::getImpl() const
109 {
110 return static_cast<T &>(*mImpl);
111 }
112
113 } // namespace cl
114
115 #endif // LIBANGLE_CLEVENT_H_
116