mesa: replace shader_info::source_sha1

Replace shader_info::source_sha1 with shader_info::source_blake3 in compiler, mesa and radeonsi.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Acked-by: David Heidelberg <david.heidelberg@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28156>
This commit is contained in:
Saroj Kumar 2024-05-01 14:36:35 +05:30 committed by Marge Bot
parent 7c0b0e660a
commit 221371e903
15 changed files with 74 additions and 72 deletions

View file

@ -33,7 +33,7 @@
#include "util/u_atomic.h" /* for p_atomic_cmpxchg */
#include "util/ralloc.h"
#include "util/disk_cache.h"
#include "util/mesa-sha1.h"
#include "util/mesa-blake3.h"
#include "ast.h"
#include "glsl_parser_extras.h"
#include "glsl_parser.h"
@ -2262,8 +2262,7 @@ opt_shader_and_create_symbol_table(const struct gl_constants *consts,
static bool
can_skip_compile(struct gl_context *ctx, struct gl_shader *shader,
const char *source,
const uint8_t source_sha1[SHA1_DIGEST_LENGTH],
const char *source, const blake3_hash source_blake3,
bool force_recompile, bool source_has_shader_include)
{
if (!force_recompile) {
@ -2287,13 +2286,13 @@ can_skip_compile(struct gl_context *ctx, struct gl_shader *shader,
*/
if (source_has_shader_include) {
shader->FallbackSource = strdup(source);
memcpy(shader->fallback_source_sha1, source_sha1,
SHA1_DIGEST_LENGTH);
memcpy(shader->fallback_source_blake3, source_blake3,
BLAKE3_OUT_LEN);
} else {
shader->FallbackSource = NULL;
}
memcpy(shader->compiled_source_sha1, source_sha1,
SHA1_DIGEST_LENGTH);
memcpy(shader->compiled_source_blake3, source_blake3,
BLAKE3_OUT_LEN);
return true;
}
}
@ -2314,14 +2313,14 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
bool dump_ast, bool dump_hir, bool force_recompile)
{
const char *source;
const uint8_t *source_sha1;
const uint8_t *source_blake3;
if (force_recompile && shader->FallbackSource) {
source = shader->FallbackSource;
source_sha1 = shader->fallback_source_sha1;
source_blake3 = shader->fallback_source_blake3;
} else {
source = shader->Source;
source_sha1 = shader->source_sha1;
source_blake3 = shader->source_blake3;
}
/* Note this will be true for shaders the have #include inside comments
@ -2336,7 +2335,7 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
* keep duplicate copies of the shader include source tree and paths.
*/
if (!source_has_shader_include &&
can_skip_compile(ctx, shader, source, source_sha1, force_recompile,
can_skip_compile(ctx, shader, source, source_blake3, force_recompile,
false))
return;
@ -2357,7 +2356,7 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
* include.
*/
if (source_has_shader_include &&
can_skip_compile(ctx, shader, source, source_sha1, force_recompile,
can_skip_compile(ctx, shader, source, source_blake3, force_recompile,
true))
return;
@ -2423,7 +2422,7 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
*/
if (source_has_shader_include) {
shader->FallbackSource = strdup(source);
memcpy(shader->fallback_source_sha1, source_sha1, SHA1_DIGEST_LENGTH);
memcpy(shader->fallback_source_blake3, source_blake3, BLAKE3_OUT_LEN);
} else {
shader->FallbackSource = NULL;
}
@ -2433,7 +2432,7 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
ralloc_free(state);
if (shader->CompileStatus == COMPILE_SUCCESS)
memcpy(shader->compiled_source_sha1, source_sha1, SHA1_DIGEST_LENGTH);
memcpy(shader->compiled_source_blake3, source_blake3, BLAKE3_OUT_LEN);
if (ctx->Cache && shader->CompileStatus == COMPILE_SUCCESS) {
char sha1_buf[41];

View file

@ -1789,22 +1789,22 @@ link_intrastage_shaders(void *mem_ctx,
}
}
/* Set the linked source SHA1. */
/* Set the linked source BLAKE3. */
if (num_shaders == 1) {
memcpy(linked->linked_source_sha1, shader_list[0]->compiled_source_sha1,
SHA1_DIGEST_LENGTH);
memcpy(linked->linked_source_blake3, shader_list[0]->compiled_source_blake3,
BLAKE3_OUT_LEN);
} else {
struct mesa_sha1 sha1_ctx;
_mesa_sha1_init(&sha1_ctx);
struct mesa_blake3 blake3_ctx;
_mesa_blake3_init(&blake3_ctx);
for (unsigned i = 0; i < num_shaders; i++) {
if (shader_list[i] == NULL)
continue;
_mesa_sha1_update(&sha1_ctx, shader_list[i]->compiled_source_sha1,
SHA1_DIGEST_LENGTH);
_mesa_blake3_update(&blake3_ctx, shader_list[i]->compiled_source_blake3,
BLAKE3_OUT_LEN);
}
_mesa_sha1_final(&sha1_ctx, linked->linked_source_sha1);
_mesa_blake3_final(&blake3_ctx, linked->linked_source_blake3);
}
return linked;

View file

@ -23,7 +23,7 @@
#include "nir.h"
#include "nir_builder.h"
#include "util/mesa-sha1.h"
#include "util/mesa-blake3.h"
#include <math.h>
/** @file nir_opt_undef.c
@ -291,29 +291,29 @@ nir_opt_undef(nir_shader *shader)
struct undef_options options = {0};
/* Disallow the undef->NaN transformation only for those shaders where
* it's known to break rendering. These are shader source SHA1s printed by
* it's known to break rendering. These are shader source BLAKE3s printed by
* nir_print_shader().
*/
uint32_t shader_sha1s[][SHA1_DIGEST_LENGTH32] = {
uint32_t shader_blake3s[][BLAKE3_OUT_LEN32] = {
/* gputest/gimark */
{0x9a1af9e2, 0x68f185bf, 0x11fc1257, 0x1102e80b, 0x5ca350fa},
{0x582c214b, 0x25478275, 0xc9a835d2, 0x95c9b643, 0x69deae47, 0x213c7427, 0xa9da66a5, 0xac254ed2},
/* Viewperf13/CATIA_car_01 */
{0x4746a4a4, 0xe3b27d27, 0xe6d2b0fb, 0xb7e9ceb3, 0x973e6152}, /* Taillights */
{0xc49cc90d, 0xd7208212, 0x726502ea, 0xe1fe62c0, 0xb62fbd1f}, /* Grill */
{0xde23f35b, 0xb6fa45ae, 0x96da7e6b, 0x5a6e4a60, 0xce0b6b31}, /* Headlights */
{0xdf36242c, 0x0705db59, 0xf1ddac9b, 0xcd1c8466, 0x4c73203b}, /* Rims */
{0x880dfa0f, 0x60e32201, 0xe3a89f59, 0xb1cc6f07, 0xcdbebe66, 0x20122aec, 0x83450d4e, 0x8f42843d}, /* Taillights */
{0x624e53bb, 0x8eb635ba, 0xb1e4ed9b, 0x651b0fec, 0x86fcf79a, 0xde0863fb, 0x09ce80c1, 0xd972e40f}, /* Grill */
{0x01a8db39, 0xfa175175, 0x621f7302, 0xfcde9177, 0x72d873bf, 0x048d38c1, 0xe669d2de, 0xaa6584af}, /* Headlights */
{0x32029770, 0xab295b41, 0x3f1daf07, 0x9dd9153e, 0xd598be73, 0xe555b2f3, 0x6e087eaf, 0x084d329c}, /* Rims */
/* Viewperf13/CATIA_car_04 */
{0x631da72a, 0xc971e849, 0xd6489a15, 0xf7c8dddb, 0xe8efd982}, /* Headlights */
{0x85984b88, 0xd16b8fee, 0x0d49d97b, 0x5f6cc66e, 0xadcafad9}, /* Rims */
{0xad023488, 0x09930735, 0xb0567e58, 0x336dce36, 0xe3c1e448}, /* Tires */
{0xdcc4a549, 0x587873fa, 0xeed94361, 0x9a47cbff, 0x846d0167}, /* Windows */
{0xfa0074a2, 0xef868430, 0x87935a0c, 0x19bc96be, 0xb5b95c74}, /* Body */
{0x55207b90, 0x08fa2f8f, 0x9db62464, 0xadba6570, 0xb6d5d962, 0xf434bff5, 0x46a34d64, 0x021bfb45}, /* Headlights */
{0x83fbdd6a, 0x231b027e, 0x6f142248, 0x2b3045de, 0xd2a4f460, 0x59dfb8d8, 0x6dbc00f9, 0xcca13143}, /* Rims */
{0x88ed3a0a, 0xf128d384, 0x8161fdac, 0xd10cb257, 0x5e63db2d, 0x56798b6f, 0x881e81ee, 0xa4e937d4}, /* Tires */
{0xbf84697c, 0x3bc75bb6, 0x9d012175, 0x2dd90bcf, 0x0562f0ed, 0x5aa80e62, 0xb5793ae3, 0x9127bcab}, /* Windows */
{0x47a3eb4b, 0x136f676d, 0x94045ed3, 0x57b00972, 0x8cda7550, 0x88327fda, 0x37f7cf37, 0x66db05e3}, /* Body */
};
for (unsigned i = 0; i < ARRAY_SIZE(shader_sha1s); i++) {
if (_mesa_printed_sha1_equal(shader->info.source_sha1, shader_sha1s[i])) {
for (unsigned i = 0; i < ARRAY_SIZE(shader_blake3s); i++) {
if (_mesa_printed_blake3_equal(shader->info.source_blake3, shader_blake3s[i])) {
options.disallow_undef_to_nan = true;
break;
}

View file

@ -32,7 +32,7 @@
#include "compiler/shader_enums.h"
#include "util/half_float.h"
#include "util/memstream.h"
#include "util/mesa-sha1.h"
#include "util/mesa-blake3.h"
#include "vulkan/vulkan_core.h"
#include "nir.h"
@ -2410,8 +2410,8 @@ print_shader_info(const struct shader_info *info, FILE *fp)
{
fprintf(fp, "shader: %s\n", gl_shader_stage_name(info->stage));
fprintf(fp, "source_sha1: {");
_mesa_sha1_print(fp, info->source_sha1);
fprintf(fp, "source_blake3: {");
_mesa_blake3_print(fp, info->source_blake3);
fprintf(fp, "}\n");
if (info->name)

View file

@ -26,7 +26,7 @@
#define SHADER_INFO_H
#include "util/bitset.h"
#include "util/sha1/sha1.h"
#include "util/mesa-blake3.h"
#include "shader_enums.h"
#include <stdint.h>
@ -46,8 +46,8 @@ typedef struct shader_info {
/* Shader is internal, and should be ignored by things like NIR_DEBUG=print */
bool internal;
/* SHA1 of the original source, used by shader detection in drivers. */
uint8_t source_sha1[SHA1_DIGEST_LENGTH];
/* BLAKE3 of the original source, used by shader detection in drivers. */
blake3_hash source_blake3;
/** The shader stage, such as MESA_SHADER_VERTEX. */
gl_shader_stage stage:8;

View file

@ -37,6 +37,7 @@
#include "util/u_math.h"
#include "util/u_string.h"
#include "util/u_debug.h"
#include "util/mesa-blake3.h"
#include <stdio.h>
@ -6746,7 +6747,7 @@ spirv_to_nir(const uint32_t *words, size_t word_count,
b->shader->info.subgroup_size = options->subgroup_size;
b->shader->info.float_controls_execution_mode = options->float_controls_execution_mode;
b->shader->info.cs.shader_index = options->shader_index;
_mesa_sha1_compute(words, word_count * sizeof(uint32_t), b->shader->info.source_sha1);
_mesa_blake3_compute(words, word_count * sizeof(uint32_t), b->shader->info.source_blake3);
/* Skip the SPIR-V header, handled at vtn_create_builder */
words+= 5;

View file

@ -2074,7 +2074,7 @@ iris_compile_tcs(struct iris_screen *screen,
assert(screen->elk);
nir = elk_nir_create_passthrough_tcs(mem_ctx, screen->elk, &elk_key);
}
source_hash = *(uint32_t*)nir->info.source_sha1;
source_hash = *(uint32_t*)nir->info.source_blake3;
}
iris_setup_uniforms(devinfo, mem_ctx, nir, 0, &system_values,
@ -3198,8 +3198,8 @@ iris_create_uncompiled_shader(struct iris_screen *screen,
update_so_info(&ish->stream_output, nir->info.outputs_written);
}
/* Use lowest dword of source shader sha1 for shader hash. */
ish->source_hash = *(uint32_t*)nir->info.source_sha1;
/* Use lowest dword of source shader blake3 for shader hash. */
ish->source_hash = *(uint32_t*)nir->info.source_blake3;
if (screen->disk_cache) {
/* Serialize the NIR to a binary blob that we can hash for the disk

View file

@ -1362,7 +1362,7 @@ static unsigned si_varying_expression_max_cost(nir_shader *producer, nir_shader
unsigned num_profiles = si_get_num_shader_profiles();
for (unsigned i = 0; i < num_profiles; i++) {
if (_mesa_printed_sha1_equal(consumer->info.source_sha1, si_shader_profiles[i].sha1)) {
if (_mesa_printed_blake3_equal(consumer->info.source_blake3, si_shader_profiles[i].blake3)) {
if (si_shader_profiles[i].options & SI_PROFILE_NO_OPT_UNIFORM_VARYINGS)
return 0; /* only propagate constants */
break;

View file

@ -1451,8 +1451,8 @@ static void si_dump_shader_key(const struct si_shader *shader, FILE *f)
gl_shader_stage stage = shader->selector->stage;
fprintf(f, "SHADER KEY\n");
fprintf(f, " source_sha1 = {");
_mesa_sha1_print(f, shader->selector->info.base.source_sha1);
fprintf(f, " source_blake3 = {");
_mesa_blake3_print(f, shader->selector->info.base.source_blake3);
fprintf(f, "}\n");
switch (stage) {

View file

@ -114,7 +114,7 @@
#include "shader_info.h"
#include "ac_binary.h"
#include "ac_gpu_info.h"
#include "util/mesa-sha1.h"
#include "util/mesa-blake3.h"
#include "util/u_live_shader_cache.h"
#include "util/u_queue.h"
#include "si_pm4.h"
@ -298,7 +298,7 @@ enum
#define SI_NGG_CULL_GET_CLIP_PLANE_ENABLE(x) (((x) >> 5) & 0xff)
struct si_shader_profile {
uint32_t sha1[SHA1_DIGEST_LENGTH32];
uint32_t blake3[BLAKE3_OUT_LEN32];
uint32_t options;
};

View file

@ -622,7 +622,7 @@ void si_nir_scan_shader(struct si_screen *sscreen, const struct nir_shader *nir,
/* Get options from shader profiles. */
for (unsigned i = 0; i < ARRAY_SIZE(si_shader_profiles); i++) {
if (_mesa_printed_sha1_equal(info->base.source_sha1, si_shader_profiles[i].sha1)) {
if (_mesa_printed_blake3_equal(info->base.source_blake3, si_shader_profiles[i].blake3)) {
info->options = si_shader_profiles[i].options;
break;
}

View file

@ -35,6 +35,7 @@
#include "util/glheader.h"
#include "main/menums.h"
#include "util/mesa-sha1.h"
#include "util/mesa-blake3.h"
#include "compiler/shader_info.h"
#include "compiler/glsl/list.h"
#include "compiler/glsl/ir_uniform.h"
@ -156,12 +157,12 @@ struct gl_shader
/** SHA1 of the pre-processed source used by the disk cache. */
uint8_t disk_cache_sha1[SHA1_DIGEST_LENGTH];
/** SHA1 of the original source before replacement, set by glShaderSource. */
uint8_t source_sha1[SHA1_DIGEST_LENGTH];
/** SHA1 of FallbackSource (a copy of some original source before replacement). */
uint8_t fallback_source_sha1[SHA1_DIGEST_LENGTH];
/** SHA1 of the current compiled source, set by successful glCompileShader. */
uint8_t compiled_source_sha1[SHA1_DIGEST_LENGTH];
/** BLAKE3 of the original source before replacement, set by glShaderSource. */
blake3_hash source_blake3;
/** BLAKE3 of FallbackSource (a copy of some original source before replacement). */
blake3_hash fallback_source_blake3;
/** BLAKE3 of the current compiled source, set by successful glCompileShader. */
blake3_hash compiled_source_blake3;
const GLchar *Source; /**< Source code string */
const GLchar *FallbackSource; /**< Fallback string used by on-disk cache*/
@ -236,8 +237,8 @@ struct gl_linked_shader
{
gl_shader_stage Stage;
/** All gl_shader::compiled_source_sha1 combined. */
uint8_t linked_source_sha1[SHA1_DIGEST_LENGTH];
/** All gl_shader::compiled_source_blake3 combined. */
blake3_hash linked_source_blake3;
struct gl_program *Program; /**< Post-compile assembly code */

View file

@ -1154,7 +1154,7 @@ get_shader_source(struct gl_context *ctx, GLuint shader, GLsizei maxLength,
*/
static void
set_shader_source(struct gl_shader *sh, const GLchar *source,
const uint8_t original_sha1[SHA1_DIGEST_LENGTH])
const blake3_hash original_blake3)
{
assert(sh);
@ -1173,7 +1173,7 @@ set_shader_source(struct gl_shader *sh, const GLchar *source,
* fallback.
*/
sh->FallbackSource = sh->Source;
memcpy(sh->fallback_source_sha1, sh->source_sha1, SHA1_DIGEST_LENGTH);
memcpy(sh->fallback_source_blake3, sh->source_blake3, BLAKE3_OUT_LEN);
sh->Source = source;
} else {
/* free old shader source string and install new one */
@ -1181,7 +1181,7 @@ set_shader_source(struct gl_shader *sh, const GLchar *source,
sh->Source = source;
}
memcpy(sh->source_sha1, original_sha1, SHA1_DIGEST_LENGTH);
memcpy(sh->source_blake3, original_blake3, BLAKE3_OUT_LEN);
}
static void
@ -2145,8 +2145,8 @@ shader_source(struct gl_context *ctx, GLuint shaderObj, GLsizei count,
source[totalLength - 2] = '\0';
/* Compute the original source sha1 before shader replacement. */
uint8_t original_sha1[SHA1_DIGEST_LENGTH];
_mesa_sha1_compute(source, strlen(source), original_sha1);
blake3_hash original_blake3;
_mesa_blake3_compute(source, strlen(source), original_blake3);
#ifdef ENABLE_SHADER_CACHE
GLcharARB *replacement;
@ -2154,16 +2154,16 @@ 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, original_sha1);
_mesa_dump_shader_source(sh->Stage, source, original_blake3);
replacement = _mesa_read_shader_source(sh->Stage, source, original_sha1);
replacement = _mesa_read_shader_source(sh->Stage, source, original_blake3);
if (replacement) {
free(source);
source = replacement;
}
#endif /* ENABLE_SHADER_CACHE */
set_shader_source(sh, source, original_sha1);
set_shader_source(sh, source, original_blake3);
free(offsets);
}

View file

@ -897,7 +897,8 @@ prog_to_nir(const struct gl_context *ctx, const struct gl_program *prog,
s->info.separate_shader = true;
s->info.io_lowered = false;
s->info.internal = false;
memcpy(s->info.source_sha1, c->build.shader->info.source_sha1, 20);
memcpy(s->info.source_blake3, c->build.shader->info.source_blake3, BLAKE3_OUT_LEN);
/* ARB_vp: */
if (prog->arb.IsPositionInvariant) {

View file

@ -544,8 +544,8 @@ st_link_glsl_to_nir(struct gl_context *ctx,
prog->nir = glsl_to_nir(&st->ctx->Const, shader_program, shader->Stage, options);
}
memcpy(prog->nir->info.source_sha1, shader->linked_source_sha1,
SHA1_DIGEST_LENGTH);
memcpy(prog->nir->info.source_blake3, shader->linked_source_blake3,
BLAKE3_OUT_LEN);
nir_shader_gather_info(prog->nir, nir_shader_get_entrypoint(prog->nir));
if (!st->ctx->SoftFP64 && ((prog->nir->info.bit_sizes_int | prog->nir->info.bit_sizes_float) & 64) &&