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 // CLCommandQueue.h: Defines the cl::CommandQueue class, which can be used to queue a set of OpenCL
7 // operations.
8
9 #ifndef LIBANGLE_CLCOMMANDQUEUE_H_
10 #define LIBANGLE_CLCOMMANDQUEUE_H_
11
12 #include "libANGLE/CLObject.h"
13 #include "libANGLE/renderer/CLCommandQueueImpl.h"
14
15 #include "common/SynchronizedValue.h"
16
17 #include <limits>
18
19 namespace cl
20 {
21
22 class CommandQueue final : public _cl_command_queue, public Object
23 {
24 public:
25 // Front end entry functions, only called from OpenCL entry points
26
27 angle::Result getInfo(CommandQueueInfo name,
28 size_t valueSize,
29 void *value,
30 size_t *valueSizeRet) const;
31
32 angle::Result setProperty(CommandQueueProperties properties,
33 cl_bool enable,
34 cl_command_queue_properties *oldProperties);
35
36 angle::Result enqueueReadBuffer(cl_mem buffer,
37 cl_bool blockingRead,
38 size_t offset,
39 size_t size,
40 void *ptr,
41 cl_uint numEventsInWaitList,
42 const cl_event *eventWaitList,
43 cl_event *event);
44
45 angle::Result enqueueWriteBuffer(cl_mem buffer,
46 cl_bool blockingWrite,
47 size_t offset,
48 size_t size,
49 const void *ptr,
50 cl_uint numEventsInWaitList,
51 const cl_event *eventWaitList,
52 cl_event *event);
53
54 angle::Result enqueueReadBufferRect(cl_mem buffer,
55 cl_bool blockingRead,
56 const cl::MemOffsets &bufferOrigin,
57 const cl::MemOffsets &hostOrigin,
58 const cl::Coordinate ®ion,
59 size_t bufferRowPitch,
60 size_t bufferSlicePitch,
61 size_t hostRowPitch,
62 size_t hostSlicePitch,
63 void *ptr,
64 cl_uint numEventsInWaitList,
65 const cl_event *eventWaitList,
66 cl_event *event);
67
68 angle::Result enqueueWriteBufferRect(cl_mem buffer,
69 cl_bool blockingWrite,
70 const cl::MemOffsets &bufferOrigin,
71 const cl::MemOffsets &hostOrigin,
72 const cl::Coordinate ®ion,
73 size_t bufferRowPitch,
74 size_t bufferSlicePitch,
75 size_t hostRowPitch,
76 size_t hostSlicePitch,
77 const void *ptr,
78 cl_uint numEventsInWaitList,
79 const cl_event *eventWaitList,
80 cl_event *event);
81
82 angle::Result enqueueCopyBuffer(cl_mem srcBuffer,
83 cl_mem dstBuffer,
84 size_t srcOffset,
85 size_t dstOffset,
86 size_t size,
87 cl_uint numEventsInWaitList,
88 const cl_event *eventWaitList,
89 cl_event *event);
90
91 angle::Result enqueueCopyBufferRect(cl_mem srcBuffer,
92 cl_mem dstBuffer,
93 const cl::MemOffsets &srcOrigin,
94 const cl::MemOffsets &dstOrigin,
95 const cl::Coordinate ®ion,
96 size_t srcRowPitch,
97 size_t srcSlicePitch,
98 size_t dstRowPitch,
99 size_t dstSlicePitch,
100 cl_uint numEventsInWaitList,
101 const cl_event *eventWaitList,
102 cl_event *event);
103
104 angle::Result enqueueFillBuffer(cl_mem buffer,
105 const void *pattern,
106 size_t patternSize,
107 size_t offset,
108 size_t size,
109 cl_uint numEventsInWaitList,
110 const cl_event *eventWaitList,
111 cl_event *event);
112
113 angle::Result enqueueMapBuffer(cl_mem buffer,
114 cl_bool blockingMap,
115 MapFlags mapFlags,
116 size_t offset,
117 size_t size,
118 cl_uint numEventsInWaitList,
119 const cl_event *eventWaitList,
120 cl_event *event,
121 void *&mapPtr);
122
123 angle::Result enqueueReadImage(cl_mem image,
124 cl_bool blockingRead,
125 const cl::MemOffsets &origin,
126 const cl::Coordinate ®ion,
127 size_t rowPitch,
128 size_t slicePitch,
129 void *ptr,
130 cl_uint numEventsInWaitList,
131 const cl_event *eventWaitList,
132 cl_event *event);
133
134 angle::Result enqueueWriteImage(cl_mem image,
135 cl_bool blockingWrite,
136 const cl::MemOffsets &origin,
137 const cl::Coordinate ®ion,
138 size_t inputRowPitch,
139 size_t inputSlicePitch,
140 const void *ptr,
141 cl_uint numEventsInWaitList,
142 const cl_event *eventWaitList,
143 cl_event *event);
144
145 angle::Result enqueueCopyImage(cl_mem srcImage,
146 cl_mem dstImage,
147 const cl::MemOffsets &srcOrigin,
148 const cl::MemOffsets &dstOrigin,
149 const cl::Coordinate ®ion,
150 cl_uint numEventsInWaitList,
151 const cl_event *eventWaitList,
152 cl_event *event);
153
154 angle::Result enqueueFillImage(cl_mem image,
155 const void *fillColor,
156 const cl::MemOffsets &origin,
157 const cl::Coordinate ®ion,
158 cl_uint numEventsInWaitList,
159 const cl_event *eventWaitList,
160 cl_event *event);
161
162 angle::Result enqueueCopyImageToBuffer(cl_mem srcImage,
163 cl_mem dstBuffer,
164 const cl::MemOffsets &srcOrigin,
165 const cl::Coordinate ®ion,
166 size_t dstOffset,
167 cl_uint numEventsInWaitList,
168 const cl_event *eventWaitList,
169 cl_event *event);
170
171 angle::Result enqueueCopyBufferToImage(cl_mem srcBuffer,
172 cl_mem dstImage,
173 size_t srcOffset,
174 const cl::MemOffsets &dstOrigin,
175 const cl::Coordinate ®ion,
176 cl_uint numEventsInWaitList,
177 const cl_event *eventWaitList,
178 cl_event *event);
179
180 angle::Result enqueueMapImage(cl_mem image,
181 cl_bool blockingMap,
182 MapFlags mapFlags,
183 const cl::MemOffsets &origin,
184 const cl::Coordinate ®ion,
185 size_t *imageRowPitch,
186 size_t *imageSlicePitch,
187 cl_uint numEventsInWaitList,
188 const cl_event *eventWaitList,
189 cl_event *event,
190 void *&mapPtr);
191
192 angle::Result enqueueUnmapMemObject(cl_mem memobj,
193 void *mappedPtr,
194 cl_uint numEventsInWaitList,
195 const cl_event *eventWaitList,
196 cl_event *event);
197
198 angle::Result enqueueMigrateMemObjects(cl_uint numMemObjects,
199 const cl_mem *memObjects,
200 MemMigrationFlags flags,
201 cl_uint numEventsInWaitList,
202 const cl_event *eventWaitList,
203 cl_event *event);
204
205 angle::Result enqueueNDRangeKernel(cl_kernel kernel,
206 const NDRange &ndrange,
207 cl_uint numEventsInWaitList,
208 const cl_event *eventWaitList,
209 cl_event *event);
210
211 angle::Result enqueueTask(cl_kernel kernel,
212 cl_uint numEventsInWaitList,
213 const cl_event *eventWaitList,
214 cl_event *event);
215
216 angle::Result enqueueNativeKernel(UserFunc userFunc,
217 void *args,
218 size_t cbArgs,
219 cl_uint numMemObjects,
220 const cl_mem *memList,
221 const void **argsMemLoc,
222 cl_uint numEventsInWaitList,
223 const cl_event *eventWaitList,
224 cl_event *event);
225
226 angle::Result enqueueMarkerWithWaitList(cl_uint numEventsInWaitList,
227 const cl_event *eventWaitList,
228 cl_event *event);
229
230 angle::Result enqueueMarker(cl_event *event);
231
232 angle::Result enqueueWaitForEvents(cl_uint numEvents, const cl_event *eventList);
233
234 angle::Result enqueueBarrierWithWaitList(cl_uint numEventsInWaitList,
235 const cl_event *eventWaitList,
236 cl_event *event);
237
238 angle::Result enqueueBarrier();
239
240 angle::Result flush();
241 angle::Result finish();
242
243 public:
244 using PropArray = std::vector<cl_queue_properties>;
245
246 static constexpr cl_uint kNoSize = std::numeric_limits<cl_uint>::max();
247
248 ~CommandQueue() override;
249
250 Context &getContext();
251 const Context &getContext() const;
252 const Device &getDevice() const;
253
254 // Get index of device in the context.
255 size_t getDeviceIndex() const;
256
257 CommandQueueProperties getProperties() const;
258 bool isOnHost() const;
259 bool isOnDevice() const;
260
261 bool hasSize() const;
262 cl_uint getSize() const;
263
264 template <typename T = rx::CLCommandQueueImpl>
265 T &getImpl() const;
266
267 private:
268 CommandQueue(Context &context,
269 Device &device,
270 PropArray &&propArray,
271 CommandQueueProperties properties,
272 cl_uint size);
273
274 CommandQueue(Context &context, Device &device, CommandQueueProperties properties);
275
276 const ContextPtr mContext;
277 const DevicePtr mDevice;
278 const PropArray mPropArray;
279 angle::SynchronizedValue<CommandQueueProperties> mProperties;
280 const cl_uint mSize = kNoSize;
281 rx::CLCommandQueueImpl::Ptr mImpl;
282
283 friend class Object;
284 };
285
getContext()286 inline Context &CommandQueue::getContext()
287 {
288 return *mContext;
289 }
290
getContext()291 inline const Context &CommandQueue::getContext() const
292 {
293 return *mContext;
294 }
295
getDevice()296 inline const Device &CommandQueue::getDevice() const
297 {
298 return *mDevice;
299 }
300
getProperties()301 inline CommandQueueProperties CommandQueue::getProperties() const
302 {
303 return *mProperties;
304 }
305
isOnHost()306 inline bool CommandQueue::isOnHost() const
307 {
308 return mProperties->isNotSet(CL_QUEUE_ON_DEVICE);
309 }
310
isOnDevice()311 inline bool CommandQueue::isOnDevice() const
312 {
313 return mProperties->isSet(CL_QUEUE_ON_DEVICE);
314 }
315
hasSize()316 inline bool CommandQueue::hasSize() const
317 {
318 return mSize != kNoSize;
319 }
320
getSize()321 inline cl_uint CommandQueue::getSize() const
322 {
323 return mSize;
324 }
325
326 template <typename T>
getImpl()327 inline T &CommandQueue::getImpl() const
328 {
329 return static_cast<T &>(*mImpl);
330 }
331
332 } // namespace cl
333
334 #endif // LIBANGLE_CLCOMMANDQUEUE_H_
335