blob: 478cefc5a6ccb5f1d1623d0c8bbf5d49521078d1 [file] [log] [blame]
Ian Romanickadfb0cd2010-03-10 10:43:16 -08001/*
2 * Copyright © 2010 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
Eric Anholtac95f2f2010-06-22 10:38:52 -070024#include "ir.h"
Ian Romanickadfb0cd2010-03-10 10:43:16 -080025#include "glsl_parser_extras.h"
Ian Romanick8bde4ce2010-03-19 11:57:24 -070026#include "glsl_symbol_table.h"
Ian Romanickadfb0cd2010-03-10 10:43:16 -080027#include "builtin_variables.h"
28
29#ifndef Elements
30#define Elements(x) (sizeof(x)/sizeof(*(x)))
31#endif
32
Ian Romanick22971e92010-06-29 15:29:56 -070033static void generate_ARB_draw_buffers_variables(exec_list *,
34 struct _mesa_glsl_parse_state *,
35 bool, _mesa_glsl_parser_targets);
Ian Romanick9c4b1f22010-06-29 15:10:09 -070036
Ian Romanickc77b2572010-04-07 16:59:46 -070037static ir_variable *
Ian Romanicked0626e2010-06-21 11:42:57 -070038add_variable(const char *name, enum ir_variable_mode mode, int slot,
Ian Romanick3f9a73d2010-04-02 11:59:57 -070039 const glsl_type *type, exec_list *instructions,
Ian Romanick8bde4ce2010-03-19 11:57:24 -070040 glsl_symbol_table *symtab)
Ian Romanickadfb0cd2010-03-10 10:43:16 -080041{
Ian Romanick7e2aa912010-07-19 17:12:42 -070042 ir_variable *var = new(symtab) ir_variable(type, name, mode);
Ian Romanickadfb0cd2010-03-10 10:43:16 -080043
Eric Anholt71df19f2010-04-19 11:10:37 -070044 switch (var->mode) {
Ian Romanicke2f84f02010-06-29 15:19:11 -070045 case ir_var_auto:
46 var->read_only = true;
47 break;
Eric Anholt71df19f2010-04-19 11:10:37 -070048 case ir_var_in:
49 var->shader_in = true;
Ian Romanickadfb0cd2010-03-10 10:43:16 -080050 var->read_only = true;
Eric Anholt71df19f2010-04-19 11:10:37 -070051 break;
52 case ir_var_inout:
53 var->shader_in = true;
54 var->shader_out = true;
Ian Romanickff236fa2010-04-21 15:08:08 -070055 break;
Eric Anholt71df19f2010-04-19 11:10:37 -070056 case ir_var_out:
57 var->shader_out = true;
58 break;
59 case ir_var_uniform:
60 var->shader_in = true;
61 var->read_only = true;
62 break;
63 default:
64 assert(0);
65 break;
66 }
Ian Romanickadfb0cd2010-03-10 10:43:16 -080067
Ian Romanicked0626e2010-06-21 11:42:57 -070068 var->location = slot;
69
Ian Romanickadfb0cd2010-03-10 10:43:16 -080070 /* Once the variable is created an initialized, add it to the symbol table
71 * and add the declaration to the IR stream.
72 */
73 instructions->push_tail(var);
74
Ian Romanick8bde4ce2010-03-19 11:57:24 -070075 symtab->add_variable(var->name, var);
Ian Romanickc77b2572010-04-07 16:59:46 -070076 return var;
Ian Romanickadfb0cd2010-03-10 10:43:16 -080077}
78
Eric Anholt85b5dba2010-07-28 12:23:51 -070079static ir_variable *
80add_uniform(exec_list *instructions,
81 struct _mesa_glsl_parse_state *state,
82 const char *name, const glsl_type *type)
83{
84 return add_variable(name, ir_var_uniform, -1, type, instructions,
85 state->symbols);
86}
Ian Romanick3f9a73d2010-04-02 11:59:57 -070087
88static void
89add_builtin_variable(const builtin_variable *proto, exec_list *instructions,
90 glsl_symbol_table *symtab)
91{
92 /* Create a new variable declaration from the description supplied by
93 * the caller.
94 */
95 const glsl_type *const type = symtab->get_type(proto->type);
96
97 assert(type != NULL);
98
Ian Romanicked0626e2010-06-21 11:42:57 -070099 add_variable(proto->name, proto->mode, proto->slot, type, instructions,
100 symtab);
Ian Romanick3f9a73d2010-04-02 11:59:57 -0700101}
102
Eric Anholtf8946692010-07-20 14:03:35 -0700103static void
104add_builtin_constant(exec_list *instructions,
105 struct _mesa_glsl_parse_state *state,
106 const char *name, int value)
107{
108 ir_variable *const var = add_variable(name, ir_var_auto,
109 -1, glsl_type::int_type,
110 instructions, state->symbols);
111 var->constant_value = new(var) ir_constant(value);
112}
Ian Romanick3f9a73d2010-04-02 11:59:57 -0700113
Eric Anholt78fe3c92010-03-28 01:46:48 -0700114static void
115generate_110_uniforms(exec_list *instructions,
Ian Romanick127308b2010-07-01 13:30:50 -0700116 struct _mesa_glsl_parse_state *state)
Eric Anholt78fe3c92010-03-28 01:46:48 -0700117{
118 for (unsigned i = 0
119 ; i < Elements(builtin_110_deprecated_uniforms)
120 ; i++) {
121 add_builtin_variable(& builtin_110_deprecated_uniforms[i],
Ian Romanick127308b2010-07-01 13:30:50 -0700122 instructions, state->symbols);
Eric Anholt78fe3c92010-03-28 01:46:48 -0700123 }
124
Eric Anholtf8946692010-07-20 14:03:35 -0700125 add_builtin_constant(instructions, state, "gl_MaxLights",
126 state->Const.MaxLights);
127 add_builtin_constant(instructions, state, "gl_MaxClipPlanes",
128 state->Const.MaxClipPlanes);
129 add_builtin_constant(instructions, state, "gl_MaxTextureUnits",
130 state->Const.MaxTextureUnits);
131 add_builtin_constant(instructions, state, "gl_MaxTextureCoords",
132 state->Const.MaxTextureCoords);
133 add_builtin_constant(instructions, state, "gl_MaxVertexAttribs",
134 state->Const.MaxVertexAttribs);
135 add_builtin_constant(instructions, state, "gl_MaxVertexUniformComponents",
136 state->Const.MaxVertexUniformComponents);
137 add_builtin_constant(instructions, state, "gl_MaxVaryingFloats",
138 state->Const.MaxVaryingFloats);
139 add_builtin_constant(instructions, state, "gl_MaxVertexTextureImageUnits",
140 state->Const.MaxVertexTextureImageUnits);
141 add_builtin_constant(instructions, state, "gl_MaxCombinedTextureImageUnits",
142 state->Const.MaxCombinedTextureImageUnits);
143 add_builtin_constant(instructions, state, "gl_MaxTextureImageUnits",
144 state->Const.MaxTextureImageUnits);
145 add_builtin_constant(instructions, state, "gl_MaxFragmentUniformComponents",
146 state->Const.MaxFragmentUniformComponents);
Ian Romanick127308b2010-07-01 13:30:50 -0700147
Ian Romanick3eba5932010-04-26 14:59:32 -0700148 const glsl_type *const mat4_array_type =
Ian Romanickf38d15b2010-07-20 15:33:40 -0700149 glsl_type::get_array_instance(glsl_type::mat4_type,
Ian Romanick127308b2010-07-01 13:30:50 -0700150 state->Const.MaxTextureCoords);
Ian Romanick3eba5932010-04-26 14:59:32 -0700151
Eric Anholt85b5dba2010-07-28 12:23:51 -0700152 add_uniform(instructions, state, "gl_TextureMatrix", mat4_array_type);
Eric Anholt78fe3c92010-03-28 01:46:48 -0700153
Eric Anholt85b5dba2010-07-28 12:23:51 -0700154 add_uniform(instructions, state, "gl_DepthRangeParameters",
155 state->symbols->get_type("gl_DepthRangeParameters"));
Eric Anholt78fe3c92010-03-28 01:46:48 -0700156
Eric Anholt85b5dba2010-07-28 12:23:51 -0700157 add_uniform(instructions, state, "gl_ClipPlane",
158 glsl_type::get_array_instance(glsl_type::vec4_type,
159 state->Const.MaxClipPlanes));
160 add_uniform(instructions, state, "gl_Point",
161 state->symbols->get_type("gl_PointParameters"));
162
163 const glsl_type *const material_parameters_type =
164 state->symbols->get_type("gl_MaterialParameters");
165 add_uniform(instructions, state, "gl_FrontMaterial", material_parameters_type);
166 add_uniform(instructions, state, "gl_BackMaterial", material_parameters_type);
Eric Anholt78fe3c92010-03-28 01:46:48 -0700167
Eric Anholtaa579432010-05-19 14:09:04 -0700168 const glsl_type *const light_source_array_type =
Eric Anholt73df6362010-07-28 08:18:59 -0700169 glsl_type::get_array_instance(state->symbols->get_type("gl_LightSourceParameters"), state->Const.MaxLights);
Eric Anholtaa579432010-05-19 14:09:04 -0700170
Eric Anholt85b5dba2010-07-28 12:23:51 -0700171 add_uniform(instructions, state, "gl_LightSource", light_source_array_type);
Eric Anholtaa579432010-05-19 14:09:04 -0700172
Eric Anholt85b5dba2010-07-28 12:23:51 -0700173 const glsl_type *const light_model_products_type =
174 state->symbols->get_type("gl_LightModelProducts");
175 add_uniform(instructions, state, "gl_FrontLightModelProduct",
176 light_model_products_type);
177 add_uniform(instructions, state, "gl_BackLightModelProduct",
178 light_model_products_type);
179
180 const glsl_type *const light_products_type =
181 glsl_type::get_array_instance(state->symbols->get_type("gl_LightProducts"),
182 state->Const.MaxLights);
183 add_uniform(instructions, state, "gl_FrontLightProduct", light_products_type);
184 add_uniform(instructions, state, "gl_BackLightProduct", light_products_type);
185
186 add_uniform(instructions, state, "gl_TextureEnvColor",
187 glsl_type::get_array_instance(glsl_type::vec4_type,
188 state->Const.MaxTextureUnits));
189
190 const glsl_type *const texcoords_vec4 =
191 glsl_type::get_array_instance(glsl_type::vec4_type,
192 state->Const.MaxTextureCoords);
193 add_uniform(instructions, state, "gl_EyePlaneS", texcoords_vec4);
194 add_uniform(instructions, state, "gl_EyePlaneT", texcoords_vec4);
195 add_uniform(instructions, state, "gl_EyePlaneR", texcoords_vec4);
196 add_uniform(instructions, state, "gl_EyePlaneQ", texcoords_vec4);
197 add_uniform(instructions, state, "gl_ObjectPlaneS", texcoords_vec4);
198 add_uniform(instructions, state, "gl_ObjectPlaneT", texcoords_vec4);
199 add_uniform(instructions, state, "gl_ObjectPlaneR", texcoords_vec4);
200 add_uniform(instructions, state, "gl_ObjectPlaneQ", texcoords_vec4);
201
202 add_uniform(instructions, state, "gl_Fog",
203 state->symbols->get_type("gl_FogParameters"));
Eric Anholt78fe3c92010-03-28 01:46:48 -0700204}
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800205
206static void
207generate_110_vs_variables(exec_list *instructions,
Ian Romanick22971e92010-06-29 15:29:56 -0700208 struct _mesa_glsl_parse_state *state)
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800209{
210 for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) {
211 add_builtin_variable(& builtin_core_vs_variables[i],
Ian Romanick22971e92010-06-29 15:29:56 -0700212 instructions, state->symbols);
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800213 }
214
215 for (unsigned i = 0
216 ; i < Elements(builtin_110_deprecated_vs_variables)
217 ; i++) {
218 add_builtin_variable(& builtin_110_deprecated_vs_variables[i],
Ian Romanick22971e92010-06-29 15:29:56 -0700219 instructions, state->symbols);
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800220 }
Ian Romanick127308b2010-07-01 13:30:50 -0700221 generate_110_uniforms(instructions, state);
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800222
Ian Romanickcd00d5b2010-07-01 13:17:54 -0700223 /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec:
224 *
225 * "As with all arrays, indices used to subscript gl_TexCoord must
226 * either be an integral constant expressions, or this array must be
227 * re-declared by the shader with a size. The size can be at most
228 * gl_MaxTextureCoords. Using indexes close to 0 may aid the
229 * implementation in preserving varying resources."
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800230 */
Ian Romanick3f9a73d2010-04-02 11:59:57 -0700231 const glsl_type *const vec4_array_type =
Ian Romanickf38d15b2010-07-20 15:33:40 -0700232 glsl_type::get_array_instance(glsl_type::vec4_type, 0);
Ian Romanick3f9a73d2010-04-02 11:59:57 -0700233
Ian Romanicked0626e2010-06-21 11:42:57 -0700234 add_variable("gl_TexCoord", ir_var_out, VERT_RESULT_TEX0, vec4_array_type,
Ian Romanick22971e92010-06-29 15:29:56 -0700235 instructions, state->symbols);
236
237 generate_ARB_draw_buffers_variables(instructions, state, false,
238 vertex_shader);
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800239}
240
241
242static void
243generate_120_vs_variables(exec_list *instructions,
Ian Romanick22971e92010-06-29 15:29:56 -0700244 struct _mesa_glsl_parse_state *state)
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800245{
246 /* GLSL version 1.20 did not add any built-in variables in the vertex
247 * shader.
248 */
Ian Romanick22971e92010-06-29 15:29:56 -0700249 generate_110_vs_variables(instructions, state);
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800250}
251
252
253static void
254generate_130_vs_variables(exec_list *instructions,
Ian Romanick22971e92010-06-29 15:29:56 -0700255 struct _mesa_glsl_parse_state *state)
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800256{
Ian Romanick22971e92010-06-29 15:29:56 -0700257 generate_120_vs_variables(instructions, state);
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800258
259 for (unsigned i = 0; i < Elements(builtin_130_vs_variables); i++) {
260 add_builtin_variable(& builtin_130_vs_variables[i],
Ian Romanick22971e92010-06-29 15:29:56 -0700261 instructions, state->symbols);
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800262 }
263
Eric Anholt271e1992010-04-02 23:47:06 -0700264 const glsl_type *const clip_distance_array_type =
Eric Anholt73df6362010-07-28 08:18:59 -0700265 glsl_type::get_array_instance(glsl_type::float_type,
266 state->Const.MaxClipPlanes);
Ian Romanicked0626e2010-06-21 11:42:57 -0700267
268 /* FINISHME: gl_ClipDistance needs a real location assigned. */
269 add_variable("gl_ClipDistance", ir_var_out, -1, clip_distance_array_type,
Ian Romanick22971e92010-06-29 15:29:56 -0700270 instructions, state->symbols);
Eric Anholt271e1992010-04-02 23:47:06 -0700271
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800272}
273
274
275static void
276initialize_vs_variables(exec_list *instructions,
277 struct _mesa_glsl_parse_state *state)
278{
279
280 switch (state->language_version) {
281 case 110:
Ian Romanick22971e92010-06-29 15:29:56 -0700282 generate_110_vs_variables(instructions, state);
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800283 break;
284 case 120:
Ian Romanick22971e92010-06-29 15:29:56 -0700285 generate_120_vs_variables(instructions, state);
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800286 break;
287 case 130:
Ian Romanick22971e92010-06-29 15:29:56 -0700288 generate_130_vs_variables(instructions, state);
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800289 break;
290 }
291}
292
Eric Anholtb3f743a2010-03-25 14:48:25 -0700293static void
294generate_110_fs_variables(exec_list *instructions,
Ian Romanick5e18b052010-06-29 14:21:05 -0700295 struct _mesa_glsl_parse_state *state)
Eric Anholtb3f743a2010-03-25 14:48:25 -0700296{
297 for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) {
298 add_builtin_variable(& builtin_core_fs_variables[i],
Ian Romanick5e18b052010-06-29 14:21:05 -0700299 instructions, state->symbols);
Eric Anholtb3f743a2010-03-25 14:48:25 -0700300 }
301
Eric Anholt0f09aea2010-03-27 12:48:57 -0700302 for (unsigned i = 0
303 ; i < Elements(builtin_110_deprecated_fs_variables)
304 ; i++) {
305 add_builtin_variable(& builtin_110_deprecated_fs_variables[i],
Ian Romanick5e18b052010-06-29 14:21:05 -0700306 instructions, state->symbols);
Eric Anholt0f09aea2010-03-27 12:48:57 -0700307 }
Ian Romanick127308b2010-07-01 13:30:50 -0700308 generate_110_uniforms(instructions, state);
Eric Anholt0f09aea2010-03-27 12:48:57 -0700309
Ian Romanickcd00d5b2010-07-01 13:17:54 -0700310 /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec:
311 *
312 * "As with all arrays, indices used to subscript gl_TexCoord must
313 * either be an integral constant expressions, or this array must be
314 * re-declared by the shader with a size. The size can be at most
315 * gl_MaxTextureCoords. Using indexes close to 0 may aid the
316 * implementation in preserving varying resources."
Ian Romanick3f9a73d2010-04-02 11:59:57 -0700317 */
Ian Romanick3f9a73d2010-04-02 11:59:57 -0700318 const glsl_type *const vec4_array_type =
Ian Romanickf38d15b2010-07-20 15:33:40 -0700319 glsl_type::get_array_instance(glsl_type::vec4_type, 0);
Ian Romanick3f9a73d2010-04-02 11:59:57 -0700320
Ian Romanicked0626e2010-06-21 11:42:57 -0700321 add_variable("gl_TexCoord", ir_var_in, FRAG_ATTRIB_TEX0, vec4_array_type,
Ian Romanick5e18b052010-06-29 14:21:05 -0700322 instructions, state->symbols);
Ian Romanick9c4b1f22010-06-29 15:10:09 -0700323
Ian Romanick22971e92010-06-29 15:29:56 -0700324 generate_ARB_draw_buffers_variables(instructions, state, false,
325 fragment_shader);
Eric Anholtb3f743a2010-03-25 14:48:25 -0700326}
327
Ian Romanickc77b2572010-04-07 16:59:46 -0700328
329static void
Ian Romanick22971e92010-06-29 15:29:56 -0700330generate_ARB_draw_buffers_variables(exec_list *instructions,
331 struct _mesa_glsl_parse_state *state,
332 bool warn, _mesa_glsl_parser_targets target)
Ian Romanickc77b2572010-04-07 16:59:46 -0700333{
Ian Romanick22971e92010-06-29 15:29:56 -0700334 /* gl_MaxDrawBuffers is available in all shader stages.
335 */
Ian Romanicke2f84f02010-06-29 15:19:11 -0700336 ir_variable *const mdb =
337 add_variable("gl_MaxDrawBuffers", ir_var_auto, -1,
338 glsl_type::int_type, instructions, state->symbols);
339
340 if (warn)
341 mdb->warn_extension = "GL_ARB_draw_buffers";
342
343 mdb->constant_value = new(mdb)
344 ir_constant(int(state->Const.MaxDrawBuffers));
345
Ian Romanickc77b2572010-04-07 16:59:46 -0700346
Ian Romanick22971e92010-06-29 15:29:56 -0700347 /* gl_FragData is only available in the fragment shader.
348 */
349 if (target == fragment_shader) {
350 const glsl_type *const vec4_array_type =
Ian Romanickf38d15b2010-07-20 15:33:40 -0700351 glsl_type::get_array_instance(glsl_type::vec4_type,
Ian Romanick22971e92010-06-29 15:29:56 -0700352 state->Const.MaxDrawBuffers);
Ian Romanickc77b2572010-04-07 16:59:46 -0700353
Ian Romanick22971e92010-06-29 15:29:56 -0700354 ir_variable *const fd =
355 add_variable("gl_FragData", ir_var_out, FRAG_RESULT_DATA0,
356 vec4_array_type, instructions, state->symbols);
357
358 if (warn)
359 fd->warn_extension = "GL_ARB_draw_buffers";
360 }
Ian Romanickc77b2572010-04-07 16:59:46 -0700361}
362
363
Eric Anholtb3f743a2010-03-25 14:48:25 -0700364static void
365generate_120_fs_variables(exec_list *instructions,
Ian Romanick5e18b052010-06-29 14:21:05 -0700366 struct _mesa_glsl_parse_state *state)
Eric Anholtb3f743a2010-03-25 14:48:25 -0700367{
Ian Romanick5e18b052010-06-29 14:21:05 -0700368 generate_110_fs_variables(instructions, state);
Eric Anholt152b55e2010-07-07 19:45:22 -0700369
370 for (unsigned i = 0
371 ; i < Elements(builtin_120_fs_variables)
372 ; i++) {
373 add_builtin_variable(& builtin_120_fs_variables[i],
374 instructions, state->symbols);
375 }
Eric Anholtb3f743a2010-03-25 14:48:25 -0700376}
377
378static void
379generate_130_fs_variables(exec_list *instructions,
Ian Romanick5e18b052010-06-29 14:21:05 -0700380 struct _mesa_glsl_parse_state *state)
Eric Anholtb3f743a2010-03-25 14:48:25 -0700381{
Ian Romanick5e18b052010-06-29 14:21:05 -0700382 generate_120_fs_variables(instructions, state);
Eric Anholtb3f743a2010-03-25 14:48:25 -0700383
Ian Romanick8645a952010-04-07 16:47:44 -0700384 const glsl_type *const clip_distance_array_type =
Eric Anholt73df6362010-07-28 08:18:59 -0700385 glsl_type::get_array_instance(glsl_type::float_type,
386 state->Const.MaxClipPlanes);
Ian Romanicked0626e2010-06-21 11:42:57 -0700387
388 /* FINISHME: gl_ClipDistance needs a real location assigned. */
389 add_variable("gl_ClipDistance", ir_var_in, -1, clip_distance_array_type,
Ian Romanick5e18b052010-06-29 14:21:05 -0700390 instructions, state->symbols);
Eric Anholtb3f743a2010-03-25 14:48:25 -0700391}
392
393static void
394initialize_fs_variables(exec_list *instructions,
395 struct _mesa_glsl_parse_state *state)
396{
397
398 switch (state->language_version) {
399 case 110:
Ian Romanick5e18b052010-06-29 14:21:05 -0700400 generate_110_fs_variables(instructions, state);
Eric Anholtb3f743a2010-03-25 14:48:25 -0700401 break;
402 case 120:
Ian Romanick5e18b052010-06-29 14:21:05 -0700403 generate_120_fs_variables(instructions, state);
Eric Anholtb3f743a2010-03-25 14:48:25 -0700404 break;
405 case 130:
Ian Romanick5e18b052010-06-29 14:21:05 -0700406 generate_130_fs_variables(instructions, state);
Eric Anholtb3f743a2010-03-25 14:48:25 -0700407 break;
408 }
409}
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800410
411void
412_mesa_glsl_initialize_variables(exec_list *instructions,
413 struct _mesa_glsl_parse_state *state)
414{
415 switch (state->target) {
416 case vertex_shader:
417 initialize_vs_variables(instructions, state);
418 break;
419 case geometry_shader:
Eric Anholtb3f743a2010-03-25 14:48:25 -0700420 break;
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800421 case fragment_shader:
Eric Anholtb3f743a2010-03-25 14:48:25 -0700422 initialize_fs_variables(instructions, state);
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800423 break;
Eric Anholt81f49a72010-04-29 17:57:28 -0700424 case ir_shader:
425 fprintf(stderr, "ir reader has no builtin variables");
426 exit(1);
427 break;
Ian Romanickadfb0cd2010-03-10 10:43:16 -0800428 }
429}