r600/sfn: Add IR instruction to fetch the TESS parameters
[mesa.git] / src / gallium / drivers / r600 / sfn / sfn_value_gpr.h
1 /* -*- mesa-c++ -*-
2 *
3 * Copyright (c) 2019 Collabora LTD
4 *
5 * Author: Gert Wollny <gert.wollny@collabora.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * on the rights to use, copy, modify, merge, publish, distribute, sub
11 * license, and/or sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27 #ifndef SFN_GPRARRAY_H
28 #define SFN_GPRARRAY_H
29
30 #include "sfn_value.h"
31 #include <vector>
32 #include <array>
33
34 namespace r600 {
35
36 class ValuePool;
37 class ValueMap;
38 class LiverangeEvaluator;
39
40 class GPRValue : public Value {
41 public:
42 GPRValue() = default;
43 GPRValue(GPRValue&& orig) = default;
44 GPRValue(const GPRValue& orig) = default;
45
46 GPRValue(uint32_t sel, uint32_t chan, int base_offset);
47
48 GPRValue(uint32_t sel, uint32_t chan);
49
50 GPRValue& operator = (const GPRValue& orig) = default;
51 GPRValue& operator = (GPRValue&& orig) = default;
52
53 uint32_t sel() const override final;
54
55 void set_as_input(){ m_input = true; }
56 bool is_input() const {return m_input; }
57 void set_pin_to_channel() { m_pin_to_channel = true;}
58 bool pin_to_channel() const { return m_pin_to_channel;}
59
60 private:
61 void do_print(std::ostream& os) const override;
62 void do_print(std::ostream& os, const PrintFlags& flags) const override;
63 bool is_equal_to(const Value& other) const override;
64 uint32_t m_sel;
65 bool m_base_offset;
66 bool m_input;
67 bool m_pin_to_channel;
68 };
69
70 class GPRVector : public Value {
71 public:
72 using Swizzle = std::array<uint32_t,4>;
73 using Values = std::array<PValue,4>;
74 GPRVector() = default;
75 GPRVector(GPRVector&& orig) = default;
76 GPRVector(const GPRVector& orig);
77
78 GPRVector(const GPRVector& orig, const std::array<uint8_t, 4>& swizzle);
79 GPRVector(std::array<PValue,4> elms);
80 GPRVector(uint32_t sel, std::array<uint32_t,4> swizzle);
81
82 GPRVector& operator = (const GPRVector& orig) = default;
83 GPRVector& operator = (GPRVector&& orig) = default;
84
85 void swizzle(const Swizzle& swz);
86
87 uint32_t sel() const override final;
88
89 void set_reg_i(int i, PValue reg);
90
91 unsigned chan_i(int i) const {return m_elms[i]->chan();}
92 PValue reg_i(int i) const {return m_elms[i];}
93 PValue operator [] (int i) const {return m_elms[i];}
94 PValue& operator [] (int i) {return m_elms[i];}
95
96 void pin_to_channel(int i);
97
98 PValue x() const {return m_elms[0];}
99 PValue y() const {return m_elms[1];}
100 PValue z() const {return m_elms[2];}
101 PValue w() const {return m_elms[3];}
102
103
104 private:
105 void do_print(std::ostream& os) const override;
106 bool is_equal_to(const Value& other) const override;
107 void validate() const;
108
109 Values m_elms;
110 mutable bool m_valid;
111 };
112
113
114 class GPRArray : public Value
115 {
116 public:
117 using Pointer = std::shared_ptr<GPRArray>;
118
119 GPRArray(int base, int size, int comp_mask, int frac);
120
121 uint32_t sel() const override;
122
123 size_t size() const {return m_values.size();}
124
125 PValue get_indirect(unsigned index, PValue indirect, unsigned component);
126
127 void record_read(LiverangeEvaluator& ev, int chan)const;
128 void record_write(LiverangeEvaluator& ev, int chan)const;
129
130 void collect_registers(ValueMap& output) const;
131
132 private:
133 void do_print(std::ostream& os) const override;
134
135 bool is_equal_to(const Value& other) const override;
136
137 int m_base_index;
138 int m_component_mask;
139 int m_frac;
140
141 std::vector<GPRVector> m_values;
142 };
143
144 using PGPRArray = GPRArray::Pointer;
145
146 class GPRArrayValue :public Value {
147 public:
148 GPRArrayValue(PValue value, GPRArray *array);
149 GPRArrayValue(PValue value, PValue index, GPRArray *array);
150
151 void record_read(LiverangeEvaluator& ev) const;
152 void record_write(LiverangeEvaluator& ev) const;
153
154 size_t array_size() const;
155 uint32_t sel() const override;
156
157 PValue value() {return m_value;}
158
159 void reset_value(PValue new_value);
160 void reset_addr(PValue new_addr);
161
162 Value::Pointer indirect() const {return m_addr;}
163
164 private:
165
166 void do_print(std::ostream& os) const override;
167
168 bool is_equal_to(const Value& other) const override;
169
170 PValue m_value;
171 PValue m_addr;
172 GPRArray *m_array;
173 };
174
175 inline size_t GPRArrayValue::array_size() const
176 {
177 return m_array->size();
178 }
179
180 inline GPRVector::Swizzle swizzle_from_mask(unsigned ncomp)
181 {
182 GPRVector::Swizzle swz = {0,1,2,3};
183 for (int i = ncomp; i < 4; ++i)
184 swz[i] = 7;
185 return swz;
186 }
187
188
189 }
190
191 #endif // SFN_GPRARRAY_H