From 479d2ab53e032d4e3ee240bfd5376a42fed42e43 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 24 Jan 2025 17:15:36 -0500 Subject: [PATCH] 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 Part-of: --- src/asahi/libagx/draws.cl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/asahi/libagx/draws.cl b/src/asahi/libagx/draws.cl index 12f8eb0a59e..c3c9d01bf3b 100644 --- a/src/asahi/libagx/draws.cl +++ b/src/asahi/libagx/draws.cl @@ -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);