[Mesa-dev] [PATCH 1/4] glsl: Keep track of location for interface block fields.

Paul Berry stereotype441 at gmail.com
Sat Sep 14 13:00:33 PDT 2013


This patch adds a "location" element to struct glsl_struct_field, so
that we can keep track of the gl_varying_slot associated with each
built-in geometry shader input.

In lower_named_interface_blocks, we use this value to populate the
"location" field in the ir_variable that stores each geometry shader
input.
---
 src/glsl/ast_to_hir.cpp                   |  1 +
 src/glsl/builtin_types.cpp                | 74 +++++++++++++++----------------
 src/glsl/glsl_types.cpp                   |  2 +
 src/glsl/glsl_types.h                     |  9 ++++
 src/glsl/lower_named_interface_blocks.cpp |  1 +
 5 files changed, 50 insertions(+), 37 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 2316cf8..c156009 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -4491,6 +4491,7 @@ ast_process_structure_or_interface_block(exec_list *instructions,
 	 }
          fields[i].type = field_type;
 	 fields[i].name = decl->identifier;
+         fields[i].location = -1;
 
          if (qual->flags.q.row_major || qual->flags.q.column_major) {
             if (!qual->flags.q.uniform) {
diff --git a/src/glsl/builtin_types.cpp b/src/glsl/builtin_types.cpp
index 722eda2..1a5e5a1 100644
--- a/src/glsl/builtin_types.cpp
+++ b/src/glsl/builtin_types.cpp
@@ -53,64 +53,64 @@
       &glsl_type::_struct_##NAME##_type;
 
 static const struct glsl_struct_field gl_DepthRangeParameters_fields[] = {
-   { glsl_type::float_type, "near", false },
-   { glsl_type::float_type, "far",  false },
-   { glsl_type::float_type, "diff", false },
+   { glsl_type::float_type, "near", false, -1 },
+   { glsl_type::float_type, "far",  false, -1 },
+   { glsl_type::float_type, "diff", false, -1 },
 };
 
 static const struct glsl_struct_field gl_PointParameters_fields[] = {
-   { glsl_type::float_type, "size", false },
-   { glsl_type::float_type, "sizeMin", false },
-   { glsl_type::float_type, "sizeMax", false },
-   { glsl_type::float_type, "fadeThresholdSize", false },
-   { glsl_type::float_type, "distanceConstantAttenuation", false },
-   { glsl_type::float_type, "distanceLinearAttenuation", false },
-   { glsl_type::float_type, "distanceQuadraticAttenuation", false },
+   { glsl_type::float_type, "size", false, -1 },
+   { glsl_type::float_type, "sizeMin", false, -1 },
+   { glsl_type::float_type, "sizeMax", false, -1 },
+   { glsl_type::float_type, "fadeThresholdSize", false, -1 },
+   { glsl_type::float_type, "distanceConstantAttenuation", false, -1 },
+   { glsl_type::float_type, "distanceLinearAttenuation", false, -1 },
+   { glsl_type::float_type, "distanceQuadraticAttenuation", false, -1 },
 };
 
 static const struct glsl_struct_field gl_MaterialParameters_fields[] = {
-   { glsl_type::vec4_type, "emission", false },
-   { glsl_type::vec4_type, "ambient", false },
-   { glsl_type::vec4_type, "diffuse", false },
-   { glsl_type::vec4_type, "specular", false },
-   { glsl_type::float_type, "shininess", false },
+   { glsl_type::vec4_type, "emission", false, -1 },
+   { glsl_type::vec4_type, "ambient", false, -1 },
+   { glsl_type::vec4_type, "diffuse", false, -1 },
+   { glsl_type::vec4_type, "specular", false, -1 },
+   { glsl_type::float_type, "shininess", false, -1 },
 };
 
 static const struct glsl_struct_field gl_LightSourceParameters_fields[] = {
-   { glsl_type::vec4_type, "ambient", false },
-   { glsl_type::vec4_type, "diffuse", false },
-   { glsl_type::vec4_type, "specular", false },
-   { glsl_type::vec4_type, "position", false },
-   { glsl_type::vec4_type, "halfVector", false },
-   { glsl_type::vec3_type, "spotDirection", false },
-   { glsl_type::float_type, "spotExponent", false },
-   { glsl_type::float_type, "spotCutoff", false },
-   { glsl_type::float_type, "spotCosCutoff", false },
-   { glsl_type::float_type, "constantAttenuation", false },
-   { glsl_type::float_type, "linearAttenuation", false },
-   { glsl_type::float_type, "quadraticAttenuation", false },
+   { glsl_type::vec4_type, "ambient", false, -1 },
+   { glsl_type::vec4_type, "diffuse", false, -1 },
+   { glsl_type::vec4_type, "specular", false, -1 },
+   { glsl_type::vec4_type, "position", false, -1 },
+   { glsl_type::vec4_type, "halfVector", false, -1 },
+   { glsl_type::vec3_type, "spotDirection", false, -1 },
+   { glsl_type::float_type, "spotExponent", false, -1 },
+   { glsl_type::float_type, "spotCutoff", false, -1 },
+   { glsl_type::float_type, "spotCosCutoff", false, -1 },
+   { glsl_type::float_type, "constantAttenuation", false, -1 },
+   { glsl_type::float_type, "linearAttenuation", false, -1 },
+   { glsl_type::float_type, "quadraticAttenuation", false, -1 },
 };
 
 static const struct glsl_struct_field gl_LightModelParameters_fields[] = {
-   { glsl_type::vec4_type, "ambient", false },
+   { glsl_type::vec4_type, "ambient", false, -1 },
 };
 
 static const struct glsl_struct_field gl_LightModelProducts_fields[] = {
-   { glsl_type::vec4_type, "sceneColor", false },
+   { glsl_type::vec4_type, "sceneColor", false, -1 },
 };
 
 static const struct glsl_struct_field gl_LightProducts_fields[] = {
-   { glsl_type::vec4_type, "ambient", false },
-   { glsl_type::vec4_type, "diffuse", false },
-   { glsl_type::vec4_type, "specular", false },
+   { glsl_type::vec4_type, "ambient", false, -1 },
+   { glsl_type::vec4_type, "diffuse", false, -1 },
+   { glsl_type::vec4_type, "specular", false, -1 },
 };
 
 static const struct glsl_struct_field gl_FogParameters_fields[] = {
-   { glsl_type::vec4_type, "color", false },
-   { glsl_type::float_type, "density", false },
-   { glsl_type::float_type, "start", false },
-   { glsl_type::float_type, "end", false },
-   { glsl_type::float_type, "scale", false },
+   { glsl_type::vec4_type, "color", false, -1 },
+   { glsl_type::float_type, "density", false, -1 },
+   { glsl_type::float_type, "start", false, -1 },
+   { glsl_type::float_type, "end", false, -1 },
+   { glsl_type::float_type, "scale", false, -1 },
 };
 
 #include "builtin_type_macros.h"
diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index 3c396dd..4782d15 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -100,6 +100,7 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
       this->fields.structure[i].type = fields[i].type;
       this->fields.structure[i].name = ralloc_strdup(this->fields.structure,
 						     fields[i].name);
+      this->fields.structure[i].location = fields[i].location;
       this->fields.structure[i].row_major = fields[i].row_major;
    }
 }
@@ -124,6 +125,7 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
       this->fields.structure[i].type = fields[i].type;
       this->fields.structure[i].name = ralloc_strdup(this->fields.structure,
 						     fields[i].name);
+      this->fields.structure[i].location = fields[i].location;
       this->fields.structure[i].row_major = fields[i].row_major;
    }
 }
diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
index 9f61eee..61c8635 100644
--- a/src/glsl/glsl_types.h
+++ b/src/glsl/glsl_types.h
@@ -581,6 +581,15 @@ struct glsl_struct_field {
    const struct glsl_type *type;
    const char *name;
    bool row_major;
+
+   /**
+    * For interface blocks, gl_varying_slot corresponding to the input/output
+    * if this is a built-in input/output (i.e. a member of the built-in
+    * gl_PerVertex interface block); -1 otherwise.
+    *
+    * Ignored for structs.
+    */
+   int location;
 };
 
 static inline unsigned int
diff --git a/src/glsl/lower_named_interface_blocks.cpp b/src/glsl/lower_named_interface_blocks.cpp
index 20196a3..2bdce5c 100644
--- a/src/glsl/lower_named_interface_blocks.cpp
+++ b/src/glsl/lower_named_interface_blocks.cpp
@@ -146,6 +146,7 @@ flatten_named_interface_blocks_declarations::run(exec_list *instructions)
                                            var_name,
                                            (ir_variable_mode) var->mode);
             }
+            new_var->location = iface_t->fields.structure[i].location;
 
             new_var->interface_type = iface_t;
             hash_table_insert(interface_namespace, new_var,
-- 
1.8.4



More information about the mesa-dev mailing list