1 /*
2 * Copyright (c) 2017-2019, 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_kernel_intra_dist_mdf.h
24 //! \brief    Defines the intra distortion kernel implementation using MDF
25 //! \details  Intra distortion base includes all common functions and definitions for intra distortion
26 //!
27 #ifndef __CODECHAL_KERNEL_INTRA_DIST_MDF_G12_H__
28 #define __CODECHAL_KERNEL_INTRA_DIST_MDF_G12_H__
29 #include "codechal_kernel_base.h"
30 
31 //!
32 //! \class    CodechalKernelIntraDist
33 //! \brief    Codechal kernel intra dist
34 //!
35 class CodechalKernelIntraDistMdfG12 : public CodechalKernelBase
36 {
37 public:
38     //!
39     //! \enum     KernelIndex
40     //! \brief    Kernel index
41     //!
42     enum KernelIndex
43     {
44         intraDistortion = 0
45     };
46 
47     //!
48     //! \enum     BindingTableOffset
49     //! \brief    Binding table offset
50     //!
51     enum BindingTableOffset
52     {
53         intraDistCurrent4xY   = 0,
54         intraDistOutputSurf   = 1,
55         intraDistVmeIntraPred = 2,
56         intraDistSurfaceNum   = 3
57     };
58 
59     //!
60     //! \class    CurbeParam
61     //! \brief    Curbe parameter
62     //!
63     struct CurbeParam
64     {
65         uint32_t downScaledWidthInMb4x = 0;
66         uint32_t downScaledHeightInMb4x = 0;
67     };
68 
69     //!
70     //! \class    SurfaceParams
71     //! \brief    Surface parameters
72     //!
73     struct SurfaceParams
74     {
75         uint32_t     intraDistBottomFieldOffset = 0;
76         PMOS_SURFACE input4xDsSurface = nullptr;
77         CmSurface2D* intraDistSurface = nullptr;
78     };
79 
80     // clang-format off
81     //!
82     //! \class    Curbe
83     //! \brief    Curbe
84     //!
85     class Curbe
86     {
87     public:
Curbe()88         Curbe()
89         {
90             memset(&m_data, 0, sizeof(CurbeData));
91             m_data.DW1.interSAD = 2;
92             m_data.DW1.intraSAD = 2;
93         }
94         //!
95         //! \struct    CurbeData
96         //! \brief     Curbe data
97         //!
98         struct CurbeData
99         {
100             //DW0
101             union
102             {
103                 struct
104                 {
105                     uint32_t picWidthInLumaSamples  : MOS_BITFIELD_RANGE(0, 15);
106                     uint32_t picHeightInLumaSamples : MOS_BITFIELD_RANGE(16, 31);
107                 };
108                 uint32_t value;
109             } DW0;
110 
111             //DW1
112             union
113             {
114                 struct
115                 {
116                     uint32_t srcSize              : MOS_BITFIELD_RANGE(0, 1);
117                     uint32_t reserved2            : MOS_BITFIELD_RANGE(2, 13);
118                     uint32_t skipType             : MOS_BITFIELD_BIT(14);
119                     uint32_t reserved15           : MOS_BITFIELD_BIT(15);
120                     uint32_t intraChromaMode      : MOS_BITFIELD_BIT(16);
121                     uint32_t ftSkipCheckEnable    : MOS_BITFIELD_BIT(17);
122                     uint32_t reserved18           : MOS_BITFIELD_BIT(18);
123                     uint32_t blockBasedSkipEnable : MOS_BITFIELD_BIT(19);
124                     uint32_t interSAD             : MOS_BITFIELD_RANGE(20, 21);
125                     uint32_t intraSAD             : MOS_BITFIELD_RANGE(22, 23);
126                     uint32_t reserved24           : MOS_BITFIELD_RANGE(24, 31);
127                 };
128                 uint32_t value;
129             } DW1;
130 
131             //DW2
132             union
133             {
134                 struct
135                 {
136                     uint32_t intraPartMask     : MOS_BITFIELD_RANGE(0, 4);
137                     uint32_t nonSkipZmvAdded   : MOS_BITFIELD_BIT(5);
138                     uint32_t nonSkipModeAdded  : MOS_BITFIELD_BIT(6);
139                     uint32_t intraCornerSwap   : MOS_BITFIELD_BIT(7);
140                     uint32_t reserved8         : MOS_BITFIELD_RANGE(8, 15);
141                     uint32_t mvCostScaleFactor : MOS_BITFIELD_RANGE(16, 17);
142                     uint32_t bilinearEnable    : MOS_BITFIELD_BIT(18);
143                     uint32_t reserved19        : MOS_BITFIELD_BIT(19);
144                     uint32_t weightedSADHaar   : MOS_BITFIELD_BIT(20);
145                     uint32_t acOnlyHaar        : MOS_BITFIELD_BIT(21);
146                     uint32_t refIDCostMode     : MOS_BITFIELD_BIT(22);
147                     uint32_t reserved23        : MOS_BITFIELD_BIT(23);
148                     uint32_t skipCenterMask    : MOS_BITFIELD_RANGE(24, 31);
149                 };
150                 uint32_t value;
151             } DW2;
152 
153             //DW3
154             union
155             {
156                 struct
157                 {
158                     uint32_t reserved;
159                 };
160                 uint32_t value;
161             } DW3;
162 
163             //DW4
164             union
165             {
166                 struct
167                 {
168                     uint32_t reserved;
169                 };
170                 uint32_t value;
171             } DW4;
172 
173             //DW5
174             union
175             {
176                 struct
177                 {
178                     uint32_t reserved;
179                 };
180                 uint32_t value;
181             } DW5;
182 
183             //DW6
184             union
185             {
186                 struct
187                 {
188                     uint32_t reserved;
189                 };
190                 uint32_t value;
191             } DW6;
192 
193             //DW7
194             union
195             {
196                 struct
197                 {
198                     uint32_t reserved;
199                 };
200                 uint32_t value;
201             } DW7;
202 
203         } m_data;
204         static const uint32_t m_curbeSize = sizeof(CurbeData);
205     };
206     // clang-format on
207 
208     CodechalKernelIntraDistMdfG12(CodechalEncoderState *encoder);
209 
210     virtual ~CodechalKernelIntraDistMdfG12();
211 
212     //!
213     //! \brief  InitializeKernelIsa
214     //!
215     //! \param  [in] kernelIsa
216     //!         pointer to the kernel isa
217     //! \param  [in] kernelIsasize
218     //!     Load the kernel
219     //! \return MOS_STATUS
220     //!         MOS_STATUS_SUCCESS if success
221     //!
222     virtual MOS_STATUS InitializeKernelIsa(void *kernelIsa, uint32_t kernelIsasize);
223 
224     //!
225     //! \brief  Execute Intra Distortion kernel
226     //!
227     //! \param  [in] curbeParam
228     //!         Reference to CodechalKernelIntraDistMdf::CurbeParam
229     //! \param  [in] surfaceParam
230     //!         Reference to CodechalKernelIntraDistMdf::SurfaceParams
231     //!
232     //! \return MOS_STATUS
233     //!         MOS_STATUS_SUCCESS if success
234     //!
235     virtual MOS_STATUS Execute(CurbeParam &curbeParam, SurfaceParams &surfaceParam);
236 
GetBTCount()237     uint32_t GetBTCount() { return BindingTableOffset::intraDistSurfaceNum; }
238 
239 protected:
240     MOS_STATUS AllocateResources();
241     MOS_STATUS ReleaseResources();
242 
GetCurbeSize()243     virtual uint32_t   GetCurbeSize() { return Curbe::m_curbeSize; }
244     virtual MOS_STATUS SetCurbe(MHW_KERNEL_STATE *kernelState);
245     virtual MOS_STATUS SendSurfaces(PMOS_COMMAND_BUFFER cmd, MHW_KERNEL_STATE *kernelState);
246     virtual MOS_STATUS AddPerfTag();
247     virtual MHW_KERNEL_STATE *GetActiveKernelState();
248     virtual MOS_STATUS InitWalkerCodecParams(CODECHAL_WALKER_CODEC_PARAMS &walkerParam);
249     virtual CODECHAL_MEDIA_STATE_TYPE GetMediaStateType();
250 
251     CurbeParam    m_curbeParam;    //!< curbe paramters
252     SurfaceParams m_surfaceParam;  //! surface parameters
253 
254     CmThreadSpace   *m_threadSpace = nullptr;
255     CmKernel        *m_cmKrn       = nullptr;
256     CmProgram       *m_cmProgram   = nullptr;
257     CmSurface2D     *m_src4xSurface = nullptr;
258     SurfaceIndex    *m_vmeIdx = nullptr;
259 
260 protected:
261 
262         //!
263         //! \brief  Set the Curbe parameters such that it can be passed as kernel argument
264         //!
265         MOS_STATUS SetIntraDistCurbe(Curbe&  curbe);
266 
267         MOS_STATUS SetupSurfaces();
268 
269         MOS_STATUS SetupKernelArgs();
270 };
271 
272 #endif /* __CODECHAL_KERNEL_INTRA_DIST_H__ */
273