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 #if (defined BUFFER_0) || (defined BUFFER_1) || (defined BUFFER_2) || (defined BUFFER_3)
23 vector <ushort, 16> LoadMaskTemp = (TempMask0.select<1, 1, 16, 1>(0, 0) != 0);
24 #elif (defined BUFFER_4) || (defined BUFFER_5)
25 uchar sec_half_shift = (Layer_Index >> 7) * 8;
26 vector <ushort, 16> LoadMaskTemp = (TempMask.select<16, 1>(0) != 0);
27 #endif
28 
29 #if defined BUFFER_0
30 Buffer_Index = 0;
31 CalculationMask = cm_pack_mask(LoadMaskTemp) & 0x000F;
32 #elif defined BUFFER_1
33 Buffer_Index = 1;
34 CalculationMask = (cm_pack_mask(LoadMaskTemp) >> 4) & 0x000F;
35 #elif defined BUFFER_2
36 Buffer_Index = 2;
37 CalculationMask = (cm_pack_mask(LoadMaskTemp) >> 8) & 0x000F;
38 #elif defined BUFFER_3
39 Buffer_Index = 3;
40 CalculationMask = (cm_pack_mask(LoadMaskTemp) >> 12) & 0x000F;
41 #elif defined BUFFER_4
42 CalculationMask = (cm_pack_mask(LoadMaskTemp) >> sec_half_shift) & 0x000F;
43 Buffer_Index = 4;
44 #elif defined BUFFER_5
45 CalculationMask = (cm_pack_mask(LoadMaskTemp) >> (4 + sec_half_shift)) & 0x000F;
46 Buffer_Index = 5;
47 #endif
48 
49 if (CalculationMask != 0)
50 {
51     float StartX;
52     float StartY;
53     float DeltaX;
54     float DeltaY;
55     uint Vertical_Block_Num;
56     uchar Layer_Index_45;
57     uchar RotationFlag;
58     bool IefBypass = true;
59     int TempOffset;
60     SamplerIndex Src_Sampler(MDF_FC_AVS_SI_Y);
61     SamplerIndex Src_Sampler1(MDF_FC_AVS_SI_U);
62     matrix<ushort, 4, 32> pl2_temp;
63 
64     /*
65     AVS Sampler 16x4 write back buffer layout for R/V, G/Y, B/U channel, each box stands for 8x1 ushort write back pixel
66     16x4 pixle deviding to 8 8x1 pixel block
67     _________________________________________________
68     |_______Block0__________|_______Block1__________|
69     |_______Block2__________|_______Block3__________|
70     |_______Block4__________|_______Block5__________|
71     |_______Block6__________|_______Block7__________|
72 
73     Write back buffer layout correlate to the block number#, each box stands for 1 GRF
74     _______________________________________________
75     |____R0_________R2_____|____R4_________R6_____|
76     |____G0_________G2_____|____G4_________G6_____|
77     |____B0_________B2_____|____B4_________B6_____|
78     |____A0_________A2_____|____A4_________A6_____|
79     |____R1_________R3_____|____R5_________R7_____|
80     |____G1_________G3_____|____G5_________G7_____|
81     |____B1_________B3_____|____B5_________B7_____|
82     |____A1_________A3_____|____A5_________A7_____|
83     */
84 #ifdef BUFFER_0
85 #ifdef ROTATE_90
86     StartX = Start_X(0);
87     StartY = Start_Y(0);
88     DeltaX = Delta_X(0);
89     DeltaY = Delta_Y(0);
90     Vertical_Block_Num = 0;
91 
92     StartX = StartX + DstY * DeltaX;
93 
94     RotationFlag = (uchar)(RotationChromaSitingFlag & 0x07);
95     if (RotationFlag == MDF_FC_ROTATE_90_MIRROR_HORIZONTAL)
96     {
97         StartY = StartY + DstX * DeltaY;
98     }
99     else
100     {
101         StartY = StartY + (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaY;
102     }
103 
104 #elif defined ROTATE_180
105     StartX = Start_X(0);
106     StartY = Start_Y(0);
107     DeltaX = Delta_X(0);
108     DeltaY = Delta_Y(0);
109     Vertical_Block_Num = (((Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY + 12) >> 2)) & 15;
110 
111     RotationFlag = (uchar)(RotationChromaSitingFlag & 0x07);
112     if (RotationFlag == MDF_FC_MIRROR_VERTICAL)
113     {
114         StartX += DstX * DeltaX;
115     }
116     else
117     {
118         StartX += (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaX;
119     }
120 
121     TempOffset = Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY + 12;
122     TempOffset &= 0xFFFFFFC3;
123     StartY = StartY + TempOffset * DeltaY;
124 #elif defined ROTATE_270
125     StartX = Start_X(0);
126     StartY = Start_Y(0);
127     DeltaX = Delta_X(0);
128     DeltaY = Delta_Y(0);
129     Vertical_Block_Num = 0;
130 
131     StartX = StartX + (Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY + 12) * DeltaX;
132 
133     RotationFlag = (uchar)(RotationChromaSitingFlag & 0x07);
134     if (RotationFlag == MDF_FC_ROTATE_90_MIRROR_VERTICAL)
135     {
136         StartY = StartY + (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaY;
137     }
138     else
139     {
140         StartY = StartY + DstX * DeltaY;
141 }
142 
143 #else
144     StartX = Start_X(0);
145     StartY = Start_Y(0);
146     DeltaX = Delta_X(0);
147     DeltaY = Delta_Y(0);
148     Vertical_Block_Num = (DstY >> 2) & 15;
149 
150     RotationFlag = (uchar)(RotationChromaSitingFlag & 0x07);
151     if (RotationFlag == MDF_FC_MIRROR_HORIZONTAL)
152     {
153         StartX += (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaX;
154     }
155     else
156     {
157         StartX += DstX * DeltaX;
158     }
159 
160     StartY = StartY + (DstY & 0xFFC3) * DeltaY;
161 #endif
162 #endif
163 
164 #ifdef BUFFER_1
165 #ifdef ROTATE_90
166     StartX = Start_X(0);
167     StartY = Start_Y(0);
168     DeltaX = Delta_X(0);
169     DeltaY = Delta_Y(0);
170     Vertical_Block_Num = 0;
171 
172     StartX = StartX + (DstY + 4) * DeltaX;
173     RotationFlag = (uchar)(RotationChromaSitingFlag & 0x07);
174 
175     if (RotationFlag == MDF_FC_ROTATE_90_MIRROR_HORIZONTAL)
176     {
177         StartY = StartY + DstX * DeltaY;
178     }
179     else
180     {
181         StartY = StartY + (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaY;
182     }
183 
184 #elif defined ROTATE_180
185     StartX = Start_X(0);
186     StartY = Start_Y(0);
187     DeltaX = Delta_X(0);
188     DeltaY = Delta_Y(0);
189     Vertical_Block_Num = (((Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY + 8) >> 2)) & 15;
190 
191     RotationFlag = (uchar)(RotationChromaSitingFlag & 0x07);
192     if (RotationFlag == MDF_FC_MIRROR_VERTICAL)
193     {
194         StartX += DstX * DeltaX;
195     }
196     else
197     {
198         StartX += (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaX;
199     }
200 
201     TempOffset = Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY + 8;
202     TempOffset &= 0xFFFFFFC3;
203     StartY = StartY + TempOffset * DeltaY;
204 #elif defined ROTATE_270
205     StartX = Start_X(0);
206     StartY = Start_Y(0);
207     DeltaX = Delta_X(0);
208     DeltaY = Delta_Y(0);
209     Vertical_Block_Num = 0;
210 
211     StartX = StartX + (Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY + 8) * DeltaX;
212     RotationFlag = (uchar)(RotationChromaSitingFlag & 0x07);
213     if (RotationFlag == MDF_FC_ROTATE_90_MIRROR_VERTICAL)
214     {
215         StartY = StartY + (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaY;
216     }
217     else
218     {
219         StartY = StartY + DstX * DeltaY;
220     }
221 
222 #else
223     StartX = Start_X(0);
224     StartY = Start_Y(0);
225     DeltaX = Delta_X(0);
226     DeltaY = Delta_Y(0);
227     Vertical_Block_Num = ((DstY >> 2) & 15) + 1;
228 
229     RotationFlag = (uchar)(RotationChromaSitingFlag & 0x07);
230     if (RotationFlag == MDF_FC_MIRROR_HORIZONTAL)
231     {
232         StartX += (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaX;
233     }
234     else
235     {
236         StartX += DstX * DeltaX;
237     }
238     StartY = StartY + (DstY & 0xFFC3) * DeltaY;
239 #endif
240 #endif
241 
242 #ifdef BUFFER_2
243 #ifdef ROTATE_90
244     StartX = Start_X(0);
245     StartY = Start_Y(0);
246     DeltaX = Delta_X(0);
247     DeltaY = Delta_Y(0);
248     Vertical_Block_Num = 0;
249 
250     StartX = StartX + (DstY + 8) * DeltaX;
251     RotationFlag = (uchar)(RotationChromaSitingFlag & 0x07);
252 
253     if (RotationFlag == MDF_FC_ROTATE_90_MIRROR_HORIZONTAL)
254     {
255         StartY = StartY + DstX * DeltaY;
256     }
257     else
258     {
259         StartY = StartY + (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaY;
260     }
261 
262 #elif defined ROTATE_180
263     StartX = Start_X(0);
264     StartY = Start_Y(0);
265     DeltaX = Delta_X(0);
266     DeltaY = Delta_Y(0);
267     Vertical_Block_Num = (((Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY + 4) >> 2)) & 15;
268 
269     RotationFlag = (uchar)(RotationChromaSitingFlag & 0x07);
270     if (RotationFlag == MDF_FC_MIRROR_VERTICAL)
271     {
272         StartX += DstX * DeltaX;
273     }
274     else
275     {
276         StartX += (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaX;
277     }
278 
279     TempOffset = Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY + 4;
280     TempOffset &= 0xFFFFFFC3;
281     StartY = StartY + TempOffset * DeltaY;
282 #elif defined ROTATE_270
283     StartX = Start_X(0);
284     StartY = Start_Y(0);
285     DeltaX = Delta_X(0);
286     DeltaY = Delta_Y(0);
287     Vertical_Block_Num = 0;
288 
289     StartX = StartX + (Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY + 4) * DeltaX;
290     RotationFlag = (uchar)(RotationChromaSitingFlag & 0x07);
291     if (RotationFlag == MDF_FC_ROTATE_90_MIRROR_VERTICAL)
292     {
293         StartY = StartY + (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaY;
294     }
295     else
296     {
297         StartY = StartY + DstX * DeltaY;
298     }
299 #else
300     StartX = Start_X(0);
301     StartY = Start_Y(0);
302     DeltaX = Delta_X(0);
303     DeltaY = Delta_Y(0);
304     Vertical_Block_Num = ((DstY >> 2) & 15) + 2;
305 
306     RotationFlag = (uchar)(RotationChromaSitingFlag & 0x07);
307     if (RotationFlag == MDF_FC_MIRROR_HORIZONTAL)
308     {
309         StartX += (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaX;
310     }
311     else
312     {
313         StartX += DstX * DeltaX;
314     }
315     StartY = StartY + (DstY & 0xFFC3) * DeltaY;
316 #endif
317 #endif
318 
319 #ifdef BUFFER_3
320 #ifdef ROTATE_90
321     StartX = Start_X(0);
322     StartY = Start_Y(0);
323     DeltaX = Delta_X(0);
324     DeltaY = Delta_Y(0);
325     Vertical_Block_Num = 0;
326 
327     StartX = StartX + (DstY + 12) * DeltaX;
328     RotationFlag = (uchar)(RotationChromaSitingFlag & 0x07);
329 
330     if (RotationFlag == MDF_FC_ROTATE_90_MIRROR_HORIZONTAL)
331     {
332         StartY = StartY + DstX * DeltaY;
333     }
334     else
335     {
336         StartY = StartY + (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaY;
337     }
338 
339 #elif defined ROTATE_180
340     StartX = Start_X(0);
341     StartY = Start_Y(0);
342     DeltaX = Delta_X(0);
343     DeltaY = Delta_Y(0);
344     Vertical_Block_Num = ((Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY) >> 2) & 15;
345 
346     RotationFlag = (uchar)(RotationChromaSitingFlag & 0x07);
347     if (RotationFlag == MDF_FC_MIRROR_VERTICAL)
348     {
349         StartX += DstX * DeltaX;
350     }
351     else
352     {
353         StartX += (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaX;
354     }
355 
356     TempOffset = Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY;
357     TempOffset &= 0xFFFFFFC3;
358     StartY = StartY + TempOffset * DeltaY;
359 #elif defined ROTATE_270
360     StartX = Start_X(0);
361     StartY = Start_Y(0);
362     DeltaX = Delta_X(0);
363     DeltaY = Delta_Y(0);
364     Vertical_Block_Num = 0;
365 
366     StartX = StartX + (Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY) * DeltaX;
367     RotationFlag = (uchar)(RotationChromaSitingFlag & 0x07);
368     if (RotationFlag == MDF_FC_ROTATE_90_MIRROR_VERTICAL)
369     {
370         StartY = StartY + (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaY;
371     }
372     else
373     {
374         StartY = StartY + DstX * DeltaY;
375     }
376 #else
377     StartX = Start_X(0);
378     StartY = Start_Y(0);
379     DeltaX = Delta_X(0);
380     DeltaY = Delta_Y(0);
381     Vertical_Block_Num = ((DstY >> 2) & 15) + 3;
382 
383     RotationFlag = (uchar)(RotationChromaSitingFlag & 0x07);
384     if (RotationFlag == MDF_FC_MIRROR_HORIZONTAL)
385     {
386         StartX += (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaX;
387     }
388     else
389     {
390         StartX += DstX * DeltaX;
391     }
392     StartY = StartY + (DstY & 0xFFC3) * DeltaY;
393 #endif
394 #endif
395 
396 #ifdef BUFFER_4
397 #ifdef ROTATE_90
398     Layer_Index_45 = Layer_Index & 0x7f;
399     StartX = Start_X(Layer_Index_45);
400     StartY = Start_Y(Layer_Index_45);
401     DeltaX = Delta_X(Layer_Index_45);
402     DeltaY = Delta_Y(Layer_Index_45);
403     Vertical_Block_Num = 0;
404 
405     StartX = StartX + (DstY + 8 * (Layer_Index >> 7)) * DeltaX;
406     RotationFlag = (uchar)((RotationChromaSitingFlag >> (3 * Layer_Index_45)) & 0x07);
407 
408     if (RotationFlag == MDF_FC_ROTATE_90_MIRROR_HORIZONTAL)
409     {
410         StartY = StartY + DstX * DeltaY;
411     }
412     else
413     {
414         StartY = StartY + (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaY;
415     }
416 
417 #elif defined ROTATE_180
418     Layer_Index_45 = Layer_Index & 0x7f;
419     StartX = Start_X(Layer_Index_45);
420     StartY = Start_Y(Layer_Index_45);
421     DeltaX = Delta_X(Layer_Index_45);
422     DeltaY = Delta_Y(Layer_Index_45);
423     Vertical_Block_Num = ((Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY + 12 - 8 * (Layer_Index >> 7)) >> 2) & 15;
424 
425     RotationFlag = (uchar)((RotationChromaSitingFlag >> (3 * Layer_Index_45)) & 0x07);
426 
427     if (RotationFlag == MDF_FC_MIRROR_VERTICAL)
428     {
429         StartX += DstX * DeltaX;
430     }
431     else
432     {
433         StartX += (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaX;
434     }
435 
436     TempOffset = Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY + 12 - 8 * (Layer_Index >> 7);
437     TempOffset &= 0xFFFFFFC3;
438     StartY = StartY + TempOffset * DeltaY;
439 #elif defined ROTATE_270
440     Layer_Index_45 = Layer_Index & 0x7f;
441 
442     StartX = Start_X(Layer_Index_45);
443     StartY = Start_Y(Layer_Index_45);
444     DeltaX = Delta_X(Layer_Index_45);
445     DeltaY = Delta_Y(Layer_Index_45);
446     Vertical_Block_Num = 0;
447 
448     StartX = StartX + (Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY + 12 - 8 * (Layer_Index >> 7)) * DeltaX;
449     RotationFlag = (uchar)((RotationChromaSitingFlag >> (3 * Layer_Index_45)) & 0x07);
450     if (RotationFlag == MDF_FC_ROTATE_90_MIRROR_VERTICAL)
451     {
452         StartY = StartY + (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaY;
453     }
454     else
455     {
456         StartY = StartY + DstX * DeltaY;
457     }
458 #else
459     Layer_Index_45 = Layer_Index & 0x7f;
460     StartX = Start_X(Layer_Index_45);
461     StartY = Start_Y(Layer_Index_45);
462     DeltaX = Delta_X(Layer_Index_45);
463     DeltaY = Delta_Y(Layer_Index_45);
464     Vertical_Block_Num = ((DstY >> 2) & 15) + (2 * (Layer_Index >> 7));
465 
466     RotationFlag = (uchar)((RotationChromaSitingFlag >> (3 * Layer_Index_45)) & 0x07);
467     if (RotationFlag == MDF_FC_MIRROR_HORIZONTAL)
468     {
469         StartX += (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaX;
470     }
471     else
472     {
473         StartX += DstX * DeltaX;
474     }
475     StartY = StartY + (DstY & 0xFFC3) * DeltaY;
476 #endif
477 #endif
478 
479 #ifdef BUFFER_5
480 #ifdef ROTATE_90
481     Layer_Index_45 = Layer_Index & 0x7f;
482     StartX = Start_X(Layer_Index_45);
483     StartY = Start_Y(Layer_Index_45);
484     DeltaX = Delta_X(Layer_Index_45);
485     DeltaY = Delta_Y(Layer_Index_45);
486     Vertical_Block_Num = 0;
487 
488     StartX = StartX + (DstY + 8 * (Layer_Index >> 7) + 4) * DeltaX;
489     RotationFlag = (uchar)((RotationChromaSitingFlag >> (3 * Layer_Index_45)) & 0x07);
490 
491     if (RotationFlag == MDF_FC_ROTATE_90_MIRROR_HORIZONTAL)
492     {
493         StartY = StartY + DstX * DeltaY;
494     }
495     else
496     {
497         StartY = StartY + (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaY;
498     }
499 
500 #elif defined ROTATE_180
501     Layer_Index_45 = Layer_Index & 0x7f;
502     StartX = Start_X(Layer_Index_45);
503     StartY = Start_Y(Layer_Index_45);
504     DeltaX = Delta_X(Layer_Index_45);
505     DeltaY = Delta_Y(Layer_Index_45);
506     Vertical_Block_Num = (((Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY + 8 - 8 * (Layer_Index >> 7)) >> 2)) & 15;
507 
508     RotationFlag = (uchar)((RotationChromaSitingFlag >> (3 * Layer_Index_45)) & 0x07);
509 
510     if (RotationFlag == MDF_FC_MIRROR_VERTICAL)
511     {
512         StartX += DstX * DeltaX;
513     }
514     else
515     {
516         StartX += (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaX;
517     }
518     TempOffset = Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY + 8 - 8 * (Layer_Index >> 7);
519     TempOffset &= 0xFFFFFFC3;
520     StartY = StartY + TempOffset * DeltaY;
521 #elif defined ROTATE_270
522     Layer_Index_45 = Layer_Index & 0x7f;
523 
524     StartX = Start_X(Layer_Index_45);
525     StartY = Start_Y(Layer_Index_45);
526     DeltaX = Delta_X(Layer_Index_45);
527     DeltaY = Delta_Y(Layer_Index_45);
528     Vertical_Block_Num = 0;
529 
530     StartX = StartX + (Dst_Height - MDF_FC_BLOCK_HEIGHT - DstY + 8 - (8 * (Layer_Index >> 7))) * DeltaX;
531     RotationFlag = (uchar)((RotationChromaSitingFlag >> (3 * Layer_Index_45)) & 0x07);
532     if (RotationFlag == MDF_FC_ROTATE_90_MIRROR_VERTICAL)
533     {
534         StartY = StartY + (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaY;
535     }
536     else
537     {
538         StartY = StartY + DstX * DeltaY;
539     }
540 #else
541     Layer_Index_45 = Layer_Index & 0x7f;
542     StartX = Start_X(Layer_Index_45);
543     StartY = Start_Y(Layer_Index_45);
544     DeltaX = Delta_X(Layer_Index_45);
545     DeltaY = Delta_Y(Layer_Index_45);
546     Vertical_Block_Num = ((DstY >> 2) & 15) + (2 * (Layer_Index >> 7)) + 1;
547 
548     RotationFlag = (uchar)((RotationChromaSitingFlag >> (3 * Layer_Index_45)) & 0x07);
549 
550     if (RotationFlag == MDF_FC_MIRROR_HORIZONTAL)
551     {
552         StartX += (Dst_Width - MDF_FC_BLOCK_WIDTH - DstX) * DeltaX;
553     }
554     else
555     {
556         StartX += DstX * DeltaX;
557     }
558     StartY = StartY + (DstY & 0xFFC3) * DeltaY;
559 #endif
560 #endif
561 
562 
563 #ifdef BUFFER_0
564 #define WriteBackBuffer DataBuffer0
565     SurfaceIndex Src_Surface(MDF_FC_INPUT_BTI_START);
566     cm_avs_sampler(
567         pl2_temp.select<2, 1, 32, 1>(0, 0),
568         CM_G_ENABLE,
569         Src_Surface,
570         Src_Sampler,
571         StartX,
572         StartY,
573         DeltaX,
574         DeltaY,
575         0,
576         0,
577         Vertical_Block_Num,
578         CM_16_FULL,
579         0,
580         CM_AVS_16x4,
581         IefBypass);
582 
583     DataBuffer0.format<ushort, 8, 32>().select<2, 4, 32, 1>(1, 0) = pl2_temp.select<2, 1, 32, 1>(0, 0);
584 
585     SurfaceIndex Src_Surface1(MDF_FC_INPUT_BTI_START + MDF_FC_UV_PLANE_BTI_OFFSET);
586     cm_avs_sampler(
587         pl2_temp.select<4, 1, 32, 1>(0, 0),
588         CM_BR_ENABLE,
589         Src_Surface1,
590         Src_Sampler1,
591         StartX,
592         StartY,
593         DeltaX,
594         DeltaY,
595         0,
596         0,
597         Vertical_Block_Num,
598         CM_16_FULL,
599         0,
600         CM_AVS_16x4,
601         IefBypass);
602 
603     DataBuffer0.format<ushort, 8, 32>().select<2, 4, 32, 1>(2, 0) = pl2_temp.select<2, 2, 32, 1>(0, 0);
604     DataBuffer0.format<ushort, 8, 32>().select<2, 4, 32, 1>(0, 0) = pl2_temp.select<2, 2, 32, 1>(1, 0);
605 
606 #endif
607 #ifdef BUFFER_1
608 #define WriteBackBuffer DataBuffer1
609     SurfaceIndex Src_Surface(MDF_FC_INPUT_BTI_START);
610     cm_avs_sampler(
611         pl2_temp.select<2, 1, 32, 1>(0, 0),
612         CM_G_ENABLE,
613         Src_Surface,
614         Src_Sampler,
615         StartX,
616         StartY,
617         DeltaX,
618         DeltaY,
619         0,
620         0,
621         Vertical_Block_Num,
622         CM_16_FULL,
623         0,
624         CM_AVS_16x4,
625         IefBypass);
626 
627     DataBuffer1.format<ushort, 8, 32>().select<2, 4, 32, 1>(1, 0) = pl2_temp.select<2, 1, 32, 1>(0, 0);
628 
629     SurfaceIndex Src_Surface1(MDF_FC_INPUT_BTI_START + MDF_FC_UV_PLANE_BTI_OFFSET);
630     cm_avs_sampler(
631         pl2_temp.select<4, 1, 32, 1>(0, 0),
632         CM_BR_ENABLE,
633         Src_Surface1,
634         Src_Sampler1,
635         StartX,
636         StartY,
637         DeltaX,
638         DeltaY,
639         0,
640         0,
641         Vertical_Block_Num,
642         CM_16_FULL,
643         0,
644         CM_AVS_16x4,
645         IefBypass);
646 
647     DataBuffer1.format<ushort, 8, 32>().select<2, 4, 32, 1>(2, 0) = pl2_temp.select<2, 2, 32, 1>(0, 0);
648     DataBuffer1.format<ushort, 8, 32>().select<2, 4, 32, 1>(0, 0) = pl2_temp.select<2, 2, 32, 1>(1, 0);
649 
650 #endif
651 #ifdef BUFFER_2
652 #define WriteBackBuffer DataBuffer2
653     SurfaceIndex Src_Surface(MDF_FC_INPUT_BTI_START);
654     cm_avs_sampler(
655         pl2_temp.select<2, 1, 32, 1>(0, 0),
656         CM_G_ENABLE,
657         Src_Surface,
658         Src_Sampler,
659         StartX,
660         StartY,
661         DeltaX,
662         DeltaY,
663         0,
664         0,
665         Vertical_Block_Num,
666         CM_16_FULL,
667         0,
668         CM_AVS_16x4,
669         IefBypass);
670 
671     DataBuffer2.format<ushort, 8, 32>().select<2, 4, 32, 1>(1, 0) = pl2_temp.select<2, 1, 32, 1>(0, 0);
672 
673     SurfaceIndex Src_Surface1(MDF_FC_INPUT_BTI_START + MDF_FC_UV_PLANE_BTI_OFFSET);
674     cm_avs_sampler(
675         pl2_temp.select<4, 1, 32, 1>(0, 0),
676         CM_BR_ENABLE,
677         Src_Surface1,
678         Src_Sampler1,
679         StartX,
680         StartY,
681         DeltaX,
682         DeltaY,
683         0,
684         0,
685         Vertical_Block_Num,
686         CM_16_FULL,
687         0,
688         CM_AVS_16x4,
689         IefBypass);
690 
691     DataBuffer2.format<ushort, 8, 32>().select<2, 4, 32, 1>(2, 0) = pl2_temp.select<2, 2, 32, 1>(0, 0);
692     DataBuffer2.format<ushort, 8, 32>().select<2, 4, 32, 1>(0, 0) = pl2_temp.select<2, 2, 32, 1>(1, 0);
693 
694 #endif
695 #ifdef BUFFER_3
696 #define WriteBackBuffer DataBuffer3
697     SurfaceIndex Src_Surface(MDF_FC_INPUT_BTI_START);
698     cm_avs_sampler(
699         pl2_temp.select<2, 1, 32, 1>(0, 0),
700         CM_G_ENABLE,
701         Src_Surface,
702         Src_Sampler,
703         StartX,
704         StartY,
705         DeltaX,
706         DeltaY,
707         0,
708         0,
709         Vertical_Block_Num,
710         CM_16_FULL,
711         0,
712         CM_AVS_16x4,
713         IefBypass);
714 
715     DataBuffer3.format<ushort, 8, 32>().select<2, 4, 32, 1>(1, 0) = pl2_temp.select<2, 1, 32, 1>(0, 0);
716 
717     SurfaceIndex Src_Surface1(MDF_FC_INPUT_BTI_START + 1);
718     cm_avs_sampler(
719         pl2_temp.select<4, 1, 32, 1>(0, 0),
720         CM_BR_ENABLE,
721         Src_Surface1,
722         Src_Sampler1,
723         StartX,
724         StartY,
725         DeltaX,
726         DeltaY,
727         0,
728         0,
729         Vertical_Block_Num,
730         CM_16_FULL,
731         0,
732         CM_AVS_16x4,
733         IefBypass);
734 
735     DataBuffer3.format<ushort, 8, 32>().select<2, 4, 32, 1>(2, 0) = pl2_temp.select<2, 2, 32, 1>(0, 0);
736     DataBuffer3.format<ushort, 8, 32>().select<2, 4, 32, 1>(0, 0) = pl2_temp.select<2, 2, 32, 1>(1, 0);
737 
738 #endif
739 #ifdef BUFFER_4
740 #define WriteBackBuffer DataBuffer4
741     SurfaceIndex Src_Surface(MDF_FC_INPUT_BTI_START + MDF_FC_INPUT_BTI_PER_LAYER * Layer_Index_45);
742 
743     cm_avs_sampler(
744         pl2_temp.select<2, 1, 32, 1>(0, 0),
745         CM_G_ENABLE,
746         Src_Surface,
747         Src_Sampler,
748         StartX,
749         StartY,
750         DeltaX,
751         DeltaY,
752         0,
753         0,
754         Vertical_Block_Num,
755         CM_16_FULL,
756         0,
757         CM_AVS_16x4,
758         IefBypass);
759 
760     DataBuffer4.format<ushort, 8, 32>().select<2, 4, 32, 1>(1, 0) = pl2_temp.select<2, 1, 32, 1>(0, 0);
761 
762     SurfaceIndex Src_Surface1(MDF_FC_INPUT_BTI_START + MDF_FC_INPUT_BTI_PER_LAYER * Layer_Index_45 + MDF_FC_UV_PLANE_BTI_OFFSET);
763     cm_avs_sampler(
764         pl2_temp.select<4, 1, 32, 1>(0, 0),
765         CM_BR_ENABLE,
766         Src_Surface1,
767         Src_Sampler1,
768         StartX,
769         StartY,
770         DeltaX,
771         DeltaY,
772         0,
773         0,
774         Vertical_Block_Num,
775         CM_16_FULL,
776         0,
777         CM_AVS_16x4,
778         IefBypass);
779 
780     DataBuffer4.format<ushort, 8, 32>().select<2, 4, 32, 1>(2, 0) = pl2_temp.select<2, 2, 32, 1>(0, 0);
781     DataBuffer4.format<ushort, 8, 32>().select<2, 4, 32, 1>(0, 0) = pl2_temp.select<2, 2, 32, 1>(1, 0);
782 
783 #endif
784 #ifdef BUFFER_5
785 #define WriteBackBuffer DataBuffer5
786     SurfaceIndex Src_Surface(MDF_FC_INPUT_BTI_START + MDF_FC_INPUT_BTI_PER_LAYER * Layer_Index_45);
787 
788     cm_avs_sampler(
789         pl2_temp.select<2, 1, 32, 1>(0, 0),
790         CM_G_ENABLE,
791         Src_Surface,
792         Src_Sampler,
793         StartX,
794         StartY,
795         DeltaX,
796         DeltaY,
797         0,
798         0,
799         Vertical_Block_Num,
800         CM_16_FULL,
801         0,
802         CM_AVS_16x4,
803         IefBypass);
804 
805     DataBuffer5.format<ushort, 8, 32>().select<2, 4, 32, 1>(1, 0) = pl2_temp.select<2, 1, 32, 1>(0, 0);
806 
807     SurfaceIndex Src_Surface1(MDF_FC_INPUT_BTI_START + MDF_FC_INPUT_BTI_PER_LAYER * Layer_Index_45 + MDF_FC_UV_PLANE_BTI_OFFSET);
808     cm_avs_sampler(
809         pl2_temp.select<4, 1, 32, 1>(0, 0),
810         CM_BR_ENABLE,
811         Src_Surface1,
812         Src_Sampler1,
813         StartX,
814         StartY,
815         DeltaX,
816         DeltaY,
817         0,
818         0,
819         Vertical_Block_Num,
820         CM_16_FULL,
821         0,
822         CM_AVS_16x4,
823         IefBypass);
824 
825     DataBuffer5.format<ushort, 8, 32>().select<2, 4, 32, 1>(2, 0) = pl2_temp.select<2, 2, 32, 1>(0, 0);
826     DataBuffer5.format<ushort, 8, 32>().select<2, 4, 32, 1>(0, 0) = pl2_temp.select<2, 2, 32, 1>(1, 0);
827 
828 #endif
829 
830 
831     // Shuffle the write back of sampler
832     /*
833     Buffer layout after shuffle
834     _________________________________________________
835     |_______Block0__________|_______Block1__________|
836     |_______Block2__________|_______Block3__________|
837     |_______Block4__________|_______Block5__________|
838     |_______Block6__________|_______Block7__________|
839 
840     Write back buffer layout correlate to the block number#, each box stands for 1 GRF
841     _______________________________________________
842     |____R0_________R1_____|____R2_________R3_____|
843     |____G0_________G1_____|____G2_________G3_____|
844     |____B0_________B1_____|____B2_________B3_____|
845     |____A0_________A1_____|____A2_________A3_____|
846     |____R4_________R5_____|____R6_________R7_____|
847     |____G4_________G5_____|____G6_________G7_____|
848     |____B4_________B5_____|____B6_________B7_____|
849     |____A4_________A5_____|____A6_________A7_____|
850     */
851 
852     WriteBackBuffer.format<ushort, 16, 16>().select<2, 1, 16, 1>(6, 0) = 0xffff;
853     WriteBackBuffer.format<ushort, 16, 16>().select<2, 1, 16, 1>(14, 0) = 0xffff;
854 
855 #undef WriteBackBuffer
856 }