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 *p
, int dst_stride
)
53 struct pipe_screen
*screen
= pipe
->screen
;
54 const uint cpp
= ps
->cpp
;
56 const uint src_stride
= ps
->pitch
* cpp
;
60 if (dst_stride
== 0) {
64 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
67 pSrc
= (const ubyte
*) screen
->surface_map(screen
, ps
,
68 PIPE_BUFFER_USAGE_CPU_READ
);
69 assert(pSrc
); /* XXX: proper error handling! */
71 pSrc
+= (y
* ps
->pitch
+ x
) * cpp
;
74 for (i
= 0; i
< h
; i
++) {
75 memcpy(pDest
, pSrc
, w
* cpp
);
80 screen
->surface_unmap(screen
, ps
);
85 * Move raw block of pixels from user memory to surface.
86 * This should be usable by any hw driver that has mappable surfaces.
89 pipe_put_tile_raw(struct pipe_context
*pipe
,
90 struct pipe_surface
*ps
,
91 uint x
, uint y
, uint w
, uint h
,
92 const void *p
, int src_stride
)
94 struct pipe_screen
*screen
= pipe
->screen
;
95 const uint cpp
= ps
->cpp
;
97 const uint dst_stride
= ps
->pitch
* cpp
;
101 if (src_stride
== 0) {
102 src_stride
= w
* cpp
;
105 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
108 pSrc
= (const ubyte
*) p
;
110 pDest
= screen
->surface_map(screen
, ps
, PIPE_BUFFER_USAGE_CPU_WRITE
);
111 assert(pDest
); /* XXX: proper error handling */
113 pDest
+= (y
* ps
->pitch
+ x
) * cpp
;
115 for (i
= 0; i
< h
; i
++) {
116 memcpy(pDest
, pSrc
, w
* cpp
);
121 screen
->surface_unmap(screen
, ps
);
127 /** Convert short in [-32768,32767] to GLfloat in [-1.0,1.0] */
128 #define SHORT_TO_FLOAT(S) ((2.0F * (S) + 1.0F) * (1.0F/65535.0F))
130 #define UNCLAMPED_FLOAT_TO_SHORT(us, f) \
131 us = ( (short) ( CLAMP((f), -1.0, 1.0) * 32767.0F) )
135 /*** PIPE_FORMAT_A8R8G8B8_UNORM ***/
138 a8r8g8b8_get_tile_rgba(unsigned *src
,
139 unsigned w
, unsigned h
,
145 for (i
= 0; i
< h
; i
++) {
147 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
148 const unsigned pixel
= *src
++;
149 pRow
[0] = UBYTE_TO_FLOAT((pixel
>> 16) & 0xff);
150 pRow
[1] = UBYTE_TO_FLOAT((pixel
>> 8) & 0xff);
151 pRow
[2] = UBYTE_TO_FLOAT((pixel
>> 0) & 0xff);
152 pRow
[3] = UBYTE_TO_FLOAT((pixel
>> 24) & 0xff);
160 a8r8g8b8_put_tile_rgba(unsigned *dst
,
161 unsigned w
, unsigned h
,
167 for (i
= 0; i
< h
; i
++) {
168 const float *pRow
= p
;
169 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
171 UNCLAMPED_FLOAT_TO_UBYTE(r
, pRow
[0]);
172 UNCLAMPED_FLOAT_TO_UBYTE(g
, pRow
[1]);
173 UNCLAMPED_FLOAT_TO_UBYTE(b
, pRow
[2]);
174 UNCLAMPED_FLOAT_TO_UBYTE(a
, pRow
[3]);
175 *dst
++ = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
182 /*** PIPE_FORMAT_A8R8G8B8_UNORM ***/
185 x8r8g8b8_get_tile_rgba(unsigned *src
,
186 unsigned w
, unsigned h
,
192 for (i
= 0; i
< h
; i
++) {
194 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
195 const unsigned pixel
= *src
++;
196 pRow
[0] = UBYTE_TO_FLOAT((pixel
>> 16) & 0xff);
197 pRow
[1] = UBYTE_TO_FLOAT((pixel
>> 8) & 0xff);
198 pRow
[2] = UBYTE_TO_FLOAT((pixel
>> 0) & 0xff);
199 pRow
[3] = UBYTE_TO_FLOAT(0xff);
207 x8r8g8b8_put_tile_rgba(unsigned *dst
,
208 unsigned w
, unsigned h
,
214 for (i
= 0; i
< h
; i
++) {
215 const float *pRow
= p
;
216 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
218 UNCLAMPED_FLOAT_TO_UBYTE(r
, pRow
[0]);
219 UNCLAMPED_FLOAT_TO_UBYTE(g
, pRow
[1]);
220 UNCLAMPED_FLOAT_TO_UBYTE(b
, pRow
[2]);
221 *dst
++ = (0xff << 24) | (r
<< 16) | (g
<< 8) | b
;
228 /*** PIPE_FORMAT_B8G8R8A8_UNORM ***/
231 b8g8r8a8_get_tile_rgba(unsigned *src
,
232 unsigned w
, unsigned h
,
238 for (i
= 0; i
< h
; i
++) {
240 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
241 const unsigned pixel
= *src
++;
242 pRow
[0] = UBYTE_TO_FLOAT((pixel
>> 8) & 0xff);
243 pRow
[1] = UBYTE_TO_FLOAT((pixel
>> 16) & 0xff);
244 pRow
[2] = UBYTE_TO_FLOAT((pixel
>> 24) & 0xff);
245 pRow
[3] = UBYTE_TO_FLOAT((pixel
>> 0) & 0xff);
253 b8g8r8a8_put_tile_rgba(unsigned *dst
,
254 unsigned w
, unsigned h
,
260 for (i
= 0; i
< h
; i
++) {
261 const float *pRow
= p
;
262 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
264 UNCLAMPED_FLOAT_TO_UBYTE(r
, pRow
[0]);
265 UNCLAMPED_FLOAT_TO_UBYTE(g
, pRow
[1]);
266 UNCLAMPED_FLOAT_TO_UBYTE(b
, pRow
[2]);
267 UNCLAMPED_FLOAT_TO_UBYTE(a
, pRow
[3]);
268 *dst
++ = (b
<< 24) | (g
<< 16) | (r
<< 8) | a
;
275 /*** PIPE_FORMAT_A1R5G5B5_UNORM ***/
278 a1r5g5b5_get_tile_rgba(ushort
*src
,
279 unsigned w
, unsigned h
,
285 for (i
= 0; i
< h
; i
++) {
287 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
288 const ushort pixel
= *src
++;
289 pRow
[0] = ((pixel
>> 10) & 0x1f) * (1.0f
/ 31.0f
);
290 pRow
[1] = ((pixel
>> 5) & 0x1f) * (1.0f
/ 31.0f
);
291 pRow
[2] = ((pixel
) & 0x1f) * (1.0f
/ 31.0f
);
292 pRow
[3] = ((pixel
>> 15) ) * 1.0f
;
299 /*** PIPE_FORMAT_A4R4G4B4_UNORM ***/
302 a4r4g4b4_get_tile_rgba(ushort
*src
,
303 unsigned w
, unsigned h
,
309 for (i
= 0; i
< h
; i
++) {
311 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
312 const ushort pixel
= *src
++;
313 pRow
[0] = ((pixel
>> 8) & 0xf) * (1.0f
/ 15.0f
);
314 pRow
[1] = ((pixel
>> 4) & 0xf) * (1.0f
/ 15.0f
);
315 pRow
[2] = ((pixel
) & 0xf) * (1.0f
/ 15.0f
);
316 pRow
[3] = ((pixel
>> 12) ) * (1.0f
/ 15.0f
);
323 /*** PIPE_FORMAT_R5G6B5_UNORM ***/
326 r5g6b5_get_tile_rgba(ushort
*src
,
327 unsigned w
, unsigned h
,
333 for (i
= 0; i
< h
; i
++) {
335 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
336 const ushort pixel
= *src
++;
337 pRow
[0] = ((pixel
>> 11) & 0x1f) * (1.0f
/ 31.0f
);
338 pRow
[1] = ((pixel
>> 5) & 0x3f) * (1.0f
/ 63.0f
);
339 pRow
[2] = ((pixel
) & 0x1f) * (1.0f
/ 31.0f
);
348 r5g5b5_put_tile_rgba(ushort
*dst
,
349 unsigned w
, unsigned h
,
355 for (i
= 0; i
< h
; i
++) {
356 const float *pRow
= p
;
357 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
358 uint r
= (uint
) (CLAMP(pRow
[0], 0.0, 1.0) * 31.0);
359 uint g
= (uint
) (CLAMP(pRow
[1], 0.0, 1.0) * 63.0);
360 uint b
= (uint
) (CLAMP(pRow
[2], 0.0, 1.0) * 31.0);
361 *dst
++ = (r
<< 11) | (g
<< 5) | (b
);
369 /*** PIPE_FORMAT_Z16_UNORM ***/
372 * Return each Z value as four floats in [0,1].
375 z16_get_tile_rgba(ushort
*src
,
376 unsigned w
, unsigned h
,
380 const float scale
= 1.0f
/ 65535.0f
;
383 for (i
= 0; i
< h
; i
++) {
385 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
389 pRow
[3] = *src
++ * scale
;
398 /*** PIPE_FORMAT_L8_UNORM ***/
401 l8_get_tile_rgba(ubyte
*src
,
402 unsigned w
, unsigned h
,
408 for (i
= 0; i
< h
; i
++) {
410 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
413 pRow
[2] = UBYTE_TO_FLOAT(*src
);
421 /*** PIPE_FORMAT_A8_UNORM ***/
424 a8_get_tile_rgba(ubyte
*src
,
425 unsigned w
, unsigned h
,
431 for (i
= 0; i
< h
; i
++) {
433 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
437 pRow
[3] = UBYTE_TO_FLOAT(*src
);
444 /*** PIPE_FORMAT_R16G16B16A16_SNORM ***/
447 r16g16b16a16_get_tile_rgba(short *src
,
448 unsigned w
, unsigned h
,
454 for (i
= 0; i
< h
; i
++) {
456 for (j
= 0; j
< w
; j
++, src
+= 4, pRow
+= 4) {
457 pRow
[0] = SHORT_TO_FLOAT(src
[0]);
458 pRow
[1] = SHORT_TO_FLOAT(src
[1]);
459 pRow
[2] = SHORT_TO_FLOAT(src
[2]);
460 pRow
[3] = SHORT_TO_FLOAT(src
[3]);
468 r16g16b16a16_put_tile_rgba(short *dst
,
469 unsigned w
, unsigned h
,
475 for (i
= 0; i
< h
; i
++) {
476 const float *pRow
= p
;
477 for (j
= 0; j
< w
; j
++, dst
+= 4, pRow
+= 4) {
478 UNCLAMPED_FLOAT_TO_SHORT(dst
[0], pRow
[0]);
479 UNCLAMPED_FLOAT_TO_SHORT(dst
[1], pRow
[1]);
480 UNCLAMPED_FLOAT_TO_SHORT(dst
[2], pRow
[2]);
481 UNCLAMPED_FLOAT_TO_SHORT(dst
[3], pRow
[3]);
489 /*** PIPE_FORMAT_I8_UNORM ***/
492 i8_get_tile_rgba(ubyte
*src
,
493 unsigned w
, unsigned h
,
499 for (i
= 0; i
< h
; i
++) {
501 for (j
= 0; j
< w
; j
++, src
++, pRow
+= 4) {
505 pRow
[3] = UBYTE_TO_FLOAT(*src
);
512 /*** PIPE_FORMAT_A8L8_UNORM ***/
515 a8_l8_get_tile_rgba(ushort
*src
,
516 unsigned w
, unsigned h
,
522 for (i
= 0; i
< h
; i
++) {
524 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
528 pRow
[2] = UBYTE_TO_FLOAT(p
& 0xff);
529 pRow
[3] = UBYTE_TO_FLOAT(p
>> 8);
538 /*** PIPE_FORMAT_Z32_UNORM ***/
541 * Return each Z value as four floats in [0,1].
544 z32_get_tile_rgba(unsigned *src
,
545 unsigned w
, unsigned h
,
549 const double scale
= 1.0 / (double) 0xffffffff;
552 for (i
= 0; i
< h
; i
++) {
554 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
558 pRow
[3] = (float) (*src
++ * scale
);
565 /*** PIPE_FORMAT_S8Z24_UNORM ***/
568 * Return Z component as four float in [0,1]. Stencil part ignored.
571 s8z24_get_tile_rgba(unsigned *src
,
572 unsigned w
, unsigned h
,
576 const double scale
= 1.0 / ((1 << 24) - 1);
579 for (i
= 0; i
< h
; i
++) {
581 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
585 pRow
[3] = (float) (scale
* (*src
++ & 0xffffff));
592 /*** PIPE_FORMAT_Z24S8_UNORM ***/
595 * Return Z component as four float in [0,1]. Stencil part ignored.
598 z24s8_get_tile_rgba(unsigned *src
,
599 unsigned w
, unsigned h
,
603 const double scale
= 1.0 / ((1 << 24) - 1);
606 for (i
= 0; i
< h
; i
++) {
608 for (j
= 0; j
< w
; j
++, pRow
+= 4) {
612 pRow
[3] = (float) (scale
* (*src
++ >> 8));
619 /*** PIPE_FORMAT_YCBCR / PIPE_FORMAT_YCBCR_REV ***/
622 * Convert YCbCr (or YCrCb) to RGBA.
625 ycbcr_get_tile_rgba(ushort
*src
,
626 unsigned w
, unsigned h
,
631 const float scale
= 1.0f
/ 255.0f
;
634 /* we're assuming we're being asked for an even number of texels */
635 assert((w
& 1) == 0);
637 for (i
= 0; i
< h
; i
++) {
639 /* do two texels at a time */
640 for (j
= 0; j
< w
; j
+= 2, src
+= 2) {
641 const ushort t0
= src
[0];
642 const ushort t1
= src
[1];
643 const ubyte y0
= (t0
>> 8) & 0xff; /* luminance */
644 const ubyte y1
= (t1
>> 8) & 0xff; /* luminance */
649 cb
= t1
& 0xff; /* chroma U */
650 cr
= t0
& 0xff; /* chroma V */
653 cb
= t0
& 0xff; /* chroma U */
654 cr
= t1
& 0xff; /* chroma V */
657 /* even pixel: y0,cr,cb */
658 r
= 1.164f
* (y0
-16) + 1.596f
* (cr
-128);
659 g
= 1.164f
* (y0
-16) - 0.813f
* (cr
-128) - 0.391f
* (cb
-128);
660 b
= 1.164f
* (y0
-16) + 2.018f
* (cb
-128);
667 /* odd pixel: use y1,cr,cb */
668 r
= 1.164f
* (y1
-16) + 1.596f
* (cr
-128);
669 g
= 1.164f
* (y1
-16) - 0.813f
* (cr
-128) - 0.391f
* (cb
-128);
670 b
= 1.164f
* (y1
-16) + 2.018f
* (cb
-128);
684 pipe_get_tile_rgba(struct pipe_context
*pipe
,
685 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(h
* w
* ps
->cpp
);
700 pipe_get_tile_raw(pipe
, ps
, x
, y
, w
, h
, packed
, w
* ps
->cpp
);
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_context
*pipe
,
767 struct pipe_surface
*ps
,
768 uint x
, uint y
, uint w
, uint h
,
771 unsigned src_stride
= w
* 4;
774 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
777 packed
= MALLOC(h
* w
* ps
->cpp
);
782 switch (ps
->format
) {
783 case PIPE_FORMAT_A8R8G8B8_UNORM
:
784 a8r8g8b8_put_tile_rgba((unsigned *) packed
, w
, h
, p
, src_stride
);
786 case PIPE_FORMAT_X8R8G8B8_UNORM
:
787 x8r8g8b8_put_tile_rgba((unsigned *) packed
, w
, h
, p
, src_stride
);
789 case PIPE_FORMAT_B8G8R8A8_UNORM
:
790 b8g8r8a8_put_tile_rgba((unsigned *) packed
, w
, h
, p
, src_stride
);
792 case PIPE_FORMAT_A1R5G5B5_UNORM
:
793 /*a1r5g5b5_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
795 case PIPE_FORMAT_R5G6B5_UNORM
:
796 r5g5b5_put_tile_rgba((ushort
*) packed
, w
, h
, p
, src_stride
);
798 case PIPE_FORMAT_R8G8B8A8_UNORM
:
800 case PIPE_FORMAT_L8_UNORM
:
801 /*l8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride);*/
803 case PIPE_FORMAT_A8_UNORM
:
804 /*a8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride);*/
806 case PIPE_FORMAT_I8_UNORM
:
807 /*i8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride);*/
809 case PIPE_FORMAT_A8L8_UNORM
:
810 /*a8_l8_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
812 case PIPE_FORMAT_R16G16B16A16_SNORM
:
813 r16g16b16a16_put_tile_rgba((short *) packed
, w
, h
, p
, src_stride
);
815 case PIPE_FORMAT_Z16_UNORM
:
816 /*z16_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
818 case PIPE_FORMAT_Z32_UNORM
:
819 /*z32_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
821 case PIPE_FORMAT_S8Z24_UNORM
:
822 case PIPE_FORMAT_X8Z24_UNORM
:
823 /*s8z24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
825 case PIPE_FORMAT_Z24S8_UNORM
:
826 /*z24s8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
832 pipe_put_tile_raw(pipe
, ps
, x
, y
, w
, h
, packed
, w
* ps
->cpp
);
839 * Get a block of Z values, converted to 32-bit range.
842 pipe_get_tile_z(struct pipe_context
*pipe
,
843 struct pipe_surface
*ps
,
844 uint x
, uint y
, uint w
, uint h
,
847 struct pipe_screen
*screen
= pipe
->screen
;
848 const uint dstStride
= w
;
853 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
856 map
= screen
->surface_map(screen
, ps
, PIPE_BUFFER_USAGE_CPU_READ
);
862 switch (ps
->format
) {
863 case PIPE_FORMAT_Z32_UNORM
:
866 = (const uint
*)map
+ (y
* ps
->pitch
+ x
);
867 for (i
= 0; i
< h
; i
++) {
868 memcpy(pDest
, pSrc
, 4 * w
);
874 case PIPE_FORMAT_S8Z24_UNORM
:
875 case PIPE_FORMAT_X8Z24_UNORM
:
878 = (const uint
*)map
+ (y
* ps
->pitch
+ x
);
879 for (i
= 0; i
< h
; i
++) {
880 for (j
= 0; j
< w
; j
++) {
881 /* convert 24-bit Z to 32-bit Z */
882 pDest
[j
] = (pSrc
[j
] << 8) | (pSrc
[j
] & 0xff);
889 case PIPE_FORMAT_Z16_UNORM
:
892 = (const ushort
*)map
+ (y
* ps
->pitch
+ x
);
893 for (i
= 0; i
< h
; i
++) {
894 for (j
= 0; j
< w
; j
++) {
895 /* convert 16-bit Z to 32-bit Z */
896 pDest
[j
] = (pSrc
[j
] << 16) | pSrc
[j
];
907 screen
->surface_unmap(screen
, ps
);
912 pipe_put_tile_z(struct pipe_context
*pipe
,
913 struct pipe_surface
*ps
,
914 uint x
, uint y
, uint w
, uint h
,
917 struct pipe_screen
*screen
= pipe
->screen
;
918 const uint srcStride
= w
;
919 const uint
*pSrc
= zSrc
;
923 if (pipe_clip_tile(x
, y
, &w
, &h
, ps
))
926 map
= screen
->surface_map(screen
, ps
, PIPE_BUFFER_USAGE_CPU_WRITE
);
932 switch (ps
->format
) {
933 case PIPE_FORMAT_Z32_UNORM
:
935 uint
*pDest
= (uint
*) map
+ (y
* ps
->pitch
+ x
);
936 for (i
= 0; i
< h
; i
++) {
937 memcpy(pDest
, pSrc
, 4 * w
);
943 case PIPE_FORMAT_S8Z24_UNORM
:
944 case PIPE_FORMAT_X8Z24_UNORM
:
946 uint
*pDest
= (uint
*) map
+ (y
* ps
->pitch
+ x
);
947 for (i
= 0; i
< h
; i
++) {
948 for (j
= 0; j
< w
; j
++) {
949 /* convert 32-bit Z to 24-bit Z (0 stencil) */
950 pDest
[j
] = pSrc
[j
] >> 8;
957 case PIPE_FORMAT_Z16_UNORM
:
959 ushort
*pDest
= (ushort
*) map
+ (y
* ps
->pitch
+ x
);
960 for (i
= 0; i
< h
; i
++) {
961 for (j
= 0; j
< w
; j
++) {
962 /* convert 32-bit Z to 16-bit Z */
963 pDest
[j
] = pSrc
[j
] >> 16;
974 screen
->surface_unmap(screen
, ps
);