xref: /aosp_15_r20/external/intel-media-driver/media_driver/agnostic/gen8/codec/hal/codechal_fei_avc_g8.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2011-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_fei_avc_g8.h
24 //! \brief    This file defines the C++ class/interface for Gen8 platform's AVC
25 //!           FEI encoding to be used across CODECHAL components.
26 //!
27 
28 #ifndef __CODECHAL_FEI_AVC_G8_H__
29 #define __CODECHAL_FEI_AVC_G8_H__
30 
31 #include "codechal_encode_avc_g8.h"
32 
33 class CodechalEncodeAvcEncFeiG8 : public CodechalEncodeAvcEncG8
34 {
35 public:
36     static const uint32_t m_feiMBEncCurbeSizeInDword = 95;
37 
38     static const uint32_t m_modeMvCost_Cm_PreProc[3][CODEC_AVC_NUM_QP][8];
39     static const uint32_t m_meCurbeCmFei[39];
40     static const uint32_t m_preProcCurbeCmNormalIFrame[49];
41     static const uint32_t m_preProcCurbeCmNormalIfield[49];
42     static const uint32_t m_preProcCurbeCmNormalPFrame[49];
43     static const uint32_t m_preProcCurbeCmNormalPField[49];
44     static const uint32_t m_preProcCurbeCmNormalBFrame[49];
45     static const uint32_t m_preProcCurbeCmNormalBField[49];
46     static const uint32_t m_feiMbEncCurbeNormalIFrame[m_feiMBEncCurbeSizeInDword];
47     static const uint32_t m_feiMbEncCurbeNormalIField[m_feiMBEncCurbeSizeInDword];
48     static const uint32_t m_feiMbEncCurbeNormalPFrame[m_feiMBEncCurbeSizeInDword];
49     static const uint32_t m_feiMbEncCurbeNormalPfield[m_feiMBEncCurbeSizeInDword];
50     static const uint32_t m_feiMbEncCurbeNormalBFrame[m_feiMBEncCurbeSizeInDword];
51     static const uint32_t m_feiMbEncCurbeNormalBField[m_feiMBEncCurbeSizeInDword];
52     static const uint32_t m_feiMbEncCurbeIFrameDist[m_feiMBEncCurbeSizeInDword];
53 
54     static const uint32_t m_mbencNumTargetUsagesCmFei = 1;
55     static const uint32_t m_feiMeCurbeDataSize = 128;
56     static const uint32_t m_feiMBEncCurbeDataSizeExcludeSurfaceIdx = 236;
57     static const uint32_t m_feiPreProcCurbeDataSize = 160;
58 
59 #ifdef FEI_ENABLE_CMRT
60     static const uint32_t m_mdfDsBufSize = 2;           //ds use 2 buffer & 4 surface for each channel,  6 buffer and 12 totally
61     static const uint32_t m_mdfDsSurfSize = 4;
62     static const uint32_t m_mdfDsVmeSurfSize = 0;
63 
64     static const uint32_t m_mdfMeBufSize = 0;           //me use 0 buffer and 12 surface
65     static const uint32_t m_mdfMeSurfSize = 12;
66     static const uint32_t m_mdfMeVmeSurfSize = 2;
67 
68     static const uint32_t m_mdfPreProcBufSize = 6;           //preproc use 5 buffers and  4 surface
69     static const uint32_t m_mdfPreProcSurfSize  = 4;
70     static const uint32_t m_mdfPreProcVmeSurfSize = 2;
71 
72     static const uint32_t m_mdfMbencBufSize = 12;           //MBEnc is not in a context with preenc
73     static const uint32_t m_mdfMbencSurfSize = 16;
74     static const uint32_t m_mdfMbencVmeSurfSize = 2;
75 
76     CodechalEncodeMdfKernelResource m_resMBEncKernel;
77     CodechalEncodeMdfKernelResource m_resPreProcKernel;
78     CodechalEncodeMdfKernelResource m_resMEKernel;
79     void                               *m_avcCmSurfIdx;
80     uint32_t                            m_dsKernelIdx;
81 #endif
82     //!
83     //! \brief    Constructor
84     //!
85     CodechalEncodeAvcEncFeiG8(
86         CodechalHwInterface *   hwInterface,
87         CodechalDebugInterface *debugInterface,
88         PCODECHAL_STANDARD_INFO standardInfo);
89 
90     ~CodechalEncodeAvcEncFeiG8();
91 
92     void UpdateSSDSliceCount();
93 
94     //!
95     //! \brief    Initializes the kernel.
96     //! \details
97     //!
98     //! \return   MOS_STATUS
99     //!           MOS_STATUS_SUCCESS if success
100     //!
101     MOS_STATUS InitializePicture(const EncoderParams& params);
102 
103     //!
104     //! \brief    Initializes the FEI PreEnc kernel.
105     //! \details  If PreEnc mode, initial PreEnc kernel.
106     //!
107     //! \return   MOS_STATUS
108     //!           MOS_STATUS_SUCCESS if success
109     //!
110     MOS_STATUS EncodePreEncInitialize(const EncoderParams& params);
111 
112     //!
113     //! \brief    Encode kernel functions
114     //!
115     //! \return   MOS_STATUS
116     //!           MOS_STATUS_SUCCESS if success, else fail reason
117     //!
118     MOS_STATUS ExecuteKernelFunctions();
119 
120     //!
121     //! \brief    Init ME kernel state
122     //!
123     //! \return   MOS_STATUS
124     //!           MOS_STATUS_SUCCESS if success, else fail reason
125     //!
126     MOS_STATUS InitKernelStateMe();
127 #ifdef FEI_ENABLE_CMRT
128         // EncodeMeKernel functions
129         //!
130         //! \brief    Run Encode ME kernel
131         //!
132         //! \param [in] brcBuffers
133         //!           Pointer to the brc buffer
134         //! \param   [in] hmeLevel
135         //!           Hme level
136         //! \return   MOS_STATUS
137         //!           MOS_STATUS_SUCCESS if success
138         //!
139         virtual MOS_STATUS EncodeMeKernel(
140             PCODECHAL_ENCODE_BRC_BUFFERS brcBuffers,
141             CODECHAL_ENCODE_HME_LEVEL hmeLevel);
142 
143         //!
144         //! \brief    Dispatch MDF Encode ME kernel
145         //!
146         //! \param [in] surfIdxArray
147         //!            Pointer to the SurfaceIndex * list which is used to Surfaces
148         //! \param [in] width
149         //!            input picture width
150         //!\param  [in]  height
151         //!            input picture height
152         //!\param  [in]   isBFrame
153         //!           if input picture is B frame
154         //! \return   MOS_STATUS
155         //!           MOS_STATUS_SUCCESS if success
156         //!
157 
158         MOS_STATUS DispatchKernelMe(
159             SurfaceIndex** surfIdxArray,
160             uint16_t width,
161             uint16_t height,
162             bool isBFrame);
163 
164         //!
165         //! \brief    Dispatch MDF Encode MBEnc kernel
166         //!
167         //! \param  [in]  params
168         //!           Dispatch Parameters
169         //! \return   MOS_STATUS
170         //!           MOSs_STATUS_SUCCESS if success
171         //!
172 
173         MOS_STATUS DispatchKernelMbEnc(
174             void      *params);
175 
176         //!
177         //! \brief    Dispatch MDF FEI preproc
178         //!
179         //! \param  [in] surfIndexArray
180         //!           Pointer to the SurfaceIndex * list which is used to Surfaces
181         //! \param  [in] width
182         //!           input picture width
183         //!\param   [in] height
184         //!           input picture height
185         //! \return   MOS_STATUS
186         //!           MOS_STATUS_SUCCESS if success
187         //!
188 
189         MOS_STATUS DispatchKernelPreProc(
190             SurfaceIndex**  surfIndexArray,
191             uint16_t            width,
192             uint16_t            height);
193 
194         //!
195         //! \brief    MBEnc Encode kernel functions
196         //!
197         //! \return   MOS_STATUS
198         //!           MOS_STATUS_SUCCESS if success, else fail reason
199         //!
200         MOS_STATUS EncodeMbEncKernelFunctions();
201 
202         //!
203         //! \brief    Init Scaling kernel state
204         //!
205         //! \return   MOS_STATUS
206         //!           MOS_STATUS_SUCCESS if success, else fail reason
207         //!
208 
209         static MOS_STATUS InitKernelStateScaling(PCODECHAL_ENCODER avcEncoder);
210 
211         //!
212         //! \brief    Dispatch MDF FEI 4x DownScalling
213         //! \param  [in]  flatnessThreshold
214         //!           flatness threshold
215         //! \param [in]  options
216         //!           down scaling option
217         //!             bit0 enable/disable flatness check
218         //!             bit1 enable/disable variance output
219         //!             bit2 enable/disable average output
220         //!             bit3 eanble/disable 8x8 statistics output
221         //! \param  [in]  sourceWidth
222         //!           input picture width
223         //!\param   [in]  sourceHeight
224         //!           input sourceHeight
225         //!\param   [in] kernelType
226         //!           if input picture frame (0) or field (1)
227         //!\param   [in]  surfIdxArray
228         //!           Pointer to the SurfaceIndex * Array which is used to Surfaces
229         //! \return   MOS_STATUS
230         //!           MOS_STATUS_SUCCESS if success
231         //!
232         MOS_STATUS DispatchKernelScaling(
233             uint32_t flatnessThreshold,
234             uint32_t options,
235             uint16_t sourceWidth,
236             uint16_t sourceHeight,
237             uint32_t kernelType,
238             SurfaceIndex** surfIdxArray);
239 
240         //!
241         //! \brief    MBEnc Encode kernel functions
242         //!
243         //! \param [in]  params
244         //!           downscalling parameters
245         //!
246         //! \return   MOS_STATUS
247         //!           MOS_STATUS_SUCCESS if success, else fail reason
248         //!
249 
250         MOS_STATUS EncodeScalingKernel(PCODECHAL_ENCODE_CSC_SCALING_KERNEL_PARAMS params);
251 
252 #endif
253         //!
254         //! \brief    Set AVC ME kernel curbe
255         //!
256         //! \param    [in] params
257         //!           Pointer to the CODECHAL_ME_CURBE_PARAMS
258         //! \return   MOS_STATUS
259         //!           MOS_STATUS_SUCCESS if success, else fail reason
260         //!
261         virtual MOS_STATUS SetCurbeMe (MeCurbeParams* params);
262 
263     //!
264     //! \brief    Send surface cmd to AVC ME kernel.
265     //!
266     //! \return   MOS_STATUS
267     //!           MOS_STATUS_SUCCESS if success, else fail reason
268     //!
269     virtual MOS_STATUS SendMeSurfaces (
270         PMOS_COMMAND_BUFFER cmdBuffer,
271         MeSurfaceParams* params);
272 
273     //!
274     //! \brief    Get encoder kernel header and kernel size
275     //!
276     //! \param    [in] binary
277     //!           Pointer to kernel binary
278     //! \param    [in] operation
279     //!           Enc kernel operation
280     //! \param    [in] krnStateIdx
281     //!           Kernel state index
282     //! \param    [out] krnHeader
283     //!           Pointer to kernel header
284     //! \param    [out] krnSize
285     //!           Pointer to kernel size
286     //!
287     //! \return   MOS_STATUS
288     //!           MOS_STATUS_SUCCESS if success, else fail reason
289     //!
290     static MOS_STATUS EncodeGetKernelHeaderAndSize(
291         void                           *binary,
292         EncOperation                   operation,
293         uint32_t                       krnStateIdx,
294         void                           *krnHeader,
295         uint32_t                       *krnSize);
296 
297     //!
298     //! \brief    PreEnc Encode kernel functions
299     //!
300     //! \return   MOS_STATUS
301     //!           MOS_STATUS_SUCCESS if success, else fail reason
302     //!
303     MOS_STATUS EncodePreEncKernelFunctions();
304 
305     // state related functions
306     //!
307     //! \brief    Initialize related states
308     //!
309     //! \return   MOS_STATUS
310     //!           MOS_STATUS_SUCCESS if success, else fail reason
311     //!
312     virtual MOS_STATUS InitializeState();
313 
314     //!
315     //! \brief    Validate reference list L0 and L1.
316     //!
317     //! \param    [in] params
318     //!           pointer to CODECHAL_ENCODE_AVC_VALIDATE_NUM_REFS_PARAMS
319     //!
320     //! \return   MOS_STATUS
321     //!           MOS_STATUS_SUCCESS if success, else fail reason
322     //!
323     virtual MOS_STATUS ValidateNumReferences(
324         PCODECHAL_ENCODE_AVC_VALIDATE_NUM_REFS_PARAMS params);
325 
326     //!
327     //! \brief    Init MbEnc kernel State.
328     //!
329     //! \return   MOS_STATUS
330     //!           MOS_STATUS_SUCCESS if success, else fail reason
331     //!
332     virtual MOS_STATUS InitKernelStateMbEnc();
333 
334     //!
335     //! \brief    Initialize PreProc kernel state
336     //!
337     //! \return   MOS_STATUS
338     //!           MOS_STATUS_SUCCESS if success, else fail reason
339     //!
340     virtual MOS_STATUS InitKernelStatePreProc();
341 
342     //!
343     //! \brief    Initialize WP kernel state
344     //!
345     //! \return   MOS_STATUS
346     //!           MOS_STATUS_SUCCESS if success, else fail reason
347     //!
348     virtual MOS_STATUS InitKernelStateWP();
349 
350     //!
351     //! \brief    Get MbEnc kernel state idx
352     //!
353     //! \param    [in] params
354     //!           Pointer to the CodechalEncodeIdOffsetParams
355     //! \param    [in] kernelOffset
356     //!           kernel offset
357     //!
358     //! \return   MOS_STATUS
359     //!           MOS_STATUS_SUCCESS if success, else fail reason
360     //!
361     virtual MOS_STATUS GetMbEncKernelStateIdx(
362         CodechalEncodeIdOffsetParams       *params,
363         uint32_t                           *kernelOffset);
364 
365     //!
366     //! \brief    Set AVC MbEnc kernel Curbe data.
367     //!
368     //! \param    [in] params
369     //!           Pointer to the CODECHAL_ENCODE_AVC_MBENC_CURBE_PARAMS
370     //!
371     //! \return   MOS_STATUS
372     //!           MOS_STATUS_SUCCESS if success, else fail reason
373     //!
374     virtual MOS_STATUS SetCurbeAvcMbEnc(
375         PCODECHAL_ENCODE_AVC_MBENC_CURBE_PARAMS params);
376 
377     //!
378     //! \brief    Set AVC PreProc kernel Curbe data.
379     //!
380     //! \param    [in] params
381     //!           Pointer to the CODECHAL_ENCODE_AVC_PREPROC_CURBE_PARAMS
382     //!
383     //! \return   MOS_STATUS
384     //!           MOS_STATUS_SUCCESS if success, else fail reason
385     //!
386     virtual MOS_STATUS SetCurbeAvcPreProc(
387         PCODECHAL_ENCODE_AVC_PREPROC_CURBE_PARAMS params);
388 
389     //!
390     //! \brief    Set AVC MbEnc kernel Surface data.
391     //!
392     //! \param    [in] cmdBuffer
393     //!           Pointer to the MOS_COMMAND_BUFFER
394     //! \param    [in] params
395     //!           Pointer to the CODECHAL_ENCODE_AVC_MBENC_SURFACE_PARAMS
396     //!
397     //! \return   MOS_STATUS
398     //!           MOS_STATUS_SUCCESS if success, else fail reason
399     //!
400     virtual MOS_STATUS SendAvcMbEncSurfaces(
401         PMOS_COMMAND_BUFFER cmdBuffer,
402         PCODECHAL_ENCODE_AVC_MBENC_SURFACE_PARAMS params);
403 
404     //!
405     //! \brief    Set AVC PreProc kernel Surface data.
406     //!
407     //! \param    [in] cmdBuffer
408     //!           Pointer to the MOS_COMMAND_BUFFER
409     //! \param    [in]  params
410     //!           Pointer to the CODECHAL_ENCODE_AVC_PREPROC_SURFACE_PARAMS
411     //!
412     //! \return   MOS_STATUS
413     //!           MOS_STATUS_SUCCESS if success, else fail reason
414     //!
415     virtual MOS_STATUS SendAvcPreProcSurfaces(
416         PMOS_COMMAND_BUFFER cmdBuffer,
417         PCODECHAL_ENCODE_AVC_PREPROC_SURFACE_PARAMS params);
418 
419     //!
420     //! \brief    Invoke FEI PreProc kernel.
421     //!
422     //! \return   MOS_STATUS
423     //!           MOS_STATUS_SUCCESS if success, else fail reason
424     //!
425     MOS_STATUS PreProcKernel();
426 };
427 
428 using PCodechalEncodeAvcEncFeiG8 = CodechalEncodeAvcEncFeiG8*;
429 #endif  // __CODECHAL_FEI_AVC_G8_H__
430