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 cl_int getInfo(CommandQueueInfo name,
28 size_t valueSize,
29 void *value,
30 size_t *valueSizeRet) const;
31
32 cl_int setProperty(CommandQueueProperties properties,
33 cl_bool enable,
34 cl_command_queue_properties *oldProperties);
35
36 cl_int 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 cl_int 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 cl_int enqueueReadBufferRect(cl_mem buffer,
55 cl_bool blockingRead,
56 const size_t *bufferOrigin,
57 const size_t *hostOrigin,
58 const size_t *region,
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 cl_int enqueueWriteBufferRect(cl_mem buffer,
69 cl_bool blockingWrite,
70 const size_t *bufferOrigin,
71 const size_t *hostOrigin,
72 const size_t *region,
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 cl_int 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 cl_int enqueueCopyBufferRect(cl_mem srcBuffer,
92 cl_mem dstBuffer,
93 const size_t *srcOrigin,
94 const size_t *dstOrigin,
95 const size_t *region,
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 cl_int 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 void *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 cl_int &errorCode);
122
123 cl_int enqueueReadImage(cl_mem image,
124 cl_bool blockingRead,
125 const size_t *origin,
126 const size_t *region,
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 cl_int enqueueWriteImage(cl_mem image,
135 cl_bool blockingWrite,
136 const size_t *origin,
137 const size_t *region,
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 cl_int enqueueCopyImage(cl_mem srcImage,
146 cl_mem dstImage,
147 const size_t *srcOrigin,
148 const size_t *dstOrigin,
149 const size_t *region,
150 cl_uint numEventsInWaitList,
151 const cl_event *eventWaitList,
152 cl_event *event);
153
154 cl_int enqueueFillImage(cl_mem image,
155 const void *fillColor,
156 const size_t *origin,
157 const size_t *region,
158 cl_uint numEventsInWaitList,
159 const cl_event *eventWaitList,
160 cl_event *event);
161
162 cl_int enqueueCopyImageToBuffer(cl_mem srcImage,
163 cl_mem dstBuffer,
164 const size_t *srcOrigin,
165 const size_t *region,
166 size_t dstOffset,
167 cl_uint numEventsInWaitList,
168 const cl_event *eventWaitList,
169 cl_event *event);
170
171 cl_int enqueueCopyBufferToImage(cl_mem srcBuffer,
172 cl_mem dstImage,
173 size_t srcOffset,
174 const size_t *dstOrigin,
175 const size_t *region,
176 cl_uint numEventsInWaitList,
177 const cl_event *eventWaitList,
178 cl_event *event);
179
180 void *enqueueMapImage(cl_mem image,
181 cl_bool blockingMap,
182 MapFlags mapFlags,
183 const size_t *origin,
184 const size_t *region,
185 size_t *imageRowPitch,
186 size_t *imageSlicePitch,
187 cl_uint numEventsInWaitList,
188 const cl_event *eventWaitList,
189 cl_event *event,
190 cl_int &errorCode);
191
192 cl_int enqueueUnmapMemObject(cl_mem memobj,
193 void *mappedPtr,
194 cl_uint numEventsInWaitList,
195 const cl_event *eventWaitList,
196 cl_event *event);
197
198 cl_int 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 cl_int enqueueNDRangeKernel(cl_kernel kernel,
206 cl_uint workDim,
207 const size_t *globalWorkOffset,
208 const size_t *globalWorkSize,
209 const size_t *localWorkSize,
210 cl_uint numEventsInWaitList,
211 const cl_event *eventWaitList,
212 cl_event *event);
213
214 cl_int enqueueTask(cl_kernel kernel,
215 cl_uint numEventsInWaitList,
216 const cl_event *eventWaitList,
217 cl_event *event);
218
219 cl_int enqueueNativeKernel(UserFunc userFunc,
220 void *args,
221 size_t cbArgs,
222 cl_uint numMemObjects,
223 const cl_mem *memList,
224 const void **argsMemLoc,
225 cl_uint numEventsInWaitList,
226 const cl_event *eventWaitList,
227 cl_event *event);
228
229 cl_int enqueueMarkerWithWaitList(cl_uint numEventsInWaitList,
230 const cl_event *eventWaitList,
231 cl_event *event);
232
233 cl_int enqueueMarker(cl_event *event);
234
235 cl_int enqueueWaitForEvents(cl_uint numEvents, const cl_event *eventList);
236
237 cl_int enqueueBarrierWithWaitList(cl_uint numEventsInWaitList,
238 const cl_event *eventWaitList,
239 cl_event *event);
240
241 cl_int enqueueBarrier();
242
243 cl_int flush();
244 cl_int finish();
245
246 public:
247 using PropArray = std::vector<cl_queue_properties>;
248
249 static constexpr cl_uint kNoSize = std::numeric_limits<cl_uint>::max();
250
251 ~CommandQueue() override;
252
253 Context &getContext();
254 const Context &getContext() const;
255 const Device &getDevice() const;
256
257 // Get index of device in the context.
258 size_t getDeviceIndex() const;
259
260 CommandQueueProperties getProperties() const;
261 bool isOnHost() const;
262 bool isOnDevice() const;
263
264 bool hasSize() const;
265 cl_uint getSize() const;
266
267 template <typename T = rx::CLCommandQueueImpl>
268 T &getImpl() const;
269
270 private:
271 CommandQueue(Context &context,
272 Device &device,
273 PropArray &&propArray,
274 CommandQueueProperties properties,
275 cl_uint size,
276 cl_int &errorCode);
277
278 CommandQueue(Context &context,
279 Device &device,
280 CommandQueueProperties properties,
281 cl_int &errorCode);
282
283 const ContextPtr mContext;
284 const DevicePtr mDevice;
285 const PropArray mPropArray;
286 angle::SynchronizedValue<CommandQueueProperties> mProperties;
287 const cl_uint mSize = kNoSize;
288 const rx::CLCommandQueueImpl::Ptr mImpl;
289
290 friend class Object;
291 };
292
getContext()293 inline Context &CommandQueue::getContext()
294 {
295 return *mContext;
296 }
297
getContext()298 inline const Context &CommandQueue::getContext() const
299 {
300 return *mContext;
301 }
302
getDevice()303 inline const Device &CommandQueue::getDevice() const
304 {
305 return *mDevice;
306 }
307
getProperties()308 inline CommandQueueProperties CommandQueue::getProperties() const
309 {
310 return *mProperties;
311 }
312
isOnHost()313 inline bool CommandQueue::isOnHost() const
314 {
315 return mProperties->isNotSet(CL_QUEUE_ON_DEVICE);
316 }
317
isOnDevice()318 inline bool CommandQueue::isOnDevice() const
319 {
320 return mProperties->isSet(CL_QUEUE_ON_DEVICE);
321 }
322
hasSize()323 inline bool CommandQueue::hasSize() const
324 {
325 return mSize != kNoSize;
326 }
327
getSize()328 inline cl_uint CommandQueue::getSize() const
329 {
330 return mSize;
331 }
332
333 template <typename T>
getImpl()334 inline T &CommandQueue::getImpl() const
335 {
336 return static_cast<T &>(*mImpl);
337 }
338
339 } // namespace cl
340
341 #endif // LIBANGLE_CLCOMMANDQUEUE_H_
342