[Mesa-dev] [PATCH 07/21] glsl: Replace ir_variable::warn_extension pointer with an 8-bit index

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


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

Also move the new warn_extension_index into ir_variable::data.  This
enables slightly better packing.

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: 5955672 1439077 7394749
After:  IR MEM: variable usage / name / total: 5746368 1439077 7185445

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

Before: IR MEM: variable usage / name / total: 4536888 915817 5452705
After:  IR MEM: variable usage / name / total: 4432236 915817 5348053

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glsl/ir.cpp       | 21 ++++++++++++++++++---
 src/glsl/ir.h         | 18 +++++++++++++-----
 src/glsl/ir_clone.cpp |  2 --
 3 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index 3d6af56..65a755e 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -1547,7 +1547,7 @@ ir_variable::ir_variable(const struct glsl_type *type, const char *name,
    this->data.location = -1;
    this->data.location_frac = 0;
    this->data.binding = 0;
-   this->warn_extension = NULL;
+   this->data.warn_extension_index = 0;
    this->constant_value = NULL;
    this->constant_initializer = NULL;
    this->data.origin_upper_left = false;
@@ -1610,16 +1610,31 @@ ir_variable::determine_interpolation_mode(bool flat_shade)
       return INTERP_QUALIFIER_SMOOTH;
 }
 
+const char *const ir_variable::warn_extension_table[] = {
+   "",
+   "GL_ARB_shader_stencil_export",
+   "GL_AMD_shader_stencil_export",
+};
+
 void
 ir_variable::enable_extension_warning(const char *extension)
 {
-   this->warn_extension = extension;
+   for (unsigned i = 0; i < Elements(warn_extension_table); i++) {
+      if (strcmp(warn_extension_table[i], extension) == 0) {
+         this->data.warn_extension_index = i;
+         return;
+      }
+   }
+
+   assert(!"Should not get here.");
+   this->data.warn_extension_index = 0;
 }
 
 const char *
 ir_variable::get_extension_warning() const
 {
-   return this->warn_extension;
+   return this->data.warn_extension_index == 0
+      ? NULL : warn_extension_table[this->data.warn_extension_index];
 }
 
 ir_function_signature::ir_function_signature(const glsl_type *return_type,
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 3298a50..4147bbc 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -685,6 +685,13 @@ public:
       uint16_t image_format;
 
       /**
+       * Emit a warning if this variable is accessed.
+       */
+   private:
+      uint8_t warn_extension_index;
+
+   public:
+      /**
        * \brief Layout qualifier for gl_FragDepth.
        *
        * This is not equal to \c ir_depth_layout_none if and only if this
@@ -733,6 +740,10 @@ public:
        */
       unsigned max_array_access;
 
+      /**
+       * Allow (only) ir_variable direct access private members.
+       */
+      friend class ir_variable;
    } data;
 
    /**
@@ -767,6 +778,8 @@ public:
    ir_constant *constant_initializer;
 
 private:
+   static const char *const warn_extension_table[];
+
    /**
     * For variables that are in an interface block or are an instance of an
     * interface block, this is the \c GLSL_TYPE_INTERFACE type for that block.
@@ -774,11 +787,6 @@ private:
     * \sa ir_variable::location
     */
    const glsl_type *interface_type;
-
-   /**
-    * Emit a warning if this variable is accessed.
-    */
-   const char *warn_extension;
 };
 
 /**
diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp
index c00adc5..d594529 100644
--- a/src/glsl/ir_clone.cpp
+++ b/src/glsl/ir_clone.cpp
@@ -53,8 +53,6 @@ ir_variable::clone(void *mem_ctx, struct hash_table *ht) const
 
    memcpy(&var->data, &this->data, sizeof(var->data));
 
-   var->warn_extension = this->warn_extension;
-
    var->num_state_slots = this->num_state_slots;
    if (this->state_slots) {
       /* FINISHME: This really wants to use something like talloc_reference, but
-- 
1.8.1.4



More information about the mesa-dev mailing list