util: Move p_debug.h into util module.
authorJosé Fonseca <jfonseca@vmware.com>
Wed, 18 Feb 2009 12:05:26 +0000 (12:05 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Wed, 18 Feb 2009 12:05:26 +0000 (12:05 +0000)
The debug functions depend on several util function for os abstractions, and
these depend on debug functions, so a seperate module is not possible.

77 files changed:
src/gallium/auxiliary/cso_cache/cso_cache.c
src/gallium/auxiliary/cso_cache/cso_hash.c
src/gallium/auxiliary/draw/draw_pipe_vbuf.c
src/gallium/auxiliary/draw/draw_vs_aos.c
src/gallium/auxiliary/gallivm/storagesoa.cpp
src/gallium/auxiliary/indices/u_indices_gen.c
src/gallium/auxiliary/indices/u_indices_gen.py
src/gallium/auxiliary/pipebuffer/pb_buffer.h
src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h
src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_alt.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_fenced.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c
src/gallium/auxiliary/pipebuffer/pb_validate.c
src/gallium/auxiliary/rtasm/rtasm_cpu.c
src/gallium/auxiliary/rtasm/rtasm_execmem.c
src/gallium/auxiliary/rtasm/rtasm_ppc.c
src/gallium/auxiliary/rtasm/rtasm_x86sse.c
src/gallium/auxiliary/tgsi/tgsi_build.c
src/gallium/auxiliary/tgsi/tgsi_dump.c
src/gallium/auxiliary/tgsi/tgsi_dump_c.c
src/gallium/auxiliary/tgsi/tgsi_info.c
src/gallium/auxiliary/tgsi/tgsi_iterate.c
src/gallium/auxiliary/tgsi/tgsi_parse.c
src/gallium/auxiliary/tgsi/tgsi_ppc.c
src/gallium/auxiliary/tgsi/tgsi_sanity.c
src/gallium/auxiliary/tgsi/tgsi_sse2.c
src/gallium/auxiliary/tgsi/tgsi_text.c
src/gallium/auxiliary/tgsi/tgsi_transform.c
src/gallium/auxiliary/tgsi/tgsi_util.c
src/gallium/auxiliary/util/Makefile
src/gallium/auxiliary/util/SConscript
src/gallium/auxiliary/util/p_debug.c [deleted file]
src/gallium/auxiliary/util/p_debug_mem.c [deleted file]
src/gallium/auxiliary/util/p_debug_prof.c [deleted file]
src/gallium/auxiliary/util/u_blit.c
src/gallium/auxiliary/util/u_cache.c
src/gallium/auxiliary/util/u_debug.c [new file with mode: 0644]
src/gallium/auxiliary/util/u_debug.h [new file with mode: 0644]
src/gallium/auxiliary/util/u_debug_memory.c [new file with mode: 0644]
src/gallium/auxiliary/util/u_debug_profile.c [new file with mode: 0644]
src/gallium/auxiliary/util/u_gen_mipmap.c
src/gallium/auxiliary/util/u_handle_table.c
src/gallium/auxiliary/util/u_hash_table.c
src/gallium/auxiliary/util/u_keymap.c
src/gallium/auxiliary/util/u_linear.c
src/gallium/auxiliary/util/u_math.h
src/gallium/auxiliary/util/u_memory.h
src/gallium/auxiliary/util/u_mm.c
src/gallium/auxiliary/util/u_simple_shaders.c
src/gallium/drivers/cell/spu/spu_util.c
src/gallium/drivers/i915simple/i915_debug.c
src/gallium/drivers/i915simple/i915_prim_vbuf.c
src/gallium/drivers/i965simple/brw_eu_debug.c
src/gallium/drivers/nouveau/nouveau_stateobj.h
src/gallium/drivers/nv04/nv04_prim_vbuf.c
src/gallium/drivers/nv10/nv10_prim_vbuf.c
src/gallium/drivers/nv20/nv20_prim_vbuf.c
src/gallium/drivers/r300/r300_chipset.c
src/gallium/drivers/r300/r300_state.c
src/gallium/drivers/trace/tr_context.h
src/gallium/drivers/trace/tr_dump.c
src/gallium/drivers/trace/tr_winsys.h
src/gallium/include/pipe/p_debug.h [deleted file]
src/gallium/include/pipe/p_format.h
src/gallium/state_trackers/wgl/icd/stw_icd.c
src/gallium/state_trackers/wgl/shared/stw_device.c
src/gallium/state_trackers/wgl/shared/stw_pixelformat.c
src/gallium/state_trackers/wgl/wgl/stw_wgl.c
src/gallium/winsys/xlib/xlib_brw_aub.c
src/mesa/state_tracker/st_mesa_to_tgsi.c

index 6b1754ea00230d7da6b431ec79286fcf74e210fe..0bc77a572879c12a1602d2ffca689b64f90e47be 100644 (file)
@@ -28,7 +28,7 @@
 /* Authors:  Zack Rusin <zack@tungstengraphics.com>
  */
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 #include "util/u_memory.h"
 
index 4e7664f9bf0316b49e146857a0f726b71877e022..288cef7b6faea8472a5687dfe36d564cb8c28556 100644 (file)
@@ -30,7 +30,7 @@
   *   Zack Rusin <zack@tungstengraphics.com>
   */
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "util/u_memory.h"
 
 #include "cso_hash.h"
index 9153bc2f8652b81959722b112989e74390577f5c..0c4e9412e2795eb6e01885d360fb12e2a2b72018 100644 (file)
  * \file
  * Vertex buffer drawing stage.
  * 
- * \author José Fonseca <jrfonsec@tungstengraphics.com>
+ * \author Jose Fonseca <jrfonsec@tungstengraphics.com>
  * \author Keith Whitwell <keith@tungstengraphics.com>
  */
 
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
 
index 78d139fd7d7e6baa67c74e16a2338c741df7e1eb..46a36af4180825694ecf9ecbd8d9631c6b4bec0d 100644 (file)
@@ -32,7 +32,7 @@
 #include "util/u_memory.h"
 #include "util/u_math.h"
 #include "pipe/p_shader_tokens.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "tgsi/tgsi_parse.h"
 #include "tgsi/tgsi_util.h"
 #include "tgsi/tgsi_exec.h"
index e1e5cabcf55c842d05f805303a7291bd406c8e90..4984ce985c6c843fa509fda5fff881258a399e96 100644 (file)
@@ -30,7 +30,7 @@
 #include "gallivm_p.h"
 
 #include "pipe/p_shader_tokens.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 #include <llvm/BasicBlock.h>
 #include <llvm/Module.h>
index 4c05b3eedb3763fba90fb01fa57d1ccee8c55d50..3c981e5d7f4a808a51c3f8e4c1707fdf932ca9bb 100644 (file)
@@ -34,7 +34,7 @@
 #include "indices/u_indices.h"
 #include "indices/u_indices_priv.h"
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_defines.h"
 #include "util/u_memory.h"
 
index 0dc58d0cd0ea2a5455465afa6946bd066c0d50d9..af63d099302a411049fb35e455069a4c7a606a41 100644 (file)
@@ -72,7 +72,7 @@ def prolog():
 #include "indices/u_indices.h"
 #include "indices/u_indices_priv.h"
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_defines.h"
 #include "util/u_memory.h"
 
index d8f1f02d681b792f40c8f8fa8200983528767760..e6b0b30ff44e378f2a0addebb9675de6438fe65e 100644 (file)
@@ -45,7 +45,7 @@
 
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_error.h"
 #include "pipe/p_state.h"
 #include "pipe/p_inlines.h"
index f9e62264368e7b83625bb096462f14b678c06564..0cddc95aa67bc127cd28a9fe27506dd79c7cb995 100644 (file)
@@ -43,7 +43,7 @@
 
 #include "pipe/p_compiler.h"
 #include "pipe/p_error.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_thread.h"
 #include "util/u_memory.h"
 #include "util/u_double_list.h"
index d1c9d4c17dff7b4bc4044816146d456eee86d460..c2b29e974b15ce79b028f39bbc4189638736c968 100644 (file)
@@ -51,7 +51,7 @@
 #define PB_BUFFER_FENCED_H_
 
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 
 #ifdef __cplusplus
index 53f497cfb04bee56053a4c320cea016713b3df54..282802b1717067466104aee25c086315269a1a41 100644 (file)
@@ -34,7 +34,7 @@
  */
 
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "util/u_memory.h"
 #include "pb_buffer.h"
 #include "pb_bufmgr.h"
index c956924cc7653df3c72dc9981f3e57baec7a662d..db67d46c56168a89c383e31301234b8e2aaeb9a0 100644 (file)
@@ -34,7 +34,7 @@
 
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "util/u_memory.h"
 
 #include "pb_buffer.h"
index a1688537134b4d983153e09e2cb3526cf622e78b..29117efe9bd3433cacd6e4148059e2abe2899d90 100644 (file)
@@ -35,7 +35,7 @@
 
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_thread.h"
 #include "util/u_memory.h"
 #include "util/u_double_list.h"
index 26d9c24aec22e7c33e7f53cd426c240e3c5c5c5c..070bf3f51736d42151ef9b2037a0d3dd660d1e52 100644 (file)
@@ -34,7 +34,7 @@
 
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_thread.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
index 47e9fee53389049335442fd1557ad31543318f2c..e352f5357b535053beed0db7b813cab3a3fd03a7 100644 (file)
@@ -34,7 +34,7 @@
  */
 
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "util/u_memory.h"
 
 #include "pb_buffer.h"
index 2f5a5d8ea0728e9f4845e335518b3d8bb1f8677f..f3b1ca73b0cbe3389564d1ebfbc0082780d52935 100644 (file)
@@ -34,7 +34,7 @@
 
 
 #include "pipe/p_defines.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_thread.h"
 #include "util/u_memory.h"
 #include "util/u_double_list.h"
index ba02a84e62de0b99ae6a9609205df7884ab6215c..3d9c7bba0ba0cf945051504d4feab5e44c78484b 100644 (file)
@@ -34,7 +34,7 @@
  */
 
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "util/u_memory.h"
 #include "pb_buffer.h"
 #include "pb_bufmgr.h"
index a6ff37653e90e3be9c75891c6a6fde4c38361e50..12447acfd9325890e25ed64a749f76c7d67a017d 100644 (file)
@@ -36,7 +36,7 @@
 
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_thread.h"
 #include "pipe/p_defines.h"
 #include "util/u_memory.h"
index 9b9fedccb4b79e5f2085d44db00f322a006f967a..a3259351b92eb5bdae8548df0ce7d0075a8a902f 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "pipe/p_compiler.h"
 #include "pipe/p_error.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_thread.h"
 #include "pipe/p_defines.h"
 #include "util/u_memory.h"
index 94532bb4cec85978adcfdc140828c90bf85f1c4f..150fd5061812e804387c2aba7589750e5d958414 100644 (file)
@@ -36,7 +36,7 @@
 #include "pipe/p_compiler.h"
 #include "pipe/p_error.h"
 #include "util/u_memory.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 #include "pb_buffer.h"
 #include "pb_buffer_fenced.h"
index 5499018b21934d026dfad9a06e834133630de3f2..03bdd472386f00717057f3ffbc7fe43da8dac09c 100644 (file)
@@ -26,7 +26,7 @@
  **************************************************************************/
 
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "rtasm_cpu.h"
 
 
index be7433baf87c6a96ca87eaceca45ab00e571ab9b..5acc5bcb7b017484f842373d8ddde63fc884f155 100644 (file)
@@ -31,7 +31,7 @@
 
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_thread.h"
 #include "util/u_memory.h"
 
index 1bb90262051689bac94388b12b02539d87dea043..e3586482db4800c380b30c8d2452ddb55ddc9569 100644 (file)
@@ -38,7 +38,7 @@
 
 #include <stdio.h>
 #include "util/u_memory.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "rtasm_execmem.h"
 #include "rtasm_ppc.h"
 
index 99ee74cf14bee4a414a9cd2819d2f497a6626c38..57fcf6de2abc2aa745d02292f8be3cabd8f9408d 100644 (file)
@@ -26,7 +26,7 @@
 #if defined(PIPE_ARCH_X86)
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "util/u_pointer.h"
 
 #include "rtasm_execmem.h"
index 17886540cf79ba92baea68fafcd329be4beafa98..a1891a140ac5956fba402b6f8abae74bbebf33a0 100644 (file)
@@ -25,7 +25,7 @@
  * 
  **************************************************************************/
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_shader_tokens.h"
 #include "tgsi_build.h"
 #include "tgsi_parse.h"
index ab2b1f2c58adb0ba8ff84ba94281ae1d68e1543e..d57cb9139f7a187dd573eeb18400dac04c284f64 100644 (file)
@@ -25,7 +25,7 @@
  * 
  **************************************************************************/
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "util/u_string.h"
 #include "tgsi_dump.h"
 #include "tgsi_info.h"
index 2ecf1e2f14b2859b1f1a5ae70b3a2981d1157ea5..3dc61c48ca371428730738608e0e97e729527a63 100644 (file)
@@ -25,7 +25,7 @@
  * 
  **************************************************************************/
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "util/u_string.h"
 #include "tgsi_dump_c.h"
 #include "tgsi_build.h"
index 68c7a6b7f58749b158662cf56a3ea40703f1a8d2..2b8a6f0fb190c39b17f4205d56168fabeba9bbdd 100644 (file)
@@ -25,7 +25,7 @@
  * 
  **************************************************************************/
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "tgsi_info.h"
 
 static const struct tgsi_opcode_info opcode_info[TGSI_OPCODE_LAST] =
index 5371a88b96410f58e3443a1ee1824d0b413844a1..d88c2558d81dcfd6541a7d255a8b0515719129dd 100644 (file)
@@ -25,7 +25,7 @@
  * 
  **************************************************************************/
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "tgsi_iterate.h"
 
 boolean
index d374b16f9a15992a4993b49fe281acad95126994..22006edf3d1d023f7705ec1093dbdaae62da8883 100644 (file)
@@ -25,7 +25,7 @@
  * 
  **************************************************************************/
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_shader_tokens.h"
 #include "tgsi_parse.h"
 #include "tgsi_build.h"
index f365030e52677f365754e87f358275d9034532ec..0c64ae5713100db80969b05529326239710f1542 100644 (file)
@@ -33,7 +33,7 @@
 
 #if defined(PIPE_ARCH_PPC)
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_shader_tokens.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
index bc7b941b7853901ee7dd6ef5d37009b07c9e977a..76e773da91cefde8b6ea5a593b711015031a8dac 100644 (file)
@@ -25,7 +25,7 @@
  * 
  **************************************************************************/
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "tgsi_sanity.h"
 #include "tgsi_info.h"
 #include "tgsi_iterate.h"
index a183603aeab91548cc6031408bfdc7c1ae82beda..d70bcd03c5caec08f847cadc09e1ddb1bbbda736 100644 (file)
@@ -29,7 +29,7 @@
 
 #if defined(PIPE_ARCH_X86)
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_shader_tokens.h"
 #include "util/u_math.h"
 #if defined(PIPE_ARCH_SSE)
index 1e822fbbea1bfc5f6b4c8534075c333f0ac15207..58fe07c11d1ac003e371001f85cfd1477d1e9c64 100644 (file)
@@ -25,7 +25,7 @@
  * 
  **************************************************************************/
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "tgsi_text.h"
 #include "tgsi_build.h"
 #include "tgsi_info.h"
index ea87da31e50dde5cd6da901e203a4826daddd69c..062c1be938a3852bde6572ddf855a7efe76739b6 100644 (file)
@@ -31,7 +31,7 @@
  * Authors:  Brian Paul
  */
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 #include "tgsi_transform.h"
 
index 50101a9bb0cafd5372388ecf58253f1ddfb7d918..71f8a6ca401262e6e92149c685e2b32bd3f27976 100644 (file)
@@ -25,7 +25,7 @@
  * 
  **************************************************************************/
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_shader_tokens.h"
 #include "tgsi_parse.h"
 #include "tgsi_build.h"
index 44c23777218c28f8e6bd6af7bf54d18cf6ba7d20..671e671df23ead4a38ce7768b8c8838f4b2e173c 100644 (file)
@@ -4,7 +4,7 @@ include $(TOP)/configs/current
 LIBNAME = util
 
 C_SOURCES = \
-       p_debug.c \
+       u_debug.c \
        u_blit.c \
        u_cache.c \
        u_draw_quad.c \
index 35f683fb8e6a06f8bcf2fa7e402465e9c648d346..84e4c4847617ac2cd87de68a43c2648f2eb8b559 100644 (file)
@@ -3,11 +3,11 @@ Import('*')
 util = env.ConvenienceLibrary(
        target = 'util',
        source = [
-               'p_debug.c',
-               'p_debug_mem.c',
-               'p_debug_prof.c',
                'u_blit.c',
                'u_cache.c',
+               'u_debug.c',
+               'u_debug_memory.c',
+               'u_debug_profile.c',
                'u_draw_quad.c',
                'u_gen_mipmap.c',
                'u_handle_table.c',
diff --git a/src/gallium/auxiliary/util/p_debug.c b/src/gallium/auxiliary/util/p_debug.c
deleted file mode 100644 (file)
index f373f94..0000000
+++ /dev/null
@@ -1,782 +0,0 @@
-/**************************************************************************
- * 
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * Copyright (c) 2008 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 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.
- * 
- **************************************************************************/
-
-
-#include "pipe/p_config.h" 
-
-#include <stdarg.h>
-
-
-#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
-
-#include <windows.h>
-#include <winddi.h>
-
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE)
-
-#include <stdio.h> 
-#include <stdlib.h> 
-#include <windows.h> 
-#include <types.h> 
-
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
-
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN      // Exclude rarely-used stuff from Windows headers
-#endif
-#include <windows.h>
-
-#else
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#endif
-
-#include "pipe/p_compiler.h" 
-#include "pipe/p_debug.h" 
-#include "pipe/p_format.h" 
-#include "pipe/p_state.h" 
-#include "pipe/p_inlines.h" 
-#include "util/u_memory.h" 
-#include "util/u_string.h" 
-#include "util/u_stream.h" 
-#include "util/u_math.h" 
-#include "util/u_tile.h" 
-
-
-#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
-static INLINE void 
-_EngDebugPrint(const char *format, ...)
-{
-   va_list ap;
-   va_start(ap, format);
-   EngDebugPrint("", (PCHAR)format, ap);
-   va_end(ap);
-}
-#endif
-
-
-void _debug_vprintf(const char *format, va_list ap)
-{
-#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
-   /* EngDebugPrint does not handle float point arguments, so we need to use
-    * our own vsnprintf implementation. It is also very slow, so buffer until
-    * we find a newline. */
-   static char buf[512] = {'\0'};
-   size_t len = strlen(buf);
-   int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
-   if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) {
-      _EngDebugPrint("%s", buf);
-      buf[0] = '\0';
-   }
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
-   /* EngDebugPrint does not handle float point arguments, so we need to use
-    * our own vsnprintf implementation. It is also very slow, so buffer until
-    * we find a newline. */
-   static char buf[512 + 1] = {'\0'};
-   size_t len = strlen(buf);
-   int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
-   if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) {
-      OutputDebugStringA(buf);
-      buf[0] = '\0';
-   }
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE)
-   wchar_t *wide_format;
-   long wide_str_len;   
-   char buf[512];   
-   int ret;   
-#if (_WIN32_WCE < 600)
-   ret = vsprintf(buf, format, ap);   
-   if(ret < 0){   
-       sprintf(buf, "Cant handle debug print!");   
-       ret = 25;
-   }
-#else
-   ret = vsprintf_s(buf, 512, format, ap);   
-   if(ret < 0){   
-       sprintf_s(buf, 512, "Cant handle debug print!");   
-       ret = 25;
-   }
-#endif
-   buf[ret] = '\0';   
-   /* Format is ascii - needs to be converted to wchar_t for printing */   
-   wide_str_len = MultiByteToWideChar(CP_ACP, 0, (const char *) buf, -1, NULL, 0);   
-   wide_format = (wchar_t *) malloc((wide_str_len+1) * sizeof(wchar_t));   
-   if (wide_format) {   
-      MultiByteToWideChar(CP_ACP, 0, (const char *) buf, -1,   
-            wide_format, wide_str_len);   
-      NKDbgPrintfW(wide_format, wide_format);   
-      free(wide_format);   
-   } 
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
-   /* TODO */
-#else /* !PIPE_SUBSYSTEM_WINDOWS */
-#ifdef DEBUG
-   vfprintf(stderr, format, ap);
-#endif
-#endif
-}
-
-
-#ifdef DEBUG
-void debug_print_blob( const char *name,
-                       const void *blob,
-                       unsigned size )
-{
-   const unsigned *ublob = (const unsigned *)blob;
-   unsigned i;
-
-   debug_printf("%s (%d dwords%s)\n", name, size/4,
-                size%4 ? "... plus a few bytes" : "");
-
-   for (i = 0; i < size/4; i++) {
-      debug_printf("%d:\t%08x\n", i, ublob[i]);
-   }
-}
-#endif
-
-
-void _debug_break(void) 
-{
-#if defined(PIPE_ARCH_X86) && defined(PIPE_CC_GCC)
-   __asm("int3");
-#elif defined(PIPE_ARCH_X86) && defined(PIPE_CC_MSVC)
-   _asm {int 3};
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
-   EngDebugBreak();
-#else
-   abort();
-#endif
-}
-
-
-#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
-static const char *
-find(const char *start, const char *end, char c) 
-{
-   const char *p;
-   for(p = start; !end || p != end; ++p) {
-      if(*p == c)
-        return p;
-      if(*p < 32)
-        break;
-   }
-   return NULL;
-}
-
-static int 
-compare(const char *start, const char *end, const char *s)
-{
-   const char *p, *q;
-   for(p = start, q = s; p != end && *q != '\0'; ++p, ++q) {
-      if(*p != *q)
-        return 0;
-   }
-   return p == end && *q == '\0';
-}
-
-static void 
-copy(char *dst, const char *start, const char *end, size_t n) 
-{
-   const char *p;
-   char *q;
-   for(p = start, q = dst, n = n - 1; p != end && n; ++p, ++q, --n)
-      *q = *p;
-   *q = '\0';
-}
-#endif
-
-
-static INLINE const char *
-_debug_get_option(const char *name)
-{
-#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
-   /* EngMapFile creates the file if it does not exists, so it must either be
-    * disabled on release versions (or put in a less conspicuous place). */
-#ifdef DEBUG
-   const char *result = NULL;
-   ULONG_PTR iFile = 0;
-   const void *pMap = NULL;
-   const char *sol, *eol, *sep;
-   static char output[1024];
-   
-   pMap = EngMapFile(L"\\??\\c:\\gallium.cfg", 0, &iFile);
-   if(pMap) {
-      sol = (const char *)pMap;
-      while(1) {
-        /* TODO: handle LF line endings */
-        eol = find(sol, NULL, '\r');
-        if(!eol || eol == sol)
-           break;
-        sep = find(sol, eol, '=');
-        if(!sep)
-           break;
-        if(compare(sol, sep, name)) {
-           copy(output, sep + 1, eol, sizeof(output));
-           result = output;
-           break;
-        }
-        sol = eol + 2;
-      }
-      EngUnmapFile(iFile);
-   }
-   return result;
-#else
-   return NULL;
-#endif
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE) || defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT) 
-   /* TODO: implement */
-   return NULL;
-#else
-   return getenv(name);
-#endif
-}
-
-const char *
-debug_get_option(const char *name, const char *dfault)
-{
-   const char *result;
-
-   result = _debug_get_option(name);
-   if(!result)
-      result = dfault;
-      
-   debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? result : "(null)");
-   
-   return result;
-}
-
-boolean
-debug_get_bool_option(const char *name, boolean dfault)
-{
-   const char *str = _debug_get_option(name);
-   boolean result;
-   
-   if(str == NULL)
-      result = dfault;
-   else if(!util_strcmp(str, "n"))
-      result = FALSE;
-   else if(!util_strcmp(str, "no"))
-      result = FALSE;
-   else if(!util_strcmp(str, "0"))
-      result = FALSE;
-   else if(!util_strcmp(str, "f"))
-      result = FALSE;
-   else if(!util_strcmp(str, "false"))
-      result = FALSE;
-   else
-      result = TRUE;
-
-   debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? "TRUE" : "FALSE");
-   
-   return result;
-}
-
-
-long
-debug_get_num_option(const char *name, long dfault)
-{
-   long result;
-   const char *str;
-   
-   str = _debug_get_option(name);
-   if(!str)
-      result = dfault;
-   else {
-      long sign;
-      char c;
-      c = *str++;
-      if(c == '-') {
-        sign = -1;
-        c = *str++;
-      } 
-      else {
-        sign = 1;
-      }
-      result = 0;
-      while('0' <= c && c <= '9') {
-        result = result*10 + (c - '0');
-        c = *str++;
-      }
-      result *= sign;
-   }
-   
-   debug_printf("%s: %s = %li\n", __FUNCTION__, name, result);
-
-   return result;
-}
-
-
-unsigned long
-debug_get_flags_option(const char *name, 
-                       const struct debug_named_value *flags,
-                       unsigned long dfault)
-{
-   unsigned long result;
-   const char *str;
-   
-   str = _debug_get_option(name);
-   if(!str)
-      result = dfault;
-   else if (!util_strcmp(str, "help")) {
-      result = dfault;
-      while (flags->name) {
-         debug_printf("%s: help for %s: %s [0x%lx]\n", __FUNCTION__, name, flags->name, flags->value);
-         flags++;
-      }
-   }
-   else {
-      result = 0;
-      while( flags->name ) {
-        if (!util_strcmp(str, "all") || util_strstr(str, flags->name ))
-           result |= flags->value;
-        ++flags;
-      }
-   }
-
-   if (str) {
-      debug_printf("%s: %s = 0x%lx (%s)\n", __FUNCTION__, name, result, str);
-   }
-   else {
-      debug_printf("%s: %s = 0x%lx\n", __FUNCTION__, name, result);
-   }
-
-   return result;
-}
-
-
-void _debug_assert_fail(const char *expr, 
-                        const char *file, 
-                        unsigned line, 
-                        const char *function) 
-{
-   _debug_printf("%s:%u:%s: Assertion `%s' failed.\n", file, line, function, expr);
-#if defined(PIPE_OS_WINDOWS) && !defined(PIPE_SUBSYSTEM_WINDOWS_USER)
-   if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", FALSE))
-#else
-   if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", TRUE))
-#endif
-      debug_break();
-   else
-      _debug_printf("continuing...\n");
-}
-
-
-const char *
-debug_dump_enum(const struct debug_named_value *names, 
-                unsigned long value)
-{
-   static char rest[64];
-   
-   while(names->name) {
-      if(names->value == value)
-        return names->name;
-      ++names;
-   }
-
-   util_snprintf(rest, sizeof(rest), "0x%08lx", value);
-   return rest;
-}
-
-
-const char *
-debug_dump_enum_noprefix(const struct debug_named_value *names, 
-                         const char *prefix,
-                         unsigned long value)
-{
-   static char rest[64];
-   
-   while(names->name) {
-      if(names->value == value) {
-         const char *name = names->name;
-         while (*name == *prefix) {
-            name++;
-            prefix++;
-         }
-         return name;
-      }
-      ++names;
-   }
-
-   
-
-   util_snprintf(rest, sizeof(rest), "0x%08lx", value);
-   return rest;
-}
-
-
-const char *
-debug_dump_flags(const struct debug_named_value *names, 
-                 unsigned long value)
-{
-   static char output[4096];
-   static char rest[256];
-   int first = 1;
-
-   output[0] = '\0';
-
-   while(names->name) {
-      if((names->value & value) == names->value) {
-        if (!first)
-           util_strncat(output, "|", sizeof(output));
-        else
-           first = 0;
-        util_strncat(output, names->name, sizeof(output));
-        value &= ~names->value;
-      }
-      ++names;
-   }
-   
-   if (value) {
-      if (!first)
-        util_strncat(output, "|", sizeof(output));
-      else
-        first = 0;
-      
-      util_snprintf(rest, sizeof(rest), "0x%08lx", value);
-      util_strncat(output, rest, sizeof(output));
-   }
-   
-   if(first)
-      return "0";
-   
-   return output;
-}
-
-
-static const struct debug_named_value pipe_format_names[] = {
-#ifdef DEBUG
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_NONE),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_A8R8G8B8_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_X8R8G8B8_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_B8G8R8A8_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_B8G8R8X8_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_A1R5G5B5_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_A4R4G4B4_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R5G6B5_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_A2B10G10R10_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_L8_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_A8_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_I8_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_A8L8_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_L16_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_YCBCR),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_YCBCR_REV),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_Z16_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_Z32_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_Z32_FLOAT),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_S8Z24_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_Z24S8_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_X8Z24_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_Z24X8_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_S8_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R64_FLOAT),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R64G64_FLOAT),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R64G64B64_FLOAT),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R64G64B64A64_FLOAT),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_FLOAT),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_FLOAT),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_FLOAT),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_FLOAT),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_USCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_USCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_USCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_USCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_SNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_SNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_SNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_SNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_SSCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_SSCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_SSCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_SSCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16A16_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16_USCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16_USCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16_USCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16A16_USCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16_SNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16_SNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16_SNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16A16_SNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16_SSCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16_SSCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16_SSCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16A16_SSCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_UNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8_USCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8_USCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_USCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_USCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_USCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8_SNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8_SNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_SNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_SNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_SNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_B6G5R5_SNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_A8B8G8R8_SNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_X8B8G8R8_SNORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8_SSCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8_SSCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_SSCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_SSCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_SSCALED),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_L8_SRGB),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_A8L8_SRGB),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_SRGB),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_SRGB),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_SRGB),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_A8R8G8B8_SRGB),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_X8R8G8B8_SRGB),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_B8G8R8A8_SRGB),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_B8G8R8X8_SRGB),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_X8UB8UG8SR8S_NORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_B6UG5SR5S_NORM),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT1_RGB),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT1_RGBA),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT3_RGBA),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT5_RGBA),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT1_SRGB),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT1_SRGBA),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT3_SRGBA),
-   DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT5_SRGBA),
-#endif
-   DEBUG_NAMED_VALUE_END
-};
-
-#ifdef DEBUG
-void debug_print_format(const char *msg, unsigned fmt )
-{
-   debug_printf("%s: %s\n", msg, debug_dump_enum(pipe_format_names, fmt)); 
-}
-#endif
-
-const char *pf_name( enum pipe_format format )
-{
-   return debug_dump_enum(pipe_format_names, format);
-}
-
-
-#ifdef DEBUG
-void debug_dump_image(const char *prefix,
-                      unsigned format, unsigned cpp,
-                      unsigned width, unsigned height,
-                      unsigned stride,
-                      const void *data)     
-{
-#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
-   static unsigned no = 0; 
-   char filename[256];
-   WCHAR wfilename[sizeof(filename)];
-   ULONG_PTR iFile = 0;
-   struct {
-      unsigned format;
-      unsigned cpp;
-      unsigned width;
-      unsigned height;
-   } header;
-   unsigned char *pMap = NULL;
-   unsigned i;
-
-   util_snprintf(filename, sizeof(filename), "\\??\\c:\\%03u%s.raw", ++no, prefix);
-   for(i = 0; i < sizeof(filename); ++i)
-      wfilename[i] = (WCHAR)filename[i];
-   
-   pMap = (unsigned char *)EngMapFile(wfilename, sizeof(header) + height*width*cpp, &iFile);
-   if(!pMap)
-      return;
-   
-   header.format = format;
-   header.cpp = cpp;
-   header.width = width;
-   header.height = height;
-   memcpy(pMap, &header, sizeof(header));
-   pMap += sizeof(header);
-   
-   for(i = 0; i < height; ++i) {
-      memcpy(pMap, (unsigned char *)data + stride*i, cpp*width);
-      pMap += cpp*width;
-   }
-      
-   EngUnmapFile(iFile);
-#endif
-}
-
-void debug_dump_surface(const char *prefix,
-                        struct pipe_surface *surface)     
-{
-   unsigned surface_usage;
-   void *data;
-
-   if (!surface)
-      goto error1;
-
-   /* XXX: force mappable surface */
-   surface_usage = surface->usage;
-   surface->usage |= PIPE_BUFFER_USAGE_CPU_READ;
-   
-   data = pipe_surface_map(surface, 
-                           PIPE_BUFFER_USAGE_CPU_READ);
-   if(!data)
-      goto error2;
-   
-   debug_dump_image(prefix, 
-                    surface->format,
-                    surface->block.size, 
-                    surface->nblocksx,
-                    surface->nblocksy,
-                    surface->stride,
-                    data);
-   
-   pipe_surface_unmap(surface);
-error2:
-   surface->usage = surface_usage;
-error1:
-   ;
-}
-
-
-#pragma pack(push,2)
-struct bmp_file_header {
-   uint16_t bfType;
-   uint32_t bfSize;
-   uint16_t bfReserved1;
-   uint16_t bfReserved2;
-   uint32_t bfOffBits;
-};
-#pragma pack(pop)
-
-struct bmp_info_header {
-   uint32_t biSize;
-   int32_t biWidth;
-   int32_t biHeight;
-   uint16_t biPlanes;
-   uint16_t biBitCount;
-   uint32_t biCompression;
-   uint32_t biSizeImage;
-   int32_t biXPelsPerMeter;
-   int32_t biYPelsPerMeter;
-   uint32_t biClrUsed;
-   uint32_t biClrImportant;
-};
-
-struct bmp_rgb_quad {
-   uint8_t rgbBlue;
-   uint8_t rgbGreen;
-   uint8_t rgbRed;
-   uint8_t rgbAlpha;
-};
-
-void 
-debug_dump_surface_bmp(const char *filename,
-                       struct pipe_surface *surface)
-{
-#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
-   struct util_stream *stream;
-   unsigned surface_usage;
-   struct bmp_file_header bmfh;
-   struct bmp_info_header bmih;
-   float *rgba;
-   unsigned x, y;
-
-   if (!surface)
-      goto error1;
-
-   rgba = MALLOC(surface->width*4*sizeof(float));
-   if(!rgba)
-      goto error1;
-   
-   bmfh.bfType = 0x4d42;
-   bmfh.bfSize = 14 + 40 + surface->height*surface->width*4;
-   bmfh.bfReserved1 = 0;
-   bmfh.bfReserved2 = 0;
-   bmfh.bfOffBits = 14 + 40;
-   
-   bmih.biSize = 40;
-   bmih.biWidth = surface->width;
-   bmih.biHeight = surface->height;
-   bmih.biPlanes = 1;
-   bmih.biBitCount = 32;
-   bmih.biCompression = 0;
-   bmih.biSizeImage = surface->height*surface->width*4;
-   bmih.biXPelsPerMeter = 0;
-   bmih.biYPelsPerMeter = 0;
-   bmih.biClrUsed = 0;
-   bmih.biClrImportant = 0;
-   
-   stream = util_stream_create(filename, bmfh.bfSize);
-   if(!stream)
-      goto error2;
-   
-   util_stream_write(stream, &bmfh, 14);
-   util_stream_write(stream, &bmih, 40);
-   
-   /* XXX: force mappable surface */
-   surface_usage = surface->usage;
-   surface->usage |= PIPE_BUFFER_USAGE_CPU_READ;
-
-   y = surface->height;
-   while(y--) {
-      pipe_get_tile_rgba(surface,
-                         0, y, surface->width, 1,
-                         rgba);
-      for(x = 0; x < surface->width; ++x)
-      {
-         struct bmp_rgb_quad pixel;
-         pixel.rgbRed   = float_to_ubyte(rgba[x*4 + 0]);
-         pixel.rgbGreen = float_to_ubyte(rgba[x*4 + 1]);
-         pixel.rgbBlue  = float_to_ubyte(rgba[x*4 + 2]);
-         pixel.rgbAlpha = float_to_ubyte(rgba[x*4 + 3]);
-         util_stream_write(stream, &pixel, 4);
-      }  
-   }
-   
-   surface->usage = surface_usage;
-
-   util_stream_close(stream);
-error2:
-   FREE(rgba);
-error1:
-   ;
-#endif
-}
-
-#endif
diff --git a/src/gallium/auxiliary/util/p_debug_mem.c b/src/gallium/auxiliary/util/p_debug_mem.c
deleted file mode 100644 (file)
index 250fd60..0000000
+++ /dev/null
@@ -1,311 +0,0 @@
-/**************************************************************************
- * 
- * 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
- * Memory debugging.
- * 
- * @author José Fonseca <jrfonseca@tungstengraphics.com>
- */
-
-#include "pipe/p_config.h" 
-
-#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
-#include <windows.h>
-#include <winddi.h>
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
-#include <wdm.h>
-#else
-#include <stdio.h>
-#include <stdlib.h>
-#endif
-
-#include "pipe/p_debug.h" 
-#include "util/u_double_list.h" 
-
-
-#define DEBUG_MEMORY_MAGIC 0x6e34090aU 
-
-
-#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) && !defined(WINCE)
-#define real_malloc(_size) EngAllocMem(0, _size, 'D3AG')
-#define real_free(_ptr) EngFreeMem(_ptr)
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
-#define real_malloc(_size) ExAllocatePool(0, _size)
-#define real_free(_ptr) ExFreePool(_ptr)
-#else
-#define real_malloc(_size) malloc(_size)
-#define real_free(_ptr) free(_ptr)
-#endif
-
-
-struct debug_memory_header 
-{
-   struct list_head head;
-   
-   unsigned long no;
-   const char *file;
-   unsigned line;
-   const char *function;
-   size_t size;
-   unsigned magic;
-};
-
-struct debug_memory_footer
-{
-   unsigned magic;
-};
-
-
-static struct list_head list = { &list, &list };
-
-static unsigned long last_no = 0;
-
-
-static INLINE struct debug_memory_header *
-header_from_data(void *data)
-{
-   if(data)
-      return (struct debug_memory_header *)((char *)data - sizeof(struct debug_memory_header));
-   else
-      return NULL;
-}
-
-static INLINE void *
-data_from_header(struct debug_memory_header *hdr)
-{
-   if(hdr)
-      return (void *)((char *)hdr + sizeof(struct debug_memory_header));
-   else
-      return NULL;
-}
-
-static INLINE struct debug_memory_footer *
-footer_from_header(struct debug_memory_header *hdr)
-{
-   if(hdr)
-      return (struct debug_memory_footer *)((char *)hdr + sizeof(struct debug_memory_header) + hdr->size);
-   else
-      return NULL;
-}
-
-
-void *
-debug_malloc(const char *file, unsigned line, const char *function,
-             size_t size) 
-{
-   struct debug_memory_header *hdr;
-   struct debug_memory_footer *ftr;
-   
-   hdr = real_malloc(sizeof(*hdr) + size + sizeof(*ftr));
-   if(!hdr) {
-      debug_printf("%s:%u:%s: out of memory when trying to allocate %lu bytes\n",
-                   file, line, function,
-                   (long unsigned)size);
-      return NULL;
-   }
-   hdr->no = last_no++;
-   hdr->file = file;
-   hdr->line = line;
-   hdr->function = function;
-   hdr->size = size;
-   hdr->magic = DEBUG_MEMORY_MAGIC;
-
-   ftr = footer_from_header(hdr);
-   ftr->magic = DEBUG_MEMORY_MAGIC;
-   
-   LIST_ADDTAIL(&hdr->head, &list);
-   
-   return data_from_header(hdr);
-}
-
-void
-debug_free(const char *file, unsigned line, const char *function,
-           void *ptr) 
-{
-   struct debug_memory_header *hdr;
-   struct debug_memory_footer *ftr;
-   
-   if(!ptr)
-      return;
-   
-   hdr = header_from_data(ptr);
-   if(hdr->magic != DEBUG_MEMORY_MAGIC) {
-      debug_printf("%s:%u:%s: freeing bad or corrupted memory %p\n",
-                   file, line, function,
-                   ptr);
-      debug_assert(0);
-      return;
-   }
-
-   ftr = footer_from_header(hdr);
-   if(ftr->magic != DEBUG_MEMORY_MAGIC) {
-      debug_printf("%s:%u:%s: buffer overflow %p\n",
-                   hdr->file, hdr->line, hdr->function,
-                   ptr);
-      debug_assert(0);
-   }
-
-   LIST_DEL(&hdr->head);
-   hdr->magic = 0;
-   ftr->magic = 0;
-   
-   real_free(hdr);
-}
-
-void *
-debug_calloc(const char *file, unsigned line, const char *function,
-             size_t count, size_t size )
-{
-   void *ptr = debug_malloc( file, line, function, count * size );
-   if( ptr )
-      memset( ptr, 0, count * size );
-   return ptr;
-}
-
-void *
-debug_realloc(const char *file, unsigned line, const char *function,
-              void *old_ptr, size_t old_size, size_t new_size )
-{
-   struct debug_memory_header *old_hdr, *new_hdr;
-   struct debug_memory_footer *old_ftr, *new_ftr;
-   void *new_ptr;
-   
-   if(!old_ptr)
-      return debug_malloc( file, line, function, new_size );
-   
-   if(!new_size) {
-      debug_free( file, line, function, old_ptr );
-      return NULL;
-   }
-   
-   old_hdr = header_from_data(old_ptr);
-   if(old_hdr->magic != DEBUG_MEMORY_MAGIC) {
-      debug_printf("%s:%u:%s: reallocating bad or corrupted memory %p\n",
-                   file, line, function,
-                   old_ptr);
-      debug_assert(0);
-      return NULL;
-   }
-   
-   old_ftr = footer_from_header(old_hdr);
-   if(old_ftr->magic != DEBUG_MEMORY_MAGIC) {
-      debug_printf("%s:%u:%s: buffer overflow %p\n",
-                   old_hdr->file, old_hdr->line, old_hdr->function,
-                   old_ptr);
-      debug_assert(0);
-   }
-
-   /* alloc new */
-   new_hdr = real_malloc(sizeof(*new_hdr) + new_size + sizeof(*new_ftr));
-   if(!new_hdr) {
-      debug_printf("%s:%u:%s: out of memory when trying to allocate %lu bytes\n",
-                   file, line, function,
-                   (long unsigned)new_size);
-      return NULL;
-   }
-   new_hdr->no = old_hdr->no;
-   new_hdr->file = old_hdr->file;
-   new_hdr->line = old_hdr->line;
-   new_hdr->function = old_hdr->function;
-   new_hdr->size = new_size;
-   new_hdr->magic = DEBUG_MEMORY_MAGIC;
-   
-   new_ftr = footer_from_header(new_hdr);
-   new_ftr->magic = DEBUG_MEMORY_MAGIC;
-   
-   LIST_REPLACE(&old_hdr->head, &new_hdr->head);
-
-   /* copy data */
-   new_ptr = data_from_header(new_hdr);
-   memcpy( new_ptr, old_ptr, old_size < new_size ? old_size : new_size );
-
-   /* free old */
-   old_hdr->magic = 0;
-   old_ftr->magic = 0;
-   real_free(old_hdr);
-
-   return new_ptr;
-}
-
-unsigned long
-debug_memory_begin(void)
-{
-   return last_no;
-}
-
-void 
-debug_memory_end(unsigned long start_no)
-{
-   size_t total_size = 0;
-   struct list_head *entry;
-
-   if(start_no == last_no)
-      return;
-
-   entry = list.prev;
-   for (; entry != &list; entry = entry->prev) {
-      struct debug_memory_header *hdr;
-      void *ptr;
-      struct debug_memory_footer *ftr;
-
-      hdr = LIST_ENTRY(struct debug_memory_header, entry, head);
-      ptr = data_from_header(hdr);
-      ftr = footer_from_header(hdr);
-
-      if(hdr->magic != DEBUG_MEMORY_MAGIC) {
-         debug_printf("%s:%u:%s: bad or corrupted memory %p\n",
-                      hdr->file, hdr->line, hdr->function,
-                      ptr);
-         debug_assert(0);
-      }
-
-      if((start_no <= hdr->no && hdr->no < last_no) ||
-        (last_no < start_no && (hdr->no < last_no || start_no <= hdr->no))) {
-        debug_printf("%s:%u:%s: %u bytes at %p not freed\n",
-                     hdr->file, hdr->line, hdr->function,
-                     hdr->size, ptr);
-        total_size += hdr->size;
-      }
-
-      if(ftr->magic != DEBUG_MEMORY_MAGIC) {
-         debug_printf("%s:%u:%s: buffer overflow %p\n",
-                      hdr->file, hdr->line, hdr->function,
-                      ptr);
-         debug_assert(0);
-      }
-   }
-
-   if(total_size) {
-      debug_printf("Total of %u KB of system memory apparently leaked\n",
-                  (total_size + 1023)/1024);
-   }
-   else {
-      debug_printf("No memory leaks detected.\n");
-   }
-}
diff --git a/src/gallium/auxiliary/util/p_debug_prof.c b/src/gallium/auxiliary/util/p_debug_prof.c
deleted file mode 100644 (file)
index 5f9772e..0000000
+++ /dev/null
@@ -1,320 +0,0 @@
-/**************************************************************************
- * 
- * 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
- * Poor-man profiling.
- * 
- * @author José Fonseca <jrfonseca@tungstengraphics.com>
- * 
- * @sa http://blogs.msdn.com/joshpoley/archive/2008/03/12/poor-man-s-profiler.aspx
- * @sa http://www.johnpanzer.com/aci_cuj/index.html
- */
-
-#include "pipe/p_config.h" 
-
-#if defined(PROFILE) && defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
-
-#include <windows.h>
-#include <winddi.h>
-
-#include "pipe/p_debug.h" 
-#include "util/u_string.h" 
-
-
-#define PROFILE_TABLE_SIZE (1024*1024)
-#define FILE_NAME_SIZE 256
-
-struct debug_profile_entry
-{
-   uintptr_t caller;
-   uintptr_t callee;
-   uint64_t samples;
-};
-
-static unsigned long enabled = 0;
-
-static WCHAR wFileName[FILE_NAME_SIZE] = L"\\??\\c:\\00000000.prof";
-static ULONG_PTR iFile = 0;
-
-static struct debug_profile_entry *table = NULL;
-static unsigned long free_table_entries = 0;
-static unsigned long max_table_entries = 0;
-
-uint64_t start_stamp = 0;
-uint64_t end_stamp = 0;
-
-
-static void
-debug_profile_entry(uintptr_t caller, uintptr_t callee, uint64_t samples)
-{
-   unsigned hash = ( caller + callee ) & PROFILE_TABLE_SIZE - 1;
-   
-   while(1) {
-      if(table[hash].caller == 0 && table[hash].callee == 0) {
-         table[hash].caller = caller;
-         table[hash].callee = callee;
-         table[hash].samples = samples;
-         --free_table_entries;
-         break;
-      }
-      else if(table[hash].caller == caller && table[hash].callee == callee) {
-         table[hash].samples += samples;
-         break;
-      }
-      else {
-         ++hash;
-      }
-   }
-}
-
-
-static uintptr_t caller_stack[1024];
-static unsigned last_caller = 0;
-
-
-static int64_t delta(void) {
-   int64_t result = end_stamp - start_stamp;
-   if(result > UINT64_C(0xffffffff))
-      result = 0;
-   return result;
-}
-
-
-static void __cdecl 
-debug_profile_enter(uintptr_t callee)
-{
-   uintptr_t caller = last_caller ? caller_stack[last_caller - 1] : 0;
-                
-   if (caller)
-      debug_profile_entry(caller, 0, delta());
-   debug_profile_entry(caller, callee, 1);
-   caller_stack[last_caller++] = callee;
-}
-
-
-static void __cdecl
-debug_profile_exit(uintptr_t callee)
-{
-   debug_profile_entry(callee, 0, delta());
-   if(last_caller)
-      --last_caller;
-}
-   
-   
-/**
- * Called at the start of every method or function.
- * 
- * @sa http://msdn.microsoft.com/en-us/library/c63a9b7h.aspx
- */
-void __declspec(naked) __cdecl 
-_penter(void) {
-   _asm {
-      push eax
-      mov eax, [enabled]
-      test eax, eax
-      jz skip
-
-      push edx
-      
-      rdtsc
-      mov dword ptr [end_stamp], eax
-      mov dword ptr [end_stamp+4], edx
-
-      xor eax, eax
-      mov [enabled], eax
-
-      mov eax, [esp+8]
-
-      push ebx
-      push ecx
-      push ebp
-      push edi
-      push esi
-
-      push eax
-      call debug_profile_enter
-      add esp, 4
-
-      pop esi
-      pop edi
-      pop ebp
-      pop ecx
-      pop ebx
-
-      mov eax, 1
-      mov [enabled], eax 
-
-      rdtsc
-      mov dword ptr [start_stamp], eax
-      mov dword ptr [start_stamp+4], edx
-      
-      pop edx
-skip:
-      pop eax
-      ret
-   }
-}
-
-
-/**
- * Called at the end of Calls the end of every method or function.
- * 
- * @sa http://msdn.microsoft.com/en-us/library/xc11y76y.aspx
- */
-void __declspec(naked) __cdecl 
-_pexit(void) {
-   _asm {
-      push eax
-      mov eax, [enabled]
-      test eax, eax
-      jz skip
-
-      push edx
-      
-      rdtsc
-      mov dword ptr [end_stamp], eax
-      mov dword ptr [end_stamp+4], edx
-
-      xor eax, eax
-      mov [enabled], eax
-
-      mov eax, [esp+8]
-
-      push ebx
-      push ecx
-      push ebp
-      push edi
-      push esi
-
-      push eax
-      call debug_profile_exit
-      add esp, 4
-
-      pop esi
-      pop edi
-      pop ebp
-      pop ecx
-      pop ebx
-
-      mov eax, 1
-      mov [enabled], eax 
-
-      rdtsc
-      mov dword ptr [start_stamp], eax
-      mov dword ptr [start_stamp+4], edx
-      
-      pop edx
-skip:
-      pop eax
-      ret
-   }
-}
-
-
-/**
- * Reference function for calibration. 
- */
-void __declspec(naked) 
-__debug_profile_reference(void) {
-   _asm {
-      call _penter
-      call _pexit
-      ret
-   }
-}
-
-
-void
-debug_profile_start(void)
-{
-   WCHAR *p;
-
-   // increment starting from the less significant digit
-   p = &wFileName[14];
-   while(1) {
-      if(*p == '9') {
-         *p-- = '0';
-      }
-      else {
-         *p += 1;
-         break;
-      }
-   }
-
-   table = EngMapFile(wFileName, 
-                      PROFILE_TABLE_SIZE*sizeof(struct debug_profile_entry), 
-                      &iFile);
-   if(table) {
-      unsigned i;
-      
-      free_table_entries = max_table_entries = PROFILE_TABLE_SIZE;
-      memset(table, 0, PROFILE_TABLE_SIZE*sizeof(struct debug_profile_entry));
-      
-      table[0].caller = (uintptr_t)&__debug_profile_reference;
-      table[0].callee = 0;
-      table[0].samples = 0;
-      --free_table_entries;
-
-      _asm {
-         push edx
-         push eax
-      
-         rdtsc
-         mov dword ptr [start_stamp], eax
-         mov dword ptr [start_stamp+4], edx
-         
-         pop edx
-         pop eax
-      }
-
-      last_caller = 0;
-      
-      enabled = 1;
-
-      for(i = 0; i < 8; ++i) {
-         _asm {
-            call __debug_profile_reference
-         }
-      }
-   }
-}
-
-
-void 
-debug_profile_stop(void)
-{
-   enabled = 0;
-
-   if(iFile)
-      EngUnmapFile(iFile);
-   iFile = 0;
-   table = NULL;
-   free_table_entries = max_table_entries = 0;
-}
-
-#endif /* PROFILE */
index 841e9c01e7ee3b8d83ee45d8d2ad3f08282a5604..efc3a874cc2b0e971a50c3b0a0d37e477b1cea53 100644 (file)
@@ -34,7 +34,7 @@
 
 
 #include "pipe/p_context.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_inlines.h"
 #include "pipe/p_shader_tokens.h"
index 0a1a64259f1e74d0c70686f4f50b81f8509ce7c2..41cd38171fad21f4423f112af9d8531b56cc1c54 100644 (file)
@@ -36,7 +36,7 @@
 
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 #include "util/u_math.h"
 #include "util/u_memory.h"
diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c
new file mode 100644 (file)
index 0000000..43d424b
--- /dev/null
@@ -0,0 +1,782 @@
+/**************************************************************************
+ * 
+ * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright (c) 2008 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 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.
+ * 
+ **************************************************************************/
+
+
+#include "pipe/p_config.h" 
+
+#include <stdarg.h>
+
+
+#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
+
+#include <windows.h>
+#include <winddi.h>
+
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE)
+
+#include <stdio.h> 
+#include <stdlib.h> 
+#include <windows.h> 
+#include <types.h> 
+
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
+
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN      // Exclude rarely-used stuff from Windows headers
+#endif
+#include <windows.h>
+
+#else
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#endif
+
+#include "pipe/p_compiler.h" 
+#include "util/u_debug.h" 
+#include "pipe/p_format.h" 
+#include "pipe/p_state.h" 
+#include "pipe/p_inlines.h" 
+#include "util/u_memory.h" 
+#include "util/u_string.h" 
+#include "util/u_stream.h" 
+#include "util/u_math.h" 
+#include "util/u_tile.h" 
+
+
+#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
+static INLINE void 
+_EngDebugPrint(const char *format, ...)
+{
+   va_list ap;
+   va_start(ap, format);
+   EngDebugPrint("", (PCHAR)format, ap);
+   va_end(ap);
+}
+#endif
+
+
+void _debug_vprintf(const char *format, va_list ap)
+{
+#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
+   /* EngDebugPrint does not handle float point arguments, so we need to use
+    * our own vsnprintf implementation. It is also very slow, so buffer until
+    * we find a newline. */
+   static char buf[512] = {'\0'};
+   size_t len = strlen(buf);
+   int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
+   if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) {
+      _EngDebugPrint("%s", buf);
+      buf[0] = '\0';
+   }
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
+   /* EngDebugPrint does not handle float point arguments, so we need to use
+    * our own vsnprintf implementation. It is also very slow, so buffer until
+    * we find a newline. */
+   static char buf[512 + 1] = {'\0'};
+   size_t len = strlen(buf);
+   int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
+   if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) {
+      OutputDebugStringA(buf);
+      buf[0] = '\0';
+   }
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE)
+   wchar_t *wide_format;
+   long wide_str_len;   
+   char buf[512];   
+   int ret;   
+#if (_WIN32_WCE < 600)
+   ret = vsprintf(buf, format, ap);   
+   if(ret < 0){   
+       sprintf(buf, "Cant handle debug print!");   
+       ret = 25;
+   }
+#else
+   ret = vsprintf_s(buf, 512, format, ap);   
+   if(ret < 0){   
+       sprintf_s(buf, 512, "Cant handle debug print!");   
+       ret = 25;
+   }
+#endif
+   buf[ret] = '\0';   
+   /* Format is ascii - needs to be converted to wchar_t for printing */   
+   wide_str_len = MultiByteToWideChar(CP_ACP, 0, (const char *) buf, -1, NULL, 0);   
+   wide_format = (wchar_t *) malloc((wide_str_len+1) * sizeof(wchar_t));   
+   if (wide_format) {   
+      MultiByteToWideChar(CP_ACP, 0, (const char *) buf, -1,   
+            wide_format, wide_str_len);   
+      NKDbgPrintfW(wide_format, wide_format);   
+      free(wide_format);   
+   } 
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
+   /* TODO */
+#else /* !PIPE_SUBSYSTEM_WINDOWS */
+#ifdef DEBUG
+   vfprintf(stderr, format, ap);
+#endif
+#endif
+}
+
+
+#ifdef DEBUG
+void debug_print_blob( const char *name,
+                       const void *blob,
+                       unsigned size )
+{
+   const unsigned *ublob = (const unsigned *)blob;
+   unsigned i;
+
+   debug_printf("%s (%d dwords%s)\n", name, size/4,
+                size%4 ? "... plus a few bytes" : "");
+
+   for (i = 0; i < size/4; i++) {
+      debug_printf("%d:\t%08x\n", i, ublob[i]);
+   }
+}
+#endif
+
+
+void _debug_break(void) 
+{
+#if defined(PIPE_ARCH_X86) && defined(PIPE_CC_GCC)
+   __asm("int3");
+#elif defined(PIPE_ARCH_X86) && defined(PIPE_CC_MSVC)
+   _asm {int 3};
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
+   EngDebugBreak();
+#else
+   abort();
+#endif
+}
+
+
+#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
+static const char *
+find(const char *start, const char *end, char c) 
+{
+   const char *p;
+   for(p = start; !end || p != end; ++p) {
+      if(*p == c)
+        return p;
+      if(*p < 32)
+        break;
+   }
+   return NULL;
+}
+
+static int 
+compare(const char *start, const char *end, const char *s)
+{
+   const char *p, *q;
+   for(p = start, q = s; p != end && *q != '\0'; ++p, ++q) {
+      if(*p != *q)
+        return 0;
+   }
+   return p == end && *q == '\0';
+}
+
+static void 
+copy(char *dst, const char *start, const char *end, size_t n) 
+{
+   const char *p;
+   char *q;
+   for(p = start, q = dst, n = n - 1; p != end && n; ++p, ++q, --n)
+      *q = *p;
+   *q = '\0';
+}
+#endif
+
+
+static INLINE const char *
+_debug_get_option(const char *name)
+{
+#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
+   /* EngMapFile creates the file if it does not exists, so it must either be
+    * disabled on release versions (or put in a less conspicuous place). */
+#ifdef DEBUG
+   const char *result = NULL;
+   ULONG_PTR iFile = 0;
+   const void *pMap = NULL;
+   const char *sol, *eol, *sep;
+   static char output[1024];
+   
+   pMap = EngMapFile(L"\\??\\c:\\gallium.cfg", 0, &iFile);
+   if(pMap) {
+      sol = (const char *)pMap;
+      while(1) {
+        /* TODO: handle LF line endings */
+        eol = find(sol, NULL, '\r');
+        if(!eol || eol == sol)
+           break;
+        sep = find(sol, eol, '=');
+        if(!sep)
+           break;
+        if(compare(sol, sep, name)) {
+           copy(output, sep + 1, eol, sizeof(output));
+           result = output;
+           break;
+        }
+        sol = eol + 2;
+      }
+      EngUnmapFile(iFile);
+   }
+   return result;
+#else
+   return NULL;
+#endif
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE) || defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT) 
+   /* TODO: implement */
+   return NULL;
+#else
+   return getenv(name);
+#endif
+}
+
+const char *
+debug_get_option(const char *name, const char *dfault)
+{
+   const char *result;
+
+   result = _debug_get_option(name);
+   if(!result)
+      result = dfault;
+      
+   debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? result : "(null)");
+   
+   return result;
+}
+
+boolean
+debug_get_bool_option(const char *name, boolean dfault)
+{
+   const char *str = _debug_get_option(name);
+   boolean result;
+   
+   if(str == NULL)
+      result = dfault;
+   else if(!util_strcmp(str, "n"))
+      result = FALSE;
+   else if(!util_strcmp(str, "no"))
+      result = FALSE;
+   else if(!util_strcmp(str, "0"))
+      result = FALSE;
+   else if(!util_strcmp(str, "f"))
+      result = FALSE;
+   else if(!util_strcmp(str, "false"))
+      result = FALSE;
+   else
+      result = TRUE;
+
+   debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? "TRUE" : "FALSE");
+   
+   return result;
+}
+
+
+long
+debug_get_num_option(const char *name, long dfault)
+{
+   long result;
+   const char *str;
+   
+   str = _debug_get_option(name);
+   if(!str)
+      result = dfault;
+   else {
+      long sign;
+      char c;
+      c = *str++;
+      if(c == '-') {
+        sign = -1;
+        c = *str++;
+      } 
+      else {
+        sign = 1;
+      }
+      result = 0;
+      while('0' <= c && c <= '9') {
+        result = result*10 + (c - '0');
+        c = *str++;
+      }
+      result *= sign;
+   }
+   
+   debug_printf("%s: %s = %li\n", __FUNCTION__, name, result);
+
+   return result;
+}
+
+
+unsigned long
+debug_get_flags_option(const char *name, 
+                       const struct debug_named_value *flags,
+                       unsigned long dfault)
+{
+   unsigned long result;
+   const char *str;
+   
+   str = _debug_get_option(name);
+   if(!str)
+      result = dfault;
+   else if (!util_strcmp(str, "help")) {
+      result = dfault;
+      while (flags->name) {
+         debug_printf("%s: help for %s: %s [0x%lx]\n", __FUNCTION__, name, flags->name, flags->value);
+         flags++;
+      }
+   }
+   else {
+      result = 0;
+      while( flags->name ) {
+        if (!util_strcmp(str, "all") || util_strstr(str, flags->name ))
+           result |= flags->value;
+        ++flags;
+      }
+   }
+
+   if (str) {
+      debug_printf("%s: %s = 0x%lx (%s)\n", __FUNCTION__, name, result, str);
+   }
+   else {
+      debug_printf("%s: %s = 0x%lx\n", __FUNCTION__, name, result);
+   }
+
+   return result;
+}
+
+
+void _debug_assert_fail(const char *expr, 
+                        const char *file, 
+                        unsigned line, 
+                        const char *function) 
+{
+   _debug_printf("%s:%u:%s: Assertion `%s' failed.\n", file, line, function, expr);
+#if defined(PIPE_OS_WINDOWS) && !defined(PIPE_SUBSYSTEM_WINDOWS_USER)
+   if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", FALSE))
+#else
+   if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", TRUE))
+#endif
+      debug_break();
+   else
+      _debug_printf("continuing...\n");
+}
+
+
+const char *
+debug_dump_enum(const struct debug_named_value *names, 
+                unsigned long value)
+{
+   static char rest[64];
+   
+   while(names->name) {
+      if(names->value == value)
+        return names->name;
+      ++names;
+   }
+
+   util_snprintf(rest, sizeof(rest), "0x%08lx", value);
+   return rest;
+}
+
+
+const char *
+debug_dump_enum_noprefix(const struct debug_named_value *names, 
+                         const char *prefix,
+                         unsigned long value)
+{
+   static char rest[64];
+   
+   while(names->name) {
+      if(names->value == value) {
+         const char *name = names->name;
+         while (*name == *prefix) {
+            name++;
+            prefix++;
+         }
+         return name;
+      }
+      ++names;
+   }
+
+   
+
+   util_snprintf(rest, sizeof(rest), "0x%08lx", value);
+   return rest;
+}
+
+
+const char *
+debug_dump_flags(const struct debug_named_value *names, 
+                 unsigned long value)
+{
+   static char output[4096];
+   static char rest[256];
+   int first = 1;
+
+   output[0] = '\0';
+
+   while(names->name) {
+      if((names->value & value) == names->value) {
+        if (!first)
+           util_strncat(output, "|", sizeof(output));
+        else
+           first = 0;
+        util_strncat(output, names->name, sizeof(output));
+        value &= ~names->value;
+      }
+      ++names;
+   }
+   
+   if (value) {
+      if (!first)
+        util_strncat(output, "|", sizeof(output));
+      else
+        first = 0;
+      
+      util_snprintf(rest, sizeof(rest), "0x%08lx", value);
+      util_strncat(output, rest, sizeof(output));
+   }
+   
+   if(first)
+      return "0";
+   
+   return output;
+}
+
+
+static const struct debug_named_value pipe_format_names[] = {
+#ifdef DEBUG
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_NONE),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_A8R8G8B8_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_X8R8G8B8_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_B8G8R8A8_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_B8G8R8X8_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_A1R5G5B5_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_A4R4G4B4_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R5G6B5_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_A2B10G10R10_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_L8_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_A8_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_I8_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_A8L8_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_L16_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_YCBCR),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_YCBCR_REV),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_Z16_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_Z32_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_Z32_FLOAT),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_S8Z24_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_Z24S8_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_X8Z24_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_Z24X8_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_S8_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R64_FLOAT),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R64G64_FLOAT),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R64G64B64_FLOAT),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R64G64B64A64_FLOAT),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_FLOAT),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_FLOAT),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_FLOAT),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_FLOAT),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_USCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_USCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_USCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_USCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_SNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_SNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_SNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_SNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_SSCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_SSCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_SSCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_SSCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16A16_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16_USCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16_USCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16_USCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16A16_USCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16_SNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16_SNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16_SNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16A16_SNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16_SSCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16_SSCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16_SSCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16A16_SSCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_UNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8_USCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8_USCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_USCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_USCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_USCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8_SNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8_SNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_SNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_SNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_SNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_B6G5R5_SNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_A8B8G8R8_SNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_X8B8G8R8_SNORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8_SSCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8_SSCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_SSCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_SSCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_SSCALED),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_L8_SRGB),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_A8L8_SRGB),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_SRGB),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_SRGB),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_SRGB),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_A8R8G8B8_SRGB),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_X8R8G8B8_SRGB),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_B8G8R8A8_SRGB),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_B8G8R8X8_SRGB),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_X8UB8UG8SR8S_NORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_B6UG5SR5S_NORM),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT1_RGB),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT1_RGBA),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT3_RGBA),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT5_RGBA),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT1_SRGB),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT1_SRGBA),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT3_SRGBA),
+   DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT5_SRGBA),
+#endif
+   DEBUG_NAMED_VALUE_END
+};
+
+#ifdef DEBUG
+void debug_print_format(const char *msg, unsigned fmt )
+{
+   debug_printf("%s: %s\n", msg, debug_dump_enum(pipe_format_names, fmt)); 
+}
+#endif
+
+const char *pf_name( enum pipe_format format )
+{
+   return debug_dump_enum(pipe_format_names, format);
+}
+
+
+#ifdef DEBUG
+void debug_dump_image(const char *prefix,
+                      unsigned format, unsigned cpp,
+                      unsigned width, unsigned height,
+                      unsigned stride,
+                      const void *data)     
+{
+#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
+   static unsigned no = 0; 
+   char filename[256];
+   WCHAR wfilename[sizeof(filename)];
+   ULONG_PTR iFile = 0;
+   struct {
+      unsigned format;
+      unsigned cpp;
+      unsigned width;
+      unsigned height;
+   } header;
+   unsigned char *pMap = NULL;
+   unsigned i;
+
+   util_snprintf(filename, sizeof(filename), "\\??\\c:\\%03u%s.raw", ++no, prefix);
+   for(i = 0; i < sizeof(filename); ++i)
+      wfilename[i] = (WCHAR)filename[i];
+   
+   pMap = (unsigned char *)EngMapFile(wfilename, sizeof(header) + height*width*cpp, &iFile);
+   if(!pMap)
+      return;
+   
+   header.format = format;
+   header.cpp = cpp;
+   header.width = width;
+   header.height = height;
+   memcpy(pMap, &header, sizeof(header));
+   pMap += sizeof(header);
+   
+   for(i = 0; i < height; ++i) {
+      memcpy(pMap, (unsigned char *)data + stride*i, cpp*width);
+      pMap += cpp*width;
+   }
+      
+   EngUnmapFile(iFile);
+#endif
+}
+
+void debug_dump_surface(const char *prefix,
+                        struct pipe_surface *surface)     
+{
+   unsigned surface_usage;
+   void *data;
+
+   if (!surface)
+      goto error1;
+
+   /* XXX: force mappable surface */
+   surface_usage = surface->usage;
+   surface->usage |= PIPE_BUFFER_USAGE_CPU_READ;
+   
+   data = pipe_surface_map(surface, 
+                           PIPE_BUFFER_USAGE_CPU_READ);
+   if(!data)
+      goto error2;
+   
+   debug_dump_image(prefix, 
+                    surface->format,
+                    surface->block.size, 
+                    surface->nblocksx,
+                    surface->nblocksy,
+                    surface->stride,
+                    data);
+   
+   pipe_surface_unmap(surface);
+error2:
+   surface->usage = surface_usage;
+error1:
+   ;
+}
+
+
+#pragma pack(push,2)
+struct bmp_file_header {
+   uint16_t bfType;
+   uint32_t bfSize;
+   uint16_t bfReserved1;
+   uint16_t bfReserved2;
+   uint32_t bfOffBits;
+};
+#pragma pack(pop)
+
+struct bmp_info_header {
+   uint32_t biSize;
+   int32_t biWidth;
+   int32_t biHeight;
+   uint16_t biPlanes;
+   uint16_t biBitCount;
+   uint32_t biCompression;
+   uint32_t biSizeImage;
+   int32_t biXPelsPerMeter;
+   int32_t biYPelsPerMeter;
+   uint32_t biClrUsed;
+   uint32_t biClrImportant;
+};
+
+struct bmp_rgb_quad {
+   uint8_t rgbBlue;
+   uint8_t rgbGreen;
+   uint8_t rgbRed;
+   uint8_t rgbAlpha;
+};
+
+void 
+debug_dump_surface_bmp(const char *filename,
+                       struct pipe_surface *surface)
+{
+#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
+   struct util_stream *stream;
+   unsigned surface_usage;
+   struct bmp_file_header bmfh;
+   struct bmp_info_header bmih;
+   float *rgba;
+   unsigned x, y;
+
+   if (!surface)
+      goto error1;
+
+   rgba = MALLOC(surface->width*4*sizeof(float));
+   if(!rgba)
+      goto error1;
+   
+   bmfh.bfType = 0x4d42;
+   bmfh.bfSize = 14 + 40 + surface->height*surface->width*4;
+   bmfh.bfReserved1 = 0;
+   bmfh.bfReserved2 = 0;
+   bmfh.bfOffBits = 14 + 40;
+   
+   bmih.biSize = 40;
+   bmih.biWidth = surface->width;
+   bmih.biHeight = surface->height;
+   bmih.biPlanes = 1;
+   bmih.biBitCount = 32;
+   bmih.biCompression = 0;
+   bmih.biSizeImage = surface->height*surface->width*4;
+   bmih.biXPelsPerMeter = 0;
+   bmih.biYPelsPerMeter = 0;
+   bmih.biClrUsed = 0;
+   bmih.biClrImportant = 0;
+   
+   stream = util_stream_create(filename, bmfh.bfSize);
+   if(!stream)
+      goto error2;
+   
+   util_stream_write(stream, &bmfh, 14);
+   util_stream_write(stream, &bmih, 40);
+   
+   /* XXX: force mappable surface */
+   surface_usage = surface->usage;
+   surface->usage |= PIPE_BUFFER_USAGE_CPU_READ;
+
+   y = surface->height;
+   while(y--) {
+      pipe_get_tile_rgba(surface,
+                         0, y, surface->width, 1,
+                         rgba);
+      for(x = 0; x < surface->width; ++x)
+      {
+         struct bmp_rgb_quad pixel;
+         pixel.rgbRed   = float_to_ubyte(rgba[x*4 + 0]);
+         pixel.rgbGreen = float_to_ubyte(rgba[x*4 + 1]);
+         pixel.rgbBlue  = float_to_ubyte(rgba[x*4 + 2]);
+         pixel.rgbAlpha = float_to_ubyte(rgba[x*4 + 3]);
+         util_stream_write(stream, &pixel, 4);
+      }  
+   }
+   
+   surface->usage = surface_usage;
+
+   util_stream_close(stream);
+error2:
+   FREE(rgba);
+error1:
+   ;
+#endif
+}
+
+#endif
diff --git a/src/gallium/auxiliary/util/u_debug.h b/src/gallium/auxiliary/util/u_debug.h
new file mode 100644 (file)
index 0000000..b298b9b
--- /dev/null
@@ -0,0 +1,361 @@
+/**************************************************************************
+ * 
+ * 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
+ * Cross-platform debugging helpers.
+ * 
+ * For now it just has assert and printf replacements, but it might be extended 
+ * with stack trace reports and more advanced logging in the near future. 
+ * 
+ * @author Jose Fonseca <jrfonseca@tungstengraphics.com>
+ */
+
+#ifndef U_DEBUG_H_
+#define U_DEBUG_H_
+
+
+#include <stdarg.h>
+
+#include "pipe/p_compiler.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#if defined(DBG) || defined(DEBUG)
+#ifndef DEBUG
+#define DEBUG 1
+#endif
+#else
+#ifndef NDEBUG
+#define NDEBUG 1
+#endif
+#endif
+
+   
+/* MSVC bebore VC7 does not have the __FUNCTION__ macro */
+#if defined(_MSC_VER) && _MSC_VER < 1300
+#define __FUNCTION__ "???"
+#endif
+
+
+void _debug_vprintf(const char *format, va_list ap);
+   
+
+static INLINE void
+_debug_printf(const char *format, ...)
+{
+   va_list ap;
+   va_start(ap, format);
+   _debug_vprintf(format, ap);
+   va_end(ap);
+}
+
+
+/**
+ * Print debug messages.
+ *
+ * The actual channel used to output debug message is platform specific. To 
+ * avoid misformating or truncation, follow these rules of thumb:   
+ * - output whole lines
+ * - avoid outputing large strings (512 bytes is the current maximum length 
+ * that is guaranteed to be printed in all platforms)
+ */
+static INLINE void
+debug_printf(const char *format, ...)
+{
+#ifdef DEBUG
+   va_list ap;
+   va_start(ap, format);
+   _debug_vprintf(format, ap);
+   va_end(ap);
+#else
+   (void) format; /* silence warning */
+#endif
+}
+
+
+#ifdef DEBUG
+#define debug_vprintf(_format, _ap) _debug_vprintf(_format, _ap)
+#else
+#define debug_vprintf(_format, _ap) ((void)0)
+#endif
+
+
+#ifdef DEBUG
+/**
+ * Dump a blob in hex to the same place that debug_printf sends its
+ * messages.
+ */
+void debug_print_blob( const char *name, const void *blob, unsigned size );
+
+/* Print a message along with a prettified format string
+ */
+void debug_print_format(const char *msg, unsigned fmt );
+#else
+#define debug_print_blob(_name, _blob, _size) ((void)0)
+#define debug_print_format(_msg, _fmt) ((void)0)
+#endif
+
+
+void _debug_break(void);
+
+
+/**
+ * Hard-coded breakpoint.
+ */
+#ifdef DEBUG
+#if defined(PIPE_ARCH_X86) && defined(PIPE_CC_GCC)
+#define debug_break() __asm("int3")
+#elif defined(PIPE_ARCH_X86) && defined(PIPE_CC_MSVC)
+#define debug_break()  do { _asm {int 3} } while(0)
+#else
+#define debug_break() _debug_break()
+#endif
+#else /* !DEBUG */
+#define debug_break() ((void)0)
+#endif /* !DEBUG */
+
+
+long
+debug_get_num_option(const char *name, long dfault);
+
+void _debug_assert_fail(const char *expr, 
+                        const char *file, 
+                        unsigned line, 
+                        const char *function);
+
+
+/** 
+ * Assert macro
+ * 
+ * Do not expect that the assert call terminates -- errors must be handled 
+ * regardless of assert behavior.
+ */
+#ifdef DEBUG
+#define debug_assert(expr) ((expr) ? (void)0 : _debug_assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__))
+#else
+#define debug_assert(expr) ((void)0)
+#endif
+
+
+/** Override standard assert macro */
+#ifdef assert
+#undef assert
+#endif
+#define assert(expr) debug_assert(expr)
+
+
+/**
+ * Output the current function name.
+ */
+#ifdef DEBUG
+#define debug_checkpoint() \
+   _debug_printf("%s\n", __FUNCTION__)
+#else
+#define debug_checkpoint() \
+   ((void)0) 
+#endif
+
+
+/**
+ * Output the full source code position.
+ */
+#ifdef DEBUG
+#define debug_checkpoint_full() \
+   _debug_printf("%s:%u:%s", __FILE__, __LINE__, __FUNCTION__) 
+#else
+#define debug_checkpoint_full() \
+   ((void)0) 
+#endif
+
+
+/**
+ * Output a warning message. Muted on release version.
+ */
+#ifdef DEBUG
+#define debug_warning(__msg) \
+   _debug_printf("%s:%u:%s: warning: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg)
+#else
+#define debug_warning(__msg) \
+   ((void)0) 
+#endif
+
+
+/**
+ * Output an error message. Not muted on release version.
+ */
+#ifdef DEBUG
+#define debug_error(__msg) \
+   _debug_printf("%s:%u:%s: error: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg) 
+#else
+#define debug_error(__msg) \
+   _debug_printf("error: %s\n", __msg)
+#endif
+
+
+/**
+ * Used by debug_dump_enum and debug_dump_flags to describe symbols.
+ */
+struct debug_named_value
+{
+   const char *name;
+   unsigned long value;
+};
+
+
+/**
+ * Some C pre-processor magic to simplify creating named values.
+ * 
+ * Example:
+ * @code
+ * static const debug_named_value my_names[] = {
+ *    DEBUG_NAMED_VALUE(MY_ENUM_VALUE_X),
+ *    DEBUG_NAMED_VALUE(MY_ENUM_VALUE_Y),
+ *    DEBUG_NAMED_VALUE(MY_ENUM_VALUE_Z),
+ *    DEBUG_NAMED_VALUE_END
+ * };
+ * 
+ *    ...
+ *    debug_printf("%s = %s\n", 
+ *                 name,
+ *                 debug_dump_enum(my_names, my_value));
+ *    ...
+ * @endcode
+ */
+#define DEBUG_NAMED_VALUE(__symbol) {#__symbol, (unsigned long)__symbol} 
+#define DEBUG_NAMED_VALUE_END {NULL, 0} 
+
+
+/**
+ * Convert a enum value to a string.
+ */
+const char *
+debug_dump_enum(const struct debug_named_value *names, 
+                unsigned long value);
+
+const char *
+debug_dump_enum_noprefix(const struct debug_named_value *names, 
+                         const char *prefix,
+                         unsigned long value);
+
+
+/**
+ * Convert binary flags value to a string.
+ */
+const char *
+debug_dump_flags(const struct debug_named_value *names, 
+                 unsigned long value);
+
+
+/**
+ * Get option.
+ * 
+ * It is an alias for getenv on Linux. 
+ * 
+ * On Windows it reads C:\gallium.cfg, which is a text file with CR+LF line 
+ * endings with one option per line as
+ *  
+ *   NAME=value
+ * 
+ * This file must be terminated with an extra empty line.
+ */
+const char *
+debug_get_option(const char *name, const char *dfault);
+
+boolean
+debug_get_bool_option(const char *name, boolean dfault);
+
+long
+debug_get_num_option(const char *name, long dfault);
+
+unsigned long
+debug_get_flags_option(const char *name, 
+                       const struct debug_named_value *flags,
+                       unsigned long dfault);
+
+
+void *
+debug_malloc(const char *file, unsigned line, const char *function,
+             size_t size);
+
+void
+debug_free(const char *file, unsigned line, const char *function,
+           void *ptr);
+
+void *
+debug_calloc(const char *file, unsigned line, const char *function,
+             size_t count, size_t size );
+
+void *
+debug_realloc(const char *file, unsigned line, const char *function,
+              void *old_ptr, size_t old_size, size_t new_size );
+
+unsigned long
+debug_memory_begin(void);
+
+void 
+debug_memory_end(unsigned long beginning);
+
+
+#if defined(PROFILE) && defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
+
+void
+debug_profile_start(void);
+
+void 
+debug_profile_stop(void);
+
+#endif
+
+
+#ifdef DEBUG
+struct pipe_surface;
+void debug_dump_image(const char *prefix,
+                      unsigned format, unsigned cpp,
+                      unsigned width, unsigned height,
+                      unsigned stride,
+                      const void *data);
+void debug_dump_surface(const char *prefix,
+                        struct pipe_surface *surface);   
+void debug_dump_surface_bmp(const char *filename,
+                            struct pipe_surface *surface);
+#else
+#define debug_dump_image(prefix, format, cpp, width, height, stride, data) ((void)0)
+#define debug_dump_surface(prefix, surface) ((void)0)
+#define debug_dump_surface_bmp(filename, surface) ((void)0)
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* U_DEBUG_H_ */
diff --git a/src/gallium/auxiliary/util/u_debug_memory.c b/src/gallium/auxiliary/util/u_debug_memory.c
new file mode 100644 (file)
index 0000000..f6c136f
--- /dev/null
@@ -0,0 +1,311 @@
+/**************************************************************************
+ * 
+ * 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
+ * Memory debugging.
+ * 
+ * @author José Fonseca <jrfonseca@tungstengraphics.com>
+ */
+
+#include "pipe/p_config.h" 
+
+#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
+#include <windows.h>
+#include <winddi.h>
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
+#include <wdm.h>
+#else
+#include <stdio.h>
+#include <stdlib.h>
+#endif
+
+#include "util/u_debug.h" 
+#include "util/u_double_list.h" 
+
+
+#define DEBUG_MEMORY_MAGIC 0x6e34090aU 
+
+
+#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) && !defined(WINCE)
+#define real_malloc(_size) EngAllocMem(0, _size, 'D3AG')
+#define real_free(_ptr) EngFreeMem(_ptr)
+#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
+#define real_malloc(_size) ExAllocatePool(0, _size)
+#define real_free(_ptr) ExFreePool(_ptr)
+#else
+#define real_malloc(_size) malloc(_size)
+#define real_free(_ptr) free(_ptr)
+#endif
+
+
+struct debug_memory_header 
+{
+   struct list_head head;
+   
+   unsigned long no;
+   const char *file;
+   unsigned line;
+   const char *function;
+   size_t size;
+   unsigned magic;
+};
+
+struct debug_memory_footer
+{
+   unsigned magic;
+};
+
+
+static struct list_head list = { &list, &list };
+
+static unsigned long last_no = 0;
+
+
+static INLINE struct debug_memory_header *
+header_from_data(void *data)
+{
+   if(data)
+      return (struct debug_memory_header *)((char *)data - sizeof(struct debug_memory_header));
+   else
+      return NULL;
+}
+
+static INLINE void *
+data_from_header(struct debug_memory_header *hdr)
+{
+   if(hdr)
+      return (void *)((char *)hdr + sizeof(struct debug_memory_header));
+   else
+      return NULL;
+}
+
+static INLINE struct debug_memory_footer *
+footer_from_header(struct debug_memory_header *hdr)
+{
+   if(hdr)
+      return (struct debug_memory_footer *)((char *)hdr + sizeof(struct debug_memory_header) + hdr->size);
+   else
+      return NULL;
+}
+
+
+void *
+debug_malloc(const char *file, unsigned line, const char *function,
+             size_t size) 
+{
+   struct debug_memory_header *hdr;
+   struct debug_memory_footer *ftr;
+   
+   hdr = real_malloc(sizeof(*hdr) + size + sizeof(*ftr));
+   if(!hdr) {
+      debug_printf("%s:%u:%s: out of memory when trying to allocate %lu bytes\n",
+                   file, line, function,
+                   (long unsigned)size);
+      return NULL;
+   }
+   hdr->no = last_no++;
+   hdr->file = file;
+   hdr->line = line;
+   hdr->function = function;
+   hdr->size = size;
+   hdr->magic = DEBUG_MEMORY_MAGIC;
+
+   ftr = footer_from_header(hdr);
+   ftr->magic = DEBUG_MEMORY_MAGIC;
+   
+   LIST_ADDTAIL(&hdr->head, &list);
+   
+   return data_from_header(hdr);
+}
+
+void
+debug_free(const char *file, unsigned line, const char *function,
+           void *ptr) 
+{
+   struct debug_memory_header *hdr;
+   struct debug_memory_footer *ftr;
+   
+   if(!ptr)
+      return;
+   
+   hdr = header_from_data(ptr);
+   if(hdr->magic != DEBUG_MEMORY_MAGIC) {
+      debug_printf("%s:%u:%s: freeing bad or corrupted memory %p\n",
+                   file, line, function,
+                   ptr);
+      debug_assert(0);
+      return;
+   }
+
+   ftr = footer_from_header(hdr);
+   if(ftr->magic != DEBUG_MEMORY_MAGIC) {
+      debug_printf("%s:%u:%s: buffer overflow %p\n",
+                   hdr->file, hdr->line, hdr->function,
+                   ptr);
+      debug_assert(0);
+   }
+
+   LIST_DEL(&hdr->head);
+   hdr->magic = 0;
+   ftr->magic = 0;
+   
+   real_free(hdr);
+}
+
+void *
+debug_calloc(const char *file, unsigned line, const char *function,
+             size_t count, size_t size )
+{
+   void *ptr = debug_malloc( file, line, function, count * size );
+   if( ptr )
+      memset( ptr, 0, count * size );
+   return ptr;
+}
+
+void *
+debug_realloc(const char *file, unsigned line, const char *function,
+              void *old_ptr, size_t old_size, size_t new_size )
+{
+   struct debug_memory_header *old_hdr, *new_hdr;
+   struct debug_memory_footer *old_ftr, *new_ftr;
+   void *new_ptr;
+   
+   if(!old_ptr)
+      return debug_malloc( file, line, function, new_size );
+   
+   if(!new_size) {
+      debug_free( file, line, function, old_ptr );
+      return NULL;
+   }
+   
+   old_hdr = header_from_data(old_ptr);
+   if(old_hdr->magic != DEBUG_MEMORY_MAGIC) {
+      debug_printf("%s:%u:%s: reallocating bad or corrupted memory %p\n",
+                   file, line, function,
+                   old_ptr);
+      debug_assert(0);
+      return NULL;
+   }
+   
+   old_ftr = footer_from_header(old_hdr);
+   if(old_ftr->magic != DEBUG_MEMORY_MAGIC) {
+      debug_printf("%s:%u:%s: buffer overflow %p\n",
+                   old_hdr->file, old_hdr->line, old_hdr->function,
+                   old_ptr);
+      debug_assert(0);
+   }
+
+   /* alloc new */
+   new_hdr = real_malloc(sizeof(*new_hdr) + new_size + sizeof(*new_ftr));
+   if(!new_hdr) {
+      debug_printf("%s:%u:%s: out of memory when trying to allocate %lu bytes\n",
+                   file, line, function,
+                   (long unsigned)new_size);
+      return NULL;
+   }
+   new_hdr->no = old_hdr->no;
+   new_hdr->file = old_hdr->file;
+   new_hdr->line = old_hdr->line;
+   new_hdr->function = old_hdr->function;
+   new_hdr->size = new_size;
+   new_hdr->magic = DEBUG_MEMORY_MAGIC;
+   
+   new_ftr = footer_from_header(new_hdr);
+   new_ftr->magic = DEBUG_MEMORY_MAGIC;
+   
+   LIST_REPLACE(&old_hdr->head, &new_hdr->head);
+
+   /* copy data */
+   new_ptr = data_from_header(new_hdr);
+   memcpy( new_ptr, old_ptr, old_size < new_size ? old_size : new_size );
+
+   /* free old */
+   old_hdr->magic = 0;
+   old_ftr->magic = 0;
+   real_free(old_hdr);
+
+   return new_ptr;
+}
+
+unsigned long
+debug_memory_begin(void)
+{
+   return last_no;
+}
+
+void 
+debug_memory_end(unsigned long start_no)
+{
+   size_t total_size = 0;
+   struct list_head *entry;
+
+   if(start_no == last_no)
+      return;
+
+   entry = list.prev;
+   for (; entry != &list; entry = entry->prev) {
+      struct debug_memory_header *hdr;
+      void *ptr;
+      struct debug_memory_footer *ftr;
+
+      hdr = LIST_ENTRY(struct debug_memory_header, entry, head);
+      ptr = data_from_header(hdr);
+      ftr = footer_from_header(hdr);
+
+      if(hdr->magic != DEBUG_MEMORY_MAGIC) {
+         debug_printf("%s:%u:%s: bad or corrupted memory %p\n",
+                      hdr->file, hdr->line, hdr->function,
+                      ptr);
+         debug_assert(0);
+      }
+
+      if((start_no <= hdr->no && hdr->no < last_no) ||
+        (last_no < start_no && (hdr->no < last_no || start_no <= hdr->no))) {
+        debug_printf("%s:%u:%s: %u bytes at %p not freed\n",
+                     hdr->file, hdr->line, hdr->function,
+                     hdr->size, ptr);
+        total_size += hdr->size;
+      }
+
+      if(ftr->magic != DEBUG_MEMORY_MAGIC) {
+         debug_printf("%s:%u:%s: buffer overflow %p\n",
+                      hdr->file, hdr->line, hdr->function,
+                      ptr);
+         debug_assert(0);
+      }
+   }
+
+   if(total_size) {
+      debug_printf("Total of %u KB of system memory apparently leaked\n",
+                  (total_size + 1023)/1024);
+   }
+   else {
+      debug_printf("No memory leaks detected.\n");
+   }
+}
diff --git a/src/gallium/auxiliary/util/u_debug_profile.c b/src/gallium/auxiliary/util/u_debug_profile.c
new file mode 100644 (file)
index 0000000..5f9772e
--- /dev/null
@@ -0,0 +1,320 @@
+/**************************************************************************
+ * 
+ * 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
+ * Poor-man profiling.
+ * 
+ * @author José Fonseca <jrfonseca@tungstengraphics.com>
+ * 
+ * @sa http://blogs.msdn.com/joshpoley/archive/2008/03/12/poor-man-s-profiler.aspx
+ * @sa http://www.johnpanzer.com/aci_cuj/index.html
+ */
+
+#include "pipe/p_config.h" 
+
+#if defined(PROFILE) && defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
+
+#include <windows.h>
+#include <winddi.h>
+
+#include "pipe/p_debug.h" 
+#include "util/u_string.h" 
+
+
+#define PROFILE_TABLE_SIZE (1024*1024)
+#define FILE_NAME_SIZE 256
+
+struct debug_profile_entry
+{
+   uintptr_t caller;
+   uintptr_t callee;
+   uint64_t samples;
+};
+
+static unsigned long enabled = 0;
+
+static WCHAR wFileName[FILE_NAME_SIZE] = L"\\??\\c:\\00000000.prof";
+static ULONG_PTR iFile = 0;
+
+static struct debug_profile_entry *table = NULL;
+static unsigned long free_table_entries = 0;
+static unsigned long max_table_entries = 0;
+
+uint64_t start_stamp = 0;
+uint64_t end_stamp = 0;
+
+
+static void
+debug_profile_entry(uintptr_t caller, uintptr_t callee, uint64_t samples)
+{
+   unsigned hash = ( caller + callee ) & PROFILE_TABLE_SIZE - 1;
+   
+   while(1) {
+      if(table[hash].caller == 0 && table[hash].callee == 0) {
+         table[hash].caller = caller;
+         table[hash].callee = callee;
+         table[hash].samples = samples;
+         --free_table_entries;
+         break;
+      }
+      else if(table[hash].caller == caller && table[hash].callee == callee) {
+         table[hash].samples += samples;
+         break;
+      }
+      else {
+         ++hash;
+      }
+   }
+}
+
+
+static uintptr_t caller_stack[1024];
+static unsigned last_caller = 0;
+
+
+static int64_t delta(void) {
+   int64_t result = end_stamp - start_stamp;
+   if(result > UINT64_C(0xffffffff))
+      result = 0;
+   return result;
+}
+
+
+static void __cdecl 
+debug_profile_enter(uintptr_t callee)
+{
+   uintptr_t caller = last_caller ? caller_stack[last_caller - 1] : 0;
+                
+   if (caller)
+      debug_profile_entry(caller, 0, delta());
+   debug_profile_entry(caller, callee, 1);
+   caller_stack[last_caller++] = callee;
+}
+
+
+static void __cdecl
+debug_profile_exit(uintptr_t callee)
+{
+   debug_profile_entry(callee, 0, delta());
+   if(last_caller)
+      --last_caller;
+}
+   
+   
+/**
+ * Called at the start of every method or function.
+ * 
+ * @sa http://msdn.microsoft.com/en-us/library/c63a9b7h.aspx
+ */
+void __declspec(naked) __cdecl 
+_penter(void) {
+   _asm {
+      push eax
+      mov eax, [enabled]
+      test eax, eax
+      jz skip
+
+      push edx
+      
+      rdtsc
+      mov dword ptr [end_stamp], eax
+      mov dword ptr [end_stamp+4], edx
+
+      xor eax, eax
+      mov [enabled], eax
+
+      mov eax, [esp+8]
+
+      push ebx
+      push ecx
+      push ebp
+      push edi
+      push esi
+
+      push eax
+      call debug_profile_enter
+      add esp, 4
+
+      pop esi
+      pop edi
+      pop ebp
+      pop ecx
+      pop ebx
+
+      mov eax, 1
+      mov [enabled], eax 
+
+      rdtsc
+      mov dword ptr [start_stamp], eax
+      mov dword ptr [start_stamp+4], edx
+      
+      pop edx
+skip:
+      pop eax
+      ret
+   }
+}
+
+
+/**
+ * Called at the end of Calls the end of every method or function.
+ * 
+ * @sa http://msdn.microsoft.com/en-us/library/xc11y76y.aspx
+ */
+void __declspec(naked) __cdecl 
+_pexit(void) {
+   _asm {
+      push eax
+      mov eax, [enabled]
+      test eax, eax
+      jz skip
+
+      push edx
+      
+      rdtsc
+      mov dword ptr [end_stamp], eax
+      mov dword ptr [end_stamp+4], edx
+
+      xor eax, eax
+      mov [enabled], eax
+
+      mov eax, [esp+8]
+
+      push ebx
+      push ecx
+      push ebp
+      push edi
+      push esi
+
+      push eax
+      call debug_profile_exit
+      add esp, 4
+
+      pop esi
+      pop edi
+      pop ebp
+      pop ecx
+      pop ebx
+
+      mov eax, 1
+      mov [enabled], eax 
+
+      rdtsc
+      mov dword ptr [start_stamp], eax
+      mov dword ptr [start_stamp+4], edx
+      
+      pop edx
+skip:
+      pop eax
+      ret
+   }
+}
+
+
+/**
+ * Reference function for calibration. 
+ */
+void __declspec(naked) 
+__debug_profile_reference(void) {
+   _asm {
+      call _penter
+      call _pexit
+      ret
+   }
+}
+
+
+void
+debug_profile_start(void)
+{
+   WCHAR *p;
+
+   // increment starting from the less significant digit
+   p = &wFileName[14];
+   while(1) {
+      if(*p == '9') {
+         *p-- = '0';
+      }
+      else {
+         *p += 1;
+         break;
+      }
+   }
+
+   table = EngMapFile(wFileName, 
+                      PROFILE_TABLE_SIZE*sizeof(struct debug_profile_entry), 
+                      &iFile);
+   if(table) {
+      unsigned i;
+      
+      free_table_entries = max_table_entries = PROFILE_TABLE_SIZE;
+      memset(table, 0, PROFILE_TABLE_SIZE*sizeof(struct debug_profile_entry));
+      
+      table[0].caller = (uintptr_t)&__debug_profile_reference;
+      table[0].callee = 0;
+      table[0].samples = 0;
+      --free_table_entries;
+
+      _asm {
+         push edx
+         push eax
+      
+         rdtsc
+         mov dword ptr [start_stamp], eax
+         mov dword ptr [start_stamp+4], edx
+         
+         pop edx
+         pop eax
+      }
+
+      last_caller = 0;
+      
+      enabled = 1;
+
+      for(i = 0; i < 8; ++i) {
+         _asm {
+            call __debug_profile_reference
+         }
+      }
+   }
+}
+
+
+void 
+debug_profile_stop(void)
+{
+   enabled = 0;
+
+   if(iFile)
+      EngUnmapFile(iFile);
+   iFile = 0;
+   table = NULL;
+   free_table_entries = max_table_entries = 0;
+}
+
+#endif /* PROFILE */
index 2b4cdab6cf3ca85583a5fb5c39c8140fdcfe2c51..7c20c7ce7bb82e6d073acb23fd62eb441ef054c7 100644 (file)
@@ -35,7 +35,7 @@
 
 
 #include "pipe/p_context.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_inlines.h"
 #include "pipe/p_shader_tokens.h"
index 2d15932ce3bb847eb3a84156d86a127642967956..6da7353e259a92b565dbf6da3987d21bc0621d81 100644 (file)
@@ -34,7 +34,7 @@
 
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 #include "util/u_memory.h"
 #include "util/u_handle_table.h"
index 0bc8de9632cfe71fb698943b102aeb0e9260ea62..2f83e318e44e17b8bef316ec5c6783dfd73f1d7b 100644 (file)
@@ -39,7 +39,7 @@
 
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 #include "cso_cache/cso_hash.h"
 
index 01b17ddb1b31dcf4ec28885643cd75eaf8be538c..3f70809efdc6868e161be4aabf75f8d12178316d 100644 (file)
@@ -35,7 +35,7 @@
 
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_error.h"
 
 #include "cso_cache/cso_hash.h"
index e999cefe748c0a39d8ef9304a4e8a30b35ddcd86..6be365e53bbc3fd56c8ac3d3d9a4152aef004ba7 100644 (file)
@@ -1,5 +1,5 @@
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "u_linear.h"
 
 void
index ab6f39ac31f44bab94038acb44c714f66efb93f2..1ecde7a9125cc3bde03bcdde144d2d1ef7fe8dd8 100644 (file)
@@ -40,7 +40,7 @@
 
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 
 #ifdef __cplusplus
index 626b13af83d105422d7829abde2487153dfb650d..ceb3a1cb6154d20b9ad8d3ef826c8d5e6e4a8748 100644 (file)
@@ -36,7 +36,7 @@
 
 
 #include "util/u_pointer.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 
 #ifdef __cplusplus
@@ -56,7 +56,7 @@ extern "C" {
 
 /* memory debugging */
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 #define MALLOC( _size ) \
    debug_malloc( __FILE__, __LINE__, __FUNCTION__, _size )
index 45ce257b5e5102154e2007ea8643c9ea874c8acb..151a480d34d084f65a5dd3074ac6cf054a1d8dcf 100644 (file)
@@ -24,7 +24,7 @@
 
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 #include "util/u_memory.h"
 #include "util/u_mm.h"
index 706155e99a7905ba605f2a6e8fdb10771385d9a5..3cd2d52c64ceb50cab47df852bb6e27355384e37 100644 (file)
@@ -34,7 +34,7 @@
 
 
 #include "pipe/p_context.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_inlines.h"
 #include "pipe/p_screen.h"
index b8a0d4a265f27b4b0085ca1e174cef629f74f05c..af25dd3718a1e04cfcfc9f042b2622b6665b3522 100644 (file)
@@ -1,7 +1,7 @@
 
 #include "cell/common.h"
 #include "pipe/p_shader_tokens.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "tgsi/tgsi_parse.h"
 //#include "tgsi_build.h"
 #include "tgsi/tgsi_util.h"
index a300b61c3b9abbeec20b2bd9b4a73a3c9453a0a4..e08582efaba2d870a9a20d05d870ca5c49a40a7d 100644 (file)
@@ -31,7 +31,7 @@
 #include "i915_debug.h"
 #include "i915_batch.h"
 #include "pipe/internal/p_winsys_screen.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 
 static void
index f49f6d6ed16954a2f9f6a47c245b9aafd0bf1606..2dc2e073291619884d58e6c353990c42cba2a1e6 100644 (file)
@@ -40,7 +40,7 @@
 
 #include "draw/draw_context.h"
 #include "draw/draw_vbuf.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_inlines.h"
 #include "pipe/internal/p_winsys_screen.h"
 #include "util/u_math.h"
index 4a94ddefa6a17731acc2e7ae5c52c1b8b14018f4..4adfb0c02f525754088683a2e2ea94e4d22472b7 100644 (file)
@@ -30,7 +30,7 @@
   */
     
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 #include "brw_eu.h"
 
index 4ae4ff494043cc7a67d369d9f6d8ca4294c2fdd9..029b01e17d519c86312db14d269bb1a0f0fe898d 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __NOUVEAU_STATEOBJ_H__
 #define __NOUVEAU_STATEOBJ_H__
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 struct nouveau_stateobj_reloc {
        struct pipe_buffer *bo;
index 18a8872ae380d7f9b24eddc8f90071d808967456..221bee4777a0a033e6d61548e4c351a000f9af91 100644 (file)
@@ -1,5 +1,5 @@
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_inlines.h"
 #include "pipe/internal/p_winsys_screen.h"
 #include "pipe/p_compiler.h"
index 7435d873154d311b7b18d6add6c010255cfe7582..5e5436be537d0e51f6b5e6ee360d91bd7153b32a 100644 (file)
@@ -38,7 +38,7 @@
  */
 
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_inlines.h"
 #include "pipe/internal/p_winsys_screen.h"
 
index 4dd7052814ef6a144f4f7822d03c7e265adf3b28..187136ce7b742fcb2162853a7c1dc17a9be7c91d 100644 (file)
@@ -38,7 +38,7 @@
  */
 
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_inlines.h"
 #include "pipe/internal/p_winsys_screen.h"
 
index 794fa2b9b81b7d0b7acb50277a31f173de570524..196537a432d202ff3b1ad23e9a4aae05332320ae 100644 (file)
@@ -21,7 +21,7 @@
  * USE OR OTHER DEALINGS IN THE SOFTWARE. */
 
 #include "r300_chipset.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 /* r300_chipset: A file all to itself for deducing the various properties of
  * Radeons. */
index c8533d764dfcb71db48fa7ad25212f48279ba9c5..da99a3be6b68604d360867707bc6f8dd4e5aa180 100644 (file)
@@ -23,7 +23,7 @@
 #include "util/u_math.h"
 #include "util/u_pack_color.h"
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/internal/p_winsys_screen.h"
 
 #include "r300_context.h"
index 7831900ec29879118f99e232b289e278e3451c0a..6704175964392607e17fdac93863904f4becc1d1 100644 (file)
@@ -30,7 +30,7 @@
 
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_context.h"
 
 
index a0ead0ded3344fc520015be88a3c4cbe212e3959..d98cef221b701ddd6ff9a6558167b2958a31c00c 100644 (file)
@@ -45,7 +45,7 @@
 #endif
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "util/u_memory.h"
 #include "util/u_string.h"
 #include "util/u_stream.h"
index 0fd2a405569d27ba1b5371396bae9e951ed83d0b..3670cb915edeb6afea117efd2878a556a0784247 100644 (file)
@@ -30,7 +30,7 @@
 
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/internal/p_winsys_screen.h"
 
 
diff --git a/src/gallium/include/pipe/p_debug.h b/src/gallium/include/pipe/p_debug.h
deleted file mode 100644 (file)
index e9c9598..0000000
+++ /dev/null
@@ -1,361 +0,0 @@
-/**************************************************************************
- * 
- * 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
- * Cross-platform debugging helpers.
- * 
- * For now it just has assert and printf replacements, but it might be extended 
- * with stack trace reports and more advanced logging in the near future. 
- * 
- * @author Jose Fonseca <jrfonseca@tungstengraphics.com>
- */
-
-#ifndef P_DEBUG_H_
-#define P_DEBUG_H_
-
-
-#include <stdarg.h>
-
-#include "p_compiler.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#if defined(DBG) || defined(DEBUG)
-#ifndef DEBUG
-#define DEBUG 1
-#endif
-#else
-#ifndef NDEBUG
-#define NDEBUG 1
-#endif
-#endif
-
-   
-/* MSVC bebore VC7 does not have the __FUNCTION__ macro */
-#if defined(_MSC_VER) && _MSC_VER < 1300
-#define __FUNCTION__ "???"
-#endif
-
-
-void _debug_vprintf(const char *format, va_list ap);
-   
-
-static INLINE void
-_debug_printf(const char *format, ...)
-{
-   va_list ap;
-   va_start(ap, format);
-   _debug_vprintf(format, ap);
-   va_end(ap);
-}
-
-
-/**
- * Print debug messages.
- *
- * The actual channel used to output debug message is platform specific. To 
- * avoid misformating or truncation, follow these rules of thumb:   
- * - output whole lines
- * - avoid outputing large strings (512 bytes is the current maximum length 
- * that is guaranteed to be printed in all platforms)
- */
-static INLINE void
-debug_printf(const char *format, ...)
-{
-#ifdef DEBUG
-   va_list ap;
-   va_start(ap, format);
-   _debug_vprintf(format, ap);
-   va_end(ap);
-#else
-   (void) format; /* silence warning */
-#endif
-}
-
-
-#ifdef DEBUG
-#define debug_vprintf(_format, _ap) _debug_vprintf(_format, _ap)
-#else
-#define debug_vprintf(_format, _ap) ((void)0)
-#endif
-
-
-#ifdef DEBUG
-/**
- * Dump a blob in hex to the same place that debug_printf sends its
- * messages.
- */
-void debug_print_blob( const char *name, const void *blob, unsigned size );
-
-/* Print a message along with a prettified format string
- */
-void debug_print_format(const char *msg, unsigned fmt );
-#else
-#define debug_print_blob(_name, _blob, _size) ((void)0)
-#define debug_print_format(_msg, _fmt) ((void)0)
-#endif
-
-
-void _debug_break(void);
-
-
-/**
- * Hard-coded breakpoint.
- */
-#ifdef DEBUG
-#if defined(PIPE_ARCH_X86) && defined(PIPE_CC_GCC)
-#define debug_break() __asm("int3")
-#elif defined(PIPE_ARCH_X86) && defined(PIPE_CC_MSVC)
-#define debug_break()  do { _asm {int 3} } while(0)
-#else
-#define debug_break() _debug_break()
-#endif
-#else /* !DEBUG */
-#define debug_break() ((void)0)
-#endif /* !DEBUG */
-
-
-long
-debug_get_num_option(const char *name, long dfault);
-
-void _debug_assert_fail(const char *expr, 
-                        const char *file, 
-                        unsigned line, 
-                        const char *function);
-
-
-/** 
- * Assert macro
- * 
- * Do not expect that the assert call terminates -- errors must be handled 
- * regardless of assert behavior.
- */
-#ifdef DEBUG
-#define debug_assert(expr) ((expr) ? (void)0 : _debug_assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__))
-#else
-#define debug_assert(expr) ((void)0)
-#endif
-
-
-/** Override standard assert macro */
-#ifdef assert
-#undef assert
-#endif
-#define assert(expr) debug_assert(expr)
-
-
-/**
- * Output the current function name.
- */
-#ifdef DEBUG
-#define debug_checkpoint() \
-   _debug_printf("%s\n", __FUNCTION__)
-#else
-#define debug_checkpoint() \
-   ((void)0) 
-#endif
-
-
-/**
- * Output the full source code position.
- */
-#ifdef DEBUG
-#define debug_checkpoint_full() \
-   _debug_printf("%s:%u:%s", __FILE__, __LINE__, __FUNCTION__) 
-#else
-#define debug_checkpoint_full() \
-   ((void)0) 
-#endif
-
-
-/**
- * Output a warning message. Muted on release version.
- */
-#ifdef DEBUG
-#define debug_warning(__msg) \
-   _debug_printf("%s:%u:%s: warning: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg)
-#else
-#define debug_warning(__msg) \
-   ((void)0) 
-#endif
-
-
-/**
- * Output an error message. Not muted on release version.
- */
-#ifdef DEBUG
-#define debug_error(__msg) \
-   _debug_printf("%s:%u:%s: error: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg) 
-#else
-#define debug_error(__msg) \
-   _debug_printf("error: %s\n", __msg)
-#endif
-
-
-/**
- * Used by debug_dump_enum and debug_dump_flags to describe symbols.
- */
-struct debug_named_value
-{
-   const char *name;
-   unsigned long value;
-};
-
-
-/**
- * Some C pre-processor magic to simplify creating named values.
- * 
- * Example:
- * @code
- * static const debug_named_value my_names[] = {
- *    DEBUG_NAMED_VALUE(MY_ENUM_VALUE_X),
- *    DEBUG_NAMED_VALUE(MY_ENUM_VALUE_Y),
- *    DEBUG_NAMED_VALUE(MY_ENUM_VALUE_Z),
- *    DEBUG_NAMED_VALUE_END
- * };
- * 
- *    ...
- *    debug_printf("%s = %s\n", 
- *                 name,
- *                 debug_dump_enum(my_names, my_value));
- *    ...
- * @endcode
- */
-#define DEBUG_NAMED_VALUE(__symbol) {#__symbol, (unsigned long)__symbol} 
-#define DEBUG_NAMED_VALUE_END {NULL, 0} 
-
-
-/**
- * Convert a enum value to a string.
- */
-const char *
-debug_dump_enum(const struct debug_named_value *names, 
-                unsigned long value);
-
-const char *
-debug_dump_enum_noprefix(const struct debug_named_value *names, 
-                         const char *prefix,
-                         unsigned long value);
-
-
-/**
- * Convert binary flags value to a string.
- */
-const char *
-debug_dump_flags(const struct debug_named_value *names, 
-                 unsigned long value);
-
-
-/**
- * Get option.
- * 
- * It is an alias for getenv on Linux. 
- * 
- * On Windows it reads C:\gallium.cfg, which is a text file with CR+LF line 
- * endings with one option per line as
- *  
- *   NAME=value
- * 
- * This file must be terminated with an extra empty line.
- */
-const char *
-debug_get_option(const char *name, const char *dfault);
-
-boolean
-debug_get_bool_option(const char *name, boolean dfault);
-
-long
-debug_get_num_option(const char *name, long dfault);
-
-unsigned long
-debug_get_flags_option(const char *name, 
-                       const struct debug_named_value *flags,
-                       unsigned long dfault);
-
-
-void *
-debug_malloc(const char *file, unsigned line, const char *function,
-             size_t size);
-
-void
-debug_free(const char *file, unsigned line, const char *function,
-           void *ptr);
-
-void *
-debug_calloc(const char *file, unsigned line, const char *function,
-             size_t count, size_t size );
-
-void *
-debug_realloc(const char *file, unsigned line, const char *function,
-              void *old_ptr, size_t old_size, size_t new_size );
-
-unsigned long
-debug_memory_begin(void);
-
-void 
-debug_memory_end(unsigned long beginning);
-
-
-#if defined(PROFILE) && defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
-
-void
-debug_profile_start(void);
-
-void 
-debug_profile_stop(void);
-
-#endif
-
-
-#ifdef DEBUG
-struct pipe_surface;
-void debug_dump_image(const char *prefix,
-                      unsigned format, unsigned cpp,
-                      unsigned width, unsigned height,
-                      unsigned stride,
-                      const void *data);
-void debug_dump_surface(const char *prefix,
-                        struct pipe_surface *surface);   
-void debug_dump_surface_bmp(const char *filename,
-                            struct pipe_surface *surface);
-#else
-#define debug_dump_image(prefix, format, cpp, width, height, stride, data) ((void)0)
-#define debug_dump_surface(prefix, surface) ((void)0)
-#define debug_dump_surface_bmp(filename, surface) ((void)0)
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* P_DEBUG_H_ */
index b42f98ceba18a6b7773f5eab0479284cc87a7b1e..3f65a60436453992984c41f097801464c40e5690 100644 (file)
@@ -30,8 +30,9 @@
 #define PIPE_FORMAT_H
 
 #include "p_compiler.h"
-#include "p_debug.h"
 
+/* FIXME: remove these header dependencies */
+#include "util/u_debug.h"
 #include "util/u_string.h"
 
 #ifdef __cplusplus
index 1aa4b8a6e22e71de6326e9bd77ef45a559da3402..5ac871da8145001a4ab0ac9fa9e1d27af0d64595 100644 (file)
@@ -30,7 +30,7 @@
 
 #include "GL/gl.h"
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_thread.h"
 
 #include "shared/stw_public.h"
index 903606b425eca2e7f28da7282615c296891f93bf..4b3cf51a5370af06a18cccea99c4b6ca4e0d9b30 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <windows.h>
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "pipe/p_screen.h"
 
 #include "shared/stw_device.h"
index 84b7b287b91499f7f6ffbe941691f2226791e554..5cfdd41597c7e04590fe7a0a7a2099af0ea13eee 100644 (file)
@@ -25,7 +25,7 @@
  * 
  **************************************************************************/
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "stw_pixelformat.h"
 #include "stw_public.h"
 
index f50b79b4e119c862bae3620ad54635fabeeb7afa..d7077ca5d4dd923bc11d7af3e52927c4e54ecc9e 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <windows.h>
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "shared/stw_public.h"
 #include "stw_wgl.h"
 #include "stw.h"
index 2956e1b960a13ba918bc5a60cc77bb79a336deef..ce4b5f83fff266f02d8fc12db76894071dc4123b 100644 (file)
@@ -34,7 +34,7 @@
 #include "xlib_brw_aub.h"
 #include "pipe/p_context.h"
 #include "pipe/p_state.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "util/u_memory.h"
 
 
index 7b5cf4c3053c0f64b9ffd0ecfe8e55763f63a923..862d29fb1bdafa3cc850f50f522b47723d5d4608 100644 (file)
@@ -41,7 +41,7 @@
 #include "shader/prog_instruction.h"
 #include "shader/prog_parameter.h"
 #include "shader/prog_print.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 /*
  * Map mesa register file to TGSI register file.