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_FETCH_H 28 #define INSTR_FETCH_H 29 30 #include "sfn_instr.h" 31 32 namespace r600 { 33 34 class ValueFactory; 35 36 class FetchInstr : public InstrWithVectorResult { 37 public: 38 enum EFlags { 39 fetch_whole_quad, 40 use_const_field, 41 format_comp_signed, 42 srf_mode, 43 buf_no_stride, 44 alt_const, 45 use_tc, 46 vpm, 47 is_mega_fetch, 48 uncached, 49 indexed, 50 wait_ack, 51 unknown 52 }; 53 54 enum EPrintSkip { 55 fmt, 56 ftype, 57 mfc, 58 count 59 }; 60 61 FetchInstr(EVFetchInstr opcode, 62 const RegisterVec4& dst, 63 const RegisterVec4::Swizzle& dest_swizzle, 64 PRegister src, 65 uint32_t src_offset, 66 EVFetchType fetch_type, 67 EVTXDataFormat data_format, 68 EVFetchNumFormat num_format, 69 EVFetchEndianSwap endian_swap, 70 uint32_t resource_id, 71 PRegister resource_offset); 72 73 void accept(ConstInstrVisitor& visitor) const override; 74 void accept(InstrVisitor& visitor) override; 75 set_src(PRegister src)76 void set_src(PRegister src) { m_src = src; } src()77 const auto& src() const 78 { 79 assert(m_src); 80 return *m_src; 81 } src_offset()82 uint32_t src_offset() const { return m_src_offset; } 83 fetch_type()84 EVFetchType fetch_type() const { return m_fetch_type; } data_format()85 EVTXDataFormat data_format() const { return m_data_format; } set_num_format(EVFetchNumFormat nf)86 void set_num_format(EVFetchNumFormat nf) { m_num_format = nf; } num_format()87 EVFetchNumFormat num_format() const { return m_num_format; } endian_swap()88 EVFetchEndianSwap endian_swap() const { return m_endian_swap; } 89 mega_fetch_count()90 uint32_t mega_fetch_count() const { return m_mega_fetch_count; } array_base()91 uint32_t array_base() const { return m_array_base; } array_size()92 uint32_t array_size() const { return m_array_size; } elm_size()93 uint32_t elm_size() const { return m_elm_size; } 94 reset_fetch_flag(EFlags flag)95 void reset_fetch_flag(EFlags flag) { m_tex_flags.reset(flag); } set_fetch_flag(EFlags flag)96 void set_fetch_flag(EFlags flag) { m_tex_flags.set(flag); } has_fetch_flag(EFlags flag)97 bool has_fetch_flag(EFlags flag) const { return m_tex_flags.test(flag); } 98 opcode()99 EVFetchInstr opcode() const { return m_opcode; } 100 101 bool is_equal_to(const FetchInstr& rhs) const; 102 103 static Instr::Pointer from_string(std::istream& is, ValueFactory& vf); 104 set_mfc(int mfc)105 void set_mfc(int mfc) 106 { 107 m_tex_flags.set(is_mega_fetch); 108 m_mega_fetch_count = mfc; 109 } set_array_base(int arrb)110 void set_array_base(int arrb) { m_array_base = arrb; } set_array_size(int arrs)111 void set_array_size(int arrs) { m_array_size = arrs; } 112 set_element_size(int size)113 void set_element_size(int size) { m_elm_size = size; } set_print_skip(EPrintSkip skip)114 void set_print_skip(EPrintSkip skip) { m_skip_print.set(skip); } slots()115 uint32_t slots() const override { return 1; }; 116 117 bool replace_source(PRegister old_src, PVirtualValue new_src) override; 118 119 protected: 120 static Instr::Pointer 121 from_string_impl(std::istream& is, EVFetchInstr opcode, ValueFactory& vf); 122 override_opname(const char * opname)123 void override_opname(const char *opname) { m_opname = opname; } 124 125 private: 126 bool do_ready() const override; 127 128 void do_print(std::ostream& os) const override; 129 130 void set_param_from_string(const std::string& next_token); 131 void set_flag_from_string(const std::string& next_token); 132 133 static const std::map<EVTXDataFormat, const char *> s_data_format_map; 134 static const std::map<const char *, EFlags> s_flag_map; 135 136 bool propagate_death() override; 137 138 EVFetchInstr m_opcode; 139 140 PRegister m_src; 141 uint32_t m_src_offset; 142 143 EVFetchType m_fetch_type; 144 EVTXDataFormat m_data_format; 145 EVFetchNumFormat m_num_format; 146 EVFetchEndianSwap m_endian_swap; 147 148 std::bitset<EFlags::unknown> m_tex_flags; 149 std::bitset<EPrintSkip::count> m_skip_print; 150 151 uint32_t m_mega_fetch_count; 152 uint32_t m_array_base; 153 uint32_t m_array_size; 154 uint32_t m_elm_size; 155 156 std::string m_opname; 157 }; 158 159 class QueryBufferSizeInstr : public FetchInstr { 160 public: 161 QueryBufferSizeInstr(const RegisterVec4& dst, 162 const RegisterVec4::Swizzle& swizzle, 163 uint32_t resid); 164 static Instr::Pointer from_string(std::istream& is, ValueFactory& vf); 165 }; 166 167 class LoadFromBuffer : public FetchInstr { 168 public: 169 LoadFromBuffer(const RegisterVec4& dst, 170 const RegisterVec4::Swizzle& swizzle, 171 PRegister addr, 172 uint32_t addr_offset, 173 uint32_t resid, 174 PRegister res_offset, 175 EVTXDataFormat data_format); 176 static Instr::Pointer from_string(std::istream& is, ValueFactory& vf); 177 }; 178 179 class LoadFromScratch : public FetchInstr { 180 public: 181 LoadFromScratch(const RegisterVec4& dst, 182 const RegisterVec4::Swizzle& swizzle, 183 PVirtualValue addr, 184 uint32_t offset); 185 static Instr::Pointer from_string(std::istream& is, ValueFactory& vf); 186 }; 187 188 } // namespace r600 189 #endif // INSTR_FETCH_H 190