mesa: don't compute the same SHA1 twice in glShaderSource

We can just use original_sha1.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13869>
This commit is contained in:
Marek Olšák 2021-11-19 03:04:11 -05:00 committed by Marge Bot
parent 67f01e02d9
commit 0b196b40a3
3 changed files with 19 additions and 22 deletions

View File

@ -379,12 +379,15 @@ set_program_string(struct gl_program *prog, GLenum target, GLenum format, GLsize
gl_shader_stage stage = _mesa_program_enum_to_shader_stage(target);
uint8_t sha1[SHA1_DIGEST_LENGTH];
_mesa_sha1_compute(string, strlen(string), sha1);
/* 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);
_mesa_dump_shader_source(stage, string, sha1);
replacement = _mesa_read_shader_source(stage, string);
replacement = _mesa_read_shader_source(stage, string, sha1);
if (replacement)
string = replacement;
#endif /* ENABLE_SHADER_CACHE */

View File

@ -1960,17 +1960,6 @@ _mesa_LinkProgram(GLuint programObj)
}
#ifdef ENABLE_SHADER_CACHE
/**
* Generate a SHA-1 hash value string for given source string.
*/
static char *
generate_sha1(const char *source, char sha_str[64])
{
unsigned char sha[20];
_mesa_sha1_compute(source, strlen(source), sha);
_mesa_sha1_format(sha_str, sha);
return sha_str;
}
/**
* Construct a full path for shader replacement functionality using
@ -1996,7 +1985,8 @@ construct_name(const gl_shader_stage stage, const char *sha,
* Write given shader source to a file in MESA_SHADER_DUMP_PATH.
*/
void
_mesa_dump_shader_source(const gl_shader_stage stage, const char *source)
_mesa_dump_shader_source(const gl_shader_stage stage, const char *source,
const uint8_t sha1[SHA1_DIGEST_LENGTH])
{
#ifndef CUSTOM_SHADER_REPLACEMENT
static bool path_exists = true;
@ -2013,8 +2003,8 @@ _mesa_dump_shader_source(const gl_shader_stage stage, const char *source)
return;
}
char *name = construct_name(stage, generate_sha1(source, sha),
source, dump_path);
_mesa_sha1_format(sha, sha1);
char *name = construct_name(stage, sha, source, dump_path);
f = fopen(name, "w");
if (f) {
@ -2034,7 +2024,8 @@ _mesa_dump_shader_source(const gl_shader_stage stage, const char *source)
* Useful for debugging to override an app's shader.
*/
GLcharARB *
_mesa_read_shader_source(const gl_shader_stage stage, const char *source)
_mesa_read_shader_source(const gl_shader_stage stage, const char *source,
const uint8_t sha1[SHA1_DIGEST_LENGTH])
{
char *read_path;
static bool path_exists = true;
@ -2043,7 +2034,7 @@ _mesa_read_shader_source(const gl_shader_stage stage, const char *source)
FILE *f;
char sha[64];
generate_sha1(source, sha);
_mesa_sha1_format(sha, sha1);
if (!debug_get_bool_option("MESA_NO_SHADER_REPLACEMENT", false)) {
const char *process_name = util_get_process_name();
@ -2191,9 +2182,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.
*/
_mesa_dump_shader_source(sh->Stage, source);
_mesa_dump_shader_source(sh->Stage, source, original_sha1);
replacement = _mesa_read_shader_source(sh->Stage, source);
replacement = _mesa_read_shader_source(sh->Stage, source, original_sha1);
if (replacement) {
free(source);
source = replacement;

View File

@ -31,6 +31,7 @@
#include "glheader.h"
#include "main/mtypes.h"
#include "compiler/shader_enums.h"
#include "util/mesa-sha1.h"
#ifdef __cplusplus
extern "C" {
@ -419,10 +420,12 @@ _mesa_GetNamedStringivARB(GLint namelen, const GLchar *name,
GLenum pname, GLint *params);
GLcharARB *
_mesa_read_shader_source(const gl_shader_stage stage, const char *source);
_mesa_read_shader_source(const gl_shader_stage stage, const char *source,
const uint8_t sha1[SHA1_DIGEST_LENGTH]);
void
_mesa_dump_shader_source(const gl_shader_stage stage, const char *source);
_mesa_dump_shader_source(const gl_shader_stage stage, const char *source,
const uint8_t sha1[SHA1_DIGEST_LENGTH]);
void
_mesa_init_shader_includes(struct gl_shared_state *shared);