xref: /aosp_15_r20/external/mesa3d/src/gallium/frontends/nine/nine_debug.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2011 Joakim Sindholt <[email protected]>
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #ifndef _NINE_DEBUG_H_
7 #define _NINE_DEBUG_H_
8 
9 #include "util/u_debug.h"
10 #include "util/compiler.h"
11 
12 void
13 _nine_debug_printf( unsigned long flag,
14                     const char *func,
15                     const char *fmt,
16                     ... ) _util_printf_format(3,4);
17 
18 #define ERR(fmt, ...) _nine_debug_printf(DBG_ERROR, __func__, fmt, ## __VA_ARGS__)
19 
20 #if MESA_DEBUG || !defined(NDEBUG)
21 #define WARN(fmt, ...) _nine_debug_printf(DBG_WARN, __func__, fmt, ## __VA_ARGS__)
22 #define WARN_ONCE(fmt, ...) \
23     do { \
24         static bool once = true; \
25         if (once) { \
26             once = false; \
27             _nine_debug_printf(DBG_WARN, __func__, fmt, ## __VA_ARGS__); \
28         } \
29     } while(0)
30 #else
31 #define WARN(fmt, ...) do {} while(0)
32 #define WARN_ONCE(fmt, ...) do {} while(0)
33 #endif
34 
35 #if MESA_DEBUG || !defined(NDEBUG)
36 #define DBG_FLAG(flag, fmt, ...) \
37     _nine_debug_printf(flag, __func__, fmt, ## __VA_ARGS__)
38 #else
39 #define DBG_FLAG(flag, fmt, ...) do {} while(0)
40 #endif
41 #define DBG(fmt, ...) DBG_FLAG(DBG_CHANNEL, fmt, ## __VA_ARGS__)
42 
43 #define DBG_UNKNOWN              (1<< 0)
44 #define DBG_ADAPTER              (1<< 1)
45 #define DBG_OVERLAYEXTENSION     (1<< 2)
46 #define DBG_AUTHENTICATEDCHANNEL (1<< 3)
47 #define DBG_BASETEXTURE          (1<< 4)
48 #define DBG_CRYPTOSESSION        (1<< 5)
49 #define DBG_CUBETEXTURE          (1<< 6)
50 #define DBG_DEVICE               (1<< 7)
51 #define DBG_DEVICEVIDEO          (1<< 8)
52 #define DBG_INDEXBUFFER          (1<< 9)
53 #define DBG_PIXELSHADER          (1<<10)
54 #define DBG_QUERY                (1<<11)
55 #define DBG_RESOURCE             (1<<12)
56 #define DBG_STATEBLOCK           (1<<13)
57 #define DBG_SURFACE              (1<<14)
58 #define DBG_SWAPCHAIN            (1<<15)
59 #define DBG_TEXTURE              (1<<16)
60 #define DBG_VERTEXBUFFER         (1<<17)
61 #define DBG_VERTEXDECLARATION    (1<<18)
62 #define DBG_VERTEXSHADER         (1<<19)
63 #define DBG_VOLUME               (1<<20)
64 #define DBG_VOLUMETEXTURE        (1<<21)
65 #define DBG_SHADER               (1<<22)
66 #define DBG_FF                   (1<<23)
67 #define DBG_USER                 (1<<24)
68 #define DBG_ERROR                (1<<25)
69 #define DBG_WARN                 (1<<26)
70 #define DBG_TID                  (1<<27)
71 
72 void
73 _nine_stub( const char *file,
74             const char *func,
75             unsigned line );
76 
77 #if MESA_DEBUG || !defined(NDEBUG)
78 #define STUB(ret) \
79     do { \
80         _nine_stub(__FILE__, __func__, __LINE__); \
81         return ret; \
82     } while (0)
83 #else
84 #define STUB(ret) do { return ret; } while (0)
85 #endif
86 
87 /* the expression for this macro is equivalent of that to assert, however this
88  * macro is designed to be used in conditionals ala
89  * if (user_error(required condition)) { assertion failed }
90  * It also prints debug message if the assertion fails. */
91 #if MESA_DEBUG || !defined(NDEBUG)
92 #define user_error(x) \
93     (!(x) ? (DBG_FLAG(DBG_USER, "User assertion failed: `%s'\n", #x), true) \
94           : false)
95 #else
96 #define user_error(x) (!(x) ? TRUE : FALSE)
97 #endif
98 
99 #if MESA_DEBUG || !defined(NDEBUG)
100 #define user_warn(x) \
101     if ((x)) { DBG_FLAG(DBG_USER, "User warning: `%s'\n", #x); }
102 #else
103 #define user_warn(x) do {} while(0)
104 #endif
105 
106 /* nonfatal assert */
107 #define user_assert(x, r) \
108     do { \
109         if (user_error(x)) { \
110             return r; \
111         } \
112     } while (0)
113 
114 #define ret_err(x, r) \
115     do { \
116         ERR(x); \
117         return r; \
118     } while(0)
119 
120 #endif /* _NINE_DEBUG_H_ */
121