diff --git a/src/amd/vulkan/bvh/encode_triangles_gfx12.comp b/src/amd/vulkan/bvh/encode_triangles_gfx12.comp index 6dee0c281bd..7b47f477210 100644 --- a/src/amd/vulkan/bvh/encode_triangles_gfx12.comp +++ b/src/amd/vulkan/bvh/encode_triangles_gfx12.comp @@ -328,9 +328,23 @@ main() vertex_used[i] = false; } } else { - uint32_t chosen_invocation = - findMSB(radv_ballot(cluster, !assigned && required_bit_size == min_required_bit_size)); - if (cluster.invocation_index != chosen_invocation && !assigned) { + uint32_t candidate_mask = radv_ballot(cluster, !assigned && required_bit_size == min_required_bit_size); + + /* Always choose a quad as the first node to make sure that a potential single triangle node will have the + * highest hw_node_index. + */ + if (assigned_mask == 0) { + uint32_t quad_mask = radv_ballot(cluster, !assigned && pair_index_node_index1 != RADV_BVH_INVALID_NODE); + if (quad_mask != 0) { + uint32_t combined_mask = candidate_mask & quad_mask; + if (combined_mask != 0) + candidate_mask = combined_mask; + else + candidate_mask = quad_mask; + } + } + + if (cluster.invocation_index != findMSB(candidate_mask) && !assigned) { vertex_indices = UNASSIGNED_VERTEX_INDICES; for (uint32_t i = 0; i < 6; i++) vertex_used[i] = false;