From de6e76f253a16d68451c4e0f72af81ed660bfd16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ADra=20Canal?= Date: Thu, 26 Feb 2026 08:39:30 -0300 Subject: [PATCH] v3d: increase BO allocation size when growing CLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we are growing a CL, double the BO allocation size to reduce the number of allocations in large command buffers. This showed significant performance improvements in workloads with large CLs (e.g. WebGL Aquarium with 5000 fishes). Also, this is the same strategy that v3dv uses. Signed-off-by: MaĆ­ra Canal Part-of: --- src/gallium/drivers/v3d/v3d_cl.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/gallium/drivers/v3d/v3d_cl.c b/src/gallium/drivers/v3d/v3d_cl.c index e08699a928e..c92c8bd11df 100644 --- a/src/gallium/drivers/v3d/v3d_cl.c +++ b/src/gallium/drivers/v3d/v3d_cl.c @@ -51,10 +51,16 @@ v3d_cl_ensure_space(struct v3d_cl *cl, uint32_t space, uint32_t alignment) return offset; } struct v3d_device_info *devinfo = &cl->job->v3d->screen->devinfo; + + /* If we are growing, double the BO allocation size to reduce the + * number of allocations with large command buffers. + */ + space = align(space, devinfo->cle_buffer_min_size); + if (cl->bo) + space = MAX2(cl->bo->size * 2, space); + v3d_bo_unreference(&cl->bo); - cl->bo = v3d_bo_alloc(cl->job->v3d->screen, - align(space, devinfo->cle_buffer_min_size), - "CL"); + cl->bo = v3d_bo_alloc(cl->job->v3d->screen, space, "CL"); cl->base = v3d_bo_map(cl->bo); cl->size = cl->bo->size; cl->next = cl->base; @@ -77,11 +83,15 @@ v3d_cl_ensure_space_with_branch(struct v3d_cl *cl, uint32_t space) */ struct v3d_device_info *devinfo = &cl->job->v3d->screen->devinfo; uint32_t unusable_size = devinfo->cle_readahead + cl_packet_length(BRANCH); - struct v3d_bo *new_bo = v3d_bo_alloc(cl->job->v3d->screen, - align(space + unusable_size, - devinfo->cle_buffer_min_size), - "CL"); - assert(space + unusable_size <= new_bo->size); + + /* If we are growing, double the BO allocation size to reduce the + * number of allocations with large command buffers. + */ + space = align(space + unusable_size, devinfo->cle_buffer_min_size); + if (cl->bo) + space = MAX2(cl->bo->size * 2, space); + + struct v3d_bo *new_bo = v3d_bo_alloc(cl->job->v3d->screen, space, "CL"); /* Chain to the new BO from the old one. */ if (cl->bo) {