<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Mar 18, 2016 at 2:32 PM, Francisco Jerez <span dir="ltr"><<a href="mailto:currojerez@riseup.net" target="_blank">currojerez@riseup.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> writes:<br>
<br>
> ---<br>
> src/compiler/Makefile.sources | 1 +<br>
> src/compiler/glsl/glsl_parser_extras.cpp | 1 +<br>
> src/compiler/glsl/ir_optimization.h | 1 +<br>
> src/compiler/glsl/propagate_invariance.cpp | 125 +++++++++++++++++++++++++++++<br>
> 4 files changed, 128 insertions(+)<br>
> create mode 100644 src/compiler/glsl/propagate_invariance.cpp<br>
><br>
> diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources<br>
> index 9f3bcf0..6ab0aa7 100644<br>
> --- a/src/compiler/Makefile.sources<br>
> +++ b/src/compiler/Makefile.sources<br>
> @@ -129,6 +129,7 @@ LIBGLSL_FILES = \<br>
> glsl/opt_tree_grafting.cpp \<br>
> glsl/opt_vectorize.cpp \<br>
> glsl/program.h \<br>
> + glsl/propagate_invariance.cpp \<br>
> glsl/s_expression.cpp \<br>
> glsl/s_expression.h<br>
><br>
> diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp<br>
> index 1c6cd43..9fcca21 100644<br>
> --- a/src/compiler/glsl/glsl_parser_extras.cpp<br>
> +++ b/src/compiler/glsl/glsl_parser_extras.cpp<br>
> @@ -1885,6 +1885,7 @@ do_common_optimization(exec_list *ir, bool linked,<br>
> OPT(do_dead_functions, ir);<br>
> OPT(do_structure_splitting, ir);<br>
> }<br>
> + propagate_invariance(ir);<br>
> OPT(do_if_simplification, ir);<br>
> OPT(opt_flatten_nested_if_blocks, ir);<br>
> OPT(opt_conditional_discard, ir);<br>
> diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h<br>
> index b56413a..4616f16 100644<br>
> --- a/src/compiler/glsl/ir_optimization.h<br>
> +++ b/src/compiler/glsl/ir_optimization.h<br>
> @@ -138,6 +138,7 @@ bool lower_tess_level(gl_shader *shader);<br>
> bool lower_vertex_id(gl_shader *shader);<br>
><br>
> bool lower_subroutine(exec_list *instructions, struct _mesa_glsl_parse_state *state);<br>
> +void propagate_invariance(exec_list *instructions);<br>
><br>
> ir_rvalue *<br>
> compare_index_block(exec_list *instructions, ir_variable *index,<br>
> diff --git a/src/compiler/glsl/propagate_invariance.cpp b/src/compiler/glsl/propagate_invariance.cpp<br>
> new file mode 100644<br>
> index 0000000..820259e<br>
> --- /dev/null<br>
> +++ b/src/compiler/glsl/propagate_invariance.cpp<br>
> @@ -0,0 +1,125 @@<br>
> +/*<br>
> + * Copyright © 2010 Intel Corporation<br>
> + *<br>
<br>
</div></div>Wow, that's been a while ;)<br></blockquote><div><br></div><div>Right. That's what I get for blindly copying and pasting. Updated to 2016 locally. Thanks!<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice (including the next<br>
> + * paragraph) shall be included in all copies or substantial portions of the<br>
> + * Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
> + * DEALINGS IN THE SOFTWARE.<br>
> + */<br>
> +<br>
> +/**<br>
> + * \file propagate_invariance.cpp<br>
> + * Propagate the "invariant" and "precise" qualifiers to variables used to<br>
> + * compute invariant or precise values.<br>
> + *<br>
> + * The GLSL spec (depending on what version you read) says, among the<br>
> + * conditions for geting bit-for-bit the same values on an invariant output:<br>
> + *<br>
> + * "All operations in the consuming expressions and any intermediate<br>
> + * expressions must be the same, with the same order of operands and same<br>
> + * associativity, to give the same order of evaluation."<br>
> + *<br>
> + * This effectively means that if a variable is used to compute an invariant<br>
> + * value then that variable becomes invariant. The same should apply to the<br>
> + * "precise" qualifier.<br>
> + */<br>
> +<br>
> +#include "ir.h"<br>
> +#include "ir_visitor.h"<br>
> +#include "ir_rvalue_visitor.h"<br>
> +#include "ir_optimization.h"<br>
> +#include "compiler/glsl_types.h"<br>
> +<br>
> +namespace {<br>
> +<br>
> +class ir_invariance_propagation_visitor : public ir_hierarchical_visitor {<br>
> +public:<br>
> + ir_invariance_propagation_visitor()<br>
> + {<br>
> + this->progress = false;<br>
> + this->dst_var = NULL;<br>
> + }<br>
> +<br>
> + virtual ~ir_invariance_propagation_visitor()<br>
> + {<br>
> + /* empty */<br>
> + }<br>
> +<br>
<br>
</div></div>Redundant destructor?<br><div><div class="h5"></div></div></blockquote><div><br></div><div>Perhaps? I thought it was somewhat customary to always provide a virtual destructor whenever you have any sort of "real" inheritance going on. I guess it's probably ok since the one instantiation of this class is in this file. However, the other passes I looked at all had destructors exactly like that one so I just followed what they did.<br><br></div><div>I don't care one way or the other. I can remove it if you'd like.<br></div><div>--Jason <br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
> + virtual ir_visitor_status visit_enter(ir_assignment *ir);<br>
> + virtual ir_visitor_status visit_leave(ir_assignment *ir);<br>
> + virtual ir_visitor_status visit(ir_dereference_variable *ir);<br>
> +<br>
> + ir_variable *dst_var;<br>
> + bool progress;<br>
> +};<br>
> +<br>
> +} /* unnamed namespace */<br>
> +<br>
> +ir_visitor_status<br>
> +ir_invariance_propagation_visitor::visit_enter(ir_assignment *ir)<br>
> +{<br>
> + assert(this->dst_var == NULL);<br>
> + ir_variable *var = ir->lhs->variable_referenced();<br>
> + if (var->data.invariant || var->data.precise) {<br>
> + this->dst_var = var;<br>
> + return visit_continue;<br>
> + } else {<br>
> + return visit_continue_with_parent;<br>
> + }<br>
> +}<br>
> +<br>
> +ir_visitor_status<br>
> +ir_invariance_propagation_visitor::visit_leave(ir_assignment *ir)<br>
> +{<br>
> + this->dst_var = NULL;<br>
> +<br>
> + return visit_continue;<br>
> +}<br>
> +<br>
> +ir_visitor_status<br>
> +ir_invariance_propagation_visitor::visit(ir_dereference_variable *ir)<br>
> +{<br>
> + if (this->dst_var == NULL)<br>
> + return visit_continue;<br>
> +<br>
> + if (this->dst_var->data.invariant) {<br>
> + if (!ir->var->data.invariant)<br>
> + this->progress = true;<br>
> +<br>
> + ir->var->data.invariant = true;<br>
> + }<br>
> +<br>
> + if (this->dst_var->data.precise) {<br>
> + if (!ir->var->data.precise)<br>
> + this->progress = true;<br>
> +<br>
> + ir->var->data.precise = true;<br>
> + }<br>
> +<br>
> + return visit_continue;<br>
> +}<br>
> +<br>
> +void<br>
> +propagate_invariance(exec_list *instructions)<br>
> +{<br>
> + ir_invariance_propagation_visitor visitor;<br>
> +<br>
> + do {<br>
> + visitor.progress = false;<br>
> + visit_list_elements(&visitor, instructions);<br>
> + } while (visitor.progress);<br>
> +}<br>
<br>
</div></div>Reviewed-by: Francisco Jerez <<a href="mailto:currojerez@riseup.net">currojerez@riseup.net</a>><br>
<span class="HOEnZb"><font color="#888888"><br>
> --<br>
> 2.5.0.400.gff86faf<br>
><br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>