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_base.h
24 //! \brief    Common interface and structure used in Vebox
25 //! \details  Common interface and structure used in Vebox which are platform independent
26 //!
27 #ifndef __VPHAL_RENDER_VEBOX_BASE_H__
28 #define __VPHAL_RENDER_VEBOX_BASE_H__
29 
30 #include "mos_os.h"
31 #include "renderhal.h"
32 #include "mhw_vebox.h"
33 #include "vphal.h"
34 #include "vphal_render_renderstate.h"
35 #include "vphal_render_common.h"
36 #include "vphal_render_vebox_iecp.h"
37 #include "vphal_render_sfc_base.h"
38 #include "vphal_render_vebox_denoise.h"
39 
40 #define VPHAL_MAX_NUM_FFDI_SURFACES     4                                       //!< 2 for ADI plus additional 2 for parallel execution on HSW+
41 #define VPHAL_NUM_FFDN_SURFACES         2                                       //!< Number of FFDN surfaces
42 #define VPHAL_NUM_STMM_SURFACES         2                                       //!< Number of STMM statistics surfaces
43 #define VPHAL_DNDI_BUFFERS_MAX          4                                       //!< Max DNDI buffers
44 #define VPHAL_NUM_KERNEL_VEBOX          8                                       //!< Max kernels called at Adv stage
45 
46 #ifndef VEBOX_AUTO_DENOISE_SUPPORTED
47 #define VEBOX_AUTO_DENOISE_SUPPORTED    1
48 #endif
49 
50 //!
51 //! \brief Denoise Range
52 //!
53 #define NOISEFACTOR_MAX                                 64                      //!< Max Slider value
54 #define NOISEFACTOR_MID                                 32                      //!< Mid Slider value, SKL+ only
55 #define NOISEFACTOR_MIN                                 0                       //!< Min Slider value
56 
57 //!
58 //! \brief Temporal Denoise Definitions
59 //!
60 #define NOISE_HISTORY_DELTA_DEFAULT                     8
61 #define NOISE_HISTORY_MAX_DEFAULT                       192
62 #define NOISE_NUMMOTIONPIXELS_THRESHOLD_DEFAULT         0
63 #define NOISE_LOWTEMPORALPIXELDIFF_THRESHOLD_DEFAULT    6
64 #define NOISE_TEMPORALPIXELDIFF_THRESHOLD_DEFAULT       12
65 #define NOISE_SUMABSTEMPORALDIFF_THRESHOLD_DEFAULT      128
66 
67 // Pixel Range Threshold Array Denoise Definitions for SKL+ 5x5 Bilateral Filter
68 #define NOISE_BLF_RANGE_THRESHOLD_ADP_NLVL          1
69 #define NOISE_BLF_RANGE_THRESHOLD_ADP_NLVL_MIN      65536
70 #define NOISE_BLF_RANGE_THRESHOLD_ADP_NLVL_MAX      393216
71 #define NOISE_BLF_RANGE_THRESHOLD_NLVL_MI0          192
72 #define NOISE_BLF_RANGE_THRESHOLD_NLVL_MI1          320
73 #define NOISE_BLF_RANGE_THRESHOLD_NLVL_MI2          384
74 #define NOISE_BLF_RANGE_THRESHOLD_NLVL_MI3          640
75 #define NOISE_BLF_RANGE_THRESHOLD_NLVL_MI4          1024
76 #define NOISE_BLF_RANGE_THRESHOLD_NLVL_MI5          1280
77 #define NOISE_BLF_RANGE_THRADPDYNR_MIN              512
78 #define NOISE_BLF_RANGE_THRADPDYNR_MAX              2048
79 #define NOISE_BLF_RANGE_THRDYNR_MIN                 256
80 #define NOISE_BLF_RANGE_THRESHOLD_S0_MIN            32
81 #define NOISE_BLF_RANGE_THRESHOLD_S0_MID            192
82 #define NOISE_BLF_RANGE_THRESHOLD_S0_MAX            384
83 #define NOISE_BLF_RANGE_THRESHOLD_S1_MIN            64
84 #define NOISE_BLF_RANGE_THRESHOLD_S1_MID            256
85 #define NOISE_BLF_RANGE_THRESHOLD_S1_MAX            576
86 #define NOISE_BLF_RANGE_THRESHOLD_S2_MIN            128
87 #define NOISE_BLF_RANGE_THRESHOLD_S2_MID            512
88 #define NOISE_BLF_RANGE_THRESHOLD_S2_MAX            896
89 #define NOISE_BLF_RANGE_THRESHOLD_S3_MIN            128
90 #define NOISE_BLF_RANGE_THRESHOLD_S3_MID            640
91 #define NOISE_BLF_RANGE_THRESHOLD_S3_MAX            1280
92 #define NOISE_BLF_RANGE_THRESHOLD_S4_MIN            128
93 #define NOISE_BLF_RANGE_THRESHOLD_S4_MID            896
94 #define NOISE_BLF_RANGE_THRESHOLD_S4_MAX            1920
95 #define NOISE_BLF_RANGE_THRESHOLD_S5_MIN            128
96 #define NOISE_BLF_RANGE_THRESHOLD_S5_MID            1280
97 #define NOISE_BLF_RANGE_THRESHOLD_S5_MAX            2560
98 #define NOISE_BLF_RANGE_THRESHOLD_S0_DEFAULT        NOISE_BLF_RANGE_THRESHOLD_S0_MID
99 #define NOISE_BLF_RANGE_THRESHOLD_S1_DEFAULT        NOISE_BLF_RANGE_THRESHOLD_S1_MID
100 #define NOISE_BLF_RANGE_THRESHOLD_S2_DEFAULT        NOISE_BLF_RANGE_THRESHOLD_S2_MID
101 #define NOISE_BLF_RANGE_THRESHOLD_S3_DEFAULT        NOISE_BLF_RANGE_THRESHOLD_S3_MID
102 #define NOISE_BLF_RANGE_THRESHOLD_S4_DEFAULT        NOISE_BLF_RANGE_THRESHOLD_S4_MID
103 #define NOISE_BLF_RANGE_THRESHOLD_S5_DEFAULT        NOISE_BLF_RANGE_THRESHOLD_S5_MID
104 #define NOISE_BLF_RANGE_THRESHOLD_S0_AUTO_DEFAULT   192
105 #define NOISE_BLF_RANGE_THRESHOLD_S1_AUTO_DEFAULT   320
106 #define NOISE_BLF_RANGE_THRESHOLD_S2_AUTO_DEFAULT   384
107 #define NOISE_BLF_RANGE_THRESHOLD_S3_AUTO_DEFAULT   640
108 #define NOISE_BLF_RANGE_THRESHOLD_S4_AUTO_DEFAULT   1024
109 #define NOISE_BLF_RANGE_THRESHOLD_S5_AUTO_DEFAULT   1280
110 
111 // Pixel Range Weight Array Denoise Definitions for SKL+ 5x5 Bilateral Filter
112 #define NOISE_BLF_RANGE_WGTS0_MIN                   16
113 #define NOISE_BLF_RANGE_WGTS0_MID                   16
114 #define NOISE_BLF_RANGE_WGTS0_MAX                   16
115 #define NOISE_BLF_RANGE_WGTS1_MIN                   9
116 #define NOISE_BLF_RANGE_WGTS1_MID                   14
117 #define NOISE_BLF_RANGE_WGTS1_MAX                   15
118 #define NOISE_BLF_RANGE_WGTS2_MIN                   2
119 #define NOISE_BLF_RANGE_WGTS2_MID                   10
120 #define NOISE_BLF_RANGE_WGTS2_MAX                   13
121 #define NOISE_BLF_RANGE_WGTS3_MIN                   0
122 #define NOISE_BLF_RANGE_WGTS3_MID                   5
123 #define NOISE_BLF_RANGE_WGTS3_MAX                   10
124 #define NOISE_BLF_RANGE_WGTS4_MIN                   0
125 #define NOISE_BLF_RANGE_WGTS4_MID                   2
126 #define NOISE_BLF_RANGE_WGTS4_MAX                   7
127 #define NOISE_BLF_RANGE_WGTS5_MIN                   0
128 #define NOISE_BLF_RANGE_WGTS5_MID                   1
129 #define NOISE_BLF_RANGE_WGTS5_MAX                   4
130 #define NOISE_BLF_RANGE_WGTS0_DEFAULT               NOISE_BLF_RANGE_WGTS0_MID
131 #define NOISE_BLF_RANGE_WGTS1_DEFAULT               NOISE_BLF_RANGE_WGTS1_MID
132 #define NOISE_BLF_RANGE_WGTS2_DEFAULT               NOISE_BLF_RANGE_WGTS2_MID
133 #define NOISE_BLF_RANGE_WGTS3_DEFAULT               NOISE_BLF_RANGE_WGTS3_MID
134 #define NOISE_BLF_RANGE_WGTS4_DEFAULT               NOISE_BLF_RANGE_WGTS4_MID
135 #define NOISE_BLF_RANGE_WGTS5_DEFAULT               NOISE_BLF_RANGE_WGTS5_MID
136 
137 // Distance Weight Matrix Denoise Definitions for SKL+ 5x5 Bilateral Filter
138 #define NOISE_BLF_DISTANCE_WGTS00_DEFAULT           12
139 #define NOISE_BLF_DISTANCE_WGTS01_DEFAULT           12
140 #define NOISE_BLF_DISTANCE_WGTS02_DEFAULT           10
141 #define NOISE_BLF_DISTANCE_WGTS10_DEFAULT           12
142 #define NOISE_BLF_DISTANCE_WGTS11_DEFAULT           11
143 #define NOISE_BLF_DISTANCE_WGTS12_DEFAULT           10
144 #define NOISE_BLF_DISTANCE_WGTS20_DEFAULT           10
145 #define NOISE_BLF_DISTANCE_WGTS21_DEFAULT           10
146 #define NOISE_BLF_DISTANCE_WGTS22_DEFAULT           8
147 
148 //!
149 //! \brief Improved Deinterlacing for CNL+
150 //!
151 #define VPHAL_VEBOX_DI_CHROMA_TDM_WEIGHT_NATUAL                     0
152 #define VPHAL_VEBOX_DI_LUMA_TDM_WEIGHT_NATUAL                       4
153 #define VPHAL_VEBOX_DI_SHCM_DELTA_NATUAL                            5
154 #define VPHAL_VEBOX_DI_SHCM_THRESHOLD_NATUAL                        255
155 #define VPHAL_VEBOX_DI_SVCM_DELTA_NATUAL                            5
156 #define VPHAL_VEBOX_DI_SVCM_THRESHOLD_NATUAL                        255
157 #define VPHAL_VEBOX_DI_LUMA_TDM_CORING_THRESHOLD_NATUAL             0
158 #define VPHAL_VEBOX_DI_CHROMA_TDM_CORING_THRESHOLD_NATUAL           0
159 #define VPHAL_VEBOX_DI_DIRECTION_CHECK_THRESHOLD_NATUAL             3
160 #define VPHAL_VEBOX_DI_TEARING_LOW_THRESHOLD_NATUAL                 20
161 #define VPHAL_VEBOX_DI_TEARING_HIGH_THRESHOLD_NATUAL                100
162 #define VPHAL_VEBOX_DI_DIFF_CHECK_SLACK_THRESHOLD_NATUAL            15
163 #define VPHAL_VEBOX_DI_SAD_WT0_NATUAL                               0
164 #define VPHAL_VEBOX_DI_SAD_WT1_NATUAL                               63
165 #define VPHAL_VEBOX_DI_SAD_WT2_NATUAL                               76
166 #define VPHAL_VEBOX_DI_SAD_WT3_NATUAL                               89
167 #define VPHAL_VEBOX_DI_SAD_WT4_NATUAL                               114
168 #define VPHAL_VEBOX_DI_SAD_WT6_NATUAL                               217
169 #define VPHAL_VEBOX_DI_LPFWTLUT0_SD_NATUAL                          0
170 #define VPHAL_VEBOX_DI_LPFWTLUT0_HD_NATUAL                          0
171 #define VPHAL_VEBOX_DI_LPFWTLUT1_SD_NATUAL                          0
172 #define VPHAL_VEBOX_DI_LPFWTLUT1_HD_NATUAL                          0
173 #define VPHAL_VEBOX_DI_LPFWTLUT2_SD_NATUAL                          0
174 #define VPHAL_VEBOX_DI_LPFWTLUT2_HD_NATUAL                          0
175 #define VPHAL_VEBOX_DI_LPFWTLUT3_SD_NATUAL                          128
176 #define VPHAL_VEBOX_DI_LPFWTLUT3_HD_NATUAL                          0
177 #define VPHAL_VEBOX_DI_LPFWTLUT4_SD_NATUAL                          128
178 #define VPHAL_VEBOX_DI_LPFWTLUT4_HD_NATUAL                          32
179 #define VPHAL_VEBOX_DI_LPFWTLUT5_SD_NATUAL                          128
180 #define VPHAL_VEBOX_DI_LPFWTLUT5_HD_NATUAL                          64
181 #define VPHAL_VEBOX_DI_LPFWTLUT6_SD_NATUAL                          255
182 #define VPHAL_VEBOX_DI_LPFWTLUT6_HD_NATUAL                          128
183 #define VPHAL_VEBOX_DI_LPFWTLUT7_SD_NATUAL                          255
184 #define VPHAL_VEBOX_DI_LPFWTLUT7_HD_NATUAL                          255
185 
186 //!
187 //! \brief Chroma Downsampling and Upsampling for CNL+
188 //!
189 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITH_DI_TYPE0_HORZ_OFFSET     0
190 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITH_DI_TYPE1_HORZ_OFFSET     1
191 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITH_DI_TYPE2_HORZ_OFFSET     0
192 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITH_DI_TYPE3_HORZ_OFFSET     1
193 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITH_DI_TYPE4_HORZ_OFFSET     0
194 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITH_DI_TYPE5_HORZ_OFFSET     1
195 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITH_DI_TYPE0_VERT_OFFSET     2
196 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITH_DI_TYPE1_VERT_OFFSET     2
197 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITH_DI_TYPE2_VERT_OFFSET     0
198 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITH_DI_TYPE3_VERT_OFFSET     0
199 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITH_DI_TYPE4_VERT_OFFSET     4
200 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITH_DI_TYPE5_VERT_OFFSET     4
201 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITHOUT_DI_TYPE0_HORZ_OFFSET  0
202 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITHOUT_DI_TYPE1_HORZ_OFFSET  1
203 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITHOUT_DI_TYPE2_HORZ_OFFSET  0
204 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITHOUT_DI_TYPE3_HORZ_OFFSET  1
205 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITHOUT_DI_TYPE4_HORZ_OFFSET  0
206 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITHOUT_DI_TYPE5_HORZ_OFFSET  1
207 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITHOUT_DI_TYPE0_VERT_OFFSET  1
208 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITHOUT_DI_TYPE1_VERT_OFFSET  1
209 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITHOUT_DI_TYPE2_VERT_OFFSET  0
210 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITHOUT_DI_TYPE3_VERT_OFFSET  0
211 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITHOUT_DI_TYPE4_VERT_OFFSET  2
212 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_420_WITHOUT_DI_TYPE5_VERT_OFFSET  2
213 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_422_TYPE2_HORZ_OFFSET             0
214 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_422_TYPE3_HORZ_OFFSET             1
215 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_422_TYPE2_VERT_OFFSET             0
216 #define VPHAL_VEBOX_CHROMA_UPSAMPLING_422_TYPE3_VERT_OFFSET             0
217 #define VPHAL_VEBOX_CHROMA_DOWNSAMPLING_420_TYPE0_HORZ_OFFSET           0
218 #define VPHAL_VEBOX_CHROMA_DOWNSAMPLING_420_TYPE1_HORZ_OFFSET           1
219 #define VPHAL_VEBOX_CHROMA_DOWNSAMPLING_420_TYPE2_HORZ_OFFSET           0
220 #define VPHAL_VEBOX_CHROMA_DOWNSAMPLING_420_TYPE3_HORZ_OFFSET           1
221 #define VPHAL_VEBOX_CHROMA_DOWNSAMPLING_420_TYPE4_HORZ_OFFSET           0
222 #define VPHAL_VEBOX_CHROMA_DOWNSAMPLING_420_TYPE5_HORZ_OFFSET           1
223 #define VPHAL_VEBOX_CHROMA_DOWNSAMPLING_420_TYPE0_VERT_OFFSET           1
224 #define VPHAL_VEBOX_CHROMA_DOWNSAMPLING_420_TYPE1_VERT_OFFSET           1
225 #define VPHAL_VEBOX_CHROMA_DOWNSAMPLING_420_TYPE2_VERT_OFFSET           0
226 #define VPHAL_VEBOX_CHROMA_DOWNSAMPLING_420_TYPE3_VERT_OFFSET           0
227 #define VPHAL_VEBOX_CHROMA_DOWNSAMPLING_420_TYPE4_VERT_OFFSET           2
228 #define VPHAL_VEBOX_CHROMA_DOWNSAMPLING_420_TYPE5_VERT_OFFSET           2
229 #define VPHAL_VEBOX_CHROMA_DOWNSAMPLING_422_TYPE2_HORZ_OFFSET           0
230 #define VPHAL_VEBOX_CHROMA_DOWNSAMPLING_422_TYPE3_HORZ_OFFSET           1
231 #define VPHAL_VEBOX_CHROMA_DOWNSAMPLING_422_TYPE2_VERT_OFFSET           0
232 #define VPHAL_VEBOX_CHROMA_DOWNSAMPLING_422_TYPE3_VERT_OFFSET           0
233 enum GFX_MEDIA_VEBOX_DI_OUTPUT_MODE
234 {
235     MEDIA_VEBOX_DI_OUTPUT_BOTH            = 0,
236     MEDIA_VEBOX_DI_OUTPUT_PREVIOUS        = 1,
237     MEDIA_VEBOX_DI_OUTPUT_CURRENT         = 2
238 };
239 
240 enum MEDIASTATE_DNDI_FIELDCOPY_SELECT
241 {
242     MEDIASTATE_DNDI_DEINTERLACE     = 0,
243     MEDIASTATE_DNDI_FIELDCOPY_PREV  = 1,
244     MEDIASTATE_DNDI_FIELDCOPY_NEXT  = 2
245 };
246 
247 struct VEBOX_SPATIAL_ATTRIBUTES_CONFIGURATION
248 {
249     // DWORD 0
250     union
251     {
252         // RangeThrStart0
253         struct
254         {
255             uint32_t       RangeThrStart0;
256         };
257 
258         uint32_t       Value;
259     } DW00;
260 
261     // DWORD 1
262     union
263     {
264         // RangeThrStart1
265         struct
266         {
267             uint32_t       RangeThrStart1;
268         };
269 
270         uint32_t       Value;
271     } DW01;
272 
273     // DWORD 2
274     union
275     {
276         // RangeThrStart2
277         struct
278         {
279             uint32_t       RangeThrStart2;
280         };
281 
282         uint32_t   Value;
283     } DW02;
284 
285     // DWORD 3
286     union
287     {
288         // RangeThrStart3
289         struct
290         {
291             uint32_t       RangeThrStart3;
292         };
293 
294         uint32_t   Value;
295     } DW03;
296 
297     // DWORD 4
298     union
299     {
300         // RangeThrStart4
301         struct
302         {
303             uint32_t       RangeThrStart4;
304         };
305 
306         uint32_t   Value;
307     } DW04;
308 
309     // DWORD 5
310     union
311     {
312         // RangeThrStart5
313         struct
314         {
315             uint32_t       RangeThrStart5;
316         };
317 
318         uint32_t   Value;
319     } DW05;
320 
321     // DWORD 6
322     union
323     {
324         // Reserved
325         struct
326         {
327             uint32_t       Reserved;
328         };
329 
330         uint32_t   Value;
331     } DW06;
332 
333     // DWORD 7
334     union
335     {
336         // Reserved
337         struct
338         {
339             uint32_t       Reserved;
340         };
341 
342         uint32_t   Value;
343     } DW07;
344 
345     // DWORD 8
346     union
347     {
348         // RangeWgt0
349         struct
350         {
351             uint32_t       RangeWgt0;
352         };
353 
354         uint32_t   Value;
355     } DW08;
356 
357     // DWORD 9
358     union
359     {
360         // RangeWgt1
361         struct
362         {
363             uint32_t       RangeWgt1;
364         };
365 
366         uint32_t   Value;
367     } DW09;
368 
369     // DWORD 10
370     union
371     {
372         // RangeWgt2
373         struct
374         {
375             uint32_t       RangeWgt2;
376         };
377 
378         uint32_t   Value;
379     } DW10;
380 
381     // DWORD 11
382     union
383     {
384         // RangeWgt3
385         struct
386         {
387             uint32_t       RangeWgt3;
388         };
389 
390         uint32_t   Value;
391     } DW11;
392 
393     // DWORD 12
394     union
395     {
396         // RangeWgt4
397         struct
398         {
399             uint32_t       RangeWgt4;
400         };
401 
402         uint32_t   Value;
403     } DW12;
404 
405     // DWORD 13
406     union
407     {
408         // RangeWgt5
409         struct
410         {
411             uint32_t       RangeWgt5;
412         };
413 
414         uint32_t   Value;
415     } DW13;
416 
417     // DWORD 14
418     union
419     {
420         // Reserved
421         struct
422         {
423             uint32_t       Reserved;
424         };
425 
426         uint32_t   Value;
427     } DW14;
428 
429     // DWORD 15
430     union
431     {
432         // Reserved
433         struct
434         {
435             uint32_t       Reserved;
436         };
437 
438         uint32_t   Value;
439     } DW15;
440 
441     // DWORD 16 - 41: DistWgt[5][5]
442     uint32_t DistWgt[5][5];
443 
444     // Padding for 32-byte alignment, VEBOX_SPATIAL_ATTRIBUTES_CONFIGURATION_G9 is 7 uint32_ts
445     uint32_t dwPad[7];
446 };
447 
448 //!
449 //! \brief Enumeration for the user feature key "Bypass Composition" values
450 //!
451 typedef enum _VPHAL_COMP_BYPASS_MODE
452 {
453     VPHAL_COMP_BYPASS_NOT_SET  = 0xffffffff,
454     VPHAL_COMP_BYPASS_DISABLED = 0x0,
455     VPHAL_COMP_BYPASS_ENABLED  = 0x1
456 } VPHAL_COMP_BYPASS_MODE, *PVPHAL_COMP_BYPASS_MODE;
457 
458 //!
459 //! \brief Kernel IDs
460 //!
461 typedef enum _VPHAL_VEBOX_KERNELID
462 {
463     KERNEL_RESERVED = 0,
464     KERNEL_UPDATEDNSTATE,
465     KERNEL_VEBOX_BASE_MAX,
466 } VPHAL_VEBOX_KERNELID, *PVPHAL_VEBOX_KERNELID;
467 
468 //!
469 //! \brief VPHAL Query Type for Vebox Statistics Surface
470 //!
471 typedef enum _VEBOX_STAT_QUERY_TYPE
472 {
473     VEBOX_STAT_QUERY_FMD_OFFEST = 0,
474     VEBOX_STAT_QUERY_WB_OFFEST,
475     VEBOX_STAT_QUERY_GNE_OFFEST,
476     VEBOX_STAT_QUERY_STD_OFFEST,
477     VEBOX_STAT_QUERY_GCC_OFFEST,
478     VEBOX_STAT_QUERY_PER_FRAME_SIZE
479 } VEBOX_STAT_QUERY_TYPE;
480 
481 #define VPHAL_VEBOX_RGB_HISTOGRAM_SIZE_PER_SLICE                (256 * 4)
482 #define VPHAL_VEBOX_ACE_HISTOGRAM_SIZE_PER_FRAME_PER_SLICE      (256 * 4)
483 
484 //!
485 //! \brief Secure Block Copy kernel width
486 //!
487 #define SECURE_BLOCK_COPY_KERNEL_SURF_WIDTH     64
488 
489 //!
490 //! \brief Secure Block Copy kernel block height
491 //!
492 #define SECURE_BLOCK_COPY_KERNEL_BLOCK_HEIGHT   24
493 
494 //!
495 //! \brief Secure Block Copy kernel inline data size
496 //!
497 #define SECURE_BLOCK_COPY_KERNEL_INLINE_SIZE    (1 * sizeof(uint32_t))
498 
499 #define VPHAL_NUM_RGB_CHANNEL                   3
500 #define VPHAL_NUM_FRAME_PREVIOUS_CURRENT        2
501 
502 //!
503 //! \brief Binding Table Index for Secure Block Copy kernel
504 //!
505 #define BI_SECURE_BLOCK_COPY_INPUT              0
506 #define BI_SECURE_BLOCK_COPY_OUTPUT             1
507 
508 //!
509 //! \brief Binding Table index for DN Update kernel
510 //!
511 #define BI_DN_STATISTICS_SURFACE                       0
512 #define BI_DN_VEBOX_STATE_SURFACE                      1
513 #define BI_DN_TEMP_SURFACE                             2
514 #define BI_DN_SPATIAL_ATTRIBUTES_CONFIGURATION_SURFACE 3
515 
516 
517 //!
518 //! \brief  Judgement for Vebox surface height alignment
519 //!         1. _a should be an integal of power(2,n)
520 //!
521 #define IS_VEBOX_SURFACE_HEIGHT_UNALIGNED(_pSrcSurface, _a)                                         \
522     ((MOS_MIN((uint32_t)_pSrcSurface->dwHeight, (uint32_t)_pSrcSurface->rcMaxSrc.bottom))             &   \
523     (uint32_t)((_a) - 1))
524 
525 typedef struct VPHAL_VEBOX_STATE_PARAMS *PVPHAL_VEBOX_STATE_PARAMS;
526 typedef struct VPHAL_VEBOX_STATE_PARAMS_EXT *PVPHAL_VEBOX_STATE_PARAMS_EXT;
527 struct VPHAL_VEBOX_STATE_PARAMS
528 {
VPHAL_VEBOX_STATE_PARAMSVPHAL_VEBOX_STATE_PARAMS529                                     VPHAL_VEBOX_STATE_PARAMS()
530                                     {
531                                         pVphalVeboxIecpParams = nullptr;
532                                         pVphalVeboxDndiParams = nullptr;
533                                     }
~VPHAL_VEBOX_STATE_PARAMSVPHAL_VEBOX_STATE_PARAMS534     virtual                         ~VPHAL_VEBOX_STATE_PARAMS()
535                                     {
536                                         pVphalVeboxIecpParams = nullptr;
537                                         pVphalVeboxDndiParams = nullptr;
538                                     }
InitVPHAL_VEBOX_STATE_PARAMS539     virtual void                    Init()
540                                     {
541                                         pVphalVeboxIecpParams = nullptr;
542                                         pVphalVeboxDndiParams = nullptr;
543                                     }
GetExtParamsVPHAL_VEBOX_STATE_PARAMS544     virtual PVPHAL_VEBOX_STATE_PARAMS_EXT   GetExtParams()  {return nullptr;}
545 
546     PMHW_VEBOX_DNDI_PARAMS          pVphalVeboxDndiParams;
547     PVPHAL_VEBOX_IECP_PARAMS        pVphalVeboxIecpParams;
548 };
549 
550 //!
551 //! \brief  Chroma Denoise params
552 //!
553 typedef struct _VPHAL_DNUV_PARAMS
554 {
555     uint32_t    dwHistoryInitUV;
556     uint32_t    dwHistoryDeltaUV;
557     uint32_t    dwHistoryMaxUV;
558     uint32_t    dwSTADThresholdU;
559     uint32_t    dwSTADThresholdV;
560     uint32_t    dwLTDThresholdU;
561     uint32_t    dwLTDThresholdV;
562     uint32_t    dwTDThresholdU;
563     uint32_t    dwTDThresholdV;
564 } VPHAL_DNUV_PARAMS, *PVPHAL_DNUV_PARAMS;
565 
566 typedef struct _VPHAL_VEBOX_SURFACE_STATE_CMD_PARAMS
567 {
568     PVPHAL_SURFACE                  pSurfInput;
569     PVPHAL_SURFACE                  pSurfOutput;
570     PVPHAL_SURFACE                  pSurfSTMM;
571     PVPHAL_SURFACE                  pSurfDNOutput;
572     PVPHAL_SURFACE                  pSurfSkinScoreOutput;
573     bool                            bDIEnable;
574 } VPHAL_VEBOX_SURFACE_STATE_CMD_PARAMS, *PVPHAL_VEBOX_SURFACE_STATE_CMD_PARAMS;
575 
576 //!
577 //! \brief  Structure to handle DNDI sampler states
578 //!
579 typedef struct _VPHAL_SAMPLER_STATE_DNDI_PARAM
580 {
581     uint32_t  dwDenoiseASDThreshold;
582     uint32_t  dwDenoiseHistoryDelta;
583     uint32_t  dwDenoiseMaximumHistory;
584     uint32_t  dwDenoiseSTADThreshold;
585     uint32_t  dwDenoiseSCMThreshold;
586     uint32_t  dwDenoiseMPThreshold;
587     uint32_t  dwLTDThreshold;
588     uint32_t  dwTDThreshold;
589     uint32_t  dwGoodNeighborThreshold;
590     bool      bDNEnable;
591     bool      bDIEnable;
592     bool      bDNDITopFirst;
593     bool      bProgressiveDN;
594     uint32_t  dwFMDFirstFieldCurrFrame;
595     uint32_t  dwFMDSecondFieldPrevFrame;
596 } VPHAL_SAMPLER_STATE_DNDI_PARAM, *PVPHAL_SAMPLER_STATE_DNDI_PARAM;
597 
598 //!
599 //! \brief Transient Render data populated for every BLT call
600 //!
601 typedef struct VPHAL_VEBOX_RENDER_DATA *PVPHAL_VEBOX_RENDER_DATA;
602 typedef struct VPHAL_VEBOX_RENDER_DATA_EXT *PVPHAL_VEBOX_RENDER_DATA_EXT;
603 struct VPHAL_VEBOX_RENDER_DATA
604 {
605 public:
VPHAL_VEBOX_RENDER_DATAVPHAL_VEBOX_RENDER_DATA606                                         VPHAL_VEBOX_RENDER_DATA()
607                                         {
608                                             // Flags
609                                             bRefValid      = false;
610                                             bSameSamples   = false;
611                                             bProgressive   = false;
612                                             bDenoise       = false;
613 #if VEBOX_AUTO_DENOISE_SUPPORTED
614                                             bAutoDenoise   = false;
615 #endif
616                                             bChromaDenoise = false;
617                                             bOutOfBound    = false;
618                                             bVDIWalker     = false;
619                                             bIECP          = false;
620                                             bColorPipe     = false;
621                                             bProcamp       = false;
622                                             // DNDI/Vebox
623                                             bDeinterlace   = false;
624                                             bSingleField   = false;
625                                             bTFF           = false;
626                                             bTopField      = false;
627                                             bBeCsc         = false;
628                                             bVeboxBypass   = false;
629                                             b60fpsDi       = false;
630                                             bQueryVariance = false;
631                                             // Surface Information
632                                             iFrame0        = 0;
633                                             iFrame1        = 0;
634                                             iCurDNIn       = 0;
635                                             iCurDNOut      = 0;
636                                             iCurHistIn     = 0;
637                                             iCurHistOut    = 0;
638                                             // Geometry
639                                             iBlocksX       = 0;
640                                             iBlocksY       = 0;
641                                             iBindingTable  = 0;
642                                             iMediaID0      = 0;
643                                             iMediaID1      = 0;
644                                             // Perf
645                                             PerfTag        = VPHAL_NONE;
646                                             // States
647                                             pMediaState        = nullptr;
648                                             pVeboxState        = nullptr;
649                                             pRenderTarget      = nullptr;
650                                             SamplerStateParams = { };
651                                             VeboxDNDIParams    = { };
652                                             pAlphaParams       = nullptr;
653                                             // Batch Buffer rendering arguments
654                                             BbArgs = { };
655                                             // Vebox output parameters
656                                             OutputPipe = VPHAL_OUTPUT_PIPE_MODE_COMP;
657                                             // Kernel Information
658                                             for (int i = 0; i < VPHAL_NUM_KERNEL_VEBOX; i++)
659                                             {
660                                                 pKernelParam[i] = nullptr;
661                                                 KernelEntry[i]  = { };
662                                             }
663                                             pDNUVParams          = nullptr;
664                                             iCurbeLength         = 0;
665                                             iCurbeOffset         = 0;
666                                             iInlineLength        = 0;
667                                             // Debug parameters
668                                             pKernelName          = nullptr;
669                                             Component            = COMPONENT_UNKNOWN;
670                                             // Memory compression flag
671                                             bEnableMMC           = false;
672 
673                                             pOutputTempField     = nullptr;
674 
675                                             fScaleX              = 0.0f;
676                                             fScaleY              = 0.0f;
677 
678                                             bHdr3DLut            = false;
679                                             bUseVEHdrSfc         = false;
680                                             uiMaxDisplayLum      = 4000;
681                                             uiMaxContentLevelLum = 1000;
682                                             hdrMode              = VPHAL_HDR_MODE_NONE;
683 
684                                             m_pVeboxStateParams  = nullptr;
685                                             m_pVeboxIecpParams   = nullptr;
686                                         }
687                                         VPHAL_VEBOX_RENDER_DATA(const VPHAL_VEBOX_RENDER_DATA&) = delete;
688                                         VPHAL_VEBOX_RENDER_DATA& operator=(const VPHAL_VEBOX_RENDER_DATA&) = delete;
689     virtual                             ~VPHAL_VEBOX_RENDER_DATA();
690     virtual MOS_STATUS                  Init();
GetVeboxStateParamsVPHAL_VEBOX_RENDER_DATA691     PVPHAL_VEBOX_STATE_PARAMS           GetVeboxStateParams()   { return m_pVeboxStateParams;}
GetVeboxIECPParamsVPHAL_VEBOX_RENDER_DATA692     PVPHAL_VEBOX_IECP_PARAMS            GetVeboxIECPParams()    { return m_pVeboxIecpParams; }
GetExtDataVPHAL_VEBOX_RENDER_DATA693     virtual PVPHAL_VEBOX_RENDER_DATA_EXT GetExtData()           { return nullptr;}
694 
695     // Flags
696     bool                                bRefValid;
697     bool                                bSameSamples;
698     bool                                bProgressive;
699     bool                                bDenoise;
700 #if VEBOX_AUTO_DENOISE_SUPPORTED
701     bool                                bAutoDenoise;
702 #endif
703     bool                                bChromaDenoise;
704     bool                                bOutOfBound;
705     bool                                bVDIWalker;
706 
707     bool                                bIECP;
708     bool                                bColorPipe;
709     bool                                bProcamp;
710 
711     // DNDI/Vebox
712     bool                                bDeinterlace;
713     bool                                bSingleField;
714     bool                                bTFF;
715     bool                                bTopField;
716     bool                                bBeCsc;
717     bool                                bVeboxBypass;
718     bool                                b60fpsDi;
719     bool                                bQueryVariance;
720 
721     // Surface Information
722     int32_t                             iFrame0;
723     int32_t                             iFrame1;
724     int32_t                             iCurDNIn;
725     int32_t                             iCurDNOut;
726     int32_t                             iCurHistIn;
727     int32_t                             iCurHistOut;
728 
729     // Geometry
730     int32_t                             iBlocksX;
731     int32_t                             iBlocksY;
732     int32_t                             iBindingTable;
733     int32_t                             iMediaID0;
734     int32_t                             iMediaID1;
735 
736     // Perf
737     VPHAL_PERFTAG                       PerfTag;
738 
739     // States
740     PRENDERHAL_MEDIA_STATE              pMediaState;
741     PMHW_VEBOX_HEAP_STATE               pVeboxState;
742     PVPHAL_SURFACE                      pRenderTarget;
743 
744     MHW_SAMPLER_STATE_PARAM             SamplerStateParams;
745 
746     MHW_VEBOX_DNDI_PARAMS               VeboxDNDIParams;
747 
748     PVPHAL_ALPHA_PARAMS                 pAlphaParams;
749 
750     // Batch Buffer rendering arguments
751     VPHAL_ADVPROC_BB_ARGS               BbArgs;
752 
753     // Vebox output parameters
754     VPHAL_OUTPUT_PIPE_MODE              OutputPipe;
755 
756     // Kernel Information
757     PRENDERHAL_KERNEL_PARAM             pKernelParam[VPHAL_NUM_KERNEL_VEBOX];
758     Kdll_CacheEntry                     KernelEntry[VPHAL_NUM_KERNEL_VEBOX];
759     PVPHAL_DNUV_PARAMS                  pDNUVParams;
760     int32_t                             iCurbeLength;
761     int32_t                             iCurbeOffset;
762     int32_t                             iInlineLength;
763 
764     // Debug parameters
765     char*                               pKernelName;                            //!< Kernel used for current rendering
766 
767     // Current component
768     MOS_COMPONENT                       Component;
769 
770     // Memory compression flag
771     bool                                bEnableMMC;                             //!< Enable memory compression flag
772 
773     // Temp surface for the field won't be output
774     PVPHAL_SURFACE                      pOutputTempField;
775 
776     // Scaling ratio from source to render target
777     // Scaling ratio is needed to determine if SFC or VEBOX is used
778     float                               fScaleX;                                //!< X Scaling ratio
779     float                               fScaleY;                                //!< Y Scaling ratio
780 
781     bool                                bHdr3DLut;                              //!< Enable 3DLut to process HDR
782     bool                                bUseVEHdrSfc;                              //!< Use SFC to perform CSC/Scaling for HDR content
783     uint32_t                            uiMaxDisplayLum;                        //!< Maximum Display Luminance
784     uint32_t                            uiMaxContentLevelLum;                   //!< Maximum Content Level Luminance
785     VPHAL_HDR_MODE                      hdrMode;
786 
787 protected:
788     // Vebox State Parameters
789     PVPHAL_VEBOX_STATE_PARAMS           m_pVeboxStateParams;                    //!< auto allocated param instance for set/submit VEBOX cmd
790     // Vebox IECP Parameters
791     PVPHAL_VEBOX_IECP_PARAMS            m_pVeboxIecpParams;                     //!< auto allocated param instance for set/submit VEBOX IECP cmd
792 };
793 
794 //!
795 //! \brief VPHAL VEBOX/IECP State
796 //!
797 typedef class VPHAL_VEBOX_STATE *PVPHAL_VEBOX_STATE;
798 class VPHAL_VEBOX_STATE : public RenderState
799 {
800 public:
801                                         VPHAL_VEBOX_STATE(
802                                             PMOS_INTERFACE                  pOsInterface,
803                                             PMHW_VEBOX_INTERFACE            pVeboxInterface,
804                                             PMHW_SFC_INTERFACE              pSfcInterface,
805                                             PRENDERHAL_INTERFACE            pRenderHal,
806                                             PVPHAL_VEBOX_EXEC_STATE         pVeboxExecState,
807                                             PVPHAL_RNDR_PERF_DATA           pPerfData,
808                                             const VPHAL_DNDI_CACHE_CNTL     &dndiCacheCntl,
809                                             MOS_STATUS                      *peStatus);
810                                         VPHAL_VEBOX_STATE(const VPHAL_VEBOX_STATE&) = delete;
811                                         VPHAL_VEBOX_STATE& operator=(const VPHAL_VEBOX_STATE&) = delete;
812     virtual                             ~VPHAL_VEBOX_STATE();
813 
AllocateExecRenderData()814     virtual MOS_STATUS                  AllocateExecRenderData()
815     {
816         if (!m_pLastExecRenderData)
817         {
818             m_pLastExecRenderData = MOS_New(VPHAL_VEBOX_RENDER_DATA);
819             if (!m_pLastExecRenderData)
820             {
821                 return MOS_STATUS_NO_SPACE;
822             }
823             m_pLastExecRenderData->Init();
824         }
825         return MOS_STATUS_SUCCESS;
826     }
GetLastExecRenderData()827     virtual PVPHAL_VEBOX_RENDER_DATA    GetLastExecRenderData()     { if (!m_pLastExecRenderData) { AllocateExecRenderData(); } return m_pLastExecRenderData; }
828 
829     //!
830     //! \brief    copy Report data
831     //! \details  copy Report data from this render
832     //! \param    [out] pReporting
833     //!           pointer to the Report data to copy data to
834     //!
835     void CopyReporting(VphalFeatureReport *pReporting);
836 
837     //!
838     //! \brief    copy Report data about features
839     //! \details  copy Report data from this render
840     //! \param    [out] pReporting
841     //!           pointer to the Report data to copy data to
842     //!
843     void CopyFeatureReporting(VphalFeatureReport *pReporting);
844 
845     //!
846     //! \brief    copy Report data about resources
847     //! \details  copy Report data from this render
848     //! \param    [out] pReporting
849     //!           pointer to the Report data to copy data to
850     //!
851     void CopyResourceReporting(VphalFeatureReport *pReporting);
852 
853     //!
854     //! \brief    Allocate sfc temp surface for Vebox output
855     //! \details  Allocate sfc temp surface for Vebox output
856     //! \param    VphalRenderer* pRenderer
857     //!           [in,out] VPHAL renderer pointer
858     //! \param    PCVPHAL_RENDER_PARAMS pcRenderParams
859     //!           [in] Const pointer to VPHAL render parameter
860     //! \param    PVPHAL_VEBOX_RENDER_DATA pRenderData
861     //!           [in] pointer to VPHAL VEBOX render parameter
862     //! \param    PVPHAL_SURFACE pInSurface
863     //!           [in] Pointer to input surface
864     //! \param    PVPHAL_SURFACE pOutSurface
865     //!           [in] Pointer to output surface
866     //! \return   MOS_STATUS
867     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
868     //!
869     MOS_STATUS AllocateSfcTempSurfaces(
870         VphalRenderer                  *pRenderer,
871         PCVPHAL_RENDER_PARAMS           pcRenderParams,
872         PVPHAL_VEBOX_RENDER_DATA        pRenderData,
873         PVPHAL_SURFACE                  pInSurface,
874         PVPHAL_SURFACE                  pOutSurface);
875 
876     //!
877     //! \brief    Allocate sfc 2pass 2nd time surface for Vebox output, only for multi-lays.
878     //! \details  Allocate sfc temp surface for Vebox output
879     //! \param    VphalRenderer* pRenderer
880     //!           [in,out] VPHAL renderer pointer
881     //! \param    PCVPHAL_RENDER_PARAMS pcRenderParams
882     //!           [in] Const pointer to VPHAL render parameter
883     //! \param    PVPHAL_VEBOX_RENDER_DATA pRenderData
884     //!           [in] pointer to VPHAL VEBOX render parameter
885     //! \param    PVPHAL_SURFACE pInSurface
886     //!           [in] Pointer to input surface
887     //! \param    PVPHAL_SURFACE pOutSurface
888     //!           [in] Pointer to output surface
889     //! \return   MOS_STATUS
890     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
891     //!
892     MOS_STATUS AllocateSfc2ndTempSurfaces(
893       VphalRenderer                  *pRenderer,
894       PCVPHAL_RENDER_PARAMS           pcRenderParams,
895       PVPHAL_VEBOX_RENDER_DATA        pRenderData,
896       PVPHAL_SURFACE                  pInSurface,
897       PVPHAL_SURFACE                  pOutSurface);
898 
899     // External components
900     PMHW_VEBOX_INTERFACE            m_pVeboxInterface;                            //!< Pointer to MHW Vebox Structure Interface
901     PMHW_SFC_INTERFACE              m_pSfcInterface;                              //!< Pointer to SFC Structure Interface
902     Kdll_State                      *m_pKernelDllState;                           //!< Kernel DLL state
903     VpKernelID                      m_currKernelId;                               //!< Kernel ID
904 
905     VphalSfcState                   *m_sfcPipeState;                              //!< SFC state
906 
907     // Execution state
908     PVPHAL_VEBOX_RENDER_DATA        m_pLastExecRenderData;                        //!< Cache last render operation info
909     PVPHAL_VEBOX_EXEC_STATE         m_pVeboxExecState;                            //!< Vebox Execution State
910 
911     // CSC in VEBOX params
912     VPHAL_CSPACE                    CscOutputCspace;                            //!< Cspace of Output Frame
913     VPHAL_CSPACE                    CscInputCspace;                             //!< Cspace of Input frame
914     float                           fCscCoeff[9];                               //!< [3x3] Coeff matrix for CSC
915     float                           fCscInOffset[3];                            //!< [3x1] Input Offset matrix for CSC
916     float                           fCscOutOffset[3];                           //!< [3x1] Output Offset matrix for CSC
917 
918     // Dynamic linking filter
919     Kdll_FilterEntry                SearchFilter[2];
920 
921     // Threshold for discontinuity check
922     int32_t                         iSameSampleThreshold;
923 
924     // Resources
925     VPHAL_SURFACE                   *m_currentSurface;                          //!< Current frame
926     VPHAL_SURFACE                   *m_previousSurface;                         //!< Previous frame
927     RENDERHAL_SURFACE               RenderHalCurrentSurface;                    //!< Current frame for MHW
928     RENDERHAL_SURFACE               RenderHalPreviousSurface;                   //!< Previous frame for MHW
929 
930     union
931     {
932         //  DNDI/VEBOX
933         struct
934         {
935             VPHAL_SURFACE           *FFDISurfaces[VPHAL_MAX_NUM_FFDI_SURFACES];  //!< FFDI output surface structure
936         };
937     };
938     VPHAL_SURFACE                   VeboxRGBHistogram = {};            //!< VEBOX RGB Histogram surface for Vebox Gen9+
939     VPHAL_SURFACE                   VeboxStatisticsSurface;                     //!< Statistics Surface for VEBOX
940     RENDERHAL_SURFACE               RenderHalVeboxStatisticsSurface;            //!< Statistics Surface for VEBOX for MHW
941 #if VEBOX_AUTO_DENOISE_SUPPORTED
942     VPHAL_SURFACE                   VeboxTempSurface;                           //!< Temp Surface for Vebox State update kernels
943     VPHAL_SURFACE                   VeboxSpatialAttributesConfigurationSurface; //!< Spatial Attributes Configuration Surface for DN kernel Gen9+
944     RENDERHAL_SURFACE               RenderHalVeboxSpatialAttributesConfigurationSurface; //!< Spatial Attributes Configuration Surface for DN kernel Gen9+ for MHW
945     VPHAL_SURFACE                   VeboxHeapResource;                          //!< Vebox Heap resource for DN kernel
946     VPHAL_SURFACE                   tmpResource;                                //!< Temp resource for DN kernel
947     RENDERHAL_SURFACE               RenderHalVeboxHeapResource;                 //!< Vebox Heap resource for DN kernel for MHW
948     RENDERHAL_SURFACE               RenderHalTmpResource;                       //!< Temp resource for DN kernel for MHW
949 #endif
950     union
951     {
952         // DNDI
953         struct
954         {
955             VPHAL_SURFACE           *FFDNSurfaces[VPHAL_NUM_FFDN_SURFACES];     //!< Denoise output surfaces
956             VPHAL_SURFACE           STMMSurfaces[VPHAL_NUM_STMM_SURFACES];      //!< Motion history (DI)
957         };
958     };
959 
960     // BNE system memory pointer
961     uint8_t*                        pBNEData;                                   //!< System memory for GNE calculating
962     uint32_t                        dwBNESize;                                  //!< System memory size for BNE surface
963 
964     // Statistics
965     uint32_t                        dwVeboxPerBlockStatisticsWidth;             //!< Per block statistics width
966     uint32_t                        dwVeboxPerBlockStatisticsHeight;            //!< Per block statistics height
967 
968     // Cache attributes
969     VPHAL_DNDI_CACHE_CNTL           DnDiSurfMemObjCtl;                          //!< Surface memory object control
970 
971     // Batch Buffers
972     int32_t                         iBatchBufferCount;                          //!< Number of batch buffers
973     MHW_BATCH_BUFFER                BatchBuffer[VPHAL_DNDI_BUFFERS_MAX];        //!< Batch buffers
974     VPHAL_BATCH_BUFFER_PARAMS       BufferParam[VPHAL_DNDI_BUFFERS_MAX];        //!< Batch buffer parameters
975 
976     // Denoise output control
977     int32_t                         iCurDNIndex;                                //!< Current index of Denoise Output
978 
979     // DNDI
980     struct
981     {
982         int32_t                     iNumFFDISurfaces;                           //!< Actual number of FFDISurfaces. Is <= VPHAL_NUM_FFDI_SURFACES
983         int32_t                     iCurStmmIndex;                              //!< Current index of Motion History Buffer
984         uint32_t                    dwGlobalNoiseLevel;                         //!< Global Noise Level
985     };
986 
987     // Chroma DN
988     struct
989     {
990         int32_t                     iCurHistIndex;                              //!< Current index of Chroma Denoise History Buffer
991         uint32_t                    dwGlobalNoiseLevelU;                        //!< Global Noise Level for U
992         uint32_t                    dwGlobalNoiseLevelV;                        //!< Global Noise Level for V
993         bool                        bFirstFrame;                                //!< First frame case for Chroma DN
994     };
995 
996     // timestamps for DI output control
997     int32_t                         iCurFrameID;                                //!< Current Frame ID
998     int32_t                         iPrvFrameID;                                //!< Previous Frame ID
999 
1000     // for Pre-Processing
1001     bool                            bSameSamples;                               //!< True for second DI
1002     int32_t                         iCallID;                                    //!< Current render call ID;
1003     bool                            bDNEnabled;                                 //!< DN was enabled in the previous call
1004     bool                            bDIEnabled;                                 //!< DI was enabled in the previous call
1005 
1006     // Platform dependent states
1007     PRENDERHAL_KERNEL_PARAM         pKernelParamTable;                          //!< Kernel Parameter table
1008 
1009     // HW Params
1010     uint32_t                        dwKernelUpdate;                             //!< Enable/Disable kernel update
1011 
1012     uint32_t                        dwCompBypassMode;                           //!< Bypass Composition Optimization read from User feature keys
1013 
1014     // Debug parameters
1015     char*                           pKernelName;                                //!< Kernel Used for current rendering
1016     bool                            bNullHwRenderDnDi;                          //!< Null rendering for DnDi function
1017 
1018     bool                            bEnableMMC;                                 //!< Memory compression enbale flag - read from User feature keys
1019     bool                            bDisableTemporalDenoiseFilter;              //!< Temporal denoise filter disable flag - read from User feature keys
1020     bool                            bDisableTemporalDenoiseFilterUserKey;       //!< Backup temporal denoise filter disable flag - read from User feature keys
1021 
1022     // S3D channel
1023     uint32_t                         uiCurrentChannel;                           //!< 0=StereoLeft or nonStereo, 1=StereoRight. N/A in nonStereo
1024 
1025     MOS_GPU_CONTEXT                  RenderGpuContext;                           //!< Render GPU context
1026 
1027     VPHAL_SURFACE                    Vebox3DLookUpTables = {};
1028     VPHAL_SURFACE                    SfcTempSurface = {};
1029     VPHAL_SURFACE                    Sfc2ndTempSurface = {};
1030 
1031     VphalHVSDenoiser                 *m_hvsDenoiser;                             //!< Human Vision System Based Denoiser - Media Kernel to generate DN parameter
1032     uint8_t                          *m_hvsKernelBinary;                         //!< Human Vision System Based Denoiser - Pointer to HVS kernel Binary
1033     uint32_t                         m_hvsKernelBinarySize;                      //!< Human Vision System Based Denoiser - Size of HVS kernel Binary
1034 
1035     bool                             bPhasedSubmission;                          //!< Flag to indicate if secondary command buffers are submitted together (Win) or separately (Linux)
1036 
1037 protected:
1038     PVPHAL_VEBOX_IECP_RENDERER      m_IECP;                                     //!< pointer to IECP Renderer module, which contains more filters like TCC, STE.
1039 
1040 public:
1041     //!
1042     //! \brief    Initialize VEBOX state
1043     //! \param    [in] pSettings
1044     //!           Pointer to VPHAL settings
1045     //! \param    [in] pKernelDllState
1046     //!           Pointer to KDLL state
1047     //! \return   MOS_STATUS
1048     //!           MOS_STATUS_SUCCESS if successful, otherwise failed
1049     //!
1050     virtual MOS_STATUS Initialize(
1051         const VphalSettings         *pSettings,
1052         Kdll_State                  *pKernelDllState);
1053 
1054     virtual void Destroy();
1055 
1056     //!
1057     //! \brief    RenderState Rendering
1058     //! \details  VpHal RenderState entry
1059     //! \param    [in] pcRenderParams
1060     //!           Pointer to Render parameters
1061     //! \param    [in,out] pRenderPassData
1062     //!           Pointer to Render data
1063     //! \return   MOS_STATUS
1064     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1065     //!
1066     virtual MOS_STATUS Render(
1067         PCVPHAL_RENDER_PARAMS  pcRenderParams,
1068         RenderpassData         *pRenderPassData);
1069 
1070     //!
1071     //! \brief    Set DI output frame
1072     //! \details  Choose 2nd Field of Previous frame or 1st Field of Current frame
1073     //!           or both frames
1074     //! \param    [in] pRenderData
1075     //!           Pointer to Render data
1076     //! \param    [in] pVeboxState
1077     //!           Pointer to Vebox State
1078     //! \param    [in] pVeboxMode
1079     //!           Pointer to Vebox Mode
1080     //! \return   GFX_MEDIA_VEBOX_DI_OUTPUT_MODE
1081     //!           Return Previous/Current/Both frames
1082     //!
1083     virtual GFX_MEDIA_VEBOX_DI_OUTPUT_MODE SetDIOutputFrame(
1084         PVPHAL_VEBOX_RENDER_DATA pRenderData,
1085         PVPHAL_VEBOX_STATE       pVeboxState,
1086         PMHW_VEBOX_MODE          pVeboxMode);
1087 
1088     //!
1089     //! \brief    Judge if render is needed
1090     //! \details  Check Render parameter/data if render needed
1091     //! \param    [in] pcRenderParams
1092     //!           Pointer to Render parameters
1093     //! \param    [in,out] pRenderPassData
1094     //!           Pointer to Render data
1095     //! \return   bool
1096     //!           true if meeded. Else false
1097     //!
1098     virtual bool IsNeeded(
1099         PCVPHAL_RENDER_PARAMS  pcRenderParams,
1100         RenderpassData         *pRenderPassData) = 0;
1101 
1102     //!
1103     //! \brief    Judge if render support multiple stream rendering
1104     //! \details  Judge if render support multiple stream rendering
1105     //! \return   bool
1106     //!           true if supported. Else false
1107     //!
IsMultipleStreamSupported()1108     virtual bool IsMultipleStreamSupported()
1109     {
1110         // VEBOX render is for single layer only.
1111         return false;
1112     }
1113 
1114     virtual MOS_STATUS AllocateResources() = 0;
1115 
1116     virtual void FreeResources() = 0;
1117 
1118     //!
1119     //! \brief    Setup kernels for Vebox auto mode features
1120     //! \details  Setup kernels that co-operate with Vebox auto mode features
1121     //! \param    [in] iKDTIndex
1122     //!           Index to Kernel Parameter Array (defined platform specific)
1123     //! \return   MOS_STATUS
1124     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1125     //!
1126     virtual MOS_STATUS SetupVeboxKernel(
1127         int32_t                     iKDTIndex) = 0;
1128 
1129     virtual MOS_STATUS SetupDiIecpState(
1130         bool                        bDiScdEnable,
1131         PMHW_VEBOX_DI_IECP_CMD_PARAMS
1132                                     pVeboxDiIecpCmdParams) = 0;
1133 
1134     virtual void SetupSurfaceStates(
1135         bool                        bDiVarianceEnable,
1136         PVPHAL_VEBOX_SURFACE_STATE_CMD_PARAMS
1137                                     pVeboxSurfaceStateCmdParams) = 0;
1138 
1139     virtual MOS_STATUS VeboxQueryStatLayout(
1140         VEBOX_STAT_QUERY_TYPE           QueryType,
1141         uint32_t*                       pQuery) = 0;
1142     //!
1143     //! \brief    Update RenderGpuContext
1144     //! \details  Update RenderGpuContext
1145     //! \param    [in] renderGpuContext
1146     //! \return   MOS_STATUS
1147     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1148     //!
1149     virtual MOS_STATUS UpdateRenderGpuContext(
1150         MOS_GPU_CONTEXT renderGpuContext);
1151 
1152 #if VEBOX_AUTO_DENOISE_SUPPORTED
1153     //!
1154     //! \brief    Load update kernel curbe data
1155     //! \details  Loads the static data of update kernel to curbe
1156     //! \param    [out] iCurbeOffsetOutDN
1157     //!           Pointer to DN kernel curbe offset
1158     //! \return   MOS_STATUS
1159     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1160     //!
1161     virtual MOS_STATUS LoadUpdateDenoiseKernelStaticData(
1162         int32_t*                        iCurbeOffsetOutDN) = 0;
1163 
1164     //!
1165     //! \brief    Setup surface states for Denoise
1166     //! \details  Setup Surface State for Vebox States Auto DN kernel
1167     //! \return   MOS_STATUS
1168     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1169     //!
1170     virtual MOS_STATUS SetupSurfaceStatesForDenoise() = 0;
1171 #endif
1172 
1173     virtual MOS_STATUS PostCompRender(
1174         PVPHAL_VEBOX_EXEC_STATE         pVeboxExecState,
1175         PVPHAL_SURFACE                  pPriSurface);
1176 
1177     virtual bool IsFormatSupported(
1178         PVPHAL_SURFACE              pSrcSurface) = 0;
1179 
1180     virtual bool IsRTFormatSupported(
1181         PVPHAL_SURFACE                  pSrcSurface,
1182         PVPHAL_SURFACE                  pRTSurface) = 0;
1183 
1184     virtual bool IsDnFormatSupported(
1185         PVPHAL_SURFACE                  pSrcSurface) = 0;
1186 
1187     virtual bool IsDiFormatSupported(
1188         PVPHAL_SURFACE              pSrcSurface) = 0;
1189 
1190     virtual bool UseKernelResource()=0;
1191 
1192     virtual void VeboxGetBeCSCMatrix(
1193         PVPHAL_SURFACE                  pSrcSurface,
1194         PVPHAL_SURFACE                  pOutSurface) = 0;
1195 
1196     //!
1197     //! \brief    Check if the BeCSCMatrx need to be calculated
1198     //! \param    [in] pSrcSurface
1199     //!           Pointer to source surface
1200     //! \param    [in] pOutSurface
1201     //!           Pointer to output surface
1202     //! \return   Return MOS_STATUS_SUCCESS if successful, otherwise failed
1203     //!
VeboxIsBeCSCMatrixNeeded(PVPHAL_SURFACE pSrcSurface,PVPHAL_SURFACE pOutSurface)1204     virtual bool VeboxIsBeCSCMatrixNeeded(
1205         PVPHAL_SURFACE                  pSrcSurface,
1206         PVPHAL_SURFACE                  pOutSurface)
1207     {
1208         if (!pSrcSurface || !pOutSurface)
1209         {
1210             VPHAL_RENDER_ASSERTMESSAGE("Null surface pointer");
1211             return false;
1212         }
1213 
1214         if ((CscInputCspace  != pSrcSurface->ColorSpace) ||
1215             (CscOutputCspace != pOutSurface->ColorSpace))
1216         {
1217             return true;
1218         }
1219         else
1220         {
1221             return false;
1222 
1223         }
1224     }
1225 
IsIECPEnabled()1226     virtual bool IsIECPEnabled()
1227     {
1228         return GetLastExecRenderData()->bIECP;
1229     }
IsQueryVarianceEnabled()1230     virtual bool IsQueryVarianceEnabled() {return false;}
1231 
1232     virtual MOS_STATUS VeboxSetPerfTag(MOS_FORMAT               srcFmt);
VeboxClearFmdStates()1233     virtual void VeboxClearFmdStates() { }
1234 
1235 protected:
1236     //!
1237     //! \brief    Vebox set up vebox state heap
1238     //! \details  Setup Vebox indirect states: DNDI and etc
1239     //! \param    [in] pSrcSurface
1240     //!           Pointer to input surface of Vebox
1241     //! \param    [in] pOutSurface
1242     //!           Pointer to output surface of Vebox
1243     //! \return   MOS_STATUS
1244     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1245     //!
1246     virtual MOS_STATUS VeboxSetupIndirectStates(
1247         PVPHAL_SURFACE                  pSrcSurface,
1248         PVPHAL_SURFACE                  pOutSurface);
1249 
1250     //!
1251     //! \brief    Vebox Set VEBOX parameter
1252     //! \details  Set up the VEBOX parameter value
1253     //! \param    [in] pSrcSurface
1254     //!           Pointer to input surface of Vebox
1255     //! \return   MOS_STATUS
1256     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1257     //!
1258     virtual MOS_STATUS VeboxSetDNDIParams(
1259         PVPHAL_SURFACE              pSrcSurface);
1260 
1261     //!
1262     //! \brief    Vebox Set FMD parameter
1263     //! \details  Set up the FMD parameters for DNDI State
1264     //! \param    [out] pLumaParams
1265     //!           Pointer to DNDI Param for set FMD parameters
1266     //! \return   MOS_STATUS
1267     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1268     //!
1269     virtual MOS_STATUS VeboxSetFMDParams(
1270         PVPHAL_SAMPLER_STATE_DNDI_PARAM     pLumaParams);
1271 
1272     //!
1273     //! \brief    Vebox Populate DNDI parameters
1274     //! \details  Populate the VEBOX state DNDI parameters to VEBOX RenderData
1275     //! \param    [in] pLumaParams
1276     //!           Pointer to Luma DN and DI parameter
1277     //! \param    [in] pChromaParams
1278     //!           Pointer to Chroma DN parameter
1279     //! \return   MOS_STATUS
1280     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1281     //!
1282     virtual MOS_STATUS VeboxPopulateDNDIParams(
1283         PVPHAL_SAMPLER_STATE_DNDI_PARAM pLumaParams,
1284         PVPHAL_DNUV_PARAMS              pChromaParams);
1285 
1286     //!
1287     //! \brief    Flush command buffer for update kernels
1288     //! \details  Flush the command buffer for Update kernels
1289     //! \return   MOS_STATUS
1290     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1291     //!
1292     virtual MOS_STATUS VeboxFlushUpdateStateCmdBuffer();
1293 
1294     //!
1295     //! \brief    Copy Vebox state heap
1296     //! \details  Call HW interface function,
1297     //!           use Secure_Block_Copy kernel,
1298     //!           copy Vebox state heap between different memory
1299     //! \return   MOS_STATUS
1300     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1301     //!
1302     virtual MOS_STATUS VeboxCopyVeboxStates();
1303 
1304     //!
1305     //! \brief    Copy and update vebox state
1306     //! \details  Copy and update vebox state for input frame.
1307     //! \param    [in] pSrcSurface
1308     //!           Pointer to input surface of Vebox
1309     //! \return   MOS_STATUS
1310     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1311     //!
1312     virtual MOS_STATUS VeboxCopyAndUpdateVeboxState(
1313         PVPHAL_SURFACE           pSrcSurface);
1314 
1315     //!
1316     //! \brief    Vebox state heap update for auto mode features
1317     //! \details  Update Vebox indirect states for auto mode features
1318     //! \param    [in] pSrcSurface
1319     //!           Pointer to input surface of Vebox
1320     //! \return   MOS_STATUS
1321     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1322     //!
1323     virtual MOS_STATUS VeboxUpdateVeboxStates(
1324         PVPHAL_SURFACE              pSrcSurface);
1325 
1326     //!
1327     //! \brief    Doing prepare stage tasks for VeboxSendVeboxCmd
1328     //!           Parameters might remain unchanged in case
1329     //! \param    [out] CmdBuffer
1330     //!           reference to Cmd buffer control struct
1331     //! \param    [out] GenericPrologParams
1332     //!           Generic prolog params struct to be set
1333     //! \param    [out] GpuStatusBuffer
1334     //!           GpuStatusBuffer resource to be set
1335     //! \param    [out] iRemaining
1336     //!           integer showing initial cmd buffer usage
1337     //! \return   MOS_STATUS
1338     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1339     //!
1340     virtual MOS_STATUS VeboxSendVeboxCmd_Prepare(
1341         MOS_COMMAND_BUFFER                      &CmdBuffer,
1342         RENDERHAL_GENERIC_PROLOG_PARAMS         &GenericPrologParams,
1343         MOS_RESOURCE                            &GpuStatusBuffer,
1344         int32_t                                 &iRemaining);
1345 
1346     //!
1347     //! \brief    Check whether the Vebox command parameters are correct
1348     //! \param    [in] VeboxStateCmdParams
1349     //!           MHW vebox state cmd params
1350     //! \param    [in] VeboxDiIecpCmdParams
1351     //!           DiIecpCmd params struct
1352     //! \return   MOS_STATUS
1353     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1354     //!
1355     virtual MOS_STATUS VeboxIsCmdParamsValid(
1356         const MHW_VEBOX_STATE_CMD_PARAMS        &VeboxStateCmdParams,
1357         const MHW_VEBOX_DI_IECP_CMD_PARAMS      &VeboxDiIecpCmdParams);
1358 
1359     //!
1360     //! \brief    Render the Vebox Cmd buffer for VeboxSendVeboxCmd
1361     //!           Parameters might remain unchanged in case
1362     //! \param    [in,out] CmdBuffer
1363     //!           reference to Cmd buffer control struct
1364     //! \param    [out] VeboxDiIecpCmdParams
1365     //!           DiIecpCmd params struct to be set
1366     //! \param    [out] VeboxSurfaceStateCmdParams
1367     //!           VPHAL surface state cmd to be set
1368     //! \param    [out] MhwVeboxSurfaceStateCmdParams
1369     //!           MHW surface state cmd to be set
1370     //! \param    [out] VeboxStateCmdParams
1371     //!           MHW vebox state cmd to be set
1372     //! \param    [out] FlushDwParams
1373     //!           MHW MI_FLUSH_DW cmd to be set
1374     //! \param    [in] pGenericPrologParams
1375     //!           pointer to Generic prolog params struct to send to cmd buffer header
1376     //! \return   MOS_STATUS
1377     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1378     //!
1379     virtual MOS_STATUS VeboxRenderVeboxCmd(
1380         MOS_COMMAND_BUFFER                      &CmdBuffer,
1381         MHW_VEBOX_DI_IECP_CMD_PARAMS            &VeboxDiIecpCmdParams,
1382         VPHAL_VEBOX_SURFACE_STATE_CMD_PARAMS    &VeboxSurfaceStateCmdParams,
1383         MHW_VEBOX_SURFACE_STATE_CMD_PARAMS      &MhwVeboxSurfaceStateCmdParams,
1384         MHW_VEBOX_STATE_CMD_PARAMS              &VeboxStateCmdParams,
1385         MHW_MI_FLUSH_DW_PARAMS                  &FlushDwParams,
1386         PRENDERHAL_GENERIC_PROLOG_PARAMS        pGenericPrologParams);
1387 
1388     //!
1389     //! \brief    Render pipe cmds to Vebox Cmd buffer for VeboxSendVeboxCmd
1390     //! \details  Render pipe cmds to Vebox Cmd buffer for VeboxSendVeboxCmd
1391     //!           Parameters might remain unchanged in case
1392     //! \param    pVeboxInterface
1393     //!           [in] Pointers to Vebox Interface
1394     //! \param    pMhwMiInterface
1395     //!           [in] Pointers to MI HW Interface
1396     //! \param    pVeboxSurfaceParams
1397     //!           [in] Pointers to Vebox Surface Params Interface
1398     //! \param    pVeboxDiIecpCmdParams
1399     //!           [in] Pointers to DI/IECP CMD Params Interface
1400     //! \param    pCmdBuffer
1401     //!           [in,out] pointer to CMD buffer
1402     //! \return   MOS_STATUS
1403     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1404     //!
VeboxRenderMMCPipeCmd(PMHW_VEBOX_INTERFACE pVeboxInterface,MhwMiInterface * pMhwMiInterface,PMHW_VEBOX_SURFACE_STATE_CMD_PARAMS pVeboxSurfaceParams,PMHW_VEBOX_DI_IECP_CMD_PARAMS pVeboxDiIecpCmdParams,PMOS_COMMAND_BUFFER pCmdBuffer)1405     virtual MOS_STATUS VeboxRenderMMCPipeCmd(
1406         PMHW_VEBOX_INTERFACE                pVeboxInterface,
1407         MhwMiInterface *                    pMhwMiInterface,
1408         PMHW_VEBOX_SURFACE_STATE_CMD_PARAMS pVeboxSurfaceParams,
1409         PMHW_VEBOX_DI_IECP_CMD_PARAMS       pVeboxDiIecpCmdParams,
1410         PMOS_COMMAND_BUFFER                 pCmdBuffer)
1411     {
1412         MOS_UNUSED(*pCmdBuffer);
1413         return MOS_STATUS_SUCCESS;
1414     }
1415 
1416     //!
1417     //! \brief    Vebox send Vebox ring HW commands
1418     //! \details  Send Vebox ring Commands.
1419     //! \return   MOS_STATUS
1420     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1421     //!
1422     virtual MOS_STATUS VeboxSendVeboxCmd();
1423 
1424     //!
1425     //! \brief    Sync for Indirect state Copy and Update Kernels
1426     //! \details  Sync for Indirect state Copy and Update Kernels before Send Vebox ring Commands.
1427     //! \return   MOS_STATUS
1428     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1429     //!
1430     virtual MOS_STATUS VeboxSyncIndirectStateCmd();
1431 
1432     //!
1433     //! \brief    Set extra parameters before submit Vebox Cmd
1434     //! \details  Set extra parameters before submit Vebox Cmd
1435     //! \return   MOS_STATUS
1436     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1437     //!
VeboxSendVeboxCmdSetParamBeforeSubmit()1438     virtual MOS_STATUS VeboxSendVeboxCmdSetParamBeforeSubmit()
1439     {       return MOS_STATUS_SUCCESS; }
1440 
1441     //!
1442     //! \brief    Vebox set common rendering flag
1443     //! \details  Common flags should be set before other flags,
1444     //!           and it should be independent with other flags
1445     //! \param    [in] pSrc
1446     //!           Pointer to input surface of Vebox
1447     //! \param    [in] pRenderTarget
1448     //!           Pointer to Render targe surface of VPP BLT
1449     //! \return   void
1450     //!
1451     virtual void VeboxSetCommonRenderingFlags(
1452         PVPHAL_SURFACE              pSrc,
1453         PVPHAL_SURFACE              pRenderTarget);
1454 
1455     //!
1456     //! \brief    Vebox set Field related rendering flag
1457     //! \details  Set Field related flags for interlaced or related features
1458     //! \param    [in] pSrc
1459     //!           Pointer to input surface of Vebox
1460     //! \return   void
1461     //!
1462     virtual void VeboxSetFieldRenderingFlags(
1463         PVPHAL_SURFACE              pSrc);
1464 
1465     //!
1466     //! \brief    Vebox set rendering flag
1467     //! \details  Setup Rendering Flags due to different usage case - main entrance
1468     //! \param    [in] pSrc
1469     //!           Pointer to input surface of Vebox
1470     //! \param    [in] pRenderTarget
1471     //!           Pointer to Render targe surface of VPP BLT
1472     //! \return   void
1473     //!
1474     virtual void VeboxSetRenderingFlags(
1475         PVPHAL_SURFACE              pSrc,
1476         PVPHAL_SURFACE              pRenderTarget);
1477 
1478     //!
1479     //! \brief    Copy Dndi Surface Params
1480     //! \details  Copies surface params to output surface
1481     //!           based on src and temp surfaces
1482     //! \param    [in] pSrcSurface
1483     //!           Pointer to Source Surface
1484     //! \param    [in] pTempSurface
1485     //!           Pointer to Temporary Surface
1486     //! \param    [in,out] pOutSurface
1487     //!           Pointer to Out Surface
1488     //! \return   void
1489     //!
1490     virtual void VeboxCopySurfaceParams(
1491         const PVPHAL_SURFACE            pSrcSurface,
1492         const PVPHAL_SURFACE            pTempSurface,
1493         PVPHAL_SURFACE                  pOutSurface);
1494 
1495     //!
1496     //! \brief    Vebox initialize STMM History
1497     //! \details  Initialize STMM History surface
1498     //! Description:
1499     //!   This function is used by VEBox for initializing
1500     //!   the STMM surface.  The STMM / Denoise history is a custom surface used
1501     //!   for both input and output. Each cache line contains data for 4 4x4s.
1502     //!   The STMM for each 4x4 is 8 bytes, while the denoise history is 1 byte
1503     //!   and the chroma denoise history is 1 byte for each U and V.
1504     //!   Byte    Data\n
1505     //!   0       STMM for 2 luma values at luma Y=0, X=0 to 1\n
1506     //!   1       STMM for 2 luma values at luma Y=0, X=2 to 3\n
1507     //!   2       Luma Denoise History for 4x4 at 0,0\n
1508     //!   3       Not Used\n
1509     //!   4-5     STMM for luma from X=4 to 7\n
1510     //!   6       Luma Denoise History for 4x4 at 0,4\n
1511     //!   7       Not Used\n
1512     //!   8-15    Repeat for 4x4s at 0,8 and 0,12\n
1513     //!   16      STMM for 2 luma values at luma Y=1,X=0 to 1\n
1514     //!   17      STMM for 2 luma values at luma Y=1, X=2 to 3\n
1515     //!   18      U Chroma Denoise History\n
1516     //!   19      Not Used\n
1517     //!   20-31   Repeat for 3 4x4s at 1,4, 1,8 and 1,12\n
1518     //!   32      STMM for 2 luma values at luma Y=2,X=0 to 1\n
1519     //!   33      STMM for 2 luma values at luma Y=2, X=2 to 3\n
1520     //!   34      V Chroma Denoise History\n
1521     //!   35      Not Used\n
1522     //!   36-47   Repeat for 3 4x4s at 2,4, 2,8 and 2,12\n
1523     //!   48      STMM for 2 luma values at luma Y=3,X=0 to 1\n
1524     //!   49      STMM for 2 luma values at luma Y=3, X=2 to 3\n
1525     //!   50-51   Not Used\n
1526     //!   36-47   Repeat for 3 4x4s at 3,4, 3,8 and 3,12\n
1527     //! \param    [in] iSurfaceIndex
1528     //!           Index of STMM surface array
1529     //! \return   MOS_STATUS
1530     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1531     //!
1532     MOS_STATUS VeboxInitSTMMHistory(
1533         int32_t                         iSurfaceIndex);
1534 
1535 #if VEBOX_AUTO_DENOISE_SUPPORTED
1536     //!
1537     //! \brief    Vebox initialize Spatial Configuration Surface
1538     //! \details  Initialize Spatial Configuration History surface
1539     //! Description:
1540     //!   This function is used by VEBox for initializing
1541     //!   the Spatial Attributes Configuration surface.
1542     //!   The GEN9+ DN kernel will use the init data in this surface and write back output data
1543     //! \return   MOS_STATUS
1544     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1545     //!
1546     MOS_STATUS VeboxInitSpatialAttributesConfiguration();
1547 #endif
1548 
1549     //!
1550     //! \brief    Update Vebox Execution State for Vebox/Render parallelism
1551     //! \details
1552     //!     Purpose   : Handle Vebox execution state machine transitions
1553     //!
1554     //!     Mode0:    Enter or stay in this state as long has (a) there are no future
1555     //!               frames present or (b) FRC is active. Parallel execution is
1556     //!               handled different in FRC mode. (c) Vebox/SFC output path is
1557     //!               applied. Parallel execution is not needed when it is Vebox/SFC
1558     //!               to output. Mode0 is considered the legacy serial vebox execution mode.
1559     //!     Mode0To2: Enter this state when a future frame becomes present. In this
1560     //!               state, perform a one time start up sequence in order to transistion
1561     //!               to Mode2 parallel execution state.
1562     //!     Mode2:    Enter this state as long a future frame is present. This is the
1563     //!               steady parallel execution state where we process 1 frame ahead.
1564     //!               i.e. On BLT(N), we do vebox on the future frame N+1 and composite
1565     //!               frame N in the same BLT().
1566     //!     Mode2To0: Enter this state when in Mode2 and no future frame is present.
1567     //!               Transition back to Mode0.
1568     //! \param    [in] pSrcSurface
1569     //!           Pointer to input surface of Vebox
1570     //! \param    [in] OutputPipe
1571     //!           The output path the driver uses to write the RenderTarget
1572     //! \return   MOS_STATUS
1573     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1574     //!
1575     virtual MOS_STATUS UpdateVeboxExecutionState(
1576         PVPHAL_SURFACE          pSrcSurface,
1577         VPHAL_OUTPUT_PIPE_MODE  OutputPipe);
1578 
1579     //!
1580     //! \brief    Vebox render mode2
1581     //! \details  VEBOX/IECP Rendering for future frame
1582     //!           [Flow] 1. For future frame; send cmd.
1583     //!                  2. setup state for next vebox operation.
1584     //!                  3. Request "speculative" copy state, update state.
1585     //! \param    [in] pSrcSurface
1586     //!           Pointer to input surface of Vebox
1587     //! \param    [in] pOutputSurface
1588     //!           Pointer to output surface of Vebox
1589     //! \return   MOS_STATUS
1590     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1591     //!
1592     virtual MOS_STATUS VeboxRenderMode2(
1593         PVPHAL_SURFACE           pSrcSurface,
1594         PVPHAL_SURFACE           pOutputSurface);
1595 
1596     //!
1597     //! \brief    Vebox render mode0to2
1598     //! \details  Purpose   : VEBOX/IECP Rendering for current and future frame
1599     //!           [Flow] 1. For current frame; setup state, copy state, update state, send cmd.
1600     //!                  2. For future frame;  setup state, copy state, update state, send cmd.
1601     //!                  3. setup state for next vebox operation.
1602     //!                  4. Request "speculative" copy state, update state.
1603     //! \param    [in] pSrcSurface
1604     //!           Pointer to input surface of Vebox
1605     //! \param    [in] pOutputSurface
1606     //!           Pointer to output surface of Vebox
1607     //! \return   MOS_STATUS
1608     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1609     //!
1610     virtual MOS_STATUS VeboxRenderMode0To2(
1611         PVPHAL_SURFACE           pSrcSurface,
1612         PVPHAL_SURFACE           pOutputSurface);
1613 
1614     //!
1615     //! \brief    Vebox Render mode0
1616     //! \details  VEBOX/IECP Rendering for current frame
1617     //!           [Flow] 1. For current frame; setup state, copy state, update state, send cmd.
1618     //! \param    [in] pSrcSurface
1619     //!           Pointer to input surface of Vebox
1620     //! \param    [in] pOutputSurface
1621     //!           Pointer to output surface of Vebox
1622     //! \return   MOS_STATUS
1623     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1624     //!
1625     virtual MOS_STATUS VeboxRenderMode0(
1626         PVPHAL_SURFACE           pSrcSurface,
1627         PVPHAL_SURFACE           pOutputSurface);
1628 
1629     //!
1630     //! \brief    Update output surface for FFDI Same sample case with SFC
1631     //! \param    [in] pSrcSurface
1632     //!           Pointer to input surface of Vebox
1633     //! \return   output surface for the same sample case
1634     //!
1635     virtual PVPHAL_SURFACE GetOutputSurfForDiSameSampleWithSFC(
1636         PVPHAL_SURFACE pSrcSurface);
1637 
1638     //!
1639     //! \brief    Set DI output sample
1640     //! \details  Set DI sample to be used for compositing stage followed by VEBOX
1641     //!           feature reporting
1642     //! \param    [in] pSrcSurface
1643     //!           Pointer to Source Surface
1644     //! \param    [in,out] pOutputSurface
1645     //!           Pointer to Output Surface
1646     //! \return   MOS_STATUS
1647     //!           MOS_STATUS_SUCCESS if no error else MOS_STATUS_UNKNOWN
1648     //!
1649     virtual MOS_STATUS VeboxSetDiOutput(
1650         PVPHAL_SURFACE                  pSrcSurface,
1651         PVPHAL_SURFACE                  pOutputSurface);
1652 
1653     //!
1654     //! \brief    Setup reference surfaces
1655     //! \details  Setup reference surfaces for app feeds reference case and
1656     //!           no reference frame case
1657     //! \param    [in] pSrcSurface
1658     //!           Pointer to Source Surface
1659     //! \return   PVPHAL_SURFACE
1660     //!           Pointer to Reference surface or nullptr if no reference
1661     //!
1662     PVPHAL_SURFACE VeboxSetReference(
1663         PVPHAL_SURFACE                  pSrcSurface);
1664 
1665     //!
1666     //! \brief    Add Extra kernels when VeboxFLushUpdateState
1667     //! \param    [in] CmdBuffer
1668     //!           reference to MOS_COMMAND_BUFFER
1669     //! \param    [out] MediaObjectParams
1670     //!           Reference to Media object params
1671     //! \return   MOS_STATUS
1672     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1673     //!
VeboxFlushUpdateStateAddExtraKernels(MOS_COMMAND_BUFFER & CmdBuffer,MHW_MEDIA_OBJECT_PARAMS & MediaObjectParams)1674     virtual MOS_STATUS VeboxFlushUpdateStateAddExtraKernels(
1675         MOS_COMMAND_BUFFER&                 CmdBuffer,
1676         MHW_MEDIA_OBJECT_PARAMS&            MediaObjectParams)
1677     {
1678         MOS_UNUSED(CmdBuffer);
1679         MOS_UNUSED(MediaObjectParams);
1680         return MOS_STATUS_SUCCESS;
1681     }
1682 
1683     //!
1684     //! \brief    Check whether DN surface limitation is satisfied
1685     //! \param    [in] bDenoise
1686     //!           Flag to indicate whether DN is enabled
1687     //! \param    [in] CurrentSurface
1688     //!           Input surface of Vebox
1689     //! \param    [in] FFDNSurface
1690     //!           DN surface of Vebox
1691     //! \return   bool
1692     //!           Return true for limitation satisfied, otherwise false
1693     //!
1694     bool VeboxDNSurfaceLimitationSatisfied(
1695         bool                    bDenoise,
1696         VPHAL_SURFACE           *CurrentSurface,
1697         VPHAL_SURFACE           *FFDNSurface);
1698 
1699     //!
1700     //! \brief    Send Vecs Status Tag
1701     //! \details  Add MI Flush with write back into command buffer for GPU to write
1702     //!           back GPU Tag. This should be the last command in 1st level batch.
1703     //!           This ensures sync tag will be written after rendering is complete.
1704     //! \param    [in] pMhwMiInterface
1705     //!           MHW MI interface
1706     //! \param    [in] pOsInterface
1707     //!           Pointer to OS Interface
1708     //! \param    [out] pCmdBuffer
1709     //!           Pointer to Command Buffer
1710     //! \return   MOS_STATUS
1711     //!
1712     MOS_STATUS VeboxSendVecsStatusTag(
1713         PMHW_MI_INTERFACE                   pMhwMiInterface,
1714         PMOS_INTERFACE                      pOsInterface,
1715         PMOS_COMMAND_BUFFER                 pCmdBuffer);
1716 
1717     //!
1718     //! \brief    Calculate offsets of statistics surface address based on the
1719     //!           functions which were enabled in the previous call,
1720     //!           and store the width and height of the per-block statistics into DNDI_STATE
1721     //! \details
1722     //! Layout of Statistics surface when Temporal DI enabled
1723     //!     --------------------------------------------------------------\n
1724     //!     | 16 bytes for x=0, Y=0       | 16 bytes for x=16, Y=0       | ...\n
1725     //!     |-------------------------------------------------------------\n
1726     //!     | 16 bytes for x=0, Y=4       | ...\n
1727     //!     |------------------------------\n
1728     //!     | ...\n
1729     //!     |------------------------------\n
1730     //!     | 16 bytes for x=0, Y=height-4| ...\n
1731     //!     |-----------------------------------------------Pitch----------------------------------------------------------\n
1732     //!     | 256 DW of ACE histogram Slice 0 (Previous)| 17 DW Reserved         | 2 DW STD0 | 2 DW GCC0 | 11 DW Reserved |\n
1733     //!     |--------------------------------------------------------------------------------------------------------------\n
1734     //!     | 256 DW of ACE histogram Slice 0 (Current) | 11 DW FMD0 | 6 DW GNE0 | 2 DW STD0 | 2 DW GCC0 | 11 DW Reserved |\n
1735     //!     |--------------------------------------------------------------------------------------------------------------\n
1736     //!     | 256 DW of ACE histogram Slice 1 (Previous)| 17 DW Reserved         | 2 DW STD1 | 2 DW GCC1 | 11 DW Reserved |\n
1737     //!     |--------------------------------------------------------------------------------------------------------------\n
1738     //!     | 256 DW of ACE histogram Slice 1 (Current) | 11 DW FMD1 | 6 DW GNE1 | 2 DW STD1 | 2 DW GCC1 | 11 DW Reserved |\n
1739     //!     ---------------------------------------------------------------------------------------------------------------\n
1740     //!
1741     //! Layout of Statistics surface when DN or Spatial DI enabled (and Temporal DI disabled)
1742     //!     --------------------------------------------------------------\n
1743     //!     | 16 bytes for x=0, Y=0       | 16 bytes for x=16, Y=0       | ...\n
1744     //!     |-------------------------------------------------------------\n
1745     //!     | 16 bytes for x=0, Y=4       | ...\n
1746     //!     |------------------------------\n
1747     //!     | ...\n
1748     //!     |------------------------------\n
1749     //!     | 16 bytes for x=0, Y=height-4| ...\n
1750     //!     |-----------------------------------------------Pitch----------------------------------------------------------\n
1751     //!     | 256 DW of ACE histogram Slice 0 (Input)   | 11 DW FMD0 | 6 DW GNE0 | 2 DW STD0 | 2 DW GCC0 | 11 DW Reserved |\n
1752     //!     |--------------------------------------------------------------------------------------------------------------\n
1753     //!     | 256 DW of ACE histogram Slice 1 (Input)   | 11 DW FMD1 | 6 DW GNE1 | 2 DW STD1 | 2 DW GCC1 | 11 DW Reserved |\n
1754     //!     ---------------------------------------------------------------------------------------------------------------\n
1755     //!
1756     //! Layout of Statistics surface when both DN and DI are disabled
1757     //!     ------------------------------------------------Pitch----------------------------------------------------------\n
1758     //!     | 256 DW of ACE histogram Slice 0 (Input)   | 17 DW Reserved         | 2 DW STD0 | 2 DW GCC0 | 11 DW Reserved |\n
1759     //!     |--------------------------------------------------------------------------------------------------------------\n
1760     //!     | 256 DW of ACE histogram Slice 1 (Input)   | 17 DW Reserved         | 2 DW STD1 | 2 DW GCC1 | 11 DW Reserved |\n
1761     //!     ---------------------------------------------------------------------------------------------------------------\n
1762     //! \param    [out] pStatSlice0Offset
1763     //!           Statistics surface Slice 0 base pointer
1764     //! \param    [out] pStatSlice1Offset
1765     //!           Statistics surface Slice 1 base pointer
1766     //! \return   MOS_STATUS
1767     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1768     //!
1769     MOS_STATUS VeboxGetStatisticsSurfaceOffsets(
1770         int32_t*                            pStatSlice0Offset,
1771         int32_t*                            pStatSlice1Offset);
1772 
1773     //!
1774     //! \brief    Check if 2 passes CSC are supported on the platform
1775     //!
Is2PassesCscPlatformSupported()1776     virtual bool Is2PassesCscPlatformSupported()
1777     {
1778         return false;
1779     }
1780 
1781     //!
1782     //! \brief    Check if 2 passes CSC are needed
1783     //! \param    [in] pSrc
1784     //!           Pointer to input surface of Vebox
1785     //! \param    [in] pRenderTarget
1786     //!           Pointer to Render targe surface of VPP BLT
1787     //! \return   bool
1788     //!           return true if 2 Passes CSC is needed, otherwise false
1789     //!
1790     bool VeboxIs2PassesCSCNeeded(
1791         PVPHAL_SURFACE              pSrc,
1792         PVPHAL_SURFACE              pRenderTarget);
1793 
1794     //!
1795     //! \brief    Copy Surface value
1796     //! \param    [in] pTargetSurface
1797     //!           Pointer to surface copy value to
1798     //! \param    [in] pSourceSurface
1799     //!           Pointer to surface copy value from
1800     //! \return   void
1801     //!
CopySurfaceValue(PVPHAL_SURFACE pTargetSurface,PVPHAL_SURFACE pSourceSurface)1802     virtual void CopySurfaceValue(
1803         PVPHAL_SURFACE              pTargetSurface,
1804         PVPHAL_SURFACE              pSourceSurface)
1805     {
1806         *pTargetSurface = *pSourceSurface;
1807     }
1808 
1809     //!
1810     //! \brief    Vebox get Luma default value
1811     //! \details  Initialize luma denoise paramters w/ default values.
1812     //! \param    [out] pLumaParams
1813     //!           Pointer to Luma DN parameter
1814     //! \return   void
1815     //!
1816     virtual void GetLumaDefaultValue(
1817         PVPHAL_SAMPLER_STATE_DNDI_PARAM pLumaParams) = 0;
1818 
1819     //!
1820     //! \brief    Vebox set DNDI parameter
1821     //! \details  Set denoise params for luma and chroma and deinterlace params
1822     //! \param    [in] pSrcSurface
1823     //!           Pointer to input surface of Vebox
1824     //! \param    [in] pLumaParams
1825     //!           Pointer to Luma DN parameter
1826     //! \param    [in] pChromaParams
1827     //!           Pointer to Chroma DN parameter
1828     //! \return   MOS_STATUS
1829     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1830     //!
1831     virtual MOS_STATUS SetDNDIParams(
1832         PVPHAL_SURFACE                  pSrcSurface,
1833         PVPHAL_SAMPLER_STATE_DNDI_PARAM pLumaParams,
1834         PVPHAL_DNUV_PARAMS              pChromaParams) = 0;
1835 
1836     //!
1837     //! \brief    Setup Vebox_State Command parameter
1838     //! \param    [in] bDiVarianceEnable
1839     //!           Is DI/Variances report enabled
1840     //! \param    [in,out] pVeboxStateCmdParams
1841     //!           Pointer to VEBOX_STATE command parameters
1842     //! \return   MOS_STATUS
1843     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1844     //!
1845     virtual MOS_STATUS SetupVeboxState(
1846         bool                        bDiVarianceEnable,
1847         PMHW_VEBOX_STATE_CMD_PARAMS pVeboxStateCmdParams) = 0;
1848 
1849     //!
1850     //! \brief    Create the platform specific sfc state
1851     //! \return   VphalSfcState*
1852     //!           Return created VphalSfcState pointer
1853     //!
1854     virtual VphalSfcState* CreateSfcState() = 0;
1855 
1856     //!
1857     //! \brief    Vebox Set Human Vision System based Denoise parameter
1858     //! \details  Vebox Set Human Vision System based Denoise parameter
1859     //! \param    [in] pSrcSurface
1860     //!           Pointer to input surface of Vebox
1861     //! \return   MOS_STATUS
1862     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1863     //!
1864     virtual MOS_STATUS VeboxSetHVSDNParams(
1865         PVPHAL_SURFACE pSrcSurface);
1866 
1867     //!
1868     //! \brief Comp can be bypassed when the following conditions are all met
1869     //!
1870     bool IS_COMP_BYPASS_FEASIBLE(bool _bCompNeeded, PCVPHAL_RENDER_PARAMS _pcRenderParams, PVPHAL_SURFACE _pSrcSurface);
1871 
1872     //!
1873     //! \brief Vebox can be the output pipe when the following conditions are all met
1874     //!
1875     bool IS_OUTPUT_PIPE_VEBOX_FEASIBLE(PVPHAL_VEBOX_STATE _pVeboxState, PCVPHAL_RENDER_PARAMS _pcRenderParams, PVPHAL_SURFACE _pSrcSurface);
1876 
1877 };
1878 
1879 //!
1880 //! \brief    Perform Rendering in VEBOX
1881 //! \details  Check whether VEBOX Rendering is enabled. When it's enabled, perform VEBOX Rendering
1882 //!           on the input surface and get the output surface
1883 //! \param    [in,out] pRenderer
1884 //!           VPHAL renderer pointer
1885 //! \param    [in] pcRenderParams
1886 //!           Const pointer to VPHAL render parameter
1887 //! \param    [in,out] pRenderPassData
1888 //!           Pointer to the VPHAL render pass data
1889 //! \return   MOS_STATUS
1890 //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1891 //!
1892 MOS_STATUS VpHal_RndrRenderVebox(
1893     VphalRenderer           *pRenderer,
1894     PCVPHAL_RENDER_PARAMS   pcRenderParams,
1895     RenderpassData          *pRenderPassData);
1896 #endif // __VPHAL_RENDER_VEBOX_BASE_H__
1897