Mesa (main): nir: add shader_info::source_sha1, its initialization and printing

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Nov 26 13:07:22 UTC 2021


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

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Thu Nov 18 09:28:17 2021 -0500

nir: add shader_info::source_sha1, its initialization and printing

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13869>

---

 src/compiler/nir/nir_print.c              | 5 +++++
 src/compiler/shader_info.h                | 4 ++++
 src/mesa/state_tracker/st_glsl_to_nir.cpp | 2 ++
 3 files changed, 11 insertions(+)

diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c
index 83f471b27f6..1d078d78a09 100644
--- a/src/compiler/nir/nir_print.c
+++ b/src/compiler/nir/nir_print.c
@@ -29,6 +29,7 @@
 #include "compiler/shader_enums.h"
 #include "util/half_float.h"
 #include "util/memstream.h"
+#include "util/mesa-sha1.h"
 #include "vulkan/vulkan_core.h"
 #include <stdio.h>
 #include <stdlib.h>
@@ -1604,6 +1605,10 @@ nir_print_shader_annotated(nir_shader *shader, FILE *fp,
 
    fprintf(fp, "shader: %s\n", gl_shader_stage_name(shader->info.stage));
 
+   fprintf(fp, "source_sha1: {");
+   _mesa_sha1_print(fp, shader->info.source_sha1);
+   fprintf(fp, "}\n");
+
    if (shader->info.name)
       fprintf(fp, "name: %s\n", shader->info.name);
 
diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h
index 405b2042288..9f517f45728 100644
--- a/src/compiler/shader_info.h
+++ b/src/compiler/shader_info.h
@@ -26,6 +26,7 @@
 #define SHADER_INFO_H
 
 #include "util/bitset.h"
+#include "util/sha1/sha1.h"
 #include "shader_enums.h"
 #include <stdint.h>
 
@@ -125,6 +126,9 @@ typedef struct shader_info {
    /* Shader is internal, and should be ignored by things like NIR_PRINT */
    bool internal;
 
+   /* SHA1 of the original source, used by shader detection in drivers. */
+   uint8_t source_sha1[SHA1_DIGEST_LENGTH];
+
    /** The shader stage, such as MESA_SHADER_VERTEX. */
    gl_shader_stage stage:8;
 
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index ae50af01400..4098a2ee07b 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -769,6 +769,8 @@ st_link_nir(struct gl_context *ctx,
          prog->nir = glsl_to_nir(st->ctx, shader_program, shader->Stage, options);
       }
 
+      memcpy(prog->nir->info.source_sha1, shader->linked_source_sha1,
+             SHA1_DIGEST_LENGTH);
       st_nir_preprocess(st, prog, shader_program, shader->Stage);
 
       if (options->lower_to_scalar) {



More information about the mesa-commit mailing list