Module: Mesa Branch: main Commit: 9b840df9f6549bb01aa3e71133d63423cc0614be URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=9b840df9f6549bb01aa3e71133d63423cc0614be
Author: Samuel Pitoiset <samuel.pitoi...@gmail.com> Date: Tue Nov 7 12:00:02 2023 +0100 radv: add drirc options to force re-compilation of shaders when needed On Steam Deck, shaders are pre-compiled for better performance (less stuttering, less CPU usage, etc). But when a compiler fix needs to be backported, there is currently no way to handle this properly. This introduces 3 drirc options radv_override_{graphics,compute,ray_tracing}_shader_version in order to force the driver to re-compile pipelines when needed. By default, the shader version is 0 for all pipelines. When one drirc is set for a specific game, RADV will re-compile all pipelines only once with the compiler fix included (because the pipeline key would be different). Signed-off-by: Samuel Pitoiset <samuel.pitoi...@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26094> --- src/amd/vulkan/radv_instance.c | 10 ++++++++++ src/amd/vulkan/radv_pipeline_compute.c | 7 ++++++- src/amd/vulkan/radv_pipeline_graphics.c | 2 ++ src/amd/vulkan/radv_pipeline_rt.c | 2 ++ src/amd/vulkan/radv_private.h | 3 +++ src/amd/vulkan/radv_shader.h | 3 +++ src/util/driconf.h | 17 +++++++++++++++++ 7 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/amd/vulkan/radv_instance.c b/src/amd/vulkan/radv_instance.c index abc410e33b8..57685184d69 100644 --- a/src/amd/vulkan/radv_instance.c +++ b/src/amd/vulkan/radv_instance.c @@ -152,6 +152,9 @@ static const driOptionDescription radv_dri_options[] = { DRI_CONF_RADV_FLUSH_BEFORE_TIMESTAMP_WRITE(false) DRI_CONF_RADV_RT_WAVE64(false) DRI_CONF_DUAL_COLOR_BLEND_BY_LOCATION(false) + DRI_CONF_RADV_OVERRIDE_GRAPHICS_SHADER_VERSION(0) + DRI_CONF_RADV_OVERRIDE_COMPUTE_SHADER_VERSION(0) + DRI_CONF_RADV_OVERRIDE_RAY_TRACING_SHADER_VERSION(0) DRI_CONF_RADV_APP_LAYER() DRI_CONF_SECTION_END }; @@ -208,6 +211,13 @@ radv_init_dri_options(struct radv_instance *instance) instance->force_rt_wave64 = driQueryOptionb(&instance->dri_options, "radv_rt_wave64"); instance->dual_color_blend_by_location = driQueryOptionb(&instance->dri_options, "dual_color_blend_by_location"); + + instance->override_graphics_shader_version = + driQueryOptioni(&instance->dri_options, "radv_override_graphics_shader_version"); + instance->override_compute_shader_version = + driQueryOptioni(&instance->dri_options, "radv_override_compute_shader_version"); + instance->override_ray_tracing_shader_version = + driQueryOptioni(&instance->dri_options, "radv_override_ray_tracing_shader_version"); } static const struct vk_instance_extension_table radv_instance_extensions_supported = { diff --git a/src/amd/vulkan/radv_pipeline_compute.c b/src/amd/vulkan/radv_pipeline_compute.c index f005df8adce..c89a74e50b8 100644 --- a/src/amd/vulkan/radv_pipeline_compute.c +++ b/src/amd/vulkan/radv_pipeline_compute.c @@ -109,7 +109,12 @@ static struct radv_pipeline_key radv_generate_compute_pipeline_key(const struct radv_device *device, const struct radv_compute_pipeline *pipeline, const VkComputePipelineCreateInfo *pCreateInfo) { - return radv_generate_pipeline_key(device, &pCreateInfo->stage, 1, pipeline->base.create_flags, pCreateInfo->pNext); + struct radv_pipeline_key key = + radv_generate_pipeline_key(device, &pCreateInfo->stage, 1, pipeline->base.create_flags, pCreateInfo->pNext); + + key.shader_version = device->instance->override_compute_shader_version; + + return key; } void diff --git a/src/amd/vulkan/radv_pipeline_graphics.c b/src/amd/vulkan/radv_pipeline_graphics.c index 8f458ce46ce..1b288ad0efc 100644 --- a/src/amd/vulkan/radv_pipeline_graphics.c +++ b/src/amd/vulkan/radv_pipeline_graphics.c @@ -1815,6 +1815,8 @@ radv_generate_graphics_pipeline_key(const struct radv_device *device, const stru struct radv_pipeline_key key = radv_generate_pipeline_key(device, pCreateInfo->pStages, pCreateInfo->stageCount, pipeline->base.create_flags, pCreateInfo->pNext); + key.shader_version = device->instance->override_graphics_shader_version; + key.lib_flags = lib_flags; key.has_multiview_view_index = state->rp ? !!state->rp->view_mask : 0; diff --git a/src/amd/vulkan/radv_pipeline_rt.c b/src/amd/vulkan/radv_pipeline_rt.c index 21e2cbec28d..e5ef87e8d02 100644 --- a/src/amd/vulkan/radv_pipeline_rt.c +++ b/src/amd/vulkan/radv_pipeline_rt.c @@ -90,6 +90,8 @@ radv_generate_rt_pipeline_key(const struct radv_device *device, const struct rad struct radv_pipeline_key key = radv_generate_pipeline_key(device, pCreateInfo->pStages, pCreateInfo->stageCount, pipeline->base.base.create_flags, pCreateInfo->pNext); + key.shader_version = device->instance->override_ray_tracing_shader_version; + if (pCreateInfo->pLibraryInfo) { for (unsigned i = 0; i < pCreateInfo->pLibraryInfo->libraryCount; ++i) { RADV_FROM_HANDLE(radv_pipeline, pipeline_lib, pCreateInfo->pLibraryInfo->pLibraries[i]); diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 26412019a0c..8f69f5e282c 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -419,6 +419,9 @@ struct radv_instance { bool force_rt_wave64; bool dual_color_blend_by_location; char *app_layer; + uint8_t override_graphics_shader_version; + uint8_t override_compute_shader_version; + uint8_t override_ray_tracing_shader_version; }; VkResult radv_init_wsi(struct radv_physical_device *physical_device); diff --git a/src/amd/vulkan/radv_shader.h b/src/amd/vulkan/radv_shader.h index 0582e6b1e47..b2e8a8e7bea 100644 --- a/src/amd/vulkan/radv_shader.h +++ b/src/amd/vulkan/radv_shader.h @@ -101,6 +101,9 @@ struct radv_pipeline_key { uint32_t vertex_robustness1 : 1; uint32_t mesh_fast_launch_2 : 1; + /* Pipeline shader version (up to 8) to force re-compilation when RADV_BUILD_ID_OVERRIDE is enabled. */ + uint32_t shader_version : 3; + struct radv_shader_stage_key stage_info[MESA_VULKAN_SHADER_STAGES]; struct { diff --git a/src/util/driconf.h b/src/util/driconf.h index 12649eb8e2d..d3d7e73ab79 100644 --- a/src/util/driconf.h +++ b/src/util/driconf.h @@ -678,6 +678,23 @@ DRI_CONF_OPT_B(radv_rt_wave64, def, \ "Force wave64 in RT shaders") +/** + * Overrides for forcing re-compilation of pipelines when RADV_BUILD_ID_OVERRIDE is enabled. + * These need to be bumped every time a compiler bugfix is backported (up to 8 shader + * versions are supported). + */ +#define DRI_CONF_RADV_OVERRIDE_GRAPHICS_SHADER_VERSION(def) \ + DRI_CONF_OPT_I(radv_override_graphics_shader_version, def, 0, 7, \ + "Override the shader version of graphics pipelines to force re-compilation. (0 = default)") + +#define DRI_CONF_RADV_OVERRIDE_COMPUTE_SHADER_VERSION(def) \ + DRI_CONF_OPT_I(radv_override_compute_shader_version, def, 0, 7, \ + "Override the shader version of compute pipelines to force re-compilation. (0 = default)") + +#define DRI_CONF_RADV_OVERRIDE_RAY_TRACING_SHADER_VERSION(def) \ + DRI_CONF_OPT_I(radv_override_ray_tracing_shader_version, def, 0, 7, \ + "Override the shader version of ray tracing pipelines to force re-compilation. (0 = default)") + #define DRI_CONF_RADV_APP_LAYER() DRI_CONF_OPT_S_NODEF(radv_app_layer, "Select an application layer.") /**