On 27/03/17 03:30, Grazvydas Ignotas wrote:
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 <[email protected]>
---
 src/compiler/glsl/shader_cache.cpp       | 3 ++-
 src/mesa/state_tracker/st_shader_cache.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/compiler/glsl/shader_cache.cpp 
b/src/compiler/glsl/shader_cache.cpp
index 274bb8c..ea1bc01 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -1219,11 +1219,12 @@ shader_cache_write_program_metadata(struct gl_context 
*ctx,
     * generate a source from.
     *
     * 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};

I don't think this will compile on Windows. Just hard-code these to 20, if you are really concerned you could use CACHE_KEY_SIZE instead.

Otherwise nice catch.

Reviewed-by: Timothy Arceri <[email protected]>

+   if (memcmp(prog->data->sha1, zero, sizeof(prog->data->sha1)) == 0)
       return;

    struct blob *metadata = blob_create();

    write_uniforms(metadata, prog);
diff --git a/src/mesa/state_tracker/st_shader_cache.c 
b/src/mesa/state_tracker/st_shader_cache.c
index 061b272..e8c7289 100644
--- a/src/mesa/state_tracker/st_shader_cache.c
+++ b/src/mesa/state_tracker/st_shader_cache.c
@@ -62,11 +62,12 @@ st_store_tgsi_in_disk_cache(struct st_context *st, struct 
gl_program *prog,
       return;

    /* 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;
    struct blob *blob = blob_create();


_______________________________________________
mesa-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to