Debian Codegraph @

media_common/agnostic/common/codec/shared/codec_def_encode.h

raw
1 /*
2 * Copyright (c) 2018-2023, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file codec_def_encode.h
24 //! \brief Defines encode types and macros shared by CodecHal and DDI layer
25 //! \details Applies to encode only. Should not contain any DDI specific code.
26 //!
27
28 #ifndef __CODEC_DEF_ENCODE_H__
29 #define __CODEC_DEF_ENCODE_H__
30 #include "mos_os.h"
31 #include "codec_def_common.h"
32
33 #define CODECHAL_VDENC_BRC_NUM_OF_PASSES 2
34 #define CODECHAL_PAK_OBJ_EACH_CU 66
35 #define CODECHAL_LPLA_NUM_OF_PASSES 2
36 #define CODECHAL_ENCODE_BRC_KBPS 1000 // 1000bps for disk storage, aligned with industry usage
37
38 //!
39 //! \struct AtomicScratchBuffer
40 //! \brief The sturct of Atomic Scratch Buffer
41 //!
42 struct AtomicScratchBuffer
43 {
44 MOS_RESOURCE resAtomicScratchBuffer; //!> Handle of eStatus buffer
45 uint32_t *pData; //!> Pointer of the buffer of actual data
46 uint16_t wEncodeUpdateIndex; //!> used for VDBOX update encode status
47 uint16_t wTearDownIndex; //!> Reserved for future extension
48 uint32_t dwZeroValueOffset; //!> Store the result of the ATOMIC_CMP
49 uint32_t dwOperand1Offset; //!> Operand 1 of the ATOMIC_CMP
50 uint32_t dwOperand2Offset; //!> Operand 2 of the ATOMIC_CMP
51 uint32_t dwOperand3Offset; //!> Copy of the operand 1
52
53 uint32_t dwSize; //!> Size of the buffer
54 uint32_t dwOperandSetSize; //!> Size of Operand set
55 };
56
57 //!
58 //! \struct CodechalEncodeSeiData
59 //! \brief Indicate the SeiData parameters
60 //!
61 struct CodechalEncodeSeiData
62 {
63 bool newSEIData;
64 uint32_t dwSEIDataSize;
65 uint32_t dwSEIBufSize;
66 uint8_t* pSEIBuffer;
67 };
68
69 typedef struct _CODEC_ENCODE_MB_CONTROL
70 {
71 union
72 {
73 struct
74 {
75 uint32_t bForceIntra : 1;
76 uint32_t Reserved : 31;
77 };
78 uint32_t value;
79 } MBParams;
80 } CODEC_ENCODE_MB_CONTROL, *PCODEC_ENCODE_MB_CONTROL;
81
82 struct MetaDataOffset
83 {
84 uint32_t dwEncodeErrorFlags = 0;
85 uint32_t dwEncodedBitstreamWrittenBytesCount = 0;
86 uint32_t dwWrittenSubregionsCount = 0;
87
88 uint32_t dwEncodeStats = 0;
89 uint32_t dwAverageQP = 0;
90 uint32_t dwIntraCodingUnitsCount = 0;
91 uint32_t dwInterCodingUnitsCount = 0;
92 uint32_t dwSkipCodingUnitsCount = 0;
93 uint32_t dwAverageMotionEstimationXDirection = 0;
94 uint32_t dwAverageMotionEstimationYDirection = 0;
95
96 uint32_t dwbSize = 0;
97 uint32_t dwbStartOffset = 0;
98 uint32_t dwbHeaderSize = 0;
99
100 uint32_t dwMetaDataSize = 0;
101 uint32_t dwMetaDataSubRegionSize = 0;
102
103 uint32_t dwTilePartitionSize = 0;
104 uint32_t dwPostFeatueSize = 0;
105 };
106
107 //!
108 //! \struct EncoderParams
109 //! \brief Encoder parameters
110 //!
111 struct EncoderParams
112 {
113 CODECHAL_FUNCTION ExecCodecFunction = CODECHAL_FUNCTION_INVALID; //!< High level codec functionality requested.
114
115 PMOS_SURFACE psRawSurface = nullptr; //!< Raw surface
116 PMOS_SURFACE psReconSurface = nullptr; //!< reconstructed surface
117 PMOS_RESOURCE presBitstreamBuffer = nullptr; //!< Output buffer for bitstream data.
118 PMOS_RESOURCE presLaDataBuffer = nullptr; //!< Output buffer for La data.
119 PMOS_RESOURCE presMetadataBuffer = nullptr; //!< Output buffer for meta data.
120 PMOS_RESOURCE presMbCodeSurface = nullptr; //!< PAK objects provided by framework.
121 PMOS_SURFACE psMbSegmentMapSurface = nullptr; //!< [VP9]
122 /* \brief [AVC & MPEG2] MB QP data provided by framework.
123 *
124 * When in CQP mode, the framework can provide this surface that contains a single QpY value for each macroblock to be used for encoding. If it is not provided, the frame level QpY(QpY + slice_qp_delta) will be used for all macroblocks.
125 */
126 PMOS_SURFACE psMbQpDataSurface = nullptr; //!< pointer to surface of Mb QP Data
127 PCODEC_ENCODE_MB_CONTROL pMbCtrlBuffer = nullptr; //!< [AVC] MB contrl map provided by framework
128 PMOS_SURFACE psMbDisableSkipMapSurface = nullptr; //!< [AVC] MB disable skip map provided by framework
129 PMOS_SURFACE psCoeffSurface = nullptr; //!< [VP9]
130 PMOS_RESOURCE presCoeffProbabilityBuffer = nullptr; //!< [VP9] Coefficient probabilities provided by framework.
131 bool bNewSeq = false; //!< Indicates the start of a new sequence.
132 bool bPicQuant = false; //!< Indicates whether the scaling list is for SPS (0) or PPS (1).
133 bool bNewQmatrixData = false; //!< Indicates that new QM data was provided by framework.
134 CodechalEncodeSeiData *pSeiData = nullptr; //!< [AVC & HEVC] Information pertaining to pSeiParamBuffer.
135 uint32_t dwSEIDataOffset = 0; //!< [AVC & HEVC] Offset to the first SEI message within pSeiParamBuffer.
136 uint8_t *pSeiParamBuffer = nullptr; //!< [AVC & HEVC] Packed SEI messages provided by the framework
137 uint32_t dwNumSlices = 0; //!< Number of slice data structures in pSliceParams.
138 uint32_t dwAppDataSize = 0; //!< [JPEG]
139 uint32_t dwNumHuffBuffers = 0; //!< [JPEG]
140 uint32_t dwMbDataBufferSize = 0; //!< Size of the data contained in presMbCodeSurface
141 uint32_t dwBitstreamSize = 0; //!< Maximum amount of data to be output to presBitstreamBuffer.
142 bool bNewVuiData = false; //!< [AVC & MPEG2] Indicates that pVuiParams is present and expected to be valid.
143 bool bJpegQuantMatrixSent = false; //!< [JPEG] Indicates whether a quant matrix was sent by the framework.
144 PBSBuffer pBSBuffer = nullptr; //!< Packed header data provided by the framework to be inserted in the bitstream.
145 PCODECHAL_NAL_UNIT_PARAMS *ppNALUnitParams = nullptr; //!< Information about the packed header data in pBSBuffer.
146 uint32_t uiNumNalUnits = 0; //!< Number of NAL units in ppNALUnitParams.
147 void *pSlcHeaderData = nullptr; //!< [AVC, HEVC, & MPEG2] Packed slice header data provided by the framework.
148 bool bAcceleratorHeaderPackingCaps = false; //!< [AVC] Indicates whether or not the driver is packing the slice headers.
149 uint32_t uiSlcStructCaps = 0; //!< [AVC] Slice capability information, formatted as CODEC_SLICE_STRUCTS
150 bool bMADEnabled = false; //!< MAD is enabled
151 bool bMbQpDataEnabled = false; //!< [AVC & MPEG2] Indicates that psMbQpDataSurface is present.
152 bool bLaDataBufferEnabled = false;
153 bool bMbDisableSkipMapEnabled = false; //!< [AVC] Indicates that psMbDisableSkipMapSurface is present.
154 bool bReportStatisticsEnabled = false; //!< [HEVC] Indicates whether statistic reporting is enabled, disabled by default.
155 bool bQualityImprovementEnable = false; //!< [HEVC] Indicates whether quality improvement is enabled, disabled by default.
156 bool newSeqHeader = false; //!< [AVC] Flag for new Sequence Header.
157 bool newPpsHeader = false; //!< [AVC] Flag for new PPS Header.
158 bool arbitraryNumMbsInSlice = false; //!< [AVC] Flag to indicate if the sliceMapSurface needs to be programmed or not.
159
160 void *pSeqParams = nullptr; //!< Sequence parameter set structure defined per standard.
161 void *pPicParams = nullptr; //!< Picture parameter set structure defined per standard.
162 void *pVuiParams = nullptr; //!< [AVC & MPEG2] Picture parameter set structure defined per standard.
163 void *pSliceParams = nullptr; //!< Slice data array defined per standard, expect dwNumSlices entries.
164 void *pSegmentParams = nullptr; //!< [VP9]
165 void *pIQMatrixBuffer = nullptr; //!< [AVC, HEVC, & MPEG2] IQ parameter structure defined per standard.
166
167 // AVC Specific Parameters
168 void *pIQWeightScaleLists = nullptr; //!< list of IQ Weight scale
169 void *pAVCQCParams = nullptr; //!< AVC QC parameters
170 void *pAVCRoundingParams = nullptr; //!< AVC rounding parameters
171
172 void *pQuantData = nullptr;
173 PMOS_RESOURCE presDistortionDataSurface = nullptr;
174 uint32_t uiFrameRate = 0;
175
176 bool bSegmentMapProvided = false; //!< [VP9]
177
178 void *pMpeg2UserDataListHead = nullptr; //!< [MPEG2]
179
180 void *pHuffmanTable = nullptr; //!< [JPEG]
181 void *pQuantizationTable = nullptr; //!< [JPEG]
182 void *pApplicationData = nullptr; //!< [JPEG]
183
184 void *pFeiPicParams = nullptr; //!< [FEI]
185 void *pPreEncParams = nullptr; //!< [FEI]
186
187 // HEVC Specific Parameters
188 bool bVdencActive = false; //!< Indicate if vdenc is active
189 bool advanced = false; //!< Indicate if vdenc is active
190
191 MOS_SURFACE rawSurface = {}; //!< Raw surface
192 MOS_SURFACE reconSurface = {}; //!< reconstructed surface
193 MOS_RESOURCE resBitstreamBuffer = {}; //!< Output buffer for bitstream data.
194 MOS_SURFACE mbQpSurface = {};
195 MOS_SURFACE disableSkipMapSurface = {}; //!< [AVC] MB disable skip map provided by framework
196 HANDLE gpuAppTaskEvent = nullptr; // MSDK event handling
197 //Call back to application. This informs the application all ENC kernel workload is submitted(in case of HEVC VME)
198 //such that Application can make use of render engine when encoder is working on PAK. this helps in efficient utilisation of
199 //Render engine for improving the performance as the render engine will be idle when encoder is working on PAK.
200 void * plastEncKernelSubmissionCompleteCallback = nullptr;
201
202
203 bool bStreamOutEnable = false;
204 PMOS_RESOURCE pStreamOutBuffer = nullptr; // StreamOut buffer
205 bool bCoeffRoundTag = false;
206 uint32_t uiRoundIntra = 0;
207 uint32_t uiRoundInter = 0;
208
209 PMOS_RESOURCE presMbInlineData = nullptr;
210 PMOS_RESOURCE presMbConstSurface = nullptr;
211 PMOS_RESOURCE presVMEOutSurface = nullptr;
212 uint32_t uiMVoffset = 0; // App provides PAK objects and MV data in the same surface. This is offset to MV Data.
213 bool fullHeaderInAppData = false; //!< [JPEG]
214 uint32_t uiOverallNALPayload = 0;
215 MetaDataOffset metaDataOffset = {};
216 void * pSliceHeaderParams = nullptr; //!< [HEVC]
217
218 /*! \brief Specifies motion search modes that will be used.
219 *
220 * SubPelMode is only valid when bEnableSubPelMode is true. Following are valid values of SubPelMode:
221 * 0:Integer mode searching
222 * 1:Half-pel mode searching
223 * 2:Reserved
224 * 3:Quarter-pel mode searching
225 */
226 bool bEnableSubPelMode = false;
227 uint8_t SubPelMode = 0;
228
229 PMOS_RESOURCE m_presPredication = nullptr; //! \brief [Predication] Resource for predication
230 uint64_t m_predicationResOffset = 0; //! \brief [Predication] Offset for Predication resource
231 bool m_predicationNotEqualZero = false; //! \brief [Predication] Predication mode
232 bool m_predicationEnabled = false; //! \brief [Predication] Indicates whether or not Predication is enabled
233 PMOS_RESOURCE *m_tempPredicationBuffer = nullptr; //! \brief [Predication] Temp buffer for Predication
234
235 bool m_setMarkerEnabled = false; //! \brief [SetMarker] Indicates whether or not SetMarker is enabled
236 PMOS_RESOURCE m_presSetMarker = nullptr; //! \brief [SetMarker] Resource for SetMarker
237 };
238
239 //!
240 //! \struct PerfTagSetting
241 //! \brief Setting of performance tags
242 //!
243 struct PerfTagSetting
244 {
245 union
246 {
247 struct
248 {
249 uint16_t PictureCodingType : 2;
250 uint16_t CallType : 6;
251 uint16_t Mode : 4;
252 uint16_t : 4;
253 };
254 uint16_t Value;
255 };
256 };
257
258 //!
259 //! \enum MbBrcSetting
260 //! \brief Indicate the MBBRC settings
261 //!
262 enum MbBrcSetting
263 {
264 mbBrcInternal = 0,
265 mbBrcEnabled = 1,
266 mbBrcDisabled = 2,
267 };
268
269 //!
270 //! \struct VdencBrcPakMmio
271 //! \brief MMIO of BRC and PAK
272 //!
273 struct VdencBrcPakMmio
274 {
275 uint32_t dwReEncode[4];
276 };
277
278 //!
279 //! \struct EncodeStatusReadParams
280 //! \brief Read encode states parameters
281 //!
282 struct EncodeStatusReadParams
283 {
284 bool vdencBrcEnabled = false;
285 bool waReadVDEncOverflowStatus = false;
286 uint32_t mode = 0;
287
288 uint32_t vdencBrcNumOfSliceOffset = 0;
289 PMOS_RESOURCE *resVdencBrcUpdateDmemBufferPtr = nullptr;
290
291 PMOS_RESOURCE resBitstreamByteCountPerFrame = nullptr;
292 uint32_t bitstreamByteCountPerFrameOffset = 0;
293
294 PMOS_RESOURCE resBitstreamSyntaxElementOnlyBitCount = nullptr;
295 uint32_t bitstreamSyntaxElementOnlyBitCountOffset = 0;
296
297 PMOS_RESOURCE resQpStatusCount = nullptr;
298 uint32_t qpStatusCountOffset = 0;
299
300 PMOS_RESOURCE resNumSlices = nullptr;
301 uint32_t numSlicesOffset = 0;
302
303 PMOS_RESOURCE resImageStatusMask = nullptr;
304 uint32_t imageStatusMaskOffset = 0;
305
306 PMOS_RESOURCE resImageStatusCtrl = nullptr;
307 uint32_t imageStatusCtrlOffset = 0;
308 };
309
310 //!
311 //! \struct FeiPreEncParams
312 //! \brief Fei pre-encode parameters
313 //!
314 struct FeiPreEncParams
315 {
316 MOS_RESOURCE resMvPredBuffer;
317 MOS_RESOURCE resMbQpBuffer;
318 MOS_RESOURCE resMvBuffer;
319 MOS_RESOURCE resStatsBuffer;
320 MOS_RESOURCE resStatsBotFieldBuffer;
321
322 PMOS_SURFACE psCurrOriginalSurface;
323
324 bool bInterlaced;
325 uint32_t dwNumPastReferences;
326 uint32_t dwNumFutureReferences;
327
328 bool bCurPicUpdated;
329 CODEC_PICTURE CurrOriginalPicture;
330
331 CODEC_PICTURE PastRefPicture;
332 bool bPastRefUpdated;
333 MOS_SURFACE sPastRefSurface;
334 bool bPastRefStatsNeeded;
335 MOS_RESOURCE sPastRefStatsBuffer;
336 MOS_RESOURCE sPastRefStatsBotFieldBuffer;
337
338 CODEC_PICTURE FutureRefPicture;
339 bool bFutureRefUpdated;
340 MOS_SURFACE sFutureRefSurface;
341 bool bFutureRefStatsNeeded;
342 MOS_RESOURCE sFutureRefStatsBuffer;
343 MOS_RESOURCE sFutureRefStatsBotFieldBuffer;
344
345 uint32_t dwFrameQp;
346 uint32_t dwLenSP;
347 uint32_t dwSearchPath;
348 uint32_t dwSubMBPartMask;
349 uint32_t dwIntraPartMask;
350 uint32_t dwSubPelMode;
351 uint32_t dwInterSAD;
352 uint32_t dwIntraSAD;
353 bool bAdaptiveSearch;
354
355 uint32_t dwMVPredictorCtrl;
356 bool bMBQp;
357 bool bFTEnable;
358 uint32_t dwRefWidth;
359 uint32_t dwRefHeight;
360 uint32_t dwSearchWindow;
361 bool bDisableMVOutput;
362 bool bDisableStatisticsOutput;
363 bool bEnable8x8Statistics;
364 bool bInputUpdated;
365 };
366
367 #endif // !__CODEC_DEF_ENCODE_H__