Mesa (main): r300: Route shader stats output to ARB_debug_output.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Dec 8 02:46:11 UTC 2021


Module: Mesa
Branch: main
Commit: 8ddefb8ea5789137d3ea99f255f3d17d10d291e0
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8ddefb8ea5789137d3ea99f255f3d17d10d291e0

Author: Emma Anholt <emma at anholt.net>
Date:   Tue Dec  7 10:18:03 2021 -0800

r300: Route shader stats output to ARB_debug_output.

This lets us use shader-db to compare stats on shaders, rather than having
to manually review the RADEON_DEBUG=pstat output.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14117>

---

 .../drivers/r300/compiler/radeon_compiler.c        | 47 ++++++----------------
 .../drivers/r300/compiler/radeon_compiler.h        |  4 +-
 src/gallium/drivers/r300/r300_context.c            | 13 ++++++
 src/gallium/drivers/r300/r300_context.h            |  2 +
 src/gallium/drivers/r300/r300_debug.c              |  1 -
 src/gallium/drivers/r300/r300_fs.c                 |  3 +-
 src/gallium/drivers/r300/r300_screen.h             |  2 -
 src/gallium/drivers/r300/r300_vs.c                 |  3 +-
 8 files changed, 32 insertions(+), 43 deletions(-)

diff --git a/src/gallium/drivers/r300/compiler/radeon_compiler.c b/src/gallium/drivers/r300/compiler/radeon_compiler.c
index 78902d98068..85bdab1d97f 100644
--- a/src/gallium/drivers/r300/compiler/radeon_compiler.c
+++ b/src/gallium/drivers/r300/compiler/radeon_compiler.c
@@ -26,6 +26,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "util/u_debug.h"
+#include "pipe/p_state.h"
 #include "radeon_dataflow.h"
 #include "radeon_program.h"
 #include "radeon_program_pair.h"
@@ -417,40 +419,17 @@ static void print_stats(struct radeon_compiler * c)
 {
 	struct rc_program_stats s;
 
-	if (c->initial_num_insts <= 5)
-		return;
-
 	rc_get_stats(c, &s);
 
-	switch (c->type) {
-	case RC_VERTEX_PROGRAM:
-		fprintf(stderr,"~~~~~~~~~ VERTEX PROGRAM ~~~~~~~~\n"
-			       "~%4u Instructions\n"
-			       "~%4u Flow Control Instructions\n"
-			       "~%4u Temporary Registers\n"
-			       "~~~~~~~~~~~~~~ END ~~~~~~~~~~~~~~\n",
-			       s.num_insts, s.num_fc_insts, s.num_temp_regs);
-		break;
-
-	case RC_FRAGMENT_PROGRAM:
-		fprintf(stderr,"~~~~~~~~ FRAGMENT PROGRAM ~~~~~~~\n"
-			       "~%4u Instructions\n"
-			       "~%4u Vector Instructions (RGB)\n"
-			       "~%4u Scalar Instructions (Alpha)\n"
-			       "~%4u Flow Control Instructions\n"
-			       "~%4u Texture Instructions\n"
-			       "~%4u Presub Operations\n"
-			       "~%4u OMOD Operations\n"
-			       "~%4u Temporary Registers\n"
-			       "~%4u Inline Literals\n"
-			       "~~~~~~~~~~~~~~ END ~~~~~~~~~~~~~~\n",
-			       s.num_insts, s.num_rgb_insts, s.num_alpha_insts,
-			       s.num_fc_insts, s.num_tex_insts, s.num_presub_ops,
-			       s.num_omod_ops, s.num_temp_regs, s.num_inline_literals);
-		break;
-	default:
-		assert(0);
-	}
+	/* Note that we print some dummy values for instruction categories that
+	 * only the FS has, becasue shader-db's report.py wants all shaders to
+	 * have the same set.
+	 */
+	pipe_debug_message(c->debug, SHADER_INFO, "%s shader: %d inst, %d vinst, %d sinst, %d flowcontrol, %d tex, %d presub, %d omod, %d temps, %d lits",
+	                   c->type == RC_VERTEX_PROGRAM ? "VS" : "FS",
+	                   s.num_insts, s.num_rgb_insts, s.num_alpha_insts,
+	                   s.num_fc_insts, s.num_tex_insts, s.num_presub_ops,
+	                   s.num_omod_ops, s.num_temp_regs, s.num_inline_literals);
 }
 
 static const char *shader_name[RC_NUM_PROGRAM_TYPES] = {
@@ -481,7 +460,6 @@ void rc_run_compiler(struct radeon_compiler *c, struct radeon_compiler_pass *lis
 	struct rc_program_stats s;
 
 	rc_get_stats(c, &s);
-	c->initial_num_insts = s.num_insts;
 
 	if (c->Debug & RC_DBG_LOG) {
 		fprintf(stderr, "%s: before compilation\n", shader_name[c->type]);
@@ -490,8 +468,7 @@ void rc_run_compiler(struct radeon_compiler *c, struct radeon_compiler_pass *lis
 
 	rc_run_compiler_passes(c, list);
 
-	if (c->Debug & RC_DBG_STATS)
-		print_stats(c);
+	print_stats(c);
 }
 
 void rc_validate_final_shader(struct radeon_compiler *c, void *user)
diff --git a/src/gallium/drivers/r300/compiler/radeon_compiler.h b/src/gallium/drivers/r300/compiler/radeon_compiler.h
index 7089bcbea2c..e33872482ea 100644
--- a/src/gallium/drivers/r300/compiler/radeon_compiler.h
+++ b/src/gallium/drivers/r300/compiler/radeon_compiler.h
@@ -29,7 +29,6 @@
 #include "radeon_emulate_loops.h"
 
 #define RC_DBG_LOG        (1 << 0)
-#define RC_DBG_STATS      (1 << 1)
 
 struct rc_swizzle_caps;
 
@@ -43,6 +42,7 @@ struct radeon_compiler {
 	struct memory_pool Pool;
 	struct rc_program Program;
 	const struct rc_regalloc_state *regalloc_state;
+	struct pipe_debug_callback *debug;
 	enum rc_program_type type;
 	unsigned Debug:2;
 	unsigned Error:1;
@@ -72,8 +72,6 @@ struct radeon_compiler {
 	/*@}*/
 
 	struct emulate_loop_state loop_state;
-
-	unsigned initial_num_insts; /* Number of instructions at start. */
 };
 
 void rc_init(struct radeon_compiler * c, const struct rc_regalloc_state *rs);
diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c
index b5a7d10a075..3acc55d312a 100644
--- a/src/gallium/drivers/r300/r300_context.c
+++ b/src/gallium/drivers/r300/r300_context.c
@@ -368,6 +368,18 @@ static void r300_init_states(struct pipe_context *pipe)
     }
 }
 
+static void
+r300_set_debug_callback(struct pipe_context *context,
+                        const struct pipe_debug_callback *cb)
+{
+    struct r300_context *r300 = r300_context(context);
+
+    if (cb)
+        r300->debug = *cb;
+    else
+        memset(&r300->debug, 0, sizeof(r300->debug));
+}
+
 struct pipe_context* r300_create_context(struct pipe_screen* screen,
                                          void *priv, unsigned flags)
 {
@@ -383,6 +395,7 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
 
     r300->context.screen = screen;
     r300->context.priv = priv;
+    r300->context.set_debug_callback = r300_set_debug_callback;
 
     r300->context.destroy = r300_destroy_context;
 
diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h
index 61899809026..e35e6271e5a 100644
--- a/src/gallium/drivers/r300/r300_context.h
+++ b/src/gallium/drivers/r300/r300_context.h
@@ -547,6 +547,8 @@ struct r300_context {
     /* Occlusion query. */
     struct r300_atom query_start;
 
+    struct pipe_debug_callback debug;
+
     /* The pointers to the first and the last atom. */
     struct r300_atom *first_dirty, *last_dirty;
 
diff --git a/src/gallium/drivers/r300/r300_debug.c b/src/gallium/drivers/r300/r300_debug.c
index 13acb634cd1..c86577cd251 100644
--- a/src/gallium/drivers/r300/r300_debug.c
+++ b/src/gallium/drivers/r300/r300_debug.c
@@ -30,7 +30,6 @@ static const struct debug_named_value r300_debug_options[] = {
     { "info", DBG_INFO, "Print hardware info (printed by default on debug builds"},
     { "fp", DBG_FP, "Log fragment program compilation" },
     { "vp", DBG_VP, "Log vertex program compilation" },
-    { "pstat", DBG_P_STAT, "Log vertex/fragment program stats" },
     { "draw", DBG_DRAW, "Log draw calls" },
     { "swtcl", DBG_SWTCL, "Log SWTCL-specific info" },
     { "rsblock", DBG_RS_BLOCK, "Log rasterizer registers" },
diff --git a/src/gallium/drivers/r300/r300_fs.c b/src/gallium/drivers/r300/r300_fs.c
index 382f39b006c..241e5c141c9 100644
--- a/src/gallium/drivers/r300/r300_fs.c
+++ b/src/gallium/drivers/r300/r300_fs.c
@@ -429,10 +429,11 @@ static void r300_translate_fragment_shader(
     memset(&compiler, 0, sizeof(compiler));
     rc_init(&compiler.Base, &r300->fs_regalloc_state);
     DBG_ON(r300, DBG_FP) ? compiler.Base.Debug |= RC_DBG_LOG : 0;
-    DBG_ON(r300, DBG_P_STAT) ? compiler.Base.Debug |= RC_DBG_STATS : 0;
 
     compiler.code = &shader->code;
     compiler.state = shader->compare_state;
+    if (!shader->dummy)
+        compiler.Base.debug = &r300->debug;
     compiler.Base.is_r500 = r300->screen->caps.is_r500;
     compiler.Base.is_r400 = r300->screen->caps.is_r400;
     compiler.Base.disable_optimizations = DBG_ON(r300, DBG_NO_OPT);
diff --git a/src/gallium/drivers/r300/r300_screen.h b/src/gallium/drivers/r300/r300_screen.h
index b28de008304..09332b3adcc 100644
--- a/src/gallium/drivers/r300/r300_screen.h
+++ b/src/gallium/drivers/r300/r300_screen.h
@@ -103,8 +103,6 @@ radeon_winsys(struct pipe_screen *screen) {
 #define DBG_NO_ZMASK    (1 << 21)
 #define DBG_NO_HIZ      (1 << 22)
 #define DBG_NO_CMASK    (1 << 23)
-/* Statistics. */
-#define DBG_P_STAT      (1 << 25)
 /*@}*/
 
 static inline boolean SCREEN_DBG_ON(struct r300_screen * screen, unsigned flags)
diff --git a/src/gallium/drivers/r300/r300_vs.c b/src/gallium/drivers/r300/r300_vs.c
index 96d6c4386ae..fb225296592 100644
--- a/src/gallium/drivers/r300/r300_vs.c
+++ b/src/gallium/drivers/r300/r300_vs.c
@@ -214,9 +214,10 @@ void r300_translate_vertex_shader(struct r300_context *r300,
     rc_init(&compiler.Base, NULL);
 
     DBG_ON(r300, DBG_VP) ? compiler.Base.Debug |= RC_DBG_LOG : 0;
-    DBG_ON(r300, DBG_P_STAT) ? compiler.Base.Debug |= RC_DBG_STATS : 0;
     compiler.code = &vs->code;
     compiler.UserData = vs;
+    if (!vs->dummy)
+        compiler.Base.debug = &r300->debug;
     compiler.Base.is_r500 = r300->screen->caps.is_r500;
     compiler.Base.disable_optimizations = DBG_ON(r300, DBG_NO_OPT);
     compiler.Base.has_half_swizzles = FALSE;



More information about the mesa-commit mailing list