Re: [Nouveau] [PATCH] glsl: Extend lowering pass for gl_ClipDistance to support other arrays

2015-08-17 Thread Ilia Mirkin
I said this on IRC, but I'll say it here too:

(a) please regenerate this with -M (not in the general case, but it
makes sense here)
(b) this seems odd as there's no support for cull distance elsewhere
yet. should be part of a series that adds cull distance support. right
now there is none, so this is out of place.

On Mon, Aug 17, 2015 at 10:50 PM, Tobias Klausmann
tobias.johannes.klausm...@mni.thm.de wrote:
 This will come in handy when we want to lower gl_CullDistance into
 gl_CullDistanceMESA.

 Signed-off-by: Tobias Klausmann tobias.johannes.klausm...@mni.thm.de
 ---
  src/glsl/Makefile.sources|   2 +-
  src/glsl/ir_optimization.h   |   1 +
  src/glsl/lower_clip_distance.cpp | 574 
  src/glsl/lower_distance.cpp  | 606 
 +++
  4 files changed, 608 insertions(+), 575 deletions(-)
  delete mode 100644 src/glsl/lower_clip_distance.cpp
  create mode 100644 src/glsl/lower_distance.cpp

 diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources
 index 0b77244..00ba480 100644
 --- a/src/glsl/Makefile.sources
 +++ b/src/glsl/Makefile.sources
 @@ -143,7 +143,7 @@ LIBGLSL_FILES = \
 loop_analysis.h \
 loop_controls.cpp \
 loop_unroll.cpp \
 -   lower_clip_distance.cpp \
 +   lower_distance.cpp \
 lower_const_arrays_to_uniforms.cpp \
 lower_discard.cpp \
 lower_discard_flow.cpp \
 diff --git a/src/glsl/ir_optimization.h b/src/glsl/ir_optimization.h
 index eef107e..fe62e74 100644
 --- a/src/glsl/ir_optimization.h
 +++ b/src/glsl/ir_optimization.h
 @@ -120,6 +120,7 @@ bool lower_variable_index_to_cond_assign(gl_shader_stage 
 stage,
  bool lower_quadop_vector(exec_list *instructions, bool dont_lower_swz);
  bool lower_const_arrays_to_uniforms(exec_list *instructions);
  bool lower_clip_distance(gl_shader *shader);
 +bool lower_cull_distance(gl_shader *shader);
  void lower_output_reads(unsigned stage, exec_list *instructions);
  bool lower_packing_builtins(exec_list *instructions, int op_mask);
  void lower_ubo_reference(struct gl_shader *shader, exec_list *instructions);
 diff --git a/src/glsl/lower_clip_distance.cpp 
 b/src/glsl/lower_clip_distance.cpp
 deleted file mode 100644
 index 1ada215..000
 --- a/src/glsl/lower_clip_distance.cpp
 +++ /dev/null
 @@ -1,574 +0,0 @@
 -/*
 - * Copyright © 2011 Intel Corporation
 - *
 - * Permission is hereby granted, free of charge, to any person obtaining a
 - * copy of this software and associated documentation files (the Software),
 - * to deal in the Software without restriction, including without limitation
 - * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 - * and/or sell copies of the Software, and to permit persons to whom the
 - * Software is furnished to do so, subject to the following conditions:
 - *
 - * The above copyright notice and this permission notice (including the next
 - * paragraph) shall be included in all copies or substantial portions of the
 - * Software.
 - *
 - * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 - * DEALINGS IN THE SOFTWARE.
 - */
 -
 -/**
 - * \file lower_clip_distance.cpp
 - *
 - * This pass accounts for the difference between the way
 - * gl_ClipDistance is declared in standard GLSL (as an array of
 - * floats), and the way it is frequently implemented in hardware (as
 - * a pair of vec4s, with four clip distances packed into each).
 - *
 - * The declaration of gl_ClipDistance is replaced with a declaration
 - * of gl_ClipDistanceMESA, and any references to gl_ClipDistance are
 - * translated to refer to gl_ClipDistanceMESA with the appropriate
 - * swizzling of array indices.  For instance:
 - *
 - *   gl_ClipDistance[i]
 - *
 - * is translated into:
 - *
 - *   gl_ClipDistanceMESA[i2][i3]
 - *
 - * Since some hardware may not internally represent gl_ClipDistance as a pair
 - * of vec4's, this lowering pass is optional.  To enable it, set the
 - * LowerClipDistance flag in gl_shader_compiler_options to true.
 - */
 -
 -#include glsl_symbol_table.h
 -#include ir_rvalue_visitor.h
 -#include ir.h
 -#include program/prog_instruction.h /* For WRITEMASK_* */
 -
 -namespace {
 -
 -class lower_clip_distance_visitor : public ir_rvalue_visitor {
 -public:
 -   explicit lower_clip_distance_visitor(gl_shader_stage shader_stage)
 -  : progress(false), old_clip_distance_out_var(NULL),
 -old_clip_distance_in_var(NULL), new_clip_distance_out_var(NULL),
 -new_clip_distance_in_var(NULL), shader_stage(shader_stage)
 -   {
 -   }
 -
 -   

[Nouveau] [PATCH] glsl: Extend lowering pass for gl_ClipDistance to support other arrays

2015-08-17 Thread Tobias Klausmann
This will come in handy when we want to lower gl_CullDistance into
gl_CullDistanceMESA.

Signed-off-by: Tobias Klausmann tobias.johannes.klausm...@mni.thm.de
---
 src/glsl/Makefile.sources|   2 +-
 src/glsl/ir_optimization.h   |   1 +
 src/glsl/lower_clip_distance.cpp | 574 
 src/glsl/lower_distance.cpp  | 606 +++
 4 files changed, 608 insertions(+), 575 deletions(-)
 delete mode 100644 src/glsl/lower_clip_distance.cpp
 create mode 100644 src/glsl/lower_distance.cpp

diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources
index 0b77244..00ba480 100644
--- a/src/glsl/Makefile.sources
+++ b/src/glsl/Makefile.sources
@@ -143,7 +143,7 @@ LIBGLSL_FILES = \
loop_analysis.h \
loop_controls.cpp \
loop_unroll.cpp \
-   lower_clip_distance.cpp \
+   lower_distance.cpp \
lower_const_arrays_to_uniforms.cpp \
lower_discard.cpp \
lower_discard_flow.cpp \
diff --git a/src/glsl/ir_optimization.h b/src/glsl/ir_optimization.h
index eef107e..fe62e74 100644
--- a/src/glsl/ir_optimization.h
+++ b/src/glsl/ir_optimization.h
@@ -120,6 +120,7 @@ bool lower_variable_index_to_cond_assign(gl_shader_stage 
stage,
 bool lower_quadop_vector(exec_list *instructions, bool dont_lower_swz);
 bool lower_const_arrays_to_uniforms(exec_list *instructions);
 bool lower_clip_distance(gl_shader *shader);
+bool lower_cull_distance(gl_shader *shader);
 void lower_output_reads(unsigned stage, exec_list *instructions);
 bool lower_packing_builtins(exec_list *instructions, int op_mask);
 void lower_ubo_reference(struct gl_shader *shader, exec_list *instructions);
diff --git a/src/glsl/lower_clip_distance.cpp b/src/glsl/lower_clip_distance.cpp
deleted file mode 100644
index 1ada215..000
--- a/src/glsl/lower_clip_distance.cpp
+++ /dev/null
@@ -1,574 +0,0 @@
-/*
- * Copyright © 2011 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the Software),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file lower_clip_distance.cpp
- *
- * This pass accounts for the difference between the way
- * gl_ClipDistance is declared in standard GLSL (as an array of
- * floats), and the way it is frequently implemented in hardware (as
- * a pair of vec4s, with four clip distances packed into each).
- *
- * The declaration of gl_ClipDistance is replaced with a declaration
- * of gl_ClipDistanceMESA, and any references to gl_ClipDistance are
- * translated to refer to gl_ClipDistanceMESA with the appropriate
- * swizzling of array indices.  For instance:
- *
- *   gl_ClipDistance[i]
- *
- * is translated into:
- *
- *   gl_ClipDistanceMESA[i2][i3]
- *
- * Since some hardware may not internally represent gl_ClipDistance as a pair
- * of vec4's, this lowering pass is optional.  To enable it, set the
- * LowerClipDistance flag in gl_shader_compiler_options to true.
- */
-
-#include glsl_symbol_table.h
-#include ir_rvalue_visitor.h
-#include ir.h
-#include program/prog_instruction.h /* For WRITEMASK_* */
-
-namespace {
-
-class lower_clip_distance_visitor : public ir_rvalue_visitor {
-public:
-   explicit lower_clip_distance_visitor(gl_shader_stage shader_stage)
-  : progress(false), old_clip_distance_out_var(NULL),
-old_clip_distance_in_var(NULL), new_clip_distance_out_var(NULL),
-new_clip_distance_in_var(NULL), shader_stage(shader_stage)
-   {
-   }
-
-   virtual ir_visitor_status visit(ir_variable *);
-   void create_indices(ir_rvalue*, ir_rvalue *, ir_rvalue *);
-   bool is_clip_distance_vec8(ir_rvalue *ir);
-   ir_rvalue *lower_clip_distance_vec8(ir_rvalue *ir);
-   virtual ir_visitor_status visit_leave(ir_assignment *);
-   void visit_new_assignment(ir_assignment *ir);
-   virtual ir_visitor_status visit_leave(ir_call *);
-
-   virtual void handle_rvalue(ir_rvalue **rvalue);
-
-   void fix_lhs(ir_assignment *);
-
-   bool progress;
-
-   /**
-* Pointer to the