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 <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17426>
This commit is contained in:
Bas Nieuwenhuizen 2022-07-08 18:18:13 +02:00 committed by Marge Bot
parent f286289c7f
commit 97641e5c94
3 changed files with 39 additions and 6 deletions

View File

@ -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'
)

View File

@ -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],

View File

@ -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));