[Mesa-dev] [PATCH 05/21] glsl: Use bit-flags image attributes and uint16_t for the image format

Ian Romanick idr at freedesktop.org
Tue May 27 19:49:00 PDT 2014


From: Ian Romanick <ian.d.romanick at intel.com>

All of the GL image enums fit in 16-bits.

Also move the fields from the anonymous "image" structucture to the next
higher structure.  This will enable packing the bits with the other
bitfield.

Reduces the peak ir_variable memory usage in a trimmed apitrace of dota2
by 204KiB on 64-bit.

Before: IR MEM: variable usage / name / total: 6164976 1439077 7604053
After:  IR MEM: variable usage / name / total: 5955672 1439077 7394749

Reduces the peak ir_variable memory usage in a trimmed apitrace of dota2
by 204KiB on 32-bit.

Before: IR MEM: variable usage / name / total: 4746192 915817 5662009
After:  IR MEM: variable usage / name / total: 4536888 915817 5452705

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glsl/ast_function.cpp      | 10 +++++-----
 src/glsl/ast_to_hir.cpp        | 14 +++++++-------
 src/glsl/builtin_functions.cpp | 10 +++++-----
 src/glsl/ir.cpp                | 20 ++++++++++----------
 src/glsl/ir.h                  | 27 +++++++++++++--------------
 src/glsl/link_uniforms.cpp     |  4 ++--
 6 files changed, 42 insertions(+), 43 deletions(-)

diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index 4b84470..c70b519 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -106,35 +106,35 @@ verify_image_parameter(YYLTYPE *loc, _mesa_glsl_parse_state *state,
     *  qualifiers. [...] It is legal to have additional qualifiers
     *  on a formal parameter, but not to have fewer."
     */
-   if (actual->data.image.coherent && !formal->data.image.coherent) {
+   if (actual->data.image_coherent && !formal->data.image_coherent) {
       _mesa_glsl_error(loc, state,
                        "function call parameter `%s' drops "
                        "`coherent' qualifier", formal->name);
       return false;
    }
 
-   if (actual->data.image._volatile && !formal->data.image._volatile) {
+   if (actual->data.image_volatile && !formal->data.image_volatile) {
       _mesa_glsl_error(loc, state,
                        "function call parameter `%s' drops "
                        "`volatile' qualifier", formal->name);
       return false;
    }
 
-   if (actual->data.image.restrict_flag && !formal->data.image.restrict_flag) {
+   if (actual->data.image_restrict && !formal->data.image_restrict) {
       _mesa_glsl_error(loc, state,
                        "function call parameter `%s' drops "
                        "`restrict' qualifier", formal->name);
       return false;
    }
 
-   if (actual->data.image.read_only && !formal->data.image.read_only) {
+   if (actual->data.image_read_only && !formal->data.image_read_only) {
       _mesa_glsl_error(loc, state,
                        "function call parameter `%s' drops "
                        "`readonly' qualifier", formal->name);
       return false;
    }
 
-   if (actual->data.image.write_only && !formal->data.image.write_only) {
+   if (actual->data.image_write_only && !formal->data.image_write_only) {
       _mesa_glsl_error(loc, state,
                        "function call parameter `%s' drops "
                        "`writeonly' qualifier", formal->name);
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 0128b3f..0621ea7 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -2314,11 +2314,11 @@ apply_image_qualifier_to_variable(const struct ast_type_qualifier *qual,
                           "global variables");
       }
 
-      var->data.image.read_only |= qual->flags.q.read_only;
-      var->data.image.write_only |= qual->flags.q.write_only;
-      var->data.image.coherent |= qual->flags.q.coherent;
-      var->data.image._volatile |= qual->flags.q._volatile;
-      var->data.image.restrict_flag |= qual->flags.q.restrict_flag;
+      var->data.image_read_only |= qual->flags.q.read_only;
+      var->data.image_write_only |= qual->flags.q.write_only;
+      var->data.image_coherent |= qual->flags.q.coherent;
+      var->data.image_volatile |= qual->flags.q._volatile;
+      var->data.image_restrict |= qual->flags.q.restrict_flag;
       var->data.read_only = true;
 
       if (qual->flags.q.explicit_image_format) {
@@ -2332,7 +2332,7 @@ apply_image_qualifier_to_variable(const struct ast_type_qualifier *qual,
                              "base data type of the image");
          }
 
-         var->data.image.format = qual->image_format;
+         var->data.image_format = qual->image_format;
       } else {
          if (var->data.mode == ir_var_uniform && !qual->flags.q.write_only) {
             _mesa_glsl_error(loc, state, "uniforms not qualified with "
@@ -2340,7 +2340,7 @@ apply_image_qualifier_to_variable(const struct ast_type_qualifier *qual,
                              "qualifier");
          }
 
-         var->data.image.format = GL_NONE;
+         var->data.image_format = GL_NONE;
       }
    }
 }
diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
index f9f0686..4b538c7 100644
--- a/src/glsl/builtin_functions.cpp
+++ b/src/glsl/builtin_functions.cpp
@@ -4301,11 +4301,11 @@ builtin_builder::_image_prototype(const glsl_type *image_type,
     * accept everything that needs to be accepted, and reject cases
     * like loads from write-only or stores to read-only images.
     */
-   image->data.image.read_only = flags & IMAGE_FUNCTION_READ_ONLY;
-   image->data.image.write_only = flags & IMAGE_FUNCTION_WRITE_ONLY;
-   image->data.image.coherent = true;
-   image->data.image._volatile = true;
-   image->data.image.restrict_flag = true;
+   image->data.image_read_only = (flags & IMAGE_FUNCTION_READ_ONLY) != 0;
+   image->data.image_write_only = (flags & IMAGE_FUNCTION_WRITE_ONLY) != 0;
+   image->data.image_coherent = true;
+   image->data.image_volatile = true;
+   image->data.image_restrict = true;
 
    return sig;
 }
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index 65541c2..c727d89 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -1563,11 +1563,11 @@ ir_variable::ir_variable(const struct glsl_type *type, const char *name,
    this->data.interpolation = INTERP_QUALIFIER_NONE;
    this->data.max_array_access = 0;
    this->data.atomic.offset = 0;
-   this->data.image.read_only = false;
-   this->data.image.write_only = false;
-   this->data.image.coherent = false;
-   this->data.image._volatile = false;
-   this->data.image.restrict_flag = false;
+   this->data.image_read_only = false;
+   this->data.image_write_only = false;
+   this->data.image_coherent = false;
+   this->data.image_volatile = false;
+   this->data.image_restrict = false;
 
    if (type != NULL) {
       if (type->base_type == GLSL_TYPE_SAMPLER)
@@ -1673,11 +1673,11 @@ ir_function_signature::qualifiers_match(exec_list *params)
 	  a->data.interpolation != b->data.interpolation ||
 	  a->data.centroid != b->data.centroid ||
           a->data.sample != b->data.sample ||
-          a->data.image.read_only != b->data.image.read_only ||
-          a->data.image.write_only != b->data.image.write_only ||
-          a->data.image.coherent != b->data.image.coherent ||
-          a->data.image._volatile != b->data.image._volatile ||
-          a->data.image.restrict_flag != b->data.image.restrict_flag) {
+          a->data.image_read_only != b->data.image_read_only ||
+          a->data.image_write_only != b->data.image_write_only ||
+          a->data.image_coherent != b->data.image_coherent ||
+          a->data.image_volatile != b->data.image_volatile ||
+          a->data.image_restrict != b->data.image_restrict) {
 
 	 /* parameter a's qualifiers don't match */
 	 return a->name;
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 3767f2a..fac24df 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -659,6 +659,19 @@ public:
        */
       unsigned index:1;
 
+
+      /**
+       * ARB_shader_image_load_store qualifiers.
+       */
+      unsigned image_read_only:1; /**< "readonly" qualifier. */
+      unsigned image_write_only:1; /**< "writeonly" qualifier. */
+      unsigned image_coherent:1;
+      unsigned image_volatile:1;
+      unsigned image_restrict:1;
+
+      /** Image internal format if specified explicitly, otherwise GL_NONE. */
+      uint16_t image_format;
+
       /**
        * \brief Layout qualifier for gl_FragDepth.
        *
@@ -702,20 +715,6 @@ public:
       } atomic;
 
       /**
-       * ARB_shader_image_load_store qualifiers.
-       */
-      struct {
-         bool read_only; /**< "readonly" qualifier. */
-         bool write_only; /**< "writeonly" qualifier. */
-         bool coherent;
-         bool _volatile;
-         bool restrict_flag;
-
-         /** Image internal format if specified explicitly, otherwise GL_NONE. */
-         GLenum format;
-      } image;
-
-      /**
        * Highest element accessed with a constant expression array index
        *
        * Not used for non-array variables.
diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp
index c7147e0..e7a8da6 100644
--- a/src/glsl/link_uniforms.cpp
+++ b/src/glsl/link_uniforms.cpp
@@ -780,8 +780,8 @@ link_set_image_access_qualifiers(struct gl_shader_program *prog)
             (void) found;
             const gl_uniform_storage *storage = &prog->UniformStorage[id];
             const unsigned index = storage->image[i].index;
-            const GLenum access = (var->data.image.read_only ? GL_READ_ONLY :
-                                   var->data.image.write_only ? GL_WRITE_ONLY :
+            const GLenum access = (var->data.image_read_only ? GL_READ_ONLY :
+                                   var->data.image_write_only ? GL_WRITE_ONLY :
                                    GL_READ_WRITE);
 
             for (unsigned j = 0; j < MAX2(1, storage->array_elements); ++j)
-- 
1.8.1.4



More information about the mesa-dev mailing list