asahi: Clamp index buffer extent to what's read
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Thu, 31 Aug 2023 00:29:43 +0000 (20:29 -0400)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sun, 1 Oct 2023 16:32:11 +0000 (12:32 -0400)
This makes for cleaner agxdecodes, I think this matches what I've seen on the
macOS side but I might be misremembering. Certainly shouldn't hurt.

This only applies for direct draws.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
src/gallium/drivers/asahi/agx_state.c

index df9d9ed..52b99d6 100644 (file)
@@ -2961,14 +2961,15 @@ agx_index_buffer_direct_ptr(struct agx_batch *batch,
                             const struct pipe_draw_info *info, size_t *extent)
 {
    off_t offset = draw->start * info->index_size;
+   uint32_t max_extent = draw->count * info->index_size;
 
    if (!info->has_user_indices) {
       uint64_t base = agx_index_buffer_rsrc_ptr(batch, info, extent);
 
-      *extent = ALIGN_POT(*extent - offset, 4);
+      *extent = ALIGN_POT(MIN2(*extent - offset, max_extent), 4);
       return base + offset;
    } else {
-      *extent = ALIGN_POT(draw->count * info->index_size, 4);
+      *extent = ALIGN_POT(max_extent, 4);
 
       return agx_pool_upload_aligned(&batch->pool,
                                      ((uint8_t *)info->index.user) + offset,