From dc4be89e7cf8c99f3fadebc8f3f2d1a9f1da8ca1 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Thu, 19 Jun 2025 09:21:44 +0200 Subject: [PATCH] radeonsi: add a way to override the disk cache key with radeonsi-build-id This is similar to radv-build-id which is mainly used on SteamOS for shaders pre-compilation. For RadeonSI, it also useful to have this option to force the disk cache key to be uniq for redistributed shaders accross machines when it's safe. Signed-off-by: Samuel Pitoiset Part-of: --- meson.options | 8 ++++++++ src/gallium/drivers/radeonsi/meson.build | 5 +++++ src/gallium/drivers/radeonsi/si_pipe.c | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/meson.options b/meson.options index 20001bcaa5f..3f9fd67704c 100644 --- a/meson.options +++ b/meson.options @@ -750,6 +750,14 @@ option( 'Can be extracted with readelf -x .note.gnu.build-id' ) +option( + 'radeonsi-build-id', + type : 'string', + value : '', + description : 'Override build id for shader cache keys (hex string). ' + + 'Can be extracted with readelf -x .note.gnu.build-id' +) + option( 'min-windows-version', type : 'integer', diff --git a/src/gallium/drivers/radeonsi/meson.build b/src/gallium/drivers/radeonsi/meson.build index 03bd067a177..7c649cf4d09 100644 --- a/src/gallium/drivers/radeonsi/meson.build +++ b/src/gallium/drivers/radeonsi/meson.build @@ -154,6 +154,11 @@ if with_amdgpu_virtio libradeonsi_cflags += ['-DHAVE_AMDGPU_VIRTIO'] endif +radeonsi_build_id = get_option('radeonsi-build-id') +if radeonsi_build_id != '' + libradeonsi_cflags += '-DRADEONSI_BUILD_ID_OVERRIDE="' + radeonsi_build_id + '"' +endif + libradeonsi = static_library( 'radeonsi', [files_libradeonsi, sid_tables_h], diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c index 5ed5163953b..53d6c893ea8 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.c +++ b/src/gallium/drivers/radeonsi/si_pipe.c @@ -1108,6 +1108,18 @@ static void si_test_vmfault(struct si_screen *sscreen, uint64_t test_flags) exit(0); } +static void +parse_hex(char *out, const char *in, unsigned length) +{ + for (unsigned i = 0; i < length; ++i) + out[i] = 0; + + for (unsigned i = 0; i < 2 * length; ++i) { + unsigned v = in[i] <= '9' ? in[i] - '0' : (in[i] >= 'a' ? (in[i] - 'a' + 10) : (in[i] - 'A' + 10)); + out[i / 2] |= v << (4 * (1 - i % 2)); + } +} + static void si_disk_cache_create(struct si_screen *sscreen) { /* Don't use the cache if shader dumping is enabled. */ @@ -1120,8 +1132,17 @@ static void si_disk_cache_create(struct si_screen *sscreen) _mesa_sha1_init(&ctx); +#ifdef RADEONSI_BUILD_ID_OVERRIDE + { + unsigned size = strlen(RADEONSI_BUILD_ID_OVERRIDE) / 2; + char *data = alloca(size); + parse_hex(data, RADEONSI_BUILD_ID_OVERRIDE, size); + _mesa_sha1_update(&ctx, data, size); + } +#else if (!disk_cache_get_function_identifier(si_disk_cache_create, &ctx)) return; +#endif #if AMD_LLVM_AVAILABLE if (!disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo, &ctx))