From 559d33b2b6b320bd480ec1c5cadfe10ed2d6f05f Mon Sep 17 00:00:00 2001 From: Connor Abbott Date: Fri, 18 Apr 2025 11:57:53 -0400 Subject: [PATCH] tu: Fix flushing when using a staging buffer for copies When doing the flushing, I forgot that because the staging buffer can be used with different formats with different cpp, we need to make sure that CCU is properly flushed and invalidated between each copy to the staging buffer to prevent stale cache entries from creeping in, as the CCU seems to rely on the cpp staying the same, even on a7xx which dropped some of the other restrictions like using the same RT index/layer. For "normal" user-visible copies this is done via transitioning from UNDEFINED. Cc: mesa-stable Part-of: (cherry picked from commit ee10938beed3840b9583ad4d67ff96052a9daaf1) --- .pick_status.json | 2 +- src/freedreno/vulkan/tu_clear_blit.cc | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index 1b2be0a1e02..a2e2b5478cf 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -364,7 +364,7 @@ "description": "tu: Fix flushing when using a staging buffer for copies", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/freedreno/vulkan/tu_clear_blit.cc b/src/freedreno/vulkan/tu_clear_blit.cc index 1222a4d7233..fbe0ad5064f 100644 --- a/src/freedreno/vulkan/tu_clear_blit.cc +++ b/src/freedreno/vulkan/tu_clear_blit.cc @@ -2999,8 +2999,16 @@ tu_copy_image_to_image(struct tu_cmd_buffer *cmd, /* When executed by the user there has to be a pipeline barrier here, * but since we're doing it manually we'll have to flush ourselves. + * Because we may reuse the staging buffer with different + * layouts/formats, we also have to invalidate CCU, which when executed + * by the user would be done before the next use of the staging buffer + * when transitioning from UNDEFINED. Here it's more optimal to + * invalidate right away after flushing instead of before the next copy + * using the staging buffer however, because we don't have to insert + * another WFI. */ tu_emit_event_write(cmd, cs, FD_CCU_CLEAN_COLOR); + tu_emit_event_write(cmd, cs, FD_CCU_INVALIDATE_COLOR); tu_emit_event_write(cmd, cs, FD_CACHE_INVALIDATE); tu_cs_emit_wfi(cs);