mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-30 03:30:10 +01:00
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>
This commit is contained in:
parent
479a849ad6
commit
656ccf4ef8
3 changed files with 31 additions and 7 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue