[Mesa-dev] [PATCH 25/32] st/mesa/glsl: build string of dri options and use as input to building sha for shaders

Timothy Arceri tarceri at itsqueeze.com
Tue Feb 14 00:52:38 UTC 2017


---
 src/compiler/glsl/shader_cache.cpp          |  6 ++++
 src/gallium/include/state_tracker/st_api.h  |  1 +
 src/gallium/state_trackers/dri/dri_screen.c |  2 ++
 src/mesa/drivers/dri/common/xmlconfig.h     | 52 +++++++++++++++++++++++++++++
 src/mesa/main/mtypes.h                      |  3 ++
 src/mesa/state_tracker/st_extensions.c      |  2 ++
 6 files changed, 66 insertions(+)

diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index 30e652f..8f97564 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -1318,7 +1318,13 @@ shader_cache_read_program_metadata(struct gl_context *ctx,
                           ctx->API, ctx->Const.GLSLVersion,
                           ctx->Const.ForceGLSLVersion);
 
+   /* DRI config options may also change the output from the compiler so
+    * include them as an input to sha1 creation.
+    */
    char sha1buf[41];
+   _mesa_sha1_format(sha1buf, ctx->Const.dri_config_options_sha1);
+   ralloc_strcat(&buf, sha1buf);
+
    for (unsigned i = 0; i < prog->NumShaders; i++) {
       struct gl_shader *sh = prog->Shaders[i];
       ralloc_asprintf_append(&buf, "%s: %s\n",
diff --git a/src/gallium/include/state_tracker/st_api.h b/src/gallium/include/state_tracker/st_api.h
index a2e37d2..872bdb6 100644
--- a/src/gallium/include/state_tracker/st_api.h
+++ b/src/gallium/include/state_tracker/st_api.h
@@ -246,6 +246,7 @@ struct st_config_options
    boolean force_s3tc_enable;
    boolean allow_glsl_extension_directive_midshader;
    boolean glsl_zero_init;
+   unsigned char config_options_sha1[20];
 };
 
 /**
diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c
index a950f52..9de970c 100644
--- a/src/gallium/state_trackers/dri/dri_screen.c
+++ b/src/gallium/state_trackers/dri/dri_screen.c
@@ -100,6 +100,8 @@ dri_fill_st_options(struct st_config_options *options,
    options->allow_glsl_extension_directive_midshader =
       driQueryOptionb(optionCache, "allow_glsl_extension_directive_midshader");
    options->glsl_zero_init = driQueryOptionb(optionCache, "glsl_zero_init");
+
+   driComputeOptionsSha1(optionCache, options->config_options_sha1);
 }
 
 static const __DRIconfig **
diff --git a/src/mesa/drivers/dri/common/xmlconfig.h b/src/mesa/drivers/dri/common/xmlconfig.h
index 8969843..4aa09e8 100644
--- a/src/mesa/drivers/dri/common/xmlconfig.h
+++ b/src/mesa/drivers/dri/common/xmlconfig.h
@@ -30,6 +30,9 @@
 #ifndef __XMLCONFIG_H
 #define __XMLCONFIG_H
 
+#include "util/mesa-sha1.h"
+#include "util/ralloc.h"
+
 #define STRING_CONF_MAXLEN 25
 
 /** \brief Option data types */
@@ -124,4 +127,53 @@ float driQueryOptionf (const driOptionCache *cache, const char *name);
 /** \brief Query a string option value */
 char *driQueryOptionstr (const driOptionCache *cache, const char *name);
 
+/**
+ * Returns a concatenated string of the options for this application.
+ */
+static inline void
+driComputeOptionsSha1(const driOptionCache *cache, unsigned char *sha1)
+{
+   void *ctx = ralloc_context(NULL);
+   char *dri_options = ralloc_strdup(ctx, "");
+
+   for (unsigned i = 0; i < 1 << cache->tableSize; i++) {
+      if (cache->info[i].name == NULL)
+         continue;
+
+      bool ret = false;
+      switch (cache->info[i].type) {
+      case DRI_BOOL:
+         ret = ralloc_asprintf_append(&dri_options, "%s:%u,",
+                                      cache->info[i].name,
+                                      cache->values[i]._bool);
+         break;
+      case DRI_INT:
+      case DRI_ENUM:
+         ret = ralloc_asprintf_append(&dri_options, "%s:%d,",
+                                      cache->info[i].name,
+                                      cache->values[i]._int);
+         break;
+      case DRI_FLOAT:
+         ret = ralloc_asprintf_append(&dri_options, "%s:%f,",
+                                      cache->info[i].name,
+                                      cache->values[i]._float);
+         break;
+      case DRI_STRING:
+         ret = ralloc_asprintf_append(&dri_options, "%s:%s,",
+                                      cache->info[i].name,
+                                      cache->values[i]._string);
+         break;
+      default:
+         unreachable("unsupported dri config type!");
+      }
+
+      if (!ret) {
+         break;
+      }
+   }
+
+   _mesa_sha1_compute(dri_options, strlen(dri_options), sha1);
+   ralloc_free(ctx);
+}
+
 #endif
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index c51e8ec..15df3cc 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3764,6 +3764,9 @@ struct gl_constants
 
    /** GL_OES_primitive_bounding_box */
    bool NoPrimitiveBoundingBoxOutput;
+
+   /** Used as an input for sha1 generation in the on-disk shader cache */
+   unsigned char *dri_config_options_sha1;
 };
 
 
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index 293814e..b1f3077 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -879,6 +879,8 @@ void st_init_extensions(struct pipe_screen *screen,
       consts->ForceGLSLVersion = options->force_glsl_version;
    }
 
+   consts->dri_config_options_sha1 = options->config_options_sha1;
+
    if (consts->GLSLVersion >= 400)
       extensions->ARB_gpu_shader5 = GL_TRUE;
    if (consts->GLSLVersion >= 410)
-- 
2.9.3



More information about the mesa-dev mailing list