Patch moves existing functionality from shader_cache_read_program_metadata to a helper function.
Signed-off-by: Tapani Pälli <tapani.pa...@intel.com> --- src/compiler/Makefile.sources | 1 + src/compiler/glsl/meson.build | 1 + src/compiler/glsl/program.cpp | 88 ++++++++++++++++++++++++++++++++++++++ src/compiler/glsl/program.h | 12 ++++-- src/compiler/glsl/shader_cache.cpp | 55 +----------------------- 5 files changed, 100 insertions(+), 57 deletions(-) create mode 100644 src/compiler/glsl/program.cpp diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources index d3f746f5f9..e3dfacf98c 100644 --- a/src/compiler/Makefile.sources +++ b/src/compiler/Makefile.sources @@ -136,6 +136,7 @@ LIBGLSL_FILES = \ glsl/opt_swizzle.cpp \ glsl/opt_tree_grafting.cpp \ glsl/opt_vectorize.cpp \ + glsl/program.cpp \ glsl/program.h \ glsl/propagate_invariance.cpp \ glsl/s_expression.cpp \ diff --git a/src/compiler/glsl/meson.build b/src/compiler/glsl/meson.build index 6aaa9bab05..5d8d8d4530 100644 --- a/src/compiler/glsl/meson.build +++ b/src/compiler/glsl/meson.build @@ -175,6 +175,7 @@ files_libglsl = files( 'opt_swizzle.cpp', 'opt_tree_grafting.cpp', 'opt_vectorize.cpp', + 'program.cpp', 'program.h', 'propagate_invariance.cpp', 's_expression.cpp', diff --git a/src/compiler/glsl/program.cpp b/src/compiler/glsl/program.cpp new file mode 100644 index 0000000000..df7124485d --- /dev/null +++ b/src/compiler/glsl/program.cpp @@ -0,0 +1,88 @@ +/* + * Copyright © 2018 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "main/mtypes.h" +#include "util/mesa-sha1.h" +#include "string_to_uint_map.h" +#include "program.h" + +static void +create_binding_str(const char *key, unsigned value, void *closure) +{ + char **bindings_str = (char **) closure; + ralloc_asprintf_append(bindings_str, "%s:%u,", key, value); +} + +extern "C" char * +create_shader_program_keystr(struct gl_context *ctx, + struct gl_shader_program *prog) +{ + /* Include bindings when creating sha1. These bindings change the resulting + * binary so they are just as important as the shader source. + */ + char *buf = ralloc_strdup(NULL, "vb: "); + prog->AttributeBindings->iterate(create_binding_str, &buf); + ralloc_strcat(&buf, "fb: "); + prog->FragDataBindings->iterate(create_binding_str, &buf); + ralloc_strcat(&buf, "fbi: "); + prog->FragDataIndexBindings->iterate(create_binding_str, &buf); + + /* SSO has an effect on the linked program so include this when generating + * the sha also. + */ + ralloc_asprintf_append(&buf, "sso: %s\n", + prog->SeparateShader ? "T" : "F"); + + /* A shader might end up producing different output depending on the glsl + * version supported by the compiler. For example a different path might be + * taken by the preprocessor, so add the version to the hash input. + */ + ralloc_asprintf_append(&buf, "api: %d glsl: %d fglsl: %d\n", + ctx->API, ctx->Const.GLSLVersion, + ctx->Const.ForceGLSLVersion); + + /* We run the preprocessor on shaders after hashing them, so we need to + * add any extension override vars to the hash. If we don't do this the + * preprocessor could result in different output and we could load the + * wrong shader. + */ + char *ext_override = getenv("MESA_EXTENSION_OVERRIDE"); + if (ext_override) { + ralloc_asprintf_append(&buf, "ext:%s", ext_override); + } + /* DRI config options may also change the output from the compiler so + * include them as an input to sha1 creation. + */ + char sha1buf[41]; + _mesa_sha1_format(sha1buf, ctx->Const.dri_config_options_sha1); + ralloc_strcat(&buf, sha1buf); + + for (unsigned i = 0; i < prog->NumShaders; i++) { + struct gl_shader *sh = prog->Shaders[i]; + _mesa_sha1_format(sha1buf, sh->sha1); + ralloc_asprintf_append(&buf, "%s: %s\n", + _mesa_shader_stage_to_abbrev(sh->Stage), sha1buf); + } + + return buf; +} diff --git a/src/compiler/glsl/program.h b/src/compiler/glsl/program.h index 480379b10b..ae349113e0 100644 --- a/src/compiler/glsl/program.h +++ b/src/compiler/glsl/program.h @@ -25,18 +25,22 @@ #ifndef GLSL_PROGRAM_H #define GLSL_PROGRAM_H -#ifdef __cplusplus -extern "C" { -#endif - struct gl_context; struct gl_shader; struct gl_shader_program; +#ifdef __cplusplus +extern "C" { +#endif + extern void _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader, bool dump_ast, bool dump_hir, bool force_recompile); +char * +create_shader_program_keystr(struct gl_context *ctx, + struct gl_shader_program *prog); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp index 5e1682b351..58c27803d3 100644 --- a/src/compiler/glsl/shader_cache.cpp +++ b/src/compiler/glsl/shader_cache.cpp @@ -74,13 +74,6 @@ compile_shaders(struct gl_context *ctx, struct gl_shader_program *prog) { } } -static void -create_binding_str(const char *key, unsigned value, void *closure) -{ - char **bindings_str = (char **) closure; - ralloc_asprintf_append(bindings_str, "%s:%u,", key, value); -} - void shader_cache_write_program_metadata(struct gl_context *ctx, struct gl_shader_program *prog) @@ -151,53 +144,8 @@ shader_cache_read_program_metadata(struct gl_context *ctx, if (!cache) return false; - /* Include bindings when creating sha1. These bindings change the resulting - * binary so they are just as important as the shader source. - */ - char *buf = ralloc_strdup(NULL, "vb: "); - prog->AttributeBindings->iterate(create_binding_str, &buf); - ralloc_strcat(&buf, "fb: "); - prog->FragDataBindings->iterate(create_binding_str, &buf); - ralloc_strcat(&buf, "fbi: "); - prog->FragDataIndexBindings->iterate(create_binding_str, &buf); - - /* SSO has an effect on the linked program so include this when generating - * the sha also. - */ - ralloc_asprintf_append(&buf, "sso: %s\n", - prog->SeparateShader ? "T" : "F"); - - /* A shader might end up producing different output depending on the glsl - * version supported by the compiler. For example a different path might be - * taken by the preprocessor, so add the version to the hash input. - */ - ralloc_asprintf_append(&buf, "api: %d glsl: %d fglsl: %d\n", - ctx->API, ctx->Const.GLSLVersion, - ctx->Const.ForceGLSLVersion); - - /* We run the preprocessor on shaders after hashing them, so we need to - * add any extension override vars to the hash. If we don't do this the - * preprocessor could result in different output and we could load the - * wrong shader. - */ - char *ext_override = getenv("MESA_EXTENSION_OVERRIDE"); - if (ext_override) { - ralloc_asprintf_append(&buf, "ext:%s", ext_override); - } + char *buf = create_shader_program_keystr(ctx, prog); - /* DRI config options may also change the output from the compiler so - * include them as an input to sha1 creation. - */ - char sha1buf[41]; - _mesa_sha1_format(sha1buf, ctx->Const.dri_config_options_sha1); - ralloc_strcat(&buf, sha1buf); - - for (unsigned i = 0; i < prog->NumShaders; i++) { - struct gl_shader *sh = prog->Shaders[i]; - _mesa_sha1_format(sha1buf, sh->sha1); - ralloc_asprintf_append(&buf, "%s: %s\n", - _mesa_shader_stage_to_abbrev(sh->Stage), sha1buf); - } disk_cache_compute_key(cache, buf, strlen(buf), prog->data->sha1); ralloc_free(buf); @@ -220,6 +168,7 @@ shader_cache_read_program_metadata(struct gl_context *ctx, } if (ctx->_Shader->Flags & GLSL_CACHE_INFO) { + char sha1buf[41]; _mesa_sha1_format(sha1buf, prog->data->sha1); fprintf(stderr, "loading shader program meta data from cache: %s\n", sha1buf); -- 2.14.3 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev