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