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@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14117>
This commit is contained in:
Emma Anholt 2021-12-07 10:18:03 -08:00 committed by Marge Bot
parent 141302e61f
commit 8ddefb8ea5
8 changed files with 32 additions and 43 deletions

View file

@ -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)

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -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" },

View file

@ -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);

View file

@ -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)

View file

@ -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;