[Mesa-dev] [PATCH 11/26] glsl: enable lowering of varyings with explicit component

Timothy Arceri timothy.arceri at collabora.com
Mon Feb 29 01:17:51 UTC 2016


Reviewed-by: Anuj Phogat <anuj.phogat at gmail.com>
Reviewed-by: Edward O'Callaghan <eocallaghan at alterapraxis.com>
---
 src/compiler/glsl/ir_optimization.h         |  3 ++-
 src/compiler/glsl/link_varyings.cpp         |  6 ++++--
 src/compiler/glsl/lower_packed_varyings.cpp | 31 ++++++++++++++++++++---------
 3 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h
index 30c95f4..b569366 100644
--- a/src/compiler/glsl/ir_optimization.h
+++ b/src/compiler/glsl/ir_optimization.h
@@ -125,7 +125,8 @@ void lower_ubo_reference(struct gl_shader *shader);
 void lower_packed_varyings(void *mem_ctx,
                            unsigned locations_used, ir_variable_mode mode,
                            unsigned gs_input_vertices, gl_shader *shader,
-                           bool disable_varying_packing);
+                           bool disable_varying_packing,
+                           bool has_enhanced_layouts);
 bool lower_vector_insert(exec_list *instructions, bool lower_nonconstant_index);
 bool lower_vector_derefs(gl_shader *shader);
 void lower_named_interface_blocks(void *mem_ctx, gl_shader *shader);
diff --git a/src/compiler/glsl/link_varyings.cpp b/src/compiler/glsl/link_varyings.cpp
index 9ab95d2..5c73064 100644
--- a/src/compiler/glsl/link_varyings.cpp
+++ b/src/compiler/glsl/link_varyings.cpp
@@ -1843,13 +1843,15 @@ assign_varying_locations(struct gl_context *ctx,
 
    if (producer) {
       lower_packed_varyings(mem_ctx, slots_used, ir_var_shader_out,
-                            0, producer, disable_varying_packing);
+                            0, producer, disable_varying_packing,
+                            ctx->Extensions.ARB_enhanced_layouts);
    }
 
    if (consumer) {
       lower_packed_varyings(mem_ctx, slots_used, ir_var_shader_in,
                             consumer_vertices, consumer,
-                            disable_varying_packing);
+                            disable_varying_packing,
+                            ctx->Extensions.ARB_enhanced_layouts);
    }
 
    return true;
diff --git a/src/compiler/glsl/lower_packed_varyings.cpp b/src/compiler/glsl/lower_packed_varyings.cpp
index 4723c2b..831a542 100644
--- a/src/compiler/glsl/lower_packed_varyings.cpp
+++ b/src/compiler/glsl/lower_packed_varyings.cpp
@@ -169,7 +169,8 @@ public:
                                  unsigned gs_input_vertices,
                                  exec_list *out_instructions,
                                  exec_list *out_variables,
-                                 bool disable_varying_packing);
+                                 bool disable_varying_packing,
+                                 bool has_enhanced_layouts);
 
    void run(struct gl_shader *shader);
 
@@ -236,6 +237,7 @@ private:
    exec_list *out_variables;
 
    bool disable_varying_packing;
+   bool has_enhanced_layouts;
 };
 
 } /* anonymous namespace */
@@ -243,7 +245,8 @@ private:
 lower_packed_varyings_visitor::lower_packed_varyings_visitor(
       void *mem_ctx, unsigned locations_used, ir_variable_mode mode,
       unsigned gs_input_vertices, exec_list *out_instructions,
-      exec_list *out_variables, bool disable_varying_packing)
+      exec_list *out_variables, bool disable_varying_packing,
+      bool has_enhanced_layouts)
    : mem_ctx(mem_ctx),
      locations_used(locations_used),
      packed_varyings((ir_variable **)
@@ -253,7 +256,8 @@ lower_packed_varyings_visitor::lower_packed_varyings_visitor(
      gs_input_vertices(gs_input_vertices),
      out_instructions(out_instructions),
      out_variables(out_variables),
-     disable_varying_packing(disable_varying_packing)
+     disable_varying_packing(disable_varying_packing),
+     has_enhanced_layouts(has_enhanced_layouts)
 {
 }
 
@@ -673,15 +677,22 @@ lower_packed_varyings_visitor::get_packed_varying_deref(
 bool
 lower_packed_varyings_visitor::needs_lowering(ir_variable *var)
 {
-   /* Things composed of vec4's and varyings with explicitly assigned
-    * locations don't need lowering.  Everything else does.
+   /* Don't lower varying with explicit location unless ARB_enhanced_layouts
+    * is enabled, also don't try to pack structs with explicit location as
+    * they don't support the component layout qualifier anyway.
     */
-   if (var->data.explicit_location)
+   if (var->data.explicit_location && (!has_enhanced_layouts ||
+       var->type->without_array()->is_record())) {
       return false;
+   }
 
-   if (disable_varying_packing)
+   /* Don't disable packing for explicit locations when ARB_enhanced_layouts
+    * is supported.
+    */
+   if (disable_varying_packing && !var->data.explicit_location)
       return false;
 
+   /* Things composed of vec4's don't need lowering everything else does. */
    const glsl_type *type = var->type->without_array();
    if (type->vector_elements == 4 && !type->is_double())
       return false;
@@ -735,7 +746,8 @@ lower_packed_varyings_gs_splicer::visit_leave(ir_emit_vertex *ev)
 void
 lower_packed_varyings(void *mem_ctx, unsigned locations_used,
                       ir_variable_mode mode, unsigned gs_input_vertices,
-                      gl_shader *shader, bool disable_varying_packing)
+                      gl_shader *shader, bool disable_varying_packing,
+                      bool has_enhanced_layouts)
 {
    ir_function *main_func = shader->symbols->get_function("main");
    exec_list void_parameters;
@@ -752,7 +764,8 @@ lower_packed_varyings(void *mem_ctx, unsigned locations_used,
                                             gs_input_vertices,
                                             &new_instructions,
                                             &new_variables,
-                                            disable_varying_packing);
+                                            disable_varying_packing,
+                                            has_enhanced_layouts);
       visitor.run(shader);
       if (mode == ir_var_shader_out) {
          if (shader->Stage == MESA_SHADER_GEOMETRY) {
-- 
2.5.0



More information about the mesa-dev mailing list