From d11c9f983632d35e7010b470fe0af2f6a2c087bf Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 4 Dec 2023 15:27:40 -0400 Subject: [PATCH] asahi: clamp draw count for mdi spec req. KHR-GL43.indirect_parameters_tests.MultiDrawArraysIndirectCount Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/lib/shaders/geometry.cl | 9 ++++++++- src/asahi/lib/shaders/geometry.h | 3 +++ src/gallium/drivers/asahi/agx_state.c | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/asahi/lib/shaders/geometry.cl b/src/asahi/lib/shaders/geometry.cl index a47ae05504e..c60b2ed3401 100644 --- a/src/asahi/lib/shaders/geometry.cl +++ b/src/asahi/lib/shaders/geometry.cl @@ -351,12 +351,19 @@ process_multidraw(global struct agx_ia_state *s, uint local_id, uintptr_t draw_ptr = s->draws; uint draw_stride = s->draw_stride; + /* Determine the number of draws. This is given by the application, but must + * be clamped to the minimum provided to the driver, implementing spec text: + * + * The actual number of executed draw calls is the minimum of the count + * specified in countBuffer and maxDrawCount. + */ + uint len = min(*(s->count), s->max_draws); + /* Prefix sum the vertex counts (multiplied by instance counts) across draws. * The number of draws is expected to be small, so this serialization should * be ok in practice. See libagx_prefix_sum for algorithm details. */ uint i, count = 0; - uint len = *(s->count); uint len_remainder = len % 32; uint len_rounded_down = len - len_remainder; diff --git a/src/asahi/lib/shaders/geometry.h b/src/asahi/lib/shaders/geometry.h index fad28ab6a17..2a0e1e794c4 100644 --- a/src/asahi/lib/shaders/geometry.h +++ b/src/asahi/lib/shaders/geometry.h @@ -73,6 +73,9 @@ struct agx_ia_state { /* When unrolling primitive restart, output draw descriptors */ GLOBAL(uint) out_draws; + /* Input: maximum draw count, count is clamped to this */ + uint32_t max_draws; + /* Primitive restart index, if unrolling */ uint32_t restart_index; diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 770ccabaa86..04c91239625 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -3510,6 +3510,7 @@ agx_upload_ia_params(struct agx_batch *batch, const struct pipe_draw_info *info, agx_batch_reads(batch, rsrc); ia.count = rsrc->bo->ptr.gpu + indirect->indirect_draw_count_offset; + ia.max_draws = indirect->draw_count; ia.draw_stride = indirect->stride; /* MDI requires prefix sums, but not for our current unroll path */