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 "main/core.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
);
43 generate_AMD_vertex_shader_layer_variables(exec_list
*instructions
,
44 struct _mesa_glsl_parse_state
*state
,
46 _mesa_glsl_parser_targets target
);
48 struct builtin_variable
{
49 enum ir_variable_mode mode
;
55 static const builtin_variable builtin_core_vs_variables
[] = {
56 { ir_var_shader_out
, VARYING_SLOT_POS
, "vec4", "gl_Position" },
57 { ir_var_shader_out
, VARYING_SLOT_PSIZ
, "float", "gl_PointSize" },
60 static const builtin_variable builtin_core_fs_variables
[] = {
61 { ir_var_shader_in
, VARYING_SLOT_POS
, "vec4", "gl_FragCoord" },
62 { ir_var_shader_in
, VARYING_SLOT_FACE
, "bool", "gl_FrontFacing" },
63 { ir_var_shader_out
, FRAG_RESULT_COLOR
, "vec4", "gl_FragColor" },
66 static const builtin_variable builtin_100ES_fs_variables
[] = {
67 { ir_var_shader_in
, VARYING_SLOT_PNTC
, "vec2", "gl_PointCoord" },
70 static const builtin_variable builtin_300ES_vs_variables
[] = {
71 { ir_var_system_value
, SYSTEM_VALUE_VERTEX_ID
, "int", "gl_VertexID" },
74 static const builtin_variable builtin_300ES_fs_variables
[] = {
75 { ir_var_shader_in
, VARYING_SLOT_POS
, "vec4", "gl_FragCoord" },
76 { ir_var_shader_in
, VARYING_SLOT_FACE
, "bool", "gl_FrontFacing" },
77 { ir_var_shader_out
, FRAG_RESULT_DEPTH
, "float", "gl_FragDepth" },
78 { ir_var_shader_in
, VARYING_SLOT_PNTC
, "vec2", "gl_PointCoord" },
81 static const builtin_variable builtin_110_fs_variables
[] = {
82 { ir_var_shader_out
, FRAG_RESULT_DEPTH
, "float", "gl_FragDepth" },
85 static const builtin_variable builtin_110_deprecated_fs_variables
[] = {
86 { ir_var_shader_in
, VARYING_SLOT_COL0
, "vec4", "gl_Color" },
87 { ir_var_shader_in
, VARYING_SLOT_COL1
, "vec4", "gl_SecondaryColor" },
88 { ir_var_shader_in
, VARYING_SLOT_FOGC
, "float", "gl_FogFragCoord" },
91 static const builtin_variable builtin_110_deprecated_vs_variables
[] = {
92 { ir_var_shader_in
, VERT_ATTRIB_POS
, "vec4", "gl_Vertex" },
93 { ir_var_shader_in
, VERT_ATTRIB_NORMAL
, "vec3", "gl_Normal" },
94 { ir_var_shader_in
, VERT_ATTRIB_COLOR0
, "vec4", "gl_Color" },
95 { ir_var_shader_in
, VERT_ATTRIB_COLOR1
, "vec4", "gl_SecondaryColor" },
96 { ir_var_shader_in
, VERT_ATTRIB_TEX0
, "vec4", "gl_MultiTexCoord0" },
97 { ir_var_shader_in
, VERT_ATTRIB_TEX1
, "vec4", "gl_MultiTexCoord1" },
98 { ir_var_shader_in
, VERT_ATTRIB_TEX2
, "vec4", "gl_MultiTexCoord2" },
99 { ir_var_shader_in
, VERT_ATTRIB_TEX3
, "vec4", "gl_MultiTexCoord3" },
100 { ir_var_shader_in
, VERT_ATTRIB_TEX4
, "vec4", "gl_MultiTexCoord4" },
101 { ir_var_shader_in
, VERT_ATTRIB_TEX5
, "vec4", "gl_MultiTexCoord5" },
102 { ir_var_shader_in
, VERT_ATTRIB_TEX6
, "vec4", "gl_MultiTexCoord6" },
103 { ir_var_shader_in
, VERT_ATTRIB_TEX7
, "vec4", "gl_MultiTexCoord7" },
104 { ir_var_shader_in
, VERT_ATTRIB_FOG
, "float", "gl_FogCoord" },
105 { ir_var_shader_out
, VARYING_SLOT_CLIP_VERTEX
, "vec4", "gl_ClipVertex" },
106 { ir_var_shader_out
, VARYING_SLOT_COL0
, "vec4", "gl_FrontColor" },
107 { ir_var_shader_out
, VARYING_SLOT_BFC0
, "vec4", "gl_BackColor" },
108 { ir_var_shader_out
, VARYING_SLOT_COL1
, "vec4", "gl_FrontSecondaryColor" },
109 { ir_var_shader_out
, VARYING_SLOT_BFC1
, "vec4", "gl_BackSecondaryColor" },
110 { ir_var_shader_out
, VARYING_SLOT_FOGC
, "float", "gl_FogFragCoord" },
113 static const builtin_variable builtin_120_fs_variables
[] = {
114 { ir_var_shader_in
, VARYING_SLOT_PNTC
, "vec2", "gl_PointCoord" },
117 static const builtin_variable builtin_130_vs_variables
[] = {
118 { ir_var_system_value
, SYSTEM_VALUE_VERTEX_ID
, "int", "gl_VertexID" },
121 static const builtin_variable builtin_110_deprecated_uniforms
[] = {
122 { ir_var_uniform
, -1, "mat4", "gl_ModelViewMatrix" },
123 { ir_var_uniform
, -1, "mat4", "gl_ProjectionMatrix" },
124 { ir_var_uniform
, -1, "mat4", "gl_ModelViewProjectionMatrix" },
125 { ir_var_uniform
, -1, "mat3", "gl_NormalMatrix" },
126 { ir_var_uniform
, -1, "mat4", "gl_ModelViewMatrixInverse" },
127 { ir_var_uniform
, -1, "mat4", "gl_ProjectionMatrixInverse" },
128 { ir_var_uniform
, -1, "mat4", "gl_ModelViewProjectionMatrixInverse" },
129 { ir_var_uniform
, -1, "mat4", "gl_ModelViewMatrixTranspose" },
130 { ir_var_uniform
, -1, "mat4", "gl_ProjectionMatrixTranspose" },
131 { ir_var_uniform
, -1, "mat4", "gl_ModelViewProjectionMatrixTranspose" },
132 { ir_var_uniform
, -1, "mat4", "gl_ModelViewMatrixInverseTranspose" },
133 { ir_var_uniform
, -1, "mat4", "gl_ProjectionMatrixInverseTranspose" },
134 { ir_var_uniform
, -1, "mat4", "gl_ModelViewProjectionMatrixInverseTranspose" },
135 { ir_var_uniform
, -1, "float", "gl_NormalScale" },
136 { ir_var_uniform
, -1, "gl_LightModelParameters", "gl_LightModel"},
138 /* Mesa-internal ATI_envmap_bumpmap state. */
139 { ir_var_uniform
, -1, "vec2", "gl_BumpRotMatrix0MESA"},
140 { ir_var_uniform
, -1, "vec2", "gl_BumpRotMatrix1MESA"},
141 { ir_var_uniform
, -1, "vec4", "gl_FogParamsOptimizedMESA"},
144 static struct gl_builtin_uniform_element gl_DepthRange_elements
[] = {
145 {"near", {STATE_DEPTH_RANGE
, 0, 0}, SWIZZLE_XXXX
},
146 {"far", {STATE_DEPTH_RANGE
, 0, 0}, SWIZZLE_YYYY
},
147 {"diff", {STATE_DEPTH_RANGE
, 0, 0}, SWIZZLE_ZZZZ
},
150 static struct gl_builtin_uniform_element gl_ClipPlane_elements
[] = {
151 {NULL
, {STATE_CLIPPLANE
, 0, 0}, SWIZZLE_XYZW
}
154 static struct gl_builtin_uniform_element gl_Point_elements
[] = {
155 {"size", {STATE_POINT_SIZE
}, SWIZZLE_XXXX
},
156 {"sizeMin", {STATE_POINT_SIZE
}, SWIZZLE_YYYY
},
157 {"sizeMax", {STATE_POINT_SIZE
}, SWIZZLE_ZZZZ
},
158 {"fadeThresholdSize", {STATE_POINT_SIZE
}, SWIZZLE_WWWW
},
159 {"distanceConstantAttenuation", {STATE_POINT_ATTENUATION
}, SWIZZLE_XXXX
},
160 {"distanceLinearAttenuation", {STATE_POINT_ATTENUATION
}, SWIZZLE_YYYY
},
161 {"distanceQuadraticAttenuation", {STATE_POINT_ATTENUATION
}, SWIZZLE_ZZZZ
},
164 static struct gl_builtin_uniform_element gl_FrontMaterial_elements
[] = {
165 {"emission", {STATE_MATERIAL
, 0, STATE_EMISSION
}, SWIZZLE_XYZW
},
166 {"ambient", {STATE_MATERIAL
, 0, STATE_AMBIENT
}, SWIZZLE_XYZW
},
167 {"diffuse", {STATE_MATERIAL
, 0, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
168 {"specular", {STATE_MATERIAL
, 0, STATE_SPECULAR
}, SWIZZLE_XYZW
},
169 {"shininess", {STATE_MATERIAL
, 0, STATE_SHININESS
}, SWIZZLE_XXXX
},
172 static struct gl_builtin_uniform_element gl_BackMaterial_elements
[] = {
173 {"emission", {STATE_MATERIAL
, 1, STATE_EMISSION
}, SWIZZLE_XYZW
},
174 {"ambient", {STATE_MATERIAL
, 1, STATE_AMBIENT
}, SWIZZLE_XYZW
},
175 {"diffuse", {STATE_MATERIAL
, 1, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
176 {"specular", {STATE_MATERIAL
, 1, STATE_SPECULAR
}, SWIZZLE_XYZW
},
177 {"shininess", {STATE_MATERIAL
, 1, STATE_SHININESS
}, SWIZZLE_XXXX
},
180 static struct gl_builtin_uniform_element gl_LightSource_elements
[] = {
181 {"ambient", {STATE_LIGHT
, 0, STATE_AMBIENT
}, SWIZZLE_XYZW
},
182 {"diffuse", {STATE_LIGHT
, 0, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
183 {"specular", {STATE_LIGHT
, 0, STATE_SPECULAR
}, SWIZZLE_XYZW
},
184 {"position", {STATE_LIGHT
, 0, STATE_POSITION
}, SWIZZLE_XYZW
},
185 {"halfVector", {STATE_LIGHT
, 0, STATE_HALF_VECTOR
}, SWIZZLE_XYZW
},
186 {"spotDirection", {STATE_LIGHT
, 0, STATE_SPOT_DIRECTION
},
187 MAKE_SWIZZLE4(SWIZZLE_X
,
191 {"spotCosCutoff", {STATE_LIGHT
, 0, STATE_SPOT_DIRECTION
}, SWIZZLE_WWWW
},
192 {"spotCutoff", {STATE_LIGHT
, 0, STATE_SPOT_CUTOFF
}, SWIZZLE_XXXX
},
193 {"spotExponent", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_WWWW
},
194 {"constantAttenuation", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_XXXX
},
195 {"linearAttenuation", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_YYYY
},
196 {"quadraticAttenuation", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_ZZZZ
},
199 static struct gl_builtin_uniform_element gl_LightModel_elements
[] = {
200 {"ambient", {STATE_LIGHTMODEL_AMBIENT
, 0}, SWIZZLE_XYZW
},
203 static struct gl_builtin_uniform_element gl_FrontLightModelProduct_elements
[] = {
204 {"sceneColor", {STATE_LIGHTMODEL_SCENECOLOR
, 0}, SWIZZLE_XYZW
},
207 static struct gl_builtin_uniform_element gl_BackLightModelProduct_elements
[] = {
208 {"sceneColor", {STATE_LIGHTMODEL_SCENECOLOR
, 1}, SWIZZLE_XYZW
},
211 static struct gl_builtin_uniform_element gl_FrontLightProduct_elements
[] = {
212 {"ambient", {STATE_LIGHTPROD
, 0, 0, STATE_AMBIENT
}, SWIZZLE_XYZW
},
213 {"diffuse", {STATE_LIGHTPROD
, 0, 0, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
214 {"specular", {STATE_LIGHTPROD
, 0, 0, STATE_SPECULAR
}, SWIZZLE_XYZW
},
217 static struct gl_builtin_uniform_element gl_BackLightProduct_elements
[] = {
218 {"ambient", {STATE_LIGHTPROD
, 0, 1, STATE_AMBIENT
}, SWIZZLE_XYZW
},
219 {"diffuse", {STATE_LIGHTPROD
, 0, 1, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
220 {"specular", {STATE_LIGHTPROD
, 0, 1, STATE_SPECULAR
}, SWIZZLE_XYZW
},
223 static struct gl_builtin_uniform_element gl_TextureEnvColor_elements
[] = {
224 {NULL
, {STATE_TEXENV_COLOR
, 0}, SWIZZLE_XYZW
},
227 static struct gl_builtin_uniform_element gl_EyePlaneS_elements
[] = {
228 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_S
}, SWIZZLE_XYZW
},
231 static struct gl_builtin_uniform_element gl_EyePlaneT_elements
[] = {
232 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_T
}, SWIZZLE_XYZW
},
235 static struct gl_builtin_uniform_element gl_EyePlaneR_elements
[] = {
236 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_R
}, SWIZZLE_XYZW
},
239 static struct gl_builtin_uniform_element gl_EyePlaneQ_elements
[] = {
240 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_Q
}, SWIZZLE_XYZW
},
243 static struct gl_builtin_uniform_element gl_ObjectPlaneS_elements
[] = {
244 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_S
}, SWIZZLE_XYZW
},
247 static struct gl_builtin_uniform_element gl_ObjectPlaneT_elements
[] = {
248 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_T
}, SWIZZLE_XYZW
},
251 static struct gl_builtin_uniform_element gl_ObjectPlaneR_elements
[] = {
252 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_R
}, SWIZZLE_XYZW
},
255 static struct gl_builtin_uniform_element gl_ObjectPlaneQ_elements
[] = {
256 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_Q
}, SWIZZLE_XYZW
},
259 static struct gl_builtin_uniform_element gl_Fog_elements
[] = {
260 {"color", {STATE_FOG_COLOR
}, SWIZZLE_XYZW
},
261 {"density", {STATE_FOG_PARAMS
}, SWIZZLE_XXXX
},
262 {"start", {STATE_FOG_PARAMS
}, SWIZZLE_YYYY
},
263 {"end", {STATE_FOG_PARAMS
}, SWIZZLE_ZZZZ
},
264 {"scale", {STATE_FOG_PARAMS
}, SWIZZLE_WWWW
},
267 static struct gl_builtin_uniform_element gl_NormalScale_elements
[] = {
268 {NULL
, {STATE_NORMAL_SCALE
}, SWIZZLE_XXXX
},
271 static struct gl_builtin_uniform_element gl_BumpRotMatrix0MESA_elements
[] = {
272 {NULL
, {STATE_INTERNAL
, STATE_ROT_MATRIX_0
}, SWIZZLE_XYZW
},
275 static struct gl_builtin_uniform_element gl_BumpRotMatrix1MESA_elements
[] = {
276 {NULL
, {STATE_INTERNAL
, STATE_ROT_MATRIX_1
}, SWIZZLE_XYZW
},
279 static struct gl_builtin_uniform_element gl_FogParamsOptimizedMESA_elements
[] = {
280 {NULL
, {STATE_INTERNAL
, STATE_FOG_PARAMS_OPTIMIZED
}, SWIZZLE_XYZW
},
283 static struct gl_builtin_uniform_element gl_CurrentAttribVertMESA_elements
[] = {
284 {NULL
, {STATE_INTERNAL
, STATE_CURRENT_ATTRIB
, 0}, SWIZZLE_XYZW
},
287 static struct gl_builtin_uniform_element gl_CurrentAttribFragMESA_elements
[] = {
288 {NULL
, {STATE_INTERNAL
, STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED
, 0}, SWIZZLE_XYZW
},
291 #define MATRIX(name, statevar, modifier) \
292 static struct gl_builtin_uniform_element name ## _elements[] = { \
293 { NULL, { statevar, 0, 0, 0, modifier}, SWIZZLE_XYZW }, \
294 { NULL, { statevar, 0, 1, 1, modifier}, SWIZZLE_XYZW }, \
295 { NULL, { statevar, 0, 2, 2, modifier}, SWIZZLE_XYZW }, \
296 { NULL, { statevar, 0, 3, 3, modifier}, SWIZZLE_XYZW }, \
299 MATRIX(gl_ModelViewMatrix
,
300 STATE_MODELVIEW_MATRIX
, STATE_MATRIX_TRANSPOSE
);
301 MATRIX(gl_ModelViewMatrixInverse
,
302 STATE_MODELVIEW_MATRIX
, STATE_MATRIX_INVTRANS
);
303 MATRIX(gl_ModelViewMatrixTranspose
,
304 STATE_MODELVIEW_MATRIX
, 0);
305 MATRIX(gl_ModelViewMatrixInverseTranspose
,
306 STATE_MODELVIEW_MATRIX
, STATE_MATRIX_INVERSE
);
308 MATRIX(gl_ProjectionMatrix
,
309 STATE_PROJECTION_MATRIX
, STATE_MATRIX_TRANSPOSE
);
310 MATRIX(gl_ProjectionMatrixInverse
,
311 STATE_PROJECTION_MATRIX
, STATE_MATRIX_INVTRANS
);
312 MATRIX(gl_ProjectionMatrixTranspose
,
313 STATE_PROJECTION_MATRIX
, 0);
314 MATRIX(gl_ProjectionMatrixInverseTranspose
,
315 STATE_PROJECTION_MATRIX
, STATE_MATRIX_INVERSE
);
317 MATRIX(gl_ModelViewProjectionMatrix
,
318 STATE_MVP_MATRIX
, STATE_MATRIX_TRANSPOSE
);
319 MATRIX(gl_ModelViewProjectionMatrixInverse
,
320 STATE_MVP_MATRIX
, STATE_MATRIX_INVTRANS
);
321 MATRIX(gl_ModelViewProjectionMatrixTranspose
,
322 STATE_MVP_MATRIX
, 0);
323 MATRIX(gl_ModelViewProjectionMatrixInverseTranspose
,
324 STATE_MVP_MATRIX
, STATE_MATRIX_INVERSE
);
326 MATRIX(gl_TextureMatrix
,
327 STATE_TEXTURE_MATRIX
, STATE_MATRIX_TRANSPOSE
);
328 MATRIX(gl_TextureMatrixInverse
,
329 STATE_TEXTURE_MATRIX
, STATE_MATRIX_INVTRANS
);
330 MATRIX(gl_TextureMatrixTranspose
,
331 STATE_TEXTURE_MATRIX
, 0);
332 MATRIX(gl_TextureMatrixInverseTranspose
,
333 STATE_TEXTURE_MATRIX
, STATE_MATRIX_INVERSE
);
335 static struct gl_builtin_uniform_element gl_NormalMatrix_elements
[] = {
336 { NULL
, { STATE_MODELVIEW_MATRIX
, 0, 0, 0, STATE_MATRIX_INVERSE
},
337 MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_Z
) },
338 { NULL
, { STATE_MODELVIEW_MATRIX
, 0, 1, 1, STATE_MATRIX_INVERSE
},
339 MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_Z
) },
340 { NULL
, { STATE_MODELVIEW_MATRIX
, 0, 2, 2, STATE_MATRIX_INVERSE
},
341 MAKE_SWIZZLE4(SWIZZLE_X
, SWIZZLE_Y
, SWIZZLE_Z
, SWIZZLE_Z
) },
346 #define STATEVAR(name) {#name, name ## _elements, Elements(name ## _elements)}
348 static const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc
[] = {
349 STATEVAR(gl_DepthRange
),
350 STATEVAR(gl_ClipPlane
),
352 STATEVAR(gl_FrontMaterial
),
353 STATEVAR(gl_BackMaterial
),
354 STATEVAR(gl_LightSource
),
355 STATEVAR(gl_LightModel
),
356 STATEVAR(gl_FrontLightModelProduct
),
357 STATEVAR(gl_BackLightModelProduct
),
358 STATEVAR(gl_FrontLightProduct
),
359 STATEVAR(gl_BackLightProduct
),
360 STATEVAR(gl_TextureEnvColor
),
361 STATEVAR(gl_EyePlaneS
),
362 STATEVAR(gl_EyePlaneT
),
363 STATEVAR(gl_EyePlaneR
),
364 STATEVAR(gl_EyePlaneQ
),
365 STATEVAR(gl_ObjectPlaneS
),
366 STATEVAR(gl_ObjectPlaneT
),
367 STATEVAR(gl_ObjectPlaneR
),
368 STATEVAR(gl_ObjectPlaneQ
),
371 STATEVAR(gl_ModelViewMatrix
),
372 STATEVAR(gl_ModelViewMatrixInverse
),
373 STATEVAR(gl_ModelViewMatrixTranspose
),
374 STATEVAR(gl_ModelViewMatrixInverseTranspose
),
376 STATEVAR(gl_ProjectionMatrix
),
377 STATEVAR(gl_ProjectionMatrixInverse
),
378 STATEVAR(gl_ProjectionMatrixTranspose
),
379 STATEVAR(gl_ProjectionMatrixInverseTranspose
),
381 STATEVAR(gl_ModelViewProjectionMatrix
),
382 STATEVAR(gl_ModelViewProjectionMatrixInverse
),
383 STATEVAR(gl_ModelViewProjectionMatrixTranspose
),
384 STATEVAR(gl_ModelViewProjectionMatrixInverseTranspose
),
386 STATEVAR(gl_TextureMatrix
),
387 STATEVAR(gl_TextureMatrixInverse
),
388 STATEVAR(gl_TextureMatrixTranspose
),
389 STATEVAR(gl_TextureMatrixInverseTranspose
),
391 STATEVAR(gl_NormalMatrix
),
392 STATEVAR(gl_NormalScale
),
394 STATEVAR(gl_BumpRotMatrix0MESA
),
395 STATEVAR(gl_BumpRotMatrix1MESA
),
396 STATEVAR(gl_FogParamsOptimizedMESA
),
397 STATEVAR(gl_CurrentAttribVertMESA
),
398 STATEVAR(gl_CurrentAttribFragMESA
),
404 add_variable(exec_list
*instructions
, glsl_symbol_table
*symtab
,
405 const char *name
, const glsl_type
*type
,
406 enum ir_variable_mode mode
, int slot
)
408 ir_variable
*var
= new(symtab
) ir_variable(type
, name
, mode
);
412 case ir_var_shader_in
:
414 case ir_var_system_value
:
415 var
->read_only
= true;
417 case ir_var_shader_out
:
420 /* The only variables that are added using this function should be
421 * uniforms, shader inputs, and shader outputs, constants (which use
422 * ir_var_auto), and system values.
428 var
->location
= slot
;
429 var
->explicit_location
= (slot
>= 0);
430 var
->explicit_index
= 0;
432 /* Once the variable is created an initialized, add it to the symbol table
433 * and add the declaration to the IR stream.
435 instructions
->push_tail(var
);
437 symtab
->add_variable(var
);
442 add_uniform(exec_list
*instructions
, glsl_symbol_table
*symtab
,
443 const char *name
, const glsl_type
*type
)
445 ir_variable
*const uni
=
446 add_variable(instructions
, symtab
, name
, type
, ir_var_uniform
, -1);
449 for (i
= 0; _mesa_builtin_uniform_desc
[i
].name
!= NULL
; i
++) {
450 if (strcmp(_mesa_builtin_uniform_desc
[i
].name
, name
) == 0) {
455 assert(_mesa_builtin_uniform_desc
[i
].name
!= NULL
);
456 const struct gl_builtin_uniform_desc
* const statevar
=
457 &_mesa_builtin_uniform_desc
[i
];
459 const unsigned array_count
= type
->is_array() ? type
->length
: 1;
460 uni
->num_state_slots
= array_count
* statevar
->num_elements
;
462 ir_state_slot
*slots
=
463 ralloc_array(uni
, ir_state_slot
, uni
->num_state_slots
);
465 uni
->state_slots
= slots
;
467 for (unsigned a
= 0; a
< array_count
; a
++) {
468 for (unsigned j
= 0; j
< statevar
->num_elements
; j
++) {
469 struct gl_builtin_uniform_element
*element
= &statevar
->elements
[j
];
471 memcpy(slots
->tokens
, element
->tokens
, sizeof(element
->tokens
));
472 if (type
->is_array()) {
473 if (strcmp(name
, "gl_CurrentAttribVertMESA") == 0 ||
474 strcmp(name
, "gl_CurrentAttribFragMESA") == 0) {
475 slots
->tokens
[2] = a
;
477 slots
->tokens
[1] = a
;
481 slots
->swizzle
= element
->swizzle
;
490 add_builtin_variable(exec_list
*instructions
, glsl_symbol_table
*symtab
,
491 const builtin_variable
*proto
)
493 /* Create a new variable declaration from the description supplied by
496 const glsl_type
*const type
= symtab
->get_type(proto
->type
);
498 assert(type
!= NULL
);
500 if (proto
->mode
== ir_var_uniform
) {
501 add_uniform(instructions
, symtab
, proto
->name
, type
);
503 add_variable(instructions
, symtab
, proto
->name
, type
, proto
->mode
,
509 add_builtin_constant(exec_list
*instructions
, glsl_symbol_table
*symtab
,
510 const char *name
, int value
)
512 ir_variable
*const var
= add_variable(instructions
, symtab
,
513 name
, glsl_type::int_type
,
515 var
->constant_value
= new(var
) ir_constant(value
);
516 var
->constant_initializer
= new(var
) ir_constant(value
);
517 var
->has_initializer
= true;
522 * Uniforms that are common to all GLSL ES implementations.
524 * Several constants in GLSL ES have different names than normal desktop GLSL.
525 * Therefore, this function should only be called on the ES path.
528 generate_common_ES_uniforms(exec_list
*instructions
,
529 struct _mesa_glsl_parse_state
*state
)
531 glsl_symbol_table
*const symtab
= state
->symbols
;
533 add_builtin_constant(instructions
, symtab
, "gl_MaxVertexAttribs",
534 state
->Const
.MaxVertexAttribs
);
535 add_builtin_constant(instructions
, symtab
, "gl_MaxVertexUniformVectors",
536 state
->Const
.MaxVertexUniformComponents
/ 4);
537 add_builtin_constant(instructions
, symtab
, "gl_MaxVertexTextureImageUnits",
538 state
->Const
.MaxVertexTextureImageUnits
);
539 add_builtin_constant(instructions
, symtab
, "gl_MaxCombinedTextureImageUnits",
540 state
->Const
.MaxCombinedTextureImageUnits
);
541 add_builtin_constant(instructions
, symtab
, "gl_MaxTextureImageUnits",
542 state
->Const
.MaxTextureImageUnits
);
543 add_builtin_constant(instructions
, symtab
, "gl_MaxFragmentUniformVectors",
544 state
->Const
.MaxFragmentUniformComponents
/ 4);
546 add_uniform(instructions
, symtab
, "gl_DepthRange",
547 state
->symbols
->get_type("gl_DepthRangeParameters"));
551 generate_100ES_uniforms(exec_list
*instructions
,
552 struct _mesa_glsl_parse_state
*state
)
554 generate_common_ES_uniforms(instructions
, state
);
556 glsl_symbol_table
*const symtab
= state
->symbols
;
558 add_builtin_constant(instructions
, symtab
, "gl_MaxVaryingVectors",
559 state
->Const
.MaxVaryingFloats
/ 4);
563 generate_300ES_uniforms(exec_list
*instructions
,
564 struct _mesa_glsl_parse_state
*state
)
566 generate_common_ES_uniforms(instructions
, state
);
568 glsl_symbol_table
*const symtab
= state
->symbols
;
570 add_builtin_constant(instructions
, symtab
, "gl_MaxVertexOutputVectors",
571 state
->Const
.MaxVaryingFloats
/ 4);
572 add_builtin_constant(instructions
, symtab
, "gl_MaxFragmentInputVectors",
573 state
->Const
.MaxVaryingFloats
/ 4);
574 add_builtin_constant(instructions
, symtab
, "gl_MinProgramTexelOffset",
575 state
->Const
.MinProgramTexelOffset
);
576 add_builtin_constant(instructions
, symtab
, "gl_MaxProgramTexelOffset",
577 state
->Const
.MaxProgramTexelOffset
);
581 generate_110_uniforms(exec_list
*instructions
,
582 struct _mesa_glsl_parse_state
*state
,
585 glsl_symbol_table
*const symtab
= state
->symbols
;
587 if (add_deprecated
) {
589 ; i
< Elements(builtin_110_deprecated_uniforms
)
591 add_builtin_variable(instructions
, symtab
,
592 & builtin_110_deprecated_uniforms
[i
]);
596 if (add_deprecated
) {
597 add_builtin_constant(instructions
, symtab
, "gl_MaxLights",
598 state
->Const
.MaxLights
);
599 add_builtin_constant(instructions
, symtab
, "gl_MaxClipPlanes",
600 state
->Const
.MaxClipPlanes
);
601 add_builtin_constant(instructions
, symtab
, "gl_MaxTextureUnits",
602 state
->Const
.MaxTextureUnits
);
603 add_builtin_constant(instructions
, symtab
, "gl_MaxTextureCoords",
604 state
->Const
.MaxTextureCoords
);
606 add_builtin_constant(instructions
, symtab
, "gl_MaxVertexAttribs",
607 state
->Const
.MaxVertexAttribs
);
608 add_builtin_constant(instructions
, symtab
, "gl_MaxVertexUniformComponents",
609 state
->Const
.MaxVertexUniformComponents
);
610 add_builtin_constant(instructions
, symtab
, "gl_MaxVaryingFloats",
611 state
->Const
.MaxVaryingFloats
);
612 add_builtin_constant(instructions
, symtab
, "gl_MaxVertexTextureImageUnits",
613 state
->Const
.MaxVertexTextureImageUnits
);
614 add_builtin_constant(instructions
, symtab
, "gl_MaxCombinedTextureImageUnits",
615 state
->Const
.MaxCombinedTextureImageUnits
);
616 add_builtin_constant(instructions
, symtab
, "gl_MaxTextureImageUnits",
617 state
->Const
.MaxTextureImageUnits
);
618 add_builtin_constant(instructions
, symtab
, "gl_MaxFragmentUniformComponents",
619 state
->Const
.MaxFragmentUniformComponents
);
621 if (add_deprecated
) {
622 const glsl_type
*const mat4_array_type
=
623 glsl_type::get_array_instance(glsl_type::mat4_type
,
624 state
->Const
.MaxTextureCoords
);
626 add_uniform(instructions
, symtab
, "gl_TextureMatrix", mat4_array_type
);
627 add_uniform(instructions
, symtab
, "gl_TextureMatrixInverse", mat4_array_type
);
628 add_uniform(instructions
, symtab
, "gl_TextureMatrixTranspose", mat4_array_type
);
629 add_uniform(instructions
, symtab
, "gl_TextureMatrixInverseTranspose", mat4_array_type
);
632 add_uniform(instructions
, symtab
, "gl_DepthRange",
633 symtab
->get_type("gl_DepthRangeParameters"));
635 if (add_deprecated
) {
636 add_uniform(instructions
, symtab
, "gl_ClipPlane",
637 glsl_type::get_array_instance(glsl_type::vec4_type
,
638 state
->Const
.MaxClipPlanes
));
639 add_uniform(instructions
, symtab
, "gl_Point",
640 symtab
->get_type("gl_PointParameters"));
642 const glsl_type
*const material_parameters_type
=
643 symtab
->get_type("gl_MaterialParameters");
644 add_uniform(instructions
, symtab
, "gl_FrontMaterial", material_parameters_type
);
645 add_uniform(instructions
, symtab
, "gl_BackMaterial", material_parameters_type
);
647 const glsl_type
*const light_source_array_type
=
648 glsl_type::get_array_instance(symtab
->get_type("gl_LightSourceParameters"), state
->Const
.MaxLights
);
650 add_uniform(instructions
, symtab
, "gl_LightSource", light_source_array_type
);
652 const glsl_type
*const light_model_products_type
=
653 symtab
->get_type("gl_LightModelProducts");
654 add_uniform(instructions
, symtab
, "gl_FrontLightModelProduct",
655 light_model_products_type
);
656 add_uniform(instructions
, symtab
, "gl_BackLightModelProduct",
657 light_model_products_type
);
659 const glsl_type
*const light_products_type
=
660 glsl_type::get_array_instance(symtab
->get_type("gl_LightProducts"),
661 state
->Const
.MaxLights
);
662 add_uniform(instructions
, symtab
, "gl_FrontLightProduct", light_products_type
);
663 add_uniform(instructions
, symtab
, "gl_BackLightProduct", light_products_type
);
665 add_uniform(instructions
, symtab
, "gl_TextureEnvColor",
666 glsl_type::get_array_instance(glsl_type::vec4_type
,
667 state
->Const
.MaxTextureUnits
));
669 const glsl_type
*const texcoords_vec4
=
670 glsl_type::get_array_instance(glsl_type::vec4_type
,
671 state
->Const
.MaxTextureCoords
);
672 add_uniform(instructions
, symtab
, "gl_EyePlaneS", texcoords_vec4
);
673 add_uniform(instructions
, symtab
, "gl_EyePlaneT", texcoords_vec4
);
674 add_uniform(instructions
, symtab
, "gl_EyePlaneR", texcoords_vec4
);
675 add_uniform(instructions
, symtab
, "gl_EyePlaneQ", texcoords_vec4
);
676 add_uniform(instructions
, symtab
, "gl_ObjectPlaneS", texcoords_vec4
);
677 add_uniform(instructions
, symtab
, "gl_ObjectPlaneT", texcoords_vec4
);
678 add_uniform(instructions
, symtab
, "gl_ObjectPlaneR", texcoords_vec4
);
679 add_uniform(instructions
, symtab
, "gl_ObjectPlaneQ", texcoords_vec4
);
681 add_uniform(instructions
, symtab
, "gl_Fog",
682 symtab
->get_type("gl_FogParameters"));
685 /* Mesa-internal current attrib state */
686 const glsl_type
*const vert_attribs
=
687 glsl_type::get_array_instance(glsl_type::vec4_type
, VERT_ATTRIB_MAX
);
688 add_uniform(instructions
, symtab
, "gl_CurrentAttribVertMESA", vert_attribs
);
689 const glsl_type
*const frag_attribs
=
690 glsl_type::get_array_instance(glsl_type::vec4_type
, VARYING_SLOT_MAX
);
691 add_uniform(instructions
, symtab
, "gl_CurrentAttribFragMESA", frag_attribs
);
694 /* This function should only be called for ES, not desktop GL. */
696 generate_100ES_vs_variables(exec_list
*instructions
,
697 struct _mesa_glsl_parse_state
*state
)
699 for (unsigned i
= 0; i
< Elements(builtin_core_vs_variables
); i
++) {
700 add_builtin_variable(instructions
, state
->symbols
,
701 & builtin_core_vs_variables
[i
]);
704 generate_100ES_uniforms(instructions
, state
);
706 generate_ARB_draw_buffers_variables(instructions
, state
, false,
711 generate_300ES_vs_variables(exec_list
*instructions
,
712 struct _mesa_glsl_parse_state
*state
)
714 for (unsigned i
= 0; i
< Elements(builtin_core_vs_variables
); i
++) {
715 add_builtin_variable(instructions
, state
->symbols
,
716 & builtin_core_vs_variables
[i
]);
719 for (unsigned i
= 0; i
< Elements(builtin_300ES_vs_variables
); i
++) {
720 add_builtin_variable(instructions
, state
->symbols
,
721 & builtin_300ES_vs_variables
[i
]);
724 generate_300ES_uniforms(instructions
, state
);
726 generate_ARB_draw_buffers_variables(instructions
, state
, false,
732 generate_110_vs_variables(exec_list
*instructions
,
733 struct _mesa_glsl_parse_state
*state
,
736 for (unsigned i
= 0; i
< Elements(builtin_core_vs_variables
); i
++) {
737 add_builtin_variable(instructions
, state
->symbols
,
738 & builtin_core_vs_variables
[i
]);
741 if (add_deprecated
) {
743 ; i
< Elements(builtin_110_deprecated_vs_variables
)
745 add_builtin_variable(instructions
, state
->symbols
,
746 & builtin_110_deprecated_vs_variables
[i
]);
749 generate_110_uniforms(instructions
, state
, add_deprecated
);
751 if (add_deprecated
) {
752 /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec:
754 * "As with all arrays, indices used to subscript gl_TexCoord must
755 * either be an integral constant expressions, or this array must be
756 * re-declared by the shader with a size. The size can be at most
757 * gl_MaxTextureCoords. Using indexes close to 0 may aid the
758 * implementation in preserving varying resources."
760 const glsl_type
*const vec4_array_type
=
761 glsl_type::get_array_instance(glsl_type::vec4_type
, 0);
763 add_variable(instructions
, state
->symbols
,
764 "gl_TexCoord", vec4_array_type
, ir_var_shader_out
,
768 generate_ARB_draw_buffers_variables(instructions
, state
, false,
774 generate_120_vs_variables(exec_list
*instructions
,
775 struct _mesa_glsl_parse_state
*state
,
778 /* GLSL version 1.20 did not add any built-in variables in the vertex
781 generate_110_vs_variables(instructions
, state
, add_deprecated
);
786 generate_130_uniforms(exec_list
*instructions
,
787 struct _mesa_glsl_parse_state
*state
)
789 glsl_symbol_table
*const symtab
= state
->symbols
;
791 add_builtin_constant(instructions
, symtab
, "gl_MaxClipDistances",
792 state
->Const
.MaxClipPlanes
);
793 add_builtin_constant(instructions
, symtab
, "gl_MaxVaryingComponents",
794 state
->Const
.MaxVaryingFloats
);
796 if (state
->ARB_shading_language_420pack_enable
) {
797 add_builtin_constant(instructions
, symtab
, "gl_MinProgramTexelOffset",
798 state
->Const
.MinProgramTexelOffset
);
799 add_builtin_constant(instructions
, symtab
, "gl_MaxProgramTexelOffset",
800 state
->Const
.MaxProgramTexelOffset
);
806 generate_130_vs_variables(exec_list
*instructions
,
807 struct _mesa_glsl_parse_state
*state
,
810 generate_120_vs_variables(instructions
, state
, add_deprecated
);
812 for (unsigned i
= 0; i
< Elements(builtin_130_vs_variables
); i
++) {
813 add_builtin_variable(instructions
, state
->symbols
,
814 & builtin_130_vs_variables
[i
]);
817 generate_130_uniforms(instructions
, state
);
819 /* From the GLSL 1.30 spec, section 7.1 (Vertex Shader Special
822 * The gl_ClipDistance array is predeclared as unsized and must
823 * be sized by the shader either redeclaring it with a size or
824 * indexing it only with integral constant expressions.
826 * We represent this in Mesa by initially declaring the array as
829 const glsl_type
*const clip_distance_array_type
=
830 glsl_type::get_array_instance(glsl_type::float_type
, 0);
832 add_variable(instructions
, state
->symbols
,
833 "gl_ClipDistance", clip_distance_array_type
, ir_var_shader_out
,
834 VARYING_SLOT_CLIP_DIST0
);
836 generate_AMD_vertex_shader_layer_variables(instructions
, state
, false,
842 initialize_vs_variables(exec_list
*instructions
,
843 struct _mesa_glsl_parse_state
*state
)
845 if (state
->es_shader
) {
846 switch (state
->language_version
) {
848 generate_100ES_vs_variables(instructions
, state
);
851 generate_300ES_vs_variables(instructions
, state
);
854 assert(!"Unexpected language version");
858 switch (state
->language_version
) {
860 generate_110_vs_variables(instructions
, state
, true);
863 generate_120_vs_variables(instructions
, state
, true);
866 generate_130_vs_variables(instructions
, state
, true);
870 generate_130_vs_variables(instructions
, state
, false);
873 assert(!"Unexpected language version");
878 generate_ARB_draw_instanced_variables(instructions
, state
, false,
883 /* This function should only be called for ES, not desktop GL. */
885 generate_100ES_fs_variables(exec_list
*instructions
,
886 struct _mesa_glsl_parse_state
*state
)
888 for (unsigned i
= 0; i
< Elements(builtin_core_fs_variables
); i
++) {
889 add_builtin_variable(instructions
, state
->symbols
,
890 & builtin_core_fs_variables
[i
]);
893 for (unsigned i
= 0; i
< Elements(builtin_100ES_fs_variables
); i
++) {
894 add_builtin_variable(instructions
, state
->symbols
,
895 & builtin_100ES_fs_variables
[i
]);
898 generate_100ES_uniforms(instructions
, state
);
900 generate_ARB_draw_buffers_variables(instructions
, state
, false,
905 generate_300ES_fs_variables(exec_list
*instructions
,
906 struct _mesa_glsl_parse_state
*state
)
908 /* Note: we don't add builtin_core_fs_variables, because it contains
909 * gl_FragColor, which is not in GLSL 3.00 ES.
912 for (unsigned i
= 0; i
< Elements(builtin_300ES_fs_variables
); i
++) {
913 add_builtin_variable(instructions
, state
->symbols
,
914 & builtin_300ES_fs_variables
[i
]);
917 generate_300ES_uniforms(instructions
, state
);
919 generate_ARB_draw_buffers_variables(instructions
, state
, false,
924 generate_110_fs_variables(exec_list
*instructions
,
925 struct _mesa_glsl_parse_state
*state
,
928 for (unsigned i
= 0; i
< Elements(builtin_core_fs_variables
); i
++) {
929 add_builtin_variable(instructions
, state
->symbols
,
930 & builtin_core_fs_variables
[i
]);
933 for (unsigned i
= 0; i
< Elements(builtin_110_fs_variables
); i
++) {
934 add_builtin_variable(instructions
, state
->symbols
,
935 & builtin_110_fs_variables
[i
]);
938 if (add_deprecated
) {
940 ; i
< Elements(builtin_110_deprecated_fs_variables
)
942 add_builtin_variable(instructions
, state
->symbols
,
943 & builtin_110_deprecated_fs_variables
[i
]);
947 generate_110_uniforms(instructions
, state
, add_deprecated
);
949 if (add_deprecated
) {
950 /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec:
952 * "As with all arrays, indices used to subscript gl_TexCoord must
953 * either be an integral constant expressions, or this array must be
954 * re-declared by the shader with a size. The size can be at most
955 * gl_MaxTextureCoords. Using indexes close to 0 may aid the
956 * implementation in preserving varying resources."
958 const glsl_type
*const vec4_array_type
=
959 glsl_type::get_array_instance(glsl_type::vec4_type
, 0);
961 add_variable(instructions
, state
->symbols
,
962 "gl_TexCoord", vec4_array_type
, ir_var_shader_in
,
966 generate_ARB_draw_buffers_variables(instructions
, state
, false,
972 generate_ARB_draw_buffers_variables(exec_list
*instructions
,
973 struct _mesa_glsl_parse_state
*state
,
974 bool warn
, _mesa_glsl_parser_targets target
)
976 /* gl_MaxDrawBuffers is available in all shader stages.
978 ir_variable
*const mdb
=
979 add_builtin_constant(instructions
, state
->symbols
, "gl_MaxDrawBuffers",
980 state
->Const
.MaxDrawBuffers
);
983 mdb
->warn_extension
= "GL_ARB_draw_buffers";
985 /* gl_FragData is only available in the fragment shader.
986 * It is not present in GLSL 3.00 ES.
988 if (target
== fragment_shader
&& !state
->is_version(0, 300)) {
989 const glsl_type
*const vec4_array_type
=
990 glsl_type::get_array_instance(glsl_type::vec4_type
,
991 state
->Const
.MaxDrawBuffers
);
993 ir_variable
*const fd
=
994 add_variable(instructions
, state
->symbols
,
995 "gl_FragData", vec4_array_type
,
996 ir_var_shader_out
, FRAG_RESULT_DATA0
);
999 fd
->warn_extension
= "GL_ARB_draw_buffers";
1005 generate_ARB_draw_instanced_variables(exec_list
*instructions
,
1006 struct _mesa_glsl_parse_state
*state
,
1008 _mesa_glsl_parser_targets target
)
1010 /* gl_InstanceIDARB is only available in the vertex shader.
1012 if (target
!= vertex_shader
)
1015 if (state
->ARB_draw_instanced_enable
) {
1017 add_variable(instructions
, state
->symbols
,
1018 "gl_InstanceIDARB", glsl_type::int_type
,
1019 ir_var_system_value
, SYSTEM_VALUE_INSTANCE_ID
);
1022 inst
->warn_extension
= "GL_ARB_draw_instanced";
1025 bool available_in_core
= state
->is_version(140, 300);
1026 if (state
->ARB_draw_instanced_enable
|| available_in_core
) {
1027 /* Originally ARB_draw_instanced only specified that ARB decorated name.
1028 * Since no vendor actually implemented that behavior and some apps use
1029 * the undecorated name, the extension now specifies that both names are
1033 add_variable(instructions
, state
->symbols
,
1034 "gl_InstanceID", glsl_type::int_type
,
1035 ir_var_system_value
, SYSTEM_VALUE_INSTANCE_ID
);
1037 if (!available_in_core
&& warn
)
1038 inst
->warn_extension
= "GL_ARB_draw_instanced";
1043 generate_AMD_vertex_shader_layer_variables(exec_list
*instructions
,
1044 struct _mesa_glsl_parse_state
*state
,
1046 _mesa_glsl_parser_targets target
)
1048 /* gl_Layer is only available in the vertex shader for the
1049 * AMD_vertex_shader_layer extension. It will also be available in the
1050 * geometry shader when GLSL 1.50 is supported.
1052 if (target
!= vertex_shader
)
1055 if (state
->AMD_vertex_shader_layer_enable
) {
1057 add_variable(instructions
, state
->symbols
,
1058 "gl_Layer", glsl_type::int_type
,
1059 ir_var_shader_out
, VARYING_SLOT_LAYER
);
1062 inst
->warn_extension
= "GL_AMD_vertex_shader_layer";
1067 generate_ARB_shader_stencil_export_variables(exec_list
*instructions
,
1068 struct _mesa_glsl_parse_state
*state
,
1071 /* gl_FragStencilRefARB is only available in the fragment shader.
1073 ir_variable
*const fd
=
1074 add_variable(instructions
, state
->symbols
,
1075 "gl_FragStencilRefARB", glsl_type::int_type
,
1076 ir_var_shader_out
, FRAG_RESULT_STENCIL
);
1079 fd
->warn_extension
= "GL_ARB_shader_stencil_export";
1083 generate_AMD_shader_stencil_export_variables(exec_list
*instructions
,
1084 struct _mesa_glsl_parse_state
*state
,
1087 /* gl_FragStencilRefAMD is only available in the fragment shader.
1089 ir_variable
*const fd
=
1090 add_variable(instructions
, state
->symbols
,
1091 "gl_FragStencilRefAMD", glsl_type::int_type
,
1092 ir_var_shader_out
, FRAG_RESULT_STENCIL
);
1095 fd
->warn_extension
= "GL_AMD_shader_stencil_export";
1099 generate_120_fs_variables(exec_list
*instructions
,
1100 struct _mesa_glsl_parse_state
*state
,
1101 bool add_deprecated
)
1103 generate_110_fs_variables(instructions
, state
, add_deprecated
);
1106 ; i
< Elements(builtin_120_fs_variables
)
1108 add_builtin_variable(instructions
, state
->symbols
,
1109 & builtin_120_fs_variables
[i
]);
1114 generate_fs_clipdistance(exec_list
*instructions
,
1115 struct _mesa_glsl_parse_state
*state
)
1117 /* From the GLSL 1.30 spec, section 7.2 (Fragment Shader Special
1120 * The built-in input variable gl_ClipDistance array contains linearly
1121 * interpolated values for the vertex values written by the vertex shader
1122 * to the gl_ClipDistance vertex output variable. This array must be
1123 * sized in the fragment shader either implicitly or explicitly to be the
1124 * same size as it was sized in the vertex shader.
1126 * In other words, the array must be pre-declared as implicitly sized. We
1127 * represent this in Mesa by initially declaring the array as size 0.
1129 const glsl_type
*const clip_distance_array_type
=
1130 glsl_type::get_array_instance(glsl_type::float_type
, 0);
1132 add_variable(instructions
, state
->symbols
,
1133 "gl_ClipDistance", clip_distance_array_type
, ir_var_shader_in
,
1134 VARYING_SLOT_CLIP_DIST0
);
1138 generate_130_fs_variables(exec_list
*instructions
,
1139 struct _mesa_glsl_parse_state
*state
)
1141 generate_120_fs_variables(instructions
, state
, true);
1143 generate_130_uniforms(instructions
, state
);
1144 generate_fs_clipdistance(instructions
, state
);
1149 generate_140_fs_variables(exec_list
*instructions
,
1150 struct _mesa_glsl_parse_state
*state
)
1152 generate_120_fs_variables(instructions
, state
, false);
1154 generate_130_uniforms(instructions
, state
);
1155 generate_fs_clipdistance(instructions
, state
);
1159 initialize_fs_variables(exec_list
*instructions
,
1160 struct _mesa_glsl_parse_state
*state
)
1162 if (state
->es_shader
) {
1163 switch (state
->language_version
) {
1165 generate_100ES_fs_variables(instructions
, state
);
1168 generate_300ES_fs_variables(instructions
, state
);
1171 assert(!"Unexpected language version");
1175 switch (state
->language_version
) {
1177 generate_110_fs_variables(instructions
, state
, true);
1180 generate_120_fs_variables(instructions
, state
, true);
1183 generate_130_fs_variables(instructions
, state
);
1187 generate_140_fs_variables(instructions
, state
);
1190 assert(!"Unexpected language version");
1195 if (state
->ARB_shader_stencil_export_enable
)
1196 generate_ARB_shader_stencil_export_variables(instructions
, state
,
1197 state
->ARB_shader_stencil_export_warn
);
1199 if (state
->AMD_shader_stencil_export_enable
)
1200 generate_AMD_shader_stencil_export_variables(instructions
, state
,
1201 state
->AMD_shader_stencil_export_warn
);
1205 _mesa_glsl_initialize_variables(exec_list
*instructions
,
1206 struct _mesa_glsl_parse_state
*state
)
1208 switch (state
->target
) {
1210 initialize_vs_variables(instructions
, state
);
1212 case geometry_shader
:
1214 case fragment_shader
:
1215 initialize_fs_variables(instructions
, state
);