1 /* -*- mesa-c++  -*-
2  *
3  * Copyright (c) 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 #include "sfn_emitinstruction.h"
28 
29 #include "sfn_shader_base.h"
30 
31 namespace r600 {
32 
EmitInstruction(ShaderFromNirProcessor & processor)33 EmitInstruction::EmitInstruction(ShaderFromNirProcessor& processor):
34    m_proc(processor)
35 {
36 
37 }
38 
~EmitInstruction()39 EmitInstruction::~EmitInstruction()
40 {
41 }
42 
emit(nir_instr * instr)43 bool EmitInstruction::emit(nir_instr* instr)
44 {
45    return do_emit(instr);
46 }
47 
from_nir(const nir_src & v,unsigned component,unsigned swizzled)48 PValue EmitInstruction::from_nir(const nir_src& v, unsigned component, unsigned swizzled)
49 {
50    return m_proc.from_nir(v, component, swizzled);
51 }
52 
from_nir(const nir_alu_src & v,unsigned component)53 PValue EmitInstruction::from_nir(const nir_alu_src& v, unsigned component)
54 {
55    return m_proc.from_nir(v, component);
56 }
57 
from_nir(const nir_tex_src & v,unsigned component)58 PValue EmitInstruction::from_nir(const nir_tex_src& v, unsigned component)
59 {
60    return m_proc.from_nir(v, component);
61 }
62 
from_nir(const nir_alu_dest & v,unsigned component)63 PValue EmitInstruction::from_nir(const nir_alu_dest& v, unsigned component)
64 {
65    return m_proc.from_nir(v, component);
66 }
67 
from_nir(const nir_dest & v,unsigned component)68 PValue EmitInstruction::from_nir(const nir_dest& v, unsigned component)
69 {
70    return m_proc.from_nir(v, component);
71 }
72 
from_nir(const nir_src & v,unsigned component)73 PValue EmitInstruction::from_nir(const nir_src& v, unsigned component)
74 {
75    return m_proc.from_nir(v, component);
76 }
77 
emit_instruction(Instruction * ir)78 void EmitInstruction::emit_instruction(Instruction *ir)
79 {
80    return m_proc.emit_instruction(ir);
81 }
82 
emit_instruction(AluInstruction * ir)83 void EmitInstruction::emit_instruction(AluInstruction *ir)
84 {
85    return m_proc.emit_instruction(ir);
86 }
87 
emit_instruction(EAluOp opcode,PValue dest,std::vector<PValue> src0,const std::set<AluModifiers> & m_flags)88 bool EmitInstruction::emit_instruction(EAluOp opcode, PValue dest,
89                                        std::vector<PValue> src0,
90                                        const std::set<AluModifiers>& m_flags)
91 {
92    return m_proc.emit_instruction(opcode, dest,src0, m_flags);
93 }
94 
95 const nir_variable *
get_deref_location(const nir_src & v) const96 EmitInstruction::get_deref_location(const nir_src& v) const
97 {
98    return m_proc.get_deref_location(v);
99 }
100 
from_nir_with_fetch_constant(const nir_src & src,unsigned component,int channel)101 PValue EmitInstruction::from_nir_with_fetch_constant(const nir_src& src, unsigned component, int channel)
102 {
103    return m_proc.from_nir_with_fetch_constant(src, component, channel);
104 }
105 
vec_from_nir_with_fetch_constant(const nir_src & src,unsigned mask,const GPRVector::Swizzle & swizzle,bool match)106 GPRVector EmitInstruction::vec_from_nir_with_fetch_constant(const nir_src& src, unsigned mask,
107                                                             const GPRVector::Swizzle& swizzle, bool match)
108 {
109    return m_proc.vec_from_nir_with_fetch_constant(src, mask, swizzle, match);
110 }
111 
lookup_register_index(const nir_src & src) const112 int EmitInstruction::lookup_register_index(const nir_src& src) const
113 {
114    return m_proc.lookup_register_index(src);
115 }
116 
allocate_temp_register()117 int EmitInstruction::allocate_temp_register()
118 {
119    return m_proc.allocate_temp_register();
120 }
121 
lookup_register_index(const nir_dest & dst)122 int EmitInstruction::lookup_register_index(const nir_dest& dst)
123 {
124    return m_proc.lookup_register_index(dst);
125 }
126 
get_temp_register(int channel)127 PGPRValue EmitInstruction::get_temp_register(int channel)
128 {
129    return m_proc.get_temp_register(channel);
130 }
131 
get_temp_vec4()132 GPRVector EmitInstruction::get_temp_vec4()
133 {
134    return m_proc.get_temp_vec4();
135 }
136 
create_register_from_nir_src(const nir_src & src,unsigned swizzle)137 PValue EmitInstruction::create_register_from_nir_src(const nir_src& src, unsigned swizzle)
138 {
139    return m_proc.create_register_from_nir_src(src, swizzle);
140 }
141 
get_chip_class(void) const142 enum chip_class EmitInstruction::get_chip_class(void) const
143 {
144    return m_proc.get_chip_class();
145 }
146 
literal(uint32_t value)147 PValue EmitInstruction::literal(uint32_t value)
148 {
149    return m_proc.literal(value);
150 }
151 
vec_from_nir(const nir_dest & dst,int num_components)152 GPRVector EmitInstruction::vec_from_nir(const nir_dest& dst, int num_components)
153 {
154    return m_proc.vec_from_nir(dst, num_components);
155 }
156 
inject_register(unsigned sel,unsigned swizzle,const PValue & reg,bool map)157 bool EmitInstruction::inject_register(unsigned sel, unsigned swizzle,
158                                       const PValue& reg, bool map)
159 {
160    return m_proc.inject_register(sel, swizzle, reg, map);
161 }
162 
remap_atomic_base(int base)163 int EmitInstruction::remap_atomic_base(int base)
164 {
165 	return m_proc.remap_atomic_base(base);
166 }
167 
168 const std::set<AluModifiers> EmitInstruction::empty = {};
169 const std::set<AluModifiers> EmitInstruction::write = {alu_write};
170 const std::set<AluModifiers> EmitInstruction::last_write = {alu_write, alu_last_instr};
171 const std::set<AluModifiers> EmitInstruction::last = {alu_last_instr};
172 
173 }
174 
175