3 * Copyright (c) 2018 Collabora LTD
5 * Author: Gert Wollny <gert.wollny@collabora.com>
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:
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
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.
27 #ifndef SFN_SHADERIO_H
28 #define SFN_SHADERIO_H
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"
43 virtual ~ShaderInput();
45 ShaderInput(tgsi_semantic name
);
46 tgsi_semantic
name() const {return m_name
;}
48 void set_gpr(int gpr
) {m_gpr
= gpr
;}
49 int gpr() const {return m_gpr
;}
50 void set_ioinfo(r600_shader_io
& io
, int translated_ij_index
) const;
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();
58 virtual bool is_varying() const;
61 virtual void set_specific_ioinfo(r600_shader_io
& io
) const;
65 bool m_uses_interpolate_at_centroid
;
68 using PShaderInput
= std::shared_ptr
<ShaderInput
>;
70 class ShaderInputSystemValue
: public ShaderInput
{
72 ShaderInputSystemValue(tgsi_semantic name
, int gpr
);
73 void set_specific_ioinfo(r600_shader_io
& io
) const;
77 class ShaderInputVarying
: public ShaderInput
{
79 ShaderInputVarying(tgsi_semantic name
, int sid
, nir_variable
*input
);
80 ShaderInputVarying(tgsi_semantic name
, const ShaderInputVarying
& orig
,
83 void set_lds_pos(int lds_pos
) override
;
85 int ij_index() const override
;
87 bool interpolate() const override
;
89 int lds_pos() const override
;
91 int sid() const {return m_sid
;}
93 void update_mask(int additional_comps
);
95 size_t location() const {return m_driver_location
;}
96 int location_frac() const {return m_location_frac
;}
98 bool is_varying() const override
;
101 void evaluate_spi_sid();
103 virtual void set_color_ioinfo(r600_shader_io
& io
) const;
104 void set_specific_ioinfo(r600_shader_io
& io
) const override
;
105 size_t m_driver_location
;
109 tgsi_interpolate_mode m_interpolate
;
110 tgsi_interpolate_loc m_interpolate_loc
;
116 class ShaderInputColor
: public ShaderInputVarying
{
118 ShaderInputColor(tgsi_semantic name
, int sid
, nir_variable
*input
);
119 void set_back_color(unsigned back_color_input_idx
);
120 unsigned back_color_input_index() const {
121 return m_back_color_input_idx
;
124 void set_color_ioinfo(UNUSED r600_shader_io
& io
) const override
;
125 unsigned m_back_color_input_idx
;
134 size_t add_input(ShaderInput
*input
);
136 std::vector
<PShaderInput
>& inputs();
137 ShaderInput
& input(size_t k
);
139 ShaderInput
& input(size_t driver_loc
, int frac
);
141 void set_two_sided();
142 bool two_sided() {return m_two_sided
;}
148 void sort_varying_inputs();
150 size_t size() const {return m_inputs
.size();}
152 PShaderInput
find_varying(tgsi_semantic name
, int sid
, int frac
);
154 void update_lds_pos();
157 std::vector
<PShaderInput
> m_inputs
;
158 std::vector
<int> m_ldspos
;
164 std::pair
<unsigned, unsigned>
165 r600_get_varying_semantic(unsigned varying_location
);
170 #endif // SFN_SHADERIO_H