glsl: Replace ir_variable::warn_extension pointer with an 8-bit index
authorIan Romanick <ian.d.romanick@intel.com>
Wed, 14 May 2014 20:25:14 +0000 (13:25 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Tue, 30 Sep 2014 20:34:41 +0000 (13:34 -0700)
Also move the new warn_extension_index into ir_variable::data.  This
enables slightly better packing.

Valgrind massif results for a trimmed apitrace of dota2:

                  n        time(i)         total(B)   useful-heap(B) extra-heap(B)    stacks(B)
Before (32-bit): 82 40,580,040,531       68,488,992       62,973,695     5,515,297            0
After  (32-bit): 73 40,580,476,304       68,488,400       62,796,151     5,692,249            0

Before (64-bit): 65 37,124,013,542       95,892,768       88,466,712     7,426,056            0
After  (64-bit): 71 37,124,890,613       95,889,584       88,089,008     7,800,576            0

A real savings of 173KiB on 32-bit and 368KiB on 64-bit.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
src/glsl/ir.cpp
src/glsl/ir.h
src/glsl/ir_clone.cpp

index b83884163d5099e5eb2693ffbefdcf4050ce0804..07f15ee0701f0abebdfcaa625e9c7e69d0f25b46 100644 (file)
@@ -1554,7 +1554,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;
@@ -1617,16 +1617,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,
index 3537ecfd9ac1c4d86b0c8be0f0ce77ea1886d1db..67150ce6cd8dba76722ea48c752f5bd3556ffb47 100644 (file)
@@ -722,6 +722,13 @@ public:
       /** Image internal format if specified explicitly, otherwise GL_NONE. */
       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.
        *
@@ -776,6 +783,10 @@ public:
        */
       unsigned max_array_access;
 
+      /**
+       * Allow (only) ir_variable direct access private members.
+       */
+      friend class ir_variable;
    } data;
 
    /**
@@ -810,6 +821,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.
@@ -817,11 +830,6 @@ private:
     * \sa ir_variable::location
     */
    const glsl_type *interface_type;
-
-   /**
-    * Emit a warning if this variable is accessed.
-    */
-   const char *warn_extension;
 };
 
 /**
index 4b444d4683df0c2832f38215feb0bc4cbed6fd0c..86c0e3166d50eb2c614e59ce527cb35f0b944dc7 100644 (file)
@@ -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