llvmpipe: Tiles in rgba8 format.
[mesa.git] / src / gallium / drivers / llvmpipe / lp_tile_soa.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /**
29 * RGBA/float tile get/put functions.
30 * Usable both by drivers and state trackers.
31 */
32
33
34 #include "pipe/p_defines.h"
35 #include "pipe/p_inlines.h"
36
37 #include "util/u_math.h"
38 #include "util/u_memory.h"
39 #include "util/u_rect.h"
40 #include "util/u_tile.h"
41 #include "lp_tile_cache.h"
42 #include "lp_tile_soa.h"
43
44
45 #define PIXEL(_p, _x, _y, _c) ((_p)[(_c)*TILE_SIZE*TILE_SIZE + (_y)*TILE_SIZE + (_x)])
46
47
48
49 /*** PIPE_FORMAT_A8R8G8B8_UNORM ***/
50
51 static void
52 a8r8g8b8_get_tile_rgba(const unsigned *src,
53 unsigned w, unsigned h,
54 uint8_t *p)
55 {
56 unsigned i, j;
57
58 for (i = 0; i < h; i++) {
59 for (j = 0; j < w; j++) {
60 const unsigned pixel = *src++;
61 PIXEL(p, j, i, 0) = (pixel >> 16) & 0xff;
62 PIXEL(p, j, i, 1) = (pixel >> 8) & 0xff;
63 PIXEL(p, j, i, 2) = (pixel >> 0) & 0xff;
64 PIXEL(p, j, i, 3) = (pixel >> 24) & 0xff;
65 }
66 }
67 }
68
69
70 static void
71 a8r8g8b8_put_tile_rgba(unsigned *dst,
72 unsigned w, unsigned h,
73 const uint8_t *p)
74 {
75 unsigned i, j;
76
77 for (i = 0; i < h; i++) {
78 for (j = 0; j < w; j++) {
79 unsigned r, g, b, a;
80 r = PIXEL(p, j, i, 0);
81 g = PIXEL(p, j, i, 1);
82 b = PIXEL(p, j, i, 2);
83 a = PIXEL(p, j, i, 3);
84 *dst++ = (a << 24) | (r << 16) | (g << 8) | b;
85 }
86 }
87 }
88
89
90 /*** PIPE_FORMAT_A8R8G8B8_UNORM ***/
91
92 static void
93 x8r8g8b8_get_tile_rgba(const unsigned *src,
94 unsigned w, unsigned h,
95 uint8_t *p)
96 {
97 unsigned i, j;
98
99 for (i = 0; i < h; i++) {
100 for (j = 0; j < w; j++) {
101 const unsigned pixel = *src++;
102 PIXEL(p, j, i, 0) = (pixel >> 16) & 0xff;
103 PIXEL(p, j, i, 1) = (pixel >> 8) & 0xff;
104 PIXEL(p, j, i, 2) = (pixel >> 0) & 0xff;
105 PIXEL(p, j, i, 3) = 0xff;
106 }
107 }
108 }
109
110
111 static void
112 x8r8g8b8_put_tile_rgba(unsigned *dst,
113 unsigned w, unsigned h,
114 const uint8_t *p)
115 {
116 unsigned i, j;
117
118 for (i = 0; i < h; i++) {
119 for (j = 0; j < w; j++) {
120 unsigned r, g, b;
121 r = PIXEL(p, j, i, 0);
122 g = PIXEL(p, j, i, 1);
123 b = PIXEL(p, j, i, 2);
124 *dst++ = (0xff << 24) | (r << 16) | (g << 8) | b;
125 }
126 }
127 }
128
129
130 /*** PIPE_FORMAT_B8G8R8A8_UNORM ***/
131
132 static void
133 b8g8r8a8_get_tile_rgba(const unsigned *src,
134 unsigned w, unsigned h,
135 uint8_t *p)
136 {
137 unsigned i, j;
138
139 for (i = 0; i < h; i++) {
140 for (j = 0; j < w; j++) {
141 const unsigned pixel = *src++;
142 PIXEL(p, j, i, 0) = (pixel >> 8) & 0xff;
143 PIXEL(p, j, i, 1) = (pixel >> 16) & 0xff;
144 PIXEL(p, j, i, 2) = (pixel >> 24) & 0xff;
145 PIXEL(p, j, i, 3) = (pixel >> 0) & 0xff;
146 }
147 }
148 }
149
150
151 static void
152 b8g8r8a8_put_tile_rgba(unsigned *dst,
153 unsigned w, unsigned h,
154 const uint8_t *p)
155 {
156 unsigned i, j;
157
158 for (i = 0; i < h; i++) {
159 for (j = 0; j < w; j++) {
160 unsigned r, g, b, a;
161 r = PIXEL(p, j, i, 0);
162 g = PIXEL(p, j, i, 1);
163 b = PIXEL(p, j, i, 2);
164 a = PIXEL(p, j, i, 3);
165 *dst++ = (b << 24) | (g << 16) | (r << 8) | a;
166 }
167 }
168 }
169
170
171 /*** PIPE_FORMAT_A1R5G5B5_UNORM ***/
172
173 static void
174 a1r5g5b5_get_tile_rgba(const ushort *src,
175 unsigned w, unsigned h,
176 uint8_t *p)
177 {
178 unsigned i, j;
179
180 for (i = 0; i < h; i++) {
181 for (j = 0; j < w; j++) {
182 const ushort pixel = *src++;
183 PIXEL(p, j, i, 0) = ((pixel >> 10) & 0x1f) * 255 / 31;
184 PIXEL(p, j, i, 1) = ((pixel >> 5) & 0x1f) * 255 / 31;
185 PIXEL(p, j, i, 2) = ((pixel ) & 0x1f) * 255 / 31;
186 PIXEL(p, j, i, 3) = ((pixel >> 15) ) * 255;
187 }
188 }
189 }
190
191
192 static void
193 a1r5g5b5_put_tile_rgba(ushort *dst,
194 unsigned w, unsigned h,
195 const uint8_t *p)
196 {
197 unsigned i, j;
198
199 for (i = 0; i < h; i++) {
200 for (j = 0; j < w; j++) {
201 unsigned r, g, b, a;
202 r = PIXEL(p, j, i, 0);
203 g = PIXEL(p, j, i, 1);
204 b = PIXEL(p, j, i, 2);
205 a = PIXEL(p, j, i, 3);
206 r = r >> 3; /* 5 bits */
207 g = g >> 3; /* 5 bits */
208 b = b >> 3; /* 5 bits */
209 a = a >> 7; /* 1 bit */
210 *dst++ = (a << 15) | (r << 10) | (g << 5) | b;
211 }
212 }
213 }
214
215
216 /*** PIPE_FORMAT_A4R4G4B4_UNORM ***/
217
218 static void
219 a4r4g4b4_get_tile_rgba(const ushort *src,
220 unsigned w, unsigned h,
221 uint8_t *p)
222 {
223 unsigned i, j;
224
225 for (i = 0; i < h; i++) {
226 for (j = 0; j < w; j++) {
227 const ushort pixel = *src++;
228 PIXEL(p, j, i, 0) = ((pixel >> 8) & 0xf) * 255 / 15;
229 PIXEL(p, j, i, 1) = ((pixel >> 4) & 0xf) * 255 / 15;
230 PIXEL(p, j, i, 2) = ((pixel ) & 0xf) * 255 / 15;
231 PIXEL(p, j, i, 3) = ((pixel >> 12) ) * 255 / 15;
232 }
233 }
234 }
235
236
237 static void
238 a4r4g4b4_put_tile_rgba(ushort *dst,
239 unsigned w, unsigned h,
240 const uint8_t *p)
241 {
242 unsigned i, j;
243
244 for (i = 0; i < h; i++) {
245 for (j = 0; j < w; j++) {
246 unsigned r, g, b, a;
247 r = PIXEL(p, j, i, 0);
248 g = PIXEL(p, j, i, 1);
249 b = PIXEL(p, j, i, 2);
250 a = PIXEL(p, j, i, 3);
251 r >>= 4;
252 g >>= 4;
253 b >>= 4;
254 a >>= 4;
255 *dst++ = (a << 12) | (r << 16) | (g << 4) | b;
256 }
257 }
258 }
259
260
261 /*** PIPE_FORMAT_R5G6B5_UNORM ***/
262
263 static void
264 r5g6b5_get_tile_rgba(const ushort *src,
265 unsigned w, unsigned h,
266 uint8_t *p)
267 {
268 unsigned i, j;
269
270 for (i = 0; i < h; i++) {
271 for (j = 0; j < w; j++) {
272 const ushort pixel = *src++;
273 PIXEL(p, j, i, 0) = ((pixel >> 11) & 0x1f) * 255 / 31;
274 PIXEL(p, j, i, 1) = ((pixel >> 5) & 0x3f) * 255 / 63;
275 PIXEL(p, j, i, 2) = ((pixel ) & 0x1f) * 255 / 31;
276 PIXEL(p, j, i, 3) = 255;
277 }
278 }
279 }
280
281
282 static void
283 r5g6b5_put_tile_rgba(ushort *dst,
284 unsigned w, unsigned h,
285 const uint8_t *p)
286 {
287 unsigned i, j;
288
289 for (i = 0; i < h; i++) {
290 for (j = 0; j < w; j++) {
291 uint r = (uint) PIXEL(p, j, i, 0) * 31 / 255;
292 uint g = (uint) PIXEL(p, j, i, 1) * 63 / 255;
293 uint b = (uint) PIXEL(p, j, i, 2) * 31 / 255;
294 *dst++ = (r << 11) | (g << 5) | (b);
295 }
296 }
297 }
298
299
300
301 /*** PIPE_FORMAT_Z16_UNORM ***/
302
303 /**
304 * Return each Z value as four floats in [0,1].
305 */
306 static void
307 z16_get_tile_rgba(const ushort *src,
308 unsigned w, unsigned h,
309 uint8_t *p)
310 {
311 const float scale = 1.0f / 65535.0f;
312 unsigned i, j;
313
314 for (i = 0; i < h; i++) {
315 for (j = 0; j < w; j++) {
316 PIXEL(p, j, i, 0) =
317 PIXEL(p, j, i, 1) =
318 PIXEL(p, j, i, 2) =
319 PIXEL(p, j, i, 3) = *src++ * scale;
320 }
321 }
322 }
323
324
325
326
327 /*** PIPE_FORMAT_L8_UNORM ***/
328
329 static void
330 l8_get_tile_rgba(const ubyte *src,
331 unsigned w, unsigned h,
332 uint8_t *p)
333 {
334 unsigned i, j;
335
336 for (i = 0; i < h; i++) {
337 for (j = 0; j < w; j++, src++) {
338 PIXEL(p, j, i, 0) =
339 PIXEL(p, j, i, 1) =
340 PIXEL(p, j, i, 2) = *src;
341 PIXEL(p, j, i, 3) = 255;
342 }
343 }
344 }
345
346
347 static void
348 l8_put_tile_rgba(ubyte *dst,
349 unsigned w, unsigned h,
350 const uint8_t *p)
351 {
352 unsigned i, j;
353
354 for (i = 0; i < h; i++) {
355 for (j = 0; j < w; j++) {
356 unsigned r;
357 r = PIXEL(p, j, i, 0);
358 *dst++ = (ubyte) r;
359 }
360 }
361 }
362
363
364
365 /*** PIPE_FORMAT_A8_UNORM ***/
366
367 static void
368 a8_get_tile_rgba(const ubyte *src,
369 unsigned w, unsigned h,
370 uint8_t *p)
371 {
372 unsigned i, j;
373
374 for (i = 0; i < h; i++) {
375 for (j = 0; j < w; j++, src++) {
376 PIXEL(p, j, i, 0) =
377 PIXEL(p, j, i, 1) =
378 PIXEL(p, j, i, 2) = 0;
379 PIXEL(p, j, i, 3) = *src;
380 }
381 }
382 }
383
384
385 static void
386 a8_put_tile_rgba(ubyte *dst,
387 unsigned w, unsigned h,
388 const uint8_t *p)
389 {
390 unsigned i, j;
391
392 for (i = 0; i < h; i++) {
393 for (j = 0; j < w; j++) {
394 unsigned a;
395 a = PIXEL(p, j, i, 3);
396 *dst++ = (ubyte) a;
397 }
398 }
399 }
400
401
402
403 /*** PIPE_FORMAT_R16_SNORM ***/
404
405 static void
406 r16_get_tile_rgba(const short *src,
407 unsigned w, unsigned h,
408 uint8_t *p)
409 {
410 unsigned i, j;
411
412 for (i = 0; i < h; i++) {
413 for (j = 0; j < w; j++, src++) {
414 PIXEL(p, j, i, 0) = MAX2(src[0] >> 7, 0);
415 PIXEL(p, j, i, 1) =
416 PIXEL(p, j, i, 2) = 0;
417 PIXEL(p, j, i, 3) = 255;
418 }
419 }
420 }
421
422
423 static void
424 r16_put_tile_rgba(short *dst,
425 unsigned w, unsigned h,
426 const uint8_t *p)
427 {
428 unsigned i, j;
429
430 for (i = 0; i < h; i++) {
431 for (j = 0; j < w; j++, dst++) {
432 dst[0] = PIXEL(p, j, i, 0) << 7;
433 }
434 }
435 }
436
437
438 /*** PIPE_FORMAT_R16G16B16A16_SNORM ***/
439
440 static void
441 r16g16b16a16_get_tile_rgba(const short *src,
442 unsigned w, unsigned h,
443 uint8_t *p)
444 {
445 unsigned i, j;
446
447 for (i = 0; i < h; i++) {
448 for (j = 0; j < w; j++, src += 4) {
449 PIXEL(p, j, i, 0) = src[0] >> 8;
450 PIXEL(p, j, i, 1) = src[1] >> 8;
451 PIXEL(p, j, i, 2) = src[2] >> 8;
452 PIXEL(p, j, i, 3) = src[3] >> 8;
453 }
454 }
455 }
456
457
458 static void
459 r16g16b16a16_put_tile_rgba(short *dst,
460 unsigned w, unsigned h,
461 const uint8_t *p)
462 {
463 unsigned i, j;
464
465 for (i = 0; i < h; i++) {
466 for (j = 0; j < w; j++, dst += 4) {
467 dst[0] = PIXEL(p, j, i, 0) << 8;
468 dst[1] = PIXEL(p, j, i, 1) << 8;
469 dst[2] = PIXEL(p, j, i, 2) << 8;
470 dst[3] = PIXEL(p, j, i, 3) << 8;
471 }
472 }
473 }
474
475
476
477 /*** PIPE_FORMAT_I8_UNORM ***/
478
479 static void
480 i8_get_tile_rgba(const ubyte *src,
481 unsigned w, unsigned h,
482 uint8_t *p)
483 {
484 unsigned i, j;
485
486 for (i = 0; i < h; i++) {
487 for (j = 0; j < w; j++, src++) {
488 PIXEL(p, j, i, 0) =
489 PIXEL(p, j, i, 1) =
490 PIXEL(p, j, i, 2) =
491 PIXEL(p, j, i, 3) = *src;
492 }
493 }
494 }
495
496
497 static void
498 i8_put_tile_rgba(ubyte *dst,
499 unsigned w, unsigned h,
500 const uint8_t *p)
501 {
502 unsigned i, j;
503
504 for (i = 0; i < h; i++) {
505 for (j = 0; j < w; j++) {
506 unsigned r;
507 r = PIXEL(p, j, i, 0);
508 *dst++ = (ubyte) r;
509 }
510 }
511 }
512
513
514 /*** PIPE_FORMAT_A8L8_UNORM ***/
515
516 static void
517 a8l8_get_tile_rgba(const ushort *src,
518 unsigned w, unsigned h,
519 uint8_t *p)
520 {
521 unsigned i, j;
522
523 for (i = 0; i < h; i++) {
524 for (j = 0; j < w; j++) {
525 ushort ra = *src++;
526 PIXEL(p, j, i, 0) =
527 PIXEL(p, j, i, 1) =
528 PIXEL(p, j, i, 2) = ra & 0xff;
529 PIXEL(p, j, i, 3) = ra >> 8;
530 }
531 }
532 }
533
534
535 static void
536 a8l8_put_tile_rgba(ushort *dst,
537 unsigned w, unsigned h,
538 const uint8_t *p)
539 {
540 unsigned i, j;
541
542 for (i = 0; i < h; i++) {
543 for (j = 0; j < w; j++) {
544 unsigned r, a;
545 r = PIXEL(p, j, i, 0);
546 a = PIXEL(p, j, i, 3);
547 *dst++ = (a << 8) | r;
548 }
549 }
550 }
551
552
553
554
555 /*** PIPE_FORMAT_Z32_UNORM ***/
556
557 /**
558 * Return each Z value as four floats in [0,1].
559 */
560 static void
561 z32_get_tile_rgba(const unsigned *src,
562 unsigned w, unsigned h,
563 uint8_t *p)
564 {
565 const double scale = 1.0 / (double) 0xffffffff;
566 unsigned i, j;
567
568 for (i = 0; i < h; i++) {
569 for (j = 0; j < w; j++) {
570 PIXEL(p, j, i, 0) =
571 PIXEL(p, j, i, 1) =
572 PIXEL(p, j, i, 2) =
573 PIXEL(p, j, i, 3) = (float) (*src++ * scale);
574 }
575 }
576 }
577
578
579 /*** PIPE_FORMAT_S8Z24_UNORM ***/
580
581 /**
582 * Return Z component as four float in [0,1]. Stencil part ignored.
583 */
584 static void
585 s8z24_get_tile_rgba(const unsigned *src,
586 unsigned w, unsigned h,
587 uint8_t *p)
588 {
589 const double scale = 1.0 / ((1 << 24) - 1);
590 unsigned i, j;
591
592 for (i = 0; i < h; i++) {
593 for (j = 0; j < w; j++) {
594 PIXEL(p, j, i, 0) =
595 PIXEL(p, j, i, 1) =
596 PIXEL(p, j, i, 2) =
597 PIXEL(p, j, i, 3) = (float) (scale * (*src++ & 0xffffff));
598 }
599 }
600 }
601
602
603 /*** PIPE_FORMAT_Z24S8_UNORM ***/
604
605 /**
606 * Return Z component as four float in [0,1]. Stencil part ignored.
607 */
608 static void
609 z24s8_get_tile_rgba(const unsigned *src,
610 unsigned w, unsigned h,
611 uint8_t *p)
612 {
613 const double scale = 1.0 / ((1 << 24) - 1);
614 unsigned i, j;
615
616 for (i = 0; i < h; i++) {
617 for (j = 0; j < w; j++) {
618 PIXEL(p, j, i, 0) =
619 PIXEL(p, j, i, 1) =
620 PIXEL(p, j, i, 2) =
621 PIXEL(p, j, i, 3) = (float) (scale * (*src++ >> 8));
622 }
623 }
624 }
625
626
627 /*** PIPE_FORMAT_Z32_FLOAT ***/
628
629 /**
630 * Return each Z value as four floats in [0,1].
631 */
632 static void
633 z32f_get_tile_rgba(const float *src,
634 unsigned w, unsigned h,
635 uint8_t *p)
636 {
637 unsigned i, j;
638
639 for (i = 0; i < h; i++) {
640 for (j = 0; j < w; j++) {
641 PIXEL(p, j, i, 0) =
642 PIXEL(p, j, i, 1) =
643 PIXEL(p, j, i, 2) =
644 PIXEL(p, j, i, 3) = *src++;
645 }
646 }
647 }
648
649
650 /*** PIPE_FORMAT_YCBCR / PIPE_FORMAT_YCBCR_REV ***/
651
652 /**
653 * Convert YCbCr (or YCrCb) to RGBA.
654 */
655 static void
656 ycbcr_get_tile_rgba(const ushort *src,
657 unsigned w, unsigned h,
658 uint8_t *p,
659 boolean rev)
660 {
661 unsigned i, j;
662
663 for (i = 0; i < h; i++) {
664 /* do two texels at a time */
665 for (j = 0; j < (w & ~1); j += 2, src += 2) {
666 const ushort t0 = src[0];
667 const ushort t1 = src[1];
668 const ubyte y0 = (t0 >> 8) & 0xff; /* luminance */
669 const ubyte y1 = (t1 >> 8) & 0xff; /* luminance */
670 ubyte cb, cr;
671 float r, g, b;
672
673 if (rev) {
674 cb = t1 & 0xff; /* chroma U */
675 cr = t0 & 0xff; /* chroma V */
676 }
677 else {
678 cb = t0 & 0xff; /* chroma U */
679 cr = t1 & 0xff; /* chroma V */
680 }
681
682 /* even pixel: y0,cr,cb */
683 r = 1.164f * (y0-16) + 1.596f * (cr-128);
684 g = 1.164f * (y0-16) - 0.813f * (cr-128) - 0.391f * (cb-128);
685 b = 1.164f * (y0-16) + 2.018f * (cb-128);
686 PIXEL(p, j, i, 0) = r;
687 PIXEL(p, j, i, 1) = g;
688 PIXEL(p, j, i, 2) = b;
689 PIXEL(p, j, i, 3) = 255;
690
691 /* odd pixel: use y1,cr,cb */
692 r = 1.164f * (y1-16) + 1.596f * (cr-128);
693 g = 1.164f * (y1-16) - 0.813f * (cr-128) - 0.391f * (cb-128);
694 b = 1.164f * (y1-16) + 2.018f * (cb-128);
695 PIXEL(p, j + 1, i, 0) = r;
696 PIXEL(p, j + 1, i, 1) = g;
697 PIXEL(p, j + 1, i, 2) = b;
698 PIXEL(p, j + 1, i, 3) = 255;
699 }
700 /* do the last texel */
701 if (w & 1) {
702 const ushort t0 = src[0];
703 const ushort t1 = src[1];
704 const ubyte y0 = (t0 >> 8) & 0xff; /* luminance */
705 ubyte cb, cr;
706 float r, g, b;
707
708 if (rev) {
709 cb = t1 & 0xff; /* chroma U */
710 cr = t0 & 0xff; /* chroma V */
711 }
712 else {
713 cb = t0 & 0xff; /* chroma U */
714 cr = t1 & 0xff; /* chroma V */
715 }
716
717 /* even pixel: y0,cr,cb */
718 r = 1.164f * (y0-16) + 1.596f * (cr-128);
719 g = 1.164f * (y0-16) - 0.813f * (cr-128) - 0.391f * (cb-128);
720 b = 1.164f * (y0-16) + 2.018f * (cb-128);
721 PIXEL(p, j, i, 0) = r;
722 PIXEL(p, j, i, 1) = g;
723 PIXEL(p, j, i, 2) = b;
724 PIXEL(p, j, i, 3) = 255;
725 }
726 }
727 }
728
729
730 static void
731 fake_get_tile_rgba(const ushort *src,
732 unsigned w, unsigned h,
733 uint8_t *p)
734 {
735 unsigned i, j;
736
737 for (i = 0; i < h; i++) {
738 for (j = 0; j < w; j++) {
739 PIXEL(p, j, i, 0) =
740 PIXEL(p, j, i, 1) =
741 PIXEL(p, j, i, 2) =
742 PIXEL(p, j, i, 3) = (i ^ j) & 1 ? 255 : 0;
743 }
744 }
745 }
746
747
748 static void
749 lp_tile_raw_to_rgba_soa(enum pipe_format format,
750 void *src,
751 uint w, uint h,
752 uint8_t *p)
753 {
754 switch (format) {
755 case PIPE_FORMAT_A8R8G8B8_UNORM:
756 a8r8g8b8_get_tile_rgba((unsigned *) src, w, h, p);
757 break;
758 case PIPE_FORMAT_X8R8G8B8_UNORM:
759 x8r8g8b8_get_tile_rgba((unsigned *) src, w, h, p);
760 break;
761 case PIPE_FORMAT_B8G8R8A8_UNORM:
762 b8g8r8a8_get_tile_rgba((unsigned *) src, w, h, p);
763 break;
764 case PIPE_FORMAT_A1R5G5B5_UNORM:
765 a1r5g5b5_get_tile_rgba((ushort *) src, w, h, p);
766 break;
767 case PIPE_FORMAT_A4R4G4B4_UNORM:
768 a4r4g4b4_get_tile_rgba((ushort *) src, w, h, p);
769 break;
770 case PIPE_FORMAT_R5G6B5_UNORM:
771 r5g6b5_get_tile_rgba((ushort *) src, w, h, p);
772 break;
773 case PIPE_FORMAT_L8_UNORM:
774 l8_get_tile_rgba((ubyte *) src, w, h, p);
775 break;
776 case PIPE_FORMAT_A8_UNORM:
777 a8_get_tile_rgba((ubyte *) src, w, h, p);
778 break;
779 case PIPE_FORMAT_I8_UNORM:
780 i8_get_tile_rgba((ubyte *) src, w, h, p);
781 break;
782 case PIPE_FORMAT_A8L8_UNORM:
783 a8l8_get_tile_rgba((ushort *) src, w, h, p);
784 break;
785 case PIPE_FORMAT_R16_SNORM:
786 r16_get_tile_rgba((short *) src, w, h, p);
787 break;
788 case PIPE_FORMAT_R16G16B16A16_SNORM:
789 r16g16b16a16_get_tile_rgba((short *) src, w, h, p);
790 break;
791 case PIPE_FORMAT_Z16_UNORM:
792 z16_get_tile_rgba((ushort *) src, w, h, p);
793 break;
794 case PIPE_FORMAT_Z32_UNORM:
795 z32_get_tile_rgba((unsigned *) src, w, h, p);
796 break;
797 case PIPE_FORMAT_S8Z24_UNORM:
798 case PIPE_FORMAT_X8Z24_UNORM:
799 s8z24_get_tile_rgba((unsigned *) src, w, h, p);
800 break;
801 case PIPE_FORMAT_Z24S8_UNORM:
802 case PIPE_FORMAT_Z24X8_UNORM:
803 z24s8_get_tile_rgba((unsigned *) src, w, h, p);
804 break;
805 case PIPE_FORMAT_Z32_FLOAT:
806 z32f_get_tile_rgba((float *) src, w, h, p);
807 break;
808 case PIPE_FORMAT_YCBCR:
809 ycbcr_get_tile_rgba((ushort *) src, w, h, p, FALSE);
810 break;
811 case PIPE_FORMAT_YCBCR_REV:
812 ycbcr_get_tile_rgba((ushort *) src, w, h, p, TRUE);
813 break;
814 default:
815 debug_printf("%s: unsupported format %s\n", __FUNCTION__, pf_name(format));
816 fake_get_tile_rgba(src, w, h, p);
817 }
818 }
819
820
821 void
822 lp_get_tile_rgba_soa(struct pipe_transfer *pt,
823 uint x, uint y,
824 uint8_t *p)
825 {
826 uint w = TILE_SIZE, h = TILE_SIZE;
827 void *packed;
828
829 if (pipe_clip_tile(x, y, &w, &h, pt))
830 return;
831
832 packed = MALLOC(pf_get_nblocks(&pt->block, w, h) * pt->block.size);
833
834 if (!packed)
835 return;
836
837 if(pt->format == PIPE_FORMAT_YCBCR || pt->format == PIPE_FORMAT_YCBCR_REV)
838 assert((x & 1) == 0);
839
840 pipe_get_tile_raw(pt, x, y, w, h, packed, 0);
841
842 lp_tile_raw_to_rgba_soa(pt->format, packed, w, h, p);
843
844 FREE(packed);
845 }
846
847
848 void
849 lp_put_tile_rgba_soa(struct pipe_transfer *pt,
850 uint x, uint y,
851 const uint8_t *p)
852 {
853 uint w = TILE_SIZE, h = TILE_SIZE;
854 void *packed;
855
856 if (pipe_clip_tile(x, y, &w, &h, pt))
857 return;
858
859 packed = MALLOC(pf_get_nblocks(&pt->block, w, h) * pt->block.size);
860
861 if (!packed)
862 return;
863
864 switch (pt->format) {
865 case PIPE_FORMAT_A8R8G8B8_UNORM:
866 a8r8g8b8_put_tile_rgba((unsigned *) packed, w, h, p);
867 break;
868 case PIPE_FORMAT_X8R8G8B8_UNORM:
869 x8r8g8b8_put_tile_rgba((unsigned *) packed, w, h, p);
870 break;
871 case PIPE_FORMAT_B8G8R8A8_UNORM:
872 b8g8r8a8_put_tile_rgba((unsigned *) packed, w, h, p);
873 break;
874 case PIPE_FORMAT_A1R5G5B5_UNORM:
875 a1r5g5b5_put_tile_rgba((ushort *) packed, w, h, p);
876 break;
877 case PIPE_FORMAT_R5G6B5_UNORM:
878 r5g6b5_put_tile_rgba((ushort *) packed, w, h, p);
879 break;
880 case PIPE_FORMAT_R8G8B8A8_UNORM:
881 assert(0);
882 break;
883 case PIPE_FORMAT_A4R4G4B4_UNORM:
884 a4r4g4b4_put_tile_rgba((ushort *) packed, w, h, p);
885 break;
886 case PIPE_FORMAT_L8_UNORM:
887 l8_put_tile_rgba((ubyte *) packed, w, h, p);
888 break;
889 case PIPE_FORMAT_A8_UNORM:
890 a8_put_tile_rgba((ubyte *) packed, w, h, p);
891 break;
892 case PIPE_FORMAT_I8_UNORM:
893 i8_put_tile_rgba((ubyte *) packed, w, h, p);
894 break;
895 case PIPE_FORMAT_A8L8_UNORM:
896 a8l8_put_tile_rgba((ushort *) packed, w, h, p);
897 break;
898 case PIPE_FORMAT_R16_SNORM:
899 r16_put_tile_rgba((short *) packed, w, h, p);
900 break;
901 case PIPE_FORMAT_R16G16B16A16_SNORM:
902 r16g16b16a16_put_tile_rgba((short *) packed, w, h, p);
903 break;
904 case PIPE_FORMAT_Z16_UNORM:
905 /*z16_put_tile_rgba((ushort *) packed, w, h, p);*/
906 break;
907 case PIPE_FORMAT_Z32_UNORM:
908 /*z32_put_tile_rgba((unsigned *) packed, w, h, p);*/
909 break;
910 case PIPE_FORMAT_S8Z24_UNORM:
911 case PIPE_FORMAT_X8Z24_UNORM:
912 /*s8z24_put_tile_rgba((unsigned *) packed, w, h, p);*/
913 break;
914 case PIPE_FORMAT_Z24S8_UNORM:
915 case PIPE_FORMAT_Z24X8_UNORM:
916 /*z24s8_put_tile_rgba((unsigned *) packed, w, h, p);*/
917 break;
918 default:
919 debug_printf("%s: unsupported format %s\n", __FUNCTION__, pf_name(pt->format));
920 }
921
922 pipe_put_tile_raw(pt, x, y, w, h, packed, 0);
923
924 FREE(packed);
925 }
926
927