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 | |
| 181 | #define MATRIX(name, statevar, modifier) \ |
| 182 | static struct gl_builtin_uniform_element name ## _elements[] = { \ |
| 183 | { NULL, { statevar, 0, 0, 0, modifier}, SWIZZLE_XYZW }, \ |
| 184 | { NULL, { statevar, 0, 1, 1, modifier}, SWIZZLE_XYZW }, \ |
| 185 | { NULL, { statevar, 0, 2, 2, modifier}, SWIZZLE_XYZW }, \ |
| 186 | { NULL, { statevar, 0, 3, 3, modifier}, SWIZZLE_XYZW }, \ |
| 187 | } |
| 188 | |
| 189 | MATRIX(gl_ModelViewMatrix, |
| 190 | STATE_MODELVIEW_MATRIX, STATE_MATRIX_TRANSPOSE); |
| 191 | MATRIX(gl_ModelViewMatrixInverse, |
| 192 | STATE_MODELVIEW_MATRIX, STATE_MATRIX_INVTRANS); |
| 193 | MATRIX(gl_ModelViewMatrixTranspose, |
| 194 | STATE_MODELVIEW_MATRIX, 0); |
| 195 | MATRIX(gl_ModelViewMatrixInverseTranspose, |
| 196 | STATE_MODELVIEW_MATRIX, STATE_MATRIX_INVERSE); |
| 197 | |
| 198 | MATRIX(gl_ProjectionMatrix, |
| 199 | STATE_PROJECTION_MATRIX, STATE_MATRIX_TRANSPOSE); |
| 200 | MATRIX(gl_ProjectionMatrixInverse, |
| 201 | STATE_PROJECTION_MATRIX, STATE_MATRIX_INVTRANS); |
| 202 | MATRIX(gl_ProjectionMatrixTranspose, |
| 203 | STATE_PROJECTION_MATRIX, 0); |
| 204 | MATRIX(gl_ProjectionMatrixInverseTranspose, |
| 205 | STATE_PROJECTION_MATRIX, STATE_MATRIX_INVERSE); |
| 206 | |
| 207 | MATRIX(gl_ModelViewProjectionMatrix, |
| 208 | STATE_MVP_MATRIX, STATE_MATRIX_TRANSPOSE); |
| 209 | MATRIX(gl_ModelViewProjectionMatrixInverse, |
| 210 | STATE_MVP_MATRIX, STATE_MATRIX_INVTRANS); |
| 211 | MATRIX(gl_ModelViewProjectionMatrixTranspose, |
| 212 | STATE_MVP_MATRIX, 0); |
| 213 | MATRIX(gl_ModelViewProjectionMatrixInverseTranspose, |
| 214 | STATE_MVP_MATRIX, STATE_MATRIX_INVERSE); |
| 215 | |
| 216 | MATRIX(gl_TextureMatrix, |
| 217 | STATE_TEXTURE_MATRIX, STATE_MATRIX_TRANSPOSE); |
| 218 | MATRIX(gl_TextureMatrixInverse, |
| 219 | STATE_TEXTURE_MATRIX, STATE_MATRIX_INVTRANS); |
| 220 | MATRIX(gl_TextureMatrixTranspose, |
| 221 | STATE_TEXTURE_MATRIX, 0); |
| 222 | MATRIX(gl_TextureMatrixInverseTranspose, |
| 223 | STATE_TEXTURE_MATRIX, STATE_MATRIX_INVERSE); |
| 224 | |
| 225 | static struct gl_builtin_uniform_element gl_NormalMatrix_elements[] = { |
| 226 | { NULL, { STATE_MODELVIEW_MATRIX, 0, 0, 0, STATE_MATRIX_INVERSE}, |
| 227 | SWIZZLE_XYZW }, |
| 228 | { NULL, { STATE_MODELVIEW_MATRIX, 0, 1, 1, STATE_MATRIX_INVERSE}, |
| 229 | SWIZZLE_XYZW }, |
| 230 | { NULL, { STATE_MODELVIEW_MATRIX, 0, 2, 2, STATE_MATRIX_INVERSE}, |
| 231 | SWIZZLE_XYZW }, |
| 232 | }; |
| 233 | |
| 234 | #undef MATRIX |
| 235 | |
| 236 | #define STATEVAR(name) {#name, name ## _elements, Elements(name ## _elements)} |
| 237 | |
| 238 | const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[] = { |
| 239 | STATEVAR(gl_DepthRange), |
| 240 | STATEVAR(gl_ClipPlane), |
| 241 | STATEVAR(gl_Point), |
| 242 | STATEVAR(gl_FrontMaterial), |
| 243 | STATEVAR(gl_BackMaterial), |
| 244 | STATEVAR(gl_LightSource), |
| 245 | STATEVAR(gl_LightModel), |
| 246 | STATEVAR(gl_FrontLightModelProduct), |
| 247 | STATEVAR(gl_BackLightModelProduct), |
| 248 | STATEVAR(gl_FrontLightProduct), |
| 249 | STATEVAR(gl_BackLightProduct), |
| 250 | STATEVAR(gl_TextureEnvColor), |
| 251 | STATEVAR(gl_EyePlaneS), |
| 252 | STATEVAR(gl_EyePlaneT), |
| 253 | STATEVAR(gl_EyePlaneR), |
| 254 | STATEVAR(gl_EyePlaneQ), |
| 255 | STATEVAR(gl_ObjectPlaneS), |
| 256 | STATEVAR(gl_ObjectPlaneT), |
| 257 | STATEVAR(gl_ObjectPlaneR), |
| 258 | STATEVAR(gl_ObjectPlaneQ), |
| 259 | STATEVAR(gl_Fog), |
| 260 | |
| 261 | STATEVAR(gl_ModelViewMatrix), |
| 262 | STATEVAR(gl_ModelViewMatrixInverse), |
| 263 | STATEVAR(gl_ModelViewMatrixTranspose), |
| 264 | STATEVAR(gl_ModelViewMatrixInverseTranspose), |
| 265 | |
| 266 | STATEVAR(gl_ProjectionMatrix), |
| 267 | STATEVAR(gl_ProjectionMatrixInverse), |
| 268 | STATEVAR(gl_ProjectionMatrixTranspose), |
| 269 | STATEVAR(gl_ProjectionMatrixInverseTranspose), |
| 270 | |
| 271 | STATEVAR(gl_ModelViewProjectionMatrix), |
| 272 | STATEVAR(gl_ModelViewProjectionMatrixInverse), |
| 273 | STATEVAR(gl_ModelViewProjectionMatrixTranspose), |
| 274 | STATEVAR(gl_ModelViewProjectionMatrixInverseTranspose), |
| 275 | |
| 276 | STATEVAR(gl_TextureMatrix), |
| 277 | STATEVAR(gl_TextureMatrixInverse), |
| 278 | STATEVAR(gl_TextureMatrixTranspose), |
| 279 | STATEVAR(gl_TextureMatrixInverseTranspose), |
| 280 | |
| 281 | STATEVAR(gl_NormalMatrix), |
| 282 | STATEVAR(gl_NormalScale), |
| 283 | |
| 284 | STATEVAR(gl_MESABumpRotMatrix0), |
| 285 | STATEVAR(gl_MESABumpRotMatrix1), |
| 286 | STATEVAR(gl_MESAFogParamsOptimized), |
| 287 | |
| 288 | {NULL, NULL, 0} |
| 289 | }; |
| 290 | |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 291 | static ir_variable * |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 292 | add_variable(exec_list *instructions, glsl_symbol_table *symtab, |
| 293 | const char *name, const glsl_type *type, |
| 294 | enum ir_variable_mode mode, int slot) |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 295 | { |
Ian Romanick | 7e2aa91 | 2010-07-19 17:12:42 -0700 | [diff] [blame] | 296 | ir_variable *var = new(symtab) ir_variable(type, name, mode); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 297 | |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 298 | switch (var->mode) { |
Ian Romanick | e2f84f0 | 2010-06-29 15:19:11 -0700 | [diff] [blame] | 299 | case ir_var_auto: |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 300 | case ir_var_in: |
Kenneth Graunke | 819d57f | 2011-01-12 15:37:37 -0800 | [diff] [blame] | 301 | case ir_var_const_in: |
Eric Anholt | 046bef2 | 2010-08-04 20:33:57 -0700 | [diff] [blame] | 302 | case ir_var_uniform: |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 303 | case ir_var_system_value: |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 304 | var->read_only = true; |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 305 | break; |
| 306 | case ir_var_inout: |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 307 | case ir_var_out: |
Eric Anholt | 71df19f | 2010-04-19 11:10:37 -0700 | [diff] [blame] | 308 | break; |
| 309 | default: |
| 310 | assert(0); |
| 311 | break; |
| 312 | } |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 313 | |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 314 | var->location = slot; |
Ian Romanick | 68a4fc9 | 2010-10-07 17:21:22 -0700 | [diff] [blame] | 315 | var->explicit_location = (slot >= 0); |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 316 | |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 317 | /* Once the variable is created an initialized, add it to the symbol table |
| 318 | * and add the declaration to the IR stream. |
| 319 | */ |
| 320 | instructions->push_tail(var); |
| 321 | |
Eric Anholt | 001eee5 | 2010-11-05 06:11:24 -0700 | [diff] [blame] | 322 | symtab->add_variable(var); |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 323 | return var; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 326 | static ir_variable * |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 327 | add_uniform(exec_list *instructions, glsl_symbol_table *symtab, |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 328 | const char *name, const glsl_type *type) |
| 329 | { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 330 | return add_variable(instructions, symtab, name, type, ir_var_uniform, -1); |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 331 | } |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 332 | |
| 333 | static void |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 334 | add_builtin_variable(exec_list *instructions, glsl_symbol_table *symtab, |
| 335 | const builtin_variable *proto) |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 336 | { |
| 337 | /* Create a new variable declaration from the description supplied by |
| 338 | * the caller. |
| 339 | */ |
| 340 | const glsl_type *const type = symtab->get_type(proto->type); |
| 341 | |
| 342 | assert(type != NULL); |
| 343 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 344 | add_variable(instructions, symtab, proto->name, type, proto->mode, |
| 345 | proto->slot); |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 348 | static void |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 349 | add_builtin_constant(exec_list *instructions, glsl_symbol_table *symtab, |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 350 | const char *name, int value) |
| 351 | { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 352 | ir_variable *const var = add_variable(instructions, symtab, |
| 353 | name, glsl_type::int_type, |
| 354 | ir_var_auto, -1); |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 355 | var->constant_value = new(var) ir_constant(value); |
| 356 | } |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 357 | |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 358 | /* Several constants in GLSL ES have different names than normal desktop GLSL. |
| 359 | * Therefore, this function should only be called on the ES path. |
| 360 | */ |
| 361 | static void |
| 362 | generate_100ES_uniforms(exec_list *instructions, |
| 363 | struct _mesa_glsl_parse_state *state) |
| 364 | { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 365 | glsl_symbol_table *const symtab = state->symbols; |
| 366 | |
| 367 | add_builtin_constant(instructions, symtab, "gl_MaxVertexAttribs", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 368 | state->Const.MaxVertexAttribs); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 369 | add_builtin_constant(instructions, symtab, "gl_MaxVertexUniformVectors", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 370 | state->Const.MaxVertexUniformComponents); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 371 | add_builtin_constant(instructions, symtab, "gl_MaxVaryingVectors", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 372 | state->Const.MaxVaryingFloats / 4); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 373 | add_builtin_constant(instructions, symtab, "gl_MaxVertexTextureImageUnits", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 374 | state->Const.MaxVertexTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 375 | add_builtin_constant(instructions, symtab, "gl_MaxCombinedTextureImageUnits", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 376 | state->Const.MaxCombinedTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 377 | add_builtin_constant(instructions, symtab, "gl_MaxTextureImageUnits", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 378 | state->Const.MaxTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 379 | add_builtin_constant(instructions, symtab, "gl_MaxFragmentUniformVectors", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 380 | state->Const.MaxFragmentUniformComponents); |
| 381 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 382 | add_uniform(instructions, symtab, "gl_DepthRange", |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 383 | state->symbols->get_type("gl_DepthRangeParameters")); |
| 384 | } |
| 385 | |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 386 | static void |
| 387 | generate_110_uniforms(exec_list *instructions, |
Ian Romanick | 127308b | 2010-07-01 13:30:50 -0700 | [diff] [blame] | 388 | struct _mesa_glsl_parse_state *state) |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 389 | { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 390 | glsl_symbol_table *const symtab = state->symbols; |
| 391 | |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 392 | for (unsigned i = 0 |
| 393 | ; i < Elements(builtin_110_deprecated_uniforms) |
| 394 | ; i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 395 | add_builtin_variable(instructions, symtab, |
| 396 | & builtin_110_deprecated_uniforms[i]); |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 399 | add_builtin_constant(instructions, symtab, "gl_MaxLights", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 400 | state->Const.MaxLights); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 401 | add_builtin_constant(instructions, symtab, "gl_MaxClipPlanes", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 402 | state->Const.MaxClipPlanes); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 403 | add_builtin_constant(instructions, symtab, "gl_MaxTextureUnits", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 404 | state->Const.MaxTextureUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 405 | add_builtin_constant(instructions, symtab, "gl_MaxTextureCoords", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 406 | state->Const.MaxTextureCoords); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 407 | add_builtin_constant(instructions, symtab, "gl_MaxVertexAttribs", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 408 | state->Const.MaxVertexAttribs); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 409 | add_builtin_constant(instructions, symtab, "gl_MaxVertexUniformComponents", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 410 | state->Const.MaxVertexUniformComponents); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 411 | add_builtin_constant(instructions, symtab, "gl_MaxVaryingFloats", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 412 | state->Const.MaxVaryingFloats); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 413 | add_builtin_constant(instructions, symtab, "gl_MaxVertexTextureImageUnits", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 414 | state->Const.MaxVertexTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 415 | add_builtin_constant(instructions, symtab, "gl_MaxCombinedTextureImageUnits", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 416 | state->Const.MaxCombinedTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 417 | add_builtin_constant(instructions, symtab, "gl_MaxTextureImageUnits", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 418 | state->Const.MaxTextureImageUnits); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 419 | add_builtin_constant(instructions, symtab, "gl_MaxFragmentUniformComponents", |
Eric Anholt | f894669 | 2010-07-20 14:03:35 -0700 | [diff] [blame] | 420 | state->Const.MaxFragmentUniformComponents); |
Ian Romanick | 127308b | 2010-07-01 13:30:50 -0700 | [diff] [blame] | 421 | |
Ian Romanick | 3eba593 | 2010-04-26 14:59:32 -0700 | [diff] [blame] | 422 | const glsl_type *const mat4_array_type = |
Ian Romanick | f38d15b | 2010-07-20 15:33:40 -0700 | [diff] [blame] | 423 | glsl_type::get_array_instance(glsl_type::mat4_type, |
Ian Romanick | 127308b | 2010-07-01 13:30:50 -0700 | [diff] [blame] | 424 | state->Const.MaxTextureCoords); |
Ian Romanick | 3eba593 | 2010-04-26 14:59:32 -0700 | [diff] [blame] | 425 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 426 | add_uniform(instructions, symtab, "gl_TextureMatrix", mat4_array_type); |
| 427 | add_uniform(instructions, symtab, "gl_TextureMatrixInverse", mat4_array_type); |
| 428 | add_uniform(instructions, symtab, "gl_TextureMatrixTranspose", mat4_array_type); |
| 429 | add_uniform(instructions, symtab, "gl_TextureMatrixInverseTranspose", mat4_array_type); |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 430 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 431 | add_uniform(instructions, symtab, "gl_DepthRange", |
| 432 | symtab->get_type("gl_DepthRangeParameters")); |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 433 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 434 | add_uniform(instructions, symtab, "gl_ClipPlane", |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 435 | glsl_type::get_array_instance(glsl_type::vec4_type, |
| 436 | state->Const.MaxClipPlanes)); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 437 | add_uniform(instructions, symtab, "gl_Point", |
| 438 | symtab->get_type("gl_PointParameters")); |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 439 | |
| 440 | const glsl_type *const material_parameters_type = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 441 | symtab->get_type("gl_MaterialParameters"); |
| 442 | add_uniform(instructions, symtab, "gl_FrontMaterial", material_parameters_type); |
| 443 | add_uniform(instructions, symtab, "gl_BackMaterial", material_parameters_type); |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 444 | |
Eric Anholt | aa57943 | 2010-05-19 14:09:04 -0700 | [diff] [blame] | 445 | const glsl_type *const light_source_array_type = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 446 | 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] | 447 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 448 | add_uniform(instructions, symtab, "gl_LightSource", light_source_array_type); |
Eric Anholt | aa57943 | 2010-05-19 14:09:04 -0700 | [diff] [blame] | 449 | |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 450 | const glsl_type *const light_model_products_type = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 451 | symtab->get_type("gl_LightModelProducts"); |
| 452 | add_uniform(instructions, symtab, "gl_FrontLightModelProduct", |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 453 | light_model_products_type); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 454 | add_uniform(instructions, symtab, "gl_BackLightModelProduct", |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 455 | light_model_products_type); |
| 456 | |
| 457 | const glsl_type *const light_products_type = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 458 | glsl_type::get_array_instance(symtab->get_type("gl_LightProducts"), |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 459 | state->Const.MaxLights); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 460 | add_uniform(instructions, symtab, "gl_FrontLightProduct", light_products_type); |
| 461 | add_uniform(instructions, symtab, "gl_BackLightProduct", light_products_type); |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 462 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 463 | add_uniform(instructions, symtab, "gl_TextureEnvColor", |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 464 | glsl_type::get_array_instance(glsl_type::vec4_type, |
| 465 | state->Const.MaxTextureUnits)); |
| 466 | |
| 467 | const glsl_type *const texcoords_vec4 = |
| 468 | glsl_type::get_array_instance(glsl_type::vec4_type, |
| 469 | state->Const.MaxTextureCoords); |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 470 | add_uniform(instructions, symtab, "gl_EyePlaneS", texcoords_vec4); |
| 471 | add_uniform(instructions, symtab, "gl_EyePlaneT", texcoords_vec4); |
| 472 | add_uniform(instructions, symtab, "gl_EyePlaneR", texcoords_vec4); |
| 473 | add_uniform(instructions, symtab, "gl_EyePlaneQ", texcoords_vec4); |
| 474 | add_uniform(instructions, symtab, "gl_ObjectPlaneS", texcoords_vec4); |
| 475 | add_uniform(instructions, symtab, "gl_ObjectPlaneT", texcoords_vec4); |
| 476 | add_uniform(instructions, symtab, "gl_ObjectPlaneR", texcoords_vec4); |
| 477 | add_uniform(instructions, symtab, "gl_ObjectPlaneQ", texcoords_vec4); |
Eric Anholt | 85b5dba | 2010-07-28 12:23:51 -0700 | [diff] [blame] | 478 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 479 | add_uniform(instructions, symtab, "gl_Fog", |
| 480 | symtab->get_type("gl_FogParameters")); |
Eric Anholt | 78fe3c9 | 2010-03-28 01:46:48 -0700 | [diff] [blame] | 481 | } |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 482 | |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 483 | /* This function should only be called for ES, not desktop GL. */ |
| 484 | static void |
| 485 | generate_100ES_vs_variables(exec_list *instructions, |
| 486 | struct _mesa_glsl_parse_state *state) |
| 487 | { |
| 488 | for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 489 | add_builtin_variable(instructions, state->symbols, |
| 490 | & builtin_core_vs_variables[i]); |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | generate_100ES_uniforms(instructions, state); |
| 494 | |
| 495 | generate_ARB_draw_buffers_variables(instructions, state, false, |
| 496 | vertex_shader); |
| 497 | } |
| 498 | |
| 499 | |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 500 | static void |
| 501 | generate_110_vs_variables(exec_list *instructions, |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 502 | struct _mesa_glsl_parse_state *state) |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 503 | { |
| 504 | for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 505 | add_builtin_variable(instructions, state->symbols, |
| 506 | & builtin_core_vs_variables[i]); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | for (unsigned i = 0 |
| 510 | ; i < Elements(builtin_110_deprecated_vs_variables) |
| 511 | ; i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 512 | add_builtin_variable(instructions, state->symbols, |
| 513 | & builtin_110_deprecated_vs_variables[i]); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 514 | } |
Ian Romanick | 127308b | 2010-07-01 13:30:50 -0700 | [diff] [blame] | 515 | generate_110_uniforms(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 516 | |
Ian Romanick | cd00d5b | 2010-07-01 13:17:54 -0700 | [diff] [blame] | 517 | /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec: |
| 518 | * |
| 519 | * "As with all arrays, indices used to subscript gl_TexCoord must |
| 520 | * either be an integral constant expressions, or this array must be |
| 521 | * re-declared by the shader with a size. The size can be at most |
| 522 | * gl_MaxTextureCoords. Using indexes close to 0 may aid the |
| 523 | * implementation in preserving varying resources." |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 524 | */ |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 525 | const glsl_type *const vec4_array_type = |
Ian Romanick | f38d15b | 2010-07-20 15:33:40 -0700 | [diff] [blame] | 526 | glsl_type::get_array_instance(glsl_type::vec4_type, 0); |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 527 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 528 | add_variable(instructions, state->symbols, |
| 529 | "gl_TexCoord", vec4_array_type, ir_var_out, VERT_RESULT_TEX0); |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 530 | |
| 531 | generate_ARB_draw_buffers_variables(instructions, state, false, |
| 532 | vertex_shader); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | |
| 536 | static void |
| 537 | generate_120_vs_variables(exec_list *instructions, |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 538 | struct _mesa_glsl_parse_state *state) |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 539 | { |
| 540 | /* GLSL version 1.20 did not add any built-in variables in the vertex |
| 541 | * shader. |
| 542 | */ |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 543 | generate_110_vs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | |
| 547 | static void |
| 548 | generate_130_vs_variables(exec_list *instructions, |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 549 | struct _mesa_glsl_parse_state *state) |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 550 | { |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 551 | generate_120_vs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 552 | |
| 553 | for (unsigned i = 0; i < Elements(builtin_130_vs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 554 | add_builtin_variable(instructions, state->symbols, |
| 555 | & builtin_130_vs_variables[i]); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 556 | } |
| 557 | |
Eric Anholt | 271e199 | 2010-04-02 23:47:06 -0700 | [diff] [blame] | 558 | const glsl_type *const clip_distance_array_type = |
Eric Anholt | 73df636 | 2010-07-28 08:18:59 -0700 | [diff] [blame] | 559 | glsl_type::get_array_instance(glsl_type::float_type, |
| 560 | state->Const.MaxClipPlanes); |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 561 | |
| 562 | /* FINISHME: gl_ClipDistance needs a real location assigned. */ |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 563 | add_variable(instructions, state->symbols, |
| 564 | "gl_ClipDistance", clip_distance_array_type, ir_var_out, -1); |
Eric Anholt | 271e199 | 2010-04-02 23:47:06 -0700 | [diff] [blame] | 565 | |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | |
| 569 | static void |
| 570 | initialize_vs_variables(exec_list *instructions, |
| 571 | struct _mesa_glsl_parse_state *state) |
| 572 | { |
| 573 | |
| 574 | switch (state->language_version) { |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 575 | case 100: |
| 576 | generate_100ES_vs_variables(instructions, state); |
| 577 | break; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 578 | case 110: |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 579 | generate_110_vs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 580 | break; |
| 581 | case 120: |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 582 | generate_120_vs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 583 | break; |
| 584 | case 130: |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 585 | generate_130_vs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 586 | break; |
| 587 | } |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 588 | |
| 589 | if (state->ARB_draw_instanced_enable) |
| 590 | generate_ARB_draw_instanced_variables(instructions, state, false, |
| 591 | vertex_shader); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 592 | } |
| 593 | |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 594 | |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 595 | /* This function should only be called for ES, not desktop GL. */ |
| 596 | static void |
| 597 | generate_100ES_fs_variables(exec_list *instructions, |
| 598 | struct _mesa_glsl_parse_state *state) |
| 599 | { |
| 600 | for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 601 | add_builtin_variable(instructions, state->symbols, |
| 602 | & builtin_core_fs_variables[i]); |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | for (unsigned i = 0; i < Elements(builtin_100ES_fs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 606 | add_builtin_variable(instructions, state->symbols, |
| 607 | & builtin_100ES_fs_variables[i]); |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | generate_100ES_uniforms(instructions, state); |
| 611 | |
| 612 | generate_ARB_draw_buffers_variables(instructions, state, false, |
| 613 | fragment_shader); |
| 614 | } |
| 615 | |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 616 | static void |
| 617 | generate_110_fs_variables(exec_list *instructions, |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 618 | struct _mesa_glsl_parse_state *state) |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 619 | { |
| 620 | for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 621 | add_builtin_variable(instructions, state->symbols, |
| 622 | & builtin_core_fs_variables[i]); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 625 | for (unsigned i = 0; i < Elements(builtin_110_fs_variables); i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 626 | add_builtin_variable(instructions, state->symbols, |
| 627 | & builtin_110_fs_variables[i]); |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Eric Anholt | 0f09aea | 2010-03-27 12:48:57 -0700 | [diff] [blame] | 630 | for (unsigned i = 0 |
| 631 | ; i < Elements(builtin_110_deprecated_fs_variables) |
| 632 | ; i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 633 | add_builtin_variable(instructions, state->symbols, |
| 634 | & builtin_110_deprecated_fs_variables[i]); |
Eric Anholt | 0f09aea | 2010-03-27 12:48:57 -0700 | [diff] [blame] | 635 | } |
Ian Romanick | 127308b | 2010-07-01 13:30:50 -0700 | [diff] [blame] | 636 | generate_110_uniforms(instructions, state); |
Eric Anholt | 0f09aea | 2010-03-27 12:48:57 -0700 | [diff] [blame] | 637 | |
Ian Romanick | cd00d5b | 2010-07-01 13:17:54 -0700 | [diff] [blame] | 638 | /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec: |
| 639 | * |
| 640 | * "As with all arrays, indices used to subscript gl_TexCoord must |
| 641 | * either be an integral constant expressions, or this array must be |
| 642 | * re-declared by the shader with a size. The size can be at most |
| 643 | * gl_MaxTextureCoords. Using indexes close to 0 may aid the |
| 644 | * implementation in preserving varying resources." |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 645 | */ |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 646 | const glsl_type *const vec4_array_type = |
Ian Romanick | f38d15b | 2010-07-20 15:33:40 -0700 | [diff] [blame] | 647 | glsl_type::get_array_instance(glsl_type::vec4_type, 0); |
Ian Romanick | 3f9a73d | 2010-04-02 11:59:57 -0700 | [diff] [blame] | 648 | |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 649 | add_variable(instructions, state->symbols, |
| 650 | "gl_TexCoord", vec4_array_type, ir_var_in, FRAG_ATTRIB_TEX0); |
Ian Romanick | 9c4b1f2 | 2010-06-29 15:10:09 -0700 | [diff] [blame] | 651 | |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 652 | generate_ARB_draw_buffers_variables(instructions, state, false, |
| 653 | fragment_shader); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 656 | |
| 657 | static void |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 658 | generate_ARB_draw_buffers_variables(exec_list *instructions, |
| 659 | struct _mesa_glsl_parse_state *state, |
| 660 | bool warn, _mesa_glsl_parser_targets target) |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 661 | { |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 662 | /* gl_MaxDrawBuffers is available in all shader stages. |
| 663 | */ |
Ian Romanick | e2f84f0 | 2010-06-29 15:19:11 -0700 | [diff] [blame] | 664 | ir_variable *const mdb = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 665 | add_variable(instructions, state->symbols, |
| 666 | "gl_MaxDrawBuffers", glsl_type::int_type, ir_var_auto, -1); |
Ian Romanick | e2f84f0 | 2010-06-29 15:19:11 -0700 | [diff] [blame] | 667 | |
| 668 | if (warn) |
| 669 | mdb->warn_extension = "GL_ARB_draw_buffers"; |
| 670 | |
| 671 | mdb->constant_value = new(mdb) |
| 672 | ir_constant(int(state->Const.MaxDrawBuffers)); |
| 673 | |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 674 | |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 675 | /* gl_FragData is only available in the fragment shader. |
| 676 | */ |
| 677 | if (target == fragment_shader) { |
| 678 | const glsl_type *const vec4_array_type = |
Ian Romanick | f38d15b | 2010-07-20 15:33:40 -0700 | [diff] [blame] | 679 | glsl_type::get_array_instance(glsl_type::vec4_type, |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 680 | state->Const.MaxDrawBuffers); |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 681 | |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 682 | ir_variable *const fd = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 683 | add_variable(instructions, state->symbols, |
| 684 | "gl_FragData", vec4_array_type, |
| 685 | ir_var_out, FRAG_RESULT_DATA0); |
Ian Romanick | 22971e9 | 2010-06-29 15:29:56 -0700 | [diff] [blame] | 686 | |
| 687 | if (warn) |
| 688 | fd->warn_extension = "GL_ARB_draw_buffers"; |
| 689 | } |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 692 | |
| 693 | static void |
| 694 | generate_ARB_draw_instanced_variables(exec_list *instructions, |
| 695 | struct _mesa_glsl_parse_state *state, |
| 696 | bool warn, |
| 697 | _mesa_glsl_parser_targets target) |
| 698 | { |
| 699 | /* gl_InstanceIDARB is only available in the vertex shader. |
| 700 | */ |
| 701 | if (target == vertex_shader) { |
| 702 | ir_variable *const inst = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 703 | add_variable(instructions, state->symbols, |
| 704 | "gl_InstanceIDARB", glsl_type::int_type, |
| 705 | ir_var_system_value, SYSTEM_VALUE_INSTANCE_ID); |
Brian Paul | 7ce1863 | 2010-12-08 18:25:38 -0700 | [diff] [blame] | 706 | |
| 707 | if (warn) |
| 708 | inst->warn_extension = "GL_ARB_draw_instanced"; |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | |
Dave Airlie | d967186 | 2010-10-06 09:36:02 +1000 | [diff] [blame] | 713 | static void |
| 714 | generate_ARB_shader_stencil_export_variables(exec_list *instructions, |
| 715 | struct _mesa_glsl_parse_state *state, |
| 716 | bool warn) |
| 717 | { |
| 718 | /* gl_FragStencilRefARB is only available in the fragment shader. |
| 719 | */ |
| 720 | ir_variable *const fd = |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 721 | add_variable(instructions, state->symbols, |
| 722 | "gl_FragStencilRefARB", glsl_type::int_type, |
| 723 | ir_var_out, FRAG_RESULT_STENCIL); |
Dave Airlie | d967186 | 2010-10-06 09:36:02 +1000 | [diff] [blame] | 724 | |
| 725 | if (warn) |
| 726 | fd->warn_extension = "GL_ARB_shader_stencil_export"; |
| 727 | } |
Ian Romanick | c77b257 | 2010-04-07 16:59:46 -0700 | [diff] [blame] | 728 | |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 729 | static void |
| 730 | generate_120_fs_variables(exec_list *instructions, |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 731 | struct _mesa_glsl_parse_state *state) |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 732 | { |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 733 | generate_110_fs_variables(instructions, state); |
Eric Anholt | 152b55e | 2010-07-07 19:45:22 -0700 | [diff] [blame] | 734 | |
| 735 | for (unsigned i = 0 |
| 736 | ; i < Elements(builtin_120_fs_variables) |
| 737 | ; i++) { |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 738 | add_builtin_variable(instructions, state->symbols, |
| 739 | & builtin_120_fs_variables[i]); |
Eric Anholt | 152b55e | 2010-07-07 19:45:22 -0700 | [diff] [blame] | 740 | } |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | static void |
| 744 | generate_130_fs_variables(exec_list *instructions, |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 745 | struct _mesa_glsl_parse_state *state) |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 746 | { |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 747 | generate_120_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 748 | |
Ian Romanick | 8645a95 | 2010-04-07 16:47:44 -0700 | [diff] [blame] | 749 | const glsl_type *const clip_distance_array_type = |
Eric Anholt | 73df636 | 2010-07-28 08:18:59 -0700 | [diff] [blame] | 750 | glsl_type::get_array_instance(glsl_type::float_type, |
| 751 | state->Const.MaxClipPlanes); |
Ian Romanick | ed0626e | 2010-06-21 11:42:57 -0700 | [diff] [blame] | 752 | |
| 753 | /* FINISHME: gl_ClipDistance needs a real location assigned. */ |
Ian Romanick | dfdff94 | 2011-01-24 16:45:11 -0800 | [diff] [blame] | 754 | add_variable(instructions, state->symbols, |
| 755 | "gl_ClipDistance", clip_distance_array_type, ir_var_in, -1); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | static void |
| 759 | initialize_fs_variables(exec_list *instructions, |
| 760 | struct _mesa_glsl_parse_state *state) |
| 761 | { |
| 762 | |
| 763 | switch (state->language_version) { |
Kenneth Graunke | b4fe4d5 | 2010-08-07 02:45:33 -0700 | [diff] [blame] | 764 | case 100: |
| 765 | generate_100ES_fs_variables(instructions, state); |
| 766 | break; |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 767 | case 110: |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 768 | generate_110_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 769 | break; |
| 770 | case 120: |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 771 | generate_120_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 772 | break; |
| 773 | case 130: |
Ian Romanick | 5e18b05 | 2010-06-29 14:21:05 -0700 | [diff] [blame] | 774 | generate_130_fs_variables(instructions, state); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 775 | break; |
| 776 | } |
Dave Airlie | d967186 | 2010-10-06 09:36:02 +1000 | [diff] [blame] | 777 | |
| 778 | if (state->ARB_shader_stencil_export_enable) |
| 779 | generate_ARB_shader_stencil_export_variables(instructions, state, |
| 780 | state->ARB_shader_stencil_export_warn); |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 781 | } |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 782 | |
| 783 | void |
| 784 | _mesa_glsl_initialize_variables(exec_list *instructions, |
| 785 | struct _mesa_glsl_parse_state *state) |
| 786 | { |
| 787 | switch (state->target) { |
| 788 | case vertex_shader: |
| 789 | initialize_vs_variables(instructions, state); |
| 790 | break; |
| 791 | case geometry_shader: |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 792 | break; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 793 | case fragment_shader: |
Eric Anholt | b3f743a | 2010-03-25 14:48:25 -0700 | [diff] [blame] | 794 | initialize_fs_variables(instructions, state); |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 795 | break; |
Ian Romanick | adfb0cd | 2010-03-10 10:43:16 -0800 | [diff] [blame] | 796 | } |
| 797 | } |