debug: Introduce VREND_DEBUG_ENABLED flag

VREND_DEBUG_ENABLED represents if debugging features are enabled and is
controlled by NDEBUG macro. By using VREND_DEBUG_ENABLED in
an if statement instead of using NDEBUG in ifdef, the compiler can
validate the content of the conditional and know its variable usage to
avoid meaningless warnings.

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
macos/master
Akihiko Odaki 3 years ago
parent 18dcea9041
commit fbbc6728d7
  1. 19
      src/vrend_debug.h
  2. 3
      src/vrend_decode.c
  3. 8
      src/vrend_renderer.c

@ -79,31 +79,30 @@ static inline void vrend_printf(const char *fmt, ...)
va_end(va); va_end(va);
} }
#ifndef NDEBUG #ifdef NDEBUG
#define VREND_DEBUG_ENABLED (false)
#else
#define VREND_DEBUG_ENABLED (true)
#endif
#define VREND_DEBUG(flag, ctx, ...) \ #define VREND_DEBUG(flag, ctx, ...) \
if (vrend_debug(ctx, flag)) \ if (VREND_DEBUG_ENABLED && vrend_debug(ctx, flag)) \
do { \ do { \
vrend_print_context_name(ctx); \ vrend_print_context_name(ctx); \
vrend_printf(__VA_ARGS__); \ vrend_printf(__VA_ARGS__); \
} while (0) } while (0)
#define VREND_DEBUG_EXT(flag, ctx, X) \ #define VREND_DEBUG_EXT(flag, ctx, X) \
if (vrend_debug(ctx, flag)) \ if (VREND_DEBUG_ENABLED && vrend_debug(ctx, flag)) \
do { \ do { \
vrend_print_context_name(ctx); \ vrend_print_context_name(ctx); \
X; \ X; \
} while (0) } while (0)
#define VREND_DEBUG_NOCTX(flag, ctx, ...) \ #define VREND_DEBUG_NOCTX(flag, ctx, ...) \
if (vrend_debug(ctx, flag)) \ if (VREND_DEBUG_ENABLED && vrend_debug(ctx, flag)) \
do { \ do { \
vrend_printf(__VA_ARGS__); \ vrend_printf(__VA_ARGS__); \
} while (0) } while (0)
#else
#define VREND_DEBUG(flag, ctx, ...) (void)ctx
#define VREND_DEBUG_EXT(flag, ctx, X) (void)ctx
#define VREND_DEBUG_NOCTX(flag, ctx, ...) (void)ctx
#endif
#endif #endif

@ -1711,10 +1711,7 @@ static int vrend_decode_ctx_submit_cmd(struct virgl_context *ctx,
uint32_t buf_offset = 0; uint32_t buf_offset = 0;
while (buf_offset < buf_total) { while (buf_offset < buf_total) {
#ifndef NDEBUG
const uint32_t cur_offset = buf_offset; const uint32_t cur_offset = buf_offset;
#endif
const uint32_t *buf = &typed_buf[buf_offset]; const uint32_t *buf = &typed_buf[buf_offset];
uint32_t len = *buf >> 16; uint32_t len = *buf >> 16;
uint32_t cmd = *buf & 0xff; uint32_t cmd = *buf & 0xff;

@ -3864,11 +3864,9 @@ int vrend_create_shader(struct vrend_context *ctx,
free(tokens); free(tokens);
ret = EINVAL; ret = EINVAL;
goto error; goto error;
} else { } else if (!VREND_DEBUG_ENABLED) {
#ifdef NDEBUG
free(sel->tmp_buf); free(sel->tmp_buf);
sel->tmp_buf = NULL; sel->tmp_buf = NULL;
#endif
} }
free(tokens); free(tokens);
sub_ctx->long_shader_in_progress_handle[type] = 0; sub_ctx->long_shader_in_progress_handle[type] = 0;
@ -6489,9 +6487,9 @@ int vrend_renderer_init(const struct vrend_if_cbs *cbs, uint32_t flags)
vrend_state.max_texture_3d_size = vrend_state.max_texture_3d_size =
vrend_state.max_texture_cube_size = 16384; vrend_state.max_texture_cube_size = 16384;
#ifndef NDEBUG if (VREND_DEBUG_ENABLED) {
vrend_init_debug_flags(); vrend_init_debug_flags();
#endif }
ctx_params.shared = false; ctx_params.shared = false;
for (uint32_t i = 0; i < ARRAY_SIZE(gl_versions); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(gl_versions); i++) {

Loading…
Cancel
Save