For the gallium state tracker a tgsi binary may have been evicted from the cache to make space. In this case we would take the fallback path and recompile/link the shader.
On i965 there are a number of reasons we can get to the program upload stage and have neither IR nor a valid cached binary. For example the binary may have been evicted from the cache or we need a variant that wasn't previously cached. This environment variable enables us to force the fallback path that would be taken in these cases and makes it easier to debug these otherwise hard to reproduce scenarios. Cc: Jordan Justen <jordan.l.jus...@intel.com> --- docs/shading.html | 2 ++ src/mesa/main/mtypes.h | 1 + src/mesa/main/shaderapi.c | 2 ++ src/mesa/state_tracker/st_shader_cache.c | 14 +++++++++++++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/shading.html b/docs/shading.html index 7e3d2e4..c789102 100644 --- a/docs/shading.html +++ b/docs/shading.html @@ -43,20 +43,22 @@ Contents The <b>MESA_GLSL</b> environment variable can be set to a comma-separated list of keywords to control some aspects of the GLSL compiler and shader execution. These are generally used for debugging. </p> <ul> <li><b>dump</b> - print GLSL shader code to stdout at link time <li><b>log</b> - log all GLSL shaders to files. The filenames will be "shader_X.vert" or "shader_X.frag" where X the shader ID. <li><b>cache_info</b> - print debug information about shader cache +<li><b>cache_fb</b> - force cached shaders to be ignored and do a full + recompile via the fallback path</li> <li><b>uniform</b> - print message to stdout when glUniform is called <li><b>nopvert</b> - force vertex shaders to be a simple shader that just transforms the vertex position with ftransform() and passes through the color and texcoord[0] attributes. <li><b>nopfrag</b> - force fragment shader to be a simple shader that passes through the color attribute. <li><b>useprog</b> - log glUseProgram calls to stderr </ul> <p> Example: export MESA_GLSL=dump,nopt diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 28d3d948..941311b 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2970,20 +2970,21 @@ struct gl_shader_program #define GLSL_DUMP 0x1 /**< Dump shaders to stdout */ #define GLSL_LOG 0x2 /**< Write shaders to files */ #define GLSL_UNIFORMS 0x4 /**< Print glUniform calls */ #define GLSL_NOP_VERT 0x8 /**< Force no-op vertex shaders */ #define GLSL_NOP_FRAG 0x10 /**< Force no-op fragment shaders */ #define GLSL_USE_PROG 0x20 /**< Log glUseProgram calls */ #define GLSL_REPORT_ERRORS 0x40 /**< Print compilation errors */ #define GLSL_DUMP_ON_ERROR 0x80 /**< Dump shaders to stderr on compile error */ #define GLSL_CACHE_INFO 0x100 /**< Print debug information about shader cache */ +#define GLSL_CACHE_FALLBACK 0x200 /**< Force shader cache fallback paths */ /** * Context state for GLSL vertex/fragment shaders. * Extended to support pipeline object */ struct gl_pipeline_object { /** Name of the pipeline object as received from glGenProgramPipelines. * It would be 0 for shaders without separate shader objects. diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index 68fb3fa..325542e 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -70,20 +70,22 @@ _mesa_get_shader_flags(void) GLbitfield flags = 0x0; const char *env = getenv("MESA_GLSL"); if (env) { if (strstr(env, "dump_on_error")) flags |= GLSL_DUMP_ON_ERROR; else if (strstr(env, "dump")) flags |= GLSL_DUMP; if (strstr(env, "log")) flags |= GLSL_LOG; + if (strstr(env, "cache_fb")) + flags |= GLSL_CACHE_FALLBACK; if (strstr(env, "cache_info")) flags |= GLSL_CACHE_INFO; if (strstr(env, "nopvert")) flags |= GLSL_NOP_VERT; if (strstr(env, "nopfrag")) flags |= GLSL_NOP_FRAG; if (strstr(env, "uniform")) flags |= GLSL_UNIFORMS; if (strstr(env, "useprog")) flags |= GLSL_USE_PROG; diff --git a/src/mesa/state_tracker/st_shader_cache.c b/src/mesa/state_tracker/st_shader_cache.c index 175d69d..394adbe 100644 --- a/src/mesa/state_tracker/st_shader_cache.c +++ b/src/mesa/state_tracker/st_shader_cache.c @@ -218,22 +218,30 @@ st_load_tgsi_from_disk_cache(struct gl_context *ctx, } /* Now that we have created the sha1 keys that will be used for writting to * the tgsi cache fallback to the regular glsl to tgsi path if we didn't * load the GLSL IR from cache. We do this as glsl to tgsi can alter things * such as gl_program_parameter_list which holds things like uniforms. */ if (prog->data->LinkStatus != linking_skipped) return false; - struct st_context *st = st_context(ctx); uint8_t *buffer = NULL; + bool cache_fb = false; + if (ctx->_Shader->Flags & GLSL_CACHE_FALLBACK) { + /* Temporarily turn off the flag to avoid getting stuck in a loop */ + ctx->_Shader->Flags ^= GLSL_CACHE_FALLBACK; + cache_fb = true; + goto fallback_recompile; + } + + struct st_context *st = st_context(ctx); for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { if (prog->_LinkedShaders[i] == NULL) continue; unsigned char *sha1 = stage_sha1[i]; size_t size; buffer = (uint8_t *) disk_cache_get(ctx->Cache, sha1, &size); if (buffer) { struct blob_reader blob_reader; blob_reader_init(&blob_reader, buffer, size); @@ -383,12 +391,16 @@ fallback_recompile: if (ctx->_Shader->Flags & GLSL_CACHE_INFO) fprintf(stderr, "TGSI cache falling back to recompile.\n"); for (unsigned i = 0; i < prog->NumShaders; i++) { _mesa_glsl_compile_shader(ctx, prog->Shaders[i], false, false, true); } prog->data->cache_fallback = true; _mesa_glsl_link_shader(ctx, prog); + /* Turn the fallback flag back on if we disabled it previously */ + if (cache_fb) + ctx->_Shader->Flags |= GLSL_CACHE_FALLBACK; + return true; } -- 2.9.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev