mesa: add shader source SHA1s that are propagated up to glCompileShader
glCompileShader can use two different sources, so we need 2 different SHA1s there. Successful compilation sets compiled_source_sha1. Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13869>
This commit is contained in:
@@ -2146,8 +2146,9 @@ opt_shader_and_create_symbol_table(struct gl_context *ctx,
|
|||||||
|
|
||||||
static bool
|
static bool
|
||||||
can_skip_compile(struct gl_context *ctx, struct gl_shader *shader,
|
can_skip_compile(struct gl_context *ctx, struct gl_shader *shader,
|
||||||
const char *source, bool force_recompile,
|
const char *source,
|
||||||
bool source_has_shader_include)
|
const uint8_t source_sha1[SHA1_DIGEST_LENGTH],
|
||||||
|
bool force_recompile, bool source_has_shader_include)
|
||||||
{
|
{
|
||||||
if (!force_recompile) {
|
if (!force_recompile) {
|
||||||
if (ctx->Cache) {
|
if (ctx->Cache) {
|
||||||
@@ -2168,8 +2169,15 @@ can_skip_compile(struct gl_context *ctx, struct gl_shader *shader,
|
|||||||
* we have no guarantee the shader include source tree has not
|
* we have no guarantee the shader include source tree has not
|
||||||
* changed.
|
* changed.
|
||||||
*/
|
*/
|
||||||
shader->FallbackSource = source_has_shader_include ?
|
if (source_has_shader_include) {
|
||||||
strdup(source) : NULL;
|
shader->FallbackSource = strdup(source);
|
||||||
|
memcpy(shader->fallback_source_sha1, source_sha1,
|
||||||
|
SHA1_DIGEST_LENGTH);
|
||||||
|
} else {
|
||||||
|
shader->FallbackSource = NULL;
|
||||||
|
}
|
||||||
|
memcpy(shader->compiled_source_sha1, source_sha1,
|
||||||
|
SHA1_DIGEST_LENGTH);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2189,8 +2197,16 @@ void
|
|||||||
_mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
|
_mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
|
||||||
bool dump_ast, bool dump_hir, bool force_recompile)
|
bool dump_ast, bool dump_hir, bool force_recompile)
|
||||||
{
|
{
|
||||||
const char *source = force_recompile && shader->FallbackSource ?
|
const char *source;
|
||||||
shader->FallbackSource : shader->Source;
|
const uint8_t *source_sha1;
|
||||||
|
|
||||||
|
if (force_recompile && shader->FallbackSource) {
|
||||||
|
source = shader->FallbackSource;
|
||||||
|
source_sha1 = shader->fallback_source_sha1;
|
||||||
|
} else {
|
||||||
|
source = shader->Source;
|
||||||
|
source_sha1 = shader->source_sha1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Note this will be true for shaders the have #include inside comments
|
/* Note this will be true for shaders the have #include inside comments
|
||||||
* however that should be rare enough not to worry about.
|
* however that should be rare enough not to worry about.
|
||||||
@@ -2204,7 +2220,8 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
|
|||||||
* keep duplicate copies of the shader include source tree and paths.
|
* keep duplicate copies of the shader include source tree and paths.
|
||||||
*/
|
*/
|
||||||
if (!source_has_shader_include &&
|
if (!source_has_shader_include &&
|
||||||
can_skip_compile(ctx, shader, source, force_recompile, false))
|
can_skip_compile(ctx, shader, source, source_sha1, force_recompile,
|
||||||
|
false))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct _mesa_glsl_parse_state *state =
|
struct _mesa_glsl_parse_state *state =
|
||||||
@@ -2224,7 +2241,8 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
|
|||||||
* include.
|
* include.
|
||||||
*/
|
*/
|
||||||
if (source_has_shader_include &&
|
if (source_has_shader_include &&
|
||||||
can_skip_compile(ctx, shader, source, force_recompile, true))
|
can_skip_compile(ctx, shader, source, source_sha1, force_recompile,
|
||||||
|
true))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!state->error) {
|
if (!state->error) {
|
||||||
@@ -2286,14 +2304,20 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
|
|||||||
/* Copy pre-processed shader include to fallback source otherwise we
|
/* Copy pre-processed shader include to fallback source otherwise we
|
||||||
* have no guarantee the shader include source tree has not changed.
|
* have no guarantee the shader include source tree has not changed.
|
||||||
*/
|
*/
|
||||||
shader->FallbackSource = source_has_shader_include ?
|
if (source_has_shader_include) {
|
||||||
strdup(source) : NULL;
|
shader->FallbackSource = strdup(source);
|
||||||
|
memcpy(shader->fallback_source_sha1, source_sha1, SHA1_DIGEST_LENGTH);
|
||||||
|
} else {
|
||||||
|
shader->FallbackSource = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete state->symbols;
|
delete state->symbols;
|
||||||
ralloc_free(state);
|
ralloc_free(state);
|
||||||
|
|
||||||
if (ctx->Cache && shader->CompileStatus == COMPILE_SUCCESS) {
|
if (ctx->Cache && shader->CompileStatus == COMPILE_SUCCESS) {
|
||||||
|
memcpy(shader->compiled_source_sha1, source_sha1, SHA1_DIGEST_LENGTH);
|
||||||
|
|
||||||
char sha1_buf[41];
|
char sha1_buf[41];
|
||||||
disk_cache_put_key(ctx->Cache, shader->disk_cache_sha1);
|
disk_cache_put_key(ctx->Cache, shader->disk_cache_sha1);
|
||||||
if (ctx->_Shader->Flags & GLSL_CACHE_INFO) {
|
if (ctx->_Shader->Flags & GLSL_CACHE_INFO) {
|
||||||
|
@@ -2684,6 +2684,12 @@ struct gl_shader
|
|||||||
|
|
||||||
/** SHA1 of the pre-processed source used by the disk cache. */
|
/** SHA1 of the pre-processed source used by the disk cache. */
|
||||||
uint8_t disk_cache_sha1[SHA1_DIGEST_LENGTH];
|
uint8_t disk_cache_sha1[SHA1_DIGEST_LENGTH];
|
||||||
|
/** SHA1 of the original source before replacement, set by glShaderSource. */
|
||||||
|
uint8_t source_sha1[SHA1_DIGEST_LENGTH];
|
||||||
|
/** SHA1 of FallbackSource (a copy of some original source before replacement). */
|
||||||
|
uint8_t fallback_source_sha1[SHA1_DIGEST_LENGTH];
|
||||||
|
/** SHA1 of the current compiled source, set by successful glCompileShader. */
|
||||||
|
uint8_t compiled_source_sha1[SHA1_DIGEST_LENGTH];
|
||||||
|
|
||||||
const GLchar *Source; /**< Source code string */
|
const GLchar *Source; /**< Source code string */
|
||||||
const GLchar *FallbackSource; /**< Fallback string used by on-disk cache*/
|
const GLchar *FallbackSource; /**< Fallback string used by on-disk cache*/
|
||||||
|
@@ -1181,7 +1181,8 @@ get_shader_source(struct gl_context *ctx, GLuint shader, GLsizei maxLength,
|
|||||||
* glShaderSource[ARB].
|
* glShaderSource[ARB].
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
set_shader_source(struct gl_shader *sh, const GLchar *source)
|
set_shader_source(struct gl_shader *sh, const GLchar *source,
|
||||||
|
const uint8_t original_sha1[SHA1_DIGEST_LENGTH])
|
||||||
{
|
{
|
||||||
assert(sh);
|
assert(sh);
|
||||||
|
|
||||||
@@ -1200,6 +1201,7 @@ set_shader_source(struct gl_shader *sh, const GLchar *source)
|
|||||||
* fallback.
|
* fallback.
|
||||||
*/
|
*/
|
||||||
sh->FallbackSource = sh->Source;
|
sh->FallbackSource = sh->Source;
|
||||||
|
memcpy(sh->fallback_source_sha1, sh->source_sha1, SHA1_DIGEST_LENGTH);
|
||||||
sh->Source = source;
|
sh->Source = source;
|
||||||
} else {
|
} else {
|
||||||
/* free old shader source string and install new one */
|
/* free old shader source string and install new one */
|
||||||
@@ -1207,6 +1209,7 @@ set_shader_source(struct gl_shader *sh, const GLchar *source)
|
|||||||
sh->Source = source;
|
sh->Source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(sh->source_sha1, original_sha1, SHA1_DIGEST_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -2178,6 +2181,10 @@ shader_source(struct gl_context *ctx, GLuint shaderObj, GLsizei count,
|
|||||||
source[totalLength - 1] = '\0';
|
source[totalLength - 1] = '\0';
|
||||||
source[totalLength - 2] = '\0';
|
source[totalLength - 2] = '\0';
|
||||||
|
|
||||||
|
/* Compute the original source sha1 before shader replacement. */
|
||||||
|
uint8_t original_sha1[SHA1_DIGEST_LENGTH];
|
||||||
|
_mesa_sha1_compute(source, strlen(source), original_sha1);
|
||||||
|
|
||||||
#ifdef ENABLE_SHADER_CACHE
|
#ifdef ENABLE_SHADER_CACHE
|
||||||
GLcharARB *replacement;
|
GLcharARB *replacement;
|
||||||
|
|
||||||
@@ -2193,7 +2200,7 @@ shader_source(struct gl_context *ctx, GLuint shaderObj, GLsizei count,
|
|||||||
}
|
}
|
||||||
#endif /* ENABLE_SHADER_CACHE */
|
#endif /* ENABLE_SHADER_CACHE */
|
||||||
|
|
||||||
set_shader_source(sh, source);
|
set_shader_source(sh, source, original_sha1);
|
||||||
|
|
||||||
free(offsets);
|
free(offsets);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user