From 7d25d214f52fb3b1c5b1179013cd18b79ff0bf5b 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 (cherry picked from commit ecb6c5d555827fcd030159f788eb308ba47362bb) Part-of: --- .pick_status.json | 2 +- src/broadcom/ci/broadcom-rpi3-fails.txt | 2 -- src/gallium/drivers/vc4/vc4_resource.c | 7 +++++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 415744770bc..9b8e66c9977 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -3914,7 +3914,7 @@ "description": "vc4: flush write jobs before BO replacement in DISCARD_WHOLE path", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "18ccda7b86b8f7ab7466265aefb3f3e773f4a757", "notes": null diff --git a/src/broadcom/ci/broadcom-rpi3-fails.txt b/src/broadcom/ci/broadcom-rpi3-fails.txt index 42f5067b3a8..b2439ad42d1 100644 --- a/src/broadcom/ci/broadcom-rpi3-fails.txt +++ b/src/broadcom/ci/broadcom-rpi3-fails.txt @@ -853,7 +853,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 @@ -953,7 +952,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.