2 * Copyright © 2010 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.
26 * Building this file with MinGW g++ 7.3 or 7.4 with:
27 * scons platform=windows toolchain=crossmingw machine=x86 build=profile
28 * triggers an internal compiler error.
29 * Overriding the optimization level to -O1 works around the issue.
30 * MinGW 5.3.1 does not seem to have the bug, neither does 8.3. So for now
31 * we're simply testing for version 7.x here.
33 #if defined(__MINGW32__) && __GNUC__ == 7
34 #warning "disabling optimizations for this file to work around compiler bug in MinGW gcc 7.x"
35 #pragma GCC optimize("O1")
40 #include "ir_builder.h"
42 #include "glsl_parser_extras.h"
43 #include "glsl_symbol_table.h"
44 #include "main/mtypes.h"
45 #include "main/uniforms.h"
46 #include "program/prog_statevars.h"
47 #include "program/prog_instruction.h"
48 #include "builtin_functions.h"
50 using namespace ir_builder
;
52 static const struct gl_builtin_uniform_element gl_NumSamples_elements
[] = {
53 {NULL
, {STATE_NUM_SAMPLES
, 0, 0}, SWIZZLE_XXXX
}
56 static const struct gl_builtin_uniform_element gl_DepthRange_elements
[] = {
57 {"near", {STATE_DEPTH_RANGE
, 0, 0}, SWIZZLE_XXXX
},
58 {"far", {STATE_DEPTH_RANGE
, 0, 0}, SWIZZLE_YYYY
},
59 {"diff", {STATE_DEPTH_RANGE
, 0, 0}, SWIZZLE_ZZZZ
},
62 static const struct gl_builtin_uniform_element gl_ClipPlane_elements
[] = {
63 {NULL
, {STATE_CLIPPLANE
, 0, 0}, SWIZZLE_XYZW
}
66 static const struct gl_builtin_uniform_element gl_Point_elements
[] = {
67 {"size", {STATE_POINT_SIZE
}, SWIZZLE_XXXX
},
68 {"sizeMin", {STATE_POINT_SIZE
}, SWIZZLE_YYYY
},
69 {"sizeMax", {STATE_POINT_SIZE
}, SWIZZLE_ZZZZ
},
70 {"fadeThresholdSize", {STATE_POINT_SIZE
}, SWIZZLE_WWWW
},
71 {"distanceConstantAttenuation", {STATE_POINT_ATTENUATION
}, SWIZZLE_XXXX
},
72 {"distanceLinearAttenuation", {STATE_POINT_ATTENUATION
}, SWIZZLE_YYYY
},
73 {"distanceQuadraticAttenuation", {STATE_POINT_ATTENUATION
}, SWIZZLE_ZZZZ
},
76 static const struct gl_builtin_uniform_element gl_FrontMaterial_elements
[] = {
77 {"emission", {STATE_MATERIAL
, 0, STATE_EMISSION
}, SWIZZLE_XYZW
},
78 {"ambient", {STATE_MATERIAL
, 0, STATE_AMBIENT
}, SWIZZLE_XYZW
},
79 {"diffuse", {STATE_MATERIAL
, 0, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
80 {"specular", {STATE_MATERIAL
, 0, STATE_SPECULAR
}, SWIZZLE_XYZW
},
81 {"shininess", {STATE_MATERIAL
, 0, STATE_SHININESS
}, SWIZZLE_XXXX
},
84 static const struct gl_builtin_uniform_element gl_BackMaterial_elements
[] = {
85 {"emission", {STATE_MATERIAL
, 1, STATE_EMISSION
}, SWIZZLE_XYZW
},
86 {"ambient", {STATE_MATERIAL
, 1, STATE_AMBIENT
}, SWIZZLE_XYZW
},
87 {"diffuse", {STATE_MATERIAL
, 1, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
88 {"specular", {STATE_MATERIAL
, 1, STATE_SPECULAR
}, SWIZZLE_XYZW
},
89 {"shininess", {STATE_MATERIAL
, 1, STATE_SHININESS
}, SWIZZLE_XXXX
},
92 static const struct gl_builtin_uniform_element gl_LightSource_elements
[] = {
93 {"ambient", {STATE_LIGHT
, 0, STATE_AMBIENT
}, SWIZZLE_XYZW
},
94 {"diffuse", {STATE_LIGHT
, 0, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
95 {"specular", {STATE_LIGHT
, 0, STATE_SPECULAR
}, SWIZZLE_XYZW
},
96 {"position", {STATE_LIGHT
, 0, STATE_POSITION
}, SWIZZLE_XYZW
},
97 {"halfVector", {STATE_LIGHT
, 0, STATE_HALF_VECTOR
}, SWIZZLE_XYZW
},
98 {"spotDirection", {STATE_LIGHT
, 0, STATE_SPOT_DIRECTION
},
99 MAKE_SWIZZLE4(SWIZZLE_X
,
103 {"spotCosCutoff", {STATE_LIGHT
, 0, STATE_SPOT_DIRECTION
}, SWIZZLE_WWWW
},
104 {"constantAttenuation", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_XXXX
},
105 {"linearAttenuation", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_YYYY
},
106 {"quadraticAttenuation", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_ZZZZ
},
107 {"spotExponent", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_WWWW
},
108 {"spotCutoff", {STATE_LIGHT
, 0, STATE_SPOT_CUTOFF
}, SWIZZLE_XXXX
},
111 static const struct gl_builtin_uniform_element gl_LightModel_elements
[] = {
112 {"ambient", {STATE_LIGHTMODEL_AMBIENT
, 0}, SWIZZLE_XYZW
},
115 static const struct gl_builtin_uniform_element gl_FrontLightModelProduct_elements
[] = {
116 {"sceneColor", {STATE_LIGHTMODEL_SCENECOLOR
, 0}, SWIZZLE_XYZW
},
119 static const struct gl_builtin_uniform_element gl_BackLightModelProduct_elements
[] = {
120 {"sceneColor", {STATE_LIGHTMODEL_SCENECOLOR
, 1}, SWIZZLE_XYZW
},
123 static const struct gl_builtin_uniform_element gl_FrontLightProduct_elements
[] = {
124 {"ambient", {STATE_LIGHTPROD
, 0, 0, STATE_AMBIENT
}, SWIZZLE_XYZW
},
125 {"diffuse", {STATE_LIGHTPROD
, 0, 0, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
126 {"specular", {STATE_LIGHTPROD
, 0, 0, STATE_SPECULAR
}, SWIZZLE_XYZW
},
129 static const struct gl_builtin_uniform_element gl_BackLightProduct_elements
[] = {
130 {"ambient", {STATE_LIGHTPROD
, 0, 1, STATE_AMBIENT
}, SWIZZLE_XYZW
},
131 {"diffuse", {STATE_LIGHTPROD
, 0, 1, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
132 {"specular", {STATE_LIGHTPROD
, 0, 1, STATE_SPECULAR
}, SWIZZLE_XYZW
},
135 static const struct gl_builtin_uniform_element gl_TextureEnvColor_elements
[] = {
136 {NULL
, {STATE_TEXENV_COLOR
, 0}, SWIZZLE_XYZW
},
139 static const struct gl_builtin_uniform_element gl_EyePlaneS_elements
[] = {
140 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_S
}, SWIZZLE_XYZW
},
143 static const struct gl_builtin_uniform_element gl_EyePlaneT_elements
[] = {
144 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_T
}, SWIZZLE_XYZW
},
147 static const struct gl_builtin_uniform_element gl_EyePlaneR_elements
[] = {
148 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_R
}, SWIZZLE_XYZW
},
151 static const struct gl_builtin_uniform_element gl_EyePlaneQ_elements
[] = {
152 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_Q
}, SWIZZLE_XYZW
},
155 static const struct gl_builtin_uniform_element gl_ObjectPlaneS_elements
[] = {
156 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_S
}, SWIZZLE_XYZW
},
159 static const struct gl_builtin_uniform_element gl_ObjectPlaneT_elements
[] = {
160 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_T
}, SWIZZLE_XYZW
},
163 static const struct gl_builtin_uniform_element gl_ObjectPlaneR_elements
[] = {
164 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_R
}, SWIZZLE_XYZW
},
167 static const struct gl_builtin_uniform_element gl_ObjectPlaneQ_elements
[] = {
168 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_Q
}, SWIZZLE_XYZW
},
171 static const struct gl_builtin_uniform_element gl_Fog_elements
[] = {
172 {"color", {STATE_FOG_COLOR
}, SWIZZLE_XYZW
},
173 {"density", {STATE_FOG_PARAMS
}, SWIZZLE_XXXX
},
174 {"start", {STATE_FOG_PARAMS
}, SWIZZLE_YYYY
},
175 {"end", {STATE_FOG_PARAMS
}, SWIZZLE_ZZZZ
},
176 {"scale", {STATE_FOG_PARAMS
}, SWIZZLE_WWWW
},
179 static const struct gl_builtin_uniform_element gl_NormalScale_elements
[] = {
180 {NULL
, {STATE_NORMAL_SCALE
}, SWIZZLE_XXXX
},
183 static const struct gl_builtin_uniform_element gl_FogParamsOptimizedMESA_elements
[] = {
184 {NULL
, {STATE_INTERNAL
, STATE_FOG_PARAMS_OPTIMIZED
}, SWIZZLE_XYZW
},
187 static const struct gl_builtin_uniform_element gl_CurrentAttribVertMESA_elements
[] = {
188 {NULL
, {STATE_INTERNAL
, STATE_CURRENT_ATTRIB
, 0}, SWIZZLE_XYZW
},
191 static const struct gl_builtin_uniform_element gl_CurrentAttribFragMESA_elements
[] = {
192 {NULL
, {STATE_INTERNAL
, STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED
, 0}, SWIZZLE_XYZW
},
195 #define MATRIX(name, statevar, modifier) \
196 static const struct gl_builtin_uniform_element name ## _elements[] = { \
197 { NULL, { statevar, 0, 0, 0, modifier}, SWIZZLE_XYZW }, \
198 { NULL, { statevar, 0, 1, 1, modifier}, SWIZZLE_XYZW }, \
199 { NULL, { statevar, 0, 2, 2, modifier}, SWIZZLE_XYZW }, \
200 { NULL, { statevar, 0, 3, 3, modifier}, SWIZZLE_XYZW }, \
203 MATRIX(gl_ModelViewMatrix
,
204 STATE_MODELVIEW_MATRIX
, STATE_MATRIX_TRANSPOSE
);
205 MATRIX(gl_ModelViewMatrixInverse
,
206 STATE_MODELVIEW_MATRIX
, STATE_MATRIX_INVTRANS
);
207 MATRIX(gl_ModelViewMatrixTranspose
,
208 STATE_MODELVIEW_MATRIX
, 0);
209 MATRIX(gl_ModelViewMatrixInverseTranspose
,
210 STATE_MODELVIEW_MATRIX
, STATE_MATRIX_INVERSE
);
212 MATRIX(gl_ProjectionMatrix
,
213 STATE_PROJECTION_MATRIX
, STATE_MATRIX_TRANSPOSE
);
214 MATRIX(gl_ProjectionMatrixInverse
,
215 STATE_PROJECTION_MATRIX
, STATE_MATRIX_INVTRANS
);
216 MATRIX(gl_ProjectionMatrixTranspose
,
217 STATE_PROJECTION_MATRIX
, 0);
218 MATRIX(gl_ProjectionMatrixInverseTranspose
,
219 STATE_PROJECTION_MATRIX
, STATE_MATRIX_INVERSE
);
221 MATRIX(gl_ModelViewProjectionMatrix
,
222 STATE_MVP_MATRIX
, STATE_MATRIX_TRANSPOSE
);
223 MATRIX(gl_ModelViewProjectionMatrixInverse
,
224 STATE_MVP_MATRIX
, STATE_MATRIX_INVTRANS
);
225 MATRIX(gl_ModelViewProjectionMatrixTranspose
,
226 STATE_MVP_MATRIX
, 0);
227 MATRIX(gl_ModelViewProjectionMatrixInverseTranspose
,
228 STATE_MVP_MATRIX
, STATE_MATRIX_INVERSE
);
230 MATRIX(gl_TextureMatrix
,
231 STATE_TEXTURE_MATRIX
, STATE_MATRIX_TRANSPOSE
);
232 MATRIX(gl_TextureMatrixInverse
,
233 STATE_TEXTURE_MATRIX
, STATE_MATRIX_INVTRANS
);
234 MATRIX(gl_TextureMatrixTranspose
,
235 STATE_TEXTURE_MATRIX
, 0);
236 MATRIX(gl_TextureMatrixInverseTranspose
,
237 STATE_TEXTURE_MATRIX
, STATE_MATRIX_INVERSE
);
239 static const struct gl_builtin_uniform_element gl_NormalMatrix_elements
[] = {
240 { NULL
, { STATE_MODELVIEW_MATRIX
, 0, 0, 0, STATE_MATRIX_INVERSE
},
241 MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_Z
) },
242 { NULL
, { STATE_MODELVIEW_MATRIX
, 0, 1, 1, STATE_MATRIX_INVERSE
},
243 MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_Z
) },
244 { NULL
, { STATE_MODELVIEW_MATRIX
, 0, 2, 2, STATE_MATRIX_INVERSE
},
245 MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_Z
) },
250 #define STATEVAR(name) {#name, name ## _elements, ARRAY_SIZE(name ## _elements)}
252 static const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc
[] = {
253 STATEVAR(gl_NumSamples
),
254 STATEVAR(gl_DepthRange
),
255 STATEVAR(gl_ClipPlane
),
257 STATEVAR(gl_FrontMaterial
),
258 STATEVAR(gl_BackMaterial
),
259 STATEVAR(gl_LightSource
),
260 STATEVAR(gl_LightModel
),
261 STATEVAR(gl_FrontLightModelProduct
),
262 STATEVAR(gl_BackLightModelProduct
),
263 STATEVAR(gl_FrontLightProduct
),
264 STATEVAR(gl_BackLightProduct
),
265 STATEVAR(gl_TextureEnvColor
),
266 STATEVAR(gl_EyePlaneS
),
267 STATEVAR(gl_EyePlaneT
),
268 STATEVAR(gl_EyePlaneR
),
269 STATEVAR(gl_EyePlaneQ
),
270 STATEVAR(gl_ObjectPlaneS
),
271 STATEVAR(gl_ObjectPlaneT
),
272 STATEVAR(gl_ObjectPlaneR
),
273 STATEVAR(gl_ObjectPlaneQ
),
276 STATEVAR(gl_ModelViewMatrix
),
277 STATEVAR(gl_ModelViewMatrixInverse
),
278 STATEVAR(gl_ModelViewMatrixTranspose
),
279 STATEVAR(gl_ModelViewMatrixInverseTranspose
),
281 STATEVAR(gl_ProjectionMatrix
),
282 STATEVAR(gl_ProjectionMatrixInverse
),
283 STATEVAR(gl_ProjectionMatrixTranspose
),
284 STATEVAR(gl_ProjectionMatrixInverseTranspose
),
286 STATEVAR(gl_ModelViewProjectionMatrix
),
287 STATEVAR(gl_ModelViewProjectionMatrixInverse
),
288 STATEVAR(gl_ModelViewProjectionMatrixTranspose
),
289 STATEVAR(gl_ModelViewProjectionMatrixInverseTranspose
),
291 STATEVAR(gl_TextureMatrix
),
292 STATEVAR(gl_TextureMatrixInverse
),
293 STATEVAR(gl_TextureMatrixTranspose
),
294 STATEVAR(gl_TextureMatrixInverseTranspose
),
296 STATEVAR(gl_NormalMatrix
),
297 STATEVAR(gl_NormalScale
),
299 STATEVAR(gl_FogParamsOptimizedMESA
),
300 STATEVAR(gl_CurrentAttribVertMESA
),
301 STATEVAR(gl_CurrentAttribFragMESA
),
310 * Data structure that accumulates fields for the gl_PerVertex interface
313 class per_vertex_accumulator
316 per_vertex_accumulator();
317 void add_field(int slot
, const glsl_type
*type
, int precision
,
318 const char *name
, enum glsl_interp_mode interp
);
319 const glsl_type
*construct_interface_instance() const;
322 glsl_struct_field fields
[11];
327 per_vertex_accumulator::per_vertex_accumulator()
335 per_vertex_accumulator::add_field(int slot
, const glsl_type
*type
,
336 int precision
, const char *name
,
337 enum glsl_interp_mode interp
)
339 assert(this->num_fields
< ARRAY_SIZE(this->fields
));
340 this->fields
[this->num_fields
].type
= type
;
341 this->fields
[this->num_fields
].name
= name
;
342 this->fields
[this->num_fields
].matrix_layout
= GLSL_MATRIX_LAYOUT_INHERITED
;
343 this->fields
[this->num_fields
].location
= slot
;
344 this->fields
[this->num_fields
].offset
= -1;
345 this->fields
[this->num_fields
].interpolation
= interp
;
346 this->fields
[this->num_fields
].centroid
= 0;
347 this->fields
[this->num_fields
].sample
= 0;
348 this->fields
[this->num_fields
].patch
= 0;
349 this->fields
[this->num_fields
].precision
= precision
;
350 this->fields
[this->num_fields
].memory_read_only
= 0;
351 this->fields
[this->num_fields
].memory_write_only
= 0;
352 this->fields
[this->num_fields
].memory_coherent
= 0;
353 this->fields
[this->num_fields
].memory_volatile
= 0;
354 this->fields
[this->num_fields
].memory_restrict
= 0;
355 this->fields
[this->num_fields
].image_format
= PIPE_FORMAT_NONE
;
356 this->fields
[this->num_fields
].explicit_xfb_buffer
= 0;
357 this->fields
[this->num_fields
].xfb_buffer
= -1;
358 this->fields
[this->num_fields
].xfb_stride
= -1;
364 per_vertex_accumulator::construct_interface_instance() const
366 return glsl_type::get_interface_instance(this->fields
, this->num_fields
,
367 GLSL_INTERFACE_PACKING_STD140
,
373 class builtin_variable_generator
376 builtin_variable_generator(exec_list
*instructions
,
377 struct _mesa_glsl_parse_state
*state
);
378 void generate_constants();
379 void generate_uniforms();
380 void generate_special_vars();
381 void generate_vs_special_vars();
382 void generate_tcs_special_vars();
383 void generate_tes_special_vars();
384 void generate_gs_special_vars();
385 void generate_fs_special_vars();
386 void generate_cs_special_vars();
387 void generate_varyings();
390 const glsl_type
*array(const glsl_type
*base
, unsigned elements
)
392 return glsl_type::get_array_instance(base
, elements
);
395 const glsl_type
*type(const char *name
)
397 return symtab
->get_type(name
);
400 ir_variable
*add_input(int slot
, const glsl_type
*type
, int precision
,
402 enum glsl_interp_mode interp
= INTERP_MODE_NONE
)
404 return add_variable(name
, type
, precision
, ir_var_shader_in
, slot
, interp
);
407 ir_variable
*add_input(int slot
, const glsl_type
*type
, const char *name
,
408 enum glsl_interp_mode interp
= INTERP_MODE_NONE
)
410 return add_input(slot
, type
, GLSL_PRECISION_NONE
, name
, interp
);
413 ir_variable
*add_output(int slot
, const glsl_type
*type
, int precision
,
416 return add_variable(name
, type
, precision
, ir_var_shader_out
, slot
);
419 ir_variable
*add_output(int slot
, const glsl_type
*type
, const char *name
)
421 return add_output(slot
, type
, GLSL_PRECISION_NONE
, name
);
424 ir_variable
*add_index_output(int slot
, int index
, const glsl_type
*type
,
425 int precision
, const char *name
)
427 return add_index_variable(name
, type
, precision
, ir_var_shader_out
, slot
,
431 ir_variable
*add_system_value(int slot
, const glsl_type
*type
, int precision
,
434 return add_variable(name
, type
, precision
, ir_var_system_value
, slot
);
436 ir_variable
*add_system_value(int slot
, const glsl_type
*type
,
439 return add_system_value(slot
, type
, GLSL_PRECISION_NONE
, name
);
442 ir_variable
*add_variable(const char *name
, const glsl_type
*type
,
443 int precision
, enum ir_variable_mode mode
,
444 int slot
, enum glsl_interp_mode interp
= INTERP_MODE_NONE
);
445 ir_variable
*add_index_variable(const char *name
, const glsl_type
*type
,
446 int precision
, enum ir_variable_mode mode
,
447 int slot
, int index
);
448 ir_variable
*add_uniform(const glsl_type
*type
, int precision
,
450 ir_variable
*add_uniform(const glsl_type
*type
, const char *name
)
452 return add_uniform(type
, GLSL_PRECISION_NONE
, name
);
454 ir_variable
*add_const(const char *name
, int precision
, int value
);
455 ir_variable
*add_const(const char *name
, int value
)
457 return add_const(name
, GLSL_PRECISION_MEDIUM
, value
);
459 ir_variable
*add_const_ivec3(const char *name
, int x
, int y
, int z
);
460 void add_varying(int slot
, const glsl_type
*type
, int precision
,
462 enum glsl_interp_mode interp
= INTERP_MODE_NONE
);
463 void add_varying(int slot
, const glsl_type
*type
, const char *name
,
464 enum glsl_interp_mode interp
= INTERP_MODE_NONE
)
466 add_varying(slot
, type
, GLSL_PRECISION_NONE
, name
, interp
);
469 exec_list
* const instructions
;
470 struct _mesa_glsl_parse_state
* const state
;
471 glsl_symbol_table
* const symtab
;
474 * True if compatibility-profile-only variables should be included. (In
475 * desktop GL, these are always included when the GLSL version is 1.30 and
478 const bool compatibility
;
480 const glsl_type
* const bool_t
;
481 const glsl_type
* const int_t
;
482 const glsl_type
* const uint_t
;
483 const glsl_type
* const uint64_t;
484 const glsl_type
* const float_t
;
485 const glsl_type
* const vec2_t
;
486 const glsl_type
* const vec3_t
;
487 const glsl_type
* const vec4_t
;
488 const glsl_type
* const uvec3_t
;
489 const glsl_type
* const mat3_t
;
490 const glsl_type
* const mat4_t
;
492 per_vertex_accumulator per_vertex_in
;
493 per_vertex_accumulator per_vertex_out
;
497 builtin_variable_generator::builtin_variable_generator(
498 exec_list
*instructions
, struct _mesa_glsl_parse_state
*state
)
499 : instructions(instructions
), state(state
), symtab(state
->symbols
),
500 compatibility(state
->compat_shader
|| state
->ARB_compatibility_enable
),
501 bool_t(glsl_type::bool_type
), int_t(glsl_type::int_type
),
502 uint_t(glsl_type::uint_type
),
503 uint64_t(glsl_type::uint64_t_type
),
504 float_t(glsl_type::float_type
), vec2_t(glsl_type::vec2_type
),
505 vec3_t(glsl_type::vec3_type
), vec4_t(glsl_type::vec4_type
),
506 uvec3_t(glsl_type::uvec3_type
),
507 mat3_t(glsl_type::mat3_type
), mat4_t(glsl_type::mat4_type
)
512 builtin_variable_generator::add_index_variable(const char *name
,
513 const glsl_type
*type
,
515 enum ir_variable_mode mode
,
518 ir_variable
*var
= new(symtab
) ir_variable(type
, name
, mode
);
519 var
->data
.how_declared
= ir_var_declared_implicitly
;
521 switch (var
->data
.mode
) {
523 case ir_var_shader_in
:
525 case ir_var_system_value
:
526 var
->data
.read_only
= true;
528 case ir_var_shader_out
:
529 case ir_var_shader_storage
:
532 /* The only variables that are added using this function should be
533 * uniforms, shader storage, shader inputs, and shader outputs, constants
534 * (which use ir_var_auto), and system values.
540 var
->data
.location
= slot
;
541 var
->data
.explicit_location
= (slot
>= 0);
542 var
->data
.explicit_index
= 1;
543 var
->data
.index
= index
;
545 if (state
->es_shader
)
546 var
->data
.precision
= precision
;
548 /* Once the variable is created an initialized, add it to the symbol table
549 * and add the declaration to the IR stream.
551 instructions
->push_tail(var
);
553 symtab
->add_variable(var
);
558 builtin_variable_generator::add_variable(const char *name
,
559 const glsl_type
*type
,
561 enum ir_variable_mode mode
, int slot
,
562 enum glsl_interp_mode interp
)
564 ir_variable
*var
= new(symtab
) ir_variable(type
, name
, mode
);
565 var
->data
.how_declared
= ir_var_declared_implicitly
;
567 switch (var
->data
.mode
) {
569 case ir_var_shader_in
:
571 case ir_var_system_value
:
572 var
->data
.read_only
= true;
574 case ir_var_shader_out
:
575 case ir_var_shader_storage
:
578 /* The only variables that are added using this function should be
579 * uniforms, shader storage, shader inputs, and shader outputs, constants
580 * (which use ir_var_auto), and system values.
586 var
->data
.location
= slot
;
587 var
->data
.explicit_location
= (slot
>= 0);
588 var
->data
.explicit_index
= 0;
589 var
->data
.interpolation
= interp
;
591 if (state
->es_shader
)
592 var
->data
.precision
= precision
;
594 /* Once the variable is created an initialized, add it to the symbol table
595 * and add the declaration to the IR stream.
597 instructions
->push_tail(var
);
599 symtab
->add_variable(var
);
603 extern "C" const struct gl_builtin_uniform_desc
*
604 _mesa_glsl_get_builtin_uniform_desc(const char *name
)
606 for (unsigned i
= 0; _mesa_builtin_uniform_desc
[i
].name
!= NULL
; i
++) {
607 if (strcmp(_mesa_builtin_uniform_desc
[i
].name
, name
) == 0) {
608 return &_mesa_builtin_uniform_desc
[i
];
615 builtin_variable_generator::add_uniform(const glsl_type
*type
,
619 ir_variable
*const uni
=
620 add_variable(name
, type
, precision
, ir_var_uniform
, -1);
622 const struct gl_builtin_uniform_desc
* const statevar
=
623 _mesa_glsl_get_builtin_uniform_desc(name
);
624 assert(statevar
!= NULL
);
626 const unsigned array_count
= type
->is_array() ? type
->length
: 1;
628 ir_state_slot
*slots
=
629 uni
->allocate_state_slots(array_count
* statevar
->num_elements
);
631 for (unsigned a
= 0; a
< array_count
; a
++) {
632 for (unsigned j
= 0; j
< statevar
->num_elements
; j
++) {
633 const struct gl_builtin_uniform_element
*element
=
634 &statevar
->elements
[j
];
636 memcpy(slots
->tokens
, element
->tokens
, sizeof(element
->tokens
));
637 if (type
->is_array()) {
638 if (strcmp(name
, "gl_CurrentAttribVertMESA") == 0 ||
639 strcmp(name
, "gl_CurrentAttribFragMESA") == 0) {
640 slots
->tokens
[2] = a
;
642 slots
->tokens
[1] = a
;
646 slots
->swizzle
= element
->swizzle
;
656 builtin_variable_generator::add_const(const char *name
, int precision
,
659 ir_variable
*const var
= add_variable(name
, glsl_type::int_type
,
660 precision
, ir_var_auto
, -1);
661 var
->constant_value
= new(var
) ir_constant(value
);
662 var
->constant_initializer
= new(var
) ir_constant(value
);
663 var
->data
.has_initializer
= true;
669 builtin_variable_generator::add_const_ivec3(const char *name
, int x
, int y
,
672 ir_variable
*const var
= add_variable(name
, glsl_type::ivec3_type
,
675 ir_constant_data data
;
676 memset(&data
, 0, sizeof(data
));
680 var
->constant_value
= new(var
) ir_constant(glsl_type::ivec3_type
, &data
);
681 var
->constant_initializer
=
682 new(var
) ir_constant(glsl_type::ivec3_type
, &data
);
683 var
->data
.has_initializer
= true;
689 builtin_variable_generator::generate_constants()
691 add_const("gl_MaxVertexAttribs", state
->Const
.MaxVertexAttribs
);
692 add_const("gl_MaxVertexTextureImageUnits",
693 state
->Const
.MaxVertexTextureImageUnits
);
694 add_const("gl_MaxCombinedTextureImageUnits",
695 state
->Const
.MaxCombinedTextureImageUnits
);
696 add_const("gl_MaxTextureImageUnits", state
->Const
.MaxTextureImageUnits
);
697 add_const("gl_MaxDrawBuffers", state
->Const
.MaxDrawBuffers
);
699 /* Max uniforms/varyings: GLSL ES counts these in units of vectors; desktop
700 * GL counts them in units of "components" or "floats" and also in units
701 * of vectors since GL 4.1
703 if (!state
->es_shader
) {
704 add_const("gl_MaxFragmentUniformComponents",
705 state
->Const
.MaxFragmentUniformComponents
);
706 add_const("gl_MaxVertexUniformComponents",
707 state
->Const
.MaxVertexUniformComponents
);
710 if (state
->is_version(410, 100)) {
711 add_const("gl_MaxVertexUniformVectors",
712 state
->Const
.MaxVertexUniformComponents
/ 4);
713 add_const("gl_MaxFragmentUniformVectors",
714 state
->Const
.MaxFragmentUniformComponents
/ 4);
716 /* In GLSL ES 3.00, gl_MaxVaryingVectors was split out to separate
717 * vertex and fragment shader constants.
719 if (state
->is_version(0, 300)) {
720 add_const("gl_MaxVertexOutputVectors",
721 state
->ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
/ 4);
722 add_const("gl_MaxFragmentInputVectors",
723 state
->ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
/ 4);
725 add_const("gl_MaxVaryingVectors",
726 state
->ctx
->Const
.MaxVarying
);
729 /* EXT_blend_func_extended brings a built in constant
730 * for determining number of dual source draw buffers
732 if (state
->EXT_blend_func_extended_enable
) {
733 add_const("gl_MaxDualSourceDrawBuffersEXT",
734 state
->Const
.MaxDualSourceDrawBuffers
);
737 /* Note: gl_MaxVaryingFloats was deprecated in GLSL 1.30+, but not
740 add_const("gl_MaxVaryingFloats", state
->ctx
->Const
.MaxVarying
* 4);
743 /* Texel offsets were introduced in ARB_shading_language_420pack (which
744 * requires desktop GLSL version 130), and adopted into desktop GLSL
745 * version 4.20 and GLSL ES version 3.00.
747 if ((state
->is_version(130, 0) &&
748 state
->ARB_shading_language_420pack_enable
) ||
749 state
->is_version(420, 300)) {
750 add_const("gl_MinProgramTexelOffset",
751 state
->Const
.MinProgramTexelOffset
);
752 add_const("gl_MaxProgramTexelOffset",
753 state
->Const
.MaxProgramTexelOffset
);
756 if (state
->has_clip_distance()) {
757 add_const("gl_MaxClipDistances", state
->Const
.MaxClipPlanes
);
759 if (state
->is_version(130, 0)) {
760 add_const("gl_MaxVaryingComponents", state
->ctx
->Const
.MaxVarying
* 4);
762 if (state
->has_cull_distance()) {
763 add_const("gl_MaxCullDistances", state
->Const
.MaxClipPlanes
);
764 add_const("gl_MaxCombinedClipAndCullDistances",
765 state
->Const
.MaxClipPlanes
);
768 if (state
->has_geometry_shader()) {
769 add_const("gl_MaxVertexOutputComponents",
770 state
->Const
.MaxVertexOutputComponents
);
771 add_const("gl_MaxGeometryInputComponents",
772 state
->Const
.MaxGeometryInputComponents
);
773 add_const("gl_MaxGeometryOutputComponents",
774 state
->Const
.MaxGeometryOutputComponents
);
775 add_const("gl_MaxFragmentInputComponents",
776 state
->Const
.MaxFragmentInputComponents
);
777 add_const("gl_MaxGeometryTextureImageUnits",
778 state
->Const
.MaxGeometryTextureImageUnits
);
779 add_const("gl_MaxGeometryOutputVertices",
780 state
->Const
.MaxGeometryOutputVertices
);
781 add_const("gl_MaxGeometryTotalOutputComponents",
782 state
->Const
.MaxGeometryTotalOutputComponents
);
783 add_const("gl_MaxGeometryUniformComponents",
784 state
->Const
.MaxGeometryUniformComponents
);
786 /* Note: the GLSL 1.50-4.40 specs require
787 * gl_MaxGeometryVaryingComponents to be present, and to be at least 64.
788 * But they do not define what it means (and there does not appear to be
789 * any corresponding constant in the GL specs). However,
790 * ARB_geometry_shader4 defines MAX_GEOMETRY_VARYING_COMPONENTS_ARB to
791 * be the maximum number of components available for use as geometry
792 * outputs. So we assume this is a synonym for
793 * gl_MaxGeometryOutputComponents.
795 add_const("gl_MaxGeometryVaryingComponents",
796 state
->Const
.MaxGeometryOutputComponents
);
800 /* Note: gl_MaxLights stopped being listed as an explicit constant in
801 * GLSL 1.30, however it continues to be referred to (as a minimum size
802 * for compatibility-mode uniforms) all the way up through GLSL 4.30, so
803 * this seems like it was probably an oversight.
805 add_const("gl_MaxLights", state
->Const
.MaxLights
);
807 add_const("gl_MaxClipPlanes", state
->Const
.MaxClipPlanes
);
809 /* Note: gl_MaxTextureUnits wasn't made compatibility-only until GLSL
810 * 1.50, however this seems like it was probably an oversight.
812 add_const("gl_MaxTextureUnits", state
->Const
.MaxTextureUnits
);
814 /* Note: gl_MaxTextureCoords was left out of GLSL 1.40, but it was
815 * re-introduced in GLSL 1.50, so this seems like it was probably an
818 add_const("gl_MaxTextureCoords", state
->Const
.MaxTextureCoords
);
821 if (state
->has_atomic_counters()) {
822 add_const("gl_MaxVertexAtomicCounters",
823 state
->Const
.MaxVertexAtomicCounters
);
824 add_const("gl_MaxFragmentAtomicCounters",
825 state
->Const
.MaxFragmentAtomicCounters
);
826 add_const("gl_MaxCombinedAtomicCounters",
827 state
->Const
.MaxCombinedAtomicCounters
);
828 add_const("gl_MaxAtomicCounterBindings",
829 state
->Const
.MaxAtomicBufferBindings
);
831 if (state
->has_geometry_shader()) {
832 add_const("gl_MaxGeometryAtomicCounters",
833 state
->Const
.MaxGeometryAtomicCounters
);
835 if (state
->is_version(110, 320)) {
836 add_const("gl_MaxTessControlAtomicCounters",
837 state
->Const
.MaxTessControlAtomicCounters
);
838 add_const("gl_MaxTessEvaluationAtomicCounters",
839 state
->Const
.MaxTessEvaluationAtomicCounters
);
843 if (state
->is_version(420, 310)) {
844 add_const("gl_MaxVertexAtomicCounterBuffers",
845 state
->Const
.MaxVertexAtomicCounterBuffers
);
846 add_const("gl_MaxFragmentAtomicCounterBuffers",
847 state
->Const
.MaxFragmentAtomicCounterBuffers
);
848 add_const("gl_MaxCombinedAtomicCounterBuffers",
849 state
->Const
.MaxCombinedAtomicCounterBuffers
);
850 add_const("gl_MaxAtomicCounterBufferSize",
851 state
->Const
.MaxAtomicCounterBufferSize
);
853 if (state
->has_geometry_shader()) {
854 add_const("gl_MaxGeometryAtomicCounterBuffers",
855 state
->Const
.MaxGeometryAtomicCounterBuffers
);
857 if (state
->is_version(110, 320)) {
858 add_const("gl_MaxTessControlAtomicCounterBuffers",
859 state
->Const
.MaxTessControlAtomicCounterBuffers
);
860 add_const("gl_MaxTessEvaluationAtomicCounterBuffers",
861 state
->Const
.MaxTessEvaluationAtomicCounterBuffers
);
865 if (state
->is_version(430, 310) || state
->ARB_compute_shader_enable
) {
866 add_const("gl_MaxComputeAtomicCounterBuffers",
867 state
->Const
.MaxComputeAtomicCounterBuffers
);
868 add_const("gl_MaxComputeAtomicCounters",
869 state
->Const
.MaxComputeAtomicCounters
);
870 add_const("gl_MaxComputeImageUniforms",
871 state
->Const
.MaxComputeImageUniforms
);
872 add_const("gl_MaxComputeTextureImageUnits",
873 state
->Const
.MaxComputeTextureImageUnits
);
874 add_const("gl_MaxComputeUniformComponents",
875 state
->Const
.MaxComputeUniformComponents
);
877 add_const_ivec3("gl_MaxComputeWorkGroupCount",
878 state
->Const
.MaxComputeWorkGroupCount
[0],
879 state
->Const
.MaxComputeWorkGroupCount
[1],
880 state
->Const
.MaxComputeWorkGroupCount
[2]);
881 add_const_ivec3("gl_MaxComputeWorkGroupSize",
882 state
->Const
.MaxComputeWorkGroupSize
[0],
883 state
->Const
.MaxComputeWorkGroupSize
[1],
884 state
->Const
.MaxComputeWorkGroupSize
[2]);
886 /* From the GLSL 4.40 spec, section 7.1 (Built-In Language Variables):
888 * The built-in constant gl_WorkGroupSize is a compute-shader
889 * constant containing the local work-group size of the shader. The
890 * size of the work group in the X, Y, and Z dimensions is stored in
891 * the x, y, and z components. The constants values in
892 * gl_WorkGroupSize will match those specified in the required
893 * local_size_x, local_size_y, and local_size_z layout qualifiers
894 * for the current shader. This is a constant so that it can be
895 * used to size arrays of memory that can be shared within the local
896 * work group. It is a compile-time error to use gl_WorkGroupSize
897 * in a shader that does not declare a fixed local group size, or
898 * before that shader has declared a fixed local group size, using
899 * local_size_x, local_size_y, and local_size_z.
901 * To prevent the shader from trying to refer to gl_WorkGroupSize before
902 * the layout declaration, we don't define it here. Intead we define it
903 * in ast_cs_input_layout::hir().
907 if (state
->has_enhanced_layouts()) {
908 add_const("gl_MaxTransformFeedbackBuffers",
909 state
->Const
.MaxTransformFeedbackBuffers
);
910 add_const("gl_MaxTransformFeedbackInterleavedComponents",
911 state
->Const
.MaxTransformFeedbackInterleavedComponents
);
914 if (state
->has_shader_image_load_store()) {
915 add_const("gl_MaxImageUnits",
916 state
->Const
.MaxImageUnits
);
917 add_const("gl_MaxVertexImageUniforms",
918 state
->Const
.MaxVertexImageUniforms
);
919 add_const("gl_MaxFragmentImageUniforms",
920 state
->Const
.MaxFragmentImageUniforms
);
921 add_const("gl_MaxCombinedImageUniforms",
922 state
->Const
.MaxCombinedImageUniforms
);
924 if (state
->has_geometry_shader()) {
925 add_const("gl_MaxGeometryImageUniforms",
926 state
->Const
.MaxGeometryImageUniforms
);
929 if (!state
->es_shader
) {
930 add_const("gl_MaxCombinedImageUnitsAndFragmentOutputs",
931 state
->Const
.MaxCombinedShaderOutputResources
);
932 add_const("gl_MaxImageSamples",
933 state
->Const
.MaxImageSamples
);
936 if (state
->has_tessellation_shader()) {
937 add_const("gl_MaxTessControlImageUniforms",
938 state
->Const
.MaxTessControlImageUniforms
);
939 add_const("gl_MaxTessEvaluationImageUniforms",
940 state
->Const
.MaxTessEvaluationImageUniforms
);
944 if (state
->is_version(440, 310) ||
945 state
->ARB_ES3_1_compatibility_enable
) {
946 add_const("gl_MaxCombinedShaderOutputResources",
947 state
->Const
.MaxCombinedShaderOutputResources
);
950 if (state
->is_version(410, 0) ||
951 state
->ARB_viewport_array_enable
||
952 state
->OES_viewport_array_enable
) {
953 add_const("gl_MaxViewports", GLSL_PRECISION_HIGH
,
954 state
->Const
.MaxViewports
);
957 if (state
->has_tessellation_shader()) {
958 add_const("gl_MaxPatchVertices", state
->Const
.MaxPatchVertices
);
959 add_const("gl_MaxTessGenLevel", state
->Const
.MaxTessGenLevel
);
960 add_const("gl_MaxTessControlInputComponents", state
->Const
.MaxTessControlInputComponents
);
961 add_const("gl_MaxTessControlOutputComponents", state
->Const
.MaxTessControlOutputComponents
);
962 add_const("gl_MaxTessControlTextureImageUnits", state
->Const
.MaxTessControlTextureImageUnits
);
963 add_const("gl_MaxTessEvaluationInputComponents", state
->Const
.MaxTessEvaluationInputComponents
);
964 add_const("gl_MaxTessEvaluationOutputComponents", state
->Const
.MaxTessEvaluationOutputComponents
);
965 add_const("gl_MaxTessEvaluationTextureImageUnits", state
->Const
.MaxTessEvaluationTextureImageUnits
);
966 add_const("gl_MaxTessPatchComponents", state
->Const
.MaxTessPatchComponents
);
967 add_const("gl_MaxTessControlTotalOutputComponents", state
->Const
.MaxTessControlTotalOutputComponents
);
968 add_const("gl_MaxTessControlUniformComponents", state
->Const
.MaxTessControlUniformComponents
);
969 add_const("gl_MaxTessEvaluationUniformComponents", state
->Const
.MaxTessEvaluationUniformComponents
);
972 if (state
->is_version(450, 320) ||
973 state
->OES_sample_variables_enable
||
974 state
->ARB_ES3_1_compatibility_enable
)
975 add_const("gl_MaxSamples", state
->Const
.MaxSamples
);
980 * Generate uniform variables (which exist in all types of shaders).
983 builtin_variable_generator::generate_uniforms()
985 if (state
->is_version(400, 320) ||
986 state
->ARB_sample_shading_enable
||
987 state
->OES_sample_variables_enable
)
988 add_uniform(int_t
, GLSL_PRECISION_LOW
, "gl_NumSamples");
989 add_uniform(type("gl_DepthRangeParameters"), "gl_DepthRange");
990 add_uniform(array(vec4_t
, VERT_ATTRIB_MAX
), "gl_CurrentAttribVertMESA");
991 add_uniform(array(vec4_t
, VARYING_SLOT_MAX
), "gl_CurrentAttribFragMESA");
994 add_uniform(mat4_t
, "gl_ModelViewMatrix");
995 add_uniform(mat4_t
, "gl_ProjectionMatrix");
996 add_uniform(mat4_t
, "gl_ModelViewProjectionMatrix");
997 add_uniform(mat3_t
, "gl_NormalMatrix");
998 add_uniform(mat4_t
, "gl_ModelViewMatrixInverse");
999 add_uniform(mat4_t
, "gl_ProjectionMatrixInverse");
1000 add_uniform(mat4_t
, "gl_ModelViewProjectionMatrixInverse");
1001 add_uniform(mat4_t
, "gl_ModelViewMatrixTranspose");
1002 add_uniform(mat4_t
, "gl_ProjectionMatrixTranspose");
1003 add_uniform(mat4_t
, "gl_ModelViewProjectionMatrixTranspose");
1004 add_uniform(mat4_t
, "gl_ModelViewMatrixInverseTranspose");
1005 add_uniform(mat4_t
, "gl_ProjectionMatrixInverseTranspose");
1006 add_uniform(mat4_t
, "gl_ModelViewProjectionMatrixInverseTranspose");
1007 add_uniform(float_t
, "gl_NormalScale");
1008 add_uniform(type("gl_LightModelParameters"), "gl_LightModel");
1009 add_uniform(vec4_t
, "gl_FogParamsOptimizedMESA");
1011 const glsl_type
*const mat4_array_type
=
1012 array(mat4_t
, state
->Const
.MaxTextureCoords
);
1013 add_uniform(mat4_array_type
, "gl_TextureMatrix");
1014 add_uniform(mat4_array_type
, "gl_TextureMatrixInverse");
1015 add_uniform(mat4_array_type
, "gl_TextureMatrixTranspose");
1016 add_uniform(mat4_array_type
, "gl_TextureMatrixInverseTranspose");
1018 add_uniform(array(vec4_t
, state
->Const
.MaxClipPlanes
), "gl_ClipPlane");
1019 add_uniform(type("gl_PointParameters"), "gl_Point");
1021 const glsl_type
*const material_parameters_type
=
1022 type("gl_MaterialParameters");
1023 add_uniform(material_parameters_type
, "gl_FrontMaterial");
1024 add_uniform(material_parameters_type
, "gl_BackMaterial");
1026 add_uniform(array(type("gl_LightSourceParameters"),
1027 state
->Const
.MaxLights
),
1030 const glsl_type
*const light_model_products_type
=
1031 type("gl_LightModelProducts");
1032 add_uniform(light_model_products_type
, "gl_FrontLightModelProduct");
1033 add_uniform(light_model_products_type
, "gl_BackLightModelProduct");
1035 const glsl_type
*const light_products_type
=
1036 array(type("gl_LightProducts"), state
->Const
.MaxLights
);
1037 add_uniform(light_products_type
, "gl_FrontLightProduct");
1038 add_uniform(light_products_type
, "gl_BackLightProduct");
1040 add_uniform(array(vec4_t
, state
->Const
.MaxTextureUnits
),
1041 "gl_TextureEnvColor");
1043 const glsl_type
*const texcoords_vec4
=
1044 array(vec4_t
, state
->Const
.MaxTextureCoords
);
1045 add_uniform(texcoords_vec4
, "gl_EyePlaneS");
1046 add_uniform(texcoords_vec4
, "gl_EyePlaneT");
1047 add_uniform(texcoords_vec4
, "gl_EyePlaneR");
1048 add_uniform(texcoords_vec4
, "gl_EyePlaneQ");
1049 add_uniform(texcoords_vec4
, "gl_ObjectPlaneS");
1050 add_uniform(texcoords_vec4
, "gl_ObjectPlaneT");
1051 add_uniform(texcoords_vec4
, "gl_ObjectPlaneR");
1052 add_uniform(texcoords_vec4
, "gl_ObjectPlaneQ");
1054 add_uniform(type("gl_FogParameters"), "gl_Fog");
1060 * Generate special variables which exist in all shaders.
1063 builtin_variable_generator::generate_special_vars()
1065 if (state
->ARB_shader_ballot_enable
) {
1066 add_system_value(SYSTEM_VALUE_SUBGROUP_SIZE
, uint_t
, "gl_SubGroupSizeARB");
1067 add_system_value(SYSTEM_VALUE_SUBGROUP_INVOCATION
, uint_t
, "gl_SubGroupInvocationARB");
1068 add_system_value(SYSTEM_VALUE_SUBGROUP_EQ_MASK
, uint64_t, "gl_SubGroupEqMaskARB");
1069 add_system_value(SYSTEM_VALUE_SUBGROUP_GE_MASK
, uint64_t, "gl_SubGroupGeMaskARB");
1070 add_system_value(SYSTEM_VALUE_SUBGROUP_GT_MASK
, uint64_t, "gl_SubGroupGtMaskARB");
1071 add_system_value(SYSTEM_VALUE_SUBGROUP_LE_MASK
, uint64_t, "gl_SubGroupLeMaskARB");
1072 add_system_value(SYSTEM_VALUE_SUBGROUP_LT_MASK
, uint64_t, "gl_SubGroupLtMaskARB");
1078 * Generate variables which only exist in vertex shaders.
1081 builtin_variable_generator::generate_vs_special_vars()
1083 if (state
->is_version(130, 300) || state
->EXT_gpu_shader4_enable
) {
1084 add_system_value(SYSTEM_VALUE_VERTEX_ID
, int_t
, GLSL_PRECISION_HIGH
,
1087 if (state
->is_version(460, 0)) {
1088 add_system_value(SYSTEM_VALUE_BASE_VERTEX
, int_t
, "gl_BaseVertex");
1089 add_system_value(SYSTEM_VALUE_BASE_INSTANCE
, int_t
, "gl_BaseInstance");
1090 add_system_value(SYSTEM_VALUE_DRAW_ID
, int_t
, "gl_DrawID");
1092 if (state
->EXT_draw_instanced_enable
&& state
->is_version(0, 100))
1093 add_system_value(SYSTEM_VALUE_INSTANCE_ID
, int_t
, GLSL_PRECISION_HIGH
,
1094 "gl_InstanceIDEXT");
1096 if (state
->ARB_draw_instanced_enable
)
1097 add_system_value(SYSTEM_VALUE_INSTANCE_ID
, int_t
, "gl_InstanceIDARB");
1099 if (state
->ARB_draw_instanced_enable
|| state
->is_version(140, 300) ||
1100 state
->EXT_gpu_shader4_enable
) {
1101 add_system_value(SYSTEM_VALUE_INSTANCE_ID
, int_t
, GLSL_PRECISION_HIGH
,
1104 if (state
->ARB_shader_draw_parameters_enable
) {
1105 add_system_value(SYSTEM_VALUE_BASE_VERTEX
, int_t
, "gl_BaseVertexARB");
1106 add_system_value(SYSTEM_VALUE_BASE_INSTANCE
, int_t
, "gl_BaseInstanceARB");
1107 add_system_value(SYSTEM_VALUE_DRAW_ID
, int_t
, "gl_DrawIDARB");
1109 if (compatibility
) {
1110 add_input(VERT_ATTRIB_POS
, vec4_t
, "gl_Vertex");
1111 add_input(VERT_ATTRIB_NORMAL
, vec3_t
, "gl_Normal");
1112 add_input(VERT_ATTRIB_COLOR0
, vec4_t
, "gl_Color");
1113 add_input(VERT_ATTRIB_COLOR1
, vec4_t
, "gl_SecondaryColor");
1114 add_input(VERT_ATTRIB_TEX0
, vec4_t
, "gl_MultiTexCoord0");
1115 add_input(VERT_ATTRIB_TEX1
, vec4_t
, "gl_MultiTexCoord1");
1116 add_input(VERT_ATTRIB_TEX2
, vec4_t
, "gl_MultiTexCoord2");
1117 add_input(VERT_ATTRIB_TEX3
, vec4_t
, "gl_MultiTexCoord3");
1118 add_input(VERT_ATTRIB_TEX4
, vec4_t
, "gl_MultiTexCoord4");
1119 add_input(VERT_ATTRIB_TEX5
, vec4_t
, "gl_MultiTexCoord5");
1120 add_input(VERT_ATTRIB_TEX6
, vec4_t
, "gl_MultiTexCoord6");
1121 add_input(VERT_ATTRIB_TEX7
, vec4_t
, "gl_MultiTexCoord7");
1122 add_input(VERT_ATTRIB_FOG
, float_t
, "gl_FogCoord");
1128 * Generate variables which only exist in tessellation control shaders.
1131 builtin_variable_generator::generate_tcs_special_vars()
1133 add_system_value(SYSTEM_VALUE_PRIMITIVE_ID
, int_t
, GLSL_PRECISION_HIGH
,
1135 add_system_value(SYSTEM_VALUE_INVOCATION_ID
, int_t
, GLSL_PRECISION_HIGH
,
1137 add_system_value(SYSTEM_VALUE_VERTICES_IN
, int_t
, GLSL_PRECISION_HIGH
,
1138 "gl_PatchVerticesIn");
1140 add_output(VARYING_SLOT_TESS_LEVEL_OUTER
, array(float_t
, 4),
1141 GLSL_PRECISION_HIGH
, "gl_TessLevelOuter")->data
.patch
= 1;
1142 add_output(VARYING_SLOT_TESS_LEVEL_INNER
, array(float_t
, 2),
1143 GLSL_PRECISION_HIGH
, "gl_TessLevelInner")->data
.patch
= 1;
1144 /* XXX What to do if multiple are flipped on? */
1145 int bbox_slot
= state
->ctx
->Const
.NoPrimitiveBoundingBoxOutput
? -1 :
1146 VARYING_SLOT_BOUNDING_BOX0
;
1147 if (state
->EXT_primitive_bounding_box_enable
)
1148 add_output(bbox_slot
, array(vec4_t
, 2), "gl_BoundingBoxEXT")
1150 if (state
->OES_primitive_bounding_box_enable
) {
1151 add_output(bbox_slot
, array(vec4_t
, 2), GLSL_PRECISION_HIGH
,
1152 "gl_BoundingBoxOES")->data
.patch
= 1;
1154 if (state
->is_version(0, 320) || state
->ARB_ES3_2_compatibility_enable
) {
1155 add_output(bbox_slot
, array(vec4_t
, 2), GLSL_PRECISION_HIGH
,
1156 "gl_BoundingBox")->data
.patch
= 1;
1159 /* NOTE: These are completely pointless. Writing these will never go
1160 * anywhere. But the specs demands it. So we add them with a slot of -1,
1161 * which makes the data go nowhere.
1163 if (state
->NV_viewport_array2_enable
) {
1164 add_output(-1, int_t
, "gl_Layer");
1165 add_output(-1, int_t
, "gl_ViewportIndex");
1166 add_output(-1, array(int_t
, 1), "gl_ViewportMask");
1173 * Generate variables which only exist in tessellation evaluation shaders.
1176 builtin_variable_generator::generate_tes_special_vars()
1180 add_system_value(SYSTEM_VALUE_PRIMITIVE_ID
, int_t
, GLSL_PRECISION_HIGH
,
1182 add_system_value(SYSTEM_VALUE_VERTICES_IN
, int_t
, GLSL_PRECISION_HIGH
,
1183 "gl_PatchVerticesIn");
1184 add_system_value(SYSTEM_VALUE_TESS_COORD
, vec3_t
, GLSL_PRECISION_HIGH
,
1186 if (this->state
->ctx
->Const
.GLSLTessLevelsAsInputs
) {
1187 add_input(VARYING_SLOT_TESS_LEVEL_OUTER
, array(float_t
, 4),
1188 GLSL_PRECISION_HIGH
, "gl_TessLevelOuter")->data
.patch
= 1;
1189 add_input(VARYING_SLOT_TESS_LEVEL_INNER
, array(float_t
, 2),
1190 GLSL_PRECISION_HIGH
, "gl_TessLevelInner")->data
.patch
= 1;
1192 add_system_value(SYSTEM_VALUE_TESS_LEVEL_OUTER
, array(float_t
, 4),
1193 GLSL_PRECISION_HIGH
, "gl_TessLevelOuter");
1194 add_system_value(SYSTEM_VALUE_TESS_LEVEL_INNER
, array(float_t
, 2),
1195 GLSL_PRECISION_HIGH
, "gl_TessLevelInner");
1197 if (state
->ARB_shader_viewport_layer_array_enable
||
1198 state
->NV_viewport_array2_enable
) {
1199 var
= add_output(VARYING_SLOT_LAYER
, int_t
, "gl_Layer");
1200 var
->data
.interpolation
= INTERP_MODE_FLAT
;
1201 var
= add_output(VARYING_SLOT_VIEWPORT
, int_t
, "gl_ViewportIndex");
1202 var
->data
.interpolation
= INTERP_MODE_FLAT
;
1204 if (state
->NV_viewport_array2_enable
) {
1205 var
= add_output(VARYING_SLOT_VIEWPORT_MASK
, array(int_t
, 1),
1207 var
->data
.interpolation
= INTERP_MODE_FLAT
;
1213 * Generate variables which only exist in geometry shaders.
1216 builtin_variable_generator::generate_gs_special_vars()
1220 var
= add_output(VARYING_SLOT_LAYER
, int_t
, GLSL_PRECISION_HIGH
, "gl_Layer");
1221 var
->data
.interpolation
= INTERP_MODE_FLAT
;
1222 if (state
->is_version(410, 0) || state
->ARB_viewport_array_enable
||
1223 state
->OES_viewport_array_enable
) {
1224 var
= add_output(VARYING_SLOT_VIEWPORT
, int_t
, GLSL_PRECISION_HIGH
,
1225 "gl_ViewportIndex");
1226 var
->data
.interpolation
= INTERP_MODE_FLAT
;
1228 if (state
->NV_viewport_array2_enable
) {
1229 var
= add_output(VARYING_SLOT_VIEWPORT_MASK
, array(int_t
, 1),
1231 var
->data
.interpolation
= INTERP_MODE_FLAT
;
1233 if (state
->is_version(400, 320) || state
->ARB_gpu_shader5_enable
||
1234 state
->OES_geometry_shader_enable
|| state
->EXT_geometry_shader_enable
) {
1235 add_system_value(SYSTEM_VALUE_INVOCATION_ID
, int_t
, GLSL_PRECISION_HIGH
,
1239 /* Although gl_PrimitiveID appears in tessellation control and tessellation
1240 * evaluation shaders, it has a different function there than it has in
1241 * geometry shaders, so we treat it (and its counterpart gl_PrimitiveIDIn)
1242 * as special geometry shader variables.
1244 * Note that although the general convention of suffixing geometry shader
1245 * input varyings with "In" was not adopted into GLSL 1.50, it is used in
1246 * the specific case of gl_PrimitiveIDIn. So we don't need to treat
1247 * gl_PrimitiveIDIn as an {ARB,EXT}_geometry_shader4-only variable.
1249 var
= add_input(VARYING_SLOT_PRIMITIVE_ID
, int_t
, GLSL_PRECISION_HIGH
,
1250 "gl_PrimitiveIDIn");
1251 var
->data
.interpolation
= INTERP_MODE_FLAT
;
1252 var
= add_output(VARYING_SLOT_PRIMITIVE_ID
, int_t
, GLSL_PRECISION_HIGH
,
1254 var
->data
.interpolation
= INTERP_MODE_FLAT
;
1259 * Generate variables which only exist in fragment shaders.
1262 builtin_variable_generator::generate_fs_special_vars()
1266 int frag_coord_precision
= (state
->is_version(0, 300) ?
1267 GLSL_PRECISION_HIGH
:
1268 GLSL_PRECISION_MEDIUM
);
1270 if (this->state
->ctx
->Const
.GLSLFragCoordIsSysVal
) {
1271 add_system_value(SYSTEM_VALUE_FRAG_COORD
, vec4_t
, frag_coord_precision
,
1274 add_input(VARYING_SLOT_POS
, vec4_t
, frag_coord_precision
, "gl_FragCoord");
1277 if (this->state
->ctx
->Const
.GLSLFrontFacingIsSysVal
) {
1278 var
= add_system_value(SYSTEM_VALUE_FRONT_FACE
, bool_t
, "gl_FrontFacing");
1279 var
->data
.interpolation
= INTERP_MODE_FLAT
;
1281 var
= add_input(VARYING_SLOT_FACE
, bool_t
, "gl_FrontFacing");
1282 var
->data
.interpolation
= INTERP_MODE_FLAT
;
1285 if (state
->is_version(120, 100)) {
1286 if (this->state
->ctx
->Const
.GLSLPointCoordIsSysVal
)
1287 add_system_value(SYSTEM_VALUE_POINT_COORD
, vec2_t
,
1288 GLSL_PRECISION_MEDIUM
, "gl_PointCoord");
1290 add_input(VARYING_SLOT_PNTC
, vec2_t
, GLSL_PRECISION_MEDIUM
,
1294 if (state
->has_geometry_shader() || state
->EXT_gpu_shader4_enable
) {
1295 var
= add_input(VARYING_SLOT_PRIMITIVE_ID
, int_t
, GLSL_PRECISION_HIGH
,
1297 var
->data
.interpolation
= INTERP_MODE_FLAT
;
1300 /* gl_FragColor and gl_FragData were deprecated starting in desktop GLSL
1301 * 1.30, and were relegated to the compatibility profile in GLSL 4.20.
1302 * They were removed from GLSL ES 3.00.
1304 if (compatibility
|| !state
->is_version(420, 300)) {
1305 add_output(FRAG_RESULT_COLOR
, vec4_t
, GLSL_PRECISION_MEDIUM
,
1307 add_output(FRAG_RESULT_DATA0
,
1308 array(vec4_t
, state
->Const
.MaxDrawBuffers
),
1309 GLSL_PRECISION_MEDIUM
,
1313 if (state
->has_framebuffer_fetch() && !state
->is_version(130, 300)) {
1314 ir_variable
*const var
=
1315 add_output(FRAG_RESULT_DATA0
,
1316 array(vec4_t
, state
->Const
.MaxDrawBuffers
),
1318 var
->data
.precision
= GLSL_PRECISION_MEDIUM
;
1319 var
->data
.read_only
= 1;
1320 var
->data
.fb_fetch_output
= 1;
1321 var
->data
.memory_coherent
= 1;
1324 if (state
->es_shader
&& state
->language_version
== 100 && state
->EXT_blend_func_extended_enable
) {
1325 add_index_output(FRAG_RESULT_COLOR
, 1, vec4_t
,
1326 GLSL_PRECISION_MEDIUM
, "gl_SecondaryFragColorEXT");
1327 add_index_output(FRAG_RESULT_DATA0
, 1,
1328 array(vec4_t
, state
->Const
.MaxDualSourceDrawBuffers
),
1329 GLSL_PRECISION_MEDIUM
, "gl_SecondaryFragDataEXT");
1332 /* gl_FragDepth has always been in desktop GLSL, but did not appear in GLSL
1335 if (state
->is_version(110, 300)) {
1336 add_output(FRAG_RESULT_DEPTH
, float_t
, GLSL_PRECISION_HIGH
,
1340 if (state
->EXT_frag_depth_enable
)
1341 add_output(FRAG_RESULT_DEPTH
, float_t
, "gl_FragDepthEXT");
1343 if (state
->ARB_shader_stencil_export_enable
) {
1344 ir_variable
*const var
=
1345 add_output(FRAG_RESULT_STENCIL
, int_t
, "gl_FragStencilRefARB");
1346 if (state
->ARB_shader_stencil_export_warn
)
1347 var
->enable_extension_warning("GL_ARB_shader_stencil_export");
1350 if (state
->AMD_shader_stencil_export_enable
) {
1351 ir_variable
*const var
=
1352 add_output(FRAG_RESULT_STENCIL
, int_t
, "gl_FragStencilRefAMD");
1353 if (state
->AMD_shader_stencil_export_warn
)
1354 var
->enable_extension_warning("GL_AMD_shader_stencil_export");
1357 if (state
->is_version(400, 320) ||
1358 state
->ARB_sample_shading_enable
||
1359 state
->OES_sample_variables_enable
) {
1360 add_system_value(SYSTEM_VALUE_SAMPLE_ID
, int_t
, GLSL_PRECISION_LOW
,
1362 add_system_value(SYSTEM_VALUE_SAMPLE_POS
, vec2_t
, GLSL_PRECISION_MEDIUM
,
1363 "gl_SamplePosition");
1364 /* From the ARB_sample_shading specification:
1365 * "The number of elements in the array is ceil(<s>/32), where
1366 * <s> is the maximum number of color samples supported by the
1368 * Since no drivers expose more than 32x MSAA, we can simply set
1369 * the array size to 1 rather than computing it.
1371 add_output(FRAG_RESULT_SAMPLE_MASK
, array(int_t
, 1),
1372 GLSL_PRECISION_HIGH
, "gl_SampleMask");
1375 if (state
->is_version(400, 320) ||
1376 state
->ARB_gpu_shader5_enable
||
1377 state
->OES_sample_variables_enable
) {
1378 add_system_value(SYSTEM_VALUE_SAMPLE_MASK_IN
, array(int_t
, 1),
1379 GLSL_PRECISION_HIGH
, "gl_SampleMaskIn");
1382 if (state
->is_version(430, 320) ||
1383 state
->ARB_fragment_layer_viewport_enable
||
1384 state
->OES_geometry_shader_enable
||
1385 state
->EXT_geometry_shader_enable
) {
1386 add_varying(VARYING_SLOT_LAYER
, int_t
, GLSL_PRECISION_HIGH
,
1387 "gl_Layer", INTERP_MODE_FLAT
);
1390 if (state
->is_version(430, 0) ||
1391 state
->ARB_fragment_layer_viewport_enable
||
1392 state
->OES_viewport_array_enable
) {
1393 add_varying(VARYING_SLOT_VIEWPORT
, int_t
, "gl_ViewportIndex", INTERP_MODE_FLAT
);
1396 if (state
->is_version(450, 310) || state
->ARB_ES3_1_compatibility_enable
)
1397 add_system_value(SYSTEM_VALUE_HELPER_INVOCATION
, bool_t
, "gl_HelperInvocation");
1402 * Generate variables which only exist in compute shaders.
1405 builtin_variable_generator::generate_cs_special_vars()
1407 add_system_value(SYSTEM_VALUE_LOCAL_INVOCATION_ID
, uvec3_t
,
1408 "gl_LocalInvocationID");
1409 add_system_value(SYSTEM_VALUE_WORK_GROUP_ID
, uvec3_t
, "gl_WorkGroupID");
1410 add_system_value(SYSTEM_VALUE_NUM_WORK_GROUPS
, uvec3_t
, "gl_NumWorkGroups");
1412 if (state
->ARB_compute_variable_group_size_enable
) {
1413 add_system_value(SYSTEM_VALUE_LOCAL_GROUP_SIZE
,
1414 uvec3_t
, "gl_LocalGroupSizeARB");
1417 add_system_value(SYSTEM_VALUE_GLOBAL_INVOCATION_ID
,
1418 uvec3_t
, "gl_GlobalInvocationID");
1419 add_system_value(SYSTEM_VALUE_LOCAL_INVOCATION_INDEX
,
1420 uint_t
, "gl_LocalInvocationIndex");
1425 * Add a single "varying" variable. The variable's type and direction (input
1426 * or output) are adjusted as appropriate for the type of shader being
1430 builtin_variable_generator::add_varying(int slot
, const glsl_type
*type
,
1431 int precision
, const char *name
,
1432 enum glsl_interp_mode interp
)
1434 switch (state
->stage
) {
1435 case MESA_SHADER_TESS_CTRL
:
1436 case MESA_SHADER_TESS_EVAL
:
1437 case MESA_SHADER_GEOMETRY
:
1438 this->per_vertex_in
.add_field(slot
, type
, precision
, name
, interp
);
1440 case MESA_SHADER_VERTEX
:
1441 this->per_vertex_out
.add_field(slot
, type
, precision
, name
, interp
);
1443 case MESA_SHADER_FRAGMENT
:
1444 add_input(slot
, type
, precision
, name
, interp
);
1446 case MESA_SHADER_COMPUTE
:
1447 /* Compute shaders don't have varyings. */
1456 * Generate variables that are used to communicate data from one shader stage
1457 * to the next ("varyings").
1460 builtin_variable_generator::generate_varyings()
1462 struct gl_shader_compiler_options
*options
=
1463 &state
->ctx
->Const
.ShaderCompilerOptions
[state
->stage
];
1465 /* gl_Position and gl_PointSize are not visible from fragment shaders. */
1466 if (state
->stage
!= MESA_SHADER_FRAGMENT
) {
1467 add_varying(VARYING_SLOT_POS
, vec4_t
, GLSL_PRECISION_HIGH
, "gl_Position");
1468 if (!state
->es_shader
||
1469 state
->stage
== MESA_SHADER_VERTEX
||
1470 (state
->stage
== MESA_SHADER_GEOMETRY
&&
1471 (state
->OES_geometry_point_size_enable
||
1472 state
->EXT_geometry_point_size_enable
)) ||
1473 ((state
->stage
== MESA_SHADER_TESS_CTRL
||
1474 state
->stage
== MESA_SHADER_TESS_EVAL
) &&
1475 (state
->OES_tessellation_point_size_enable
||
1476 state
->EXT_tessellation_point_size_enable
))) {
1477 add_varying(VARYING_SLOT_PSIZ
,
1479 state
->is_version(0, 300) ?
1480 GLSL_PRECISION_HIGH
:
1481 GLSL_PRECISION_MEDIUM
,
1484 if (state
->stage
== MESA_SHADER_VERTEX
) {
1485 if (state
->AMD_vertex_shader_viewport_index_enable
||
1486 state
->ARB_shader_viewport_layer_array_enable
||
1487 state
->NV_viewport_array2_enable
) {
1488 add_varying(VARYING_SLOT_VIEWPORT
, int_t
, "gl_ViewportIndex", INTERP_MODE_FLAT
);
1491 if (state
->AMD_vertex_shader_layer_enable
||
1492 state
->ARB_shader_viewport_layer_array_enable
||
1493 state
->NV_viewport_array2_enable
) {
1494 add_varying(VARYING_SLOT_LAYER
, int_t
, GLSL_PRECISION_HIGH
,
1495 "gl_Layer", INTERP_MODE_FLAT
);
1498 /* From the NV_viewport_array2 specification:
1500 * "The variable gl_ViewportMask[] is available as an output variable
1501 * in the VTG languages. The array has ceil(v/32) elements where v is
1502 * the maximum number of viewports supported by the implementation."
1504 * Since no drivers expose more than 16 viewports, we can simply set the
1505 * array size to 1 rather than computing it and dealing with varying
1506 * slot complication.
1508 if (state
->NV_viewport_array2_enable
)
1509 add_varying(VARYING_SLOT_VIEWPORT_MASK
, array(int_t
, 1),
1510 "gl_ViewportMask", INTERP_MODE_FLAT
);
1514 if (state
->has_clip_distance()) {
1515 add_varying(VARYING_SLOT_CLIP_DIST0
, array(float_t
, 0),
1516 GLSL_PRECISION_HIGH
, "gl_ClipDistance");
1518 if (state
->has_cull_distance()) {
1519 add_varying(VARYING_SLOT_CULL_DIST0
, array(float_t
, 0),
1520 GLSL_PRECISION_HIGH
, "gl_CullDistance");
1523 if (compatibility
) {
1524 add_varying(VARYING_SLOT_TEX0
, array(vec4_t
, 0), "gl_TexCoord");
1525 add_varying(VARYING_SLOT_FOGC
, float_t
, "gl_FogFragCoord");
1526 if (state
->stage
== MESA_SHADER_FRAGMENT
) {
1527 add_varying(VARYING_SLOT_COL0
, vec4_t
, "gl_Color");
1528 add_varying(VARYING_SLOT_COL1
, vec4_t
, "gl_SecondaryColor");
1530 add_varying(VARYING_SLOT_CLIP_VERTEX
, vec4_t
, "gl_ClipVertex");
1531 add_varying(VARYING_SLOT_COL0
, vec4_t
, "gl_FrontColor");
1532 add_varying(VARYING_SLOT_BFC0
, vec4_t
, "gl_BackColor");
1533 add_varying(VARYING_SLOT_COL1
, vec4_t
, "gl_FrontSecondaryColor");
1534 add_varying(VARYING_SLOT_BFC1
, vec4_t
, "gl_BackSecondaryColor");
1538 /* Section 7.1 (Built-In Language Variables) of the GLSL 4.00 spec
1541 * "In the tessellation control language, built-in variables are
1542 * intrinsically declared as:
1546 * float gl_PointSize;
1547 * float gl_ClipDistance[];
1548 * } gl_in[gl_MaxPatchVertices];"
1550 if (state
->stage
== MESA_SHADER_TESS_CTRL
||
1551 state
->stage
== MESA_SHADER_TESS_EVAL
) {
1552 const glsl_type
*per_vertex_in_type
=
1553 this->per_vertex_in
.construct_interface_instance();
1554 add_variable("gl_in", array(per_vertex_in_type
, state
->Const
.MaxPatchVertices
),
1555 GLSL_PRECISION_NONE
, ir_var_shader_in
, -1);
1557 if (state
->stage
== MESA_SHADER_GEOMETRY
) {
1558 const glsl_type
*per_vertex_in_type
=
1559 this->per_vertex_in
.construct_interface_instance();
1560 add_variable("gl_in", array(per_vertex_in_type
, 0),
1561 GLSL_PRECISION_NONE
, ir_var_shader_in
, -1);
1563 if (state
->stage
== MESA_SHADER_TESS_CTRL
) {
1564 const glsl_type
*per_vertex_out_type
=
1565 this->per_vertex_out
.construct_interface_instance();
1566 add_variable("gl_out", array(per_vertex_out_type
, 0),
1567 GLSL_PRECISION_NONE
, ir_var_shader_out
, -1);
1569 if (state
->stage
== MESA_SHADER_VERTEX
||
1570 state
->stage
== MESA_SHADER_TESS_EVAL
||
1571 state
->stage
== MESA_SHADER_GEOMETRY
) {
1572 const glsl_type
*per_vertex_out_type
=
1573 this->per_vertex_out
.construct_interface_instance();
1574 const glsl_struct_field
*fields
= per_vertex_out_type
->fields
.structure
;
1575 for (unsigned i
= 0; i
< per_vertex_out_type
->length
; i
++) {
1577 add_variable(fields
[i
].name
, fields
[i
].type
, fields
[i
].precision
,
1578 ir_var_shader_out
, fields
[i
].location
);
1579 var
->data
.interpolation
= fields
[i
].interpolation
;
1580 var
->data
.centroid
= fields
[i
].centroid
;
1581 var
->data
.sample
= fields
[i
].sample
;
1582 var
->data
.patch
= fields
[i
].patch
;
1583 var
->init_interface_type(per_vertex_out_type
);
1585 var
->data
.invariant
= fields
[i
].location
== VARYING_SLOT_POS
&&
1586 options
->PositionAlwaysInvariant
;
1592 }; /* Anonymous namespace */
1596 _mesa_glsl_initialize_variables(exec_list
*instructions
,
1597 struct _mesa_glsl_parse_state
*state
)
1599 builtin_variable_generator
gen(instructions
, state
);
1601 gen
.generate_constants();
1602 gen
.generate_uniforms();
1603 gen
.generate_special_vars();
1605 gen
.generate_varyings();
1607 switch (state
->stage
) {
1608 case MESA_SHADER_VERTEX
:
1609 gen
.generate_vs_special_vars();
1611 case MESA_SHADER_TESS_CTRL
:
1612 gen
.generate_tcs_special_vars();
1614 case MESA_SHADER_TESS_EVAL
:
1615 gen
.generate_tes_special_vars();
1617 case MESA_SHADER_GEOMETRY
:
1618 gen
.generate_gs_special_vars();
1620 case MESA_SHADER_FRAGMENT
:
1621 gen
.generate_fs_special_vars();
1623 case MESA_SHADER_COMPUTE
:
1624 gen
.generate_cs_special_vars();