diff --git a/src/gallium/drivers/asahi/agx_batch.c b/src/gallium/drivers/asahi/agx_batch.c index 0cea6b35e0f..c8b501d81ee 100644 --- a/src/gallium/drivers/asahi/agx_batch.c +++ b/src/gallium/drivers/asahi/agx_batch.c @@ -118,6 +118,7 @@ agx_batch_init(struct agx_context *ctx, batch->varyings = 0; batch->any_draws = false; batch->initialized = false; + batch->draws = 0; /* We need to emit prim state at the start. Max collides with all. */ batch->reduced_prim = MESA_PRIM_COUNT; diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index d9f4105efbb..8d7c1821312 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -3182,12 +3182,17 @@ agx_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info, assert(batch == agx_get_batch(ctx) && "batch should not change under us"); + batch->draws++; + /* The scissor/zbias arrays are indexed with 16-bit integers, imposigin a * maximum of UINT16_MAX descriptors. Flush if the next draw would overflow */ if (unlikely((batch->scissor.size / AGX_SCISSOR_LENGTH) >= UINT16_MAX) || (batch->depth_bias.size / AGX_DEPTH_BIAS_LENGTH) >= UINT16_MAX) { agx_flush_batch_for_reason(ctx, batch, "Scissor/depth bias overflow"); + } else if (unlikely(batch->draws > 100000)) { + /* Mostly so drawoverhead doesn't OOM */ + agx_flush_batch_for_reason(ctx, batch, "Absurd number of draws"); } } diff --git a/src/gallium/drivers/asahi/agx_state.h b/src/gallium/drivers/asahi/agx_state.h index 29fc6fe62c5..1ccac760957 100644 --- a/src/gallium/drivers/asahi/agx_state.h +++ b/src/gallium/drivers/asahi/agx_state.h @@ -225,6 +225,7 @@ struct agx_batch { struct pipe_framebuffer_state key; uint64_t seqnum; uint32_t syncobj; + uint32_t draws; struct agx_tilebuffer_layout tilebuffer_layout;