2010-03-10 10:43:16 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2010 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-06-22 10:38:52 -07:00
|
|
|
#include "ir.h"
|
2010-03-10 10:43:16 -08:00
|
|
|
#include "glsl_parser_extras.h"
|
2010-03-19 11:57:24 -07:00
|
|
|
#include "glsl_symbol_table.h"
|
2011-11-08 14:46:25 -08:00
|
|
|
#include "main/core.h"
|
2011-01-24 16:55:50 -08:00
|
|
|
#include "main/uniforms.h"
|
|
|
|
|
#include "program/prog_parameter.h"
|
|
|
|
|
#include "program/prog_statevars.h"
|
|
|
|
|
#include "program/prog_instruction.h"
|
2010-03-10 10:43:16 -08:00
|
|
|
|
2010-06-29 15:29:56 -07:00
|
|
|
static void generate_ARB_draw_buffers_variables(exec_list *,
|
|
|
|
|
struct _mesa_glsl_parse_state *,
|
|
|
|
|
bool, _mesa_glsl_parser_targets);
|
2010-06-29 15:10:09 -07:00
|
|
|
|
2010-12-08 18:25:38 -07:00
|
|
|
static void
|
|
|
|
|
generate_ARB_draw_instanced_variables(exec_list *,
|
|
|
|
|
struct _mesa_glsl_parse_state *,
|
|
|
|
|
bool, _mesa_glsl_parser_targets);
|
|
|
|
|
|
2011-11-08 14:46:25 -08:00
|
|
|
struct builtin_variable {
|
|
|
|
|
enum ir_variable_mode mode;
|
|
|
|
|
int slot;
|
|
|
|
|
const char *type;
|
|
|
|
|
const char *name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const builtin_variable builtin_core_vs_variables[] = {
|
2013-02-23 07:22:01 -08:00
|
|
|
{ ir_var_shader_out, VARYING_SLOT_POS, "vec4", "gl_Position" },
|
|
|
|
|
{ ir_var_shader_out, VARYING_SLOT_PSIZ, "float", "gl_PointSize" },
|
2011-11-08 14:46:25 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const builtin_variable builtin_core_fs_variables[] = {
|
2013-02-23 09:00:58 -08:00
|
|
|
{ ir_var_shader_in, VARYING_SLOT_POS, "vec4", "gl_FragCoord" },
|
|
|
|
|
{ ir_var_shader_in, VARYING_SLOT_FACE, "bool", "gl_FrontFacing" },
|
2013-01-11 14:39:32 -08:00
|
|
|
{ ir_var_shader_out, FRAG_RESULT_COLOR, "vec4", "gl_FragColor" },
|
2011-11-08 14:46:25 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const builtin_variable builtin_100ES_fs_variables[] = {
|
2013-02-23 09:00:58 -08:00
|
|
|
{ ir_var_shader_in, VARYING_SLOT_PNTC, "vec2", "gl_PointCoord" },
|
2011-11-08 14:46:25 -08:00
|
|
|
};
|
|
|
|
|
|
2012-08-04 10:29:49 -07:00
|
|
|
static const builtin_variable builtin_300ES_vs_variables[] = {
|
|
|
|
|
{ ir_var_system_value, SYSTEM_VALUE_VERTEX_ID, "int", "gl_VertexID" },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const builtin_variable builtin_300ES_fs_variables[] = {
|
2013-02-23 09:00:58 -08:00
|
|
|
{ ir_var_shader_in, VARYING_SLOT_POS, "vec4", "gl_FragCoord" },
|
|
|
|
|
{ ir_var_shader_in, VARYING_SLOT_FACE, "bool", "gl_FrontFacing" },
|
2013-01-11 14:39:32 -08:00
|
|
|
{ ir_var_shader_out, FRAG_RESULT_DEPTH, "float", "gl_FragDepth" },
|
2013-02-23 09:00:58 -08:00
|
|
|
{ ir_var_shader_in, VARYING_SLOT_PNTC, "vec2", "gl_PointCoord" },
|
2012-08-04 10:29:49 -07:00
|
|
|
};
|
|
|
|
|
|
2011-11-08 14:46:25 -08:00
|
|
|
static const builtin_variable builtin_110_fs_variables[] = {
|
2013-01-11 14:39:32 -08:00
|
|
|
{ ir_var_shader_out, FRAG_RESULT_DEPTH, "float", "gl_FragDepth" },
|
2011-11-08 14:46:25 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const builtin_variable builtin_110_deprecated_fs_variables[] = {
|
2013-02-23 09:00:58 -08:00
|
|
|
{ ir_var_shader_in, VARYING_SLOT_COL0, "vec4", "gl_Color" },
|
|
|
|
|
{ ir_var_shader_in, VARYING_SLOT_COL1, "vec4", "gl_SecondaryColor" },
|
|
|
|
|
{ ir_var_shader_in, VARYING_SLOT_FOGC, "float", "gl_FogFragCoord" },
|
2011-11-08 14:46:25 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const builtin_variable builtin_110_deprecated_vs_variables[] = {
|
2013-01-11 14:39:32 -08:00
|
|
|
{ ir_var_shader_in, VERT_ATTRIB_POS, "vec4", "gl_Vertex" },
|
|
|
|
|
{ ir_var_shader_in, VERT_ATTRIB_NORMAL, "vec3", "gl_Normal" },
|
|
|
|
|
{ ir_var_shader_in, VERT_ATTRIB_COLOR0, "vec4", "gl_Color" },
|
|
|
|
|
{ ir_var_shader_in, VERT_ATTRIB_COLOR1, "vec4", "gl_SecondaryColor" },
|
|
|
|
|
{ ir_var_shader_in, VERT_ATTRIB_TEX0, "vec4", "gl_MultiTexCoord0" },
|
|
|
|
|
{ ir_var_shader_in, VERT_ATTRIB_TEX1, "vec4", "gl_MultiTexCoord1" },
|
|
|
|
|
{ ir_var_shader_in, VERT_ATTRIB_TEX2, "vec4", "gl_MultiTexCoord2" },
|
|
|
|
|
{ ir_var_shader_in, VERT_ATTRIB_TEX3, "vec4", "gl_MultiTexCoord3" },
|
|
|
|
|
{ ir_var_shader_in, VERT_ATTRIB_TEX4, "vec4", "gl_MultiTexCoord4" },
|
|
|
|
|
{ ir_var_shader_in, VERT_ATTRIB_TEX5, "vec4", "gl_MultiTexCoord5" },
|
|
|
|
|
{ ir_var_shader_in, VERT_ATTRIB_TEX6, "vec4", "gl_MultiTexCoord6" },
|
|
|
|
|
{ ir_var_shader_in, VERT_ATTRIB_TEX7, "vec4", "gl_MultiTexCoord7" },
|
|
|
|
|
{ ir_var_shader_in, VERT_ATTRIB_FOG, "float", "gl_FogCoord" },
|
2013-02-23 07:22:01 -08:00
|
|
|
{ ir_var_shader_out, VARYING_SLOT_CLIP_VERTEX, "vec4", "gl_ClipVertex" },
|
|
|
|
|
{ ir_var_shader_out, VARYING_SLOT_COL0, "vec4", "gl_FrontColor" },
|
|
|
|
|
{ ir_var_shader_out, VARYING_SLOT_BFC0, "vec4", "gl_BackColor" },
|
|
|
|
|
{ ir_var_shader_out, VARYING_SLOT_COL1, "vec4", "gl_FrontSecondaryColor" },
|
|
|
|
|
{ ir_var_shader_out, VARYING_SLOT_BFC1, "vec4", "gl_BackSecondaryColor" },
|
|
|
|
|
{ ir_var_shader_out, VARYING_SLOT_FOGC, "float", "gl_FogFragCoord" },
|
2011-11-08 14:46:25 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const builtin_variable builtin_120_fs_variables[] = {
|
2013-02-23 09:00:58 -08:00
|
|
|
{ ir_var_shader_in, VARYING_SLOT_PNTC, "vec2", "gl_PointCoord" },
|
2011-11-08 14:46:25 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const builtin_variable builtin_130_vs_variables[] = {
|
2011-11-08 14:49:07 -08:00
|
|
|
{ ir_var_system_value, SYSTEM_VALUE_VERTEX_ID, "int", "gl_VertexID" },
|
2011-11-08 14:46:25 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const builtin_variable builtin_110_deprecated_uniforms[] = {
|
|
|
|
|
{ ir_var_uniform, -1, "mat4", "gl_ModelViewMatrix" },
|
|
|
|
|
{ ir_var_uniform, -1, "mat4", "gl_ProjectionMatrix" },
|
|
|
|
|
{ ir_var_uniform, -1, "mat4", "gl_ModelViewProjectionMatrix" },
|
|
|
|
|
{ ir_var_uniform, -1, "mat3", "gl_NormalMatrix" },
|
|
|
|
|
{ ir_var_uniform, -1, "mat4", "gl_ModelViewMatrixInverse" },
|
|
|
|
|
{ ir_var_uniform, -1, "mat4", "gl_ProjectionMatrixInverse" },
|
|
|
|
|
{ ir_var_uniform, -1, "mat4", "gl_ModelViewProjectionMatrixInverse" },
|
|
|
|
|
{ ir_var_uniform, -1, "mat4", "gl_ModelViewMatrixTranspose" },
|
|
|
|
|
{ ir_var_uniform, -1, "mat4", "gl_ProjectionMatrixTranspose" },
|
|
|
|
|
{ ir_var_uniform, -1, "mat4", "gl_ModelViewProjectionMatrixTranspose" },
|
|
|
|
|
{ ir_var_uniform, -1, "mat4", "gl_ModelViewMatrixInverseTranspose" },
|
|
|
|
|
{ ir_var_uniform, -1, "mat4", "gl_ProjectionMatrixInverseTranspose" },
|
|
|
|
|
{ ir_var_uniform, -1, "mat4", "gl_ModelViewProjectionMatrixInverseTranspose" },
|
|
|
|
|
{ ir_var_uniform, -1, "float", "gl_NormalScale" },
|
|
|
|
|
{ ir_var_uniform, -1, "gl_LightModelParameters", "gl_LightModel"},
|
|
|
|
|
|
|
|
|
|
/* Mesa-internal ATI_envmap_bumpmap state. */
|
|
|
|
|
{ ir_var_uniform, -1, "vec2", "gl_BumpRotMatrix0MESA"},
|
|
|
|
|
{ ir_var_uniform, -1, "vec2", "gl_BumpRotMatrix1MESA"},
|
|
|
|
|
{ ir_var_uniform, -1, "vec4", "gl_FogParamsOptimizedMESA"},
|
|
|
|
|
};
|
|
|
|
|
|
2011-01-24 16:55:50 -08:00
|
|
|
static struct gl_builtin_uniform_element gl_DepthRange_elements[] = {
|
|
|
|
|
{"near", {STATE_DEPTH_RANGE, 0, 0}, SWIZZLE_XXXX},
|
|
|
|
|
{"far", {STATE_DEPTH_RANGE, 0, 0}, SWIZZLE_YYYY},
|
|
|
|
|
{"diff", {STATE_DEPTH_RANGE, 0, 0}, SWIZZLE_ZZZZ},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_ClipPlane_elements[] = {
|
|
|
|
|
{NULL, {STATE_CLIPPLANE, 0, 0}, SWIZZLE_XYZW}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_Point_elements[] = {
|
|
|
|
|
{"size", {STATE_POINT_SIZE}, SWIZZLE_XXXX},
|
|
|
|
|
{"sizeMin", {STATE_POINT_SIZE}, SWIZZLE_YYYY},
|
|
|
|
|
{"sizeMax", {STATE_POINT_SIZE}, SWIZZLE_ZZZZ},
|
|
|
|
|
{"fadeThresholdSize", {STATE_POINT_SIZE}, SWIZZLE_WWWW},
|
|
|
|
|
{"distanceConstantAttenuation", {STATE_POINT_ATTENUATION}, SWIZZLE_XXXX},
|
|
|
|
|
{"distanceLinearAttenuation", {STATE_POINT_ATTENUATION}, SWIZZLE_YYYY},
|
|
|
|
|
{"distanceQuadraticAttenuation", {STATE_POINT_ATTENUATION}, SWIZZLE_ZZZZ},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_FrontMaterial_elements[] = {
|
|
|
|
|
{"emission", {STATE_MATERIAL, 0, STATE_EMISSION}, SWIZZLE_XYZW},
|
|
|
|
|
{"ambient", {STATE_MATERIAL, 0, STATE_AMBIENT}, SWIZZLE_XYZW},
|
|
|
|
|
{"diffuse", {STATE_MATERIAL, 0, STATE_DIFFUSE}, SWIZZLE_XYZW},
|
|
|
|
|
{"specular", {STATE_MATERIAL, 0, STATE_SPECULAR}, SWIZZLE_XYZW},
|
|
|
|
|
{"shininess", {STATE_MATERIAL, 0, STATE_SHININESS}, SWIZZLE_XXXX},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_BackMaterial_elements[] = {
|
|
|
|
|
{"emission", {STATE_MATERIAL, 1, STATE_EMISSION}, SWIZZLE_XYZW},
|
|
|
|
|
{"ambient", {STATE_MATERIAL, 1, STATE_AMBIENT}, SWIZZLE_XYZW},
|
|
|
|
|
{"diffuse", {STATE_MATERIAL, 1, STATE_DIFFUSE}, SWIZZLE_XYZW},
|
|
|
|
|
{"specular", {STATE_MATERIAL, 1, STATE_SPECULAR}, SWIZZLE_XYZW},
|
|
|
|
|
{"shininess", {STATE_MATERIAL, 1, STATE_SHININESS}, SWIZZLE_XXXX},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_LightSource_elements[] = {
|
|
|
|
|
{"ambient", {STATE_LIGHT, 0, STATE_AMBIENT}, SWIZZLE_XYZW},
|
|
|
|
|
{"diffuse", {STATE_LIGHT, 0, STATE_DIFFUSE}, SWIZZLE_XYZW},
|
|
|
|
|
{"specular", {STATE_LIGHT, 0, STATE_SPECULAR}, SWIZZLE_XYZW},
|
|
|
|
|
{"position", {STATE_LIGHT, 0, STATE_POSITION}, SWIZZLE_XYZW},
|
|
|
|
|
{"halfVector", {STATE_LIGHT, 0, STATE_HALF_VECTOR}, SWIZZLE_XYZW},
|
|
|
|
|
{"spotDirection", {STATE_LIGHT, 0, STATE_SPOT_DIRECTION},
|
|
|
|
|
MAKE_SWIZZLE4(SWIZZLE_X,
|
|
|
|
|
SWIZZLE_Y,
|
|
|
|
|
SWIZZLE_Z,
|
|
|
|
|
SWIZZLE_Z)},
|
|
|
|
|
{"spotCosCutoff", {STATE_LIGHT, 0, STATE_SPOT_DIRECTION}, SWIZZLE_WWWW},
|
|
|
|
|
{"spotCutoff", {STATE_LIGHT, 0, STATE_SPOT_CUTOFF}, SWIZZLE_XXXX},
|
|
|
|
|
{"spotExponent", {STATE_LIGHT, 0, STATE_ATTENUATION}, SWIZZLE_WWWW},
|
|
|
|
|
{"constantAttenuation", {STATE_LIGHT, 0, STATE_ATTENUATION}, SWIZZLE_XXXX},
|
|
|
|
|
{"linearAttenuation", {STATE_LIGHT, 0, STATE_ATTENUATION}, SWIZZLE_YYYY},
|
|
|
|
|
{"quadraticAttenuation", {STATE_LIGHT, 0, STATE_ATTENUATION}, SWIZZLE_ZZZZ},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_LightModel_elements[] = {
|
|
|
|
|
{"ambient", {STATE_LIGHTMODEL_AMBIENT, 0}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_FrontLightModelProduct_elements[] = {
|
|
|
|
|
{"sceneColor", {STATE_LIGHTMODEL_SCENECOLOR, 0}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_BackLightModelProduct_elements[] = {
|
|
|
|
|
{"sceneColor", {STATE_LIGHTMODEL_SCENECOLOR, 1}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_FrontLightProduct_elements[] = {
|
|
|
|
|
{"ambient", {STATE_LIGHTPROD, 0, 0, STATE_AMBIENT}, SWIZZLE_XYZW},
|
|
|
|
|
{"diffuse", {STATE_LIGHTPROD, 0, 0, STATE_DIFFUSE}, SWIZZLE_XYZW},
|
|
|
|
|
{"specular", {STATE_LIGHTPROD, 0, 0, STATE_SPECULAR}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_BackLightProduct_elements[] = {
|
|
|
|
|
{"ambient", {STATE_LIGHTPROD, 0, 1, STATE_AMBIENT}, SWIZZLE_XYZW},
|
|
|
|
|
{"diffuse", {STATE_LIGHTPROD, 0, 1, STATE_DIFFUSE}, SWIZZLE_XYZW},
|
|
|
|
|
{"specular", {STATE_LIGHTPROD, 0, 1, STATE_SPECULAR}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_TextureEnvColor_elements[] = {
|
|
|
|
|
{NULL, {STATE_TEXENV_COLOR, 0}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_EyePlaneS_elements[] = {
|
|
|
|
|
{NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_EYE_S}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_EyePlaneT_elements[] = {
|
|
|
|
|
{NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_EYE_T}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_EyePlaneR_elements[] = {
|
|
|
|
|
{NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_EYE_R}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_EyePlaneQ_elements[] = {
|
|
|
|
|
{NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_EYE_Q}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_ObjectPlaneS_elements[] = {
|
|
|
|
|
{NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_OBJECT_S}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_ObjectPlaneT_elements[] = {
|
|
|
|
|
{NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_OBJECT_T}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_ObjectPlaneR_elements[] = {
|
|
|
|
|
{NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_OBJECT_R}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_ObjectPlaneQ_elements[] = {
|
|
|
|
|
{NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_OBJECT_Q}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_Fog_elements[] = {
|
|
|
|
|
{"color", {STATE_FOG_COLOR}, SWIZZLE_XYZW},
|
|
|
|
|
{"density", {STATE_FOG_PARAMS}, SWIZZLE_XXXX},
|
|
|
|
|
{"start", {STATE_FOG_PARAMS}, SWIZZLE_YYYY},
|
|
|
|
|
{"end", {STATE_FOG_PARAMS}, SWIZZLE_ZZZZ},
|
|
|
|
|
{"scale", {STATE_FOG_PARAMS}, SWIZZLE_WWWW},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_NormalScale_elements[] = {
|
|
|
|
|
{NULL, {STATE_NORMAL_SCALE}, SWIZZLE_XXXX},
|
|
|
|
|
};
|
|
|
|
|
|
2011-10-21 10:45:48 -07:00
|
|
|
static struct gl_builtin_uniform_element gl_BumpRotMatrix0MESA_elements[] = {
|
2011-01-24 16:55:50 -08:00
|
|
|
{NULL, {STATE_INTERNAL, STATE_ROT_MATRIX_0}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
2011-10-21 10:45:48 -07:00
|
|
|
static struct gl_builtin_uniform_element gl_BumpRotMatrix1MESA_elements[] = {
|
2011-01-24 16:55:50 -08:00
|
|
|
{NULL, {STATE_INTERNAL, STATE_ROT_MATRIX_1}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
2011-10-21 10:45:48 -07:00
|
|
|
static struct gl_builtin_uniform_element gl_FogParamsOptimizedMESA_elements[] = {
|
2011-01-24 16:55:50 -08:00
|
|
|
{NULL, {STATE_INTERNAL, STATE_FOG_PARAMS_OPTIMIZED}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
2011-07-16 17:41:26 -07:00
|
|
|
static struct gl_builtin_uniform_element gl_CurrentAttribVertMESA_elements[] = {
|
|
|
|
|
{NULL, {STATE_INTERNAL, STATE_CURRENT_ATTRIB, 0}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_CurrentAttribFragMESA_elements[] = {
|
|
|
|
|
{NULL, {STATE_INTERNAL, STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED, 0}, SWIZZLE_XYZW},
|
|
|
|
|
};
|
|
|
|
|
|
2011-01-24 16:55:50 -08:00
|
|
|
#define MATRIX(name, statevar, modifier) \
|
|
|
|
|
static struct gl_builtin_uniform_element name ## _elements[] = { \
|
|
|
|
|
{ NULL, { statevar, 0, 0, 0, modifier}, SWIZZLE_XYZW }, \
|
|
|
|
|
{ NULL, { statevar, 0, 1, 1, modifier}, SWIZZLE_XYZW }, \
|
|
|
|
|
{ NULL, { statevar, 0, 2, 2, modifier}, SWIZZLE_XYZW }, \
|
|
|
|
|
{ NULL, { statevar, 0, 3, 3, modifier}, SWIZZLE_XYZW }, \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MATRIX(gl_ModelViewMatrix,
|
|
|
|
|
STATE_MODELVIEW_MATRIX, STATE_MATRIX_TRANSPOSE);
|
|
|
|
|
MATRIX(gl_ModelViewMatrixInverse,
|
|
|
|
|
STATE_MODELVIEW_MATRIX, STATE_MATRIX_INVTRANS);
|
|
|
|
|
MATRIX(gl_ModelViewMatrixTranspose,
|
|
|
|
|
STATE_MODELVIEW_MATRIX, 0);
|
|
|
|
|
MATRIX(gl_ModelViewMatrixInverseTranspose,
|
|
|
|
|
STATE_MODELVIEW_MATRIX, STATE_MATRIX_INVERSE);
|
|
|
|
|
|
|
|
|
|
MATRIX(gl_ProjectionMatrix,
|
|
|
|
|
STATE_PROJECTION_MATRIX, STATE_MATRIX_TRANSPOSE);
|
|
|
|
|
MATRIX(gl_ProjectionMatrixInverse,
|
|
|
|
|
STATE_PROJECTION_MATRIX, STATE_MATRIX_INVTRANS);
|
|
|
|
|
MATRIX(gl_ProjectionMatrixTranspose,
|
|
|
|
|
STATE_PROJECTION_MATRIX, 0);
|
|
|
|
|
MATRIX(gl_ProjectionMatrixInverseTranspose,
|
|
|
|
|
STATE_PROJECTION_MATRIX, STATE_MATRIX_INVERSE);
|
|
|
|
|
|
|
|
|
|
MATRIX(gl_ModelViewProjectionMatrix,
|
|
|
|
|
STATE_MVP_MATRIX, STATE_MATRIX_TRANSPOSE);
|
|
|
|
|
MATRIX(gl_ModelViewProjectionMatrixInverse,
|
|
|
|
|
STATE_MVP_MATRIX, STATE_MATRIX_INVTRANS);
|
|
|
|
|
MATRIX(gl_ModelViewProjectionMatrixTranspose,
|
|
|
|
|
STATE_MVP_MATRIX, 0);
|
|
|
|
|
MATRIX(gl_ModelViewProjectionMatrixInverseTranspose,
|
|
|
|
|
STATE_MVP_MATRIX, STATE_MATRIX_INVERSE);
|
|
|
|
|
|
|
|
|
|
MATRIX(gl_TextureMatrix,
|
|
|
|
|
STATE_TEXTURE_MATRIX, STATE_MATRIX_TRANSPOSE);
|
|
|
|
|
MATRIX(gl_TextureMatrixInverse,
|
|
|
|
|
STATE_TEXTURE_MATRIX, STATE_MATRIX_INVTRANS);
|
|
|
|
|
MATRIX(gl_TextureMatrixTranspose,
|
|
|
|
|
STATE_TEXTURE_MATRIX, 0);
|
|
|
|
|
MATRIX(gl_TextureMatrixInverseTranspose,
|
|
|
|
|
STATE_TEXTURE_MATRIX, STATE_MATRIX_INVERSE);
|
|
|
|
|
|
|
|
|
|
static struct gl_builtin_uniform_element gl_NormalMatrix_elements[] = {
|
|
|
|
|
{ NULL, { STATE_MODELVIEW_MATRIX, 0, 0, 0, STATE_MATRIX_INVERSE},
|
2011-10-18 17:17:28 -07:00
|
|
|
MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_Z) },
|
2011-01-24 16:55:50 -08:00
|
|
|
{ NULL, { STATE_MODELVIEW_MATRIX, 0, 1, 1, STATE_MATRIX_INVERSE},
|
2011-10-18 17:17:28 -07:00
|
|
|
MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_Z) },
|
2011-01-24 16:55:50 -08:00
|
|
|
{ NULL, { STATE_MODELVIEW_MATRIX, 0, 2, 2, STATE_MATRIX_INVERSE},
|
2011-10-18 17:17:28 -07:00
|
|
|
MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_Z) },
|
2011-01-24 16:55:50 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#undef MATRIX
|
|
|
|
|
|
|
|
|
|
#define STATEVAR(name) {#name, name ## _elements, Elements(name ## _elements)}
|
|
|
|
|
|
2012-09-15 13:26:39 +10:00
|
|
|
static const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[] = {
|
2011-01-24 16:55:50 -08:00
|
|
|
STATEVAR(gl_DepthRange),
|
|
|
|
|
STATEVAR(gl_ClipPlane),
|
|
|
|
|
STATEVAR(gl_Point),
|
|
|
|
|
STATEVAR(gl_FrontMaterial),
|
|
|
|
|
STATEVAR(gl_BackMaterial),
|
|
|
|
|
STATEVAR(gl_LightSource),
|
|
|
|
|
STATEVAR(gl_LightModel),
|
|
|
|
|
STATEVAR(gl_FrontLightModelProduct),
|
|
|
|
|
STATEVAR(gl_BackLightModelProduct),
|
|
|
|
|
STATEVAR(gl_FrontLightProduct),
|
|
|
|
|
STATEVAR(gl_BackLightProduct),
|
|
|
|
|
STATEVAR(gl_TextureEnvColor),
|
|
|
|
|
STATEVAR(gl_EyePlaneS),
|
|
|
|
|
STATEVAR(gl_EyePlaneT),
|
|
|
|
|
STATEVAR(gl_EyePlaneR),
|
|
|
|
|
STATEVAR(gl_EyePlaneQ),
|
|
|
|
|
STATEVAR(gl_ObjectPlaneS),
|
|
|
|
|
STATEVAR(gl_ObjectPlaneT),
|
|
|
|
|
STATEVAR(gl_ObjectPlaneR),
|
|
|
|
|
STATEVAR(gl_ObjectPlaneQ),
|
|
|
|
|
STATEVAR(gl_Fog),
|
|
|
|
|
|
|
|
|
|
STATEVAR(gl_ModelViewMatrix),
|
|
|
|
|
STATEVAR(gl_ModelViewMatrixInverse),
|
|
|
|
|
STATEVAR(gl_ModelViewMatrixTranspose),
|
|
|
|
|
STATEVAR(gl_ModelViewMatrixInverseTranspose),
|
|
|
|
|
|
|
|
|
|
STATEVAR(gl_ProjectionMatrix),
|
|
|
|
|
STATEVAR(gl_ProjectionMatrixInverse),
|
|
|
|
|
STATEVAR(gl_ProjectionMatrixTranspose),
|
|
|
|
|
STATEVAR(gl_ProjectionMatrixInverseTranspose),
|
|
|
|
|
|
|
|
|
|
STATEVAR(gl_ModelViewProjectionMatrix),
|
|
|
|
|
STATEVAR(gl_ModelViewProjectionMatrixInverse),
|
|
|
|
|
STATEVAR(gl_ModelViewProjectionMatrixTranspose),
|
|
|
|
|
STATEVAR(gl_ModelViewProjectionMatrixInverseTranspose),
|
|
|
|
|
|
|
|
|
|
STATEVAR(gl_TextureMatrix),
|
|
|
|
|
STATEVAR(gl_TextureMatrixInverse),
|
|
|
|
|
STATEVAR(gl_TextureMatrixTranspose),
|
|
|
|
|
STATEVAR(gl_TextureMatrixInverseTranspose),
|
|
|
|
|
|
|
|
|
|
STATEVAR(gl_NormalMatrix),
|
|
|
|
|
STATEVAR(gl_NormalScale),
|
|
|
|
|
|
2011-10-21 10:45:48 -07:00
|
|
|
STATEVAR(gl_BumpRotMatrix0MESA),
|
|
|
|
|
STATEVAR(gl_BumpRotMatrix1MESA),
|
|
|
|
|
STATEVAR(gl_FogParamsOptimizedMESA),
|
2011-07-16 17:41:26 -07:00
|
|
|
STATEVAR(gl_CurrentAttribVertMESA),
|
|
|
|
|
STATEVAR(gl_CurrentAttribFragMESA),
|
2011-01-24 16:55:50 -08:00
|
|
|
|
|
|
|
|
{NULL, NULL, 0}
|
|
|
|
|
};
|
|
|
|
|
|
2010-04-07 16:59:46 -07:00
|
|
|
static ir_variable *
|
2011-01-24 16:45:11 -08:00
|
|
|
add_variable(exec_list *instructions, glsl_symbol_table *symtab,
|
|
|
|
|
const char *name, const glsl_type *type,
|
|
|
|
|
enum ir_variable_mode mode, int slot)
|
2010-03-10 10:43:16 -08:00
|
|
|
{
|
2010-07-19 17:12:42 -07:00
|
|
|
ir_variable *var = new(symtab) ir_variable(type, name, mode);
|
2010-03-10 10:43:16 -08:00
|
|
|
|
2010-04-19 11:10:37 -07:00
|
|
|
switch (var->mode) {
|
2010-06-29 15:19:11 -07:00
|
|
|
case ir_var_auto:
|
2013-01-11 14:39:32 -08:00
|
|
|
case ir_var_shader_in:
|
2010-08-04 20:33:57 -07:00
|
|
|
case ir_var_uniform:
|
2010-12-08 18:25:38 -07:00
|
|
|
case ir_var_system_value:
|
2010-03-10 10:43:16 -08:00
|
|
|
var->read_only = true;
|
2010-04-19 11:10:37 -07:00
|
|
|
break;
|
2013-01-11 14:39:32 -08:00
|
|
|
case ir_var_shader_out:
|
2010-04-19 11:10:37 -07:00
|
|
|
break;
|
|
|
|
|
default:
|
2013-01-24 16:11:08 -08:00
|
|
|
/* The only variables that are added using this function should be
|
|
|
|
|
* uniforms, shader inputs, and shader outputs, constants (which use
|
|
|
|
|
* ir_var_auto), and system values.
|
|
|
|
|
*/
|
2010-04-19 11:10:37 -07:00
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-03-10 10:43:16 -08:00
|
|
|
|
2010-06-21 11:42:57 -07:00
|
|
|
var->location = slot;
|
2010-10-07 17:21:22 -07:00
|
|
|
var->explicit_location = (slot >= 0);
|
glsl: add support for ARB_blend_func_extended (v3)
This adds index support to the GLSL compiler.
I'm not 100% sure of my approach here, esp without how output ordering
happens wrt location, index pairs, in the "mark" function.
Since current hw doesn't ever have a location > 0 with an index > 0,
we don't have to work out if the output ordering the hw requires is
location, index, location, index or location, location, index, index.
But we have no hw to know, so punt on it for now.
v2: index requires layout - catch and error
setup explicit index properly.
v3: drop idx_offset stuff, assume index follow location
Signed-off-by: Dave Airlie <airlied@redhat.com>
2012-03-24 13:33:41 +00:00
|
|
|
var->explicit_index = 0;
|
2010-06-21 11:42:57 -07:00
|
|
|
|
2010-03-10 10:43:16 -08:00
|
|
|
/* Once the variable is created an initialized, add it to the symbol table
|
|
|
|
|
* and add the declaration to the IR stream.
|
|
|
|
|
*/
|
|
|
|
|
instructions->push_tail(var);
|
|
|
|
|
|
2010-11-05 06:11:24 -07:00
|
|
|
symtab->add_variable(var);
|
2010-04-07 16:59:46 -07:00
|
|
|
return var;
|
2010-03-10 10:43:16 -08:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 12:23:51 -07:00
|
|
|
static ir_variable *
|
2011-01-24 16:45:11 -08:00
|
|
|
add_uniform(exec_list *instructions, glsl_symbol_table *symtab,
|
2010-07-28 12:23:51 -07:00
|
|
|
const char *name, const glsl_type *type)
|
|
|
|
|
{
|
2011-01-25 10:41:20 -08:00
|
|
|
ir_variable *const uni =
|
|
|
|
|
add_variable(instructions, symtab, name, type, ir_var_uniform, -1);
|
|
|
|
|
|
|
|
|
|
unsigned i;
|
|
|
|
|
for (i = 0; _mesa_builtin_uniform_desc[i].name != NULL; i++) {
|
|
|
|
|
if (strcmp(_mesa_builtin_uniform_desc[i].name, name) == 0) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(_mesa_builtin_uniform_desc[i].name != NULL);
|
|
|
|
|
const struct gl_builtin_uniform_desc* const statevar =
|
|
|
|
|
&_mesa_builtin_uniform_desc[i];
|
|
|
|
|
|
|
|
|
|
const unsigned array_count = type->is_array() ? type->length : 1;
|
|
|
|
|
uni->num_state_slots = array_count * statevar->num_elements;
|
|
|
|
|
|
|
|
|
|
ir_state_slot *slots =
|
|
|
|
|
ralloc_array(uni, ir_state_slot, uni->num_state_slots);
|
|
|
|
|
|
|
|
|
|
uni->state_slots = slots;
|
|
|
|
|
|
|
|
|
|
for (unsigned a = 0; a < array_count; a++) {
|
|
|
|
|
for (unsigned j = 0; j < statevar->num_elements; j++) {
|
|
|
|
|
struct gl_builtin_uniform_element *element = &statevar->elements[j];
|
|
|
|
|
|
|
|
|
|
memcpy(slots->tokens, element->tokens, sizeof(element->tokens));
|
|
|
|
|
if (type->is_array()) {
|
2011-07-16 17:41:26 -07:00
|
|
|
if (strcmp(name, "gl_CurrentAttribVertMESA") == 0 ||
|
|
|
|
|
strcmp(name, "gl_CurrentAttribFragMESA") == 0) {
|
|
|
|
|
slots->tokens[2] = a;
|
|
|
|
|
} else {
|
|
|
|
|
slots->tokens[1] = a;
|
|
|
|
|
}
|
2011-01-25 10:41:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
slots->swizzle = element->swizzle;
|
|
|
|
|
slots++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return uni;
|
2010-07-28 12:23:51 -07:00
|
|
|
}
|
2010-04-02 11:59:57 -07:00
|
|
|
|
|
|
|
|
static void
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_variable(exec_list *instructions, glsl_symbol_table *symtab,
|
|
|
|
|
const builtin_variable *proto)
|
2010-04-02 11:59:57 -07:00
|
|
|
{
|
|
|
|
|
/* Create a new variable declaration from the description supplied by
|
|
|
|
|
* the caller.
|
|
|
|
|
*/
|
|
|
|
|
const glsl_type *const type = symtab->get_type(proto->type);
|
|
|
|
|
|
|
|
|
|
assert(type != NULL);
|
|
|
|
|
|
2011-01-25 10:41:20 -08:00
|
|
|
if (proto->mode == ir_var_uniform) {
|
|
|
|
|
add_uniform(instructions, symtab, proto->name, type);
|
|
|
|
|
} else {
|
|
|
|
|
add_variable(instructions, symtab, proto->name, type, proto->mode,
|
|
|
|
|
proto->slot);
|
|
|
|
|
}
|
2010-04-02 11:59:57 -07:00
|
|
|
}
|
|
|
|
|
|
2011-10-31 14:43:27 -07:00
|
|
|
static ir_variable *
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_constant(exec_list *instructions, glsl_symbol_table *symtab,
|
2010-07-20 14:03:35 -07:00
|
|
|
const char *name, int value)
|
|
|
|
|
{
|
2011-01-24 16:45:11 -08:00
|
|
|
ir_variable *const var = add_variable(instructions, symtab,
|
|
|
|
|
name, glsl_type::int_type,
|
|
|
|
|
ir_var_auto, -1);
|
2010-07-20 14:03:35 -07:00
|
|
|
var->constant_value = new(var) ir_constant(value);
|
2011-10-31 14:31:07 -07:00
|
|
|
var->constant_initializer = new(var) ir_constant(value);
|
|
|
|
|
var->has_initializer = true;
|
2011-10-31 14:43:27 -07:00
|
|
|
return var;
|
2010-07-20 14:03:35 -07:00
|
|
|
}
|
2010-04-02 11:59:57 -07:00
|
|
|
|
2012-08-04 10:29:49 -07:00
|
|
|
/**
|
|
|
|
|
* Uniforms that are common to all GLSL ES implementations.
|
|
|
|
|
*
|
|
|
|
|
* Several constants in GLSL ES have different names than normal desktop GLSL.
|
2010-08-07 02:45:33 -07:00
|
|
|
* Therefore, this function should only be called on the ES path.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2012-08-04 10:29:49 -07:00
|
|
|
generate_common_ES_uniforms(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state)
|
2010-08-07 02:45:33 -07:00
|
|
|
{
|
2011-01-24 16:45:11 -08:00
|
|
|
glsl_symbol_table *const symtab = state->symbols;
|
|
|
|
|
|
|
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxVertexAttribs",
|
2010-08-07 02:45:33 -07:00
|
|
|
state->Const.MaxVertexAttribs);
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxVertexUniformVectors",
|
2010-08-07 02:45:33 -07:00
|
|
|
state->Const.MaxVertexUniformComponents);
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxVertexTextureImageUnits",
|
2010-08-07 02:45:33 -07:00
|
|
|
state->Const.MaxVertexTextureImageUnits);
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxCombinedTextureImageUnits",
|
2010-08-07 02:45:33 -07:00
|
|
|
state->Const.MaxCombinedTextureImageUnits);
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxTextureImageUnits",
|
2010-08-07 02:45:33 -07:00
|
|
|
state->Const.MaxTextureImageUnits);
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxFragmentUniformVectors",
|
2013-05-02 01:44:14 +02:00
|
|
|
state->Const.MaxFragmentUniformComponents / 4);
|
2010-08-07 02:45:33 -07:00
|
|
|
|
2011-01-24 16:45:11 -08:00
|
|
|
add_uniform(instructions, symtab, "gl_DepthRange",
|
2010-08-07 02:45:33 -07:00
|
|
|
state->symbols->get_type("gl_DepthRangeParameters"));
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-04 10:29:49 -07:00
|
|
|
static void
|
|
|
|
|
generate_100ES_uniforms(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state)
|
|
|
|
|
{
|
|
|
|
|
generate_common_ES_uniforms(instructions, state);
|
|
|
|
|
|
|
|
|
|
glsl_symbol_table *const symtab = state->symbols;
|
|
|
|
|
|
|
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxVaryingVectors",
|
|
|
|
|
state->Const.MaxVaryingFloats / 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
generate_300ES_uniforms(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state)
|
|
|
|
|
{
|
|
|
|
|
generate_common_ES_uniforms(instructions, state);
|
|
|
|
|
|
|
|
|
|
glsl_symbol_table *const symtab = state->symbols;
|
|
|
|
|
|
|
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxVertexOutputVectors",
|
|
|
|
|
state->Const.MaxVaryingFloats / 4);
|
|
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxFragmentInputVectors",
|
|
|
|
|
state->Const.MaxVaryingFloats / 4);
|
|
|
|
|
add_builtin_constant(instructions, symtab, "gl_MinProgramTexelOffset",
|
|
|
|
|
state->Const.MinProgramTexelOffset);
|
|
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxProgramTexelOffset",
|
|
|
|
|
state->Const.MaxProgramTexelOffset);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-28 01:46:48 -07:00
|
|
|
static void
|
|
|
|
|
generate_110_uniforms(exec_list *instructions,
|
2012-03-09 11:38:34 -08:00
|
|
|
struct _mesa_glsl_parse_state *state,
|
|
|
|
|
bool add_deprecated)
|
2010-03-28 01:46:48 -07:00
|
|
|
{
|
2011-01-24 16:45:11 -08:00
|
|
|
glsl_symbol_table *const symtab = state->symbols;
|
|
|
|
|
|
2012-03-09 11:38:34 -08:00
|
|
|
if (add_deprecated) {
|
|
|
|
|
for (unsigned i = 0
|
|
|
|
|
; i < Elements(builtin_110_deprecated_uniforms)
|
|
|
|
|
; i++) {
|
|
|
|
|
add_builtin_variable(instructions, symtab,
|
|
|
|
|
& builtin_110_deprecated_uniforms[i]);
|
|
|
|
|
}
|
2010-03-28 01:46:48 -07:00
|
|
|
}
|
|
|
|
|
|
2012-03-09 11:38:34 -08:00
|
|
|
if (add_deprecated) {
|
|
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxLights",
|
|
|
|
|
state->Const.MaxLights);
|
|
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxClipPlanes",
|
|
|
|
|
state->Const.MaxClipPlanes);
|
|
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxTextureUnits",
|
|
|
|
|
state->Const.MaxTextureUnits);
|
|
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxTextureCoords",
|
|
|
|
|
state->Const.MaxTextureCoords);
|
|
|
|
|
}
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxVertexAttribs",
|
2010-07-20 14:03:35 -07:00
|
|
|
state->Const.MaxVertexAttribs);
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxVertexUniformComponents",
|
2010-07-20 14:03:35 -07:00
|
|
|
state->Const.MaxVertexUniformComponents);
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxVaryingFloats",
|
2010-07-20 14:03:35 -07:00
|
|
|
state->Const.MaxVaryingFloats);
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxVertexTextureImageUnits",
|
2010-07-20 14:03:35 -07:00
|
|
|
state->Const.MaxVertexTextureImageUnits);
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxCombinedTextureImageUnits",
|
2010-07-20 14:03:35 -07:00
|
|
|
state->Const.MaxCombinedTextureImageUnits);
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxTextureImageUnits",
|
2010-07-20 14:03:35 -07:00
|
|
|
state->Const.MaxTextureImageUnits);
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxFragmentUniformComponents",
|
2010-07-20 14:03:35 -07:00
|
|
|
state->Const.MaxFragmentUniformComponents);
|
2010-07-01 13:30:50 -07:00
|
|
|
|
2012-03-09 11:38:34 -08:00
|
|
|
if (add_deprecated) {
|
|
|
|
|
const glsl_type *const mat4_array_type =
|
|
|
|
|
glsl_type::get_array_instance(glsl_type::mat4_type,
|
|
|
|
|
state->Const.MaxTextureCoords);
|
2010-04-26 14:59:32 -07:00
|
|
|
|
2012-03-09 11:38:34 -08:00
|
|
|
add_uniform(instructions, symtab, "gl_TextureMatrix", mat4_array_type);
|
|
|
|
|
add_uniform(instructions, symtab, "gl_TextureMatrixInverse", mat4_array_type);
|
|
|
|
|
add_uniform(instructions, symtab, "gl_TextureMatrixTranspose", mat4_array_type);
|
|
|
|
|
add_uniform(instructions, symtab, "gl_TextureMatrixInverseTranspose", mat4_array_type);
|
|
|
|
|
}
|
2010-03-28 01:46:48 -07:00
|
|
|
|
2011-01-24 16:45:11 -08:00
|
|
|
add_uniform(instructions, symtab, "gl_DepthRange",
|
|
|
|
|
symtab->get_type("gl_DepthRangeParameters"));
|
2010-03-28 01:46:48 -07:00
|
|
|
|
2012-03-09 11:38:34 -08:00
|
|
|
if (add_deprecated) {
|
|
|
|
|
add_uniform(instructions, symtab, "gl_ClipPlane",
|
|
|
|
|
glsl_type::get_array_instance(glsl_type::vec4_type,
|
|
|
|
|
state->Const.MaxClipPlanes));
|
|
|
|
|
add_uniform(instructions, symtab, "gl_Point",
|
|
|
|
|
symtab->get_type("gl_PointParameters"));
|
|
|
|
|
|
|
|
|
|
const glsl_type *const material_parameters_type =
|
|
|
|
|
symtab->get_type("gl_MaterialParameters");
|
|
|
|
|
add_uniform(instructions, symtab, "gl_FrontMaterial", material_parameters_type);
|
|
|
|
|
add_uniform(instructions, symtab, "gl_BackMaterial", material_parameters_type);
|
|
|
|
|
|
|
|
|
|
const glsl_type *const light_source_array_type =
|
|
|
|
|
glsl_type::get_array_instance(symtab->get_type("gl_LightSourceParameters"), state->Const.MaxLights);
|
|
|
|
|
|
|
|
|
|
add_uniform(instructions, symtab, "gl_LightSource", light_source_array_type);
|
|
|
|
|
|
|
|
|
|
const glsl_type *const light_model_products_type =
|
|
|
|
|
symtab->get_type("gl_LightModelProducts");
|
|
|
|
|
add_uniform(instructions, symtab, "gl_FrontLightModelProduct",
|
|
|
|
|
light_model_products_type);
|
|
|
|
|
add_uniform(instructions, symtab, "gl_BackLightModelProduct",
|
|
|
|
|
light_model_products_type);
|
|
|
|
|
|
|
|
|
|
const glsl_type *const light_products_type =
|
|
|
|
|
glsl_type::get_array_instance(symtab->get_type("gl_LightProducts"),
|
|
|
|
|
state->Const.MaxLights);
|
|
|
|
|
add_uniform(instructions, symtab, "gl_FrontLightProduct", light_products_type);
|
|
|
|
|
add_uniform(instructions, symtab, "gl_BackLightProduct", light_products_type);
|
|
|
|
|
|
|
|
|
|
add_uniform(instructions, symtab, "gl_TextureEnvColor",
|
|
|
|
|
glsl_type::get_array_instance(glsl_type::vec4_type,
|
|
|
|
|
state->Const.MaxTextureUnits));
|
|
|
|
|
|
|
|
|
|
const glsl_type *const texcoords_vec4 =
|
|
|
|
|
glsl_type::get_array_instance(glsl_type::vec4_type,
|
|
|
|
|
state->Const.MaxTextureCoords);
|
|
|
|
|
add_uniform(instructions, symtab, "gl_EyePlaneS", texcoords_vec4);
|
|
|
|
|
add_uniform(instructions, symtab, "gl_EyePlaneT", texcoords_vec4);
|
|
|
|
|
add_uniform(instructions, symtab, "gl_EyePlaneR", texcoords_vec4);
|
|
|
|
|
add_uniform(instructions, symtab, "gl_EyePlaneQ", texcoords_vec4);
|
|
|
|
|
add_uniform(instructions, symtab, "gl_ObjectPlaneS", texcoords_vec4);
|
|
|
|
|
add_uniform(instructions, symtab, "gl_ObjectPlaneT", texcoords_vec4);
|
|
|
|
|
add_uniform(instructions, symtab, "gl_ObjectPlaneR", texcoords_vec4);
|
|
|
|
|
add_uniform(instructions, symtab, "gl_ObjectPlaneQ", texcoords_vec4);
|
|
|
|
|
|
|
|
|
|
add_uniform(instructions, symtab, "gl_Fog",
|
|
|
|
|
symtab->get_type("gl_FogParameters"));
|
|
|
|
|
}
|
2011-07-16 17:41:26 -07:00
|
|
|
|
|
|
|
|
/* Mesa-internal current attrib state */
|
|
|
|
|
const glsl_type *const vert_attribs =
|
|
|
|
|
glsl_type::get_array_instance(glsl_type::vec4_type, VERT_ATTRIB_MAX);
|
|
|
|
|
add_uniform(instructions, symtab, "gl_CurrentAttribVertMESA", vert_attribs);
|
|
|
|
|
const glsl_type *const frag_attribs =
|
2013-02-23 09:00:58 -08:00
|
|
|
glsl_type::get_array_instance(glsl_type::vec4_type, VARYING_SLOT_MAX);
|
2011-07-16 17:41:26 -07:00
|
|
|
add_uniform(instructions, symtab, "gl_CurrentAttribFragMESA", frag_attribs);
|
2010-03-28 01:46:48 -07:00
|
|
|
}
|
2010-03-10 10:43:16 -08:00
|
|
|
|
2010-08-07 02:45:33 -07:00
|
|
|
/* This function should only be called for ES, not desktop GL. */
|
|
|
|
|
static void
|
|
|
|
|
generate_100ES_vs_variables(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state)
|
|
|
|
|
{
|
|
|
|
|
for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) {
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_variable(instructions, state->symbols,
|
|
|
|
|
& builtin_core_vs_variables[i]);
|
2010-08-07 02:45:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
generate_100ES_uniforms(instructions, state);
|
|
|
|
|
|
|
|
|
|
generate_ARB_draw_buffers_variables(instructions, state, false,
|
|
|
|
|
vertex_shader);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-04 10:29:49 -07:00
|
|
|
static void
|
|
|
|
|
generate_300ES_vs_variables(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state)
|
|
|
|
|
{
|
|
|
|
|
for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) {
|
|
|
|
|
add_builtin_variable(instructions, state->symbols,
|
|
|
|
|
& builtin_core_vs_variables[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < Elements(builtin_300ES_vs_variables); i++) {
|
|
|
|
|
add_builtin_variable(instructions, state->symbols,
|
|
|
|
|
& builtin_300ES_vs_variables[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
generate_300ES_uniforms(instructions, state);
|
|
|
|
|
|
|
|
|
|
generate_ARB_draw_buffers_variables(instructions, state, false,
|
|
|
|
|
vertex_shader);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-07 02:45:33 -07:00
|
|
|
|
2010-03-10 10:43:16 -08:00
|
|
|
static void
|
|
|
|
|
generate_110_vs_variables(exec_list *instructions,
|
2012-03-09 11:38:34 -08:00
|
|
|
struct _mesa_glsl_parse_state *state,
|
|
|
|
|
bool add_deprecated)
|
2010-03-10 10:43:16 -08:00
|
|
|
{
|
|
|
|
|
for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) {
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_variable(instructions, state->symbols,
|
|
|
|
|
& builtin_core_vs_variables[i]);
|
2010-03-10 10:43:16 -08:00
|
|
|
}
|
|
|
|
|
|
2012-03-09 11:38:34 -08:00
|
|
|
if (add_deprecated) {
|
|
|
|
|
for (unsigned i = 0
|
|
|
|
|
; i < Elements(builtin_110_deprecated_vs_variables)
|
|
|
|
|
; i++) {
|
|
|
|
|
add_builtin_variable(instructions, state->symbols,
|
|
|
|
|
& builtin_110_deprecated_vs_variables[i]);
|
|
|
|
|
}
|
2010-03-10 10:43:16 -08:00
|
|
|
}
|
2012-03-09 11:38:34 -08:00
|
|
|
generate_110_uniforms(instructions, state, add_deprecated);
|
2010-03-10 10:43:16 -08:00
|
|
|
|
2010-07-01 13:17:54 -07:00
|
|
|
/* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec:
|
|
|
|
|
*
|
|
|
|
|
* "As with all arrays, indices used to subscript gl_TexCoord must
|
|
|
|
|
* either be an integral constant expressions, or this array must be
|
|
|
|
|
* re-declared by the shader with a size. The size can be at most
|
|
|
|
|
* gl_MaxTextureCoords. Using indexes close to 0 may aid the
|
|
|
|
|
* implementation in preserving varying resources."
|
2010-03-10 10:43:16 -08:00
|
|
|
*/
|
2010-04-02 11:59:57 -07:00
|
|
|
const glsl_type *const vec4_array_type =
|
2010-07-20 15:33:40 -07:00
|
|
|
glsl_type::get_array_instance(glsl_type::vec4_type, 0);
|
2010-04-02 11:59:57 -07:00
|
|
|
|
2011-01-24 16:45:11 -08:00
|
|
|
add_variable(instructions, state->symbols,
|
2013-01-11 14:39:32 -08:00
|
|
|
"gl_TexCoord", vec4_array_type, ir_var_shader_out,
|
2013-02-23 07:22:01 -08:00
|
|
|
VARYING_SLOT_TEX0);
|
2010-06-29 15:29:56 -07:00
|
|
|
|
|
|
|
|
generate_ARB_draw_buffers_variables(instructions, state, false,
|
|
|
|
|
vertex_shader);
|
2010-03-10 10:43:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
generate_120_vs_variables(exec_list *instructions,
|
2012-03-09 11:38:34 -08:00
|
|
|
struct _mesa_glsl_parse_state *state,
|
|
|
|
|
bool add_deprecated)
|
2010-03-10 10:43:16 -08:00
|
|
|
{
|
|
|
|
|
/* GLSL version 1.20 did not add any built-in variables in the vertex
|
|
|
|
|
* shader.
|
|
|
|
|
*/
|
2012-03-09 11:38:34 -08:00
|
|
|
generate_110_vs_variables(instructions, state, add_deprecated);
|
2010-03-10 10:43:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-08-11 17:33:06 -07:00
|
|
|
static void
|
|
|
|
|
generate_130_uniforms(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state)
|
|
|
|
|
{
|
|
|
|
|
glsl_symbol_table *const symtab = state->symbols;
|
|
|
|
|
|
|
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxClipDistances",
|
|
|
|
|
state->Const.MaxClipPlanes);
|
2011-10-21 15:17:16 -07:00
|
|
|
add_builtin_constant(instructions, symtab, "gl_MaxVaryingComponents",
|
|
|
|
|
state->Const.MaxVaryingFloats);
|
2011-08-11 17:33:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-03-10 10:43:16 -08:00
|
|
|
static void
|
|
|
|
|
generate_130_vs_variables(exec_list *instructions,
|
2012-03-09 11:38:34 -08:00
|
|
|
struct _mesa_glsl_parse_state *state,
|
|
|
|
|
bool add_deprecated)
|
2010-03-10 10:43:16 -08:00
|
|
|
{
|
2012-03-09 11:38:34 -08:00
|
|
|
generate_120_vs_variables(instructions, state, add_deprecated);
|
2010-03-10 10:43:16 -08:00
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < Elements(builtin_130_vs_variables); i++) {
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_variable(instructions, state->symbols,
|
|
|
|
|
& builtin_130_vs_variables[i]);
|
2010-03-10 10:43:16 -08:00
|
|
|
}
|
|
|
|
|
|
2011-08-11 17:33:06 -07:00
|
|
|
generate_130_uniforms(instructions, state);
|
|
|
|
|
|
2011-08-11 15:03:19 -07:00
|
|
|
/* From the GLSL 1.30 spec, section 7.1 (Vertex Shader Special
|
|
|
|
|
* Variables):
|
|
|
|
|
*
|
|
|
|
|
* The gl_ClipDistance array is predeclared as unsized and must
|
|
|
|
|
* be sized by the shader either redeclaring it with a size or
|
|
|
|
|
* indexing it only with integral constant expressions.
|
|
|
|
|
*
|
|
|
|
|
* We represent this in Mesa by initially declaring the array as
|
|
|
|
|
* size 0.
|
|
|
|
|
*/
|
2010-04-02 23:47:06 -07:00
|
|
|
const glsl_type *const clip_distance_array_type =
|
2011-08-11 15:03:19 -07:00
|
|
|
glsl_type::get_array_instance(glsl_type::float_type, 0);
|
2010-06-21 11:42:57 -07:00
|
|
|
|
2011-01-24 16:45:11 -08:00
|
|
|
add_variable(instructions, state->symbols,
|
2013-01-11 14:39:32 -08:00
|
|
|
"gl_ClipDistance", clip_distance_array_type, ir_var_shader_out,
|
2013-02-23 07:22:01 -08:00
|
|
|
VARYING_SLOT_CLIP_DIST0);
|
2010-04-02 23:47:06 -07:00
|
|
|
|
2010-03-10 10:43:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
initialize_vs_variables(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state)
|
|
|
|
|
{
|
2012-08-04 10:29:49 -07:00
|
|
|
if (state->es_shader) {
|
|
|
|
|
switch (state->language_version) {
|
|
|
|
|
case 100:
|
|
|
|
|
generate_100ES_vs_variables(instructions, state);
|
|
|
|
|
break;
|
|
|
|
|
case 300:
|
|
|
|
|
generate_300ES_vs_variables(instructions, state);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(!"Unexpected language version");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
switch (state->language_version) {
|
|
|
|
|
case 110:
|
|
|
|
|
generate_110_vs_variables(instructions, state, true);
|
|
|
|
|
break;
|
|
|
|
|
case 120:
|
|
|
|
|
generate_120_vs_variables(instructions, state, true);
|
|
|
|
|
break;
|
|
|
|
|
case 130:
|
|
|
|
|
generate_130_vs_variables(instructions, state, true);
|
|
|
|
|
break;
|
|
|
|
|
case 140:
|
2013-02-19 09:23:51 -08:00
|
|
|
case 150:
|
2012-08-04 10:29:49 -07:00
|
|
|
generate_130_vs_variables(instructions, state, false);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(!"Unexpected language version");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-03-10 10:43:16 -08:00
|
|
|
}
|
2010-12-08 18:25:38 -07:00
|
|
|
|
2012-03-09 11:38:34 -08:00
|
|
|
generate_ARB_draw_instanced_variables(instructions, state, false,
|
|
|
|
|
vertex_shader);
|
2010-03-10 10:43:16 -08:00
|
|
|
}
|
|
|
|
|
|
2010-12-08 18:25:38 -07:00
|
|
|
|
2010-08-07 02:45:33 -07:00
|
|
|
/* This function should only be called for ES, not desktop GL. */
|
|
|
|
|
static void
|
|
|
|
|
generate_100ES_fs_variables(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state)
|
|
|
|
|
{
|
|
|
|
|
for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) {
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_variable(instructions, state->symbols,
|
|
|
|
|
& builtin_core_fs_variables[i]);
|
2010-08-07 02:45:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < Elements(builtin_100ES_fs_variables); i++) {
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_variable(instructions, state->symbols,
|
|
|
|
|
& builtin_100ES_fs_variables[i]);
|
2010-08-07 02:45:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
generate_100ES_uniforms(instructions, state);
|
|
|
|
|
|
|
|
|
|
generate_ARB_draw_buffers_variables(instructions, state, false,
|
|
|
|
|
fragment_shader);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-04 10:29:49 -07:00
|
|
|
static void
|
|
|
|
|
generate_300ES_fs_variables(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state)
|
|
|
|
|
{
|
|
|
|
|
/* Note: we don't add builtin_core_fs_variables, because it contains
|
|
|
|
|
* gl_FragColor, which is not in GLSL 3.00 ES.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < Elements(builtin_300ES_fs_variables); i++) {
|
|
|
|
|
add_builtin_variable(instructions, state->symbols,
|
|
|
|
|
& builtin_300ES_fs_variables[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
generate_300ES_uniforms(instructions, state);
|
|
|
|
|
|
|
|
|
|
generate_ARB_draw_buffers_variables(instructions, state, false,
|
|
|
|
|
fragment_shader);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-25 14:48:25 -07:00
|
|
|
static void
|
|
|
|
|
generate_110_fs_variables(exec_list *instructions,
|
2012-03-09 11:38:34 -08:00
|
|
|
struct _mesa_glsl_parse_state *state,
|
|
|
|
|
bool add_deprecated)
|
2010-03-25 14:48:25 -07:00
|
|
|
{
|
|
|
|
|
for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) {
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_variable(instructions, state->symbols,
|
|
|
|
|
& builtin_core_fs_variables[i]);
|
2010-03-25 14:48:25 -07:00
|
|
|
}
|
|
|
|
|
|
2010-08-07 02:45:33 -07:00
|
|
|
for (unsigned i = 0; i < Elements(builtin_110_fs_variables); i++) {
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_variable(instructions, state->symbols,
|
|
|
|
|
& builtin_110_fs_variables[i]);
|
2010-08-07 02:45:33 -07:00
|
|
|
}
|
|
|
|
|
|
2012-03-09 11:38:34 -08:00
|
|
|
if (add_deprecated) {
|
|
|
|
|
for (unsigned i = 0
|
|
|
|
|
; i < Elements(builtin_110_deprecated_fs_variables)
|
|
|
|
|
; i++) {
|
|
|
|
|
add_builtin_variable(instructions, state->symbols,
|
|
|
|
|
& builtin_110_deprecated_fs_variables[i]);
|
|
|
|
|
}
|
2010-03-27 12:48:57 -07:00
|
|
|
}
|
2012-03-09 11:38:34 -08:00
|
|
|
|
|
|
|
|
generate_110_uniforms(instructions, state, add_deprecated);
|
2010-03-27 12:48:57 -07:00
|
|
|
|
2010-07-01 13:17:54 -07:00
|
|
|
/* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec:
|
|
|
|
|
*
|
|
|
|
|
* "As with all arrays, indices used to subscript gl_TexCoord must
|
|
|
|
|
* either be an integral constant expressions, or this array must be
|
|
|
|
|
* re-declared by the shader with a size. The size can be at most
|
|
|
|
|
* gl_MaxTextureCoords. Using indexes close to 0 may aid the
|
|
|
|
|
* implementation in preserving varying resources."
|
2010-04-02 11:59:57 -07:00
|
|
|
*/
|
|
|
|
|
const glsl_type *const vec4_array_type =
|
2010-07-20 15:33:40 -07:00
|
|
|
glsl_type::get_array_instance(glsl_type::vec4_type, 0);
|
2010-04-02 11:59:57 -07:00
|
|
|
|
2011-01-24 16:45:11 -08:00
|
|
|
add_variable(instructions, state->symbols,
|
2013-01-11 14:39:32 -08:00
|
|
|
"gl_TexCoord", vec4_array_type, ir_var_shader_in,
|
2013-02-23 09:00:58 -08:00
|
|
|
VARYING_SLOT_TEX0);
|
2010-06-29 15:10:09 -07:00
|
|
|
|
2010-06-29 15:29:56 -07:00
|
|
|
generate_ARB_draw_buffers_variables(instructions, state, false,
|
|
|
|
|
fragment_shader);
|
2010-03-25 14:48:25 -07:00
|
|
|
}
|
|
|
|
|
|
2010-04-07 16:59:46 -07:00
|
|
|
|
|
|
|
|
static void
|
2010-06-29 15:29:56 -07:00
|
|
|
generate_ARB_draw_buffers_variables(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state,
|
|
|
|
|
bool warn, _mesa_glsl_parser_targets target)
|
2010-04-07 16:59:46 -07:00
|
|
|
{
|
2010-06-29 15:29:56 -07:00
|
|
|
/* gl_MaxDrawBuffers is available in all shader stages.
|
|
|
|
|
*/
|
2010-06-29 15:19:11 -07:00
|
|
|
ir_variable *const mdb =
|
2011-10-31 14:43:27 -07:00
|
|
|
add_builtin_constant(instructions, state->symbols, "gl_MaxDrawBuffers",
|
|
|
|
|
state->Const.MaxDrawBuffers);
|
2010-06-29 15:19:11 -07:00
|
|
|
|
|
|
|
|
if (warn)
|
|
|
|
|
mdb->warn_extension = "GL_ARB_draw_buffers";
|
|
|
|
|
|
2010-06-29 15:29:56 -07:00
|
|
|
/* gl_FragData is only available in the fragment shader.
|
2012-08-04 10:29:49 -07:00
|
|
|
* It is not present in GLSL 3.00 ES.
|
2010-06-29 15:29:56 -07:00
|
|
|
*/
|
2012-08-04 10:29:49 -07:00
|
|
|
if (target == fragment_shader && !state->is_version(0, 300)) {
|
2010-06-29 15:29:56 -07:00
|
|
|
const glsl_type *const vec4_array_type =
|
2010-07-20 15:33:40 -07:00
|
|
|
glsl_type::get_array_instance(glsl_type::vec4_type,
|
2010-06-29 15:29:56 -07:00
|
|
|
state->Const.MaxDrawBuffers);
|
|
|
|
|
|
|
|
|
|
ir_variable *const fd =
|
2011-01-24 16:45:11 -08:00
|
|
|
add_variable(instructions, state->symbols,
|
|
|
|
|
"gl_FragData", vec4_array_type,
|
2013-01-11 14:39:32 -08:00
|
|
|
ir_var_shader_out, FRAG_RESULT_DATA0);
|
2010-04-07 16:59:46 -07:00
|
|
|
|
2010-06-29 15:29:56 -07:00
|
|
|
if (warn)
|
|
|
|
|
fd->warn_extension = "GL_ARB_draw_buffers";
|
|
|
|
|
}
|
2010-04-07 16:59:46 -07:00
|
|
|
}
|
|
|
|
|
|
2010-12-08 18:25:38 -07:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
generate_ARB_draw_instanced_variables(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state,
|
|
|
|
|
bool warn,
|
|
|
|
|
_mesa_glsl_parser_targets target)
|
|
|
|
|
{
|
|
|
|
|
/* gl_InstanceIDARB is only available in the vertex shader.
|
|
|
|
|
*/
|
2012-03-09 11:38:34 -08:00
|
|
|
if (target != vertex_shader)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (state->ARB_draw_instanced_enable) {
|
2012-02-29 08:29:39 -08:00
|
|
|
ir_variable *inst =
|
2011-01-24 16:45:11 -08:00
|
|
|
add_variable(instructions, state->symbols,
|
|
|
|
|
"gl_InstanceIDARB", glsl_type::int_type,
|
|
|
|
|
ir_var_system_value, SYSTEM_VALUE_INSTANCE_ID);
|
2010-12-08 18:25:38 -07:00
|
|
|
|
|
|
|
|
if (warn)
|
|
|
|
|
inst->warn_extension = "GL_ARB_draw_instanced";
|
2012-03-09 11:38:34 -08:00
|
|
|
}
|
2012-02-29 08:29:39 -08:00
|
|
|
|
2012-08-04 10:29:49 -07:00
|
|
|
bool available_in_core = state->is_version(140, 300);
|
|
|
|
|
if (state->ARB_draw_instanced_enable || available_in_core) {
|
2012-02-29 08:29:39 -08:00
|
|
|
/* Originally ARB_draw_instanced only specified that ARB decorated name.
|
|
|
|
|
* Since no vendor actually implemented that behavior and some apps use
|
|
|
|
|
* the undecorated name, the extension now specifies that both names are
|
|
|
|
|
* available.
|
|
|
|
|
*/
|
2012-03-09 11:38:34 -08:00
|
|
|
ir_variable *inst =
|
|
|
|
|
add_variable(instructions, state->symbols,
|
|
|
|
|
"gl_InstanceID", glsl_type::int_type,
|
|
|
|
|
ir_var_system_value, SYSTEM_VALUE_INSTANCE_ID);
|
2012-02-29 08:29:39 -08:00
|
|
|
|
2012-08-04 10:29:49 -07:00
|
|
|
if (!available_in_core && warn)
|
2012-02-29 08:29:39 -08:00
|
|
|
inst->warn_extension = "GL_ARB_draw_instanced";
|
2010-12-08 18:25:38 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-10-06 09:36:02 +10:00
|
|
|
static void
|
|
|
|
|
generate_ARB_shader_stencil_export_variables(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state,
|
|
|
|
|
bool warn)
|
|
|
|
|
{
|
|
|
|
|
/* gl_FragStencilRefARB is only available in the fragment shader.
|
|
|
|
|
*/
|
|
|
|
|
ir_variable *const fd =
|
2011-01-24 16:45:11 -08:00
|
|
|
add_variable(instructions, state->symbols,
|
|
|
|
|
"gl_FragStencilRefARB", glsl_type::int_type,
|
2013-01-11 14:39:32 -08:00
|
|
|
ir_var_shader_out, FRAG_RESULT_STENCIL);
|
2010-10-06 09:36:02 +10:00
|
|
|
|
|
|
|
|
if (warn)
|
|
|
|
|
fd->warn_extension = "GL_ARB_shader_stencil_export";
|
|
|
|
|
}
|
2010-04-07 16:59:46 -07:00
|
|
|
|
2011-05-02 16:41:04 +02:00
|
|
|
static void
|
|
|
|
|
generate_AMD_shader_stencil_export_variables(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state,
|
|
|
|
|
bool warn)
|
|
|
|
|
{
|
|
|
|
|
/* gl_FragStencilRefAMD is only available in the fragment shader.
|
|
|
|
|
*/
|
|
|
|
|
ir_variable *const fd =
|
|
|
|
|
add_variable(instructions, state->symbols,
|
|
|
|
|
"gl_FragStencilRefAMD", glsl_type::int_type,
|
2013-01-11 14:39:32 -08:00
|
|
|
ir_var_shader_out, FRAG_RESULT_STENCIL);
|
2011-05-02 16:41:04 +02:00
|
|
|
|
|
|
|
|
if (warn)
|
|
|
|
|
fd->warn_extension = "GL_AMD_shader_stencil_export";
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-25 14:48:25 -07:00
|
|
|
static void
|
|
|
|
|
generate_120_fs_variables(exec_list *instructions,
|
2012-03-09 11:38:34 -08:00
|
|
|
struct _mesa_glsl_parse_state *state,
|
|
|
|
|
bool add_deprecated)
|
2010-03-25 14:48:25 -07:00
|
|
|
{
|
2012-03-09 11:38:34 -08:00
|
|
|
generate_110_fs_variables(instructions, state, add_deprecated);
|
2010-07-07 19:45:22 -07:00
|
|
|
|
|
|
|
|
for (unsigned i = 0
|
|
|
|
|
; i < Elements(builtin_120_fs_variables)
|
|
|
|
|
; i++) {
|
2011-01-24 16:45:11 -08:00
|
|
|
add_builtin_variable(instructions, state->symbols,
|
|
|
|
|
& builtin_120_fs_variables[i]);
|
2010-07-07 19:45:22 -07:00
|
|
|
}
|
2010-03-25 14:48:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-03-09 11:38:34 -08:00
|
|
|
generate_fs_clipdistance(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state)
|
2010-03-25 14:48:25 -07:00
|
|
|
{
|
2011-08-11 15:03:19 -07:00
|
|
|
/* From the GLSL 1.30 spec, section 7.2 (Fragment Shader Special
|
|
|
|
|
* Variables):
|
|
|
|
|
*
|
|
|
|
|
* The built-in input variable gl_ClipDistance array contains linearly
|
|
|
|
|
* interpolated values for the vertex values written by the vertex shader
|
|
|
|
|
* to the gl_ClipDistance vertex output variable. This array must be
|
|
|
|
|
* sized in the fragment shader either implicitly or explicitly to be the
|
|
|
|
|
* same size as it was sized in the vertex shader.
|
|
|
|
|
*
|
|
|
|
|
* In other words, the array must be pre-declared as implicitly sized. We
|
|
|
|
|
* represent this in Mesa by initially declaring the array as size 0.
|
|
|
|
|
*/
|
2010-04-07 16:47:44 -07:00
|
|
|
const glsl_type *const clip_distance_array_type =
|
2011-08-11 15:03:19 -07:00
|
|
|
glsl_type::get_array_instance(glsl_type::float_type, 0);
|
2010-06-21 11:42:57 -07:00
|
|
|
|
2011-01-24 16:45:11 -08:00
|
|
|
add_variable(instructions, state->symbols,
|
2013-01-11 14:39:32 -08:00
|
|
|
"gl_ClipDistance", clip_distance_array_type, ir_var_shader_in,
|
2013-02-23 09:00:58 -08:00
|
|
|
VARYING_SLOT_CLIP_DIST0);
|
2010-03-25 14:48:25 -07:00
|
|
|
}
|
|
|
|
|
|
2012-03-09 11:38:34 -08:00
|
|
|
static void
|
|
|
|
|
generate_130_fs_variables(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state)
|
|
|
|
|
{
|
|
|
|
|
generate_120_fs_variables(instructions, state, true);
|
|
|
|
|
|
|
|
|
|
generate_130_uniforms(instructions, state);
|
|
|
|
|
generate_fs_clipdistance(instructions, state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
generate_140_fs_variables(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state)
|
|
|
|
|
{
|
|
|
|
|
generate_120_fs_variables(instructions, state, false);
|
|
|
|
|
|
|
|
|
|
generate_130_uniforms(instructions, state);
|
|
|
|
|
generate_fs_clipdistance(instructions, state);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-25 14:48:25 -07:00
|
|
|
static void
|
|
|
|
|
initialize_fs_variables(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state)
|
|
|
|
|
{
|
2012-08-04 10:29:49 -07:00
|
|
|
if (state->es_shader) {
|
|
|
|
|
switch (state->language_version) {
|
|
|
|
|
case 100:
|
|
|
|
|
generate_100ES_fs_variables(instructions, state);
|
|
|
|
|
break;
|
|
|
|
|
case 300:
|
|
|
|
|
generate_300ES_fs_variables(instructions, state);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(!"Unexpected language version");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
switch (state->language_version) {
|
|
|
|
|
case 110:
|
|
|
|
|
generate_110_fs_variables(instructions, state, true);
|
|
|
|
|
break;
|
|
|
|
|
case 120:
|
|
|
|
|
generate_120_fs_variables(instructions, state, true);
|
|
|
|
|
break;
|
|
|
|
|
case 130:
|
|
|
|
|
generate_130_fs_variables(instructions, state);
|
|
|
|
|
break;
|
|
|
|
|
case 140:
|
2013-02-19 09:23:51 -08:00
|
|
|
case 150:
|
2012-08-04 10:29:49 -07:00
|
|
|
generate_140_fs_variables(instructions, state);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(!"Unexpected language version");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-03-25 14:48:25 -07:00
|
|
|
}
|
2010-10-06 09:36:02 +10:00
|
|
|
|
|
|
|
|
if (state->ARB_shader_stencil_export_enable)
|
|
|
|
|
generate_ARB_shader_stencil_export_variables(instructions, state,
|
|
|
|
|
state->ARB_shader_stencil_export_warn);
|
2011-05-02 16:41:04 +02:00
|
|
|
|
|
|
|
|
if (state->AMD_shader_stencil_export_enable)
|
|
|
|
|
generate_AMD_shader_stencil_export_variables(instructions, state,
|
|
|
|
|
state->AMD_shader_stencil_export_warn);
|
2010-03-25 14:48:25 -07:00
|
|
|
}
|
2010-03-10 10:43:16 -08:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
_mesa_glsl_initialize_variables(exec_list *instructions,
|
|
|
|
|
struct _mesa_glsl_parse_state *state)
|
|
|
|
|
{
|
|
|
|
|
switch (state->target) {
|
|
|
|
|
case vertex_shader:
|
|
|
|
|
initialize_vs_variables(instructions, state);
|
|
|
|
|
break;
|
|
|
|
|
case geometry_shader:
|
2010-03-25 14:48:25 -07:00
|
|
|
break;
|
2010-03-10 10:43:16 -08:00
|
|
|
case fragment_shader:
|
2010-03-25 14:48:25 -07:00
|
|
|
initialize_fs_variables(instructions, state);
|
2010-03-10 10:43:16 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|