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 "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 struct _mesa_symbol_table
*symtab
)
37 /* Create a new variable declaration from the description supplied by
40 const glsl_type
*const type
= (glsl_type
*)
41 _mesa_symbol_table_find_symbol(symtab
, 0, proto
->type
);
45 ir_variable
*var
= new ir_variable(type
, proto
->name
);
47 var
->mode
= proto
->mode
;
48 if (var
->mode
!= ir_var_out
)
49 var
->read_only
= true;
52 /* Once the variable is created an initialized, add it to the symbol table
53 * and add the declaration to the IR stream.
55 instructions
->push_tail(var
);
57 _mesa_symbol_table_add_symbol(symtab
, 0, var
->name
, var
);
62 generate_110_vs_variables(exec_list
*instructions
,
63 struct _mesa_symbol_table
*symtab
)
65 for (unsigned i
= 0; i
< Elements(builtin_core_vs_variables
); i
++) {
66 add_builtin_variable(& builtin_core_vs_variables
[i
],
67 instructions
, symtab
);
71 ; i
< Elements(builtin_110_deprecated_vs_variables
)
73 add_builtin_variable(& builtin_110_deprecated_vs_variables
[i
],
74 instructions
, symtab
);
77 /* FINISHME: Add support fo gl_TexCoord. The size of this array is
78 * FINISHME: implementation dependent based on the value of
79 * FINISHME: GL_MAX_TEXTURE_COORDS.
85 generate_120_vs_variables(exec_list
*instructions
,
86 struct _mesa_symbol_table
*symtab
)
88 /* GLSL version 1.20 did not add any built-in variables in the vertex
91 generate_110_vs_variables(instructions
, symtab
);
96 generate_130_vs_variables(exec_list
*instructions
,
97 struct _mesa_symbol_table
*symtab
)
99 generate_120_vs_variables(instructions
, symtab
);
101 for (unsigned i
= 0; i
< Elements(builtin_130_vs_variables
); i
++) {
102 add_builtin_variable(& builtin_130_vs_variables
[i
],
103 instructions
, symtab
);
106 /* FINISHME: Add support fo gl_ClipDistance. The size of this array is
107 * FINISHME: implementation dependent based on the value of
108 * FINISHME: GL_MAX_CLIP_DISTANCES.
114 initialize_vs_variables(exec_list
*instructions
,
115 struct _mesa_glsl_parse_state
*state
)
118 switch (state
->language_version
) {
120 generate_110_vs_variables(instructions
, state
->symbols
);
123 generate_120_vs_variables(instructions
, state
->symbols
);
126 generate_130_vs_variables(instructions
, state
->symbols
);
133 _mesa_glsl_initialize_variables(exec_list
*instructions
,
134 struct _mesa_glsl_parse_state
*state
)
136 switch (state
->target
) {
138 initialize_vs_variables(instructions
, state
);
140 case geometry_shader
:
141 case fragment_shader
: