radv/bvh: Prefer selecting quads as the first pair of a HW node

Is a single triangle is selected, it can be the case that the next iteration
can't merge any pair with the triangle. In that case, the HW node with a
single triangle will not have the highest hw_node_index, triggering an
assert.

Fixes: c18a7d0 ("radv: Emit compressed primitive nodes on GFX12")
Reviewed-by: Natalie Vock <natalie.vock@gmx.de>
(cherry picked from commit db38d1a98c)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40979>
This commit is contained in:
Konstantin Seurer 2026-02-02 16:49:28 +01:00 committed by Eric Engestrom
parent 392b4ab6b2
commit 573d326bc2
2 changed files with 18 additions and 4 deletions

View file

@ -1104,7 +1104,7 @@
"description": "radv/bvh: Prefer selecting quads as the first pair of a HW node",
"nominated": true,
"nomination_type": 2,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "c18a7d0e2b639659f97c29d54268e3d800ac5d5f",
"notes": null

View file

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