diff options
author | Timothy Arceri <[email protected]> | 2019-01-17 17:16:29 +1100 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2019-01-19 13:12:25 +1100 |
commit | 6ca652faf368427e3e6d57ef5456f78203b8207e (patch) | |
tree | b13c969393f98398857d17201c296750e35687b0 /src/compiler/glsl | |
parent | c84ec70b3a72a3640a40e72689d72da8337e9801 (diff) |
glsl: be much more aggressive when skipping shader compilation
Currently we only add a cache key for a shader once it is linked.
However games like Team Fortress 2 compile a whole bunch of shaders
which are never actually linked. These compiled shaders can take
up a bunch of memory.
This patch changes things so that we add the key for the shader to
the cache as soon as it is compiled. This means on a warm cache we
can avoid the wasted memory from these shaders. Worst case scenario
is we need to compile the shaders at link time but this can happen
anyway if the shader has been evicted from the cache.
Reduces memory use in Team Fortress 2 from 1.3GB -> 770MB on a
warm cache from start up to the game menu.
V2: only add key to cache when compilation is successful.
Acked-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/compiler/glsl')
-rw-r--r-- | src/compiler/glsl/glsl_parser_extras.cpp | 9 | ||||
-rw-r--r-- | src/compiler/glsl/shader_cache.cpp | 7 |
2 files changed, 10 insertions, 6 deletions
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp index 200df7759bb..bde93dd3f37 100644 --- a/src/compiler/glsl/glsl_parser_extras.cpp +++ b/src/compiler/glsl/glsl_parser_extras.cpp @@ -2155,6 +2155,15 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader, delete state->symbols; ralloc_free(state); + + if (ctx->Cache && shader->CompileStatus == COMPILE_SUCCESS) { + char sha1_buf[41]; + disk_cache_put_key(ctx->Cache, shader->sha1); + if (ctx->_Shader->Flags & GLSL_CACHE_INFO) { + _mesa_sha1_format(sha1_buf, shader->sha1); + fprintf(stderr, "marking shader: %s\n", sha1_buf); + } + } } } /* extern "C" */ diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp index 879511a9d7c..581098b88f0 100644 --- a/src/compiler/glsl/shader_cache.cpp +++ b/src/compiler/glsl/shader_cache.cpp @@ -121,20 +121,15 @@ shader_cache_write_program_metadata(struct gl_context *ctx, if (!cache_item_metadata.keys) goto fail; - char sha1_buf[41]; for (unsigned i = 0; i < prog->NumShaders; i++) { - disk_cache_put_key(cache, prog->Shaders[i]->sha1); memcpy(cache_item_metadata.keys[i], prog->Shaders[i]->sha1, sizeof(cache_key)); - if (ctx->_Shader->Flags & GLSL_CACHE_INFO) { - _mesa_sha1_format(sha1_buf, prog->Shaders[i]->sha1); - fprintf(stderr, "marking shader: %s\n", sha1_buf); - } } disk_cache_put(cache, prog->data->sha1, metadata.data, metadata.size, &cache_item_metadata); + char sha1_buf[41]; if (ctx->_Shader->Flags & GLSL_CACHE_INFO) { _mesa_sha1_format(sha1_buf, prog->data->sha1); fprintf(stderr, "putting program metadata in cache: %s\n", sha1_buf); |