tu: add option to override the build ID

Add the tu-build-id meson option to force the build ID to a particular
value. This allows us the share the shader cache between different
builds. This enables, for example, sharing the cache between x86
drm-shim and aarch64 native builds.

Also add tu_override_{graphics,compute}_shader_version driconf options
to force recompilation of shaders even when tu-build-id stays the same.

Signed-off-by: Job Noorman <jnoorman@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41954>
This commit is contained in:
Job Noorman 2026-06-04 07:51:55 +02:00 committed by Marge Bot
parent 59438fba2a
commit 5943d01e86
6 changed files with 45 additions and 1 deletions

View file

@ -760,6 +760,13 @@ option(
'Can be extracted with readelf -x .note.gnu.build-id'
)
option(
'tu-build-id',
type : 'string',
value : '',
description : 'Override build id for shader cache keys (hex string). '
)
option(
'min-windows-version',
type : 'integer',

View file

@ -150,6 +150,11 @@ if freedreno_kmds.contains('virtio')
tu_deps += dep_libdrm
endif
tu_build_id = get_option('tu-build-id')
if tu_build_id != ''
tu_flags += '-DTU_BUILD_ID_OVERRIDE="' + tu_build_id + '"'
endif
tu_tracepoints = custom_target(
'tu_tracepoints.[ch]',
input: 'tu_tracepoints.py',

View file

@ -52,6 +52,24 @@
uint64_t os_page_size = 4096;
static bool
tu_device_get_build_id(blake3_hasher *ctx)
{
#ifdef TU_BUILD_ID_OVERRIDE
{
assert(strlen(TU_BUILD_ID_OVERRIDE) % 2 == 0);
unsigned size = strlen(TU_BUILD_ID_OVERRIDE) / 2;
auto data = static_cast<unsigned char *>(ralloc_size(NULL, size));
mesa_hex_to_bytes(data, TU_BUILD_ID_OVERRIDE, size);
_mesa_blake3_update(ctx, data, size);
ralloc_free(data);
return true;
}
#else
return disk_cache_get_function_identifier((void *) tu_device_get_build_id, ctx);
#endif
}
static int
tu_device_get_cache_uuid(struct tu_physical_device *device, void *uuid)
{
@ -72,7 +90,7 @@ tu_device_get_cache_uuid(struct tu_physical_device *device, void *uuid)
memset(uuid, 0, VK_UUID_SIZE);
_mesa_blake3_init(&ctx);
if (!disk_cache_get_function_identifier((void *)tu_device_get_cache_uuid, &ctx))
if (!tu_device_get_build_id(&ctx))
return -1;
_mesa_blake3_update(&ctx, &chip_id, sizeof(chip_id));

View file

@ -100,6 +100,13 @@ def declare_options():
F("heap_memory_percent", 0.0, 0.0, 1.0, "Percentage of total system memory to report as gpu heap memory (0 = driver default)",
c_name="heap_memory_percent"),
I("tu_override_graphics_shader_version", 0, 0, 255,
"Override graphics shader version to force recompilation when TU_BUILD_ID_OVERRIDE is enabled.",
c_name="override_graphics_shader_version"),
I("tu_override_compute_shader_version", 0, 0, 255,
"Override compute shader version to force recompilation when TU_BUILD_ID_OVERRIDE is enabled.",
c_name="override_compute_shader_version"),
]
drirc_gen.add_common_vk_wsi_options(debug_options, perf_options)

View file

@ -1777,6 +1777,9 @@ tu_pipeline_builder_compile_shaders(struct tu_pipeline_builder *builder,
struct tu_shader_key keys[ARRAY_SIZE(stage_infos)] = { };
for (mesa_shader_stage stage = MESA_SHADER_VERTEX;
stage < ARRAY_SIZE(keys); stage = (mesa_shader_stage) (stage+1)) {
keys[stage].version =
builder->device->instance->drirc.misc.override_graphics_shader_version;
const VkPipelineShaderStageRequiredSubgroupSizeCreateInfo *subgroup_info = NULL;
if (stage_infos[stage])
subgroup_info = vk_find_struct_const(stage_infos[stage],
@ -4934,6 +4937,7 @@ tu_compute_pipeline_create(VkDevice device,
pipeline->base.active_stages = VK_SHADER_STAGE_COMPUTE_BIT;
struct tu_shader_key key = { };
key.version = dev->instance->drirc.misc.override_compute_shader_version;
bool allow_varying_subgroup_size =
(stage_info->flags &
VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT);

View file

@ -132,6 +132,9 @@ struct tu_shader_key {
bool custom_resolve;
bool emulate_alpha_to_coverage;
enum ir3_wavesize_option api_wavesize, real_wavesize;
/* Shader version to force recompilation when TU_BUILD_ID_OVERRIDE is used. */
uint8_t version;
};
/* Information needed for tu_shader creation that is gathered during NIR