2 * Copyright © 2012 Intel Corporation
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:
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
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.
25 #ifndef GLSL_LINK_VARYINGS_H
26 #define GLSL_LINK_VARYINGS_H
29 * \file link_varyings.h
31 * Linker functions related specifically to linking varyings between shader
36 #include "main/glheader.h"
39 struct gl_shader_program
;
45 * Data structure describing a varying which is available for use in transform
48 * For example, if the vertex shader contains:
57 * Then there would be tfeedback_candidate objects corresponding to the
65 struct tfeedback_candidate
68 * Toplevel variable containing this varying. In the above example, this
69 * would point to the declaration of the varying v.
71 ir_variable
*toplevel_var
;
74 * Type of this varying. In the above example, this would point to the
75 * glsl_type for "vec4" or "float[3]".
77 const glsl_type
*type
;
80 * Offset within the toplevel variable where this varying occurs (counted
81 * in multiples of the size of a float).
88 * Data structure tracking information about a transform feedback declaration
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
, bool has_xfb_qualifiers
) const;
102 const tfeedback_candidate
*find_candidate(gl_shader_program
*prog
,
103 hash_table
*tfeedback_candidates
);
105 bool is_next_buffer_separator() const
107 return this->next_buffer_separator
;
110 bool is_varying() const
112 return !this->next_buffer_separator
&& !this->skip_components
;
115 const char *name() const
117 return this->orig_name
;
120 unsigned get_stream_id() const
122 return this->stream_id
;
125 unsigned get_buffer() const
130 unsigned get_offset() const
136 * The total number of varying components taken up by this variable. Only
137 * valid if assign_location() has been called.
139 unsigned num_components() const
141 if (this->lowered_builtin_array_variable
)
144 return this->vector_elements
* this->matrix_columns
* this->size
*
145 (this->is_double() ? 2 : 1);
148 unsigned get_location() const {
149 return this->location
;
154 bool is_double() const
156 switch (this->type
) {
162 case GL_DOUBLE_MAT2x3
:
163 case GL_DOUBLE_MAT2x4
:
165 case GL_DOUBLE_MAT3x2
:
166 case GL_DOUBLE_MAT3x4
:
168 case GL_DOUBLE_MAT4x2
:
169 case GL_DOUBLE_MAT4x3
:
177 * The name that was supplied to glTransformFeedbackVaryings. Used for
178 * error reporting and glGetTransformFeedbackVarying().
180 const char *orig_name
;
183 * The name of the variable, parsed from orig_name.
185 const char *var_name
;
188 * True if the declaration in orig_name represents an array.
193 * If is_subscripted is true, the subscript that was specified in orig_name.
195 unsigned array_subscript
;
198 * Non-zero if the variable is gl_ClipDistance, glTessLevelOuter or
199 * gl_TessLevelInner and the driver lowers it to gl_*MESA.
206 } lowered_builtin_array_variable
;
209 * The vertex shader output location that the linker assigned for this
210 * variable. -1 if a location hasn't been assigned yet.
215 * Used to store the buffer assigned by xfb_buffer.
220 * Used to store the offset assigned by xfb_offset.
225 * If non-zero, then this variable may be packed along with other variables
226 * into a single varying slot, so this offset should be applied when
227 * accessing components. For example, an offset of 1 means that the x
228 * component of this variable is actually stored in component y of the
229 * location specified by \c location.
231 * Only valid if location != -1.
233 unsigned location_frac
;
236 * If location != -1, the number of vector elements in this variable, or 1
237 * if this variable is a scalar.
239 unsigned vector_elements
;
242 * If location != -1, the number of matrix columns in this variable, or 1
243 * if this variable is not a matrix.
245 unsigned matrix_columns
;
247 /** Type of the varying returned by glGetTransformFeedbackVarying() */
251 * If location != -1, the size that should be returned by
252 * glGetTransformFeedbackVarying().
257 * How many components to skip. If non-zero, this is
258 * gl_SkipComponents{1,2,3,4} from ARB_transform_feedback3.
260 unsigned skip_components
;
263 * Whether this is gl_NextBuffer from ARB_transform_feedback3.
265 bool next_buffer_separator
;
268 * If find_candidate() has been called, pointer to the tfeedback_candidate
269 * data structure that was found. Otherwise NULL.
271 const tfeedback_candidate
*matched_candidate
;
274 * StreamId assigned to this varying (defaults to 0). Can only be set to
275 * values other than 0 in geometry shaders that use the stream layout
276 * modifier. Accepted values must be in the range [0, MAX_VERTEX_STREAMS-1].
283 cross_validate_outputs_to_inputs(struct gl_shader_program
*prog
,
284 gl_shader
*producer
, gl_shader
*consumer
);
287 parse_tfeedback_decls(struct gl_context
*ctx
, struct gl_shader_program
*prog
,
288 const void *mem_ctx
, unsigned num_names
,
289 char **varying_names
, tfeedback_decl
*decls
);
292 process_xfb_layout_qualifiers(void *mem_ctx
, const gl_shader
*sh
,
293 unsigned *num_tfeedback_decls
,
294 char ***varying_names
);
297 remove_unused_shader_inputs_and_outputs(bool is_separate_shader_object
,
299 enum ir_variable_mode mode
);
302 store_tfeedback_info(struct gl_context
*ctx
, struct gl_shader_program
*prog
,
303 unsigned num_tfeedback_decls
,
304 tfeedback_decl
*tfeedback_decls
,
305 bool has_xfb_qualifiers
);
308 assign_varying_locations(struct gl_context
*ctx
,
310 struct gl_shader_program
*prog
,
311 gl_shader
*producer
, gl_shader
*consumer
,
312 unsigned num_tfeedback_decls
,
313 tfeedback_decl
*tfeedback_decls
);
316 check_against_output_limit(struct gl_context
*ctx
,
317 struct gl_shader_program
*prog
,
318 gl_shader
*producer
);
321 check_against_input_limit(struct gl_context
*ctx
,
322 struct gl_shader_program
*prog
,
323 gl_shader
*consumer
);
325 #endif /* GLSL_LINK_VARYINGS_H */