glsl: Replace atomic_ssbo and ssbo_atomic with atomic
[mesa.git] / src / glsl / link_varyings.h
1 /*
2 * Copyright © 2012 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #pragma once
25 #ifndef GLSL_LINK_VARYINGS_H
26 #define GLSL_LINK_VARYINGS_H
27
28 /**
29 * \file link_varyings.h
30 *
31 * Linker functions related specifically to linking varyings between shader
32 * stages.
33 */
34
35
36 #include "main/glheader.h"
37
38
39 struct gl_shader_program;
40 struct gl_shader;
41 class ir_variable;
42
43
44 /**
45 * Data structure describing a varying which is available for use in transform
46 * feedback.
47 *
48 * For example, if the vertex shader contains:
49 *
50 * struct S {
51 * vec4 foo;
52 * float[3] bar;
53 * };
54 *
55 * varying S[2] v;
56 *
57 * Then there would be tfeedback_candidate objects corresponding to the
58 * following varyings:
59 *
60 * v[0].foo
61 * v[0].bar
62 * v[1].foo
63 * v[1].bar
64 */
65 struct tfeedback_candidate
66 {
67 /**
68 * Toplevel variable containing this varying. In the above example, this
69 * would point to the declaration of the varying v.
70 */
71 ir_variable *toplevel_var;
72
73 /**
74 * Type of this varying. In the above example, this would point to the
75 * glsl_type for "vec4" or "float[3]".
76 */
77 const glsl_type *type;
78
79 /**
80 * Offset within the toplevel variable where this varying occurs (counted
81 * in multiples of the size of a float).
82 */
83 unsigned offset;
84 };
85
86
87 /**
88 * Data structure tracking information about a transform feedback declaration
89 * during linking.
90 */
91 class tfeedback_decl
92 {
93 public:
94 void init(struct gl_context *ctx, const void *mem_ctx, const char *input);
95 static bool is_same(const tfeedback_decl &x, const tfeedback_decl &y);
96 bool assign_location(struct gl_context *ctx,
97 struct gl_shader_program *prog);
98 unsigned get_num_outputs() const;
99 bool store(struct gl_context *ctx, struct gl_shader_program *prog,
100 struct gl_transform_feedback_info *info, unsigned buffer,
101 const unsigned max_outputs) const;
102 const tfeedback_candidate *find_candidate(gl_shader_program *prog,
103 hash_table *tfeedback_candidates);
104
105 bool is_next_buffer_separator() const
106 {
107 return this->next_buffer_separator;
108 }
109
110 bool is_varying() const
111 {
112 return !this->next_buffer_separator && !this->skip_components;
113 }
114
115 const char *name() const
116 {
117 return this->orig_name;
118 }
119
120 unsigned get_stream_id() const
121 {
122 return this->stream_id;
123 }
124
125 /**
126 * The total number of varying components taken up by this variable. Only
127 * valid if assign_location() has been called.
128 */
129 unsigned num_components() const
130 {
131 if (this->lowered_builtin_array_variable)
132 return this->size;
133 else
134 return this->vector_elements * this->matrix_columns * this->size;
135 }
136
137 unsigned get_location() const {
138 return this->location;
139 }
140
141 private:
142 /**
143 * The name that was supplied to glTransformFeedbackVaryings. Used for
144 * error reporting and glGetTransformFeedbackVarying().
145 */
146 const char *orig_name;
147
148 /**
149 * The name of the variable, parsed from orig_name.
150 */
151 const char *var_name;
152
153 /**
154 * True if the declaration in orig_name represents an array.
155 */
156 bool is_subscripted;
157
158 /**
159 * If is_subscripted is true, the subscript that was specified in orig_name.
160 */
161 unsigned array_subscript;
162
163 /**
164 * Non-zero if the variable is gl_ClipDistance, glTessLevelOuter or
165 * gl_TessLevelInner and the driver lowers it to gl_*MESA.
166 */
167 enum {
168 none,
169 clip_distance,
170 tess_level_outer,
171 tess_level_inner,
172 } lowered_builtin_array_variable;
173
174 /**
175 * The vertex shader output location that the linker assigned for this
176 * variable. -1 if a location hasn't been assigned yet.
177 */
178 int location;
179
180 /**
181 * If non-zero, then this variable may be packed along with other variables
182 * into a single varying slot, so this offset should be applied when
183 * accessing components. For example, an offset of 1 means that the x
184 * component of this variable is actually stored in component y of the
185 * location specified by \c location.
186 *
187 * Only valid if location != -1.
188 */
189 unsigned location_frac;
190
191 /**
192 * If location != -1, the number of vector elements in this variable, or 1
193 * if this variable is a scalar.
194 */
195 unsigned vector_elements;
196
197 /**
198 * If location != -1, the number of matrix columns in this variable, or 1
199 * if this variable is not a matrix.
200 */
201 unsigned matrix_columns;
202
203 /** Type of the varying returned by glGetTransformFeedbackVarying() */
204 GLenum type;
205
206 /**
207 * If location != -1, the size that should be returned by
208 * glGetTransformFeedbackVarying().
209 */
210 unsigned size;
211
212 /**
213 * How many components to skip. If non-zero, this is
214 * gl_SkipComponents{1,2,3,4} from ARB_transform_feedback3.
215 */
216 unsigned skip_components;
217
218 /**
219 * Whether this is gl_NextBuffer from ARB_transform_feedback3.
220 */
221 bool next_buffer_separator;
222
223 /**
224 * If find_candidate() has been called, pointer to the tfeedback_candidate
225 * data structure that was found. Otherwise NULL.
226 */
227 const tfeedback_candidate *matched_candidate;
228
229 /**
230 * StreamId assigned to this varying (defaults to 0). Can only be set to
231 * values other than 0 in geometry shaders that use the stream layout
232 * modifier. Accepted values must be in the range [0, MAX_VERTEX_STREAMS-1].
233 */
234 unsigned stream_id;
235 };
236
237
238 void
239 cross_validate_outputs_to_inputs(struct gl_shader_program *prog,
240 gl_shader *producer, gl_shader *consumer);
241
242 bool
243 parse_tfeedback_decls(struct gl_context *ctx, struct gl_shader_program *prog,
244 const void *mem_ctx, unsigned num_names,
245 char **varying_names, tfeedback_decl *decls);
246
247 bool
248 store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
249 unsigned num_tfeedback_decls,
250 tfeedback_decl *tfeedback_decls);
251
252 bool
253 assign_varying_locations(struct gl_context *ctx,
254 void *mem_ctx,
255 struct gl_shader_program *prog,
256 gl_shader *producer, gl_shader *consumer,
257 unsigned num_tfeedback_decls,
258 tfeedback_decl *tfeedback_decls);
259
260 bool
261 check_against_output_limit(struct gl_context *ctx,
262 struct gl_shader_program *prog,
263 gl_shader *producer);
264
265 bool
266 check_against_input_limit(struct gl_context *ctx,
267 struct gl_shader_program *prog,
268 gl_shader *consumer);
269
270 #endif /* GLSL_LINK_VARYINGS_H */