• 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_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 
39    enum EFlags {
40       fetch_whole_quad,
41       use_const_field,
42       format_comp_signed,
43       srf_mode,
44       buf_no_stride,
45       alt_const,
46       use_tc,
47       vpm,
48       is_mega_fetch,
49       uncached,
50       indexed,
51       wait_ack,
52       unknown
53    };
54 
55    enum EPrintSkip {
56       fmt,
57       ftype,
58       mfc,
59       count
60    };
61 
62    FetchInstr(EVFetchInstr opcode,
63               const RegisterVec4& dst,
64               const RegisterVec4::Swizzle& dest_swizzle,
65               PRegister src,
66               uint32_t src_offset,
67               EVFetchType fetch_type,
68               EVTXDataFormat data_format,
69               EVFetchNumFormat num_format,
70               EVFetchEndianSwap endian_swap,
71               uint32_t resource_id,
72               PRegister resource_offset);
73 
74    void accept(ConstInstrVisitor& visitor) const override;
75    void accept(InstrVisitor& visitor) override;
76 
set_src(PRegister src)77    void set_src(PRegister src) { m_src = src; }
src()78    const auto& src() const {assert(m_src); return *m_src;}
src_offset()79    uint32_t src_offset() const {return m_src_offset;}
80 
resource_id()81    uint32_t resource_id() const {return m_resource_id;}
resource_offset()82    auto resource_offset() const {return m_resource_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) {m_tex_flags.set(is_mega_fetch); m_mega_fetch_count = mfc;}
set_array_base(int arrb)106    void set_array_base(int arrb) {m_array_base = arrb;}
set_array_size(int arrs)107    void set_array_size(int arrs) {m_array_size = arrs;}
108 
set_element_size(int size)109    void set_element_size(int size) { m_elm_size = size;}
set_print_skip(EPrintSkip skip)110    void set_print_skip(EPrintSkip skip) {m_skip_print.set(skip);}
slots()111    uint32_t slots() const override {return 1;};
112 
113    bool replace_source(PRegister old_src, PVirtualValue new_src) override;
114 
115 protected:
116    static Instr::Pointer from_string_impl(std::istream& is, EVFetchInstr opcode, ValueFactory &vf);
117 
override_opname(const char * opname)118    void override_opname(const char *opname) { m_opname = opname;}
119 
120 private:
121    bool do_ready() const override;
122 
123    void do_print(std::ostream& os) const override;
124 
125    void set_param_from_string(const std::string& next_token);
126    void set_flag_from_string(const std::string& next_token);
127 
128    static const std::map<EVTXDataFormat, const char *> s_data_format_map;
129    static const std::map<const char *, EFlags> s_flag_map;
130 
131    bool propagate_death() override;
132 
133    EVFetchInstr m_opcode;
134 
135    PRegister m_src;
136    uint32_t m_src_offset;
137 
138    EVFetchType m_fetch_type;
139    EVTXDataFormat m_data_format;
140    EVFetchNumFormat m_num_format;
141    EVFetchEndianSwap m_endian_swap;
142 
143    uint32_t m_resource_id;
144    PRegister m_resource_offset;
145 
146    std::bitset<EFlags::unknown> m_tex_flags;
147    std::bitset<EPrintSkip::count> m_skip_print;
148 
149    uint32_t m_mega_fetch_count;
150    uint32_t m_array_base;
151    uint32_t m_array_size;
152    uint32_t m_elm_size;
153 
154    std::string m_opname;
155 };
156 
157 class QueryBufferSizeInstr : public FetchInstr {
158 public:
159    QueryBufferSizeInstr(const RegisterVec4& dst, const RegisterVec4::Swizzle& swizzle, uint32_t resid);
160    static Instr::Pointer from_string(std::istream& is, ValueFactory& vf);
161 };
162 
163 class LoadFromBuffer : public FetchInstr {
164 public:
165    LoadFromBuffer(const RegisterVec4& dst, const RegisterVec4::Swizzle& swizzle,
166                   PRegister addr, uint32_t addr_offset,
167                   uint32_t resid, PRegister res_offset, EVTXDataFormat data_format);
168    static Instr::Pointer from_string(std::istream& is, ValueFactory& vf);
169 };
170 
171 class LoadFromScratch : public FetchInstr {
172 public:
173    LoadFromScratch(const RegisterVec4& dst, const RegisterVec4::Swizzle& swizzle, PVirtualValue addr, uint32_t offset);
174    static Instr::Pointer from_string(std::istream& is, ValueFactory& vf);
175 };
176 
177 }
178 #endif // INSTR_FETCH_H
179