From: Nicolai Hähnle <nicolai.haeh...@amd.com>

Help identify bugs related to corruption of shaders in memory,
or errors in shader upload / rtld.
---
 src/gallium/drivers/radeonsi/si_debug.c        | 18 ++++++++++++++++++
 .../drivers/radeonsi/si_debug_options.h        |  1 +
 2 files changed, 19 insertions(+)

diff --git a/src/gallium/drivers/radeonsi/si_debug.c 
b/src/gallium/drivers/radeonsi/si_debug.c
index 9a4494a98fe..c40dcd0b5d6 100644
--- a/src/gallium/drivers/radeonsi/si_debug.c
+++ b/src/gallium/drivers/radeonsi/si_debug.c
@@ -98,20 +98,38 @@ void si_destroy_saved_cs(struct si_saved_cs *scs)
 }
 
 static void si_dump_shader(struct si_screen *sscreen,
                           enum pipe_shader_type processor,
                           const struct si_shader *shader, FILE *f)
 {
        if (shader->shader_log)
                fwrite(shader->shader_log, shader->shader_log_size, 1, f);
        else
                si_shader_dump(sscreen, shader, NULL, processor, f, false);
+
+       if (shader->bo && sscreen->options.dump_shader_binary) {
+               unsigned size = shader->bo->b.b.width0;
+               fprintf(f, "BO: VA=%"PRIx64" Size=%u\n", 
shader->bo->gpu_address, size);
+
+               const char *mapped = sscreen->ws->buffer_map(shader->bo->buf, 
NULL,
+                                                      
PIPE_TRANSFER_UNSYNCHRONIZED |
+                                                      PIPE_TRANSFER_READ |
+                                                      
RADEON_TRANSFER_TEMPORARY);
+
+               for (unsigned i = 0; i < size; i += 4) {
+                       fprintf(f, " %4x: %08x\n", i, *(uint32_t*)(mapped + i));
+               }
+
+               sscreen->ws->buffer_unmap(shader->bo->buf);
+
+               fprintf(f, "\n");
+       }
 }
 
 struct si_log_chunk_shader {
        /* The shader destroy code assumes a current context for unlinking of
         * PM4 packets etc.
         *
         * While we should be able to destroy shaders without a context, doing
         * so would happen only very rarely and be therefore likely to fail
         * just when you're trying to debug something. Let's just remember the
         * current context in the chunk.
diff --git a/src/gallium/drivers/radeonsi/si_debug_options.h 
b/src/gallium/drivers/radeonsi/si_debug_options.h
index 0bde7910fc6..db642366ca6 100644
--- a/src/gallium/drivers/radeonsi/si_debug_options.h
+++ b/src/gallium/drivers/radeonsi/si_debug_options.h
@@ -1,7 +1,8 @@
 OPT_BOOL(clear_db_cache_before_clear, false, "Clear DB cache before fast depth 
clear")
 OPT_BOOL(enable_nir, false, "Enable NIR")
 OPT_BOOL(aux_debug, false, "Generate ddebug_dumps for the auxiliary context")
 OPT_BOOL(sync_compile, false, "Always compile synchronously (will cause 
stalls)")
+OPT_BOOL(dump_shader_binary, false, "Dump shader binary as part of 
ddebug_dumps")
 OPT_BOOL(vs_fetch_always_opencode, false, "Always open code vertex fetches 
(less efficient, purely for testing)")
 
 #undef OPT_BOOL
-- 
2.20.1

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to