{
struct _mesa_glsl_parse_state *state =
new(shader) _mesa_glsl_parse_state(ctx, shader->Stage, shader);
- const char *source = shader->Source;
+ const char *source = force_recompile && shader->FallbackSource ?
+ shader->FallbackSource : shader->Source;
if (ctx->Const.GenerateTemporaryNames)
(void) p_atomic_cmpxchg(&ir_variable::temporaries_allocate_names,
_mesa_sha1_format(buf, shader->sha1));
}
shader->CompileStatus = true;
+
+ free((void *)shader->FallbackSource);
+ shader->FallbackSource = NULL;
return;
}
}
_mesa_glsl_initialize_derived_variables(ctx, shader);
+ if (!force_recompile) {
+ free((void *)shader->FallbackSource);
+ shader->FallbackSource = NULL;
+ }
+
delete state->symbols;
ralloc_free(state);
}
#endif
const GLchar *Source; /**< Source code string */
+ const GLchar *FallbackSource; /**< Fallback string used by on-disk cache*/
+
GLchar *InfoLog;
unsigned Version; /**< GLSL version used for linking */
{
assert(sh);
- /* free old shader source string and install new one */
- free((void *)sh->Source);
- sh->Source = source;
+ if (sh->CompileStatus == GL_TRUE && !sh->FallbackSource) {
+ /* If shader was previously compiled back-up the source in case of cache
+ * fallback.
+ */
+ sh->FallbackSource = sh->Source;
+ sh->Source = source;
+ } else {
+ /* free old shader source string and install new one */
+ free((void *)sh->Source);
+ sh->Source = source;
+ }
+
#ifdef DEBUG
sh->SourceChecksum = util_hash_crc32(sh->Source, strlen(sh->Source));
#endif
_mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh)
{
free((void *)sh->Source);
+ free((void *)sh->FallbackSource);
free(sh->Label);
ralloc_free(sh);
}