1 /* -*- mesa-c++ -*- 2 * 3 * Copyright (c) 2018 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_SHADERIO_H 28 #define SFN_SHADERIO_H 29 30 #include "compiler/nir/nir.h" 31 #include "pipe/p_defines.h" 32 #include "pipe/p_shader_tokens.h" 33 #include "gallium/drivers/r600/r600_shader.h" 34 35 #include <vector> 36 #include <memory> 37 38 namespace r600 { 39 40 class ShaderInput { 41 public: 42 ShaderInput(); 43 virtual ~ShaderInput(); 44 45 ShaderInput(tgsi_semantic name); name()46 tgsi_semantic name() const {return m_name;} 47 set_gpr(int gpr)48 void set_gpr(int gpr) {m_gpr = gpr;} gpr()49 int gpr() const {return m_gpr;} 50 void set_ioinfo(r600_shader_io& io, int translated_ij_index) const; 51 52 virtual void set_lds_pos(int lds_pos); 53 virtual int ij_index() const; 54 virtual bool interpolate() const; 55 virtual int lds_pos() const; 56 void set_uses_interpolate_at_centroid(); 57 58 virtual bool is_varying() const; 59 60 private: 61 virtual void set_specific_ioinfo(r600_shader_io& io) const; 62 63 tgsi_semantic m_name; 64 int m_gpr; 65 bool m_uses_interpolate_at_centroid; 66 }; 67 68 using PShaderInput = std::shared_ptr<ShaderInput>; 69 70 class ShaderInputSystemValue: public ShaderInput { 71 public: 72 ShaderInputSystemValue(tgsi_semantic name, int gpr); 73 void set_specific_ioinfo(r600_shader_io& io) const; 74 int m_gpr; 75 }; 76 77 class ShaderInputVarying : public ShaderInput { 78 public: 79 ShaderInputVarying(tgsi_semantic _name, int sid, unsigned driver_location, 80 unsigned frac, unsigned components, tgsi_interpolate_mode interpolate, 81 tgsi_interpolate_loc interp_loc); 82 ShaderInputVarying(tgsi_semantic name, int sid, nir_variable *input); 83 ShaderInputVarying(tgsi_semantic name, const ShaderInputVarying& orig, 84 size_t location); 85 86 void set_lds_pos(int lds_pos) override; 87 88 int ij_index() const override; 89 90 bool interpolate() const override; 91 92 int lds_pos() const override; 93 sid()94 int sid() const {return m_sid;} 95 96 void update_mask(int additional_comps, int frac); 97 location()98 size_t location() const {return m_driver_location;} location_frac()99 int location_frac() const {return m_location_frac;} 100 101 bool is_varying() const override; 102 103 private: 104 void evaluate_spi_sid(); 105 106 virtual void set_color_ioinfo(r600_shader_io& io) const; 107 void set_specific_ioinfo(r600_shader_io& io) const override; 108 size_t m_driver_location; 109 int m_location_frac; 110 int m_sid; 111 int m_spi_sid; 112 tgsi_interpolate_mode m_interpolate; 113 tgsi_interpolate_loc m_interpolate_loc; 114 int m_ij_index; 115 int m_lds_pos; 116 int m_mask; 117 }; 118 119 class ShaderInputColor: public ShaderInputVarying { 120 public: 121 ShaderInputColor(tgsi_semantic _name, int sid, unsigned driver_location, 122 unsigned frac, unsigned components, tgsi_interpolate_mode interpolate, 123 tgsi_interpolate_loc interp_loc); 124 ShaderInputColor(tgsi_semantic name, int sid, nir_variable *input); 125 void set_back_color(unsigned back_color_input_idx); back_color_input_index()126 unsigned back_color_input_index() const { 127 return m_back_color_input_idx; 128 } 129 private: 130 void set_color_ioinfo(UNUSED r600_shader_io& io) const override; 131 unsigned m_back_color_input_idx; 132 133 }; 134 135 class ShaderIO 136 { 137 public: 138 ShaderIO(); 139 140 size_t add_input(ShaderInput *input); 141 142 std::vector<PShaderInput>& inputs(); 143 ShaderInput& input(size_t k); 144 145 ShaderInput& input(size_t driver_loc, int frac); 146 147 void set_two_sided(); two_sided()148 bool two_sided() {return m_two_sided;} 149 nlds()150 int nlds() const { 151 return m_lds_pos; 152 } 153 154 void sort_varying_inputs(); 155 size()156 size_t size() const {return m_inputs.size();} 157 158 PShaderInput find_varying(tgsi_semantic name, int sid); 159 160 void update_lds_pos(); 161 162 private: 163 std::vector<PShaderInput> m_inputs; 164 std::vector<int> m_ldspos; 165 bool m_two_sided; 166 int m_lds_pos; 167 168 }; 169 170 std::pair<unsigned, unsigned> 171 r600_get_varying_semantic(unsigned varying_location); 172 173 174 } 175 176 #endif // SFN_SHADERIO_H 177