mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-06 09:28:07 +02:00
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:
parent
67f01e02d9
commit
0b196b40a3
3 changed files with 19 additions and 22 deletions
|
|
@ -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);
|
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
|
/* Dump original shader source to MESA_SHADER_DUMP_PATH and replace
|
||||||
* if corresponding entry found from MESA_SHADER_READ_PATH.
|
* 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)
|
if (replacement)
|
||||||
string = replacement;
|
string = replacement;
|
||||||
#endif /* ENABLE_SHADER_CACHE */
|
#endif /* ENABLE_SHADER_CACHE */
|
||||||
|
|
|
||||||
|
|
@ -1960,17 +1960,6 @@ _mesa_LinkProgram(GLuint programObj)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_SHADER_CACHE
|
#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
|
* 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.
|
* Write given shader source to a file in MESA_SHADER_DUMP_PATH.
|
||||||
*/
|
*/
|
||||||
void
|
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
|
#ifndef CUSTOM_SHADER_REPLACEMENT
|
||||||
static bool path_exists = true;
|
static bool path_exists = true;
|
||||||
|
|
@ -2013,8 +2003,8 @@ _mesa_dump_shader_source(const gl_shader_stage stage, const char *source)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *name = construct_name(stage, generate_sha1(source, sha),
|
_mesa_sha1_format(sha, sha1);
|
||||||
source, dump_path);
|
char *name = construct_name(stage, sha, source, dump_path);
|
||||||
|
|
||||||
f = fopen(name, "w");
|
f = fopen(name, "w");
|
||||||
if (f) {
|
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.
|
* Useful for debugging to override an app's shader.
|
||||||
*/
|
*/
|
||||||
GLcharARB *
|
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;
|
char *read_path;
|
||||||
static bool path_exists = true;
|
static bool path_exists = true;
|
||||||
|
|
@ -2043,7 +2034,7 @@ _mesa_read_shader_source(const gl_shader_stage stage, const char *source)
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char sha[64];
|
char sha[64];
|
||||||
|
|
||||||
generate_sha1(source, sha);
|
_mesa_sha1_format(sha, sha1);
|
||||||
|
|
||||||
if (!debug_get_bool_option("MESA_NO_SHADER_REPLACEMENT", false)) {
|
if (!debug_get_bool_option("MESA_NO_SHADER_REPLACEMENT", false)) {
|
||||||
const char *process_name = util_get_process_name();
|
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
|
/* Dump original shader source to MESA_SHADER_DUMP_PATH and replace
|
||||||
* if corresponding entry found from MESA_SHADER_READ_PATH.
|
* 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) {
|
if (replacement) {
|
||||||
free(source);
|
free(source);
|
||||||
source = replacement;
|
source = replacement;
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@
|
||||||
#include "glheader.h"
|
#include "glheader.h"
|
||||||
#include "main/mtypes.h"
|
#include "main/mtypes.h"
|
||||||
#include "compiler/shader_enums.h"
|
#include "compiler/shader_enums.h"
|
||||||
|
#include "util/mesa-sha1.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
@ -419,10 +420,12 @@ _mesa_GetNamedStringivARB(GLint namelen, const GLchar *name,
|
||||||
GLenum pname, GLint *params);
|
GLenum pname, GLint *params);
|
||||||
|
|
||||||
GLcharARB *
|
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
|
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
|
void
|
||||||
_mesa_init_shader_includes(struct gl_shared_state *shared);
|
_mesa_init_shader_includes(struct gl_shared_state *shared);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue