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 EMITINSTRUCTION_H 28 #define EMITINSTRUCTION_H 29 30 #include "compiler/nir/nir.h" 31 #include "sfn_defines.h" 32 #include "sfn_value.h" 33 #include "sfn_instruction_alu.h" 34 35 namespace r600 { 36 37 class ShaderFromNirProcessor; 38 39 class EmitInstruction 40 { 41 public: 42 EmitInstruction(ShaderFromNirProcessor& processor); 43 virtual ~EmitInstruction(); 44 bool emit(nir_instr* instr); 45 46 static const std::set<AluModifiers> empty; 47 static const std::set<AluModifiers> write; 48 static const std::set<AluModifiers> last_write; 49 static const std::set<AluModifiers> last; 50 51 protected: 52 virtual bool do_emit(nir_instr* instr) = 0; 53 54 // forwards from ValuePool 55 PValue from_nir(const nir_src& v, unsigned component, unsigned swizzled); 56 PValue from_nir(const nir_src& v, unsigned component); 57 PValue from_nir(const nir_alu_src& v, unsigned component); 58 PValue from_nir(const nir_tex_src& v, unsigned component); 59 PValue from_nir(const nir_alu_dest& v, unsigned component); 60 PValue from_nir(const nir_dest& v, unsigned component); 61 62 PValue create_register_from_nir_src(const nir_src& src, unsigned comp); 63 64 PGPRValue get_temp_register(int channel = -1); 65 GPRVector get_temp_vec4(const GPRVector::Swizzle& swizzle = {0,1,2,3}); 66 67 // forwards from ShaderFromNirProcessor 68 void emit_instruction(Instruction *ir); 69 void emit_instruction(AluInstruction *ir); 70 bool emit_instruction(EAluOp opcode, PValue dest, 71 std::vector<PValue> src0, 72 const std::set<AluModifiers>& m_flags); 73 74 PValue from_nir_with_fetch_constant(const nir_src& src, unsigned component, int channel = -1); 75 GPRVector vec_from_nir_with_fetch_constant(const nir_src& src, unsigned mask, 76 const GPRVector::Swizzle& swizzle, bool match = false); 77 78 const nir_variable *get_deref_location(const nir_src& v) const; 79 80 enum chip_class get_chip_class(void) const; 81 82 PValue literal(uint32_t value); 83 84 GPRVector vec_from_nir(const nir_dest& dst, int num_components); 85 86 bool inject_register(unsigned sel, unsigned swizzle, 87 const PValue& reg, bool map); 88 89 int remap_atomic_base(int base); 90 91 void set_has_txs_cube_array_comp(); 92 private: 93 94 ShaderFromNirProcessor& m_proc; 95 }; 96 97 } 98 99 100 101 #endif // EMITINSTRUCTION_H 102