OSDN Git Service

glsl, st/shader_cache: check the whole sha1 for zero
authorGrazvydas Ignotas <notasas@gmail.com>
Sun, 26 Mar 2017 16:30:23 +0000 (19:30 +0300)
committerTimothy Arceri <tarceri@itsqueeze.com>
Mon, 27 Mar 2017 04:05:10 +0000 (15:05 +1100)
The checks were only looking at the first byte, while the intention
seems to be to check if the whole sha1 is zero. This prevented all
shaders with first byte zero in their sha1 from being saved.

This shaves around a second from Deus Ex load time on a hot cache.

Signed-off-by: Grazvydas Ignotas <notasas@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Edward O'Callaghan <funfunctor@folklore1984.net>
src/compiler/glsl/shader_cache.cpp
src/mesa/state_tracker/st_shader_cache.c

index 274bb8c..ea1bc01 100644 (file)
@@ -1221,7 +1221,8 @@ shader_cache_write_program_metadata(struct gl_context *ctx,
     * TODO: In future we should use another method to generate a key for ff
     * programs.
     */
-   if (*prog->data->sha1 == 0)
+   static const char zero[sizeof(prog->data->sha1)] = {0};
+   if (memcmp(prog->data->sha1, zero, sizeof(prog->data->sha1)) == 0)
       return;
 
    struct blob *metadata = blob_create();
index 061b272..e8c7289 100644 (file)
@@ -64,7 +64,8 @@ st_store_tgsi_in_disk_cache(struct st_context *st, struct gl_program *prog,
    /* Exit early when we are dealing with a ff shader with no source file to
     * generate a source from.
     */
-   if (*prog->sh.data->sha1 == 0)
+   static const char zero[sizeof(prog->sh.data->sha1)] = {0};
+   if (memcmp(prog->sh.data->sha1, zero, sizeof(prog->sh.data->sha1)) == 0)
       return;
 
    unsigned char *sha1;