replace _mesa_logbase2 with util_logbase2
[mesa.git] / src / mesa / state_tracker / st_glsl_to_tgsi_array_merge.h
index 028de2c9f5feea290847864fdf5c515c07a11c25..15738a817d342e562a0c60719f0e9a00572c9859 100644 (file)
@@ -95,4 +95,94 @@ std::ostream& operator << (std::ostream& os, const array_live_range& lt) {
    lt.print(os);
    return os;
 }
-#endif
\ No newline at end of file
+
+namespace tgsi_array_merge {
+
+/* Helper class to apply array merge and interleav to the shader.
+ * The interface is exposed here to make unit tests possible.
+ */
+class array_remapping {
+public:
+
+   /** Create an invalid mapping that is used as place-holder for
+    * arrays that are not mapped at all.
+    */
+   array_remapping();
+
+   /* Predefined remapping, needed for testing */
+   array_remapping(int trgt_array_id, const int8_t swizzle[]);
+
+   /* Initialiaze the mapping from an array_live_range that has been
+    * processed by the array merge and interleave algorithm.
+    */
+   void init_from(const array_live_range& range);
+
+   /* (Re)-set target id, needed when the mapping is resolved */
+   void set_target_id(int tid) {target_id = tid;}
+
+   /* Defines a valid remapping */
+   bool is_valid() const {return target_id > 0;}
+
+   /* Translates the write mask to the new, interleaved component
+    * position
+    */
+   int map_writemask(int original_write_mask) const;
+
+   /* Translates all read swizzles to the new, interleaved component
+    * swizzles
+    */
+   uint16_t map_swizzles(uint16_t original_swizzle) const;
+
+   /* Move the read swizzles to the positiones that correspond to
+    * a changed write mask.
+    */
+   uint16_t move_read_swizzles(uint16_t original_swizzle) const;
+
+   unsigned target_array_id() const {return target_id;}
+
+   void print(std::ostream& os) const;
+
+   friend bool operator == (const array_remapping& lhs,
+                           const array_remapping& rhs);
+
+private:
+
+   void interleave(int trgt_access_mask, int src_access_mask);
+
+   unsigned target_id;
+   int8_t read_swizzle_map[4];
+};
+
+inline
+std::ostream& operator << (std::ostream& os, const array_remapping& am)
+{
+   am.print(os);
+   return os;
+}
+
+/* Apply the array remapping (internal use, exposed here for testing) */
+ bool get_array_remapping(int narrays, array_live_range *array_live_ranges,
+                        array_remapping *remapping);
+
+/* Apply the array remapping (internal use, exposed here for testing) */
+int remap_arrays(int narrays, unsigned *array_sizes,
+                exec_list *instructions,
+                array_remapping *map);
+
+}
+
+/** Remap the array access to finalize the array merging and interleaving.
+  * @param[in] narrays number of input arrays,
+  * @param[in,out] array_sizes length array of input arrays, on output the
+  *   array sizes will be updated according to the remapping,
+  * @param[in,out] instructions TGSI program, on output the arrays access is
+  *    remapped to the new array layout,
+  * @param[in] array_live_ranges live ranges and access information of the
+  *    arrays.
+  * @returns number of remaining arrays
+  */
+int merge_arrays(int narrays,
+                unsigned *array_sizes,
+                exec_list *instructions,
+                class array_live_range *arr_live_ranges);
+#endif