From: Eric Anholt Date: Tue, 21 Jul 2020 22:55:40 +0000 (-0700) Subject: softpipe: Add support for reporting shader-db output. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=259a03b4f0b04903d348a38bccc8954ef9f83738;p=mesa.git softpipe: Add support for reporting shader-db output. In doing the softpipe NIR and NIR-to-TGSI transition, I want to make sure I don't make shaders significantly worse, so I need shader-db output. Reviewed-by: Dave Airlie Part-of: --- diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c index 6a896b8a41d..d82e996bffc 100644 --- a/src/gallium/drivers/softpipe/sp_context.c +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -191,6 +191,18 @@ softpipe_render_condition(struct pipe_context *pipe, } +static void +softpipe_set_debug_callback(struct pipe_context *pipe, + const struct pipe_debug_callback *cb) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + if (cb) + softpipe->debug = *cb; + else + memset(&softpipe->debug, 0, sizeof(softpipe->debug)); +} + struct pipe_context * softpipe_create_context(struct pipe_screen *screen, @@ -231,6 +243,7 @@ softpipe_create_context(struct pipe_screen *screen, softpipe_init_image_funcs(&softpipe->pipe); softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state; + softpipe->pipe.set_debug_callback = softpipe_set_debug_callback; softpipe->pipe.draw_vbo = softpipe_draw_vbo; diff --git a/src/gallium/drivers/softpipe/sp_context.h b/src/gallium/drivers/softpipe/sp_context.h index d4be1efc945..cd2e498de6b 100644 --- a/src/gallium/drivers/softpipe/sp_context.h +++ b/src/gallium/drivers/softpipe/sp_context.h @@ -204,6 +204,8 @@ struct softpipe_context { * of sp_sampler_view? */ struct softpipe_tex_tile_cache *tex_cache[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS]; + + struct pipe_debug_callback debug; }; diff --git a/src/gallium/drivers/softpipe/sp_state_shader.c b/src/gallium/drivers/softpipe/sp_state_shader.c index b53d5540bdb..19e854ce39f 100644 --- a/src/gallium/drivers/softpipe/sp_state_shader.c +++ b/src/gallium/drivers/softpipe/sp_state_shader.c @@ -39,8 +39,10 @@ #include "draw/draw_vs.h" #include "draw/draw_gs.h" #include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_from_mesa.h" #include "tgsi/tgsi_scan.h" #include "tgsi/tgsi_parse.h" +#include "compiler/shader_enums.h" /** @@ -116,7 +118,24 @@ softpipe_find_fs_variant(struct softpipe_context *sp, } static void -softpipe_create_shader_state(struct pipe_shader_state *shader, +softpipe_shader_db(struct pipe_context *pipe, const struct tgsi_token *tokens) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + struct tgsi_shader_info info; + tgsi_scan_shader(tokens, &info); + pipe_debug_message(&softpipe->debug, SHADER_INFO, "%s shader: %d inst, %d loops, %d temps, %d const, %d imm", + _mesa_shader_stage_to_abbrev(tgsi_processor_to_shader_stage(info.processor)), + info.num_instructions, + info.opcode_count[TGSI_OPCODE_BGNLOOP], + info.file_max[TGSI_FILE_TEMPORARY] + 1, + info.file_max[TGSI_FILE_CONSTANT] + 1, + info.immediate_count); +} + +static void +softpipe_create_shader_state(struct pipe_context *pipe, + struct pipe_shader_state *shader, const struct pipe_shader_state *templ, bool debug) { @@ -129,6 +148,8 @@ softpipe_create_shader_state(struct pipe_shader_state *shader, if (debug) tgsi_dump(shader->tokens, 0); + + softpipe_shader_db(pipe, shader->tokens); } static void * @@ -138,7 +159,8 @@ softpipe_create_fs_state(struct pipe_context *pipe, struct softpipe_context *softpipe = softpipe_context(pipe); struct sp_fragment_shader *state = CALLOC_STRUCT(sp_fragment_shader); - softpipe_create_shader_state(&state->shader, templ, sp_debug & SP_DBG_FS); + softpipe_create_shader_state(pipe, &state->shader, templ, + sp_debug & SP_DBG_FS); /* draw's fs state */ state->draw_shader = draw_create_fragment_shader(softpipe->draw, @@ -222,7 +244,8 @@ softpipe_create_vs_state(struct pipe_context *pipe, if (!state) goto fail; - softpipe_create_shader_state(&state->shader, templ, sp_debug & SP_DBG_VS); + softpipe_create_shader_state(pipe, &state->shader, templ, + sp_debug & SP_DBG_VS); if (!state->shader.tokens) goto fail; @@ -282,7 +305,8 @@ softpipe_create_gs_state(struct pipe_context *pipe, if (!state) goto fail; - softpipe_create_shader_state(&state->shader, templ, sp_debug & SP_DBG_GS); + softpipe_create_shader_state(pipe, &state->shader, templ, + sp_debug & SP_DBG_GS); if (templ->tokens) { state->draw_data = draw_create_geometry_shader(softpipe->draw, templ); @@ -391,6 +415,8 @@ softpipe_create_compute_state(struct pipe_context *pipe, if (sp_debug & SP_DBG_CS) tgsi_dump(tokens, 0); + softpipe_shader_db(pipe, tokens); + state = CALLOC_STRUCT(sp_compute_shader); state->shader = *templ;