Mesa (main): radeonsi: generate unique shader name in si_get_nir_shader

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue May 3 11:04:00 UTC 2022


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

Author: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Date:   Fri Apr 29 16:40:09 2022 +0200

radeonsi: generate unique shader name in si_get_nir_shader

This function modifies the NIR shader, so when using NIR_DEBUG=print and
nir_viewer all the variants are displayed using the original name.

With this change, we get the original shader (eg: GLSL3), and then each
variant gets its own name (GLSL3-xxxxxxxx) - and is displayed in its
own tab in nir_viewer.

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

---

 src/gallium/drivers/radeonsi/si_shader.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index 2a90a07f214..b45bc77522a 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -28,6 +28,7 @@
 #include "nir_builder.h"
 #include "nir_serialize.h"
 #include "nir/nir_helpers.h"
+#include "ralloc.h"
 #include "si_pipe.h"
 #include "si_shader_internal.h"
 #include "sid.h"
@@ -1480,6 +1481,17 @@ struct nir_shader *si_get_nir_shader(struct si_shader_selector *sel,
 
    bool progress = false;
 
+   const char *original_name = NULL;
+   if (unlikely(should_print_nir(nir))) {
+      /* Modify the shader's name so that each variant gets its own name. */
+      original_name = ralloc_strdup(nir, nir->info.name);
+      ralloc_asprintf_append((char **)&nir->info.name, "-%08x", _mesa_hash_data(key, sizeof(*key)));
+
+      /* Dummy pass to get the starting point. */
+      printf("nir_dummy_pass\n");
+      nir_print_shader(nir, stdout);
+   }
+
    /* Kill outputs according to the shader key. */
    if (sel->stage <= MESA_SHADER_GEOMETRY)
       NIR_PASS(progress, nir, si_nir_kill_outputs, key);
@@ -1568,6 +1580,11 @@ struct nir_shader *si_get_nir_shader(struct si_shader_selector *sel,
     */
    NIR_PASS_V(nir, nir_group_loads, nir_group_same_resource_only, 200);
 
+   if (unlikely(original_name)) {
+      ralloc_free((void*)nir->info.name);
+      nir->info.name = original_name;
+   }
+
    return nir;
 }
 



More information about the mesa-commit mailing list