diff options
author | Tapani Pälli <tapani.palli@intel.com> | 2018-07-24 10:41:46 +0300 |
---|---|---|
committer | Tapani Pälli <tapani.palli@intel.com> | 2018-08-15 11:03:35 +0300 |
commit | 656ccf4ef890b91debbb72b38957723ca04411d0 (patch) | |
tree | 646198661955a9c4515a78d71667376453856668 | |
parent | 479a849ad606482c3cf67157b77af94ecd450ace (diff) |
mesa: shader dump/read support for ARB programs
Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=106283
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
-rw-r--r-- | src/mesa/main/arbprogram.c | 15 | ||||
-rw-r--r-- | src/mesa/main/shaderapi.c | 17 | ||||
-rw-r--r-- | src/mesa/main/shaderapi.h | 6 |
3 files changed, 31 insertions, 7 deletions
diff --git a/src/mesa/main/arbprogram.c b/src/mesa/main/arbprogram.c index b169bce0c5..24ef8666b3 100644 --- a/src/mesa/main/arbprogram.c +++ b/src/mesa/main/arbprogram.c @@ -347,6 +347,21 @@ _mesa_ProgramStringARB(GLenum target, GLenum format, GLsizei len, return; } +#ifdef ENABLE_SHADER_CACHE + GLcharARB *replacement; + + gl_shader_stage stage = _mesa_program_enum_to_shader_stage(target); + + /* Dump original shader source to MESA_SHADER_DUMP_PATH and replace + * if corresponding entry found from MESA_SHADER_READ_PATH. + */ + _mesa_dump_shader_source(stage, string); + + replacement = _mesa_read_shader_source(stage, string); + if (replacement) + string = replacement; +#endif /* ENABLE_SHADER_CACHE */ + if (target == GL_VERTEX_PROGRAM_ARB && ctx->Extensions.ARB_vertex_program) { prog = ctx->VertexProgram.Current; _mesa_parse_arb_vertex_program(ctx, target, string, len, prog); diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index f7080847cc..2ea8d965ab 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -1795,6 +1795,7 @@ generate_sha1(const char *source, char sha_str[64]) * following format: * * <path>/<stage prefix>_<CHECKSUM>.glsl + * <path>/<stage prefix>_<CHECKSUM>.arb */ static char * construct_name(const gl_shader_stage stage, const char *source, @@ -1805,15 +1806,17 @@ construct_name(const gl_shader_stage stage, const char *source, "VS", "TC", "TE", "GS", "FS", "CS", }; + const char *format = strncmp(source, "!!ARB", 5) ? "glsl" : "arb"; + generate_sha1(source, sha); - return ralloc_asprintf(NULL, "%s/%s_%s.glsl", path, types[stage], sha); + return ralloc_asprintf(NULL, "%s/%s_%s.%s", path, types[stage], sha, format); } /** * Write given shader source to a file in MESA_SHADER_DUMP_PATH. */ -static void -dump_shader(const gl_shader_stage stage, const char *source) +void +_mesa_dump_shader_source(const gl_shader_stage stage, const char *source) { static bool path_exists = true; char *dump_path; @@ -1846,8 +1849,8 @@ dump_shader(const gl_shader_stage stage, const char *source) * Read shader source code from a file. * Useful for debugging to override an app's shader. */ -static GLcharARB * -read_shader(const gl_shader_stage stage, const char *source) +GLcharARB * +_mesa_read_shader_source(const gl_shader_stage stage, const char *source) { char *read_path; static bool path_exists = true; @@ -1971,9 +1974,9 @@ shader_source(struct gl_context *ctx, GLuint shaderObj, GLsizei count, /* Dump original shader source to MESA_SHADER_DUMP_PATH and replace * if corresponding entry found from MESA_SHADER_READ_PATH. */ - dump_shader(sh->Stage, source); + _mesa_dump_shader_source(sh->Stage, source); - replacement = read_shader(sh->Stage, source); + replacement = _mesa_read_shader_source(sh->Stage, source); if (replacement) { free(source); source = replacement; diff --git a/src/mesa/main/shaderapi.h b/src/mesa/main/shaderapi.h index dbfd68fd3a..a8227ecc96 100644 --- a/src/mesa/main/shaderapi.h +++ b/src/mesa/main/shaderapi.h @@ -374,6 +374,12 @@ extern GLvoid GLAPIENTRY _mesa_GetProgramStageiv(GLuint program, GLenum shadertype, GLenum pname, GLint *values); +GLcharARB * +_mesa_read_shader_source(const gl_shader_stage stage, const char *source); + +void +_mesa_dump_shader_source(const gl_shader_stage stage, const char *source); + #ifdef __cplusplus } #endif |