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" |
Ian Romanick | 92e412e | 2011-01-24 16:55:50 -0800 | [diff] [blame] | 28 | #include "main/uniforms.h" |
| 29 | #include "program/prog_parameter.h" |
| 30 | #include "program/prog_statevars.h" |
| 31 | #include "program/prog_instruction.h" |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 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 | |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 37 | static void |
| 38 | generate_ARB_draw_instanced_variables(exec_list *, |
| 39 | struct _mesa_glsl_parse_state *, |
| 40 | bool, _mesa_glsl_parser_targets); |
| 41 | |
Ian Romanick | 92e412e | 2011-01-24 16:55:50 -0800 | [diff] [blame] | 42 | static struct gl_builtin_uniform_element gl_DepthRange_elements[] = { |
| 43 | {"near", {STATE_DEPTH_RANGE, 0, 0}, SWIZZLE_XXXX}, |
| 44 | {"far", {STATE_DEPTH_RANGE, 0, 0}, SWIZZLE_YYYY}, |
| 45 | {"diff", {STATE_DEPTH_RANGE, 0, 0}, SWIZZLE_ZZZZ}, |
| 46 | }; |
| 47 | |
| 48 | static struct gl_builtin_uniform_element gl_ClipPlane_elements[] = { |
| 49 | {NULL, {STATE_CLIPPLANE, 0, 0}, SWIZZLE_XYZW} |
| 50 | }; |
| 51 | |
| 52 | static struct gl_builtin_uniform_element gl_Point_elements[] = { |
| 53 | {"size", {STATE_POINT_SIZE}, SWIZZLE_XXXX}, |
| 54 | {"sizeMin", {STATE_POINT_SIZE}, SWIZZLE_YYYY}, |
| 55 | {"sizeMax", {STATE_POINT_SIZE}, SWIZZLE_ZZZZ}, |
| 56 | {"fadeThresholdSize", {STATE_POINT_SIZE}, SWIZZLE_WWWW}, |
| 57 | {"distanceConstantAttenuation", {STATE_POINT_ATTENUATION}, SWIZZLE_XXXX}, |
| 58 | {"distanceLinearAttenuation", {STATE_POINT_ATTENUATION}, SWIZZLE_YYYY}, |
| 59 | {"distanceQuadraticAttenuation", {STATE_POINT_ATTENUATION}, SWIZZLE_ZZZZ}, |
| 60 | }; |
| 61 | |
| 62 | static struct gl_builtin_uniform_element gl_FrontMaterial_elements[] = { |
| 63 | {"emission", {STATE_MATERIAL, 0, STATE_EMISSION}, SWIZZLE_XYZW}, |
| 64 | {"ambient", {STATE_MATERIAL, 0, STATE_AMBIENT}, SWIZZLE_XYZW}, |
| 65 | {"diffuse", {STATE_MATERIAL, 0, STATE_DIFFUSE}, SWIZZLE_XYZW}, |
| 66 | {"specular", {STATE_MATERIAL, 0, STATE_SPECULAR}, SWIZZLE_XYZW}, |
| 67 | {"shininess", {STATE_MATERIAL, 0, STATE_SHININESS}, SWIZZLE_XXXX}, |
| 68 | }; |
| 69 | |
| 70 | static struct gl_builtin_uniform_element gl_BackMaterial_elements[] = { |
| 71 | {"emission", {STATE_MATERIAL, 1, STATE_EMISSION}, SWIZZLE_XYZW}, |
| 72 | {"ambient", {STATE_MATERIAL, 1, STATE_AMBIENT}, SWIZZLE_XYZW}, |
| 73 | {"diffuse", {STATE_MATERIAL, 1, STATE_DIFFUSE}, SWIZZLE_XYZW}, |
| 74 | {"specular", {STATE_MATERIAL, 1, STATE_SPECULAR}, SWIZZLE_XYZW}, |
| 75 | {"shininess", {STATE_MATERIAL, 1, STATE_SHININESS}, SWIZZLE_XXXX}, |
| 76 | }; |
| 77 | |
| 78 | static struct gl_builtin_uniform_element gl_LightSource_elements[] = { |
| 79 | {"ambient", {STATE_LIGHT, 0, STATE_AMBIENT}, SWIZZLE_XYZW}, |
| 80 | {"diffuse", {STATE_LIGHT, 0, STATE_DIFFUSE}, SWIZZLE_XYZW}, |
| 81 | {"specular", {STATE_LIGHT, 0, STATE_SPECULAR}, SWIZZLE_XYZW}, |
| 82 | {"position", {STATE_LIGHT, 0, STATE_POSITION}, SWIZZLE_XYZW}, |
| 83 | {"halfVector", {STATE_LIGHT, 0, STATE_HALF_VECTOR}, SWIZZLE_XYZW}, |
| 84 | {"spotDirection", {STATE_LIGHT, 0, STATE_SPOT_DIRECTION}, |
| 85 | MAKE_SWIZZLE4(SWIZZLE_X, |
| 86 | SWIZZLE_Y, |
| 87 | SWIZZLE_Z, |
| 88 | SWIZZLE_Z)}, |
| 89 | {"spotCosCutoff", {STATE_LIGHT, 0, STATE_SPOT_DIRECTION}, SWIZZLE_WWWW}, |
| 90 | {"spotCutoff", {STATE_LIGHT, 0, STATE_SPOT_CUTOFF}, SWIZZLE_XXXX}, |
| 91 | {"spotExponent", {STATE_LIGHT, 0, STATE_ATTENUATION}, SWIZZLE_WWWW}, |
| 92 | {"constantAttenuation", {STATE_LIGHT, 0, STATE_ATTENUATION}, SWIZZLE_XXXX}, |
| 93 | {"linearAttenuation", {STATE_LIGHT, 0, STATE_ATTENUATION}, SWIZZLE_YYYY}, |
| 94 | {"quadraticAttenuation", {STATE_LIGHT, 0, STATE_ATTENUATION}, SWIZZLE_ZZZZ}, |
| 95 | }; |
| 96 | |
| 97 | static struct gl_builtin_uniform_element gl_LightModel_elements[] = { |
| 98 | {"ambient", {STATE_LIGHTMODEL_AMBIENT, 0}, SWIZZLE_XYZW}, |
| 99 | }; |
| 100 | |
| 101 | static struct gl_builtin_uniform_element gl_FrontLightModelProduct_elements[] = { |
| 102 | {"sceneColor", {STATE_LIGHTMODEL_SCENECOLOR, 0}, SWIZZLE_XYZW}, |
| 103 | }; |
| 104 | |
| 105 | static struct gl_builtin_uniform_element gl_BackLightModelProduct_elements[] = { |
| 106 | {"sceneColor", {STATE_LIGHTMODEL_SCENECOLOR, 1}, SWIZZLE_XYZW}, |
| 107 | }; |
| 108 | |
| 109 | static struct gl_builtin_uniform_element gl_FrontLightProduct_elements[] = { |
| 110 | {"ambient", {STATE_LIGHTPROD, 0, 0, STATE_AMBIENT}, SWIZZLE_XYZW}, |
| 111 | {"diffuse", {STATE_LIGHTPROD, 0, 0, STATE_DIFFUSE}, SWIZZLE_XYZW}, |
| 112 | {"specular", {STATE_LIGHTPROD, 0, 0, STATE_SPECULAR}, SWIZZLE_XYZW}, |
| 113 | }; |
| 114 | |
| 115 | static struct gl_builtin_uniform_element gl_BackLightProduct_elements[] = { |
| 116 | {"ambient", {STATE_LIGHTPROD, 0, 1, STATE_AMBIENT}, SWIZZLE_XYZW}, |
| 117 | {"diffuse", {STATE_LIGHTPROD, 0, 1, STATE_DIFFUSE}, SWIZZLE_XYZW}, |
| 118 | {"specular", {STATE_LIGHTPROD, 0, 1, STATE_SPECULAR}, SWIZZLE_XYZW}, |
| 119 | }; |
| 120 | |
| 121 | static struct gl_builtin_uniform_element gl_TextureEnvColor_elements[] = { |
| 122 | {NULL, {STATE_TEXENV_COLOR, 0}, SWIZZLE_XYZW}, |
| 123 | }; |
| 124 | |
| 125 | static struct gl_builtin_uniform_element gl_EyePlaneS_elements[] = { |
| 126 | {NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_EYE_S}, SWIZZLE_XYZW}, |
| 127 | }; |
| 128 | |
| 129 | static struct gl_builtin_uniform_element gl_EyePlaneT_elements[] = { |
| 130 | {NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_EYE_T}, SWIZZLE_XYZW}, |
| 131 | }; |
| 132 | |
| 133 | static struct gl_builtin_uniform_element gl_EyePlaneR_elements[] = { |
| 134 | {NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_EYE_R}, SWIZZLE_XYZW}, |
| 135 | }; |
| 136 | |
| 137 | static struct gl_builtin_uniform_element gl_EyePlaneQ_elements[] = { |
| 138 | {NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_EYE_Q}, SWIZZLE_XYZW}, |
| 139 | }; |
| 140 | |
| 141 | static struct gl_builtin_uniform_element gl_ObjectPlaneS_elements[] = { |
| 142 | {NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_OBJECT_S}, SWIZZLE_XYZW}, |
| 143 | }; |
| 144 | |
| 145 | static struct gl_builtin_uniform_element gl_ObjectPlaneT_elements[] = { |
| 146 | {NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_OBJECT_T}, SWIZZLE_XYZW}, |
| 147 | }; |
| 148 | |
| 149 | static struct gl_builtin_uniform_element gl_ObjectPlaneR_elements[] = { |
| 150 | {NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_OBJECT_R}, SWIZZLE_XYZW}, |
| 151 | }; |
| 152 | |
| 153 | static struct gl_builtin_uniform_element gl_ObjectPlaneQ_elements[] = { |
| 154 | {NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_OBJECT_Q}, SWIZZLE_XYZW}, |
| 155 | }; |
| 156 | |
| 157 | static struct gl_builtin_uniform_element gl_Fog_elements[] = { |
| 158 | {"color", {STATE_FOG_COLOR}, SWIZZLE_XYZW}, |
| 159 | {"density", {STATE_FOG_PARAMS}, SWIZZLE_XXXX}, |
| 160 | {"start", {STATE_FOG_PARAMS}, SWIZZLE_YYYY}, |
| 161 | {"end", {STATE_FOG_PARAMS}, SWIZZLE_ZZZZ}, |
| 162 | {"scale", {STATE_FOG_PARAMS}, SWIZZLE_WWWW}, |
| 163 | }; |
| 164 | |
| 165 | static struct gl_builtin_uniform_element gl_NormalScale_elements[] = { |
| 166 | {NULL, {STATE_NORMAL_SCALE}, SWIZZLE_XXXX}, |
| 167 | }; |
| 168 | |
| 169 | static struct gl_builtin_uniform_element gl_MESABumpRotMatrix0_elements[] = { |
| 170 | {NULL, {STATE_INTERNAL, STATE_ROT_MATRIX_0}, SWIZZLE_XYZW}, |
| 171 | }; |
| 172 | |
| 173 | static struct gl_builtin_uniform_element gl_MESABumpRotMatrix1_elements[] = { |
| 174 | {NULL, {STATE_INTERNAL, STATE_ROT_MATRIX_1}, SWIZZLE_XYZW}, |
| 175 | }; |
| 176 | |
| 177 | static struct gl_builtin_uniform_element gl_MESAFogParamsOptimized_elements[] = { |
| 178 | {NULL, {STATE_INTERNAL, STATE_FOG_PARAMS_OPTIMIZED}, SWIZZLE_XYZW}, |
| 179 | }; |
| 180 | |
Eric Anholt | f868cb0 | 2011-07-16 17:41:26 -0700 | [diff] [blame^] | 181 | static struct gl_builtin_uniform_element gl_CurrentAttribVertMESA_elements[] = { |
| 182 | {NULL, {STATE_INTERNAL, STATE_CURRENT_ATTRIB, 0}, SWIZZLE_XYZW}, |
| 183 | }; |
| 184 | |
| 185 | static struct gl_builtin_uniform_element gl_CurrentAttribFragMESA_elements[] = { |
| 186 | {NULL, {STATE_INTERNAL, STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED, 0}, SWIZZLE_XYZW}, |
| 187 | }; |
| 188 | |
Ian Romanick | 92e412e | 2011-01-24 16:55:50 -0800 | [diff] [blame] | 189 | #define MATRIX(name, statevar, modifier) \ |
| 190 | static struct gl_builtin_uniform_element name ## _elements[] = { \ |
| 191 | { NULL, { statevar, 0, 0, 0, modifier}, SWIZZLE_XYZW }, \ |
| 192 | { NULL, { statevar, 0, 1, 1, modifier}, SWIZZLE_XYZW }, \ |
| 193 | { NULL, { statevar, 0, 2, 2, modifier}, SWIZZLE_XYZW }, \ |
| 194 | { NULL, { statevar, 0, 3, 3, modifier}, SWIZZLE_XYZW }, \ |
| 195 | } |
| 196 | |
| 197 | MATRIX(gl_ModelViewMatrix, |
| 198 | STATE_MODELVIEW_MATRIX, STATE_MATRIX_TRANSPOSE); |
| 199 | MATRIX(gl_ModelViewMatrixInverse, |
| 200 | STATE_MODELVIEW_MATRIX, STATE_MATRIX_INVTRANS); |
| 201 | MATRIX(gl_ModelViewMatrixTranspose, |
| 202 | STATE_MODELVIEW_MATRIX, 0); |
| 203 | MATRIX(gl_ModelViewMatrixInverseTranspose, |
| 204 | STATE_MODELVIEW_MATRIX, STATE_MATRIX_INVERSE); |
| 205 | |
| 206 | MATRIX(gl_ProjectionMatrix, |
| 207 | STATE_PROJECTION_MATRIX, STATE_MATRIX_TRANSPOSE); |
| 208 | MATRIX(gl_ProjectionMatrixInverse, |
| 209 | STATE_PROJECTION_MATRIX, STATE_MATRIX_INVTRANS); |
| 210 | MATRIX(gl_ProjectionMatrixTranspose, |
| 211 | STATE_PROJECTION_MATRIX, 0); |
| 212 | MATRIX(gl_ProjectionMatrixInverseTranspose, |
| 213 | STATE_PROJECTION_MATRIX, STATE_MATRIX_INVERSE); |
| 214 | |
| 215 | MATRIX(gl_ModelViewProjectionMatrix, |
| 216 | STATE_MVP_MATRIX, STATE_MATRIX_TRANSPOSE); |
| 217 | MATRIX(gl_ModelViewProjectionMatrixInverse, |
| 218 | STATE_MVP_MATRIX, STATE_MATRIX_INVTRANS); |
| 219 | MATRIX(gl_ModelViewProjectionMatrixTranspose, |
| 220 | STATE_MVP_MATRIX, 0); |
| 221 | MATRIX(gl_ModelViewProjectionMatrixInverseTranspose, |
| 222 | STATE_MVP_MATRIX, STATE_MATRIX_INVERSE); |
| 223 | |
| 224 | MATRIX(gl_TextureMatrix, |
| 225 | STATE_TEXTURE_MATRIX, STATE_MATRIX_TRANSPOSE); |
| 226 | MATRIX(gl_TextureMatrixInverse, |
| 227 | STATE_TEXTURE_MATRIX, STATE_MATRIX_INVTRANS); |
| 228 | MATRIX(gl_TextureMatrixTranspose, |
| 229 | STATE_TEXTURE_MATRIX, 0); |
| 230 | MATRIX(gl_TextureMatrixInverseTranspose, |
| 231 | STATE_TEXTURE_MATRIX, STATE_MATRIX_INVERSE); |
| 232 | |
| 233 | static struct gl_builtin_uniform_element gl_NormalMatrix_elements[] = { |
| 234 | { NULL, { STATE_MODELVIEW_MATRIX, 0, 0, 0, STATE_MATRIX_INVERSE}, |
| 235 | SWIZZLE_XYZW }, |
| 236 | { NULL, { STATE_MODELVIEW_MATRIX, 0, 1, 1, STATE_MATRIX_INVERSE}, |
| 237 | SWIZZLE_XYZW }, |
| 238 | { NULL, { STATE_MODELVIEW_MATRIX, 0, 2, 2, STATE_MATRIX_INVERSE}, |
| 239 | SWIZZLE_XYZW }, |
| 240 | }; |
| 241 | |
| 242 | #undef MATRIX |
| 243 | |
| 244 | #define STATEVAR(name) {#name, name ## _elements, Elements(name ## _elements)} |
| 245 | |
| 246 | const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[] = { |
| 247 | STATEVAR(gl_DepthRange), |
| 248 | STATEVAR(gl_ClipPlane), |
| 249 | STATEVAR(gl_Point), |
| 250 | STATEVAR(gl_FrontMaterial), |
| 251 | STATEVAR(gl_BackMaterial), |
| 252 | STATEVAR(gl_LightSource), |
| 253 | STATEVAR(gl_LightModel), |
| 254 | STATEVAR(gl_FrontLightModelProduct), |
| 255 | STATEVAR(gl_BackLightModelProduct), |
| 256 | STATEVAR(gl_FrontLightProduct), |
| 257 | STATEVAR(gl_BackLightProduct), |
| 258 | STATEVAR(gl_TextureEnvColor), |
| 259 | STATEVAR(gl_EyePlaneS), |
| 260 | STATEVAR(gl_EyePlaneT), |
| 261 | STATEVAR(gl_EyePlaneR), |
| 262 | STATEVAR(gl_EyePlaneQ), |
| 263 | STATEVAR(gl_ObjectPlaneS), |
| 264 | STATEVAR(gl_ObjectPlaneT), |
| 265 | STATEVAR(gl_ObjectPlaneR), |
| 266 | STATEVAR(gl_ObjectPlaneQ), |
| 267 | STATEVAR(gl_Fog), |
| 268 | |
| 269 | STATEVAR(gl_ModelViewMatrix), |
| 270 | STATEVAR(gl_ModelViewMatrixInverse), |
| 271 | STATEVAR(gl_ModelViewMatrixTranspose), |
| 272 | STATEVAR(gl_ModelViewMatrixInverseTranspose), |
| 273 | |
| 274 | STATEVAR(gl_ProjectionMatrix), |
| 275 | STATEVAR(gl_ProjectionMatrixInverse), |
| 276 | STATEVAR(gl_ProjectionMatrixTranspose), |
| 277 | STATEVAR(gl_ProjectionMatrixInverseTranspose), |
| 278 | |
| 279 | STATEVAR(gl_ModelViewProjectionMatrix), |
| 280 | STATEVAR(gl_ModelViewProjectionMatrixInverse), |
| 281 | STATEVAR(gl_ModelViewProjectionMatrixTranspose), |
| 282 | STATEVAR(gl_ModelViewProjectionMatrixInverseTranspose), |
| 283 | |
| 284 | STATEVAR(gl_TextureMatrix), |
| 285 | STATEVAR(gl_TextureMatrixInverse), |
| 286 | STATEVAR(gl_TextureMatrixTranspose), |
| 287 | STATEVAR(gl_TextureMatrixInverseTranspose), |
| 288 | |
| 289 | STATEVAR(gl_NormalMatrix), |
| 290 | STATEVAR(gl_NormalScale), |
| 291 | |
| 292 | STATEVAR(gl_MESABumpRotMatrix0), |
| 293 | STATEVAR(gl_MESABumpRotMatrix1), |
| 294 | STATEVAR(gl_MESAFogParamsOptimized), |
Eric Anholt | f868cb0 | 2011-07-16 17:41:26 -0700 | [diff] [blame^] | 295 | STATEVAR(gl_CurrentAttribVertMESA), |
| 296 | STATEVAR(gl_CurrentAttribFragMESA), |
Ian Romanick | 92e412e | 2011-01-24 16:55:50 -0800 | [diff] [blame] | 297 | |
| 298 | {NULL, NULL, 0} |
| 299 | }; |
| 300 | |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 301 | static ir_variable * |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 302 | add_variable(exec_list *instructions, glsl_symbol_table *symtab, |
| 303 | const char *name, const glsl_type *type, |
| 304 | enum ir_variable_mode mode, int slot) |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 305 | { |
Ian Romanick | 7e2aa91 | 2010-07-19 17:12:42 -0700 | [diff] [blame] | 306 | ir_variable *var = new(symtab) ir_variable(type, name, mode); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 307 | |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 308 | switch (var->mode) { |
Ian Romanick | e2f84f0 | 2010-06-29 15:19:11 -0700 | [diff] [blame] | 309 | case ir_var_auto: |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 310 | case ir_var_in: |
Kenneth Graunke | 819d57f | 2011-01-12 15:37:37 -0800 | [diff] [blame] | 311 | case ir_var_const_in: |
Eric Anholt | 046bef2 | 2010-08-04 20:33:57 -0700 | [diff] [blame] | 312 | case ir_var_uniform: |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 313 | case ir_var_system_value: |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 314 | var->read_only = true; |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 315 | break; |
| 316 | case ir_var_inout: |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 317 | case ir_var_out: |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 318 | break; |
| 319 | default: |
| 320 | assert(0); |
| 321 | break; |
| 322 | } |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 323 | |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 324 | var->location = slot; |
Ian Romanick | 68a4fc9 | 2010-10-07 17:21:22 -0700 | [diff] [blame] | 325 | var->explicit_location = (slot >= 0); |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 326 | |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 327 | /* Once the variable is created an initialized, add it to the symbol table |
| 328 | * and add the declaration to the IR stream. |
| 329 | */ |
| 330 | instructions->push_tail(var); |
| 331 | |
Eric Anholt | 001eee5 | 2010-11-05 06:11:24 -0700 | [diff] [blame] | 332 | symtab->add_variable(var); |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 333 | return var; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 334 | } |
| 335 | |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 336 | static ir_variable * |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 337 | add_uniform(exec_list *instructions, glsl_symbol_table *symtab, |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 338 | const char *name, const glsl_type *type) |
| 339 | { |
Ian Romanick | 89d81ab | 2011-01-25 10:41:20 -0800 | [diff] [blame] | 340 | ir_variable *const uni = |
| 341 | add_variable(instructions, symtab, name, type, ir_var_uniform, -1); |
| 342 | |
| 343 | unsigned i; |
| 344 | for (i = 0; _mesa_builtin_uniform_desc[i].name != NULL; i++) { |
| 345 | if (strcmp(_mesa_builtin_uniform_desc[i].name, name) == 0) { |
| 346 | break; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | assert(_mesa_builtin_uniform_desc[i].name != NULL); |
| 351 | const struct gl_builtin_uniform_desc* const statevar = |
| 352 | &_mesa_builtin_uniform_desc[i]; |
| 353 | |
| 354 | const unsigned array_count = type->is_array() ? type->length : 1; |
| 355 | uni->num_state_slots = array_count * statevar->num_elements; |
| 356 | |
| 357 | ir_state_slot *slots = |
| 358 | ralloc_array(uni, ir_state_slot, uni->num_state_slots); |
| 359 | |
| 360 | uni->state_slots = slots; |
| 361 | |
| 362 | for (unsigned a = 0; a < array_count; a++) { |
| 363 | for (unsigned j = 0; j < statevar->num_elements; j++) { |
| 364 | struct gl_builtin_uniform_element *element = &statevar->elements[j]; |
| 365 | |
| 366 | memcpy(slots->tokens, element->tokens, sizeof(element->tokens)); |
| 367 | if (type->is_array()) { |
Eric Anholt | f868cb0 | 2011-07-16 17:41:26 -0700 | [diff] [blame^] | 368 | if (strcmp(name, "gl_CurrentAttribVertMESA") == 0 || |
| 369 | strcmp(name, "gl_CurrentAttribFragMESA") == 0) { |
| 370 | slots->tokens[2] = a; |
| 371 | } else { |
| 372 | slots->tokens[1] = a; |
| 373 | } |
Ian Romanick | 89d81ab | 2011-01-25 10:41:20 -0800 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | slots->swizzle = element->swizzle; |
| 377 | slots++; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | return uni; |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 382 | } |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 383 | |
| 384 | static void |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 385 | add_builtin_variable(exec_list *instructions, glsl_symbol_table *symtab, |
| 386 | const builtin_variable *proto) |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 387 | { |
| 388 | /* Create a new variable declaration from the description supplied by |
| 389 | * the caller. |
| 390 | */ |
| 391 | const glsl_type *const type = symtab->get_type(proto->type); |
| 392 | |
| 393 | assert(type != NULL); |
| 394 | |
Ian Romanick | 89d81ab | 2011-01-25 10:41:20 -0800 | [diff] [blame] | 395 | if (proto->mode == ir_var_uniform) { |
| 396 | add_uniform(instructions, symtab, proto->name, type); |
| 397 | } else { |
| 398 | add_variable(instructions, symtab, proto->name, type, proto->mode, |
| 399 | proto->slot); |
| 400 | } |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 403 | static void |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 404 | add_builtin_constant(exec_list *instructions, glsl_symbol_table *symtab, |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 405 | const char *name, int value) |
| 406 | { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 407 | ir_variable *const var = add_variable(instructions, symtab, |
| 408 | name, glsl_type::int_type, |
| 409 | ir_var_auto, -1); |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 410 | var->constant_value = new(var) ir_constant(value); |
| 411 | } |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 412 | |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 413 | /* Several constants in GLSL ES have different names than normal desktop GLSL. |
| 414 | * Therefore, this function should only be called on the ES path. |
| 415 | */ |
| 416 | static void |
| 417 | generate_100ES_uniforms(exec_list *instructions, |
| 418 | struct _mesa_glsl_parse_state *state) |
| 419 | { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 420 | glsl_symbol_table *const symtab = state->symbols; |
| 421 | |
| 422 | add_builtin_constant(instructions, symtab, "gl_MaxVertexAttribs", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 423 | state->Const.MaxVertexAttribs); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 424 | add_builtin_constant(instructions, symtab, "gl_MaxVertexUniformVectors", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 425 | state->Const.MaxVertexUniformComponents); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 426 | add_builtin_constant(instructions, symtab, "gl_MaxVaryingVectors", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 427 | state->Const.MaxVaryingFloats / 4); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 428 | add_builtin_constant(instructions, symtab, "gl_MaxVertexTextureImageUnits", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 429 | state->Const.MaxVertexTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 430 | add_builtin_constant(instructions, symtab, "gl_MaxCombinedTextureImageUnits", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 431 | state->Const.MaxCombinedTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 432 | add_builtin_constant(instructions, symtab, "gl_MaxTextureImageUnits", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 433 | state->Const.MaxTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 434 | add_builtin_constant(instructions, symtab, "gl_MaxFragmentUniformVectors", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 435 | state->Const.MaxFragmentUniformComponents); |
| 436 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 437 | add_uniform(instructions, symtab, "gl_DepthRange", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 438 | state->symbols->get_type("gl_DepthRangeParameters")); |
| 439 | } |
| 440 | |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 441 | static void |
| 442 | generate_110_uniforms(exec_list *instructions, |
Ian Romanick | 127308b | 2010-07-01 13:30:50 -0700 | [diff] [blame] | 443 | struct _mesa_glsl_parse_state *state) |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 444 | { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 445 | glsl_symbol_table *const symtab = state->symbols; |
| 446 | |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 447 | for (unsigned i = 0 |
| 448 | ; i < Elements(builtin_110_deprecated_uniforms) |
| 449 | ; i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 450 | add_builtin_variable(instructions, symtab, |
| 451 | & builtin_110_deprecated_uniforms[i]); |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 454 | add_builtin_constant(instructions, symtab, "gl_MaxLights", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 455 | state->Const.MaxLights); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 456 | add_builtin_constant(instructions, symtab, "gl_MaxClipPlanes", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 457 | state->Const.MaxClipPlanes); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 458 | add_builtin_constant(instructions, symtab, "gl_MaxTextureUnits", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 459 | state->Const.MaxTextureUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 460 | add_builtin_constant(instructions, symtab, "gl_MaxTextureCoords", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 461 | state->Const.MaxTextureCoords); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 462 | add_builtin_constant(instructions, symtab, "gl_MaxVertexAttribs", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 463 | state->Const.MaxVertexAttribs); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 464 | add_builtin_constant(instructions, symtab, "gl_MaxVertexUniformComponents", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 465 | state->Const.MaxVertexUniformComponents); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 466 | add_builtin_constant(instructions, symtab, "gl_MaxVaryingFloats", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 467 | state->Const.MaxVaryingFloats); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 468 | add_builtin_constant(instructions, symtab, "gl_MaxVertexTextureImageUnits", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 469 | state->Const.MaxVertexTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 470 | add_builtin_constant(instructions, symtab, "gl_MaxCombinedTextureImageUnits", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 471 | state->Const.MaxCombinedTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 472 | add_builtin_constant(instructions, symtab, "gl_MaxTextureImageUnits", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 473 | state->Const.MaxTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 474 | add_builtin_constant(instructions, symtab, "gl_MaxFragmentUniformComponents", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 475 | state->Const.MaxFragmentUniformComponents); |
Ian Romanick | 127308b | 2010-07-01 13:30:50 -0700 | [diff] [blame] | 476 | |
Ian Romanick | 3eba593 | 2010-04-26 14:59:32 -0700 | [diff] [blame] | 477 | const glsl_type *const mat4_array_type = |
Ian Romanick | f38d15b | 2010-07-20 15:33:40 -0700 | [diff] [blame] | 478 | glsl_type::get_array_instance(glsl_type::mat4_type, |
Ian Romanick | 127308b | 2010-07-01 13:30:50 -0700 | [diff] [blame] | 479 | state->Const.MaxTextureCoords); |
Ian Romanick | 3eba593 | 2010-04-26 14:59:32 -0700 | [diff] [blame] | 480 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 481 | add_uniform(instructions, symtab, "gl_TextureMatrix", mat4_array_type); |
| 482 | add_uniform(instructions, symtab, "gl_TextureMatrixInverse", mat4_array_type); |
| 483 | add_uniform(instructions, symtab, "gl_TextureMatrixTranspose", mat4_array_type); |
| 484 | add_uniform(instructions, symtab, "gl_TextureMatrixInverseTranspose", mat4_array_type); |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 485 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 486 | add_uniform(instructions, symtab, "gl_DepthRange", |
| 487 | symtab->get_type("gl_DepthRangeParameters")); |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 488 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 489 | add_uniform(instructions, symtab, "gl_ClipPlane", |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 490 | glsl_type::get_array_instance(glsl_type::vec4_type, |
| 491 | state->Const.MaxClipPlanes)); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 492 | add_uniform(instructions, symtab, "gl_Point", |
| 493 | symtab->get_type("gl_PointParameters")); |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 494 | |
| 495 | const glsl_type *const material_parameters_type = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 496 | symtab->get_type("gl_MaterialParameters"); |
| 497 | add_uniform(instructions, symtab, "gl_FrontMaterial", material_parameters_type); |
| 498 | add_uniform(instructions, symtab, "gl_BackMaterial", material_parameters_type); |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 499 | |
Eric Anholt | aa57943 | 2010-05-19 14:09:04 -0700 | [diff] [blame] | 500 | const glsl_type *const light_source_array_type = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 501 | 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] | 502 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 503 | add_uniform(instructions, symtab, "gl_LightSource", light_source_array_type); |
Eric Anholt | aa57943 | 2010-05-19 14:09:04 -0700 | [diff] [blame] | 504 | |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 505 | const glsl_type *const light_model_products_type = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 506 | symtab->get_type("gl_LightModelProducts"); |
| 507 | add_uniform(instructions, symtab, "gl_FrontLightModelProduct", |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 508 | light_model_products_type); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 509 | add_uniform(instructions, symtab, "gl_BackLightModelProduct", |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 510 | light_model_products_type); |
| 511 | |
| 512 | const glsl_type *const light_products_type = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 513 | glsl_type::get_array_instance(symtab->get_type("gl_LightProducts"), |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 514 | state->Const.MaxLights); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 515 | add_uniform(instructions, symtab, "gl_FrontLightProduct", light_products_type); |
| 516 | add_uniform(instructions, symtab, "gl_BackLightProduct", light_products_type); |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 517 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 518 | add_uniform(instructions, symtab, "gl_TextureEnvColor", |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 519 | glsl_type::get_array_instance(glsl_type::vec4_type, |
| 520 | state->Const.MaxTextureUnits)); |
| 521 | |
| 522 | const glsl_type *const texcoords_vec4 = |
| 523 | glsl_type::get_array_instance(glsl_type::vec4_type, |
| 524 | state->Const.MaxTextureCoords); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 525 | add_uniform(instructions, symtab, "gl_EyePlaneS", texcoords_vec4); |
| 526 | add_uniform(instructions, symtab, "gl_EyePlaneT", texcoords_vec4); |
| 527 | add_uniform(instructions, symtab, "gl_EyePlaneR", texcoords_vec4); |
| 528 | add_uniform(instructions, symtab, "gl_EyePlaneQ", texcoords_vec4); |
| 529 | add_uniform(instructions, symtab, "gl_ObjectPlaneS", texcoords_vec4); |
| 530 | add_uniform(instructions, symtab, "gl_ObjectPlaneT", texcoords_vec4); |
| 531 | add_uniform(instructions, symtab, "gl_ObjectPlaneR", texcoords_vec4); |
| 532 | add_uniform(instructions, symtab, "gl_ObjectPlaneQ", texcoords_vec4); |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 533 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 534 | add_uniform(instructions, symtab, "gl_Fog", |
| 535 | symtab->get_type("gl_FogParameters")); |
Eric Anholt | f868cb0 | 2011-07-16 17:41:26 -0700 | [diff] [blame^] | 536 | |
| 537 | /* Mesa-internal current attrib state */ |
| 538 | const glsl_type *const vert_attribs = |
| 539 | glsl_type::get_array_instance(glsl_type::vec4_type, VERT_ATTRIB_MAX); |
| 540 | add_uniform(instructions, symtab, "gl_CurrentAttribVertMESA", vert_attribs); |
| 541 | const glsl_type *const frag_attribs = |
| 542 | glsl_type::get_array_instance(glsl_type::vec4_type, FRAG_ATTRIB_MAX); |
| 543 | add_uniform(instructions, symtab, "gl_CurrentAttribFragMESA", frag_attribs); |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 544 | } |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 545 | |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 546 | /* This function should only be called for ES, not desktop GL. */ |
| 547 | static void |
| 548 | generate_100ES_vs_variables(exec_list *instructions, |
| 549 | struct _mesa_glsl_parse_state *state) |
| 550 | { |
| 551 | for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 552 | add_builtin_variable(instructions, state->symbols, |
| 553 | & builtin_core_vs_variables[i]); |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | generate_100ES_uniforms(instructions, state); |
| 557 | |
| 558 | generate_ARB_draw_buffers_variables(instructions, state, false, |
| 559 | vertex_shader); |
| 560 | } |
| 561 | |
| 562 | |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 563 | static void |
| 564 | generate_110_vs_variables(exec_list *instructions, |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 565 | struct _mesa_glsl_parse_state *state) |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 566 | { |
| 567 | for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 568 | add_builtin_variable(instructions, state->symbols, |
| 569 | & builtin_core_vs_variables[i]); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | for (unsigned i = 0 |
| 573 | ; i < Elements(builtin_110_deprecated_vs_variables) |
| 574 | ; i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 575 | add_builtin_variable(instructions, state->symbols, |
| 576 | & builtin_110_deprecated_vs_variables[i]); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 577 | } |
Ian Romanick | 127308b | 2010-07-01 13:30:50 -0700 | [diff] [blame] | 578 | generate_110_uniforms(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 579 | |
Ian Romanick | cd00d5b | 2010-07-01 13:17:54 -0700 | [diff] [blame] | 580 | /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec: |
| 581 | * |
| 582 | * "As with all arrays, indices used to subscript gl_TexCoord must |
| 583 | * either be an integral constant expressions, or this array must be |
| 584 | * re-declared by the shader with a size. The size can be at most |
| 585 | * gl_MaxTextureCoords. Using indexes close to 0 may aid the |
| 586 | * implementation in preserving varying resources." |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 587 | */ |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 588 | const glsl_type *const vec4_array_type = |
Ian Romanick | f38d15b | 2010-07-20 15:33:40 -0700 | [diff] [blame] | 589 | glsl_type::get_array_instance(glsl_type::vec4_type, 0); |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 590 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 591 | add_variable(instructions, state->symbols, |
| 592 | "gl_TexCoord", vec4_array_type, ir_var_out, VERT_RESULT_TEX0); |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 593 | |
| 594 | generate_ARB_draw_buffers_variables(instructions, state, false, |
| 595 | vertex_shader); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | |
| 599 | static void |
| 600 | generate_120_vs_variables(exec_list *instructions, |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 601 | struct _mesa_glsl_parse_state *state) |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 602 | { |
| 603 | /* GLSL version 1.20 did not add any built-in variables in the vertex |
| 604 | * shader. |
| 605 | */ |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 606 | generate_110_vs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | |
| 610 | static void |
Paul Berry | 36c4b1a | 2011-08-11 17:33:06 -0700 | [diff] [blame] | 611 | generate_130_uniforms(exec_list *instructions, |
| 612 | struct _mesa_glsl_parse_state *state) |
| 613 | { |
| 614 | glsl_symbol_table *const symtab = state->symbols; |
| 615 | |
| 616 | add_builtin_constant(instructions, symtab, "gl_MaxClipDistances", |
| 617 | state->Const.MaxClipPlanes); |
| 618 | } |
| 619 | |
| 620 | |
| 621 | static void |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 622 | generate_130_vs_variables(exec_list *instructions, |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 623 | struct _mesa_glsl_parse_state *state) |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 624 | { |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 625 | generate_120_vs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 626 | |
| 627 | for (unsigned i = 0; i < Elements(builtin_130_vs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 628 | add_builtin_variable(instructions, state->symbols, |
| 629 | & builtin_130_vs_variables[i]); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 630 | } |
| 631 | |
Paul Berry | 36c4b1a | 2011-08-11 17:33:06 -0700 | [diff] [blame] | 632 | generate_130_uniforms(instructions, state); |
| 633 | |
Paul Berry | af243b5 | 2011-08-11 15:03:19 -0700 | [diff] [blame] | 634 | /* From the GLSL 1.30 spec, section 7.1 (Vertex Shader Special |
| 635 | * Variables): |
| 636 | * |
| 637 | * The gl_ClipDistance array is predeclared as unsized and must |
| 638 | * be sized by the shader either redeclaring it with a size or |
| 639 | * indexing it only with integral constant expressions. |
| 640 | * |
| 641 | * We represent this in Mesa by initially declaring the array as |
| 642 | * size 0. |
| 643 | */ |
Eric Anholt | 271e199 | 2010-04-02 23:47:06 -0700 | [diff] [blame] | 644 | const glsl_type *const clip_distance_array_type = |
Paul Berry | af243b5 | 2011-08-11 15:03:19 -0700 | [diff] [blame] | 645 | glsl_type::get_array_instance(glsl_type::float_type, 0); |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 646 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 647 | add_variable(instructions, state->symbols, |
Paul Berry | 3d7c5a4 | 2011-08-19 13:12:23 -0700 | [diff] [blame] | 648 | "gl_ClipDistance", clip_distance_array_type, ir_var_out, |
| 649 | VERT_RESULT_CLIP_DIST0); |
Eric Anholt | 271e199 | 2010-04-02 23:47:06 -0700 | [diff] [blame] | 650 | |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | |
| 654 | static void |
| 655 | initialize_vs_variables(exec_list *instructions, |
| 656 | struct _mesa_glsl_parse_state *state) |
| 657 | { |
| 658 | |
| 659 | switch (state->language_version) { |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 660 | case 100: |
| 661 | generate_100ES_vs_variables(instructions, state); |
| 662 | break; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 663 | case 110: |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 664 | generate_110_vs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 665 | break; |
| 666 | case 120: |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 667 | generate_120_vs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 668 | break; |
| 669 | case 130: |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 670 | generate_130_vs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 671 | break; |
| 672 | } |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 673 | |
| 674 | if (state->ARB_draw_instanced_enable) |
| 675 | generate_ARB_draw_instanced_variables(instructions, state, false, |
| 676 | vertex_shader); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 677 | } |
| 678 | |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 679 | |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 680 | /* This function should only be called for ES, not desktop GL. */ |
| 681 | static void |
| 682 | generate_100ES_fs_variables(exec_list *instructions, |
| 683 | struct _mesa_glsl_parse_state *state) |
| 684 | { |
| 685 | for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 686 | add_builtin_variable(instructions, state->symbols, |
| 687 | & builtin_core_fs_variables[i]); |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | for (unsigned i = 0; i < Elements(builtin_100ES_fs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 691 | add_builtin_variable(instructions, state->symbols, |
| 692 | & builtin_100ES_fs_variables[i]); |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | generate_100ES_uniforms(instructions, state); |
| 696 | |
| 697 | generate_ARB_draw_buffers_variables(instructions, state, false, |
| 698 | fragment_shader); |
| 699 | } |
| 700 | |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 701 | static void |
| 702 | generate_110_fs_variables(exec_list *instructions, |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 703 | struct _mesa_glsl_parse_state *state) |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 704 | { |
| 705 | for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 706 | add_builtin_variable(instructions, state->symbols, |
| 707 | & builtin_core_fs_variables[i]); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 710 | for (unsigned i = 0; i < Elements(builtin_110_fs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 711 | add_builtin_variable(instructions, state->symbols, |
| 712 | & builtin_110_fs_variables[i]); |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 713 | } |
| 714 | |
Eric Anholt | 0f09aea | 2010-03-27 12:48:57 -0700 | [diff] [blame] | 715 | for (unsigned i = 0 |
| 716 | ; i < Elements(builtin_110_deprecated_fs_variables) |
| 717 | ; i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 718 | add_builtin_variable(instructions, state->symbols, |
| 719 | & builtin_110_deprecated_fs_variables[i]); |
Eric Anholt | 0f09aea | 2010-03-27 12:48:57 -0700 | [diff] [blame] | 720 | } |
Ian Romanick | 127308b | 2010-07-01 13:30:50 -0700 | [diff] [blame] | 721 | generate_110_uniforms(instructions, state); |
Eric Anholt | 0f09aea | 2010-03-27 12:48:57 -0700 | [diff] [blame] | 722 | |
Ian Romanick | cd00d5b | 2010-07-01 13:17:54 -0700 | [diff] [blame] | 723 | /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec: |
| 724 | * |
| 725 | * "As with all arrays, indices used to subscript gl_TexCoord must |
| 726 | * either be an integral constant expressions, or this array must be |
| 727 | * re-declared by the shader with a size. The size can be at most |
| 728 | * gl_MaxTextureCoords. Using indexes close to 0 may aid the |
| 729 | * implementation in preserving varying resources." |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 730 | */ |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 731 | const glsl_type *const vec4_array_type = |
Ian Romanick | f38d15b | 2010-07-20 15:33:40 -0700 | [diff] [blame] | 732 | glsl_type::get_array_instance(glsl_type::vec4_type, 0); |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 733 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 734 | add_variable(instructions, state->symbols, |
| 735 | "gl_TexCoord", vec4_array_type, ir_var_in, FRAG_ATTRIB_TEX0); |
Ian Romanick | 9c4b1f2 | 2010-06-29 15:10:09 -0700 | [diff] [blame] | 736 | |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 737 | generate_ARB_draw_buffers_variables(instructions, state, false, |
| 738 | fragment_shader); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 739 | } |
| 740 | |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 741 | |
| 742 | static void |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 743 | generate_ARB_draw_buffers_variables(exec_list *instructions, |
| 744 | struct _mesa_glsl_parse_state *state, |
| 745 | bool warn, _mesa_glsl_parser_targets target) |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 746 | { |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 747 | /* gl_MaxDrawBuffers is available in all shader stages. |
| 748 | */ |
Ian Romanick | e2f84f0 | 2010-06-29 15:19:11 -0700 | [diff] [blame] | 749 | ir_variable *const mdb = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 750 | add_variable(instructions, state->symbols, |
| 751 | "gl_MaxDrawBuffers", glsl_type::int_type, ir_var_auto, -1); |
Ian Romanick | e2f84f0 | 2010-06-29 15:19:11 -0700 | [diff] [blame] | 752 | |
| 753 | if (warn) |
| 754 | mdb->warn_extension = "GL_ARB_draw_buffers"; |
| 755 | |
| 756 | mdb->constant_value = new(mdb) |
| 757 | ir_constant(int(state->Const.MaxDrawBuffers)); |
| 758 | |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 759 | |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 760 | /* gl_FragData is only available in the fragment shader. |
| 761 | */ |
| 762 | if (target == fragment_shader) { |
| 763 | const glsl_type *const vec4_array_type = |
Ian Romanick | f38d15b | 2010-07-20 15:33:40 -0700 | [diff] [blame] | 764 | glsl_type::get_array_instance(glsl_type::vec4_type, |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 765 | state->Const.MaxDrawBuffers); |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 766 | |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 767 | ir_variable *const fd = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 768 | add_variable(instructions, state->symbols, |
| 769 | "gl_FragData", vec4_array_type, |
| 770 | ir_var_out, FRAG_RESULT_DATA0); |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 771 | |
| 772 | if (warn) |
| 773 | fd->warn_extension = "GL_ARB_draw_buffers"; |
| 774 | } |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 775 | } |
| 776 | |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 777 | |
| 778 | static void |
| 779 | generate_ARB_draw_instanced_variables(exec_list *instructions, |
| 780 | struct _mesa_glsl_parse_state *state, |
| 781 | bool warn, |
| 782 | _mesa_glsl_parser_targets target) |
| 783 | { |
| 784 | /* gl_InstanceIDARB is only available in the vertex shader. |
| 785 | */ |
| 786 | if (target == vertex_shader) { |
| 787 | ir_variable *const inst = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 788 | add_variable(instructions, state->symbols, |
| 789 | "gl_InstanceIDARB", glsl_type::int_type, |
| 790 | ir_var_system_value, SYSTEM_VALUE_INSTANCE_ID); |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 791 | |
| 792 | if (warn) |
| 793 | inst->warn_extension = "GL_ARB_draw_instanced"; |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | |
Dave Airlie | d967186 | 2010-10-06 09:36:02 +1000 | [diff] [blame] | 798 | static void |
| 799 | generate_ARB_shader_stencil_export_variables(exec_list *instructions, |
| 800 | struct _mesa_glsl_parse_state *state, |
| 801 | bool warn) |
| 802 | { |
| 803 | /* gl_FragStencilRefARB is only available in the fragment shader. |
| 804 | */ |
| 805 | ir_variable *const fd = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 806 | add_variable(instructions, state->symbols, |
| 807 | "gl_FragStencilRefARB", glsl_type::int_type, |
| 808 | ir_var_out, FRAG_RESULT_STENCIL); |
Dave Airlie | d967186 | 2010-10-06 09:36:02 +1000 | [diff] [blame] | 809 | |
| 810 | if (warn) |
| 811 | fd->warn_extension = "GL_ARB_shader_stencil_export"; |
| 812 | } |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 813 | |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 814 | static void |
Marek Olšák | 5ba2e7a | 2011-05-02 16:41:04 +0200 | [diff] [blame] | 815 | generate_AMD_shader_stencil_export_variables(exec_list *instructions, |
| 816 | struct _mesa_glsl_parse_state *state, |
| 817 | bool warn) |
| 818 | { |
| 819 | /* gl_FragStencilRefAMD is only available in the fragment shader. |
| 820 | */ |
| 821 | ir_variable *const fd = |
| 822 | add_variable(instructions, state->symbols, |
| 823 | "gl_FragStencilRefAMD", glsl_type::int_type, |
| 824 | ir_var_out, FRAG_RESULT_STENCIL); |
| 825 | |
| 826 | if (warn) |
| 827 | fd->warn_extension = "GL_AMD_shader_stencil_export"; |
| 828 | } |
| 829 | |
| 830 | static void |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 831 | generate_120_fs_variables(exec_list *instructions, |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 832 | struct _mesa_glsl_parse_state *state) |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 833 | { |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 834 | generate_110_fs_variables(instructions, state); |
Eric Anholt | 152b55e | 2010-07-07 19:45:22 -0700 | [diff] [blame] | 835 | |
| 836 | for (unsigned i = 0 |
| 837 | ; i < Elements(builtin_120_fs_variables) |
| 838 | ; i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 839 | add_builtin_variable(instructions, state->symbols, |
| 840 | & builtin_120_fs_variables[i]); |
Eric Anholt | 152b55e | 2010-07-07 19:45:22 -0700 | [diff] [blame] | 841 | } |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | static void |
| 845 | generate_130_fs_variables(exec_list *instructions, |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 846 | struct _mesa_glsl_parse_state *state) |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 847 | { |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 848 | generate_120_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 849 | |
Paul Berry | 36c4b1a | 2011-08-11 17:33:06 -0700 | [diff] [blame] | 850 | generate_130_uniforms(instructions, state); |
| 851 | |
Paul Berry | af243b5 | 2011-08-11 15:03:19 -0700 | [diff] [blame] | 852 | /* From the GLSL 1.30 spec, section 7.2 (Fragment Shader Special |
| 853 | * Variables): |
| 854 | * |
| 855 | * The built-in input variable gl_ClipDistance array contains linearly |
| 856 | * interpolated values for the vertex values written by the vertex shader |
| 857 | * to the gl_ClipDistance vertex output variable. This array must be |
| 858 | * sized in the fragment shader either implicitly or explicitly to be the |
| 859 | * same size as it was sized in the vertex shader. |
| 860 | * |
| 861 | * In other words, the array must be pre-declared as implicitly sized. We |
| 862 | * represent this in Mesa by initially declaring the array as size 0. |
| 863 | */ |
Ian Romanick | 8645a95 | 2010-04-07 16:47:44 -0700 | [diff] [blame] | 864 | const glsl_type *const clip_distance_array_type = |
Paul Berry | af243b5 | 2011-08-11 15:03:19 -0700 | [diff] [blame] | 865 | glsl_type::get_array_instance(glsl_type::float_type, 0); |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 866 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 867 | add_variable(instructions, state->symbols, |
Paul Berry | 3d7c5a4 | 2011-08-19 13:12:23 -0700 | [diff] [blame] | 868 | "gl_ClipDistance", clip_distance_array_type, ir_var_in, |
| 869 | FRAG_ATTRIB_CLIP_DIST0); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | static void |
| 873 | initialize_fs_variables(exec_list *instructions, |
| 874 | struct _mesa_glsl_parse_state *state) |
| 875 | { |
| 876 | |
| 877 | switch (state->language_version) { |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 878 | case 100: |
| 879 | generate_100ES_fs_variables(instructions, state); |
| 880 | break; |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 881 | case 110: |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 882 | generate_110_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 883 | break; |
| 884 | case 120: |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 885 | generate_120_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 886 | break; |
| 887 | case 130: |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 888 | generate_130_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 889 | break; |
| 890 | } |
Dave Airlie | d967186 | 2010-10-06 09:36:02 +1000 | [diff] [blame] | 891 | |
| 892 | if (state->ARB_shader_stencil_export_enable) |
| 893 | generate_ARB_shader_stencil_export_variables(instructions, state, |
| 894 | state->ARB_shader_stencil_export_warn); |
Marek Olšák | 5ba2e7a | 2011-05-02 16:41:04 +0200 | [diff] [blame] | 895 | |
| 896 | if (state->AMD_shader_stencil_export_enable) |
| 897 | generate_AMD_shader_stencil_export_variables(instructions, state, |
| 898 | state->AMD_shader_stencil_export_warn); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 899 | } |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 900 | |
| 901 | void |
| 902 | _mesa_glsl_initialize_variables(exec_list *instructions, |
| 903 | struct _mesa_glsl_parse_state *state) |
| 904 | { |
| 905 | switch (state->target) { |
| 906 | case vertex_shader: |
| 907 | initialize_vs_variables(instructions, state); |
| 908 | break; |
| 909 | case geometry_shader: |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 910 | break; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 911 | case fragment_shader: |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 912 | initialize_fs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 913 | break; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 914 | } |
| 915 | } |