• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "virgl_util.h"
30 #include <stdarg.h>
31 
32 struct vrend_context;
33 void vrend_print_context_name(const struct vrend_context *ctx);
34 
35 enum virgl_debug_flags {
36    dbg_shader_tgsi = 1 << 0,
37    dbg_shader_glsl = 1 << 1,
38    dbg_shader_streamout = 1 << 2,
39    dbg_shader = dbg_shader_tgsi | dbg_shader_glsl | dbg_shader_streamout,
40    dbg_cmd = 1 << 3,
41    dbg_object = 1 << 4,
42    dbg_blit = 1 << 5,
43    dbg_copy_resource = 1 << 6,
44    dbg_features = 1 << 7,
45    dbg_tex = 1 << 8,
46    dbg_caller = 1 << 9,
47    dbg_tweak =  1 << 10,
48    dbg_query =  1 << 11,
49    dbg_gles =  1 << 12,
50    dbg_bgra = 1 << 13,
51    dbg_all = (1 << 14) - 1,
52    dbg_allow_guest_override = 1 << 16,
53    dbg_feature_use = 1 << 17,
54    dbg_khr = 1 << 18,
55 };
56 
57 const char *vrend_get_comand_name(enum virgl_context_cmd cmd);
58 
59 const char *vrend_get_object_type_name(enum virgl_object_type cmd);
60 
61 
62 void vrend_init_debug_flags(void);
63 
64 int  vrend_debug_can_override(void);
65 
66 int vrend_get_debug_flags(const char *flagstring);
67 
68 void vrend_context_set_debug_flags(struct vrend_context *ctx, const char *flags);
69 
70 unsigned vrend_debug(const struct vrend_context *ctx, enum virgl_debug_flags flag);
71 
72 void vrend_debug_add_flag(enum virgl_debug_flags flag);
73 
vrend_printf(const char * fmt,...)74 static inline void vrend_printf(const char *fmt, ...)
75 {
76    va_list va;
77    va_start(va, fmt);
78    virgl_logv(fmt, va);
79    va_end(va);
80 }
81 
82 #ifdef NDEBUG
83 #define VREND_DEBUG_ENABLED (false)
84 #else
85 #define VREND_DEBUG_ENABLED (true)
86 #endif
87 
88 #define VREND_DEBUG(flag, ctx,  ...) \
89    if (VREND_DEBUG_ENABLED && vrend_debug(ctx, flag)) \
90       do { \
91             vrend_print_context_name(ctx); \
92             vrend_printf(__VA_ARGS__); \
93       } while (0)
94 
95 #define VREND_DEBUG_EXT(flag, ctx, X) \
96    if (VREND_DEBUG_ENABLED && vrend_debug(ctx, flag)) \
97       do { \
98             vrend_print_context_name(ctx); \
99             X; \
100       } while (0)
101 
102 #define VREND_DEBUG_NOCTX(flag, ctx, ...) \
103    if (VREND_DEBUG_ENABLED && vrend_debug(ctx, flag)) \
104       do { \
105             vrend_printf(__VA_ARGS__); \
106       } while (0)
107 
108 #endif
109