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