aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/r600/sfn/sfn_shaderio.h
blob: e77c44cc25d45ca43d943ed4071523837c8af952 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* -*- mesa-c++  -*-
 *
 * Copyright (c) 2018 Collabora LTD
 *
 * Author: Gert Wollny <gert.wollny@collabora.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 * license, and/or sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef SFN_SHADERIO_H
#define SFN_SHADERIO_H

#include "compiler/nir/nir.h"
#include "pipe/p_defines.h"
#include "pipe/p_shader_tokens.h"
#include "gallium/drivers/r600/r600_shader.h"

#include <vector>
#include <memory>

namespace r600 {

class ShaderInput {
public:
   ShaderInput();
   virtual  ~ShaderInput();

   ShaderInput(tgsi_semantic name);
   tgsi_semantic name() const {return m_name;}

   void set_gpr(int gpr) {m_gpr = gpr;}
   int gpr() const {return m_gpr;}
   void set_ioinfo(r600_shader_io& io, int translated_ij_index) const;

   virtual void set_lds_pos(int lds_pos);
   virtual int ij_index() const;
   virtual bool interpolate() const;
   virtual int lds_pos() const;
   void set_uses_interpolate_at_centroid();

   virtual bool is_varying() const;

private:
   virtual void set_specific_ioinfo(r600_shader_io& io) const;

   tgsi_semantic m_name;
   int m_gpr;
   bool m_uses_interpolate_at_centroid;
};

using PShaderInput = std::shared_ptr<ShaderInput>;

class ShaderInputSystemValue: public ShaderInput {
public:
   ShaderInputSystemValue(tgsi_semantic name, int gpr);
   void set_specific_ioinfo(r600_shader_io& io) const;
   int m_gpr;
};

class ShaderInputVarying : public ShaderInput {
public:
   ShaderInputVarying(tgsi_semantic name, int sid, nir_variable *input);
   ShaderInputVarying(tgsi_semantic name, const ShaderInputVarying& orig,
                      size_t location);

   void set_lds_pos(int lds_pos) override;

   int ij_index() const override;

   bool interpolate() const override;

   int lds_pos() const override;

   int sid() const {return m_sid;}

   void update_mask(int additional_comps);

   size_t location() const {return m_driver_location;}
   int location_frac() const {return m_location_frac;}

   bool is_varying() const override;

private:
   void evaluate_spi_sid();

   virtual void set_color_ioinfo(r600_shader_io& io) const;
   void set_specific_ioinfo(r600_shader_io& io) const override;
   size_t m_driver_location;
   int m_location_frac;
   int m_sid;
   int m_spi_sid;
   tgsi_interpolate_mode m_interpolate;
   tgsi_interpolate_loc m_interpolate_loc;
   int m_ij_index;
   int m_lds_pos;
   int m_mask;
};

class ShaderInputColor: public ShaderInputVarying {
public:
   ShaderInputColor(tgsi_semantic name, int sid, nir_variable *input);
   void set_back_color(unsigned back_color_input_idx);
   unsigned back_color_input_index() const {
      return m_back_color_input_idx;
   }
private:
   void set_color_ioinfo(UNUSED r600_shader_io& io) const override;
   unsigned m_back_color_input_idx;

};

class ShaderIO
{
public:
   ShaderIO();

   size_t add_input(ShaderInput *input);

   std::vector<PShaderInput>& inputs();
   ShaderInput& input(size_t k);

   ShaderInput& input(size_t driver_loc, int frac);

   void set_two_sided();
   bool two_sided() {return m_two_sided;}

   int nlds() const  {
      return m_lds_pos;
   }

   void sort_varying_inputs();

   size_t size() const {return m_inputs.size();}

   PShaderInput find_varying(tgsi_semantic name, int sid, int frac);

   void update_lds_pos();

private:
   std::vector<PShaderInput> m_inputs;
   std::vector<int> m_ldspos;
   bool m_two_sided;
   int m_lds_pos;

};

std::pair<unsigned, unsigned>
r600_get_varying_semantic(unsigned varying_location);


}

#endif // SFN_SHADERIO_H