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 #ifndef INSTRUCTION_TEX_H 28 #define INSTRUCTION_TEX_H 29 30 #include "sfn_instruction_base.h" 31 32 namespace r600 { 33 34 class TexInstruction : public Instruction { 35 public: 36 enum Opcode { 37 ld = FETCH_OP_LD, 38 get_resinfo = FETCH_OP_GET_TEXTURE_RESINFO, 39 get_nsampled = FETCH_OP_GET_NUMBER_OF_SAMPLES, 40 get_tex_lod = FETCH_OP_GET_LOD, 41 get_gradient_h = FETCH_OP_GET_GRADIENTS_H, 42 get_gradient_v = FETCH_OP_GET_GRADIENTS_V, 43 set_offsets = FETCH_OP_SET_TEXTURE_OFFSETS, 44 keep_gradients = FETCH_OP_KEEP_GRADIENTS, 45 set_gradient_h = FETCH_OP_SET_GRADIENTS_H, 46 set_gradient_v = FETCH_OP_SET_GRADIENTS_V, 47 sample = FETCH_OP_SAMPLE, 48 sample_l = FETCH_OP_SAMPLE_L, 49 sample_lb = FETCH_OP_SAMPLE_LB, 50 sample_lz = FETCH_OP_SAMPLE_LZ, 51 sample_g = FETCH_OP_SAMPLE_G, 52 sample_g_lb = FETCH_OP_SAMPLE_G_L, 53 gather4 = FETCH_OP_GATHER4, 54 gather4_o = FETCH_OP_GATHER4_O, 55 56 sample_c = FETCH_OP_SAMPLE_C, 57 sample_c_l = FETCH_OP_SAMPLE_C_L, 58 sample_c_lb = FETCH_OP_SAMPLE_C_LB, 59 sample_c_lz = FETCH_OP_SAMPLE_C_LZ, 60 sample_c_g = FETCH_OP_SAMPLE_C_G, 61 sample_c_g_lb = FETCH_OP_SAMPLE_C_G_L, 62 gather4_c = FETCH_OP_GATHER4_C, 63 gather4_c_o = FETCH_OP_GATHER4_C_O, 64 65 }; 66 67 enum Flags { 68 x_unnormalized, 69 y_unnormalized, 70 z_unnormalized, 71 w_unnormalized, 72 grad_fine 73 }; 74 75 TexInstruction(Opcode op, const GPRVector& dest, const GPRVector& src, unsigned sid, 76 unsigned rid, PValue sampler_offset); 77 src()78 const GPRVector& src() const {return m_src;} dst()79 const GPRVector& dst() const {return m_dst;} opcode()80 unsigned opcode() const {return m_opcode;} sampler_id()81 unsigned sampler_id() const {return m_sampler_id;} resource_id()82 unsigned resource_id() const {return m_resource_id;} 83 84 void replace_values(const ValueSet& candiates, PValue new_value) override; 85 86 void set_offset(unsigned index, int32_t val); 87 int get_offset(unsigned index) const; 88 set_inst_mode(int inst_mode)89 void set_inst_mode(int inst_mode) { m_inst_mode = inst_mode;} 90 inst_mode()91 int inst_mode() const { return m_inst_mode;} 92 set_flag(Flags flag)93 void set_flag(Flags flag) { 94 m_flags.set(flag); 95 } 96 sampler_offset()97 PValue sampler_offset() const { 98 return m_sampler_offset; 99 } 100 has_flag(Flags flag)101 bool has_flag(Flags flag) const { 102 return m_flags.test(flag); 103 } 104 dest_swizzle(int i)105 int dest_swizzle(int i) const { 106 assert(i < 4); 107 return m_dest_swizzle[i]; 108 } 109 set_dest_swizzle(const std::array<int,4> & swz)110 void set_dest_swizzle(const std::array<int,4>& swz) { 111 m_dest_swizzle = swz; 112 } 113 114 void set_gather_comp(int cmp); 115 116 private: 117 bool is_equal_to(const Instruction& lhs) const override; 118 void do_print(std::ostream& os) const override; 119 120 static const char *opname(Opcode code); 121 122 Opcode m_opcode; 123 GPRVector m_dst; 124 GPRVector m_src; 125 unsigned m_sampler_id; 126 unsigned m_resource_id; 127 std::bitset<8> m_flags; 128 int m_offset[3]; 129 int m_inst_mode; 130 std::array<int,4> m_dest_swizzle; 131 PValue m_sampler_offset; 132 }; 133 134 bool r600_nir_lower_int_tg4(nir_shader *nir); 135 bool r600_nir_lower_txl_txf_array_or_cube(nir_shader *shader); 136 137 } 138 139 #endif // INSTRUCTION_TEX_H 140