From 6f288303650dd7a68f2f02b65ee8690e5fe0bc75 Mon Sep 17 00:00:00 2001 From: Patrick Lerda Date: Mon, 23 Feb 2026 13:32:21 +0100 Subject: [PATCH] r600: fix cs atomic operations when the shader is called multiple times This change is useful when the compute shader is called multiple times with the atomic operations enabled. It fixes some data coherency issues. This is done by moving evergreen_emit_atomic_buffer_setup() after r600_flush_emit(). This change is also a partial fix for compute_shader.pipeline-compute-chain. In this specific case, it makes the memory barrier working. This change was tested on cayman and barts; it makes these tests fully deterministic: khr-gl4[2-6]/shader_atomic_counters/advanced-usage-many-dispatches: fail pass khr-gles31/core/shader_atomic_counters/advanced-usage-many-dispatches: fail pass deqp-gles31/functional/synchronization/inter_call/without_memory_barrier/atomic_counter_dispatch_.*_calls_.*_invocations: fail pass Cc: mesa-stable Signed-off-by: Patrick Lerda (cherry picked from commit dad942b468b79a382771408319a28d6faa225462) Part-of: --- .pick_status.json | 2 +- src/gallium/drivers/r600/ci/r600-turks-fails.txt | 1 - src/gallium/drivers/r600/ci/r600-turks-flakes.txt | 1 - src/gallium/drivers/r600/evergreen_compute.c | 12 ++++++------ 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 08449acbd0c..e77f123def8 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -4424,7 +4424,7 @@ "description": "r600: fix cs atomic operations when the shader is called multiple times", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/gallium/drivers/r600/ci/r600-turks-fails.txt b/src/gallium/drivers/r600/ci/r600-turks-fails.txt index adf9f530ef5..34bb9ff9eb7 100644 --- a/src/gallium/drivers/r600/ci/r600-turks-fails.txt +++ b/src/gallium/drivers/r600/ci/r600-turks-fails.txt @@ -15,7 +15,6 @@ KHR-GLES31.core.gpu_shader5.texture_gather_offset_color_clamp_to_edge,Fail KHR-GLES31.core.layout_binding.image2D_layout_binding_imageLoad_ComputeShader,Fail -KHR-GLES31.core.shader_atomic_counters.advanced-usage-many-dispatches,Fail KHR-GLES31.core.shader_atomic_counters.advanced-usage-many-draw-calls2,Fail KHR-GLES31.core.shader_atomic_counters.advanced-usage-multi-stage,Fail diff --git a/src/gallium/drivers/r600/ci/r600-turks-flakes.txt b/src/gallium/drivers/r600/ci/r600-turks-flakes.txt index 2438cfc20fc..ce40a1727c7 100644 --- a/src/gallium/drivers/r600/ci/r600-turks-flakes.txt +++ b/src/gallium/drivers/r600/ci/r600-turks-flakes.txt @@ -1,6 +1,5 @@ # Sometimes passes. KHR-GLES31.core.compute_shader.pipeline-compute-chain -KHR-GLES31.core.shader_atomic_counters.advanced-usage-many-dispatches KHR-GLES31.core.shader_atomic_counters.advanced-usage-many-draw-calls2 # Occasional "args_equal: Assertion `l.size() == r.size()' failed." diff --git a/src/gallium/drivers/r600/evergreen_compute.c b/src/gallium/drivers/r600/evergreen_compute.c index 00e3896847a..2124709487a 100644 --- a/src/gallium/drivers/r600/evergreen_compute.c +++ b/src/gallium/drivers/r600/evergreen_compute.c @@ -350,12 +350,6 @@ static void compute_emit_cs(struct r600_context *rctx, } r600_update_driver_const_buffers(rctx, true); - evergreen_emit_atomic_buffer_setup(rctx, true, combined_atomics, global_atomic_count); - if (global_atomic_count) { - radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0)); - radeon_emit(cs, EVENT_TYPE(EVENT_TYPE_CS_PARTIAL_FLUSH) | EVENT_INDEX(4)); - } - /* Initialize all the compute-related registers. * * See evergreen_init_atom_start_compute_cs() in this file for the list @@ -375,6 +369,12 @@ static void compute_emit_cs(struct r600_context *rctx, rctx->b.flags |= R600_CONTEXT_WAIT_3D_IDLE | R600_CONTEXT_FLUSH_AND_INV; r600_flush_emit(rctx); + evergreen_emit_atomic_buffer_setup(rctx, true, combined_atomics, global_atomic_count); + if (global_atomic_count) { + radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 0, 0)); + radeon_emit(cs, EVENT_TYPE(EVENT_TYPE_CS_PARTIAL_FLUSH) | EVENT_INDEX(4)); + } + uint32_t rat_mask; rat_mask = evergreen_construct_rat_mask(rctx, &rctx->cb_misc_state, 0);