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 // CLCommandQueueImpl.h: Defines the abstract rx::CLCommandQueueImpl class.
7 
8 #ifndef LIBANGLE_RENDERER_CLCOMMANDQUEUEIMPL_H_
9 #define LIBANGLE_RENDERER_CLCOMMANDQUEUEIMPL_H_
10 
11 #include "libANGLE/renderer/CLEventImpl.h"
12 
13 namespace rx
14 {
15 
16 class CLCommandQueueImpl : angle::NonCopyable
17 {
18   public:
19     using Ptr = std::unique_ptr<CLCommandQueueImpl>;
20 
21     CLCommandQueueImpl(const cl::CommandQueue &commandQueue);
22     virtual ~CLCommandQueueImpl();
23 
24     virtual cl_int setProperty(cl::CommandQueueProperties properties, cl_bool enable) = 0;
25 
26     virtual cl_int enqueueReadBuffer(const cl::Buffer &buffer,
27                                      bool blocking,
28                                      size_t offset,
29                                      size_t size,
30                                      void *ptr,
31                                      const cl::EventPtrs &waitEvents,
32                                      CLEventImpl::CreateFunc *eventCreateFunc) = 0;
33 
34     virtual cl_int enqueueWriteBuffer(const cl::Buffer &buffer,
35                                       bool blocking,
36                                       size_t offset,
37                                       size_t size,
38                                       const void *ptr,
39                                       const cl::EventPtrs &waitEvents,
40                                       CLEventImpl::CreateFunc *eventCreateFunc) = 0;
41 
42     virtual cl_int enqueueReadBufferRect(const cl::Buffer &buffer,
43                                          bool blocking,
44                                          const size_t bufferOrigin[3],
45                                          const size_t hostOrigin[3],
46                                          const size_t region[3],
47                                          size_t bufferRowPitch,
48                                          size_t bufferSlicePitch,
49                                          size_t hostRowPitch,
50                                          size_t hostSlicePitch,
51                                          void *ptr,
52                                          const cl::EventPtrs &waitEvents,
53                                          CLEventImpl::CreateFunc *eventCreateFunc) = 0;
54 
55     virtual cl_int enqueueWriteBufferRect(const cl::Buffer &buffer,
56                                           bool blocking,
57                                           const size_t bufferOrigin[3],
58                                           const size_t hostOrigin[3],
59                                           const size_t region[3],
60                                           size_t bufferRowPitch,
61                                           size_t bufferSlicePitch,
62                                           size_t hostRowPitch,
63                                           size_t hostSlicePitch,
64                                           const void *ptr,
65                                           const cl::EventPtrs &waitEvents,
66                                           CLEventImpl::CreateFunc *eventCreateFunc) = 0;
67 
68     virtual cl_int enqueueCopyBuffer(const cl::Buffer &srcBuffer,
69                                      const cl::Buffer &dstBuffer,
70                                      size_t srcOffset,
71                                      size_t dstOffset,
72                                      size_t size,
73                                      const cl::EventPtrs &waitEvents,
74                                      CLEventImpl::CreateFunc *eventCreateFunc) = 0;
75 
76     virtual cl_int enqueueCopyBufferRect(const cl::Buffer &srcBuffer,
77                                          const cl::Buffer &dstBuffer,
78                                          const size_t srcOrigin[3],
79                                          const size_t dstOrigin[3],
80                                          const size_t region[3],
81                                          size_t srcRowPitch,
82                                          size_t srcSlicePitch,
83                                          size_t dstRowPitch,
84                                          size_t dstSlicePitch,
85                                          const cl::EventPtrs &waitEvents,
86                                          CLEventImpl::CreateFunc *eventCreateFunc) = 0;
87 
88     virtual cl_int enqueueFillBuffer(const cl::Buffer &buffer,
89                                      const void *pattern,
90                                      size_t patternSize,
91                                      size_t offset,
92                                      size_t size,
93                                      const cl::EventPtrs &waitEvents,
94                                      CLEventImpl::CreateFunc *eventCreateFunc) = 0;
95 
96     virtual void *enqueueMapBuffer(const cl::Buffer &buffer,
97                                    bool blocking,
98                                    cl::MapFlags mapFlags,
99                                    size_t offset,
100                                    size_t size,
101                                    const cl::EventPtrs &waitEvents,
102                                    CLEventImpl::CreateFunc *eventCreateFunc,
103                                    cl_int &errorCode) = 0;
104 
105     virtual cl_int enqueueReadImage(const cl::Image &image,
106                                     bool blocking,
107                                     const size_t origin[3],
108                                     const size_t region[3],
109                                     size_t rowPitch,
110                                     size_t slicePitch,
111                                     void *ptr,
112                                     const cl::EventPtrs &waitEvents,
113                                     CLEventImpl::CreateFunc *eventCreateFunc) = 0;
114 
115     virtual cl_int enqueueWriteImage(const cl::Image &image,
116                                      bool blocking,
117                                      const size_t origin[3],
118                                      const size_t region[3],
119                                      size_t inputRowPitch,
120                                      size_t inputSlicePitch,
121                                      const void *ptr,
122                                      const cl::EventPtrs &waitEvents,
123                                      CLEventImpl::CreateFunc *eventCreateFunc) = 0;
124 
125     virtual cl_int enqueueCopyImage(const cl::Image &srcImage,
126                                     const cl::Image &dstImage,
127                                     const size_t srcOrigin[3],
128                                     const size_t dstOrigin[3],
129                                     const size_t region[3],
130                                     const cl::EventPtrs &waitEvents,
131                                     CLEventImpl::CreateFunc *eventCreateFunc) = 0;
132 
133     virtual cl_int enqueueFillImage(const cl::Image &image,
134                                     const void *fillColor,
135                                     const size_t origin[3],
136                                     const size_t region[3],
137                                     const cl::EventPtrs &waitEvents,
138                                     CLEventImpl::CreateFunc *eventCreateFunc) = 0;
139 
140     virtual cl_int enqueueCopyImageToBuffer(const cl::Image &srcImage,
141                                             const cl::Buffer &dstBuffer,
142                                             const size_t srcOrigin[3],
143                                             const size_t region[3],
144                                             size_t dstOffset,
145                                             const cl::EventPtrs &waitEvents,
146                                             CLEventImpl::CreateFunc *eventCreateFunc) = 0;
147 
148     virtual cl_int enqueueCopyBufferToImage(const cl::Buffer &srcBuffer,
149                                             const cl::Image &dstImage,
150                                             size_t srcOffset,
151                                             const size_t dstOrigin[3],
152                                             const size_t region[3],
153                                             const cl::EventPtrs &waitEvents,
154                                             CLEventImpl::CreateFunc *eventCreateFunc) = 0;
155 
156     virtual void *enqueueMapImage(const cl::Image &image,
157                                   bool blocking,
158                                   cl::MapFlags mapFlags,
159                                   const size_t origin[3],
160                                   const size_t region[3],
161                                   size_t *imageRowPitch,
162                                   size_t *imageSlicePitch,
163                                   const cl::EventPtrs &waitEvents,
164                                   CLEventImpl::CreateFunc *eventCreateFunc,
165                                   cl_int &errorCode) = 0;
166 
167     virtual cl_int enqueueUnmapMemObject(const cl::Memory &memory,
168                                          void *mappedPtr,
169                                          const cl::EventPtrs &waitEvents,
170                                          CLEventImpl::CreateFunc *eventCreateFunc) = 0;
171 
172     virtual cl_int enqueueMigrateMemObjects(const cl::MemoryPtrs &memObjects,
173                                             cl::MemMigrationFlags flags,
174                                             const cl::EventPtrs &waitEvents,
175                                             CLEventImpl::CreateFunc *eventCreateFunc) = 0;
176 
177     virtual cl_int enqueueNDRangeKernel(const cl::Kernel &kernel,
178                                         cl_uint workDim,
179                                         const size_t *globalWorkOffset,
180                                         const size_t *globalWorkSize,
181                                         const size_t *localWorkSize,
182                                         const cl::EventPtrs &waitEvents,
183                                         CLEventImpl::CreateFunc *eventCreateFunc) = 0;
184 
185     virtual cl_int enqueueTask(const cl::Kernel &kernel,
186                                const cl::EventPtrs &waitEvents,
187                                CLEventImpl::CreateFunc *eventCreateFunc) = 0;
188 
189     virtual cl_int enqueueNativeKernel(cl::UserFunc userFunc,
190                                        void *args,
191                                        size_t cbArgs,
192                                        const cl::BufferPtrs &buffers,
193                                        const std::vector<size_t> bufferPtrOffsets,
194                                        const cl::EventPtrs &waitEvents,
195                                        CLEventImpl::CreateFunc *eventCreateFunc) = 0;
196 
197     virtual cl_int enqueueMarkerWithWaitList(const cl::EventPtrs &waitEvents,
198                                              CLEventImpl::CreateFunc *eventCreateFunc) = 0;
199 
200     virtual cl_int enqueueMarker(CLEventImpl::CreateFunc &eventCreateFunc) = 0;
201 
202     virtual cl_int enqueueWaitForEvents(const cl::EventPtrs &events) = 0;
203 
204     virtual cl_int enqueueBarrierWithWaitList(const cl::EventPtrs &waitEvents,
205                                               CLEventImpl::CreateFunc *eventCreateFunc) = 0;
206 
207     virtual cl_int enqueueBarrier() = 0;
208 
209     virtual cl_int flush()  = 0;
210     virtual cl_int finish() = 0;
211 
212   protected:
213     const cl::CommandQueue &mCommandQueue;
214 };
215 
216 }  // namespace rx
217 
218 #endif  // LIBANGLE_RENDERER_CLCOMMANDQUEUEIMPL_H_
219