summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/nine/nine_debug.h
blob: 4c017eaac7e32e40e224de8099dad856f006c0be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 * license, and/or sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE. */

#ifndef _NINE_DEBUG_H_
#define _NINE_DEBUG_H_

#include "util/u_debug.h"

void
_nine_debug_printf( unsigned long flag,
                    const char *func,
                    const char *fmt,
                    ... ) _util_printf_format(3,4);

#define ERR(fmt, ...) _nine_debug_printf(DBG_ERROR, __FUNCTION__, fmt, ## __VA_ARGS__)

#ifdef DEBUG
#define WARN(fmt, ...) _nine_debug_printf(DBG_WARN, __FUNCTION__, fmt, ## __VA_ARGS__)
#define WARN_ONCE(fmt, ...) \
    do { \
        static boolean once = TRUE; \
        if (once) { \
            once = FALSE; \
            _nine_debug_printf(DBG_WARN, __FUNCTION__, fmt, ## __VA_ARGS__); \
        } \
    } while(0)
#else
#define WARN(fmt, ...)
#define WARN_ONCE(fmt, ...)
#endif

#ifdef DEBUG
#define DBG_FLAG(flag, fmt, ...) \
    _nine_debug_printf(flag, __FUNCTION__, fmt, ## __VA_ARGS__)
#else
#define DBG_FLAG(flag, fmt, ...)
#endif
#define DBG(fmt, ...) DBG_FLAG(DBG_CHANNEL, fmt, ## __VA_ARGS__)

#define DBG_UNKNOWN              (1<< 0)
#define DBG_ADAPTER              (1<< 1)
#define DBG_OVERLAYEXTENSION     (1<< 2)
#define DBG_AUTHENTICATEDCHANNEL (1<< 3)
#define DBG_BASETEXTURE          (1<< 4)
#define DBG_CRYPTOSESSION        (1<< 5)
#define DBG_CUBETEXTURE          (1<< 6)
#define DBG_DEVICE               (1<< 7)
#define DBG_DEVICEVIDEO          (1<< 8)
#define DBG_INDEXBUFFER          (1<< 9)
#define DBG_PIXELSHADER          (1<<10)
#define DBG_QUERY                (1<<11)
#define DBG_RESOURCE             (1<<12)
#define DBG_STATEBLOCK           (1<<13)
#define DBG_SURFACE              (1<<14)
#define DBG_SWAPCHAIN            (1<<15)
#define DBG_TEXTURE              (1<<16)
#define DBG_VERTEXBUFFER         (1<<17)
#define DBG_VERTEXDECLARATION    (1<<18)
#define DBG_VERTEXSHADER         (1<<19)
#define DBG_VOLUME               (1<<20)
#define DBG_VOLUMETEXTURE        (1<<21)
#define DBG_SHADER               (1<<22)
#define DBG_FF                   (1<<23)
#define DBG_USER                 (1<<24)
#define DBG_ERROR                (1<<25)
#define DBG_WARN                 (1<<26)

void
_nine_stub( const char *file,
            const char *func,
            unsigned line );

#ifdef DEBUG
#define STUB(ret) \
    do { \
        _nine_stub(__FILE__, __FUNCTION__, __LINE__); \
        return ret; \
    } while (0)
#else
#define STUB(ret) do { return ret; } while (0)
#endif

/* the expression for this macro is equivalent of that to assert, however this
 * macro is designed to be used in conditionals ala
 * if (user_error(required condition)) { assertion failed }
 * It also prints debug message if the assertion fails. */
#ifdef DEBUG
#define user_error(x) \
    (!(x) ? (DBG_FLAG(DBG_USER, "User assertion failed: `%s'\n", #x), TRUE) \
          : FALSE)
#else
#define user_error(x) (!(x) ? TRUE : FALSE)
#endif

#ifdef DEBUG
#define user_warn(x) \
    if ((x)) { DBG_FLAG(DBG_USER, "User warning: `%s'\n", #x); }
#else
#define user_warn(x)
#endif

/* nonfatal assert */
#define user_assert(x, r) \
    do { \
        if (user_error(x)) { \
            return r; \
        } \
    } while (0)

#define ret_err(x, r) \
    do { \
        ERR(x); \
        return r; \
    } while(0)

#endif /* _NINE_DEBUG_H_ */