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.
25 #include "glsl_parser_extras.h"
26 #include "glsl_symbol_table.h"
27 #include "builtin_variables.h"
28 #include "main/uniforms.h"
29 #include "program/prog_parameter.h"
30 #include "program/prog_statevars.h"
31 #include "program/prog_instruction.h"
33 static void generate_ARB_draw_buffers_variables(exec_list
*,
34 struct _mesa_glsl_parse_state
*,
35 bool, _mesa_glsl_parser_targets
);
38 generate_ARB_draw_instanced_variables(exec_list
*,
39 struct _mesa_glsl_parse_state
*,
40 bool, _mesa_glsl_parser_targets
);
42 static struct gl_builtin_uniform_element gl_DepthRange_elements
[] = {
43 {"near", {STATE_DEPTH_RANGE
, 0, 0}, SWIZZLE_XXXX
},
44 {"far", {STATE_DEPTH_RANGE
, 0, 0}, SWIZZLE_YYYY
},
45 {"diff", {STATE_DEPTH_RANGE
, 0, 0}, SWIZZLE_ZZZZ
},
48 static struct gl_builtin_uniform_element gl_ClipPlane_elements
[] = {
49 {NULL
, {STATE_CLIPPLANE
, 0, 0}, SWIZZLE_XYZW
}
52 static struct gl_builtin_uniform_element gl_Point_elements
[] = {
53 {"size", {STATE_POINT_SIZE
}, SWIZZLE_XXXX
},
54 {"sizeMin", {STATE_POINT_SIZE
}, SWIZZLE_YYYY
},
55 {"sizeMax", {STATE_POINT_SIZE
}, SWIZZLE_ZZZZ
},
56 {"fadeThresholdSize", {STATE_POINT_SIZE
}, SWIZZLE_WWWW
},
57 {"distanceConstantAttenuation", {STATE_POINT_ATTENUATION
}, SWIZZLE_XXXX
},
58 {"distanceLinearAttenuation", {STATE_POINT_ATTENUATION
}, SWIZZLE_YYYY
},
59 {"distanceQuadraticAttenuation", {STATE_POINT_ATTENUATION
}, SWIZZLE_ZZZZ
},
62 static struct gl_builtin_uniform_element gl_FrontMaterial_elements
[] = {
63 {"emission", {STATE_MATERIAL
, 0, STATE_EMISSION
}, SWIZZLE_XYZW
},
64 {"ambient", {STATE_MATERIAL
, 0, STATE_AMBIENT
}, SWIZZLE_XYZW
},
65 {"diffuse", {STATE_MATERIAL
, 0, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
66 {"specular", {STATE_MATERIAL
, 0, STATE_SPECULAR
}, SWIZZLE_XYZW
},
67 {"shininess", {STATE_MATERIAL
, 0, STATE_SHININESS
}, SWIZZLE_XXXX
},
70 static struct gl_builtin_uniform_element gl_BackMaterial_elements
[] = {
71 {"emission", {STATE_MATERIAL
, 1, STATE_EMISSION
}, SWIZZLE_XYZW
},
72 {"ambient", {STATE_MATERIAL
, 1, STATE_AMBIENT
}, SWIZZLE_XYZW
},
73 {"diffuse", {STATE_MATERIAL
, 1, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
74 {"specular", {STATE_MATERIAL
, 1, STATE_SPECULAR
}, SWIZZLE_XYZW
},
75 {"shininess", {STATE_MATERIAL
, 1, STATE_SHININESS
}, SWIZZLE_XXXX
},
78 static struct gl_builtin_uniform_element gl_LightSource_elements
[] = {
79 {"ambient", {STATE_LIGHT
, 0, STATE_AMBIENT
}, SWIZZLE_XYZW
},
80 {"diffuse", {STATE_LIGHT
, 0, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
81 {"specular", {STATE_LIGHT
, 0, STATE_SPECULAR
}, SWIZZLE_XYZW
},
82 {"position", {STATE_LIGHT
, 0, STATE_POSITION
}, SWIZZLE_XYZW
},
83 {"halfVector", {STATE_LIGHT
, 0, STATE_HALF_VECTOR
}, SWIZZLE_XYZW
},
84 {"spotDirection", {STATE_LIGHT
, 0, STATE_SPOT_DIRECTION
},
85 MAKE_SWIZZLE4(SWIZZLE_X
,
89 {"spotCosCutoff", {STATE_LIGHT
, 0, STATE_SPOT_DIRECTION
}, SWIZZLE_WWWW
},
90 {"spotCutoff", {STATE_LIGHT
, 0, STATE_SPOT_CUTOFF
}, SWIZZLE_XXXX
},
91 {"spotExponent", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_WWWW
},
92 {"constantAttenuation", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_XXXX
},
93 {"linearAttenuation", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_YYYY
},
94 {"quadraticAttenuation", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_ZZZZ
},
97 static struct gl_builtin_uniform_element gl_LightModel_elements
[] = {
98 {"ambient", {STATE_LIGHTMODEL_AMBIENT
, 0}, SWIZZLE_XYZW
},
101 static struct gl_builtin_uniform_element gl_FrontLightModelProduct_elements
[] = {
102 {"sceneColor", {STATE_LIGHTMODEL_SCENECOLOR
, 0}, SWIZZLE_XYZW
},
105 static struct gl_builtin_uniform_element gl_BackLightModelProduct_elements
[] = {
106 {"sceneColor", {STATE_LIGHTMODEL_SCENECOLOR
, 1}, SWIZZLE_XYZW
},
109 static struct gl_builtin_uniform_element gl_FrontLightProduct_elements
[] = {
110 {"ambient", {STATE_LIGHTPROD
, 0, 0, STATE_AMBIENT
}, SWIZZLE_XYZW
},
111 {"diffuse", {STATE_LIGHTPROD
, 0, 0, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
112 {"specular", {STATE_LIGHTPROD
, 0, 0, STATE_SPECULAR
}, SWIZZLE_XYZW
},
115 static struct gl_builtin_uniform_element gl_BackLightProduct_elements
[] = {
116 {"ambient", {STATE_LIGHTPROD
, 0, 1, STATE_AMBIENT
}, SWIZZLE_XYZW
},
117 {"diffuse", {STATE_LIGHTPROD
, 0, 1, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
118 {"specular", {STATE_LIGHTPROD
, 0, 1, STATE_SPECULAR
}, SWIZZLE_XYZW
},
121 static struct gl_builtin_uniform_element gl_TextureEnvColor_elements
[] = {
122 {NULL
, {STATE_TEXENV_COLOR
, 0}, SWIZZLE_XYZW
},
125 static struct gl_builtin_uniform_element gl_EyePlaneS_elements
[] = {
126 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_S
}, SWIZZLE_XYZW
},
129 static struct gl_builtin_uniform_element gl_EyePlaneT_elements
[] = {
130 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_T
}, SWIZZLE_XYZW
},
133 static struct gl_builtin_uniform_element gl_EyePlaneR_elements
[] = {
134 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_R
}, SWIZZLE_XYZW
},
137 static struct gl_builtin_uniform_element gl_EyePlaneQ_elements
[] = {
138 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_Q
}, SWIZZLE_XYZW
},
141 static struct gl_builtin_uniform_element gl_ObjectPlaneS_elements
[] = {
142 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_S
}, SWIZZLE_XYZW
},
145 static struct gl_builtin_uniform_element gl_ObjectPlaneT_elements
[] = {
146 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_T
}, SWIZZLE_XYZW
},
149 static struct gl_builtin_uniform_element gl_ObjectPlaneR_elements
[] = {
150 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_R
}, SWIZZLE_XYZW
},
153 static struct gl_builtin_uniform_element gl_ObjectPlaneQ_elements
[] = {
154 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_Q
}, SWIZZLE_XYZW
},
157 static struct gl_builtin_uniform_element gl_Fog_elements
[] = {
158 {"color", {STATE_FOG_COLOR
}, SWIZZLE_XYZW
},
159 {"density", {STATE_FOG_PARAMS
}, SWIZZLE_XXXX
},
160 {"start", {STATE_FOG_PARAMS
}, SWIZZLE_YYYY
},
161 {"end", {STATE_FOG_PARAMS
}, SWIZZLE_ZZZZ
},
162 {"scale", {STATE_FOG_PARAMS
}, SWIZZLE_WWWW
},
165 static struct gl_builtin_uniform_element gl_NormalScale_elements
[] = {
166 {NULL
, {STATE_NORMAL_SCALE
}, SWIZZLE_XXXX
},
169 static struct gl_builtin_uniform_element gl_MESABumpRotMatrix0_elements
[] = {
170 {NULL
, {STATE_INTERNAL
, STATE_ROT_MATRIX_0
}, SWIZZLE_XYZW
},
173 static struct gl_builtin_uniform_element gl_MESABumpRotMatrix1_elements
[] = {
174 {NULL
, {STATE_INTERNAL
, STATE_ROT_MATRIX_1
}, SWIZZLE_XYZW
},
177 static struct gl_builtin_uniform_element gl_MESAFogParamsOptimized_elements
[] = {
178 {NULL
, {STATE_INTERNAL
, STATE_FOG_PARAMS_OPTIMIZED
}, SWIZZLE_XYZW
},
181 #define MATRIX(name, statevar, modifier) \
182 static struct gl_builtin_uniform_element name ## _elements[] = { \
183 { NULL, { statevar, 0, 0, 0, modifier}, SWIZZLE_XYZW }, \
184 { NULL, { statevar, 0, 1, 1, modifier}, SWIZZLE_XYZW }, \
185 { NULL, { statevar, 0, 2, 2, modifier}, SWIZZLE_XYZW }, \
186 { NULL, { statevar, 0, 3, 3, modifier}, SWIZZLE_XYZW }, \
189 MATRIX(gl_ModelViewMatrix
,
190 STATE_MODELVIEW_MATRIX
, STATE_MATRIX_TRANSPOSE
);
191 MATRIX(gl_ModelViewMatrixInverse
,
192 STATE_MODELVIEW_MATRIX
, STATE_MATRIX_INVTRANS
);
193 MATRIX(gl_ModelViewMatrixTranspose
,
194 STATE_MODELVIEW_MATRIX
, 0);
195 MATRIX(gl_ModelViewMatrixInverseTranspose
,
196 STATE_MODELVIEW_MATRIX
, STATE_MATRIX_INVERSE
);
198 MATRIX(gl_ProjectionMatrix
,
199 STATE_PROJECTION_MATRIX
, STATE_MATRIX_TRANSPOSE
);
200 MATRIX(gl_ProjectionMatrixInverse
,
201 STATE_PROJECTION_MATRIX
, STATE_MATRIX_INVTRANS
);
202 MATRIX(gl_ProjectionMatrixTranspose
,
203 STATE_PROJECTION_MATRIX
, 0);
204 MATRIX(gl_ProjectionMatrixInverseTranspose
,
205 STATE_PROJECTION_MATRIX
, STATE_MATRIX_INVERSE
);
207 MATRIX(gl_ModelViewProjectionMatrix
,
208 STATE_MVP_MATRIX
, STATE_MATRIX_TRANSPOSE
);
209 MATRIX(gl_ModelViewProjectionMatrixInverse
,
210 STATE_MVP_MATRIX
, STATE_MATRIX_INVTRANS
);
211 MATRIX(gl_ModelViewProjectionMatrixTranspose
,
212 STATE_MVP_MATRIX
, 0);
213 MATRIX(gl_ModelViewProjectionMatrixInverseTranspose
,
214 STATE_MVP_MATRIX
, STATE_MATRIX_INVERSE
);
216 MATRIX(gl_TextureMatrix
,
217 STATE_TEXTURE_MATRIX
, STATE_MATRIX_TRANSPOSE
);
218 MATRIX(gl_TextureMatrixInverse
,
219 STATE_TEXTURE_MATRIX
, STATE_MATRIX_INVTRANS
);
220 MATRIX(gl_TextureMatrixTranspose
,
221 STATE_TEXTURE_MATRIX
, 0);
222 MATRIX(gl_TextureMatrixInverseTranspose
,
223 STATE_TEXTURE_MATRIX
, STATE_MATRIX_INVERSE
);
225 static struct gl_builtin_uniform_element gl_NormalMatrix_elements
[] = {
226 { NULL
, { STATE_MODELVIEW_MATRIX
, 0, 0, 0, STATE_MATRIX_INVERSE
},
228 { NULL
, { STATE_MODELVIEW_MATRIX
, 0, 1, 1, STATE_MATRIX_INVERSE
},
230 { NULL
, { STATE_MODELVIEW_MATRIX
, 0, 2, 2, STATE_MATRIX_INVERSE
},
236 #define STATEVAR(name) {#name, name ## _elements, Elements(name ## _elements)}
238 const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc
[] = {
239 STATEVAR(gl_DepthRange
),
240 STATEVAR(gl_ClipPlane
),
242 STATEVAR(gl_FrontMaterial
),
243 STATEVAR(gl_BackMaterial
),
244 STATEVAR(gl_LightSource
),
245 STATEVAR(gl_LightModel
),
246 STATEVAR(gl_FrontLightModelProduct
),
247 STATEVAR(gl_BackLightModelProduct
),
248 STATEVAR(gl_FrontLightProduct
),
249 STATEVAR(gl_BackLightProduct
),
250 STATEVAR(gl_TextureEnvColor
),
251 STATEVAR(gl_EyePlaneS
),
252 STATEVAR(gl_EyePlaneT
),
253 STATEVAR(gl_EyePlaneR
),
254 STATEVAR(gl_EyePlaneQ
),
255 STATEVAR(gl_ObjectPlaneS
),
256 STATEVAR(gl_ObjectPlaneT
),
257 STATEVAR(gl_ObjectPlaneR
),
258 STATEVAR(gl_ObjectPlaneQ
),
261 STATEVAR(gl_ModelViewMatrix
),
262 STATEVAR(gl_ModelViewMatrixInverse
),
263 STATEVAR(gl_ModelViewMatrixTranspose
),
264 STATEVAR(gl_ModelViewMatrixInverseTranspose
),
266 STATEVAR(gl_ProjectionMatrix
),
267 STATEVAR(gl_ProjectionMatrixInverse
),
268 STATEVAR(gl_ProjectionMatrixTranspose
),
269 STATEVAR(gl_ProjectionMatrixInverseTranspose
),
271 STATEVAR(gl_ModelViewProjectionMatrix
),
272 STATEVAR(gl_ModelViewProjectionMatrixInverse
),
273 STATEVAR(gl_ModelViewProjectionMatrixTranspose
),
274 STATEVAR(gl_ModelViewProjectionMatrixInverseTranspose
),
276 STATEVAR(gl_TextureMatrix
),
277 STATEVAR(gl_TextureMatrixInverse
),
278 STATEVAR(gl_TextureMatrixTranspose
),
279 STATEVAR(gl_TextureMatrixInverseTranspose
),
281 STATEVAR(gl_NormalMatrix
),
282 STATEVAR(gl_NormalScale
),
284 STATEVAR(gl_MESABumpRotMatrix0
),
285 STATEVAR(gl_MESABumpRotMatrix1
),
286 STATEVAR(gl_MESAFogParamsOptimized
),
292 add_variable(exec_list
*instructions
, glsl_symbol_table
*symtab
,
293 const char *name
, const glsl_type
*type
,
294 enum ir_variable_mode mode
, int slot
)
296 ir_variable
*var
= new(symtab
) ir_variable(type
, name
, mode
);
301 case ir_var_const_in
:
303 case ir_var_system_value
:
304 var
->read_only
= true;
314 var
->location
= slot
;
315 var
->explicit_location
= (slot
>= 0);
317 /* Once the variable is created an initialized, add it to the symbol table
318 * and add the declaration to the IR stream.
320 instructions
->push_tail(var
);
322 symtab
->add_variable(var
);
327 add_uniform(exec_list
*instructions
, glsl_symbol_table
*symtab
,
328 const char *name
, const glsl_type
*type
)
330 ir_variable
*const uni
=
331 add_variable(instructions
, symtab
, name
, type
, ir_var_uniform
, -1);
334 for (i
= 0; _mesa_builtin_uniform_desc
[i
].name
!= NULL
; i
++) {
335 if (strcmp(_mesa_builtin_uniform_desc
[i
].name
, name
) == 0) {
340 assert(_mesa_builtin_uniform_desc
[i
].name
!= NULL
);
341 const struct gl_builtin_uniform_desc
* const statevar
=
342 &_mesa_builtin_uniform_desc
[i
];
344 const unsigned array_count
= type
->is_array() ? type
->length
: 1;
345 uni
->num_state_slots
= array_count
* statevar
->num_elements
;
347 ir_state_slot
*slots
=
348 ralloc_array(uni
, ir_state_slot
, uni
->num_state_slots
);
350 uni
->state_slots
= slots
;
352 for (unsigned a
= 0; a
< array_count
; a
++) {
353 for (unsigned j
= 0; j
< statevar
->num_elements
; j
++) {
354 struct gl_builtin_uniform_element
*element
= &statevar
->elements
[j
];
356 memcpy(slots
->tokens
, element
->tokens
, sizeof(element
->tokens
));
357 if (type
->is_array()) {
358 slots
->tokens
[1] = a
;
361 slots
->swizzle
= element
->swizzle
;
370 add_builtin_variable(exec_list
*instructions
, glsl_symbol_table
*symtab
,
371 const builtin_variable
*proto
)
373 /* Create a new variable declaration from the description supplied by
376 const glsl_type
*const type
= symtab
->get_type(proto
->type
);
378 assert(type
!= NULL
);
380 if (proto
->mode
== ir_var_uniform
) {
381 add_uniform(instructions
, symtab
, proto
->name
, type
);
383 add_variable(instructions
, symtab
, proto
->name
, type
, proto
->mode
,
389 add_builtin_constant(exec_list
*instructions
, glsl_symbol_table
*symtab
,
390 const char *name
, int value
)
392 ir_variable
*const var
= add_variable(instructions
, symtab
,
393 name
, glsl_type::int_type
,
395 var
->constant_value
= new(var
) ir_constant(value
);
398 /* Several constants in GLSL ES have different names than normal desktop GLSL.
399 * Therefore, this function should only be called on the ES path.
402 generate_100ES_uniforms(exec_list
*instructions
,
403 struct _mesa_glsl_parse_state
*state
)
405 glsl_symbol_table
*const symtab
= state
->symbols
;
407 add_builtin_constant(instructions
, symtab
, "gl_MaxVertexAttribs",
408 state
->Const
.MaxVertexAttribs
);
409 add_builtin_constant(instructions
, symtab
, "gl_MaxVertexUniformVectors",
410 state
->Const
.MaxVertexUniformComponents
);
411 add_builtin_constant(instructions
, symtab
, "gl_MaxVaryingVectors",
412 state
->Const
.MaxVaryingFloats
/ 4);
413 add_builtin_constant(instructions
, symtab
, "gl_MaxVertexTextureImageUnits",
414 state
->Const
.MaxVertexTextureImageUnits
);
415 add_builtin_constant(instructions
, symtab
, "gl_MaxCombinedTextureImageUnits",
416 state
->Const
.MaxCombinedTextureImageUnits
);
417 add_builtin_constant(instructions
, symtab
, "gl_MaxTextureImageUnits",
418 state
->Const
.MaxTextureImageUnits
);
419 add_builtin_constant(instructions
, symtab
, "gl_MaxFragmentUniformVectors",
420 state
->Const
.MaxFragmentUniformComponents
);
422 add_uniform(instructions
, symtab
, "gl_DepthRange",
423 state
->symbols
->get_type("gl_DepthRangeParameters"));
427 generate_110_uniforms(exec_list
*instructions
,
428 struct _mesa_glsl_parse_state
*state
)
430 glsl_symbol_table
*const symtab
= state
->symbols
;
433 ; i
< Elements(builtin_110_deprecated_uniforms
)
435 add_builtin_variable(instructions
, symtab
,
436 & builtin_110_deprecated_uniforms
[i
]);
439 add_builtin_constant(instructions
, symtab
, "gl_MaxLights",
440 state
->Const
.MaxLights
);
441 add_builtin_constant(instructions
, symtab
, "gl_MaxClipPlanes",
442 state
->Const
.MaxClipPlanes
);
443 add_builtin_constant(instructions
, symtab
, "gl_MaxTextureUnits",
444 state
->Const
.MaxTextureUnits
);
445 add_builtin_constant(instructions
, symtab
, "gl_MaxTextureCoords",
446 state
->Const
.MaxTextureCoords
);
447 add_builtin_constant(instructions
, symtab
, "gl_MaxVertexAttribs",
448 state
->Const
.MaxVertexAttribs
);
449 add_builtin_constant(instructions
, symtab
, "gl_MaxVertexUniformComponents",
450 state
->Const
.MaxVertexUniformComponents
);
451 add_builtin_constant(instructions
, symtab
, "gl_MaxVaryingFloats",
452 state
->Const
.MaxVaryingFloats
);
453 add_builtin_constant(instructions
, symtab
, "gl_MaxVertexTextureImageUnits",
454 state
->Const
.MaxVertexTextureImageUnits
);
455 add_builtin_constant(instructions
, symtab
, "gl_MaxCombinedTextureImageUnits",
456 state
->Const
.MaxCombinedTextureImageUnits
);
457 add_builtin_constant(instructions
, symtab
, "gl_MaxTextureImageUnits",
458 state
->Const
.MaxTextureImageUnits
);
459 add_builtin_constant(instructions
, symtab
, "gl_MaxFragmentUniformComponents",
460 state
->Const
.MaxFragmentUniformComponents
);
462 const glsl_type
*const mat4_array_type
=
463 glsl_type::get_array_instance(glsl_type::mat4_type
,
464 state
->Const
.MaxTextureCoords
);
466 add_uniform(instructions
, symtab
, "gl_TextureMatrix", mat4_array_type
);
467 add_uniform(instructions
, symtab
, "gl_TextureMatrixInverse", mat4_array_type
);
468 add_uniform(instructions
, symtab
, "gl_TextureMatrixTranspose", mat4_array_type
);
469 add_uniform(instructions
, symtab
, "gl_TextureMatrixInverseTranspose", mat4_array_type
);
471 add_uniform(instructions
, symtab
, "gl_DepthRange",
472 symtab
->get_type("gl_DepthRangeParameters"));
474 add_uniform(instructions
, symtab
, "gl_ClipPlane",
475 glsl_type::get_array_instance(glsl_type::vec4_type
,
476 state
->Const
.MaxClipPlanes
));
477 add_uniform(instructions
, symtab
, "gl_Point",
478 symtab
->get_type("gl_PointParameters"));
480 const glsl_type
*const material_parameters_type
=
481 symtab
->get_type("gl_MaterialParameters");
482 add_uniform(instructions
, symtab
, "gl_FrontMaterial", material_parameters_type
);
483 add_uniform(instructions
, symtab
, "gl_BackMaterial", material_parameters_type
);
485 const glsl_type
*const light_source_array_type
=
486 glsl_type::get_array_instance(symtab
->get_type("gl_LightSourceParameters"), state
->Const
.MaxLights
);
488 add_uniform(instructions
, symtab
, "gl_LightSource", light_source_array_type
);
490 const glsl_type
*const light_model_products_type
=
491 symtab
->get_type("gl_LightModelProducts");
492 add_uniform(instructions
, symtab
, "gl_FrontLightModelProduct",
493 light_model_products_type
);
494 add_uniform(instructions
, symtab
, "gl_BackLightModelProduct",
495 light_model_products_type
);
497 const glsl_type
*const light_products_type
=
498 glsl_type::get_array_instance(symtab
->get_type("gl_LightProducts"),
499 state
->Const
.MaxLights
);
500 add_uniform(instructions
, symtab
, "gl_FrontLightProduct", light_products_type
);
501 add_uniform(instructions
, symtab
, "gl_BackLightProduct", light_products_type
);
503 add_uniform(instructions
, symtab
, "gl_TextureEnvColor",
504 glsl_type::get_array_instance(glsl_type::vec4_type
,
505 state
->Const
.MaxTextureUnits
));
507 const glsl_type
*const texcoords_vec4
=
508 glsl_type::get_array_instance(glsl_type::vec4_type
,
509 state
->Const
.MaxTextureCoords
);
510 add_uniform(instructions
, symtab
, "gl_EyePlaneS", texcoords_vec4
);
511 add_uniform(instructions
, symtab
, "gl_EyePlaneT", texcoords_vec4
);
512 add_uniform(instructions
, symtab
, "gl_EyePlaneR", texcoords_vec4
);
513 add_uniform(instructions
, symtab
, "gl_EyePlaneQ", texcoords_vec4
);
514 add_uniform(instructions
, symtab
, "gl_ObjectPlaneS", texcoords_vec4
);
515 add_uniform(instructions
, symtab
, "gl_ObjectPlaneT", texcoords_vec4
);
516 add_uniform(instructions
, symtab
, "gl_ObjectPlaneR", texcoords_vec4
);
517 add_uniform(instructions
, symtab
, "gl_ObjectPlaneQ", texcoords_vec4
);
519 add_uniform(instructions
, symtab
, "gl_Fog",
520 symtab
->get_type("gl_FogParameters"));
523 /* This function should only be called for ES, not desktop GL. */
525 generate_100ES_vs_variables(exec_list
*instructions
,
526 struct _mesa_glsl_parse_state
*state
)
528 for (unsigned i
= 0; i
< Elements(builtin_core_vs_variables
); i
++) {
529 add_builtin_variable(instructions
, state
->symbols
,
530 & builtin_core_vs_variables
[i
]);
533 generate_100ES_uniforms(instructions
, state
);
535 generate_ARB_draw_buffers_variables(instructions
, state
, false,
541 generate_110_vs_variables(exec_list
*instructions
,
542 struct _mesa_glsl_parse_state
*state
)
544 for (unsigned i
= 0; i
< Elements(builtin_core_vs_variables
); i
++) {
545 add_builtin_variable(instructions
, state
->symbols
,
546 & builtin_core_vs_variables
[i
]);
550 ; i
< Elements(builtin_110_deprecated_vs_variables
)
552 add_builtin_variable(instructions
, state
->symbols
,
553 & builtin_110_deprecated_vs_variables
[i
]);
555 generate_110_uniforms(instructions
, state
);
557 /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec:
559 * "As with all arrays, indices used to subscript gl_TexCoord must
560 * either be an integral constant expressions, or this array must be
561 * re-declared by the shader with a size. The size can be at most
562 * gl_MaxTextureCoords. Using indexes close to 0 may aid the
563 * implementation in preserving varying resources."
565 const glsl_type
*const vec4_array_type
=
566 glsl_type::get_array_instance(glsl_type::vec4_type
, 0);
568 add_variable(instructions
, state
->symbols
,
569 "gl_TexCoord", vec4_array_type
, ir_var_out
, VERT_RESULT_TEX0
);
571 generate_ARB_draw_buffers_variables(instructions
, state
, false,
577 generate_120_vs_variables(exec_list
*instructions
,
578 struct _mesa_glsl_parse_state
*state
)
580 /* GLSL version 1.20 did not add any built-in variables in the vertex
583 generate_110_vs_variables(instructions
, state
);
588 generate_130_vs_variables(exec_list
*instructions
,
589 struct _mesa_glsl_parse_state
*state
)
591 generate_120_vs_variables(instructions
, state
);
593 for (unsigned i
= 0; i
< Elements(builtin_130_vs_variables
); i
++) {
594 add_builtin_variable(instructions
, state
->symbols
,
595 & builtin_130_vs_variables
[i
]);
598 const glsl_type
*const clip_distance_array_type
=
599 glsl_type::get_array_instance(glsl_type::float_type
,
600 state
->Const
.MaxClipPlanes
);
602 /* FINISHME: gl_ClipDistance needs a real location assigned. */
603 add_variable(instructions
, state
->symbols
,
604 "gl_ClipDistance", clip_distance_array_type
, ir_var_out
, -1);
610 initialize_vs_variables(exec_list
*instructions
,
611 struct _mesa_glsl_parse_state
*state
)
614 switch (state
->language_version
) {
616 generate_100ES_vs_variables(instructions
, state
);
619 generate_110_vs_variables(instructions
, state
);
622 generate_120_vs_variables(instructions
, state
);
625 generate_130_vs_variables(instructions
, state
);
629 if (state
->ARB_draw_instanced_enable
)
630 generate_ARB_draw_instanced_variables(instructions
, state
, false,
635 /* This function should only be called for ES, not desktop GL. */
637 generate_100ES_fs_variables(exec_list
*instructions
,
638 struct _mesa_glsl_parse_state
*state
)
640 for (unsigned i
= 0; i
< Elements(builtin_core_fs_variables
); i
++) {
641 add_builtin_variable(instructions
, state
->symbols
,
642 & builtin_core_fs_variables
[i
]);
645 for (unsigned i
= 0; i
< Elements(builtin_100ES_fs_variables
); i
++) {
646 add_builtin_variable(instructions
, state
->symbols
,
647 & builtin_100ES_fs_variables
[i
]);
650 generate_100ES_uniforms(instructions
, state
);
652 generate_ARB_draw_buffers_variables(instructions
, state
, false,
657 generate_110_fs_variables(exec_list
*instructions
,
658 struct _mesa_glsl_parse_state
*state
)
660 for (unsigned i
= 0; i
< Elements(builtin_core_fs_variables
); i
++) {
661 add_builtin_variable(instructions
, state
->symbols
,
662 & builtin_core_fs_variables
[i
]);
665 for (unsigned i
= 0; i
< Elements(builtin_110_fs_variables
); i
++) {
666 add_builtin_variable(instructions
, state
->symbols
,
667 & builtin_110_fs_variables
[i
]);
671 ; i
< Elements(builtin_110_deprecated_fs_variables
)
673 add_builtin_variable(instructions
, state
->symbols
,
674 & builtin_110_deprecated_fs_variables
[i
]);
676 generate_110_uniforms(instructions
, state
);
678 /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec:
680 * "As with all arrays, indices used to subscript gl_TexCoord must
681 * either be an integral constant expressions, or this array must be
682 * re-declared by the shader with a size. The size can be at most
683 * gl_MaxTextureCoords. Using indexes close to 0 may aid the
684 * implementation in preserving varying resources."
686 const glsl_type
*const vec4_array_type
=
687 glsl_type::get_array_instance(glsl_type::vec4_type
, 0);
689 add_variable(instructions
, state
->symbols
,
690 "gl_TexCoord", vec4_array_type
, ir_var_in
, FRAG_ATTRIB_TEX0
);
692 generate_ARB_draw_buffers_variables(instructions
, state
, false,
698 generate_ARB_draw_buffers_variables(exec_list
*instructions
,
699 struct _mesa_glsl_parse_state
*state
,
700 bool warn
, _mesa_glsl_parser_targets target
)
702 /* gl_MaxDrawBuffers is available in all shader stages.
704 ir_variable
*const mdb
=
705 add_variable(instructions
, state
->symbols
,
706 "gl_MaxDrawBuffers", glsl_type::int_type
, ir_var_auto
, -1);
709 mdb
->warn_extension
= "GL_ARB_draw_buffers";
711 mdb
->constant_value
= new(mdb
)
712 ir_constant(int(state
->Const
.MaxDrawBuffers
));
715 /* gl_FragData is only available in the fragment shader.
717 if (target
== fragment_shader
) {
718 const glsl_type
*const vec4_array_type
=
719 glsl_type::get_array_instance(glsl_type::vec4_type
,
720 state
->Const
.MaxDrawBuffers
);
722 ir_variable
*const fd
=
723 add_variable(instructions
, state
->symbols
,
724 "gl_FragData", vec4_array_type
,
725 ir_var_out
, FRAG_RESULT_DATA0
);
728 fd
->warn_extension
= "GL_ARB_draw_buffers";
734 generate_ARB_draw_instanced_variables(exec_list
*instructions
,
735 struct _mesa_glsl_parse_state
*state
,
737 _mesa_glsl_parser_targets target
)
739 /* gl_InstanceIDARB is only available in the vertex shader.
741 if (target
== vertex_shader
) {
742 ir_variable
*const inst
=
743 add_variable(instructions
, state
->symbols
,
744 "gl_InstanceIDARB", glsl_type::int_type
,
745 ir_var_system_value
, SYSTEM_VALUE_INSTANCE_ID
);
748 inst
->warn_extension
= "GL_ARB_draw_instanced";
754 generate_ARB_shader_stencil_export_variables(exec_list
*instructions
,
755 struct _mesa_glsl_parse_state
*state
,
758 /* gl_FragStencilRefARB is only available in the fragment shader.
760 ir_variable
*const fd
=
761 add_variable(instructions
, state
->symbols
,
762 "gl_FragStencilRefARB", glsl_type::int_type
,
763 ir_var_out
, FRAG_RESULT_STENCIL
);
766 fd
->warn_extension
= "GL_ARB_shader_stencil_export";
770 generate_AMD_shader_stencil_export_variables(exec_list
*instructions
,
771 struct _mesa_glsl_parse_state
*state
,
774 /* gl_FragStencilRefAMD is only available in the fragment shader.
776 ir_variable
*const fd
=
777 add_variable(instructions
, state
->symbols
,
778 "gl_FragStencilRefAMD", glsl_type::int_type
,
779 ir_var_out
, FRAG_RESULT_STENCIL
);
782 fd
->warn_extension
= "GL_AMD_shader_stencil_export";
786 generate_120_fs_variables(exec_list
*instructions
,
787 struct _mesa_glsl_parse_state
*state
)
789 generate_110_fs_variables(instructions
, state
);
792 ; i
< Elements(builtin_120_fs_variables
)
794 add_builtin_variable(instructions
, state
->symbols
,
795 & builtin_120_fs_variables
[i
]);
800 generate_130_fs_variables(exec_list
*instructions
,
801 struct _mesa_glsl_parse_state
*state
)
803 generate_120_fs_variables(instructions
, state
);
805 const glsl_type
*const clip_distance_array_type
=
806 glsl_type::get_array_instance(glsl_type::float_type
,
807 state
->Const
.MaxClipPlanes
);
809 /* FINISHME: gl_ClipDistance needs a real location assigned. */
810 add_variable(instructions
, state
->symbols
,
811 "gl_ClipDistance", clip_distance_array_type
, ir_var_in
, -1);
815 initialize_fs_variables(exec_list
*instructions
,
816 struct _mesa_glsl_parse_state
*state
)
819 switch (state
->language_version
) {
821 generate_100ES_fs_variables(instructions
, state
);
824 generate_110_fs_variables(instructions
, state
);
827 generate_120_fs_variables(instructions
, state
);
830 generate_130_fs_variables(instructions
, state
);
834 if (state
->ARB_shader_stencil_export_enable
)
835 generate_ARB_shader_stencil_export_variables(instructions
, state
,
836 state
->ARB_shader_stencil_export_warn
);
838 if (state
->AMD_shader_stencil_export_enable
)
839 generate_AMD_shader_stencil_export_variables(instructions
, state
,
840 state
->AMD_shader_stencil_export_warn
);
844 _mesa_glsl_initialize_variables(exec_list
*instructions
,
845 struct _mesa_glsl_parse_state
*state
)
847 switch (state
->target
) {
849 initialize_vs_variables(instructions
, state
);
851 case geometry_shader
:
853 case fragment_shader
:
854 initialize_fs_variables(instructions
, state
);