aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/gallium/auxiliary/util
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-07-11 09:02:33 +0200
committermarha <marha@users.sourceforge.net>2011-07-11 09:02:33 +0200
commit4611d27b8966b26b8ac63514a461f31c3172c31c (patch)
tree5de36cfa4517b997cb703cb1eced374c9db1f2b1 /mesalib/src/gallium/auxiliary/util
parentdbe01a4f78f09723b327d1d8522bfa5026c4f6e0 (diff)
parent0b43e0b4ddbd9fdac70658164f3dbf653067a4de (diff)
downloadvcxsrv-4611d27b8966b26b8ac63514a461f31c3172c31c.tar.gz
vcxsrv-4611d27b8966b26b8ac63514a461f31c3172c31c.tar.bz2
vcxsrv-4611d27b8966b26b8ac63514a461f31c3172c31c.zip
Merge remote-tracking branch 'origin/released'
Conflicts: mesalib/docs/GL3.txt mesalib/src/glsl/linker.cpp mesalib/src/mesa/main/depthstencil.c mesalib/src/mesa/main/fbobject.c mesalib/src/mesa/main/formats.c mesalib/src/mesa/main/formats.h mesalib/src/mesa/main/framebuffer.c mesalib/src/mesa/main/mtypes.h mesalib/src/mesa/main/pack.c mesalib/src/mesa/main/readpix.c mesalib/src/mesa/main/renderbuffer.c mesalib/src/mesa/main/samplerobj.c mesalib/src/mesa/main/shaderapi.c mesalib/src/mesa/main/texenv.c mesalib/src/mesa/main/texobj.c mesalib/src/mesa/main/uniforms.c mesalib/src/mesa/state_tracker/st_cb_clear.c mesalib/src/mesa/state_tracker/st_cb_drawpixels.c mesalib/src/mesa/state_tracker/st_cb_readpixels.c mesalib/src/mesa/state_tracker/st_extensions.c mesalib/src/mesa/state_tracker/st_format.c mesalib/src/mesa/swrast/s_readpix.c
Diffstat (limited to 'mesalib/src/gallium/auxiliary/util')
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_pack_color.h1232
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_surface.c775
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_tile.c1345
3 files changed, 1742 insertions, 1610 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_pack_color.h b/mesalib/src/gallium/auxiliary/util/u_pack_color.h
index c51cc7bcb..9391f1b80 100644
--- a/mesalib/src/gallium/auxiliary/util/u_pack_color.h
+++ b/mesalib/src/gallium/auxiliary/util/u_pack_color.h
@@ -1,584 +1,648 @@
-/**************************************************************************
- *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-/**
- * @file
- * Functions to produce packed colors/Z from floats.
- */
-
-
-#ifndef U_PACK_COLOR_H
-#define U_PACK_COLOR_H
-
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_format.h"
-#include "util/u_debug.h"
-#include "util/u_format.h"
-#include "util/u_math.h"
-
-
-/**
- * Helper union for packing pixel values.
- * Will often contain values in formats which are too complex to be described
- * in simple terms, hence might just effectively contain a number of bytes.
- * Must be big enough to hold data for all formats (currently 256 bits).
- */
-union util_color {
- ubyte ub;
- ushort us;
- uint ui;
- float f[4];
- double d[4];
-};
-
-/**
- * Pack ubyte R,G,B,A into dest pixel.
- */
-static INLINE void
-util_pack_color_ub(ubyte r, ubyte g, ubyte b, ubyte a,
- enum pipe_format format, union util_color *uc)
-{
- switch (format) {
- case PIPE_FORMAT_A8B8G8R8_UNORM:
- {
- uc->ui = (r << 24) | (g << 16) | (b << 8) | a;
- }
- return;
- case PIPE_FORMAT_X8B8G8R8_UNORM:
- {
- uc->ui = (r << 24) | (g << 16) | (b << 8) | 0xff;
- }
- return;
- case PIPE_FORMAT_B8G8R8A8_UNORM:
- {
- uc->ui = (a << 24) | (r << 16) | (g << 8) | b;
- }
- return;
- case PIPE_FORMAT_B8G8R8X8_UNORM:
- {
- uc->ui = (0xff << 24) | (r << 16) | (g << 8) | b;
- }
- return;
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- {
- uc->ui = (b << 24) | (g << 16) | (r << 8) | a;
- }
- return;
- case PIPE_FORMAT_X8R8G8B8_UNORM:
- {
- uc->ui = (b << 24) | (g << 16) | (r << 8) | 0xff;
- }
- return;
- case PIPE_FORMAT_B5G6R5_UNORM:
- {
- uc->us = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3);
- }
- return;
- case PIPE_FORMAT_B5G5R5X1_UNORM:
- {
- uc->us = ((0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3);
- }
- return;
- case PIPE_FORMAT_B5G5R5A1_UNORM:
- {
- uc->us = ((a & 0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3);
- }
- return;
- case PIPE_FORMAT_B4G4R4A4_UNORM:
- {
- uc->us = ((a & 0xf0) << 8) | ((r & 0xf0) << 4) | ((g & 0xf0) << 0) | (b >> 4);
- }
- return;
- case PIPE_FORMAT_A8_UNORM:
- {
- uc->ub = a;
- }
- return;
- case PIPE_FORMAT_L8_UNORM:
- case PIPE_FORMAT_I8_UNORM:
- {
- uc->ub = a;
- }
- return;
- case PIPE_FORMAT_R32G32B32A32_FLOAT:
- {
- uc->f[0] = (float)r / 255.0f;
- uc->f[1] = (float)g / 255.0f;
- uc->f[2] = (float)b / 255.0f;
- uc->f[3] = (float)a / 255.0f;
- }
- return;
- case PIPE_FORMAT_R32G32B32_FLOAT:
- {
- uc->f[0] = (float)r / 255.0f;
- uc->f[1] = (float)g / 255.0f;
- uc->f[2] = (float)b / 255.0f;
- }
- return;
-
- /* Handle other cases with a generic function.
- */
- default:
- {
- ubyte src[4];
-
- src[0] = r;
- src[1] = g;
- src[2] = b;
- src[3] = a;
- util_format_write_4ub(format, src, 0, uc, 0, 0, 0, 1, 1);
- }
- }
-}
-
-
-/**
- * Unpack RGBA from a packed pixel, returning values as ubytes in [0,255].
- */
-static INLINE void
-util_unpack_color_ub(enum pipe_format format, union util_color *uc,
- ubyte *r, ubyte *g, ubyte *b, ubyte *a)
-{
- switch (format) {
- case PIPE_FORMAT_A8B8G8R8_UNORM:
- {
- uint p = uc->ui;
- *r = (ubyte) ((p >> 24) & 0xff);
- *g = (ubyte) ((p >> 16) & 0xff);
- *b = (ubyte) ((p >> 8) & 0xff);
- *a = (ubyte) ((p >> 0) & 0xff);
- }
- return;
- case PIPE_FORMAT_X8B8G8R8_UNORM:
- {
- uint p = uc->ui;
- *r = (ubyte) ((p >> 24) & 0xff);
- *g = (ubyte) ((p >> 16) & 0xff);
- *b = (ubyte) ((p >> 8) & 0xff);
- *a = (ubyte) 0xff;
- }
- return;
- case PIPE_FORMAT_B8G8R8A8_UNORM:
- {
- uint p = uc->ui;
- *r = (ubyte) ((p >> 16) & 0xff);
- *g = (ubyte) ((p >> 8) & 0xff);
- *b = (ubyte) ((p >> 0) & 0xff);
- *a = (ubyte) ((p >> 24) & 0xff);
- }
- return;
- case PIPE_FORMAT_B8G8R8X8_UNORM:
- {
- uint p = uc->ui;
- *r = (ubyte) ((p >> 16) & 0xff);
- *g = (ubyte) ((p >> 8) & 0xff);
- *b = (ubyte) ((p >> 0) & 0xff);
- *a = (ubyte) 0xff;
- }
- return;
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- {
- uint p = uc->ui;
- *r = (ubyte) ((p >> 8) & 0xff);
- *g = (ubyte) ((p >> 16) & 0xff);
- *b = (ubyte) ((p >> 24) & 0xff);
- *a = (ubyte) ((p >> 0) & 0xff);
- }
- return;
- case PIPE_FORMAT_X8R8G8B8_UNORM:
- {
- uint p = uc->ui;
- *r = (ubyte) ((p >> 8) & 0xff);
- *g = (ubyte) ((p >> 16) & 0xff);
- *b = (ubyte) ((p >> 24) & 0xff);
- *a = (ubyte) 0xff;
- }
- return;
- case PIPE_FORMAT_B5G6R5_UNORM:
- {
- ushort p = uc->us;
- *r = (ubyte) (((p >> 8) & 0xf8) | ((p >> 13) & 0x7));
- *g = (ubyte) (((p >> 3) & 0xfc) | ((p >> 9) & 0x3));
- *b = (ubyte) (((p << 3) & 0xf8) | ((p >> 2) & 0x7));
- *a = (ubyte) 0xff;
- }
- return;
- case PIPE_FORMAT_B5G5R5X1_UNORM:
- {
- ushort p = uc->us;
- *r = (ubyte) (((p >> 7) & 0xf8) | ((p >> 12) & 0x7));
- *g = (ubyte) (((p >> 2) & 0xf8) | ((p >> 7) & 0x7));
- *b = (ubyte) (((p << 3) & 0xf8) | ((p >> 2) & 0x7));
- *a = (ubyte) 0xff;
- }
- return;
- case PIPE_FORMAT_B5G5R5A1_UNORM:
- {
- ushort p = uc->us;
- *r = (ubyte) (((p >> 7) & 0xf8) | ((p >> 12) & 0x7));
- *g = (ubyte) (((p >> 2) & 0xf8) | ((p >> 7) & 0x7));
- *b = (ubyte) (((p << 3) & 0xf8) | ((p >> 2) & 0x7));
- *a = (ubyte) (0xff * (p >> 15));
- }
- return;
- case PIPE_FORMAT_B4G4R4A4_UNORM:
- {
- ushort p = uc->us;
- *r = (ubyte) (((p >> 4) & 0xf0) | ((p >> 8) & 0xf));
- *g = (ubyte) (((p >> 0) & 0xf0) | ((p >> 4) & 0xf));
- *b = (ubyte) (((p << 4) & 0xf0) | ((p >> 0) & 0xf));
- *a = (ubyte) (((p >> 8) & 0xf0) | ((p >> 12) & 0xf));
- }
- return;
- case PIPE_FORMAT_A8_UNORM:
- {
- ubyte p = uc->ub;
- *r = *g = *b = (ubyte) 0xff;
- *a = p;
- }
- return;
- case PIPE_FORMAT_L8_UNORM:
- {
- ubyte p = uc->ub;
- *r = *g = *b = p;
- *a = (ubyte) 0xff;
- }
- return;
- case PIPE_FORMAT_I8_UNORM:
- {
- ubyte p = uc->ub;
- *r = *g = *b = *a = p;
- }
- return;
- case PIPE_FORMAT_R32G32B32A32_FLOAT:
- {
- const float *p = &uc->f[0];
- *r = float_to_ubyte(p[0]);
- *g = float_to_ubyte(p[1]);
- *b = float_to_ubyte(p[2]);
- *a = float_to_ubyte(p[3]);
- }
- return;
- case PIPE_FORMAT_R32G32B32_FLOAT:
- {
- const float *p = &uc->f[0];
- *r = float_to_ubyte(p[0]);
- *g = float_to_ubyte(p[1]);
- *b = float_to_ubyte(p[2]);
- *a = (ubyte) 0xff;
- }
- return;
-
- case PIPE_FORMAT_R32G32_FLOAT:
- {
- const float *p = &uc->f[0];
- *r = float_to_ubyte(p[0]);
- *g = float_to_ubyte(p[1]);
- *b = *a = (ubyte) 0xff;
- }
- return;
-
- case PIPE_FORMAT_R32_FLOAT:
- {
- const float *p = &uc->f[0];
- *r = float_to_ubyte(p[0]);
- *g = *b = *a = (ubyte) 0xff;
- }
- return;
-
- /* Handle other cases with a generic function.
- */
- default:
- {
- ubyte dst[4];
-
- util_format_read_4ub(format, dst, 0, uc, 0, 0, 0, 1, 1);
- *r = dst[0];
- *g = dst[1];
- *b = dst[2];
- *a = dst[3];
- }
- }
-}
-
-
-/**
- * Note rgba outside [0,1] will be clamped for int pixel formats.
- */
-static INLINE void
-util_pack_color(const float rgba[4], enum pipe_format format, union util_color *uc)
-{
- ubyte r = 0;
- ubyte g = 0;
- ubyte b = 0;
- ubyte a = 0;
-
- if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0) <= 8) {
- /* format uses 8-bit components or less */
- r = float_to_ubyte(rgba[0]);
- g = float_to_ubyte(rgba[1]);
- b = float_to_ubyte(rgba[2]);
- a = float_to_ubyte(rgba[3]);
- }
-
- switch (format) {
- case PIPE_FORMAT_A8B8G8R8_UNORM:
- {
- uc->ui = (r << 24) | (g << 16) | (b << 8) | a;
- }
- return;
- case PIPE_FORMAT_X8B8G8R8_UNORM:
- {
- uc->ui = (r << 24) | (g << 16) | (b << 8) | 0xff;
- }
- return;
- case PIPE_FORMAT_B8G8R8A8_UNORM:
- {
- uc->ui = (a << 24) | (r << 16) | (g << 8) | b;
- }
- return;
- case PIPE_FORMAT_B8G8R8X8_UNORM:
- {
- uc->ui = (0xff << 24) | (r << 16) | (g << 8) | b;
- }
- return;
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- {
- uc->ui = (b << 24) | (g << 16) | (r << 8) | a;
- }
- return;
- case PIPE_FORMAT_X8R8G8B8_UNORM:
- {
- uc->ui = (b << 24) | (g << 16) | (r << 8) | 0xff;
- }
- return;
- case PIPE_FORMAT_B5G6R5_UNORM:
- {
- uc->us = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3);
- }
- return;
- case PIPE_FORMAT_B5G5R5X1_UNORM:
- {
- uc->us = ((0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3);
- }
- return;
- case PIPE_FORMAT_B5G5R5A1_UNORM:
- {
- uc->us = ((a & 0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3);
- }
- return;
- case PIPE_FORMAT_B4G4R4A4_UNORM:
- {
- uc->us = ((a & 0xf0) << 8) | ((r & 0xf0) << 4) | ((g & 0xf0) << 0) | (b >> 4);
- }
- return;
- case PIPE_FORMAT_A8_UNORM:
- {
- uc->ub = a;
- }
- return;
- case PIPE_FORMAT_L8_UNORM:
- case PIPE_FORMAT_I8_UNORM:
- {
- uc->ub = r;
- }
- return;
- case PIPE_FORMAT_R32G32B32A32_FLOAT:
- {
- uc->f[0] = rgba[0];
- uc->f[1] = rgba[1];
- uc->f[2] = rgba[2];
- uc->f[3] = rgba[3];
- }
- return;
- case PIPE_FORMAT_R32G32B32_FLOAT:
- {
- uc->f[0] = rgba[0];
- uc->f[1] = rgba[1];
- uc->f[2] = rgba[2];
- }
- return;
-
- /* Handle other cases with a generic function.
- */
- default:
- util_format_write_4f(format, rgba, 0, uc, 0, 0, 0, 1, 1);
- }
-}
-
-/* Integer versions of util_pack_z and util_pack_z_stencil - useful for
- * constructing clear masks.
- */
-static INLINE uint32_t
-util_pack_mask_z(enum pipe_format format, uint32_t z)
-{
- switch (format) {
- case PIPE_FORMAT_Z16_UNORM:
- return z & 0xffff;
- case PIPE_FORMAT_Z32_UNORM:
- case PIPE_FORMAT_Z32_FLOAT:
- return z;
- case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
- case PIPE_FORMAT_Z24X8_UNORM:
- return z & 0xffffff;
- case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
- case PIPE_FORMAT_X8Z24_UNORM:
- return (z & 0xffffff) << 8;
- case PIPE_FORMAT_S8_USCALED:
- return 0;
- default:
- debug_print_format("gallium: unhandled format in util_pack_mask_z()", format);
- assert(0);
- return 0;
- }
-}
-
-static INLINE uint32_t
-util_pack_mask_z_stencil(enum pipe_format format, uint32_t z, uint8_t s)
-{
- uint32_t packed = util_pack_mask_z(format, z);
-
- switch (format) {
- case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
- packed |= (uint32_t)s << 24;
- break;
- case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
- packed |= s;
- break;
- case PIPE_FORMAT_S8_USCALED:
- packed |= s;
- break;
- default:
- break;
- }
-
- return packed;
-}
-
-
-
-/**
- * Note: it's assumed that z is in [0,1]
- */
-static INLINE uint32_t
-util_pack_z(enum pipe_format format, double z)
-{
- union fi fui;
-
- if (z == 0.0)
- return 0;
-
- switch (format) {
- case PIPE_FORMAT_Z16_UNORM:
- if (z == 1.0)
- return 0xffff;
- return (uint32_t) (z * 0xffff);
- case PIPE_FORMAT_Z32_UNORM:
- /* special-case to avoid overflow */
- if (z == 1.0)
- return 0xffffffff;
- return (uint32_t) (z * 0xffffffff);
- case PIPE_FORMAT_Z32_FLOAT:
- fui.f = (float)z;
- return fui.ui;
- case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
- case PIPE_FORMAT_Z24X8_UNORM:
- if (z == 1.0)
- return 0xffffff;
- return (uint32_t) (z * 0xffffff);
- case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
- case PIPE_FORMAT_X8Z24_UNORM:
- if (z == 1.0)
- return 0xffffff00;
- return ((uint32_t) (z * 0xffffff)) << 8;
- case PIPE_FORMAT_S8_USCALED:
- /* this case can get it via util_pack_z_stencil() */
- return 0;
- default:
- debug_print_format("gallium: unhandled format in util_pack_z()", format);
- assert(0);
- return 0;
- }
-}
-
-
-/**
- * Pack Z and/or stencil values into a 32-bit value described by format.
- * Note: it's assumed that z is in [0,1] and s in [0,255]
- */
-static INLINE uint32_t
-util_pack_z_stencil(enum pipe_format format, double z, uint8_t s)
-{
- uint32_t packed = util_pack_z(format, z);
-
- switch (format) {
- case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
- packed |= (uint32_t)s << 24;
- break;
- case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
- packed |= s;
- break;
- case PIPE_FORMAT_S8_USCALED:
- packed |= s;
- break;
- default:
- break;
- }
-
- return packed;
-}
-
-
-/**
- * Pack 4 ubytes into a 4-byte word
- */
-static INLINE unsigned
-pack_ub4(ubyte b0, ubyte b1, ubyte b2, ubyte b3)
-{
- return ((((unsigned int)b0) << 0) |
- (((unsigned int)b1) << 8) |
- (((unsigned int)b2) << 16) |
- (((unsigned int)b3) << 24));
-}
-
-
-/**
- * Pack/convert 4 floats into one 4-byte word.
- */
-static INLINE unsigned
-pack_ui32_float4(float a, float b, float c, float d)
-{
- return pack_ub4( float_to_ubyte(a),
- float_to_ubyte(b),
- float_to_ubyte(c),
- float_to_ubyte(d) );
-}
-
-
-
-#endif /* U_PACK_COLOR_H */
+/**************************************************************************
+ *
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/**
+ * @file
+ * Functions to produce packed colors/Z from floats.
+ */
+
+
+#ifndef U_PACK_COLOR_H
+#define U_PACK_COLOR_H
+
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_format.h"
+#include "util/u_debug.h"
+#include "util/u_format.h"
+#include "util/u_math.h"
+
+
+/**
+ * Helper union for packing pixel values.
+ * Will often contain values in formats which are too complex to be described
+ * in simple terms, hence might just effectively contain a number of bytes.
+ * Must be big enough to hold data for all formats (currently 256 bits).
+ */
+union util_color {
+ ubyte ub;
+ ushort us;
+ uint ui;
+ float f[4];
+ double d[4];
+};
+
+/**
+ * Pack ubyte R,G,B,A into dest pixel.
+ */
+static INLINE void
+util_pack_color_ub(ubyte r, ubyte g, ubyte b, ubyte a,
+ enum pipe_format format, union util_color *uc)
+{
+ switch (format) {
+ case PIPE_FORMAT_A8B8G8R8_UNORM:
+ {
+ uc->ui = (r << 24) | (g << 16) | (b << 8) | a;
+ }
+ return;
+ case PIPE_FORMAT_X8B8G8R8_UNORM:
+ {
+ uc->ui = (r << 24) | (g << 16) | (b << 8) | 0xff;
+ }
+ return;
+ case PIPE_FORMAT_B8G8R8A8_UNORM:
+ {
+ uc->ui = (a << 24) | (r << 16) | (g << 8) | b;
+ }
+ return;
+ case PIPE_FORMAT_B8G8R8X8_UNORM:
+ {
+ uc->ui = (0xff << 24) | (r << 16) | (g << 8) | b;
+ }
+ return;
+ case PIPE_FORMAT_A8R8G8B8_UNORM:
+ {
+ uc->ui = (b << 24) | (g << 16) | (r << 8) | a;
+ }
+ return;
+ case PIPE_FORMAT_X8R8G8B8_UNORM:
+ {
+ uc->ui = (b << 24) | (g << 16) | (r << 8) | 0xff;
+ }
+ return;
+ case PIPE_FORMAT_B5G6R5_UNORM:
+ {
+ uc->us = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3);
+ }
+ return;
+ case PIPE_FORMAT_B5G5R5X1_UNORM:
+ {
+ uc->us = ((0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3);
+ }
+ return;
+ case PIPE_FORMAT_B5G5R5A1_UNORM:
+ {
+ uc->us = ((a & 0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3);
+ }
+ return;
+ case PIPE_FORMAT_B4G4R4A4_UNORM:
+ {
+ uc->us = ((a & 0xf0) << 8) | ((r & 0xf0) << 4) | ((g & 0xf0) << 0) | (b >> 4);
+ }
+ return;
+ case PIPE_FORMAT_A8_UNORM:
+ {
+ uc->ub = a;
+ }
+ return;
+ case PIPE_FORMAT_L8_UNORM:
+ case PIPE_FORMAT_I8_UNORM:
+ {
+ uc->ub = a;
+ }
+ return;
+ case PIPE_FORMAT_R32G32B32A32_FLOAT:
+ {
+ uc->f[0] = (float)r / 255.0f;
+ uc->f[1] = (float)g / 255.0f;
+ uc->f[2] = (float)b / 255.0f;
+ uc->f[3] = (float)a / 255.0f;
+ }
+ return;
+ case PIPE_FORMAT_R32G32B32_FLOAT:
+ {
+ uc->f[0] = (float)r / 255.0f;
+ uc->f[1] = (float)g / 255.0f;
+ uc->f[2] = (float)b / 255.0f;
+ }
+ return;
+
+ /* Handle other cases with a generic function.
+ */
+ default:
+ {
+ ubyte src[4];
+
+ src[0] = r;
+ src[1] = g;
+ src[2] = b;
+ src[3] = a;
+ util_format_write_4ub(format, src, 0, uc, 0, 0, 0, 1, 1);
+ }
+ }
+}
+
+
+/**
+ * Unpack RGBA from a packed pixel, returning values as ubytes in [0,255].
+ */
+static INLINE void
+util_unpack_color_ub(enum pipe_format format, union util_color *uc,
+ ubyte *r, ubyte *g, ubyte *b, ubyte *a)
+{
+ switch (format) {
+ case PIPE_FORMAT_A8B8G8R8_UNORM:
+ {
+ uint p = uc->ui;
+ *r = (ubyte) ((p >> 24) & 0xff);
+ *g = (ubyte) ((p >> 16) & 0xff);
+ *b = (ubyte) ((p >> 8) & 0xff);
+ *a = (ubyte) ((p >> 0) & 0xff);
+ }
+ return;
+ case PIPE_FORMAT_X8B8G8R8_UNORM:
+ {
+ uint p = uc->ui;
+ *r = (ubyte) ((p >> 24) & 0xff);
+ *g = (ubyte) ((p >> 16) & 0xff);
+ *b = (ubyte) ((p >> 8) & 0xff);
+ *a = (ubyte) 0xff;
+ }
+ return;
+ case PIPE_FORMAT_B8G8R8A8_UNORM:
+ {
+ uint p = uc->ui;
+ *r = (ubyte) ((p >> 16) & 0xff);
+ *g = (ubyte) ((p >> 8) & 0xff);
+ *b = (ubyte) ((p >> 0) & 0xff);
+ *a = (ubyte) ((p >> 24) & 0xff);
+ }
+ return;
+ case PIPE_FORMAT_B8G8R8X8_UNORM:
+ {
+ uint p = uc->ui;
+ *r = (ubyte) ((p >> 16) & 0xff);
+ *g = (ubyte) ((p >> 8) & 0xff);
+ *b = (ubyte) ((p >> 0) & 0xff);
+ *a = (ubyte) 0xff;
+ }
+ return;
+ case PIPE_FORMAT_A8R8G8B8_UNORM:
+ {
+ uint p = uc->ui;
+ *r = (ubyte) ((p >> 8) & 0xff);
+ *g = (ubyte) ((p >> 16) & 0xff);
+ *b = (ubyte) ((p >> 24) & 0xff);
+ *a = (ubyte) ((p >> 0) & 0xff);
+ }
+ return;
+ case PIPE_FORMAT_X8R8G8B8_UNORM:
+ {
+ uint p = uc->ui;
+ *r = (ubyte) ((p >> 8) & 0xff);
+ *g = (ubyte) ((p >> 16) & 0xff);
+ *b = (ubyte) ((p >> 24) & 0xff);
+ *a = (ubyte) 0xff;
+ }
+ return;
+ case PIPE_FORMAT_B5G6R5_UNORM:
+ {
+ ushort p = uc->us;
+ *r = (ubyte) (((p >> 8) & 0xf8) | ((p >> 13) & 0x7));
+ *g = (ubyte) (((p >> 3) & 0xfc) | ((p >> 9) & 0x3));
+ *b = (ubyte) (((p << 3) & 0xf8) | ((p >> 2) & 0x7));
+ *a = (ubyte) 0xff;
+ }
+ return;
+ case PIPE_FORMAT_B5G5R5X1_UNORM:
+ {
+ ushort p = uc->us;
+ *r = (ubyte) (((p >> 7) & 0xf8) | ((p >> 12) & 0x7));
+ *g = (ubyte) (((p >> 2) & 0xf8) | ((p >> 7) & 0x7));
+ *b = (ubyte) (((p << 3) & 0xf8) | ((p >> 2) & 0x7));
+ *a = (ubyte) 0xff;
+ }
+ return;
+ case PIPE_FORMAT_B5G5R5A1_UNORM:
+ {
+ ushort p = uc->us;
+ *r = (ubyte) (((p >> 7) & 0xf8) | ((p >> 12) & 0x7));
+ *g = (ubyte) (((p >> 2) & 0xf8) | ((p >> 7) & 0x7));
+ *b = (ubyte) (((p << 3) & 0xf8) | ((p >> 2) & 0x7));
+ *a = (ubyte) (0xff * (p >> 15));
+ }
+ return;
+ case PIPE_FORMAT_B4G4R4A4_UNORM:
+ {
+ ushort p = uc->us;
+ *r = (ubyte) (((p >> 4) & 0xf0) | ((p >> 8) & 0xf));
+ *g = (ubyte) (((p >> 0) & 0xf0) | ((p >> 4) & 0xf));
+ *b = (ubyte) (((p << 4) & 0xf0) | ((p >> 0) & 0xf));
+ *a = (ubyte) (((p >> 8) & 0xf0) | ((p >> 12) & 0xf));
+ }
+ return;
+ case PIPE_FORMAT_A8_UNORM:
+ {
+ ubyte p = uc->ub;
+ *r = *g = *b = (ubyte) 0xff;
+ *a = p;
+ }
+ return;
+ case PIPE_FORMAT_L8_UNORM:
+ {
+ ubyte p = uc->ub;
+ *r = *g = *b = p;
+ *a = (ubyte) 0xff;
+ }
+ return;
+ case PIPE_FORMAT_I8_UNORM:
+ {
+ ubyte p = uc->ub;
+ *r = *g = *b = *a = p;
+ }
+ return;
+ case PIPE_FORMAT_R32G32B32A32_FLOAT:
+ {
+ const float *p = &uc->f[0];
+ *r = float_to_ubyte(p[0]);
+ *g = float_to_ubyte(p[1]);
+ *b = float_to_ubyte(p[2]);
+ *a = float_to_ubyte(p[3]);
+ }
+ return;
+ case PIPE_FORMAT_R32G32B32_FLOAT:
+ {
+ const float *p = &uc->f[0];
+ *r = float_to_ubyte(p[0]);
+ *g = float_to_ubyte(p[1]);
+ *b = float_to_ubyte(p[2]);
+ *a = (ubyte) 0xff;
+ }
+ return;
+
+ case PIPE_FORMAT_R32G32_FLOAT:
+ {
+ const float *p = &uc->f[0];
+ *r = float_to_ubyte(p[0]);
+ *g = float_to_ubyte(p[1]);
+ *b = *a = (ubyte) 0xff;
+ }
+ return;
+
+ case PIPE_FORMAT_R32_FLOAT:
+ {
+ const float *p = &uc->f[0];
+ *r = float_to_ubyte(p[0]);
+ *g = *b = *a = (ubyte) 0xff;
+ }
+ return;
+
+ /* Handle other cases with a generic function.
+ */
+ default:
+ {
+ ubyte dst[4];
+
+ util_format_read_4ub(format, dst, 0, uc, 0, 0, 0, 1, 1);
+ *r = dst[0];
+ *g = dst[1];
+ *b = dst[2];
+ *a = dst[3];
+ }
+ }
+}
+
+
+/**
+ * Note rgba outside [0,1] will be clamped for int pixel formats.
+ */
+static INLINE void
+util_pack_color(const float rgba[4], enum pipe_format format, union util_color *uc)
+{
+ ubyte r = 0;
+ ubyte g = 0;
+ ubyte b = 0;
+ ubyte a = 0;
+
+ if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0) <= 8) {
+ /* format uses 8-bit components or less */
+ r = float_to_ubyte(rgba[0]);
+ g = float_to_ubyte(rgba[1]);
+ b = float_to_ubyte(rgba[2]);
+ a = float_to_ubyte(rgba[3]);
+ }
+
+ switch (format) {
+ case PIPE_FORMAT_A8B8G8R8_UNORM:
+ {
+ uc->ui = (r << 24) | (g << 16) | (b << 8) | a;
+ }
+ return;
+ case PIPE_FORMAT_X8B8G8R8_UNORM:
+ {
+ uc->ui = (r << 24) | (g << 16) | (b << 8) | 0xff;
+ }
+ return;
+ case PIPE_FORMAT_B8G8R8A8_UNORM:
+ {
+ uc->ui = (a << 24) | (r << 16) | (g << 8) | b;
+ }
+ return;
+ case PIPE_FORMAT_B8G8R8X8_UNORM:
+ {
+ uc->ui = (0xff << 24) | (r << 16) | (g << 8) | b;
+ }
+ return;
+ case PIPE_FORMAT_A8R8G8B8_UNORM:
+ {
+ uc->ui = (b << 24) | (g << 16) | (r << 8) | a;
+ }
+ return;
+ case PIPE_FORMAT_X8R8G8B8_UNORM:
+ {
+ uc->ui = (b << 24) | (g << 16) | (r << 8) | 0xff;
+ }
+ return;
+ case PIPE_FORMAT_B5G6R5_UNORM:
+ {
+ uc->us = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3);
+ }
+ return;
+ case PIPE_FORMAT_B5G5R5X1_UNORM:
+ {
+ uc->us = ((0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3);
+ }
+ return;
+ case PIPE_FORMAT_B5G5R5A1_UNORM:
+ {
+ uc->us = ((a & 0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3);
+ }
+ return;
+ case PIPE_FORMAT_B4G4R4A4_UNORM:
+ {
+ uc->us = ((a & 0xf0) << 8) | ((r & 0xf0) << 4) | ((g & 0xf0) << 0) | (b >> 4);
+ }
+ return;
+ case PIPE_FORMAT_A8_UNORM:
+ {
+ uc->ub = a;
+ }
+ return;
+ case PIPE_FORMAT_L8_UNORM:
+ case PIPE_FORMAT_I8_UNORM:
+ {
+ uc->ub = r;
+ }
+ return;
+ case PIPE_FORMAT_R32G32B32A32_FLOAT:
+ {
+ uc->f[0] = rgba[0];
+ uc->f[1] = rgba[1];
+ uc->f[2] = rgba[2];
+ uc->f[3] = rgba[3];
+ }
+ return;
+ case PIPE_FORMAT_R32G32B32_FLOAT:
+ {
+ uc->f[0] = rgba[0];
+ uc->f[1] = rgba[1];
+ uc->f[2] = rgba[2];
+ }
+ return;
+
+ /* Handle other cases with a generic function.
+ */
+ default:
+ util_format_write_4f(format, rgba, 0, uc, 0, 0, 0, 1, 1);
+ }
+}
+
+/* Integer versions of util_pack_z and util_pack_z_stencil - useful for
+ * constructing clear masks.
+ */
+static INLINE uint32_t
+util_pack_mask_z(enum pipe_format format, uint32_t z)
+{
+ switch (format) {
+ case PIPE_FORMAT_Z16_UNORM:
+ return z & 0xffff;
+ case PIPE_FORMAT_Z32_UNORM:
+ case PIPE_FORMAT_Z32_FLOAT:
+ return z;
+ case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
+ case PIPE_FORMAT_Z24X8_UNORM:
+ return z & 0xffffff;
+ case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
+ case PIPE_FORMAT_X8Z24_UNORM:
+ return (z & 0xffffff) << 8;
+ case PIPE_FORMAT_S8_USCALED:
+ return 0;
+ default:
+ debug_print_format("gallium: unhandled format in util_pack_mask_z()", format);
+ assert(0);
+ return 0;
+ }
+}
+
+
+static INLINE uint64_t
+util_pack64_mask_z(enum pipe_format format, uint32_t z)
+{
+ switch (format) {
+ case PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED:
+ return z;
+ default:
+ return util_pack_mask_z(format, z);
+ }
+}
+
+
+static INLINE uint32_t
+util_pack_mask_z_stencil(enum pipe_format format, uint32_t z, uint8_t s)
+{
+ uint32_t packed = util_pack_mask_z(format, z);
+
+ switch (format) {
+ case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
+ packed |= (uint32_t)s << 24;
+ break;
+ case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
+ packed |= s;
+ break;
+ case PIPE_FORMAT_S8_USCALED:
+ packed |= s;
+ break;
+ default:
+ break;
+ }
+
+ return packed;
+}
+
+
+static INLINE uint64_t
+util_pack64_mask_z_stencil(enum pipe_format format, uint32_t z, uint8_t s)
+{
+ uint64_t packed;
+
+ switch (format) {
+ case PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED:
+ packed = util_pack64_mask_z(format, z);
+ packed |= (uint64_t)s << 32ull;
+ return packed;
+ default:
+ return util_pack_mask_z_stencil(format, z, s);
+ }
+}
+
+
+/**
+ * Note: it's assumed that z is in [0,1]
+ */
+static INLINE uint32_t
+util_pack_z(enum pipe_format format, double z)
+{
+ union fi fui;
+
+ if (z == 0.0)
+ return 0;
+
+ switch (format) {
+ case PIPE_FORMAT_Z16_UNORM:
+ if (z == 1.0)
+ return 0xffff;
+ return (uint32_t) (z * 0xffff);
+ case PIPE_FORMAT_Z32_UNORM:
+ /* special-case to avoid overflow */
+ if (z == 1.0)
+ return 0xffffffff;
+ return (uint32_t) (z * 0xffffffff);
+ case PIPE_FORMAT_Z32_FLOAT:
+ fui.f = (float)z;
+ return fui.ui;
+ case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
+ case PIPE_FORMAT_Z24X8_UNORM:
+ if (z == 1.0)
+ return 0xffffff;
+ return (uint32_t) (z * 0xffffff);
+ case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
+ case PIPE_FORMAT_X8Z24_UNORM:
+ if (z == 1.0)
+ return 0xffffff00;
+ return ((uint32_t) (z * 0xffffff)) << 8;
+ case PIPE_FORMAT_S8_USCALED:
+ /* this case can get it via util_pack_z_stencil() */
+ return 0;
+ default:
+ debug_print_format("gallium: unhandled format in util_pack_z()", format);
+ assert(0);
+ return 0;
+ }
+}
+
+
+static INLINE uint64_t
+util_pack64_z(enum pipe_format format, double z)
+{
+ union fi fui;
+
+ if (z == 0)
+ return 0;
+
+ switch (format) {
+ case PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED:
+ fui.f = (float)z;
+ return fui.ui;
+ default:
+ return util_pack_z(format, z);
+ }
+}
+
+
+/**
+ * Pack Z and/or stencil values into a 32-bit value described by format.
+ * Note: it's assumed that z is in [0,1] and s in [0,255]
+ */
+static INLINE uint32_t
+util_pack_z_stencil(enum pipe_format format, double z, uint8_t s)
+{
+ uint32_t packed = util_pack_z(format, z);
+
+ switch (format) {
+ case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
+ packed |= (uint32_t)s << 24;
+ break;
+ case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
+ packed |= s;
+ break;
+ case PIPE_FORMAT_S8_USCALED:
+ packed |= s;
+ break;
+ default:
+ break;
+ }
+
+ return packed;
+}
+
+
+static INLINE uint64_t
+util_pack64_z_stencil(enum pipe_format format, double z, uint8_t s)
+{
+ uint64_t packed;
+
+ switch (format) {
+ case PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED:
+ packed = util_pack64_z(format, z);
+ packed |= (uint64_t)s << 32ull;
+ break;
+ default:
+ return util_pack_z_stencil(format, z, s);
+ }
+
+ return packed;
+}
+
+
+/**
+ * Pack 4 ubytes into a 4-byte word
+ */
+static INLINE unsigned
+pack_ub4(ubyte b0, ubyte b1, ubyte b2, ubyte b3)
+{
+ return ((((unsigned int)b0) << 0) |
+ (((unsigned int)b1) << 8) |
+ (((unsigned int)b2) << 16) |
+ (((unsigned int)b3) << 24));
+}
+
+
+/**
+ * Pack/convert 4 floats into one 4-byte word.
+ */
+static INLINE unsigned
+pack_ui32_float4(float a, float b, float c, float d)
+{
+ return pack_ub4( float_to_ubyte(a),
+ float_to_ubyte(b),
+ float_to_ubyte(c),
+ float_to_ubyte(d) );
+}
+
+
+
+#endif /* U_PACK_COLOR_H */
diff --git a/mesalib/src/gallium/auxiliary/util/u_surface.c b/mesalib/src/gallium/auxiliary/util/u_surface.c
index 26f2aee99..8e123867d 100644
--- a/mesalib/src/gallium/auxiliary/util/u_surface.c
+++ b/mesalib/src/gallium/auxiliary/util/u_surface.c
@@ -1,371 +1,404 @@
-/**************************************************************************
- *
- * Copyright 2009 VMware, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-/**
- * @file
- * Surface utility functions.
- *
- * @author Brian Paul
- */
-
-
-#include "pipe/p_defines.h"
-#include "pipe/p_screen.h"
-#include "pipe/p_state.h"
-
-#include "util/u_format.h"
-#include "util/u_inlines.h"
-#include "util/u_rect.h"
-#include "util/u_surface.h"
-#include "util/u_pack_color.h"
-
-void
-u_surface_default_template(struct pipe_surface *view,
- const struct pipe_resource *texture,
- unsigned bind)
-{
- view->format = texture->format;
- view->u.tex.level = 0;
- view->u.tex.first_layer = 0;
- view->u.tex.last_layer = 0;
- /* XXX should filter out all non-rt/ds bind flags ? */
- view->usage = bind;
-}
-
-/**
- * Helper to quickly create an RGBA rendering surface of a certain size.
- * \param textureOut returns the new texture
- * \param surfaceOut returns the new surface
- * \return TRUE for success, FALSE if failure
- */
-boolean
-util_create_rgba_surface(struct pipe_context *pipe,
- uint width, uint height,
- uint bind,
- struct pipe_resource **textureOut,
- struct pipe_surface **surfaceOut)
-{
- static const enum pipe_format rgbaFormats[] = {
- PIPE_FORMAT_B8G8R8A8_UNORM,
- PIPE_FORMAT_A8R8G8B8_UNORM,
- PIPE_FORMAT_A8B8G8R8_UNORM,
- PIPE_FORMAT_NONE
- };
- const uint target = PIPE_TEXTURE_2D;
- enum pipe_format format = PIPE_FORMAT_NONE;
- struct pipe_resource templ;
- struct pipe_surface surf_templ;
- struct pipe_screen *screen = pipe->screen;
- uint i;
-
- /* Choose surface format */
- for (i = 0; rgbaFormats[i]; i++) {
- if (screen->is_format_supported(screen, rgbaFormats[i],
- target, 0, bind)) {
- format = rgbaFormats[i];
- break;
- }
- }
- if (format == PIPE_FORMAT_NONE)
- return FALSE; /* unable to get an rgba format!?! */
-
- /* create texture */
- memset(&templ, 0, sizeof(templ));
- templ.target = target;
- templ.format = format;
- templ.last_level = 0;
- templ.width0 = width;
- templ.height0 = height;
- templ.depth0 = 1;
- templ.array_size = 1;
- templ.bind = bind;
-
- *textureOut = screen->resource_create(screen, &templ);
- if (!*textureOut)
- return FALSE;
-
- /* create surface */
- memset(&surf_templ, 0, sizeof(surf_templ));
- u_surface_default_template(&surf_templ, *textureOut, bind);
- /* create surface / view into texture */
- *surfaceOut = pipe->create_surface(pipe,
- *textureOut,
- &surf_templ);
- if (!*surfaceOut) {
- pipe_resource_reference(textureOut, NULL);
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-/**
- * Release the surface and texture from util_create_rgba_surface().
- */
-void
-util_destroy_rgba_surface(struct pipe_resource *texture,
- struct pipe_surface *surface)
-{
- pipe_surface_reference(&surface, NULL);
- pipe_resource_reference(&texture, NULL);
-}
-
-
-
-/**
- * Fallback function for pipe->resource_copy_region().
- * Note: (X,Y)=(0,0) is always the upper-left corner.
- */
-void
-util_resource_copy_region(struct pipe_context *pipe,
- struct pipe_resource *dst,
- unsigned dst_level,
- unsigned dst_x, unsigned dst_y, unsigned dst_z,
- struct pipe_resource *src,
- unsigned src_level,
- const struct pipe_box *src_box)
-{
- struct pipe_transfer *src_trans, *dst_trans;
- void *dst_map;
- const void *src_map;
- enum pipe_format src_format, dst_format;
- unsigned w = src_box->width;
- unsigned h = src_box->height;
-
- assert(src && dst);
- assert((src->target == PIPE_BUFFER && dst->target == PIPE_BUFFER) ||
- (src->target != PIPE_BUFFER && dst->target != PIPE_BUFFER));
-
- if (!src || !dst)
- return;
-
- src_format = src->format;
- dst_format = dst->format;
-
- src_trans = pipe_get_transfer(pipe,
- src,
- src_level,
- src_box->z,
- PIPE_TRANSFER_READ,
- src_box->x, src_box->y, w, h);
-
- dst_trans = pipe_get_transfer(pipe,
- dst,
- dst_level,
- dst_z,
- PIPE_TRANSFER_WRITE,
- dst_x, dst_y, w, h);
-
- assert(util_format_get_blocksize(dst_format) == util_format_get_blocksize(src_format));
- assert(util_format_get_blockwidth(dst_format) == util_format_get_blockwidth(src_format));
- assert(util_format_get_blockheight(dst_format) == util_format_get_blockheight(src_format));
-
- src_map = pipe->transfer_map(pipe, src_trans);
- dst_map = pipe->transfer_map(pipe, dst_trans);
-
- assert(src_map);
- assert(dst_map);
-
- if (src_map && dst_map) {
- if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) {
- memcpy(dst_map, src_map, w);
- } else {
- util_copy_rect(dst_map,
- dst_format,
- dst_trans->stride,
- 0, 0,
- w, h,
- src_map,
- src_trans->stride,
- 0,
- 0);
- }
- }
-
- pipe->transfer_unmap(pipe, src_trans);
- pipe->transfer_unmap(pipe, dst_trans);
-
- pipe->transfer_destroy(pipe, src_trans);
- pipe->transfer_destroy(pipe, dst_trans);
-}
-
-
-
-#define UBYTE_TO_USHORT(B) ((B) | ((B) << 8))
-
-
-/**
- * Fallback for pipe->clear_render_target() function.
- * XXX this looks too hackish to be really useful.
- * cpp > 4 looks like a gross hack at best...
- * Plus can't use these transfer fallbacks when clearing
- * multisampled surfaces for instance.
- */
-void
-util_clear_render_target(struct pipe_context *pipe,
- struct pipe_surface *dst,
- const float *rgba,
- unsigned dstx, unsigned dsty,
- unsigned width, unsigned height)
-{
- struct pipe_transfer *dst_trans;
- void *dst_map;
- union util_color uc;
-
- assert(dst->texture);
- if (!dst->texture)
- return;
- /* XXX: should handle multiple layers */
- dst_trans = pipe_get_transfer(pipe,
- dst->texture,
- dst->u.tex.level,
- dst->u.tex.first_layer,
- PIPE_TRANSFER_WRITE,
- dstx, dsty, width, height);
-
- dst_map = pipe->transfer_map(pipe, dst_trans);
-
- assert(dst_map);
-
- if (dst_map) {
- assert(dst_trans->stride > 0);
-
- util_pack_color(rgba, dst->texture->format, &uc);
- util_fill_rect(dst_map, dst->texture->format,
- dst_trans->stride,
- 0, 0, width, height, &uc);
- }
-
- pipe->transfer_unmap(pipe, dst_trans);
- pipe->transfer_destroy(pipe, dst_trans);
-}
-
-/**
- * Fallback for pipe->clear_stencil() function.
- * sw fallback doesn't look terribly useful here.
- * Plus can't use these transfer fallbacks when clearing
- * multisampled surfaces for instance.
- */
-void
-util_clear_depth_stencil(struct pipe_context *pipe,
- struct pipe_surface *dst,
- unsigned clear_flags,
- double depth,
- unsigned stencil,
- unsigned dstx, unsigned dsty,
- unsigned width, unsigned height)
-{
- struct pipe_transfer *dst_trans;
- ubyte *dst_map;
- boolean need_rmw = FALSE;
-
- if ((clear_flags & PIPE_CLEAR_DEPTHSTENCIL) &&
- ((clear_flags & PIPE_CLEAR_DEPTHSTENCIL) != PIPE_CLEAR_DEPTHSTENCIL) &&
- util_format_is_depth_and_stencil(dst->format))
- need_rmw = TRUE;
-
- assert(dst->texture);
- if (!dst->texture)
- return;
- dst_trans = pipe_get_transfer(pipe,
- dst->texture,
- dst->u.tex.level,
- dst->u.tex.first_layer,
- (need_rmw ? PIPE_TRANSFER_READ_WRITE :
- PIPE_TRANSFER_WRITE),
- dstx, dsty, width, height);
-
- dst_map = pipe->transfer_map(pipe, dst_trans);
-
- assert(dst_map);
-
- if (dst_map) {
- unsigned dst_stride = dst_trans->stride;
- unsigned zstencil = util_pack_z_stencil(dst->texture->format, depth, stencil);
- unsigned i, j;
- assert(dst_trans->stride > 0);
-
- switch (util_format_get_blocksize(dst->format)) {
- case 1:
- assert(dst->format == PIPE_FORMAT_S8_USCALED);
- if(dst_stride == width)
- memset(dst_map, (ubyte) zstencil, height * width);
- else {
- for (i = 0; i < height; i++) {
- memset(dst_map, (ubyte) zstencil, width);
- dst_map += dst_stride;
- }
- }
- break;
- case 2:
- assert(dst->format == PIPE_FORMAT_Z16_UNORM);
- for (i = 0; i < height; i++) {
- uint16_t *row = (uint16_t *)dst_map;
- for (j = 0; j < width; j++)
- *row++ = (uint16_t) zstencil;
- dst_map += dst_stride;
- }
- break;
- case 4:
- if (!need_rmw) {
- for (i = 0; i < height; i++) {
- uint32_t *row = (uint32_t *)dst_map;
- for (j = 0; j < width; j++)
- *row++ = zstencil;
- dst_map += dst_stride;
- }
- }
- else {
- uint32_t dst_mask;
- if (dst->format == PIPE_FORMAT_Z24_UNORM_S8_USCALED)
- dst_mask = 0xffffff00;
- else {
- assert(dst->format == PIPE_FORMAT_S8_USCALED_Z24_UNORM);
- dst_mask = 0xffffff;
- }
- if (clear_flags & PIPE_CLEAR_DEPTH)
- dst_mask = ~dst_mask;
- for (i = 0; i < height; i++) {
- uint32_t *row = (uint32_t *)dst_map;
- for (j = 0; j < width; j++) {
- uint32_t tmp = *row & dst_mask;
- *row++ = tmp | (zstencil & ~dst_mask);
- }
- dst_map += dst_stride;
- }
- }
- break;
- case 8:
- default:
- assert(0);
- break;
- }
- }
-
- pipe->transfer_unmap(pipe, dst_trans);
- pipe->transfer_destroy(pipe, dst_trans);
-}
+/**************************************************************************
+ *
+ * Copyright 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/**
+ * @file
+ * Surface utility functions.
+ *
+ * @author Brian Paul
+ */
+
+
+#include "pipe/p_defines.h"
+#include "pipe/p_screen.h"
+#include "pipe/p_state.h"
+
+#include "util/u_format.h"
+#include "util/u_inlines.h"
+#include "util/u_rect.h"
+#include "util/u_surface.h"
+#include "util/u_pack_color.h"
+
+void
+u_surface_default_template(struct pipe_surface *view,
+ const struct pipe_resource *texture,
+ unsigned bind)
+{
+ view->format = texture->format;
+ view->u.tex.level = 0;
+ view->u.tex.first_layer = 0;
+ view->u.tex.last_layer = 0;
+ /* XXX should filter out all non-rt/ds bind flags ? */
+ view->usage = bind;
+}
+
+/**
+ * Helper to quickly create an RGBA rendering surface of a certain size.
+ * \param textureOut returns the new texture
+ * \param surfaceOut returns the new surface
+ * \return TRUE for success, FALSE if failure
+ */
+boolean
+util_create_rgba_surface(struct pipe_context *pipe,
+ uint width, uint height,
+ uint bind,
+ struct pipe_resource **textureOut,
+ struct pipe_surface **surfaceOut)
+{
+ static const enum pipe_format rgbaFormats[] = {
+ PIPE_FORMAT_B8G8R8A8_UNORM,
+ PIPE_FORMAT_A8R8G8B8_UNORM,
+ PIPE_FORMAT_A8B8G8R8_UNORM,
+ PIPE_FORMAT_NONE
+ };
+ const uint target = PIPE_TEXTURE_2D;
+ enum pipe_format format = PIPE_FORMAT_NONE;
+ struct pipe_resource templ;
+ struct pipe_surface surf_templ;
+ struct pipe_screen *screen = pipe->screen;
+ uint i;
+
+ /* Choose surface format */
+ for (i = 0; rgbaFormats[i]; i++) {
+ if (screen->is_format_supported(screen, rgbaFormats[i],
+ target, 0, bind)) {
+ format = rgbaFormats[i];
+ break;
+ }
+ }
+ if (format == PIPE_FORMAT_NONE)
+ return FALSE; /* unable to get an rgba format!?! */
+
+ /* create texture */
+ memset(&templ, 0, sizeof(templ));
+ templ.target = target;
+ templ.format = format;
+ templ.last_level = 0;
+ templ.width0 = width;
+ templ.height0 = height;
+ templ.depth0 = 1;
+ templ.array_size = 1;
+ templ.bind = bind;
+
+ *textureOut = screen->resource_create(screen, &templ);
+ if (!*textureOut)
+ return FALSE;
+
+ /* create surface */
+ memset(&surf_templ, 0, sizeof(surf_templ));
+ u_surface_default_template(&surf_templ, *textureOut, bind);
+ /* create surface / view into texture */
+ *surfaceOut = pipe->create_surface(pipe,
+ *textureOut,
+ &surf_templ);
+ if (!*surfaceOut) {
+ pipe_resource_reference(textureOut, NULL);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/**
+ * Release the surface and texture from util_create_rgba_surface().
+ */
+void
+util_destroy_rgba_surface(struct pipe_resource *texture,
+ struct pipe_surface *surface)
+{
+ pipe_surface_reference(&surface, NULL);
+ pipe_resource_reference(&texture, NULL);
+}
+
+
+
+/**
+ * Fallback function for pipe->resource_copy_region().
+ * Note: (X,Y)=(0,0) is always the upper-left corner.
+ */
+void
+util_resource_copy_region(struct pipe_context *pipe,
+ struct pipe_resource *dst,
+ unsigned dst_level,
+ unsigned dst_x, unsigned dst_y, unsigned dst_z,
+ struct pipe_resource *src,
+ unsigned src_level,
+ const struct pipe_box *src_box)
+{
+ struct pipe_transfer *src_trans, *dst_trans;
+ void *dst_map;
+ const void *src_map;
+ enum pipe_format src_format, dst_format;
+ unsigned w = src_box->width;
+ unsigned h = src_box->height;
+
+ assert(src && dst);
+ assert((src->target == PIPE_BUFFER && dst->target == PIPE_BUFFER) ||
+ (src->target != PIPE_BUFFER && dst->target != PIPE_BUFFER));
+
+ if (!src || !dst)
+ return;
+
+ src_format = src->format;
+ dst_format = dst->format;
+
+ src_trans = pipe_get_transfer(pipe,
+ src,
+ src_level,
+ src_box->z,
+ PIPE_TRANSFER_READ,
+ src_box->x, src_box->y, w, h);
+
+ dst_trans = pipe_get_transfer(pipe,
+ dst,
+ dst_level,
+ dst_z,
+ PIPE_TRANSFER_WRITE,
+ dst_x, dst_y, w, h);
+
+ assert(util_format_get_blocksize(dst_format) == util_format_get_blocksize(src_format));
+ assert(util_format_get_blockwidth(dst_format) == util_format_get_blockwidth(src_format));
+ assert(util_format_get_blockheight(dst_format) == util_format_get_blockheight(src_format));
+
+ src_map = pipe->transfer_map(pipe, src_trans);
+ dst_map = pipe->transfer_map(pipe, dst_trans);
+
+ assert(src_map);
+ assert(dst_map);
+
+ if (src_map && dst_map) {
+ if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) {
+ memcpy(dst_map, src_map, w);
+ } else {
+ util_copy_rect(dst_map,
+ dst_format,
+ dst_trans->stride,
+ 0, 0,
+ w, h,
+ src_map,
+ src_trans->stride,
+ 0,
+ 0);
+ }
+ }
+
+ pipe->transfer_unmap(pipe, src_trans);
+ pipe->transfer_unmap(pipe, dst_trans);
+
+ pipe->transfer_destroy(pipe, src_trans);
+ pipe->transfer_destroy(pipe, dst_trans);
+}
+
+
+
+#define UBYTE_TO_USHORT(B) ((B) | ((B) << 8))
+
+
+/**
+ * Fallback for pipe->clear_render_target() function.
+ * XXX this looks too hackish to be really useful.
+ * cpp > 4 looks like a gross hack at best...
+ * Plus can't use these transfer fallbacks when clearing
+ * multisampled surfaces for instance.
+ */
+void
+util_clear_render_target(struct pipe_context *pipe,
+ struct pipe_surface *dst,
+ const float *rgba,
+ unsigned dstx, unsigned dsty,
+ unsigned width, unsigned height)
+{
+ struct pipe_transfer *dst_trans;
+ void *dst_map;
+ union util_color uc;
+
+ assert(dst->texture);
+ if (!dst->texture)
+ return;
+ /* XXX: should handle multiple layers */
+ dst_trans = pipe_get_transfer(pipe,
+ dst->texture,
+ dst->u.tex.level,
+ dst->u.tex.first_layer,
+ PIPE_TRANSFER_WRITE,
+ dstx, dsty, width, height);
+
+ dst_map = pipe->transfer_map(pipe, dst_trans);
+
+ assert(dst_map);
+
+ if (dst_map) {
+ assert(dst_trans->stride > 0);
+
+ util_pack_color(rgba, dst->texture->format, &uc);
+ util_fill_rect(dst_map, dst->texture->format,
+ dst_trans->stride,
+ 0, 0, width, height, &uc);
+ }
+
+ pipe->transfer_unmap(pipe, dst_trans);
+ pipe->transfer_destroy(pipe, dst_trans);
+}
+
+/**
+ * Fallback for pipe->clear_stencil() function.
+ * sw fallback doesn't look terribly useful here.
+ * Plus can't use these transfer fallbacks when clearing
+ * multisampled surfaces for instance.
+ */
+void
+util_clear_depth_stencil(struct pipe_context *pipe,
+ struct pipe_surface *dst,
+ unsigned clear_flags,
+ double depth,
+ unsigned stencil,
+ unsigned dstx, unsigned dsty,
+ unsigned width, unsigned height)
+{
+ struct pipe_transfer *dst_trans;
+ ubyte *dst_map;
+ boolean need_rmw = FALSE;
+
+ if ((clear_flags & PIPE_CLEAR_DEPTHSTENCIL) &&
+ ((clear_flags & PIPE_CLEAR_DEPTHSTENCIL) != PIPE_CLEAR_DEPTHSTENCIL) &&
+ util_format_is_depth_and_stencil(dst->format))
+ need_rmw = TRUE;
+
+ assert(dst->texture);
+ if (!dst->texture)
+ return;
+ dst_trans = pipe_get_transfer(pipe,
+ dst->texture,
+ dst->u.tex.level,
+ dst->u.tex.first_layer,
+ (need_rmw ? PIPE_TRANSFER_READ_WRITE :
+ PIPE_TRANSFER_WRITE),
+ dstx, dsty, width, height);
+
+ dst_map = pipe->transfer_map(pipe, dst_trans);
+
+ assert(dst_map);
+
+ if (dst_map) {
+ unsigned dst_stride = dst_trans->stride;
+ unsigned zstencil = util_pack_z_stencil(dst->texture->format, depth, stencil);
+ unsigned i, j;
+ assert(dst_trans->stride > 0);
+
+ switch (util_format_get_blocksize(dst->format)) {
+ case 1:
+ assert(dst->format == PIPE_FORMAT_S8_USCALED);
+ if(dst_stride == width)
+ memset(dst_map, (ubyte) zstencil, height * width);
+ else {
+ for (i = 0; i < height; i++) {
+ memset(dst_map, (ubyte) zstencil, width);
+ dst_map += dst_stride;
+ }
+ }
+ break;
+ case 2:
+ assert(dst->format == PIPE_FORMAT_Z16_UNORM);
+ for (i = 0; i < height; i++) {
+ uint16_t *row = (uint16_t *)dst_map;
+ for (j = 0; j < width; j++)
+ *row++ = (uint16_t) zstencil;
+ dst_map += dst_stride;
+ }
+ break;
+ case 4:
+ if (!need_rmw) {
+ for (i = 0; i < height; i++) {
+ uint32_t *row = (uint32_t *)dst_map;
+ for (j = 0; j < width; j++)
+ *row++ = zstencil;
+ dst_map += dst_stride;
+ }
+ }
+ else {
+ uint32_t dst_mask;
+ if (dst->format == PIPE_FORMAT_Z24_UNORM_S8_USCALED)
+ dst_mask = 0xffffff00;
+ else {
+ assert(dst->format == PIPE_FORMAT_S8_USCALED_Z24_UNORM);
+ dst_mask = 0xffffff;
+ }
+ if (clear_flags & PIPE_CLEAR_DEPTH)
+ dst_mask = ~dst_mask;
+ for (i = 0; i < height; i++) {
+ uint32_t *row = (uint32_t *)dst_map;
+ for (j = 0; j < width; j++) {
+ uint32_t tmp = *row & dst_mask;
+ *row++ = tmp | (zstencil & ~dst_mask);
+ }
+ dst_map += dst_stride;
+ }
+ }
+ break;
+ case 8:
+ {
+ uint64_t zstencil = util_pack64_z_stencil(dst->texture->format,
+ depth, stencil);
+
+ assert(dst->format == PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED);
+
+ if (!need_rmw) {
+ for (i = 0; i < height; i++) {
+ uint64_t *row = (uint64_t *)dst_map;
+ for (j = 0; j < width; j++)
+ *row++ = zstencil;
+ dst_map += dst_stride;
+ }
+ }
+ else {
+ uint64_t src_mask;
+
+ if (clear_flags & PIPE_CLEAR_DEPTH)
+ src_mask = 0x00000000ffffffffull;
+ else
+ src_mask = 0x000000ff00000000ull;
+
+ for (i = 0; i < height; i++) {
+ uint64_t *row = (uint64_t *)dst_map;
+ for (j = 0; j < width; j++) {
+ uint64_t tmp = *row & ~src_mask;
+ *row++ = tmp | (zstencil & src_mask);
+ }
+ dst_map += dst_stride;
+ }
+ }
+ break;
+ }
+ default:
+ assert(0);
+ break;
+ }
+ }
+
+ pipe->transfer_unmap(pipe, dst_trans);
+ pipe->transfer_destroy(pipe, dst_trans);
+}
diff --git a/mesalib/src/gallium/auxiliary/util/u_tile.c b/mesalib/src/gallium/auxiliary/util/u_tile.c
index 54f634948..23f12e5f4 100644
--- a/mesalib/src/gallium/auxiliary/util/u_tile.c
+++ b/mesalib/src/gallium/auxiliary/util/u_tile.c
@@ -1,655 +1,690 @@
-/**************************************************************************
- *
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-/**
- * RGBA/float tile get/put functions.
- * Usable both by drivers and state trackers.
- */
-
-
-#include "pipe/p_defines.h"
-#include "util/u_inlines.h"
-
-#include "util/u_format.h"
-#include "util/u_math.h"
-#include "util/u_memory.h"
-#include "util/u_rect.h"
-#include "util/u_tile.h"
-
-
-/**
- * Move raw block of pixels from transfer object to user memory.
- */
-void
-pipe_get_tile_raw(struct pipe_context *pipe,
- struct pipe_transfer *pt,
- uint x, uint y, uint w, uint h,
- void *dst, int dst_stride)
-{
- const void *src;
-
- if (dst_stride == 0)
- dst_stride = util_format_get_stride(pt->resource->format, w);
-
- if (u_clip_tile(x, y, &w, &h, &pt->box))
- return;
-
- src = pipe->transfer_map(pipe, pt);
- assert(src);
- if(!src)
- return;
-
- util_copy_rect(dst, pt->resource->format, dst_stride, 0, 0, w, h, src, pt->stride, x, y);
-
- pipe->transfer_unmap(pipe, pt);
-}
-
-
-/**
- * Move raw block of pixels from user memory to transfer object.
- */
-void
-pipe_put_tile_raw(struct pipe_context *pipe,
- struct pipe_transfer *pt,
- uint x, uint y, uint w, uint h,
- const void *src, int src_stride)
-{
- void *dst;
- enum pipe_format format = pt->resource->format;
-
- if (src_stride == 0)
- src_stride = util_format_get_stride(format, w);
-
- if (u_clip_tile(x, y, &w, &h, &pt->box))
- return;
-
- dst = pipe->transfer_map(pipe, pt);
- assert(dst);
- if(!dst)
- return;
-
- util_copy_rect(dst, format, pt->stride, x, y, w, h, src, src_stride, 0, 0);
-
- pipe->transfer_unmap(pipe, pt);
-}
-
-
-
-
-/** Convert short in [-32768,32767] to GLfloat in [-1.0,1.0] */
-#define SHORT_TO_FLOAT(S) ((2.0F * (S) + 1.0F) * (1.0F/65535.0F))
-
-#define UNCLAMPED_FLOAT_TO_SHORT(us, f) \
- us = ( (short) ( CLAMP((f), -1.0, 1.0) * 32767.0F) )
-
-
-
-/*** PIPE_FORMAT_Z16_UNORM ***/
-
-/**
- * Return each Z value as four floats in [0,1].
- */
-static void
-z16_get_tile_rgba(const ushort *src,
- unsigned w, unsigned h,
- float *p,
- unsigned dst_stride)
-{
- const float scale = 1.0f / 65535.0f;
- unsigned i, j;
-
- for (i = 0; i < h; i++) {
- float *pRow = p;
- for (j = 0; j < w; j++, pRow += 4) {
- pRow[0] =
- pRow[1] =
- pRow[2] =
- pRow[3] = *src++ * scale;
- }
- p += dst_stride;
- }
-}
-
-
-
-
-/*** PIPE_FORMAT_Z32_UNORM ***/
-
-/**
- * Return each Z value as four floats in [0,1].
- */
-static void
-z32_get_tile_rgba(const unsigned *src,
- unsigned w, unsigned h,
- float *p,
- unsigned dst_stride)
-{
- const double scale = 1.0 / (double) 0xffffffff;
- unsigned i, j;
-
- for (i = 0; i < h; i++) {
- float *pRow = p;
- for (j = 0; j < w; j++, pRow += 4) {
- pRow[0] =
- pRow[1] =
- pRow[2] =
- pRow[3] = (float) (*src++ * scale);
- }
- p += dst_stride;
- }
-}
-
-
-/*** PIPE_FORMAT_Z24_UNORM_S8_USCALED ***/
-
-/**
- * Return Z component as four float in [0,1]. Stencil part ignored.
- */
-static void
-s8z24_get_tile_rgba(const unsigned *src,
- unsigned w, unsigned h,
- float *p,
- unsigned dst_stride)
-{
- const double scale = 1.0 / ((1 << 24) - 1);
- unsigned i, j;
-
- for (i = 0; i < h; i++) {
- float *pRow = p;
- for (j = 0; j < w; j++, pRow += 4) {
- pRow[0] =
- pRow[1] =
- pRow[2] =
- pRow[3] = (float) (scale * (*src++ & 0xffffff));
- }
- p += dst_stride;
- }
-}
-
-
-/*** PIPE_FORMAT_S8_USCALED_Z24_UNORM ***/
-
-/**
- * Return Z component as four float in [0,1]. Stencil part ignored.
- */
-static void
-z24s8_get_tile_rgba(const unsigned *src,
- unsigned w, unsigned h,
- float *p,
- unsigned dst_stride)
-{
- const double scale = 1.0 / ((1 << 24) - 1);
- unsigned i, j;
-
- for (i = 0; i < h; i++) {
- float *pRow = p;
- for (j = 0; j < w; j++, pRow += 4) {
- pRow[0] =
- pRow[1] =
- pRow[2] =
- pRow[3] = (float) (scale * (*src++ >> 8));
- }
- p += dst_stride;
- }
-}
-
-/*** PIPE_FORMAT_S8X24_USCALED ***/
-
-/**
- * Return S component as four uint32_t in [0..255]. Z part ignored.
- */
-static void
-s8x24_get_tile_rgba(const unsigned *src,
- unsigned w, unsigned h,
- float *p,
- unsigned dst_stride)
-{
- unsigned i, j;
-
- for (i = 0; i < h; i++) {
- float *pRow = p;
-
- for (j = 0; j < w; j++, pRow += 4) {
- pRow[0] =
- pRow[1] =
- pRow[2] =
- pRow[3] = (float)((*src++ >> 24) & 0xff);
- }
-
- p += dst_stride;
- }
-}
-
-/*** PIPE_FORMAT_X24S8_USCALED ***/
-
-/**
- * Return S component as four uint32_t in [0..255]. Z part ignored.
- */
-static void
-x24s8_get_tile_rgba(const unsigned *src,
- unsigned w, unsigned h,
- float *p,
- unsigned dst_stride)
-{
- unsigned i, j;
-
- for (i = 0; i < h; i++) {
- float *pRow = p;
- for (j = 0; j < w; j++, pRow += 4) {
- pRow[0] =
- pRow[1] =
- pRow[2] =
- pRow[3] = (float)(*src++ & 0xff);
- }
- p += dst_stride;
- }
-}
-
-
-/**
- * Return S component as four uint32_t in [0..255]. Z part ignored.
- */
-static void
-s8_get_tile_rgba(const unsigned char *src,
- unsigned w, unsigned h,
- float *p,
- unsigned dst_stride)
-{
- unsigned i, j;
-
- for (i = 0; i < h; i++) {
- float *pRow = p;
- for (j = 0; j < w; j++, pRow += 4) {
- pRow[0] =
- pRow[1] =
- pRow[2] =
- pRow[3] = (float)(*src++ & 0xff);
- }
- p += dst_stride;
- }
-}
-
-/*** PIPE_FORMAT_Z32_FLOAT ***/
-
-/**
- * Return each Z value as four floats in [0,1].
- */
-static void
-z32f_get_tile_rgba(const float *src,
- unsigned w, unsigned h,
- float *p,
- unsigned dst_stride)
-{
- unsigned i, j;
-
- for (i = 0; i < h; i++) {
- float *pRow = p;
- for (j = 0; j < w; j++, pRow += 4) {
- pRow[0] =
- pRow[1] =
- pRow[2] =
- pRow[3] = *src++;
- }
- p += dst_stride;
- }
-}
-
-
-void
-pipe_tile_raw_to_rgba(enum pipe_format format,
- void *src,
- uint w, uint h,
- float *dst, unsigned dst_stride)
-{
- switch (format) {
- case PIPE_FORMAT_Z16_UNORM:
- z16_get_tile_rgba((ushort *) src, w, h, dst, dst_stride);
- break;
- case PIPE_FORMAT_Z32_UNORM:
- z32_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
- break;
- case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
- case PIPE_FORMAT_Z24X8_UNORM:
- s8z24_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
- break;
- case PIPE_FORMAT_S8_USCALED:
- s8_get_tile_rgba((unsigned char *) src, w, h, dst, dst_stride);
- break;
- case PIPE_FORMAT_X24S8_USCALED:
- s8x24_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
- break;
- case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
- case PIPE_FORMAT_X8Z24_UNORM:
- z24s8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
- break;
- case PIPE_FORMAT_S8X24_USCALED:
- x24s8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
- break;
- case PIPE_FORMAT_Z32_FLOAT:
- z32f_get_tile_rgba((float *) src, w, h, dst, dst_stride);
- break;
- default:
- util_format_read_4f(format,
- dst, dst_stride * sizeof(float),
- src, util_format_get_stride(format, w),
- 0, 0, w, h);
- }
-}
-
-
-void
-pipe_get_tile_rgba(struct pipe_context *pipe,
- struct pipe_transfer *pt,
- uint x, uint y, uint w, uint h,
- float *p)
-{
- pipe_get_tile_rgba_format(pipe, pt, x, y, w, h, pt->resource->format, p);
-}
-
-
-void
-pipe_get_tile_rgba_format(struct pipe_context *pipe,
- struct pipe_transfer *pt,
- uint x, uint y, uint w, uint h,
- enum pipe_format format,
- float *p)
-{
- unsigned dst_stride = w * 4;
- void *packed;
-
- if (u_clip_tile(x, y, &w, &h, &pt->box)) {
- return;
- }
-
- packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
- if (!packed) {
- return;
- }
-
- if (format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) {
- assert((x & 1) == 0);
- }
-
- pipe_get_tile_raw(pipe, pt, x, y, w, h, packed, 0);
-
- pipe_tile_raw_to_rgba(format, packed, w, h, p, dst_stride);
-
- FREE(packed);
-}
-
-
-void
-pipe_put_tile_rgba(struct pipe_context *pipe,
- struct pipe_transfer *pt,
- uint x, uint y, uint w, uint h,
- const float *p)
-{
- pipe_put_tile_rgba_format(pipe, pt, x, y, w, h, pt->resource->format, p);
-}
-
-
-void
-pipe_put_tile_rgba_format(struct pipe_context *pipe,
- struct pipe_transfer *pt,
- uint x, uint y, uint w, uint h,
- enum pipe_format format,
- const float *p)
-{
- unsigned src_stride = w * 4;
- void *packed;
-
- if (u_clip_tile(x, y, &w, &h, &pt->box))
- return;
-
- packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
-
- if (!packed)
- return;
-
- switch (format) {
- case PIPE_FORMAT_Z16_UNORM:
- /*z16_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
- break;
- case PIPE_FORMAT_Z32_UNORM:
- /*z32_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
- break;
- case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
- case PIPE_FORMAT_Z24X8_UNORM:
- /*s8z24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
- break;
- case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
- case PIPE_FORMAT_X8Z24_UNORM:
- /*z24s8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
- break;
- default:
- util_format_write_4f(format,
- p, src_stride * sizeof(float),
- packed, util_format_get_stride(format, w),
- 0, 0, w, h);
- }
-
- pipe_put_tile_raw(pipe, pt, x, y, w, h, packed, 0);
-
- FREE(packed);
-}
-
-
-/**
- * Get a block of Z values, converted to 32-bit range.
- */
-void
-pipe_get_tile_z(struct pipe_context *pipe,
- struct pipe_transfer *pt,
- uint x, uint y, uint w, uint h,
- uint *z)
-{
- const uint dstStride = w;
- ubyte *map;
- uint *pDest = z;
- uint i, j;
- enum pipe_format format = pt->resource->format;
-
- if (u_clip_tile(x, y, &w, &h, &pt->box))
- return;
-
- map = (ubyte *)pipe->transfer_map(pipe, pt);
- if (!map) {
- assert(0);
- return;
- }
-
- switch (format) {
- case PIPE_FORMAT_Z32_UNORM:
- {
- const uint *ptrc
- = (const uint *)(map + y * pt->stride + x*4);
- for (i = 0; i < h; i++) {
- memcpy(pDest, ptrc, 4 * w);
- pDest += dstStride;
- ptrc += pt->stride/4;
- }
- }
- break;
- case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
- case PIPE_FORMAT_Z24X8_UNORM:
- {
- const uint *ptrc
- = (const uint *)(map + y * pt->stride + x*4);
- for (i = 0; i < h; i++) {
- for (j = 0; j < w; j++) {
- /* convert 24-bit Z to 32-bit Z */
- pDest[j] = (ptrc[j] << 8) | ((ptrc[j] >> 16) & 0xff);
- }
- pDest += dstStride;
- ptrc += pt->stride/4;
- }
- }
- break;
- case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
- case PIPE_FORMAT_X8Z24_UNORM:
- {
- const uint *ptrc
- = (const uint *)(map + y * pt->stride + x*4);
- for (i = 0; i < h; i++) {
- for (j = 0; j < w; j++) {
- /* convert 24-bit Z to 32-bit Z */
- pDest[j] = (ptrc[j] & 0xffffff00) | ((ptrc[j] >> 24) & 0xff);
- }
- pDest += dstStride;
- ptrc += pt->stride/4;
- }
- }
- break;
- case PIPE_FORMAT_Z16_UNORM:
- {
- const ushort *ptrc
- = (const ushort *)(map + y * pt->stride + x*2);
- for (i = 0; i < h; i++) {
- for (j = 0; j < w; j++) {
- /* convert 16-bit Z to 32-bit Z */
- pDest[j] = (ptrc[j] << 16) | ptrc[j];
- }
- pDest += dstStride;
- ptrc += pt->stride/2;
- }
- }
- break;
- default:
- assert(0);
- }
-
- pipe->transfer_unmap(pipe, pt);
-}
-
-
-void
-pipe_put_tile_z(struct pipe_context *pipe,
- struct pipe_transfer *pt,
- uint x, uint y, uint w, uint h,
- const uint *zSrc)
-{
- const uint srcStride = w;
- const uint *ptrc = zSrc;
- ubyte *map;
- uint i, j;
- enum pipe_format format = pt->resource->format;
-
- if (u_clip_tile(x, y, &w, &h, &pt->box))
- return;
-
- map = (ubyte *)pipe->transfer_map(pipe, pt);
- if (!map) {
- assert(0);
- return;
- }
-
- switch (format) {
- case PIPE_FORMAT_Z32_UNORM:
- {
- uint *pDest = (uint *) (map + y * pt->stride + x*4);
- for (i = 0; i < h; i++) {
- memcpy(pDest, ptrc, 4 * w);
- pDest += pt->stride/4;
- ptrc += srcStride;
- }
- }
- break;
- case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
- {
- uint *pDest = (uint *) (map + y * pt->stride + x*4);
- /*assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);*/
- for (i = 0; i < h; i++) {
- for (j = 0; j < w; j++) {
- /* convert 32-bit Z to 24-bit Z, preserve stencil */
- pDest[j] = (pDest[j] & 0xff000000) | ptrc[j] >> 8;
- }
- pDest += pt->stride/4;
- ptrc += srcStride;
- }
- }
- break;
- case PIPE_FORMAT_Z24X8_UNORM:
- {
- uint *pDest = (uint *) (map + y * pt->stride + x*4);
- for (i = 0; i < h; i++) {
- for (j = 0; j < w; j++) {
- /* convert 32-bit Z to 24-bit Z (0 stencil) */
- pDest[j] = ptrc[j] >> 8;
- }
- pDest += pt->stride/4;
- ptrc += srcStride;
- }
- }
- break;
- case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
- {
- uint *pDest = (uint *) (map + y * pt->stride + x*4);
- /*assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);*/
- for (i = 0; i < h; i++) {
- for (j = 0; j < w; j++) {
- /* convert 32-bit Z to 24-bit Z, preserve stencil */
- pDest[j] = (pDest[j] & 0xff) | (ptrc[j] & 0xffffff00);
- }
- pDest += pt->stride/4;
- ptrc += srcStride;
- }
- }
- break;
- case PIPE_FORMAT_X8Z24_UNORM:
- {
- uint *pDest = (uint *) (map + y * pt->stride + x*4);
- for (i = 0; i < h; i++) {
- for (j = 0; j < w; j++) {
- /* convert 32-bit Z to 24-bit Z (0 stencil) */
- pDest[j] = ptrc[j] & 0xffffff00;
- }
- pDest += pt->stride/4;
- ptrc += srcStride;
- }
- }
- break;
- case PIPE_FORMAT_Z16_UNORM:
- {
- ushort *pDest = (ushort *) (map + y * pt->stride + x*2);
- for (i = 0; i < h; i++) {
- for (j = 0; j < w; j++) {
- /* convert 32-bit Z to 16-bit Z */
- pDest[j] = ptrc[j] >> 16;
- }
- pDest += pt->stride/2;
- ptrc += srcStride;
- }
- }
- break;
- default:
- assert(0);
- }
-
- pipe->transfer_unmap(pipe, pt);
-}
-
-
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/**
+ * RGBA/float tile get/put functions.
+ * Usable both by drivers and state trackers.
+ */
+
+
+#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
+
+#include "util/u_format.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
+#include "util/u_rect.h"
+#include "util/u_tile.h"
+
+
+/**
+ * Move raw block of pixels from transfer object to user memory.
+ */
+void
+pipe_get_tile_raw(struct pipe_context *pipe,
+ struct pipe_transfer *pt,
+ uint x, uint y, uint w, uint h,
+ void *dst, int dst_stride)
+{
+ const void *src;
+
+ if (dst_stride == 0)
+ dst_stride = util_format_get_stride(pt->resource->format, w);
+
+ if (u_clip_tile(x, y, &w, &h, &pt->box))
+ return;
+
+ src = pipe->transfer_map(pipe, pt);
+ assert(src);
+ if(!src)
+ return;
+
+ util_copy_rect(dst, pt->resource->format, dst_stride, 0, 0, w, h, src, pt->stride, x, y);
+
+ pipe->transfer_unmap(pipe, pt);
+}
+
+
+/**
+ * Move raw block of pixels from user memory to transfer object.
+ */
+void
+pipe_put_tile_raw(struct pipe_context *pipe,
+ struct pipe_transfer *pt,
+ uint x, uint y, uint w, uint h,
+ const void *src, int src_stride)
+{
+ void *dst;
+ enum pipe_format format = pt->resource->format;
+
+ if (src_stride == 0)
+ src_stride = util_format_get_stride(format, w);
+
+ if (u_clip_tile(x, y, &w, &h, &pt->box))
+ return;
+
+ dst = pipe->transfer_map(pipe, pt);
+ assert(dst);
+ if(!dst)
+ return;
+
+ util_copy_rect(dst, format, pt->stride, x, y, w, h, src, src_stride, 0, 0);
+
+ pipe->transfer_unmap(pipe, pt);
+}
+
+
+
+
+/** Convert short in [-32768,32767] to GLfloat in [-1.0,1.0] */
+#define SHORT_TO_FLOAT(S) ((2.0F * (S) + 1.0F) * (1.0F/65535.0F))
+
+#define UNCLAMPED_FLOAT_TO_SHORT(us, f) \
+ us = ( (short) ( CLAMP((f), -1.0, 1.0) * 32767.0F) )
+
+
+
+/*** PIPE_FORMAT_Z16_UNORM ***/
+
+/**
+ * Return each Z value as four floats in [0,1].
+ */
+static void
+z16_get_tile_rgba(const ushort *src,
+ unsigned w, unsigned h,
+ float *p,
+ unsigned dst_stride)
+{
+ const float scale = 1.0f / 65535.0f;
+ unsigned i, j;
+
+ for (i = 0; i < h; i++) {
+ float *pRow = p;
+ for (j = 0; j < w; j++, pRow += 4) {
+ pRow[0] =
+ pRow[1] =
+ pRow[2] =
+ pRow[3] = *src++ * scale;
+ }
+ p += dst_stride;
+ }
+}
+
+
+
+
+/*** PIPE_FORMAT_Z32_UNORM ***/
+
+/**
+ * Return each Z value as four floats in [0,1].
+ */
+static void
+z32_get_tile_rgba(const unsigned *src,
+ unsigned w, unsigned h,
+ float *p,
+ unsigned dst_stride)
+{
+ const double scale = 1.0 / (double) 0xffffffff;
+ unsigned i, j;
+
+ for (i = 0; i < h; i++) {
+ float *pRow = p;
+ for (j = 0; j < w; j++, pRow += 4) {
+ pRow[0] =
+ pRow[1] =
+ pRow[2] =
+ pRow[3] = (float) (*src++ * scale);
+ }
+ p += dst_stride;
+ }
+}
+
+
+/*** PIPE_FORMAT_Z24_UNORM_S8_USCALED ***/
+
+/**
+ * Return Z component as four float in [0,1]. Stencil part ignored.
+ */
+static void
+s8z24_get_tile_rgba(const unsigned *src,
+ unsigned w, unsigned h,
+ float *p,
+ unsigned dst_stride)
+{
+ const double scale = 1.0 / ((1 << 24) - 1);
+ unsigned i, j;
+
+ for (i = 0; i < h; i++) {
+ float *pRow = p;
+ for (j = 0; j < w; j++, pRow += 4) {
+ pRow[0] =
+ pRow[1] =
+ pRow[2] =
+ pRow[3] = (float) (scale * (*src++ & 0xffffff));
+ }
+ p += dst_stride;
+ }
+}
+
+
+/*** PIPE_FORMAT_S8_USCALED_Z24_UNORM ***/
+
+/**
+ * Return Z component as four float in [0,1]. Stencil part ignored.
+ */
+static void
+z24s8_get_tile_rgba(const unsigned *src,
+ unsigned w, unsigned h,
+ float *p,
+ unsigned dst_stride)
+{
+ const double scale = 1.0 / ((1 << 24) - 1);
+ unsigned i, j;
+
+ for (i = 0; i < h; i++) {
+ float *pRow = p;
+ for (j = 0; j < w; j++, pRow += 4) {
+ pRow[0] =
+ pRow[1] =
+ pRow[2] =
+ pRow[3] = (float) (scale * (*src++ >> 8));
+ }
+ p += dst_stride;
+ }
+}
+
+/*** PIPE_FORMAT_S8X24_USCALED ***/
+
+/**
+ * Return S component as four uint32_t in [0..255]. Z part ignored.
+ */
+static void
+s8x24_get_tile_rgba(const unsigned *src,
+ unsigned w, unsigned h,
+ float *p,
+ unsigned dst_stride)
+{
+ unsigned i, j;
+
+ for (i = 0; i < h; i++) {
+ float *pRow = p;
+
+ for (j = 0; j < w; j++, pRow += 4) {
+ pRow[0] =
+ pRow[1] =
+ pRow[2] =
+ pRow[3] = (float)((*src++ >> 24) & 0xff);
+ }
+
+ p += dst_stride;
+ }
+}
+
+/*** PIPE_FORMAT_X24S8_USCALED ***/
+
+/**
+ * Return S component as four uint32_t in [0..255]. Z part ignored.
+ */
+static void
+x24s8_get_tile_rgba(const unsigned *src,
+ unsigned w, unsigned h,
+ float *p,
+ unsigned dst_stride)
+{
+ unsigned i, j;
+
+ for (i = 0; i < h; i++) {
+ float *pRow = p;
+ for (j = 0; j < w; j++, pRow += 4) {
+ pRow[0] =
+ pRow[1] =
+ pRow[2] =
+ pRow[3] = (float)(*src++ & 0xff);
+ }
+ p += dst_stride;
+ }
+}
+
+
+/**
+ * Return S component as four uint32_t in [0..255]. Z part ignored.
+ */
+static void
+s8_get_tile_rgba(const unsigned char *src,
+ unsigned w, unsigned h,
+ float *p,
+ unsigned dst_stride)
+{
+ unsigned i, j;
+
+ for (i = 0; i < h; i++) {
+ float *pRow = p;
+ for (j = 0; j < w; j++, pRow += 4) {
+ pRow[0] =
+ pRow[1] =
+ pRow[2] =
+ pRow[3] = (float)(*src++ & 0xff);
+ }
+ p += dst_stride;
+ }
+}
+
+/*** PIPE_FORMAT_Z32_FLOAT ***/
+
+/**
+ * Return each Z value as four floats in [0,1].
+ */
+static void
+z32f_get_tile_rgba(const float *src,
+ unsigned w, unsigned h,
+ float *p,
+ unsigned dst_stride)
+{
+ unsigned i, j;
+
+ for (i = 0; i < h; i++) {
+ float *pRow = p;
+ for (j = 0; j < w; j++, pRow += 4) {
+ pRow[0] =
+ pRow[1] =
+ pRow[2] =
+ pRow[3] = *src++;
+ }
+ p += dst_stride;
+ }
+}
+
+/*** PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED ***/
+
+/**
+ * Return each Z value as four floats in [0,1].
+ */
+static void
+z32f_x24s8_get_tile_rgba(const float *src,
+ unsigned w, unsigned h,
+ float *p,
+ unsigned dst_stride)
+{
+ unsigned i, j;
+
+ for (i = 0; i < h; i++) {
+ float *pRow = p;
+ for (j = 0; j < w; j++, pRow += 4) {
+ pRow[0] =
+ pRow[1] =
+ pRow[2] =
+ pRow[3] = *src;
+ src += 2;
+ }
+ p += dst_stride;
+ }
+}
+
+
+void
+pipe_tile_raw_to_rgba(enum pipe_format format,
+ void *src,
+ uint w, uint h,
+ float *dst, unsigned dst_stride)
+{
+ switch (format) {
+ case PIPE_FORMAT_Z16_UNORM:
+ z16_get_tile_rgba((ushort *) src, w, h, dst, dst_stride);
+ break;
+ case PIPE_FORMAT_Z32_UNORM:
+ z32_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
+ break;
+ case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
+ case PIPE_FORMAT_Z24X8_UNORM:
+ s8z24_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
+ break;
+ case PIPE_FORMAT_S8_USCALED:
+ s8_get_tile_rgba((unsigned char *) src, w, h, dst, dst_stride);
+ break;
+ case PIPE_FORMAT_X24S8_USCALED:
+ s8x24_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
+ break;
+ case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
+ case PIPE_FORMAT_X8Z24_UNORM:
+ z24s8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
+ break;
+ case PIPE_FORMAT_S8X24_USCALED:
+ x24s8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
+ break;
+ case PIPE_FORMAT_Z32_FLOAT:
+ z32f_get_tile_rgba((float *) src, w, h, dst, dst_stride);
+ break;
+ case PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED:
+ z32f_x24s8_get_tile_rgba((float *) src, w, h, dst, dst_stride);
+ break;
+ default:
+ util_format_read_4f(format,
+ dst, dst_stride * sizeof(float),
+ src, util_format_get_stride(format, w),
+ 0, 0, w, h);
+ }
+}
+
+
+void
+pipe_get_tile_rgba(struct pipe_context *pipe,
+ struct pipe_transfer *pt,
+ uint x, uint y, uint w, uint h,
+ float *p)
+{
+ pipe_get_tile_rgba_format(pipe, pt, x, y, w, h, pt->resource->format, p);
+}
+
+
+void
+pipe_get_tile_rgba_format(struct pipe_context *pipe,
+ struct pipe_transfer *pt,
+ uint x, uint y, uint w, uint h,
+ enum pipe_format format,
+ float *p)
+{
+ unsigned dst_stride = w * 4;
+ void *packed;
+
+ if (u_clip_tile(x, y, &w, &h, &pt->box)) {
+ return;
+ }
+
+ packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
+ if (!packed) {
+ return;
+ }
+
+ if (format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) {
+ assert((x & 1) == 0);
+ }
+
+ pipe_get_tile_raw(pipe, pt, x, y, w, h, packed, 0);
+
+ pipe_tile_raw_to_rgba(format, packed, w, h, p, dst_stride);
+
+ FREE(packed);
+}
+
+
+void
+pipe_put_tile_rgba(struct pipe_context *pipe,
+ struct pipe_transfer *pt,
+ uint x, uint y, uint w, uint h,
+ const float *p)
+{
+ pipe_put_tile_rgba_format(pipe, pt, x, y, w, h, pt->resource->format, p);
+}
+
+
+void
+pipe_put_tile_rgba_format(struct pipe_context *pipe,
+ struct pipe_transfer *pt,
+ uint x, uint y, uint w, uint h,
+ enum pipe_format format,
+ const float *p)
+{
+ unsigned src_stride = w * 4;
+ void *packed;
+
+ if (u_clip_tile(x, y, &w, &h, &pt->box))
+ return;
+
+ packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
+
+ if (!packed)
+ return;
+
+ switch (format) {
+ case PIPE_FORMAT_Z16_UNORM:
+ /*z16_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
+ break;
+ case PIPE_FORMAT_Z32_UNORM:
+ /*z32_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
+ break;
+ case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
+ case PIPE_FORMAT_Z24X8_UNORM:
+ /*s8z24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
+ break;
+ case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
+ case PIPE_FORMAT_X8Z24_UNORM:
+ /*z24s8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
+ break;
+ case PIPE_FORMAT_Z32_FLOAT:
+ /*z32f_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
+ break;
+ case PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED:
+ /*z32f_s8x24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
+ break;
+ default:
+ util_format_write_4f(format,
+ p, src_stride * sizeof(float),
+ packed, util_format_get_stride(format, w),
+ 0, 0, w, h);
+ }
+
+ pipe_put_tile_raw(pipe, pt, x, y, w, h, packed, 0);
+
+ FREE(packed);
+}
+
+
+/**
+ * Get a block of Z values, converted to 32-bit range.
+ */
+void
+pipe_get_tile_z(struct pipe_context *pipe,
+ struct pipe_transfer *pt,
+ uint x, uint y, uint w, uint h,
+ uint *z)
+{
+ const uint dstStride = w;
+ ubyte *map;
+ uint *pDest = z;
+ uint i, j;
+ enum pipe_format format = pt->resource->format;
+
+ if (u_clip_tile(x, y, &w, &h, &pt->box))
+ return;
+
+ map = (ubyte *)pipe->transfer_map(pipe, pt);
+ if (!map) {
+ assert(0);
+ return;
+ }
+
+ switch (format) {
+ case PIPE_FORMAT_Z32_UNORM:
+ {
+ const uint *ptrc
+ = (const uint *)(map + y * pt->stride + x*4);
+ for (i = 0; i < h; i++) {
+ memcpy(pDest, ptrc, 4 * w);
+ pDest += dstStride;
+ ptrc += pt->stride/4;
+ }
+ }
+ break;
+ case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
+ case PIPE_FORMAT_Z24X8_UNORM:
+ {
+ const uint *ptrc
+ = (const uint *)(map + y * pt->stride + x*4);
+ for (i = 0; i < h; i++) {
+ for (j = 0; j < w; j++) {
+ /* convert 24-bit Z to 32-bit Z */
+ pDest[j] = (ptrc[j] << 8) | ((ptrc[j] >> 16) & 0xff);
+ }
+ pDest += dstStride;
+ ptrc += pt->stride/4;
+ }
+ }
+ break;
+ case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
+ case PIPE_FORMAT_X8Z24_UNORM:
+ {
+ const uint *ptrc
+ = (const uint *)(map + y * pt->stride + x*4);
+ for (i = 0; i < h; i++) {
+ for (j = 0; j < w; j++) {
+ /* convert 24-bit Z to 32-bit Z */
+ pDest[j] = (ptrc[j] & 0xffffff00) | ((ptrc[j] >> 24) & 0xff);
+ }
+ pDest += dstStride;
+ ptrc += pt->stride/4;
+ }
+ }
+ break;
+ case PIPE_FORMAT_Z16_UNORM:
+ {
+ const ushort *ptrc
+ = (const ushort *)(map + y * pt->stride + x*2);
+ for (i = 0; i < h; i++) {
+ for (j = 0; j < w; j++) {
+ /* convert 16-bit Z to 32-bit Z */
+ pDest[j] = (ptrc[j] << 16) | ptrc[j];
+ }
+ pDest += dstStride;
+ ptrc += pt->stride/2;
+ }
+ }
+ break;
+ default:
+ assert(0);
+ }
+
+ pipe->transfer_unmap(pipe, pt);
+}
+
+
+void
+pipe_put_tile_z(struct pipe_context *pipe,
+ struct pipe_transfer *pt,
+ uint x, uint y, uint w, uint h,
+ const uint *zSrc)
+{
+ const uint srcStride = w;
+ const uint *ptrc = zSrc;
+ ubyte *map;
+ uint i, j;
+ enum pipe_format format = pt->resource->format;
+
+ if (u_clip_tile(x, y, &w, &h, &pt->box))
+ return;
+
+ map = (ubyte *)pipe->transfer_map(pipe, pt);
+ if (!map) {
+ assert(0);
+ return;
+ }
+
+ switch (format) {
+ case PIPE_FORMAT_Z32_UNORM:
+ {
+ uint *pDest = (uint *) (map + y * pt->stride + x*4);
+ for (i = 0; i < h; i++) {
+ memcpy(pDest, ptrc, 4 * w);
+ pDest += pt->stride/4;
+ ptrc += srcStride;
+ }
+ }
+ break;
+ case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
+ {
+ uint *pDest = (uint *) (map + y * pt->stride + x*4);
+ /*assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);*/
+ for (i = 0; i < h; i++) {
+ for (j = 0; j < w; j++) {
+ /* convert 32-bit Z to 24-bit Z, preserve stencil */
+ pDest[j] = (pDest[j] & 0xff000000) | ptrc[j] >> 8;
+ }
+ pDest += pt->stride/4;
+ ptrc += srcStride;
+ }
+ }
+ break;
+ case PIPE_FORMAT_Z24X8_UNORM:
+ {
+ uint *pDest = (uint *) (map + y * pt->stride + x*4);
+ for (i = 0; i < h; i++) {
+ for (j = 0; j < w; j++) {
+ /* convert 32-bit Z to 24-bit Z (0 stencil) */
+ pDest[j] = ptrc[j] >> 8;
+ }
+ pDest += pt->stride/4;
+ ptrc += srcStride;
+ }
+ }
+ break;
+ case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
+ {
+ uint *pDest = (uint *) (map + y * pt->stride + x*4);
+ /*assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);*/
+ for (i = 0; i < h; i++) {
+ for (j = 0; j < w; j++) {
+ /* convert 32-bit Z to 24-bit Z, preserve stencil */
+ pDest[j] = (pDest[j] & 0xff) | (ptrc[j] & 0xffffff00);
+ }
+ pDest += pt->stride/4;
+ ptrc += srcStride;
+ }
+ }
+ break;
+ case PIPE_FORMAT_X8Z24_UNORM:
+ {
+ uint *pDest = (uint *) (map + y * pt->stride + x*4);
+ for (i = 0; i < h; i++) {
+ for (j = 0; j < w; j++) {
+ /* convert 32-bit Z to 24-bit Z (0 stencil) */
+ pDest[j] = ptrc[j] & 0xffffff00;
+ }
+ pDest += pt->stride/4;
+ ptrc += srcStride;
+ }
+ }
+ break;
+ case PIPE_FORMAT_Z16_UNORM:
+ {
+ ushort *pDest = (ushort *) (map + y * pt->stride + x*2);
+ for (i = 0; i < h; i++) {
+ for (j = 0; j < w; j++) {
+ /* convert 32-bit Z to 16-bit Z */
+ pDest[j] = ptrc[j] >> 16;
+ }
+ pDest += pt->stride/2;
+ ptrc += srcStride;
+ }
+ }
+ break;
+ default:
+ assert(0);
+ }
+
+ pipe->transfer_unmap(pipe, pt);
+}
+
+