mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-03-06 23:00:31 +01:00
mesa: switch remaining shader functions from SHA1 to BLAKE3
This fixes shader replacements, which require BLAKE3 now. Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30110>
This commit is contained in:
parent
c2d26a5c08
commit
090f27035d
5 changed files with 25 additions and 26 deletions
|
|
@ -380,15 +380,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, len, sha1);
|
||||
blake3_hash blake3;
|
||||
_mesa_blake3_compute(string, len, blake3);
|
||||
|
||||
/* 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, sha1);
|
||||
_mesa_dump_shader_source(stage, string, blake3);
|
||||
|
||||
replacement = _mesa_read_shader_source(stage, string, sha1);
|
||||
replacement = _mesa_read_shader_source(stage, string, blake3);
|
||||
if (replacement)
|
||||
string = replacement;
|
||||
#endif /* ENABLE_SHADER_CACHE */
|
||||
|
|
|
|||
|
|
@ -55,7 +55,6 @@
|
|||
#include "util/u_idalloc.h"
|
||||
#include "util/simple_mtx.h"
|
||||
#include "util/u_dynarray.h"
|
||||
#include "util/mesa-sha1.h"
|
||||
#include "vbo/vbo.h"
|
||||
|
||||
#include "pipe/p_state.h"
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@
|
|||
#include "compiler/glsl/ir.h"
|
||||
#include "compiler/glsl/linker_util.h"
|
||||
#include "compiler/glsl/string_to_uint_map.h"
|
||||
#include "util/mesa-sha1.h"
|
||||
#include "c99_alloca.h"
|
||||
#include "api_exec_decl.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -79,10 +79,10 @@
|
|||
/* shader_replacement.h must declare a variable like this:
|
||||
|
||||
struct _shader_replacement {
|
||||
// process name. If null, only sha1 is used to match
|
||||
// process name. If null, only blake3 is used to match
|
||||
const char *app;
|
||||
// original glsl shader sha1
|
||||
const char *sha1;
|
||||
// original glsl shader blake3
|
||||
const char *blake3;
|
||||
// shader stage
|
||||
gl_shader_stage stage;
|
||||
... any other information ...
|
||||
|
|
@ -94,7 +94,7 @@
|
|||
|
||||
char* load_shader_replacement(struct _shader_replacement *repl);
|
||||
|
||||
And a method to replace the shader without sha1 matching:
|
||||
And a method to replace the shader without blake3 matching:
|
||||
|
||||
char *try_direct_replace(const char *app, const char *source)
|
||||
|
||||
|
|
@ -104,7 +104,7 @@
|
|||
#else
|
||||
struct _shader_replacement {
|
||||
const char *app;
|
||||
const char *sha1;
|
||||
const char *blake3;
|
||||
gl_shader_stage stage;
|
||||
};
|
||||
struct _shader_replacement shader_replacements[0];
|
||||
|
|
@ -1942,7 +1942,7 @@ _mesa_LinkProgram(GLuint programObj)
|
|||
* <path>/<stage prefix>_<CHECKSUM>.arb
|
||||
*/
|
||||
static char *
|
||||
construct_name(const gl_shader_stage stage, const char *sha,
|
||||
construct_name(const gl_shader_stage stage, const char *blake3_str,
|
||||
const char *source, const char *path)
|
||||
{
|
||||
static const char *types[] = {
|
||||
|
|
@ -1951,7 +1951,7 @@ construct_name(const gl_shader_stage stage, const char *sha,
|
|||
|
||||
const char *format = strncmp(source, "!!ARB", 5) ? "glsl" : "arb";
|
||||
|
||||
return ralloc_asprintf(NULL, "%s/%s_%s.%s", path, types[stage], sha, format);
|
||||
return ralloc_asprintf(NULL, "%s/%s_%s.%s", path, types[stage], blake3_str, format);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1959,13 +1959,13 @@ construct_name(const gl_shader_stage stage, const char *sha,
|
|||
*/
|
||||
void
|
||||
_mesa_dump_shader_source(const gl_shader_stage stage, const char *source,
|
||||
const uint8_t sha1[SHA1_DIGEST_LENGTH])
|
||||
const blake3_hash blake3)
|
||||
{
|
||||
#ifndef CUSTOM_SHADER_REPLACEMENT
|
||||
static bool path_exists = true;
|
||||
char *dump_path;
|
||||
FILE *f;
|
||||
char sha[64];
|
||||
char blake3_str[BLAKE3_OUT_LEN * 2 + 1];
|
||||
|
||||
if (!path_exists)
|
||||
return;
|
||||
|
|
@ -1976,8 +1976,8 @@ _mesa_dump_shader_source(const gl_shader_stage stage, const char *source,
|
|||
return;
|
||||
}
|
||||
|
||||
_mesa_sha1_format(sha, sha1);
|
||||
char *name = construct_name(stage, sha, source, dump_path);
|
||||
_mesa_blake3_format(blake3_str, blake3);
|
||||
char *name = construct_name(stage, blake3_str, source, dump_path);
|
||||
|
||||
f = fopen(name, "w");
|
||||
if (f) {
|
||||
|
|
@ -1998,16 +1998,16 @@ _mesa_dump_shader_source(const gl_shader_stage stage, const char *source,
|
|||
*/
|
||||
GLcharARB *
|
||||
_mesa_read_shader_source(const gl_shader_stage stage, const char *source,
|
||||
const uint8_t sha1[SHA1_DIGEST_LENGTH])
|
||||
const blake3_hash blake3)
|
||||
{
|
||||
char *read_path;
|
||||
static bool path_exists = true;
|
||||
int len, shader_size = 0;
|
||||
GLcharARB *buffer;
|
||||
FILE *f;
|
||||
char sha[64];
|
||||
char blake3_str[BLAKE3_OUT_LEN * 2 + 1];
|
||||
|
||||
_mesa_sha1_format(sha, sha1);
|
||||
_mesa_blake3_format(blake3_str, blake3);
|
||||
|
||||
if (!debug_get_bool_option("MESA_NO_SHADER_REPLACEMENT", false)) {
|
||||
const char *process_name = util_get_process_name();
|
||||
|
|
@ -2024,7 +2024,8 @@ _mesa_read_shader_source(const gl_shader_stage stage, const char *source,
|
|||
strcmp(process_name, shader_replacements[i].app) != 0)
|
||||
continue;
|
||||
|
||||
if (memcmp(sha, shader_replacements[i].sha1, 40) != 0)
|
||||
if (memcmp(blake3_str, shader_replacements[i].blake3,
|
||||
BLAKE3_OUT_LEN * 2) != 0)
|
||||
continue;
|
||||
|
||||
return load_shader_replacement(&shader_replacements[i]);
|
||||
|
|
@ -2040,7 +2041,7 @@ _mesa_read_shader_source(const gl_shader_stage stage, const char *source,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char *name = construct_name(stage, sha, source, read_path);
|
||||
char *name = construct_name(stage, blake3_str, source, read_path);
|
||||
f = fopen(name, "r");
|
||||
ralloc_free(name);
|
||||
if (!f)
|
||||
|
|
@ -2145,7 +2146,7 @@ shader_source(struct gl_context *ctx, GLuint shaderObj, GLsizei count,
|
|||
source[totalLength - 1] = '\0';
|
||||
source[totalLength - 2] = '\0';
|
||||
|
||||
/* Compute the original source sha1 before shader replacement. */
|
||||
/* Compute the original source blake3 before shader replacement. */
|
||||
blake3_hash original_blake3;
|
||||
_mesa_blake3_compute(source, strlen(source), original_blake3);
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
#include "util/glheader.h"
|
||||
#include "compiler/shader_enums.h"
|
||||
#include "util/mesa-sha1.h"
|
||||
#include "util/mesa-blake3.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
@ -174,11 +174,11 @@ _mesa_program_init_subroutine_defaults(struct gl_context *ctx,
|
|||
|
||||
GLcharARB *
|
||||
_mesa_read_shader_source(const gl_shader_stage stage, const char *source,
|
||||
const uint8_t sha1[SHA1_DIGEST_LENGTH]);
|
||||
const blake3_hash blake3);
|
||||
|
||||
void
|
||||
_mesa_dump_shader_source(const gl_shader_stage stage, const char *source,
|
||||
const uint8_t sha1[SHA1_DIGEST_LENGTH]);
|
||||
const blake3_hash blake3);
|
||||
|
||||
void
|
||||
_mesa_init_shader_includes(struct gl_shared_state *shared);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue