v3d: increase BO allocation size when growing CLs
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

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 <mcanal@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40425>
This commit is contained in:
Maíra Canal 2026-02-26 08:39:30 -03:00 committed by Marge Bot
parent 0885328fe9
commit de6e76f253

View file

@ -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) {