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
36 typedef enum radeon_debug_levels
{
37 RADEON_CRITICAL
= 0, /* Only errors */
38 RADEON_IMPORTANT
= 1, /* Important warnings and messages */
39 RADEON_NORMAL
= 2, /* Normal log messages usefull for debugging */
40 RADEON_VERBOSE
= 3, /* Extra details to debugging */
41 RADEON_TRACE
= 4 /* Log about everything that happens */
42 } radeon_debug_level_t
;
45 * Compile time option to change level of debugging compiled to dri driver.
46 * Selecting critical level is not recommended because perfromance gains are
47 * going to minimal but you will lose a lot of important warnings in case of
50 #ifndef RADEON_DEBUG_LEVEL
51 #define RADEON_DEBUG_LEVEL RADEON_VERBOSE
54 typedef enum radeon_debug_types
{
55 RADEON_TEXTURE
= 0x00001,
56 RADEON_STATE
= 0x00002,
57 RADEON_IOCTL
= 0x00004,
58 RADEON_RENDER
= 0x00008,
59 RADEON_SWRENDER
= 0x00010,
60 RADEON_FALLBACKS
= 0x00020,
61 RADEON_VFMT
= 0x00040,
62 RADEON_SHADER
= 0x00080,
66 RADEON_SANITY
= 0x00800,
67 RADEON_SYNC
= 0x01000,
68 RADEON_PIXEL
= 0x02000,
69 RADEON_MEMORY
= 0x04000,
70 RADEON_VERTS
= 0x08000,
71 RADEON_GENERAL
= 0x10000 /* Used for errors and warnings */
72 } radeon_debug_type_t
;
74 #define RADEON_MAX_INDENT 5
78 char indent
[RADEON_MAX_INDENT
];
81 extern radeon_debug_type_t radeon_enabled_debug_types
;
84 * Compabibility layer for old debug code
86 #define RADEON_DEBUG radeon_enabled_debug_types
88 static inline int radeon_is_debug_enabled(const radeon_debug_type_t type
,
89 const radeon_debug_level_t level
)
91 return RADEON_DEBUG_LEVEL
<= level
92 && (type
& radeon_enabled_debug_types
);
95 * define macro for gcc specific __attribute__ if using alternative compiler
98 #define __attribute__(x) /*empty*/
102 extern void _radeon_print(const radeon_debug_type_t type
,
103 const radeon_debug_level_t level
,
107 * Format attribute requires declaration for setting it. Don't ask me why!
109 static inline void radeon_print(const radeon_debug_type_t type
,
110 const radeon_debug_level_t level
,
112 ...) __attribute__((format(printf
,3,4)));
115 * Print out debug message if channel specified by type is enabled
116 * and compile time debugging level is at least as high as level parameter
118 static inline void radeon_print(const radeon_debug_type_t type
,
119 const radeon_debug_level_t level
,
123 /* Compile out if level of message is too high */
124 if (radeon_is_debug_enabled(type
, level
)) {
127 va_start( values
, message
);
128 _radeon_print(type
, level
, message
, values
);
133 static inline void radeon_error(const char* message
, ...) __attribute__((format(printf
,1,2)));
135 * printf style function for writing error messages.
137 static inline void radeon_error(const char* message
, ...)
140 va_start( values
, message
);
141 radeon_print(RADEON_GENERAL
, RADEON_CRITICAL
, message
, values
);
145 static inline void radeon_warning(const char* message
, ...) __attribute__((format(printf
,1,2)));
147 * printf style function for writing warnings.
149 static inline void radeon_warning(const char* message
, ...)
152 va_start( values
, message
);
153 radeon_print(RADEON_GENERAL
, RADEON_IMPORTANT
, message
, values
);
157 extern void radeon_init_debug(void);
158 extern void _radeon_debug_add_indent(void);
159 extern void _radeon_debug_remove_indent(void);
161 static inline void radeon_debug_add_indent(void)
163 if (RADEON_DEBUG_LEVEL
>= RADEON_VERBOSE
) {
164 _radeon_debug_add_indent();
167 static inline void radeon_debug_remove_indent(void)
169 if (RADEON_DEBUG_LEVEL
>= RADEON_VERBOSE
) {
170 _radeon_debug_remove_indent();
174 /* From http://gcc. gnu.org/onlinedocs/gcc-3.2.3/gcc/Variadic-Macros.html .
175 I suppose we could inline this and use macro to fetch out __LINE__ and stuff in case we run into trouble
176 with other compilers ... GLUE!
178 #define WARN_ONCE(a, ...) { \
179 static int warn##__LINE__=1; \
180 if(warn##__LINE__){ \
181 radeon_warning("*********************************WARN_ONCE*********************************\n"); \
182 radeon_warning("File %s function %s line %d\n", \
183 __FILE__, __FUNCTION__, __LINE__); \
184 radeon_warning( (a), ## __VA_ARGS__);\
185 radeon_warning("***************************************************************************\n"); \