From: Ian Romanick Date: Mon, 21 Jun 2010 18:42:57 +0000 (-0700) Subject: ir_variable: Set locations for shader built-in variables X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ed0626ebc7201cab365572a1326a088c5678a054;p=mesa.git ir_variable: Set locations for shader built-in variables --- diff --git a/builtin_variables.h b/builtin_variables.h index b405b46f071..77f2fe55023 100644 --- a/builtin_variables.h +++ b/builtin_variables.h @@ -21,70 +21,73 @@ * DEALINGS IN THE SOFTWARE. */ +#include "main/mtypes.h" + struct builtin_variable { enum ir_variable_mode mode; + int slot; const char *type; const char *name; }; static const builtin_variable builtin_core_vs_variables[] = { - { ir_var_out, "vec4", "gl_Position" }, - { ir_var_out, "float", "gl_PointSize" }, + { ir_var_out, VERT_RESULT_HPOS, "vec4", "gl_Position" }, + { ir_var_out, VERT_RESULT_PSIZ, "float", "gl_PointSize" }, }; static const builtin_variable builtin_core_fs_variables[] = { - { ir_var_in, "vec4", "gl_FragCoord" }, - { ir_var_in, "bool", "gl_FrontFacing" }, - { ir_var_out, "vec4", "gl_FragColor" }, - { ir_var_out, "float", "gl_FragDepth" }, + { ir_var_in, FRAG_ATTRIB_WPOS, "vec4", "gl_FragCoord" }, + { ir_var_in, FRAG_ATTRIB_FACE, "bool", "gl_FrontFacing" }, + { ir_var_out, FRAG_RESULT_COLOR, "vec4", "gl_FragColor" }, + { ir_var_out, FRAG_RESULT_DEPTH, "float", "gl_FragDepth" }, }; static const builtin_variable builtin_110_deprecated_fs_variables[] = { - { ir_var_in, "vec4", "gl_Color" }, - { ir_var_in, "vec4", "gl_SecondaryColor" }, - { ir_var_in, "float", "gl_FogFragCoord" }, + { ir_var_in, FRAG_ATTRIB_COL0, "vec4", "gl_Color" }, + { ir_var_in, FRAG_ATTRIB_COL1, "vec4", "gl_SecondaryColor" }, + { ir_var_in, FRAG_ATTRIB_FOGC, "float", "gl_FogFragCoord" }, }; static const builtin_variable builtin_110_deprecated_vs_variables[] = { - { ir_var_in, "vec4", "gl_Vertex" }, - { ir_var_in, "vec3", "gl_Normal" }, - { ir_var_in, "vec4", "gl_Color" }, - { ir_var_in, "vec4", "gl_SecondaryColor" }, - { ir_var_in, "vec4", "gl_MultiTexCoord0" }, - { ir_var_in, "vec4", "gl_MultiTexCoord1" }, - { ir_var_in, "vec4", "gl_MultiTexCoord2" }, - { ir_var_in, "vec4", "gl_MultiTexCoord3" }, - { ir_var_in, "vec4", "gl_MultiTexCoord4" }, - { ir_var_in, "vec4", "gl_MultiTexCoord5" }, - { ir_var_in, "vec4", "gl_MultiTexCoord6" }, - { ir_var_in, "vec4", "gl_MultiTexCoord7" }, - { ir_var_in, "float", "gl_FogCoord" }, - { ir_var_out, "vec4", "gl_ClipVertex" }, - { ir_var_out, "vec4", "gl_FrontColor" }, - { ir_var_out, "vec4", "gl_BackColor" }, - { ir_var_out, "vec4", "gl_FrontSecondaryColor" }, - { ir_var_out, "vec4", "gl_BackSecondaryColor" }, - { ir_var_out, "float", "gl_FogFragCoord" }, + { ir_var_in, VERT_ATTRIB_POS, "vec4", "gl_Vertex" }, + { ir_var_in, VERT_ATTRIB_NORMAL, "vec3", "gl_Normal" }, + { ir_var_in, VERT_ATTRIB_COLOR0, "vec4", "gl_Color" }, + { ir_var_in, VERT_ATTRIB_COLOR1, "vec4", "gl_SecondaryColor" }, + { ir_var_in, VERT_ATTRIB_TEX0, "vec4", "gl_MultiTexCoord0" }, + { ir_var_in, VERT_ATTRIB_TEX1, "vec4", "gl_MultiTexCoord1" }, + { ir_var_in, VERT_ATTRIB_TEX2, "vec4", "gl_MultiTexCoord2" }, + { ir_var_in, VERT_ATTRIB_TEX3, "vec4", "gl_MultiTexCoord3" }, + { ir_var_in, VERT_ATTRIB_TEX4, "vec4", "gl_MultiTexCoord4" }, + { ir_var_in, VERT_ATTRIB_TEX5, "vec4", "gl_MultiTexCoord5" }, + { ir_var_in, VERT_ATTRIB_TEX6, "vec4", "gl_MultiTexCoord6" }, + { ir_var_in, VERT_ATTRIB_TEX7, "vec4", "gl_MultiTexCoord7" }, + { ir_var_in, VERT_ATTRIB_FOG, "float", "gl_FogCoord" }, + { ir_var_out, VERT_RESULT_HPOS, "vec4", "gl_ClipVertex" }, + { ir_var_out, VERT_RESULT_COL0, "vec4", "gl_FrontColor" }, + { ir_var_out, VERT_RESULT_BFC0, "vec4", "gl_BackColor" }, + { ir_var_out, VERT_RESULT_COL1, "vec4", "gl_FrontSecondaryColor" }, + { ir_var_out, VERT_RESULT_BFC1, "vec4", "gl_BackSecondaryColor" }, + { ir_var_out, VERT_RESULT_FOGC, "float", "gl_FogFragCoord" }, }; static const builtin_variable builtin_130_vs_variables[] = { - { ir_var_in, "int", "gl_VertexID" }, + { ir_var_in, -1, "int", "gl_VertexID" }, }; static const builtin_variable builtin_110_deprecated_uniforms[] = { - { ir_var_uniform, "mat4", "gl_ModelViewMatrix" }, - { ir_var_uniform, "mat4", "gl_ProjectionMatrix" }, - { ir_var_uniform, "mat4", "gl_ModelViewProjectionMatrix" }, - { ir_var_uniform, "mat3", "gl_NormalMatrix" }, - { ir_var_uniform, "mat4", "gl_ModelViewMatrixInverse" }, - { ir_var_uniform, "mat4", "gl_ProjectionMatrixInverse" }, - { ir_var_uniform, "mat4", "gl_ModelViewProjectionMatrixInverse" }, - { ir_var_uniform, "mat4", "gl_ModelViewMatrixTranspose" }, - { ir_var_uniform, "mat4", "gl_ProjectionMatrixTranspose" }, - { ir_var_uniform, "mat4", "gl_ModelViewProjectionMatrixTranspose" }, - { ir_var_uniform, "mat4", "gl_ModelViewMatrixInverseTranspose" }, - { ir_var_uniform, "mat4", "gl_ProjectionMatrixInverseTranspose" }, - { ir_var_uniform, "mat4", "gl_ModelViewProjectionMatrixInverseTranspose" }, - { ir_var_uniform, "float", "gl_NormalScale" }, + { 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" }, }; diff --git a/ir_variable.cpp b/ir_variable.cpp index 49d8e3dcfb5..efebe9199fa 100644 --- a/ir_variable.cpp +++ b/ir_variable.cpp @@ -31,7 +31,7 @@ #endif static ir_variable * -add_variable(const char *name, enum ir_variable_mode mode, +add_variable(const char *name, enum ir_variable_mode mode, int slot, const glsl_type *type, exec_list *instructions, glsl_symbol_table *symtab) { @@ -59,6 +59,8 @@ add_variable(const char *name, enum ir_variable_mode mode, break; } + var->location = slot; + /* Once the variable is created an initialized, add it to the symbol table * and add the declaration to the IR stream. */ @@ -80,7 +82,8 @@ add_builtin_variable(const builtin_variable *proto, exec_list *instructions, assert(type != NULL); - add_variable(proto->name, proto->mode, type, instructions, symtab); + add_variable(proto->name, proto->mode, proto->slot, type, instructions, + symtab); } @@ -103,7 +106,7 @@ generate_110_uniforms(exec_list *instructions, const glsl_type *const mat4_array_type = glsl_type::get_array_instance(glsl_type::mat4_type, 4); - add_variable("gl_TextureMatrix", ir_var_uniform, mat4_array_type, + add_variable("gl_TextureMatrix", ir_var_uniform, -1, mat4_array_type, instructions, symtab); /* FINISHME: Add support for gl_DepthRangeParameters */ @@ -121,7 +124,7 @@ generate_110_uniforms(exec_list *instructions, const glsl_type *const light_source_array_type = glsl_type::get_array_instance(symtab->get_type("gl_LightSourceParameters"), 8); - add_variable("gl_LightSource", ir_var_uniform, light_source_array_type, + add_variable("gl_LightSource", ir_var_uniform, -1, light_source_array_type, instructions, symtab); /* FINISHME: Add support for gl_LightModel */ @@ -156,8 +159,8 @@ generate_110_vs_variables(exec_list *instructions, const glsl_type *const vec4_array_type = glsl_type::get_array_instance(glsl_type::vec4_type, 4); - add_variable("gl_TexCoord", ir_var_out, vec4_array_type, instructions, - symtab); + add_variable("gl_TexCoord", ir_var_out, VERT_RESULT_TEX0, vec4_array_type, + instructions, symtab); } @@ -188,7 +191,9 @@ generate_130_vs_variables(exec_list *instructions, */ const glsl_type *const clip_distance_array_type = glsl_type::get_array_instance(glsl_type::float_type, 8); - add_variable("gl_ClipDistance", ir_var_out, clip_distance_array_type, + + /* FINISHME: gl_ClipDistance needs a real location assigned. */ + add_variable("gl_ClipDistance", ir_var_out, -1, clip_distance_array_type, instructions, symtab); } @@ -237,8 +242,8 @@ generate_110_fs_variables(exec_list *instructions, const glsl_type *const vec4_array_type = glsl_type::get_array_instance(glsl_type::vec4_type, 4); - add_variable("gl_TexCoord", ir_var_in, vec4_array_type, instructions, - symtab); + add_variable("gl_TexCoord", ir_var_in, FRAG_ATTRIB_TEX0, vec4_array_type, + instructions, symtab); } @@ -254,8 +259,8 @@ generate_ARB_draw_buffers_fs_variables(exec_list *instructions, glsl_type::get_array_instance(glsl_type::vec4_type, 1); ir_variable *const fd = - add_variable("gl_FragData", ir_var_out, vec4_array_type, instructions, - symtab); + add_variable("gl_FragData", ir_var_out, FRAG_RESULT_DATA0, + vec4_array_type, instructions, symtab); if (warn) fd->warn_extension = "GL_ARB_draw_buffers"; @@ -281,7 +286,9 @@ generate_130_fs_variables(exec_list *instructions, */ const glsl_type *const clip_distance_array_type = glsl_type::get_array_instance(glsl_type::float_type, 8); - add_variable("gl_ClipDistance", ir_var_in, clip_distance_array_type, + + /* FINISHME: gl_ClipDistance needs a real location assigned. */ + add_variable("gl_ClipDistance", ir_var_in, -1, clip_distance_array_type, instructions, symtab); }