1 /**************************************************************************
2  *
3  * Copyright (C) 2018 Collabora Ltd
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21  * OTHER DEALINGS IN THE SOFTWARE.
22  *
23  **************************************************************************/
24 
25 #ifndef vrend_debug_h
26 #define vrend_debug_h
27 
28 #include "virgl_protocol.h"
29 #include <stdarg.h>
30 
31 struct vrend_context;
32 void vrend_print_context_name(struct vrend_context *ctx);
33 
34 enum virgl_debug_flags {
35    dbg_shader_tgsi = 1 << 0,
36    dbg_shader_glsl = 1 << 1,
37    dbg_shader_streamout = 1 << 2,
38    dbg_shader = dbg_shader_tgsi | dbg_shader_glsl | dbg_shader_streamout,
39    dbg_cmd = 1 << 3,
40    dbg_object = 1 << 4,
41    dbg_blit = 1 << 5,
42    dbg_copy_resource = 1 << 6,
43    dbg_features = 1 << 7,
44    dbg_tex = 1 << 8,
45    dbg_caller = 1 << 9,
46    dbg_tweak =  1 << 10,
47    dbg_query =  1 << 11,
48    dbg_gles =  1 << 12,
49    dbg_all = (1 << 13) - 1,
50    dbg_allow_guest_override = 1 << 16,
51    dbg_feature_use = 1 << 17,
52    dbg_khr = 1 << 18,
53 };
54 
55 const char *vrend_get_comand_name(enum virgl_context_cmd cmd);
56 
57 const char *vrend_get_object_type_name(enum virgl_object_type cmd);
58 
59 
60 void vrend_init_debug_flags(void);
61 
62 int  vrend_debug_can_override(void);
63 
64 int vrend_get_debug_flags(const char *flagstring);
65 
66 void vrend_context_set_debug_flags(struct vrend_context *ctx, const char *flags);
67 
68 unsigned vrend_debug(struct vrend_context *ctx, enum virgl_debug_flags flag);
69 
70 void vrend_debug_add_flag(enum virgl_debug_flags flag);
71 
72 void vrend_printf(const char *fmt, ...);
73 
74 typedef void (*virgl_debug_callback_type)(const char *fmt, va_list ap);
75 
76 virgl_debug_callback_type vrend_set_debug_callback(virgl_debug_callback_type cb);
77 
78 #ifndef NDEBUG
79 #define VREND_DEBUG(flag, ctx,  ...) \
80    if (vrend_debug(ctx, flag)) \
81       do { \
82             vrend_print_context_name(ctx); \
83             vrend_printf(__VA_ARGS__); \
84       } while (0)
85 
86 #define VREND_DEBUG_EXT(flag, ctx, X) \
87    if (vrend_debug(ctx, flag)) \
88       do { \
89             vrend_print_context_name(ctx); \
90             X; \
91       } while (0)
92 
93 #define VREND_DEBUG_NOCTX(flag, ctx, ...) \
94    if (vrend_debug(ctx, flag)) \
95       do { \
96             vrend_printf(__VA_ARGS__); \
97       } while (0)
98 
99 #else
100 #define VREND_DEBUG(flag, ctx, fmt, ...)
101 #define VREND_DEBUG_EXT(flag, ctx, X)
102 #define VREND_DEBUG_NOCTX(flag, ctx, ...)
103 #endif
104 
105 #endif
106