Mesa (master): glsl/gs: add gl_in support to builtin_variables.cpp.

Paul Berry stereotype441 at kemper.freedesktop.org
Tue Oct 8 19:59:54 UTC 2013


Module: Mesa
Branch: master
Commit: c09adcb21bd2c3993f1e8a4997d718d9fee89e6d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c09adcb21bd2c3993f1e8a4997d718d9fee89e6d

Author: Paul Berry <stereotype441 at gmail.com>
Date:   Fri Aug  2 18:12:23 2013 -0700

glsl/gs: add gl_in support to builtin_variables.cpp.

Previously, builtin_variables.cpp was written assuming that we
supported ARB_geometry_shader4 style geometry shader inputs, meaning
that each built-in varying input to a geometry was supplied via an
array variable whose name ended in "In", e.g. gl_PositionIn or
gl_PointSizeIn.

However, in GLSL 1.50 style geometry shaders, things work
differently--built-in inputs are supplied to geometry shaders via a
built-in interface block called gl_in, which contains all the built-in
inputs using their usual names (e.g. the gl_Position input is supplied
to the geometry shader as gl_in[i].gl_Position).

This patch adds the necessary logic to builtin_variables.cpp to create
the gl_in interface block and populate it accordingly for geometry
shader inputs.  The old ARB_geometry_shader4 style varyings are
removed, though they can easily be added back in the future if we
decide to support ARB_geometry_shader4.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Jordan Justen <jordan.l.justen at intel.com>

---

 src/glsl/builtin_variables.cpp |   33 +++++++++++++++++++++++++++++++--
 1 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/src/glsl/builtin_variables.cpp b/src/glsl/builtin_variables.cpp
index cb970fb..e2f69fa 100644
--- a/src/glsl/builtin_variables.cpp
+++ b/src/glsl/builtin_variables.cpp
@@ -358,6 +358,17 @@ private:
    const glsl_type * const vec4_t;
    const glsl_type * const mat3_t;
    const glsl_type * const mat4_t;
+
+   /**
+    * Array where the contents of the gl_PerVertex interface instance are
+    * accumulated.
+    */
+   glsl_struct_field per_vertex_fields[10];
+
+   /**
+    * Number of elements of per_vertex_fields which have been populated.
+    */
+   unsigned num_per_vertex_fields;
 };
 
 
@@ -368,7 +379,8 @@ builtin_variable_generator::builtin_variable_generator(
      bool_t(glsl_type::bool_type), int_t(glsl_type::int_type),
      float_t(glsl_type::float_type), vec2_t(glsl_type::vec2_type),
      vec3_t(glsl_type::vec3_type), vec4_t(glsl_type::vec4_type),
-     mat3_t(glsl_type::mat3_type), mat4_t(glsl_type::mat4_type)
+     mat3_t(glsl_type::mat3_type), mat4_t(glsl_type::mat4_type),
+     num_per_vertex_fields(0)
 {
 }
 
@@ -757,7 +769,13 @@ builtin_variable_generator::add_varying(int slot, const glsl_type *type,
 {
    switch (state->target) {
    case geometry_shader:
-      add_input(slot, array(type, 0), name_as_gs_input);
+      assert(this->num_per_vertex_fields <
+             ARRAY_SIZE(this->per_vertex_fields));
+      this->per_vertex_fields[this->num_per_vertex_fields].type = type;
+      this->per_vertex_fields[this->num_per_vertex_fields].name = name;
+      this->per_vertex_fields[this->num_per_vertex_fields].row_major = false;
+      this->per_vertex_fields[this->num_per_vertex_fields].location = slot;
+      this->num_per_vertex_fields++;
       /* FALLTHROUGH */
    case vertex_shader:
       add_output(slot, type, name);
@@ -804,6 +822,17 @@ builtin_variable_generator::generate_varyings()
          ADD_VARYING(VARYING_SLOT_BFC1, vec4_t, "gl_BackSecondaryColor");
       }
    }
+
+   if (state->target == geometry_shader) {
+      const glsl_type *per_vertex_type =
+         glsl_type::get_interface_instance(this->per_vertex_fields,
+                                           this->num_per_vertex_fields,
+                                           GLSL_INTERFACE_PACKING_STD140,
+                                           "gl_in");
+      ir_variable *var = add_variable("gl_in", array(per_vertex_type, 0),
+                                      ir_var_shader_in, 0);
+      var->interface_type = per_vertex_type;
+   }
 }
 
 




More information about the mesa-commit mailing list