[Mesa-dev] [PATCH 56/68] i965: move binary sha1 gen into its own helper

Timothy Arceri timothy.arceri at collabora.com
Wed Jun 1 06:23:37 UTC 2016


And call it from write cache as its possible that read cache hasn't
been called at this point or the current sha is the wrong one so we
need to make sure a fresh sha is generated before writting.
---
 src/mesa/drivers/dri/i965/brw_shader_cache.c | 54 ++++++++++++++++++----------
 1 file changed, 35 insertions(+), 19 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_shader_cache.c b/src/mesa/drivers/dri/i965/brw_shader_cache.c
index 9104057..07f3a64 100644
--- a/src/mesa/drivers/dri/i965/brw_shader_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_shader_cache.c
@@ -38,6 +38,35 @@
 #include "brw_vs.h"
 #include "brw_context.h"
 
+static void
+gen_binary_sha1(struct brw_context *brw, struct gl_shader_program *prog,
+                struct brw_vs_prog_key *vs_key,
+                struct brw_wm_prog_key *wm_key)
+{
+   char sha1_buf[41];
+   unsigned char sha1[20];
+   char manifest[256];
+   int offset = 0;
+
+   offset += snprintf(manifest + offset, sizeof(manifest) - offset,
+                      "program: %s\n", _mesa_sha1_format(sha1_buf, prog->sha1));
+
+   brw_vs_populate_key(brw, vs_key);
+   vs_key->program_string_id = 0;
+   _mesa_sha1_compute(vs_key, sizeof *vs_key, sha1);
+   offset += snprintf(manifest + offset, sizeof(manifest) - offset,
+                      "vs_key: %s\n", _mesa_sha1_format(sha1_buf, sha1));
+
+   brw_wm_populate_key(brw, wm_key);
+   wm_key->program_string_id = 0;
+   _mesa_sha1_compute(wm_key, sizeof *wm_key, sha1);
+   offset += snprintf(manifest + offset, sizeof(manifest) - offset,
+                      "wm_key: %s\n", _mesa_sha1_format(sha1_buf, sha1));
+
+   _mesa_sha1_compute(manifest, strlen(manifest), brw->binary_sha1);
+
+}
+
 void
 upload_cached_program(struct brw_context *brw)
 {
@@ -48,9 +77,7 @@ upload_cached_program(struct brw_context *brw)
    struct gl_shader_program *prog;
    struct brw_wm_prog_key wm_key;
    struct brw_vs_prog_key vs_key;
-   unsigned char sha1[20];
-   char manifest[256];
-   int i, offset = 0;
+   int i;
    struct program_cache *cache;
    uint8_t *vs_program, *wm_program;
    size_t vs_program_size, wm_program_size;
@@ -79,22 +106,7 @@ upload_cached_program(struct brw_context *brw)
    if (prog->TransformFeedback.NumVarying > 0)
       return;
 
-   offset += snprintf(manifest + offset, sizeof(manifest) - offset,
-                      "program: %s\n", _mesa_sha1_format(sha1_buf, prog->sha1));
-
-   brw_wm_populate_key(brw, &wm_key);
-   wm_key.program_string_id = 0;
-   _mesa_sha1_compute(&wm_key, sizeof wm_key, sha1);
-   offset += snprintf(manifest + offset, sizeof(manifest) - offset,
-                      "wm_key: %s\n", _mesa_sha1_format(sha1_buf, sha1));
-
-   brw_vs_populate_key(brw, &vs_key);
-   vs_key.program_string_id = 0;
-   _mesa_sha1_compute(&vs_key, sizeof vs_key, sha1);
-   offset += snprintf(manifest + offset, sizeof(manifest) - offset,
-                      "vs_key: %s\n", _mesa_sha1_format(sha1_buf, sha1));
-
-   _mesa_sha1_compute(manifest, strlen(manifest), brw->binary_sha1);
+   gen_binary_sha1(brw, prog, &vs_key, &wm_key);
 
    buffer = cache_get(cache, brw->binary_sha1, &size);
    if (buffer == NULL)
@@ -407,6 +419,10 @@ write_cached_program(struct brw_context *brw)
    if (binary == NULL)
       return;
 
+   struct brw_vs_prog_key vs_key;
+   struct brw_wm_prog_key wm_key;
+   gen_binary_sha1(brw, prog, &vs_key, &wm_key);
+
    /* Write VS program to blob. */
    vs_program_size = brw->vs.prog_data->program_size;
 
-- 
2.5.5



More information about the mesa-dev mailing list