[Mesa-dev] [PATCH V2] glsl: add support for doubles in GL 4.4+

Timothy Arceri timothy.arceri at collabora.com
Tue May 24 01:34:15 UTC 2016


We disable varying packing in GL 4.4+ as we can no longer assume
varying have the same interpolation qualifiers. However doubles used
as fs inputs must always be qualified as "flat" and backends expect
doubles to have been packed as floats so we enable packing for them.

V2: fix comments and only call without_array() one type once. Also
make sure we don't enable packing for doubles if we are dealing
with a tessellation interface that doesn't support packing.

Cc: Iago Toral Quiroga <itoral at igalia.com>
---
 src/compiler/glsl/ir_optimization.h         |  3 ++-
 src/compiler/glsl/link_varyings.cpp         |  5 +++--
 src/compiler/glsl/lower_packed_varyings.cpp | 22 ++++++++++++++--------
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h
index 5fc2740..e26149f 100644
--- a/src/compiler/glsl/ir_optimization.h
+++ b/src/compiler/glsl/ir_optimization.h
@@ -127,7 +127,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 xfb_enabled);
+                           bool disable_varying_packing, bool xfb_enabled,
+                           bool unpackable_tess);
 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 1782a96..a89a220 100644
--- a/src/compiler/glsl/link_varyings.cpp
+++ b/src/compiler/glsl/link_varyings.cpp
@@ -2214,13 +2214,14 @@ 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,
-                            xfb_enabled);
+                            xfb_enabled, unpackable_tess);
    }
 
    if (consumer) {
       lower_packed_varyings(mem_ctx, slots_used, ir_var_shader_in,
                             consumer_vertices, consumer,
-                            disable_varying_packing, xfb_enabled);
+                            disable_varying_packing, xfb_enabled,
+                            unpackable_tess);
    }
 
    return true;
diff --git a/src/compiler/glsl/lower_packed_varyings.cpp b/src/compiler/glsl/lower_packed_varyings.cpp
index 41edada..b22f85d 100644
--- a/src/compiler/glsl/lower_packed_varyings.cpp
+++ b/src/compiler/glsl/lower_packed_varyings.cpp
@@ -170,7 +170,7 @@ public:
                                  exec_list *out_instructions,
                                  exec_list *out_variables,
                                  bool disable_varying_packing,
-                                 bool xfb_enabled);
+                                 bool xfb_enabled, bool unpackable_tess);
 
    void run(struct gl_shader *shader);
 
@@ -236,6 +236,7 @@ private:
 
    bool disable_varying_packing;
    bool xfb_enabled;
+   bool unpackable_tess;
 };
 
 } /* anonymous namespace */
@@ -244,7 +245,7 @@ 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,
-      bool xfb_enabled)
+      bool xfb_enabled, bool unpackable_tess)
    : mem_ctx(mem_ctx),
      locations_used(locations_used),
      packed_varyings((ir_variable **)
@@ -255,7 +256,8 @@ lower_packed_varyings_visitor::lower_packed_varyings_visitor(
      out_instructions(out_instructions),
      out_variables(out_variables),
      disable_varying_packing(disable_varying_packing),
-     xfb_enabled(xfb_enabled)
+     xfb_enabled(xfb_enabled),
+     unpackable_tess(unpackable_tess)
 {
 }
 
@@ -667,16 +669,20 @@ lower_packed_varyings_visitor::needs_lowering(ir_variable *var)
    /* Override disable_varying_packing if the var is only used by transform
     * feedback. Also override it if transform feedback is enabled and the
     * variable is an array, struct or matrix as the elements of these types
-    * will always has the same interpolation and therefore asre safe to pack.
+    * will always have the same interpolation and therefore are safe to pack.
+    *
+    * We also override disable_varying_packing for doubles used as fs inputs
+    * because they must always be qualified as "flat".
     */
    const glsl_type *type = var->type;
+   const glsl_type *wa_type = type->without_array();
    if (disable_varying_packing && !var->data.is_xfb_only &&
+       (!wa_type->is_double() || unpackable_tess) &&
        !((type->is_array() || type->is_record() || type->is_matrix()) &&
          xfb_enabled))
       return false;
 
-   type = type->without_array();
-   if (type->vector_elements == 4 && !type->is_double())
+   if (wa_type->vector_elements == 4 && !wa_type->is_double())
       return false;
    return true;
 }
@@ -768,7 +774,7 @@ 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 xfb_enabled)
+                      bool xfb_enabled, bool unpackable_tess)
 {
    exec_list *instructions = shader->ir;
    ir_function *main_func = shader->symbols->get_function("main");
@@ -781,7 +787,7 @@ lower_packed_varyings(void *mem_ctx, unsigned locations_used,
                                          &new_instructions,
                                          &new_variables,
                                          disable_varying_packing,
-                                         xfb_enabled);
+                                         xfb_enabled, unpackable_tess);
    visitor.run(shader);
    if (mode == ir_var_shader_out) {
       if (shader->Stage == MESA_SHADER_GEOMETRY) {
-- 
2.5.5



More information about the mesa-dev mailing list