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_surface
*ps
,
49 uint x
, uint y
, uint w
, uint h
,
50 void *dst
, int dst_stride
)
54 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
58 dst_stride
= pf_get_nblocksx(&ps
->block
, w
) * ps
->block
.size
;
60 src
= pipe_surface_map(ps
, PIPE_BUFFER_USAGE_CPU_READ
);
65 pipe_copy_rect(dst
, &ps
->block
, dst_stride
, 0, 0, w
, h
, src
, ps
->stride
, x
, y
);
67 pipe_surface_unmap(ps
);
72 * Move raw block of pixels from user memory to surface.
73 * This should be usable by any hw driver that has mappable surfaces.
76 pipe_put_tile_raw(struct pipe_surface
*ps
,
77 uint x
, uint y
, uint w
, uint h
,
78 const void *src
, int src_stride
)
82 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
86 src_stride
= pf_get_nblocksx(&ps
->block
, w
) * ps
->block
.size
;
88 dst
= pipe_surface_map(ps
, PIPE_BUFFER_USAGE_CPU_WRITE
);
93 pipe_copy_rect(dst
, &ps
->block
, ps
->stride
, x
, y
, w
, h
, src
, src_stride
, 0, 0);
95 pipe_surface_unmap(ps
);
101 /** Convert short in [-32768,32767] to GLfloat in [-1.0,1.0] */
102 #define SHORT_TO_FLOAT(S) ((2.0F * (S) + 1.0F) * (1.0F/65535.0F))
104 #define UNCLAMPED_FLOAT_TO_SHORT(us, f) \
105 us = ( (short) ( CLAMP((f), -1.0, 1.0) * 32767.0F) )
109 /*** PIPE_FORMAT_A8R8G8B8_UNORM ***/
112 a8r8g8b8_get_tile_rgba(unsigned *src
,
113 unsigned w
, unsigned h
,
119 for (i
= 0; i
< h
; i
++) {
121 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
122 const unsigned pixel
= *src
++;
123 pRow
[0] = UBYTE_TO_FLOAT((pixel
>> 16) & 0xff);
124 pRow
[1] = UBYTE_TO_FLOAT((pixel
>> 8) & 0xff);
125 pRow
[2] = UBYTE_TO_FLOAT((pixel
>> 0) & 0xff);
126 pRow
[3] = UBYTE_TO_FLOAT((pixel
>> 24) & 0xff);
134 a8r8g8b8_put_tile_rgba(unsigned *dst
,
135 unsigned w
, unsigned h
,
141 for (i
= 0; i
< h
; i
++) {
142 const float *pRow
= p
;
143 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
145 UNCLAMPED_FLOAT_TO_UBYTE(r
, pRow
[0]);
146 UNCLAMPED_FLOAT_TO_UBYTE(g
, pRow
[1]);
147 UNCLAMPED_FLOAT_TO_UBYTE(b
, pRow
[2]);
148 UNCLAMPED_FLOAT_TO_UBYTE(a
, pRow
[3]);
149 *dst
++ = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
156 /*** PIPE_FORMAT_A8R8G8B8_UNORM ***/
159 x8r8g8b8_get_tile_rgba(unsigned *src
,
160 unsigned w
, unsigned h
,
166 for (i
= 0; i
< h
; i
++) {
168 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
169 const unsigned pixel
= *src
++;
170 pRow
[0] = UBYTE_TO_FLOAT((pixel
>> 16) & 0xff);
171 pRow
[1] = UBYTE_TO_FLOAT((pixel
>> 8) & 0xff);
172 pRow
[2] = UBYTE_TO_FLOAT((pixel
>> 0) & 0xff);
173 pRow
[3] = UBYTE_TO_FLOAT(0xff);
181 x8r8g8b8_put_tile_rgba(unsigned *dst
,
182 unsigned w
, unsigned h
,
188 for (i
= 0; i
< h
; i
++) {
189 const float *pRow
= p
;
190 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
192 UNCLAMPED_FLOAT_TO_UBYTE(r
, pRow
[0]);
193 UNCLAMPED_FLOAT_TO_UBYTE(g
, pRow
[1]);
194 UNCLAMPED_FLOAT_TO_UBYTE(b
, pRow
[2]);
195 *dst
++ = (0xff << 24) | (r
<< 16) | (g
<< 8) | b
;
202 /*** PIPE_FORMAT_B8G8R8A8_UNORM ***/
205 b8g8r8a8_get_tile_rgba(unsigned *src
,
206 unsigned w
, unsigned h
,
212 for (i
= 0; i
< h
; i
++) {
214 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
215 const unsigned pixel
= *src
++;
216 pRow
[0] = UBYTE_TO_FLOAT((pixel
>> 8) & 0xff);
217 pRow
[1] = UBYTE_TO_FLOAT((pixel
>> 16) & 0xff);
218 pRow
[2] = UBYTE_TO_FLOAT((pixel
>> 24) & 0xff);
219 pRow
[3] = UBYTE_TO_FLOAT((pixel
>> 0) & 0xff);
227 b8g8r8a8_put_tile_rgba(unsigned *dst
,
228 unsigned w
, unsigned h
,
234 for (i
= 0; i
< h
; i
++) {
235 const float *pRow
= p
;
236 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
238 UNCLAMPED_FLOAT_TO_UBYTE(r
, pRow
[0]);
239 UNCLAMPED_FLOAT_TO_UBYTE(g
, pRow
[1]);
240 UNCLAMPED_FLOAT_TO_UBYTE(b
, pRow
[2]);
241 UNCLAMPED_FLOAT_TO_UBYTE(a
, pRow
[3]);
242 *dst
++ = (b
<< 24) | (g
<< 16) | (r
<< 8) | a
;
249 /*** PIPE_FORMAT_A1R5G5B5_UNORM ***/
252 a1r5g5b5_get_tile_rgba(ushort
*src
,
253 unsigned w
, unsigned h
,
259 for (i
= 0; i
< h
; i
++) {
261 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
262 const ushort pixel
= *src
++;
263 pRow
[0] = ((pixel
>> 10) & 0x1f) * (1.0f
/ 31.0f
);
264 pRow
[1] = ((pixel
>> 5) & 0x1f) * (1.0f
/ 31.0f
);
265 pRow
[2] = ((pixel
) & 0x1f) * (1.0f
/ 31.0f
);
266 pRow
[3] = ((pixel
>> 15) ) * 1.0f
;
273 /*** PIPE_FORMAT_A4R4G4B4_UNORM ***/
276 a4r4g4b4_get_tile_rgba(ushort
*src
,
277 unsigned w
, unsigned h
,
283 for (i
= 0; i
< h
; i
++) {
285 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
286 const ushort pixel
= *src
++;
287 pRow
[0] = ((pixel
>> 8) & 0xf) * (1.0f
/ 15.0f
);
288 pRow
[1] = ((pixel
>> 4) & 0xf) * (1.0f
/ 15.0f
);
289 pRow
[2] = ((pixel
) & 0xf) * (1.0f
/ 15.0f
);
290 pRow
[3] = ((pixel
>> 12) ) * (1.0f
/ 15.0f
);
298 a4r4g4b4_put_tile_rgba(ushort
*dst
,
299 unsigned w
, unsigned h
,
305 for (i
= 0; i
< h
; i
++) {
306 const float *pRow
= p
;
307 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
309 UNCLAMPED_FLOAT_TO_UBYTE(r
, pRow
[0]);
310 UNCLAMPED_FLOAT_TO_UBYTE(g
, pRow
[1]);
311 UNCLAMPED_FLOAT_TO_UBYTE(b
, pRow
[2]);
312 UNCLAMPED_FLOAT_TO_UBYTE(a
, pRow
[3]);
317 *dst
++ = (a
<< 12) | (r
<< 16) | (g
<< 4) | b
;
324 /*** PIPE_FORMAT_R5G6B5_UNORM ***/
327 r5g6b5_get_tile_rgba(ushort
*src
,
328 unsigned w
, unsigned h
,
334 for (i
= 0; i
< h
; i
++) {
336 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
337 const ushort pixel
= *src
++;
338 pRow
[0] = ((pixel
>> 11) & 0x1f) * (1.0f
/ 31.0f
);
339 pRow
[1] = ((pixel
>> 5) & 0x3f) * (1.0f
/ 63.0f
);
340 pRow
[2] = ((pixel
) & 0x1f) * (1.0f
/ 31.0f
);
349 r5g5b5_put_tile_rgba(ushort
*dst
,
350 unsigned w
, unsigned h
,
356 for (i
= 0; i
< h
; i
++) {
357 const float *pRow
= p
;
358 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
359 uint r
= (uint
) (CLAMP(pRow
[0], 0.0, 1.0) * 31.0);
360 uint g
= (uint
) (CLAMP(pRow
[1], 0.0, 1.0) * 63.0);
361 uint b
= (uint
) (CLAMP(pRow
[2], 0.0, 1.0) * 31.0);
362 *dst
++ = (r
<< 11) | (g
<< 5) | (b
);
370 /*** PIPE_FORMAT_Z16_UNORM ***/
373 * Return each Z value as four floats in [0,1].
376 z16_get_tile_rgba(ushort
*src
,
377 unsigned w
, unsigned h
,
381 const float scale
= 1.0f
/ 65535.0f
;
384 for (i
= 0; i
< h
; i
++) {
386 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
390 pRow
[3] = *src
++ * scale
;
399 /*** PIPE_FORMAT_L8_UNORM ***/
402 l8_get_tile_rgba(ubyte
*src
,
403 unsigned w
, unsigned h
,
409 for (i
= 0; i
< h
; i
++) {
411 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
414 pRow
[2] = UBYTE_TO_FLOAT(*src
);
422 /*** PIPE_FORMAT_A8_UNORM ***/
425 a8_get_tile_rgba(ubyte
*src
,
426 unsigned w
, unsigned h
,
432 for (i
= 0; i
< h
; i
++) {
434 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
438 pRow
[3] = UBYTE_TO_FLOAT(*src
);
445 /*** PIPE_FORMAT_R16G16B16A16_SNORM ***/
448 r16g16b16a16_get_tile_rgba(short *src
,
449 unsigned w
, unsigned h
,
455 for (i
= 0; i
< h
; i
++) {
457 for (j
= 0; j
< w
; j
++, src
+= 4, pRow
+= 4) {
458 pRow
[0] = SHORT_TO_FLOAT(src
[0]);
459 pRow
[1] = SHORT_TO_FLOAT(src
[1]);
460 pRow
[2] = SHORT_TO_FLOAT(src
[2]);
461 pRow
[3] = SHORT_TO_FLOAT(src
[3]);
469 r16g16b16a16_put_tile_rgba(short *dst
,
470 unsigned w
, unsigned h
,
476 for (i
= 0; i
< h
; i
++) {
477 const float *pRow
= p
;
478 for (j
= 0; j
< w
; j
++, dst
+= 4, pRow
+= 4) {
479 UNCLAMPED_FLOAT_TO_SHORT(dst
[0], pRow
[0]);
480 UNCLAMPED_FLOAT_TO_SHORT(dst
[1], pRow
[1]);
481 UNCLAMPED_FLOAT_TO_SHORT(dst
[2], pRow
[2]);
482 UNCLAMPED_FLOAT_TO_SHORT(dst
[3], pRow
[3]);
490 /*** PIPE_FORMAT_I8_UNORM ***/
493 i8_get_tile_rgba(ubyte
*src
,
494 unsigned w
, unsigned h
,
500 for (i
= 0; i
< h
; i
++) {
502 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
506 pRow
[3] = UBYTE_TO_FLOAT(*src
);
513 /*** PIPE_FORMAT_A8L8_UNORM ***/
516 a8_l8_get_tile_rgba(ushort
*src
,
517 unsigned w
, unsigned h
,
523 for (i
= 0; i
< h
; i
++) {
525 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
529 pRow
[2] = UBYTE_TO_FLOAT(p
& 0xff);
530 pRow
[3] = UBYTE_TO_FLOAT(p
>> 8);
539 /*** PIPE_FORMAT_Z32_UNORM ***/
542 * Return each Z value as four floats in [0,1].
545 z32_get_tile_rgba(unsigned *src
,
546 unsigned w
, unsigned h
,
550 const double scale
= 1.0 / (double) 0xffffffff;
553 for (i
= 0; i
< h
; i
++) {
555 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
559 pRow
[3] = (float) (*src
++ * scale
);
566 /*** PIPE_FORMAT_S8Z24_UNORM ***/
569 * Return Z component as four float in [0,1]. Stencil part ignored.
572 s8z24_get_tile_rgba(unsigned *src
,
573 unsigned w
, unsigned h
,
577 const double scale
= 1.0 / ((1 << 24) - 1);
580 for (i
= 0; i
< h
; i
++) {
582 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
586 pRow
[3] = (float) (scale
* (*src
++ & 0xffffff));
593 /*** PIPE_FORMAT_Z24S8_UNORM ***/
596 * Return Z component as four float in [0,1]. Stencil part ignored.
599 z24s8_get_tile_rgba(unsigned *src
,
600 unsigned w
, unsigned h
,
604 const double scale
= 1.0 / ((1 << 24) - 1);
607 for (i
= 0; i
< h
; i
++) {
609 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
613 pRow
[3] = (float) (scale
* (*src
++ >> 8));
620 /*** PIPE_FORMAT_YCBCR / PIPE_FORMAT_YCBCR_REV ***/
623 * Convert YCbCr (or YCrCb) to RGBA.
626 ycbcr_get_tile_rgba(ushort
*src
,
627 unsigned w
, unsigned h
,
632 const float scale
= 1.0f
/ 255.0f
;
635 /* we're assuming we're being asked for an even number of texels */
636 assert((w
& 1) == 0);
638 for (i
= 0; i
< h
; i
++) {
640 /* do two texels at a time */
641 for (j
= 0; j
< w
; j
+= 2, src
+= 2) {
642 const ushort t0
= src
[0];
643 const ushort t1
= src
[1];
644 const ubyte y0
= (t0
>> 8) & 0xff; /* luminance */
645 const ubyte y1
= (t1
>> 8) & 0xff; /* luminance */
650 cb
= t1
& 0xff; /* chroma U */
651 cr
= t0
& 0xff; /* chroma V */
654 cb
= t0
& 0xff; /* chroma U */
655 cr
= t1
& 0xff; /* chroma V */
658 /* even pixel: y0,cr,cb */
659 r
= 1.164f
* (y0
-16) + 1.596f
* (cr
-128);
660 g
= 1.164f
* (y0
-16) - 0.813f
* (cr
-128) - 0.391f
* (cb
-128);
661 b
= 1.164f
* (y0
-16) + 2.018f
* (cb
-128);
668 /* odd pixel: use y1,cr,cb */
669 r
= 1.164f
* (y1
-16) + 1.596f
* (cr
-128);
670 g
= 1.164f
* (y1
-16) - 0.813f
* (cr
-128) - 0.391f
* (cb
-128);
671 b
= 1.164f
* (y1
-16) + 2.018f
* (cb
-128);
685 pipe_get_tile_rgba(struct pipe_surface
*ps
,
686 uint x
, uint y
, uint w
, uint h
,
689 unsigned dst_stride
= w
* 4;
692 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
695 packed
= MALLOC(pf_get_nblocks(&ps
->block
, w
, h
) * ps
->block
.size
);
700 pipe_get_tile_raw(ps
, x
, y
, w
, h
, packed
, 0);
702 switch (ps
->format
) {
703 case PIPE_FORMAT_A8R8G8B8_UNORM
:
704 a8r8g8b8_get_tile_rgba((unsigned *) packed
, w
, h
, p
, dst_stride
);
706 case PIPE_FORMAT_X8R8G8B8_UNORM
:
707 x8r8g8b8_get_tile_rgba((unsigned *) packed
, w
, h
, p
, dst_stride
);
709 case PIPE_FORMAT_B8G8R8A8_UNORM
:
710 b8g8r8a8_get_tile_rgba((unsigned *) packed
, w
, h
, p
, dst_stride
);
712 case PIPE_FORMAT_A1R5G5B5_UNORM
:
713 a1r5g5b5_get_tile_rgba((ushort
*) packed
, w
, h
, p
, dst_stride
);
715 case PIPE_FORMAT_A4R4G4B4_UNORM
:
716 a4r4g4b4_get_tile_rgba((ushort
*) packed
, w
, h
, p
, dst_stride
);
718 case PIPE_FORMAT_R5G6B5_UNORM
:
719 r5g6b5_get_tile_rgba((ushort
*) packed
, w
, h
, p
, dst_stride
);
721 case PIPE_FORMAT_L8_UNORM
:
722 l8_get_tile_rgba((ubyte
*) packed
, w
, h
, p
, dst_stride
);
724 case PIPE_FORMAT_A8_UNORM
:
725 a8_get_tile_rgba((ubyte
*) packed
, w
, h
, p
, dst_stride
);
727 case PIPE_FORMAT_I8_UNORM
:
728 i8_get_tile_rgba((ubyte
*) packed
, w
, h
, p
, dst_stride
);
730 case PIPE_FORMAT_A8L8_UNORM
:
731 a8_l8_get_tile_rgba((ushort
*) packed
, w
, h
, p
, dst_stride
);
733 case PIPE_FORMAT_R16G16B16A16_SNORM
:
734 r16g16b16a16_get_tile_rgba((short *) packed
, w
, h
, p
, dst_stride
);
736 case PIPE_FORMAT_Z16_UNORM
:
737 z16_get_tile_rgba((ushort
*) packed
, w
, h
, p
, dst_stride
);
739 case PIPE_FORMAT_Z32_UNORM
:
740 z32_get_tile_rgba((unsigned *) packed
, w
, h
, p
, dst_stride
);
742 case PIPE_FORMAT_S8Z24_UNORM
:
743 case PIPE_FORMAT_X8Z24_UNORM
:
744 s8z24_get_tile_rgba((unsigned *) packed
, w
, h
, p
, dst_stride
);
746 case PIPE_FORMAT_Z24S8_UNORM
:
747 z24s8_get_tile_rgba((unsigned *) packed
, w
, h
, p
, dst_stride
);
749 case PIPE_FORMAT_YCBCR
:
750 assert((x
& 1) == 0);
751 ycbcr_get_tile_rgba((ushort
*) packed
, w
, h
, p
, dst_stride
, FALSE
);
753 case PIPE_FORMAT_YCBCR_REV
:
754 assert((x
& 1) == 0);
755 ycbcr_get_tile_rgba((ushort
*) packed
, w
, h
, p
, dst_stride
, TRUE
);
766 pipe_put_tile_rgba(struct pipe_surface
*ps
,
767 uint x
, uint y
, uint w
, uint h
,
770 unsigned src_stride
= w
* 4;
773 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
776 packed
= MALLOC(pf_get_nblocks(&ps
->block
, w
, h
) * ps
->block
.size
);
781 switch (ps
->format
) {
782 case PIPE_FORMAT_A8R8G8B8_UNORM
:
783 a8r8g8b8_put_tile_rgba((unsigned *) packed
, w
, h
, p
, src_stride
);
785 case PIPE_FORMAT_X8R8G8B8_UNORM
:
786 x8r8g8b8_put_tile_rgba((unsigned *) packed
, w
, h
, p
, src_stride
);
788 case PIPE_FORMAT_B8G8R8A8_UNORM
:
789 b8g8r8a8_put_tile_rgba((unsigned *) packed
, w
, h
, p
, src_stride
);
791 case PIPE_FORMAT_A1R5G5B5_UNORM
:
792 /*a1r5g5b5_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
794 case PIPE_FORMAT_R5G6B5_UNORM
:
795 r5g5b5_put_tile_rgba((ushort
*) packed
, w
, h
, p
, src_stride
);
797 case PIPE_FORMAT_R8G8B8A8_UNORM
:
800 case PIPE_FORMAT_A4R4G4B4_UNORM
:
801 a4r4g4b4_put_tile_rgba((ushort
*) packed
, w
, h
, p
, src_stride
);
803 case PIPE_FORMAT_L8_UNORM
:
804 /*l8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride);*/
806 case PIPE_FORMAT_A8_UNORM
:
807 /*a8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride);*/
809 case PIPE_FORMAT_I8_UNORM
:
810 /*i8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride);*/
812 case PIPE_FORMAT_A8L8_UNORM
:
813 /*a8_l8_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
815 case PIPE_FORMAT_R16G16B16A16_SNORM
:
816 r16g16b16a16_put_tile_rgba((short *) packed
, w
, h
, p
, src_stride
);
818 case PIPE_FORMAT_Z16_UNORM
:
819 /*z16_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
821 case PIPE_FORMAT_Z32_UNORM
:
822 /*z32_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
824 case PIPE_FORMAT_S8Z24_UNORM
:
825 case PIPE_FORMAT_X8Z24_UNORM
:
826 /*s8z24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
828 case PIPE_FORMAT_Z24S8_UNORM
:
829 /*z24s8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
835 pipe_put_tile_raw(ps
, x
, y
, w
, h
, packed
, 0);
842 * Get a block of Z values, converted to 32-bit range.
845 pipe_get_tile_z(struct pipe_surface
*ps
,
846 uint x
, uint y
, uint w
, uint h
,
849 const uint dstStride
= w
;
854 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
857 map
= (ubyte
*)pipe_surface_map(ps
, PIPE_BUFFER_USAGE_CPU_READ
);
863 switch (ps
->format
) {
864 case PIPE_FORMAT_Z32_UNORM
:
867 = (const uint
*)(map
+ y
* ps
->stride
+ x
*4);
868 for (i
= 0; i
< h
; i
++) {
869 memcpy(pDest
, pSrc
, 4 * w
);
871 pSrc
+= ps
->stride
/4;
875 case PIPE_FORMAT_S8Z24_UNORM
:
876 case PIPE_FORMAT_X8Z24_UNORM
:
879 = (const uint
*)(map
+ y
* ps
->stride
+ x
*4);
880 for (i
= 0; i
< h
; i
++) {
881 for (j
= 0; j
< w
; j
++) {
882 /* convert 24-bit Z to 32-bit Z */
883 pDest
[j
] = (pSrc
[j
] << 8) | (pSrc
[j
] & 0xff);
886 pSrc
+= ps
->stride
/4;
890 case PIPE_FORMAT_Z16_UNORM
:
893 = (const ushort
*)(map
+ y
* ps
->stride
+ x
*2);
894 for (i
= 0; i
< h
; i
++) {
895 for (j
= 0; j
< w
; j
++) {
896 /* convert 16-bit Z to 32-bit Z */
897 pDest
[j
] = (pSrc
[j
] << 16) | pSrc
[j
];
900 pSrc
+= ps
->stride
/2;
908 pipe_surface_unmap(ps
);
913 pipe_put_tile_z(struct pipe_surface
*ps
,
914 uint x
, uint y
, uint w
, uint h
,
917 const uint srcStride
= w
;
918 const uint
*pSrc
= zSrc
;
922 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
925 map
= (ubyte
*)pipe_surface_map(ps
, PIPE_BUFFER_USAGE_CPU_WRITE
);
931 switch (ps
->format
) {
932 case PIPE_FORMAT_Z32_UNORM
:
934 uint
*pDest
= (uint
*) (map
+ y
* ps
->stride
+ x
*4);
935 for (i
= 0; i
< h
; i
++) {
936 memcpy(pDest
, pSrc
, 4 * w
);
937 pDest
+= ps
->stride
/4;
942 case PIPE_FORMAT_S8Z24_UNORM
:
943 case PIPE_FORMAT_X8Z24_UNORM
:
945 uint
*pDest
= (uint
*) (map
+ y
* ps
->stride
+ x
*4);
946 for (i
= 0; i
< h
; i
++) {
947 for (j
= 0; j
< w
; j
++) {
948 /* convert 32-bit Z to 24-bit Z (0 stencil) */
949 pDest
[j
] = pSrc
[j
] >> 8;
951 pDest
+= ps
->stride
/4;
956 case PIPE_FORMAT_Z16_UNORM
:
958 ushort
*pDest
= (ushort
*) (map
+ y
* ps
->stride
+ x
*2);
959 for (i
= 0; i
< h
; i
++) {
960 for (j
= 0; j
< w
; j
++) {
961 /* convert 32-bit Z to 16-bit Z */
962 pDest
[j
] = pSrc
[j
] >> 16;
964 pDest
+= ps
->stride
/2;
973 pipe_surface_unmap(ps
);