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: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27034>
This commit is contained in:
Friedrich Vock 2024-01-12 13:03:55 +01:00 committed by Marge Bot
parent a18ea091af
commit a9831caa14
8 changed files with 37 additions and 4 deletions

View File

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

View File

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

View File

@ -53,7 +53,12 @@ bvh_shaders = [
[
'leaf.comp',
'leaf',
[],
['ALWAYS_ACTIVE=0'],
],
[
'leaf.comp',
'leaf_always_active',
['ALWAYS_ACTIVE=1'],
],
[
'morton.comp',

View File

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

View File

@ -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 = {

View File

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

View File

@ -106,6 +106,7 @@ Application bugs worked around in this file:
<application name="DOOM Eternal" application_name_match="DOOMEternal">
<option name="radv_zero_vram" value="true" />
<option name="radv_legacy_sparse_binding" value="true" />
<option name="radv_force_active_accel_struct_leaves" value="true" />
</application>
<application name="No Man's Sky" application_name_match="No Man's Sky">

View File

@ -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
*/