File: cm_queue_rt.h

package info (click to toggle)
intel-media-driver 18.4.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 77,144 kB
  • sloc: cpp: 784,288; ansic: 95,944; asm: 42,125; python: 353; sh: 156; makefile: 15
file content (352 lines) | stat: -rw-r--r-- 13,062 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
//!
//! \file      cm_queue_rt.h
//! \brief     Contains CmQueueRT declarations.
//!

#ifndef MEDIADRIVER_AGNOSTIC_COMMON_CM_CMQUEUERT_H_
#define MEDIADRIVER_AGNOSTIC_COMMON_CM_CMQUEUERT_H_

#include "cm_queue.h"

#include <queue>

#include "cm_array.h"
#include "cm_csync.h"
#include "cm_hal.h"

enum CM_GPUCOPY_DIRECTION
{
    CM_FASTCOPY_GPU2CPU = 0,
    CM_FASTCOPY_CPU2GPU = 1,
    CM_FASTCOPY_GPU2GPU = 2,
    CM_FASTCOPY_CPU2CPU = 3
};

namespace CMRT_UMD
{
class CmDeviceRT;
class CmKernel;
class CmKernelRT;
class CmTaskInternal;
class CmEventRT;
class CmThreadSpaceRT;
class CmThreadGroupSpace;
class CmVebox;
class CmSurface2D;
class CmSurface2DRT;

struct CM_GPUCOPY_KERNEL
{
    CmKernel *kernel;
    CM_GPUCOPY_KERNEL_ID kernelID;
    bool locked;
};

class ThreadSafeQueue
{
public:
    bool Push(CmTaskInternal *element)
    {
        mCriticalSection.Acquire();
        mQueue.push(element);
        mCriticalSection.Release();
        return true;
    }

    CmTaskInternal *Pop()
    {
        CmTaskInternal *element = nullptr;
        mCriticalSection.Acquire();
        if (mQueue.empty())
        {
            CM_ASSERT(0);
        }
        else
        {
            element = mQueue.front();
            mQueue.pop();
        }
        mCriticalSection.Release();
        return element;
    }

    CmTaskInternal *Top()
    {
        CmTaskInternal *element = nullptr;
        if (mQueue.empty())
        {
            CM_ASSERT(0);
        }
        else
        {
            element = mQueue.front();
        }
        return element;
    }

    bool IsEmpty() { return mQueue.empty(); }

    int GetCount() { return mQueue.size(); }

private:
    std::queue<CmTaskInternal*> mQueue;
    CSync mCriticalSection;
};

//!
//! \brief    Class CmQueueRT definitions.
//!
class CmQueueRT: public CmQueue
{
public:
    static int32_t Create(CmDeviceRT *device,
                          CmQueueRT *&queue,
                          CM_QUEUE_CREATE_OPTION queueCreateOption);

    static int32_t Destroy(CmQueueRT *&queue);

    CM_RT_API int32_t Enqueue(CmTask *task,
                              CmEvent *&event,
                              const CmThreadSpace *threadSpace = nullptr);

    CM_RT_API int32_t DestroyEvent(CmEvent *&event);

    CM_RT_API int32_t
    EnqueueWithGroup(CmTask *task,
                     CmEvent *&event,
                     const CmThreadGroupSpace *threadGroupSpace = nullptr);

    CM_RT_API int32_t EnqueueVebox(CmVebox *vebox, CmEvent *&event);

    CM_RT_API int32_t EnqueueWithHints(CmTask *task,
                                       CmEvent *&event,
                                       uint32_t hints = 0);

    CM_RT_API int32_t EnqueueCopyCPUToGPU(CmSurface2D *surface,
                                          const unsigned char *sysMem,
                                          CmEvent *&event);

    CM_RT_API int32_t EnqueueCopyGPUToCPU(CmSurface2D *surface,
                                          unsigned char *sysMem,
                                          CmEvent *&event);

    CM_RT_API int32_t EnqueueInitSurface2D(CmSurface2D *surf2D,
                                           const uint32_t initValue,
                                           CmEvent *&event);

    CM_RT_API int32_t EnqueueCopyGPUToGPU(CmSurface2D *outputSurface,
                                          CmSurface2D *inputSurface,
                                          uint32_t option,
                                          CmEvent *&event);

    CM_RT_API int32_t EnqueueCopyCPUToCPU(unsigned char *dstSysMem,
                                          unsigned char *srcSysMem,
                                          uint32_t size,
                                          uint32_t option,
                                          CmEvent *&event);

    CM_RT_API int32_t EnqueueCopyCPUToGPUFullStride(CmSurface2D *surface,
                                                    const unsigned char *sysMem,
                                                    const uint32_t widthStride,
                                                    const uint32_t heightStride,
                                                    const uint32_t option,
                                                    CmEvent *&event);

    CM_RT_API int32_t EnqueueCopyGPUToCPUFullStride(CmSurface2D *surface,
                                                    unsigned char *sysMem,
                                                    const uint32_t widthStride,
                                                    const uint32_t heightStride,
                                                    const uint32_t option,
                                                    CmEvent *&event);

    CM_RT_API int32_t EnqueueFast(CmTask *task,
                              CmEvent *&event,
                              const CmThreadSpace *threadSpace = nullptr);

    CM_RT_API int32_t DestroyEventFast(CmEvent *&event);

    CM_RT_API int32_t EnqueueWithGroupFast(CmTask *task,
                                      CmEvent *&event,
                                      const CmThreadGroupSpace *threadGroupSpace = nullptr);

    int32_t EnqueueCopyInternal_1Plane(CmSurface2DRT *surface,
                                       unsigned char *sysMem,
                                       CM_SURFACE_FORMAT format,
                                       const uint32_t widthInPixel,
                                       const uint32_t widthStride,
                                       const uint32_t heightInRow,
                                       const uint32_t heightStride,
                                       const uint32_t sizePerPixel,
                                       CM_GPUCOPY_DIRECTION direction,
                                       const uint32_t option,
                                       CmEvent *&event);

    int32_t EnqueueCopyInternal_2Planes(CmSurface2DRT *surface,
                                        unsigned char *sysMem,
                                        CM_SURFACE_FORMAT format,
                                        const uint32_t widthInPixel,
                                        const uint32_t widthStride,
                                        const uint32_t heightInRow,
                                        const uint32_t heightStride,
                                        const uint32_t sizePerPixel,
                                        CM_GPUCOPY_DIRECTION direction,
                                        const uint32_t option,
                                        CmEvent *&event);

    int32_t EnqueueCopyInternal(CmSurface2DRT *surface,
                                unsigned char *sysMem,
                                const uint32_t widthStride,
                                const uint32_t heightStride,
                                CM_GPUCOPY_DIRECTION direction,
                                const uint32_t option,
                                CmEvent *&event);

    int32_t EnqueueUnalignedCopyInternal(CmSurface2DRT *surface,
                                         unsigned char *sysMem,
                                         const uint32_t widthStride,
                                         const uint32_t heightStride,
                                         CM_GPUCOPY_DIRECTION direction);

    int32_t FlushTaskWithoutSync(bool flushBlocked = false);

    int32_t GetTaskCount(uint32_t &numTasks);

    int32_t TouchFlushedTasks();

    int32_t GetTaskHasThreadArg(CmKernelRT *kernelArray[],
                                uint32_t numKernels,
                                bool &threadArgExists);
    int32_t CleanQueue();

    CM_QUEUE_CREATE_OPTION &GetQueueOption();

protected:
    CmQueueRT(CmDeviceRT *device, CM_QUEUE_CREATE_OPTION queueCreateOption);

    ~CmQueueRT();

    int32_t Initialize();

    int32_t
    Enqueue_RT(CmKernelRT *kernelArray[],
               const uint32_t kernelCount,
               const uint32_t totalThreadCount,
               CmEventRT *&event,
               const CmThreadSpaceRT *threadSpace = nullptr,
               const uint64_t syncBitmap = 0,
               PCM_POWER_OPTION powerOption = nullptr,
               const uint64_t conditionalEndBitmap = 0,
               PCM_HAL_CONDITIONAL_BB_END_INFO conditionalEndInfo = nullptr,
               CM_TASK_CONFIG *taskConfig = nullptr);

    int32_t Enqueue_RT(CmKernelRT *kernelArray[],
                       const uint32_t kernelCount,
                       const uint32_t totalThreadCount,
                       CmEventRT *&event,
                       const CmThreadGroupSpace *threadGroupSpace = nullptr,
                       const uint64_t syncBitmap = 0,
                       PCM_POWER_OPTION powerOption = nullptr,
                       const uint64_t conditionalEndBitmap = 0,
                       PCM_HAL_CONDITIONAL_BB_END_INFO conditionalEndInfo = nullptr,
                       CM_TASK_CONFIG *taskConfig = nullptr,
                       const CM_EXECUTION_CONFIG* krnExecCfg = nullptr);

    int32_t Enqueue_RT(CmKernelRT *kernelArray[],
                       CmEventRT *&event,
                       uint32_t numTaskGenerated,
                       bool isLastTask,
                       uint32_t hints = 0,
                       PCM_POWER_OPTION powerOption = nullptr);

    int32_t QueryFlushedTasks();

    //New sub functions for different task flush
    int32_t FlushGeneralTask(CmTaskInternal *task);

    int32_t FlushGroupTask(CmTaskInternal *task);

    int32_t FlushVeboxTask(CmTaskInternal *task);

    int32_t FlushEnqueueWithHintsTask(CmTaskInternal *task);

    void PopTaskFromFlushedQueue();

    int32_t CreateEvent(CmTaskInternal *task,
                        bool isVisible,
                        int32_t &taskDriverId,
                        CmEventRT *&event);

    int32_t AddGPUCopyKernel(CM_GPUCOPY_KERNEL* &kernelParam);

    int32_t GetGPUCopyKrnID(uint32_t widthInByte,
                            uint32_t height,
                            CM_SURFACE_FORMAT format,
                            CM_GPUCOPY_DIRECTION copyDirection,
                            CM_GPUCOPY_KERNEL_ID &kernelID);

    int32_t AllocateGPUCopyKernel(uint32_t widthInByte,
                                  uint32_t height,
                                  CM_SURFACE_FORMAT format,
                                  CM_GPUCOPY_DIRECTION copyDirection,
                                  CmKernel* &kernel);

    int32_t CreateGPUCopyKernel(uint32_t widthInByte,
                                uint32_t height,
                                CM_SURFACE_FORMAT format,
                                CM_GPUCOPY_DIRECTION copyDirection,
                                CM_GPUCOPY_KERNEL* &gpuCopyKernelParam);

    int32_t SearchGPUCopyKernel(uint32_t widthInByte,
                                uint32_t height,
                                CM_SURFACE_FORMAT format,
                                CM_GPUCOPY_DIRECTION copyDirection,
                                CM_GPUCOPY_KERNEL* &kernelParam);

    CmDeviceRT *m_device;
    ThreadSafeQueue m_enqueuedTasks;
    ThreadSafeQueue m_flushedTasks;

    CmDynamicArray m_eventArray;
    CSync m_criticalSectionEvent;        // Protect m_eventArray
    CSync m_criticalSectionHalExecute;   // Protect execution in HALCm, i.e HalCm_Execute
    CSync m_criticalSectionFlushedTask;  // Protect QueryFlushedTask
    CSync m_criticalSectionTaskInternal;

    uint32_t m_eventCount;

    CmDynamicArray m_copyKernelParamArray;
    uint32_t m_copyKernelParamArrayCount;

    CSync m_criticalSectionGPUCopyKrn;

    CM_HAL_MAX_VALUES *m_halMaxValues;
    CM_QUEUE_CREATE_OPTION m_queueOption;

private:
    CmQueueRT(const CmQueueRT& other);
    CmQueueRT& operator=(const CmQueueRT& other);
};
};  //namespace

#endif  // #ifnfef MEDIADRIVER_AGNOSTIC_COMMON_CM_CMQUEUERT_H_