Debian Codegraph @

media_driver/agnostic/common/codec/hal/codechal_encoder_base.h

raw
1 /*
2 * Copyright (c) 2017-2025, 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 codechal_encoder_base.h
24 //! \brief Defines the encode interface for CodecHal.
25 //! \details The encode interface is further sub-divided by standard, this file is for the base interface which is shared by all encode standards.
26 //!
27
28 #ifndef __CODECHAL_ENCODER_BASE_H__
29 #define __CODECHAL_ENCODER_BASE_H__
30
31 #include "codechal.h"
32 #include "codechal_setting.h"
33 #include "codechal_hw.h"
34 #include "codechal_debug.h"
35 #include "codechal_encode_sfc.h"
36 #include "codechal_encode_csc_ds.h"
37 #include "codechal_encode_tracked_buffer.h"
38 #include "codechal_encode_allocator.h"
39 #include "codechal_mmc.h"
40 #include "codechal_utilities.h"
41 #include "codec_def_encode.h"
42 #include "cm_rt_umd.h"
43 #include "media_perf_profiler.h"
44 #include <algorithm> // std::reverse
45
46 //------------------------------------------------------------------------------
47 // Macros specific to MOS_CODEC_SUBCOMP_ENCODE sub-comp
48 //------------------------------------------------------------------------------
49 #define CODECHAL_ENCODE_ASSERT(_expr) \
50 MOS_ASSERT(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _expr)
51
52 #define CODECHAL_ENCODE_ASSERTMESSAGE(_message, ...) \
53 MOS_ASSERTMESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _message, ##__VA_ARGS__)
54
55 #define CODECHAL_ENCODE_WARNINGMESSAGE(_message, ...) \
56 MOS_WARNINGMESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _message, ##__VA_ARGS__)
57
58 #define CODECHAL_ENCODE_NORMALMESSAGE(_message, ...) \
59 MOS_NORMALMESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _message, ##__VA_ARGS__)
60
61 #define CODECHAL_ENCODE_VERBOSEMESSAGE(_message, ...) \
62 MOS_VERBOSEMESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _message, ##__VA_ARGS__)
63
64 #define CODECHAL_ENCODE_FUNCTION_ENTER \
65 MOS_FUNCTION_ENTER(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE)
66
67 #define CODECHAL_ENCODE_CHK_STATUS(_stmt) \
68 MOS_CHK_STATUS(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _stmt)
69
70 #define CODECHAL_ENCODE_CHK_STATUS_MESSAGE(_stmt, _message, ...) \
71 MOS_CHK_STATUS_MESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _stmt, _message, ##__VA_ARGS__)
72
73 #define CODECHAL_ENCODE_CHK_NULL(_ptr) \
74 MOS_CHK_NULL(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _ptr)
75
76 #define CODECHAL_ENCODE_CHK_NULL_NO_STATUS(_ptr) \
77 MOS_CHK_NULL_NO_STATUS(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _ptr)
78
79 #define CODECHAL_ENCODE_CHK_COND(_expr, _message, ...) \
80 MOS_CHK_COND(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE,_expr,_message, ##__VA_ARGS__)
81
82 #define CODECHAL_ENCODE_CHK_NULL_NO_STATUS_RETURN(_ptr) \
83 MOS_CHK_NULL_NO_STATUS_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _ptr)
84
85 #define CODECHAL_ENCODE_CHK_NULL_RETURN(_ptr) \
86 MOS_CHK_NULL_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _ptr)
87
88 #define CODECHAL_ENCODE_CHK_STATUS_RETURN(_stmt) \
89 MOS_CHK_STATUS_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _stmt)
90
91 #define CODECHAL_ENCODE_CHK_STATUS_MESSAGE_RETURN(_stmt, _message, ...) \
92 MOS_CHK_STATUS_MESSAGE_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _stmt, _message, ##__VA_ARGS__)
93
94 #define CODECHAL_ENCODE_CHK_COND_RETURN(_expr, _message, ...) \
95 MOS_CHK_COND_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE,_expr,_message, ##__VA_ARGS__)
96
97 #define CODECHAL_ENCODE_CHK_NULL_WITH_DESTROY_RETURN(_ptr, destroyFunction) \
98 MOS_CHK_COND_WITH_DESTROY_RETURN_VALUE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, (nullptr == _ptr), destroyFunction, MOS_STATUS_NULL_POINTER, "error nullptr!")
99
100 #define CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(_stmt, destroyFunction) \
101 { \
102 MOS_STATUS sts = (MOS_STATUS)(_stmt); \
103 MOS_CHK_COND_WITH_DESTROY_RETURN_VALUE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, (MOS_STATUS_SUCCESS != sts), destroyFunction, sts, "error status!") \
104 }
105
106 // User Feature Report Writeout
107 #define CodecHalEncode_WriteKey64(key, value, mosCtx)\
108 {\
109 MOS_USER_FEATURE_VALUE_WRITE_DATA UserFeatureWriteData = __NULL_USER_FEATURE_VALUE_WRITE_DATA__;\
110 UserFeatureWriteData.Value.i64Data = (value);\
111 UserFeatureWriteData.ValueID = (key);\
112 MOS_UserFeature_WriteValues_ID(nullptr, &UserFeatureWriteData, 1, mosCtx);\
113 }
114
115 #define CodecHalEncode_WriteKey(key, value, mosCtx)\
116 {\
117 MOS_USER_FEATURE_VALUE_WRITE_DATA UserFeatureWriteData = __NULL_USER_FEATURE_VALUE_WRITE_DATA__;\
118 UserFeatureWriteData.Value.i32Data = (value);\
119 UserFeatureWriteData.ValueID = (key);\
120 MOS_UserFeature_WriteValues_ID(nullptr, &UserFeatureWriteData, 1, mosCtx);\
121 }
122
123 #define CodecHalEncode_WriteStringKey(key, value, len, mosCtx)\
124 {\
125 MOS_USER_FEATURE_VALUE_WRITE_DATA UserFeatureWriteData = __NULL_USER_FEATURE_VALUE_WRITE_DATA__;\
126 UserFeatureWriteData.Value.StringData.pStringData = (value);\
127 UserFeatureWriteData.Value.StringData.uSize = (len);\
128 UserFeatureWriteData.ValueID = (key);\
129 MOS_UserFeature_WriteValues_ID(nullptr, &UserFeatureWriteData, 1, mosCtx);\
130 }
131
132 //!
133 //! \brief Recycled buffers are buffers which are locked and populated each execute
134 //! to be consumed by HW. The driver loops through these buffers, if for the
135 //! current index it is detected that the buffers for that index are still in
136 //! use by HW, the driver waits until the buffers are available. 6 of each
137 //! recycled buffer type are allocated to achieve performance parity with the
138 //! old method of not having any waits.
139 //!
140 #define CODECHAL_ENCODE_RECYCLED_BUFFER_NUM 6
141
142 // Encode Sizes
143 #define CODECHAL_ENCODE_VME_BBUF_NUM 2
144 #define CODECHAL_ENCODE_MIN_SCALED_SURFACE_SIZE 48
145 #define CODECHAL_ENCODE_BRC_PAK_STATISTICS_SIZE 64
146 #define CODECHAL_ENCODE_MAX_NUM_MAD_BUFFERS CODEC_MAX_NUM_REF_FIELD
147 #define CODECHAL_VDENC_BRC_NUM_OF_PASSES 2
148 #define CODECHAL_VDENC_BRC_NUM_OF_PASSES_FOR_TILE_REPLAY 22
149 #define CODECHAL_DP_MAX_NUM_BRC_PASSES 4
150 #define CODECHAL_VDENC_NUMIMEPREDICTORS 8
151 #define CODECHAL_VDENC_NUMIMEPREDICTORS_SPEED 4
152 #define CODECHAL_VDENC_NUMIMEPREDICTORS_QUALITY 12
153 #define CODECHAL_CMDINITIALIZER_MAX_CMD_SIZE CODECHAL_CACHELINE_SIZE * 4
154 #define CODECHAL_ENCODE_NUM_MAX_VME_L0_REF 8 // multiref - G7.5+ - used from DDI
155 #define CODECHAL_ENCODE_NUM_MAX_VME_L1_REF 2 // multiref - G7.5+ - used from DDI
156 #define CODECHAL_ENCODE_ME_DATA_SIZE_MULTIPLIER (CODECHAL_ENCODE_NUM_MAX_VME_L0_REF + CODECHAL_ENCODE_NUM_MAX_VME_L1_REF)
157 #define CODECHAL_ENCODE_FIELD_NUM_MAX_VME_L0_REF 4 // multiref - G7.5+
158 #define CODECHAL_ENCODE_FIELD_NUM_MAX_VME_L1_REF 1 // multiref - G7.5+
159 #define CODECHAL_VP9_MB_CODE_SIZE 204
160
161 // BRC
162 #define CODECHAL_ENCODE_MIN_BITS_PER_PIXEL 12 // 8b 420
163 #define CODECHAL_ENCODE_MAX_BITSTREAM_COMPRESSION 700
164
165 typedef enum _CODECHAL_ENCODE_BRC_KERNEL_STATE_IDX
166 {
167 CODECHAL_ENCODE_BRC_IDX_INIT = 0,
168 CODECHAL_ENCODE_BRC_IDX_FrameBRC_UPDATE,
169 CODECHAL_ENCODE_BRC_IDX_RESET,
170 CODECHAL_ENCODE_BRC_IDX_IFRAMEDIST,
171 CODECHAL_ENCODE_BRC_IDX_BLOCKCOPY,
172 CODECHAL_ENCODE_BRC_IDX_MbBRC_UPDATE, // extra MbBRCUpdate kernel starting GEN9
173 CODECHAL_ENCODE_BRC_IDX_NUM
174 } CODECHAL_ENCODE_BRC_KERNEL_STATE_IDX;
175
176 typedef struct KernelHeaderEncode
177 {
178 int nKernelCount;
179
180 union
181 {
182 struct
183 {
184 CODECHAL_KERNEL_HEADER Gen10_HEVC_VP9_VDEnc_DS4X_Frame;
185 CODECHAL_KERNEL_HEADER Gen10_HEVC_VP9_VDEnc_DS4X_Field;
186 CODECHAL_KERNEL_HEADER Gen10_HEVC_VP9_VDEnc_DS2X_Frame;
187 CODECHAL_KERNEL_HEADER Gen10_HEVC_VP9_VDEnc_DS2X_Field;
188 CODECHAL_KERNEL_HEADER Gen10_HEVC_VP9_VDEnc_HME_P;
189 CODECHAL_KERNEL_HEADER Gen10_HEVC_VP9_VDEnc_HME_B;
190 CODECHAL_KERNEL_HEADER Gen10_HEVC_VP9_VDEnc_HME_Streamin;
191 CODECHAL_KERNEL_HEADER Gen10_HEVC_VP9_VDEnc_HME_HEVC_Streamin;
192 CODECHAL_KERNEL_HEADER Gen10_HEVC_VP9_VDEnc_HMEDetection;
193 };
194 };
195
196 }KernelHeaderEncode;
197
198 //!
199 //! \enum BindingTableOffsetKernel
200 //! \brief Binding table offset kernel
201 //!
202 enum BindingTableOffsetKernel
203 {
204 // VDEnc HME kernel
205 HmeBegin = 0,
206 HmeMvDataSurfaceCm = HmeBegin,
207 Hme16xMeMvDataSurfaceCm,
208 Hme32xMeMvDataSurfaceCm = Hme16xMeMvDataSurfaceCm,
209 HmeDistortionSurfaceCm,
210 HmeBrcDistortionCm,
211 HmeCurrForFwdRefCm,
212 HmeFwdRefIdx0Cm,
213 HmeReserved1Cm,
214 HmeFwdRefIdx1Cm,
215 HmeReserved2Cm,
216 HmeFwdRefIdx2Cm,
217 HmeReserved3Cm,
218 HmeFwdRefIdx3Cm,
219 HmeReserved4Cm,
220 HmeFwdRefIdx4Cm,
221 HmeReserved5Cm,
222 HmeFwdRefIdx5Cm,
223 HmeReserved6Cm,
224 HmeFwdRefIdx6Cm,
225 HmeReserved7Cm,
226 HmeFwdRefIdx7Cm,
227 HmeReserved8Cm,
228 HmeCurrForBwdRefCm,
229 HmeBwdRefIdx0Cm,
230 HmeReserved9Cm,
231 HmeBwdRefIdx1Cm,
232 HmeReserved10Cm,
233 HmeVdencStreaminOutputCm,
234 HmeVdencStreaminInputCm,
235 HmeEnd,
236 };
237
238 //!
239 //! \enum BrcUpdateFlag
240 //! \brief Indicate the Brc Update Flag
241 //!
242 enum BrcUpdateFlag
243 {
244 brcUpdateIsField = 0x01,
245 brcUpdateIsMbaff = (0x01 << 1),
246 brcUpdateIsBottomField = (0x01 << 2),
247 brcUpdateAutoPbFrameSize = (0x01 << 3),
248 brcUpdateIsActualQp = (0x01 << 6),
249 brcUpdateIsReference = (0x01 << 7)
250 };
251
252 // User Feature Key Report Writeout
253 #define CodecHalEncodeWriteKey64(key, value, mosCtx)\
254 {\
255 MOS_USER_FEATURE_VALUE_WRITE_DATA UserFeatureWriteData = __NULL_USER_FEATURE_VALUE_WRITE_DATA__;\
256 UserFeatureWriteData.Value.i64Data = (value);\
257 UserFeatureWriteData.ValueID = (key);\
258 MOS_UserFeature_WriteValues_ID(nullptr, &UserFeatureWriteData, 1, mosCtx);\
259 }
260
261 #define CodecHalEncodeWriteKey(key, value, mosCtx)\
262 {\
263 MOS_USER_FEATURE_VALUE_WRITE_DATA UserFeatureWriteData = __NULL_USER_FEATURE_VALUE_WRITE_DATA__;\
264 UserFeatureWriteData.Value.i32Data = (value);\
265 UserFeatureWriteData.ValueID = (key);\
266 MOS_UserFeature_WriteValues_ID(nullptr, &UserFeatureWriteData, 1, mosCtx);\
267 }
268
269 #define CodecHalEncodeWriteStringKey(key, value, len, mosCtx)\
270 {\
271 MOS_USER_FEATURE_VALUE_WRITE_DATA UserFeatureWriteData = __NULL_USER_FEATURE_VALUE_WRITE_DATA__;\
272 UserFeatureWriteData.Value.StringData.pStringData = (value);\
273 UserFeatureWriteData.Value.StringData.uSize = (len);\
274 UserFeatureWriteData.ValueID = (key);\
275 MOS_UserFeature_WriteValues_ID(nullptr, &UserFeatureWriteData, 1, mosCtx);\
276 }
277
278 // ---------------------------
279 // Tables
280 // ---------------------------
281
282 // ---------------------------
283 // Structures
284 // ---------------------------
285
286 #define CODECHAL_ENCODE_SET_PERFTAG_INFO(perfTag, type) { \
287 perfTag.Value = 0; \
288 perfTag.Mode = m_mode & CODECHAL_ENCODE_MODE_BIT_MASK; \
289 perfTag.CallType = type; \
290 perfTag.PictureCodingType = m_pictureCodingType > 3 ? 0 : m_pictureCodingType; \
291 m_osInterface->pfnSetPerfTag(m_osInterface, perfTag.Value); \
292 m_osInterface->pfnIncPerfBufferID(m_osInterface); }
293
294 //!
295 //! \struct CodechalEncodeMdfKernelResource
296 //! \brief Codechal encode mdf kernel resource
297 //!
298 struct CodechalEncodeMdfKernelResource
299 {
300 void *pCommonISA;
301 CmProgram *pCmProgram;
302 CmKernel **ppKernel;
303 uint8_t *pCurbe;
304 CmThreadSpace *pTS;
305 CmBuffer **ppCmBuf;
306 CmSurface2D **ppCmSurf;
307 SurfaceIndex **ppCmVmeSurf;
308 CmEvent *e;
309
310 uint8_t KernelNum;
311 uint8_t BufNum;
312 uint8_t SurfNum;
313 uint8_t VmeSurfNum;
314 uint16_t wCurbeSize;
315 uint16_t wReserved;
316 };
317
318 //!
319 //! \struct MfeParams
320 //! \brief Mfe encode parameters
321 //!
322 struct MfeParams
323 {
324 uint32_t streamId; //!< Unique id
325 uint32_t submitIndex; //!< Index during this submission
326 uint32_t submitNumber; //!< Total stream number during this submission
327 uint32_t maxWidth; //!< Maximum width for all frames
328 uint32_t maxHeight; //!< Maximum height for all frames
329 };
330
331 //!
332 //! \struct MfeSharedState
333 //! \brief State shared across multiple streams
334 //!
335 struct MfeSharedState
336 {
337 CodechalHwInterface *pHwInterface = nullptr;
338 PMOS_INTERFACE pOsInterface;
339 PMHW_KERNEL_STATE pMfeMbEncKernelState; //!< Set in the first stream, Used by the rest streams
340 uint32_t dwPicWidthInMB; //!< Keep the maximum width
341 uint32_t dwPicHeightInMB; //!< Keep the maximum height
342 uint16_t sliceHeight; //!< Keep the maximum slice height
343 uint32_t maxTheadWidth = 0; //!< Keep the maximum width of the threadspace
344 uint32_t maxTheadHeight = 0; //!< Keep the maximum Height of the threadspace
345 uint32_t *maxThreadWidthFrames = nullptr; //!< Keep the thread space width for all frames
346
347 CmDevice *pCmDev = nullptr; //!< Set in the first stream, Used by the rest streams
348 CmTask *pCmTask = nullptr;
349 CmQueue *pCmQueue = nullptr;
350 CodechalEncodeMdfKernelResource *resMbencKernel = nullptr;
351 SurfaceIndex *vmeSurface = nullptr;
352 SurfaceIndex *commonSurface = nullptr;
353 std::vector<CodechalEncoderState*> encoders;
354 };
355
356 //!
357 //! \enum EncOperation
358 //! \brief Encode operations
359 //!
360 enum EncOperation
361 {
362 ENC_SCALING4X = 0,
363 ENC_SCALING2X,
364 ENC_ME,
365 ENC_BRC,
366 ENC_MBENC,
367 ENC_MBENC_ADV,
368 ENC_RESETVLINESTRIDE,
369 ENC_MC,
370 ENC_MBPAK,
371 ENC_DEBLOCK,
372 ENC_PREPROC,
373 VDENC_ME,
374 ENC_WP,
375 ENC_SFD, //!< Static frame detection
376 ENC_SCOREBOARD,
377 ENC_MBENC_I_LUMA,
378 ENC_MPU,
379 ENC_TPU,
380 ENC_SCALING_CONVERSION, //!< for HEVC
381 ENC_DYS,
382 ENC_INTRA_DISTORTION,
383 VDENC_ME_P,
384 VDENC_ME_B,
385 VDENC_STREAMIN,
386 VDENC_STREAMIN_HEVC,
387 VDENC_STREAMIN_HEVC_RAB
388 };
389
390 //!
391 //! \enum HmeLevel
392 //! \brief Indicate the Hme level
393 //!
394 enum HmeLevel
395 {
396 HME_LEVEL_4x = 0,
397 HME_LEVEL_16x = 1,
398 HME_LEVEL_32x = 2
399 };
400
401 //!
402 //! \enum EncodeMeMode
403 //! \brief Encode me mode
404 //!
405 enum EncodeMeMode
406 {
407 CODECHAL_ENCODE_ME16X_BEFORE_ME4X = 0,
408 CODECHAL_ENCODE_ME16X_ONLY = 1,
409 CODECHAL_ENCODE_ME4X_ONLY = 2,
410 CODECHAL_ENCODE_ME4X_AFTER_ME16X = 3
411 };
412
413 //!
414 //! \enum CodechalEncodeBrcNumPasses
415 //! \brief used in GetNumBrcPakPasses
416 //!
417 enum CodechalEncodeBrcNumPasses
418 {
419 CODECHAL_ENCODE_BRC_SINGLE_PASS = 1, // No IPCM case
420 CODECHAL_ENCODE_BRC_MINIMUM_NUM_PASSES = 2, // 2 to cover IPCM case
421 CODECHAL_ENCODE_BRC_DEFAULT_NUM_PASSES = 4,
422 CODECHAL_ENCODE_BRC_MAXIMUM_NUM_PASSES = 7
423 };
424
425 //!
426 //! \struct HmeParams
427 //! \brief Indicate the Hme parameters
428 //!
429 struct HmeParams
430 {
431 // ME
432 PMOS_SURFACE ps4xMeMvDataBuffer;
433 PMOS_SURFACE ps16xMeMvDataBuffer;
434 PMOS_SURFACE ps32xMeMvDataBuffer;
435 PMOS_SURFACE ps4xMeDistortionBuffer;
436 PMOS_RESOURCE presMvAndDistortionSumSurface;
437 bool b4xMeDistortionBufferSupported;
438 };
439
440 //!
441 //! \brief Generic binding table
442 //!
443 struct GenericBindingTable
444 {
445 uint32_t dwMediaState;
446 uint32_t dwBindingTableStartOffset;
447 uint32_t dwNumBindingTableEntries;
448 uint32_t dwBindingTableEntries[64];
449 };
450 using PCODECHAL_ENCODE_BINDING_TABLE_GENERIC = GenericBindingTable*;
451
452 //!
453 //! \struct MeKernelBindingTable
454 //! \brief The struct of Me kernel binding table
455 //!
456 struct MeKernelBindingTable
457 {
458 uint32_t dwMEMVDataSurface;
459 uint32_t dwMECurrY;
460 uint32_t dwMEFwdRefY;
461 uint32_t dwMEBwdRefY;
462 uint32_t dwMECurrForFwdRef;
463 uint32_t dwMEFwdRef;
464 uint32_t dwMECurrForBwdRef;
465 uint32_t dwMEBwdRef;
466 uint32_t dw16xMEMVDataSurface;
467 uint32_t dw32xMEMVDataSurface;
468 uint32_t dwMEDist;
469 uint32_t dwMEBRCDist;
470 uint32_t dwMECurrForFwdRefIdx[CODECHAL_ENCODE_NUM_MAX_VME_L0_REF];
471 uint32_t dwMECurrForBwdRefIdx[CODECHAL_ENCODE_NUM_MAX_VME_L1_REF];
472
473 // Frame Binding Table Entries
474 uint32_t dwMEFwdRefPicIdx[CODECHAL_ENCODE_NUM_MAX_VME_L0_REF];
475 uint32_t dwMEBwdRefPicIdx[CODECHAL_ENCODE_NUM_MAX_VME_L1_REF];
476
477 // Field Binding Table Entries
478 uint32_t dwMEFwdRefPicTopIdx[CODECHAL_ENCODE_FIELD_NUM_MAX_VME_L0_REF];
479 uint32_t dwMEFwdRefPicBotIdx[CODECHAL_ENCODE_FIELD_NUM_MAX_VME_L0_REF];
480 uint32_t dwMEBwdRefPicTopIdx[CODECHAL_ENCODE_FIELD_NUM_MAX_VME_L1_REF];
481 uint32_t dwMEBwdRefPicBotIdx[CODECHAL_ENCODE_FIELD_NUM_MAX_VME_L1_REF];
482
483 uint32_t dwVdencStreamInSurface;
484 uint32_t dwVdencStreamInInputSurface;
485
486 uint32_t dwBindingTableStartOffset;
487 uint32_t dwNumBindingTableEntries;
488 };
489
490 //!
491 //! \struct MeSurfaceParams
492 //! \brief The struct of Me surface parameters
493 //!
494 struct MeSurfaceParams
495 {
496 PCODEC_REF_LIST *ppRefList;
497 PCODEC_PIC_ID pPicIdx;
498 PCODEC_PICTURE pCurrOriginalPic;
499 PMOS_SURFACE ps4xMeMvDataBuffer;
500 uint32_t dw4xMeMvBottomFieldOffset;
501 PMOS_SURFACE ps16xMeMvDataBuffer;
502 uint32_t dw16xMeMvBottomFieldOffset;
503 PMOS_SURFACE ps32xMeMvDataBuffer;
504 uint32_t dw32xMeMvBottomFieldOffset;
505 uint32_t dw4xScaledBottomFieldOffset;
506 uint32_t dw16xScaledBottomFieldOffset;
507 uint32_t dw32xScaledBottomFieldOffset;
508 PMOS_SURFACE psMeDistortionBuffer;
509 uint32_t dwMeDistortionBottomFieldOffset;
510 PMOS_SURFACE psMeBrcDistortionBuffer;
511 PMOS_RESOURCE psMeVdencStreamInBuffer;
512 uint32_t dwMeBrcDistortionBottomFieldOffset;
513 uint32_t dwDownscaledWidthInMb;
514 uint32_t dwDownscaledHeightInMb;
515 uint32_t dwVDEncStreamInSurfaceSize;
516 uint32_t dwVerticalLineStride;
517 uint32_t dwVerticalLineStrideOffset;
518 bool b16xMeInUse;
519 bool b32xMeInUse;
520 bool b16xMeEnabled;
521 bool b32xMeEnabled;
522 bool bVdencStreamInEnabled;
523 PCODEC_PICTURE pL0RefFrameList;
524 PCODEC_PICTURE pL1RefFrameList;
525 uint32_t dwNumRefIdxL0ActiveMinus1;
526 uint32_t dwNumRefIdxL1ActiveMinus1;
527 PMHW_KERNEL_STATE pKernelState;
528 MeKernelBindingTable* pMeBindingTable;
529 bool bMbaff;
530 bool b4xMeDistortionBufferSupported;
531 };
532
533 //!
534 //! \struct MeCurbeParams
535 //! \brief The struct of Me Curbe parameters
536 //!
537 struct MeCurbeParams
538 {
539 PMHW_KERNEL_STATE pKernelState;
540 HmeLevel hmeLvl;
541 bool b16xMeEnabled;
542 bool b32xMeEnabled;
543 bool segmapProvided;
544 uint8_t TargetUsage;
545 uint8_t *pMEMethodTable;
546 uint8_t *pBMEMethodTable;
547 int32_t MaxMvLen;
548
549 // Picture parameters
550 CODEC_PICTURE CurrOriginalPic; // Source sent in by BeginFrame
551 int8_t pic_init_qp_minus26;
552
553 // Slice parameters
554 int8_t slice_qp_delta;
555 uint8_t num_ref_idx_l0_active_minus1;
556 uint8_t num_ref_idx_l1_active_minus1;
557 bool List0RefID0FieldParity;
558 bool List0RefID1FieldParity;
559 bool List0RefID2FieldParity;
560 bool List0RefID3FieldParity;
561 bool List0RefID4FieldParity;
562 bool List0RefID5FieldParity;
563 bool List0RefID6FieldParity;
564 bool List0RefID7FieldParity;
565 bool List1RefID0FieldParity;
566 bool List1RefID1FieldParity;
567 uint8_t *pCurbeBinary;
568 };
569
570 //!
571 //! \struct EncodeReadBrcPakStatsParams
572 //! \brief Encode read brc pak states parameters
573 //!
574 struct EncodeReadBrcPakStatsParams
575 {
576 CodechalHwInterface *pHwInterface;
577 PMOS_RESOURCE presBrcPakStatisticBuffer;
578 PMOS_RESOURCE presStatusBuffer;
579 uint32_t dwStatusBufNumPassesOffset;
580 uint8_t ucPass;
581 MOS_GPU_CONTEXT VideoContext;
582 };
583
584 //!
585 //! \struct PakIntegrationBrcData
586 //! \brief The struct of Huc input command 2
587 //!
588 struct PakIntegrationBrcData
589 {
590 uint32_t FrameByteCount;
591 uint32_t FrameByteCountNoHeader;
592 uint32_t HCP_ImageStatusControl;
593 };
594
595 //!
596 //! \struct SearchPathDelta
597 //! \brief The struct of Search Path Delta
598 //!
599 struct SearchPathDelta
600 {
601 uint8_t SearchPathDelta_X : 4;
602 uint8_t SearchPathDelta_Y : 4;
603 };
604
605 //!
606 //! \struct SendKernelCmdsParams
607 //! \brief Struct of send kernel commands parameters
608 //!
609 struct SendKernelCmdsParams
610 {
611 CODECHAL_MEDIA_STATE_TYPE EncFunctionType = CODECHAL_NUM_MEDIA_STATES;
612 uint32_t uiDshIdx = 0;
613 uint8_t ucDmvPredFlag = 0;
614 bool bBrcResetRequested = false;
615 bool bEnable45ZWalkingPattern = false;
616 bool bEnableCustomScoreBoard = false;
617 PMHW_VFE_SCOREBOARD pCustomScoreBoard = nullptr;
618 PMHW_KERNEL_STATE pKernelState = nullptr;
619 bool bDshInUse = false;
620 };
621
622 //!
623 //! \struct BrcQpReport
624 //! \brief Struct of Query bit rate control and QP Status
625 //!
626 struct BrcQpReport
627 {
628 // uint32_t 0
629 union
630 {
631 struct
632 {
633 uint32_t QPPrimeY : 8;
634 uint32_t QPPrimeCb : 8;
635 uint32_t QPPrimeCr : 8;
636 uint32_t Reserved : 8;
637 };
638 struct
639 {
640 uint32_t Value;
641 };
642 } DW0;
643
644 // uint32_t 1 ~ 15
645 struct
646 {
647 uint32_t Value[15];
648 };
649 };
650
651 //!
652 //! \struct LookaheadStatus
653 //! \brief Struct of Query bit rate control and QP Status
654 //!
655 struct LookaheadReport
656 {
657 uint32_t StatusReportNumber;
658 union
659 {
660 struct
661 {
662 uint32_t cqmHint : 8;
663 uint32_t intraHint : 1;
664 uint32_t reserved2 : 22;
665 uint32_t isValid : 1;
666 };
667 uint32_t encodeHints;
668 };
669 uint32_t targetFrameSize;
670 uint32_t targetBufferFulness;
671 uint32_t pyramidDeltaQP;
672 uint8_t adaptive_rounding;
673 uint8_t miniGopSize;
674 uint8_t reserved1[2];
675 uint32_t reserved3[10];
676 };
677
678 //!
679 //! \struct EncodeBrcBuffers
680 //! \brief Encode brc buffers
681 //!
682 struct EncodeBrcBuffers
683 {
684 MOS_RESOURCE resBrcHistoryBuffer; // BRC history buffer
685 MOS_RESOURCE resBrcPakStatisticBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM];
686 uint32_t uiCurrBrcPakStasIdxForRead;
687 uint32_t uiCurrBrcPakStasIdxForWrite;
688 MOS_RESOURCE resBrcImageStatesReadBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM]; // read only BRC image state buffer
689 MOS_RESOURCE resBrcImageStatesWriteBuffer; // write only BRC image state buffer
690 MOS_RESOURCE resHevcBrcImageStatesWriteBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM]; // write only HEVC BRC image state buffers
691 MOS_RESOURCE resPakQPInputTable;
692 MOS_RESOURCE resBrcConstantDataBuffer;
693 MOS_RESOURCE resEncoderCfgCommandReadBuffer;
694 MOS_RESOURCE resEncoderCfgCommandWriteBuffer;
695 MOS_RESOURCE resBrcPakStatsBeforeDumpBuffer; // These buffers are used to dump all the MMIO read values
696 MOS_RESOURCE resBrcPakStatsAfterDumpBuffer; // which are super-set of PakStat
697 MOS_SURFACE sBrcConstantDataBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM];
698 MOS_SURFACE sMeBrcDistortionBuffer;
699 uint32_t dwMeBrcDistortionBottomFieldOffset;
700 MOS_RESOURCE resMbBrcConstDataBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM];
701 MOS_SURFACE sBrcMbQpBuffer;
702 uint32_t dwBrcMbQpBottomFieldOffset;
703 MOS_RESOURCE resBrcPicHeaderInputBuffer;
704 MOS_RESOURCE resBrcPicHeaderOutputBuffer;
705 MOS_RESOURCE resMbEncAdvancedDsh;
706 MOS_RESOURCE resMbEncBrcBuffer;
707 MOS_SURFACE sBrcRoiSurface; // BRC ROI surface
708 PMHW_KERNEL_STATE pMbEncKernelStateInUse;
709 };
710
711 //!
712 //! \struct CODECHAL_ENCODE_BUFFER
713 //! \brief Codechal encode buffer
714 //!
715 struct CODECHAL_ENCODE_BUFFER
716 {
717 MOS_RESOURCE sResource;
718 uint32_t dwSize = 0;
719 };
720 using PCODECHAL_ENCODE_BUFFER = CODECHAL_ENCODE_BUFFER*;
721
722 //!
723 //! \struct EncodeStatusReport
724 //! \brief Encode status report structure
725 //!
726 struct EncodeStatusReport
727 {
728 enum BLOCK_SIZE
729 {
730 BLOCK_4X4 = 0,
731 BLOCK_16X16 = 1,
732 };
733
734 struct FRAME_STATS_INFO
735 {
736 float PSNRLuma;
737 float PSNRCb;
738 float PSNRCr;
739 uint64_t SADLuma;
740 float Qp;
741
742 union
743 {
744 uint32_t NumMB;
745 uint32_t NumCTU;
746 };
747
748 BLOCK_SIZE BlockSize;
749 uint32_t NumIntraBlock;
750 uint32_t NumInterBlock;
751 uint32_t NumSkippedBlock;
752 uint32_t reserved[8];
753 };
754
755 struct CTUHeader
756 {
757 union
758 {
759 struct
760 {
761 uint32_t CUcountminus1 : 6;
762 uint32_t MaxDepth : 2;
763 uint32_t reserved : 24;
764 };
765 uint32_t DW0;
766 };
767 uint16_t CurrXAddr;
768 uint16_t CurrYAddr;
769 uint32_t reserved1;
770 };
771
772 struct Int16Pair
773 {
774 int16_t x;
775 int16_t y;
776 };
777
778 struct CUInfo
779 {
780 union
781 {
782 struct
783 {
784 uint32_t CU_Size : 2;
785 uint32_t CU_pred_mode : 1;
786 uint32_t CU_part_mode : 3;
787 uint32_t InterPred_IDC_MV0 : 2;
788 uint32_t InterPred_IDC_MV1 : 2;
789 uint32_t LumaIntraMode : 6;
790 uint32_t ChromaIntraMode : 3;
791 uint32_t reserved : 13;
792 };
793 uint32_t DW0;
794 };
795
796 union
797 {
798 struct
799 {
800 uint32_t LumaIntraMode4x4_1 : 6;
801 uint32_t LumaIntraMode4x4_2 : 6;
802 uint32_t LumaIntraMode4x4_3 : 6;
803 uint32_t reserved1 : 14;
804 };
805 uint32_t DW1;
806 };
807
808 int8_t QP;
809 uint8_t reserved2[3];
810 uint32_t SAD;
811
812 Int16Pair MV[2][2];
813
814 union
815 {
816 struct
817 {
818 uint32_t L0_MV0_RefID : 4;
819 uint32_t L0_MV1_RefID : 4;
820 uint32_t L1_MV0_RefID : 4;
821 uint32_t L1_MV1_RefID : 4;
822 uint32_t reserved3 : 16;
823 };
824 uint32_t DW8;
825 };
826
827 uint32_t reserved4[10];
828 };
829
830 struct CTUInfo
831 {
832 CTUHeader CtuHeader;
833 CUInfo CuInfo[64];
834 uint32_t reserved;
835 };
836
837 struct MBInfo
838 {
839 union
840 {
841 struct
842 {
843 uint32_t MBType : 5;
844 uint32_t InterMBMode : 2;
845 uint32_t IntraMBMode : 2;
846 uint32_t IntraMBFlag : 1;
847 uint32_t SubMBShapes : 8;
848 uint32_t SubMBShapeMode : 8;
849 uint32_t ChromaIntraPredMode : 2;
850 uint32_t reserved : 4;
851 };
852 uint32_t DW0;
853 };
854
855 uint32_t SAD;
856 int8_t Qp;
857 uint8_t reserved1[3];
858
859 uint16_t LumaIntraMode[4];
860
861 uint32_t reserved2;
862 };
863
864 struct BLOCK_STATS_INFO
865 {
866 union
867 {
868 uint32_t NumMB;
869 uint32_t NumCTU;
870 };
871
872 union
873 {
874 CTUInfo *HEVCCTUArray;
875 MBInfo *AVCMBArray;
876 };
877
878 uint32_t reserved[8];
879 };
880
881 struct BLOCK_SSIM_INFO
882 {
883 uint32_t NumBlockInColumns;
884 uint32_t NumBlockInRows;
885 uint8_t* BlockSsimArray;
886 uint32_t reserved1[2];
887 uint64_t reserved2[2];
888 };
889
890 struct BLOCK_QUALITY_INFO
891 {
892 BLOCK_SSIM_INFO BlockSsim2DS;
893 BLOCK_SSIM_INFO BlockSsim4DS;
894 BLOCK_SSIM_INFO BlockSsim8DS;
895 BLOCK_SSIM_INFO BlockSsim16DS;
896 uint32_t reserved1[32];
897 uint64_t reserved2[12];
898 };
899
900 CODECHAL_STATUS CodecStatus; //!< Status for the picture associated with this status report
901 uint32_t StatusReportNumber; //!< Status report number associated with the picture in this status report provided in CodechalEncoderState::Execute()
902 CODEC_PICTURE CurrOriginalPic; //!< Uncompressed frame information for the picture associated with this status report
903 CODECHAL_ENCODE_FUNCTION_ID Func; //!< Encode function requested at CodechalEncoderState::Execute()
904 PCODEC_REF_LIST pCurrRefList; //!< Reference list for the current frame, used for dump purposes with CodecHal Debug Tool
905 /*! \brief Specifies the order in which the statuses are expected.
906 *
907 * The order in which a status is returned is requested at the DDI level and the order itself is determined by StatusReportNumber.
908 * FALSE indicates the statuses should be returned in reverse order.
909 * TRUE indicates the statuses should be returned in sequential order.
910 */
911 bool bSequential;
912 /*! \brief Coded bitstream size reported by HW.
913 *
914 * The size reported by HW is the total bitstream size that is encoded by HW including any bitstream buffer overrun. That is, HW continues counting the encoded bytes past the programmed upperbound based on the allocated bitstream buffer size. The framework can compare this value to the allocated buffer size to determine if there was overflow for this frame and can act accordingly.
915 */
916 uint32_t bitstreamSize;
917 /*! \brief Qp value for Y used for the first PAK pass.
918 *
919 * It is not valid if CQP is set by framework.
920 */
921 int8_t QpY;
922 /*! \brief Suggested Qp delta value for Y.
923 *
924 * Framework can add this delta Qp with the first pass QpY to get the final Qp used for multi-pass. It is not valid if CQP is set by framework.
925 * Note: Framework can use this reported QpY and suggestedQpYDelta to set QpY in picture parameter to minimize LCU level Qp delta.
926 */
927 int8_t SuggestedQpYDelta;
928 uint8_t NumberPasses; //!< Number of PAK passes executed.
929 uint8_t AverageQp; //!< The average QP of all MBs or LCUs of the frame.
930 HwCounter HWCounterValue;
931 uint64_t * hwctr;
932 union
933 {
934 struct
935 {
936 uint32_t PanicMode : 1; //!< Indicates that panic mode was triggered by HW for this frame.
937 uint32_t SliceSizeOverflow : 1; //!< When SliceLevelRateCtrl is used, indicates the requested slice size was not met for one or more generated slices.
938 uint32_t NumSlicesNonCompliant : 1; //!< When SliceLevelRateCtrl is used, indicates whether or not the number of generated slices exceeds specification limits.
939 uint32_t LongTermReference : 1;
940 uint32_t FrameSkipped : 1;
941 uint32_t SceneChangeDetected : 1;
942 uint32_t : 26;
943 };
944 uint32_t QueryStatusFlags;
945 };
946 /*! \brief The average MAD (Mean Absolute Difference) across all macroblocks in the Y plane.
947 *
948 * The MAD value is the mean of the absolute difference between the pixels in the original block and the corresponding pixels in the block being used for comparison, from motion compensation or intra spatial prediction. MAD reporting is disabled by default.
949 */
950 uint32_t MAD;
951 uint32_t loopFilterLevel; //!< [VP9]
952 int8_t LongTermIndication; //!< [VP9]
953 uint16_t NextFrameWidthMinus1; //!< [VP9]
954 uint16_t NextFrameHeightMinus1; //!< [VP9]
955 uint8_t NumberSlices; //!< Number of slices generated for the frame.
956 uint16_t PSNRx100[3]; //!< PSNR for different channels
957 uint32_t NumberTilesInFrame; //!< Number of tiles generated for the frame.
958 uint8_t UsedVdBoxNumber; //!< Number of vdbox used.
959 uint32_t SizeOfSliceSizesBuffer; //!< Store the size of slice size buffer
960 uint16_t *pSliceSizes; //!< Pointer to the slice size buffer
961 uint32_t SizeOfTileInfoBuffer; //!< Store the size of tile info buffer
962 CodechalTileInfo* pHEVCTileinfo; //!< Pointer to the tile info buffer
963 uint32_t NumTileReported; //!< The number of tiles reported in status
964
965 /*! \brief indicate whether it is single stream encoder or MFE.
966 *
967 * For single stream encoder (regular), this value should be set to default 0. For Multi-Frame-Encoder (MFE), this value is the StreamId that is set by application.
968 */
969 uint32_t StreamId;
970
971 LookaheadReport* pLookaheadStatus; //!< Pointer to the lookahead status buffer. Valid in lookahead pass only.
972
973 FRAME_STATS_INFO *pFrmStatsInfo;
974 BLOCK_STATS_INFO *pBlkStatsInfo;
975
976 uint32_t reserved[6]; //!< align with apo path hal structure EncodeStatusReportData
977
978 uint32_t MSE[3];
979
980 BLOCK_QUALITY_INFO* pBlkQualityInfo;
981 };
982
983 //!
984 //! \struct EncodeStatusSliceReport
985 //! \brief The struct stores Encode status buffers
986 //!
987 struct EncodeStatusSliceReport
988 {
989 uint32_t SliceSizeOverflow;
990 uint8_t NumberSlices;
991 uint32_t SizeOfSliceSizesBuffer;
992 PMOS_RESOURCE pSliceSize;
993 uint32_t reserved;
994 };
995
996 //!
997 //! \struct EncodeStatus
998 //! \brief The struct stores Encode status
999 //!
1000 struct EncodeStatus
1001 {
1002 uint32_t dwStoredDataMfx; //!< HW requires a QW aligned offset for data storage
1003 uint32_t dwPad; //!< Pad
1004 struct
1005 {
1006 uint32_t dwStoredData;
1007 uint32_t dwPad;
1008 } qwStoredDataEnc[CODECHAL_NUM_MEDIA_STATES]; //!< Media states of stored encode data
1009 uint32_t dwStoredData; //!< SW stored data
1010 uint32_t dwMFCBitstreamByteCountPerFrame; //!< Media fixed function bitstream byte count per frame
1011 uint32_t dwMFCBitstreamSyntaxElementOnlyBitCount; //!< Media fixed function bitstream bit count for syntax element only
1012 uint32_t reserved;
1013 uint32_t dwImageStatusMask; //!< MUST ENSURE THAT THIS IS QWORD ALIGNED as it's used for the conditional BB end
1014 MHW_VDBOX_IMAGE_STATUS_CONTROL ImageStatusCtrl; //!< Used for storing the control flags for the image status
1015 uint32_t HuCStatusRegMask; //!< MUST ENSURE THAT THIS IS QWORD ALIGNED as it's used for the conditional BB end
1016 uint32_t HuCStatusReg; //!< Register value saving HuC Status
1017 MHW_VDBOX_PAK_NUM_OF_SLICES NumSlices; //!< Num of slices for encode
1018 uint32_t dwErrorFlags; //!< The definition is different on SNB/IVB, hence DWORD
1019 union
1020 {
1021 BrcQpReport BrcQPReport; //!< Query bit rate control and QP Status
1022 LookaheadReport lookaheadStatus; //!< Lookahead status. valid in lookahead pass only
1023 };
1024 uint32_t dwNumberPasses; //!< Number of passes
1025 uint32_t dwHeaderBytesInserted; //!< The size including header, prevention bytes and dummy "0xff" inserted by SW driver
1026 CodechalQpStatusCount QpStatusCount; //!< This is used to obtain the cumulative QP
1027 EncodeStatusReport encodeStatusReport; //!< The detailed encode status report structure
1028 uint16_t wPictureCodingType; //!< Type of picture coding
1029 uint32_t LoopFilterLevel; //!< The level of loop filter
1030 MHW_VDBOX_IMAGE_STATUS_CONTROL ImageStatusCtrlOfLastBRCPass; //!< The level of loop filter
1031 uint32_t dwSceneChangedFlag; //!< The flag indicate if the scene is changed
1032 uint64_t sumSquareError[3]; //!< The list of sum square error
1033 uint32_t dwSADLuma; //!< SAD for Y channel
1034 uint32_t dwIntraBlockCount; //!< Intra block count
1035 uint32_t dwInterBlockCount; //!< Inter block count
1036 uint32_t dwSkipBlockCount; //!< Skip block count
1037 EncodeStatusSliceReport sliceReport;
1038 uint32_t HuCStatus2Reg; //!< Register value saving HuC Status2
1039 };
1040
1041 //!
1042 //! \struct EncodeStatusBuffer
1043 //! \brief The sturct of encode status buffer
1044 //!
1045 struct EncodeStatusBuffer
1046 {
1047 uint8_t *pEncodeStatus; //!> needs to be first to ensure alingment of dwStoredDataMfx/Vme
1048 MOS_RESOURCE resStatusBuffer; //!> Handle of eStatus buffer
1049 uint32_t *pData; //!> Pointer of the buffer of actual data
1050 uint16_t wFirstIndex; //!> Indicate the first index of status
1051 uint16_t wCurrIndex; //!> Indicate current index of status
1052 uint32_t dwStoreDataOffset; //!> The offset of stored data
1053 uint32_t dwBSByteCountOffset; //!> The offset of BS byte count
1054 uint32_t dwBSSEBitCountOffset; //!> The offset of BS SE byte count
1055 uint32_t dwImageStatusMaskOffset; //!> The offset of image status mask
1056 uint32_t dwImageStatusCtrlOffset; //!> The offset of status control
1057 uint32_t dwHuCStatusMaskOffset; //!> The offset of HuC status register mask
1058 uint32_t dwHuCStatusRegOffset; //!> The offset of HuC status register
1059 uint32_t dwNumSlicesOffset; //!> The offset of silce num
1060 uint32_t dwErrorFlagOffset; //!> The offset of error flag
1061 uint32_t dwBRCQPReportOffset; //!> The offset of bitrate control QP report
1062 uint32_t dwNumPassesOffset; //!> The offset of passes number
1063 uint32_t dwQpStatusCountOffset; //!> The offset of QP status count
1064 uint32_t dwImageStatusCtrlOfLastBRCPassOffset; //!> The offset of image status control of last bitrate control pass
1065 uint32_t dwSceneChangedOffset; //!> The offset of the scene changed flag
1066 uint32_t dwSumSquareErrorOffset; //!> The offset of list of sum square error
1067 uint32_t dwSliceReportOffset; //!> The offset of slice size report structure
1068 uint32_t dwLookaheadStatusOffset; //!> The offset of lookahead status
1069 uint32_t dwSADLumaOffset; //!> The offset of SAD Luma
1070 uint32_t dwIntraBlockCountOffset; //!> The offset of intra block count
1071 uint32_t dwInterBlockCountOffset; //!> The offset of inter block count
1072 uint32_t dwSkipBlockCountOffset; //!> The offset of skip block count
1073 uint32_t dwSize; //!> Size of status buffer
1074 uint32_t dwReportSize; //!> Size of report
1075 uint32_t dwHuCStatus2RegOffset; //!> The offset of HuC status2 register
1076 };
1077
1078 //!
1079 //! \struct CodechalEncodeBbuf
1080 //! \brief Struct for Batch buffer
1081 //!
1082 struct CodechalEncodeBbuf
1083 {
1084 MHW_BATCH_BUFFER BatchBuffer;
1085 uint32_t dwSize;
1086 uint32_t dwNumMbsInBBuf;
1087 bool fieldScale;
1088 };
1089
1090 //!
1091 //! \struct CodechalEncodeIdOffsetParams
1092 //! \brief Indicate the ID Offset parameters
1093 //!
1094 struct CodechalEncodeIdOffsetParams
1095 {
1096 uint32_t Standard;
1097 CODECHAL_MEDIA_STATE_TYPE EncFunctionType;
1098 uint16_t wPictureCodingType;
1099 uint8_t ucDmvPredFlag;
1100 bool interlacedField;
1101 };
1102
1103 //!
1104 //! \struct VdencHucErrorStatus
1105 //! \brief Huc Error Flags
1106 //!
1107 struct VdencHucErrorStatus
1108 {
1109 uint32_t dwErrorFlag[4];
1110 };
1111
1112 //!
1113 //! \enum EncodeMode
1114 //! \brief Encode mode
1115 //!
1116 enum EncodeMode
1117 {
1118 encodeNormalMode = 0,
1119 encodePerformanceMode = 1,
1120 encodeQualityMode = 2
1121 };
1122
1123 class CodechalEncodeWP;
1124 #if USE_CODECHAL_DEBUG_TOOL
1125 class CodechalDebugEncodePar;
1126 #endif
1127
1128 //!
1129 //! \class CodechalEncoderGenState
1130 //! \brief Codechal encoder gen state
1131 //!
1132 class CodechalEncoderGenState
1133 {
1134 public:
1135 CodechalEncoderGenState(CodechalEncoderState* encoder);
1136
1137 virtual ~CodechalEncoderGenState() {}
1138
1139 CodechalEncoderState* m_encoder = nullptr;
1140 // Encoder private data
1141 CodechalHwInterface* m_hwInterface = nullptr;
1142 PMOS_INTERFACE m_osInterface = nullptr;
1143 CodechalDebugInterface* m_debugInterface = nullptr;
1144 MhwMiInterface* m_miInterface = nullptr; //!< Common Mi Interface
1145 MhwRenderInterface* m_renderEngineInterface = nullptr; //!< Render engine interface
1146 PMHW_STATE_HEAP_INTERFACE m_stateHeapInterface = nullptr; //!< State heap interface
1147
1148 virtual MOS_STATUS SetCurbeMe(
1149 MeCurbeParams* params)
1150 {
1151 return MOS_STATUS_SUCCESS;
1152 }
1153
1154 virtual MOS_STATUS SendMeSurfaces(
1155 PMOS_COMMAND_BUFFER cmdBuffer,
1156 MeSurfaceParams* params)
1157 {
1158 return MOS_STATUS_SUCCESS;
1159 }
1160 };
1161
1162 //!
1163 //! \class CodechalEncoderState
1164 //! \brief This base class defines the common member fields, functions etc used by all encoder.
1165 //!
1166 class CodechalEncoderState : public Codechal
1167 {
1168 public:
1169 CodechalHwInterface *m_hwInterface = nullptr;
1170 //!
1171 //! \enum RefId
1172 //! \brief Reference id
1173 //!
1174 enum RefId
1175 {
1176 CODECHAL_ENCODE_REF_ID_0 = 0,
1177 CODECHAL_ENCODE_REF_ID_1 = 1,
1178 CODECHAL_ENCODE_REF_ID_2 = 2,
1179 CODECHAL_ENCODE_REF_ID_3 = 3,
1180 CODECHAL_ENCODE_REF_ID_4 = 4,
1181 CODECHAL_ENCODE_REF_ID_5 = 5,
1182 CODECHAL_ENCODE_REF_ID_6 = 6,
1183 CODECHAL_ENCODE_REF_ID_7 = 7,
1184 };
1185
1186 // this is used for Mpeg2 encoding BRC as well,
1187 // therefore, the last entry is for Mpeg2
1188 const uint8_t m_bMeMethodGeneric[NUM_TARGET_USAGE_MODES + 1] = {0, 4, 4, 6, 6, 6, 6, 4, 7};
1189
1190 const uint8_t m_meMethodGeneric[NUM_TARGET_USAGE_MODES + 1] = {0, 4, 4, 6, 6, 6, 6, 4, 7};
1191
1192 const uint32_t m_superCombineDistGeneric[NUM_TARGET_USAGE_MODES + 1] ={0, 1, 1, 5, 5, 5, 9, 9, 0};
1193
1194 static constexpr uint32_t CODECHAL_ENCODE_BRCINIT_ISCBR = 0x0010;
1195 static constexpr uint32_t CODECHAL_ENCODE_BRCINIT_ISVBR = 0x0020;
1196 static constexpr uint32_t CODECHAL_ENCODE_BRCINIT_ISAVBR = 0x0040;
1197 static constexpr uint32_t CODECHAL_ENCODE_BRCINIT_ISCQL = 0x0080;
1198 static constexpr uint32_t CODECHAL_ENCODE_BRCINIT_FIELD_PIC = 0x0100;
1199 static constexpr uint32_t CODECHAL_ENCODE_BRCINIT_ISICQ = 0x0200;
1200 static constexpr uint32_t CODECHAL_ENCODE_BRCINIT_ISVCM = 0x0400;
1201 static constexpr uint32_t CODECHAL_ENCODE_BRCINIT_IGNORE_PICTURE_HEADER_SIZE = 0x2000;
1202 static constexpr uint32_t CODECHAL_ENCODE_BRCINIT_ISQVBR = 0x4000;
1203 static constexpr uint32_t CODECHAL_ENCODE_BRCINIT_DISABLE_MBBRC = 0x8000;
1204 static constexpr uint32_t m_numLaDataEntry = 128; //!< number of entries in lookahead data buffer and lookahead stats buffer
1205
1206 // SearchPath Table, index [CodingType][MEMethod][]
1207 const uint32_t m_encodeSearchPath[2][8][16] =
1208 {
1209 // I-Frame & P-Frame
1210 {
1211 // MEMethod: 0
1212 {
1213 0x120FF10F, 0x1E22E20D, 0x20E2FF10, 0x2EDD06FC, 0x11D33FF1, 0xEB1FF33D, 0x4EF1F1F1, 0xF1F21211,
1214 0x0DFFFFE0, 0x11201F1F, 0x1105F1CF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
1215 },
1216 // MEMethod: 1
1217 {
1218 0x120FF10F, 0x1E22E20D, 0x20E2FF10, 0x2EDD06FC, 0x11D33FF1, 0xEB1FF33D, 0x4EF1F1F1, 0xF1F21211,
1219 0x0DFFFFE0, 0x11201F1F, 0x1105F1CF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
1220 },
1221 // MEMethod: 2
1222 {
1223 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1224 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
1225 },
1226 // MEMethod: 3
1227 {
1228 0x01010101, 0x11010101, 0x01010101, 0x11010101, 0x01010101, 0x11010101, 0x01010101, 0x11010101,
1229 0x01010101, 0x11010101, 0x01010101, 0x00010101, 0x00000000, 0x00000000, 0x00000000, 0x00000000
1230 },
1231 // MEMethod: 4
1232 {
1233 0x0101F00F, 0x0F0F1010, 0xF0F0F00F, 0x01010101, 0x10101010, 0x0F0F0F0F, 0xF0F0F00F, 0x0101F0F0,
1234 0x01010101, 0x10101010, 0x0F0F1010, 0x0F0F0F0F, 0xF0F0F00F, 0xF0F0F0F0, 0x00000000, 0x00000000
1235 },
1236 // MEMethod: 5
1237 {
1238 0x0101F00F, 0x0F0F1010, 0xF0F0F00F, 0x01010101, 0x10101010, 0x0F0F0F0F, 0xF0F0F00F, 0x0101F0F0,
1239 0x01010101, 0x10101010, 0x0F0F1010, 0x0F0F0F0F, 0xF0F0F00F, 0xF0F0F0F0, 0x00000000, 0x00000000
1240 },
1241 // MEMethod: 6
1242 {
1243 0x120FF10F, 0x1E22E20D, 0x20E2FF10, 0x2EDD06FC, 0x11D33FF1, 0xEB1FF33D, 0x4EF1F1F1, 0xF1F21211,
1244 0x0DFFFFE0, 0x11201F1F, 0x1105F1CF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
1245 },
1246 // MEMethod: 7 used for mpeg2 encoding P frames
1247 {
1248 0x1F11F10F, 0x2E22E2FE, 0x20E220DF, 0x2EDD06FC, 0x11D33FF1, 0xEB1FF33D, 0x02F1F1F1, 0x1F201111,
1249 0xF1EFFF0C, 0xF01104F1, 0x10FF0A50, 0x000FF1C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000
1250 }
1251 },
1252 // B-Frame
1253 {
1254 // MEMethod: 0
1255 {
1256 0x0101F00F, 0x0F0F1010, 0xF0F0F00F, 0x01010101, 0x10101010, 0x0F0F0F0F, 0xF0F0F00F, 0x0101F0F0,
1257 0x01010101, 0x10101010, 0x0F0F1010, 0x0F0F0F0F, 0xF0F0F00F, 0xF0F0F0F0, 0x00000000, 0x00000000
1258 },
1259 // MEMethod: 1
1260 {
1261 0x0101F00F, 0x0F0F1010, 0xF0F0F00F, 0x01010101, 0x10101010, 0x0F0F0F0F, 0xF0F0F00F, 0x0101F0F0,
1262 0x01010101, 0x10101010, 0x0F0F1010, 0x0F0F0F0F, 0xF0F0F00F, 0xF0F0F0F0, 0x00000000, 0x00000000
1263 },
1264 // MEMethod: 2
1265 {
1266 0x0101F00F, 0x0F0F1010, 0xF0F0F00F, 0x01010101, 0x10101010, 0x0F0F0F0F, 0xF0F0F00F, 0x0101F0F0,
1267 0x01010101, 0x10101010, 0x0F0F1010, 0x0F0F0F0F, 0xF0F0F00F, 0xF0F0F0F0, 0x00000000, 0x00000000
1268 },
1269 // MEMethod: 3
1270 {
1271 0x0101F00F, 0x0F0F1010, 0xF0F0F00F, 0x01010101, 0x10101010, 0x0F0F0F0F, 0xF0F0F00F, 0x0101F0F0,
1272 0x01010101, 0x10101010, 0x0F0F1010, 0x0F0F0F0F, 0xF0F0F00F, 0xF0F0F0F0, 0x00000000, 0x00000000
1273 },
1274 // MEMethod: 4
1275 {
1276 0x0101F00F, 0x0F0F1010, 0xF0F0F00F, 0x01010101, 0x10101010, 0x0F0F0F0F, 0xF0F0F00F, 0x0101F0F0,
1277 0x01010101, 0x10101010, 0x0F0F1010, 0x0F0F0F0F, 0xF0F0F00F, 0xF0F0F0F0, 0x00000000, 0x00000000
1278 },
1279 // MEMethod: 5
1280 {
1281 0x0101F00F, 0x0F0F1010, 0xF0F0F00F, 0x01010101, 0x10101010, 0x0F0F0F0F, 0xF0F0F00F, 0x0101F0F0,
1282 0x01010101, 0x10101010, 0x0F0F1010, 0x0F0F0F0F, 0xF0F0F00F, 0xF0F0F0F0, 0x00000000, 0x00000000
1283 },
1284 // MEMethod: 6
1285 {
1286 0x120FF10F, 0x1E22E20D, 0x20E2FF10, 0x2EDD06FC, 0x11D33FF1, 0xEB1FF33D, 0x4EF1F1F1, 0xF1F21211,
1287 0x0DFFFFE0, 0x11201F1F, 0x1105F1CF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
1288 },
1289 // MEMethod: 7 used for mpeg2 encoding B frames
1290 {
1291 0x1F11F10F, 0x2E22E2FE, 0x20E220DF, 0x2EDD06FC, 0x11D33FF1, 0xEB1FF33D, 0x02F1F1F1, 0x1F201111,
1292 0xF1EFFF0C, 0xF01104F1, 0x10FF0A50, 0x000FF1C0, 0x00000000, 0x00000000, 0x00000000, 0x00000000
1293 }
1294 }
1295 };
1296
1297 // ME kernel
1298 enum
1299 {
1300 CODECHAL_ENCODE_ME_IDX_P = 0,
1301 CODECHAL_ENCODE_ME_IDX_B = 1,
1302 CODECHAL_ENCODE_ME_IDX_VDENC = 1,
1303 CODECHAL_ENCODE_ME_IDX_NUM = 2
1304 };
1305
1306 //!
1307 //! \struct MediaObjectInlineData
1308 //! \brief Media object inline data
1309 //!
1310 struct MediaObjectInlineData
1311 {
1312 // uint32_t 0
1313 union
1314 {
1315 struct
1316 {
1317 uint32_t mbHorizontalOrigin : 8; // in MB unit
1318 uint32_t mbVerticalOrigin : 8; // in MB unit
1319 uint32_t : 16;
1320 };
1321 // For BRC Block Copy kernels
1322 struct
1323 {
1324 uint32_t blockHeight : 16;
1325 uint32_t bufferOffset : 16;
1326 };
1327 struct
1328 {
1329 uint32_t value;
1330 };
1331 } DW0;
1332 };
1333
1334 //!
1335 //! \brief Constructor
1336 //!
1337 CodechalEncoderState(
1338 CodechalHwInterface* hwInterface,
1339 CodechalDebugInterface* debugInterface,
1340 PCODECHAL_STANDARD_INFO standardInfo);
1341
1342 //!
1343 //! \brief Destructor
1344 //!
1345 virtual ~CodechalEncoderState();
1346
1347 // Encoder private data
1348 MhwVdboxMfxInterface* m_mfxInterface = nullptr; //!< Mfx Interface
1349 MhwVdboxHcpInterface* m_hcpInterface = nullptr; //!< Hcp Interface
1350 MhwVdboxHucInterface* m_hucInterface = nullptr; //!< Huc Interface
1351 MhwVdboxVdencInterface* m_vdencInterface = nullptr; //!< Vdenc Interface
1352 MhwMiInterface* m_miInterface = nullptr; //!< Mi Interface
1353 MhwRenderInterface* m_renderEngineInterface = nullptr; //!< Render engine interface
1354 PMHW_STATE_HEAP_INTERFACE m_stateHeapInterface = nullptr; //!< State heap interface
1355 CodechalEncodeAllocator* m_allocator = nullptr; //!< Resource allocator
1356 CodechalEncodeTrackedBuffer* m_trackedBuf = nullptr; //!< Tracked buffer state
1357
1358 PLATFORM m_platform = {}; //!< The platorm info
1359 MEDIA_FEATURE_TABLE *m_skuTable = nullptr; //!< SKU table
1360 MEDIA_WA_TABLE *m_waTable = nullptr; //!< WA table
1361 CodecHalMmcState* m_mmcState = nullptr; //!< Memory compression
1362 MEDIA_SYSTEM_INFO *m_gtSystemInfo = nullptr; //!< GT system infomation
1363 MOS_GPU_NODE m_videoGpuNode = MOS_GPU_NODE_MAX; //!< GPU node of video
1364 MOS_GPU_CONTEXT m_videoContext = MOS_GPU_CONTEXT_INVALID_HANDLE; //!< GPU context of video
1365 MOS_GPU_CONTEXT m_videoContextExt[4] = {}; //!< Extand GPU context
1366 MOS_GPU_CONTEXT m_renderContext = MOS_GPU_CONTEXT_INVALID_HANDLE; //!< GPU context of render
1367 bool m_pakEnabled = false; //!< flag to indicate if PAK is enabled
1368 bool m_encEnabled = false; //!< flag to indicate if ENC is enabled
1369 bool m_videoNodeAssociationCreated = false; //!< flag to indicate if video node association is created
1370 bool m_computeContextEnabled = false; //!< flag to indicate if compute context is enabled
1371 bool m_needCheckCpEnabled = false; //!< Indicate if checking cp is needed when prepare default nodes
1372 bool m_vdboxOneDefaultUsed = false; //!< Indicate VDBOX 1 is always used when prepare default nodes
1373
1374 CodechalEncoderGenState* m_encoderGenState = nullptr; //!< Pointer to Gen Specific Encoder State
1375 CodechalEncodeCscDs* m_cscDsState = nullptr; //!< pointer to CSC Downscaling state
1376 CodechalEncodeWP* m_wpState = nullptr; //!< pointer to weighted prediction state
1377 CODECHAL_FUNCTION m_codecFunction = CODECHAL_FUNCTION_INVALID; //!< The encode state's codec function used
1378 uint32_t m_standard = 0; //!< The encode state's standard
1379 uint32_t m_mode = 0; //!< The encode mode
1380 MHW_WALKER_MODE m_walkerMode = MHW_WALKER_MODE_NOT_SET; //!< The encode walker's mode
1381 uint8_t m_kernelMode = 0; //!< normal, performance, quality.
1382
1383 bool m_mfeEnabled = false; //!< Mfe enabled
1384 bool m_mfeMbEncEanbled = false; //!< Mfe MBEnc kernel enabled
1385 bool m_mfeLastStream = false; //!< Is last stream during this submission
1386 bool m_mfeFirstStream = false; //!< Is first stream during this submission
1387 bool m_mfeInitialized = false; //!< Used for initializing MFE resources during first execute
1388 MfeParams m_mfeEncodeParams = {}; //!< Mfe encode params during this submission
1389 MfeSharedState * m_mfeEncodeSharedState = nullptr; //!< shared state from the parent context
1390
1391 // Common Kernel Parameters
1392 uint8_t* m_kernelBase = nullptr; //!< Kernel base address
1393 uint32_t m_kuid = 0; //!< Kernel unified ID
1394
1395 // Per-frame Application Settings
1396 EncoderParams m_encodeParams = {}; //!< Encode parameters used in each frame
1397 uint32_t *m_dataHwCount = nullptr; //!< HW count data
1398 MOS_RESOURCE m_resHwCount = {}; //!< Resource of HW count
1399 MOS_SURFACE m_prevRawSurface = {}; //!< Pointer to MOS_SURFACE of previous raw surface
1400 MOS_SURFACE m_rawSurface = {}; //!< Pointer to MOS_SURFACE of raw surface
1401 MOS_SURFACE m_reconSurface = {}; //!< Pointer to MOS_SURFACE of reconstructed surface
1402 MOS_RESOURCE m_resBitstreamBuffer = {}; //!< Pointer to MOS_SURFACE of bitstream surface
1403 PMOS_RESOURCE m_presMetadataBuffer = {}; //!< Pointer to metadata buffer
1404 MetaDataOffset m_metaDataOffset = {}; //!< meta data offset
1405 MOS_RESOURCE m_resMbCodeSurface = {}; //!< Pointer to MOS_SURFACE of MbCode surface
1406 MOS_RESOURCE m_resMvDataSurface = {}; //!< Pointer to MOS_SURFACE of MvData surface
1407 uint32_t m_mbDataBufferSize = 0;
1408 HwCounter m_regHwCount[CODECHAL_ENCODE_STATUS_NUM + 1] = {}; //!< HW count register value
1409
1410 CODEC_PICTURE m_currOriginalPic = {}; //!< Raw.
1411 CODEC_PICTURE m_currReconstructedPic = {}; //!< Recon.
1412 uint16_t m_pictureCodingType = 0; //!< I, P, or B frame
1413 int16_t m_frameNum = 0; //!< Frame number
1414 bool m_firstFrame = true; //!< Flag to indicate if it is first frame
1415 bool m_firstTwoFrames = false; //!< Flag to indicate if they are first two frames
1416 bool m_firstField = true; //!< Flag to indicate if it is first field
1417 bool m_resolutionChanged = false; //!< Flag to indicate if resolution is changed
1418 bool m_scalingEnabled = false; //!< 4x Scaling kernel needs to be called for this frame
1419 bool m_2xScalingEnabled = false; //!< 2x Scaling kernel only used by HEVC now
1420 bool m_useRawForRef = false; //!< Flag to indicate if using raw surface for reference
1421 bool m_disableReconMMCD = false; //!< disable Recon surface's MMC
1422 bool m_repeatFrame = false; //!< Flag to indicate if current frame is repeat frame
1423 bool m_pollingSyncEnabled = false; //!< Flag to indicate if GPU polling based sync for raw surface copy is enabled
1424 uint32_t m_syncMarkerOffset = 0; //!< Sync marker offset in raw surface for GPU polling based sync
1425 uint32_t m_syncMarkerValue = 0; //!< Sync marker value in raw surface for GPU polling based sync
1426 uint8_t m_prevReconFrameIdx = 0; //!< Previous reconstruct frame index
1427 uint8_t m_currReconFrameIdx = 0; //!< Current reconstruct frame index
1428
1429 uint32_t m_frameWidth = 0; //!< Frame width in luma samples
1430 uint32_t m_frameHeight = 0; //!< Frame height in luma samples
1431 uint32_t m_frameFieldHeight = 0; //!< Frame height in luma samples
1432 uint32_t m_oriFrameHeight = 0; //!< Original frame height
1433 uint16_t m_frame_crop_bottom_offset = 0; //!< frame_crop_bottom_offset
1434 uint16_t m_frame_mbs_only_flag = 0; //!< frame_mbs_only_flag
1435 uint32_t m_oriFrameWidth = 0; //!< Original frame width
1436 uint32_t m_createWidth = 0; //!< Max Frame Width for resolution reset
1437 uint32_t m_createHeight = 0; //!< Max Frame Height for resolution reset
1438 uint16_t m_picWidthInMb = 0; //!< Picture Width in MB width count
1439 uint16_t m_picHeightInMb = 0; //!< Picture Height in MB height count
1440 uint16_t m_frameFieldHeightInMb = 0; //!< Frame/field Height in MB
1441 uint32_t m_bitstreamUpperBound = 0; //!< Bitstream upper bound
1442 uint8_t m_oriFieldCodingFlag = 0; //!< Original field coding flag
1443 uint32_t m_maxBtCount = 0; //!< Max bt count
1444 bool m_cmKernelEnable = false; //!< Flag to indicate if cm kernel is enabled
1445 bool m_feiEnable = false; //!< FEI is enabled
1446
1447 // Synchronization
1448 MOS_RESOURCE m_resSyncObjectRenderContextInUse = {}; //!< Resource of the sync object to indicate render context is in use
1449 MOS_RESOURCE m_resSyncObjectVideoContextInUse = {}; //!< Resource of the sync object to indicate video context is in use
1450 bool m_waitForPak = false; //!< Flag to indicate if waiting for PAK
1451 bool m_signalEnc = false; //!< Flag used to signal ENC
1452 uint32_t m_semaphoreObjCount = 0; //!< Count of semaphore objects
1453 uint32_t m_semaphoreMaxCount = 0; //!< Max count of semaphore
1454
1455 // Status Reporting
1456 bool m_codecGetStatusReportDefined = false; //!< Need to be set to true by any codec/gen that has their own impleementation.
1457 uint32_t m_storeData = 0; //!< Stored data
1458 bool m_statusQueryReportingEnabled = false; //!< Flag to indicate if we support eStatus query reporting on current Platform
1459 EncodeStatusBuffer m_encodeStatusBuf = {}; //!< Stores all the status_query related data for PAK engine
1460 EncodeStatusBuffer m_encodeStatusBufRcs = {}; //!< Stores all the status_query related data for render ring (RCS)
1461 MHW_VDBOX_IMAGE_STATUS_CONTROL m_imgStatusControlBuffer = {}; //!< Stores image eStatus control data
1462 uint32_t m_statusReportFeedbackNumber = 0; //!< Status report feed back number
1463 bool m_frameTrackingEnabled = false; //!< Flag to indicate if we enable KMD frame tracking
1464 uint32_t m_numberTilesInFrame = 0; //!< Track number of tiles per frame
1465 bool m_inlineEncodeStatusUpdate = false; //!< check whether use inline encode status update or seperate BB
1466 AtomicScratchBuffer m_atomicScratchBuf = {}; //!< Stores atomic operands and result
1467 bool m_skipFrameBasedHWCounterRead = false; //!< Skip reading Frame base HW counter for status report
1468 bool m_disableStatusReport = false; //!< Indicate status report is not needed.
1469
1470 // Shared Parameters
1471 BSBuffer m_bsBuffer = {}; //!< Bitstream buffer
1472 bool m_newSeqHeader = false; //!< New sequence header flag
1473 bool m_newPpsHeader = false; //!< New PPS header flag
1474 bool m_newVuiData = false; //!< New Vui data flag
1475 bool m_newSeq = false; //!< New sequence flag
1476 bool m_lastPicInSeq = false; //!< Flag to indicate if it is last picture in sequence
1477 bool m_lastPicInStream = false; //!< Flag to indicate if it is last picture in stream
1478 uint8_t m_numRefPair = 0; //!< number of reference pair (forward & backward)
1479 uint8_t m_numPasses = 0; //!< Number passes
1480 uint8_t m_currPass = 0; //!< Current pass
1481 bool m_forceSinglePakPass = false; //!< Flag to enable forcing single pak pass
1482 bool m_useCmScalingKernel = false; //!< Flag to use cm scaling kernel
1483 bool m_useMwWlkrForAsmScalingKernel = false; //!< Use media walker for ASM scaling kernel flag
1484 bool m_combinedDownScaleAndDepthConversion = false; //!< Combied downscale and depth conversion
1485 bool m_bRenderOcaEnabled = false; //!< Should encoder support OCA for RCS
1486 uint32_t m_brcPakStatisticsSize = 0; //!< Bitrate control PAK statistics size
1487 uint32_t m_brcHistoryBufferSize = 0; //!< Bitrate control history buffer size
1488 uint32_t m_mbencBrcBufferSize = 0; //!< Mbenc bitrate control buffer size
1489 uint8_t m_numVdbox = 0; //!< Number of vdbox
1490 uint8_t m_numUsedVdbox = 0; //!< Number of vdbox used
1491
1492 // ENC/PAK batch buffer and surface indices
1493 PCODEC_REF_LIST m_currRefList = nullptr; //!< Current reference list
1494 uint8_t m_currRecycledBufIdx = 0; //!< Current recycled buffer index
1495 uint8_t m_currEncBbSet = 0; //!< Current encode bb set
1496 uint8_t m_currMbCodeIdx = 0; //!< Current mb code index
1497 uint8_t m_currMadBufferIdx = 0; //!< Current mad buffer
1498 uint32_t m_recycledBufStatusNum[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM] = {0}; //!< Recycled buffer status num list
1499 uint32_t m_recycledBufWaitMs = 0; //!< Recycled buffer wait (ms)
1500
1501 // User Feature Key Capabilities
1502 bool m_hmeSupported = false; //!< Flag to indicate if HME is supported
1503 bool m_noMeKernelForPFrame = false; //!< HEVC does not have P-frame, no need to load P-frame ME kernel
1504 bool m_16xMeSupported = false; //!< 16x ME supported
1505 bool m_16xMeUserfeatureControl = false; //!< User feature control if 16x ME is supported
1506 bool m_32xMeSupported = false; //!< 32x ME supported
1507 bool m_useNonLegacyStreamin = false; //!< Use non-legacy stream in
1508 bool m_32xMeUserfeatureControl = false; //!< User feature control if 32x ME is supported
1509 bool m_2xMeSupported = false; //!< 2x DS surface, currently only used by Gen10 Hevc Encode
1510 bool m_suppressReconPicSupported = false; //!< Suppress reconstructed picture supported flag
1511 bool m_useHwScoreboard = true; //!< Flag to indicate if HW score board is used
1512 bool m_hwWalker = false; //!< HW walker used
1513 bool m_panicEnable = false; //!< Rc panic enabled flag
1514 bool m_sliceShutdownEnable = false; //!< Slice Shutdown Enable
1515 uint32_t m_encodeVfeMaxThreads = 0; //!< Encode vfe max threads number
1516 uint32_t m_encodeVfeMaxThreadsScaling = 0; //!< Encode vfe max threads scaling number
1517 uint32_t m_hwScoreboardType = 0; //!< HW score board type
1518 bool m_flatnessCheckSupported = false; //!< Flatness check supported flag
1519 bool m_groupIdSelectSupported = false; //!< Group id select supported flag
1520 uint8_t m_groupId = 0; //!< Group id
1521 bool m_multipassBrcSupported = false; //!< Multi-pass bitrate control supported flag
1522 uint8_t m_targetUsageOverride = 0; //!< Target usage override
1523 bool m_userFeatureKeyReport = false; //!< User feature key report flag
1524 bool m_singlePassDys = false; //!< sungle pass dynamic scaling supported flag
1525
1526 // CmdGen HuC FW for HEVC/VP9 VDEnc
1527 MOS_RESOURCE m_resVdencCmdInitializerDmemBuffer = {}; //!< Resource of vdenc command initializer DMEM buffer
1528 MOS_RESOURCE m_resVdencCmdInitializerDataBuffer[2] = {}; //!< Resource of vdenc command initializer data buffer
1529
1530 // VDEnc params
1531 bool m_vdencEnabled = false; //!< Vdenc enabled flag
1532 bool m_vdencBrcEnabled = false; //!< Vdenc bitrate control enabled flag
1533 bool m_vdencStreamInEnabled = false; //!< Vdenc stream in enabled flag
1534 bool m_vdencNoTailInsertion = false; //!< Vdenc no tail insertion enabled flag
1535 uint32_t m_vdencBrcStatsBufferSize = 0; //!< Vdenc bitrate control buffer size
1536 uint32_t m_vdencBrcPakStatsBufferSize = 0; //!< Vdenc bitrate control PAK buffer size
1537 uint32_t m_vdencBrcNumOfSliceOffset = 0; //!< Vdenc bitrate control number of slice offset
1538 bool m_waReadVDEncOverflowStatus = false; //!< Read vdenc overflow status used flag
1539 bool m_vdencBrcImgStatAllocated = false; //!< Vdenc bitrate control image state allocated flag
1540 uint32_t m_vdencMvTemporalBufferSize = 0; //!< Vdenc temporal MV buffer size
1541
1542 // VDEnc dynamic slice control params
1543 uint32_t m_vdencFlushDelayCount = 0; //!< Vdenc flush delay count
1544
1545 HMODULE m_swBrcMode = nullptr; //!< Software bitrate control mode
1546
1547 // IQmatrix params
1548 bool m_picQuant = false; //!< picture quant
1549 bool m_newQmatrixData = false; //!< New Qmatrix data
1550 PCODEC_ENCODER_SLCDATA m_slcData = nullptr; //!< record slice header size & position
1551 uint32_t m_numSlices = 0; //!< Number of slices
1552 uint32_t m_numHuffBuffers = 0; //!< Number of Huffman buffers
1553
1554 // ENC input/output buffers
1555 uint32_t m_mbCodeStrideInDW = 0; //!< Offset + Size of MB + size of MV
1556 uint32_t m_mbCodeOffset = 0; //!< MB data offset
1557 uint32_t m_mvOffset = 0; //!< MV data offset, in 64 byte
1558 uint32_t m_mbCodeSize = 0; //!< MB code buffer size
1559 uint32_t m_mbcodeBottomFieldOffset = 0; //!< MB code offset frame/TopField - zero, BottomField - nonzero
1560 uint32_t m_mvDataSize = 0; //!< MV data size
1561 uint32_t m_mvBottomFieldOffset = 0; //!< MV data offset frame/TopField - zero, BottomField - nonzero
1562 MOS_RESOURCE m_resDistortionBuffer = {}; //!< MBEnc Distortion Buffer
1563 MOS_RESOURCE m_resMadDataBuffer[CODECHAL_ENCODE_MAX_NUM_MAD_BUFFERS] = {}; //!< Buffers to store Mean of Absolute Differences
1564 bool m_madEnabled = false; //!< Mad enabled flag
1565
1566 bool m_arbitraryNumMbsInSlice = false; //!< Flag to indicate if the sliceMapSurface needs to be programmed or not
1567 MOS_SURFACE m_sliceMapSurface[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM] = {}; //!< Slice map surface
1568 uint32_t m_sliceMapBottomFieldOffset = 0; //!< Slice map bottom field offset
1569
1570 // VDENC and PAK Data Buffer
1571 PMOS_RESOURCE m_resVdencStatsBuffer = nullptr; //!< Resource of Vdenc status buffer
1572 PMOS_RESOURCE m_resVdencCuObjStreamOutBuffer = nullptr; //!< Resource of Vdenc Cu object stream out buffer
1573 PMOS_RESOURCE m_resVdencPakObjCmdStreamOutBuffer = nullptr; //!< Resource of Vdenc Pak object command stream out buffer
1574 PMOS_RESOURCE m_resPakStatsBuffer = nullptr; //!< Resource of Pak status buffer
1575 PMOS_RESOURCE m_resSliceCountBuffer = nullptr; //!< Resource of slice count buffer
1576 PMOS_RESOURCE m_resVdencModeTimerBuffer = nullptr; //!< Resource of Vdenc mode timer buffer
1577
1578 // VDEnc StreamIn Buffer
1579 MOS_RESOURCE m_resVdencStreamInBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM] = {}; //!< Resources of Vdenc stream in buffer
1580
1581 // Maximum number of slices allowed by video spec
1582 uint32_t m_maxNumSlicesAllowed = 0; //!< Max number of slices allowed
1583
1584 //VDEnc HuC FW status
1585 MOS_RESOURCE m_resPakMmioBuffer = {}; //!< Resource of PAK MMIO buffer
1586 MOS_RESOURCE m_resHucErrorStatusBuffer = {}; //!< Resource of Huc Error Status buffer
1587 MOS_RESOURCE m_resHucStatus2Buffer = {}; //!< Resource of HuC status 2 buffer
1588 MOS_RESOURCE m_resHucFwBuffer = {}; //!< Resource of HuC Fw buffer
1589 PMOS_RESOURCE m_resVdencBrcUpdateDmemBufferPtr[2] = {nullptr, nullptr}; //!< One for 1st pass of next frame, and the other for the next pass of current frame.
1590
1591 // PAK Scratch Buffers
1592 MOS_RESOURCE m_resDeblockingFilterRowStoreScratchBuffer = {}; //!< Handle of deblock row store surface
1593 MOS_RESOURCE m_resMPCRowStoreScratchBuffer = {}; //!< Handle of mpc row store surface
1594 MOS_RESOURCE m_resStreamOutBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM] = {}; //!< Handle of streamout data surface
1595
1596 // Scaling
1597 MHW_KERNEL_STATE m_scaling4xKernelStates[CODEC_NUM_FIELDS_PER_FRAME]; //!< Scaling 4x Kernel States
1598 ScalingBindingTable m_scaling4xBindingTable = {}; //!< Scaling 4x Binding Table
1599 MHW_KERNEL_STATE m_scaling2xKernelStates[CODEC_NUM_FIELDS_PER_FRAME]; //!< Scaling 2x Kernel States
1600 ScalingBindingTable m_scaling2xBindingTable = {}; //!< Scaling 2x Binding Table
1601 uint32_t m_scalingCurbeSize = 0; //!< Scaling curbe size
1602 bool m_interlacedFieldDisabled = false; //!< interlaced field disabled flag
1603 CodechalEncodeBbuf m_scalingBBUF[CODECHAL_ENCODE_VME_BBUF_NUM] = {}; //!< This Batch Buffer is used for scaling kernel.
1604 uint32_t m_scaledBottomFieldOffset = 0; //!< Scaled Bottom Field Offset
1605 uint32_t m_scaled16xBottomFieldOffset = 0; //!< Scaled 16x Bottom Field Offset
1606 uint32_t m_scaled32xBottomFieldOffset = 0; //!< Scaled 32x Bottom Field Offset
1607 uint32_t m_scalingBBufIdx = 0; //!< Scaling batch buffer index
1608 uint8_t m_minScaledDimension = 0; //!< min scaled dimension
1609 uint8_t m_minScaledDimensionInMb = 0; //!< min scaled dimension in Mb
1610 uint32_t m_downscaledWidth2x = 0; //!< Downscale width 2x
1611 uint32_t m_downscaledHeight2x = 0; //!< Downscale height 2x
1612 uint32_t m_downscaledWidth4x = 0; //!< Downscale width 4x
1613 uint32_t m_downscaledHeight4x = 0; //!< Downscale height 4x
1614 uint32_t m_downscaledWidthInMb4x = 0; //!< Downscale width in Mb 4x
1615 uint32_t m_downscaledHeightInMb4x = 0; //!< Downscale height in Mb 4x
1616 uint32_t m_downscaledFrameFieldHeightInMb4x = 0; //!< Downscale frame field height in Mb 4x
1617 uint32_t m_downscaledWidth16x = 0; //!< Downscale width 16x
1618 uint32_t m_downscaledHeight16x = 0; //!< Downscale height 16x
1619 uint32_t m_downscaledWidthInMb16x = 0; //!< Downscale width in Mb 16x
1620 uint32_t m_downscaledHeightInMb16x = 0; //!< Downscale height in Mb 16x
1621 uint32_t m_downscaledFrameFieldHeightInMb16x = 0; //!< Downscale frame field height in Mb 16x
1622 uint32_t m_downscaledWidth32x = 0; //!< Downscale width 2x
1623 uint32_t m_downscaledHeight32x = 0; //!< Downscale height 2x
1624 uint32_t m_downscaledWidthInMb32x = 0; //!< Downscale width 2x
1625 uint32_t m_downscaledHeightInMb32x = 0; //!< Downscale height 2x
1626 uint32_t m_downscaledFrameFieldHeightInMb32x = 0; //!< Downscale frame field height in Mb 32x
1627
1628 bool m_fieldScalingOutputInterleaved = false; //!< Field scaling output interleaved flag
1629 MOS_SURFACE m_flatnessCheckSurface = {}; //!< Flatness check surface
1630 uint32_t m_flatnessCheckBottomFieldOffset = 0; //!< Flatness check bottom field offset
1631 bool m_flatnessCheckEnabled = false; //!< Flatness check enabled flag
1632 bool m_mbStatsEnabled = false; //!< MB status enabled flag
1633 bool m_adaptiveTransformDecisionEnabled = false; //!< Adaptive Transform Decision Enabled flag
1634 bool m_forceBrcMbStatsEnabled = false; //!< Force Brc Mb statistics Enabled flag
1635 uint32_t m_mbvProcStatsBottomFieldOffset = 0; //!< MB VProc statistics Bottom Field Offset
1636 CODECHAL_ENCODE_BUFFER m_resMbStatisticsSurface; //!< Resource of Mb statistics surface
1637 bool m_mbStatsSupported = false; //!< Mb statistics supported flag
1638 MOS_RESOURCE m_resMbStatsBuffer = {}; //!< Resource of Mb statistics buffer
1639 uint32_t m_mbStatsBottomFieldOffset = 0; //!< Mb statistics bottom field offset
1640
1641 // ME
1642 MHW_KERNEL_STATE m_meKernelStates[CODECHAL_ENCODE_ME_IDX_NUM]; //!< ME kernel states
1643 MeKernelBindingTable m_meBindingTable = {}; //!< ME binding table
1644 bool bStreamOutEnable = false;
1645 MOS_RESOURCE StreamOutBuffer = {}; // StreamOut buffer
1646
1647 //GVA paramters to change inter and intra rounding
1648 bool bCoeffRoundTag = false;
1649 uint32_t uiRoundIntra = 0;
1650 uint32_t uiRoundInter = 0;
1651
1652 // Ds+Copy kernel optimization
1653 uint8_t m_outputChromaFormat = (uint8_t)HCP_CHROMA_FORMAT_YUV420; //!< 1: 420 2: 422 3: 444
1654 bool m_gopIsIdrFrameOnly = false; //!< GOP structure contains I-frame only
1655 PMOS_SURFACE m_rawSurfaceToEnc = nullptr; //!< raw surf to enc
1656 PMOS_SURFACE m_rawSurfaceToPak = nullptr; //!< raw surf to pak
1657
1658 // HME VDEnc
1659 GenericBindingTable m_vdencMeKernelBindingTable = {}; //!< Vdenc ME kernel binding table
1660 MHW_KERNEL_STATE m_vdencMeKernelState; //!< Vdenc ME kernel state for Low Delay B
1661 MHW_KERNEL_STATE m_vdencMeKernelStateRAB = {}; //!< Vdenc ME kernel state for Random Access B
1662
1663 GenericBindingTable m_vdencStreaminKernelBindingTable = {}; //!< Vdenc stream in kernel binding table
1664 MHW_KERNEL_STATE m_vdencStreaminKernelState; //!< Vdenc stream in kernel state for Low Delay B
1665 MHW_KERNEL_STATE m_vdencStreaminKernelStateRAB; //!< Vdenc stream in kernel state for Random Access B
1666
1667 // Common kernel
1668 uint32_t m_kuidCommon = 0; //!< Common kernel UID
1669 bool m_useCommonKernel = false; //!< Use common kernel
1670 bool m_wpUseCommonKernel = false; //!< WP uses common kernel
1671
1672 // Generic ENC parameters
1673 uint32_t m_verticalLineStride = 0; //!< vertical line stride
1674 uint32_t m_verticalLineStrideOffset = 0; //!< vertical line stride offset
1675
1676 // CMD buffer sizes
1677 uint32_t m_pictureStatesSize = 0; //!< Picture states size
1678 uint32_t m_extraPictureStatesSize = 0; //!< Picture states size extra
1679 uint32_t m_sliceStatesSize = 0; //!< Slice states size
1680 uint32_t m_vmeStatesSize = 0; //!< VME states size
1681 uint32_t m_hucCommandsSize = 0; //!< HuC command size
1682
1683 // Patch List Size
1684 uint32_t m_picturePatchListSize = 0; //!< Picture patch list size
1685 uint32_t m_extraPicturePatchListSize = 0; //!< Picture patch list size extra
1686 uint32_t m_slicePatchListSize = 0; //!< Slice patch list size
1687 uint32_t m_vmePatchListSize = 0; //!< not used yet, for future development
1688
1689 // Single Task Phase parameters
1690 bool m_singleTaskPhaseSupported = false; //!< Single task phase supported flag
1691 bool m_firstTaskInPhase = false; //!< first task in phase flag
1692 bool m_lastTaskInPhase = false; //!< last task in phase flag
1693 bool m_lastEncPhase = false; //!< first enc phase flag
1694 bool m_singleTaskPhaseSupportedInPak = false; //!< Single task phase supported in pak flag
1695 uint32_t m_headerBytesInserted = 0; //!< Header bytes inserted flag
1696
1697 // Null Rendering Flags
1698 bool m_videoContextUsesNullHw = false; //!< Using null HW flags for video context
1699 bool m_renderContextUsesNullHw = false; //!< Using null HW flags for render context
1700
1701 // Slice Shutdown parameters
1702 bool m_setRequestedEUSlices = false; //!< Flag to indicate the need to set requested EU slices
1703 bool m_setRequestedSubSlices = false; //!< Flag to indicate the need to set requested EU sub-slices
1704 bool m_setRequestedEUs = false; //!< Flag to indicate the need to set requested EUs
1705 uint32_t m_sliceShutdownDefaultState = 0; //!< Default state of slice shutdown
1706 uint32_t m_sliceShutdownRequestState = 0; //!< Request state of slice shutdown
1707 uint32_t m_ssdResolutionThreshold = 0; //!< Resolution threshold for slice shutdown
1708 uint32_t m_ssdTargetUsageThreshold = 0; //!< Target usage threshold for slice shutdown
1709 uint32_t m_targetUsage = 0; //!< Target usage
1710
1711 // Skip frame params
1712 uint8_t m_skipFrameFlag = 0; //!< Skip frame flag
1713 uint32_t m_numSkipFrames = 0; //!< Number of skip frame
1714 uint32_t m_sizeSkipFrames = 0; //!< acccumulative size of skipped frames for skipflag = 2
1715 uint32_t m_sizeCurrSkipFrame = 0; //!< size of curr skipped frame for skipflag = 2
1716
1717 // Lookahead
1718 uint8_t m_lookaheadDepth = 0; //!< Number of frames to lookahead
1719 uint8_t m_currLaDataIdx = 0; //!< Current lookahead data index
1720 uint32_t m_averageFrameSize = 0; //!< Average frame size based on targed bitrate and frame rate, in unit of bits
1721 uint32_t m_prevTargetFrameSize = 0; //!< Target frame size of previous frame.
1722 uint32_t m_targetBufferFulness = 0; //!< Target encode buffer fulness in bits, used by BRC and calculated from initial buffer fulness, target frame size (from DDI) and average frame size
1723
1724 MHW_VDBOX_NODE_IND m_vdboxIndex = MHW_VDBOX_NODE_MAX; //!< Index of vdbox
1725 MediaPerfProfiler *m_perfProfiler = nullptr; //!< Performance data profiler
1726 PMOS_GPUCTX_CREATOPTIONS m_gpuCtxCreatOpt = nullptr; //!< Used for creating GPU context
1727 bool intraModeMaskControl = false;
1728 uint32_t intraModeMask = 0; // to disable intra mode
1729 bool interMbTransformSizeControl = false;
1730 bool interMbTransform8x8Enabled = false;
1731
1732 PMOS_RESOURCE presMbInlineData = nullptr;
1733 PMOS_RESOURCE presMbConstSurface = nullptr;
1734 PMOS_RESOURCE presVMEOutSurface = nullptr;
1735
1736 MOS_RESOURCE m_predicationBuffer = {}; //! \brief Internal buffer for predication
1737
1738 #if (_DEBUG || _RELEASE_INTERNAL)
1739 bool m_mmcUserFeatureUpdated; //!< indicate if the user feature is updated with MMC state
1740 #endif
1741
1742 CmDevice *m_cmDev = nullptr;
1743 CmTask * m_cmTask = nullptr;
1744 CmQueue * m_cmQueue = nullptr;
1745 CmDevice *m_origCmDev = nullptr;
1746
1747 #define CM_EVENT_NUM 128
1748 CmEvent *m_cmEvent[CM_EVENT_NUM] = {nullptr};
1749 short m_cmEventIdx = 0; // current event idx
1750 short m_cmEventCheckIdx = 0;
1751
1752 bool m_colorbitSupported = false;
1753
1754 #if USE_CODECHAL_DEBUG_TOOL
1755 CodechalDebugEncodePar *m_encodeParState = nullptr; //!< Encode Par state
1756 #endif
1757
1758 //!
1759 //! \brief Entry to allocate and intialize the encode instance
1760 //! \param [in] codecHalSettings
1761 //! The settings to inialize the encode instance
1762 //! \return MOS_STATUS
1763 //! MOS_STATUS_SUCCESS if success, else fail reason
1764 //!
1765 MOS_STATUS Allocate(CodechalSetting * codecHalSettings) override;
1766
1767 //!
1768 //! \brief The entry to encode each frame.
1769 //! \param [in] params
1770 //! Pointer to encode parameters of this frame
1771 //! \return MOS_STATUS
1772 //! MOS_STATUS_SUCCESS if success, else fail reason
1773 //!
1774 MOS_STATUS Execute(void *params) override;
1775
1776 //!
1777 //! \brief The entry to get status report.
1778 //! \param [out] status
1779 //! The point to encode status
1780 //! \param [in] numStatus
1781 //! The requested number of status reports
1782 //! \return MOS_STATUS
1783 //! MOS_STATUS_SUCCESS if success, else fail reason
1784 //!
1785 MOS_STATUS GetStatusReport(void *status, uint16_t numStatus) override;
1786
1787 //!
1788 //! \brief Get Status Report for the common codec part
1789 //! \param [out] encodeStatus
1790 //! Encoder status
1791 //! \param [out] encodeStatusReport
1792 //! Encoder status report
1793 //! \return MOS_STATUS
1794 //! MOS_STATUS_SUCCESS if success, else fail reason
1795 //!
1796 MOS_STATUS GetStatusReportCommon(
1797 EncodeStatus* encodeStatus,
1798 EncodeStatusReport* encodeStatusReport);
1799
1800 //!
1801 //! \brief Get Status Report extension
1802 //! \param [out] encodeStatus
1803 //! Encoder status
1804 //! \param [out] encodeStatusReport
1805 //! Encoder status report
1806 //! \param [in] index
1807 //! The index of status report number
1808 //! \return MOS_STATUS
1809 //! MOS_STATUS_SUCCESS if success, else fail reason
1810 //!
1811 virtual MOS_STATUS GetStatusReportExt(
1812 EncodeStatus* encodeStatus,
1813 EncodeStatusReport* encodeStatusReport,
1814 uint16_t index)
1815 {
1816 return MOS_STATUS_SUCCESS;
1817 };
1818
1819 //!
1820 //! \brief Read counter value for encode.
1821 //! \param [in] index
1822 //! The index of status report number
1823 //! \param [in, out] encodeStatusReport
1824 //! The address of encodeStatusReport
1825 //! \return MOS_STATUS
1826 //! MOS_STATUS_SUCCESS if success, else fail reason
1827 //!
1828 MOS_STATUS ReadCounterValue(uint16_t index, EncodeStatusReport* encodeStatusReport);
1829
1830 //!
1831 //! \brief Initialize the encoder state
1832 //! \param [in] settings
1833 //! Pointer to the initialize settings
1834 //! \return MOS_STATUS
1835 //! MOS_STATUS_SUCCESS if success, else fail reason
1836 //!
1837 virtual MOS_STATUS Initialize(
1838 CodechalSetting * settings);
1839
1840 //!
1841 //! \brief Allocate resources for encoder
1842 //! \return MOS_STATUS
1843 //! MOS_STATUS_SUCCESS if success, else fail reason
1844 //!
1845 virtual MOS_STATUS AllocateResources();
1846
1847 //!
1848 //! \brief Free resources in encoder
1849 //! \return void
1850 //!
1851 virtual void FreeResources();
1852
1853 //!
1854 //! \brief Initialize the picture
1855 //! \param [in] params
1856 //! Encoder parameters
1857 //! \return MOS_STATUS
1858 //! MOS_STATUS_SUCCESS if success, else fail reason
1859 //!
1860 virtual MOS_STATUS InitializePicture(const EncoderParams& params) = 0;
1861
1862 //!
1863 //! \brief Execute kernel functions
1864 //! \return MOS_STATUS
1865 //! MOS_STATUS_SUCCESS if success, else fail reason
1866 //!
1867 virtual MOS_STATUS ExecuteKernelFunctions() = 0;
1868
1869 //!
1870 //! \brief Execute picture level in encoder
1871 //! \return MOS_STATUS
1872 //! MOS_STATUS_SUCCESS if success, else fail reason
1873 //!
1874 virtual MOS_STATUS ExecutePictureLevel() = 0;
1875
1876 //!
1877 //! \brief Execute slice level in encoder
1878 //! \return MOS_STATUS
1879 //! MOS_STATUS_SUCCESS if success, else fail reason
1880 //!
1881 virtual MOS_STATUS ExecuteSliceLevel() = 0;
1882
1883 //!
1884 //! \brief Get Status Report
1885 //! \details Each Codec need to define its own GetStatusReport
1886 //! \param [out] encodeStatus
1887 //! Encoder status
1888 //! \param [out] encodeStatusReport
1889 //! Encoder status report
1890 //! \return MOS_STATUS
1891 //! MOS_STATUS_SUCCESS if success, else fail reason
1892 //!
1893 virtual MOS_STATUS GetStatusReport(
1894 EncodeStatus* encodeStatus,
1895 EncodeStatusReport* encodeStatusReport) = 0;
1896
1897 //!
1898 //! \brief User Feature Key Report
1899 //! \return MOS_STATUS
1900 //! MOS_STATUS_SUCCESS if success, else fail reason
1901 //!
1902 virtual MOS_STATUS UserFeatureKeyReport();
1903
1904 //!
1905 //! \brief Help function to submit a command buffer
1906 //!
1907 //! \param [in] cmdBuffer
1908 //! Pointer to command buffer
1909 //! \param [in] nullRendering
1910 //! Null rendering flag
1911 //!
1912 //! \return MOS_STATUS
1913 //! MOS_STATUS_SUCCESS if success, else fail reason
1914 //!
1915 virtual MOS_STATUS SubmitCommandBuffer(
1916 PMOS_COMMAND_BUFFER cmdBuffer,
1917 bool bNullRendering);
1918
1919 //!
1920 //! \brief Check Supported Format
1921 //! \param [in] surface
1922 //! Input surface to check
1923 //! \return bool
1924 //! true if supported, false if not
1925 //!
1926 virtual bool CheckSupportedFormat(
1927 PMOS_SURFACE surface);
1928
1929 //!
1930 //! \brief Encode Copy Skip Frame
1931 //! \return MOS_STATUS
1932 //! MOS_STATUS_SUCCESS if success, else fail reason
1933 //!
1934 virtual MOS_STATUS EncodeCopySkipFrame()
1935 {
1936 return MOS_STATUS_SUCCESS;
1937 }
1938
1939 //!
1940 //! \brief Read Image Status
1941 //! \param [in, out] cmdBuffer
1942 //! Input and output cmdbuffer
1943 //! \return MOS_STATUS
1944 //! MOS_STATUS_SUCCESS if success, else fail reason
1945 //!
1946 virtual MOS_STATUS ReadImageStatus(
1947 PMOS_COMMAND_BUFFER cmdBuffer);
1948
1949 //!
1950 //! \brief Read Mfc Status
1951 //! \param [in, out] cmdBuffer
1952 //! Input and output cmdbuffer
1953 //! \return MOS_STATUS
1954 //! MOS_STATUS_SUCCESS if success, else fail reason
1955 //!
1956 virtual MOS_STATUS ReadMfcStatus(
1957 PMOS_COMMAND_BUFFER cmdBuffer);
1958
1959 //!
1960 //! \brief Send Prolog With Frame Tracking
1961 //! \param [in, out] cmdBuffer
1962 //! Input and output cmdbuffer
1963 //! \param [in] frameTrackingRequested
1964 //! frame Tracking Requested
1965 //! \return MOS_STATUS
1966 //! MOS_STATUS_SUCCESS if success, else fail reason
1967 //!
1968 virtual MOS_STATUS SendPrologWithFrameTracking(
1969 PMOS_COMMAND_BUFFER cmdBuffer,
1970 bool frameTrackingRequested,
1971 MHW_MI_MMIOREGISTERS* mmioRegister = nullptr);
1972
1973 //!
1974 //! \brief Inserts predication command for a command buffer
1975 //! \param [in] cmdBuffer
1976 //! Command buffer
1977 //! \return MOS_STATUS
1978 //! MOS_STATUS_SUCCESS if success, else fail reason
1979 //!
1980 MOS_STATUS SendPredicationCommand(
1981 PMOS_COMMAND_BUFFER cmdBuffer);
1982
1983 //!
1984 //! \brief Inserts marker commands for a command buffer
1985 //! \param [in] cmdBuffer
1986 //! Command buffer
1987 //! \param [in] isRender
1988 //! Whether render engine workload or not
1989 //! \return MOS_STATUS
1990 //! MOS_STATUS_SUCCESS if success, else fail reason
1991 //!
1992 MOS_STATUS SendMarkerCommand(
1993 PMOS_COMMAND_BUFFER cmdBuffer,
1994 bool isRender);
1995
1996 //!
1997 //! \brief Calculate Command Buffer Size
1998 //!
1999 //! \return uint32_t
2000 //! Command buffer size calculated
2001 //!
2002 virtual uint32_t CalculateCommandBufferSize();
2003
2004 //!
2005 //! \brief Prepare Nodes
2006 //! \param [in, out] videoGpuNode
2007 //! GPU node prepared
2008 //! \param [in, out] setVideoNode
2009 //! flag indicates if node needs to set
2010 //! \return void
2011 //!
2012 virtual void PrepareNodes(
2013 MOS_GPU_NODE& videoGpuNode,
2014 bool& setVideoNode);
2015
2016 //!
2017 //! \brief Set up params for gpu context creation
2018 //! \return MOS_STATUS
2019 //! MOS_STATUS_SUCCESS if success, else fail reason
2020 //!
2021 virtual MOS_STATUS SetGpuCtxCreatOption();
2022
2023 //!
2024 //! \brief Sets video gpu context
2025 //!
2026 void SetVideoContext(MOS_GPU_CONTEXT videoContext) { m_videoContext = videoContext; }
2027
2028 //!
2029 //! \brief Create Gpu Contexts
2030 //!
2031 //! \return MOS_STATUS
2032 //! MOS_STATUS_SUCCESS if success, else fail reason
2033 //!
2034 virtual MOS_STATUS CreateGpuContexts();
2035
2036 //!
2037 //! \brief Verify Space Available
2038 //! \return MOS_STATUS
2039 //! MOS_STATUS_SUCCESS if success, else fail reason
2040 //!
2041 MOS_STATUS VerifySpaceAvailable();
2042
2043 //!
2044 //! \brief Add MEDIA_VFE command to command buffer
2045 //! \param [in, out] cmdBuffer
2046 //! cmdbuffer to send cmds
2047 //! \param [in] params
2048 //! Parameters for send cmds
2049 //! \return MOS_STATUS
2050 //! MOS_STATUS_SUCCESS if success, else fail reason
2051 //!
2052 virtual MOS_STATUS AddMediaVfeCmd(
2053 PMOS_COMMAND_BUFFER cmdBuffer,
2054 SendKernelCmdsParams *params);
2055
2056 //!
2057 //! \brief Send Generic Kernel Cmds
2058 //! \param [in, out] cmdBuffer
2059 //! cmdbuffer to send cmds
2060 //! \param [in] params
2061 //! Parameters for send cmds
2062 //! \return MOS_STATUS
2063 //! MOS_STATUS_SUCCESS if success, else fail reason
2064 //!
2065 MOS_STATUS SendGenericKernelCmds(
2066 PMOS_COMMAND_BUFFER cmdBuffer,
2067 SendKernelCmdsParams *params);
2068
2069 //!
2070 //! \brief Start Status Report
2071 //! \param [in, out] cmdBuffer
2072 //! cmdbuffer to send cmds
2073 //! \param [in] encFunctionType
2074 //! encFunctionType for send cmds
2075 //! \return MOS_STATUS
2076 //! MOS_STATUS_SUCCESS if success, else fail reason
2077 //!
2078 MOS_STATUS StartStatusReport(
2079 PMOS_COMMAND_BUFFER cmdBuffer,
2080 CODECHAL_MEDIA_STATE_TYPE encFunctionType);
2081
2082 //!
2083 //! \brief End Status Report
2084 //! \param [in, out] cmdBuffer
2085 //! cmdbuffer to send cmds
2086 //! \param [in] encFunctionType
2087 //! encFunctionType for send cmds
2088 //! \return MOS_STATUS
2089 //! MOS_STATUS_SUCCESS if success, else fail reason
2090 //!
2091 MOS_STATUS EndStatusReport(
2092 PMOS_COMMAND_BUFFER cmdBuffer,
2093 CODECHAL_MEDIA_STATE_TYPE encFunctionType);
2094
2095 //!
2096 //! \brief Set Status Report Parameters
2097 //! \param [in] currRefList
2098 //! current RefList used to set
2099 //! \return MOS_STATUS
2100 //! MOS_STATUS_SUCCESS if success, else fail reason
2101 //!
2102 MOS_STATUS SetStatusReportParams(
2103 PCODEC_REF_LIST currRefList);
2104
2105 //!
2106 //! \brief Motion Estimation Disable Check
2107 //!
2108 //! \return void
2109 //!
2110 virtual void MotionEstimationDisableCheck();
2111
2112 //!
2113 //! \brief Execute the encode
2114 //!
2115 //! \param [in] encodeParams
2116 //! Encode parameters used
2117 //!
2118 //! \return MOS_STATUS
2119 //! MOS_STATUS_SUCCESS if success, else fail reason
2120 //!
2121 MOS_STATUS ExecuteEnc(
2122 EncoderParams* encodeParams);
2123
2124 //! \brief Execute FEI PreEnc
2125 //!
2126 //! \param [in] encodeParams
2127 //! Encode parameters used
2128 //!
2129 //! \return MOS_STATUS
2130 //! MOS_STATUS_SUCCESS if success, else fail reason
2131 //!
2132 virtual MOS_STATUS ExecutePreEnc(
2133 EncoderParams* encodeParams) { return MOS_STATUS_SUCCESS; }
2134
2135 //!
2136 //! \brief Destroy Me Resources
2137 //!
2138 //! \param [in] param
2139 //! Hme parameters used
2140 //!
2141 //! \return MOS_STATUS
2142 //! MOS_STATUS_SUCCESS if success, else fail reason
2143 //!
2144 MOS_STATUS DestroyMeResources(
2145 HmeParams* param);
2146
2147 //!
2148 //! \brief Clean Up Resource
2149 //!
2150 //! \param [in, out] resource
2151 //! Resource to clean up
2152 //! \param [in] allocParams
2153 //! allocParams used to clean
2154 //!
2155 //! \return MOS_STATUS
2156 //! MOS_STATUS_SUCCESS if success, else fail reason
2157 //!
2158 MOS_STATUS CleanUpResource(
2159 PMOS_RESOURCE resource,
2160 PMOS_ALLOC_GFXRES_PARAMS allocParams);
2161
2162 //!
2163 //! \brief Allocate Resources 4x Me
2164 //!
2165 //! \param [in] param
2166 //! Hme parameters used
2167 //!
2168 //! \return MOS_STATUS
2169 //! MOS_STATUS_SUCCESS if success, else fail reason
2170 //!
2171 MOS_STATUS AllocateResources4xMe(
2172 HmeParams* param);
2173
2174 //!
2175 //! \brief Allocate Resources 16x Me
2176 //!
2177 //! \param [in] param
2178 //! Hme parameters used
2179 //!
2180 //! \return MOS_STATUS
2181 //! MOS_STATUS_SUCCESS if success, else fail reason
2182 //!
2183 MOS_STATUS AllocateResources16xMe(
2184 HmeParams* param);
2185
2186 //!
2187 //! \brief Allocate Resources 32x Me
2188 //!
2189 //! \param [in] param
2190 //! Hme parameters used
2191 //!
2192 //! \return MOS_STATUS
2193 //! MOS_STATUS_SUCCESS if success, else fail reason
2194 //!
2195 MOS_STATUS AllocateResources32xMe(
2196 HmeParams* param);
2197
2198 //!
2199 //! \brief Initialize Common
2200 //!
2201 //! \return MOS_STATUS
2202 //! MOS_STATUS_SUCCESS if success, else fail reason
2203 //!
2204 MOS_STATUS InitCommon();
2205
2206 //!
2207 //! \brief Resize Internal Buffer on Resolution Change
2208 //!
2209 virtual void ResizeOnResChange();
2210
2211 //!
2212 //! \brief Check Resolution Change and CSC
2213 //!
2214 //! \details On resolution change, resize internal buffer
2215 //! Check raw surface to set flag for CSC operation
2216 //!
2217 //! \return MOS_STATUS
2218 //! MOS_STATUS_SUCCESS if success, else fail reason
2219 //!
2220 virtual MOS_STATUS CheckResChangeAndCsc();
2221
2222 //!
2223 //! \brief Destroy encode state
2224 //!
2225 //! \return void
2226 //!
2227 void Destroy() override;
2228
2229 //!
2230 //! \brief Allocate Scaling Resources
2231 //!
2232 //! \return MOS_STATUS
2233 //! MOS_STATUS_SUCCESS if success, else fail reason
2234 //!
2235 MOS_STATUS AllocateScalingResources();
2236
2237 //!
2238 //! \brief Execute Me Kernel
2239 //!
2240 //! \param [in] meParams
2241 //! meParams used to execute kernel
2242 //! \param [in] meSurfaceParams
2243 //! meSurfaceParams used to execute kernel
2244 //! \param [in] hmeLevel
2245 //! hme Level used to execute kernel
2246 //!
2247 //! \return MOS_STATUS
2248 //! MOS_STATUS_SUCCESS if success, else fail reason
2249 //!
2250 virtual MOS_STATUS ExecuteMeKernel(
2251 MeCurbeParams *meParams,
2252 MeSurfaceParams *meSurfaceParams,
2253 HmeLevel hmeLevel);
2254
2255 //!
2256 //! \brief Initialize Status Report
2257 //!
2258 //! \return MOS_STATUS
2259 //! MOS_STATUS_SUCCESS if success, else fail reason
2260 //!
2261 MOS_STATUS InitStatusReport();
2262
2263 //!
2264 //! \brief Update Encode Status
2265 //!
2266 //! \param [in, out] cmdBuffer
2267 //! cmdbuffer to send cmds
2268 //! \param [in] forceOperation
2269 //! forceOperation flag used
2270 //!
2271 //! \return MOS_STATUS
2272 //! MOS_STATUS_SUCCESS if success, else fail reason
2273 //!
2274 MOS_STATUS UpdateEncodeStatus(
2275 PMOS_COMMAND_BUFFER cmdBuffer,
2276 bool forceOperation);
2277
2278 //!
2279 //! \brief Reset Encode Status
2280 //!
2281 //! \return MOS_STATUS
2282 //! MOS_STATUS_SUCCESS if success, else fail reason
2283 //!
2284 MOS_STATUS ResetStatusReport();
2285
2286 //!
2287 //! \brief Read Brc Pak Statistics
2288 //!
2289 //! \param [in, out] cmdBuffer
2290 //! cmdbuffer to send cmds
2291 //! \param [in] params
2292 //! parameters used
2293 //!
2294 //! \return MOS_STATUS
2295 //! MOS_STATUS_SUCCESS if success, else fail reason
2296 //!
2297 MOS_STATUS ReadBrcPakStatistics(
2298 PMOS_COMMAND_BUFFER cmdBuffer,
2299 EncodeReadBrcPakStatsParams* params);
2300
2301 //!
2302 //! \brief Update command buffer attribute
2303 //!
2304 //! \param [in] cmdBuffer
2305 //! cmdbuffer to send cmds
2306 //! \param [in] renderEngineInUse
2307 //! renderEngineInUse flag used
2308 //!
2309 //! \return MOS_STATUS
2310 //! MOS_STATUS_SUCCESS if success, else fail reason
2311 //!
2312 virtual MOS_STATUS UpdateCmdBufAttribute(
2313 PMOS_COMMAND_BUFFER cmdBuffer,
2314 bool renderEngineInUse);
2315
2316 //!
2317 //! \brief Function pointer of Get Kernel Header And Size
2318 //!
2319 //! \return MOS_STATUS
2320 //! MOS_STATUS_SUCCESS if success, else fail reason
2321 //!
2322 MOS_STATUS(*pfnGetKernelHeaderAndSize) (
2323 void *binary,
2324 EncOperation operation,
2325 uint32_t krnStateIdx,
2326 void *krnHeader,
2327 uint32_t *krnSize);
2328
2329 //!
2330 //! \brief Function to allocate MDF required resources
2331 //!
2332 //! \return MOS_STATUS
2333 //! MOS_STATUS_SUCCESS if success, else fail reason
2334 //!
2335 virtual MOS_STATUS AllocateMDFResources();
2336
2337 //!
2338 //! \brief Function to destroy MDF required resources
2339 //!
2340 //! \return MOS_STATUS
2341 //! MOS_STATUS_SUCCESS if success, else fail reason
2342 //!
2343 virtual MOS_STATUS DestroyMDFResources();
2344
2345 //!
2346 //! \brief Function to set MFE Shared State
2347 //!
2348 //! \details Pointer on passed object will be saved in the local field,
2349 //! content of source object might be changed later
2350 //! (for example, CmDevice might be set or chagned)
2351 //!
2352 //! \return MOS_STATUS
2353 //! MOS_STATUS_SUCCESS if success, else fail reason
2354 //!
2355 virtual MOS_STATUS SetMfeSharedState(MfeSharedState *pMfeSharedState);
2356
2357 //!
2358 //! \brief Function to add MDF kernel
2359 //!
2360 //! \param [in] device
2361 //! pointer to CmDevice
2362 //! \param [in] queue
2363 //! pointer to CmQueue
2364 //! \param [in] kernel
2365 //! pointer to CmKernel
2366 //! \param [in] task
2367 //! pointer to CmTask
2368 //! \param [in] threadspace
2369 //! pointer to CmThreadSpace
2370 //! \param [in] event
2371 //! reference to CmEvent*
2372 //! \param [in] isEnqueue
2373 //! bool
2374 //!
2375 //! \return MOS_STATUS
2376 //! MOS_STATUS_SUCCESS if success, else fail reason
2377 //!
2378 MOS_STATUS AddKernelMdf(
2379 CmDevice *device,
2380 CmQueue *queue,
2381 CmKernel *kernel,
2382 CmTask *task,
2383 CmThreadSpace *threadspace,
2384 CmEvent *&event,
2385 bool isEnqueue);
2386
2387 //!
2388 //! \brief Function to create Mdf Kernel resource
2389 //!
2390 //! \param [out] resource
2391 //! pointer to CodechalEncodeMdfKernelResource
2392 //! \param [in] kernelNum
2393 //! uint8_t, kernel number
2394 //! \param [in] bufNum
2395 //! uint8_t, buffer number
2396 //! \param [in] surfNum
2397 //! uint8_t, surface number
2398 //! \param [in] vmeSurfNum
2399 //! uint8_t, vme surface number
2400 //! \param [in] curbeSize
2401 //! uint16_t, curbe structure size
2402 //!
2403 //! \return MOS_STATUS
2404 //! MOS_STATUS_SUCCESS if success, else fail reason
2405 //!
2406 MOS_STATUS CreateMDFKernelResource(
2407 CodechalEncodeMdfKernelResource *resource,
2408 uint8_t kernelNum,
2409 uint8_t bufNum,
2410 uint8_t surfNum,
2411 uint8_t vmeSurfNum,
2412 uint16_t curbeSize);
2413
2414 //!
2415 //! \brief Function to destroy Mdf kernel resource
2416 //!
2417 //! \param [in] resource
2418 //! pointer to CodechalEncodeMdfKernelResource
2419 //!
2420 //! \return MOS_STATUS
2421 //! MOS_STATUS_SUCCESS if success, else fail reason
2422 //!
2423 MOS_STATUS DestroyMDFKernelResource(
2424 CodechalEncodeMdfKernelResource *resource);
2425
2426 //!
2427 //! \brief Function to free Mdf kernel surfaces
2428 //!
2429 //! \param [in] resource
2430 //! pointer to CodechalEncodeMdfKernelResource
2431 //!
2432 //! \return MOS_STATUS
2433 //! MOS_STATUS_SUCCESS if success, else fail reason
2434 //!
2435 MOS_STATUS FreeMDFKernelSurfaces(
2436 CodechalEncodeMdfKernelResource *resource);
2437
2438 //!
2439 //! \brief Returns number of PAK Passes based on BRC Precision flag
2440 //!
2441 //! \param [in] usBRCPrecision
2442 //! refer to CodechalEncodeBrcNumPasses
2443 //!
2444 //! \return uint8_t
2445 //! number of pak passes
2446 //!
2447 uint8_t GetNumBrcPakPasses(uint16_t usBRCPrecision);
2448
2449 //!
2450 //! \brief Setup Walker Context
2451 //! \param [in, out] cmdBuffer
2452 //! Input and output cmdbuffer
2453 //! \param [in] Pointer to kernel state
2454 //!
2455 //! \return MOS_STATUS
2456 //! MOS_STATUS_SUCCESS if success, else fail reason
2457 //!
2458 virtual MOS_STATUS SetupWalkerContext(
2459 MOS_COMMAND_BUFFER* cmdBuffer,
2460 SendKernelCmdsParams* params);
2461
2462 MOS_STATUS ResolveMetaData(
2463 PMOS_RESOURCE pHwLayoutMetaData,
2464 PMOS_RESOURCE pResolvedLayoutMetadata) override;
2465
2466 MOS_STATUS ReportErrorFlag(
2467 PMOS_RESOURCE pMetadataBuffer,
2468 uint32_t size,
2469 uint32_t offset,
2470 uint32_t flag) override;
2471
2472 virtual MOS_STATUS PrepareHWMetaData(
2473 PMOS_RESOURCE presMetadataBuffer,
2474 PMOS_RESOURCE presLcuBaseAddressBuffer,
2475 PMOS_COMMAND_BUFFER cmdBuffer)
2476 {
2477 return MOS_STATUS_SUCCESS;
2478 }
2479
2480 //!
2481 //! \brief Add store HUC_STATUS2 register
2482 //!
2483 //! \param [in] cmdBuffer
2484 //! Pointer to the command buffer
2485 //!
2486 //! \return MOS_STATUS
2487 //! MOS_STATUS_SUCCESS if success, else fail reason
2488 //!
2489 MOS_STATUS StoreHuCStatus2Report(PMOS_COMMAND_BUFFER cmdBuffer);
2490 //!
2491 //! \brief Gets hardware interface.
2492 //! \return CodechalHwInterface
2493 //! return hardware interface
2494 //!
2495 CodechalHwInterface *GetHwInterface() { return m_hwInterface; }
2496 #if USE_CODECHAL_DEBUG_TOOL
2497 virtual MOS_STATUS DumpMbEncPakOutput(PCODEC_REF_LIST currRefList, CodechalDebugInterface* debugInterface);
2498 virtual MOS_STATUS DumpFrameStatsBuffer(CodechalDebugInterface* debugInterface) { return MOS_STATUS_SUCCESS; }
2499
2500 //!
2501 //! \brief Add/Subtract a value to specified gfx memory
2502 //!
2503 //! \param [in] cmdBuffer
2504 //! command buffer
2505 //! \param [in] presStoreBuffer
2506 //! buffer to modify
2507 //! \param [in] offset
2508 //! member offset in the buffer
2509 //! \param [in] value
2510 //! value to add/subtract
2511 //! \param [in] bAdd
2512 //! add or subtract
2513 //!
2514 //! \return MOS_STATUS
2515 //! MOS_STATUS_SUCCESS if success, else fail reason
2516 //!
2517 MOS_STATUS AddBufferWithIMMValue(
2518 PMOS_COMMAND_BUFFER cmdBuffer,
2519 PMOS_RESOURCE presStoreBuffer,
2520 uint32_t offset,
2521 uint32_t value,
2522 bool bAdd);
2523
2524 //!
2525 //! \brief Set a 16 bit value to specified gfx memory dword
2526 //!
2527 //! \param [in] cmdBuffer
2528 //! command buffer
2529 //! \param [in] presStoreBuffer
2530 //! buffer to modify
2531 //! \param [in] offset
2532 //! member offset in the buffer
2533 //! \param [in] value
2534 //! value to set
2535 //! \param [in] bSecond
2536 //! second or first word in dword
2537 //!
2538 //! \return MOS_STATUS
2539 //! MOS_STATUS_SUCCESS if success, else fail reason
2540 //!
2541 MOS_STATUS SetBufferWithIMMValueU16(
2542 PMOS_COMMAND_BUFFER cmdBuffer,
2543 PMOS_RESOURCE presStoreBuffer,
2544 uint32_t offset,
2545 uint32_t value,
2546 bool bSecond);
2547
2548 bool m_enableFakeHrdSize = false;
2549 int32_t m_fakeIFrameHrdSize = 0;
2550 int32_t m_fakePBFrameHrdSize = 0;
2551 #endif
2552 };
2553
2554 static void PutBit(BSBuffer *bsbuffer, uint32_t code)
2555 {
2556 if (code & 1)
2557 {
2558 *(bsbuffer->pCurrent) = (*(bsbuffer->pCurrent) | (uint8_t)(0x01 << (7 - bsbuffer->BitOffset)));
2559 }
2560
2561 bsbuffer->BitOffset++;
2562 if (bsbuffer->BitOffset == 8)
2563 {
2564 bsbuffer->BitOffset = 0;
2565 bsbuffer->pCurrent++;
2566 *(bsbuffer->pCurrent) = 0;
2567 }
2568 }
2569
2570 static void PutBitsSub(BSBuffer *bsbuffer, uint32_t code, uint32_t length)
2571 {
2572 uint8_t *byte = bsbuffer->pCurrent;
2573
2574 // make sure that the number of bits given is <= 24
2575 CODECHAL_ENCODE_ASSERT(length <= 24);
2576
2577 code <<= (32 - length);
2578
2579 // shift field so that the given code begins at the current bit
2580 // offset in the most significant byte of the 32-bit word
2581 length += bsbuffer->BitOffset;
2582 code >>= bsbuffer->BitOffset;
2583
2584 // write bytes back into memory, big-endian
2585 byte[0] = (uint8_t)((code >> 24) | byte[0]);
2586 byte[1] = (uint8_t)(code >> 16);
2587 if (length > 16)
2588 {
2589 byte[2] = (uint8_t)(code >> 8);
2590 byte[3] = (uint8_t)code;
2591 }
2592 else
2593 {
2594 byte[2] = 0;
2595 }
2596
2597 // update bitstream pointer and bit offset
2598 bsbuffer->pCurrent += (length >> 3);
2599 bsbuffer->BitOffset = (length & 7);
2600 }
2601
2602 static void PutBits(BSBuffer *bsbuffer, uint32_t code, uint32_t length)
2603 {
2604 uint32_t code1, code2;
2605
2606 // temp solution, only support up to 32 bits based on current usage
2607 CODECHAL_ENCODE_ASSERT(length <= 32);
2608
2609 if (length >= 24)
2610 {
2611 code1 = code & 0xFFFF;
2612 code2 = code >> 16;
2613
2614 // high bits go first
2615 PutBitsSub(bsbuffer, code2, length - 16);
2616 PutBitsSub(bsbuffer, code1, 16);
2617 }
2618 else
2619 {
2620 PutBitsSub(bsbuffer, code, length);
2621 }
2622 }
2623
2624 #endif // __CODECHAL_ENCODER_BASE_H__