radeonsi: generate unique shader name in si_get_nir_shader
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Fri, 29 Apr 2022 14:40:09 +0000 (16:40 +0200)
committerMarge Bot <emma+marge@anholt.net>
Tue, 3 May 2022 10:39:51 +0000 (10:39 +0000)
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@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16247>

src/gallium/drivers/radeonsi/si_shader.c

index 2a90a07..b45bc77 100644 (file)
@@ -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;
 }