On 19 September 2011 11:10, Ian Romanick <span dir="ltr">&lt;<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
-----BEGIN PGP SIGNED MESSAGE-----<br>
Hash: SHA1<br>
<div><div></div><div class="h5"><br>
On 09/15/2011 04:40 PM, Paul Berry wrote:<br>
&gt; In i965 GEN6+ (and I suspect most other hardware), gl_ClipDistance<br>
&gt; needs to be laid out as a pair of vec4&#39;s (the first containing<br>
&gt; clip distances 0-3, and the second containing clip distances 4-7).<br>
&gt; However, it is declared in GLSL as an array of 8 floats.<br>
&gt;<br>
&gt; This lowering pass acts at the GLSL level, modifying the<br>
&gt; declaration of gl_ClipDistance so that it is an array of vec4&#39;s<br>
&gt; rather than an array of floats, and renaming it to<br>
&gt; gl_ClipDistanceMESA.  In addition, it modifies all accesses to the<br>
&gt; array so that they access the appropiate component of one of the<br>
&gt; vec4&#39;s.<br>
&gt;<br>
&gt; Since some hardware may not internally represent gl_ClipDistance as<br>
&gt; a pair of vec4&#39;s, this lowering pass is optional.  To enable it,<br>
&gt; set the LowerClipDistance flag in gl_shader_compiler_options to<br>
&gt; true. --- src/glsl/Makefile                |    1 +<br>
&gt; src/glsl/SConscript              |    1 +<br>
&gt; src/glsl/ir_optimization.h       |    1 + src/glsl/linker.cpp<br>
&gt; |    3 + src/glsl/lower_clip_distance.cpp |  347<br>
&gt; ++++++++++++++++++++++++++++++++++++++ src/mesa/main/mtypes.h<br>
&gt; |    1 + 6 files changed, 354 insertions(+), 0 deletions(-) create<br>
&gt; mode 100644 src/glsl/lower_clip_distance.cpp<br>
&gt;<br>
&gt; diff --git a/src/glsl/Makefile b/src/glsl/Makefile index<br>
&gt; c20a6c9..bee21c2 100644 --- a/src/glsl/Makefile +++<br>
&gt; b/src/glsl/Makefile @@ -56,6 +56,7 @@ CXX_SOURCES = \<br>
&gt; loop_analysis.cpp \ loop_controls.cpp \ loop_unroll.cpp \ +<br>
&gt; lower_clip_distance.cpp \ lower_discard.cpp \<br>
&gt; lower_if_to_cond_assign.cpp \ lower_instructions.cpp \ diff --git<br>
&gt; a/src/glsl/SConscript b/src/glsl/SConscript index 1da58a9..b4786c5<br>
&gt; 100644 --- a/src/glsl/SConscript +++ b/src/glsl/SConscript @@ -67,6<br>
&gt; +67,7 @@ glsl_sources = [ &#39;loop_analysis.cpp&#39;,<br>
&gt; &#39;loop_controls.cpp&#39;, &#39;loop_unroll.cpp&#39;, +<br>
&gt; &#39;lower_clip_distance.cpp&#39;, &#39;lower_discard.cpp&#39;,<br>
&gt; &#39;lower_if_to_cond_assign.cpp&#39;, &#39;lower_instructions.cpp&#39;, diff --git<br>
&gt; a/src/glsl/ir_optimization.h b/src/glsl/ir_optimization.h index<br>
&gt; 48448d4..af80e26 100644 --- a/src/glsl/ir_optimization.h +++<br>
&gt; b/src/glsl/ir_optimization.h @@ -69,6 +69,7 @@ bool<br>
&gt; lower_noise(exec_list *instructions); bool<br>
&gt; lower_variable_index_to_cond_assign(exec_list *instructions, bool<br>
&gt; lower_input, bool lower_output, bool lower_temp, bool<br>
&gt; lower_uniform); bool lower_quadop_vector(exec_list *instructions,<br>
&gt; bool dont_lower_swz); +bool lower_clip_distance(exec_list<br>
&gt; *instructions); bool optimize_redundant_jumps(exec_list<br>
&gt; *instructions);<br>
&gt;<br>
&gt; ir_rvalue * diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp<br>
&gt; index 195f58f..ceb49fd 100644 --- a/src/glsl/linker.cpp +++<br>
&gt; b/src/glsl/linker.cpp @@ -1743,6 +1743,9 @@ link_shaders(struct<br>
&gt; gl_context *ctx, struct gl_shader_program *prog) if<br>
&gt; (!prog-&gt;LinkStatus) goto done;<br>
&gt;<br>
&gt; +      if (ctx-&gt;ShaderCompilerOptions[i].LowerClipDistance) +<br>
&gt; lower_clip_distance(prog-&gt;_LinkedShaders[i]-&gt;ir); + while<br>
&gt; (do_common_optimization(prog-&gt;_LinkedShaders[i]-&gt;ir, true, 32)) ;<br>
&gt; } diff --git a/src/glsl/lower_clip_distance.cpp<br>
&gt; b/src/glsl/lower_clip_distance.cpp new file mode 100644 index<br>
&gt; 0000000..55a9e9d --- /dev/null +++<br>
&gt; b/src/glsl/lower_clip_distance.cpp @@ -0,0 +1,347 @@ +/* + *<br>
&gt; Copyright © 2011 Intel Corporation + * + * Permission is hereby<br>
&gt; granted, free of charge, to any person obtaining a + * copy of this<br>
&gt; software and associated documentation files (the &quot;Software&quot;), + *<br>
&gt; to deal in the Software without restriction, including without<br>
&gt; limitation + * the rights to use, copy, modify, merge, publish,<br>
&gt; distribute, sublicense, + * and/or sell copies of the Software, and<br>
&gt; to permit persons to whom the + * Software is furnished to do so,<br>
&gt; subject to the following conditions: + * + * The above copyright<br>
&gt; notice and this permission notice (including the next + *<br>
&gt; paragraph) shall be included in all copies or substantial portions<br>
&gt; of the + * Software. + * + * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;,<br>
&gt; WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT<br>
&gt; NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A<br>
&gt; PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL + * THE<br>
&gt; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR<br>
&gt; OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR<br>
&gt; OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE<br>
&gt; SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +<br>
&gt; +/** + * \file lower_clip_distance.cpp + * + * This pass accounts<br>
&gt; for the difference between the way + * gl_ClipDistance is declared<br>
&gt; in standard GLSL (as an array of + * floats), and the way it is<br>
&gt; frequently implemented in hardware (as + * a pair of vec4s, with<br>
&gt; four clip distances packed into each). + * + * The declaration of<br>
&gt; gl_ClipDistance is replaced with a declaration + * of<br>
&gt; gl_ClipDistanceMESA, and any references to gl_ClipDistance are + *<br>
&gt; translated to refer to gl_ClipDistanceMESA with the appropriate + *<br>
&gt; swizzling of array indices.  For instance: + * + *<br>
&gt; gl_ClipDistance[i] + * + * is translated into: + * + *<br>
&gt; gl_ClipDistanceMESA[i&gt;&gt;2][i&amp;3] + * + * Since some hardware may not<br>
&gt; internally represent gl_ClipDistance as a pair + * of vec4&#39;s, this<br>
&gt; lowering pass is optional.  To enable it, set the + *<br>
&gt; LowerClipDistance flag in gl_shader_compiler_options to true. + */<br>
&gt; + +#include &quot;ir_hierarchical_visitor.h&quot; +#include &quot;ir.h&quot; + +class<br>
&gt; lower_clip_distance_visitor : public ir_hierarchical_visitor {<br>
&gt; +public: +   lower_clip_distance_visitor() +      :<br>
&gt; progress(false), old_clip_distance_var(NULL), +<br>
&gt; new_clip_distance_var(NULL) +   { +   } + +   virtual<br>
&gt; ir_visitor_status visit(ir_variable *); +   void<br>
&gt; create_indices(ir_rvalue*, ir_rvalue *&amp;, ir_rvalue *&amp;); +   virtual<br>
&gt; ir_visitor_status visit_leave(ir_dereference_array *); +   virtual<br>
&gt; ir_visitor_status visit_leave(ir_assignment *); +   void<br>
&gt; visit_new_assignment(ir_assignment *ir); +   virtual<br>
&gt; ir_visitor_status visit_leave(ir_call *); + +   bool progress; + +<br>
&gt; /** +    * Pointer to the declaration of gl_ClipDistance, if<br>
&gt; found. +    */ +   ir_variable *old_clip_distance_var; + +   /** +<br>
&gt; * Pointer to the newly-created gl_ClipDistanceMESA variable. +<br>
&gt; */ +   ir_variable *new_clip_distance_var; +}; + + +/** + * Replace<br>
&gt; any declaration of gl_ClipDistance as an array of floats with a + *<br>
&gt; declaration of gl_ClipDistanceMESA as an array of vec4&#39;s. + */<br>
&gt; +ir_visitor_status +lower_clip_distance_visitor::visit(ir_variable<br>
&gt; *ir) +{ +   /* No point in looking for the declaration of<br>
&gt; gl_ClipDistance if +    * we&#39;ve already found it. +    */ +   if<br>
&gt; (this-&gt;old_clip_distance_var) +      return visit_continue; + +<br>
&gt; if (ir-&gt;name &amp;&amp; strcmp(ir-&gt;name, &quot;gl_ClipDistance&quot;) == 0) { +<br>
&gt; this-&gt;progress = true; +      this-&gt;old_clip_distance_var = ir; +<br>
&gt; assert (ir-&gt;type-&gt;is_array()); +      assert<br>
&gt; (ir-&gt;type-&gt;element_type() == glsl_type::float_type); +<br>
&gt; unsigned new_size = (ir-&gt;type-&gt;array_size() + 3) / 4; + +      /*<br>
&gt; Clone the old var so that we inherit all of its properties */ +<br>
&gt; this-&gt;new_clip_distance_var = ir-&gt;clone(ralloc_parent(ir), NULL);<br>
&gt; + +      /* And change the properties that we need to change */ +<br>
&gt; this-&gt;new_clip_distance_var-&gt;name +         =<br>
&gt; ralloc_strdup(this-&gt;new_clip_distance_var, &quot;gl_ClipDistanceMESA&quot;);<br>
&gt; +      this-&gt;new_clip_distance_var-&gt;type +         =<br>
&gt; glsl_type::get_array_instance(glsl_type::vec4_type, new_size); +<br>
&gt; this-&gt;new_clip_distance_var-&gt;max_array_access =<br>
&gt; ir-&gt;max_array_access / 4; + +<br>
&gt; ir-&gt;replace_with(this-&gt;new_clip_distance_var); +   } +   return<br>
&gt; visit_continue; +} + + +/** + * Create the necessary GLSL rvalues<br>
&gt; to index into gl_ClipDistanceMESA based + * on the rvalue<br>
&gt; previously used to index into gl_ClipDistance.  The first, + *<br>
&gt; &quot;outer&quot; index, selects one of the vec4&#39;s in gl_ClipDistanceMESA,<br>
&gt; and the + * second, &quot;inner&quot; index, selects a component within that<br>
&gt; vec4. + */<br>
<br>
</div></div>I&#39;d call these array_index and swizzle_index instead of outer_index<br>
and inner_index.  Also, documenting function parameters should be done<br>
in the Doxygen magic format:<br>
<br>
/**<br>
 *<br>
 * \param array_index   Selects one of the vec4&#39;s in gl_ClipDistanceMESA<br>
 * \param swizzle_index Selects a component within the vec4 selected by<br>
 *                      array_index.<br>
<div class="im"> */<br></div></blockquote><div><br>Ok, sounds reasonable.<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">

<br>
&gt; +void +lower_clip_distance_visitor::create_indices(ir_rvalue<br>
&gt; *old_index, +                                            ir_rvalue<br>
&gt; *&amp;outer_index, +<br>
&gt; ir_rvalue *&amp;inner_index) +{ +   void *ctx =<br>
&gt; ralloc_parent(old_index); + +   /* Make sure old_index is a signed<br>
&gt; int so that the bitwise &quot;shift&quot; and +    * &quot;and&quot; operations below<br>
&gt; type check properly. +    */ +   if (old_index-&gt;type !=<br>
&gt; glsl_type::int_type) { +      assert (old_index-&gt;type ==<br>
&gt; glsl_type::uint_type); +      old_index = new(ctx)<br>
&gt; ir_expression(ir_unop_u2i, old_index); +   }<br>
<br>
</div>Does this matter?  The only case where it would be different is if the<br>
index is negative.  In that case, the array look-up already has<br>
undefined results.<br></blockquote><div><br>The reason for this is that according to GLSL IR type validation rules, the two operands to a binary AND need to be the same type, so in addition to using old_index-&gt;type for old_index_var (as you mention below), I would have to dynamically choose between ir_constant(3) and ir_constant(3u) based on the type of the index.  Also, the call to get_int_component() would feel more fragile, since technically one *ought* to use get_uint_component() to get the value of a uint (even though get_int_component() works in practice due to int and uint constants being stored in the same union).  Finally, there are bugs in lower_vec_index_to_swizzle.cpp and lower_variable_index_to_cond_assign.cpp that prevent them from working on uint array indices right now.  Those should be pretty easy to fix but I would rather get gl_ClipDistance to work first.<br>
<br>Considering that on most back-ends, converting an int to a uint should not cost any GPU instructions (since it&#39;s just a reinterpretation of bits), just doing the conversion seemed easier than dealing with all the stuff above.<br>
 </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
&gt; + +   ir_constant *old_index_constant =<br>
<div class="im">&gt; old_index-&gt;constant_expression_value(); +   if (old_index_constant)<br>
&gt; { +      /* gl_ClipDistance is being accessed via a constant index.<br>
&gt; Don&#39;t bother +       * creating expressions to calculate the<br>
&gt; lowered indices.  Just create +       * constants. +       */ +<br>
&gt; int const_val = old_index_constant-&gt;get_int_component(0); +<br>
&gt; outer_index = new(ctx) ir_constant(const_val / 4); +<br>
&gt; inner_index = new(ctx) ir_constant(const_val % 4); +   } else { +<br>
&gt; /* Create a variable to hold the value of old_index (so that we +<br>
&gt; * don&#39;t compute it twice). +       */ +      ir_variable<br>
&gt; *old_index_var = new(ctx) ir_variable( +<br>
&gt; glsl_type::int_type, &quot;clip_distance_index&quot;, ir_var_temporary);<br>
<br>
</div>Based on my comment above, I think this should use old_index-&gt;type<br>
instead of hard-coding glsl_type::int_type.<br>
<div><div></div><div class="h5"><br>
&gt; +      this-&gt;base_ir-&gt;insert_before(old_index_var); +<br>
&gt; this-&gt;base_ir-&gt;insert_before(new(ctx) ir_assignment( +<br>
&gt; new(ctx) ir_dereference_variable(old_index_var), old_index)); + +<br>
&gt; /* Create the expression clip_distance_index / 4.  Do this as a<br>
&gt; bit +       * shift because that&#39;s likely to be more efficient. +<br>
&gt; */ +      outer_index = new(ctx) ir_expression( +<br>
&gt; ir_binop_rshift, new(ctx) ir_dereference_variable(old_index_var), +<br>
&gt; new(ctx) ir_constant(2)); + +      /* Create the expression<br>
&gt; clip_distance_index % 4.  Do this as a bitwise +       * AND<br>
&gt; because that&#39;s likely to be more efficient. +       */ +<br>
&gt; inner_index = new(ctx) ir_expression( +         ir_binop_bit_and,<br>
&gt; new(ctx) ir_dereference_variable(old_index_var), +         new(ctx)<br>
&gt; ir_constant(3)); +   } +} + + +/** + * Replace any expression that<br>
&gt; indexes into the gl_ClipDistance array with an + * expression that<br>
&gt; indexes into one of the vec4&#39;s in gl_ClipDistanceMESA and + *<br>
&gt; accesses the appropriate component. + */ +ir_visitor_status<br>
&gt; +lower_clip_distance_visitor::visit_leave(ir_dereference_array<br>
&gt; *ir) +{ +   /* If the gl_ClipDistance var hasn&#39;t been declared yet,<br>
&gt; then +    * there&#39;s no way this deref can refer to it. +    */ +<br>
&gt; if (!this-&gt;old_clip_distance_var) +      return visit_continue; + +<br>
&gt; ir_dereference_variable *old_var_ref =<br>
&gt; ir-&gt;array-&gt;as_dereference_variable(); +   if (old_var_ref &amp;&amp;<br>
&gt; old_var_ref-&gt;variable_referenced() +       ==<br>
&gt; this-&gt;old_clip_distance_var) { +      this-&gt;progress = true; +<br>
&gt; ir_rvalue *outer_index; +      ir_rvalue *inner_index; +<br>
&gt; this-&gt;create_indices(ir-&gt;array_index, outer_index, inner_index); +<br>
&gt; void *mem_ctx = ralloc_parent(ir); +      ir-&gt;array = new(mem_ctx)<br>
&gt; ir_dereference_array( +         this-&gt;new_clip_distance_var,<br>
&gt; outer_index); +      ir-&gt;array_index = inner_index; +   } + +<br>
&gt; return visit_continue; +} + + +/** + * Replace any assignment<br>
&gt; having gl_ClipDistance (undereferenced) as its LHS + * or RHS with<br>
&gt; a sequence of assignments, one for each component of the array. + *<br>
&gt; Each of these assignments is lowered to refer to<br>
&gt; gl_ClipDistanceMESA as + * appropriate. + */<br>
<br>
</div></div>Don&#39;t we already have a lowering pass that does this?  If not, it<br>
seems like this could / should be it&#39;s own pass (that operates on<br>
general arrays).  Perhaps Eric will have an opinion...<br></blockquote><div><br>I&#39;m not aware of such a pass at the GLSL level (I think we may have something like this in i965, but that wouldn&#39;t be useful here).  Eric, are you aware of anything?<br>
 <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div><div class="h5"><br>
&gt; +ir_visitor_status<br>
&gt; +lower_clip_distance_visitor::visit_leave(ir_assignment *ir) +{ +<br>
&gt; ir_dereference_variable *lhs_var =<br>
&gt; ir-&gt;lhs-&gt;as_dereference_variable(); +   ir_dereference_variable<br>
&gt; *rhs_var = ir-&gt;rhs-&gt;as_dereference_variable(); +   if ((lhs_var &amp;&amp;<br>
&gt; lhs_var-&gt;variable_referenced() +        ==<br>
&gt; this-&gt;old_clip_distance_var) +       || (rhs_var &amp;&amp;<br>
&gt; rhs_var-&gt;variable_referenced() +           ==<br>
&gt; this-&gt;old_clip_distance_var)) { +      /* LHS or RHS of the<br>
&gt; assignment is the entire gl_ClipDistance array. +       * Since we<br>
&gt; are reshaping gl_ClipDistance from an array of floats to an +<br>
&gt; * array of vec4&#39;s, this isn&#39;t going to work as a bulk assignment +<br>
&gt; * anymore, so unroll it to element-by-element assignments and<br>
&gt; lower +       * each of them. +       * +       * Note: to unroll<br>
&gt; into element-by-element assignments, we need to make +       *<br>
&gt; clones of the LHS and RHS.  This is only safe if the LHS and RHS<br>
&gt; are +       * side-effect free.  Fortunately, we know that they<br>
&gt; are, because the +       * only kind of rvalue that can have side<br>
&gt; effects is an ir_call, and +       * ir_calls only appear (a) as a<br>
&gt; statement on their own, or (b) as the +       * RHS of an<br>
&gt; assignment that stores the result of the call in a +       *<br>
&gt; temporary variable. +       */ +      void *ctx =<br>
&gt; ralloc_parent(ir); +      int array_size =<br>
&gt; this-&gt;old_clip_distance_var-&gt;type-&gt;array_size(); +      for (int i<br>
&gt; = 0; i &lt; array_size; ++i) { +         ir_dereference_array *new_lhs<br>
&gt; = new(ctx) ir_dereference_array( +            ir-&gt;lhs-&gt;clone(ctx,<br>
&gt; NULL), new(ctx) ir_constant(i)); +<br>
&gt; this-&gt;visit_leave(new_lhs); +         ir_dereference_array *new_rhs<br>
&gt; = new(ctx) ir_dereference_array( +            ir-&gt;rhs-&gt;clone(ctx,<br>
&gt; NULL), new(ctx) ir_constant(i)); +<br>
&gt; this-&gt;visit_leave(new_rhs); +<br>
&gt; this-&gt;base_ir-&gt;insert_before( +            new(ctx)<br>
&gt; ir_assignment(new_lhs, new_rhs)); +      } +      ir-&gt;remove(); +<br>
&gt; } + +   return visit_continue; +} + + +/** + * Set up base_ir<br>
&gt; properly and call visit_leave() on a newly created + *<br>
&gt; ir_assignment node.  This is used in cases where we have to insert<br>
&gt; an + * ir_assignment in a place where we know the hierarchical<br>
&gt; visitor won&#39;t see + * it. + */ +void<br>
&gt; +lower_clip_distance_visitor::visit_new_assignment(ir_assignment<br>
&gt; *ir) +{ +   ir_instruction *old_base_ir = this-&gt;base_ir; +<br>
&gt; this-&gt;base_ir = ir; +   this-&gt;visit_leave(ir); +   this-&gt;base_ir =<br>
&gt; old_base_ir; +} + + +/** + * If gl_ClipDistance appears as an<br>
&gt; argument in an ir_call expression, replace + * it with a temporary<br>
&gt; variable, and make sure the ir_call is preceded and/or + * followed<br>
&gt; by assignments that copy the contents of the temporary variable to<br>
&gt; + * and/or from gl_ClipDistance.  Each of these assignments is then<br>
&gt; lowered to + * refer to gl_ClipDistanceMESA. + */<br>
&gt; +ir_visitor_status<br>
&gt; +lower_clip_distance_visitor::visit_leave(ir_call *ir) +{ +   void<br>
&gt; *ctx = ralloc_parent(ir); + +   const exec_node *formal_param_node<br>
&gt; = ir-&gt;get_callee()-&gt;parameters.head; +   const exec_node<br>
&gt; *actual_param_node = ir-&gt;actual_parameters.head; +   while<br>
&gt; (!actual_param_node-&gt;is_tail_sentinel()) { +      ir_variable<br>
&gt; *formal_param = (ir_variable *) formal_param_node; +      ir_rvalue<br>
&gt; *actual_param = (ir_rvalue *) actual_param_node; + +      /*<br>
&gt; Advance formal_param_node and actual_param_node now so that we can<br>
&gt; +       * safely replace actual_param with another node, if<br>
&gt; necessary, below. +       */ +      formal_param_node =<br>
&gt; formal_param_node-&gt;next; +      actual_param_node =<br>
&gt; actual_param_node-&gt;next; + +      ir_dereference_variable *deref =<br>
&gt; actual_param-&gt;as_dereference_variable(); +      if (deref &amp;&amp;<br>
&gt; deref-&gt;variable_referenced() +          ==<br>
&gt; this-&gt;old_clip_distance_var) { +         /* User is trying to pass<br>
&gt; gl_ClipDistance as an in, out, or inout +          * parameter to a<br>
&gt; function call.  Since we are reshaping +          * gl_ClipDistance<br>
&gt; from an array of floats to an array of vec4&#39;s, +          * this<br>
&gt; isn&#39;t going to work anymore, so use a temporary array +          *<br>
&gt; instead. +          */ +         ir_variable *temp_clip_distance =<br>
&gt; new(ctx) ir_variable( +            actual_param-&gt;type,<br>
&gt; &quot;temp_clip_distance&quot;, ir_var_temporary); +<br>
&gt; this-&gt;base_ir-&gt;insert_before(temp_clip_distance); +<br>
&gt; actual_param-&gt;replace_with( +            new(ctx)<br>
&gt; ir_dereference_variable(temp_clip_distance)); +         if<br>
&gt; (formal_param-&gt;mode == ir_var_in +             ||<br>
&gt; formal_param-&gt;mode == ir_var_inout) { +            /* Copy from<br>
&gt; gl_ClipDistance to the temporary before the call. +             *<br>
&gt; Since we are going to insert this copy before the current +<br>
&gt; * instruction, we need to visit it afterwards to make sure it +<br>
&gt; * gets lowered. +             */ +            ir_assignment<br>
&gt; *new_assignment = new(ctx) ir_assignment( +               new(ctx)<br>
&gt; ir_dereference_variable(temp_clip_distance), +<br>
&gt; actual_param-&gt;clone(ctx, NULL)); +<br>
&gt; this-&gt;base_ir-&gt;insert_before(new_assignment); +<br>
&gt; this-&gt;visit_new_assignment(new_assignment); +         } +<br>
&gt; if (formal_param-&gt;mode == ir_var_out +             ||<br>
&gt; formal_param-&gt;mode == ir_var_inout) { +            /* Copy from the<br>
&gt; temporary to gl_ClipDistance after the call. +             * Since<br>
&gt; visit_list_elements() has already decided which +             *<br>
&gt; instruction it&#39;s going to visit next, we need to visit +<br>
&gt; * afterwards to make sure it gets lowered. +             */ +<br>
&gt; ir_assignment *new_assignment = new(ctx) ir_assignment( +<br>
&gt; actual_param-&gt;clone(ctx, NULL), +               new(ctx)<br>
&gt; ir_dereference_variable(temp_clip_distance)); +<br>
&gt; this-&gt;base_ir-&gt;insert_after(new_assignment); +<br>
&gt; this-&gt;visit_new_assignment(new_assignment); +         } +      } +<br>
&gt; } + +   return visit_continue; +} + + +bool<br>
&gt; +lower_clip_distance(exec_list *instructions) +{ +<br>
&gt; lower_clip_distance_visitor v; + +   visit_list_elements(&amp;v,<br>
&gt; instructions); + +   return v.progress; +} diff --git<br>
&gt; a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index<br>
&gt; 8671ecd..ef04749 100644 --- a/src/mesa/main/mtypes.h +++<br>
&gt; b/src/mesa/main/mtypes.h @@ -2297,6 +2297,7 @@ struct<br>
&gt; gl_shader_compiler_options GLboolean EmitNoMainReturn;<br>
&gt; /**&lt; Emit CONT/RET opcodes? */ GLboolean EmitNoNoise;<br>
&gt; /**&lt; Emit NOISE opcodes? */ GLboolean EmitNoPow;<br>
&gt; /**&lt; Emit POW opcodes? */ +   GLboolean LowerClipDistance; /**&lt;<br>
&gt; Lower gl_ClipDistance from float[8] to vec4[2]? */<br>
&gt;<br>
&gt; /** * \name Forms of indirect addressing the driver cannot do.<br>
<br>
</div></div>-----BEGIN PGP SIGNATURE-----<br>
Version: GnuPG v1.4.11 (GNU/Linux)<br>
Comment: Using GnuPG with Mozilla - <a href="http://enigmail.mozdev.org/" target="_blank">http://enigmail.mozdev.org/</a><br>
<br>
iEYEARECAAYFAk53hZUACgkQX1gOwKyEAw/wVQCfbjFA83RlnUOSXd57EbPCGDQl<br>
WvYAnRyiiNA6JL1K6q3wKdLgkg/vyjFh<br>
=9UAG<br>
-----END PGP SIGNATURE-----<br>
</blockquote></div><br>