From 9d524bbd21340338d9026e3a0c49c0c4657cda77 Mon Sep 17 00:00:00 2001 From: Natalie Vock Date: Fri, 19 Sep 2025 20:56:52 +0200 Subject: [PATCH] radv/bvh: Encode empty AS bounds as NaN If there are no leaves, the root node bounds still span -inf/inf. Making empty BLASs infinite-sized guarantees ray traversal needs to enter the BLAS (and immediately exit because it's empty). Remove the BLAS from the BVH entirely by marking its bounds as NaN. As a bonus, this works around RADV encountering issues in Silent Hill 2 on RDNA4 due to infinite-sized BVHs. Cc: mesa-stable Part-of: (cherry picked from commit 52c7b0d20c88620fd55d21a62468211674559978) --- .pick_status.json | 2 +- src/amd/vulkan/bvh/encode.comp | 6 +++++- src/amd/vulkan/bvh/encode_gfx12.comp | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 035d5f03cea..953c0b919c4 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -6024,7 +6024,7 @@ "description": "radv/bvh: Encode empty AS bounds as NaN", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/amd/vulkan/bvh/encode.comp b/src/amd/vulkan/bvh/encode.comp index 6c0cb53aa4e..a12021d3a42 100644 --- a/src/amd/vulkan/bvh/encode.comp +++ b/src/amd/vulkan/bvh/encode.comp @@ -243,10 +243,14 @@ main() } if (is_root_node) { + vk_aabb aabb = src.base.aabb; + if (DEREF(args.header).active_leaf_count == 0) + aabb = vk_aabb(vec3(NAN), vec3(NAN)); + REF(radv_accel_struct_header) header = REF(radv_accel_struct_header)(args.output_bvh - args.output_bvh_offset); DEREF(header).bvh_offset = args.output_bvh_offset; DEREF(header).root_flags = src.flags; - DEREF(header).aabb = src.base.aabb; + DEREF(header).aabb = aabb; set_parent(RADV_BVH_ROOT_NODE, RADV_BVH_INVALID_NODE); } diff --git a/src/amd/vulkan/bvh/encode_gfx12.comp b/src/amd/vulkan/bvh/encode_gfx12.comp index 06ddc3b895b..e62a6d50644 100644 --- a/src/amd/vulkan/bvh/encode_gfx12.comp +++ b/src/amd/vulkan/bvh/encode_gfx12.comp @@ -271,8 +271,12 @@ encode_gfx12(uint32_t ir_leaf_node_size, REF(vk_ir_box_node) intermediate_intern } if (is_root_node && cluster.invocation_index == 0) { + vk_aabb aabb = src.base.aabb; + if (DEREF(args.header).active_leaf_count == 0) + aabb = vk_aabb(vec3(NAN), vec3(NAN)); + REF(radv_accel_struct_header) header = REF(radv_accel_struct_header)(args.output_base); - DEREF(header).aabb = src.base.aabb; + DEREF(header).aabb = aabb; DEREF(header).bvh_offset = args.output_bvh_offset; set_parent(RADV_BVH_ROOT_NODE, RADV_BVH_INVALID_NODE);