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