From b8fe130fa47b13c3ea5cd42af8adc2ce127ded26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tapani=20P=C3=A4lli?= Date: Tue, 26 Jun 2018 13:36:37 +0300 Subject: [PATCH] mesa: shader dump/read support for ARB programs WIP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tapani Pälli Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=106283 --- src/mesa/main/arbprogram.c | 26 ++++++++++++++++++++++++++ src/mesa/main/shaderapi.c | 12 ++++++------ src/mesa/main/shaderapi.h | 6 ++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/mesa/main/arbprogram.c b/src/mesa/main/arbprogram.c index b169bce0c5..d1dc5029a9 100644 --- a/src/mesa/main/arbprogram.c +++ b/src/mesa/main/arbprogram.c @@ -326,6 +326,19 @@ get_env_param_pointer(struct gl_context *ctx, const char *func, } } +static gl_shader_stage +stage_from_target(GLenum target) +{ + switch (target) { + case GL_VERTEX_PROGRAM_ARB: + return MESA_SHADER_VERTEX; + case GL_FRAGMENT_PROGRAM_ARB: + return MESA_SHADER_FRAGMENT; + default: + return -1; + } +} + void GLAPIENTRY _mesa_ProgramStringARB(GLenum target, GLenum format, GLsizei len, const GLvoid *string) @@ -347,6 +360,19 @@ _mesa_ProgramStringARB(GLenum target, GLenum format, GLsizei len, return; } +#ifdef ENABLE_SHADER_CACHE + GLcharARB *replacement; + + /* 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_from_target(target), string); + + replacement = _mesa_read_shader_source(stage_from_target(target), 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..b47b522bf1 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -1812,8 +1812,8 @@ construct_name(const gl_shader_stage stage, const char *source, /** * 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 +1846,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 +1971,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 -- 2.14.4