From 97641e5c9422430b74967a77ddb12f3e57604e4b Mon Sep 17 00:00:00 2001 From: Bas Nieuwenhuizen Date: Fri, 8 Jul 2022 18:18:13 +0200 Subject: [PATCH] radv: Add ability to override the build id for the cache. This would allow us to keep the shader cache key the same for updates that we know won't impact compilation on SteamOS. Reviewed-by: Samuel Pitoiset Part-of: --- meson_options.txt | 6 ++++++ src/amd/vulkan/meson.build | 5 +++++ src/amd/vulkan/radv_device.c | 34 ++++++++++++++++++++++++++++------ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/meson_options.txt b/meson_options.txt index b223bbc798d..7a5622101e9 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -542,3 +542,9 @@ option( value : 'auto', description : 'build gallium d3d12 with video support.', ) +option( + 'radv-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' +) \ No newline at end of file diff --git a/src/amd/vulkan/meson.build b/src/amd/vulkan/meson.build index 75f0685a77a..b9c4aa1d18b 100644 --- a/src/amd/vulkan/meson.build +++ b/src/amd/vulkan/meson.build @@ -153,6 +153,11 @@ if with_ld_version_script libvulkan_radeon_link_depends += files('vulkan.sym') endif +radv_build_id = get_option('radv-build-id') +if radv_build_id != '' + radv_flags += '-DRADV_BUILD_ID_OVERRIDE="' + radv_build_id + '"' +endif + libvulkan_radeon = shared_library( 'vulkan_radeon', [libradv_files, radv_entrypoints, sha1_h, radix_sort_spv], diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index fe6752ff841..52e918cf1e1 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -98,6 +98,19 @@ radv_get_current_time(void) return os_time_get_nano(); } +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 int radv_device_get_cache_uuid(struct radv_physical_device *pdevice, void *uuid) { @@ -109,13 +122,22 @@ radv_device_get_cache_uuid(struct radv_physical_device *pdevice, void *uuid) memset(uuid, 0, VK_UUID_SIZE); _mesa_sha1_init(&ctx); - if (!disk_cache_get_function_identifier(radv_device_get_cache_uuid, &ctx) -#ifdef LLVM_AVAILABLE - || (pdevice->use_llvm && - !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo, &ctx)) -#endif - ) +#ifdef RADV_BUILD_ID_OVERRIDE + { + char data[strlen(RADV_BUILD_ID_OVERRIDE) / 2]; + parse_hex(data, RADV_BUILD_ID_OVERRIDE, ARRAY_SIZE(data)); + _mesa_sha1_update(&ctx, data, ARRAY_SIZE(data)); + } +#else + if (!disk_cache_get_function_identifier(radv_device_get_cache_uuid, &ctx)) return -1; +#endif + +#ifdef LLVM_AVAILABLE + if (pdevice->use_llvm && + !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo, &ctx)) + return -1; +#endif _mesa_sha1_update(&ctx, &family, sizeof(family)); _mesa_sha1_update(&ctx, &ptr_size, sizeof(ptr_size));