Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 1 | /* |
| 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 Anholt | ac95f2f | 2010-06-22 10:38:52 -0700 | [diff] [blame] | 24 | #include "ir.h" |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 25 | #include "glsl_parser_extras.h" |
Ian Romanick | 8bde4ce | 2010-03-19 11:57:24 -0700 | [diff] [blame] | 26 | #include "glsl_symbol_table.h" |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 27 | #include "builtin_variables.h" |
| 28 | |
| 29 | #ifndef Elements |
| 30 | #define Elements(x) (sizeof(x)/sizeof(*(x))) |
| 31 | #endif |
| 32 | |
Ian Romanick | 9c4b1f2 | 2010-06-29 15:10:09 -0700 | [diff] [blame^] | 33 | static void generate_ARB_draw_buffers_fs_variables(exec_list *, |
| 34 | struct _mesa_glsl_parse_state *, bool); |
| 35 | |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 36 | static ir_variable * |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 37 | add_variable(const char *name, enum ir_variable_mode mode, int slot, |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 38 | const glsl_type *type, exec_list *instructions, |
Ian Romanick | 8bde4ce | 2010-03-19 11:57:24 -0700 | [diff] [blame] | 39 | glsl_symbol_table *symtab) |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 40 | { |
Carl Worth | 1660a29 | 2010-06-23 18:11:51 -0700 | [diff] [blame] | 41 | ir_variable *var = new(symtab) ir_variable(type, name); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 42 | |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 43 | var->mode = mode; |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 44 | switch (var->mode) { |
| 45 | case ir_var_in: |
| 46 | var->shader_in = true; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 47 | var->read_only = true; |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 48 | break; |
| 49 | case ir_var_inout: |
| 50 | var->shader_in = true; |
| 51 | var->shader_out = true; |
Ian Romanick | ff236fa | 2010-04-21 15:08:08 -0700 | [diff] [blame] | 52 | break; |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 53 | case ir_var_out: |
| 54 | var->shader_out = true; |
| 55 | break; |
| 56 | case ir_var_uniform: |
| 57 | var->shader_in = true; |
| 58 | var->read_only = true; |
| 59 | break; |
| 60 | default: |
| 61 | assert(0); |
| 62 | break; |
| 63 | } |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 64 | |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 65 | var->location = slot; |
| 66 | |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 67 | /* Once the variable is created an initialized, add it to the symbol table |
| 68 | * and add the declaration to the IR stream. |
| 69 | */ |
| 70 | instructions->push_tail(var); |
| 71 | |
Ian Romanick | 8bde4ce | 2010-03-19 11:57:24 -0700 | [diff] [blame] | 72 | symtab->add_variable(var->name, var); |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 73 | return var; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 76 | |
| 77 | static void |
| 78 | add_builtin_variable(const builtin_variable *proto, exec_list *instructions, |
| 79 | glsl_symbol_table *symtab) |
| 80 | { |
| 81 | /* Create a new variable declaration from the description supplied by |
| 82 | * the caller. |
| 83 | */ |
| 84 | const glsl_type *const type = symtab->get_type(proto->type); |
| 85 | |
| 86 | assert(type != NULL); |
| 87 | |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 88 | add_variable(proto->name, proto->mode, proto->slot, type, instructions, |
| 89 | symtab); |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 93 | static void |
| 94 | generate_110_uniforms(exec_list *instructions, |
| 95 | glsl_symbol_table *symtab) |
| 96 | { |
| 97 | for (unsigned i = 0 |
| 98 | ; i < Elements(builtin_110_deprecated_uniforms) |
| 99 | ; i++) { |
| 100 | add_builtin_variable(& builtin_110_deprecated_uniforms[i], |
| 101 | instructions, symtab); |
| 102 | } |
| 103 | |
Ian Romanick | 3eba593 | 2010-04-26 14:59:32 -0700 | [diff] [blame] | 104 | /* FINISHME: The size of this array is implementation dependent based on the |
Ian Romanick | cfb3536 | 2010-06-07 19:10:33 -0700 | [diff] [blame] | 105 | * FINISHME: value of GL_MAX_TEXTURE_COORDS. Every platform that supports |
| 106 | * FINISHME: GLSL sets GL_MAX_TEXTURE_COORDS to at least 4, so hard-code 4 |
| 107 | * FINISHME: for now. |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 108 | */ |
Ian Romanick | 3eba593 | 2010-04-26 14:59:32 -0700 | [diff] [blame] | 109 | const glsl_type *const mat4_array_type = |
Carl Worth | 12c4115 | 2010-06-18 17:52:59 -0700 | [diff] [blame] | 110 | glsl_type::get_array_instance(symtab, glsl_type::mat4_type, 4); |
Ian Romanick | 3eba593 | 2010-04-26 14:59:32 -0700 | [diff] [blame] | 111 | |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 112 | add_variable("gl_TextureMatrix", ir_var_uniform, -1, mat4_array_type, |
Ian Romanick | 3eba593 | 2010-04-26 14:59:32 -0700 | [diff] [blame] | 113 | instructions, symtab); |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 114 | |
| 115 | /* FINISHME: Add support for gl_DepthRangeParameters */ |
| 116 | /* FINISHME: Add support for gl_ClipPlane[] */ |
| 117 | /* FINISHME: Add support for gl_PointParameters */ |
| 118 | |
| 119 | /* FINISHME: Add support for gl_MaterialParameters |
| 120 | * FINISHME: (glFrontMaterial, glBackMaterial) |
| 121 | */ |
| 122 | |
Eric Anholt | aa57943 | 2010-05-19 14:09:04 -0700 | [diff] [blame] | 123 | /* FINISHME: The size of this array is implementation dependent based on the |
| 124 | * FINISHME: value of GL_MAX_TEXTURE_LIGHTS. GL_MAX_TEXTURE_LIGHTS must be |
| 125 | * FINISHME: at least 8, so hard-code 8 for now. |
| 126 | */ |
| 127 | const glsl_type *const light_source_array_type = |
Carl Worth | 12c4115 | 2010-06-18 17:52:59 -0700 | [diff] [blame] | 128 | glsl_type::get_array_instance(symtab, |
| 129 | symtab->get_type("gl_LightSourceParameters"), 8); |
Eric Anholt | aa57943 | 2010-05-19 14:09:04 -0700 | [diff] [blame] | 130 | |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 131 | add_variable("gl_LightSource", ir_var_uniform, -1, light_source_array_type, |
Eric Anholt | aa57943 | 2010-05-19 14:09:04 -0700 | [diff] [blame] | 132 | instructions, symtab); |
| 133 | |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 134 | /* FINISHME: Add support for gl_LightModel */ |
| 135 | /* FINISHME: Add support for gl_FrontLightProduct[], gl_BackLightProduct[] */ |
| 136 | /* FINISHME: Add support for gl_TextureEnvColor[] */ |
| 137 | /* FINISHME: Add support for gl_ObjectPlane*[], gl_EyePlane*[] */ |
| 138 | /* FINISHME: Add support for gl_Fog */ |
| 139 | } |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 140 | |
| 141 | static void |
| 142 | generate_110_vs_variables(exec_list *instructions, |
Ian Romanick | 8bde4ce | 2010-03-19 11:57:24 -0700 | [diff] [blame] | 143 | glsl_symbol_table *symtab) |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 144 | { |
| 145 | for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) { |
| 146 | add_builtin_variable(& builtin_core_vs_variables[i], |
| 147 | instructions, symtab); |
| 148 | } |
| 149 | |
| 150 | for (unsigned i = 0 |
| 151 | ; i < Elements(builtin_110_deprecated_vs_variables) |
| 152 | ; i++) { |
| 153 | add_builtin_variable(& builtin_110_deprecated_vs_variables[i], |
| 154 | instructions, symtab); |
| 155 | } |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 156 | generate_110_uniforms(instructions, symtab); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 157 | |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 158 | /* FINISHME: The size of this array is implementation dependent based on the |
Ian Romanick | cfb3536 | 2010-06-07 19:10:33 -0700 | [diff] [blame] | 159 | * FINISHME: value of GL_MAX_TEXTURE_COORDS. Every platform that supports |
| 160 | * FINISHME: GLSL sets GL_MAX_TEXTURE_COORDS to at least 4, so hard-code 4 |
| 161 | * FINISHME: for now. |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 162 | */ |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 163 | const glsl_type *const vec4_array_type = |
Carl Worth | 12c4115 | 2010-06-18 17:52:59 -0700 | [diff] [blame] | 164 | glsl_type::get_array_instance(symtab, glsl_type::vec4_type, 4); |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 165 | |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 166 | add_variable("gl_TexCoord", ir_var_out, VERT_RESULT_TEX0, vec4_array_type, |
| 167 | instructions, symtab); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | |
| 171 | static void |
| 172 | generate_120_vs_variables(exec_list *instructions, |
Ian Romanick | 8bde4ce | 2010-03-19 11:57:24 -0700 | [diff] [blame] | 173 | glsl_symbol_table *symtab) |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 174 | { |
| 175 | /* GLSL version 1.20 did not add any built-in variables in the vertex |
| 176 | * shader. |
| 177 | */ |
| 178 | generate_110_vs_variables(instructions, symtab); |
| 179 | } |
| 180 | |
| 181 | |
| 182 | static void |
| 183 | generate_130_vs_variables(exec_list *instructions, |
Ian Romanick | 8bde4ce | 2010-03-19 11:57:24 -0700 | [diff] [blame] | 184 | glsl_symbol_table *symtab) |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 185 | { |
Carl Worth | 12c4115 | 2010-06-18 17:52:59 -0700 | [diff] [blame] | 186 | void *ctx = symtab; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 187 | generate_120_vs_variables(instructions, symtab); |
| 188 | |
| 189 | for (unsigned i = 0; i < Elements(builtin_130_vs_variables); i++) { |
| 190 | add_builtin_variable(& builtin_130_vs_variables[i], |
| 191 | instructions, symtab); |
| 192 | } |
| 193 | |
Eric Anholt | 271e199 | 2010-04-02 23:47:06 -0700 | [diff] [blame] | 194 | /* FINISHME: The size of this array is implementation dependent based on |
| 195 | * FINISHME: the value of GL_MAX_CLIP_DISTANCES. |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 196 | */ |
Eric Anholt | 271e199 | 2010-04-02 23:47:06 -0700 | [diff] [blame] | 197 | const glsl_type *const clip_distance_array_type = |
Carl Worth | 12c4115 | 2010-06-18 17:52:59 -0700 | [diff] [blame] | 198 | glsl_type::get_array_instance(ctx, glsl_type::float_type, 8); |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 199 | |
| 200 | /* FINISHME: gl_ClipDistance needs a real location assigned. */ |
| 201 | add_variable("gl_ClipDistance", ir_var_out, -1, clip_distance_array_type, |
Eric Anholt | 271e199 | 2010-04-02 23:47:06 -0700 | [diff] [blame] | 202 | instructions, symtab); |
| 203 | |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | |
| 207 | static void |
| 208 | initialize_vs_variables(exec_list *instructions, |
| 209 | struct _mesa_glsl_parse_state *state) |
| 210 | { |
| 211 | |
| 212 | switch (state->language_version) { |
| 213 | case 110: |
| 214 | generate_110_vs_variables(instructions, state->symbols); |
| 215 | break; |
| 216 | case 120: |
| 217 | generate_120_vs_variables(instructions, state->symbols); |
| 218 | break; |
| 219 | case 130: |
| 220 | generate_130_vs_variables(instructions, state->symbols); |
| 221 | break; |
| 222 | } |
| 223 | } |
| 224 | |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 225 | static void |
| 226 | generate_110_fs_variables(exec_list *instructions, |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 227 | struct _mesa_glsl_parse_state *state) |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 228 | { |
| 229 | for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) { |
| 230 | add_builtin_variable(& builtin_core_fs_variables[i], |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 231 | instructions, state->symbols); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Eric Anholt | 0f09aea | 2010-03-27 12:48:57 -0700 | [diff] [blame] | 234 | for (unsigned i = 0 |
| 235 | ; i < Elements(builtin_110_deprecated_fs_variables) |
| 236 | ; i++) { |
| 237 | add_builtin_variable(& builtin_110_deprecated_fs_variables[i], |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 238 | instructions, state->symbols); |
Eric Anholt | 0f09aea | 2010-03-27 12:48:57 -0700 | [diff] [blame] | 239 | } |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 240 | generate_110_uniforms(instructions, state->symbols); |
Eric Anholt | 0f09aea | 2010-03-27 12:48:57 -0700 | [diff] [blame] | 241 | |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 242 | /* FINISHME: The size of this array is implementation dependent based on the |
Ian Romanick | cfb3536 | 2010-06-07 19:10:33 -0700 | [diff] [blame] | 243 | * FINISHME: value of GL_MAX_TEXTURE_COORDS. Every platform that supports |
| 244 | * FINISHME: GLSL sets GL_MAX_TEXTURE_COORDS to at least 4, so hard-code 4 |
| 245 | * FINISHME: for now. |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 246 | */ |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 247 | const glsl_type *const vec4_array_type = |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 248 | glsl_type::get_array_instance(state->symbols, glsl_type::vec4_type, 4); |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 249 | |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 250 | add_variable("gl_TexCoord", ir_var_in, FRAG_ATTRIB_TEX0, vec4_array_type, |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 251 | instructions, state->symbols); |
Ian Romanick | 9c4b1f2 | 2010-06-29 15:10:09 -0700 | [diff] [blame^] | 252 | |
| 253 | generate_ARB_draw_buffers_fs_variables(instructions, state, false); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 256 | |
| 257 | static void |
| 258 | generate_ARB_draw_buffers_fs_variables(exec_list *instructions, |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 259 | struct _mesa_glsl_parse_state *state, |
| 260 | bool warn) |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 261 | { |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 262 | const glsl_type *const vec4_array_type = |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 263 | glsl_type::get_array_instance(state->symbols, glsl_type::vec4_type, |
| 264 | state->Const.MaxDrawBuffers); |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 265 | |
| 266 | ir_variable *const fd = |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 267 | add_variable("gl_FragData", ir_var_out, FRAG_RESULT_DATA0, |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 268 | vec4_array_type, instructions, state->symbols); |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 269 | |
| 270 | if (warn) |
| 271 | fd->warn_extension = "GL_ARB_draw_buffers"; |
| 272 | } |
| 273 | |
| 274 | |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 275 | static void |
| 276 | generate_120_fs_variables(exec_list *instructions, |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 277 | struct _mesa_glsl_parse_state *state) |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 278 | { |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 279 | generate_110_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | static void |
| 283 | generate_130_fs_variables(exec_list *instructions, |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 284 | struct _mesa_glsl_parse_state *state) |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 285 | { |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 286 | void *ctx = state->symbols; |
| 287 | generate_120_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 288 | |
Ian Romanick | 8645a95 | 2010-04-07 16:47:44 -0700 | [diff] [blame] | 289 | /* FINISHME: The size of this array is implementation dependent based on |
| 290 | * FINISHME: the value of GL_MAX_CLIP_DISTANCES. |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 291 | */ |
Ian Romanick | 8645a95 | 2010-04-07 16:47:44 -0700 | [diff] [blame] | 292 | const glsl_type *const clip_distance_array_type = |
Carl Worth | 12c4115 | 2010-06-18 17:52:59 -0700 | [diff] [blame] | 293 | glsl_type::get_array_instance(ctx, glsl_type::float_type, 8); |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 294 | |
| 295 | /* FINISHME: gl_ClipDistance needs a real location assigned. */ |
| 296 | add_variable("gl_ClipDistance", ir_var_in, -1, clip_distance_array_type, |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 297 | instructions, state->symbols); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | static void |
| 301 | initialize_fs_variables(exec_list *instructions, |
| 302 | struct _mesa_glsl_parse_state *state) |
| 303 | { |
| 304 | |
| 305 | switch (state->language_version) { |
| 306 | case 110: |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 307 | generate_110_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 308 | break; |
| 309 | case 120: |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 310 | generate_120_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 311 | break; |
| 312 | case 130: |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 313 | generate_130_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 314 | break; |
| 315 | } |
| 316 | } |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 317 | |
| 318 | void |
| 319 | _mesa_glsl_initialize_variables(exec_list *instructions, |
| 320 | struct _mesa_glsl_parse_state *state) |
| 321 | { |
| 322 | switch (state->target) { |
| 323 | case vertex_shader: |
| 324 | initialize_vs_variables(instructions, state); |
| 325 | break; |
| 326 | case geometry_shader: |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 327 | break; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 328 | case fragment_shader: |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 329 | initialize_fs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 330 | break; |
Eric Anholt | 81f49a7 | 2010-04-29 17:57:28 -0700 | [diff] [blame] | 331 | case ir_shader: |
| 332 | fprintf(stderr, "ir reader has no builtin variables"); |
| 333 | exit(1); |
| 334 | break; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 335 | } |
| 336 | } |