From 0b251d43622391cbffad4a4e748e41223b2344fe Mon Sep 17 00:00:00 2001 From: Friedrich Vock Date: Wed, 3 May 2023 12:20:39 +0200 Subject: [PATCH] radv: Add driconf to always drain waves before writing timestamps UE4's Vulkan backend uses vkCmdWriteTimestamp with TOP_OF_PIPE to measure how long a workload took in the GPU Benchmark. This is wrong and writes the timestamp before the workload is actually finished, making it seem like the GPU is much faster than it actually is. This caused subsequent benchmark passes to contain way too big workloads, which caused soft hangs on slower GPUs. Fixes GPU hangs with Splitgate during automatic settings configuration. Cc: mesa-stable Part-of: --- src/amd/vulkan/radv_instance.c | 4 ++++ src/amd/vulkan/radv_private.h | 1 + src/amd/vulkan/radv_query.c | 5 +++++ src/util/00-radv-defaults.conf | 1 + src/util/driconf.h | 4 ++++ 5 files changed, 15 insertions(+) diff --git a/src/amd/vulkan/radv_instance.c b/src/amd/vulkan/radv_instance.c index e2431e0..ebd2787 100644 --- a/src/amd/vulkan/radv_instance.c +++ b/src/amd/vulkan/radv_instance.c @@ -144,6 +144,7 @@ static const driOptionDescription radv_dri_options[] = { DRI_CONF_RADV_ENABLE_UNIFIED_HEAP_ON_APU(false) DRI_CONF_RADV_TEX_NON_UNIFORM(false) DRI_CONF_RADV_RT(false) + DRI_CONF_RADV_FLUSH_BEFORE_TIMESTAMP_WRITE(false) DRI_CONF_RADV_APP_LAYER() DRI_CONF_SECTION_END }; @@ -202,6 +203,9 @@ radv_init_dri_options(struct radv_instance *instance) instance->tex_non_uniform = driQueryOptionb(&instance->dri_options, "radv_tex_non_uniform"); instance->app_layer = driQueryOptionstr(&instance->dri_options, "radv_app_layer"); + + instance->flush_before_timestamp_write = + driQueryOptionb(&instance->dri_options, "radv_flush_before_timestamp_write"); } static const struct vk_instance_extension_table radv_instance_extensions_supported = { diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 4d36407..fb4a6a3 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -413,6 +413,7 @@ struct radv_instance { bool flush_before_query_copy; bool enable_unified_heap_on_apu; bool tex_non_uniform; + bool flush_before_timestamp_write; char *app_layer; }; diff --git a/src/amd/vulkan/radv_query.c b/src/amd/vulkan/radv_query.c index 801f958..144b4a0 100644 --- a/src/amd/vulkan/radv_query.c +++ b/src/amd/vulkan/radv_query.c @@ -2145,6 +2145,11 @@ radv_CmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 sta radv_cs_add_buffer(cmd_buffer->device->ws, cs, pool->bo); + if (cmd_buffer->device->instance->flush_before_timestamp_write) { + /* Make sure previously launched waves have finished */ + cmd_buffer->state.flush_bits |= RADV_CMD_FLAG_PS_PARTIAL_FLUSH | RADV_CMD_FLAG_CS_PARTIAL_FLUSH; + } + si_emit_cache_flush(cmd_buffer); int num_queries = 1; diff --git a/src/util/00-radv-defaults.conf b/src/util/00-radv-defaults.conf index b7cf2c2..f127955 100644 --- a/src/util/00-radv-defaults.conf +++ b/src/util/00-radv-defaults.conf @@ -54,6 +54,7 @@ Application bugs worked around in this file: diff --git a/src/util/driconf.h b/src/util/driconf.h index f1d0a89..ea8976a 100644 --- a/src/util/driconf.h +++ b/src/util/driconf.h @@ -627,6 +627,10 @@ DRI_CONF_OPT_B(radv_rt, def, \ "Expose support for VK_KHR_ray_tracing_pipeline") +#define DRI_CONF_RADV_FLUSH_BEFORE_TIMESTAMP_WRITE(def) \ + DRI_CONF_OPT_B(radv_flush_before_timestamp_write, def, \ + "Wait for previous commands to finish before writing timestamps") + #define DRI_CONF_RADV_APP_LAYER() DRI_CONF_OPT_S_NODEF(radv_app_layer, "Select an application layer.") /** -- 2.7.4