libagx: fix wraparound issue with robust draw kernel

fixes dEQP-VK.robustness.index_access.draw_multi_indexed_2 with hard faults.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33682>
This commit is contained in:
Alyssa Rosenzweig
2025-01-24 17:15:36 -05:00
committed by Marge Bot
parent bec073d3ca
commit 479d2ab53e

View File

@@ -2,6 +2,7 @@
* Copyright 2024 Valve Corporation
* SPDX-License-Identifier: MIT
*/
#include "asahi/lib/agx_abi.h"
#include "compiler/libcl/libcl_vk.h"
#include "agx_pack.h"
#include "geometry.h"
@@ -136,7 +137,15 @@ libagx_draw_robust_index(global uint32_t *vdm,
cmd->indexCount, cmd->instanceCount, cmd->firstIndex, cmd->vertexOffset,
cmd->firstInstance, in_buf_ptr, in_buf_range_B, index_size, restart);
if (agx_direct_draw_overreads_indices(draw)) {
if (agx_indices_to_B(cmd->firstIndex, index_size) >= in_buf_range_B) {
/* If the entire draw is out-of-bounds, skip it. We handle this specially
* for both performance and to avoid integer wrapping issues in the main
* code path (where cmd->firstIndex could get treated as a negative).
*/
draw.index_buffer = AGX_ZERO_PAGE_ADDRESS;
draw.index_buffer_range_B = 4;
draw.start = 0;
} else if (agx_direct_draw_overreads_indices(draw)) {
constant void *in_buf = (constant void *)agx_draw_index_buffer(draw);
uint in_size_el = agx_draw_index_range_el(draw);
uint in_size_B = agx_indices_to_B(in_size_el, index_size);