radeonsi: send shader info as debug messages in addition to stderr output
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Sat, 2 Jan 2016 21:30:57 +0000 (16:30 -0500)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Sat, 2 Jan 2016 21:47:24 +0000 (16:47 -0500)
The output via stderr is very helpful for ad-hoc debugging tasks, so that remains
unchanged, but having the information available via debug messages as well
will allow the use of parallel shader-db runs.

Shader stats are always provided (if the context is a debug context, that is),
but you still have to enable the appropriate R600_DEBUG flags to get
disassembly (since it is rather spammy and is only generated by LLVM when we
explicitly ask for it).

Reviewed-by: Edward O'Callaghan <eocallaghan@alterapraxis.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/drivers/radeonsi/si_shader.c

index 309219f7bc5755dfc7d86ff456cf49e6390b89e1..a34f7da711da06f396305db54682bf886316aaf8 100644 (file)
@@ -3840,11 +3840,57 @@ int si_shader_binary_upload(struct si_screen *sscreen, struct si_shader *shader)
        return 0;
 }
 
+static void si_shader_dump_disassembly(const struct radeon_shader_binary *binary,
+                                      struct pipe_debug_callback *debug)
+{
+       char *line, *p;
+       unsigned i, count;
+
+       if (binary->disasm_string) {
+               fprintf(stderr, "\nShader Disassembly:\n\n");
+               fprintf(stderr, "%s\n", binary->disasm_string);
+
+               if (debug && debug->debug_message) {
+                       /* Very long debug messages are cut off, so send the
+                        * disassembly one line at a time. This causes more
+                        * overhead, but on the plus side it simplifies
+                        * parsing of resulting logs.
+                        */
+                       pipe_debug_message(debug, SHADER_INFO,
+                                          "Shader Disassembly Begin");
+
+                       line = binary->disasm_string;
+                       while (*line) {
+                               p = strchrnul(line, '\n');
+                               count = p - line;
+
+                               if (count) {
+                                       pipe_debug_message(debug, SHADER_INFO,
+                                                          "%.*s", count, line);
+                               }
+
+                               if (!*p)
+                                       break;
+                               line = p + 1;
+                       }
+
+                       pipe_debug_message(debug, SHADER_INFO,
+                                          "Shader Disassembly End");
+               }
+       } else {
+               fprintf(stderr, "SI CODE:\n");
+               for (i = 0; i < binary->code_size; i += 4) {
+                       fprintf(stderr, "@0x%x: %02x%02x%02x%02x\n", i,
+                               binary->code[i + 3], binary->code[i + 2],
+                               binary->code[i + 1], binary->code[i]);
+               }
+       }
+}
+
 int si_shader_binary_read(struct si_screen *sscreen, struct si_shader *shader,
                          struct pipe_debug_callback *debug)
 {
        const struct radeon_shader_binary *binary = &shader->binary;
-       unsigned i;
        int r;
        bool dump  = r600_can_dump_shader(&sscreen->b,
                shader->selector ? shader->selector->tokens : NULL);
@@ -3855,19 +3901,8 @@ int si_shader_binary_read(struct si_screen *sscreen, struct si_shader *shader,
                return r;
 
        if (dump) {
-               if (!(sscreen->b.debug_flags & DBG_NO_ASM)) {
-                       if (binary->disasm_string) {
-                               fprintf(stderr, "\nShader Disassembly:\n\n");
-                               fprintf(stderr, "%s\n", binary->disasm_string);
-                       } else {
-                               fprintf(stderr, "SI CODE:\n");
-                               for (i = 0; i < binary->code_size; i+=4 ) {
-                                       fprintf(stderr, "@0x%x: %02x%02x%02x%02x\n", i, binary->code[i + 3],
-                                       binary->code[i + 2], binary->code[i + 1],
-                                       binary->code[i]);
-                               }
-                       }
-               }
+               if (!(sscreen->b.debug_flags & DBG_NO_ASM))
+                       si_shader_dump_disassembly(binary, debug);
 
                fprintf(stderr, "*** SHADER STATS ***\n"
                        "SGPRS: %d\nVGPRS: %d\nCode Size: %d bytes\nLDS: %d blocks\n"
@@ -3875,6 +3910,12 @@ int si_shader_binary_read(struct si_screen *sscreen, struct si_shader *shader,
                        shader->num_sgprs, shader->num_vgprs, binary->code_size,
                        shader->lds_size, shader->scratch_bytes_per_wave);
        }
+
+       pipe_debug_message(debug, SHADER_INFO,
+                          "Shader Stats: SGPRS: %d VGPRS: %d Code Size: %d LDS: %d Scratch: %d",
+                          shader->num_sgprs, shader->num_vgprs, binary->code_size,
+                          shader->lds_size, shader->scratch_bytes_per_wave);
+
        return 0;
 }