1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 * RGBA/float tile get/put functions.
30 * Usable both by drivers and state trackers.
31 * Surfaces should already be in a mapped state.
35 #include "pipe/p_defines.h"
36 #include "pipe/p_util.h"
37 #include "pipe/p_inlines.h"
44 * Move raw block of pixels from surface to user memory.
45 * This should be usable by any hw driver that has mappable surfaces.
48 pipe_get_tile_raw(struct pipe_context
*pipe
,
49 struct pipe_surface
*ps
,
50 uint x
, uint y
, uint w
, uint h
,
51 void *dst
, int dst_stride
)
53 struct pipe_screen
*screen
= pipe
->screen
;
56 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
60 dst_stride
= pf_get_nblocksx(&ps
->block
, w
) * ps
->block
.size
;
62 src
= screen
->surface_map(screen
, ps
, PIPE_BUFFER_USAGE_CPU_READ
);
67 pipe_copy_rect(dst
, &ps
->block
, dst_stride
, 0, 0, w
, h
, src
, ps
->stride
, x
, y
);
69 screen
->surface_unmap(screen
, ps
);
74 * Move raw block of pixels from user memory to surface.
75 * This should be usable by any hw driver that has mappable surfaces.
78 pipe_put_tile_raw(struct pipe_context
*pipe
,
79 struct pipe_surface
*ps
,
80 uint x
, uint y
, uint w
, uint h
,
81 const void *src
, int src_stride
)
83 struct pipe_screen
*screen
= pipe
->screen
;
86 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
90 src_stride
= pf_get_nblocksx(&ps
->block
, w
) * ps
->block
.size
;
92 dst
= screen
->surface_map(screen
, ps
, PIPE_BUFFER_USAGE_CPU_WRITE
);
97 pipe_copy_rect(dst
, &ps
->block
, ps
->stride
, x
, y
, w
, h
, src
, src_stride
, 0, 0);
99 screen
->surface_unmap(screen
, ps
);
105 /** Convert short in [-32768,32767] to GLfloat in [-1.0,1.0] */
106 #define SHORT_TO_FLOAT(S) ((2.0F * (S) + 1.0F) * (1.0F/65535.0F))
108 #define UNCLAMPED_FLOAT_TO_SHORT(us, f) \
109 us = ( (short) ( CLAMP((f), -1.0, 1.0) * 32767.0F) )
113 /*** PIPE_FORMAT_A8R8G8B8_UNORM ***/
116 a8r8g8b8_get_tile_rgba(unsigned *src
,
117 unsigned w
, unsigned h
,
123 for (i
= 0; i
< h
; i
++) {
125 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
126 const unsigned pixel
= *src
++;
127 pRow
[0] = UBYTE_TO_FLOAT((pixel
>> 16) & 0xff);
128 pRow
[1] = UBYTE_TO_FLOAT((pixel
>> 8) & 0xff);
129 pRow
[2] = UBYTE_TO_FLOAT((pixel
>> 0) & 0xff);
130 pRow
[3] = UBYTE_TO_FLOAT((pixel
>> 24) & 0xff);
138 a8r8g8b8_put_tile_rgba(unsigned *dst
,
139 unsigned w
, unsigned h
,
145 for (i
= 0; i
< h
; i
++) {
146 const float *pRow
= p
;
147 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
149 UNCLAMPED_FLOAT_TO_UBYTE(r
, pRow
[0]);
150 UNCLAMPED_FLOAT_TO_UBYTE(g
, pRow
[1]);
151 UNCLAMPED_FLOAT_TO_UBYTE(b
, pRow
[2]);
152 UNCLAMPED_FLOAT_TO_UBYTE(a
, pRow
[3]);
153 *dst
++ = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
160 /*** PIPE_FORMAT_A8R8G8B8_UNORM ***/
163 x8r8g8b8_get_tile_rgba(unsigned *src
,
164 unsigned w
, unsigned h
,
170 for (i
= 0; i
< h
; i
++) {
172 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
173 const unsigned pixel
= *src
++;
174 pRow
[0] = UBYTE_TO_FLOAT((pixel
>> 16) & 0xff);
175 pRow
[1] = UBYTE_TO_FLOAT((pixel
>> 8) & 0xff);
176 pRow
[2] = UBYTE_TO_FLOAT((pixel
>> 0) & 0xff);
177 pRow
[3] = UBYTE_TO_FLOAT(0xff);
185 x8r8g8b8_put_tile_rgba(unsigned *dst
,
186 unsigned w
, unsigned h
,
192 for (i
= 0; i
< h
; i
++) {
193 const float *pRow
= p
;
194 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
196 UNCLAMPED_FLOAT_TO_UBYTE(r
, pRow
[0]);
197 UNCLAMPED_FLOAT_TO_UBYTE(g
, pRow
[1]);
198 UNCLAMPED_FLOAT_TO_UBYTE(b
, pRow
[2]);
199 *dst
++ = (0xff << 24) | (r
<< 16) | (g
<< 8) | b
;
206 /*** PIPE_FORMAT_B8G8R8A8_UNORM ***/
209 b8g8r8a8_get_tile_rgba(unsigned *src
,
210 unsigned w
, unsigned h
,
216 for (i
= 0; i
< h
; i
++) {
218 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
219 const unsigned pixel
= *src
++;
220 pRow
[0] = UBYTE_TO_FLOAT((pixel
>> 8) & 0xff);
221 pRow
[1] = UBYTE_TO_FLOAT((pixel
>> 16) & 0xff);
222 pRow
[2] = UBYTE_TO_FLOAT((pixel
>> 24) & 0xff);
223 pRow
[3] = UBYTE_TO_FLOAT((pixel
>> 0) & 0xff);
231 b8g8r8a8_put_tile_rgba(unsigned *dst
,
232 unsigned w
, unsigned h
,
238 for (i
= 0; i
< h
; i
++) {
239 const float *pRow
= p
;
240 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
242 UNCLAMPED_FLOAT_TO_UBYTE(r
, pRow
[0]);
243 UNCLAMPED_FLOAT_TO_UBYTE(g
, pRow
[1]);
244 UNCLAMPED_FLOAT_TO_UBYTE(b
, pRow
[2]);
245 UNCLAMPED_FLOAT_TO_UBYTE(a
, pRow
[3]);
246 *dst
++ = (b
<< 24) | (g
<< 16) | (r
<< 8) | a
;
253 /*** PIPE_FORMAT_A1R5G5B5_UNORM ***/
256 a1r5g5b5_get_tile_rgba(ushort
*src
,
257 unsigned w
, unsigned h
,
263 for (i
= 0; i
< h
; i
++) {
265 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
266 const ushort pixel
= *src
++;
267 pRow
[0] = ((pixel
>> 10) & 0x1f) * (1.0f
/ 31.0f
);
268 pRow
[1] = ((pixel
>> 5) & 0x1f) * (1.0f
/ 31.0f
);
269 pRow
[2] = ((pixel
) & 0x1f) * (1.0f
/ 31.0f
);
270 pRow
[3] = ((pixel
>> 15) ) * 1.0f
;
277 /*** PIPE_FORMAT_A4R4G4B4_UNORM ***/
280 a4r4g4b4_get_tile_rgba(ushort
*src
,
281 unsigned w
, unsigned h
,
287 for (i
= 0; i
< h
; i
++) {
289 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
290 const ushort pixel
= *src
++;
291 pRow
[0] = ((pixel
>> 8) & 0xf) * (1.0f
/ 15.0f
);
292 pRow
[1] = ((pixel
>> 4) & 0xf) * (1.0f
/ 15.0f
);
293 pRow
[2] = ((pixel
) & 0xf) * (1.0f
/ 15.0f
);
294 pRow
[3] = ((pixel
>> 12) ) * (1.0f
/ 15.0f
);
302 a4r4g4b4_put_tile_rgba(ushort
*dst
,
303 unsigned w
, unsigned h
,
309 for (i
= 0; i
< h
; i
++) {
310 const float *pRow
= p
;
311 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
313 UNCLAMPED_FLOAT_TO_UBYTE(r
, pRow
[0]);
314 UNCLAMPED_FLOAT_TO_UBYTE(g
, pRow
[1]);
315 UNCLAMPED_FLOAT_TO_UBYTE(b
, pRow
[2]);
316 UNCLAMPED_FLOAT_TO_UBYTE(a
, pRow
[3]);
321 *dst
++ = (a
<< 12) | (r
<< 16) | (g
<< 4) | b
;
328 /*** PIPE_FORMAT_R5G6B5_UNORM ***/
331 r5g6b5_get_tile_rgba(ushort
*src
,
332 unsigned w
, unsigned h
,
338 for (i
= 0; i
< h
; i
++) {
340 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
341 const ushort pixel
= *src
++;
342 pRow
[0] = ((pixel
>> 11) & 0x1f) * (1.0f
/ 31.0f
);
343 pRow
[1] = ((pixel
>> 5) & 0x3f) * (1.0f
/ 63.0f
);
344 pRow
[2] = ((pixel
) & 0x1f) * (1.0f
/ 31.0f
);
353 r5g5b5_put_tile_rgba(ushort
*dst
,
354 unsigned w
, unsigned h
,
360 for (i
= 0; i
< h
; i
++) {
361 const float *pRow
= p
;
362 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
363 uint r
= (uint
) (CLAMP(pRow
[0], 0.0, 1.0) * 31.0);
364 uint g
= (uint
) (CLAMP(pRow
[1], 0.0, 1.0) * 63.0);
365 uint b
= (uint
) (CLAMP(pRow
[2], 0.0, 1.0) * 31.0);
366 *dst
++ = (r
<< 11) | (g
<< 5) | (b
);
374 /*** PIPE_FORMAT_Z16_UNORM ***/
377 * Return each Z value as four floats in [0,1].
380 z16_get_tile_rgba(ushort
*src
,
381 unsigned w
, unsigned h
,
385 const float scale
= 1.0f
/ 65535.0f
;
388 for (i
= 0; i
< h
; i
++) {
390 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
394 pRow
[3] = *src
++ * scale
;
403 /*** PIPE_FORMAT_L8_UNORM ***/
406 l8_get_tile_rgba(ubyte
*src
,
407 unsigned w
, unsigned h
,
413 for (i
= 0; i
< h
; i
++) {
415 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
418 pRow
[2] = UBYTE_TO_FLOAT(*src
);
426 /*** PIPE_FORMAT_A8_UNORM ***/
429 a8_get_tile_rgba(ubyte
*src
,
430 unsigned w
, unsigned h
,
436 for (i
= 0; i
< h
; i
++) {
438 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
442 pRow
[3] = UBYTE_TO_FLOAT(*src
);
449 /*** PIPE_FORMAT_R16G16B16A16_SNORM ***/
452 r16g16b16a16_get_tile_rgba(short *src
,
453 unsigned w
, unsigned h
,
459 for (i
= 0; i
< h
; i
++) {
461 for (j
= 0; j
< w
; j
++, src
+= 4, pRow
+= 4) {
462 pRow
[0] = SHORT_TO_FLOAT(src
[0]);
463 pRow
[1] = SHORT_TO_FLOAT(src
[1]);
464 pRow
[2] = SHORT_TO_FLOAT(src
[2]);
465 pRow
[3] = SHORT_TO_FLOAT(src
[3]);
473 r16g16b16a16_put_tile_rgba(short *dst
,
474 unsigned w
, unsigned h
,
480 for (i
= 0; i
< h
; i
++) {
481 const float *pRow
= p
;
482 for (j
= 0; j
< w
; j
++, dst
+= 4, pRow
+= 4) {
483 UNCLAMPED_FLOAT_TO_SHORT(dst
[0], pRow
[0]);
484 UNCLAMPED_FLOAT_TO_SHORT(dst
[1], pRow
[1]);
485 UNCLAMPED_FLOAT_TO_SHORT(dst
[2], pRow
[2]);
486 UNCLAMPED_FLOAT_TO_SHORT(dst
[3], pRow
[3]);
494 /*** PIPE_FORMAT_I8_UNORM ***/
497 i8_get_tile_rgba(ubyte
*src
,
498 unsigned w
, unsigned h
,
504 for (i
= 0; i
< h
; i
++) {
506 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
510 pRow
[3] = UBYTE_TO_FLOAT(*src
);
517 /*** PIPE_FORMAT_A8L8_UNORM ***/
520 a8_l8_get_tile_rgba(ushort
*src
,
521 unsigned w
, unsigned h
,
527 for (i
= 0; i
< h
; i
++) {
529 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
533 pRow
[2] = UBYTE_TO_FLOAT(p
& 0xff);
534 pRow
[3] = UBYTE_TO_FLOAT(p
>> 8);
543 /*** PIPE_FORMAT_Z32_UNORM ***/
546 * Return each Z value as four floats in [0,1].
549 z32_get_tile_rgba(unsigned *src
,
550 unsigned w
, unsigned h
,
554 const double scale
= 1.0 / (double) 0xffffffff;
557 for (i
= 0; i
< h
; i
++) {
559 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
563 pRow
[3] = (float) (*src
++ * scale
);
570 /*** PIPE_FORMAT_S8Z24_UNORM ***/
573 * Return Z component as four float in [0,1]. Stencil part ignored.
576 s8z24_get_tile_rgba(unsigned *src
,
577 unsigned w
, unsigned h
,
581 const double scale
= 1.0 / ((1 << 24) - 1);
584 for (i
= 0; i
< h
; i
++) {
586 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
590 pRow
[3] = (float) (scale
* (*src
++ & 0xffffff));
597 /*** PIPE_FORMAT_Z24S8_UNORM ***/
600 * Return Z component as four float in [0,1]. Stencil part ignored.
603 z24s8_get_tile_rgba(unsigned *src
,
604 unsigned w
, unsigned h
,
608 const double scale
= 1.0 / ((1 << 24) - 1);
611 for (i
= 0; i
< h
; i
++) {
613 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
617 pRow
[3] = (float) (scale
* (*src
++ >> 8));
624 /*** PIPE_FORMAT_YCBCR / PIPE_FORMAT_YCBCR_REV ***/
627 * Convert YCbCr (or YCrCb) to RGBA.
630 ycbcr_get_tile_rgba(ushort
*src
,
631 unsigned w
, unsigned h
,
636 const float scale
= 1.0f
/ 255.0f
;
639 /* we're assuming we're being asked for an even number of texels */
640 assert((w
& 1) == 0);
642 for (i
= 0; i
< h
; i
++) {
644 /* do two texels at a time */
645 for (j
= 0; j
< w
; j
+= 2, src
+= 2) {
646 const ushort t0
= src
[0];
647 const ushort t1
= src
[1];
648 const ubyte y0
= (t0
>> 8) & 0xff; /* luminance */
649 const ubyte y1
= (t1
>> 8) & 0xff; /* luminance */
654 cb
= t1
& 0xff; /* chroma U */
655 cr
= t0
& 0xff; /* chroma V */
658 cb
= t0
& 0xff; /* chroma U */
659 cr
= t1
& 0xff; /* chroma V */
662 /* even pixel: y0,cr,cb */
663 r
= 1.164f
* (y0
-16) + 1.596f
* (cr
-128);
664 g
= 1.164f
* (y0
-16) - 0.813f
* (cr
-128) - 0.391f
* (cb
-128);
665 b
= 1.164f
* (y0
-16) + 2.018f
* (cb
-128);
672 /* odd pixel: use y1,cr,cb */
673 r
= 1.164f
* (y1
-16) + 1.596f
* (cr
-128);
674 g
= 1.164f
* (y1
-16) - 0.813f
* (cr
-128) - 0.391f
* (cb
-128);
675 b
= 1.164f
* (y1
-16) + 2.018f
* (cb
-128);
689 pipe_get_tile_rgba(struct pipe_context
*pipe
,
690 struct pipe_surface
*ps
,
691 uint x
, uint y
, uint w
, uint h
,
694 unsigned dst_stride
= w
* 4;
697 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
700 packed
= MALLOC(pf_get_nblocks(&ps
->block
, w
, h
) * ps
->block
.size
);
705 pipe_get_tile_raw(pipe
, ps
, x
, y
, w
, h
, packed
, 0);
707 switch (ps
->format
) {
708 case PIPE_FORMAT_A8R8G8B8_UNORM
:
709 a8r8g8b8_get_tile_rgba((unsigned *) packed
, w
, h
, p
, dst_stride
);
711 case PIPE_FORMAT_X8R8G8B8_UNORM
:
712 x8r8g8b8_get_tile_rgba((unsigned *) packed
, w
, h
, p
, dst_stride
);
714 case PIPE_FORMAT_B8G8R8A8_UNORM
:
715 b8g8r8a8_get_tile_rgba((unsigned *) packed
, w
, h
, p
, dst_stride
);
717 case PIPE_FORMAT_A1R5G5B5_UNORM
:
718 a1r5g5b5_get_tile_rgba((ushort
*) packed
, w
, h
, p
, dst_stride
);
720 case PIPE_FORMAT_A4R4G4B4_UNORM
:
721 a4r4g4b4_get_tile_rgba((ushort
*) packed
, w
, h
, p
, dst_stride
);
723 case PIPE_FORMAT_R5G6B5_UNORM
:
724 r5g6b5_get_tile_rgba((ushort
*) packed
, w
, h
, p
, dst_stride
);
726 case PIPE_FORMAT_L8_UNORM
:
727 l8_get_tile_rgba((ubyte
*) packed
, w
, h
, p
, dst_stride
);
729 case PIPE_FORMAT_A8_UNORM
:
730 a8_get_tile_rgba((ubyte
*) packed
, w
, h
, p
, dst_stride
);
732 case PIPE_FORMAT_I8_UNORM
:
733 i8_get_tile_rgba((ubyte
*) packed
, w
, h
, p
, dst_stride
);
735 case PIPE_FORMAT_A8L8_UNORM
:
736 a8_l8_get_tile_rgba((ushort
*) packed
, w
, h
, p
, dst_stride
);
738 case PIPE_FORMAT_R16G16B16A16_SNORM
:
739 r16g16b16a16_get_tile_rgba((short *) packed
, w
, h
, p
, dst_stride
);
741 case PIPE_FORMAT_Z16_UNORM
:
742 z16_get_tile_rgba((ushort
*) packed
, w
, h
, p
, dst_stride
);
744 case PIPE_FORMAT_Z32_UNORM
:
745 z32_get_tile_rgba((unsigned *) packed
, w
, h
, p
, dst_stride
);
747 case PIPE_FORMAT_S8Z24_UNORM
:
748 case PIPE_FORMAT_X8Z24_UNORM
:
749 s8z24_get_tile_rgba((unsigned *) packed
, w
, h
, p
, dst_stride
);
751 case PIPE_FORMAT_Z24S8_UNORM
:
752 z24s8_get_tile_rgba((unsigned *) packed
, w
, h
, p
, dst_stride
);
754 case PIPE_FORMAT_YCBCR
:
755 assert((x
& 1) == 0);
756 ycbcr_get_tile_rgba((ushort
*) packed
, w
, h
, p
, dst_stride
, FALSE
);
758 case PIPE_FORMAT_YCBCR_REV
:
759 assert((x
& 1) == 0);
760 ycbcr_get_tile_rgba((ushort
*) packed
, w
, h
, p
, dst_stride
, TRUE
);
771 pipe_put_tile_rgba(struct pipe_context
*pipe
,
772 struct pipe_surface
*ps
,
773 uint x
, uint y
, uint w
, uint h
,
776 unsigned src_stride
= w
* 4;
779 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
782 packed
= MALLOC(pf_get_nblocks(&ps
->block
, w
, h
) * ps
->block
.size
);
787 switch (ps
->format
) {
788 case PIPE_FORMAT_A8R8G8B8_UNORM
:
789 a8r8g8b8_put_tile_rgba((unsigned *) packed
, w
, h
, p
, src_stride
);
791 case PIPE_FORMAT_X8R8G8B8_UNORM
:
792 x8r8g8b8_put_tile_rgba((unsigned *) packed
, w
, h
, p
, src_stride
);
794 case PIPE_FORMAT_B8G8R8A8_UNORM
:
795 b8g8r8a8_put_tile_rgba((unsigned *) packed
, w
, h
, p
, src_stride
);
797 case PIPE_FORMAT_A1R5G5B5_UNORM
:
798 /*a1r5g5b5_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
800 case PIPE_FORMAT_R5G6B5_UNORM
:
801 r5g5b5_put_tile_rgba((ushort
*) packed
, w
, h
, p
, src_stride
);
803 case PIPE_FORMAT_R8G8B8A8_UNORM
:
806 case PIPE_FORMAT_A4R4G4B4_UNORM
:
807 a4r4g4b4_put_tile_rgba((ushort
*) packed
, w
, h
, p
, src_stride
);
809 case PIPE_FORMAT_L8_UNORM
:
810 /*l8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride);*/
812 case PIPE_FORMAT_A8_UNORM
:
813 /*a8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride);*/
815 case PIPE_FORMAT_I8_UNORM
:
816 /*i8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride);*/
818 case PIPE_FORMAT_A8L8_UNORM
:
819 /*a8_l8_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
821 case PIPE_FORMAT_R16G16B16A16_SNORM
:
822 r16g16b16a16_put_tile_rgba((short *) packed
, w
, h
, p
, src_stride
);
824 case PIPE_FORMAT_Z16_UNORM
:
825 /*z16_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
827 case PIPE_FORMAT_Z32_UNORM
:
828 /*z32_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
830 case PIPE_FORMAT_S8Z24_UNORM
:
831 case PIPE_FORMAT_X8Z24_UNORM
:
832 /*s8z24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
834 case PIPE_FORMAT_Z24S8_UNORM
:
835 /*z24s8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
841 pipe_put_tile_raw(pipe
, ps
, x
, y
, w
, h
, packed
, 0);
848 * Get a block of Z values, converted to 32-bit range.
851 pipe_get_tile_z(struct pipe_context
*pipe
,
852 struct pipe_surface
*ps
,
853 uint x
, uint y
, uint w
, uint h
,
856 struct pipe_screen
*screen
= pipe
->screen
;
857 const uint dstStride
= w
;
862 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
865 map
= (ubyte
*)screen
->surface_map(screen
, ps
, PIPE_BUFFER_USAGE_CPU_READ
);
871 switch (ps
->format
) {
872 case PIPE_FORMAT_Z32_UNORM
:
875 = (const uint
*)(map
+ y
* ps
->stride
+ x
*4);
876 for (i
= 0; i
< h
; i
++) {
877 memcpy(pDest
, pSrc
, 4 * w
);
879 pSrc
+= ps
->stride
/4;
883 case PIPE_FORMAT_S8Z24_UNORM
:
884 case PIPE_FORMAT_X8Z24_UNORM
:
887 = (const uint
*)(map
+ y
* ps
->stride
+ x
*4);
888 for (i
= 0; i
< h
; i
++) {
889 for (j
= 0; j
< w
; j
++) {
890 /* convert 24-bit Z to 32-bit Z */
891 pDest
[j
] = (pSrc
[j
] << 8) | (pSrc
[j
] & 0xff);
894 pSrc
+= ps
->stride
/4;
898 case PIPE_FORMAT_Z16_UNORM
:
901 = (const ushort
*)(map
+ y
* ps
->stride
+ x
*2);
902 for (i
= 0; i
< h
; i
++) {
903 for (j
= 0; j
< w
; j
++) {
904 /* convert 16-bit Z to 32-bit Z */
905 pDest
[j
] = (pSrc
[j
] << 16) | pSrc
[j
];
908 pSrc
+= ps
->stride
/2;
916 screen
->surface_unmap(screen
, ps
);
921 pipe_put_tile_z(struct pipe_context
*pipe
,
922 struct pipe_surface
*ps
,
923 uint x
, uint y
, uint w
, uint h
,
926 struct pipe_screen
*screen
= pipe
->screen
;
927 const uint srcStride
= w
;
928 const uint
*pSrc
= zSrc
;
932 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
935 map
= (ubyte
*)screen
->surface_map(screen
, ps
, PIPE_BUFFER_USAGE_CPU_WRITE
);
941 switch (ps
->format
) {
942 case PIPE_FORMAT_Z32_UNORM
:
944 uint
*pDest
= (uint
*) (map
+ y
* ps
->stride
+ x
*4);
945 for (i
= 0; i
< h
; i
++) {
946 memcpy(pDest
, pSrc
, 4 * w
);
947 pDest
+= ps
->stride
/4;
952 case PIPE_FORMAT_S8Z24_UNORM
:
953 case PIPE_FORMAT_X8Z24_UNORM
:
955 uint
*pDest
= (uint
*) (map
+ y
* ps
->stride
+ x
*4);
956 for (i
= 0; i
< h
; i
++) {
957 for (j
= 0; j
< w
; j
++) {
958 /* convert 32-bit Z to 24-bit Z (0 stencil) */
959 pDest
[j
] = pSrc
[j
] >> 8;
961 pDest
+= ps
->stride
/4;
966 case PIPE_FORMAT_Z16_UNORM
:
968 ushort
*pDest
= (ushort
*) (map
+ y
* ps
->stride
+ x
*2);
969 for (i
= 0; i
< h
; i
++) {
970 for (j
= 0; j
< w
; j
++) {
971 /* convert 32-bit Z to 16-bit Z */
972 pDest
[j
] = pSrc
[j
] >> 16;
974 pDest
+= ps
->stride
/2;
983 screen
->surface_unmap(screen
, ps
);