Mesa (staging/22.0): glsl/nir/linker: fix shader_storage_blocks_write_access

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Apr 21 07:13:49 UTC 2022


Module: Mesa
Branch: staging/22.0
Commit: 42bff7eca3f03f8d49c5752f8f50e34da3da45cb
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=42bff7eca3f03f8d49c5752f8f50e34da3da45cb

Author: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Date:   Wed Mar 23 15:37:49 2022 +0100

glsl/nir/linker: fix shader_storage_blocks_write_access

shader_storage_blocks_write_access was computed using the buffer indices
in the program but ShaderStorageBlocksWriteAccess is used with the shader
buffers.

So if a VS had 3 SSBOs and a FS had 4, the mask for VS was 0x3 (correct) but
the mask for the FS was 0x78 instead of 0x15.

Fix this by substracting the index of the first shader buffer in the program's
buffers.

Fixes: 79127f8d5be ("glsl: set ShaderStorageBlocksWriteAccess in the nir linker")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/6184
Reviewed-by: Alejandro Piñeiro <apinheiro at igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15552>
(cherry picked from commit 2bc933f7d5852df4aaf3c2d59b153a85ced111c2)

---

 .pick_status.json                             |  2 +-
 src/compiler/glsl/gl_nir_link_uniforms.c      | 18 ++++++++++++++++--
 src/gallium/drivers/virgl/ci/traces-virgl.yml |  4 ++--
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 2e52f4c9bdc..eeead9d618c 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -7788,7 +7788,7 @@
         "description": "glsl/nir/linker: fix shader_storage_blocks_write_access",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 5,
+        "resolution": 1,
         "because_sha": "79127f8d5be7ab95bde0ab30a03eb21e00df70c2"
     },
     {
diff --git a/src/compiler/glsl/gl_nir_link_uniforms.c b/src/compiler/glsl/gl_nir_link_uniforms.c
index d1d483bd502..aa77225600b 100644
--- a/src/compiler/glsl/gl_nir_link_uniforms.c
+++ b/src/compiler/glsl/gl_nir_link_uniforms.c
@@ -1742,14 +1742,28 @@ gl_nir_link_uniforms(const struct gl_constants *consts,
 
             STATIC_ASSERT(MAX_SHADER_STORAGE_BUFFERS <= 32);
 
+            /* Buffers from each stage are pointers to the one stored in the program. We need
+             * to account for this before computing the mask below otherwise the mask will be
+             * incorrect.
+             *    sh->Program->sh.SSBlocks: [a][b][c][d][e][f]
+             *    VS prog->data->SSBlocks : [a][b][c]
+             *    FS prog->data->SSBlocks : [d][e][f]
+             * eg for FS buffer 1, buffer_block_index will be 4 but sh_block_index will be 1.
+             */
+            int base = 0;
+            base = sh->Program->sh.ShaderStorageBlocks[0] - prog->data->ShaderStorageBlocks;
+
+            assert(base >= 0);
+
+            int sh_block_index = buffer_block_index - base;
             /* Shaders that use too many SSBOs will fail to compile, which
              * we don't care about.
              *
              * This is true for shaders that do not use too many SSBOs:
              */
-            if (buffer_block_index + array_size <= 32) {
+            if (sh_block_index + array_size <= 32) {
                state.shader_storage_blocks_write_access |=
-                  u_bit_consecutive(buffer_block_index, array_size);
+                  u_bit_consecutive(sh_block_index, array_size);
             }
          }
 
diff --git a/src/gallium/drivers/virgl/ci/traces-virgl.yml b/src/gallium/drivers/virgl/ci/traces-virgl.yml
index 1b9d70c941a..26aa65215ce 100644
--- a/src/gallium/drivers/virgl/ci/traces-virgl.yml
+++ b/src/gallium/drivers/virgl/ci/traces-virgl.yml
@@ -246,7 +246,7 @@ traces:
   - path: supertuxkart/supertuxkart-mansion-egl-gles.trace
     expectations:
       - device: gl-virgl
-        checksum: c8e5d7c4377b8e484ae41270692914f3
+        checksum: 5e4e0cedd57bedf3eb7f127489a46b12
   - path: xonotic/xonotic-keybench-high.trace
     expectations:
       - device: gl-virgl
@@ -267,7 +267,7 @@ traces:
   - path: valve/portal-2.trace
     expectations:
       - device: gl-virgl
-        checksum: 9f7fecf8df89e105a4d2b4a61468b427
+        checksum: 7489a8412ee2bca45431d208e0006a3e
 # Piglit crashes when trying to run this one
 #  - path: supertuxkart/supertuxkart-antediluvian-abyss.rdc
 #    expectations:



More information about the mesa-commit mailing list