From ecb6c5d555827fcd030159f788eb308ba47362bb Mon Sep 17 00:00:00 2001 From: Jose Maria Casanova Crespo Date: Mon, 2 Mar 2026 16:45:50 +0100 Subject: [PATCH] vc4: flush write jobs before BO replacement in DISCARD_WHOLE path The DISCARD_WHOLE_RESOURCE path in vc4_map_usage_prep() replaces the resource's BO with vc4_resource_bo_alloc(). As the RCL resolves rsc->bo at job submit in vc4_submit_setup_rcl_surface(), any pending write job would store to the new BO instead of the old one, corrupting the new written data. This is the same bug that was fixed in v3d in the previous commit. Fixes: 18ccda7b86b ("vc4: When asked to discard-map a whole resource, discard it.") Reviewed-by: Iago Toral Quiroga Part-of: --- src/broadcom/ci/broadcom-rpi3-fails.txt | 2 -- src/gallium/drivers/vc4/vc4_resource.c | 7 +++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/broadcom/ci/broadcom-rpi3-fails.txt b/src/broadcom/ci/broadcom-rpi3-fails.txt index 40720d76b3e..bae3b0d97f1 100644 --- a/src/broadcom/ci/broadcom-rpi3-fails.txt +++ b/src/broadcom/ci/broadcom-rpi3-fails.txt @@ -860,7 +860,6 @@ spec@!opengl 1.1@polygon-mode-offset@config 6: Expected blue pixel in center,Fai spec@!opengl 1.1@polygon-mode-offset@config 6: Expected white pixel on right edge,Fail spec@!opengl 1.1@polygon-mode-offset@config 6: Expected white pixel on top edge,Fail -spec@!opengl 1.1@texsubimage-unpack,Fail spec@!opengl 1.1@texwrap 2d proj,Fail spec@!opengl 1.1@texwrap 2d proj@GL_RGBA8- NPOT- projected,Fail spec@!opengl 1.1@texwrap 2d proj@GL_RGBA8- projected,Fail @@ -959,7 +958,6 @@ spec@arb_occlusion_query@occlusion_query_conform,Fail spec@arb_occlusion_query@occlusion_query_conform@GetObjivAval_multi2,Fail spec@arb_pixel_buffer_object@fbo-pbo-readpixels-small,Fail spec@arb_pixel_buffer_object@pbo-getteximage,Fail -spec@arb_pixel_buffer_object@texsubimage-unpack pbo,Fail spec@arb_point_sprite@arb_point_sprite-mipmap,Fail spec@arb_provoking_vertex@arb-provoking-vertex-render,Fail spec@arb_sampler_objects@sampler-objects,Fail diff --git a/src/gallium/drivers/vc4/vc4_resource.c b/src/gallium/drivers/vc4/vc4_resource.c index efa000ccd77..1e2d9c50701 100644 --- a/src/gallium/drivers/vc4/vc4_resource.c +++ b/src/gallium/drivers/vc4/vc4_resource.c @@ -108,6 +108,13 @@ vc4_map_usage_prep(struct pipe_context *pctx, MESA_TRACE_FUNC(); if (usage & PIPE_MAP_DISCARD_WHOLE_RESOURCE) { + /* Flush any pending write jobs before replacing the BO. + * The RCL reads rsc->bo at job submit time, so if we + * replace the BO first, a later flush of the pending + * job would resolve the new BO instead of the old one, + * corrupting the new data with a stale store. + */ + vc4_flush_jobs_writing_resource(vc4, prsc); if (vc4_resource_bo_alloc(rsc)) { /* If it might be bound as one of our vertex buffers, * make sure we re-emit vertex buffer state.