Coverage Report

Created: 2025-07-23 08:18

/src/x265/source/common/cudata.h
Line
Count
Source (jump to first uncovered line)
1
/*****************************************************************************
2
 * Copyright (C) 2013-2020 MulticoreWare, Inc
3
 *
4
 * Authors: Steve Borho <steve@borho.org>
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
19
 *
20
 * This program is also available under a commercial proprietary license.
21
 * For more information, contact us at license @ x265.com.
22
 *****************************************************************************/
23
24
#ifndef X265_CUDATA_H
25
#define X265_CUDATA_H
26
27
#include "common.h"
28
#include "slice.h"
29
#include "mv.h"
30
31
0
#define NUM_TU_DEPTH 21
32
33
namespace X265_NS {
34
// private namespace
35
36
class FrameData;
37
class Slice;
38
struct TUEntropyCodingParameters;
39
struct CUDataMemPool;
40
#if ENABLE_SCC_EXT
41
struct IBC;
42
#endif
43
44
enum PartSize
45
{
46
    SIZE_2Nx2N, // symmetric motion partition,  2Nx2N
47
    SIZE_2NxN,  // symmetric motion partition,  2Nx N
48
    SIZE_Nx2N,  // symmetric motion partition,   Nx2N
49
    SIZE_NxN,   // symmetric motion partition,   Nx N
50
    SIZE_2NxnU, // asymmetric motion partition, 2Nx( N/2) + 2Nx(3N/2)
51
    SIZE_2NxnD, // asymmetric motion partition, 2Nx(3N/2) + 2Nx( N/2)
52
    SIZE_nLx2N, // asymmetric motion partition, ( N/2)x2N + (3N/2)x2N
53
    SIZE_nRx2N, // asymmetric motion partition, (3N/2)x2N + ( N/2)x2N
54
    NUM_PART_SIZES
55
};
56
57
enum PredMode
58
{
59
    MODE_NONE  = 0,
60
    MODE_INTER = (1 << 0),
61
    MODE_INTRA = (1 << 1),
62
    MODE_SKIP  = (1 << 2) | MODE_INTER
63
};
64
65
// motion vector predictor direction used in AMVP
66
enum MVP_DIR
67
{
68
    MD_LEFT = 0,    // MVP of left block
69
    MD_ABOVE,       // MVP of above block
70
    MD_ABOVE_RIGHT, // MVP of above right block
71
    MD_BELOW_LEFT,  // MVP of below left block
72
    MD_ABOVE_LEFT,  // MVP of above left block
73
    MD_COLLOCATED   // MVP of temporal neighbour
74
};
75
76
struct CUGeom
77
{
78
    enum {
79
        INTRA           = 1<<0, // CU is intra predicted
80
        PRESENT         = 1<<1, // CU is not completely outside the frame
81
        SPLIT_MANDATORY = 1<<2, // CU split is mandatory if CU is inside frame and can be split
82
        LEAF            = 1<<3, // CU is a leaf node of the CTU
83
        SPLIT           = 1<<4, // CU is currently split in four child CUs.
84
    };
85
    
86
    // (1 + 4 + 16 + 64) = 85.
87
    enum { MAX_GEOMS = 85 };
88
89
    uint32_t log2CUSize;    // Log of the CU size.
90
    uint32_t childOffset;   // offset of the first child CU from current CU
91
    uint32_t absPartIdx;    // Part index of this CU in terms of 4x4 blocks.
92
    uint32_t numPartitions; // Number of 4x4 blocks in the CU
93
    uint32_t flags;         // CU flags.
94
    uint32_t depth;         // depth of this CU relative from CTU
95
    uint32_t geomRecurId;   // Unique geom id from 0 to MAX_GEOMS - 1 for every depth
96
};
97
98
struct MVField
99
{
100
    MV  mv;
101
    int refIdx;
102
};
103
104
// Structure that keeps the neighbour's MV information.
105
struct InterNeighbourMV
106
{
107
    // Neighbour MV. The index represents the list.
108
    MV mv[2];
109
110
    // Collocated right bottom CU addr.
111
    uint32_t cuAddr[2];
112
113
    bool isAvailable;
114
115
    // For spatial prediction, this field contains the reference index
116
    // in each list (-1 if not available).
117
    //
118
    // For temporal prediction, the first value is used for the 
119
    // prediction with list 0. The second value is used for the prediction 
120
    // with list 1. For each value, the first four bits are the reference index 
121
    // associated to the PMV, and the fifth bit is the list associated to the PMV.
122
    // if both reference indices are -1, then unifiedRef is also -1
123
    union { int16_t refIdx[2]; int32_t unifiedRef; };
124
};
125
126
struct IBC
127
{
128
    int             m_numBVs;
129
    int             m_numBV16s;
130
    MV              m_BVs[64];
131
    MV              m_lastIntraBCMv[2];
132
};
133
134
typedef void(*cucopy_t)(uint8_t* dst, uint8_t* src); // dst and src are aligned to MIN(size, 32)
135
typedef void(*cubcast_t)(uint8_t* dst, uint8_t val); // dst is aligned to MIN(size, 32)
136
137
// Partition count table, index represents partitioning mode.
138
const uint32_t nbPartsTable[8] = { 1, 2, 2, 4, 2, 2, 2, 2 };
139
140
// Partition table.
141
// First index is partitioning mode. Second index is partition index.
142
// Third index is 0 for partition sizes, 1 for partition offsets. The 
143
// sizes and offsets are encoded as two packed 4-bit values (X,Y). 
144
// X and Y represent 1/4 fractions of the block size.
145
const uint32_t partTable[8][4][2] =
146
{
147
    //        XY
148
    { { 0x44, 0x00 }, { 0x00, 0x00 }, { 0x00, 0x00 }, { 0x00, 0x00 } }, // SIZE_2Nx2N.
149
    { { 0x42, 0x00 }, { 0x42, 0x02 }, { 0x00, 0x00 }, { 0x00, 0x00 } }, // SIZE_2NxN.
150
    { { 0x24, 0x00 }, { 0x24, 0x20 }, { 0x00, 0x00 }, { 0x00, 0x00 } }, // SIZE_Nx2N.
151
    { { 0x22, 0x00 }, { 0x22, 0x20 }, { 0x22, 0x02 }, { 0x22, 0x22 } }, // SIZE_NxN.
152
    { { 0x41, 0x00 }, { 0x43, 0x01 }, { 0x00, 0x00 }, { 0x00, 0x00 } }, // SIZE_2NxnU.
153
    { { 0x43, 0x00 }, { 0x41, 0x03 }, { 0x00, 0x00 }, { 0x00, 0x00 } }, // SIZE_2NxnD.
154
    { { 0x14, 0x00 }, { 0x34, 0x10 }, { 0x00, 0x00 }, { 0x00, 0x00 } }, // SIZE_nLx2N.
155
    { { 0x34, 0x00 }, { 0x14, 0x30 }, { 0x00, 0x00 }, { 0x00, 0x00 } }  // SIZE_nRx2N.
156
};
157
158
// Partition Address table.
159
// First index is partitioning mode. Second index is partition address.
160
const uint32_t partAddrTable[8][4] =
161
{
162
    { 0x00, 0x00, 0x00, 0x00 }, // SIZE_2Nx2N.
163
    { 0x00, 0x08, 0x08, 0x08 }, // SIZE_2NxN.
164
    { 0x00, 0x04, 0x04, 0x04 }, // SIZE_Nx2N.
165
    { 0x00, 0x04, 0x08, 0x0C }, // SIZE_NxN.
166
    { 0x00, 0x02, 0x02, 0x02 }, // SIZE_2NxnU.
167
    { 0x00, 0x0A, 0x0A, 0x0A }, // SIZE_2NxnD.
168
    { 0x00, 0x01, 0x01, 0x01 }, // SIZE_nLx2N.
169
    { 0x00, 0x05, 0x05, 0x05 }  // SIZE_nRx2N.
170
};
171
172
// Holds part data for a CU of a given size, from an 8x8 CU to a CTU
173
class CUData
174
{
175
public:
176
177
    cubcast_t s_partSet[NUM_FULL_DEPTH]; // pointer to broadcast set functions per absolute depth
178
    uint32_t  s_numPartInCUSize;
179
180
    bool          m_vbvAffected;
181
182
    FrameData*    m_encData;
183
    const Slice*  m_slice;
184
185
    cucopy_t      m_partCopy;         // pointer to function that copies m_numPartitions elements
186
    cubcast_t     m_partSet;          // pointer to function that sets m_numPartitions elements
187
    cucopy_t      m_subPartCopy;      // pointer to function that copies m_numPartitions/4 elements, may be NULL
188
    cubcast_t     m_subPartSet;       // pointer to function that sets m_numPartitions/4 elements, may be NULL
189
190
    uint32_t      m_cuAddr;           // address of CTU within the picture in raster order
191
    uint32_t      m_absIdxInCTU;      // address of CU within its CTU in Z scan order
192
    uint32_t      m_cuPelX;           // CU position within the picture, in pixels (X)
193
    uint32_t      m_cuPelY;           // CU position within the picture, in pixels (Y)
194
    uint32_t      m_numPartitions;    // maximum number of 4x4 partitions within this CU
195
196
    uint32_t      m_chromaFormat;
197
    uint32_t      m_hChromaShift;
198
    uint32_t      m_vChromaShift;
199
200
    /* multiple slices informations */
201
    uint8_t      m_bFirstRowInSlice;
202
    uint8_t      m_bLastRowInSlice;
203
    uint8_t      m_bLastCuInSlice;
204
205
    /* Per-part data, stored contiguously */
206
    int8_t*       m_qp;               // array of QP values
207
    int8_t*       m_qpAnalysis;       // array of QP values for analysis reuse
208
    uint8_t*      m_log2CUSize;       // array of cu log2Size TODO: seems redundant to depth
209
    uint8_t*      m_lumaIntraDir;     // array of intra directions (luma)
210
    uint8_t*      m_tqBypass;         // array of CU lossless flags
211
    int8_t*       m_refIdx[2];        // array of motion reference indices per list
212
    uint8_t*      m_cuDepth;          // array of depths
213
    uint8_t*      m_predMode;         // array of prediction modes
214
    uint8_t*      m_partSize;         // array of partition sizes
215
    uint8_t*      m_mergeFlag;        // array of merge flags
216
    uint8_t*      m_skipFlag[2];
217
    uint8_t*      m_interDir;         // array of inter directions
218
    uint8_t*      m_mvpIdx[2];        // array of motion vector predictor candidates or merge candidate indices [0]
219
    uint8_t*      m_tuDepth;          // array of transform indices
220
    uint8_t*      m_transformSkip[3]; // array of transform skipping flags per plane
221
    uint8_t*      m_cbf[3];           // array of coded block flags (CBF) per plane
222
    uint8_t*      m_chromaIntraDir;   // array of intra directions (chroma)
223
    enum { BytesPerPartition = 24 };  // combined sizeof() of all per-part data
224
225
    sse_t*        m_distortion;
226
    coeff_t*      m_trCoeff[3];       // transformed coefficient buffer per plane
227
    int8_t        m_refTuDepth[NUM_TU_DEPTH];   // TU depth of CU at depths 0, 1 and 2
228
229
    MV*           m_mv[2];            // array of motion vectors per list
230
    MV*           m_mvd[2];           // array of coded motion vector deltas per list
231
    enum { TMVP_UNIT_MASK = 0xF0 };  // mask for mapping index to into a compressed (reference) MV field
232
233
    const CUData* m_cuAboveLeft;      // pointer to above-left neighbor CTU
234
    const CUData* m_cuAboveRight;     // pointer to above-right neighbor CTU
235
    const CUData* m_cuAbove;          // pointer to above neighbor CTU
236
    const CUData* m_cuLeft;           // pointer to left neighbor CTU
237
    double m_meanQP;
238
    uint64_t      m_fAc_den[3];
239
    uint64_t      m_fDc_den[3];
240
241
    /* Feature values per CTU for dynamic refinement */
242
    uint64_t*       m_collectCURd;
243
    uint32_t*       m_collectCUVariance;
244
    uint32_t*       m_collectCUCount;
245
246
#if ENABLE_SCC_EXT
247
    MV              m_lastIntraBCMv[2];
248
#endif
249
250
    CUData();
251
252
    void     initialize(const CUDataMemPool& dataPool, uint32_t depth, const x265_param& param, int instance);
253
    static void calcCTUGeoms(uint32_t ctuWidth, uint32_t ctuHeight, uint32_t maxCUSize, uint32_t minCUSize, CUGeom cuDataArray[CUGeom::MAX_GEOMS]);
254
255
    void     initCTU(const Frame& frame, uint32_t cuAddr, int qp, uint32_t firstRowInSlice, uint32_t lastRowInSlice, uint32_t lastCUInSlice);
256
#if !ENABLE_SCC_EXT
257
    void     initSubCU(const CUData& ctu, const CUGeom& cuGeom, int qp);
258
#endif
259
    void     initLosslessCU(const CUData& cu, const CUGeom& cuGeom);
260
261
    void     copyPartFrom(const CUData& cu, const CUGeom& childGeom, uint32_t subPartIdx);
262
    void     setEmptyPart(const CUGeom& childGeom, uint32_t subPartIdx);
263
    void     copyToPic(uint32_t depth) const;
264
265
    /* RD-0 methods called only from encodeResidue */
266
    void     copyFromPic(const CUData& ctu, const CUGeom& cuGeom, int csp, bool copyQp = true);
267
    void     updatePic(uint32_t depth, int picCsp) const;
268
269
0
    void     setPartSizeSubParts(PartSize size)    { m_partSet(m_partSize, (uint8_t)size); }
270
0
    void     setPredModeSubParts(PredMode mode)    { m_partSet(m_predMode, (uint8_t)mode); }
271
0
    void     clearCbf()                            { m_partSet(m_cbf[0], 0); if (m_chromaFormat != X265_CSP_I400) { m_partSet(m_cbf[1], 0); m_partSet(m_cbf[2], 0);} }
272
273
    /* these functions all take depth as an absolute depth from CTU, it is used to calculate the number of parts to copy */
274
0
    void     setQPSubParts(int8_t qp, uint32_t absPartIdx, uint32_t depth)                    { s_partSet[depth]((uint8_t*)m_qp + absPartIdx, (uint8_t)qp); }
275
0
    void     setTUDepthSubParts(uint8_t tuDepth, uint32_t absPartIdx, uint32_t depth)         { s_partSet[depth](m_tuDepth + absPartIdx, tuDepth); }
276
0
    void     setLumaIntraDirSubParts(uint8_t dir, uint32_t absPartIdx, uint32_t depth)        { s_partSet[depth](m_lumaIntraDir + absPartIdx, dir); }
277
0
    void     setChromIntraDirSubParts(uint8_t dir, uint32_t absPartIdx, uint32_t depth)       { s_partSet[depth](m_chromaIntraDir + absPartIdx, dir); }
278
0
    void     setCbfSubParts(uint8_t cbf, TextType ttype, uint32_t absPartIdx, uint32_t depth) { s_partSet[depth](m_cbf[ttype] + absPartIdx, cbf); }
279
0
    void     setCbfPartRange(uint8_t cbf, TextType ttype, uint32_t absPartIdx, uint32_t coveredPartIdxes) { memset(m_cbf[ttype] + absPartIdx, cbf, coveredPartIdxes); }
280
0
    void     setTransformSkipSubParts(uint8_t tskip, TextType ttype, uint32_t absPartIdx, uint32_t depth) { s_partSet[depth](m_transformSkip[ttype] + absPartIdx, tskip); }
281
0
    void     setTransformSkipPartRange(uint8_t tskip, TextType ttype, uint32_t absPartIdx, uint32_t coveredPartIdxes) { memset(m_transformSkip[ttype] + absPartIdx, tskip, coveredPartIdxes); }
282
283
    bool     setQPSubCUs(int8_t qp, uint32_t absPartIdx, uint32_t depth);
284
285
    void     setPUInterDir(uint8_t dir, uint32_t absPartIdx, uint32_t puIdx);
286
    void     setPUMv(int list, const MV& mv, int absPartIdx, int puIdx);
287
    void     setPURefIdx(int list, int8_t refIdx, int absPartIdx, int puIdx);
288
289
0
    uint8_t  getCbf(uint32_t absPartIdx, TextType ttype, uint32_t tuDepth) const { return (m_cbf[ttype][absPartIdx] >> tuDepth) & 0x1; }
290
0
    bool     getQtRootCbf(uint32_t absPartIdx) const                             { return (m_cbf[0][absPartIdx] || ((m_chromaFormat != X265_CSP_I400) && (m_cbf[1][absPartIdx] || m_cbf[2][absPartIdx]))); }
291
    int8_t   getRefQP(uint32_t currAbsIdxInCTU) const;
292
    uint32_t getInterMergeCandidates(uint32_t absPartIdx, uint32_t puIdx, MVField (*candMvField)[2], uint8_t* candDir) const;
293
    void     clipMv(MV& outMV) const;
294
#if (ENABLE_MULTIVIEW || ENABLE_SCC_EXT)
295
    int      getPMV(InterNeighbourMV* neighbours, uint32_t reference_list, uint32_t refIdx, MV* amvpCand, MV* pmv, uint32_t puIdx = 0, uint32_t absPartIdx = 0) const;
296
#else
297
    int      getPMV(InterNeighbourMV* neighbours, uint32_t reference_list, uint32_t refIdx, MV* amvpCand, MV* pmv) const;
298
#endif
299
    void     getNeighbourMV(uint32_t puIdx, uint32_t absPartIdx, InterNeighbourMV* neighbours) const;
300
    void     getIntraTUQtDepthRange(uint32_t tuDepthRange[2], uint32_t absPartIdx) const;
301
    void     getInterTUQtDepthRange(uint32_t tuDepthRange[2], uint32_t absPartIdx) const;
302
0
    uint32_t getBestRefIdx(uint32_t subPartIdx) const { return ((m_interDir[subPartIdx] & 1) << m_refIdx[0][subPartIdx]) | 
303
0
                                                              (((m_interDir[subPartIdx] >> 1) & 1) << (m_refIdx[1][subPartIdx] + 16)); }
304
0
    uint32_t getPUOffset(uint32_t puIdx, uint32_t absPartIdx) const { return (partAddrTable[(int)m_partSize[absPartIdx]][puIdx] << (m_slice->m_param->unitSizeDepth - m_cuDepth[absPartIdx]) * 2) >> 4; }
305
306
0
    uint32_t getNumPartInter(uint32_t absPartIdx) const              { return nbPartsTable[(int)m_partSize[absPartIdx]]; }
307
0
    bool     isIntra(uint32_t absPartIdx) const   { return m_predMode[absPartIdx] == MODE_INTRA; }
308
0
    bool     isInter(uint32_t absPartIdx) const   { return !!(m_predMode[absPartIdx] & MODE_INTER); }
309
0
    bool     isSkipped(uint32_t absPartIdx) const { return m_predMode[absPartIdx] == MODE_SKIP; }
310
0
    bool     isBipredRestriction() const          { return m_log2CUSize[0] == 3 && m_partSize[0] != SIZE_2Nx2N; }
311
312
    void     getPartIndexAndSize(uint32_t puIdx, uint32_t& absPartIdx, int& puWidth, int& puHeight) const;
313
    void     getMvField(const CUData* cu, uint32_t absPartIdx, int picList, MVField& mvField) const;
314
315
    void     getAllowedChromaDir(uint32_t absPartIdx, uint32_t* modeList) const;
316
    int      getIntraDirLumaPredictor(uint32_t absPartIdx, uint32_t* intraDirPred) const;
317
318
0
    uint32_t getSCUAddr() const                  { return (m_cuAddr << m_slice->m_param->unitSizeDepth * 2) + m_absIdxInCTU; }
319
    uint32_t getCtxSplitFlag(uint32_t absPartIdx, uint32_t depth) const;
320
    uint32_t getCtxSkipFlag(uint32_t absPartIdx) const;
321
    void     getTUEntropyCodingParameters(TUEntropyCodingParameters &result, uint32_t absPartIdx, uint32_t log2TrSize, bool bIsLuma) const;
322
323
    const CUData* getPULeft(uint32_t& lPartUnitIdx, uint32_t curPartUnitIdx) const;
324
    const CUData* getPUAbove(uint32_t& aPartUnitIdx, uint32_t curPartUnitIdx) const;
325
    const CUData* getPUAboveLeft(uint32_t& alPartUnitIdx, uint32_t curPartUnitIdx) const;
326
    const CUData* getPUAboveRight(uint32_t& arPartUnitIdx, uint32_t curPartUnitIdx) const;
327
    const CUData* getPUBelowLeft(uint32_t& blPartUnitIdx, uint32_t curPartUnitIdx) const;
328
329
    const CUData* getQpMinCuLeft(uint32_t& lPartUnitIdx, uint32_t currAbsIdxInCTU) const;
330
    const CUData* getQpMinCuAbove(uint32_t& aPartUnitIdx, uint32_t currAbsIdxInCTU) const;
331
332
    const CUData* getPUAboveRightAdi(uint32_t& arPartUnitIdx, uint32_t curPartUnitIdx, uint32_t partUnitOffset) const;
333
    const CUData* getPUBelowLeftAdi(uint32_t& blPartUnitIdx, uint32_t curPartUnitIdx, uint32_t partUnitOffset) const;
334
335
#if ENABLE_SCC_EXT
336
    void     initSubCU(const CUData& ctu, const CUGeom& cuGeom, int qp, MV lastIntraBCMv[2] = 0);
337
338
    void getIntraBCMVPsEncOnly(uint32_t absPartIdx, MV* MvPred, int& nbPred, int puIdx);
339
    bool getDerivedBV(uint32_t absPartIdx, const MV& currentMv, MV& derivedMv, uint32_t width, uint32_t height);
340
    bool isIntraBC(const CUData* cu, uint32_t absPartIdx) const;
341
    bool getColMVPIBC(int ctuRsAddr, int partUnitIdx, MV& rcMv);
342
    void roundMergeCandidates(MVField(*candMvField)[2], int iCount) const;
343
    bool is8x8BipredRestriction(MV mvL0, MV mvL1, int iRefIdxL0, int iRefIdxL1) const;
344
#endif
345
346
protected:
347
348
    template<typename T>
349
    void setAllPU(T *p, const T& val, int absPartIdx, int puIdx);
350
351
    int8_t getLastCodedQP(uint32_t absPartIdx) const;
352
    int  getLastValidPartIdx(int absPartIdx) const;
353
354
    bool hasEqualMotion(uint32_t absPartIdx, const CUData& candCU, uint32_t candAbsPartIdx) const;
355
356
    /* Check whether the current PU and a spatial neighboring PU are in same merge region */
357
0
    bool isDiffMER(int xN, int yN, int xP, int yP) const { return ((xN >> 2) != (xP >> 2)) || ((yN >> 2) != (yP >> 2)); }
358
359
    // add possible motion vector predictor candidates
360
    bool getDirectPMV(MV& pmv, InterNeighbourMV *neighbours, uint32_t picList, uint32_t refIdx) const;
361
    bool getIndirectPMV(MV& outMV, InterNeighbourMV *neighbours, uint32_t reference_list, uint32_t refIdx) const;
362
    void getInterNeighbourMV(InterNeighbourMV *neighbour, uint32_t partUnitIdx, MVP_DIR dir) const;
363
364
    bool getColMVP(MV& outMV, int& outRefIdx, int picList, int cuAddr, int absPartIdx) const;
365
    bool getCollocatedMV(int cuAddr, int partUnitIdx, InterNeighbourMV *neighbour) const;
366
367
    MV scaleMvByPOCDist(const MV& inMV, int curPOC, int curRefPOC, int colPOC, int colRefPOC) const;
368
369
    void     deriveLeftRightTopIdx(uint32_t puIdx, uint32_t& partIdxLT, uint32_t& partIdxRT) const;
370
371
    uint32_t deriveCenterIdx(uint32_t puIdx) const;
372
    uint32_t deriveRightBottomIdx(uint32_t puIdx) const;
373
    uint32_t deriveLeftBottomIdx(uint32_t puIdx) const;
374
};
375
376
// TU settings for entropy encoding
377
struct TUEntropyCodingParameters
378
{
379
    const uint16_t *scan;
380
    const uint16_t *scanCG;
381
    ScanType        scanType;
382
    uint32_t        firstSignificanceMapContext;
383
};
384
385
struct CUDataMemPool
386
{
387
    uint8_t* charMemBlock;
388
    coeff_t* trCoeffMemBlock;
389
    MV*      mvMemBlock;
390
    sse_t*   distortionMemBlock;
391
    uint64_t* dynRefineRdBlock;
392
    uint32_t* dynRefCntBlock;
393
    uint32_t* dynRefVarBlock;
394
395
0
    CUDataMemPool() { charMemBlock = NULL; trCoeffMemBlock = NULL; mvMemBlock = NULL; distortionMemBlock = NULL; 
396
0
                      dynRefineRdBlock = NULL; dynRefCntBlock = NULL; dynRefVarBlock = NULL;}
397
398
    bool create(uint32_t depth, uint32_t csp, uint32_t numInstances, const x265_param& param)
399
0
    {
400
0
        uint32_t numPartition = param.num4x4Partitions >> (depth * 2);
401
0
        uint32_t cuSize = param.maxCUSize >> depth;
402
0
        uint32_t sizeL = cuSize * cuSize;
403
0
        if (csp == X265_CSP_I400)
404
0
        {
405
0
            CHECKED_MALLOC(trCoeffMemBlock, coeff_t, (sizeL) * numInstances);
406
0
        }
407
0
        else
408
0
        {            
409
0
            uint32_t sizeC = sizeL >> (CHROMA_H_SHIFT(csp) + CHROMA_V_SHIFT(csp));
410
0
            CHECKED_MALLOC(trCoeffMemBlock, coeff_t, (sizeL + sizeC * 2) * numInstances);
411
0
        }
412
0
        CHECKED_MALLOC(charMemBlock, uint8_t, numPartition * numInstances * CUData::BytesPerPartition);
413
0
        CHECKED_MALLOC_ZERO(mvMemBlock, MV, numPartition * 4 * numInstances);
414
0
        CHECKED_MALLOC(distortionMemBlock, sse_t, numPartition * numInstances);
415
0
        return true;
416
0
    fail:
417
0
        return false;
418
0
    }
419
420
    void destroy()
421
0
    {
422
0
        X265_FREE(trCoeffMemBlock);
423
0
        X265_FREE(mvMemBlock);
424
0
        X265_FREE(charMemBlock);
425
0
        X265_FREE(distortionMemBlock);
426
0
    }
427
};
428
}
429
430
#endif // ifndef X265_CUDATA_H