[Mesa-dev] [PATCH v2 71/82] glsl: Apply memory qualifiers to buffer variables

Iago Toral Quiroga itoral at igalia.com
Wed Jun 3 00:02:01 PDT 2015


---
 src/glsl/ast_to_hir.cpp | 25 +++++++++++++++++++++++++
 src/glsl/glsl_types.h   | 10 ++++++++++
 2 files changed, 35 insertions(+)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 77d8b9e..ab8eda7 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -5495,6 +5495,23 @@ ast_process_structure_or_interface_block(exec_list *instructions,
                    || fields[i].matrix_layout == GLSL_MATRIX_LAYOUT_COLUMN_MAJOR);
          }
 
+         /* Image qualifiers are allowed on buffer variables, which can only
+          * be defined inside shader storage buffer objects
+          */
+         if (var_mode == ir_var_shader_storage) {
+            fields[i].image_read_only = qual->flags.q.read_only;
+            fields[i].image_write_only = qual->flags.q.write_only;
+            fields[i].image_coherent = qual->flags.q.coherent;
+            fields[i].image_volatile = qual->flags.q._volatile;
+            fields[i].image_restrict = qual->flags.q.restrict_flag;
+
+            if (fields[i].image_read_only && fields[i].image_write_only) {
+               _mesa_glsl_error(&loc, state,
+                                "buffer variable `%s' can't be "
+                                "readonly and writeonly.", fields[i].name);
+            }
+         }
+
          i++;
       }
    }
@@ -6003,6 +6020,14 @@ ast_interface_block::hir(exec_list *instructions,
 
          var->data.stream = this->layout.stream;
 
+         if (var->data.mode == ir_var_shader_storage) {
+            var->data.image_read_only = fields[i].image_read_only;
+            var->data.image_write_only = fields[i].image_write_only;
+            var->data.image_coherent = fields[i].image_coherent;
+            var->data.image_volatile = fields[i].image_volatile;
+            var->data.image_restrict = fields[i].image_restrict;
+         }
+
          /* Examine var name here since var may get deleted in the next call */
          bool var_is_gl_id = is_gl_identifier(var->name);
 
diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
index a2c654d..08f6573 100644
--- a/src/glsl/glsl_types.h
+++ b/src/glsl/glsl_types.h
@@ -774,6 +774,16 @@ struct glsl_struct_field {
     * streams (as in ir_variable::stream). -1 otherwise.
     */
    int stream;
+
+   /**
+    * Image qualifiers, applicable to buffer variables defined in shader
+    * storage buffer objects (SSBOs)
+    */
+   unsigned image_read_only:1;
+   unsigned image_write_only:1;
+   unsigned image_coherent:1;
+   unsigned image_volatile:1;
+   unsigned image_restrict:1;
 };
 
 static inline unsigned int
-- 
1.9.1



More information about the mesa-dev mailing list