From a9831caa144f9944fec936608faf03d253e9bb7d Mon Sep 17 00:00:00 2001 From: Friedrich Vock Date: Fri, 12 Jan 2024 13:03:55 +0100 Subject: [PATCH] radv/rt: Add workaround to make leaves always active DOOM Eternal builds acceleration structures with inactive primitives and tries to make them active in later AS updates. This is disallowed by the spec and triggers a GPU hang. Fix the hang by working around the bug. Cc: mesa-stable Part-of: --- src/amd/vulkan/bvh/build_helpers.h | 1 + src/amd/vulkan/bvh/leaf.comp | 8 ++++++++ src/amd/vulkan/bvh/meson.build | 7 ++++++- src/amd/vulkan/radv_acceleration_structure.c | 15 ++++++++++++--- src/amd/vulkan/radv_instance.c | 4 ++++ src/amd/vulkan/radv_private.h | 1 + src/util/00-radv-defaults.conf | 1 + src/util/driconf.h | 4 ++++ 8 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/amd/vulkan/bvh/build_helpers.h b/src/amd/vulkan/bvh/build_helpers.h index adbf621a308..59584f1caf8 100644 --- a/src/amd/vulkan/bvh/build_helpers.h +++ b/src/amd/vulkan/bvh/build_helpers.h @@ -156,6 +156,7 @@ #define VK_GEOMETRY_TYPE_TRIANGLES_KHR 0 #define VK_GEOMETRY_TYPE_AABBS_KHR 1 +#define VK_GEOMETRY_TYPE_INSTANCES_KHR 2 #define VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR 1 #define VK_GEOMETRY_INSTANCE_TRIANGLE_FLIP_FACING_BIT_KHR 2 diff --git a/src/amd/vulkan/bvh/leaf.comp b/src/amd/vulkan/bvh/leaf.comp index ba706fbb91c..259532d9ae9 100644 --- a/src/amd/vulkan/bvh/leaf.comp +++ b/src/amd/vulkan/bvh/leaf.comp @@ -87,6 +87,14 @@ main(void) is_active = build_instance(bounds, src_ptr, dst_ptr, global_id); } +#if ALWAYS_ACTIVE + if (!is_active && args.geom_data.geometry_type != VK_GEOMETRY_TYPE_INSTANCES_KHR) { + bounds.min = vec3(0.0); + bounds.max = vec3(0.0); + is_active = true; + } +#endif + if (is_active) { REF(radv_ir_node) ir_node = INDEX(radv_ir_node, args.ir, primitive_id); DEREF(ir_node).aabb = bounds; diff --git a/src/amd/vulkan/bvh/meson.build b/src/amd/vulkan/bvh/meson.build index 017a0bfc28e..5f654a9f438 100644 --- a/src/amd/vulkan/bvh/meson.build +++ b/src/amd/vulkan/bvh/meson.build @@ -53,7 +53,12 @@ bvh_shaders = [ [ 'leaf.comp', 'leaf', - [], + ['ALWAYS_ACTIVE=0'], + ], + [ + 'leaf.comp', + 'leaf_always_active', + ['ALWAYS_ACTIVE=1'], ], [ 'morton.comp', diff --git a/src/amd/vulkan/radv_acceleration_structure.c b/src/amd/vulkan/radv_acceleration_structure.c index 0b2b82a660b..8f4872ad611 100644 --- a/src/amd/vulkan/radv_acceleration_structure.c +++ b/src/amd/vulkan/radv_acceleration_structure.c @@ -41,6 +41,10 @@ static const uint32_t leaf_spv[] = { #include "bvh/leaf.spv.h" }; +static const uint32_t leaf_always_active_spv[] = { +#include "bvh/leaf_always_active.spv.h" +}; + static const uint32_t morton_spv[] = { #include "bvh/morton.spv.h" }; @@ -538,9 +542,14 @@ radv_device_init_accel_struct_build_state(struct radv_device *device) if (device->meta_state.accel_struct_build.radix_sort) goto exit; - result = create_build_pipeline_spv(device, leaf_spv, sizeof(leaf_spv), sizeof(struct leaf_args), - &device->meta_state.accel_struct_build.leaf_pipeline, - &device->meta_state.accel_struct_build.leaf_p_layout); + if (device->instance->drirc.force_active_accel_struct_leaves) + result = create_build_pipeline_spv(device, leaf_always_active_spv, sizeof(leaf_always_active_spv), + sizeof(struct leaf_args), &device->meta_state.accel_struct_build.leaf_pipeline, + &device->meta_state.accel_struct_build.leaf_p_layout); + else + result = create_build_pipeline_spv(device, leaf_spv, sizeof(leaf_spv), sizeof(struct leaf_args), + &device->meta_state.accel_struct_build.leaf_pipeline, + &device->meta_state.accel_struct_build.leaf_p_layout); if (result != VK_SUCCESS) goto exit; diff --git a/src/amd/vulkan/radv_instance.c b/src/amd/vulkan/radv_instance.c index 6f47daba764..4279bc4af3d 100644 --- a/src/amd/vulkan/radv_instance.c +++ b/src/amd/vulkan/radv_instance.c @@ -160,6 +160,7 @@ static const driOptionDescription radv_dri_options[] = { DRI_CONF_RADV_OVERRIDE_COMPUTE_SHADER_VERSION(0) DRI_CONF_RADV_OVERRIDE_RAY_TRACING_SHADER_VERSION(0) DRI_CONF_RADV_SSBO_NON_UNIFORM(false) + DRI_CONF_RADV_FORCE_ACTIVE_ACCEL_STRUCT_LEAVES(false) DRI_CONF_RADV_APP_LAYER() DRI_CONF_SECTION_END }; @@ -251,6 +252,9 @@ radv_init_dri_options(struct radv_instance *instance) instance->drirc.vk_require_etc2 = driQueryOptionb(&instance->drirc.options, "vk_require_etc2"); instance->drirc.vk_require_astc = driQueryOptionb(&instance->drirc.options, "vk_require_astc"); + + instance->drirc.force_active_accel_struct_leaves = + driQueryOptionb(&instance->drirc.options, "radv_force_active_accel_struct_leaves"); } 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 ac2f5a170f8..1baea731ccf 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -386,6 +386,7 @@ struct radv_instance { bool report_llvm9_version_string; bool vk_require_etc2; bool vk_require_astc; + bool force_active_accel_struct_leaves; char *app_layer; uint8_t override_graphics_shader_version; uint8_t override_compute_shader_version; diff --git a/src/util/00-radv-defaults.conf b/src/util/00-radv-defaults.conf index d58c86c1909..d7e6115c866 100644 --- a/src/util/00-radv-defaults.conf +++ b/src/util/00-radv-defaults.conf @@ -106,6 +106,7 @@ Application bugs worked around in this file: diff --git a/src/util/driconf.h b/src/util/driconf.h index e91bf81a381..32ccf87a5e1 100644 --- a/src/util/driconf.h +++ b/src/util/driconf.h @@ -716,6 +716,10 @@ #define DRI_CONF_RADV_CLEAR_LDS(def) \ DRI_CONF_OPT_B(radv_clear_lds, def, "Clear LDS at the end of shaders. Might decrease performance.") +#define DRI_CONF_RADV_FORCE_ACTIVE_ACCEL_STRUCT_LEAVES(def) \ + DRI_CONF_OPT_B(radv_force_active_accel_struct_leaves, def, \ + "Force leaf nodes of acceleration structures to be marked active.") + /** * \brief ANV specific configuration options */