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

Anuj Phogat anuj.phogat at gmail.com
Thu Jan 7 16:56:53 PST 2016


On Mon, Dec 28, 2015 at 9:00 PM, Timothy Arceri
<timothy.arceri at collabora.com> wrote:
> ---
>  src/glsl/ir_optimization.h         |  3 ++-
>  src/glsl/link_varyings.cpp         |  6 ++++--
>  src/glsl/lower_packed_varyings.cpp | 33 ++++++++++++++++++++++++---------
>  3 files changed, 30 insertions(+), 12 deletions(-)
>
> diff --git a/src/glsl/ir_optimization.h b/src/glsl/ir_optimization.h
> index 19ebf86..eab76ff 100644
> --- a/src/glsl/ir_optimization.h
> +++ b/src/glsl/ir_optimization.h
> @@ -129,7 +129,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/glsl/link_varyings.cpp b/src/glsl/link_varyings.cpp
> index 7e6089d..7066481 100644
> --- a/src/glsl/link_varyings.cpp
> +++ b/src/glsl/link_varyings.cpp
> @@ -1876,13 +1876,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/glsl/lower_packed_varyings.cpp b/src/glsl/lower_packed_varyings.cpp
> index e4e9a35..1696373 100644
> --- a/src/glsl/lower_packed_varyings.cpp
> +++ b/src/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,24 @@ 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 and doubles don't need lowering everything
> +    * else does.
> +    */
Doubles always need lowering. What below code says is: vec4's which are not
doubles don't need lowering.

>     const glsl_type *type = var->type->without_array();
>     if (type->vector_elements == 4 && !type->is_double())
>        return false;
> @@ -735,7 +748,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;
> @@ -751,7 +765,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.4.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev

With above comment fixed:
Reviewed-by: Anuj Phogat <anuj.phogat at gmail.com>


More information about the mesa-dev mailing list