Re: [Mesa-dev] [PATCH v4 2/6] mesa/st: glsl_to_tgsi: implement new temporary register lifetime tracker

2017-06-22 Thread Gert Wollny
Thanks for the comments, 

I've fixed these little issues locally, but I think in order to not to
spam the list, I'll send the changes later. I kind of suspect that
Nicolai might have one or the other additional comment :)

best, 
Gert 

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH v4 2/6] mesa/st: glsl_to_tgsi: implement new temporary register lifetime tracker

2017-06-22 Thread Emil Velikov
Hi Gert,

A couple of trivial bits I've noticed in patches 2 and 3, but
applicable overall.

 - Unify if/return chains
I've seen the following three examples, sometimes even right next to each other.

if foo
   return f1;
if bar
   return b1;
return c1;

if foo
   return f1;
if bar
   return b1;
else
   return c1;

if foo
   return f1;
else if bar
   return b1;
return c1;

Personal fav. is the first one (with blank lines in between), although
regardless of the option do make sure code is consistent.

 - Braces for a single line statement in a if conditionals
Some instances have, while others don't. I think most people prefer
omitting them, although as long as you're consistent with surrounding
code it's fine.

- Tests still use STL?
Am I looking at the right patches - shouldn't be a big deal either way.

Regards,
Emil
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v4 2/6] mesa/st: glsl_to_tgsi: implement new temporary register lifetime tracker

2017-06-21 Thread Gert Wollny
This patch adds a class for tracking the life times of temporary registers
in the glsl to tgsi translation. The algorithm runs in three steps:
First, in order to minimize the number of needed memory allocations the
program is scanned to evaluate the number of scopes.
Then, the program is scanned  second time to recorc the important register
access time points: first and last reads and writes and their link to the
execution scope (loop, if/else branch, switch case).
In the third step for each register the actuall minimal life time is
evaluated.
---
 src/mesa/Makefile.sources  |   2 +
 .../state_tracker/st_glsl_to_tgsi_temprename.cpp   | 648 +
 .../state_tracker/st_glsl_to_tgsi_temprename.h |  33 ++
 3 files changed, 683 insertions(+)
 create mode 100644 src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp
 create mode 100644 src/mesa/state_tracker/st_glsl_to_tgsi_temprename.h

diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
index 21f9167bda..2359ec3c7d 100644
--- a/src/mesa/Makefile.sources
+++ b/src/mesa/Makefile.sources
@@ -509,6 +509,8 @@ STATETRACKER_FILES = \
state_tracker/st_glsl_to_tgsi.h \
state_tracker/st_glsl_to_tgsi_private.cpp \
state_tracker/st_glsl_to_tgsi_private.h \
+   state_tracker/st_glsl_to_tgsi_temprename.cpp \
+   state_tracker/st_glsl_to_tgsi_temprename.h \
state_tracker/st_glsl_types.cpp \
state_tracker/st_glsl_types.h \
state_tracker/st_manager.c \
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp
new file mode 100644
index 00..1e02c4d710
--- /dev/null
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp
@@ -0,0 +1,648 @@
+/*
+ * Copyright © 2017 Gert Wollny
+ *
+ * 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.
+ */
+
+
+#include "st_glsl_to_tgsi_temprename.h"
+#include 
+#include 
+#include 
+
+/* Without c++11 define the nullptr for forward-compatibility
+ * and better readibility */
+#if __cplusplus < 201103L
+#define nullptr 0
+#endif
+
+using std::numeric_limits;
+
+enum e_scope_type {
+   sct_outer,
+   sct_loop,
+   sct_if,
+   sct_else,
+   sct_switch,
+   sct_switch_case,
+   sct_switch_default,
+   sct_unknown
+};
+
+enum e_acc_type {
+   acc_read,
+   acc_write,
+   acc_write_cond_from_self
+};
+
+class prog_scope {
+
+public:
+   prog_scope(prog_scope *parent, e_scope_type type, int id, int depth,
+  int begin);
+
+   e_scope_type type() const;
+   prog_scope *parent() const;
+   int nesting_depth() const;
+   int id() const;
+   int end() const;
+   int begin() const;
+   int loop_continue_line() const;
+
+   const prog_scope *in_ifelse_scope() const;
+   const prog_scope *in_switchcase_scope() const;
+   const prog_scope *innermost_loop() const;
+   const prog_scope *outermost_loop() const;
+
+   bool in_loop() const;
+   bool is_conditional() const;
+   bool break_is_for_switchcase() const;
+   bool contains(const prog_scope& other) const;
+
+   void set_end(int end);
+   void set_previous_case_scope(prog_scope *prev);
+   void set_continue_line(int line);
+
+private:
+   e_scope_type scope_type;
+   int scope_id;
+   int scope_nesting_depth;
+   int scope_begin;
+   int scope_end;
+   int loop_cont_line;
+   prog_scope *previous_case_scope;
+   prog_scope *parent_scope;
+};
+
+class temp_access {
+public:
+   temp_access();
+   void record(int line, e_acc_type rw, prog_scope *scope);
+   lifetime get_required_lifetime();
+private:
+   prog_scope *last_read_scope;
+   prog_scope *first_read_scope;
+   prog_scope *first_write_scope;
+   int first_dominant_write;
+   int last_read;
+   int last_write;
+   int first_read;
+   bool keep_for_full_loop;
+};
+
+/* Some storage class to encapsulate the prog_scope (de-)allocations */
+class prog_scope_storage {
+public:
+   prog_scope_storage(void