Mesa (staging/20.1): glsl: only allow 32 bits atomic operations on images

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jul 10 10:35:33 UTC 2020


Module: Mesa
Branch: staging/20.1
Commit: 5394bcbc728aa496bc806c6243b46d7bd28e87d4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=5394bcbc728aa496bc806c6243b46d7bd28e87d4

Author: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Date:   Fri Jun 19 18:37:00 2020 +0200

glsl: only allow 32 bits atomic operations on images

EXT_shader_image_load_store says:
   The format of the image unit must be in the "1x32" equivalence class
   otherwise the atomic operation is invalid.

ARB_shader_image_load_store says:
   We will only support 32-bit atomic operations on images

Fixes: fc0a2e5d017 ("glsl: add EXT_shader_image_load_store new image functions")
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5688>
(cherry picked from commit 1e3aeda5281e5d246e37a035d91f08af4bb0e5e3)

---

 .pick_status.json                  |  2 +-
 src/compiler/glsl/ast_function.cpp | 44 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/.pick_status.json b/.pick_status.json
index 386d0150302..5d1e26704ec 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -346,7 +346,7 @@
         "description": "glsl: only allow 32 bits atomic operations on images",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "master_sha": null,
         "because_sha": "fc0a2e5d017dcb9e7f236d69745dff89e116b92e"
     },
diff --git a/src/compiler/glsl/ast_function.cpp b/src/compiler/glsl/ast_function.cpp
index b6b81bf1e14..3084d5ada21 100644
--- a/src/compiler/glsl/ast_function.cpp
+++ b/src/compiler/glsl/ast_function.cpp
@@ -182,6 +182,37 @@ is_atomic_function(const char *func_name)
           !strcmp(func_name, "atomicCompSwap");
 }
 
+static bool
+verify_atomic_image_parameter_qualifier(YYLTYPE *loc, _mesa_glsl_parse_state *state,
+                                        ir_variable *var)
+{
+   if (!var ||
+       (var->data.image_format != PIPE_FORMAT_R32_UINT &&
+        var->data.image_format != PIPE_FORMAT_R32_SINT &&
+        var->data.image_format != PIPE_FORMAT_R32_FLOAT)) {
+      _mesa_glsl_error(loc, state, "Image atomic functions should use r32i/r32ui "
+                       "format qualifier");
+      return false;
+   }
+   return true;
+}
+
+static bool
+is_atomic_image_function(const char *func_name)
+{
+   return !strcmp(func_name, "imageAtomicAdd") ||
+          !strcmp(func_name, "imageAtomicMin") ||
+          !strcmp(func_name, "imageAtomicMax") ||
+          !strcmp(func_name, "imageAtomicAnd") ||
+          !strcmp(func_name, "imageAtomicOr") ||
+          !strcmp(func_name, "imageAtomicXor") ||
+          !strcmp(func_name, "imageAtomicExchange") ||
+          !strcmp(func_name, "imageAtomicCompSwap") ||
+          !strcmp(func_name, "imageAtomicIncWrap") ||
+          !strcmp(func_name, "imageAtomicDecWrap");
+}
+
+
 /**
  * Verify that 'out' and 'inout' actual parameters are lvalues.  Also, verify
  * that 'const_in' formal parameters (an extension in our IR) correspond to
@@ -350,6 +381,19 @@ verify_parameter_modes(_mesa_glsl_parse_state *state,
                                          actual->variable_referenced())) {
          return false;
       }
+   } else if (is_atomic_image_function(func_name)) {
+      const ir_rvalue *const actual =
+         (ir_rvalue *) actual_ir_parameters.get_head_raw();
+
+      const ast_expression *const actual_ast =
+         exec_node_data(ast_expression,
+                        actual_ast_parameters.get_head_raw(), link);
+      YYLTYPE loc = actual_ast->get_location();
+
+      if (!verify_atomic_image_parameter_qualifier(&loc, state,
+                                         actual->variable_referenced())) {
+         return false;
+      }
    }
 
    return true;



More information about the mesa-commit mailing list