• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*- mesa-c++  -*-
2  *
3  * Copyright (c) 2022 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 INSTR_EXPORT_H
28 #define INSTR_EXPORT_H
29 
30 #include "sfn_instr.h"
31 
32 namespace r600 {
33 
34 class ValueFactory;
35 
36 
37 class WriteOutInstr: public Instr {
38 public:
39    WriteOutInstr(const RegisterVec4& value);
40    WriteOutInstr(const WriteOutInstr& orig) = delete;
41 
42    void override_chan(int i, int chan);
43 
value()44    const RegisterVec4& value() const {return m_value;};
value()45    RegisterVec4& value() {return m_value;};
46 private:
47 
48    RegisterVec4 m_value;
49 };
50 
51 class ExportInstr: public WriteOutInstr {
52 public:
53    enum ExportType {
54       pixel,
55       pos,
56       param
57    };
58 
59    using Pointer = R600_POINTER_TYPE(ExportInstr);
60 
61    ExportInstr(ExportType type, unsigned loc, const RegisterVec4& value);
62    ExportInstr(const ExportInstr& orig) = delete;
63 
64    void accept(ConstInstrVisitor& visitor) const override;
65    void accept(InstrVisitor& visitor) override;
66 
67    bool is_equal_to(const ExportInstr& lhs) const;
68 
69 
70    static ExportType type_from_string(const std::string& s);
71 
export_type()72    ExportType export_type() const {return m_type;}
73 
location()74    unsigned location() const {return m_loc;}
75 
set_is_last_export(bool value)76    void set_is_last_export(bool value) {m_is_last = value;}
is_last_export()77    bool is_last_export()  const {return m_is_last;}
78 
79    static Instr::Pointer from_string(std::istream& is, ValueFactory &vf);
80    static Instr::Pointer last_from_string(std::istream& is, ValueFactory &vf);
81 
82 private:
83    static ExportInstr::Pointer from_string_impl(std::istream& is, ValueFactory &vf);
84 
85    bool do_ready() const override;
86    void do_print(std::ostream& os) const override;
87 
88    ExportType m_type;
89    unsigned m_loc;
90    bool m_is_last;
91 };
92 
93 class ScratchIOInstr : public WriteOutInstr {
94 public:
95    ScratchIOInstr(const RegisterVec4& value, PRegister addr,
96                   int align, int align_offset, int writemask, int array_size,
97                   bool is_read = false);
98    ScratchIOInstr(const RegisterVec4& value, int addr,  int align, int align_offset,
99                   int writemask, bool is_read = false);
100 
101    void accept(ConstInstrVisitor& visitor) const override;
102    void accept(InstrVisitor& visitor) override;
103 
104    bool is_equal_to(const ScratchIOInstr& lhs) const;
105 
location()106    unsigned location() const { return m_loc;};
write_mask()107    int write_mask() const { return m_writemask;}
address()108    auto address() const { return m_address;}
indirect()109    bool indirect() const { return !!m_address;}
array_size()110    int array_size() const { return m_array_size;}
is_read()111    bool is_read() const {return m_read; }
112 
113    static auto from_string(std::istream& is, ValueFactory &vf) -> Pointer;
114 private:
115 
116    bool do_ready() const override;
117    void do_print(std::ostream& os) const override;
118 
119    unsigned m_loc{0};
120    PRegister m_address {nullptr};
121    unsigned m_align;
122    unsigned m_align_offset;
123    unsigned m_writemask;
124    int m_array_size{0};
125    bool m_read{false};
126 };
127 
128 class StreamOutInstr: public WriteOutInstr {
129 public:
130    StreamOutInstr(const RegisterVec4& value, int num_components,
131                        int array_base, int comp_mask, int out_buffer,
132                        int stream);
element_size()133    int element_size() const { return m_element_size;}
burst_count()134    int burst_count() const { return m_burst_count;}
array_base()135    int array_base() const { return m_array_base;}
array_size()136    int array_size() const { return m_array_size;}
comp_mask()137    int comp_mask() const { return m_writemask;}
138    unsigned op(amd_gfx_level gfx_level) const;
139 
140    bool is_equal_to(const StreamOutInstr& lhs) const;
141 
142    void accept(ConstInstrVisitor& visitor) const override;
143    void accept(InstrVisitor& visitor) override;
144 private:
145 
146    bool do_ready() const override;
147    void do_print(std::ostream& os) const override;
148 
149    int m_element_size{0};
150    int m_burst_count{1};
151    int m_array_base{0};
152    int m_array_size{0xfff};
153    int m_writemask{0};
154    int m_output_buffer{0};
155    int m_stream{0};
156 };
157 
158 class MemRingOutInstr: public WriteOutInstr {
159 public:
160 
161    enum EMemWriteType {
162       mem_write = 0,
163       mem_write_ind = 1,
164       mem_write_ack = 2,
165       mem_write_ind_ack = 3,
166    };
167 
168    MemRingOutInstr(ECFOpCode ring, EMemWriteType type,
169                         const RegisterVec4& value, unsigned base_addr,
170                         unsigned ncomp, PRegister m_index);
171 
op()172    unsigned op() const{return m_ring_op;}
173    unsigned ncomp() const;
addr()174    unsigned addr() const {return m_base_address;}
type()175    EMemWriteType type() const {return m_type;}
index_reg()176    unsigned index_reg() const {assert(m_export_index->sel() >= 0); return m_export_index->sel();}
array_base()177    unsigned array_base() const {return m_base_address; }
export_index()178    PVirtualValue export_index()  const {return m_export_index;}
179 
180    void patch_ring(int stream, PRegister index);
181 
182    void accept(ConstInstrVisitor& visitor) const override;
183    void accept(InstrVisitor& visitor) override;
184 
185    bool is_equal_to(const MemRingOutInstr& lhs) const;
186 
187    static auto from_string(std::istream& is, ValueFactory &vf) -> Pointer;
188 
189 private:
190 
191    bool do_ready() const override;
192    void do_print(std::ostream& os) const override;
193 
194    ECFOpCode m_ring_op;
195    EMemWriteType m_type;
196    unsigned m_base_address;
197    unsigned m_num_comp;
198    PRegister m_export_index;
199 };
200 
201 class EmitVertexInstr : public Instr {
202 public:
203    EmitVertexInstr(int stream, bool cut);
op()204    ECFOpCode op() const {return m_cut ? cf_cut_vertex: cf_emit_vertex;}
stream()205    int stream() const { return m_stream;}
206 
207    void accept(ConstInstrVisitor& visitor) const override;
208    void accept(InstrVisitor& visitor) override;
209 
210    bool is_equal_to(const EmitVertexInstr& lhs) const;
211 
212    static auto from_string(std::istream& is, bool cut) -> Pointer;
213 
214 private:
215    bool do_ready() const override;
216    void do_print(std::ostream& os) const override;
217 
218    int m_stream;
219    bool m_cut;
220 };
221 
222 class WriteTFInstr : public WriteOutInstr {
223 public:
224    using WriteOutInstr::WriteOutInstr;
225 
226    void accept(ConstInstrVisitor& visitor) const override;
227    void accept(InstrVisitor& visitor) override;
228 
229    bool is_equal_to(const WriteTFInstr& rhs) const;
230 
231    static auto from_string(std::istream& is, ValueFactory &vf) -> Pointer;
232 
233 private:
234    bool do_ready() const override;
235    void do_print(std::ostream& os) const override;
236 
237 };
238 
239 
240 }
241 
242 #endif // INSTR_EXPORT_H
243