1 /*
2 * Copyright (c) 2020-2021, 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     decode_av1_filmgrain_feature_g12.cpp
24 //! \brief    Defines the interface for av1 decode film grain feature
25 //!
26 
27 #include "decode_av1_filmgrain_feature_g12.h"
28 #include "decode_av1_feature_manager_g12.h"
29 #include "codechal_utilities.h"
30 #include "decode_av1_feature_defs_g12.h"
31 #include "mhw_render_g12_X.h"
32 #include "decode_utils.h"
33 
34 namespace decode
35 {
36 
37 // Constant values
38 // Samples with Gaussian distribution in the range of [-2048, 2047] (12 bits)
39 // with zero mean and standard deviation of about 512.
40 // should be divided by 4 for 10-bit range and 16 for 8-bit range.
41 static const int16_t defaultGaussianSequence[2048] = {
42     56,    568,   -180,  172,   124,   -84,   172,   -64,   -900,  24,   820,
43     224,   1248,  996,   272,   -8,    -916,  -388,  -732,  -104,  -188, 800,
44     112,   -652,  -320,  -376,  140,   -252,  492,   -168,  44,    -788, 588,
45     -584,  500,   -228,  12,    680,   272,   -476,  972,   -100,  652,  368,
46     432,   -196,  -720,  -192,  1000,  -332,  652,   -136,  -552,  -604, -4,
47     192,   -220,  -136,  1000,  -52,   372,   -96,   -624,  124,   -24,  396,
48     540,   -12,   -104,  640,   464,   244,   -208,  -84,   368,   -528, -740,
49     248,   -968,  -848,  608,   376,   -60,   -292,  -40,   -156,  252,  -292,
50     248,   224,   -280,  400,   -244,  244,   -60,   76,    -80,   212,  532,
51     340,   128,   -36,   824,   -352,  -60,   -264,  -96,   -612,  416,  -704,
52     220,   -204,  640,   -160,  1220,  -408,  900,   336,   20,    -336, -96,
53     -792,  304,   48,    -28,   -1232, -1172, -448,  104,   -292,  -520, 244,
54     60,    -948,  0,     -708,  268,   108,   356,   -548,  488,   -344, -136,
55     488,   -196,  -224,  656,   -236,  -1128, 60,    4,     140,   276,  -676,
56     -376,  168,   -108,  464,   8,     564,   64,    240,   308,   -300, -400,
57     -456,  -136,  56,    120,   -408,  -116,  436,   504,   -232,  328,  844,
58     -164,  -84,   784,   -168,  232,   -224,  348,   -376,  128,   568,  96,
59     -1244, -288,  276,   848,   832,   -360,  656,   464,   -384,  -332, -356,
60     728,   -388,  160,   -192,  468,   296,   224,   140,   -776,  -100, 280,
61     4,     196,   44,    -36,   -648,  932,   16,    1428,  28,    528,  808,
62     772,   20,    268,   88,    -332,  -284,  124,   -384,  -448,  208,  -228,
63     -1044, -328,  660,   380,   -148,  -300,  588,   240,   540,   28,   136,
64     -88,   -436,  256,   296,   -1000, 1400,  0,     -48,   1056,  -136, 264,
65     -528,  -1108, 632,   -484,  -592,  -344,  796,   124,   -668,  -768, 388,
66     1296,  -232,  -188,  -200,  -288,  -4,    308,   100,   -168,  256,  -500,
67     204,   -508,  648,   -136,  372,   -272,  -120,  -1004, -552,  -548, -384,
68     548,   -296,  428,   -108,  -8,    -912,  -324,  -224,  -88,   -112, -220,
69     -100,  996,   -796,  548,   360,   -216,  180,   428,   -200,  -212, 148,
70     96,    148,   284,   216,   -412,  -320,  120,   -300,  -384,  -604, -572,
71     -332,  -8,    -180,  -176,  696,   116,   -88,   628,   76,    44,   -516,
72     240,   -208,  -40,   100,   -592,  344,   -308,  -452,  -228,  20,   916,
73     -1752, -136,  -340,  -804,  140,   40,    512,   340,   248,   184,  -492,
74     896,   -156,  932,   -628,  328,   -688,  -448,  -616,  -752,  -100, 560,
75     -1020, 180,   -800,  -64,   76,    576,   1068,  396,   660,   552,  -108,
76     -28,   320,   -628,  312,   -92,   -92,   -472,  268,   16,    560,  516,
77     -672,  -52,   492,   -100,  260,   384,   284,   292,   304,   -148, 88,
78     -152,  1012,  1064,  -228,  164,   -376,  -684,  592,   -392,  156,  196,
79     -524,  -64,   -884,  160,   -176,  636,   648,   404,   -396,  -436, 864,
80     424,   -728,  988,   -604,  904,   -592,  296,   -224,  536,   -176, -920,
81     436,   -48,   1176,  -884,  416,   -776,  -824,  -884,  524,   -548, -564,
82     -68,   -164,  -96,   692,   364,   -692,  -1012, -68,   260,   -480, 876,
83     -1116, 452,   -332,  -352,  892,   -1088, 1220,  -676,  12,    -292, 244,
84     496,   372,   -32,   280,   200,   112,   -440,  -96,   24,    -644, -184,
85     56,    -432,  224,   -980,  272,   -260,  144,   -436,  420,   356,  364,
86     -528,  76,    172,   -744,  -368,  404,   -752,  -416,  684,   -688, 72,
87     540,   416,   92,    444,   480,   -72,   -1416, 164,   -1172, -68,  24,
88     424,   264,   1040,  128,   -912,  -524,  -356,  64,    876,   -12,  4,
89     -88,   532,   272,   -524,  320,   276,   -508,  940,   24,    -400, -120,
90     756,   60,    236,   -412,  100,   376,   -484,  400,   -100,  -740, -108,
91     -260,  328,   -268,  224,   -200,  -416,  184,   -604,  -564,  -20,  296,
92     60,    892,   -888,  60,    164,   68,    -760,  216,   -296,  904,  -336,
93     -28,   404,   -356,  -568,  -208,  -1480, -512,  296,   328,   -360, -164,
94     -1560, -776,  1156,  -428,  164,   -504,  -112,  120,   -216,  -148, -264,
95     308,   32,    64,    -72,   72,    116,   176,   -64,   -272,  460,  -536,
96     -784,  -280,  348,   108,   -752,  -132,  524,   -540,  -776,  116,  -296,
97     -1196, -288,  -560,  1040,  -472,  116,   -848,  -1116, 116,   636,  696,
98     284,   -176,  1016,  204,   -864,  -648,  -248,  356,   972,   -584, -204,
99     264,   880,   528,   -24,   -184,  116,   448,   -144,  828,   524,  212,
100     -212,  52,    12,    200,   268,   -488,  -404,  -880,  824,   -672, -40,
101     908,   -248,  500,   716,   -576,  492,   -576,  16,    720,   -108, 384,
102     124,   344,   280,   576,   -500,  252,   104,   -308,  196,   -188, -8,
103     1268,  296,   1032,  -1196, 436,   316,   372,   -432,  -200,  -660, 704,
104     -224,  596,   -132,  268,   32,    -452,  884,   104,   -1008, 424,  -1348,
105     -280,  4,     -1168, 368,   476,   696,   300,   -8,    24,    180,  -592,
106     -196,  388,   304,   500,   724,   -160,  244,   -84,   272,   -256, -420,
107     320,   208,   -144,  -156,  156,   364,   452,   28,    540,   316,  220,
108     -644,  -248,  464,   72,    360,   32,    -388,  496,   -680,  -48,  208,
109     -116,  -408,  60,    -604,  -392,  548,   -840,  784,   -460,  656,  -544,
110     -388,  -264,  908,   -800,  -628,  -612,  -568,  572,   -220,  164,  288,
111     -16,   -308,  308,   -112,  -636,  -760,  280,   -668,  432,   364,  240,
112     -196,  604,   340,   384,   196,   592,   -44,   -500,  432,   -580, -132,
113     636,   -76,   392,   4,     -412,  540,   508,   328,   -356,  -36,  16,
114     -220,  -64,   -248,  -60,   24,    -192,  368,   1040,  92,    -24,  -1044,
115     -32,   40,    104,   148,   192,   -136,  -520,  56,    -816,  -224, 732,
116     392,   356,   212,   -80,   -424,  -1008, -324,  588,   -1496, 576,  460,
117     -816,  -848,  56,    -580,  -92,   -1372, -112,  -496,  200,   364,  52,
118     -140,  48,    -48,   -60,   84,    72,    40,    132,   -356,  -268, -104,
119     -284,  -404,  732,   -520,  164,   -304,  -540,  120,   328,   -76,  -460,
120     756,   388,   588,   236,   -436,  -72,   -176,  -404,  -316,  -148, 716,
121     -604,  404,   -72,   -88,   -888,  -68,   944,   88,    -220,  -344, 960,
122     472,   460,   -232,  704,   120,   832,   -228,  692,   -508,  132,  -476,
123     844,   -748,  -364,  -44,   1116,  -1104, -1056, 76,    428,   552,  -692,
124     60,    356,   96,    -384,  -188,  -612,  -576,  736,   508,   892,  352,
125     -1132, 504,   -24,   -352,  324,   332,   -600,  -312,  292,   508,  -144,
126     -8,    484,   48,    284,   -260,  -240,  256,   -100,  -292,  -204, -44,
127     472,   -204,  908,   -188,  -1000, -256,  92,    1164,  -392,  564,  356,
128     652,   -28,   -884,  256,   484,   -192,  760,   -176,  376,   -524, -452,
129     -436,  860,   -736,  212,   124,   504,   -476,  468,   76,    -472, 552,
130     -692,  -944,  -620,  740,   -240,  400,   132,   20,    192,   -196, 264,
131     -668,  -1012, -60,   296,   -316,  -828,  76,    -156,  284,   -768, -448,
132     -832,  148,   248,   652,   616,   1236,  288,   -328,  -400,  -124, 588,
133     220,   520,   -696,  1032,  768,   -740,  -92,   -272,  296,   448,  -464,
134     412,   -200,  392,   440,   -200,  264,   -152,  -260,  320,   1032, 216,
135     320,   -8,    -64,   156,   -1016, 1084,  1172,  536,   484,   -432, 132,
136     372,   -52,   -256,  84,    116,   -352,  48,    116,   304,   -384, 412,
137     924,   -300,  528,   628,   180,   648,   44,    -980,  -220,  1320, 48,
138     332,   748,   524,   -268,  -720,  540,   -276,  564,   -344,  -208, -196,
139     436,   896,   88,    -392,  132,   80,    -964,  -288,  568,   56,   -48,
140     -456,  888,   8,     552,   -156,  -292,  948,   288,   128,   -716, -292,
141     1192,  -152,  876,   352,   -600,  -260,  -812,  -468,  -28,   -120, -32,
142     -44,   1284,  496,   192,   464,   312,   -76,   -516,  -380,  -456, -1012,
143     -48,   308,   -156,  36,    492,   -156,  -808,  188,   1652,  68,   -120,
144     -116,  316,   160,   -140,  352,   808,   -416,  592,   316,   -480, 56,
145     528,   -204,  -568,  372,   -232,  752,   -344,  744,   -4,    324,  -416,
146     -600,  768,   268,   -248,  -88,   -132,  -420,  -432,  80,    -288, 404,
147     -316,  -1216, -588,  520,   -108,  92,    -320,  368,   -480,  -216, -92,
148     1688,  -300,  180,   1020,  -176,  820,   -68,   -228,  -260,  436,  -904,
149     20,    40,    -508,  440,   -736,  312,   332,   204,   760,   -372, 728,
150     96,    -20,   -632,  -520,  -560,  336,   1076,  -64,   -532,  776,  584,
151     192,   396,   -728,  -520,  276,   -188,  80,    -52,   -612,  -252, -48,
152     648,   212,   -688,  228,   -52,   -260,  428,   -412,  -272,  -404, 180,
153     816,   -796,  48,    152,   484,   -88,   -216,  988,   696,   188,  -528,
154     648,   -116,  -180,  316,   476,   12,    -564,  96,    476,   -252, -364,
155     -376,  -392,  556,   -256,  -576,  260,   -352,  120,   -16,   -136, -260,
156     -492,  72,    556,   660,   580,   616,   772,   436,   424,   -32,  -324,
157     -1268, 416,   -324,  -80,   920,   160,   228,   724,   32,    -516, 64,
158     384,   68,    -128,  136,   240,   248,   -204,  -68,   252,   -932, -120,
159     -480,  -628,  -84,   192,   852,   -404,  -288,  -132,  204,   100,  168,
160     -68,   -196,  -868,  460,   1080,  380,   -80,   244,   0,     484,  -888,
161     64,    184,   352,   600,   460,   164,   604,   -196,  320,   -64,  588,
162     -184,  228,   12,    372,   48,    -848,  -344,  224,   208,   -200, 484,
163     128,   -20,   272,   -468,  -840,  384,   256,   -720,  -520,  -464, -580,
164     112,   -120,  644,   -356,  -208,  -608,  -528,  704,   560,   -424, 392,
165     828,   40,    84,    200,   -152,  0,     -144,  584,   280,   -120, 80,
166     -556,  -972,  -196,  -472,  724,   80,    168,   -32,   88,    160,  -688,
167     0,     160,   356,   372,   -776,  740,   -128,  676,   -248,  -480, 4,
168     -364,  96,    544,   232,   -1032, 956,   236,   356,   20,    -40,  300,
169     24,    -676,  -596,  132,   1120,  -104,  532,   -1096, 568,   648,  444,
170     508,   380,   188,   -376,  -604,  1488,  424,   24,    756,   -220, -192,
171     716,   120,   920,   688,   168,   44,    -460,  568,   284,   1144, 1160,
172     600,   424,   888,   656,   -356,  -320,  220,   316,   -176,  -724, -188,
173     -816,  -628,  -348,  -228,  -380,  1012,  -452,  -660,  736,   928,  404,
174     -696,  -72,   -268,  -892,  128,   184,   -344,  -780,  360,   336,  400,
175     344,   428,   548,   -112,  136,   -228,  -216,  -820,  -516,  340,  92,
176     -136,  116,   -300,  376,   -244,  100,   -316,  -520,  -284,  -12,  824,
177     164,   -548,  -180,  -128,  116,   -924,  -828,  268,   -368,  -580, 620,
178     192,   160,   0,     -1676, 1068,  424,   -56,   -360,  468,   -156, 720,
179     288,   -528,  556,   -364,  548,   -148,  504,   316,   152,   -648, -620,
180     -684,  -24,   -376,  -384,  -108,  -920,  -1032, 768,   180,   -264, -508,
181     -1268, -260,  -60,   300,   -240,  988,   724,   -376,  -576,  -212, -736,
182     556,   192,   1092,  -620,  -880,  376,   -56,   -4,    -216,  -32,  836,
183     268,   396,   1332,  864,   -600,  100,   56,    -412,  -92,   356,  180,
184     884,   -468,  -436,  292,   -388,  -804,  -704,  -840,  368,   -348, 140,
185     -724,  1536,  940,   372,   112,   -372,  436,   -480,  1136,  296,  -32,
186     -228,  132,   -48,   -220,  868,   -1016, -60,   -1044, -464,  328,  916,
187     244,   12,    -736,  -296,  360,   468,   -376,  -108,  -92,   788,  368,
188     -56,   544,   400,   -672,  -420,  728,   16,    320,   44,    -284, -380,
189     -796,  488,   132,   204,   -596,  -372,  88,    -152,  -908,  -636, -572,
190     -624,  -116,  -692,  -200,  -56,   276,   -88,   484,   -324,  948,  864,
191     1000,  -456,  -184,  -276,  292,   -296,  156,   676,   320,   160,  908,
192     -84,   -1236, -288,  -116,  260,   -372,  -644,  732,   -756,  -96,  84,
193     344,   -520,  348,   -688,  240,   -84,   216,   -1044, -136,  -676, -396,
194     -1500, 960,   -40,   176,   168,   1516,  420,   -504,  -344,  -364, -360,
195     1216,  -940,  -380,  -212,  252,   -660,  -708,  484,   -444,  -152, 928,
196     -120,  1112,  476,   -260,  560,   -148,  -344,  108,   -196,  228,  -288,
197     504,   560,   -328,  -88,   288,   -1008, 460,   -228,  468,   -836, -196,
198     76,    388,   232,   412,   -1168, -716,  -644,  756,   -172,  -356, -504,
199     116,   432,   528,   48,    476,   -168,  -608,  448,   160,   -532, -272,
200     28,    -676,  -12,   828,   980,   456,   520,   104,   -104,  256,  -344,
201     -4,    -28,   -368,  -52,   -524,  -572,  -556,  -200,  768,   1124, -208,
202     -512,  176,   232,   248,   -148,  -888,  604,   -600,  -304,  804,  -156,
203     -212,  488,   -192,  -804,  -256,  368,   -360,  -916,  -328,  228,  -240,
204     -448,  -472,  856,   -556,  -364,  572,   -12,   -156,  -368,  -340, 432,
205     252,   -752,  -152,  288,   268,   -580,  -848,  -592,  108,   -76,  244,
206     312,   -716,  592,   -80,   436,   360,   4,     -248,  160,   516,  584,
207     732,   44,    -468,  -280,  -292,  -156,  -588,  28,    308,   912,  24,
208     124,   156,   180,   -252,  944,   -924,  -772,  -520,  -428,  -624, 300,
209     -212,  -1144, 32,    -724,  800,   -1128, -212,  -1288, -848,  180,  -416,
210     440,   192,   -576,  -792,  -76,   -1080, 80,    -532,  -352,  -132, 380,
211     -820,  148,   1112,  128,   164,   456,   700,   -924,  144,   -668, -384,
212     648,   -832,  508,   552,   -52,   -100,  -656,  208,   -568,  748,  -88,
213     680,   232,   300,   192,   -408,  -1012, -152,  -252,  -268,  272,  -876,
214     -664,  -648,  -332,  -136,  16,    12,    1152,  -28,   332,   -536, 320,
215     -672,  -460,  -316,  532,   -260,  228,   -40,   1052,  -816,  180,  88,
216     -496,  -556,  -672,  -368,  428,   92,    356,   404,   -408,  252,  196,
217     -176,  -556,  792,   268,   32,    372,   40,    96,    -332,  328,  120,
218     372,   -900,  -40,   472,   -264,  -592,  952,   128,   656,   112,  664,
219     -232,  420,   4,     -344,  -464,  556,   244,   -416,  -32,   252,  0,
220     -412,  188,   -696,  508,   -476,  324,   -1096, 656,   -312,  560,  264,
221     -136,  304,   160,   -64,   -580,  248,   336,   -720,  560,   -348, -288,
222     -276,  -196,  -500,  852,   -544,  -236,  -1128, -992,  -776,  116,  56,
223     52,    860,   884,   212,   -12,   168,   1020,  512,   -552,  924,  -148,
224     716,   188,   164,   -340,  -520,  -184,  880,   -152,  -680,  -208, -1156,
225     -300,  -528,  -472,  364,   100,   -744,  -1056, -32,   540,   280,  144,
226     -676,  -32,   -232,  -280,  -224,  96,    568,   -76,   172,   148,  148,
227     104,   32,    -296,  -32,   788,   -80,   32,    -16,   280,   288,  944,
228     428,   -484
229 };
230 
231 // Binding Table Definitions
232 //!
233 //! \enum     FilmGrainGetRandomValuesBindingTableOffset
234 //! \brief    Binding table offset for GetRandomValues kernel
235 //!
236 enum FilmGrainGetRandomValuesBindingTableOffset
237 {
238     grvInputGaussianSeq = 0,
239     grvOutputYRandomValue,
240     grvOutputURandomValue,
241     grvOutputVRandomValue,
242     grvOutputCoordinates,
243     grvNumSurfaces
244 };
245 
246 //!
247 //! \enum     FilmGrainRegressPhase1BindingTableOffset
248 //! \brief    Binding table offset for regressPhase1 kernel
249 //!
250 enum FilmGrainRegressPhase1BindingTableOffset
251 {
252     rp1InputYRandomValue = 0,
253     rp1OutputYDitheringSurface,
254     rp1InputYCoeff,
255     rp1NumSurfaces
256 };
257 
258 //!
259 //! \enum     FilmGrainRegressPhase2BindingTableOffset
260 //! \brief    Binding table offset for regressPhase2 kernel
261 //!
262 enum FilmGrainRegressPhase2BindingTableOffset
263 {
264     rp2InputYRandomValue = 0,
265     rp2InputURandomValue,
266     rp2InputVRandomValue,
267     rp2InputYDithering,
268     rp2OutputYDithering,
269     rp2OutputUDithering,
270     rp2OutputVDithering,
271     rp2InputYCoeff,
272     rp2InputUCoeff,
273     rp2InputVCoeff,
274     rp2NumSurfaces
275 };
276 
277 //!
278 //! \enum     FilmGrainApplyNoiseBindingTableOffset
279 //! \brief    Binding table offset for ApplyNoise kernel
280 //!
281 enum FilmGrainApplyNoiseBindingTableOffset
282 {
283     anInputYuv = 0,
284     anOutputY,
285     anOutputUv,
286     anInputYDithering,
287     anInputUDithering,
288     anInputVDithering,
289     anInputRandomValuesCoordinates,
290     anInputYGammaLut,
291     anInputUGammaLut,
292     anInputVGammaLut,
293     anNumSurfaces
294 };
295 
296 const int32_t Av1DecodeFilmGrainG12::m_filmGrainBindingTableCount[kernelNum] = {
297     grvNumSurfaces,
298     rp1NumSurfaces,
299     rp2NumSurfaces,
300     anNumSurfaces
301 };
302 
303 //Curbe definitions
304 struct FilmGrainGetRandomValuesCurbe
305 {
306     // uint32_t 0
307     union
308     {
309         struct
310         {
311             uint32_t   GaussianSeqSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
312         };
313         struct
314         {
315             uint32_t   Value;
316         };
317     } DW0;
318 
319     // uint32_t 1
320     union
321     {
322         struct
323         {
324             uint32_t   YRandomValuesSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
325         };
326         struct
327         {
328             uint32_t   Value;
329         };
330     } DW1;
331 
332     // uint32_t 2
333     union
334     {
335         struct
336         {
337             uint32_t  URandomValuesSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
338         };
339         struct
340         {
341             uint32_t   Value;
342         };
343     } DW2;
344 
345     // uint32_t 3
346     union
347     {
348         struct
349         {
350             uint32_t  VRandomValuesSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
351         };
352         struct
353         {
354             uint32_t   Value;
355         };
356     } DW3;
357 
358     // uint32_t 4
359     union
360     {
361         struct
362         {
363             uint32_t  CoordinatesSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);  //Random values for coordinates surface index
364         };
365         struct
366         {
367             uint32_t   Value;
368         };
369     } DW4;
370 
371     // uint32_t 5
372     union
373     {
374         struct
375         {
376             uint32_t  NoiseShiftAmount  : MOS_BITFIELD_RANGE(0, 15);
377             uint32_t  Reserved          : MOS_BITFIELD_RANGE(16, 31);
378         };
379         struct
380         {
381             uint32_t   Value;
382         };
383     } DW5;
384 
385     // uint32_t 6
386     union
387     {
388         struct
389         {
390             uint32_t  GrainSeed : MOS_BITFIELD_RANGE(0, 31);    //Random number generation initializer
391         };
392         struct
393         {
394             uint32_t   Value;
395         };
396     } DW6;
397 
398     // uint32_t 7
399     union
400     {
401         struct
402         {
403             uint32_t  CoordinatesWidth  : MOS_BITFIELD_RANGE(0, 15);   //RoundUp(ImageHeight/64)
404             uint32_t  CoordinatesHeight : MOS_BITFIELD_RANGE(16, 31);  //RoundUp(ImageWidth/64)
405         };
406         struct
407         {
408             uint32_t   Value;
409         };
410     } DW7;
411 
412     static const size_t m_size = 8;
413     static const size_t m_byteSize = 32;
414 };
415 C_ASSERT(sizeof(FilmGrainGetRandomValuesCurbe) == 32);
416 
417 struct FilmGrainRegressPhase1Curbe
418 {
419     // uint32_t 0
420     union
421     {
422         struct
423         {
424             uint32_t   YRandomValuesSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
425         };
426         struct
427         {
428             uint32_t   Value;
429         };
430     } DW0;
431 
432     // uint32_t 1
433     union
434     {
435         struct
436         {
437             uint32_t   YDitheringSurface : MOS_BITFIELD_RANGE(0, 31);
438         };
439         struct
440         {
441             uint32_t   Value;
442         };
443     } DW1;
444 
445     // uint32_t 2
446     union
447     {
448         struct
449         {
450             uint32_t  YCoeffSurface : MOS_BITFIELD_RANGE(0, 31);
451         };
452         struct
453         {
454             uint32_t   Value;
455         };
456     } DW2;
457 
458     static const size_t m_size = 3;
459     static const size_t m_byteSize = 12;
460 };
461 C_ASSERT(sizeof(FilmGrainRegressPhase1Curbe) == 12);
462 
463 struct FilmGrainRegressPhase2Curbe
464 {
465     // uint32_t 0
466     union
467     {
468         struct
469         {
470             uint32_t   YRandomValuesSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
471         };
472         struct
473         {
474             uint32_t   Value;
475         };
476     } DW0;
477 
478     // uint32_t 1
479     union
480     {
481         struct
482         {
483             uint32_t   URandomValuesSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
484         };
485         struct
486         {
487             uint32_t   Value;
488         };
489     } DW1;
490 
491     // uint32_t 2
492     union
493     {
494         struct
495         {
496             uint32_t  VRandomValuesSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
497         };
498         struct
499         {
500             uint32_t   Value;
501         };
502     } DW2;
503 
504     // uint32_t 3
505     union
506     {
507         struct
508         {
509             uint32_t  YDitheringInputSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
510         };
511         struct
512         {
513             uint32_t   Value;
514         };
515     } DW3;
516 
517     // uint32_t 4
518     union
519     {
520         struct
521         {
522             uint32_t  YDitheringSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
523         };
524         struct
525         {
526             uint32_t   Value;
527         };
528     } DW4;
529 
530     // uint32_t 5
531     union
532     {
533         struct
534         {
535             uint32_t  UDitheringSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
536         };
537         struct
538         {
539             uint32_t   Value;
540         };
541     } DW5;
542 
543     // uint32_t 6
544     union
545     {
546         struct
547         {
548             uint32_t  VDitheringSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
549         };
550         struct
551         {
552             uint32_t   Value;
553         };
554     } DW6;
555 
556     // uint32_t 7
557     union
558     {
559         struct
560         {
561             uint32_t  YCoeffSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
562         };
563         struct
564         {
565             uint32_t   Value;
566         };
567     } DW7;
568 
569     // uint32_t 8
570     union
571     {
572         struct
573         {
574             uint32_t  UCoeffSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
575         };
576         struct
577         {
578             uint32_t   Value;
579         };
580     } DW8;
581 
582     // uint32_t 9
583     union
584     {
585         struct
586         {
587             uint32_t  VCoeffSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
588         };
589         struct
590         {
591             uint32_t   Value;
592         };
593     } DW9;
594 
595     // uint32_t 10
596     union
597     {
598         struct
599         {
600             uint32_t  RegressionCoefficientShift    : MOS_BITFIELD_RANGE(0, 15);
601             uint32_t  Reserved                      : MOS_BITFIELD_RANGE(16, 31);
602         };
603         struct
604         {
605             uint32_t   Value;
606         };
607     } DW10;
608 
609     static const size_t m_size = 11;
610     static const size_t m_byteSize = 44;
611 };
612 C_ASSERT(sizeof(FilmGrainRegressPhase2Curbe) == 44);
613 
614 struct FilmGrainApplyNoiseCurbe
615 {
616     // uint32_t 0
617     union
618     {
619         struct
620         {
621             uint32_t   InputYuvSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
622         };
623         struct
624         {
625             uint32_t   Value;
626         };
627     } DW0;
628 
629     // uint32_t 1
630     union
631     {
632         struct
633         {
634             uint32_t   OutputYSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
635         };
636         struct
637         {
638             uint32_t   Value;
639         };
640     } DW1;
641 
642     // uint32_t 2
643     union
644     {
645         struct
646         {
647             uint32_t  OutputUvSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
648         };
649         struct
650         {
651             uint32_t   Value;
652         };
653     } DW2;
654 
655     // uint32_t 3
656     union
657     {
658         struct
659         {
660             uint32_t  YDitheringSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
661         };
662         struct
663         {
664             uint32_t   Value;
665         };
666     } DW3;
667 
668     // uint32_t 4
669     union
670     {
671         struct
672         {
673             uint32_t  UDitheringSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
674         };
675         struct
676         {
677             uint32_t   Value;
678         };
679     } DW4;
680 
681     // uint32_t 5
682     union
683     {
684         struct
685         {
686             uint32_t  VDitheringSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
687         };
688         struct
689         {
690             uint32_t   Value;
691         };
692     } DW5;
693 
694     // uint32_t 6
695     union
696     {
697         struct
698         {
699             uint32_t  RandomValuesForCoordinatesSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
700         };
701         struct
702         {
703             uint32_t   Value;
704         };
705     } DW6;
706 
707     // uint32_t 7
708     union
709     {
710         struct
711         {
712             uint32_t  YGammaCorrectionLutSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
713         };
714         struct
715         {
716             uint32_t   Value;
717         };
718     } DW7;
719 
720     // uint32_t 8
721     union
722     {
723         struct
724         {
725             uint32_t  UGammaCorrectionLutSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
726         };
727         struct
728         {
729             uint32_t   Value;
730         };
731     } DW8;
732 
733     // uint32_t 9
734     union
735     {
736         struct
737         {
738             uint32_t  VGammaCorrectionLutSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
739         };
740         struct
741         {
742             uint32_t   Value;
743         };
744     } DW9;
745 
746     // uint32_t 10
747     union
748     {
749         struct
750         {
751             uint32_t  EnableYFilmGrain                     : MOS_BITFIELD_RANGE(0, 15);
752             uint32_t  EnableUFilmGrain                     : MOS_BITFIELD_RANGE(16, 31);
753         };
754         struct
755         {
756             uint32_t   Value;
757         };
758     } DW10;
759 
760     // uint32_t 11
761     union
762     {
763         struct
764         {
765             uint32_t  EnableVFilmGrain                      : MOS_BITFIELD_RANGE(0, 15);
766             uint32_t  RandomValuesForCoordinatesTableWidth  : MOS_BITFIELD_RANGE(16, 31);
767         };
768         struct
769         {
770             uint32_t   Value;
771         };
772     } DW11;
773 
774     // uint32_t 12
775     union
776     {
777         struct
778         {
779             uint32_t  ImageHeight       : MOS_BITFIELD_RANGE(0, 15);
780             uint32_t  ScalingShiftValue : MOS_BITFIELD_RANGE(16, 31);
781         };
782         struct
783         {
784             uint32_t   Value;
785         };
786     } DW12;
787 
788     // uint32_t 13
789     union
790     {
791         struct
792         {
793             uint32_t  MinimumYClippingValue : MOS_BITFIELD_RANGE(0, 15);
794             uint32_t  MaximumYClippingValue : MOS_BITFIELD_RANGE(16, 31);
795         };
796         struct
797         {
798             uint32_t   Value;
799         };
800     } DW13;
801 
802     // uint32_t 14
803     union
804     {
805         struct
806         {
807             uint32_t  MinimumUvClippingValue : MOS_BITFIELD_RANGE(0, 15);
808             uint32_t  MaximumUvClippingValue : MOS_BITFIELD_RANGE(16, 31);
809         };
810         struct
811         {
812             uint32_t   Value;
813         };
814     } DW14;
815 
816     // uint32_t 15
817     union
818     {
819         struct
820         {
821             uint32_t  CbLumaMultiplier : MOS_BITFIELD_RANGE(0, 15);
822             uint32_t  CbMultiplier : MOS_BITFIELD_RANGE(16, 31);
823         };
824         struct
825         {
826             uint32_t   Value;
827         };
828     } DW15;
829 
830     // uint32_t 16
831     union
832     {
833         struct
834         {
835             uint32_t  CbOffset          : MOS_BITFIELD_RANGE(0, 15);
836             uint32_t  CrLumaMultiplier  : MOS_BITFIELD_RANGE(16, 31);
837         };
838         struct
839         {
840             uint32_t   Value;
841         };
842     } DW16;
843 
844     // uint32_t 17
845     union
846     {
847         struct
848         {
849             uint32_t  CrMultiplier  : MOS_BITFIELD_RANGE(0, 15);
850             uint32_t  CrOffset      : MOS_BITFIELD_RANGE(16, 31);
851         };
852         struct
853         {
854             uint32_t   Value;
855         };
856     } DW17;
857 
858     static const size_t m_size = 18;
859     static const size_t m_byteSize = 72;
860 };
861 C_ASSERT(sizeof(FilmGrainApplyNoiseCurbe) == 72);
862 
863 const int32_t Av1DecodeFilmGrainG12::m_filmGrainCurbeSize[kernelNum] = {
864     (sizeof(FilmGrainGetRandomValuesCurbe)),
865     (sizeof(FilmGrainRegressPhase1Curbe)),
866     (sizeof(FilmGrainRegressPhase2Curbe)),
867     (sizeof(FilmGrainApplyNoiseCurbe))
868 };
869 
870 // Initialize the static const float variables in class Av1DecodeFilmGrainG12.
871 const float Av1DecodeFilmGrainG12::m_maxScaleRatio = 1.0f;
872 const float Av1DecodeFilmGrainG12::m_minScaleRatio = 0.125f;
873 
Av1DecodeFilmGrainG12(MediaFeatureManager * featureManager,DecodeAllocator * allocator,CodechalHwInterface * hwInterface)874 Av1DecodeFilmGrainG12::Av1DecodeFilmGrainG12(
875     MediaFeatureManager *featureManager,
876     DecodeAllocator     *allocator,
877     CodechalHwInterface *hwInterface) :
878     m_allocator(allocator)
879 {
880     m_featureManager = featureManager;
881 
882     auto decFeatureManager = dynamic_cast<DecodeAv1FeatureManagerG12 *>(featureManager);
883     DECODE_CHK_NULL_NO_STATUS_RETURN(decFeatureManager);
884 
885     m_basicFeature = dynamic_cast<Av1BasicFeatureG12 *>(m_featureManager->GetFeature(Av1FeatureIDs::basicFeature));
886     DECODE_CHK_NULL_NO_STATUS_RETURN(m_basicFeature);
887 
888     m_hwInterface = hwInterface;
889 }
890 
~Av1DecodeFilmGrainG12()891 Av1DecodeFilmGrainG12::~Av1DecodeFilmGrainG12()
892 {
893     m_allocator->Destroy(m_gaussianSequenceSurface);
894     m_allocator->Destroy(m_yRandomValuesSurface);
895     m_allocator->Destroy(m_uRandomValuesSurface);
896     m_allocator->Destroy(m_vRandomValuesSurface);
897     m_allocator->Destroy(m_yDitheringTempSurface);
898 
899     m_allocator->Destroy(m_coordinatesRandomValuesSurfaceArray);
900     m_allocator->Destroy(m_yCoefficientsSurfaceArray);
901     m_allocator->Destroy(m_yDitheringSurfaceArray);
902     m_allocator->Destroy(m_uDitheringSurfaceArray);
903     m_allocator->Destroy(m_vDitheringSurfaceArray);
904     m_allocator->Destroy(m_yCoeffSurfaceArray);
905     m_allocator->Destroy(m_uCoeffSurfaceArray);
906     m_allocator->Destroy(m_vCoeffSurfaceArray);
907     m_allocator->Destroy(m_yGammaLUTSurfaceArray);
908     m_allocator->Destroy(m_uGammaLUTSurfaceArray);
909     m_allocator->Destroy(m_vGammaLUTSurfaceArray);
910     m_allocator->Destroy(m_coordinatesRandomValuesSurfaceArray);
911 }
912 
Init(void * settings)913 MOS_STATUS Av1DecodeFilmGrainG12::Init(void *settings)
914 {
915     DECODE_FUNC_CALL();
916 
917     memset(&m_kernelSize, 0, sizeof(m_kernelSize));
918     memset(&m_dshSize, 0, sizeof(m_dshSize));
919     memset(&m_syncObject, 0, sizeof(m_syncObject));
920 
921     for (uint8_t i = getRandomValues; i < kernelNum; i++)
922     {
923         m_kernelBinary[i] = nullptr;
924         m_kernelStates[i] = MHW_KERNEL_STATE();
925     }
926 
927     return MOS_STATUS_SUCCESS;
928 }
929 
Update(void * params)930 MOS_STATUS Av1DecodeFilmGrainG12::Update(void *params)
931 {
932     DECODE_FUNC_CALL();
933     DECODE_CHK_NULL(params);
934 
935     CodechalDecodeParams *decodeParams = (CodechalDecodeParams *)params;
936     m_picParams = static_cast<CodecAv1PicParams *>(decodeParams->m_picParams);
937     DECODE_CHK_NULL(m_picParams);
938 
939     m_bitDepthIndicator = m_basicFeature->m_av1DepthIndicator;
940 
941     if (!m_resourceAllocated)
942     {
943         DECODE_CHK_STATUS(InitializeKernelState());
944         DECODE_CHK_STATUS(AllocateFixedSizeSurfaces());
945         m_resourceAllocated = true;
946     }
947 
948     /*Note: for scenario that m_applyGrain=true but (applyY | applyCb | applyCr)=false,
949      * umd no need to generate noise for perf optimization, but need to apply noise with default value directly*/
950     bool applyY  = (m_picParams->m_filmGrainParams.m_numYPoints > 0) ? 1 : 0;
951     bool applyCb = (m_picParams->m_filmGrainParams.m_numCbPoints > 0 || m_picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_chromaScalingFromLuma) ? 1 : 0;
952     bool applyCr = (m_picParams->m_filmGrainParams.m_numCrPoints > 0 || m_picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_chromaScalingFromLuma) ? 1 : 0;
953     m_filmGrainEnabled = m_picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_applyGrain && (applyY | applyCb | applyCr);
954 
955     if (m_picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_applyGrain)
956     {
957         m_av1TileParams = static_cast<CodecAv1TileParams*>(decodeParams->m_sliceParams);
958         DECODE_CHK_NULL(m_av1TileParams);
959 
960         m_segmentParams = &m_picParams->m_av1SegData;
961         DECODE_CHK_NULL(m_segmentParams);
962 
963         DECODE_CHK_STATUS(SetFrameStates(m_picParams));
964         DECODE_CHK_STATUS(AllocateVariableSizeSurfaces());
965     }
966 
967 #if (_DEBUG || _RELEASE_INTERNAL)
968     m_fgOutputSurfList[m_basicFeature->m_curRenderPic.FrameIdx] = m_basicFeature->m_fgOutputSurf;
969 #endif
970 
971     return MOS_STATUS_SUCCESS;
972 }
973 
InitInterfaceStateHeapSetting()974 MOS_STATUS Av1DecodeFilmGrainG12::InitInterfaceStateHeapSetting()
975 {
976     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
977 
978     DECODE_FUNC_CALL();
979 
980     DECODE_CHK_STATUS(m_hwInterface->GetFilmGrainKernelInfo(
981         m_kernelBaseCommon,
982         m_combinedKernelSize));
983     DECODE_CHK_NULL(m_kernelBaseCommon);
984 
985     return eStatus;
986 }
987 
AllocateStateHeap(CodechalHwInterface * hwInterface)988 MOS_STATUS Av1DecodeFilmGrainG12::AllocateStateHeap(
989     CodechalHwInterface               *hwInterface)
990 {
991     MOS_STATUS              eStatus = MOS_STATUS_SUCCESS;
992 
993     DECODE_FUNC_CALL();
994 
995     MhwRenderInterface *renderInterface = m_hwInterface->GetRenderInterface();
996     DECODE_CHK_NULL(renderInterface);
997 
998     MHW_STATE_HEAP_SETTINGS *stateHeapSettings = m_hwInterface->GetStateHeapSettings();
999     DECODE_CHK_NULL(stateHeapSettings);
1000 
1001     stateHeapSettings->m_ishBehavior = HeapManager::Behavior::clientControlled;
1002     stateHeapSettings->m_dshBehavior = HeapManager::Behavior::destructiveExtend;
1003     // As a performance optimization keep the DSH locked always,
1004     // the ISH is only accessed at device creation and thus does not need to be locked
1005     stateHeapSettings->m_keepDshLocked = true;
1006     stateHeapSettings->dwDshIncrement = 2 * MOS_PAGE_SIZE;
1007 
1008     if (stateHeapSettings->dwIshSize > 0 &&
1009         stateHeapSettings->dwDshSize > 0 &&
1010         stateHeapSettings->dwNumSyncTags > 0)
1011     {
1012         DECODE_CHK_STATUS(renderInterface->AllocateHeaps(
1013             *stateHeapSettings));
1014     }
1015 
1016     return eStatus;
1017 }
1018 
GetCommonKernelHeaderAndSize(void * binary,FilmGrainKernelStateIdx index,uint8_t bitDepthIndicator,void * krnHeader,uint32_t * krnSize)1019 MOS_STATUS Av1DecodeFilmGrainG12::GetCommonKernelHeaderAndSize(
1020     void                            *binary,
1021     FilmGrainKernelStateIdx         index,
1022     uint8_t                         bitDepthIndicator,
1023     void                            *krnHeader,
1024     uint32_t                        *krnSize)
1025 {
1026     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
1027 
1028     DECODE_FUNC_CALL();
1029 
1030     DECODE_CHK_NULL(binary);
1031     DECODE_CHK_NULL(krnHeader);
1032     DECODE_CHK_NULL(krnSize);
1033 
1034     FilmGrainCombinedKernelHeader *kernelHeaderTable;
1035     kernelHeaderTable = (FilmGrainCombinedKernelHeader*)binary;
1036     CodecKernelHeader *invalidEntry;
1037     invalidEntry = &(kernelHeaderTable->applyNoise10b) + 1;
1038 
1039     CodecKernelHeader *currKrnHeader;
1040     switch (index)
1041     {
1042     case getRandomValues:
1043         currKrnHeader = &kernelHeaderTable->getRandomValues8b;
1044         break;
1045     case regressPhase1:
1046         currKrnHeader = &kernelHeaderTable->regressPhase1;
1047         break;
1048     case regressPhase2:
1049         currKrnHeader = &kernelHeaderTable->regressPhase2For8b;
1050         break;
1051     case applyNoise:
1052         currKrnHeader = &kernelHeaderTable->applyNoise8b;
1053         break;
1054     default:
1055         DECODE_VERBOSEMESSAGE("Unsupported film grain stage requested");
1056         eStatus = MOS_STATUS_INVALID_PARAMETER;
1057         return eStatus;
1058     }
1059 
1060     if (index != regressPhase1)
1061     {
1062         currKrnHeader += bitDepthIndicator;
1063     }
1064 
1065     *((CodecKernelHeader *)krnHeader) = *currKrnHeader;
1066 
1067     CodecKernelHeader *nextKrnHeader;
1068     nextKrnHeader = (currKrnHeader + 1);
1069     uint32_t nextKrnOffset;
1070     nextKrnOffset = *krnSize;
1071 
1072     if (nextKrnHeader < invalidEntry)
1073     {
1074         nextKrnOffset = nextKrnHeader->KernelStartPointer << MHW_KERNEL_OFFSET_SHIFT;
1075     }
1076     *krnSize = nextKrnOffset - (currKrnHeader->KernelStartPointer << MHW_KERNEL_OFFSET_SHIFT);
1077 
1078     return eStatus;
1079 }
1080 
InitializeKernelState()1081 MOS_STATUS Av1DecodeFilmGrainG12::InitializeKernelState()
1082 {
1083     MOS_STATUS              eStatus = MOS_STATUS_SUCCESS;
1084 
1085     DECODE_FUNC_CALL();
1086 
1087     if (m_bitDepthIndicator > 1)
1088     {
1089         DECODE_VERBOSEMESSAGE("Bit depth not supported!\n");
1090         return MOS_STATUS_INVALID_PARAMETER;
1091     }
1092 
1093     PMOS_INTERFACE osInterface = m_hwInterface->GetOsInterface();
1094     m_osInterface           = osInterface;
1095 
1096     // Init State Heap
1097     DECODE_CHK_STATUS(InitInterfaceStateHeapSetting());
1098 
1099     CODECHAL_KERNEL_HEADER currKrnHeader;
1100     MHW_KERNEL_STATE *kernelState;
1101     for (auto krnStateIdx = 0; krnStateIdx < kernelNum; krnStateIdx++)
1102     {
1103         uint32_t kernelSize = m_combinedKernelSize;
1104         kernelState = &m_kernelStates[krnStateIdx];
1105 
1106         DECODE_CHK_STATUS(GetCommonKernelHeaderAndSize(
1107             m_kernelBaseCommon,
1108             (FilmGrainKernelStateIdx)krnStateIdx,
1109             m_bitDepthIndicator,
1110             &currKrnHeader,
1111             &kernelSize))
1112 
1113         kernelState->KernelParams.iBTCount          = m_filmGrainBindingTableCount[krnStateIdx];
1114         kernelState->KernelParams.iCurbeLength      = m_filmGrainCurbeSize[krnStateIdx];
1115         kernelState->KernelParams.iBlockWidth       = CODECHAL_MACROBLOCK_WIDTH;
1116         kernelState->KernelParams.iBlockHeight      = CODECHAL_MACROBLOCK_HEIGHT;
1117         kernelState->KernelParams.iIdCount          = 1;
1118         kernelState->dwKernelBinaryOffset           = 0;
1119 
1120         kernelState->KernelParams.pBinary   = m_kernelBaseCommon + (currKrnHeader.KernelStartPointer << MHW_KERNEL_OFFSET_SHIFT);
1121         kernelState->KernelParams.iSize     = kernelSize;
1122     }
1123 
1124     DECODE_CHK_STATUS(m_osInterface->pfnCreateSyncResource(
1125         m_osInterface,
1126         &m_syncObject));
1127 
1128     return eStatus;
1129 }
1130 
SetupMediaVfe(PMOS_COMMAND_BUFFER cmdBuffer,MHW_KERNEL_STATE * kernelState)1131 MOS_STATUS Av1DecodeFilmGrainG12::SetupMediaVfe(
1132     PMOS_COMMAND_BUFFER  cmdBuffer,
1133     MHW_KERNEL_STATE     *kernelState)
1134 {
1135     MHW_VFE_PARAMS_G12 vfeParams = {};
1136     vfeParams.pKernelState = kernelState;
1137 
1138     DECODE_CHK_STATUS(m_renderInterface->AddMediaVfeCmd(cmdBuffer, &vfeParams));
1139 
1140     return MOS_STATUS_SUCCESS;
1141 }
1142 
AllocateFixedSizeSurfaces()1143 MOS_STATUS Av1DecodeFilmGrainG12::AllocateFixedSizeSurfaces()
1144 {
1145     MOS_STATUS                  eStatus = MOS_STATUS_SUCCESS;
1146 
1147     DECODE_FUNC_CALL();
1148 
1149     //Gaussian sequence surface
1150     m_gaussianSequenceSurface = m_allocator->AllocateBuffer(
1151         MOS_ALIGN_CEIL(2048 * sizeof(int16_t), CODECHAL_PAGE_SIZE), "GaussianSequenceSurface",
1152         resourceInternalReadWriteCache, lockableVideoMem);
1153     DECODE_CHK_NULL(m_gaussianSequenceSurface);
1154 
1155     auto data = (int16_t *)m_allocator->LockResourceForWrite(&m_gaussianSequenceSurface->OsResource);
1156     DECODE_CHK_NULL(data);
1157     MOS_SecureMemcpy(data, 2048 * sizeof(int16_t), defaultGaussianSequence, 2048 * sizeof(int16_t));
1158 
1159     // Surfaces/buffers for GetRandomValues kernel
1160     //Y random values surface
1161     PMOS_SURFACE surface = nullptr;
1162     m_yRandomValuesSurface = m_allocator->AllocateSurface(
1163         70 * sizeof(int16_t),
1164         70,
1165         "Film Grain GRV [out] YRandomValuesSurface",
1166         Format_R8UN,
1167         false,
1168         resourceInternalReadWriteCache,
1169         notLockableVideoMem);
1170     DECODE_CHK_NULL(m_yRandomValuesSurface);
1171 
1172     //U random values surface
1173     m_uRandomValuesSurface = m_allocator->AllocateSurface(
1174         38 * sizeof(int16_t),
1175         38,
1176         "Film Grain GRV [out] URandomValuesSurface",
1177         Format_R8UN,
1178         false,
1179         resourceInternalReadWriteCache,
1180         notLockableVideoMem);
1181     DECODE_CHK_NULL(m_uRandomValuesSurface);
1182 
1183     //V random values surface
1184     m_vRandomValuesSurface = m_allocator->AllocateSurface(
1185         38 * sizeof(int16_t),
1186         38,
1187         "Film Grain GRV [out] VRandomValuesSurface",
1188         Format_R8UN,
1189         false,
1190         resourceInternalReadWriteCache,
1191         notLockableVideoMem);
1192     DECODE_CHK_NULL(m_vRandomValuesSurface);
1193 
1194     //Y Dithering Temp LUT Surface
1195     m_yDitheringTempSurface = m_allocator->AllocateSurface(
1196         70 * sizeof(int32_t),
1197         70,
1198         "Film Grain RP1 [out] YDitheringTempSurface",
1199         Format_R8UN,
1200         false,
1201         resourceInternalReadWriteCache,
1202         notLockableVideoMem);
1203     DECODE_CHK_NULL(m_yDitheringTempSurface);
1204 
1205     // Surfaces/buffers for RegressPhase1 kernel
1206     //Y Coefficients Surface
1207     m_yCoefficientsSurfaceArray = m_allocator->AllocateBufferArray(
1208         24 * sizeof(int16_t),
1209         "YCoeffSurface",
1210         m_bufferPoolDepth,
1211         resourceInternalReadWriteCache,
1212         lockableVideoMem);
1213     DECODE_CHK_NULL(m_yCoefficientsSurfaceArray);
1214 
1215     //Y dithering Surface
1216     m_yDitheringSurfaceArray = m_allocator->AllocateSurfaceArray(
1217         128 * ((m_bitDepthIndicator == 1) ? sizeof(int16_t) : sizeof(int8_t)),
1218         128,
1219         "Film Grain RP2 [out] YDitheringSurface",
1220         m_bufferPoolDepth,
1221         Format_R8UN,
1222         false,
1223         resourceInternalReadWriteCache,
1224         notLockableVideoMem);
1225     DECODE_CHK_NULL(m_yDitheringSurfaceArray);
1226 
1227     //U dithering surface
1228     m_uDitheringSurfaceArray = m_allocator->AllocateSurfaceArray(
1229         64 * ((m_bitDepthIndicator == 1) ? sizeof(int16_t) : sizeof(int8_t)),
1230         64,
1231         "Film Grain RP2 [out] UDitheringSurface",
1232         m_bufferPoolDepth,
1233         Format_R8UN,
1234         false,
1235         resourceInternalReadWriteCache,
1236         notLockableVideoMem);
1237     DECODE_CHK_NULL(m_uDitheringSurfaceArray);
1238 
1239     //V Dithering surface
1240     m_vDitheringSurfaceArray = m_allocator->AllocateSurfaceArray(
1241         64 * ((m_bitDepthIndicator == 1) ? sizeof(int16_t) : sizeof(int8_t)),
1242         64,
1243         "Film Grain RP2 [out] VDitheringSurface",
1244         m_bufferPoolDepth,
1245         Format_R8UN,
1246         false,
1247         resourceInternalReadWriteCache,
1248         notLockableVideoMem);
1249     DECODE_CHK_NULL(m_vDitheringSurfaceArray);
1250 
1251     //Y Coefficients Surface, for input of RegressPhase2
1252     m_yCoeffSurfaceArray = m_allocator->AllocateBufferArray(
1253         MOS_ALIGN_CEIL(32 * sizeof(int16_t), CODECHAL_PAGE_SIZE),
1254         "YCoeffSurface",
1255         m_bufferPoolDepth,
1256         resourceInternalReadWriteCache,
1257         lockableVideoMem);
1258     DECODE_CHK_NULL(m_yCoeffSurfaceArray);
1259 
1260     //U Coefficients Surface, for input of RegressPhase2
1261     m_uCoeffSurfaceArray = m_allocator->AllocateBufferArray(
1262         MOS_ALIGN_CEIL(32 * sizeof(int16_t), CODECHAL_PAGE_SIZE),
1263         "UCoeffSurface",
1264         m_bufferPoolDepth,
1265         resourceInternalReadWriteCache,
1266         lockableVideoMem);
1267     DECODE_CHK_NULL(m_uCoeffSurfaceArray);
1268 
1269     //V Coefficients Surface, for input of RegressPhase2
1270     m_vCoeffSurfaceArray = m_allocator->AllocateBufferArray(
1271         MOS_ALIGN_CEIL(32 * sizeof(int16_t), CODECHAL_PAGE_SIZE),
1272         "VCoeffSurface",
1273         m_bufferPoolDepth,
1274         resourceInternalReadWriteCache,
1275         lockableVideoMem);
1276     DECODE_CHK_NULL(m_vCoeffSurfaceArray);
1277 
1278     //Y Gamma LUT Surface, for input of ApplyNoise
1279     m_yGammaLUTSurfaceArray = m_allocator->AllocateBufferArray(
1280         MOS_ALIGN_CEIL(257 * sizeof(int16_t), CODECHAL_PAGE_SIZE),
1281         "YGammaLUTSurface",
1282         m_bufferPoolDepth,
1283         resourceInternalReadWriteCache,
1284         lockableVideoMem);
1285     DECODE_CHK_NULL(m_yGammaLUTSurfaceArray);
1286 
1287     //U Gamma LUT Surface, for input of ApplyNoise
1288     m_uGammaLUTSurfaceArray = m_allocator->AllocateBufferArray(
1289         MOS_ALIGN_CEIL(257 * sizeof(int16_t), CODECHAL_PAGE_SIZE),
1290         "UGammaLUTSurface",
1291         m_bufferPoolDepth,
1292         resourceInternalReadWriteCache,
1293         lockableVideoMem);
1294     DECODE_CHK_NULL(m_uGammaLUTSurfaceArray);
1295 
1296     //V Gamma LUT Surface, for input of ApplyNoise
1297     m_vGammaLUTSurfaceArray = m_allocator->AllocateBufferArray(
1298         MOS_ALIGN_CEIL(257 * sizeof(int16_t), CODECHAL_PAGE_SIZE),
1299         "VGammaLUTSurface",
1300         m_bufferPoolDepth,
1301         resourceInternalReadWriteCache,
1302         lockableVideoMem);
1303     DECODE_CHK_NULL(m_vGammaLUTSurfaceArray);
1304 
1305     return eStatus;
1306 }
1307 
AllocateVariableSizeSurfaces()1308 MOS_STATUS Av1DecodeFilmGrainG12::AllocateVariableSizeSurfaces()
1309 {
1310     MOS_STATUS                  eStatus = MOS_STATUS_SUCCESS;
1311 
1312     DECODE_FUNC_CALL();
1313 
1314     //Random values for coordinates
1315     uint32_t coordsWidth = MOS_ROUNDUP_SHIFT(m_picParams->m_superResUpscaledWidthMinus1 + 1, 6);
1316     uint32_t coordsHeight = MOS_ROUNDUP_SHIFT(m_picParams->m_superResUpscaledHeightMinus1 + 1, 6);
1317     uint32_t allocSize = MOS_ALIGN_CEIL(coordsWidth * coordsHeight * sizeof(int32_t), CODECHAL_PAGE_SIZE);
1318 
1319     if (m_coordinatesRandomValuesSurfaceArray == nullptr)
1320     {
1321         m_coordinatesRandomValuesSurfaceArray= m_allocator->AllocateBufferArray(
1322             allocSize,
1323             "FilmGrainGRVCoordinateSurface",
1324             m_bufferPoolDepth,
1325             resourceInternalReadWriteCache,
1326             notLockableVideoMem);
1327         DECODE_CHK_NULL(m_coordinatesRandomValuesSurfaceArray);
1328         m_coordinatesRandomValuesSurface = m_coordinatesRandomValuesSurfaceArray->Fetch();
1329         DECODE_CHK_NULL(m_coordinatesRandomValuesSurface);
1330     }
1331     else
1332     {
1333         auto &buffer = m_coordinatesRandomValuesSurfaceArray->Fetch();
1334         DECODE_CHK_NULL(buffer);
1335         DECODE_CHK_STATUS(m_allocator->Resize(
1336             buffer, allocSize, notLockableVideoMem));
1337         m_coordinatesRandomValuesSurface = buffer;
1338     }
1339     m_coordinateSurfaceSize = allocSize;
1340 
1341     return eStatus;
1342 }
1343 
InitScalingFunction(uint8_t * pointValue,uint8_t * pointScaling,uint8_t numPoints,int16_t * scalingLUT)1344 MOS_STATUS Av1DecodeFilmGrainG12::InitScalingFunction(
1345     uint8_t *pointValue,    //corresponds to scaling_points[][0]
1346     uint8_t *pointScaling,  //corresponds to scaling_points[][1]
1347     uint8_t numPoints,
1348     int16_t *scalingLUT)
1349 {
1350     MOS_STATUS              eStatus = MOS_STATUS_SUCCESS;
1351 
1352     DECODE_FUNC_CALL();
1353 
1354     DECODE_CHK_NULL(pointValue);
1355     DECODE_CHK_NULL(pointScaling);
1356     DECODE_CHK_NULL(scalingLUT);
1357 
1358     if (numPoints == 0)
1359     {
1360         return MOS_STATUS_SUCCESS;
1361     }
1362 
1363     for (auto i = 0; i < pointValue[0]; i++)
1364     {
1365         scalingLUT[i] = pointScaling[0];
1366     }
1367 
1368     for (auto point = 0; point < numPoints - 1; point++)
1369     {
1370         int32_t delta_y = pointScaling[point + 1] - pointScaling[point];
1371         int32_t delta_x = pointValue[point + 1] - pointValue[point];
1372 
1373         DECODE_CHK_COND(delta_x == 0, " Value of delta x cannot be zero.");
1374         int64_t delta = (int64_t)delta_y * ((65536 + (delta_x >> 1)) / delta_x);
1375 
1376         for (auto x = 0; x < delta_x; x++)
1377         {
1378             scalingLUT[pointValue[point] + x] = pointScaling[point] + (int32_t)((x * delta + 32768) >> 16);
1379         }
1380     }
1381 
1382     for (uint32_t i = pointValue[numPoints - 1]; i < 256; i++)
1383     {
1384         scalingLUT[i] = pointScaling[numPoints - 1];
1385     }
1386 
1387     return eStatus;
1388 }
1389 
PreProcScalingPointsAndLUTs()1390 MOS_STATUS Av1DecodeFilmGrainG12::PreProcScalingPointsAndLUTs()
1391 {
1392     MOS_STATUS                  eStatus = MOS_STATUS_SUCCESS;
1393 
1394     DECODE_FUNC_CALL();
1395 
1396     memset(m_scalingLutY, 0, sizeof(*m_scalingLutY) * 256);
1397     memset(m_scalingLutCb, 0, sizeof(*m_scalingLutCb) * 256);
1398     memset(m_scalingLutCr, 0, sizeof(*m_scalingLutCr) * 256);
1399 
1400     // Check film grain parameter of the luma component
1401     if (m_picParams->m_filmGrainParams.m_numYPoints > 14)
1402     {
1403         DECODE_ASSERTMESSAGE("Invalid film grain num_y_points (should be in [0, 14]) in pic parameter!");
1404         return MOS_STATUS_INVALID_PARAMETER;
1405     }
1406     for (auto i = 1; i < m_picParams->m_filmGrainParams.m_numYPoints; i++)
1407     {
1408         if (m_picParams->m_filmGrainParams.m_pointYValue[i] <= m_picParams->m_filmGrainParams.m_pointYValue[i - 1])
1409         {
1410             DECODE_ASSERTMESSAGE("Invalid film grain point_y_value (point_y_value[%d] should be greater than point_y_value[%d]) in pic parameter!", i, i - 1);
1411             return MOS_STATUS_INVALID_PARAMETER;
1412         }
1413     }
1414     DECODE_CHK_STATUS(InitScalingFunction(
1415         m_picParams->m_filmGrainParams.m_pointYValue,
1416         m_picParams->m_filmGrainParams.m_pointYScaling,
1417         m_picParams->m_filmGrainParams.m_numYPoints,
1418         m_scalingLutY));
1419 
1420     if (m_picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_chromaScalingFromLuma)
1421     {
1422         MOS_SecureMemcpy(m_scalingLutCb, sizeof(int16_t) * 256, m_scalingLutY, sizeof(int16_t) * 256);
1423         MOS_SecureMemcpy(m_scalingLutCr, sizeof(int16_t) * 256, m_scalingLutY, sizeof(int16_t) * 256);
1424     }
1425     else
1426     {
1427         // Check film grain parameter of the cb component
1428         if (m_picParams->m_filmGrainParams.m_numCbPoints > 10)
1429         {
1430             DECODE_ASSERTMESSAGE("Invalid film grain num_cb_points (should be in [0, 10]) in pic parameter!");
1431             return MOS_STATUS_INVALID_PARAMETER;
1432         }
1433         for (auto i = 1; i < m_picParams->m_filmGrainParams.m_numCbPoints; i++)
1434         {
1435             if (m_picParams->m_filmGrainParams.m_pointCbValue[i] <= m_picParams->m_filmGrainParams.m_pointCbValue[i - 1])
1436             {
1437                 DECODE_ASSERTMESSAGE("Invalid film grain point_cb_value (point_cb_value[%d] should be greater than point_cb_value[%d]) in pic parameter!", i, i - 1);
1438                 return MOS_STATUS_INVALID_PARAMETER;
1439             }
1440         }
1441         DECODE_CHK_STATUS(InitScalingFunction(
1442             m_picParams->m_filmGrainParams.m_pointCbValue,
1443             m_picParams->m_filmGrainParams.m_pointCbScaling,
1444             m_picParams->m_filmGrainParams.m_numCbPoints,
1445             m_scalingLutCb));
1446 
1447         // Check film grain parameter of the cr component
1448         if (m_picParams->m_filmGrainParams.m_numCrPoints > 10)
1449         {
1450             DECODE_ASSERTMESSAGE("Invalid film grain num_cr_points (should be in [0, 10]) in pic parameter!");
1451             return MOS_STATUS_INVALID_PARAMETER;
1452         }
1453         for (auto i = 1; i < m_picParams->m_filmGrainParams.m_numCrPoints; i++)
1454         {
1455             if (m_picParams->m_filmGrainParams.m_pointCrValue[i] <= m_picParams->m_filmGrainParams.m_pointCrValue[i - 1])
1456             {
1457                 DECODE_ASSERTMESSAGE("Invalid film grain point_cr_value (point_cr_value[%d] should be greater than point_cr_value[%d]) in pic parameter!", i, i - 1);
1458                 return MOS_STATUS_INVALID_PARAMETER;
1459             }
1460         }
1461         DECODE_CHK_STATUS(InitScalingFunction(
1462             m_picParams->m_filmGrainParams.m_pointCrValue,
1463             m_picParams->m_filmGrainParams.m_pointCrScaling,
1464             m_picParams->m_filmGrainParams.m_numCrPoints,
1465             m_scalingLutCr));
1466     }
1467 
1468     return eStatus;
1469 }
1470 
PreProcArCoeffs(int16_t * yCoeff,int16_t * uCoeff,int16_t * vCoeff)1471 MOS_STATUS Av1DecodeFilmGrainG12::PreProcArCoeffs(
1472     int16_t *yCoeff,
1473     int16_t *uCoeff,
1474     int16_t *vCoeff)
1475 {
1476 
1477     MOS_STATUS                  eStatus = MOS_STATUS_SUCCESS;
1478 
1479     DECODE_FUNC_CALL();
1480 
1481     uint32_t arCoeffLag = m_picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_arCoeffLag;
1482     if (arCoeffLag == 3)
1483     {
1484         for (auto i = 0; i < 24; i++)
1485         {
1486             yCoeff[i] = m_picParams->m_filmGrainParams.m_arCoeffsY[i];
1487         }
1488         for (auto i = 0; i < 25; i++)
1489         {
1490             uCoeff[i] = m_picParams->m_filmGrainParams.m_arCoeffsCb[i];
1491         }
1492         for (auto i = 0; i < 25; i++)
1493         {
1494             vCoeff[i] = m_picParams->m_filmGrainParams.m_arCoeffsCr[i];
1495         }
1496 
1497         return MOS_STATUS_SUCCESS;
1498     }
1499 
1500     memset(yCoeff, 0, 24 * sizeof(int16_t));
1501     memset(uCoeff, 0, 25 * sizeof(int16_t));
1502     memset(vCoeff, 0, 25 * sizeof(int16_t));
1503 
1504     uint32_t mappedIdxLag2[13]  = { 8, 9, 10, 11, 12, 15, 16, 17, 18, 19, 22, 23, 24 };
1505     uint32_t mappedIdxLag1[5]   = { 16, 17, 18, 23, 24 };
1506     uint32_t mappedIdxLag0[1]   = { 24 };
1507 
1508     uint32_t numPosLuma = 2 * arCoeffLag * (arCoeffLag + 1);
1509     uint32_t numPosChroma = numPosLuma;
1510     if (m_picParams->m_filmGrainParams.m_numYPoints > 0)
1511     {
1512         ++numPosChroma;
1513     }
1514 
1515     uint32_t *mappedIdx = nullptr; mappedIdxLag2;
1516     if (arCoeffLag == 2)
1517     {
1518         mappedIdx = mappedIdxLag2;
1519     }
1520     else if (arCoeffLag == 1)
1521     {
1522         mappedIdx = mappedIdxLag1;
1523     }
1524     else if (arCoeffLag == 0)
1525     {
1526         mappedIdx = mappedIdxLag0;
1527     }
1528     else
1529     {
1530         return MOS_STATUS_INVALID_PARAMETER;
1531     }
1532 
1533     for (uint32_t i = 0; i < numPosLuma; i++)
1534     {
1535         yCoeff[mappedIdx[i]] = m_picParams->m_filmGrainParams.m_arCoeffsY[i];
1536     }
1537     for (uint32_t i = 0; i < numPosChroma; i++)
1538     {
1539         uCoeff[mappedIdx[i]] = m_picParams->m_filmGrainParams.m_arCoeffsCb[i];
1540         vCoeff[mappedIdx[i]] = m_picParams->m_filmGrainParams.m_arCoeffsCr[i];
1541     }
1542 
1543     return eStatus;
1544 }
1545 
SetFrameStates(CodecAv1PicParams * picParams)1546 MOS_STATUS Av1DecodeFilmGrainG12::SetFrameStates(
1547     CodecAv1PicParams *picParams)
1548 {
1549     MOS_STATUS                  eStatus = MOS_STATUS_SUCCESS;
1550 
1551     DECODE_CHK_NULL(picParams);
1552 
1553     DECODE_FUNC_CALL();
1554 
1555     // Picture parameters from decoder
1556     m_picParams = picParams;
1557 
1558     //Pre-process Scaling Points related params and calculate scaling LUTs
1559     DECODE_CHK_STATUS(PreProcScalingPointsAndLUTs());
1560 
1561     // Initialize surfaces
1562     int16_t coeffY[24], coeffU[25], coeffV[25];
1563     DECODE_CHK_STATUS(PreProcArCoeffs(coeffY,coeffU, coeffV));
1564 
1565     // Y coefficients surface as input of RegressPhase1
1566     m_yCoefficientsSurface = m_yCoefficientsSurfaceArray->Fetch();
1567     DECODE_CHK_NULL(m_yCoefficientsSurface);
1568     auto data = (int16_t *)m_allocator->LockResourceForWrite(&m_yCoefficientsSurface->OsResource);
1569     DECODE_CHK_NULL(data);
1570     MOS_SecureMemcpy(data, 24 * sizeof(int16_t), coeffY, 24 * sizeof(int16_t));
1571 
1572     //Y/U/V dithering surfaces as out of RegressPhase2
1573     m_yDitheringSurface                = m_yDitheringSurfaceArray->Fetch();
1574     DECODE_CHK_NULL(m_yDitheringSurface);
1575     m_uDitheringSurface                = m_uDitheringSurfaceArray->Fetch();
1576     DECODE_CHK_NULL(m_uDitheringSurface);
1577     m_vDitheringSurface                = m_vDitheringSurfaceArray->Fetch();
1578     DECODE_CHK_NULL(m_vDitheringSurface);
1579 
1580     //Y/U/V coefficients surfaces as input of RegressPhase2
1581     m_yCoeffSurface = m_yCoeffSurfaceArray->Fetch();
1582     DECODE_CHK_NULL(m_yCoeffSurface);
1583     data = (int16_t *)m_allocator->LockResourceForWrite(&m_yCoeffSurface->OsResource);
1584     DECODE_CHK_NULL(data);
1585     MOS_SecureMemcpy(data, 24 * sizeof(int16_t), coeffY, 24 * sizeof(int16_t));
1586 
1587     m_uCoeffSurface = m_uCoeffSurfaceArray->Fetch();
1588     DECODE_CHK_NULL(m_uCoeffSurface);
1589     data = (int16_t *)m_allocator->LockResourceForWrite(&m_uCoeffSurface->OsResource);
1590     DECODE_CHK_NULL(data);
1591     MOS_SecureMemcpy(data, 25 * sizeof(int16_t), coeffU, 25 * sizeof(int16_t));
1592 
1593     m_vCoeffSurface = m_vCoeffSurfaceArray->Fetch();
1594     DECODE_CHK_NULL(m_vCoeffSurface);
1595     data = (int16_t *)m_allocator->LockResourceForWrite(&m_vCoeffSurface->OsResource);
1596     DECODE_CHK_NULL(data);
1597     MOS_SecureMemcpy(data, 25 * sizeof(int16_t), coeffV, 25 * sizeof(int16_t));
1598 
1599     // Scaling LUTs surfaces
1600     m_yGammaLUTSurface = m_yGammaLUTSurfaceArray->Fetch();
1601     DECODE_CHK_NULL(m_yGammaLUTSurface);
1602     data = (int16_t *)m_allocator->LockResourceForWrite(&m_yGammaLUTSurface->OsResource);
1603     DECODE_CHK_NULL(data);
1604     MOS_SecureMemcpy(data, 256 * sizeof(int16_t), m_scalingLutY, 256 * sizeof(int16_t));
1605     data[256] = m_scalingLutY[255];
1606 
1607     m_uGammaLUTSurface = m_uGammaLUTSurfaceArray->Fetch();
1608     DECODE_CHK_NULL(m_uGammaLUTSurface);
1609     data = (int16_t *)m_allocator->LockResourceForWrite(&m_uGammaLUTSurface->OsResource);
1610     DECODE_CHK_NULL(data);
1611     MOS_SecureMemcpy(data, 256 * sizeof(int16_t), m_scalingLutCb, 256 * sizeof(int16_t));
1612     data[256] = m_scalingLutCb[255];
1613 
1614     m_vGammaLUTSurface = m_vGammaLUTSurfaceArray->Fetch();
1615     DECODE_CHK_NULL(m_vGammaLUTSurface);
1616     data = (int16_t *)m_allocator->LockResourceForWrite(&m_vGammaLUTSurface->OsResource);
1617     DECODE_CHK_NULL(data);
1618     MOS_SecureMemcpy(data, 256 * sizeof(int16_t), m_scalingLutCr, 256 * sizeof(int16_t));
1619     data[256] = m_scalingLutCr[255];
1620 
1621     return eStatus;
1622 }
1623 
1624 }  // namespace Decode
1625