1 /* 2 * Mesa 3-D graphics library 3 * 4 * Copyright (C) 2012-2013 LunarG, Inc. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included 14 * in all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 * DEALINGS IN THE SOFTWARE. 23 * 24 * Authors: 25 * Chia-I Wu <olv (at) lunarg.com> 26 */ 27 28 #ifndef ILO_DEBUG_H 29 #define ILO_DEBUG_H 30 31 #include "util/u_debug.h" 32 33 #include "ilo_core.h" 34 35 /* enable debug flags affecting hot pathes only with debug builds */ 36 #ifdef DEBUG 37 #define ILO_DEBUG_HOT 1 38 #else 39 #define ILO_DEBUG_HOT 0 40 #endif 41 42 enum ilo_debug { 43 ILO_DEBUG_BATCH = 1 << 0, 44 ILO_DEBUG_VS = 1 << 1, 45 ILO_DEBUG_GS = 1 << 2, 46 ILO_DEBUG_FS = 1 << 3, 47 ILO_DEBUG_CS = 1 << 4, 48 ILO_DEBUG_DRAW = ILO_DEBUG_HOT << 5, 49 ILO_DEBUG_SUBMIT = 1 << 6, 50 ILO_DEBUG_HANG = 1 << 7, 51 52 /* flags that affect the behaviors of the driver */ 53 ILO_DEBUG_NOHW = 1 << 20, 54 ILO_DEBUG_NOCACHE = 1 << 21, 55 ILO_DEBUG_NOHIZ = 1 << 22, 56 }; 57 58 extern int ilo_debug; 59 60 void 61 ilo_debug_init(const char *name); 62 63 /** 64 * Print a message, for dumping or debugging. 65 */ 66 static inline void _util_printf_format(1, 2) 67 ilo_printf(const char *format, ...) 68 { 69 va_list ap; 70 71 va_start(ap, format); 72 _debug_vprintf(format, ap); 73 va_end(ap); 74 } 75 76 /** 77 * Print a critical error. 78 */ 79 static inline void _util_printf_format(1, 2) 80 ilo_err(const char *format, ...) 81 { 82 va_list ap; 83 84 va_start(ap, format); 85 _debug_vprintf(format, ap); 86 va_end(ap); 87 } 88 89 /** 90 * Print a warning, silenced for release builds. 91 */ 92 static inline void _util_printf_format(1, 2) 93 ilo_warn(const char *format, ...) 94 { 95 #ifdef DEBUG 96 va_list ap; 97 98 va_start(ap, format); 99 _debug_vprintf(format, ap); 100 va_end(ap); 101 #else 102 #endif 103 } 104 105 static inline bool 106 ilo_is_zeroed(const void *ptr, size_t size) 107 { 108 #ifdef DEBUG 109 size_t i; 110 111 for (i = 0; i < size; i++) { 112 if (*((const char *) ptr) != 0) 113 return false; 114 } 115 116 return true; 117 #else 118 return true; 119 #endif 120 } 121 122 #endif /* ILO_DEBUG_H */ 123