1 /*
2 * Copyright (c) 2018-2022, 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     vphal_render_16alignment.h
24 //! \brief    Common interface and structure used in 16align
25 //! \details  Common interface and structure used in 16align
26 //!
27 #ifndef __VPHAL_RENDER_16ALIGNMENT_H__
28 #define __VPHAL_RENDER_16ALIGNMENT_H__
29 
30 #include "mos_os.h"
31 #include "renderhal_legacy.h"
32 #include "vphal_render_common.h"
33 
34 // Static Data for Gen9 16ALIGN kernel
35 typedef struct _MEDIA_WALKER_16ALIGN_STATIC_DATA
36 {
37     // DWORD 0 - GRF R1.0
38     union
39     {
40         uint32_t       Sampler_Index;
41     } DW0;
42 
43     // DWORD 1 - GRF R1.1
44     union
45     {
46         uint32_t       pSrcSurface;          // Input - YUY2/ARGB
47         uint32_t       pSrcSurface_Y;        // Input - Y Channel for NV12/YV12
48     } DW1;
49 
50     // DWORD 2 - GRF R1.2
51     union
52     {
53         uint32_t        pSrcSurface_UV;       // Input - UV Channel for NV12
54         uint32_t        pSrcSurface_U;        // Input - U Channel for YV12
55     } DW2;
56 
57     // DWORD 3 - GRF R1.3
58     union
59     {
60         uint32_t        pSrcSurface_V;        // Input - V Channel for YV12
61     } DW3;
62 
63     // DWORD 4 - GRF R1.4
64     union
65     {
66         uint32_t        pOutSurface;          // Output - Buffer YUY2, size need to be 16 bytes alignment.
67         uint32_t        pOutSurface_Y;        // Output - Buffer NV12/YV12, size need to be 32 bytes alignment
68     } DW4;
69 
70     // DWORD 5 - GRF R1.5
71     union
72     {
73         uint32_t        pOutSurface_UV;       // Output - Buffer NV12, size need to be 16 bytes alignment.
74         uint32_t        pOutSurface_U;        // Output - Buffer YV12, size need to be 16 bytes alignment.
75     } DW5;
76 
77     // DWORD 6 - GRF R1.6
78     union
79     {
80         uint32_t        pOutSurface_V;        // Output - Buffer YV12, size need to be 16 bytes alignment.
81     } DW6;
82 
83     // DWORD 7 - GRF R1.7
84     union
85     {
86         float           ScalingStep_H;       // Scaling ratio in Horizontal direction.
87     } DW7;
88 
89     // DWORD 8 - GRF R2.0
90     union
91     {
92         float           ScalingStep_V;       // Scaling ratio in Vertical direction.
93     } DW8;
94 
95     // DWORD 9 - GRF R2.1
96     union
97     {
98         struct {
99             uint32_t       Input_Format    : 16;  // 0 NV12, 1 YUY2, 2 YV12, 3 argb
100             uint32_t       Output_Format   : 16;  // 0 NV12, 1 YUY2, 2 YV12
101         };
102     } DW9;
103 
104     // DWORD 10 - GRF R2.2
105     union
106     {
107         struct {
108             uint32_t       Output_Pitch    : 16;  // Pitch of Output surface (Map to 2D)
109             uint32_t       Output_Height   : 16;  // the Height of output surface
110         };
111     } DW10;
112 
113     // DWORD 11 - GRF R2.3
114     union
115     {
116         uint32_t        ScalingMode;              // 0 for 3D(bilinear, Nearest), 1 for AVS
117     } DW11;
118 
119     // DWORD 12 - GRF R2.4
120     union
121     {
122         float           Original_X;
123     } DW12;
124 
125     // DWORD 13 - GRG R2.5
126     union
127     {
128         float           Original_Y;
129     } DW13;
130 
131     // DWORD 14 - GRG R2.6
132     union
133     {
134         uint32_t        reserved;
135     } DW14;
136 
137     // DWORD 15 - GRG R2.7
138     union
139     {
140         uint32_t        reserved;
141     } DW15;
142 
143     // DWORD 16 - GRG R3.0
144     union
145     {
146         struct {
147             uint32_t       CSC_COEFF_0    : 16;
148             uint32_t       CSC_COEFF_1    : 16;
149         };
150     } DW16;
151 
152     // DWORD 17 - GRG R3.1
153     union
154     {
155         struct {
156             uint32_t       CSC_COEFF_2   : 16;
157             uint32_t       CSC_COEFF_3   : 16;
158         };
159     } DW17;
160 
161     // DWORD 18 - GRG R3.2
162     union
163     {
164         struct {
165             uint32_t       CSC_COEFF_4   : 16;
166             uint32_t       CSC_COEFF_5   : 16;
167         };
168     } DW18;
169 
170     // DWORD 19 - GRG R3.3
171     union
172     {
173         struct {
174             uint32_t       CSC_COEFF_6   : 16;
175             uint32_t       CSC_COEFF_7   : 16;
176         };
177     } DW19;
178 
179     // DWORD 20 - GRG R3.4
180     union
181     {
182         struct {
183             uint32_t       CSC_COEFF_8   : 16;
184             uint32_t       CSC_COEFF_9   : 16;
185         };
186     } DW20;
187 
188     // DWORD 21 - GRG R3.5
189     union
190     {
191         struct {
192             uint32_t       CSC_COEFF_10   : 16;
193             uint32_t       CSC_COEFF_11   : 16;
194         };
195     } DW21;
196 
197     // DWORD 22 - GRG R3.6
198     union
199     {
200         struct {
201             uint32_t       OutputMode     :  1;   // 0 UsrPtr, 1: VA
202             uint32_t       reserved       : 15;
203             uint32_t       Output_Top     : 16;   // output cropping Top
204         };
205     } DW22;
206 
207     // DWORD 23 - GRG R3.7
208     union
209     {
210         struct {
211             uint32_t       Output_Bottom  : 16;   // output cropping Bottom
212             uint32_t       Output_Left    : 16;   // output cropping left
213         };
214     } DW23;
215 
216     // DWORD 24 - GRG R4.0
217     union
218     {
219         struct {
220             uint32_t       Output_Right   : 16;    // output cropping right
221             uint32_t       bClearFlag     : 1;     // 0 don't clear out of cropped area, 1 Clear unavaliable area
222             uint32_t       reserved       : 15;
223         };
224     } DW24;
225 }MEDIA_WALKER_16ALIGN_STATIC_DATA, * PMEDIA_WALKER_16ALIGN_STATIC_DATA;
226 
227 //!
228 //! \brief VPHAL 16 Bytes Alignment render data
229 //!
230 typedef struct _VPHAL_16_ALIGN_RENDER_DATA
231 {
232     int32_t                             iBlocksX;
233     int32_t                             iBlocksY;
234     int32_t                             iBindingTable;
235     int32_t                             iMediaID;
236     PRENDERHAL_MEDIA_STATE              pMediaState;
237     float                               ScalingRatio_H;
238     float                               ScalingRatio_V;
239     // Kernel Information
240     PRENDERHAL_KERNEL_PARAM             pKernelParam;
241     Kdll_CacheEntry                     KernelEntry;
242     int32_t                             iCurbeLength;
243     int32_t                             iInlineLength;
244     uint32_t                            dwSurfStateWd;       //!< Surface Height as programmed in SS
245     uint32_t                            dwSurfStateHt;       //!< Surface Height as programmed in SS
246 
247     MHW_SAMPLER_STATE_PARAM             SamplerStateParams;           //!< Sampler State
248     PMHW_AVS_PARAMS                     pAVSParameters;               //!< AVS parameters
249     MHW_SAMPLER_AVS_TABLE_PARAM         mhwSamplerAvsTableParam;      //!< params for AVS scaling 8x8 table
250 
251     // Perf
252     VPHAL_PERFTAG                       PerfTag;
253 
254     // Debug parameters
255     // Kernel Used for current rendering
256     char*                               pKernelName;
257 } VPHAL_16_ALIGN_RENDER_DATA, *PVPHAL_16_ALIGN_RENDER_DATA;
258 
259 //!
260 //! \brief VPHAL 16 Bytes Alignment render state
261 //!
262 typedef struct _VPHAL_16_ALIGN_STATE *PVPHAL_16_ALIGN_STATE;
263 typedef struct _VPHAL_16_ALIGN_STATE
264 {
265     // External components and tables
266     PMOS_INTERFACE                  pOsInterface;
267     PRENDERHAL_INTERFACE            pRenderHal;
268     Kdll_State                      *pKernelDllState;
269     MEDIA_FEATURE_TABLE             *pSkuTable;
270     MEDIA_WA_TABLE                  *pWaTable;
271     bool                            bFtrMediaWalker;
272     MHW_AVS_PARAMS                  AVSParameters;                  //!< AVS for configure Sampler
273     MHW_SAMPLER_AVS_TABLE_PARAM     mhwSamplerAvsTableParam;
274     // Input and output surfaces
275     PVPHAL_SURFACE                  pSource;
276     PVPHAL_SURFACE                  pTarget;
277     RENDERHAL_SURFACE               RenderHalSource; // source for mhw
278     RENDERHAL_SURFACE               RenderHalTarget; // target for mhw
279 
280     // Internal parameters
281     // iBindingTableID: Binding table ID
282     // SurfMemObjCtl:   Cache attributes for sampled surface and target surface
283     int32_t                         iBindingTableID;
284     VPHAL_16_ALIGN_CACHE_CNTL       SurfMemObjCtl;
285 
286     // Platform dependent states
287     PRENDERHAL_KERNEL_PARAM         pKernelParamTable;
288 
289     // Null rendering flag for 16 Bytes Alignment function
290     bool                            bNullHwRender16Align;
291 
292     // Feature reporting
293     VphalFeatureReport              Reporting;
294 
295     // Performance Related item
296     PVPHAL_RNDR_PERF_DATA           pPerfData;
297 
298     // Status table, Vide Pre-Processing Only
299     STATUS_TABLE_UPDATE_PARAMS      StatusTableUpdateParams;
300 
301     // Interface Functions
302     MOS_STATUS (* pfnInitialize) (
303         PVPHAL_16_ALIGN_STATE        p16AlignState,
304         const VphalSettings          *pSettings,
305         Kdll_State                   *pKernelDllState);
306 
307     MOS_STATUS (* pfnDestroy) (
308         PVPHAL_16_ALIGN_STATE         p16AlignState);
309 
310     MOS_STATUS (* pfnRender) (
311         PVPHAL_16_ALIGN_STATE         p16AlignState,
312         PVPHAL_RENDER_PARAMS          pRenderParams);
313 
314     MOS_STATUS (* pfnSetupSurfaceStates) (
315         PVPHAL_16_ALIGN_STATE         p16AlignState,
316         PVPHAL_16_ALIGN_RENDER_DATA   pRenderData);
317 
318     MOS_STATUS (* pfnLoadStaticData) (
319         PVPHAL_16_ALIGN_STATE         p16AlignState,
320         PVPHAL_16_ALIGN_RENDER_DATA   pRenderData,
321         int32_t                       *piCurbeOffset);
322 
323     MOS_STATUS (* pfnSetupKernel) (
324         PVPHAL_16_ALIGN_STATE         p16AlignState,
325         PVPHAL_16_ALIGN_RENDER_DATA   pRenderData);
326 
327     MOS_STATUS (* pfnSetSamplerStates) (
328         PVPHAL_16_ALIGN_STATE         p16AlignState,
329         PVPHAL_16_ALIGN_RENDER_DATA   pRenderData);
330 } VPHAL_16_ALIGN_STATE;
331 
332 
333 //!
334 //! \brief    16Align interface Initializations
335 //! \details  Interface Initializations for 16Align
336 //! \param    PVPHAL_16_ALIGN_STATE p16AlignState
337 //!           [in] Pointer to the 16Align State
338 //! \param    PRENDERHAL_INTERFACE pRenderHal
339 //!           [in/out] Pointer to RenderHal Interface Structure
340 //! \return   MOS_STATUS
341 //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
342 //!
343 MOS_STATUS VpHal_16AlignInitInterface(
344     PVPHAL_16_ALIGN_STATE    p16AlignState,
345     PRENDERHAL_INTERFACE     pRenderHal);
346 
347 //!
348 //! \brief    check 16Align whether can be processed
349 //! \details  check 16Align whether can be processed
350 //! \param    PVPHAL_RENDER_PARAMS  pRenderParams
351 //!           [in] Pointer to VPHAL render parameter
352 //! \return   bool
353 //!           Return true if 16 Bytes Alignment can be processed, otherwise false
354 //!
355 bool VpHal_RndrIs16Align(
356     PVPHAL_16_ALIGN_STATE   p16AlignState,
357     PVPHAL_RENDER_PARAMS    pRenderParams);
358 #endif // __VPHAL_RENDER_16ALIGNMENT_H__
359 
360