Debian Codegraph @

media_driver/agnostic/gen11/codec/kernel_free/Source/downscale_convert_kernel_genx.cpp

raw
1 /*
2 * Copyright (c) 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 #include <cm/cm.h>
24
25 #define CURBEDATACTR_SIZE 10
26
27 const uint Stat_offsets[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
28 static const ushort masktab[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
29 static const uint offset_idx[] = {0,1,2,3,4,5,6,7};
30
31 #define NV12 0
32 #define P010 1
33 #define P210 2
34 #define YUY2 3
35 #define Y210 4
36 #define ARGB 5
37 #define NV12_Linear 6
38
39 #define HEVC_HISTORY_BUFFER_ENTRY_SIZE 32
40 #define HEVC_MT_TASKDATA_BUFFER_ENTRY_SIZE 96
41
42 ////////////////////CURBE and VME//////////////////////////////////////
43
44 extern "C" _GENX_MAIN_ void DS_Convert(
45 vector<uint, CURBEDATACTR_SIZE> CURBEData,
46 SurfaceIndex PakSurfIndex,
47 SurfaceIndex EncSurfIndex,
48 SurfaceIndex DS4XSurf,
49 SurfaceIndex MBStats,
50 SurfaceIndex DS2XSurf,
51 SurfaceIndex Hevc_History_Surface_index,
52 SurfaceIndex Hevc_History_Sum_Surface_index,
53 SurfaceIndex Scratch_Surface_index
54 )
55 {
56 ushort h_pos = get_thread_origin_x();
57 ushort v_pos = get_thread_origin_y();
58
59 vector_ref<uchar, 4 * CURBEDATACTR_SIZE> CURBEData_U8 = CURBEData.format<uchar>();
60 vector_ref<ushort, 2 * CURBEDATACTR_SIZE> CURBEData_U16 = CURBEData.format<ushort>();
61
62 uchar ENCChromaDepth = CURBEData_U8(2);
63 uchar ENCLumaDepth = CURBEData_U8(3) & 0x7F;
64 uchar colorformat = CURBEData_U8(4);
65 vector<ushort, 1>uWidth = CURBEData_U8.format<ushort>().select<1, 1>(4);
66 vector<ushort, 1>uHeight = CURBEData_U8.format<ushort>().select<1, 1>(5);
67
68 uint height, width;
69
70 uchar bflagConvert = CURBEData_U8(5) & 0x01;
71 uchar stage = (CURBEData_U8(5) >> 1) & 0x7;
72 uchar MBStatflag = (CURBEData_U8(5) >> 4) & 0x1;
73
74 if(stage == 3)
75 {
76 height = (((uHeight(0) >> 2) + 31) / 32) * 32;
77 width = (((uWidth(0) >> 2) + 31) / 32) * 32;
78 }
79 else
80 {
81 height = uHeight(0);
82 width = uWidth(0);
83 }
84
85 uint Flatness_Threshold = CURBEData(3);
86
87 // CSC Coefficients
88 ushort CSC0 = CURBEData_U16(8);
89 ushort CSC1 = CURBEData_U16(9);
90 ushort CSC2 = CURBEData_U16(10);
91 ushort CSC3 = CURBEData_U16(11);
92 ushort CSC4 = CURBEData_U16(12);
93 ushort CSC5 = CURBEData_U16(13);
94 ushort CSC6 = CURBEData_U16(14);
95 ushort CSC7 = CURBEData_U16(15);
96 ushort CSC8 = CURBEData_U16(16);
97 ushort CSC9 = CURBEData_U16(17);
98 ushort CSC10 = CURBEData_U16(18);
99 ushort CSC11 = CURBEData_U16(19);
100
101 // Chroma Siting Location
102 uchar chroma_siting_location = CURBEData_U8(6);
103
104 vector<uint, 1> numLCUs;
105 matrix<uchar, 32, 32> YPix;
106
107 vector<ushort, 1> replicate;
108 replicate[0] = 0;
109 ushort h_pos_write = h_pos << 3;
110 ushort v_pos_write = v_pos << 3;
111
112 ushort h_pos_read = h_pos_write;
113 vector<ushort, 1> v_pos_read = v_pos_write;
114 vector<ushort, 1> max_dst_row = v_pos_write + 8;
115 vector<ushort, 1> max_real_dst_row = (height >> 2);
116
117 if (stage == 3)
118 {
119 max_real_dst_row = uHeight(0) >> 4;
120 }
121
122 replicate.merge((max_dst_row - max_real_dst_row), (max_dst_row > max_real_dst_row));
123
124 v_pos_read.merge(((max_real_dst_row << 2) - 4) >> 2, v_pos_write >= max_real_dst_row);
125 replicate.merge(7, v_pos_write >= max_real_dst_row);
126
127 int final_h_pos = h_pos_read << 2;
128 int final_h_pos_plus_32 = 2 * final_h_pos + 32;
129
130 int final_v_pos = v_pos_read(0) << 2;
131 int final_v_pos_c = final_v_pos >> 1 ;
132
133 vector<ushort, 1> replicate2;
134 replicate2[0] = 0;
135
136 ushort h_pos_write2 = h_pos << 4;
137 ushort v_pos_write2 = v_pos << 4;
138 ushort h_pos_read2 = h_pos_write2;
139
140 vector<ushort, 1> v_pos_read2 = v_pos_write2;
141 vector<ushort, 1> max_dst_row2 = v_pos_write2 + 16;
142
143 vector<ushort, 1> max_real_dst_row2 = (height >> 1);
144
145 if(stage==3)
146 {
147 max_real_dst_row2 = uHeight(0) >> 5;
148 }
149
150 replicate2.merge((max_dst_row2 - max_real_dst_row2), (max_dst_row2 > max_real_dst_row2));
151
152 v_pos_read2.merge(max_real_dst_row2 - 1, v_pos_write2 >= max_real_dst_row2);
153 replicate2.merge(15, v_pos_write2 >= max_real_dst_row2);
154
155 v_pos_read2[0] = v_pos_read2[0] << 1;
156
157 uint final_h_pos_argb = 0;
158 uchar quot = 0, first_index_val = 0, first_index = 0;
159
160 if(bflagConvert)
161 {
162 final_h_pos_argb = final_h_pos;
163 if(final_h_pos == width)
164 {
165 final_h_pos_argb = final_h_pos - 32;
166 }
167
168 quot = (final_h_pos + 31) / width;
169 first_index_val = (final_h_pos + 31) % width;
170 first_index = first_index_val;
171
172 if((first_index_val > 32) && (quot > 0))
173 {
174 final_h_pos_argb = final_h_pos - (first_index_val / 32) * 32;
175 first_index = first_index_val - (first_index_val / 32) * 32;
176
177 if(final_h_pos_argb == width)
178 {
179 final_h_pos_argb = final_h_pos_argb - 32;
180 }
181 }
182
183 if(colorformat == P010)
184 {
185 matrix<ushort, 32, 32> YPix_16;
186 vector<ushort, 1> max_col = h_pos_write;
187 vector<ushort, 1> max_real_col = width >> 2;
188 vector<ushort, 1> replicate_col(0);
189
190 replicate_col.merge(1, (max_col >= max_real_col));
191 if(replicate_col[0])
192 {
193 read_plane(PakSurfIndex, GENX_SURFACE_Y_PLANE, 2 * width - 2, final_v_pos, YPix_16.select<32, 1, 4, 1>(0, 0));
194 YPix_16.select<32, 1, 4, 1>(0, 4) = YPix_16.select<32, 1, 4, 1>(0, 0);
195 YPix_16.select<32, 1, 8, 1>(0, 8) = YPix_16.select<32, 1, 8, 1>(0, 0);
196 YPix_16.select<32, 1, 16, 1>(0, 16) = YPix_16.select<32, 1, 16,1>(0, 0);
197 }
198 else
199 {
200 read_plane(PakSurfIndex, GENX_SURFACE_Y_PLANE, 2 * final_h_pos, final_v_pos, YPix_16.select<8, 1, 16, 1>(0, 0));
201 read_plane(PakSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos_plus_32, final_v_pos, YPix_16.select<8, 1, 16, 1>(0, 16));
202 read_plane(PakSurfIndex, GENX_SURFACE_Y_PLANE, 2 * final_h_pos, final_v_pos + 8, YPix_16.select<8, 1, 16, 1>(8, 0));
203 read_plane(PakSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos_plus_32, final_v_pos + 8, YPix_16.select<8, 1, 16, 1>(8, 16));
204 read_plane(PakSurfIndex, GENX_SURFACE_Y_PLANE, 2 * final_h_pos, final_v_pos + 16, YPix_16.select<8, 1, 16, 1>(16, 0));
205 read_plane(PakSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos_plus_32, final_v_pos + 16, YPix_16.select<8, 1, 16, 1>(16, 16));
206 read_plane(PakSurfIndex, GENX_SURFACE_Y_PLANE, 2 * final_h_pos, final_v_pos + 24, YPix_16.select<8, 1, 16, 1>(24, 0));
207 read_plane(PakSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos_plus_32, final_v_pos + 24, YPix_16.select<8, 1, 16, 1>(24, 16));
208 }
209
210 uint shiftval = 16 - ENCLumaDepth;
211 uint tempval = 1 << (shiftval - 1);
212
213 vector<ushort, 32> roundval;
214 vector<uchar, 32> roundingenable = 1;
215
216 roundval.merge(tempval, 0, roundingenable);
217
218 vector<ushort, 32> temptemp;
219 int cnt;
220 for(cnt=0; cnt < 32; cnt++)
221 {
222 temptemp = YPix_16.row(cnt);
223 temptemp.merge(temptemp, 0xFF00, temptemp < 0xFF00);
224 YPix.row(cnt) = cm_shr<uchar>(temptemp + tempval, shiftval);
225 }
226
227 matrix_ref<ushort, 16, 32> UVPix_16 = YPix_16.select<16, 1, 32, 1>(0, 0);
228 matrix<uchar, 16, 32> UVPix;
229
230 read_plane(PakSurfIndex, GENX_SURFACE_UV_PLANE, 2 * final_h_pos, final_v_pos_c, UVPix_16.select<8, 1, 16, 1>(0, 0));
231 read_plane(PakSurfIndex, GENX_SURFACE_UV_PLANE, final_h_pos_plus_32, final_v_pos_c, UVPix_16.select<8, 1, 16, 1>(0, 16));
232 read_plane(PakSurfIndex, GENX_SURFACE_UV_PLANE, 2 * final_h_pos, final_v_pos_c + 8, UVPix_16.select<8, 1, 16, 1>(8, 0));
233 read_plane(PakSurfIndex, GENX_SURFACE_UV_PLANE, final_h_pos_plus_32, final_v_pos_c + 8, UVPix_16.select<8, 1, 16, 1>(8, 16));
234
235 shiftval = 16 - ENCChromaDepth;
236 tempval = 1 << (shiftval - 1);
237 roundval.merge(tempval, 0, roundingenable);
238
239 for(cnt = 0; cnt < 16; cnt++)
240 {
241 temptemp = UVPix_16.row(cnt);
242 temptemp.merge(temptemp, 0xFF00, temptemp < 0xFF00);
243 UVPix.row(cnt) = cm_shr<uchar>(temptemp + tempval, shiftval);
244 }
245
246 write_plane(EncSurfIndex, GENX_SURFACE_UV_PLANE, final_h_pos, final_v_pos_c, UVPix.select<8, 1, 32, 1>(0, 0));
247 write_plane(EncSurfIndex, GENX_SURFACE_UV_PLANE, final_h_pos, final_v_pos_c + 8, UVPix.select<8, 1, 32, 1>(8, 0));
248
249 write_plane(EncSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos, final_v_pos, YPix.select<8, 1, 32, 1>(0, 0));
250 write_plane(EncSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos, final_v_pos + 8, YPix.select<8, 1, 32, 1>(8, 0));
251 write_plane(EncSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos, final_v_pos + 16, YPix.select<8, 1, 32, 1>(16,0));
252 write_plane(EncSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos, final_v_pos + 24, YPix.select<8, 1, 32, 1>(24,0));
253
254 if (!stage)
255 {
256 cm_fence();
257 return;
258 }
259 }
260 else if (colorformat == Y210)
261 {
262 matrix<ushort, 8, 32> YUV_Data16_10bit;
263 matrix<uchar, 8, 32> UVPix_422;
264
265 read (PakSurfIndex, 4 * final_h_pos_argb, final_v_pos, YUV_Data16_10bit.select<8, 1, 16, 1>(0, 0));
266 read (PakSurfIndex, 4 * final_h_pos_argb + 32, final_v_pos, YUV_Data16_10bit.select<8, 1, 16, 1>(0, 16));
267
268 YUV_Data16_10bit.merge(YUV_Data16_10bit, 0xFF00, YUV_Data16_10bit < 0xFF00);
269
270 YPix.select<8, 1, 16, 1>(0, 0) = cm_shr<uchar>(YUV_Data16_10bit.select<8, 1, 16, 2>(0, 0) + 0x80, 8);
271 UVPix_422.select<8, 1, 16, 1>(0, 0) = cm_shr<uchar>(YUV_Data16_10bit.select<8, 1, 16, 2>(0, 1) + 0x80, 8);
272
273 read (PakSurfIndex, 4 * final_h_pos_argb+64, final_v_pos, YUV_Data16_10bit.select<8, 1, 16, 1>(0, 0));
274 read (PakSurfIndex, 4 * final_h_pos_argb+96, final_v_pos, YUV_Data16_10bit.select<8, 1, 16, 1>(0, 16));
275
276 YUV_Data16_10bit.merge(YUV_Data16_10bit, 0xFF00, YUV_Data16_10bit < 0xFF00);
277 YPix.select<8, 1, 16, 1>(0, 16) = cm_shr<uchar>(YUV_Data16_10bit.select<8, 1, 16, 2>(0, 0) + 0x80, 8);
278 UVPix_422.select<8,1,16,1>(0,16) = cm_shr<uchar>(YUV_Data16_10bit.select<8, 1, 16, 2>(0, 1) + 0x80, 8);
279
280 if((final_v_pos + 8) <= height)
281 {
282 write(EncSurfIndex, final_h_pos, final_v_pos, YPix.select<8, 1, 32, 1>(0, 0));
283 }
284 write(EncSurfIndex, final_h_pos, height + final_v_pos, UVPix_422 );
285
286 read (PakSurfIndex, 4 * final_h_pos_argb, final_v_pos + 8, YUV_Data16_10bit.select<8, 1, 16, 1>(0, 0));
287 read (PakSurfIndex, 4 * final_h_pos_argb + 32, final_v_pos + 8, YUV_Data16_10bit.select<8, 1, 16, 1>(0, 16));
288
289 YUV_Data16_10bit.merge(YUV_Data16_10bit, 0xFF00, YUV_Data16_10bit < 0xFF00);
290 YPix.select<8, 1, 16, 1>(8, 0) = cm_shr<uchar>(YUV_Data16_10bit.select<8, 1, 16, 2>(0, 0) + 0x80, 8);
291 UVPix_422.select<8,1,16,1>(0, 0) = cm_shr<uchar>(YUV_Data16_10bit.select<8, 1, 16, 2>(0, 1) + 0x80, 8);
292
293 read (PakSurfIndex, 4 * final_h_pos_argb + 64, final_v_pos + 8, YUV_Data16_10bit.select<8, 1, 16, 1>(0, 0));
294 read (PakSurfIndex, 4 * final_h_pos_argb + 96, final_v_pos + 8, YUV_Data16_10bit.select<8, 1, 16, 1>(0, 16));
295
296 YUV_Data16_10bit.merge(YUV_Data16_10bit, 0xFF00, YUV_Data16_10bit < 0xFF00);
297 YPix.select<8, 1, 16, 1>(8, 16) = cm_shr<uchar>(YUV_Data16_10bit.select<8, 1, 16, 2>(0, 0) + 0x80, 8);
298 UVPix_422.select<8,1,16,1>(0, 16) = cm_shr<uchar>(YUV_Data16_10bit.select<8, 1, 16, 2>(0, 1) + 0x80, 8);
299
300 if( (final_v_pos + 16) <= height)
301 {
302 write(EncSurfIndex, final_h_pos, final_v_pos + 8, YPix.select<8, 1, 32, 1>(8, 0) );
303 }
304 write(EncSurfIndex, final_h_pos, height + final_v_pos + 8, UVPix_422 );
305
306 read (PakSurfIndex, 4 * final_h_pos_argb, final_v_pos + 16, YUV_Data16_10bit.select<8, 1, 16, 1>(0, 0));
307 read (PakSurfIndex, 4 * final_h_pos_argb + 32, final_v_pos + 16, YUV_Data16_10bit.select<8, 1, 16, 1>(0, 16));
308
309 YUV_Data16_10bit.merge(YUV_Data16_10bit, 0xFF00, YUV_Data16_10bit < 0xFF00);
310 YPix.select<8, 1, 16, 1>(16, 0) = cm_shr<uchar>(YUV_Data16_10bit.select<8, 1, 16, 2>(0, 0) + 0x80, 8);
311 UVPix_422.select<8, 1, 16, 1>(0, 0) = cm_shr<uchar>(YUV_Data16_10bit.select<8, 1, 16, 2>(0, 1) + 0x80, 8);
312
313 read (PakSurfIndex, 4 * final_h_pos_argb + 64, final_v_pos+16, YUV_Data16_10bit.select<8, 1, 16, 1>(0, 0));
314 read (PakSurfIndex, 4 * final_h_pos_argb + 96, final_v_pos+16, YUV_Data16_10bit.select<8, 1, 16, 1>(0, 16));
315
316 YUV_Data16_10bit.merge(YUV_Data16_10bit, 0xFF00, YUV_Data16_10bit < 0xFF00);
317 YPix.select<8, 1, 16, 1>(16, 16) = cm_shr<uchar>(YUV_Data16_10bit.select<8, 1, 16, 2>(0, 0) + 0x80, 8);
318 UVPix_422.select<8,1,16,1>(0, 16) = cm_shr<uchar>(YUV_Data16_10bit.select<8, 1, 16, 2>(0, 1) + 0x80, 8);
319
320 if( (final_v_pos + 24) <= height)
321 {
322 write(EncSurfIndex, final_h_pos, final_v_pos+16, YPix.select<8, 1, 32, 1>(16, 0) );
323 }
324 write(EncSurfIndex, final_h_pos, height + final_v_pos + 16, UVPix_422 );
325
326 read (PakSurfIndex, 4 * final_h_pos_argb, final_v_pos + 24, YUV_Data16_10bit.select<8, 1, 16, 1>(0, 0));
327 read (PakSurfIndex, 4 * final_h_pos_argb + 32, final_v_pos + 24, YUV_Data16_10bit.select<8, 1, 16, 1>(0, 16));
328
329 YUV_Data16_10bit.merge(YUV_Data16_10bit, 0xFF00, YUV_Data16_10bit < 0xFF00);
330 YPix.select<8, 1, 16, 1>(24, 0) = cm_shr<uchar>(YUV_Data16_10bit.select<8, 1, 16, 2>(0, 0) + 0x80, 8);
331 UVPix_422.select<8, 1, 16, 1>(0, 0) = cm_shr<uchar>(YUV_Data16_10bit.select<8, 1, 16, 2>(0, 1) + 0x80, 8);
332
333 read (PakSurfIndex, 4 * final_h_pos_argb + 64, final_v_pos + 24, YUV_Data16_10bit.select<8, 1, 16, 1>(0, 0));
334 read (PakSurfIndex, 4 * final_h_pos_argb + 96, final_v_pos + 24, YUV_Data16_10bit.select<8, 1, 16, 1>(0, 16));
335
336 YUV_Data16_10bit.merge(YUV_Data16_10bit, 0xFF00, YUV_Data16_10bit < 0xFF00);
337 YPix.select<8, 1, 16, 1>(24, 16) = cm_shr<uchar>(YUV_Data16_10bit.select<8, 1, 16, 2>(0, 0) + 0x80, 8);
338 UVPix_422.select<8, 1, 16, 1>(0, 16) = cm_shr<uchar>(YUV_Data16_10bit.select<8, 1, 16, 2>(0, 1) + 0x80, 8);
339
340 if( (final_v_pos + 32) <= height)
341 {
342 write(EncSurfIndex, final_h_pos, final_v_pos + 24, YPix.select<8, 1, 32, 1>(24, 0) );
343 }
344 write(EncSurfIndex, final_h_pos, height + final_v_pos+24, UVPix_422 );
345 }
346 else if(colorformat == ARGB)
347 {
348 matrix<uchar, 16, 32> ARGB_Data;
349 matrix_ref<uchar, 8, 32> c1 = ARGB_Data.select<8,1,32,1>(0, 0);
350 matrix<uchar, 16, 32> r;
351 matrix<uchar, 16, 32> g;
352 matrix<uchar, 16, 32> b;
353
354 for(uint i = 0; i < 2; i++)
355 {
356 #pragma unroll
357 for( int j = 0; j < 4;j++)
358 {
359 read(PakSurfIndex, 4 * final_h_pos_argb + 32 * j, final_v_pos + i * 16, c1);
360 r.select<8, 1, 8, 1>(0, 8 * j) = c1.select<8, 1, 8, 4>(0, 2);
361 g.select<8, 1, 8, 1>(0, 8 * j) = c1.select<8, 1, 8, 4>(0, 1);
362 b.select<8, 1, 8, 1>(0, 8 * j) = c1.select<8, 1, 8, 4>(0, 0);
363 }
364
365 #pragma unroll
366 for( int j = 0; j < 4;j++)
367 {
368 read(PakSurfIndex, 4 * final_h_pos_argb + 32 * j, final_v_pos + i * 16 + 8, c1);
369 r.select<8,1,8,1>(8,8*j) = c1.select<8, 1, 8, 4>(0, 2);
370 g.select<8,1,8,1>(8,8*j) = c1.select<8, 1, 8, 4>(0, 1);
371 b.select<8,1,8,1>(8,8*j) = c1.select<8, 1, 8, 4>(0, 0);
372 }
373
374 if(quot > 0)
375 {
376 vector<uchar, 32> replicants;
377 vector<ushort, 32> masktable = 1;
378
379 vector<ushort, 32> final_h_pos_mask(masktab);
380 final_h_pos_mask = final_h_pos_mask + final_h_pos;
381
382 masktable.merge(masktable, 0, final_h_pos_mask < width);
383
384 for(uint mcount=0;mcount<16;mcount++)
385 {
386 replicants = r(mcount,first_index);
387 r.row(mcount).merge(r.row(mcount), replicants, masktable);
388
389 replicants = g(mcount,first_index);
390 g.row(mcount).merge(g.row(mcount), replicants, masktable);
391
392 replicants = b(mcount,first_index);
393 b.row(mcount).merge(b.row(mcount), replicants, masktable);
394 }
395 }
396
397 vector<uint, 32> temp;
398 matrix_ref<uchar, 16, 32> v = YPix.select<16, 1, 32, 1>(16, 0).format<uchar, 16, 32>();
399
400 #pragma unroll
401 for(uint k = 0; k < 16; k++)
402 {
403 temp = g.row(k) * CSC8;
404 temp = temp + r.row(k) * CSC10;
405
406 temp = (temp + b.row(k) * CSC9) >> 7;
407 ARGB_Data.row(k) = temp.select<32,1>(0) + CSC11;
408 }
409
410 #pragma unroll
411 for(uint k=0; k<16; k++)
412 {
413 temp = r.row(k) * CSC2;
414 temp = temp + g.row(k) * CSC0;
415 temp = (temp + b.row(k) * CSC1) >> 7;
416 v.row(k) = temp.select<32,1>(0) + CSC3;
417 }
418
419 matrix<ushort, 4, 16> first_sum;
420 if (chroma_siting_location == 1)
421 {
422
423 #pragma unroll
424 for(uint k = 0; k < 2; k++)
425 {
426 first_sum.select<4, 1, 16, 1>(0, 0) = ARGB_Data.select<4, 2, 16, 2>(8 * k, 0) + ARGB_Data.select<4, 2, 16, 2>(8 * k, 1);
427 first_sum.select<4, 1, 16, 1>(0, 0) += 1;
428 ARGB_Data.select<4, 1, 16, 2>(4 * k, 0) = first_sum.select<4, 1, 16, 1>(0, 0) >> 1;
429 }
430
431 #pragma unroll
432 for(uint k=0; k<2; k++)
433 {
434 first_sum.select<4, 1, 16, 1>(0, 0) = v.select<4, 2, 16, 2>(8 * k, 0) + v.select<4, 2, 16, 2>(8 * k, 1);
435 first_sum.select<4, 1, 16, 1>(0, 0) += 1;
436 ARGB_Data.select<4, 1, 16, 2>(4 * k, 1) = first_sum.select<4, 1, 16, 1>(0, 0) >> 1;
437 }
438 }
439 else if (chroma_siting_location == 2)
440 {
441 #pragma unroll
442 for(uint k = 0; k < 2; k++)
443 {
444 first_sum.select<4, 1, 16, 1>(0, 0) = ARGB_Data.select<4, 2, 16, 2>(8 * k + 1, 0) + ARGB_Data.select<4, 2, 16, 2>(8 * k + 1, 1);
445 first_sum.select<4, 1, 16, 1>(0, 0) += 1;
446 ARGB_Data.select<4, 1, 16, 2>(4 * k, 0) = first_sum.select<4, 1, 16, 1>(0, 0) >> 1;
447 }
448
449 #pragma unroll
450 for(uint k=0; k<2; k++)
451 {
452 first_sum.select<4, 1, 16, 1>(0, 0) = v.select<4, 2, 16, 2>(8 * k + 1, 0) + v.select<4, 2, 16, 2>(8 * k + 1, 1);
453 first_sum.select<4, 1, 16, 1>(0, 0) += 1;
454 ARGB_Data.select<4, 1, 16, 2>(4 * k, 1) = first_sum.select<4, 1, 16, 1>(0, 0) >> 1;
455 }
456 }
457 else if (chroma_siting_location == 3)
458 {
459 ARGB_Data.select<8, 1, 16, 2>(0, 0) = ARGB_Data.select<8, 2, 16, 2>(0, 0);
460 ARGB_Data.select<8, 1, 16, 2>(0, 1) = v.select<8, 2, 16, 2>(0, 0);
461 }
462 else if (chroma_siting_location == 4)
463 {
464 #pragma unroll
465 for(uint k=0; k<2; k++)
466 {
467 first_sum.select<4, 1, 16, 1>(0, 0) = ARGB_Data.select<4, 2, 16, 2>(8 * k, 0) + ARGB_Data.select<4, 2, 16, 2>(8 * k + 1, 0);
468 first_sum.select<4, 1, 16, 1>(0, 0) += 1;
469 ARGB_Data.select<4, 1, 16, 2>(4 * k, 0) = first_sum.select<4, 1, 16, 1>(0, 0) >> 1;
470 }
471
472 #pragma unroll
473 for(uint k=0; k<2; k++)
474 {
475 first_sum.select<4, 1, 16, 1>(0, 0) = v.select<4, 2, 16, 2>(8 * k, 0) + v.select<4, 2, 16, 2>(8 * k + 1, 0);
476 first_sum.select<4, 1, 16, 1>(0, 0) += 1;
477 ARGB_Data.select<4, 1, 16, 2>(4 * k, 1) = first_sum.select<4, 1, 16, 1>(0, 0) >> 1;
478 }
479 }
480 else if (chroma_siting_location == 5)
481 {
482 ARGB_Data.select<8, 1, 16, 2>(0, 0) = ARGB_Data.select<8, 2, 16, 2>(1, 0);
483 ARGB_Data.select<8, 1, 16, 2>(0, 1) = v.select<8, 2, 16, 2>(1, 0);
484 }
485 else
486 {
487
488 #pragma unroll
489 for(uint k = 0; k < 4; k++)
490 {
491 first_sum = ARGB_Data.select<4, 1, 16, 2>(4 * k, 0) + ARGB_Data.select<4, 1, 16, 2>(4 * k, 1);
492
493 first_sum.select<2, 1, 16, 1>(0, 0) = first_sum.select<2, 2, 16, 1>(0, 0) + first_sum.select<2, 2, 16, 1>(1, 0);
494 first_sum.select<2, 1, 16, 1>(0, 0) += 2;
495 ARGB_Data.select<2, 1, 16, 2>(2*k, 0) = first_sum.select<2, 1, 16, 1>(0, 0) >> 2;
496 }
497
498 #pragma unroll
499 for(uint k=0; k<4; k++)
500 {
501 first_sum = v.select<4, 1, 16, 2>(4 * k, 0) + v.select<4, 1, 16, 2>(4 * k, 1);
502
503 first_sum.select<2, 1, 16, 1>(0, 0) = first_sum.select<2, 2, 16, 1>(0, 0) + first_sum.select<2, 2, 16, 1>(1, 0);
504 first_sum.select<2, 1, 16, 1>(0, 0) += 2;
505 ARGB_Data.select<2, 1, 16, 2>(2 * k, 1) = first_sum.select<2, 1, 16, 1>(0, 0) >> 2;
506 }
507 }
508
509 write_plane(EncSurfIndex, GENX_SURFACE_UV_PLANE, final_h_pos, (final_v_pos >> 1) + i * 8, ARGB_Data.select<8, 1, 32, 1>(0, 0));
510
511 #pragma unroll
512 for(uint k=0; k < 16; k++)
513 {
514 temp = r.row(k) * CSC6;
515 temp = temp + g.row(k) * CSC4;
516 temp = (temp + b.row(k) * CSC5) >> 7;
517 ARGB_Data.row(k) = temp.select<32,1>(0) + CSC7;
518 }
519
520 write_plane(EncSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos, final_v_pos + i*16, ARGB_Data.select<8, 1, 32, 1>(0, 0));
521 write_plane(EncSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos, final_v_pos + i*16 + 8, ARGB_Data.select<8, 1, 32, 1>(8, 0));
522 YPix.select<16,1,32,1>(0+i*16,0) = ARGB_Data.select<16,1,32,1>(0,0);
523 }
524
525 if (!stage)
526 {
527 cm_fence();
528 return;
529 }
530 }
531 else if (colorformat == YUY2)
532 {
533 matrix<uchar, 8, 64> YUV_Data8_8bit;
534 matrix<ushort, 4, 32> temp = 0;
535
536 uchar YUY2convertflag = (CURBEData_U8(5) >> 5) & 0x1;
537
538 for(int i=0; i<2; i++)
539 {
540 read (PakSurfIndex, 2 * final_h_pos_argb, final_v_pos + i * 16, YUV_Data8_8bit.select<8, 1, 32, 1>(0, 0));
541 read (PakSurfIndex, 2 * final_h_pos_argb + 32, final_v_pos + i * 16, YUV_Data8_8bit.select<8, 1, 32, 1>(0, 32));
542
543 YPix.select<8, 1, 32, 1>(i * 16, 0) = YUV_Data8_8bit.select<8, 1, 32, 2>(0, 0);
544
545 if(YUY2convertflag)
546 {
547 matrix_ref<uchar, 8, 32> uv_channel = YUV_Data8_8bit.select<8, 1, 32, 2>(0, 1);
548
549 temp.select<4, 1, 32, 1>(0, 0) = uv_channel.select<4, 2, 32, 1>(0, 0) + uv_channel.select<4, 2, 32, 1>(1, 0);
550 temp.select<4, 1, 32, 1>(0, 0) += 1;
551 temp.select<4, 1, 32, 1>(0, 0) = temp.select<4, 1, 32, 1>(0, 0) >> 1;
552
553 matrix_ref <uchar, 4, 64> uv_temp = temp.format<uchar, 4, 64>();
554 matrix_ref <uchar, 4, 32> uv = uv_temp.select<4, 1, 32, 2>(0, 0);
555
556 if( (final_v_pos+8 + i * 16) <= height)
557 {
558 write_plane(EncSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos, final_v_pos + i * 16, YUV_Data8_8bit.select<8, 1, 32, 2>(0, 0));
559 }
560
561 write_plane(EncSurfIndex, GENX_SURFACE_UV_PLANE, final_h_pos, (final_v_pos >> 1) + i * 8, uv.select<4, 1, 32, 1>(0, 0));
562 }
563 else
564 {
565 if( (final_v_pos + 8 + i * 16) <= height)
566 {
567 write(EncSurfIndex, final_h_pos, final_v_pos + i * 16, YUV_Data8_8bit.select<8, 1, 32, 2>(0, 0));
568 }
569 write(EncSurfIndex, final_h_pos, height + final_v_pos + i * 16, YUV_Data8_8bit.select<8, 1, 32, 2>(0, 1));
570 }
571
572
573 read (PakSurfIndex, 2 * final_h_pos_argb, final_v_pos + 8 + i * 16, YUV_Data8_8bit.select<8, 1, 32, 1>(0, 0));
574 read (PakSurfIndex, 2 * final_h_pos_argb + 32, final_v_pos + 8 + i * 16, YUV_Data8_8bit.select<8, 1, 32, 1>(0, 32));
575 YPix.select<8, 1, 32, 1>(8 + i * 16, 0) = YUV_Data8_8bit.select<8, 1, 32, 2>(0, 0);
576
577 if(YUY2convertflag)
578 {
579 matrix_ref<uchar, 8, 32> uv_channel = YUV_Data8_8bit.select<8, 1, 32, 2>(0, 1);
580 temp.select<4, 1, 32, 1>(0, 0) = uv_channel.select<4, 2, 32, 1>(0, 0) + uv_channel.select<4, 2, 32, 1>(1, 0);
581 temp.select<4, 1, 32, 1>(0, 0) += 1;
582 temp.select<4, 1, 32, 1>(0, 0) = temp.select<4, 1, 32, 1>(0, 0) >> 1;
583
584 matrix_ref<uchar, 4, 64> uv_temp = temp.format<uchar, 4, 64>();
585 matrix_ref<uchar, 4, 32> uv = uv_temp.select<4, 1, 32, 2>(0, 0);
586
587 if ((final_v_pos+16 + i * 16) <= height)
588 {
589 write_plane(EncSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos, final_v_pos + 8 + i * 16, YUV_Data8_8bit.select<8, 1, 32, 2>(0, 0) );
590 }
591 write_plane(EncSurfIndex, GENX_SURFACE_UV_PLANE, final_h_pos, (final_v_pos >> 1) + 4 + i * 8, uv.select<4, 1, 32, 1>(0, 0));
592 }
593 else
594 {
595 if ((final_v_pos + 16 + i * 16) <= height)
596 {
597 write(EncSurfIndex, final_h_pos, final_v_pos + 8 + i * 16, YUV_Data8_8bit.select<8, 1, 32, 2>(0, 0));
598 }
599 write(EncSurfIndex, final_h_pos, height + final_v_pos + 8 + i * 16, YUV_Data8_8bit.select<8, 1, 32, 2>(0, 1));
600 }
601 }
602
603 if(!stage)
604 {
605 cm_fence();
606 return;
607 }
608 }
609 else if (colorformat == NV12_Linear)
610 {
611 read(PakSurfIndex, final_h_pos, height + (final_v_pos >> 1), YPix.select<8,1,32,1>(0, 0));
612 read(PakSurfIndex, final_h_pos, height + (final_v_pos >> 1) + 8, YPix.select<8,1,32,1>(8, 0));
613
614 write_plane(EncSurfIndex, GENX_SURFACE_UV_PLANE, final_h_pos, final_v_pos >> 1, YPix.select<8,1,32,1>(0, 0));
615 write_plane(EncSurfIndex, GENX_SURFACE_UV_PLANE, final_h_pos, (final_v_pos >> 1) + 8, YPix.select<8,1,32,1>(8, 0));
616
617 read(PakSurfIndex, final_h_pos, final_v_pos, YPix.select<8, 1, 32, 1>(0, 0));
618 read(PakSurfIndex, final_h_pos, final_v_pos + 8, YPix.select<8, 1, 32, 1>(8, 0));
619 read(PakSurfIndex, final_h_pos, final_v_pos + 16, YPix.select<8, 1, 32, 1>(16,0));
620 read(PakSurfIndex, final_h_pos, final_v_pos + 24, YPix.select<8, 1, 32, 1>(24,0));
621
622 write_plane(EncSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos, final_v_pos, YPix.select<8, 1, 32, 1>(0, 0));
623 write_plane(EncSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos, final_v_pos + 8, YPix.select<8, 1, 32, 1>(8, 0));
624 write_plane(EncSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos, final_v_pos + 16, YPix.select<8, 1, 32, 1>(16,0));
625 write_plane(EncSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos, final_v_pos + 24, YPix.select<8, 1, 32, 1>(24,0));
626 }
627
628 if( (colorformat == YUY2) || (colorformat == Y210) )
629 {
630 if(quot > 0)
631 {
632 vector<ushort, 32> maskgb = masktab;
633 first_index = first_index >> 1;
634
635 vector<ushort, 16> replicants = 0;
636 vector<ushort, 16> masktable = 0;
637
638 vector<ushort, 16> final_h_pos_mask = 0;
639 final_h_pos_mask = final_h_pos + 2 * maskgb.select<16, 1>();
640
641 matrix_ref<ushort, 32, 16>YPix_2byte = YPix.format<ushort, 32, 16>();
642
643 masktable = 1;
644 masktable.merge(masktable, 0, final_h_pos_mask < width);
645
646 for(uint mcount = 0; mcount < 32; mcount++)
647 {
648 replicants = YPix_2byte(mcount, first_index);
649 YPix_2byte.row(mcount).merge(YPix_2byte.row(mcount), replicants, masktable);
650
651 mcount++;
652 replicants = YPix_2byte(mcount, first_index);
653 YPix_2byte.row(mcount).merge(YPix_2byte.row(mcount), replicants, masktable);
654
655 mcount++;
656 replicants = YPix_2byte(mcount, first_index);
657 YPix_2byte.row(mcount).merge(YPix_2byte.row(mcount), replicants, masktable);
658
659 mcount++;
660 replicants = YPix_2byte(mcount,first_index);
661 YPix_2byte.row(mcount).merge(YPix_2byte.row(mcount), replicants, masktable);
662 }
663 }
664 }
665 }
666 else
667 {
668 read_plane(PakSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos, final_v_pos, YPix.select<8, 1, 32, 1>(0, 0));
669 read_plane(PakSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos, final_v_pos + 8, YPix.select<8, 1, 32, 1>(8, 0));
670 read_plane(PakSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos, final_v_pos + 16, YPix.select<8, 1, 32, 1>(16,0));
671 read_plane(PakSurfIndex, GENX_SURFACE_Y_PLANE, final_h_pos, final_v_pos + 24, YPix.select<8, 1, 32, 1>(24,0));
672 }
673
674 matrix<uchar, 16, 16> YDown2 = 0;
675 matrix<ushort, 8, 16> temp1 = 0;
676 matrix<ushort, 8, 8> temp2 = 0;
677 matrix<ushort, 4, 4> temp3 = 0;
678 matrix<uchar, 8, 8> out = 0;
679
680 #pragma unroll
681 for(uint i = 0; i < 2; i++) {
682 #pragma unroll
683 for(uint j = 0; j< 2; j++)
684 {
685 temp1.select<8, 1, 16, 1>(0, 0) = YPix.select<8, 2, 16, 1>(i << 4, j << 4) + YPix.select<8, 2, 16, 1>((i << 4) + 1, j << 4 );
686 temp2.select<8, 1, 8, 1>(0, 0) = temp1.select<8, 1, 8, 2>(0, 0) + temp1.select<8, 1, 8, 2>(0, 1);
687
688 temp2.select<8, 1, 8, 1>(0, 0) += 2;
689 temp2.select<8, 1, 8, 1>(0, 0) = temp2.select<8, 1, 8, 1>(0, 0) >> 2;
690
691 if((stage == 1) || (stage == 4))
692 {
693 YDown2.select<8, 1, 8, 1>(i << 3, j << 3) = temp2.select<8, 1, 8, 1>(0, 0);
694 }
695
696 temp2.select<4, 2, 8, 1>(0, 0) = temp2.select<4, 2, 8, 1>(0, 0) + temp2.select<4, 2, 8, 1>(1, 0);
697 temp3.select<4, 1, 4, 1>(0, 0) = temp2.select<4, 2, 4, 2>(0, 0) + temp2.select<4, 2, 4, 2>(0, 1);
698
699 temp3.select<4, 1, 4, 1>(0, 0) += 2;
700 temp3.select<4, 1, 4, 1>(0, 0) = temp3.select<4, 1, 4, 1>(0, 0) >> 2;
701
702 out.select<4, 1, 4, 1>(i << 2, j << 2) = temp3.select<4, 1, 4, 1>(0, 0);
703 }
704 }
705
706 if ((!replicate[0]) || (!replicate2[0]))
707 {
708 if(stage>1)
709 {
710 write(DS4XSurf, h_pos_write, v_pos_write, out);
711 }
712
713 if(stage ==1 || stage == 4)
714 {
715 write(DS2XSurf, h_pos_write2, v_pos_write2, YDown2);
716 }
717 }
718 else
719 {
720 matrix<uchar, 1, 8>last_line = out.select<1, 1, 8, 1>(7 - replicate[0], 0);
721 vector<int, 16>mask2;
722 vector_ref<int, 8>mask = mask2.select<8, 1>();
723
724 #pragma unroll
725 for(uint i = 1; i < 8; i++)
726 {
727 mask = i > 7 - replicate[0];
728 out.select<1, 1, 8, 1>(i, 0).merge(last_line, mask);
729 }
730
731 if ((stage == 4) || (stage == 1))
732 {
733 if(replicate2[0] >= 15)
734 {
735 matrix<uchar, 1, 16> lastline2 = YDown2.row(1);
736
737 for(uint i=0; i<16; i++)
738 {
739 YDown2.row(i) = lastline2;
740 }
741 }
742 else
743 {
744 matrix<uchar, 1, 16> last_line2 = YDown2.select<1, 1, 16, 1>(15 - replicate2[0], 0);
745
746 #pragma unroll
747 for(uint i = 1; i < 16; i++)
748 {
749 mask2 = i > 15 - replicate2[0];
750 YDown2.select<1, 1, 16, 1>(i, 0).merge(last_line2, mask2 );
751 }
752 }
753 write(DS2XSurf, h_pos_write2, v_pos_write2, YDown2);
754 }
755
756 if(stage>1)
757 write(DS4XSurf, h_pos_write, v_pos_write, out);
758 }
759
760 if(MBStatflag)
761 {
762 width = uWidth(0);
763 height = uHeight(0);
764
765 matrix<ushort, 32, 32> squared;
766 matrix<uint, 2, 2> sum;
767 matrix<uint, 2, 2> pixAvg;
768 matrix<uint, 2, 2> SumOfSquared;
769 matrix_ref<uint,2, 2> VarianceLuma = SumOfSquared;
770 matrix_ref<uint,2, 2> flatness_check = sum;
771
772 squared = YPix * YPix;
773
774 sum[0][0] = cm_sum<uint>(YPix.select<16, 1, 16, 1>(0, 0), SAT);
775 SumOfSquared[0][0] = cm_sum<uint>(squared.select<16, 1, 16, 1>(0, 0), SAT);
776
777 sum[0][1] = cm_sum<uint>(YPix.select<16, 1, 16, 1>(0, 16), SAT);
778 SumOfSquared[0][1] = cm_sum<uint>(squared.select<16, 1, 16, 1>(0, 16), SAT);
779
780 sum[1][0] = cm_sum<uint>(YPix.select<16, 1, 16, 1>(16, 0), SAT);
781 SumOfSquared[1][0] = cm_sum<uint>(squared.select<16, 1, 16, 1>(16, 0), SAT);
782
783 sum[1][1] = cm_sum<uint>(YPix.select<16, 1, 16, 1>(16, 16), SAT);
784 SumOfSquared[1][1] = cm_sum<uint>(squared.select<16, 1, 16, 1>(16, 16), SAT);
785
786 pixAvg = sum >> 8;
787 sum *= sum;
788 sum >>= 8;
789
790 VarianceLuma = SumOfSquared - sum;
791 VarianceLuma >>= 8;
792
793 flatness_check = (VarianceLuma < Flatness_Threshold);
794
795 unsigned short NumMBperRow = width / 16;
796 NumMBperRow += ((width % 16)> 0);
797
798 unsigned int offset_vp = (2 * 16 * 4 * (v_pos * NumMBperRow + h_pos));
799 unsigned int offset2_vp = offset_vp + NumMBperRow * 64;
800 vector<uint, 64> writeVProc(0);
801 vector<uint, 16> Element_Offset(Stat_offsets);
802
803 offset_vp >>= 2;
804 offset2_vp >>= 2;
805
806 writeVProc.select<2,16>(5) = flatness_check.row(0);
807 writeVProc.select<2,16>(37) = flatness_check.row(1);
808
809 writeVProc.select<2,16>(6) = VarianceLuma.row(0);
810 writeVProc.select<2,16>(38) = VarianceLuma.row(1);
811
812 writeVProc.select<2,16>(11) = pixAvg.row(0);
813 writeVProc.select<2,16>(43) = pixAvg.row(1);
814
815 if((h_pos * 32 < width) && (v_pos * 32 < height))
816 {
817 if((h_pos * 32)+ 16 >= width)
818 {
819 write(MBStats, offset_vp, Element_Offset, writeVProc.select<16,1>(0));
820 }
821 else
822 {
823 write(MBStats, offset_vp, Element_Offset, writeVProc.select<16,1>(0));
824 write(MBStats, offset_vp + 16, Element_Offset, writeVProc.select<16,1>(16));
825 }
826
827 if((v_pos * 32)+16 < height)
828 {
829 if((h_pos * 32)+ 16 >= width)
830 {
831 write(MBStats, offset2_vp, Element_Offset, writeVProc.select<16,1>(32));
832 }
833 else
834 {
835 write(MBStats, offset2_vp, Element_Offset, writeVProc.select<16,1>(32));
836 write(MBStats, offset2_vp + 16, Element_Offset, writeVProc.select<16,1>(48));
837 }
838 }
839 }
840 }
841
842 uchar hevc_enc_history = (CURBEData_U8(5) >> 6) & 0x1;
843
844 if(hevc_enc_history)
845 {
846 uchar LCUtype = (CURBEData_U8(5) >> 7) & 0x1;
847
848 vector<ushort, 32> clear_buffer;
849 vector_ref<ushort, 16> clear_buffer1 = clear_buffer.select<16, 1>(0);
850 vector<ushort, 16> History_perLCU;
851
852 uint offset = 0;
853 uchar shift_factor = LCUtype == 0 ? 6 : 5;
854
855 vector_ref<ushort, 1> WidthLCU = History_perLCU.select<1, 1>(0);
856 vector_ref<ushort, 1> HeightLCU = History_perLCU.select<1, 1>(1);
857
858 WidthLCU(0) = (uWidth(0) + ((1 << shift_factor) - 1)) >> shift_factor;
859 HeightLCU(0) = (uHeight(0) + ((1 << shift_factor) - 1)) >> shift_factor;
860
861 if(h_pos == 0 && v_pos == 0)
862 {
863 clear_buffer = 0;
864 numLCUs = WidthLCU * HeightLCU;
865
866 for(uint i = 0; i < numLCUs(0); i++)
867 {
868 read(Hevc_History_Surface_index, offset, History_perLCU);
869 clear_buffer.select<16, 1>(0) += History_perLCU;
870 offset += HEVC_HISTORY_BUFFER_ENTRY_SIZE;
871 }
872
873 clear_buffer.select<4,1>(4) = History_perLCU.select<4,1>(4);
874 clear_buffer.select<8,1>(8) = History_perLCU.select<8,1>(8);
875
876 write(Hevc_History_Sum_Surface_index, 0, clear_buffer);
877 }
878
879 if((h_pos == 1) && (v_pos == 0))
880 {
881 offset = 0;
882 clear_buffer1 = 0;
883 numLCUs = WidthLCU * HeightLCU;
884
885 for(uint i = 0; i < numLCUs(0); i++)
886 {
887 write(Scratch_Surface_index, offset, clear_buffer1);
888 write(Scratch_Surface_index, offset + 32, clear_buffer1);
889 write(Scratch_Surface_index, offset + 64, clear_buffer1);
890
891 offset += 96;
892 }
893 }
894 }
895
896 cm_fence();
897 }