From ed1910dc68e86dda8042c2c3ecb24695fe88f398 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 7 Jul 2020 16:15:45 -0400 Subject: [PATCH] panfrost: Move debug flags into the device Removes random global state flying about which doesn't really work for common code. We cleanup some debug messages while we're at it because the mostly-unused DBG macro relies on magic state. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/panfrost/pan_assemble.c | 5 ++- src/gallium/drivers/panfrost/pan_blit.c | 10 ++++-- src/gallium/drivers/panfrost/pan_context.c | 16 ++++----- src/gallium/drivers/panfrost/pan_job.c | 13 +++++--- src/gallium/drivers/panfrost/pan_resource.c | 17 +++++----- src/gallium/drivers/panfrost/pan_screen.c | 36 ++++++++++----------- src/panfrost/encoder/pan_device.h | 3 ++ src/panfrost/encoder/pan_util.h | 7 ---- 8 files changed, 54 insertions(+), 53 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_assemble.c b/src/gallium/drivers/panfrost/pan_assemble.c index 8a6caead34c..e7ac80a7f5c 100644 --- a/src/gallium/drivers/panfrost/pan_assemble.c +++ b/src/gallium/drivers/panfrost/pan_assemble.c @@ -132,8 +132,7 @@ bifrost_blend_type_from_nir(nir_alu_type nir_type) case nir_type_uint16: return BIFROST_BLEND_U16; default: - DBG("Unsupported blend shader type for NIR alu type %d", nir_type); - assert(0); + unreachable("Unsupported blend shader type for NIR alu type"); return 0; } } @@ -170,7 +169,7 @@ panfrost_shader_compile(struct panfrost_context *ctx, bifrost_compile_shader_nir(s, &program, dev->gpu_id); } else { midgard_compile_shader_nir(s, &program, false, 0, dev->gpu_id, - pan_debug & PAN_DBG_PRECOMPILE); + dev->debug & PAN_DBG_PRECOMPILE); } /* Prepare the compiled binary for upload */ diff --git a/src/gallium/drivers/panfrost/pan_blit.c b/src/gallium/drivers/panfrost/pan_blit.c index 3f45cdded09..6361e7c7737 100644 --- a/src/gallium/drivers/panfrost/pan_blit.c +++ b/src/gallium/drivers/panfrost/pan_blit.c @@ -64,11 +64,15 @@ panfrost_u_blitter_blit(struct pipe_context *pipe, const struct pipe_blit_info *info) { struct panfrost_context *ctx = pan_context(pipe); + struct panfrost_device *dev = pan_device(pipe->screen); if (!util_blitter_is_blit_supported(ctx->blitter, info)) { - DBG("blit unsupported %s -> %s\n", - util_format_short_name(info->src.resource->format), - util_format_short_name(info->dst.resource->format)); + if (dev->debug & PAN_DBG_MSGS) { + fprintf(stderr, "blit unsupported %s -> %s\n", + util_format_short_name(info->src.resource->format), + util_format_short_name(info->dst.resource->format)); + } + return false; } diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index b96aef2a11e..5614ee4535a 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -238,6 +238,7 @@ panfrost_flush( unsigned flags) { struct panfrost_context *ctx = pan_context(pipe); + struct panfrost_device *dev = pan_device(pipe->screen); struct util_dynarray fences; /* We must collect the fences before the flush is done, otherwise we'll @@ -269,7 +270,7 @@ panfrost_flush( util_dynarray_fini(&fences); } - if (pan_debug & PAN_DBG_TRACE) + if (dev->debug & PAN_DBG_TRACE) pandecode_next_frame(); } @@ -557,6 +558,7 @@ panfrost_create_shader_state( enum pipe_shader_type stage) { struct panfrost_shader_variants *so = CALLOC_STRUCT(panfrost_shader_variants); + struct panfrost_device *dev = pan_device(pctx->screen); so->base = *cso; /* Token deep copy to prevent memory corruption */ @@ -565,7 +567,7 @@ panfrost_create_shader_state( so->base.tokens = tgsi_dup_tokens(so->base.tokens); /* Precompile for shader-db if we need to */ - if (unlikely((pan_debug & PAN_DBG_PRECOMPILE) && cso->type == PIPE_SHADER_IR_NIR)) { + if (unlikely((dev->debug & PAN_DBG_PRECOMPILE) && cso->type == PIPE_SHADER_IR_NIR)) { struct panfrost_context *ctx = pan_context(pctx); struct panfrost_shader_state state; @@ -588,7 +590,7 @@ panfrost_delete_shader_state( struct panfrost_shader_variants *cso = (struct panfrost_shader_variants *) so; if (cso->base.type == PIPE_SHADER_IR_TGSI) { - DBG("Deleting TGSI shader leaks duplicated tokens\n"); + /* TODO: leaks TGSI tokens! */ } for (unsigned i = 0; i < cso->variant_count; ++i) { @@ -1098,7 +1100,7 @@ panfrost_hint_afbc( const struct pipe_framebuffer_state *fb) { /* AFBC implemenation incomplete; hide it */ - if (!(pan_debug & PAN_DBG_AFBC)) return; + if (!(device->debug & PAN_DBG_AFBC)) return; /* Hint AFBC to the resources bound to each color buffer */ @@ -1298,7 +1300,7 @@ panfrost_begin_query(struct pipe_context *pipe, struct pipe_query *q) break; default: - DBG("Skipping query %u\n", query->type); + /* TODO: timestamp queries, etc? */ break; } @@ -1342,7 +1344,6 @@ panfrost_get_query_result(struct pipe_context *pipe, case PIPE_QUERY_OCCLUSION_COUNTER: case PIPE_QUERY_OCCLUSION_PREDICATE: case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE: - DBG("Flushing for occlusion query\n"); panfrost_flush_batches_accessing_bo(ctx, query->bo, PAN_BO_ACCESS_WRITE); panfrost_bo_wait(query->bo, INT64_MAX, PAN_BO_ACCESS_WRITE); @@ -1360,13 +1361,12 @@ panfrost_get_query_result(struct pipe_context *pipe, case PIPE_QUERY_PRIMITIVES_GENERATED: case PIPE_QUERY_PRIMITIVES_EMITTED: - DBG("Flushing for primitive query\n"); panfrost_flush_all_batches(ctx, true); vresult->u64 = query->end - query->start; break; default: - DBG("Skipped query get %u\n", query->type); + /* TODO: more queries */ break; } diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c index 82596f3d9b1..113812fbb70 100644 --- a/src/gallium/drivers/panfrost/pan_job.c +++ b/src/gallium/drivers/panfrost/pan_job.c @@ -973,18 +973,20 @@ panfrost_batch_submit_ioctl(struct panfrost_batch *batch, free(in_syncs); if (ret) { - DBG("Error submitting: %m\n"); + if (dev->debug & PAN_DBG_MSGS) + fprintf(stderr, "Error submitting: %m\n"); + return errno; } /* Trace the job if we're doing that */ - if (pan_debug & (PAN_DBG_TRACE | PAN_DBG_SYNC)) { + if (dev->debug & (PAN_DBG_TRACE | PAN_DBG_SYNC)) { /* Wait so we can get errors reported back */ drmSyncobjWait(dev->fd, &batch->out_sync->syncobj, 1, INT64_MAX, 0, NULL); /* Trace gets priority over sync */ - bool minimal = !(pan_debug & PAN_DBG_TRACE); + bool minimal = !(dev->debug & PAN_DBG_TRACE); pandecode_jc(submit.jc, dev->quirks & IS_BIFROST, dev->gpu_id, minimal); } @@ -1015,6 +1017,7 @@ static void panfrost_batch_submit(struct panfrost_batch *batch) { assert(batch); + struct panfrost_device *dev = pan_device(batch->ctx->base.screen); /* Submit the dependencies first. */ util_dynarray_foreach(&batch->dependencies, @@ -1054,8 +1057,8 @@ panfrost_batch_submit(struct panfrost_batch *batch) ret = panfrost_batch_submit_jobs(batch); - if (ret) - DBG("panfrost_batch_submit failed: %d\n", ret); + if (ret && dev->debug & PAN_DBG_MSGS) + fprintf(stderr, "panfrost_batch_submit failed: %d\n", ret); /* We must reset the damage info of our render targets here even * though a damage reset normally happens when the DRI layer swaps diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index a8362bee8a9..e73f3a0f787 100644 --- a/src/gallium/drivers/panfrost/pan_resource.c +++ b/src/gallium/drivers/panfrost/pan_resource.c @@ -57,7 +57,7 @@ pan_bo_create(struct panfrost_device *dev, size_t size, uint32_t flags) { struct panfrost_bo *bo = panfrost_bo_create(dev, size, flags); - if (pan_debug & (PAN_DBG_TRACE | PAN_DBG_SYNC)) { + if (dev->debug & (PAN_DBG_TRACE | PAN_DBG_SYNC)) { if (flags & PAN_BO_INVISIBLE) pandecode_inject_mmap(bo->gpu, NULL, bo->size, NULL); else if (!(flags & PAN_BO_DELAY_MMAP)) @@ -183,7 +183,7 @@ panfrost_resource_get_handle(struct pipe_screen *pscreen, static void panfrost_flush_resource(struct pipe_context *pctx, struct pipe_resource *prsc) { - //DBG("TODO %s\n", __func__); + /* TODO */ } static struct pipe_surface * @@ -535,8 +535,7 @@ panfrost_resource_create(struct pipe_screen *screen, case PIPE_TEXTURE_2D_ARRAY: break; default: - DBG("Unknown texture target %d\n", template->target); - assert(0); + unreachable("Unknown texture target\n"); } if (dev->ro && (template->bind & @@ -591,6 +590,7 @@ panfrost_transfer_map(struct pipe_context *pctx, struct pipe_transfer **out_transfer) { struct panfrost_context *ctx = pan_context(pctx); + struct panfrost_device *dev = pan_device(pctx->screen); struct panfrost_resource *rsrc = pan_resource(resource); int bytes_per_pixel = util_format_get_blocksize(rsrc->internal_format); struct panfrost_bo *bo = rsrc->bo; @@ -607,7 +607,7 @@ panfrost_transfer_map(struct pipe_context *pctx, /* If we haven't already mmaped, now's the time */ panfrost_bo_mmap(bo); - if (pan_debug & (PAN_DBG_TRACE | PAN_DBG_SYNC)) + if (dev->debug & (PAN_DBG_TRACE | PAN_DBG_SYNC)) pandecode_inject_mmap(bo->gpu, bo->cpu, bo->size, NULL); bool create_new_bo = usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE; @@ -640,7 +640,6 @@ panfrost_transfer_map(struct pipe_context *pctx, */ if (panfrost_pending_batches_access_bo(ctx, bo) || !panfrost_bo_wait(bo, 0, PAN_BO_ACCESS_RW)) { - struct panfrost_device *dev = pan_device(pctx->screen); /* We want the BO to be MMAPed. */ uint32_t flags = bo->flags & ~PAN_BO_DELAY_MMAP; struct panfrost_bo *newbo = NULL; @@ -699,7 +698,7 @@ panfrost_transfer_map(struct pipe_context *pctx, if ((usage & PIPE_TRANSFER_READ) && rsrc->slices[level].initialized) { if (rsrc->layout == MALI_TEXTURE_AFBC) { - DBG("Unimplemented: reads from AFBC"); + unreachable("Unimplemented: reads from AFBC"); } else if (rsrc->layout == MALI_TEXTURE_TILED) { panfrost_load_tiled_image( transfer->map, @@ -761,7 +760,7 @@ panfrost_transfer_unmap(struct pipe_context *pctx, if (transfer->usage & PIPE_TRANSFER_WRITE) { if (prsrc->layout == MALI_TEXTURE_AFBC) { - DBG("Unimplemented: writes to AFBC\n"); + unreachable("Unimplemented: writes to AFBC\n"); } else if (prsrc->layout == MALI_TEXTURE_TILED) { assert(transfer->box.depth == 1); @@ -845,7 +844,7 @@ panfrost_transfer_flush_region(struct pipe_context *pctx, static void panfrost_invalidate_resource(struct pipe_context *pctx, struct pipe_resource *prsc) { - //DBG("TODO %s\n", __func__); + /* TODO */ } static enum pipe_format diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c index 3a486a04bc1..c0af92e316c 100644 --- a/src/gallium/drivers/panfrost/pan_screen.c +++ b/src/gallium/drivers/panfrost/pan_screen.c @@ -69,10 +69,6 @@ static const struct debug_named_value debug_options[] = { DEBUG_NAMED_VALUE_END }; -DEBUG_GET_ONCE_FLAGS_OPTION(pan_debug, "PAN_MESA_DEBUG", debug_options, 0) - -int pan_debug = 0; - static const char * panfrost_get_name(struct pipe_screen *screen) { @@ -95,15 +91,15 @@ static int panfrost_get_param(struct pipe_screen *screen, enum pipe_cap param) { /* We expose in-dev stuff for dEQP that we don't want apps to use yet */ - bool is_deqp = pan_debug & PAN_DBG_DEQP; struct panfrost_device *dev = pan_device(screen); + bool is_deqp = dev->debug & PAN_DBG_DEQP; /* Our GL 3.x implementation is WIP */ - bool is_gl3 = pan_debug & PAN_DBG_GL3; + bool is_gl3 = dev->debug & PAN_DBG_GL3; is_gl3 |= is_deqp; /* Same with GLES 3 */ - bool is_gles3 = pan_debug & PAN_DBG_GLES3; + bool is_gles3 = dev->debug & PAN_DBG_GLES3; is_gles3 |= is_gl3; switch (param) { @@ -299,9 +295,9 @@ panfrost_get_shader_param(struct pipe_screen *screen, enum pipe_shader_type shader, enum pipe_shader_cap param) { - bool is_deqp = pan_debug & PAN_DBG_DEQP; - bool is_fp16 = pan_debug & PAN_DBG_FP16; struct panfrost_device *dev = pan_device(screen); + bool is_deqp = dev->debug & PAN_DBG_DEQP; + bool is_fp16 = dev->debug & PAN_DBG_FP16; if (shader != PIPE_SHADER_VERTEX && shader != PIPE_SHADER_FRAGMENT && @@ -396,7 +392,7 @@ panfrost_get_shader_param(struct pipe_screen *screen, return 0; default: - DBG("unknown shader param %d\n", param); + /* Other params are unknown */ return 0; } @@ -449,6 +445,7 @@ panfrost_is_format_supported( struct pipe_screen *screen, unsigned storage_sample_count, unsigned bind) { + struct panfrost_device *dev = pan_device(screen); const struct util_format_description *format_desc; assert(target == PIPE_BUFFER || @@ -485,7 +482,7 @@ panfrost_is_format_supported( struct pipe_screen *screen, if (scanout && renderable && !util_format_is_rgba8_variant(format_desc)) return false; - if (pan_debug & (PAN_DBG_GL3 | PAN_DBG_DEQP)) { + if (dev->debug & (PAN_DBG_GL3 | PAN_DBG_DEQP)) { if (format_desc->layout == UTIL_FORMAT_LAYOUT_RGTC) return true; } @@ -504,9 +501,10 @@ static int panfrost_get_compute_param(struct pipe_screen *pscreen, enum pipe_shader_ir ir_type, enum pipe_compute_cap param, void *ret) { + struct panfrost_device *dev = pan_device(pscreen); const char * const ir = "panfrost"; - if (!(pan_debug & PAN_DBG_DEQP)) + if (!(dev->debug & PAN_DBG_DEQP)) return 0; #define RET(x) do { \ @@ -687,8 +685,6 @@ panfrost_screen_get_compiler_options(struct pipe_screen *pscreen, struct pipe_screen * panfrost_create_screen(int fd, struct renderonly *ro) { - pan_debug = debug_get_option_pan_debug(); - /* Blacklist apps known to be buggy under Panfrost */ const char *proc = util_get_process_name(); const char *blacklist[] = { @@ -710,10 +706,14 @@ panfrost_create_screen(int fd, struct renderonly *ro) struct panfrost_device *dev = pan_device(&screen->base); panfrost_open_device(screen, fd, dev); + dev->debug = debug_get_flags_option("PAN_MESA_DEBUG", debug_options, 0); + if (ro) { dev->ro = renderonly_dup(ro); if (!dev->ro) { - DBG("Failed to dup renderonly object\n"); + if (dev->debug & PAN_DBG_MSGS) + fprintf(stderr, "Failed to dup renderonly object\n"); + free(screen); return NULL; } @@ -729,7 +729,7 @@ panfrost_create_screen(int fd, struct renderonly *ro) break; case 0x7093: /* G31 */ case 0x7212: /* G52 */ - if (pan_debug & PAN_DBG_BIFROST) + if (dev->debug & PAN_DBG_BIFROST) break; /* fallthrough */ @@ -740,8 +740,8 @@ panfrost_create_screen(int fd, struct renderonly *ro) return NULL; } - if (pan_debug & (PAN_DBG_TRACE | PAN_DBG_SYNC)) - pandecode_initialize(!(pan_debug & PAN_DBG_TRACE)); + if (dev->debug & (PAN_DBG_TRACE | PAN_DBG_SYNC)) + pandecode_initialize(!(dev->debug & PAN_DBG_TRACE)); screen->base.destroy = panfrost_destroy_screen; diff --git a/src/panfrost/encoder/pan_device.h b/src/panfrost/encoder/pan_device.h index 75bf82e4434..693c156f2e3 100644 --- a/src/panfrost/encoder/pan_device.h +++ b/src/panfrost/encoder/pan_device.h @@ -79,6 +79,9 @@ struct panfrost_device { unsigned thread_tls_alloc; unsigned quirks; + /* debug flags, see pan_util.h how to interpret */ + unsigned debug; + drmVersionPtr kernel_version; struct renderonly *ro; diff --git a/src/panfrost/encoder/pan_util.h b/src/panfrost/encoder/pan_util.h index 46a335251d8..75086e78d8b 100644 --- a/src/panfrost/encoder/pan_util.h +++ b/src/panfrost/encoder/pan_util.h @@ -39,11 +39,4 @@ #define PAN_DBG_BIFROST 0x0100 #define PAN_DBG_GL3 0x0200 -extern int pan_debug; - -#define DBG(fmt, ...) \ - do { if (pan_debug & PAN_DBG_MSGS) \ - fprintf(stderr, "%s:%d: "fmt, \ - __FUNCTION__, __LINE__, ##__VA_ARGS__); } while (0) - #endif /* PAN_UTIL_H */ -- 2.30.2