1 /*
2 * Copyright (c) 2017, 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_encode_hevc_g10.h
24 //! \brief    HEVC dual-pipe encoder for GEN10 platform.
25 //!
26 
27 #ifndef __CODECHAL_ENCODE_HEVC_G10_H__
28 #define __CODECHAL_ENCODE_HEVC_G10_H__
29 
30 #include "codechal.h"
31 #include "codechal_hw.h"
32 #include "codechal_encode_hevc.h"
33 
34 struct DsConvCurbeDataG10
35 {
DsConvCurbeDataG10DsConvCurbeDataG1036     DsConvCurbeDataG10()
37     {
38         DW0_InputBitDepthForChroma = 10;
39         DW0_InputBitDepthForLuma = 10;
40         DW0_OutputBitDepthForChroma = 8;
41         DW0_OutputBitDepthForLuma = 8;
42         DW0_RoundingEnable = 1;
43         DW1_PictureFormat = 0;
44         DW1_ConvertFlag = 0;
45         DW1_DownscaleStage = dsDisabled;
46         DW1_MbStatisticsDumpFlag = 0;
47         DW1_Reserved_0 = 0;
48         DW1_LcuSize = 0;
49         DW1_JobQueueSize = 2656;
50         DW2_OriginalPicWidthInSamples = 0;
51         DW2_OriginalPicHeightInSamples = 0;
52         DW3_BTI_InputConversionSurface = 0xffff;
53         DW4_BTI_Value = 0xffff;
54         DW5_BTI_4xDsSurface = 0xffff;
55         DW6_BTI_MBStatsSurface = 0xffff;
56         DW7_BTI_2xDsSurface = 0xffff;
57         DW8_BTI_MB_Split_Surface = 0xffff;
58         DW9_BTI_LCU32_JobQueueScratchBufferSurface = 0xffff;
59         DW10_BTI_LCU64_CU32_JobQueueScratchBufferSurface = 0xffff;
60         DW11_BTI_LCU64_CU32_64x64_DistortionSurface = 0xffff;
61     }
62 
63     // DWORD 0
64     uint32_t   DW0_InputBitDepthForChroma : MOS_BITFIELD_RANGE(0, 7);
65     uint32_t   DW0_InputBitDepthForLuma : MOS_BITFIELD_RANGE(8, 15);
66     uint32_t   DW0_OutputBitDepthForChroma : MOS_BITFIELD_RANGE(16, 23);
67     uint32_t   DW0_OutputBitDepthForLuma : MOS_BITFIELD_RANGE(24, 30);
68     uint32_t   DW0_RoundingEnable : MOS_BITFIELD_BIT(31);
69 
70     // DWORD 1
71     uint32_t   DW1_PictureFormat : MOS_BITFIELD_RANGE(0, 7);
72     uint32_t   DW1_ConvertFlag : MOS_BITFIELD_BIT(8);
73     uint32_t   DW1_DownscaleStage : MOS_BITFIELD_RANGE(9, 11);
74     uint32_t   DW1_MbStatisticsDumpFlag : MOS_BITFIELD_BIT(12);
75     uint32_t   DW1_Reserved_0 : MOS_BITFIELD_RANGE(13, 14);
76     uint32_t   DW1_LcuSize : MOS_BITFIELD_BIT(15);
77     uint32_t   DW1_JobQueueSize : MOS_BITFIELD_RANGE(16, 31);
78 
79     // DWORD 2
80     uint32_t   DW2_OriginalPicWidthInSamples : MOS_BITFIELD_RANGE(0, 15);
81     uint32_t   DW2_OriginalPicHeightInSamples : MOS_BITFIELD_RANGE(16, 31);
82 
83     // DWORD 3
84     uint32_t   DW3_BTI_InputConversionSurface : MOS_BITFIELD_RANGE(0, 31);
85 
86     // DWORD 4
87     union {
88         uint32_t   DW4_BTI_OutputConversionSurface : MOS_BITFIELD_RANGE(0, 31);
89         uint32_t   DW4_BTI_InputDsSurface : MOS_BITFIELD_RANGE(0, 31);
90         uint32_t   DW4_BTI_Value : MOS_BITFIELD_RANGE(0, 31);
91     };
92 
93     // DWORD 5
94     uint32_t   DW5_BTI_4xDsSurface : MOS_BITFIELD_RANGE(0, 31);
95 
96     // DWORD 6
97     uint32_t   DW6_BTI_MBStatsSurface : MOS_BITFIELD_RANGE(0, 31);
98 
99     // DWORD 7
100     uint32_t   DW7_BTI_2xDsSurface : MOS_BITFIELD_RANGE(0, 31);
101 
102     // DWORD 8
103     uint32_t   DW8_BTI_MB_Split_Surface : MOS_BITFIELD_RANGE(0, 31);
104 
105     // DWORD 9
106     uint32_t   DW9_BTI_LCU32_JobQueueScratchBufferSurface : MOS_BITFIELD_RANGE(0, 31);
107 
108     // DWORD 10
109     uint32_t   DW10_BTI_LCU64_CU32_JobQueueScratchBufferSurface : MOS_BITFIELD_RANGE(0, 31);
110 
111     // DWORD 11
112     uint32_t   DW11_BTI_LCU64_CU32_64x64_DistortionSurface : MOS_BITFIELD_RANGE(0, 31);
113 
114 };
115 
116 //!
117 //! \brief    Surface params for DsConv kernel
118 //!
119 struct SurfaceParamsDsConv
120 {
121     PMOS_SURFACE                        psInputSurface = nullptr;
122     uint32_t                            dwInputFrameWidth = 0;
123     uint32_t                            dwInputFrameHeight = 0;
124     PMOS_SURFACE                        psOutputConvertedSurface = nullptr;
125     uint32_t                            dwOutputConvertedFrameWidth = 0;
126     uint32_t                            dwOutputConvertedFrameHeight = 0;
127     PMOS_SURFACE                        psOutputScaledSurface4x = nullptr;
128     uint32_t                            dwOutputScaledFrameWidth4x = 0;
129     uint32_t                            dwOutputScaledFrameHeight4x = 0;
130     PMOS_SURFACE                        psOutputScaledSurface2x = nullptr;
131     uint32_t                            dwOutputScaledFrameWidth2x = 0;
132     uint32_t                            dwOutputScaledFrameHeight2x = 0;
133     PCODECHAL_ENCODE_BINDING_TABLE_GENERIC      pBindingTable = nullptr;
134     PMHW_KERNEL_STATE                   pKernelState = nullptr;
135     DsStage                             downScaleConversionType = dsDisabled;
136 };
137 
138 //!  HEVC dual-pipe encoder class for GEN10
139 /*!
140 This class defines the member fields, functions for GEN10 platform
141 */
142 class CodechalEncHevcStateG10 : public CodechalEncHevcState
143 {
144 public:
145 
146     //! TU based param list
147     enum {
148         EnableCu64CheckTuParam = 0,
149         Cu64SkipCheckOnlyTuParam,
150         EncQtDecisionModeTuParam,
151         EncTuDecisionModeTuParam,
152         EncTuDecisionForAllQtTuParam,
153         EncRdDecisionModeForAllQtTuParam,
154         CoefBitEstModeTuParam,
155         MaxNumIMESearchCenterTuParam,
156         EncSkipDecisionModeTuParam,
157         EncTransformSimplifyTuParam,
158         Log2TUMaxDepthInterTuParam,
159         Log2TUMaxDepthIntraTuParam,
160         TotalThreadNumPerLCUTuParam,
161         SICDynamicRunPathMode,
162         TotalThreadNumPerLCUTuParamFor4KOnly,
163         NumRegionLCU64,
164         TotalTuParams
165     };
166 
167     //! Integer motion estimation ref window mode
168     enum
169     {
170         IME_REF_WINDOW_MODE_RESERVED = 0,
171         IME_REF_WINDOW_MODE_BIG,
172         IME_REF_WINDOW_MODE_MEDIUM,
173         IME_REF_WINDOW_MODE_SMALL,
174         IME_REF_WINDOW_MODE_MAX
175     };
176 
177     static const uint32_t  m_jobQueueSizeFor32x32Block      = 2656;     //!< Job queue size for 32x32 block
178     static const uint32_t  m_brcLambdaModeCostTableSize     = 1664;     //!< Size in bytes for BRC lambda mode cost LUT
179     static const uint32_t  m_encIConstantDataLutSize        = 24576;    //!< Constant data LUT size in ints for I-kernel
180     static const uint32_t  m_encBConstantDataLutSize        = 582240;   //!< Constant data LUT size in ints for B-kernel
181     static const uint32_t  m_encBConstantDataLutLcu64Size   = 1003520;  //!< Constant data LUT size in ints for LCU64 B-kernel
182     static const uint32_t  m_maxThreadsPerLcuB              = 8;        //!< Maximum number of threads for LCU B
183     static const uint32_t  m_minThreadsPerLcuB              = 3;        //!< Minimum number of threads for LCU B
184     static const uint32_t  m_brcConstantSurfaceHeight       = 35;       //!< BRC constant surface height
185     static const uint32_t  m_minScaledSurfaceSize           = 64;       //!< Minimal scaled surface size
186     static const uint32_t  m_brcCombinedEncBufferSize       = 128;      //!< Brc Combined Enc buffer size
187 
188     static const uint32_t  m_brcLcu32x32LambdaModeCost[m_brcLambdaModeCostTableSize>>2];   //!< Lambda mode cost table for BRC LCU32x32
189     static const uint32_t  m_brcLcu64x64LambdaModeCost[m_brcLambdaModeCostTableSize>>2];   //!< Lambda mode cost table for BRC LCU64x64
190     static const uint32_t  m_encIConstantDataLut[m_encIConstantDataLutSize];               //!< Constant data table for I kernel
191     static const uint32_t  m_encBConstantDataLut[m_encBConstantDataLutSize];               //!< Constant data table for B kernel
192     static const uint32_t  m_encBConstantDataLutLcu64[m_encBConstantDataLutLcu64Size];     //!< Constant data table for LCU64 B kernel
193 
194     static const double   m_lambdaScaling[3][QP_NUM];                                   //!< Cost table weighting factor
195     static const uint8_t  m_imeRefWindowSize[IME_REF_WINDOW_MODE_MAX][2];               //!< Table specifying the search window size for IME
196     static const double   m_modeBits[2][3][15];                                         //!< Mode Bits table for cost computing
197     static const uint8_t  m_tuSettings[TotalTuParams][3];                               //!< Table for TU based settings for different TU params
198 
199     static const struct CODECHAL_ENC_HEVC_ME_CURBE_G10 m_meCurbeInit;                          //!< Curbe initialization data for ME kernel
200     static const struct CODECHAL_ENC_HEVC_BRC_INITRESET_CURBE_G10 m_brcInitResetCurbeInit;     //!< Curbe initialization data for BRC Init/Reset kernel
201     static const struct CODECHAL_ENC_HEVC_BRC_UPDATE_CURBE_G10 m_brcUpdateCurbeInit;           //!< Curbe initialization data for BRC Update kernel
202     static const struct CODECHAL_ENC_HEVC_MBENC_I_CURBE_G10 m_mbencICurbeInit;                 //!< Curbe initialization data for MBENC I kernel
203     static const struct CODECHAL_ENC_HEVC_MBENC_B_CURBE_G10 m_mbencBCurbeInit;                 //!< Curbe initialization data for MBENC B kernel
204 
205     CODECHAL_ENCODE_BUFFER  m_kernelDebug;                             //!< Kernel Debug Surface for B-kernel
206     MOS_SURFACE             m_intermediateCuRecordSurfaceLcu32;        //!< Intermediate CU Record Surface for I and B kernel
207     MOS_SURFACE             m_secondIntermediateCuRecordSurfaceLcu32;  //!< Second Intermediate CU Record Surface for B kernel
208     MOS_SURFACE             m_intermediateCuRecordSurfaceLcu64B;       //!< Intermediate CU Record Surface for Lcu64 B-kernel
209     CODECHAL_ENCODE_BUFFER  m_encConstantTableForI;                    //!< Enc Constant Table for I
210     CODECHAL_ENCODE_BUFFER  m_encConstantTableForB;                    //!< Enc constant table for B LCU32
211     CODECHAL_ENCODE_BUFFER  m_encConstantTableForLcu64B;               //!< Enc constant table for B LCU64
212     CODECHAL_ENCODE_BUFFER  m_lcuLevelInputData;                       //!< Lcu level input data
213     CODECHAL_ENCODE_BUFFER  m_lcuEncodingScratchSurface;               //!< Lcu encoding scratch surface
214     CODECHAL_ENCODE_BUFFER  m_lcuEncodingScratchSurfaceLcu64B;         //!< Lcu scratch surface
215     CODECHAL_ENCODE_BUFFER  m_64x64DistortionSurface;                  //!< Distortion surface for 64x64
216     MOS_SURFACE             m_scratchSurface;                          //!< Scartch Surface for I-kernel
217     CODECHAL_ENCODE_BUFFER  m_concurrentThreadGroupData;               //!< Concurrent Thread Group Data Surface
218     CODECHAL_ENCODE_BUFFER  m_jobQueueHeaderSurfaceForB;               //!< Job Queue Header buffer surface. When used by LCU64 kernel, it is the 1D header surface with smaller size
219     CODECHAL_ENCODE_BUFFER  m_jobQueueHeaderSurfaceForBLcu64;          //!< Job Queue Header buffer surface
220     MOS_SURFACE             m_jobQueueDataSurfaceForBLcu64Cu32;        //!< Job Queue Data Surface for LCU64 CU32
221     MOS_SURFACE             m_jobQueueDataSurfaceForBLcu64;            //!< Job Queue Data Surface for LCU64
222     MOS_SURFACE             m_cuSplitSurface;                          //!< Cu Split Surface
223     MOS_SURFACE             m_mbStatisticsSurface;                     //!< MB statistics surface
224     MOS_SURFACE             m_mbSplitSurface;                          //!< MB split surface
225     MOS_SURFACE             m_residualDataScratchSurfaceForBLcu32;     //!< Residual Data Scratch Surface for LCU 32 B-kernel
226     MOS_SURFACE             m_residualDataScratchSurfaceForBLcu64;     //!< Residual Data Scratch Surface for LCU 64 B-kernel
227     CODECHAL_ENCODE_BUFFER  m_mvAndDistortionSumSurface;               //!< Mv and Distortion summation surface
228     uint32_t                m_totalNumThreadsPerLcu = 0;               //!< Number of threads per LCU
229 
230     uint8_t m_modeCost[14] = {0};                                      //!< Mode Cost
231     CODECHAL_ENCODE_HEVC_WALKINGPATTERN_PARAM m_walkingPatternParam;   //!< WalkingPattern parameter
232 
233     //!
234     //! \brief    Constructor
235     //!
236     CodechalEncHevcStateG10(CodechalHwInterface* hwInterface,
237         CodechalDebugInterface* debugInterface,
238         PCODECHAL_STANDARD_INFO standardInfo);
239 
240     //!
241     //! \brief    Destructor
242     //!
~CodechalEncHevcStateG10()243     ~CodechalEncHevcStateG10() {};
244 
245     // inherited virtual functions
246     MOS_STATUS Initialize(CodechalSetting * settings);
247     MOS_STATUS InitKernelState();
248     uint32_t GetMaxBtCount();
249     MOS_STATUS EncodeKernelFunctions();
250     MOS_STATUS AllocateEncResources();
251     MOS_STATUS AllocateEncResourcesLCU64();
252     MOS_STATUS FreeEncResources();
253     MOS_STATUS AllocatePakResources();
254     MOS_STATUS FreePakResources();
255     MOS_STATUS SetSequenceStructs();
256     MOS_STATUS CalcScaledDimensions();
257     void GetMaxRefFrames(uint8_t& maxNumRef0, uint8_t& maxNumRef1);
258 
259     //!
260     //! \brief    Allocate ME resources
261     //!
262     //! \return   MOS_STATUS
263     //!           MOS_STATUS_SUCCESS if success, else fail reason
264     //!
265     MOS_STATUS AllocateMeResources();
266 
267     //!
268     //! \brief    Free ME resources
269     //!
270     //! \return   MOS_STATUS
271     //!           MOS_STATUS_SUCCESS if success, else fail reason
272     //!
273     MOS_STATUS DestroyMeResources();
274 
275     //!
276     //! \brief    Get encoder kernel header and kernel size
277     //!
278     //! \param    [in] binary
279     //!           Pointer to kernel binary
280     //! \param    [in] operation
281     //!           Enc kernel operation
282     //! \param    [in] krnStateIdx
283     //!           Kernel state index
284     //! \param    [out] krnHeader
285     //!           Pointer to kernel header
286     //! \param    [out] krnSize
287     //!           Pointer to kernel size
288     //!
289     //! \return   MOS_STATUS
290     //!           MOS_STATUS_SUCCESS if success, else fail reason
291     //!
292     static MOS_STATUS GetKernelHeaderAndSize(
293         void                           *binary,
294         EncOperation                   operation,
295         uint32_t                       krnStateIdx,
296         void                           *krnHeader,
297         uint32_t                       *krnSize);
298 
299     //!
300     //! \brief    Get encoder kernel header and kernel size
301     //!
302     //! \param    [in] encOperation
303     //!           Specifies the media function type
304     //! \param    [in] kernelParams
305     //!           Pointer to kernel parameters
306     //! \param    [in] idx
307     //!           MbEnc/BRC kernel index
308     //!
309     //! \return   MOS_STATUS
310     //!           MOS_STATUS_SUCCESS if success, else fail reason
311     //!
312     MOS_STATUS SetKernelParams(
313         EncOperation                    encOperation,
314         PMHW_KERNEL_PARAM               kernelParams,
315         uint32_t                        idx);
316 
317     //!
318     //! \brief    Set Binding table for different kernelsge
319     //!
320     //! \param    [in] encOperation
321     //!           Specifies the media function type
322     //! \param    [in] bindingTable
323     //!           Pointer to the binding table
324     //! \param    [in] idx
325     //!           MbEnc/BRC kernel index
326     //!
327     //! \return   MOS_STATUS
328     //!           MOS_STATUS_SUCCESS if success, else fail reason
329     //!
330     MOS_STATUS SetBindingTable(
331         EncOperation                            encOperation,
332         PCODECHAL_ENCODE_BINDING_TABLE_GENERIC  bindingTable,
333         uint32_t                                idx);
334 
335     //!
336     //! \brief    Send surfaces to the ME kernel
337     //!
338     //! \param    [in]  cmdBuffer
339     //!           Pointer to command buffer
340     //! \param    [in]  hmeLevel
341     //!           Level of HME
342     //! \param    [in]  distType
343     //!           Type of distortion surface
344     //!
345     //! \return   MOS_STATUS
346     //!           MOS_STATUS_SUCCESS if success, else fail reason
347     //!
348     MOS_STATUS SendMeSurfaces(
349         PMOS_COMMAND_BUFFER                 cmdBuffer,
350         HmeLevel                            hmeLevel,
351         HEVC_ME_DIST_TYPE                   distType);
352 
353     //!
354     //! \brief    Generate walking control region
355     //!
356     //! \return   MOS_STATUS
357     //!           MOS_STATUS_SUCCESS if success, else fail reason
358     //!
359     MOS_STATUS GenerateWalkingControlRegion();
360 
361     //!
362     //! \brief    Prepare walker params for custom pattern thread dispatch
363     //!
364     //! \param    [in]  walkerParams
365     //!           Pointer to HW walker params
366     //! \param    [in]  scoreBoard
367     //!           poitner to HW scoreboard
368     //! \param    [in]  walkerCodecParams
369     //!           Input params to program the HW walker
370     //!
371     //! \return   MOS_STATUS
372     //!           MOS_STATUS_SUCCESS if success, else fail reason
373     //!
374     MOS_STATUS GetCustomDispatchPattern(
375         PMHW_WALKER_PARAMS              walkerParams,
376         PMHW_VFE_SCOREBOARD             scoreBoard,
377         PCODECHAL_WALKER_CODEC_PARAMS   walkerCodecParams);
378 
379     //!
380     //! \brief    Prepare the Curbe for ME kernel
381     //!
382     //! \param    [in]  hmeLevel
383     //!           Level of HME
384     //! \param    [in]  distType
385     //!           Type of distortion surface
386     //!
387     //! \return   MOS_STATUS
388     //!           MOS_STATUS_SUCCESS if success, else fail reason
389     //!
390     MOS_STATUS SetCurbeMe(
391         HmeLevel                    hmeLevel,
392         HEVC_ME_DIST_TYPE           distType);
393 
394     //!
395     //! \brief    Check formats supported
396     //!
397     //! \param    [in]  surface
398     //!           Surface used
399     //!
400     //! \return   bool
401     //!
402     bool CheckSupportedFormat(PMOS_SURFACE surface);
403 
404     //!
405     //! \brief    Invoke HME kernel
406     //!
407     //! \param    [in]  hmeLevel
408     //!           Level of HME
409     //! \param    [in]  distType
410     //!           Type of distortion surface
411     //!
412     //! \return   MOS_STATUS
413     //!           MOS_STATUS_SUCCESS if success, else fail reason
414     //!
415     MOS_STATUS EncodeMeKernel(
416         HmeLevel                        hmeLevel,
417         HEVC_ME_DIST_TYPE               distType);
418 
419     //!
420     //! \brief    Initialize kernel state for Scaling and Depth conversion
421     //!
422     //! \return   MOS_STATUS
423     //!           MOS_STATUS_SUCCESS if success, else fail reason
424     //!
425     MOS_STATUS InitKernelStateScalingAndConversion();
426 
427     //!
428     //! \brief    Initialize HME kernel state
429     //!
430     //! \return   MOS_STATUS
431     //!           MOS_STATUS_SUCCESS if success, else fail reason
432     //!
433     MOS_STATUS InitKernelStateMe();
434 
435     //!
436     //! \brief    Initialize MbEnc kernel state
437     //!
438     //! \return   MOS_STATUS
439     //!           MOS_STATUS_SUCCESS if success, else fail reason
440     //!
441     MOS_STATUS InitKernelStateMbEnc();
442 
443     //!
444     //! \brief    Initialize BRC kernel state
445     //!
446     //! \return   MOS_STATUS
447     //!           MOS_STATUS_SUCCESS if success, else fail reason
448     //!
449     MOS_STATUS InitKernelStateBrc();
450 
451     //!
452     //! \brief    Send surfaces to the ScalingAndConversion kernel
453     //!
454     //! \param    [in]  cmdBuffer
455     //!           Pointer to command buffer
456     //! \param    [in]  params
457     //!           Input params for programming the surfaces
458     //! \return   MOS_STATUS
459     //!           MOS_STATUS_SUCCESS if success, else fail reason
460     //!
461     MOS_STATUS SendScalingAndConversionSurfaces(
462         PMOS_COMMAND_BUFFER cmdBuffer, SurfaceParamsDsConv* params);
463 
464     //!
465     //! \brief    Set Curbe for ScalingAndConversion kernel
466     //!
467     //! \param    [in]  params
468     //!           Input curbe params
469     //! \return   MOS_STATUS
470     //!           MOS_STATUS_SUCCESS if success, else fail reason
471     //!
472     MOS_STATUS SetCurbeScalingAndConversion(
473         CodechalEncodeCscDs::CurbeParams* params);
474 
475     //!
476     //! \brief    Invoke Downscaling and Conversion kernel
477     //!
478     //! \param    [in]  params
479     //!           Input params to invoke the kernel
480     //! \return   MOS_STATUS
481     //!           MOS_STATUS_SUCCESS if success, else fail reason
482     //!
483     MOS_STATUS EncodeScalingAndConversionKernel(
484         CodechalEncodeCscDs::KernelParams* params);
485 
486     //!
487     //! \brief    Top level function for Scaling and Conversion
488     //! \details  ScalingAndConversionKernel is called inside this.
489     //!
490     //! \return   MOS_STATUS
491     //!           MOS_STATUS_SUCCESS if success, else fail reason
492     //!
493     MOS_STATUS PerformScalingAndConversion();
494 
495     //!
496     //! \brief    Invoke BRC Init/Reset kernel
497     //!
498     //! \return   MOS_STATUS
499     //!           MOS_STATUS_SUCCESS if success, else fail reason
500     //!
501     MOS_STATUS EncodeBrcInitResetKernel();
502 
503     //!
504     //! \brief    Send surfaces BRC Init/Reset kernel
505     //!
506     //! \param    [in]  cmdBuffer
507     //!           Pointer to command buffer
508     //! \param    [in]  krnIdx
509     //!           Index of the BRC kernel for which surfaces are being sent
510     //! \return   MOS_STATUS
511     //!           MOS_STATUS_SUCCESS if success, else fail reason
512     //!
513     MOS_STATUS SendBrcInitResetSurfaces(
514         PMOS_COMMAND_BUFFER                 cmdBuffer,
515         CODECHAL_HEVC_BRC_KRNIDX            krnIdx);
516 
517     //!
518     //! \brief    Setup Curbe for BRC Init/Reset kernel
519     //!
520     //! \param    [in]  brcKrnIdx
521     //!           Index of the BRC kernel for which Curbe is setup
522     //! \return   MOS_STATUS
523     //!           MOS_STATUS_SUCCESS if success, else fail reason
524     //!
525     MOS_STATUS SetCurbeBrcInitReset(CODECHAL_HEVC_BRC_KRNIDX brcKrnIdx);
526 
527     //!
528     //! \brief    Invoke frame level BRC update kernel
529     //!
530     //! \return   MOS_STATUS
531     //!           MOS_STATUS_SUCCESS if success, else fail reason
532     //!
533     MOS_STATUS EncodeBrcFrameUpdateKernel();
534 
535     //!
536     //! \brief    Send surfaces for BRC Frame Update kernel
537     //!
538     //! \param    [in]  cmdBuffer
539     //!           Pointer to command buffer
540     //! \return   MOS_STATUS
541     //!           MOS_STATUS_SUCCESS if success, else fail reason
542     //!
543     MOS_STATUS SendBrcFrameUpdateSurfaces(PMOS_COMMAND_BUFFER cmdBuffer);
544 
545     //!
546     //! \brief    Setup Curbe for BRC Update kernel
547     //!
548     //! \param    [in]  brcKrnIdx
549     //!           Index of the BRC update kernel(frame or LCU) for which Curbe is setup
550     //! \return   MOS_STATUS
551     //!           MOS_STATUS_SUCCESS if success, else fail reason
552     //!
553     MOS_STATUS SetCurbeBrcUpdate(CODECHAL_HEVC_BRC_KRNIDX brcKrnIdx);
554 
555     //!
556     //! \brief    Invoke LCU level BRC update kernel
557     //!
558     //! \return   MOS_STATUS
559     //!           MOS_STATUS_SUCCESS if success, else fail reason
560     //!
561     MOS_STATUS EncodeBrcLcuUpdateKernel();
562 
563     //!
564     //! \brief    Send surfaces for BRC LCU Update kernel
565     //!
566     //! \param    [in]  cmdBuffer
567     //!           Pointer to command buffer
568     //! \return   MOS_STATUS
569     //!           MOS_STATUS_SUCCESS if success, else fail reason
570     //!
571     MOS_STATUS SendBrcLcuUpdateSurfaces(PMOS_COMMAND_BUFFER cmdBuffer);
572 
573     //!
574     //! \brief    Top level function for invoking MBenc kernel
575     //! \details  I, B or LCU64_B MBEnc kernel, based on encFunctionType
576     //! \param    [in]  encFunctionType
577     //!           Specifies the media state type
578     //! \return   MOS_STATUS
579     //!           MOS_STATUS_SUCCESS if success, else fail reason
580     //!
581     MOS_STATUS EncodeMbEncKernel(CODECHAL_MEDIA_STATE_TYPE encFunctionType);
582 
583     //!
584     //! \brief    Send Surfaces for MbEnc I kernel
585     //!
586     //! \param    [in]  cmdBuffer
587     //!           Pointer to command buffer
588     //!
589     //! \return   MOS_STATUS
590     //!           MOS_STATUS_SUCCESS if success, else fail reason
591     //!
592     MOS_STATUS SendMbEncSurfacesIKernel(PMOS_COMMAND_BUFFER cmdBuffer);
593 
594     //!
595     //! \brief    Setup Curbe for MbEnc I kernel
596     //!
597     //! \return   MOS_STATUS
598     //!           MOS_STATUS_SUCCESS if success, else fail reason
599     //!
600     MOS_STATUS SetCurbeMbEncIKernel();
601 
602     //!
603     //! \brief    Send Surfaces for MbEnc B kernel
604     //!
605     //! \param    [in]  cmdBuffer
606     //!           Pointer to command buffer
607     //!
608     //! \return   MOS_STATUS
609     //!           MOS_STATUS_SUCCESS if success, else fail reason
610     //!
611     MOS_STATUS SendMbEncSurfacesBKernel(PMOS_COMMAND_BUFFER cmdBuffer);
612 
613     //!
614     //! \brief    Setup Curbe for MbEnc B LCU32 and LCU64_32 Kernels
615     //!
616     //! \return   MOS_STATUS
617     //!           MOS_STATUS_SUCCESS if success, else fail reason
618     //!
619     MOS_STATUS SetCurbeMbEncBKernel();
620 
621     //!
622     //! \brief    Generate LCU Level Data
623     //!
624     //! \return   MOS_STATUS
625     //!           MOS_STATUS_SUCCESS if success, else fail reason
626     //!
627     MOS_STATUS GenerateLcuLevelData();
628 
629     //!
630     //! \brief    Load cost table
631     //!
632     //! \param    [in]  sliceType
633     //!           Slice Type
634     //! \param    [in]  qp
635     //!           QP value
636     //! \param    [out]  lambdaMd
637     //!           Intra SAD transform type
638     //! \param    [out]  lambdaRd
639     //!           Intra SAD transform type
640     //! \param    [out]  tuSadThreshold
641     //!           Intra SAD transform type
642     //!
643     //! \return   void
644     //!
645     void LoadCosts(uint8_t sliceType, uint8_t qp, uint16_t *lambdaMd, uint32_t *lambdaRd, uint32_t *tuSadThreshold);
646 
647     //!
648     //! \brief    Setup BRC constant data
649     //!
650     //! \param    [in, out]  brcConstantData
651     //!           Pointer to BRC constant data surface
652     //!
653     //! \return   MOS_STATUS
654     //!           MOS_STATUS_SUCCESS if success, else fail reason
655     //!
656     MOS_STATUS SetupBrcConstantTable(PMOS_SURFACE brcConstantData);
657 
658 };
659 
660 //! \brief  typedef of class CodechalEncHevcStateG10*
661 using PCODECHAL_ENC_HEVC_STATE_G10 = class CodechalEncHevcStateG10*;
662 
663 #endif  // __CODECHAL_ENCODE_HEVC_G10_H__
664