1 /*
2 * Copyright (c) 2011-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     vphal_render_vebox_g12_base.h
24 //! \brief    Interface and structure specific for GEN12 Vebox
25 //! \details  Interface and structure specific for GEN12 Vebox
26 //!
27 #ifndef __VPHAL_RENDER_VEBOX_G12_BASE_H__
28 #define __VPHAL_RENDER_VEBOX_G12_BASE_H__
29 
30 #include "vphal_render_vebox_base.h"
31 #include "vphal_render_hdr_3dlut_g12.h"
32 #include "vp_common_hdr.h"
33 #define VPHAL_VEBOX_MAX_SLICES_G12 4
34 #define VPHAL_VEBOX_RGB_HISTOGRAM_SIZE_G12                      (VPHAL_VEBOX_RGB_HISTOGRAM_SIZE_PER_SLICE * \
35                                                                  VPHAL_NUM_RGB_CHANNEL                    * \
36                                                                  VPHAL_VEBOX_HISTOGRAM_SLICES_COUNT)
37 #define VPHAL_VEBOX_RGB_ACE_HISTOGRAM_SIZE_RESERVED_G12         (3072 * 4)
38 //!
39 //! \brief Denoise Definitions
40 //!
41 #define NOISE_HISTORY_MAX_DEFAULT_G12                            208
42 #define NOISE_NUMMOTIONPIXELS_THRESHOLD_DEFAULT_G12              2
43 #define NOISE_CHROMA_LOWTEMPORALPIXELDIFF_THRESHOLD_LOW_G12      4
44 #define NOISE_CHROMA_LOWTEMPORALPIXELDIFF_THRESHOLD_HIGH_G12     8
45 #define NOISE_CHROMA_TEMPORALPIXELDIFF_THRESHOLD_LOW_G12         10
46 #define NOISE_CHROMA_TEMPORALPIXELDIFF_THRESHOLD_HIGH_G12        14
47 #define NOISE_CHROMA_SUMABSTEMPORALDIFF_THRESHOLD_LOW_G12        128
48 #define NOISE_CHROMA_SUMABSTEMPORALDIFF_THRESHOLD_HIGH_G12       144
49 
50 //!
51 //! \brief added 4 LSB for ASD/STAD/SCM/LTDT/TDT, hence shifting 4 below.
52 //!
53 #define NOISE_ABSSUMTEMPORALDIFF_THRESHOLD_LOW_G12               (32  << 4)
54 #define NOISE_ABSSUMTEMPORALDIFF_THRESHOLD_DEFAULT_G12           (32  << 4)
55 #define NOISE_ABSSUMTEMPORALDIFF_THRESHOLD_HIGH_G12              (40  << 4)
56 #define NOISE_SPATIALCOMPLEXITYMATRIX_THRESHOLD_LOW_G12          (32  << 4)
57 #define NOISE_SPATIALCOMPLEXITYMATRIX_THRESHOLD_DEFAULT_G12      (32  << 4)
58 #define NOISE_SPATIALCOMPLEXITYMATRIX_THRESHOLD_HIGH_G12         (40  << 4)
59 #define NOISE_LOWTEMPORALPIXELDIFF_THRESHOLD_LOW_G12             (4   << 4)
60 #define NOISE_LOWTEMPORALPIXELDIFF_THRESHOLD_DEFAULT_G12         (8   << 4)
61 #define NOISE_LOWTEMPORALPIXELDIFF_THRESHOLD_HIGH_G12            (8   << 4)
62 #define NOISE_TEMPORALPIXELDIFF_THRESHOLD_LOW_G12                (8  << 4)
63 #define NOISE_TEMPORALPIXELDIFF_THRESHOLD_DEFAULT_G12            (12  << 4)
64 #define NOISE_TEMPORALPIXELDIFF_THRESHOLD_HIGH_G12               (12  << 4)
65 #define NOISE_SUMABSTEMPORALDIFF_THRESHOLD_LOW_G12               (128 << 4)
66 #define NOISE_SUMABSTEMPORALDIFF_THRESHOLD_DEFAULT_G12           (128 << 4)
67 #define NOISE_SUMABSTEMPORALDIFF_THRESHOLD_HIGH_G12              (144 << 4)
68 
69 //!
70 //! \brief Vebox Statistics Surface definition for TGL
71 //!
72 #define VPHAL_VEBOX_STATISTICS_SIZE_G12                          (32 * 8)
73 #define VPHAL_VEBOX_STATISTICS_PER_FRAME_SIZE_G12                (32 * sizeof(uint32_t))
74 #define VPHAL_VEBOX_STATISTICS_SURFACE_FMD_OFFSET_G12            0
75 #define VPHAL_VEBOX_STATISTICS_SURFACE_GNE_OFFSET_G12            0x2C
76 #define VPHAL_VEBOX_STATISTICS_SURFACE_STD_OFFSET_G12            0x44
77 
78 struct VEBOX_STATE_UPDATE_STATIC_DATA_G12
79 {
80     // uint32_t 0 - GRF R1.0
81     union
82     {
83         // DN State Update
84         struct
85         {
86             uint32_t    OffsetToSlice0;
87         };
88 
89         uint32_t    Value;
90     } DW00;
91 
92     // uint32_t 1 - GRF R1.1
93     union
94     {
95         // DN State Update
96         struct
97         {
98             uint32_t    OffsetToSlice1;
99         };
100 
101         uint32_t    Value;
102     } DW01;
103 
104     // uint32_t 2 - GRF R1.2
105     union
106     {
107         // DN State Update
108         struct
109         {
110             uint32_t    OffsetToSlice2;
111         };
112 
113         uint32_t    Value;
114     } DW02;
115 
116     // uint32_t 3 - GRF R1.3
117     union
118     {
119         // DN State Update
120         struct
121         {
122             uint32_t    OffsetToSlice3;
123         };
124 
125         uint32_t   Value;
126     } DW03;
127 
128     // uint32_t 4 - GRF R1.4
129     union
130     {
131         // DN State Update
132         struct
133         {
134             uint32_t    FirstFrameFlag : 16;
135             uint32_t    NoiseLevel : 16;
136         };
137 
138         uint32_t    Value;
139     } DW04;
140 
141     // uint32_t 5 - GRF R1.5
142     union
143     {
144         // RangeThr Adp2NLvl: 1 if enabled, 0 otherwise
145         struct
146         {
147             uint32_t    RangeThrAdp2NLvl : 16;
148             uint32_t    Reserved : 16;
149         };
150 
151         uint32_t    Value;
152     } DW05;
153 
154     // uint32_t 6 - GRF R1.6
155     union
156     {
157         // Vebox Statistics Surface
158         struct
159         {
160             uint32_t    VeboxStatisticsSurface;
161         };
162 
163         uint32_t     Value;
164     } DW06;
165 
166     // uint32_t 7 - GRF R1.7
167     union
168     {
169         // Vebox DnDi State Surface
170         struct
171         {
172             uint32_t    VeboxDndiStateSurface;
173         };
174 
175         uint32_t Value;
176     } DW07;
177 
178     // uint32_t 8 - GRF R2.0
179     union
180     {
181         // Vebox GNE surface
182         struct
183         {
184             uint32_t    VeboxTempSurface;
185         };
186 
187         uint32_t Value;
188     } DW08;
189 
190     // uint32_t 9 - GRF R2.1
191     union
192     {
193         // Vebox Spatial Attributes Configuration Surface
194         struct
195         {
196             uint32_t    VeboxSpatialAttributesConfigurationSurface;
197         };
198 
199         uint32_t Value;
200     } DW09;
201 };
202 
203 typedef class VPHAL_VEBOX_STATE_G12_BASE *PVPHAL_VEBOX_STATE_G12_BASE;
204 class VPHAL_VEBOX_STATE_G12_BASE:virtual public VPHAL_VEBOX_STATE
205 {
206 public:
207     VPHAL_VEBOX_STATE_G12_BASE(
208         PMOS_INTERFACE                 pOsInterface,
209         PMHW_VEBOX_INTERFACE           pVeboxInterface,
210         PMHW_SFC_INTERFACE             pSfcInterface,
211         PRENDERHAL_INTERFACE           pRenderHal,
212         PVPHAL_VEBOX_EXEC_STATE        pVeboxExecState,
213         PVPHAL_RNDR_PERF_DATA          pPerfData,
214         const VPHAL_DNDI_CACHE_CNTL    &dndiCacheCntl,
215         MOS_STATUS                     *peStatus);
216 
~VPHAL_VEBOX_STATE_G12_BASE()217     virtual                             ~VPHAL_VEBOX_STATE_G12_BASE() { }
218 
219     virtual MOS_STATUS Initialize(
220         const VphalSettings         *pSettings,
221         Kdll_State                  *pKernelDllState);
222 
223     virtual MOS_STATUS AllocateResources();
224 
225     virtual void FreeResources();
226 
227     virtual MOS_STATUS SetupVeboxKernel(
228         int32_t     iKDTIndex);
229 
230     virtual MOS_STATUS SetupDiIecpState(
231         bool                            bDiScdEnable,
232         PMHW_VEBOX_DI_IECP_CMD_PARAMS   pVeboxDiIecpCmdParams);
233 
234     virtual void SetupSurfaceStates(
235         bool                                    bDiVarianceEnable,
236         PVPHAL_VEBOX_SURFACE_STATE_CMD_PARAMS   pVeboxSurfaceStateCmdParams);
237 
238     virtual MOS_STATUS SetupVeboxState(
239         bool                           bDiVarianceEnable,
240         PMHW_VEBOX_STATE_CMD_PARAMS    pVeboxStateCmdParams);
241 
242     virtual bool IsNeeded(
243         PCVPHAL_RENDER_PARAMS   pcRenderParams,
244         RenderpassData         *pRenderPassData);
245 
246 #if VEBOX_AUTO_DENOISE_SUPPORTED
247     virtual MOS_STATUS LoadUpdateDenoiseKernelStaticData(
248         int32_t     *iCurbeOffsetOutDN);
249 
250     virtual MOS_STATUS SetupSurfaceStatesForDenoise();
251 #endif
252 
253     virtual bool IsFormatSupported(
254         PVPHAL_SURFACE    pSrcSurface);
255 
256     virtual bool IsRTFormatSupported(
257         PVPHAL_SURFACE    pSrcSurface,
258         PVPHAL_SURFACE    pRTSurface);
259 
260     virtual bool IsDnFormatSupported(
261         PVPHAL_SURFACE    pSrcSurface);
262 
263     virtual bool IsDiFormatSupported(
264         PVPHAL_SURFACE    pSrcSurface);
265 
266     virtual bool UseKernelResource();
267 
268     virtual void VeboxGetBeCSCMatrix(
269         PVPHAL_SURFACE    pSrcSurface,
270         PVPHAL_SURFACE    pOutSurface);
271 
272 protected:
273     //!
274     //! \brief    IsMMCEnabledForCurrOutputSurf
275     //! \details  Check if MMC can be enabled for current output surface.
276     //! \return   bool  true if suported, otherwise not supported
277     //!
278     virtual bool IsMMCEnabledForCurrOutputSurf();
279 
280     //!
281     //! \brief    Setup Vebox_DI_IECP Command params for VEBOX final output surface on G75
282     //! \details  Setup Vebox_DI_IECP Command params for VEBOX final output surface on G75
283     //! \param    bDiScdEnable
284     //!           [in] Is DI/Variances report enabled
285     //! \param    pVeboxDiIecpCmdParams
286     //!           [in,out] Pointer to VEBOX_DI_IECP command parameters
287     //! \return   MOS_STATUS
288     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
289     //!
290     virtual MOS_STATUS SetupDiIecpStateForOutputSurf(
291         bool                             bDiScdEnable,
292         PMHW_VEBOX_DI_IECP_CMD_PARAMS    pVeboxDiIecpCmdParams);
293 
294     //!
295     //! \brief    IsFormatMMCSupported
296     //! \details  Check if the format of vebox output surface is supported by MMC
297     //! \param    [in] Format
298     //! \return   bool  true if suported, otherwise not supported
299     //!
300     virtual bool IsFormatMMCSupported(
301         MOS_FORMAT    Format);
302 
303     //!
304     //! \brief    Get Output surface params needed when allocate surfaces
305     //! \details  Get Output surface params needed when allocate surfaces
306     //! \param    Format
307     //!           [out] Format of output surface
308     //! \param    TileType
309     //!           [out] Tile type of output surface
310     //! \return   MOS_STATUS
311     //!           Return MOS_STATUS_SUCCESS if success, otherwise failed
312     //!
313     virtual MOS_STATUS GetOutputSurfParams(
314         MOS_FORMAT       &Format,
315         MOS_TILE_TYPE    &TileType);
316 
317     //!
318     //! \brief    Get related surf parameters needed when allocate FFDI surface
319     //! \details  Get related surf parameters needed when allocate FFDI surface
320     //! \param    ColorSpace
321     //!           [out] Color space of FFDI surface
322     //! \param    SampleType
323     //!           [out] Sample type of FFDI surface
324     //! \return   MOS_STATUS
325     //!           Return MOS_STATUS_SUCCESS if success, otherwise failed
326     //!
327     virtual MOS_STATUS GetFFDISurfParams(
328         VPHAL_CSPACE         &ColorSpace,
329         VPHAL_SAMPLE_TYPE    &SampleType);
330 
331     //!
332     //! \brief    Check for DN only case
333     //! \details  Check for DN only case
334     //! \return   bool
335     //!           Return true if DN only case, otherwise not
336     //!
337     virtual bool IsDNOnly();
338 
339     //!
340     //! \brief    Check whether FFDI Surf is needed
341     //! \details  For decide whether FFDI surf should be allocated or will be used
342     //! \return   bool
343     //!           Return true is needed, otherwise false
344     //!
345     virtual bool IsFFDISurfNeeded();
346 
347     //!
348     //! \brief    Check whether FFDN Surf is needed
349     //! \details  For decide whether FFDN surf should be allocated or will be used
350     //! \return   bool
351     //!           Return true is needed, otherwise false
352     //!
353     virtual bool IsFFDNSurfNeeded();
354 
355     //!
356     //! \brief    Check whether STMM Surf is needed
357     //! \details  For decide whether STMM surf should be allocated or will be used
358     //! \return   bool
359     //!           Return true is needed, otherwise false
360     //!
361     virtual bool IsSTMMSurfNeeded();
362 
363     //!
364     //! \brief    Get output surface of Vebox
365     //! \details  Get output surface of Vebox in current operation
366     //! \param    bDiVarianceEnable
367     //!           [in] Is DI/Variances report enabled
368     //! \return   PVPHAL_SURFACE
369     //!           Corresponding output surface pointer
370     //!
371     virtual PVPHAL_SURFACE GetSurfOutput(
372         bool    bDiVarianceEnable);
373 
374     virtual MOS_STATUS VeboxQueryStatLayout(
375         VEBOX_STAT_QUERY_TYPE    QueryType,
376         uint32_t*                pQuery);
377 
378     //!
379     //! \brief    Check if 2 passes CSC are supported on the platform
380     //!
Is2PassesCscPlatformSupported()381     virtual bool Is2PassesCscPlatformSupported()
382     {
383         return true;
384     }
385 
386     virtual void GetLumaDefaultValue(
387         PVPHAL_SAMPLER_STATE_DNDI_PARAM     pLumaParams);
388 
389     //!
390     //! \brief    Vebox set DN parameter
391     //! \details  Set denoise paramters for luma and chroma.
392     //! \param    [in] pSrcSurface
393     //!           Pointer to input surface of Vebox
394     //! \param    [in] pLumaParams
395     //!           Pointer to Luma DN parameter
396     //! \param    [in] pChromaParams
397     //!           Pointer to Chroma DN parameter
398     //! \return   MOS_STATUS
399     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
400     //!
401     virtual MOS_STATUS SetDNParams(
402         PVPHAL_SURFACE                     pSrcSurface,
403         PVPHAL_SAMPLER_STATE_DNDI_PARAM    pLumaParams,
404         PVPHAL_DNUV_PARAMS                 pChromaParams);
405 
406     //!
407     //! \brief    Vebox set DI parameter
408     //! \details  Set deinterlace paramters
409     //! \param    [in] pSrcSurface
410     //!           Pointer to input surface of Vebox
411     //! \return   MOS_STATUS
412     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
413     //!
414     virtual MOS_STATUS SetDIParams(
415         PVPHAL_SURFACE    pSrcSurface);
416 
417     virtual MOS_STATUS SetDNDIParams(
418         PVPHAL_SURFACE                     pSrcSurface,
419         PVPHAL_SAMPLER_STATE_DNDI_PARAM    pLumaParams,
420         PVPHAL_DNUV_PARAMS                 pChromaParams);
421 
422     //!
423     //! \brief    Setup Chroma Sampling for Vebox
424     //! \details  Setup Chroma Sampling for use in the current Vebox Operation
425     //! \param    [in] pChromaSampling
426     //!           Pointer to chroma sampling params of Vebox
427     //! \return   void
428     //!
429     virtual void SetupChromaSampling(
430         PMHW_VEBOX_CHROMA_SAMPLING    pChromaSampling);
431 
432     virtual VphalSfcState* CreateSfcState();
433 
434     //!
435     //! \brief    Get Output Pipe
436     //! \details  Get Output Pipe
437     //! \param    [in] pcRenderParams
438     //!           Pointer to Render parmas
439     //! \param    [in] pSrcSurface
440     //!           Pointer to input surface of Vebox
441     //! \param    [in/out] pRenderData
442     //!           Pointer to Render data
443     //! \return   MOS_STATUS
444     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
445     //!
446     virtual VPHAL_OUTPUT_PIPE_MODE  GetOutputPipe(
447         PCVPHAL_RENDER_PARAMS           pcRenderParams,
448         PVPHAL_SURFACE                  pSrcSurface,
449         RenderpassData*                 pRenderData);
450 
451     //!
452     //! \brief    Vebox Set Rendering Flags
453     //! \details  Vebox Set Rendering Flags
454     //! \param    [in] pSrc
455     //!           Pointer to Input Surface
456     //! \param    [in] pRenderTarget
457     //!           Pointer to Output Surface
458     //! \return   void
459     //!
460     void VeboxSetRenderingFlags(
461         PVPHAL_SURFACE              pSrc,
462         PVPHAL_SURFACE              pRenderTarget);
463 
464     //!
465     //! \brief    Render the Vebox Cmd buffer for VeboxSendVeboxCmd
466     //!           Parameters might remain unchanged in case
467     //! \param    [in,out] CmdBuffer
468     //!           reference to Cmd buffer control struct
469     //! \param    [out] VeboxDiIecpCmdParams
470     //!           DiIecpCmd params struct to be set
471     //! \param    [out] VeboxSurfaceStateCmdParams
472     //!           VPHAL surface state cmd to be set
473     //! \param    [out] MhwVeboxSurfaceStateCmdParams
474     //!           MHW surface state cmd to be set
475     //! \param    [out] VeboxStateCmdParams
476     //!           MHW vebox state cmd to be set
477     //! \param    [out] FlushDwParams
478     //!           MHW MI_FLUSH_DW cmd to be set
479     //! \param    [in] pGenericPrologParams
480     //!           pointer to Generic prolog params struct to send to cmd buffer header
481     //! \return   MOS_STATUS
482     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
483     //!
484     virtual MOS_STATUS VeboxRenderVeboxCmd(
485         MOS_COMMAND_BUFFER                      &CmdBuffer,
486         MHW_VEBOX_DI_IECP_CMD_PARAMS            &VeboxDiIecpCmdParams,
487         VPHAL_VEBOX_SURFACE_STATE_CMD_PARAMS    &VeboxSurfaceStateCmdParams,
488         MHW_VEBOX_SURFACE_STATE_CMD_PARAMS      &MhwVeboxSurfaceStateCmdParams,
489         MHW_VEBOX_STATE_CMD_PARAMS              &VeboxStateCmdParams,
490         MHW_MI_FLUSH_DW_PARAMS                  &FlushDwParams,
491         PRENDERHAL_GENERIC_PROLOG_PARAMS        pGenericPrologParams);
492 
493 protected:
494     VPHAL_SURFACE      Vebox3DLutOutputSurface     = {};
495     Hdr3DLutGeneratorG12  *m_hdr3DLutGenerator        = nullptr;   //!< HDR 3DLut Generator - Media Kernel to generate HDR 3DLut table
496     uint32_t *          m_hdr3DLutKernelBinary      = nullptr;  //!< HDR 3DLut Generator - Pointer to HDR 3DLut kernel Binary
497     uint32_t            m_hdr3DLutKernelBinarySize  = 0;        //!< HDR 3DLut Generator - Size of HDR 3DLut kernel Binary
498 };
499 
500 #endif // __VPHAL_RENDER_VEBOX_G12_BASE_H__
501