[Mesa-dev] [PATCH v3 06/13] mesa/st/glsl_to_tgsi: Add class to track array live range

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


todo explain

Signed-off-by: Gert Wollny <gw.fossdev at gmail.com>
---
 .../state_tracker/st_glsl_to_tgsi_array_merge.cpp  | 69 ++++++++++++++++++++++
 .../state_tracker/st_glsl_to_tgsi_array_merge.h    | 46 +++++++++++++++
 2 files changed, 115 insertions(+)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi_array_merge.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi_array_merge.cpp
index 52d0d81796..89b9bf66d4 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi_array_merge.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi_array_merge.cpp
@@ -37,6 +37,75 @@ using std::unique_ptr;
 using std::make_unique;
 #endif
 
+
+array_live_range::array_live_range():
+   id(0),
+   length(0),
+   first_access(0),
+   last_access(0),
+   component_access_mask(0),
+   used_component_count(0)
+{
+}
+
+array_live_range::array_live_range(unsigned aid, unsigned alength):
+   id(aid),
+   length(alength),
+   first_access(0),
+   last_access(0),
+   component_access_mask(0),
+   used_component_count(0)
+{
+}
+
+array_live_range::array_live_range(unsigned aid, unsigned alength, int begin,
+                               int end, int sw):
+   id(aid),
+   length(alength),
+   first_access(begin),
+   last_access(end),
+   component_access_mask(sw),
+   used_component_count(util_bitcount(sw))
+{
+}
+
+void array_live_range::set_live_range(int _begin, int _end)
+{
+   set_begin(_begin);
+   set_end(_end);
+}
+
+void array_live_range::set_access_mask(int mask)
+{
+   component_access_mask = mask;
+   used_component_count = util_bitcount(mask);
+}
+
+void array_live_range::merge_live_range(const array_live_range &other)
+{
+   if (other.begin() < first_access)
+      first_access = other.begin();
+   if (other.end() > last_access)
+      last_access = other.end();
+}
+
+void array_live_range::print(std::ostream& os) const
+{
+   os << "[id:" << id
+      << ", length:" << length
+      << ", (b:" << first_access
+      << ", e:" << last_access
+      << "), sw:" << component_access_mask
+      << ", nc:" << used_component_count
+      << "]";
+}
+
+bool array_live_range::time_doesnt_overlap(const array_live_range& other) const
+{
+   return (other.last_access < first_access ||
+           last_access < other.first_access);
+}
+
 namespace tgsi_array_merge {
 
 array_remapping::array_remapping():
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi_array_merge.h b/src/mesa/state_tracker/st_glsl_to_tgsi_array_merge.h
index c74c854e09..b9fb498e69 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi_array_merge.h
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi_array_merge.h
@@ -27,6 +27,52 @@
 #include "st_glsl_to_tgsi_private.h"
 #include <iosfwd>
 
+/* Helper class to evaluate the required live range of an array.
+ *
+ * For arrays not only the live range must be tracked, but also the arrays
+ * length and since we want to interleave arrays, we also track an access mask.
+ * Consequently, one array can be merged into another or interleaved with
+ * another only if the target array is longer.
+ */
+class array_live_range {
+public:
+   array_live_range();
+   array_live_range(unsigned aid, unsigned alength);
+   array_live_range(unsigned aid, unsigned alength, int first_access,
+                  int last_access, int mask);
+
+   void set_live_range(int first_access, int last_access);
+   void set_begin(int _begin){first_access = _begin;}
+   void set_end(int _end){last_access = _end;}
+   void set_access_mask(int s);
+   void merge_live_range(const array_live_range& other);
+
+   unsigned array_id() const {return id;}
+   int array_length() const { return length;}
+   int begin() const { return first_access;}
+   int end() const { return last_access;}
+   int access_mask() const { return component_access_mask;}
+   int used_components() const {return used_component_count;}
+
+   bool time_doesnt_overlap(const array_live_range& other) const;
+
+   void print(std::ostream& os) const;
+
+private:
+   unsigned id;
+   unsigned length;
+   int first_access;
+   int last_access;
+   int component_access_mask;
+   int used_component_count;
+};
+
+inline
+std::ostream& operator << (std::ostream& os, const array_live_range& lt) {
+   lt.print(os);
+   return os;
+}
+
 namespace tgsi_array_merge {
 
 /* Helper class to merge and interleave arrays.
-- 
2.16.1



More information about the mesa-dev mailing list