2 * Copyright © 2009 Pauli Nieminen
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
16 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
17 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
19 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 * The above copyright notice and this permission notice (including the
22 * next paragraph) shall be included in all copies or substantial portions
27 * Pauli Nieminen <suokkos@gmail.com>
30 #ifndef RADEON_DEBUG_H_INCLUDED
31 #define RADEON_DEBUG_H_INCLUDED
35 typedef enum radeon_debug_levels
{
36 RADEON_CRITICAL
= 0, /* Only errors */
37 RADEON_IMPORTANT
= 1, /* Important warnings and messages */
38 RADEON_NORMAL
= 2, /* Normal log messages usefull for debugging */
39 RADEON_VERBOSE
= 3, /* Extra details to debugging */
40 RADEON_TRACE
= 4 /* Log about everything that happens */
41 } radeon_debug_level_t
;
44 * Compile time option to change level of debugging compiled to dri driver.
45 * Selecting critical level is not recommended because perfromance gains are
46 * going to minimal but you will lose a lot of important warnings in case of
49 #ifndef RADEON_DEBUG_LEVEL
50 #define RADEON_DEBUG_LEVEL RADEON_VERBOSE
53 typedef enum radeon_debug_types
{
54 RADEON_TEXTURE
= 0x00001,
55 RADEON_STATE
= 0x00002,
56 RADEON_IOCTL
= 0x00004,
57 RADEON_RENDER
= 0x00008,
58 RADEON_SWRENDER
= 0x00010,
59 RADEON_FALLBACKS
= 0x00020,
60 RADEON_VFMT
= 0x00040,
61 RADEON_SHADER
= 0x00080,
65 RADEON_SANITY
= 0x00800,
66 RADEON_SYNC
= 0x01000,
67 RADEON_PIXEL
= 0x02000,
68 RADEON_MEMORY
= 0x04000,
69 RADEON_VERTS
= 0x08000,
70 RADEON_GENERAL
= 0x10000 /* Used for errors and warnings */
71 } radeon_debug_type_t
;
73 #define RADEON_MAX_INDENT 5
77 char indent
[RADEON_MAX_INDENT
];
80 extern radeon_debug_type_t radeon_enabled_debug_types
;
83 * Compabibility layer for old debug code
85 #define RADEON_DEBUG radeon_enabled_debug_types
87 static inline int radeon_is_debug_enabled(const radeon_debug_type_t type
,
88 const radeon_debug_level_t level
)
90 return RADEON_DEBUG_LEVEL
>= level
91 && (type
& radeon_enabled_debug_types
);
94 * define macro for gcc specific __attribute__ if using alternative compiler
97 #define __attribute__(x) /*empty*/
101 extern void _radeon_print(const radeon_debug_type_t type
,
102 const radeon_debug_level_t level
,
104 ...) __attribute__((format(printf
,3,4)));
106 * Print out debug message if channel specified by type is enabled
107 * and compile time debugging level is at least as high as level parameter
109 #define radeon_print(type, level, message, ...) do { \
110 const radeon_debug_level_t _debug_level = (level); \
111 const radeon_debug_type_t _debug_type = (type); \
112 /* Compile out if level of message is too high */ \
113 if (radeon_is_debug_enabled(type, level)) { \
114 _radeon_print(_debug_type, _debug_level, \
115 (message), ## __VA_ARGS__); \
120 * printf style function for writing error messages.
122 #define radeon_error(message, ...) do { \
123 radeon_print(RADEON_GENERAL, RADEON_CRITICAL, \
124 (message), ## __VA_ARGS__); \
128 * printf style function for writing warnings.
130 #define radeon_warning(message, ...) do { \
131 radeon_print(RADEON_GENERAL, RADEON_IMPORTANT, \
132 (message), ## __VA_ARGS__); \
135 extern void radeon_init_debug(void);
136 extern void _radeon_debug_add_indent(void);
137 extern void _radeon_debug_remove_indent(void);
139 static inline void radeon_debug_add_indent(void)
141 if (RADEON_DEBUG_LEVEL
>= RADEON_VERBOSE
) {
142 _radeon_debug_add_indent();
145 static inline void radeon_debug_remove_indent(void)
147 if (RADEON_DEBUG_LEVEL
>= RADEON_VERBOSE
) {
148 _radeon_debug_remove_indent();
153 /* From http://gcc. gnu.org/onlinedocs/gcc-3.2.3/gcc/Variadic-Macros.html .
154 I suppose we could inline this and use macro to fetch out __LINE__ and stuff in case we run into trouble
155 with other compilers ... GLUE!
157 #define WARN_ONCE(a, ...) do { \
158 static int __warn_once=1; \
160 radeon_warning("*********************************WARN_ONCE*********************************\n"); \
161 radeon_warning("File %s function %s line %d\n", \
162 __FILE__, __FUNCTION__, __LINE__); \
163 radeon_warning( (a), ## __VA_ARGS__);\
164 radeon_warning("***************************************************************************\n"); \