Mesa (main): zink: fix barrier generation for ssbo descriptors

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Apr 6 04:47:47 UTC 2022


Module: Mesa
Branch: main
Commit: 3dcb80da9d6d34e567680ef7fecd24aab4537e8a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3dcb80da9d6d34e567680ef7fecd24aab4537e8a

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Thu Mar 31 11:29:36 2022 -0400

zink: fix barrier generation for ssbo descriptors

ssbo binds are always at least readable, so without deeper shader
inspection, never assume that write binds mean no read access

this is different than image descriptors which can explicitly get
write-only access set

cc: mesa-stable

fixes #6231

THANKS TO @daniel-schuermann FOR SOLVING THIS WITH HIS INCREDIBLE TALENT AND WIT

Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15697>

---

 src/gallium/drivers/zink/zink_draw.cpp | 36 ++++++++++++++++------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_draw.cpp b/src/gallium/drivers/zink/zink_draw.cpp
index 25f6c87ecad..0adc8a99ee7 100644
--- a/src/gallium/drivers/zink/zink_draw.cpp
+++ b/src/gallium/drivers/zink/zink_draw.cpp
@@ -381,38 +381,36 @@ update_barriers(struct zink_context *ctx, bool is_compute)
    ctx->need_barriers[is_compute] = &ctx->update_barriers[is_compute][ctx->barrier_set_idx[is_compute]];
    set_foreach(need_barriers, he) {
       struct zink_resource *res = (struct zink_resource *)he->key;
+      bool is_buffer = res->obj->is_buffer;
       VkPipelineStageFlags pipeline = 0;
       VkAccessFlags access = 0;
       if (res->bind_count[is_compute]) {
          if (res->write_bind_count[is_compute])
             access |= VK_ACCESS_SHADER_WRITE_BIT;
-         if (res->write_bind_count[is_compute] != res->bind_count[is_compute]) {
-            unsigned bind_count = res->bind_count[is_compute] - res->write_bind_count[is_compute];
-            if (res->obj->is_buffer) {
-               if (res->ubo_bind_count[is_compute]) {
-                  access |= VK_ACCESS_UNIFORM_READ_BIT;
-                  bind_count -= res->ubo_bind_count[is_compute];
-               }
-               if (!is_compute && res->vbo_bind_mask) {
-                  access |= VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
-                  pipeline |= VK_PIPELINE_STAGE_VERTEX_INPUT_BIT;
-                  bind_count -= util_bitcount(res->vbo_bind_mask);
-                  if (res->write_bind_count[is_compute])
-                     pipeline |= VK_PIPELINE_STAGE_VERTEX_SHADER_BIT;
-               }
-               bind_count -= res->so_bind_count;
+         if (is_buffer) {
+            if (res->ubo_bind_count[is_compute])
+               access |= VK_ACCESS_UNIFORM_READ_BIT;
+            if (!is_compute && res->vbo_bind_mask) {
+               access |= VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
+               pipeline |= VK_PIPELINE_STAGE_VERTEX_INPUT_BIT;
+               if (res->write_bind_count[is_compute])
+                  pipeline |= VK_PIPELINE_STAGE_VERTEX_SHADER_BIT;
             }
-            if (bind_count)
+            if (res->write_bind_count[is_compute])
+               access |= VK_ACCESS_SHADER_READ_BIT;
+            /* TODO: there are no other write-only buffer descriptors without deeper shader analysis */
+            if (res->image_bind_count[is_compute] != res->bind_count[is_compute] ||
+                res->write_bind_count[is_compute] != res->image_bind_count[is_compute])
                access |= VK_ACCESS_SHADER_READ_BIT;
          }
          if (is_compute)
             pipeline = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
          else if (!pipeline) {
-            if (res->obj->is_buffer) {
+            if (is_buffer) {
+               pipeline |= find_pipeline_bits(res->ssbo_bind_mask);
+
                if (res->ubo_bind_count[0])
                   pipeline |= find_pipeline_bits(res->ubo_bind_mask);
-               if (!pipeline)
-                  pipeline |= find_pipeline_bits(res->ssbo_bind_mask);
             }
             if (!pipeline)
                pipeline |= find_pipeline_bits(res->sampler_binds);



More information about the mesa-commit mailing list