1 /* 2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com> 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * on the rights to use, copy, modify, merge, publish, distribute, sub 8 * license, and/or sell copies of the Software, and to permit persons to whom 9 * the Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */ 22 23 #ifndef _NINE_DEBUG_H_ 24 #define _NINE_DEBUG_H_ 25 26 #include "util/u_debug.h" 27 #include "pipe/p_compiler.h" 28 29 void 30 _nine_debug_printf( unsigned long flag, 31 const char *func, 32 const char *fmt, 33 ... ) _util_printf_format(3,4); 34 35 #define ERR(fmt, ...) _nine_debug_printf(DBG_ERROR, __FUNCTION__, fmt, ## __VA_ARGS__) 36 37 #if defined(DEBUG) || !defined(NDEBUG) 38 #define WARN(fmt, ...) _nine_debug_printf(DBG_WARN, __FUNCTION__, fmt, ## __VA_ARGS__) 39 #define WARN_ONCE(fmt, ...) \ 40 do { \ 41 static boolean once = TRUE; \ 42 if (once) { \ 43 once = FALSE; \ 44 _nine_debug_printf(DBG_WARN, __FUNCTION__, fmt, ## __VA_ARGS__); \ 45 } \ 46 } while(0) 47 #else 48 #define WARN(fmt, ...) do {} while(0) 49 #define WARN_ONCE(fmt, ...) do {} while(0) 50 #endif 51 52 #if defined(DEBUG) || !defined(NDEBUG) 53 #define DBG_FLAG(flag, fmt, ...) \ 54 _nine_debug_printf(flag, __FUNCTION__, fmt, ## __VA_ARGS__) 55 #else 56 #define DBG_FLAG(flag, fmt, ...) do {} while(0) 57 #endif 58 #define DBG(fmt, ...) DBG_FLAG(DBG_CHANNEL, fmt, ## __VA_ARGS__) 59 60 #define DBG_UNKNOWN (1<< 0) 61 #define DBG_ADAPTER (1<< 1) 62 #define DBG_OVERLAYEXTENSION (1<< 2) 63 #define DBG_AUTHENTICATEDCHANNEL (1<< 3) 64 #define DBG_BASETEXTURE (1<< 4) 65 #define DBG_CRYPTOSESSION (1<< 5) 66 #define DBG_CUBETEXTURE (1<< 6) 67 #define DBG_DEVICE (1<< 7) 68 #define DBG_DEVICEVIDEO (1<< 8) 69 #define DBG_INDEXBUFFER (1<< 9) 70 #define DBG_PIXELSHADER (1<<10) 71 #define DBG_QUERY (1<<11) 72 #define DBG_RESOURCE (1<<12) 73 #define DBG_STATEBLOCK (1<<13) 74 #define DBG_SURFACE (1<<14) 75 #define DBG_SWAPCHAIN (1<<15) 76 #define DBG_TEXTURE (1<<16) 77 #define DBG_VERTEXBUFFER (1<<17) 78 #define DBG_VERTEXDECLARATION (1<<18) 79 #define DBG_VERTEXSHADER (1<<19) 80 #define DBG_VOLUME (1<<20) 81 #define DBG_VOLUMETEXTURE (1<<21) 82 #define DBG_SHADER (1<<22) 83 #define DBG_FF (1<<23) 84 #define DBG_USER (1<<24) 85 #define DBG_ERROR (1<<25) 86 #define DBG_WARN (1<<26) 87 #define DBG_TID (1<<27) 88 89 void 90 _nine_stub( const char *file, 91 const char *func, 92 unsigned line ); 93 94 #if defined(DEBUG) || !defined(NDEBUG) 95 #define STUB(ret) \ 96 do { \ 97 _nine_stub(__FILE__, __FUNCTION__, __LINE__); \ 98 return ret; \ 99 } while (0) 100 #else 101 #define STUB(ret) do { return ret; } while (0) 102 #endif 103 104 /* the expression for this macro is equivalent of that to assert, however this 105 * macro is designed to be used in conditionals ala 106 * if (user_error(required condition)) { assertion failed } 107 * It also prints debug message if the assertion fails. */ 108 #if defined(DEBUG) || !defined(NDEBUG) 109 #define user_error(x) \ 110 (!(x) ? (DBG_FLAG(DBG_USER, "User assertion failed: `%s'\n", #x), TRUE) \ 111 : FALSE) 112 #else 113 #define user_error(x) (!(x) ? TRUE : FALSE) 114 #endif 115 116 #if defined(DEBUG) || !defined(NDEBUG) 117 #define user_warn(x) \ 118 if ((x)) { DBG_FLAG(DBG_USER, "User warning: `%s'\n", #x); } 119 #else 120 #define user_warn(x) do {} while(0) 121 #endif 122 123 /* nonfatal assert */ 124 #define user_assert(x, r) \ 125 do { \ 126 if (user_error(x)) { \ 127 return r; \ 128 } \ 129 } while (0) 130 131 #define ret_err(x, r) \ 132 do { \ 133 ERR(x); \ 134 return r; \ 135 } while(0) 136 137 #endif /* _NINE_DEBUG_H_ */ 138