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 | |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 29 | static void generate_ARB_draw_buffers_variables(exec_list *, |
| 30 | struct _mesa_glsl_parse_state *, |
| 31 | bool, _mesa_glsl_parser_targets); |
Ian Romanick | 9c4b1f2 | 2010-06-29 15:10:09 -0700 | [diff] [blame] | 32 | |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 33 | static void |
| 34 | generate_ARB_draw_instanced_variables(exec_list *, |
| 35 | struct _mesa_glsl_parse_state *, |
| 36 | bool, _mesa_glsl_parser_targets); |
| 37 | |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 38 | static ir_variable * |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 39 | add_variable(exec_list *instructions, glsl_symbol_table *symtab, |
| 40 | const char *name, const glsl_type *type, |
| 41 | enum ir_variable_mode mode, int slot) |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 42 | { |
Ian Romanick | 7e2aa91 | 2010-07-19 17:12:42 -0700 | [diff] [blame] | 43 | ir_variable *var = new(symtab) ir_variable(type, name, mode); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 44 | |
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: |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 47 | case ir_var_in: |
Kenneth Graunke | 819d57f | 2011-01-12 15:37:37 -0800 | [diff] [blame] | 48 | case ir_var_const_in: |
Eric Anholt | 046bef2 | 2010-08-04 20:33:57 -0700 | [diff] [blame] | 49 | case ir_var_uniform: |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 50 | case ir_var_system_value: |
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: |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 54 | case ir_var_out: |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 55 | break; |
| 56 | default: |
| 57 | assert(0); |
| 58 | break; |
| 59 | } |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 60 | |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 61 | var->location = slot; |
Ian Romanick | 68a4fc9 | 2010-10-07 17:21:22 -0700 | [diff] [blame] | 62 | var->explicit_location = (slot >= 0); |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 63 | |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 64 | /* Once the variable is created an initialized, add it to the symbol table |
| 65 | * and add the declaration to the IR stream. |
| 66 | */ |
| 67 | instructions->push_tail(var); |
| 68 | |
Eric Anholt | 001eee5 | 2010-11-05 06:11:24 -0700 | [diff] [blame] | 69 | symtab->add_variable(var); |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 70 | return var; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 73 | static ir_variable * |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 74 | add_uniform(exec_list *instructions, glsl_symbol_table *symtab, |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 75 | const char *name, const glsl_type *type) |
| 76 | { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 77 | return add_variable(instructions, symtab, name, type, ir_var_uniform, -1); |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 78 | } |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 79 | |
| 80 | static void |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 81 | add_builtin_variable(exec_list *instructions, glsl_symbol_table *symtab, |
| 82 | const builtin_variable *proto) |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 83 | { |
| 84 | /* Create a new variable declaration from the description supplied by |
| 85 | * the caller. |
| 86 | */ |
| 87 | const glsl_type *const type = symtab->get_type(proto->type); |
| 88 | |
| 89 | assert(type != NULL); |
| 90 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 91 | add_variable(instructions, symtab, proto->name, type, proto->mode, |
| 92 | proto->slot); |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 95 | static void |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 96 | add_builtin_constant(exec_list *instructions, glsl_symbol_table *symtab, |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 97 | const char *name, int value) |
| 98 | { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 99 | ir_variable *const var = add_variable(instructions, symtab, |
| 100 | name, glsl_type::int_type, |
| 101 | ir_var_auto, -1); |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 102 | var->constant_value = new(var) ir_constant(value); |
| 103 | } |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 104 | |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 105 | /* Several constants in GLSL ES have different names than normal desktop GLSL. |
| 106 | * Therefore, this function should only be called on the ES path. |
| 107 | */ |
| 108 | static void |
| 109 | generate_100ES_uniforms(exec_list *instructions, |
| 110 | struct _mesa_glsl_parse_state *state) |
| 111 | { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 112 | glsl_symbol_table *const symtab = state->symbols; |
| 113 | |
| 114 | add_builtin_constant(instructions, symtab, "gl_MaxVertexAttribs", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 115 | state->Const.MaxVertexAttribs); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 116 | add_builtin_constant(instructions, symtab, "gl_MaxVertexUniformVectors", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 117 | state->Const.MaxVertexUniformComponents); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 118 | add_builtin_constant(instructions, symtab, "gl_MaxVaryingVectors", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 119 | state->Const.MaxVaryingFloats / 4); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 120 | add_builtin_constant(instructions, symtab, "gl_MaxVertexTextureImageUnits", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 121 | state->Const.MaxVertexTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 122 | add_builtin_constant(instructions, symtab, "gl_MaxCombinedTextureImageUnits", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 123 | state->Const.MaxCombinedTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 124 | add_builtin_constant(instructions, symtab, "gl_MaxTextureImageUnits", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 125 | state->Const.MaxTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 126 | add_builtin_constant(instructions, symtab, "gl_MaxFragmentUniformVectors", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 127 | state->Const.MaxFragmentUniformComponents); |
| 128 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 129 | add_uniform(instructions, symtab, "gl_DepthRange", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 130 | state->symbols->get_type("gl_DepthRangeParameters")); |
| 131 | } |
| 132 | |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 133 | static void |
| 134 | generate_110_uniforms(exec_list *instructions, |
Ian Romanick | 127308b | 2010-07-01 13:30:50 -0700 | [diff] [blame] | 135 | struct _mesa_glsl_parse_state *state) |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 136 | { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 137 | glsl_symbol_table *const symtab = state->symbols; |
| 138 | |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 139 | for (unsigned i = 0 |
| 140 | ; i < Elements(builtin_110_deprecated_uniforms) |
| 141 | ; i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 142 | add_builtin_variable(instructions, symtab, |
| 143 | & builtin_110_deprecated_uniforms[i]); |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 146 | add_builtin_constant(instructions, symtab, "gl_MaxLights", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 147 | state->Const.MaxLights); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 148 | add_builtin_constant(instructions, symtab, "gl_MaxClipPlanes", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 149 | state->Const.MaxClipPlanes); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 150 | add_builtin_constant(instructions, symtab, "gl_MaxTextureUnits", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 151 | state->Const.MaxTextureUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 152 | add_builtin_constant(instructions, symtab, "gl_MaxTextureCoords", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 153 | state->Const.MaxTextureCoords); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 154 | add_builtin_constant(instructions, symtab, "gl_MaxVertexAttribs", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 155 | state->Const.MaxVertexAttribs); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 156 | add_builtin_constant(instructions, symtab, "gl_MaxVertexUniformComponents", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 157 | state->Const.MaxVertexUniformComponents); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 158 | add_builtin_constant(instructions, symtab, "gl_MaxVaryingFloats", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 159 | state->Const.MaxVaryingFloats); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 160 | add_builtin_constant(instructions, symtab, "gl_MaxVertexTextureImageUnits", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 161 | state->Const.MaxVertexTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 162 | add_builtin_constant(instructions, symtab, "gl_MaxCombinedTextureImageUnits", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 163 | state->Const.MaxCombinedTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 164 | add_builtin_constant(instructions, symtab, "gl_MaxTextureImageUnits", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 165 | state->Const.MaxTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 166 | add_builtin_constant(instructions, symtab, "gl_MaxFragmentUniformComponents", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 167 | state->Const.MaxFragmentUniformComponents); |
Ian Romanick | 127308b | 2010-07-01 13:30:50 -0700 | [diff] [blame] | 168 | |
Ian Romanick | 3eba593 | 2010-04-26 14:59:32 -0700 | [diff] [blame] | 169 | const glsl_type *const mat4_array_type = |
Ian Romanick | f38d15b | 2010-07-20 15:33:40 -0700 | [diff] [blame] | 170 | glsl_type::get_array_instance(glsl_type::mat4_type, |
Ian Romanick | 127308b | 2010-07-01 13:30:50 -0700 | [diff] [blame] | 171 | state->Const.MaxTextureCoords); |
Ian Romanick | 3eba593 | 2010-04-26 14:59:32 -0700 | [diff] [blame] | 172 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 173 | add_uniform(instructions, symtab, "gl_TextureMatrix", mat4_array_type); |
| 174 | add_uniform(instructions, symtab, "gl_TextureMatrixInverse", mat4_array_type); |
| 175 | add_uniform(instructions, symtab, "gl_TextureMatrixTranspose", mat4_array_type); |
| 176 | add_uniform(instructions, symtab, "gl_TextureMatrixInverseTranspose", mat4_array_type); |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 177 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 178 | add_uniform(instructions, symtab, "gl_DepthRange", |
| 179 | symtab->get_type("gl_DepthRangeParameters")); |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 180 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 181 | add_uniform(instructions, symtab, "gl_ClipPlane", |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 182 | glsl_type::get_array_instance(glsl_type::vec4_type, |
| 183 | state->Const.MaxClipPlanes)); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 184 | add_uniform(instructions, symtab, "gl_Point", |
| 185 | symtab->get_type("gl_PointParameters")); |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 186 | |
| 187 | const glsl_type *const material_parameters_type = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 188 | symtab->get_type("gl_MaterialParameters"); |
| 189 | add_uniform(instructions, symtab, "gl_FrontMaterial", material_parameters_type); |
| 190 | add_uniform(instructions, symtab, "gl_BackMaterial", material_parameters_type); |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 191 | |
Eric Anholt | aa57943 | 2010-05-19 14:09:04 -0700 | [diff] [blame] | 192 | const glsl_type *const light_source_array_type = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 193 | glsl_type::get_array_instance(symtab->get_type("gl_LightSourceParameters"), state->Const.MaxLights); |
Eric Anholt | aa57943 | 2010-05-19 14:09:04 -0700 | [diff] [blame] | 194 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 195 | add_uniform(instructions, symtab, "gl_LightSource", light_source_array_type); |
Eric Anholt | aa57943 | 2010-05-19 14:09:04 -0700 | [diff] [blame] | 196 | |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 197 | const glsl_type *const light_model_products_type = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 198 | symtab->get_type("gl_LightModelProducts"); |
| 199 | add_uniform(instructions, symtab, "gl_FrontLightModelProduct", |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 200 | light_model_products_type); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 201 | add_uniform(instructions, symtab, "gl_BackLightModelProduct", |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 202 | light_model_products_type); |
| 203 | |
| 204 | const glsl_type *const light_products_type = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 205 | glsl_type::get_array_instance(symtab->get_type("gl_LightProducts"), |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 206 | state->Const.MaxLights); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 207 | add_uniform(instructions, symtab, "gl_FrontLightProduct", light_products_type); |
| 208 | add_uniform(instructions, symtab, "gl_BackLightProduct", light_products_type); |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 209 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 210 | add_uniform(instructions, symtab, "gl_TextureEnvColor", |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 211 | glsl_type::get_array_instance(glsl_type::vec4_type, |
| 212 | state->Const.MaxTextureUnits)); |
| 213 | |
| 214 | const glsl_type *const texcoords_vec4 = |
| 215 | glsl_type::get_array_instance(glsl_type::vec4_type, |
| 216 | state->Const.MaxTextureCoords); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 217 | add_uniform(instructions, symtab, "gl_EyePlaneS", texcoords_vec4); |
| 218 | add_uniform(instructions, symtab, "gl_EyePlaneT", texcoords_vec4); |
| 219 | add_uniform(instructions, symtab, "gl_EyePlaneR", texcoords_vec4); |
| 220 | add_uniform(instructions, symtab, "gl_EyePlaneQ", texcoords_vec4); |
| 221 | add_uniform(instructions, symtab, "gl_ObjectPlaneS", texcoords_vec4); |
| 222 | add_uniform(instructions, symtab, "gl_ObjectPlaneT", texcoords_vec4); |
| 223 | add_uniform(instructions, symtab, "gl_ObjectPlaneR", texcoords_vec4); |
| 224 | add_uniform(instructions, symtab, "gl_ObjectPlaneQ", texcoords_vec4); |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 225 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 226 | add_uniform(instructions, symtab, "gl_Fog", |
| 227 | symtab->get_type("gl_FogParameters")); |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 228 | } |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 229 | |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 230 | /* This function should only be called for ES, not desktop GL. */ |
| 231 | static void |
| 232 | generate_100ES_vs_variables(exec_list *instructions, |
| 233 | struct _mesa_glsl_parse_state *state) |
| 234 | { |
| 235 | for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 236 | add_builtin_variable(instructions, state->symbols, |
| 237 | & builtin_core_vs_variables[i]); |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | generate_100ES_uniforms(instructions, state); |
| 241 | |
| 242 | generate_ARB_draw_buffers_variables(instructions, state, false, |
| 243 | vertex_shader); |
| 244 | } |
| 245 | |
| 246 | |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 247 | static void |
| 248 | generate_110_vs_variables(exec_list *instructions, |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 249 | struct _mesa_glsl_parse_state *state) |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 250 | { |
| 251 | for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 252 | add_builtin_variable(instructions, state->symbols, |
| 253 | & builtin_core_vs_variables[i]); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | for (unsigned i = 0 |
| 257 | ; i < Elements(builtin_110_deprecated_vs_variables) |
| 258 | ; i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 259 | add_builtin_variable(instructions, state->symbols, |
| 260 | & builtin_110_deprecated_vs_variables[i]); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 261 | } |
Ian Romanick | 127308b | 2010-07-01 13:30:50 -0700 | [diff] [blame] | 262 | generate_110_uniforms(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 263 | |
Ian Romanick | cd00d5b | 2010-07-01 13:17:54 -0700 | [diff] [blame] | 264 | /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec: |
| 265 | * |
| 266 | * "As with all arrays, indices used to subscript gl_TexCoord must |
| 267 | * either be an integral constant expressions, or this array must be |
| 268 | * re-declared by the shader with a size. The size can be at most |
| 269 | * gl_MaxTextureCoords. Using indexes close to 0 may aid the |
| 270 | * implementation in preserving varying resources." |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 271 | */ |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 272 | const glsl_type *const vec4_array_type = |
Ian Romanick | f38d15b | 2010-07-20 15:33:40 -0700 | [diff] [blame] | 273 | glsl_type::get_array_instance(glsl_type::vec4_type, 0); |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 274 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 275 | add_variable(instructions, state->symbols, |
| 276 | "gl_TexCoord", vec4_array_type, ir_var_out, VERT_RESULT_TEX0); |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 277 | |
| 278 | generate_ARB_draw_buffers_variables(instructions, state, false, |
| 279 | vertex_shader); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | |
| 283 | static void |
| 284 | generate_120_vs_variables(exec_list *instructions, |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 285 | struct _mesa_glsl_parse_state *state) |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 286 | { |
| 287 | /* GLSL version 1.20 did not add any built-in variables in the vertex |
| 288 | * shader. |
| 289 | */ |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 290 | generate_110_vs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | |
| 294 | static void |
| 295 | generate_130_vs_variables(exec_list *instructions, |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 296 | struct _mesa_glsl_parse_state *state) |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 297 | { |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 298 | generate_120_vs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 299 | |
| 300 | for (unsigned i = 0; i < Elements(builtin_130_vs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 301 | add_builtin_variable(instructions, state->symbols, |
| 302 | & builtin_130_vs_variables[i]); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 303 | } |
| 304 | |
Eric Anholt | 271e199 | 2010-04-02 23:47:06 -0700 | [diff] [blame] | 305 | const glsl_type *const clip_distance_array_type = |
Eric Anholt | 73df636 | 2010-07-28 08:18:59 -0700 | [diff] [blame] | 306 | glsl_type::get_array_instance(glsl_type::float_type, |
| 307 | state->Const.MaxClipPlanes); |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 308 | |
| 309 | /* FINISHME: gl_ClipDistance needs a real location assigned. */ |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 310 | add_variable(instructions, state->symbols, |
| 311 | "gl_ClipDistance", clip_distance_array_type, ir_var_out, -1); |
Eric Anholt | 271e199 | 2010-04-02 23:47:06 -0700 | [diff] [blame] | 312 | |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | |
| 316 | static void |
| 317 | initialize_vs_variables(exec_list *instructions, |
| 318 | struct _mesa_glsl_parse_state *state) |
| 319 | { |
| 320 | |
| 321 | switch (state->language_version) { |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 322 | case 100: |
| 323 | generate_100ES_vs_variables(instructions, state); |
| 324 | break; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 325 | case 110: |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 326 | generate_110_vs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 327 | break; |
| 328 | case 120: |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 329 | generate_120_vs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 330 | break; |
| 331 | case 130: |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 332 | generate_130_vs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 333 | break; |
| 334 | } |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 335 | |
| 336 | if (state->ARB_draw_instanced_enable) |
| 337 | generate_ARB_draw_instanced_variables(instructions, state, false, |
| 338 | vertex_shader); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 339 | } |
| 340 | |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 341 | |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 342 | /* This function should only be called for ES, not desktop GL. */ |
| 343 | static void |
| 344 | generate_100ES_fs_variables(exec_list *instructions, |
| 345 | struct _mesa_glsl_parse_state *state) |
| 346 | { |
| 347 | for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 348 | add_builtin_variable(instructions, state->symbols, |
| 349 | & builtin_core_fs_variables[i]); |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | for (unsigned i = 0; i < Elements(builtin_100ES_fs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 353 | add_builtin_variable(instructions, state->symbols, |
| 354 | & builtin_100ES_fs_variables[i]); |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | generate_100ES_uniforms(instructions, state); |
| 358 | |
| 359 | generate_ARB_draw_buffers_variables(instructions, state, false, |
| 360 | fragment_shader); |
| 361 | } |
| 362 | |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 363 | static void |
| 364 | generate_110_fs_variables(exec_list *instructions, |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 365 | struct _mesa_glsl_parse_state *state) |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 366 | { |
| 367 | for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 368 | add_builtin_variable(instructions, state->symbols, |
| 369 | & builtin_core_fs_variables[i]); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 372 | for (unsigned i = 0; i < Elements(builtin_110_fs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 373 | add_builtin_variable(instructions, state->symbols, |
| 374 | & builtin_110_fs_variables[i]); |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Eric Anholt | 0f09aea | 2010-03-27 12:48:57 -0700 | [diff] [blame] | 377 | for (unsigned i = 0 |
| 378 | ; i < Elements(builtin_110_deprecated_fs_variables) |
| 379 | ; i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 380 | add_builtin_variable(instructions, state->symbols, |
| 381 | & builtin_110_deprecated_fs_variables[i]); |
Eric Anholt | 0f09aea | 2010-03-27 12:48:57 -0700 | [diff] [blame] | 382 | } |
Ian Romanick | 127308b | 2010-07-01 13:30:50 -0700 | [diff] [blame] | 383 | generate_110_uniforms(instructions, state); |
Eric Anholt | 0f09aea | 2010-03-27 12:48:57 -0700 | [diff] [blame] | 384 | |
Ian Romanick | cd00d5b | 2010-07-01 13:17:54 -0700 | [diff] [blame] | 385 | /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec: |
| 386 | * |
| 387 | * "As with all arrays, indices used to subscript gl_TexCoord must |
| 388 | * either be an integral constant expressions, or this array must be |
| 389 | * re-declared by the shader with a size. The size can be at most |
| 390 | * gl_MaxTextureCoords. Using indexes close to 0 may aid the |
| 391 | * implementation in preserving varying resources." |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 392 | */ |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 393 | const glsl_type *const vec4_array_type = |
Ian Romanick | f38d15b | 2010-07-20 15:33:40 -0700 | [diff] [blame] | 394 | glsl_type::get_array_instance(glsl_type::vec4_type, 0); |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 395 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 396 | add_variable(instructions, state->symbols, |
| 397 | "gl_TexCoord", vec4_array_type, ir_var_in, FRAG_ATTRIB_TEX0); |
Ian Romanick | 9c4b1f2 | 2010-06-29 15:10:09 -0700 | [diff] [blame] | 398 | |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 399 | generate_ARB_draw_buffers_variables(instructions, state, false, |
| 400 | fragment_shader); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 403 | |
| 404 | static void |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 405 | generate_ARB_draw_buffers_variables(exec_list *instructions, |
| 406 | struct _mesa_glsl_parse_state *state, |
| 407 | bool warn, _mesa_glsl_parser_targets target) |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 408 | { |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 409 | /* gl_MaxDrawBuffers is available in all shader stages. |
| 410 | */ |
Ian Romanick | e2f84f0 | 2010-06-29 15:19:11 -0700 | [diff] [blame] | 411 | ir_variable *const mdb = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 412 | add_variable(instructions, state->symbols, |
| 413 | "gl_MaxDrawBuffers", glsl_type::int_type, ir_var_auto, -1); |
Ian Romanick | e2f84f0 | 2010-06-29 15:19:11 -0700 | [diff] [blame] | 414 | |
| 415 | if (warn) |
| 416 | mdb->warn_extension = "GL_ARB_draw_buffers"; |
| 417 | |
| 418 | mdb->constant_value = new(mdb) |
| 419 | ir_constant(int(state->Const.MaxDrawBuffers)); |
| 420 | |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 421 | |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 422 | /* gl_FragData is only available in the fragment shader. |
| 423 | */ |
| 424 | if (target == fragment_shader) { |
| 425 | const glsl_type *const vec4_array_type = |
Ian Romanick | f38d15b | 2010-07-20 15:33:40 -0700 | [diff] [blame] | 426 | glsl_type::get_array_instance(glsl_type::vec4_type, |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 427 | state->Const.MaxDrawBuffers); |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 428 | |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 429 | ir_variable *const fd = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 430 | add_variable(instructions, state->symbols, |
| 431 | "gl_FragData", vec4_array_type, |
| 432 | ir_var_out, FRAG_RESULT_DATA0); |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 433 | |
| 434 | if (warn) |
| 435 | fd->warn_extension = "GL_ARB_draw_buffers"; |
| 436 | } |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 439 | |
| 440 | static void |
| 441 | generate_ARB_draw_instanced_variables(exec_list *instructions, |
| 442 | struct _mesa_glsl_parse_state *state, |
| 443 | bool warn, |
| 444 | _mesa_glsl_parser_targets target) |
| 445 | { |
| 446 | /* gl_InstanceIDARB is only available in the vertex shader. |
| 447 | */ |
| 448 | if (target == vertex_shader) { |
| 449 | ir_variable *const inst = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 450 | add_variable(instructions, state->symbols, |
| 451 | "gl_InstanceIDARB", glsl_type::int_type, |
| 452 | ir_var_system_value, SYSTEM_VALUE_INSTANCE_ID); |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 453 | |
| 454 | if (warn) |
| 455 | inst->warn_extension = "GL_ARB_draw_instanced"; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | |
Dave Airlie | d967186 | 2010-10-06 09:36:02 +1000 | [diff] [blame] | 460 | static void |
| 461 | generate_ARB_shader_stencil_export_variables(exec_list *instructions, |
| 462 | struct _mesa_glsl_parse_state *state, |
| 463 | bool warn) |
| 464 | { |
| 465 | /* gl_FragStencilRefARB is only available in the fragment shader. |
| 466 | */ |
| 467 | ir_variable *const fd = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 468 | add_variable(instructions, state->symbols, |
| 469 | "gl_FragStencilRefARB", glsl_type::int_type, |
| 470 | ir_var_out, FRAG_RESULT_STENCIL); |
Dave Airlie | d967186 | 2010-10-06 09:36:02 +1000 | [diff] [blame] | 471 | |
| 472 | if (warn) |
| 473 | fd->warn_extension = "GL_ARB_shader_stencil_export"; |
| 474 | } |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 475 | |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 476 | static void |
| 477 | generate_120_fs_variables(exec_list *instructions, |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 478 | struct _mesa_glsl_parse_state *state) |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 479 | { |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 480 | generate_110_fs_variables(instructions, state); |
Eric Anholt | 152b55e | 2010-07-07 19:45:22 -0700 | [diff] [blame] | 481 | |
| 482 | for (unsigned i = 0 |
| 483 | ; i < Elements(builtin_120_fs_variables) |
| 484 | ; i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 485 | add_builtin_variable(instructions, state->symbols, |
| 486 | & builtin_120_fs_variables[i]); |
Eric Anholt | 152b55e | 2010-07-07 19:45:22 -0700 | [diff] [blame] | 487 | } |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | static void |
| 491 | generate_130_fs_variables(exec_list *instructions, |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 492 | struct _mesa_glsl_parse_state *state) |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 493 | { |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 494 | generate_120_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 495 | |
Ian Romanick | 8645a95 | 2010-04-07 16:47:44 -0700 | [diff] [blame] | 496 | const glsl_type *const clip_distance_array_type = |
Eric Anholt | 73df636 | 2010-07-28 08:18:59 -0700 | [diff] [blame] | 497 | glsl_type::get_array_instance(glsl_type::float_type, |
| 498 | state->Const.MaxClipPlanes); |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 499 | |
| 500 | /* FINISHME: gl_ClipDistance needs a real location assigned. */ |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame^] | 501 | add_variable(instructions, state->symbols, |
| 502 | "gl_ClipDistance", clip_distance_array_type, ir_var_in, -1); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | static void |
| 506 | initialize_fs_variables(exec_list *instructions, |
| 507 | struct _mesa_glsl_parse_state *state) |
| 508 | { |
| 509 | |
| 510 | switch (state->language_version) { |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 511 | case 100: |
| 512 | generate_100ES_fs_variables(instructions, state); |
| 513 | break; |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 514 | case 110: |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 515 | generate_110_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 516 | break; |
| 517 | case 120: |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 518 | generate_120_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 519 | break; |
| 520 | case 130: |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 521 | generate_130_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 522 | break; |
| 523 | } |
Dave Airlie | d967186 | 2010-10-06 09:36:02 +1000 | [diff] [blame] | 524 | |
| 525 | if (state->ARB_shader_stencil_export_enable) |
| 526 | generate_ARB_shader_stencil_export_variables(instructions, state, |
| 527 | state->ARB_shader_stencil_export_warn); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 528 | } |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 529 | |
| 530 | void |
| 531 | _mesa_glsl_initialize_variables(exec_list *instructions, |
| 532 | struct _mesa_glsl_parse_state *state) |
| 533 | { |
| 534 | switch (state->target) { |
| 535 | case vertex_shader: |
| 536 | initialize_vs_variables(instructions, state); |
| 537 | break; |
| 538 | case geometry_shader: |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 539 | break; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 540 | case fragment_shader: |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 541 | initialize_fs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 542 | break; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 543 | } |
| 544 | } |