[Mesa-dev] [PATCH v3 13/13] mesa/st/glsl_to_tgsi: Expose array live range tracking and merging

Gert Wollny gw.fossdev at gmail.com
Sat Apr 28 19:30:13 UTC 2018


This patch ties in the array split, merge, and interleave code.

shader-wb changes in the TGSI code are:

           original code  |  array-merge  |  change in %
           mean      max  |  mean    max  | mean     -max
  -----------------------------------------------------------
  arrays   0.05       2  |   0.00     0   |  -100     -100
  temps    5.05      21  |   4.92    20   |  -2.59   -4.76
  instr   55.33     988  |  55.20   988   |  -0.25    0.00

Signed-off-by: Gert Wollny <gw.fossdev at gmail.com>
---
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp            | 19 +++++++++++++++++--
 src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp |  7 ++-----
 src/mesa/state_tracker/st_glsl_to_tgsi_temprename.h   | 11 +++++++++--
 src/mesa/state_tracker/tests/st_tests_common.cpp      | 13 +++++++------
 4 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index a390dd0b74..788357db5f 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -5513,17 +5513,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);
 }
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp
index bc63bfc1cd..68f613534e 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp
@@ -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
     */
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.h b/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.h
index 86c21587ef..5f2878e2fe 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.h
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.h
@@ -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_*
diff --git a/src/mesa/state_tracker/tests/st_tests_common.cpp b/src/mesa/state_tracker/tests/st_tests_common.cpp
index 375d058e77..e80519f691 100644
--- a/src/mesa/state_tracker/tests/st_tests_common.cpp
+++ b/src/mesa/state_tracker/tests/st_tests_common.cpp
@@ -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]);
+                                               &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);
 }
-- 
2.16.1



More information about the mesa-dev mailing list