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