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.
24 #include "glsl_parser_extras.h"
25 #include "glsl_symbol_table.h"
27 #include "builtin_variables.h"
30 #define Elements(x) (sizeof(x)/sizeof(*(x)))
34 add_builtin_variable(const builtin_variable *proto, exec_list *instructions,
35 glsl_symbol_table *symtab)
37 /* Create a new variable declaration from the description supplied by
40 const glsl_type *const type = symtab->get_type(proto->type);
44 ir_variable *var = new ir_variable(type, proto->name);
46 var->mode = proto->mode;
47 if (var->mode != ir_var_out)
48 var->read_only = true;
51 /* Once the variable is created an initialized, add it to the symbol table
52 * and add the declaration to the IR stream.
54 instructions->push_tail(var);
56 symtab->add_variable(var->name, var);
60 generate_110_uniforms(exec_list *instructions,
61 glsl_symbol_table *symtab)
64 ; i < Elements(builtin_110_deprecated_uniforms)
66 add_builtin_variable(& builtin_110_deprecated_uniforms[i],
67 instructions, symtab);
70 /* FINISHME: Add support for gl_TextureMatrix[]. The size of this array is
71 * FINISHME: implementation dependent based on the value of
72 * FINISHME: GL_MAX_TEXTURE_COORDS.
75 /* FINISHME: Add support for gl_DepthRangeParameters */
76 /* FINISHME: Add support for gl_ClipPlane[] */
77 /* FINISHME: Add support for gl_PointParameters */
79 /* FINISHME: Add support for gl_MaterialParameters
80 * FINISHME: (glFrontMaterial, glBackMaterial)
83 /* FINISHME: Add support for gl_LightSource[] */
84 /* FINISHME: Add support for gl_LightModel */
85 /* FINISHME: Add support for gl_FrontLightProduct[], gl_BackLightProduct[] */
86 /* FINISHME: Add support for gl_TextureEnvColor[] */
87 /* FINISHME: Add support for gl_ObjectPlane*[], gl_EyePlane*[] */
88 /* FINISHME: Add support for gl_Fog */
92 generate_110_vs_variables(exec_list *instructions,
93 glsl_symbol_table *symtab)
95 for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) {
96 add_builtin_variable(& builtin_core_vs_variables[i],
97 instructions, symtab);
101 ; i < Elements(builtin_110_deprecated_vs_variables)
103 add_builtin_variable(& builtin_110_deprecated_vs_variables[i],
104 instructions, symtab);
106 generate_110_uniforms(instructions, symtab);
108 /* FINISHME: Add support fo gl_TexCoord. The size of this array is
109 * FINISHME: implementation dependent based on the value of
110 * FINISHME: GL_MAX_TEXTURE_COORDS.
116 generate_120_vs_variables(exec_list *instructions,
117 glsl_symbol_table *symtab)
119 /* GLSL version 1.20 did not add any built-in variables in the vertex
122 generate_110_vs_variables(instructions, symtab);
127 generate_130_vs_variables(exec_list *instructions,
128 glsl_symbol_table *symtab)
130 generate_120_vs_variables(instructions, symtab);
132 for (unsigned i = 0; i < Elements(builtin_130_vs_variables); i++) {
133 add_builtin_variable(& builtin_130_vs_variables[i],
134 instructions, symtab);
137 /* FINISHME: Add support fo gl_ClipDistance. The size of this array is
138 * FINISHME: implementation dependent based on the value of
139 * FINISHME: GL_MAX_CLIP_DISTANCES.
145 initialize_vs_variables(exec_list *instructions,
146 struct _mesa_glsl_parse_state *state)
149 switch (state->language_version) {
151 generate_110_vs_variables(instructions, state->symbols);
154 generate_120_vs_variables(instructions, state->symbols);
157 generate_130_vs_variables(instructions, state->symbols);
163 generate_110_fs_variables(exec_list *instructions,
164 glsl_symbol_table *symtab)
166 for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) {
167 add_builtin_variable(& builtin_core_fs_variables[i],
168 instructions, symtab);
171 /* FINISHME: Add support for gl_TexCoord[] */
173 ; i < Elements(builtin_110_deprecated_fs_variables)
175 add_builtin_variable(& builtin_110_deprecated_fs_variables[i],
176 instructions, symtab);
178 generate_110_uniforms(instructions, symtab);
180 /* FINISHME: Add support for gl_FragData[GL_MAX_DRAW_BUFFERS]. */
184 generate_120_fs_variables(exec_list *instructions,
185 glsl_symbol_table *symtab)
187 /* GLSL version 1.20 did not add any built-in variables in the fragment
190 generate_110_fs_variables(instructions, symtab);
194 generate_130_fs_variables(exec_list *instructions,
195 glsl_symbol_table *symtab)
197 generate_120_fs_variables(instructions, symtab);
199 /* FINISHME: Add support fo gl_ClipDistance. The size of this array is
200 * FINISHME: implementation dependent based on the value of
201 * FINISHME: GL_MAX_CLIP_DISTANCES.
206 initialize_fs_variables(exec_list *instructions,
207 struct _mesa_glsl_parse_state *state)
210 switch (state->language_version) {
212 generate_110_fs_variables(instructions, state->symbols);
215 generate_120_fs_variables(instructions, state->symbols);
218 generate_130_fs_variables(instructions, state->symbols);
224 _mesa_glsl_initialize_variables(exec_list *instructions,
225 struct _mesa_glsl_parse_state *state)
227 switch (state->target) {
229 initialize_vs_variables(instructions, state);
231 case geometry_shader:
233 case fragment_shader:
234 initialize_fs_variables(instructions, state);