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