From 4e033ffb27f798066a624738409dbe2c3267dd37 Mon Sep 17 00:00:00 2001 From: Jose Maria Casanova Crespo Date: Wed, 16 Jul 2025 13:08:00 +0200 Subject: [PATCH] v3d: Add V3D_TFU_READAHEAD padding for allocated resources Reviewed-by: Iago Toral Quiroga Part-of: --- src/gallium/drivers/v3d/v3d_resource.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/gallium/drivers/v3d/v3d_resource.c b/src/gallium/drivers/v3d/v3d_resource.c index 0ac9256a7fb..eecca1f5625 100644 --- a/src/gallium/drivers/v3d/v3d_resource.c +++ b/src/gallium/drivers/v3d/v3d_resource.c @@ -102,17 +102,18 @@ v3d_resource_bo_alloc(struct v3d_resource *rsc) struct pipe_screen *pscreen = prsc->screen; struct v3d_bo *bo; - /* Buffers may be read using ldunifa, which prefetches the next - * 4 bytes after a read. If the buffer's size is exactly a multiple - * of a page size and the shader reads the last 4 bytes with ldunifa - * the prefetching would read out of bounds and cause an MMU error, - * so we allocate extra space to avoid kernel error spamming. + /* Buffers may be read using ldunifa, which prefetches the next 4 + * bytes after a read. If the buffer's size is exactly a multiple of a + * page size and the shader reads the last 4 bytes with ldunifa the + * prefetching would read out of bounds and cause an MMU error, so we + * allocate extra space to avoid kernel error spamming. We also need + * to add a V3D_TFU_READAHEAD padding to avoid invalid reads done by + * the TFU unit after the end of the last page allocated. */ - uint32_t size = rsc->size; - if (rsc->base.target == PIPE_BUFFER && (size % 4096 == 0)) - size += 4; - - bo = v3d_bo_alloc(v3d_screen(pscreen), size, "resource"); + uint32_t padding = + rsc->base.target == PIPE_BUFFER ? 4 : V3D_TFU_READAHEAD_SIZE; + bo = v3d_bo_alloc(v3d_screen(pscreen), rsc->size + padding, + "resource"); if (bo) { v3d_bo_unreference(&rsc->bo); rsc->bo = bo;