diff options
author | Timothy Arceri <[email protected]> | 2017-01-24 08:39:13 +1100 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2017-02-17 11:18:42 +1100 |
commit | 877194068208a9fb87f7b5513bca85d09be8a20f (patch) | |
tree | bddab5b55b75f3552e710ac6a8604e18ad5709d3 /src/compiler/glsl/glsl_parser_extras.cpp | |
parent | 34ca0fce228224121d1a3b111c38325e731bace3 (diff) |
glsl: make use of on disk shader cache
The hash key for glsl metadata is a hash of the hashes of each GLSL
source string.
This commit uses the put_key/get_key support in the cache put the SHA-1
hash of the source string for each successfully compiled shader into the
cache. This allows for early, optimistic returns from glCompileShader
(if the identical source string had been successfully compiled in the past),
in the hope that the final, linked shader will be found in the cache.
This is based on the intial patch by Carl.
Reviewed-by: Nicolai Hähnle <[email protected]>
Diffstat (limited to 'src/compiler/glsl/glsl_parser_extras.cpp')
-rw-r--r-- | src/compiler/glsl/glsl_parser_extras.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp index f6a9c9a051d..833b5fefa18 100644 --- a/src/compiler/glsl/glsl_parser_extras.cpp +++ b/src/compiler/glsl/glsl_parser_extras.cpp @@ -33,6 +33,8 @@ #include "main/shaderobj.h" #include "util/u_atomic.h" /* for p_atomic_cmpxchg */ #include "util/ralloc.h" +#include "util/disk_cache.h" +#include "util/mesa-sha1.h" #include "ast.h" #include "glsl_parser_extras.h" #include "glsl_parser.h" @@ -1934,6 +1936,20 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader, state->error = glcpp_preprocess(state, &source, &state->info_log, add_builtin_defines, state, ctx); + if (!force_recompile) { + char buf[41]; + _mesa_sha1_compute(source, strlen(source), shader->sha1); + if (ctx->Cache && disk_cache_has_key(ctx->Cache, shader->sha1)) { + /* We've seen this shader before and know it compiles */ + if (ctx->_Shader->Flags & GLSL_CACHE_INFO) { + fprintf(stderr, "deferring compile of shader: %s\n", + _mesa_sha1_format(buf, shader->sha1)); + } + shader->CompileStatus = true; + return; + } + } + if (!state->error) { _mesa_glsl_lexer_ctor(state, source); _mesa_glsl_parse(state); |