mesa/st/glsl_to_tgsi: Expose array live range tracking and merging
authorGert Wollny <gw.fossdev@gmail.com>
Tue, 5 Jun 2018 20:26:47 +0000 (22:26 +0200)
committerGert Wollny <gw.fossdev@gmail.com>
Sat, 11 Aug 2018 10:32:42 +0000 (12:32 +0200)
This patch ties in the array split, merge, and interleave code.

shader-db changes in the TGSI code are:

              original code  |  array-merge  |       change
              mean      max  |  mean    max  | best  mean %  worst
      -----------------------------------------------------------
      arrays   0.05       2  |   0.00     0  |  -2   -100      0
total temps    5.05      21  |   4.92    20  | -15   -2.59     1
      instr   55.33     988  |  55.20   988  | -15   -0.24     0

Evaluation:

Run shader-db in single thread mode (otherwise the output is
not ordered and the best and worst column don't make sense) to
get results pre-stats.txt and post-stats.txt. Then using
python pandas:

 import pandas as pd
 old_stats = pd.read_csv('pre-stats.txt')
 new_stats = pd.read_csv('post-stats.txt')
 omean = old_stats.mean()
 omax = old_stats.max()
 nmean = new_stats.mean()
 nmax = new_stats.max()
 delta =  new_stats - old_stats
 pd.concat([omean, omax, nmean, nmax, delta.min(),
            delta.mean()/old_stats.mean()*100, delta.max()],
            axis=1, keys=['mean', 'max', 'mean', 'max', 'best',
            'avg change %', 'worst'])

v4: - Correct typo and add bugs that are fixed by this series.
    - Update stats and describe stats evaluation

Bugzilla:
  https://bugs.freedesktop.org/show_bug.cgi?id=105371
  https://bugs.freedesktop.org/show_bug.cgi?id=100200
Signed-off-by: Gert Wollny <gw.fossdev@gmail.com>
Acked-by: Dave Airlie <airlied@redhat.com>
src/mesa/state_tracker/st_glsl_to_tgsi.cpp
src/mesa/state_tracker/st_glsl_to_tgsi_array_merge.h
src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp
src/mesa/state_tracker/st_glsl_to_tgsi_temprename.h
src/mesa/state_tracker/tests/st_tests_common.cpp

index 3af7333ebd3f059f1dd068a3065ee744246f6a88..a2083a4f856c82e6d0803a220063859aefbd156a 100644 (file)
@@ -5593,17 +5593,32 @@ glsl_to_tgsi_visitor::split_arrays(void)
 void
 glsl_to_tgsi_visitor::merge_registers(void)
 {
+   struct array_live_range *arr_live_ranges = NULL;
+
    struct register_live_range *reg_live_ranges =
         rzalloc_array(mem_ctx, struct register_live_range, this->next_temp);
 
+   if (this->next_array > 0) {
+      arr_live_ranges = new array_live_range[this->next_array];
+      for (unsigned i = 0; i < this->next_array; ++i)
+        arr_live_ranges[i] = array_live_range(i+1, this->array_sizes[i+1]);
+   }
+
+
    if (get_temp_registers_required_live_ranges(reg_live_ranges, &this->instructions,
-                                            this->next_temp, reg_live_ranges)) {
+                                              this->next_temp, reg_live_ranges,
+                                              this->next_array, arr_live_ranges)) {
       struct rename_reg_pair *renames =
            rzalloc_array(reg_live_ranges, struct rename_reg_pair, this->next_temp);
       get_temp_registers_remapping(reg_live_ranges, this->next_temp,
                                   reg_live_ranges, renames);
       rename_temp_registers(renames);
-      ralloc_free(renames);
+
+      this->next_array =  merge_arrays(this->next_array, this->array_sizes,
+                                      &this->instructions, arr_live_ranges);
+
+      if (arr_live_ranges)
+        delete[] arr_live_ranges;
    }
    ralloc_free(reg_live_ranges);
 }
index abf58c307a6de29d78f13978f7e438c9d90cd8d1..7d52d095cfb84b080d14135f14ab7d2da4f10000 100644 (file)
@@ -146,6 +146,9 @@ public:
                            const array_remapping& rhs);
 
 private:
+
+   void interleave(int trgt_access_mask, int src_access_mask);
+
    unsigned target_id;
    int8_t read_swizzle_map[4];
 };
@@ -182,4 +185,4 @@ int merge_arrays(int narrays,
                 unsigned *array_sizes,
                 exec_list *instructions,
                 struct array_live_range *arr_live_ranges);
-#endif
\ No newline at end of file
+#endif
index 2726e9ddcab7678ebcae6e2a1d26f8ad842d33d2..e1519ef3ca3027a610daa5a559cc340a6b8037fc 100644 (file)
@@ -1121,7 +1121,8 @@ static void dump_instruction(ostream& os, int line, prog_scope *scope,
  */
 bool
 get_temp_registers_required_live_ranges(void *mem_ctx, exec_list *instructions,
-                 int ntemps, struct register_live_range *register_live_ranges)
+                 int ntemps, struct register_live_range *register_live_ranges,
+                 int narrays, struct array_live_range *array_live_ranges)
 {
    int line = 0;
    int loop_id = 1;
@@ -1130,10 +1131,6 @@ get_temp_registers_required_live_ranges(void *mem_ctx, exec_list *instructions,
    bool is_at_end = false;
    int n_scopes = 1;
 
-   /* Placeholder to make the tests pass */
-   int narrays = 2;
-   struct array_live_range array_live_ranges[3];
-
    /* Count scopes to allocate the needed space without the need for
     * re-allocation
     */
index 5a812072f93d7f7d6adef7a56edb403e4e914e83..c70cd88819103ba44a4b4241a0ff5984e653138c 100644 (file)
@@ -24,7 +24,7 @@
 #ifndef MESA_GLSL_TO_TGSI_TEMPRENAME_H
 #define MESA_GLSL_TO_TGSI_TEMPRENAME_H
 
-#include "st_glsl_to_tgsi_private.h"
+#include "st_glsl_to_tgsi_array_merge.h"
 
 /** Storage to record the required live range of a temporary register
  * begin == end == -1 indicates that the register can be reused without
@@ -50,12 +50,19 @@ struct register_live_range {
  *   point to allocated memory that can hold ntemps register_live_range
  *   structures. On output the live ranges contains the live ranges for
  *   the registers with the exception of TEMP[0]
+ * @param[in] narrays number of array sreserved for this shader
+ * @param[in,out] arr_live_ranges memory location to store the estimated required
+ *   live ranges for each array. The parameter must point to allocated memory
+ *   that can hold narrays array_live_range structures. On output the live
+ *   ranges contains the live ranges for the registers with the exception of
+ *   ARRAY[0].
  * @returns: true if the lifetimes were estimated, false if not (i.e. if a
  * subroutine was called).
  */
 bool
 get_temp_registers_required_live_ranges(void *mem_ctx, exec_list *instructions,
-                 int ntemps, struct register_live_range *register_live_ranges);
+                 int ntemps, struct register_live_range *register_live_ranges,
+                 int narrays, array_live_range *array_live_ranges);
 
 /** Estimate the merge remapping of the registers.
  * @param[in] mem_ctx a memory context that can be used with the ralloc_*
index ef2513a59958d1660f8489b03f389fea34c1021f..91b989880915bf19ff06d9d6478bbcc3f09bc2c5 100644 (file)
@@ -409,11 +409,11 @@ LifetimeEvaluatorTest::run(const vector<FakeCodeline>& code, bool& success)
 {
    FakeShader shader(code);
    lifetime_result result(shader.get_num_temps());
-
+   vector <array_live_range> arr(10);
    success =
         get_temp_registers_required_live_ranges(mem_ctx, shader.get_program(mem_ctx),
-                                               shader.get_num_temps(),
-                                               &result[0]);
+                                              shader.get_num_temps(),
+                                              &result[0], 9, &arr[0]);
 
    return result;
 }
@@ -422,11 +422,11 @@ void LifetimeEvaluatorTest::run(const vector<FakeCodeline>& code, const temp_lt_
 {
    FakeShader shader(code);
    lifetime_result result(shader.get_num_temps());
-
+   vector <array_live_range> arr(10);
    bool success =
       get_temp_registers_required_live_ranges(mem_ctx, shader.get_program(mem_ctx),
                                             shader.get_num_temps(),
-                                            &result[0]);
+                                           &result[0], 9, &arr[0]);
    ASSERT_TRUE(success);
    ASSERT_EQ(result.size(), e.size());
    check(result, e);
@@ -478,8 +478,9 @@ void RegisterLifetimeAndRemappingTest::run(const vector<FakeCodeline>& code,
 {
      FakeShader shader(code);
      std::vector<register_live_range> lt(shader.get_num_temps());
-
+     vector <array_live_range> arr(10);
      get_temp_registers_required_live_ranges(mem_ctx, shader.get_program(mem_ctx),
-                                           shader.get_num_temps(), &lt[0]);
+                                            shader.get_num_temps(), &lt[0],
+                                            9, &arr[0]);
      this->run(lt, expect);
 }