/* Authors: Zack Rusin <zack@tungstengraphics.com>
*/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "util/u_memory.h"
* Zack Rusin <zack@tungstengraphics.com>
*/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "util/u_memory.h"
#include "cso_hash.h"
* \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"
#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"
#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>
#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"
#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"
#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"
#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"
#define PB_BUFFER_FENCED_H_
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#ifdef __cplusplus
*/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "util/u_memory.h"
#include "pb_buffer.h"
#include "pb_bufmgr.h"
#include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "util/u_memory.h"
#include "pb_buffer.h"
#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"
#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"
*/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "util/u_memory.h"
#include "pb_buffer.h"
#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"
*/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "util/u_memory.h"
#include "pb_buffer.h"
#include "pb_bufmgr.h"
#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"
#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"
#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"
**************************************************************************/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "rtasm_cpu.h"
#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 <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"
#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"
*
**************************************************************************/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "pipe/p_shader_tokens.h"
#include "tgsi_build.h"
#include "tgsi_parse.h"
*
**************************************************************************/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "util/u_string.h"
#include "tgsi_dump.h"
#include "tgsi_info.h"
*
**************************************************************************/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "util/u_string.h"
#include "tgsi_dump_c.h"
#include "tgsi_build.h"
*
**************************************************************************/
-#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] =
*
**************************************************************************/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "tgsi_iterate.h"
boolean
*
**************************************************************************/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "pipe/p_shader_tokens.h"
#include "tgsi_parse.h"
#include "tgsi_build.h"
#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"
*
**************************************************************************/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "tgsi_sanity.h"
#include "tgsi_info.h"
#include "tgsi_iterate.h"
#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)
*
**************************************************************************/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "tgsi_text.h"
#include "tgsi_build.h"
#include "tgsi_info.h"
* Authors: Brian Paul
*/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "tgsi_transform.h"
*
**************************************************************************/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "pipe/p_shader_tokens.h"
#include "tgsi_parse.h"
#include "tgsi_build.h"
LIBNAME = util
C_SOURCES = \
- p_debug.c \
+ u_debug.c \
u_blit.c \
u_cache.c \
u_draw_quad.c \
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',
+++ /dev/null
-/**************************************************************************
- *
- * 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
+++ /dev/null
-/**************************************************************************
- *
- * 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");
- }
-}
+++ /dev/null
-/**************************************************************************
- *
- * 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 */
#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"
#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"
--- /dev/null
+/**************************************************************************
+ *
+ * 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
--- /dev/null
+/**************************************************************************
+ *
+ * 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_ */
--- /dev/null
+/**************************************************************************
+ *
+ * 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");
+ }
+}
--- /dev/null
+/**************************************************************************
+ *
+ * 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 */
#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"
#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"
#include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "cso_cache/cso_hash.h"
#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"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "u_linear.h"
void
#include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#ifdef __cplusplus
#include "util/u_pointer.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#ifdef __cplusplus
/* memory debugging */
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#define MALLOC( _size ) \
debug_malloc( __FILE__, __LINE__, __FUNCTION__, _size )
#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"
#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"
#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"
#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
#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"
*/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "brw_eu.h"
#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;
-#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"
*/
-#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_debug.h"
+#include "util/u_debug.h"
#include "pipe/p_inlines.h"
#include "pipe/internal/p_winsys_screen.h"
* 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. */
#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"
#include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "pipe/p_context.h"
#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"
#include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "pipe/internal/p_winsys_screen.h"
+++ /dev/null
-/**************************************************************************
- *
- * 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_ */
#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
#include "GL/gl.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "pipe/p_thread.h"
#include "shared/stw_public.h"
#include <windows.h>
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "pipe/p_screen.h"
#include "shared/stw_device.h"
*
**************************************************************************/
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
#include "stw_pixelformat.h"
#include "stw_public.h"
#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"
#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"
#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.