softpipe: Add support for reporting shader-db output.
authorEric Anholt <eric@anholt.net>
Tue, 21 Jul 2020 22:55:40 +0000 (15:55 -0700)
committerMarge Bot <eric+marge@anholt.net>
Thu, 23 Jul 2020 00:24:26 +0000 (00:24 +0000)
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 <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6018>

src/gallium/drivers/softpipe/sp_context.c
src/gallium/drivers/softpipe/sp_context.h
src/gallium/drivers/softpipe/sp_state_shader.c

index 6a896b8a41d70ac09266ec6d47dfbf0f66841103..d82e996bffcf91377413266e43186fbcc380344f 100644 (file)
@@ -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;
 
index d4be1efc945a9db16e65a1202cd5f3a1f7767158..cd2e498de6b4da4e8f81f27796b1702e09052a84 100644 (file)
@@ -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;
 };
 
 
index b53d5540bdb2b1fb8cc25369d40ccbe01865d365..19e854ce39fa6b1f17efc458add7d1187d12ea26 100644 (file)
 #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;