1 /*
2 * Copyright (c) 2011-2018, 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_g11_base.h
24 //! \brief    Interface and structure specific for GEN11 Vebox
25 //! \details  Interface and structure specific for GEN11 Vebox
26 //!
27 #ifndef __VPHAL_RENDER_VEBOX_G11_BASE_H__
28 #define __VPHAL_RENDER_VEBOX_G11_BASE_H__
29 
30 #include "vphal_render_vebox_base.h"
31 #include "vphal_render_hdr_g11.h"
32 
33 #define VPHAL_VEBOX_MAX_SLICES_G11                              4
34 
35 #define VPHAL_VEBOX_RGB_HISTOGRAM_SIZE_G11                      (VPHAL_VEBOX_RGB_HISTOGRAM_SIZE_PER_SLICE * \
36                                                                  VPHAL_NUM_RGB_CHANNEL                    * \
37                                                                  VPHAL_VEBOX_MAX_SLICES_G11)
38 #define VPHAL_VEBOX_RGB_ACE_HISTOGRAM_SIZE_RESERVED_G11         (3072 * 4)
39 //!
40 //! \brief Denoise Definitions
41 //!
42 #define NOISE_HISTORY_MAX_DEFAULT_G11                            208
43 #define NOISE_NUMMOTIONPIXELS_THRESHOLD_DEFAULT_G11              2
44 #define NOISE_CHROMA_LOWTEMPORALPIXELDIFF_THRESHOLD_LOW_G11      4
45 #define NOISE_CHROMA_LOWTEMPORALPIXELDIFF_THRESHOLD_HIGH_G11     8
46 #define NOISE_CHROMA_TEMPORALPIXELDIFF_THRESHOLD_LOW_G11         10
47 #define NOISE_CHROMA_TEMPORALPIXELDIFF_THRESHOLD_HIGH_G11        14
48 #define NOISE_CHROMA_SUMABSTEMPORALDIFF_THRESHOLD_LOW_G11        128
49 #define NOISE_CHROMA_SUMABSTEMPORALDIFF_THRESHOLD_HIGH_G11       144
50 
51 //!
52 //! \brief added 4 LSB for ASD/STAD/SCM/LTDT/TDT, hence shifting 4 below.
53 //!
54 #define NOISE_ABSSUMTEMPORALDIFF_THRESHOLD_LOW_G11               (32  << 4)
55 #define NOISE_ABSSUMTEMPORALDIFF_THRESHOLD_DEFAULT_G11           (32  << 4)
56 #define NOISE_ABSSUMTEMPORALDIFF_THRESHOLD_HIGH_G11              (40  << 4)
57 #define NOISE_SPATIALCOMPLEXITYMATRIX_THRESHOLD_LOW_G11          (32  << 4)
58 #define NOISE_SPATIALCOMPLEXITYMATRIX_THRESHOLD_DEFAULT_G11      (32  << 4)
59 #define NOISE_SPATIALCOMPLEXITYMATRIX_THRESHOLD_HIGH_G11         (40  << 4)
60 #define NOISE_LOWTEMPORALPIXELDIFF_THRESHOLD_LOW_G11             (4   << 4)
61 #define NOISE_LOWTEMPORALPIXELDIFF_THRESHOLD_DEFAULT_G11         (8   << 4)
62 #define NOISE_LOWTEMPORALPIXELDIFF_THRESHOLD_HIGH_G11            (8   << 4)
63 #define NOISE_TEMPORALPIXELDIFF_THRESHOLD_LOW_G11                (8  << 4)
64 #define NOISE_TEMPORALPIXELDIFF_THRESHOLD_DEFAULT_G11            (12  << 4)
65 #define NOISE_TEMPORALPIXELDIFF_THRESHOLD_HIGH_G11               (12  << 4)
66 #define NOISE_SUMABSTEMPORALDIFF_THRESHOLD_LOW_G11               (128 << 4)
67 #define NOISE_SUMABSTEMPORALDIFF_THRESHOLD_DEFAULT_G11           (128 << 4)
68 #define NOISE_SUMABSTEMPORALDIFF_THRESHOLD_HIGH_G11              (144 << 4)
69 
70 //!
71 //! \brief Vebox Statistics Surface definition for ICL
72 //!
73 #define VPHAL_VEBOX_STATISTICS_SIZE_G11                          (32 * 8)
74 #define VPHAL_VEBOX_STATISTICS_PER_FRAME_SIZE_G11                (32 * sizeof(uint32_t))
75 #define VPHAL_VEBOX_STATISTICS_SURFACE_FMD_OFFSET_G11            0
76 #define VPHAL_VEBOX_STATISTICS_SURFACE_GNE_OFFSET_G11            0x2C
77 #define VPHAL_VEBOX_STATISTICS_SURFACE_STD_OFFSET_G11            0x44
78 
79 //!
80 //! \brief Vebox Histogram Surface definition for ICL
81 //!
82 #define VPHAL_VEBOX_ACE_HISTOGRAM_SLICE0_OFFSET_G11              0x6400
83 #define VPHAL_VEBOX_ACE_HISTOGRAM_SLICE1_OFFSET_G11              0x6c00
84 #define VPHAL_VEBOX_ACE_HISTOGRAM_SLICE2_OFFSET_G11              0x7400
85 #define VPHAL_VEBOX_ACE_HISTOGRAM_SLICE3_OFFSET_G11              0x7c00
86 #define VPHAL_VEBOX_ACE_HISTOGRAM_PREVIOUS_SLICE0_OFFSET_G11     0x6000
87 #define VPHAL_VEBOX_ACE_HISTOGRAM_PREVIOUS_SLICE1_OFFSET_G11     0x6800
88 
89 struct VEBOX_STATE_UPDATE_STATIC_DATA_G11
90 {
91     // uint32_t 0 - GRF R1.0
92     union
93     {
94         // DN State Update
95         struct
96         {
97             uint32_t       OffsetToSlice0;
98         };
99 
100         uint32_t       Value;
101     } DW00;
102 
103     // uint32_t 1 - GRF R1.1
104     union
105     {
106         // DN State Update
107         struct
108         {
109             uint32_t       OffsetToSlice1;
110         };
111 
112         uint32_t       Value;
113     } DW01;
114 
115     // uint32_t 2 - GRF R1.2
116     union
117     {
118         // DN State Update
119         struct
120         {
121             uint32_t       OffsetToSlice2;
122         };
123 
124         uint32_t   Value;
125     } DW02;
126 
127     // uint32_t 3 - GRF R1.3
128     union
129     {
130         // DN State Update
131         struct
132         {
133              uint32_t       OffsetToSlice3;
134         };
135 
136          uint32_t    Value;
137      } DW03;
138 
139      // uint32_t 4 - GRF R1.4
140      union
141      {
142           // DN State Update
143           struct
144           {
145            uint32_t    FirstFrameFlag : 16;
146            uint32_t    NoiseLevel : 16;
147           };
148 
149           uint32_t Value;
150      } DW04;
151 
152      // uint32_t 5 - GRF R1.5
153      union
154      {
155           // RangeThr Adp2NLvl: 1 if enabled, 0 otherwise
156           struct
157           {
158            uint32_t    RangeThrAdp2NLvl : 16;
159            uint32_t    Reserved : 16;
160           };
161 
162           uint32_t Value;
163      } DW05;
164 
165      // uint32_t 6 - GRF R1.6
166      union
167      {
168           // Vebox Statistics Surface
169           struct
170           {
171            uint32_t    VeboxStatisticsSurface;
172           };
173 
174           uint32_t Value;
175      } DW06;
176 
177      // uint32_t 7 - GRF R1.7
178      union
179      {
180           // Vebox DnDi State Surface
181           struct
182           {
183            uint32_t    VeboxDndiStateSurface;
184           };
185 
186           uint32_t Value;
187      } DW07;
188 
189      // uint32_t 8 - GRF R2.0
190      union
191      {
192           // Vebox GNE surface
193           struct
194           {
195            uint32_t    VeboxTempSurface;
196           };
197 
198           uint32_t Value;
199      } DW08;
200 
201      // uint32_t 9 - GRF R2.1
202      union
203      {
204           // Vebox Spatial Attributes Configuration Surface
205           struct
206           {
207            uint32_t    VeboxSpatialAttributesConfigurationSurface;
208           };
209 
210           uint32_t Value;
211      } DW09;
212 };
213 
214 typedef class VPHAL_VEBOX_STATE_G11_BASE *PVPHAL_VEBOX_STATE_G11_BASE;
215 class VPHAL_VEBOX_STATE_G11_BASE:virtual public VPHAL_VEBOX_STATE
216 {
217 public:
218     VPHAL_VEBOX_STATE_G11_BASE(
219         PMOS_INTERFACE                  pOsInterface,
220         PMHW_VEBOX_INTERFACE            pVeboxInterface,
221         PMHW_SFC_INTERFACE              pSfcInterface,
222         PRENDERHAL_INTERFACE            pRenderHal,
223         PVPHAL_VEBOX_EXEC_STATE         pVeboxExecState,
224         PVPHAL_RNDR_PERF_DATA           pPerfData,
225         const VPHAL_DNDI_CACHE_CNTL     &dndiCacheCntl,
226         MOS_STATUS                      *peStatus);
227 
~VPHAL_VEBOX_STATE_G11_BASE()228     virtual                             ~VPHAL_VEBOX_STATE_G11_BASE() { }
229 
230     virtual MOS_STATUS AllocateResources();
231 
232     virtual void FreeResources();
233 
234     virtual MOS_STATUS SetupVeboxKernel(
235         int32_t                     iKDTIndex);
236 
237     virtual MOS_STATUS SetupDiIecpState(
238         bool                        bDiScdEnable,
239         PMHW_VEBOX_DI_IECP_CMD_PARAMS
240         pVeboxDiIecpCmdParams);
241 
242     virtual void SetupSurfaceStates(
243         bool                        bDiVarianceEnable,
244         PVPHAL_VEBOX_SURFACE_STATE_CMD_PARAMS
245         pVeboxSurfaceStateCmdParams);
246 
247     virtual MOS_STATUS SetupVeboxState(
248         bool                        bDiVarianceEnable,
249         PMHW_VEBOX_STATE_CMD_PARAMS pVeboxStateCmdParams);
250 
251     virtual bool IsNeeded(
252         PCVPHAL_RENDER_PARAMS       pcRenderParams,
253         RenderpassData              *pRenderPassData);
254 
255 #if VEBOX_AUTO_DENOISE_SUPPORTED
256     virtual MOS_STATUS LoadUpdateDenoiseKernelStaticData(
257         int32_t*                        iCurbeOffsetOutDN);
258 
259     virtual MOS_STATUS SetupSurfaceStatesForDenoise();
260 #endif
261 
262     virtual bool IsFormatSupported(
263         PVPHAL_SURFACE              pSrcSurface);
264 
265     virtual bool IsRTFormatSupported(
266         PVPHAL_SURFACE                  pSrcSurface,
267         PVPHAL_SURFACE                  pRTSurface);
268 
269     virtual bool IsDnFormatSupported(
270         PVPHAL_SURFACE                  pSrcSurface);
271 
272     virtual bool IsDiFormatSupported(
273         PVPHAL_SURFACE              pSrcSurface);
274 
275     virtual VPHAL_OUTPUT_PIPE_MODE  GetOutputPipe(
276         PCVPHAL_RENDER_PARAMS               pcRenderParams,
277         PVPHAL_SURFACE                      pSrcSurface,
278         bool*                               pbCompNeeded);
279 
280     virtual bool UseKernelResource();
281 
282     virtual void VeboxGetBeCSCMatrix(
283         PVPHAL_SURFACE                  pSrcSurface,
284         PVPHAL_SURFACE                  pOutSurface);
285 
286 protected:
287     //!
288     //! \brief    IsMMCEnabledForCurrOutputSurf
289     //! \details  Check if MMC can be enabled for current output surface.
290     //! \return   bool  true if suported, otherwise not supported
291     //!
292     virtual bool IsMMCEnabledForCurrOutputSurf();
293 
294     //!
295     //! \brief    Setup Vebox_DI_IECP Command params for VEBOX final output surface on G75
296     //! \details  Setup Vebox_DI_IECP Command params for VEBOX final output surface on G75
297     //! \param    bDiScdEnable
298     //!           [in] Is DI/Variances report enabled
299     //! \param    pVeboxDiIecpCmdParams
300     //!           [in,out] Pointer to VEBOX_DI_IECP command parameters
301     //! \return   MOS_STATUS
302     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
303     //!
304     virtual MOS_STATUS SetupDiIecpStateForOutputSurf(
305         bool                                    bDiScdEnable,
306         PMHW_VEBOX_DI_IECP_CMD_PARAMS           pVeboxDiIecpCmdParams);
307 
308     //!
309     //! \brief    IsFormatMMCSupported
310     //! \details  Check if the format of vebox output surface is supported by MMC
311     //! \param    [in] Format
312     //! \return   bool  true if suported, otherwise not supported
313     //!
314     virtual bool IsFormatMMCSupported(
315         MOS_FORMAT                  Format);
316 
317     //!
318     //! \brief    Get Output surface params needed when allocate surfaces
319     //! \details  Get Output surface params needed when allocate surfaces
320     //! \param    Format
321     //!           [out] Format of output surface
322     //! \param    TileType
323     //!           [out] Tile type of output surface
324     //! \return   MOS_STATUS
325     //!           Return MOS_STATUS_SUCCESS if success, otherwise failed
326     //!
327     virtual MOS_STATUS      GetOutputSurfParams(
328         MOS_FORMAT          &Format,
329         MOS_TILE_TYPE       &TileType);
330 
331     //!
332     //! \brief    Get related surf parameters needed when allocate FFDI surface
333     //! \details  Get related surf parameters needed when allocate FFDI surface
334     //! \param    ColorSpace
335     //!           [out] Color space of FFDI surface
336     //! \param    SampleType
337     //!           [out] Sample type of FFDI surface
338     //! \return   MOS_STATUS
339     //!           Return MOS_STATUS_SUCCESS if success, otherwise failed
340     //!
341     virtual MOS_STATUS      GetFFDISurfParams(
342         VPHAL_CSPACE        &ColorSpace,
343         VPHAL_SAMPLE_TYPE   &SampleType);
344 
345     //!
346     //! \brief    Check for DN only case
347     //! \details  Check for DN only case
348     //! \return   bool
349     //!           Return true if DN only case, otherwise not
350     //!
351     virtual bool            IsDNOnly();
352 
353     //!
354     //! \brief    Check whether FFDI Surf is needed
355     //! \details  For decide whether FFDI surf should be allocated or will be used
356     //! \return   bool
357     //!           Return true is needed, otherwise false
358     //!
359     virtual bool            IsFFDISurfNeeded();
360 
361     //!
362     //! \brief    Check whether FFDN Surf is needed
363     //! \details  For decide whether FFDN surf should be allocated or will be used
364     //! \return   bool
365     //!           Return true is needed, otherwise false
366     //!
367     virtual bool            IsFFDNSurfNeeded();
368 
369     //!
370     //! \brief    Check whether STMM Surf is needed
371     //! \details  For decide whether STMM surf should be allocated or will be used
372     //! \return   bool
373     //!           Return true is needed, otherwise false
374     //!
375     virtual bool            IsSTMMSurfNeeded();
376 
377     //!
378     //! \brief    Get output surface of Vebox
379     //! \details  Get output surface of Vebox in current operation
380     //! \param    bDiVarianceEnable
381     //!           [in] Is DI/Variances report enabled
382     //! \return   PVPHAL_SURFACE
383     //!           Corresponding output surface pointer
384     //!
385     virtual PVPHAL_SURFACE GetSurfOutput(
386         bool                                    bDiVarianceEnable);
387 
388     virtual MOS_STATUS VeboxQueryStatLayout(
389         VEBOX_STAT_QUERY_TYPE       QueryType,
390         uint32_t*                   pQuery);
391 
392     //!
393     //! \brief    Check if 2 passes CSC are supported on the platform
394     //!
Is2PassesCscPlatformSupported()395     virtual bool Is2PassesCscPlatformSupported()
396     {
397         return true;
398     }
399 
400     virtual void GetLumaDefaultValue(
401         PVPHAL_SAMPLER_STATE_DNDI_PARAM pLumaParams);
402 
403     //!
404     //! \brief    Vebox set DN parameter
405     //! \details  Set denoise paramters for luma and chroma.
406     //! \param    [in] pSrcSurface
407     //!           Pointer to input surface of Vebox
408     //! \param    [in] pLumaParams
409     //!           Pointer to Luma DN parameter
410     //! \param    [in] pChromaParams
411     //!           Pointer to Chroma DN parameter
412     //! \return   MOS_STATUS
413     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
414     //!
415     virtual MOS_STATUS SetDNParams(
416         PVPHAL_SURFACE                   pSrcSurface,
417         PVPHAL_SAMPLER_STATE_DNDI_PARAM  pLumaParams,
418         PVPHAL_DNUV_PARAMS               pChromaParams);
419 
420     //!
421     //! \brief    Vebox set DI parameter
422     //! \details  Set deinterlace paramters
423     //! \param    [in] pSrcSurface
424     //!           Pointer to input surface of Vebox
425     //! \return   MOS_STATUS
426     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
427     //!
428     virtual MOS_STATUS SetDIParams(
429         PVPHAL_SURFACE                   pSrcSurface);
430 
431     virtual MOS_STATUS SetDNDIParams(
432         PVPHAL_SURFACE                  pSrcSurface,
433         PVPHAL_SAMPLER_STATE_DNDI_PARAM pLumaParams,
434         PVPHAL_DNUV_PARAMS              pChromaParams);
435 
436     //!
437     //! \brief    Setup Chroma Sampling for Vebox
438     //! \details  Setup Chroma Sampling for use in the current Vebox Operation
439     //! \param    [in] pChromaSampling
440     //!           Pointer to chroma sampling params of Vebox
441     //! \return   void
442     //!
443     virtual void SetupChromaSampling(
444         PMHW_VEBOX_CHROMA_SAMPLING      pChromaSampling);
445 
446     virtual VphalSfcState* CreateSfcState();
447 
448     //!
449     //! \brief    Vebox set rendering flag
450     //! \details  Setup Rendering Flags due to different usage case - main entrance
451     //! \param    [in] pSrc
452     //!           Pointer to input surface of Vebox
453     //! \param    [in] pRenderTarget
454     //!           Pointer to Render targe surface of VPP BLT
455     //! \return   void
456     //!
457     virtual void VeboxSetRenderingFlags(
458         PVPHAL_SURFACE              pSrc,
459         PVPHAL_SURFACE              pRenderTarget);
460 
461 protected:
462     VPHAL_SURFACE               Vebox3DLutOutputSurface         = {};
463     Hdr3DLutGenerator           *m_hdr3DLutGenerator            = nullptr;
464 };
465 
466 #endif // __VPHAL_RENDER_VEBOX_G11_BASE_H__
467