From e178ecf8a923b982728eb180050142a1e7bc2180 Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Mon, 15 Aug 2022 22:38:26 +0100 Subject: [PATCH] vc4: introduce VC4_DBG() macro to make VC4_DEBUG checks consistent The main issue was the inconsistent use of `unlikely()`, but the macro also simplifies the code a little bit. Signed-off-by: Eric Engestrom Reviewed-by: Juan A. Suarez Part-of: --- src/gallium/drivers/vc4/vc4_bufmgr.c | 6 +++--- src/gallium/drivers/vc4/vc4_context.c | 6 +++--- src/gallium/drivers/vc4/vc4_context.h | 2 +- src/gallium/drivers/vc4/vc4_draw.c | 2 +- src/gallium/drivers/vc4/vc4_job.c | 6 +++--- src/gallium/drivers/vc4/vc4_program.c | 16 ++++++++-------- src/gallium/drivers/vc4/vc4_qir_live_variables.c | 2 +- src/gallium/drivers/vc4/vc4_qpu_emit.c | 4 ++-- src/gallium/drivers/vc4/vc4_resource.c | 4 ++-- src/gallium/drivers/vc4/vc4_screen.c | 4 ++-- src/gallium/drivers/vc4/vc4_screen.h | 6 ++++-- src/gallium/drivers/vc4/vc4_simulator.c | 4 ++-- 12 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/gallium/drivers/vc4/vc4_bufmgr.c b/src/gallium/drivers/vc4/vc4_bufmgr.c index 81b479d32a9..7a366caf6a1 100644 --- a/src/gallium/drivers/vc4/vc4_bufmgr.c +++ b/src/gallium/drivers/vc4/vc4_bufmgr.c @@ -56,7 +56,7 @@ vc4_bo_label(struct vc4_screen *screen, struct vc4_bo *bo, const char *fmt, ...) * (for debugging a single app's allocation). */ #ifndef DEBUG - if (!(vc4_debug & VC4_DEBUG_SURFACE)) + if (!VC4_DBG(SURFACE)) return; #endif va_list va; @@ -550,7 +550,7 @@ vc4_wait_seqno(struct vc4_screen *screen, uint64_t seqno, uint64_t timeout_ns, if (screen->finished_seqno >= seqno) return true; - if (unlikely(vc4_debug & VC4_DEBUG_PERF) && timeout_ns && reason) { + if (VC4_DBG(PERF) && timeout_ns && reason) { if (vc4_wait_seqno_ioctl(screen->fd, seqno, 0) == -ETIME) { fprintf(stderr, "Blocking on seqno %lld for %s\n", (long long)seqno, reason); @@ -590,7 +590,7 @@ vc4_bo_wait(struct vc4_bo *bo, uint64_t timeout_ns, const char *reason) { struct vc4_screen *screen = bo->screen; - if (unlikely(vc4_debug & VC4_DEBUG_PERF) && timeout_ns && reason) { + if (VC4_DBG(PERF) && timeout_ns && reason) { if (vc4_wait_bo_ioctl(screen->fd, bo->handle, 0) == -ETIME) { fprintf(stderr, "Blocking on %s BO for %s\n", bo->name, reason); diff --git a/src/gallium/drivers/vc4/vc4_context.c b/src/gallium/drivers/vc4/vc4_context.c index 531416ca3f6..50e5a632d8e 100644 --- a/src/gallium/drivers/vc4/vc4_context.c +++ b/src/gallium/drivers/vc4/vc4_context.c @@ -158,8 +158,8 @@ vc4_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags) int err; /* Prevent dumping of the shaders built during context setup. */ - uint32_t saved_shaderdb_flag = vc4_debug & VC4_DEBUG_SHADERDB; - vc4_debug &= ~VC4_DEBUG_SHADERDB; + uint32_t saved_shaderdb_flag = vc4_mesa_debug & VC4_DEBUG_SHADERDB; + vc4_mesa_debug &= ~VC4_DEBUG_SHADERDB; vc4 = rzalloc(NULL, struct vc4_context); if (!vc4) @@ -202,7 +202,7 @@ vc4_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags) if (!vc4->blitter) goto fail; - vc4_debug |= saved_shaderdb_flag; + vc4_mesa_debug |= saved_shaderdb_flag; vc4->sample_mask = (1 << VC4_MAX_SAMPLES) - 1; diff --git a/src/gallium/drivers/vc4/vc4_context.h b/src/gallium/drivers/vc4/vc4_context.h index a55f808a7f6..e3f2c66e957 100644 --- a/src/gallium/drivers/vc4/vc4_context.h +++ b/src/gallium/drivers/vc4/vc4_context.h @@ -426,7 +426,7 @@ struct vc4_depth_stencil_alpha_state { }; #define perf_debug(...) do { \ - if (unlikely(vc4_debug & VC4_DEBUG_PERF)) \ + if (VC4_DBG(PERF)) \ fprintf(stderr, __VA_ARGS__); \ if (unlikely(vc4->debug.debug_message)) \ util_debug_message(&vc4->debug, PERF_INFO, __VA_ARGS__); \ diff --git a/src/gallium/drivers/vc4/vc4_draw.c b/src/gallium/drivers/vc4/vc4_draw.c index 0143072fe12..08c0c71cc31 100644 --- a/src/gallium/drivers/vc4/vc4_draw.c +++ b/src/gallium/drivers/vc4/vc4_draw.c @@ -525,7 +525,7 @@ vc4_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info, if (job->bo_space > 128 * 1024 * 1024) vc4_flush(pctx); - if (vc4_debug & VC4_DEBUG_ALWAYS_FLUSH) + if (VC4_DBG(ALWAYS_FLUSH)) vc4_flush(pctx); } diff --git a/src/gallium/drivers/vc4/vc4_job.c b/src/gallium/drivers/vc4/vc4_job.c index 30dfebdb8c2..2e79a368a37 100644 --- a/src/gallium/drivers/vc4/vc4_job.c +++ b/src/gallium/drivers/vc4/vc4_job.c @@ -380,7 +380,7 @@ vc4_job_submit(struct vc4_context *vc4, struct vc4_job *job) goto done; } - if (vc4_debug & VC4_DEBUG_CL) { + if (VC4_DBG(CL)) { fprintf(stderr, "BCL:\n"); vc4_dump_cl(job->bcl.base, cl_offset(&job->bcl), false); } @@ -486,7 +486,7 @@ vc4_job_submit(struct vc4_context *vc4, struct vc4_job *job) } } - if (!(vc4_debug & VC4_DEBUG_NORAST)) { + if (!VC4_DBG(NORAST)) { int ret; ret = vc4_ioctl(vc4->fd, DRM_IOCTL_VC4_SUBMIT_CL, &submit); @@ -511,7 +511,7 @@ vc4_job_submit(struct vc4_context *vc4, struct vc4_job *job) } } - if (vc4_debug & VC4_DEBUG_ALWAYS_SYNC) { + if (VC4_DBG(ALWAYS_SYNC)) { if (!vc4_wait_seqno(vc4->screen, vc4->last_emit_seqno, PIPE_TIMEOUT_INFINITE, "sync")) { fprintf(stderr, "Wait failed.\n"); diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c index ac8bd19a1b8..5aadb8ff24e 100644 --- a/src/gallium/drivers/vc4/vc4_program.c +++ b/src/gallium/drivers/vc4/vc4_program.c @@ -2327,14 +2327,14 @@ vc4_shader_ntq(struct vc4_context *vc4, enum qstage stage, NIR_PASS_V(c->s, nir_convert_from_ssa, true); - if (vc4_debug & VC4_DEBUG_SHADERDB) { + if (VC4_DBG(SHADERDB)) { fprintf(stderr, "SHADER-DB: %s prog %d/%d: %d NIR instructions\n", qir_get_stage_name(c->stage), c->program_id, c->variant_id, count_nir_instrs(c->s)); } - if (vc4_debug & VC4_DEBUG_NIR) { + if (VC4_DBG(NIR)) { fprintf(stderr, "%s prog %d/%d NIR:\n", qir_get_stage_name(c->stage), c->program_id, c->variant_id); @@ -2368,7 +2368,7 @@ vc4_shader_ntq(struct vc4_context *vc4, enum qstage stage, break; } - if (vc4_debug & VC4_DEBUG_QIR) { + if (VC4_DBG(QIR)) { fprintf(stderr, "%s prog %d/%d pre-opt QIR:\n", qir_get_stage_name(c->stage), c->program_id, c->variant_id); @@ -2382,7 +2382,7 @@ vc4_shader_ntq(struct vc4_context *vc4, enum qstage stage, qir_schedule_instructions(c); qir_emit_uniform_stream_resets(c); - if (vc4_debug & VC4_DEBUG_QIR) { + if (VC4_DBG(QIR)) { fprintf(stderr, "%s prog %d/%d QIR:\n", qir_get_stage_name(c->stage), c->program_id, c->variant_id); @@ -2393,7 +2393,7 @@ vc4_shader_ntq(struct vc4_context *vc4, enum qstage stage, qir_reorder_uniforms(c); vc4_generate_code(vc4, c); - if (vc4_debug & VC4_DEBUG_SHADERDB) { + if (VC4_DBG(SHADERDB)) { fprintf(stderr, "SHADER-DB: %s prog %d/%d: %d instructions\n", qir_get_stage_name(c->stage), c->program_id, c->variant_id, @@ -2430,7 +2430,7 @@ vc4_shader_state_create(struct pipe_context *pctx, } else { assert(cso->type == PIPE_SHADER_IR_TGSI); - if (vc4_debug & VC4_DEBUG_TGSI) { + if (VC4_DBG(TGSI)) { fprintf(stderr, "prog %d TGSI:\n", so->program_id); tgsi_dump(cso->tokens, 0); @@ -2461,7 +2461,7 @@ vc4_shader_state_create(struct pipe_context *pctx, so->base.type = PIPE_SHADER_IR_NIR; so->base.ir.nir = s; - if (vc4_debug & VC4_DEBUG_NIR) { + if (VC4_DBG(NIR)) { fprintf(stderr, "%s prog %d NIR:\n", gl_shader_stage_name(s->info.stage), so->program_id); @@ -2621,7 +2621,7 @@ vc4_get_compiled_shader(struct vc4_context *vc4, enum qstage stage, shader->fs_threaded = c->fs_threaded; - if ((vc4_debug & VC4_DEBUG_SHADERDB) && stage == QSTAGE_FRAG) { + if (VC4_DBG(SHADERDB) && stage == QSTAGE_FRAG) { fprintf(stderr, "SHADER-DB: %s prog %d/%d: %d FS threads\n", qir_get_stage_name(c->stage), c->program_id, c->variant_id, diff --git a/src/gallium/drivers/vc4/vc4_qir_live_variables.c b/src/gallium/drivers/vc4/vc4_qir_live_variables.c index 61dc16915b7..992a5006b6d 100644 --- a/src/gallium/drivers/vc4/vc4_qir_live_variables.c +++ b/src/gallium/drivers/vc4/vc4_qir_live_variables.c @@ -314,7 +314,7 @@ qir_calculate_live_intervals(struct vc4_compile *c) qir_compute_start_end(c, c->num_temps); - if (vc4_debug & VC4_DEBUG_SHADERDB) { + if (VC4_DBG(SHADERDB)) { int last_ip = 0; for (int i = 0; i < c->num_temps; i++) last_ip = MAX2(last_ip, c->temp_end[i]); diff --git a/src/gallium/drivers/vc4/vc4_qpu_emit.c b/src/gallium/drivers/vc4/vc4_qpu_emit.c index 7926bfd39da..fab3a539860 100644 --- a/src/gallium/drivers/vc4/vc4_qpu_emit.c +++ b/src/gallium/drivers/vc4/vc4_qpu_emit.c @@ -679,14 +679,14 @@ vc4_generate_code(struct vc4_context *vc4, struct vc4_compile *c) cycles += c->qpu_inst_count - inst_count_at_schedule_time; - if (vc4_debug & VC4_DEBUG_SHADERDB) { + if (VC4_DBG(SHADERDB)) { fprintf(stderr, "SHADER-DB: %s prog %d/%d: %d estimated cycles\n", qir_get_stage_name(c->stage), c->program_id, c->variant_id, cycles); } - if (vc4_debug & VC4_DEBUG_QPU) + if (VC4_DBG(QPU)) vc4_dump_program(c); vc4_qpu_validate(c->qpu_insts, c->qpu_inst_count); diff --git a/src/gallium/drivers/vc4/vc4_resource.c b/src/gallium/drivers/vc4/vc4_resource.c index 28ca799ed21..d9b80a51700 100644 --- a/src/gallium/drivers/vc4/vc4_resource.c +++ b/src/gallium/drivers/vc4/vc4_resource.c @@ -45,7 +45,7 @@ vc4_resource_bo_alloc(struct vc4_resource *rsc) struct pipe_screen *pscreen = prsc->screen; struct vc4_bo *bo; - if (vc4_debug & VC4_DEBUG_SURFACE) { + if (VC4_DBG(SURFACE)) { fprintf(stderr, "alloc %p: size %d + offset %d -> %d\n", rsc, rsc->slices[0].size, @@ -410,7 +410,7 @@ vc4_setup_slices(struct vc4_resource *rsc, const char *caller) offset += slice->size; - if (vc4_debug & VC4_DEBUG_SURFACE) { + if (VC4_DBG(SURFACE)) { static const char tiling_chars[] = { [VC4_TILING_FORMAT_LINEAR] = 'R', [VC4_TILING_FORMAT_LT] = 'L', diff --git a/src/gallium/drivers/vc4/vc4_screen.c b/src/gallium/drivers/vc4/vc4_screen.c index d6074c19597..42bdabad9b1 100644 --- a/src/gallium/drivers/vc4/vc4_screen.c +++ b/src/gallium/drivers/vc4/vc4_screen.c @@ -73,7 +73,7 @@ static const struct debug_named_value vc4_debug_options[] = { }; DEBUG_GET_ONCE_FLAGS_OPTION(vc4_debug, "VC4_DEBUG", vc4_debug_options, 0) -uint32_t vc4_debug; +uint32_t vc4_mesa_debug; static const char * vc4_screen_get_name(struct pipe_screen *pscreen) @@ -588,7 +588,7 @@ vc4_screen_create(int fd, struct renderonly *ro) vc4_fence_screen_init(screen); - vc4_debug = debug_get_option_vc4_debug(); + vc4_mesa_debug = debug_get_option_vc4_debug(); #ifdef USE_VC4_SIMULATOR vc4_simulator_init(screen); diff --git a/src/gallium/drivers/vc4/vc4_screen.h b/src/gallium/drivers/vc4/vc4_screen.h index 06342f717f8..52e19a32b57 100644 --- a/src/gallium/drivers/vc4/vc4_screen.h +++ b/src/gallium/drivers/vc4/vc4_screen.h @@ -37,6 +37,10 @@ struct vc4_bo; +extern uint32_t vc4_mesa_debug; + +#define VC4_DBG(flag) unlikely(vc4_mesa_debug & VC4_DEBUG_ ## flag) + #define VC4_DEBUG_CL 0x0001 #define VC4_DEBUG_QPU 0x0002 #define VC4_DEBUG_QIR 0x0004 @@ -117,8 +121,6 @@ vc4_screen_get_compiler_options(struct pipe_screen *pscreen, enum pipe_shader_ir ir, enum pipe_shader_type shader); -extern uint32_t vc4_debug; - void vc4_fence_screen_init(struct vc4_screen *screen); diff --git a/src/gallium/drivers/vc4/vc4_simulator.c b/src/gallium/drivers/vc4/vc4_simulator.c index b71fcc1af45..e9f73ba1fd5 100644 --- a/src/gallium/drivers/vc4/vc4_simulator.c +++ b/src/gallium/drivers/vc4/vc4_simulator.c @@ -377,7 +377,7 @@ vc4_dump_to_file(struct vc4_exec_info *exec) struct drm_vc4_get_hang_state_bo *bo_state; unsigned int dump_version = 0; - if (!(vc4_debug & VC4_DEBUG_DUMP)) + if (!VC4_DBG(DUMP)) return; state = calloc(1, sizeof(*state)); @@ -477,7 +477,7 @@ vc4_simulator_submit_cl_ioctl(int fd, struct drm_vc4_submit_cl *args) if (ret) return ret; - if (vc4_debug & VC4_DEBUG_CL) { + if (VC4_DBG(CL)) { fprintf(stderr, "RCL:\n"); vc4_dump_cl(sim_state.mem + exec.ct1ca, exec.ct1ea - exec.ct1ca, true);