1/* -*- mesa-c++  -*-
2 *
3 * Copyright (c) 2018-2019 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 SFN_INSTRUCTION_FETCH_H
28#define SFN_INSTRUCTION_FETCH_H
29
30#include "sfn_instruction_base.h"
31
32namespace r600 {
33
34class FetchInstruction : public Instruction {
35public:
36
37   FetchInstruction(EVFetchInstr vc_opcode,
38                    EVFetchType fetch_type,
39                    EVTXDataFormat data_format,
40                    EVFetchNumFormat num_format,
41                    EVFetchEndianSwap endian_swap,
42                    const PValue src,
43                    const GPRVector dst,
44                    uint32_t offset,
45                    bool is_mega_fetch,
46                    uint32_t mega_fetch_count,
47                    uint32_t buffer_id,
48                    uint32_t semantic_id,
49
50                    EBufferIndexMode buffer_index_mode,
51                    bool uncached,
52                    bool indexed,
53                    int array_base,
54                    int array_size,
55                    int elm_size,
56                    PValue buffer_offset,
57                    const std::array<int, 4>& dest_swizzle);
58
59   FetchInstruction(EVFetchInstr op,
60                    EVFetchType type,
61                    GPRVector dst,
62                    PValue src, int offset,
63                    int buffer_id, PValue buffer_offset,
64                    EBufferIndexMode cp_rel,
65                    bool use_const_field = false);
66
67   FetchInstruction(GPRVector dst,
68                    PValue src,
69                    int buffer_id,
70                    PValue buffer_offset,
71                    EVTXDataFormat format,
72                    EVFetchNumFormat num_format);
73
74   FetchInstruction(GPRVector dst,
75                    PValue src,
76                    int buffer_id,
77                    EBufferIndexMode cp_rel);
78
79   FetchInstruction(GPRVector dst, PValue src, int scratch_size);
80
81   void replace_values(const ValueSet& candidates, PValue new_value) override;
82   EVFetchInstr vc_opcode() const { return m_vc_opcode;}
83   EVFetchType fetch_type() const { return m_fetch_type;}
84
85   EVTXDataFormat data_format() const { return m_data_format;}
86   EVFetchNumFormat num_format() const { return m_num_format;}
87   EVFetchEndianSwap endian_swap() const { return m_endian_swap;}
88
89   const Value& src() const { return *m_src;}
90   const GPRVector& dst() const { return m_dst;}
91   uint32_t offset() const { return m_offset;}
92
93   bool is_mega_fetchconst() { return m_is_mega_fetch;}
94   uint32_t mega_fetch_count() const { return m_mega_fetch_count;}
95
96   uint32_t buffer_id() const { return m_buffer_id;}
97   uint32_t semantic_id() const { return m_semantic_id;}
98   EBufferIndexMode buffer_index_mode() const{ return m_buffer_index_mode;}
99
100   bool is_signed() const { return m_flags.test(vtx_format_comp_signed);}
101   bool use_const_fields() const { return m_flags.test(vtx_use_const_field);}
102
103   bool srf_mode_no_zero() const { return m_flags.test(vtx_srf_mode);}
104
105   void set_flag(EVFetchFlagShift flag) {m_flags.set(flag);}
106
107   bool uncached() const {return m_uncached; }
108   bool indexed() const {return m_indexed; }
109   int array_base()const {return m_array_base; }
110   int array_size() const {return m_array_size; }
111   int elm_size() const {return m_elm_size; }
112
113   void set_buffer_offset(PValue buffer_offset) {
114      m_buffer_offset = buffer_offset;
115      add_remappable_src_value(&m_buffer_offset);
116   }
117   PValue buffer_offset() const { return m_buffer_offset; }
118
119   void set_dest_swizzle(const std::array<int,4>& swz);
120   void set_format(EVTXDataFormat fmt);
121
122   int swz(int idx) const { return m_dest_swizzle[idx];}
123
124   bool use_tc() const {return m_flags.test(vtx_use_tc);}
125
126   bool use_vpm() const {return m_flags.test(vtx_vpm);}
127
128   void prelude_append(Instruction *instr);
129
130   const std::vector<PInstruction>& prelude() const;
131
132   bool has_prelude() const {return !m_prelude.empty();}
133
134   bool accept(InstructionVisitor& visitor) override {return visitor.visit(*this);}
135   bool accept(ConstInstructionVisitor& visitor) const override {return visitor.visit(*this);}
136
137private:
138   bool is_equal_to(const Instruction& lhs) const override;
139   void do_print(std::ostream& os) const override;
140
141   EVFetchInstr m_vc_opcode;
142   EVFetchType m_fetch_type;
143
144   EVTXDataFormat m_data_format;
145   EVFetchNumFormat m_num_format;
146   EVFetchEndianSwap m_endian_swap;
147
148   PValue m_src;
149   GPRVector m_dst;
150   uint32_t m_offset;
151
152   bool m_is_mega_fetch;
153   uint32_t m_mega_fetch_count;
154
155   uint32_t m_buffer_id;
156   uint32_t m_semantic_id;
157
158   EBufferIndexMode m_buffer_index_mode;
159   std::bitset<16> m_flags;
160   bool m_uncached;
161   bool m_indexed;
162   int m_array_base;
163   int m_array_size;
164   int m_elm_size;
165   PValue m_buffer_offset;
166   std::array<int, 4> m_dest_swizzle;
167   std::vector<PInstruction> m_prelude;
168};
169
170class LoadFromScratch: public FetchInstruction {
171public:
172   LoadFromScratch(GPRVector dst, PValue src, int scratch_size);
173};
174
175class FetchGDSOpResult : public FetchInstruction {
176public:
177   FetchGDSOpResult(const GPRVector dst, const PValue src);
178};
179
180class FetchTCSIOParam : public FetchInstruction {
181public:
182   FetchTCSIOParam(GPRVector dst, PValue src, int offset);
183};
184
185}
186
187#endif // SFN_INSTRUCTION_FETCH_H
188