Path: blob/21.2-virgl/src/compiler/glsl/builtin_variables.cpp
4547 views
/*1* Copyright © 2010 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER20* DEALINGS IN THE SOFTWARE.21*/222324/**25* Building this file with MinGW g++ 7.3 or 7.4 with:26* scons platform=windows toolchain=crossmingw machine=x86 build=profile27* triggers an internal compiler error.28* Overriding the optimization level to -O1 works around the issue.29* MinGW 5.3.1 does not seem to have the bug, neither does 8.3. So for now30* we're simply testing for version 7.x here.31*/32#if defined(__MINGW32__) && __GNUC__ == 733#warning "disabling optimizations for this file to work around compiler bug in MinGW gcc 7.x"34#pragma GCC optimize("O1")35#endif363738#include "ir.h"39#include "ir_builder.h"40#include "linker.h"41#include "glsl_parser_extras.h"42#include "glsl_symbol_table.h"43#include "main/mtypes.h"44#include "main/uniforms.h"45#include "program/prog_statevars.h"46#include "program/prog_instruction.h"47#include "builtin_functions.h"4849using namespace ir_builder;5051static const struct gl_builtin_uniform_element gl_NumSamples_elements[] = {52{NULL, {STATE_NUM_SAMPLES, 0, 0}, SWIZZLE_XXXX}53};5455static const struct gl_builtin_uniform_element gl_DepthRange_elements[] = {56{"near", {STATE_DEPTH_RANGE, 0, 0}, SWIZZLE_XXXX},57{"far", {STATE_DEPTH_RANGE, 0, 0}, SWIZZLE_YYYY},58{"diff", {STATE_DEPTH_RANGE, 0, 0}, SWIZZLE_ZZZZ},59};6061static const struct gl_builtin_uniform_element gl_ClipPlane_elements[] = {62{NULL, {STATE_CLIPPLANE, 0, 0}, SWIZZLE_XYZW}63};6465static const struct gl_builtin_uniform_element gl_Point_elements[] = {66{"size", {STATE_POINT_SIZE}, SWIZZLE_XXXX},67{"sizeMin", {STATE_POINT_SIZE}, SWIZZLE_YYYY},68{"sizeMax", {STATE_POINT_SIZE}, SWIZZLE_ZZZZ},69{"fadeThresholdSize", {STATE_POINT_SIZE}, SWIZZLE_WWWW},70{"distanceConstantAttenuation", {STATE_POINT_ATTENUATION}, SWIZZLE_XXXX},71{"distanceLinearAttenuation", {STATE_POINT_ATTENUATION}, SWIZZLE_YYYY},72{"distanceQuadraticAttenuation", {STATE_POINT_ATTENUATION}, SWIZZLE_ZZZZ},73};7475static const struct gl_builtin_uniform_element gl_FrontMaterial_elements[] = {76{"emission", {STATE_MATERIAL, MAT_ATTRIB_FRONT_EMISSION}, SWIZZLE_XYZW},77{"ambient", {STATE_MATERIAL, MAT_ATTRIB_FRONT_AMBIENT}, SWIZZLE_XYZW},78{"diffuse", {STATE_MATERIAL, MAT_ATTRIB_FRONT_DIFFUSE}, SWIZZLE_XYZW},79{"specular", {STATE_MATERIAL, MAT_ATTRIB_FRONT_SPECULAR}, SWIZZLE_XYZW},80{"shininess", {STATE_MATERIAL, MAT_ATTRIB_FRONT_SHININESS}, SWIZZLE_XXXX},81};8283static const struct gl_builtin_uniform_element gl_BackMaterial_elements[] = {84{"emission", {STATE_MATERIAL, MAT_ATTRIB_BACK_EMISSION}, SWIZZLE_XYZW},85{"ambient", {STATE_MATERIAL, MAT_ATTRIB_BACK_AMBIENT}, SWIZZLE_XYZW},86{"diffuse", {STATE_MATERIAL, MAT_ATTRIB_BACK_DIFFUSE}, SWIZZLE_XYZW},87{"specular", {STATE_MATERIAL, MAT_ATTRIB_BACK_SPECULAR}, SWIZZLE_XYZW},88{"shininess", {STATE_MATERIAL, MAT_ATTRIB_BACK_SHININESS}, SWIZZLE_XXXX},89};9091static const struct gl_builtin_uniform_element gl_LightSource_elements[] = {92{"ambient", {STATE_LIGHT, 0, STATE_AMBIENT}, SWIZZLE_XYZW},93{"diffuse", {STATE_LIGHT, 0, STATE_DIFFUSE}, SWIZZLE_XYZW},94{"specular", {STATE_LIGHT, 0, STATE_SPECULAR}, SWIZZLE_XYZW},95{"position", {STATE_LIGHT, 0, STATE_POSITION}, SWIZZLE_XYZW},96{"halfVector", {STATE_LIGHT, 0, STATE_HALF_VECTOR}, SWIZZLE_XYZW},97{"spotDirection", {STATE_LIGHT, 0, STATE_SPOT_DIRECTION},98MAKE_SWIZZLE4(SWIZZLE_X,99SWIZZLE_Y,100SWIZZLE_Z,101SWIZZLE_Z)},102{"spotCosCutoff", {STATE_LIGHT, 0, STATE_SPOT_DIRECTION}, SWIZZLE_WWWW},103{"constantAttenuation", {STATE_LIGHT, 0, STATE_ATTENUATION}, SWIZZLE_XXXX},104{"linearAttenuation", {STATE_LIGHT, 0, STATE_ATTENUATION}, SWIZZLE_YYYY},105{"quadraticAttenuation", {STATE_LIGHT, 0, STATE_ATTENUATION}, SWIZZLE_ZZZZ},106{"spotExponent", {STATE_LIGHT, 0, STATE_ATTENUATION}, SWIZZLE_WWWW},107{"spotCutoff", {STATE_LIGHT, 0, STATE_SPOT_CUTOFF}, SWIZZLE_XXXX},108};109110static const struct gl_builtin_uniform_element gl_LightModel_elements[] = {111{"ambient", {STATE_LIGHTMODEL_AMBIENT, 0}, SWIZZLE_XYZW},112};113114static const struct gl_builtin_uniform_element gl_FrontLightModelProduct_elements[] = {115{"sceneColor", {STATE_LIGHTMODEL_SCENECOLOR, 0}, SWIZZLE_XYZW},116};117118static const struct gl_builtin_uniform_element gl_BackLightModelProduct_elements[] = {119{"sceneColor", {STATE_LIGHTMODEL_SCENECOLOR, 1}, SWIZZLE_XYZW},120};121122static const struct gl_builtin_uniform_element gl_FrontLightProduct_elements[] = {123{"ambient", {STATE_LIGHTPROD, 0, MAT_ATTRIB_FRONT_AMBIENT}, SWIZZLE_XYZW},124{"diffuse", {STATE_LIGHTPROD, 0, MAT_ATTRIB_FRONT_DIFFUSE}, SWIZZLE_XYZW},125{"specular", {STATE_LIGHTPROD, 0, MAT_ATTRIB_FRONT_SPECULAR}, SWIZZLE_XYZW},126};127128static const struct gl_builtin_uniform_element gl_BackLightProduct_elements[] = {129{"ambient", {STATE_LIGHTPROD, 0, MAT_ATTRIB_BACK_AMBIENT}, SWIZZLE_XYZW},130{"diffuse", {STATE_LIGHTPROD, 0, MAT_ATTRIB_BACK_DIFFUSE}, SWIZZLE_XYZW},131{"specular", {STATE_LIGHTPROD, 0, MAT_ATTRIB_BACK_SPECULAR}, SWIZZLE_XYZW},132};133134static const struct gl_builtin_uniform_element gl_TextureEnvColor_elements[] = {135{NULL, {STATE_TEXENV_COLOR, 0}, SWIZZLE_XYZW},136};137138static const struct gl_builtin_uniform_element gl_EyePlaneS_elements[] = {139{NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_EYE_S}, SWIZZLE_XYZW},140};141142static const struct gl_builtin_uniform_element gl_EyePlaneT_elements[] = {143{NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_EYE_T}, SWIZZLE_XYZW},144};145146static const struct gl_builtin_uniform_element gl_EyePlaneR_elements[] = {147{NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_EYE_R}, SWIZZLE_XYZW},148};149150static const struct gl_builtin_uniform_element gl_EyePlaneQ_elements[] = {151{NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_EYE_Q}, SWIZZLE_XYZW},152};153154static const struct gl_builtin_uniform_element gl_ObjectPlaneS_elements[] = {155{NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_OBJECT_S}, SWIZZLE_XYZW},156};157158static const struct gl_builtin_uniform_element gl_ObjectPlaneT_elements[] = {159{NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_OBJECT_T}, SWIZZLE_XYZW},160};161162static const struct gl_builtin_uniform_element gl_ObjectPlaneR_elements[] = {163{NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_OBJECT_R}, SWIZZLE_XYZW},164};165166static const struct gl_builtin_uniform_element gl_ObjectPlaneQ_elements[] = {167{NULL, {STATE_TEXGEN, 0, STATE_TEXGEN_OBJECT_Q}, SWIZZLE_XYZW},168};169170static const struct gl_builtin_uniform_element gl_Fog_elements[] = {171{"color", {STATE_FOG_COLOR}, SWIZZLE_XYZW},172{"density", {STATE_FOG_PARAMS}, SWIZZLE_XXXX},173{"start", {STATE_FOG_PARAMS}, SWIZZLE_YYYY},174{"end", {STATE_FOG_PARAMS}, SWIZZLE_ZZZZ},175{"scale", {STATE_FOG_PARAMS}, SWIZZLE_WWWW},176};177178static const struct gl_builtin_uniform_element gl_NormalScale_elements[] = {179{NULL, {STATE_NORMAL_SCALE_EYESPACE}, SWIZZLE_XXXX},180};181182static const struct gl_builtin_uniform_element gl_FogParamsOptimizedMESA_elements[] = {183{NULL, {STATE_FOG_PARAMS_OPTIMIZED}, SWIZZLE_XYZW},184};185186#define ATTRIB(i) \187static const struct gl_builtin_uniform_element gl_CurrentAttribFrag##i##MESA_elements[] = { \188{NULL, {STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED, i}, SWIZZLE_XYZW}, \189};190191ATTRIB(0)192ATTRIB(1)193ATTRIB(2)194ATTRIB(3)195ATTRIB(4)196ATTRIB(5)197ATTRIB(6)198ATTRIB(7)199ATTRIB(8)200ATTRIB(9)201ATTRIB(10)202ATTRIB(11)203ATTRIB(12)204ATTRIB(13)205ATTRIB(14)206ATTRIB(15)207ATTRIB(16)208ATTRIB(17)209ATTRIB(18)210ATTRIB(19)211ATTRIB(20)212ATTRIB(21)213ATTRIB(22)214ATTRIB(23)215ATTRIB(24)216ATTRIB(25)217ATTRIB(26)218ATTRIB(27)219ATTRIB(28)220ATTRIB(29)221ATTRIB(30)222ATTRIB(31)223224#define MATRIX(name, statevar) \225static const struct gl_builtin_uniform_element name ## _elements[] = { \226{ NULL, { statevar, 0, 0, 0}, SWIZZLE_XYZW }, \227{ NULL, { statevar, 0, 1, 1}, SWIZZLE_XYZW }, \228{ NULL, { statevar, 0, 2, 2}, SWIZZLE_XYZW }, \229{ NULL, { statevar, 0, 3, 3}, SWIZZLE_XYZW }, \230}231232MATRIX(gl_ModelViewMatrix, STATE_MODELVIEW_MATRIX_TRANSPOSE);233MATRIX(gl_ModelViewMatrixInverse, STATE_MODELVIEW_MATRIX_INVTRANS);234MATRIX(gl_ModelViewMatrixTranspose, STATE_MODELVIEW_MATRIX);235MATRIX(gl_ModelViewMatrixInverseTranspose, STATE_MODELVIEW_MATRIX_INVERSE);236237MATRIX(gl_ProjectionMatrix, STATE_PROJECTION_MATRIX_TRANSPOSE);238MATRIX(gl_ProjectionMatrixInverse, STATE_PROJECTION_MATRIX_INVTRANS);239MATRIX(gl_ProjectionMatrixTranspose, STATE_PROJECTION_MATRIX);240MATRIX(gl_ProjectionMatrixInverseTranspose, STATE_PROJECTION_MATRIX_INVERSE);241242MATRIX(gl_ModelViewProjectionMatrix, STATE_MVP_MATRIX_TRANSPOSE);243MATRIX(gl_ModelViewProjectionMatrixInverse, STATE_MVP_MATRIX_INVTRANS);244MATRIX(gl_ModelViewProjectionMatrixTranspose, STATE_MVP_MATRIX);245MATRIX(gl_ModelViewProjectionMatrixInverseTranspose, STATE_MVP_MATRIX_INVERSE);246247MATRIX(gl_TextureMatrix, STATE_TEXTURE_MATRIX_TRANSPOSE);248MATRIX(gl_TextureMatrixInverse, STATE_TEXTURE_MATRIX_INVTRANS);249MATRIX(gl_TextureMatrixTranspose, STATE_TEXTURE_MATRIX);250MATRIX(gl_TextureMatrixInverseTranspose, STATE_TEXTURE_MATRIX_INVERSE);251252static const struct gl_builtin_uniform_element gl_NormalMatrix_elements[] = {253{ NULL, { STATE_MODELVIEW_MATRIX_INVERSE, 0, 0, 0},254MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_Z) },255{ NULL, { STATE_MODELVIEW_MATRIX_INVERSE, 0, 1, 1},256MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_Z) },257{ NULL, { STATE_MODELVIEW_MATRIX_INVERSE, 0, 2, 2},258MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_Z) },259};260261#undef MATRIX262263#define STATEVAR(name) {#name, name ## _elements, ARRAY_SIZE(name ## _elements)}264265static const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[] = {266STATEVAR(gl_NumSamples),267STATEVAR(gl_DepthRange),268STATEVAR(gl_ClipPlane),269STATEVAR(gl_Point),270STATEVAR(gl_FrontMaterial),271STATEVAR(gl_BackMaterial),272STATEVAR(gl_LightSource),273STATEVAR(gl_LightModel),274STATEVAR(gl_FrontLightModelProduct),275STATEVAR(gl_BackLightModelProduct),276STATEVAR(gl_FrontLightProduct),277STATEVAR(gl_BackLightProduct),278STATEVAR(gl_TextureEnvColor),279STATEVAR(gl_EyePlaneS),280STATEVAR(gl_EyePlaneT),281STATEVAR(gl_EyePlaneR),282STATEVAR(gl_EyePlaneQ),283STATEVAR(gl_ObjectPlaneS),284STATEVAR(gl_ObjectPlaneT),285STATEVAR(gl_ObjectPlaneR),286STATEVAR(gl_ObjectPlaneQ),287STATEVAR(gl_Fog),288289STATEVAR(gl_ModelViewMatrix),290STATEVAR(gl_ModelViewMatrixInverse),291STATEVAR(gl_ModelViewMatrixTranspose),292STATEVAR(gl_ModelViewMatrixInverseTranspose),293294STATEVAR(gl_ProjectionMatrix),295STATEVAR(gl_ProjectionMatrixInverse),296STATEVAR(gl_ProjectionMatrixTranspose),297STATEVAR(gl_ProjectionMatrixInverseTranspose),298299STATEVAR(gl_ModelViewProjectionMatrix),300STATEVAR(gl_ModelViewProjectionMatrixInverse),301STATEVAR(gl_ModelViewProjectionMatrixTranspose),302STATEVAR(gl_ModelViewProjectionMatrixInverseTranspose),303304STATEVAR(gl_TextureMatrix),305STATEVAR(gl_TextureMatrixInverse),306STATEVAR(gl_TextureMatrixTranspose),307STATEVAR(gl_TextureMatrixInverseTranspose),308309STATEVAR(gl_NormalMatrix),310STATEVAR(gl_NormalScale),311312STATEVAR(gl_FogParamsOptimizedMESA),313314STATEVAR(gl_CurrentAttribFrag0MESA),315STATEVAR(gl_CurrentAttribFrag1MESA),316STATEVAR(gl_CurrentAttribFrag2MESA),317STATEVAR(gl_CurrentAttribFrag3MESA),318STATEVAR(gl_CurrentAttribFrag4MESA),319STATEVAR(gl_CurrentAttribFrag5MESA),320STATEVAR(gl_CurrentAttribFrag6MESA),321STATEVAR(gl_CurrentAttribFrag7MESA),322STATEVAR(gl_CurrentAttribFrag8MESA),323STATEVAR(gl_CurrentAttribFrag9MESA),324STATEVAR(gl_CurrentAttribFrag10MESA),325STATEVAR(gl_CurrentAttribFrag11MESA),326STATEVAR(gl_CurrentAttribFrag12MESA),327STATEVAR(gl_CurrentAttribFrag13MESA),328STATEVAR(gl_CurrentAttribFrag14MESA),329STATEVAR(gl_CurrentAttribFrag15MESA),330STATEVAR(gl_CurrentAttribFrag16MESA),331STATEVAR(gl_CurrentAttribFrag17MESA),332STATEVAR(gl_CurrentAttribFrag18MESA),333STATEVAR(gl_CurrentAttribFrag19MESA),334STATEVAR(gl_CurrentAttribFrag20MESA),335STATEVAR(gl_CurrentAttribFrag21MESA),336STATEVAR(gl_CurrentAttribFrag22MESA),337STATEVAR(gl_CurrentAttribFrag23MESA),338STATEVAR(gl_CurrentAttribFrag24MESA),339STATEVAR(gl_CurrentAttribFrag25MESA),340STATEVAR(gl_CurrentAttribFrag26MESA),341STATEVAR(gl_CurrentAttribFrag27MESA),342STATEVAR(gl_CurrentAttribFrag28MESA),343STATEVAR(gl_CurrentAttribFrag29MESA),344STATEVAR(gl_CurrentAttribFrag30MESA),345STATEVAR(gl_CurrentAttribFrag31MESA),346347{NULL, NULL, 0}348};349350351namespace {352353/**354* Data structure that accumulates fields for the gl_PerVertex interface355* block.356*/357class per_vertex_accumulator358{359public:360per_vertex_accumulator();361void add_field(int slot, const glsl_type *type, int precision,362const char *name, enum glsl_interp_mode interp);363const glsl_type *construct_interface_instance() const;364365private:366glsl_struct_field fields[14];367unsigned num_fields;368};369370371per_vertex_accumulator::per_vertex_accumulator()372: fields(),373num_fields(0)374{375}376377378void379per_vertex_accumulator::add_field(int slot, const glsl_type *type,380int precision, const char *name,381enum glsl_interp_mode interp)382{383assert(this->num_fields < ARRAY_SIZE(this->fields));384this->fields[this->num_fields].type = type;385this->fields[this->num_fields].name = name;386this->fields[this->num_fields].matrix_layout = GLSL_MATRIX_LAYOUT_INHERITED;387this->fields[this->num_fields].location = slot;388this->fields[this->num_fields].offset = -1;389this->fields[this->num_fields].interpolation = interp;390this->fields[this->num_fields].centroid = 0;391this->fields[this->num_fields].sample = 0;392this->fields[this->num_fields].patch = 0;393this->fields[this->num_fields].precision = precision;394this->fields[this->num_fields].memory_read_only = 0;395this->fields[this->num_fields].memory_write_only = 0;396this->fields[this->num_fields].memory_coherent = 0;397this->fields[this->num_fields].memory_volatile = 0;398this->fields[this->num_fields].memory_restrict = 0;399this->fields[this->num_fields].image_format = PIPE_FORMAT_NONE;400this->fields[this->num_fields].explicit_xfb_buffer = 0;401this->fields[this->num_fields].xfb_buffer = -1;402this->fields[this->num_fields].xfb_stride = -1;403this->num_fields++;404}405406407const glsl_type *408per_vertex_accumulator::construct_interface_instance() const409{410return glsl_type::get_interface_instance(this->fields, this->num_fields,411GLSL_INTERFACE_PACKING_STD140,412false,413"gl_PerVertex");414}415416417class builtin_variable_generator418{419public:420builtin_variable_generator(exec_list *instructions,421struct _mesa_glsl_parse_state *state);422void generate_constants();423void generate_uniforms();424void generate_special_vars();425void generate_vs_special_vars();426void generate_tcs_special_vars();427void generate_tes_special_vars();428void generate_gs_special_vars();429void generate_fs_special_vars();430void generate_cs_special_vars();431void generate_varyings();432433private:434const glsl_type *array(const glsl_type *base, unsigned elements)435{436return glsl_type::get_array_instance(base, elements);437}438439const glsl_type *type(const char *name)440{441return symtab->get_type(name);442}443444ir_variable *add_input(int slot, const glsl_type *type, int precision,445const char *name,446enum glsl_interp_mode interp = INTERP_MODE_NONE)447{448return add_variable(name, type, precision, ir_var_shader_in, slot, interp);449}450451ir_variable *add_input(int slot, const glsl_type *type, const char *name,452enum glsl_interp_mode interp = INTERP_MODE_NONE)453{454return add_input(slot, type, GLSL_PRECISION_NONE, name, interp);455}456457ir_variable *add_output(int slot, const glsl_type *type, int precision,458const char *name)459{460return add_variable(name, type, precision, ir_var_shader_out, slot);461}462463ir_variable *add_output(int slot, const glsl_type *type, const char *name)464{465return add_output(slot, type, GLSL_PRECISION_NONE, name);466}467468ir_variable *add_index_output(int slot, int index, const glsl_type *type,469int precision, const char *name)470{471return add_index_variable(name, type, precision, ir_var_shader_out, slot,472index);473}474475ir_variable *add_system_value(int slot, const glsl_type *type, int precision,476const char *name)477{478return add_variable(name, type, precision, ir_var_system_value, slot);479}480ir_variable *add_system_value(int slot, const glsl_type *type,481const char *name)482{483return add_system_value(slot, type, GLSL_PRECISION_NONE, name);484}485486ir_variable *add_variable(const char *name, const glsl_type *type,487int precision, enum ir_variable_mode mode,488int slot, enum glsl_interp_mode interp = INTERP_MODE_NONE);489ir_variable *add_index_variable(const char *name, const glsl_type *type,490int precision, enum ir_variable_mode mode,491int slot, int index);492ir_variable *add_uniform(const glsl_type *type, int precision,493const char *name);494ir_variable *add_uniform(const glsl_type *type, const char *name)495{496return add_uniform(type, GLSL_PRECISION_NONE, name);497}498ir_variable *add_const(const char *name, int precision, int value);499ir_variable *add_const(const char *name, int value)500{501return add_const(name, GLSL_PRECISION_MEDIUM, value);502}503ir_variable *add_const_ivec3(const char *name, int x, int y, int z);504void add_varying(int slot, const glsl_type *type, int precision,505const char *name,506enum glsl_interp_mode interp = INTERP_MODE_NONE);507void add_varying(int slot, const glsl_type *type, const char *name,508enum glsl_interp_mode interp = INTERP_MODE_NONE)509{510add_varying(slot, type, GLSL_PRECISION_NONE, name, interp);511}512513exec_list * const instructions;514struct _mesa_glsl_parse_state * const state;515glsl_symbol_table * const symtab;516517/**518* True if compatibility-profile-only variables should be included. (In519* desktop GL, these are always included when the GLSL version is 1.30 and520* or below).521*/522const bool compatibility;523524const glsl_type * const bool_t;525const glsl_type * const int_t;526const glsl_type * const uint_t;527const glsl_type * const uint64_t;528const glsl_type * const float_t;529const glsl_type * const vec2_t;530const glsl_type * const vec3_t;531const glsl_type * const vec4_t;532const glsl_type * const uvec3_t;533const glsl_type * const mat3_t;534const glsl_type * const mat4_t;535536per_vertex_accumulator per_vertex_in;537per_vertex_accumulator per_vertex_out;538};539540541builtin_variable_generator::builtin_variable_generator(542exec_list *instructions, struct _mesa_glsl_parse_state *state)543: instructions(instructions), state(state), symtab(state->symbols),544compatibility(state->compat_shader || state->ARB_compatibility_enable),545bool_t(glsl_type::bool_type), int_t(glsl_type::int_type),546uint_t(glsl_type::uint_type),547uint64_t(glsl_type::uint64_t_type),548float_t(glsl_type::float_type), vec2_t(glsl_type::vec2_type),549vec3_t(glsl_type::vec3_type), vec4_t(glsl_type::vec4_type),550uvec3_t(glsl_type::uvec3_type),551mat3_t(glsl_type::mat3_type), mat4_t(glsl_type::mat4_type)552{553}554555ir_variable *556builtin_variable_generator::add_index_variable(const char *name,557const glsl_type *type,558int precision,559enum ir_variable_mode mode,560int slot, int index)561{562ir_variable *var = new(symtab) ir_variable(type, name, mode);563var->data.how_declared = ir_var_declared_implicitly;564565switch (var->data.mode) {566case ir_var_auto:567case ir_var_shader_in:568case ir_var_uniform:569case ir_var_system_value:570var->data.read_only = true;571break;572case ir_var_shader_out:573case ir_var_shader_storage:574break;575default:576/* The only variables that are added using this function should be577* uniforms, shader storage, shader inputs, and shader outputs, constants578* (which use ir_var_auto), and system values.579*/580assert(0);581break;582}583584var->data.location = slot;585var->data.explicit_location = (slot >= 0);586var->data.explicit_index = 1;587var->data.index = index;588589if (state->es_shader)590var->data.precision = precision;591592/* Once the variable is created an initialized, add it to the symbol table593* and add the declaration to the IR stream.594*/595instructions->push_tail(var);596597symtab->add_variable(var);598return var;599}600601ir_variable *602builtin_variable_generator::add_variable(const char *name,603const glsl_type *type,604int precision,605enum ir_variable_mode mode, int slot,606enum glsl_interp_mode interp)607{608ir_variable *var = new(symtab) ir_variable(type, name, mode);609var->data.how_declared = ir_var_declared_implicitly;610611switch (var->data.mode) {612case ir_var_auto:613case ir_var_shader_in:614case ir_var_uniform:615case ir_var_system_value:616var->data.read_only = true;617break;618case ir_var_shader_out:619case ir_var_shader_storage:620break;621default:622/* The only variables that are added using this function should be623* uniforms, shader storage, shader inputs, and shader outputs, constants624* (which use ir_var_auto), and system values.625*/626assert(0);627break;628}629630var->data.location = slot;631var->data.explicit_location = (slot >= 0);632var->data.explicit_index = 0;633var->data.interpolation = interp;634635if (state->es_shader)636var->data.precision = precision;637638/* Once the variable is created an initialized, add it to the symbol table639* and add the declaration to the IR stream.640*/641instructions->push_tail(var);642643symtab->add_variable(var);644return var;645}646647extern "C" const struct gl_builtin_uniform_desc *648_mesa_glsl_get_builtin_uniform_desc(const char *name)649{650for (unsigned i = 0; _mesa_builtin_uniform_desc[i].name != NULL; i++) {651if (strcmp(_mesa_builtin_uniform_desc[i].name, name) == 0) {652return &_mesa_builtin_uniform_desc[i];653}654}655return NULL;656}657658ir_variable *659builtin_variable_generator::add_uniform(const glsl_type *type,660int precision,661const char *name)662{663ir_variable *const uni =664add_variable(name, type, precision, ir_var_uniform, -1);665666const struct gl_builtin_uniform_desc* const statevar =667_mesa_glsl_get_builtin_uniform_desc(name);668assert(statevar != NULL);669670const unsigned array_count = type->is_array() ? type->length : 1;671672ir_state_slot *slots =673uni->allocate_state_slots(array_count * statevar->num_elements);674675for (unsigned a = 0; a < array_count; a++) {676for (unsigned j = 0; j < statevar->num_elements; j++) {677const struct gl_builtin_uniform_element *element =678&statevar->elements[j];679680memcpy(slots->tokens, element->tokens, sizeof(element->tokens));681if (type->is_array())682slots->tokens[1] = a;683684slots->swizzle = element->swizzle;685slots++;686}687}688689return uni;690}691692693ir_variable *694builtin_variable_generator::add_const(const char *name, int precision,695int value)696{697ir_variable *const var = add_variable(name, glsl_type::int_type,698precision, ir_var_auto, -1);699var->constant_value = new(var) ir_constant(value);700var->constant_initializer = new(var) ir_constant(value);701var->data.has_initializer = true;702return var;703}704705706ir_variable *707builtin_variable_generator::add_const_ivec3(const char *name, int x, int y,708int z)709{710ir_variable *const var = add_variable(name, glsl_type::ivec3_type,711GLSL_PRECISION_HIGH,712ir_var_auto, -1);713ir_constant_data data;714memset(&data, 0, sizeof(data));715data.i[0] = x;716data.i[1] = y;717data.i[2] = z;718var->constant_value = new(var) ir_constant(glsl_type::ivec3_type, &data);719var->constant_initializer =720new(var) ir_constant(glsl_type::ivec3_type, &data);721var->data.has_initializer = true;722return var;723}724725726void727builtin_variable_generator::generate_constants()728{729add_const("gl_MaxVertexAttribs", state->Const.MaxVertexAttribs);730add_const("gl_MaxVertexTextureImageUnits",731state->Const.MaxVertexTextureImageUnits);732add_const("gl_MaxCombinedTextureImageUnits",733state->Const.MaxCombinedTextureImageUnits);734add_const("gl_MaxTextureImageUnits", state->Const.MaxTextureImageUnits);735add_const("gl_MaxDrawBuffers", state->Const.MaxDrawBuffers);736737/* Max uniforms/varyings: GLSL ES counts these in units of vectors; desktop738* GL counts them in units of "components" or "floats" and also in units739* of vectors since GL 4.1740*/741if (!state->es_shader) {742add_const("gl_MaxFragmentUniformComponents",743state->Const.MaxFragmentUniformComponents);744add_const("gl_MaxVertexUniformComponents",745state->Const.MaxVertexUniformComponents);746}747748if (state->is_version(410, 100)) {749add_const("gl_MaxVertexUniformVectors",750state->Const.MaxVertexUniformComponents / 4);751add_const("gl_MaxFragmentUniformVectors",752state->Const.MaxFragmentUniformComponents / 4);753754/* In GLSL ES 3.00, gl_MaxVaryingVectors was split out to separate755* vertex and fragment shader constants.756*/757if (state->is_version(0, 300)) {758add_const("gl_MaxVertexOutputVectors",759state->ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents / 4);760add_const("gl_MaxFragmentInputVectors",761state->ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents / 4);762} else {763add_const("gl_MaxVaryingVectors",764state->ctx->Const.MaxVarying);765}766767/* EXT_blend_func_extended brings a built in constant768* for determining number of dual source draw buffers769*/770if (state->EXT_blend_func_extended_enable) {771add_const("gl_MaxDualSourceDrawBuffersEXT",772state->Const.MaxDualSourceDrawBuffers);773}774}775776/* gl_MaxVaryingFloats was deprecated in GLSL 1.30+, and was moved to777* compat profile in GLSL 4.20. GLSL ES never supported this constant.778*/779if (compatibility || !state->is_version(420, 100)) {780add_const("gl_MaxVaryingFloats", state->ctx->Const.MaxVarying * 4);781}782783/* Texel offsets were introduced in ARB_shading_language_420pack (which784* requires desktop GLSL version 130), and adopted into desktop GLSL785* version 4.20 and GLSL ES version 3.00.786*/787if ((state->is_version(130, 0) &&788state->ARB_shading_language_420pack_enable) ||789state->is_version(420, 300)) {790add_const("gl_MinProgramTexelOffset",791state->Const.MinProgramTexelOffset);792add_const("gl_MaxProgramTexelOffset",793state->Const.MaxProgramTexelOffset);794}795796if (state->has_clip_distance()) {797add_const("gl_MaxClipDistances", state->Const.MaxClipPlanes);798}799if (state->is_version(130, 0)) {800add_const("gl_MaxVaryingComponents", state->ctx->Const.MaxVarying * 4);801}802if (state->has_cull_distance()) {803add_const("gl_MaxCullDistances", state->Const.MaxClipPlanes);804add_const("gl_MaxCombinedClipAndCullDistances",805state->Const.MaxClipPlanes);806}807808if (state->has_geometry_shader()) {809add_const("gl_MaxVertexOutputComponents",810state->Const.MaxVertexOutputComponents);811add_const("gl_MaxGeometryInputComponents",812state->Const.MaxGeometryInputComponents);813add_const("gl_MaxGeometryOutputComponents",814state->Const.MaxGeometryOutputComponents);815add_const("gl_MaxFragmentInputComponents",816state->Const.MaxFragmentInputComponents);817add_const("gl_MaxGeometryTextureImageUnits",818state->Const.MaxGeometryTextureImageUnits);819add_const("gl_MaxGeometryOutputVertices",820state->Const.MaxGeometryOutputVertices);821add_const("gl_MaxGeometryTotalOutputComponents",822state->Const.MaxGeometryTotalOutputComponents);823add_const("gl_MaxGeometryUniformComponents",824state->Const.MaxGeometryUniformComponents);825826/* Note: the GLSL 1.50-4.40 specs require827* gl_MaxGeometryVaryingComponents to be present, and to be at least 64.828* But they do not define what it means (and there does not appear to be829* any corresponding constant in the GL specs). However,830* ARB_geometry_shader4 defines MAX_GEOMETRY_VARYING_COMPONENTS_ARB to831* be the maximum number of components available for use as geometry832* outputs. So we assume this is a synonym for833* gl_MaxGeometryOutputComponents.834*/835add_const("gl_MaxGeometryVaryingComponents",836state->Const.MaxGeometryOutputComponents);837}838839if (compatibility) {840/* Note: gl_MaxLights stopped being listed as an explicit constant in841* GLSL 1.30, however it continues to be referred to (as a minimum size842* for compatibility-mode uniforms) all the way up through GLSL 4.30, so843* this seems like it was probably an oversight.844*/845add_const("gl_MaxLights", state->Const.MaxLights);846847add_const("gl_MaxClipPlanes", state->Const.MaxClipPlanes);848849/* Note: gl_MaxTextureUnits wasn't made compatibility-only until GLSL850* 1.50, however this seems like it was probably an oversight.851*/852add_const("gl_MaxTextureUnits", state->Const.MaxTextureUnits);853854/* Note: gl_MaxTextureCoords was left out of GLSL 1.40, but it was855* re-introduced in GLSL 1.50, so this seems like it was probably an856* oversight.857*/858add_const("gl_MaxTextureCoords", state->Const.MaxTextureCoords);859}860861if (state->has_atomic_counters()) {862add_const("gl_MaxVertexAtomicCounters",863state->Const.MaxVertexAtomicCounters);864add_const("gl_MaxFragmentAtomicCounters",865state->Const.MaxFragmentAtomicCounters);866add_const("gl_MaxCombinedAtomicCounters",867state->Const.MaxCombinedAtomicCounters);868add_const("gl_MaxAtomicCounterBindings",869state->Const.MaxAtomicBufferBindings);870871if (state->has_geometry_shader()) {872add_const("gl_MaxGeometryAtomicCounters",873state->Const.MaxGeometryAtomicCounters);874}875if (state->is_version(110, 320)) {876add_const("gl_MaxTessControlAtomicCounters",877state->Const.MaxTessControlAtomicCounters);878add_const("gl_MaxTessEvaluationAtomicCounters",879state->Const.MaxTessEvaluationAtomicCounters);880}881}882883if (state->is_version(420, 310)) {884add_const("gl_MaxVertexAtomicCounterBuffers",885state->Const.MaxVertexAtomicCounterBuffers);886add_const("gl_MaxFragmentAtomicCounterBuffers",887state->Const.MaxFragmentAtomicCounterBuffers);888add_const("gl_MaxCombinedAtomicCounterBuffers",889state->Const.MaxCombinedAtomicCounterBuffers);890add_const("gl_MaxAtomicCounterBufferSize",891state->Const.MaxAtomicCounterBufferSize);892893if (state->has_geometry_shader()) {894add_const("gl_MaxGeometryAtomicCounterBuffers",895state->Const.MaxGeometryAtomicCounterBuffers);896}897if (state->is_version(110, 320)) {898add_const("gl_MaxTessControlAtomicCounterBuffers",899state->Const.MaxTessControlAtomicCounterBuffers);900add_const("gl_MaxTessEvaluationAtomicCounterBuffers",901state->Const.MaxTessEvaluationAtomicCounterBuffers);902}903}904905if (state->is_version(430, 310) || state->ARB_compute_shader_enable) {906add_const("gl_MaxComputeAtomicCounterBuffers",907state->Const.MaxComputeAtomicCounterBuffers);908add_const("gl_MaxComputeAtomicCounters",909state->Const.MaxComputeAtomicCounters);910add_const("gl_MaxComputeImageUniforms",911state->Const.MaxComputeImageUniforms);912add_const("gl_MaxComputeTextureImageUnits",913state->Const.MaxComputeTextureImageUnits);914add_const("gl_MaxComputeUniformComponents",915state->Const.MaxComputeUniformComponents);916917add_const_ivec3("gl_MaxComputeWorkGroupCount",918state->Const.MaxComputeWorkGroupCount[0],919state->Const.MaxComputeWorkGroupCount[1],920state->Const.MaxComputeWorkGroupCount[2]);921add_const_ivec3("gl_MaxComputeWorkGroupSize",922state->Const.MaxComputeWorkGroupSize[0],923state->Const.MaxComputeWorkGroupSize[1],924state->Const.MaxComputeWorkGroupSize[2]);925926/* From the GLSL 4.40 spec, section 7.1 (Built-In Language Variables):927*928* The built-in constant gl_WorkGroupSize is a compute-shader929* constant containing the local work-group size of the shader. The930* size of the work group in the X, Y, and Z dimensions is stored in931* the x, y, and z components. The constants values in932* gl_WorkGroupSize will match those specified in the required933* local_size_x, local_size_y, and local_size_z layout qualifiers934* for the current shader. This is a constant so that it can be935* used to size arrays of memory that can be shared within the local936* work group. It is a compile-time error to use gl_WorkGroupSize937* in a shader that does not declare a fixed local group size, or938* before that shader has declared a fixed local group size, using939* local_size_x, local_size_y, and local_size_z.940*941* To prevent the shader from trying to refer to gl_WorkGroupSize before942* the layout declaration, we don't define it here. Intead we define it943* in ast_cs_input_layout::hir().944*/945}946947if (state->has_enhanced_layouts()) {948add_const("gl_MaxTransformFeedbackBuffers",949state->Const.MaxTransformFeedbackBuffers);950add_const("gl_MaxTransformFeedbackInterleavedComponents",951state->Const.MaxTransformFeedbackInterleavedComponents);952}953954if (state->has_shader_image_load_store()) {955add_const("gl_MaxImageUnits",956state->Const.MaxImageUnits);957add_const("gl_MaxVertexImageUniforms",958state->Const.MaxVertexImageUniforms);959add_const("gl_MaxFragmentImageUniforms",960state->Const.MaxFragmentImageUniforms);961add_const("gl_MaxCombinedImageUniforms",962state->Const.MaxCombinedImageUniforms);963964if (state->has_geometry_shader()) {965add_const("gl_MaxGeometryImageUniforms",966state->Const.MaxGeometryImageUniforms);967}968969if (!state->es_shader) {970add_const("gl_MaxCombinedImageUnitsAndFragmentOutputs",971state->Const.MaxCombinedShaderOutputResources);972add_const("gl_MaxImageSamples",973state->Const.MaxImageSamples);974}975976if (state->has_tessellation_shader()) {977add_const("gl_MaxTessControlImageUniforms",978state->Const.MaxTessControlImageUniforms);979add_const("gl_MaxTessEvaluationImageUniforms",980state->Const.MaxTessEvaluationImageUniforms);981}982}983984if (state->is_version(440, 310) ||985state->ARB_ES3_1_compatibility_enable) {986add_const("gl_MaxCombinedShaderOutputResources",987state->Const.MaxCombinedShaderOutputResources);988}989990if (state->is_version(410, 0) ||991state->ARB_viewport_array_enable ||992state->OES_viewport_array_enable) {993add_const("gl_MaxViewports", GLSL_PRECISION_HIGH,994state->Const.MaxViewports);995}996997if (state->has_tessellation_shader()) {998add_const("gl_MaxPatchVertices", state->Const.MaxPatchVertices);999add_const("gl_MaxTessGenLevel", state->Const.MaxTessGenLevel);1000add_const("gl_MaxTessControlInputComponents", state->Const.MaxTessControlInputComponents);1001add_const("gl_MaxTessControlOutputComponents", state->Const.MaxTessControlOutputComponents);1002add_const("gl_MaxTessControlTextureImageUnits", state->Const.MaxTessControlTextureImageUnits);1003add_const("gl_MaxTessEvaluationInputComponents", state->Const.MaxTessEvaluationInputComponents);1004add_const("gl_MaxTessEvaluationOutputComponents", state->Const.MaxTessEvaluationOutputComponents);1005add_const("gl_MaxTessEvaluationTextureImageUnits", state->Const.MaxTessEvaluationTextureImageUnits);1006add_const("gl_MaxTessPatchComponents", state->Const.MaxTessPatchComponents);1007add_const("gl_MaxTessControlTotalOutputComponents", state->Const.MaxTessControlTotalOutputComponents);1008add_const("gl_MaxTessControlUniformComponents", state->Const.MaxTessControlUniformComponents);1009add_const("gl_MaxTessEvaluationUniformComponents", state->Const.MaxTessEvaluationUniformComponents);1010}10111012if (state->is_version(450, 320) ||1013state->OES_sample_variables_enable ||1014state->ARB_ES3_1_compatibility_enable)1015add_const("gl_MaxSamples", state->Const.MaxSamples);1016}101710181019/**1020* Generate uniform variables (which exist in all types of shaders).1021*/1022void1023builtin_variable_generator::generate_uniforms()1024{1025if (state->is_version(400, 320) ||1026state->ARB_sample_shading_enable ||1027state->OES_sample_variables_enable)1028add_uniform(int_t, GLSL_PRECISION_LOW, "gl_NumSamples");1029add_uniform(type("gl_DepthRangeParameters"), "gl_DepthRange");10301031for (unsigned i = 0; i < VARYING_SLOT_VAR0; i++) {1032char name[128];10331034snprintf(name, sizeof(name), "gl_CurrentAttribFrag%uMESA", i);1035add_uniform(vec4_t, name);1036}10371038if (compatibility) {1039add_uniform(mat4_t, "gl_ModelViewMatrix");1040add_uniform(mat4_t, "gl_ProjectionMatrix");1041add_uniform(mat4_t, "gl_ModelViewProjectionMatrix");1042add_uniform(mat3_t, "gl_NormalMatrix");1043add_uniform(mat4_t, "gl_ModelViewMatrixInverse");1044add_uniform(mat4_t, "gl_ProjectionMatrixInverse");1045add_uniform(mat4_t, "gl_ModelViewProjectionMatrixInverse");1046add_uniform(mat4_t, "gl_ModelViewMatrixTranspose");1047add_uniform(mat4_t, "gl_ProjectionMatrixTranspose");1048add_uniform(mat4_t, "gl_ModelViewProjectionMatrixTranspose");1049add_uniform(mat4_t, "gl_ModelViewMatrixInverseTranspose");1050add_uniform(mat4_t, "gl_ProjectionMatrixInverseTranspose");1051add_uniform(mat4_t, "gl_ModelViewProjectionMatrixInverseTranspose");1052add_uniform(float_t, "gl_NormalScale");1053add_uniform(type("gl_LightModelParameters"), "gl_LightModel");1054add_uniform(vec4_t, "gl_FogParamsOptimizedMESA");10551056const glsl_type *const mat4_array_type =1057array(mat4_t, state->Const.MaxTextureCoords);1058add_uniform(mat4_array_type, "gl_TextureMatrix");1059add_uniform(mat4_array_type, "gl_TextureMatrixInverse");1060add_uniform(mat4_array_type, "gl_TextureMatrixTranspose");1061add_uniform(mat4_array_type, "gl_TextureMatrixInverseTranspose");10621063add_uniform(array(vec4_t, state->Const.MaxClipPlanes), "gl_ClipPlane");1064add_uniform(type("gl_PointParameters"), "gl_Point");10651066const glsl_type *const material_parameters_type =1067type("gl_MaterialParameters");1068add_uniform(material_parameters_type, "gl_FrontMaterial");1069add_uniform(material_parameters_type, "gl_BackMaterial");10701071add_uniform(array(type("gl_LightSourceParameters"),1072state->Const.MaxLights),1073"gl_LightSource");10741075const glsl_type *const light_model_products_type =1076type("gl_LightModelProducts");1077add_uniform(light_model_products_type, "gl_FrontLightModelProduct");1078add_uniform(light_model_products_type, "gl_BackLightModelProduct");10791080const glsl_type *const light_products_type =1081array(type("gl_LightProducts"), state->Const.MaxLights);1082add_uniform(light_products_type, "gl_FrontLightProduct");1083add_uniform(light_products_type, "gl_BackLightProduct");10841085add_uniform(array(vec4_t, state->Const.MaxTextureUnits),1086"gl_TextureEnvColor");10871088const glsl_type *const texcoords_vec4 =1089array(vec4_t, state->Const.MaxTextureCoords);1090add_uniform(texcoords_vec4, "gl_EyePlaneS");1091add_uniform(texcoords_vec4, "gl_EyePlaneT");1092add_uniform(texcoords_vec4, "gl_EyePlaneR");1093add_uniform(texcoords_vec4, "gl_EyePlaneQ");1094add_uniform(texcoords_vec4, "gl_ObjectPlaneS");1095add_uniform(texcoords_vec4, "gl_ObjectPlaneT");1096add_uniform(texcoords_vec4, "gl_ObjectPlaneR");1097add_uniform(texcoords_vec4, "gl_ObjectPlaneQ");10981099add_uniform(type("gl_FogParameters"), "gl_Fog");1100}1101}110211031104/**1105* Generate special variables which exist in all shaders.1106*/1107void1108builtin_variable_generator::generate_special_vars()1109{1110if (state->ARB_shader_ballot_enable) {1111add_system_value(SYSTEM_VALUE_SUBGROUP_SIZE, uint_t, "gl_SubGroupSizeARB");1112add_system_value(SYSTEM_VALUE_SUBGROUP_INVOCATION, uint_t, "gl_SubGroupInvocationARB");1113add_system_value(SYSTEM_VALUE_SUBGROUP_EQ_MASK, uint64_t, "gl_SubGroupEqMaskARB");1114add_system_value(SYSTEM_VALUE_SUBGROUP_GE_MASK, uint64_t, "gl_SubGroupGeMaskARB");1115add_system_value(SYSTEM_VALUE_SUBGROUP_GT_MASK, uint64_t, "gl_SubGroupGtMaskARB");1116add_system_value(SYSTEM_VALUE_SUBGROUP_LE_MASK, uint64_t, "gl_SubGroupLeMaskARB");1117add_system_value(SYSTEM_VALUE_SUBGROUP_LT_MASK, uint64_t, "gl_SubGroupLtMaskARB");1118}1119}112011211122/**1123* Generate variables which only exist in vertex shaders.1124*/1125void1126builtin_variable_generator::generate_vs_special_vars()1127{1128if (state->is_version(130, 300) || state->EXT_gpu_shader4_enable) {1129add_system_value(SYSTEM_VALUE_VERTEX_ID, int_t, GLSL_PRECISION_HIGH,1130"gl_VertexID");1131}1132if (state->is_version(460, 0)) {1133add_system_value(SYSTEM_VALUE_BASE_VERTEX, int_t, "gl_BaseVertex");1134add_system_value(SYSTEM_VALUE_BASE_INSTANCE, int_t, "gl_BaseInstance");1135add_system_value(SYSTEM_VALUE_DRAW_ID, int_t, "gl_DrawID");1136}1137if (state->EXT_draw_instanced_enable && state->is_version(0, 100))1138add_system_value(SYSTEM_VALUE_INSTANCE_ID, int_t, GLSL_PRECISION_HIGH,1139"gl_InstanceIDEXT");11401141if (state->ARB_draw_instanced_enable)1142add_system_value(SYSTEM_VALUE_INSTANCE_ID, int_t, "gl_InstanceIDARB");11431144if (state->ARB_draw_instanced_enable || state->is_version(140, 300) ||1145state->EXT_gpu_shader4_enable) {1146add_system_value(SYSTEM_VALUE_INSTANCE_ID, int_t, GLSL_PRECISION_HIGH,1147"gl_InstanceID");1148}1149if (state->ARB_shader_draw_parameters_enable) {1150add_system_value(SYSTEM_VALUE_BASE_VERTEX, int_t, "gl_BaseVertexARB");1151add_system_value(SYSTEM_VALUE_BASE_INSTANCE, int_t, "gl_BaseInstanceARB");1152add_system_value(SYSTEM_VALUE_DRAW_ID, int_t, "gl_DrawIDARB");1153}1154if (compatibility) {1155add_input(VERT_ATTRIB_POS, vec4_t, "gl_Vertex");1156add_input(VERT_ATTRIB_NORMAL, vec3_t, "gl_Normal");1157add_input(VERT_ATTRIB_COLOR0, vec4_t, "gl_Color");1158add_input(VERT_ATTRIB_COLOR1, vec4_t, "gl_SecondaryColor");1159add_input(VERT_ATTRIB_TEX0, vec4_t, "gl_MultiTexCoord0");1160add_input(VERT_ATTRIB_TEX1, vec4_t, "gl_MultiTexCoord1");1161add_input(VERT_ATTRIB_TEX2, vec4_t, "gl_MultiTexCoord2");1162add_input(VERT_ATTRIB_TEX3, vec4_t, "gl_MultiTexCoord3");1163add_input(VERT_ATTRIB_TEX4, vec4_t, "gl_MultiTexCoord4");1164add_input(VERT_ATTRIB_TEX5, vec4_t, "gl_MultiTexCoord5");1165add_input(VERT_ATTRIB_TEX6, vec4_t, "gl_MultiTexCoord6");1166add_input(VERT_ATTRIB_TEX7, vec4_t, "gl_MultiTexCoord7");1167add_input(VERT_ATTRIB_FOG, float_t, "gl_FogCoord");1168}1169}117011711172/**1173* Generate variables which only exist in tessellation control shaders.1174*/1175void1176builtin_variable_generator::generate_tcs_special_vars()1177{1178add_system_value(SYSTEM_VALUE_PRIMITIVE_ID, int_t, GLSL_PRECISION_HIGH,1179"gl_PrimitiveID");1180add_system_value(SYSTEM_VALUE_INVOCATION_ID, int_t, GLSL_PRECISION_HIGH,1181"gl_InvocationID");1182add_system_value(SYSTEM_VALUE_VERTICES_IN, int_t, GLSL_PRECISION_HIGH,1183"gl_PatchVerticesIn");11841185add_output(VARYING_SLOT_TESS_LEVEL_OUTER, array(float_t, 4),1186GLSL_PRECISION_HIGH, "gl_TessLevelOuter")->data.patch = 1;1187add_output(VARYING_SLOT_TESS_LEVEL_INNER, array(float_t, 2),1188GLSL_PRECISION_HIGH, "gl_TessLevelInner")->data.patch = 1;1189/* XXX What to do if multiple are flipped on? */1190int bbox_slot = state->ctx->Const.NoPrimitiveBoundingBoxOutput ? -1 :1191VARYING_SLOT_BOUNDING_BOX0;1192if (state->EXT_primitive_bounding_box_enable)1193add_output(bbox_slot, array(vec4_t, 2), "gl_BoundingBoxEXT")1194->data.patch = 1;1195if (state->OES_primitive_bounding_box_enable) {1196add_output(bbox_slot, array(vec4_t, 2), GLSL_PRECISION_HIGH,1197"gl_BoundingBoxOES")->data.patch = 1;1198}1199if (state->is_version(0, 320) || state->ARB_ES3_2_compatibility_enable) {1200add_output(bbox_slot, array(vec4_t, 2), GLSL_PRECISION_HIGH,1201"gl_BoundingBox")->data.patch = 1;1202}12031204/* NOTE: These are completely pointless. Writing these will never go1205* anywhere. But the specs demands it. So we add them with a slot of -1,1206* which makes the data go nowhere.1207*/1208if (state->NV_viewport_array2_enable) {1209add_output(-1, int_t, "gl_Layer");1210add_output(-1, int_t, "gl_ViewportIndex");1211add_output(-1, array(int_t, 1), "gl_ViewportMask");1212}12131214}121512161217/**1218* Generate variables which only exist in tessellation evaluation shaders.1219*/1220void1221builtin_variable_generator::generate_tes_special_vars()1222{1223ir_variable *var;12241225add_system_value(SYSTEM_VALUE_PRIMITIVE_ID, int_t, GLSL_PRECISION_HIGH,1226"gl_PrimitiveID");1227add_system_value(SYSTEM_VALUE_VERTICES_IN, int_t, GLSL_PRECISION_HIGH,1228"gl_PatchVerticesIn");1229add_system_value(SYSTEM_VALUE_TESS_COORD, vec3_t, GLSL_PRECISION_HIGH,1230"gl_TessCoord");1231if (this->state->ctx->Const.GLSLTessLevelsAsInputs) {1232add_input(VARYING_SLOT_TESS_LEVEL_OUTER, array(float_t, 4),1233GLSL_PRECISION_HIGH, "gl_TessLevelOuter")->data.patch = 1;1234add_input(VARYING_SLOT_TESS_LEVEL_INNER, array(float_t, 2),1235GLSL_PRECISION_HIGH, "gl_TessLevelInner")->data.patch = 1;1236} else {1237add_system_value(SYSTEM_VALUE_TESS_LEVEL_OUTER, array(float_t, 4),1238GLSL_PRECISION_HIGH, "gl_TessLevelOuter");1239add_system_value(SYSTEM_VALUE_TESS_LEVEL_INNER, array(float_t, 2),1240GLSL_PRECISION_HIGH, "gl_TessLevelInner");1241}1242if (state->ARB_shader_viewport_layer_array_enable ||1243state->NV_viewport_array2_enable) {1244var = add_output(VARYING_SLOT_LAYER, int_t, "gl_Layer");1245var->data.interpolation = INTERP_MODE_FLAT;1246var = add_output(VARYING_SLOT_VIEWPORT, int_t, "gl_ViewportIndex");1247var->data.interpolation = INTERP_MODE_FLAT;1248}1249if (state->NV_viewport_array2_enable) {1250var = add_output(VARYING_SLOT_VIEWPORT_MASK, array(int_t, 1),1251"gl_ViewportMask");1252var->data.interpolation = INTERP_MODE_FLAT;1253}1254}125512561257/**1258* Generate variables which only exist in geometry shaders.1259*/1260void1261builtin_variable_generator::generate_gs_special_vars()1262{1263ir_variable *var;12641265var = add_output(VARYING_SLOT_LAYER, int_t, GLSL_PRECISION_HIGH, "gl_Layer");1266var->data.interpolation = INTERP_MODE_FLAT;1267if (state->is_version(410, 0) || state->ARB_viewport_array_enable ||1268state->OES_viewport_array_enable) {1269var = add_output(VARYING_SLOT_VIEWPORT, int_t, GLSL_PRECISION_HIGH,1270"gl_ViewportIndex");1271var->data.interpolation = INTERP_MODE_FLAT;1272}1273if (state->NV_viewport_array2_enable) {1274var = add_output(VARYING_SLOT_VIEWPORT_MASK, array(int_t, 1),1275"gl_ViewportMask");1276var->data.interpolation = INTERP_MODE_FLAT;1277}1278if (state->is_version(400, 320) || state->ARB_gpu_shader5_enable ||1279state->OES_geometry_shader_enable || state->EXT_geometry_shader_enable) {1280add_system_value(SYSTEM_VALUE_INVOCATION_ID, int_t, GLSL_PRECISION_HIGH,1281"gl_InvocationID");1282}12831284/* Although gl_PrimitiveID appears in tessellation control and tessellation1285* evaluation shaders, it has a different function there than it has in1286* geometry shaders, so we treat it (and its counterpart gl_PrimitiveIDIn)1287* as special geometry shader variables.1288*1289* Note that although the general convention of suffixing geometry shader1290* input varyings with "In" was not adopted into GLSL 1.50, it is used in1291* the specific case of gl_PrimitiveIDIn. So we don't need to treat1292* gl_PrimitiveIDIn as an {ARB,EXT}_geometry_shader4-only variable.1293*/1294var = add_input(VARYING_SLOT_PRIMITIVE_ID, int_t, GLSL_PRECISION_HIGH,1295"gl_PrimitiveIDIn");1296var->data.interpolation = INTERP_MODE_FLAT;1297var = add_output(VARYING_SLOT_PRIMITIVE_ID, int_t, GLSL_PRECISION_HIGH,1298"gl_PrimitiveID");1299var->data.interpolation = INTERP_MODE_FLAT;1300}130113021303/**1304* Generate variables which only exist in fragment shaders.1305*/1306void1307builtin_variable_generator::generate_fs_special_vars()1308{1309ir_variable *var;13101311int frag_coord_precision = (state->is_version(0, 300) ?1312GLSL_PRECISION_HIGH :1313GLSL_PRECISION_MEDIUM);13141315if (this->state->ctx->Const.GLSLFragCoordIsSysVal) {1316add_system_value(SYSTEM_VALUE_FRAG_COORD, vec4_t, frag_coord_precision,1317"gl_FragCoord");1318} else {1319add_input(VARYING_SLOT_POS, vec4_t, frag_coord_precision, "gl_FragCoord");1320}13211322if (this->state->ctx->Const.GLSLFrontFacingIsSysVal) {1323var = add_system_value(SYSTEM_VALUE_FRONT_FACE, bool_t, "gl_FrontFacing");1324var->data.interpolation = INTERP_MODE_FLAT;1325} else {1326var = add_input(VARYING_SLOT_FACE, bool_t, "gl_FrontFacing");1327var->data.interpolation = INTERP_MODE_FLAT;1328}13291330if (state->is_version(120, 100)) {1331if (this->state->ctx->Const.GLSLPointCoordIsSysVal)1332add_system_value(SYSTEM_VALUE_POINT_COORD, vec2_t,1333GLSL_PRECISION_MEDIUM, "gl_PointCoord");1334else1335add_input(VARYING_SLOT_PNTC, vec2_t, GLSL_PRECISION_MEDIUM,1336"gl_PointCoord");1337}13381339if (state->has_geometry_shader() || state->EXT_gpu_shader4_enable) {1340var = add_input(VARYING_SLOT_PRIMITIVE_ID, int_t, GLSL_PRECISION_HIGH,1341"gl_PrimitiveID");1342var->data.interpolation = INTERP_MODE_FLAT;1343}13441345/* gl_FragColor and gl_FragData were deprecated starting in desktop GLSL1346* 1.30, and were relegated to the compatibility profile in GLSL 4.20.1347* They were removed from GLSL ES 3.00.1348*/1349if (compatibility || !state->is_version(420, 300)) {1350add_output(FRAG_RESULT_COLOR, vec4_t, GLSL_PRECISION_MEDIUM,1351"gl_FragColor");1352add_output(FRAG_RESULT_DATA0,1353array(vec4_t, state->Const.MaxDrawBuffers),1354GLSL_PRECISION_MEDIUM,1355"gl_FragData");1356}13571358if (state->has_framebuffer_fetch() && !state->is_version(130, 300)) {1359ir_variable *const var =1360add_output(FRAG_RESULT_DATA0,1361array(vec4_t, state->Const.MaxDrawBuffers),1362"gl_LastFragData");1363var->data.precision = GLSL_PRECISION_MEDIUM;1364var->data.read_only = 1;1365var->data.fb_fetch_output = 1;1366var->data.memory_coherent = 1;1367}13681369if (state->es_shader && state->language_version == 100 && state->EXT_blend_func_extended_enable) {1370add_index_output(FRAG_RESULT_COLOR, 1, vec4_t,1371GLSL_PRECISION_MEDIUM, "gl_SecondaryFragColorEXT");1372add_index_output(FRAG_RESULT_DATA0, 1,1373array(vec4_t, state->Const.MaxDualSourceDrawBuffers),1374GLSL_PRECISION_MEDIUM, "gl_SecondaryFragDataEXT");1375}13761377/* gl_FragDepth has always been in desktop GLSL, but did not appear in GLSL1378* ES 1.00.1379*/1380if (state->is_version(110, 300)) {1381add_output(FRAG_RESULT_DEPTH, float_t, GLSL_PRECISION_HIGH,1382"gl_FragDepth");1383}13841385if (state->EXT_frag_depth_enable)1386add_output(FRAG_RESULT_DEPTH, float_t, "gl_FragDepthEXT");13871388if (state->ARB_shader_stencil_export_enable) {1389ir_variable *const var =1390add_output(FRAG_RESULT_STENCIL, int_t, "gl_FragStencilRefARB");1391if (state->ARB_shader_stencil_export_warn)1392var->enable_extension_warning("GL_ARB_shader_stencil_export");1393}13941395if (state->AMD_shader_stencil_export_enable) {1396ir_variable *const var =1397add_output(FRAG_RESULT_STENCIL, int_t, "gl_FragStencilRefAMD");1398if (state->AMD_shader_stencil_export_warn)1399var->enable_extension_warning("GL_AMD_shader_stencil_export");1400}14011402if (state->is_version(400, 320) ||1403state->ARB_sample_shading_enable ||1404state->OES_sample_variables_enable) {1405add_system_value(SYSTEM_VALUE_SAMPLE_ID, int_t, GLSL_PRECISION_LOW,1406"gl_SampleID");1407add_system_value(SYSTEM_VALUE_SAMPLE_POS, vec2_t, GLSL_PRECISION_MEDIUM,1408"gl_SamplePosition");1409/* From the ARB_sample_shading specification:1410* "The number of elements in the array is ceil(<s>/32), where1411* <s> is the maximum number of color samples supported by the1412* implementation."1413* Since no drivers expose more than 32x MSAA, we can simply set1414* the array size to 1 rather than computing it.1415*/1416add_output(FRAG_RESULT_SAMPLE_MASK, array(int_t, 1),1417GLSL_PRECISION_HIGH, "gl_SampleMask");1418}14191420if (state->is_version(400, 320) ||1421state->ARB_gpu_shader5_enable ||1422state->OES_sample_variables_enable) {1423add_system_value(SYSTEM_VALUE_SAMPLE_MASK_IN, array(int_t, 1),1424GLSL_PRECISION_HIGH, "gl_SampleMaskIn");1425}14261427if (state->is_version(430, 320) ||1428state->ARB_fragment_layer_viewport_enable ||1429state->OES_geometry_shader_enable ||1430state->EXT_geometry_shader_enable) {1431add_varying(VARYING_SLOT_LAYER, int_t, GLSL_PRECISION_HIGH,1432"gl_Layer", INTERP_MODE_FLAT);1433}14341435if (state->is_version(430, 0) ||1436state->ARB_fragment_layer_viewport_enable ||1437state->OES_viewport_array_enable) {1438add_varying(VARYING_SLOT_VIEWPORT, int_t, "gl_ViewportIndex", INTERP_MODE_FLAT);1439}14401441if (state->is_version(450, 310) || state->ARB_ES3_1_compatibility_enable)1442add_system_value(SYSTEM_VALUE_HELPER_INVOCATION, bool_t, "gl_HelperInvocation");1443}144414451446/**1447* Generate variables which only exist in compute shaders.1448*/1449void1450builtin_variable_generator::generate_cs_special_vars()1451{1452add_system_value(SYSTEM_VALUE_LOCAL_INVOCATION_ID, uvec3_t,1453"gl_LocalInvocationID");1454add_system_value(SYSTEM_VALUE_WORKGROUP_ID, uvec3_t, "gl_WorkGroupID");1455add_system_value(SYSTEM_VALUE_NUM_WORKGROUPS, uvec3_t, "gl_NumWorkGroups");14561457if (state->ARB_compute_variable_group_size_enable) {1458add_system_value(SYSTEM_VALUE_WORKGROUP_SIZE,1459uvec3_t, "gl_LocalGroupSizeARB");1460}14611462add_system_value(SYSTEM_VALUE_GLOBAL_INVOCATION_ID,1463uvec3_t, "gl_GlobalInvocationID");1464add_system_value(SYSTEM_VALUE_LOCAL_INVOCATION_INDEX,1465uint_t, "gl_LocalInvocationIndex");1466}146714681469/**1470* Add a single "varying" variable. The variable's type and direction (input1471* or output) are adjusted as appropriate for the type of shader being1472* compiled.1473*/1474void1475builtin_variable_generator::add_varying(int slot, const glsl_type *type,1476int precision, const char *name,1477enum glsl_interp_mode interp)1478{1479switch (state->stage) {1480case MESA_SHADER_TESS_CTRL:1481case MESA_SHADER_TESS_EVAL:1482case MESA_SHADER_GEOMETRY:1483this->per_vertex_in.add_field(slot, type, precision, name, interp);1484FALLTHROUGH;1485case MESA_SHADER_VERTEX:1486this->per_vertex_out.add_field(slot, type, precision, name, interp);1487break;1488case MESA_SHADER_FRAGMENT:1489add_input(slot, type, precision, name, interp);1490break;1491case MESA_SHADER_COMPUTE:1492/* Compute shaders don't have varyings. */1493break;1494default:1495break;1496}1497}149814991500/**1501* Generate variables that are used to communicate data from one shader stage1502* to the next ("varyings").1503*/1504void1505builtin_variable_generator::generate_varyings()1506{1507struct gl_shader_compiler_options *options =1508&state->ctx->Const.ShaderCompilerOptions[state->stage];15091510/* gl_Position and gl_PointSize are not visible from fragment shaders. */1511if (state->stage != MESA_SHADER_FRAGMENT) {1512add_varying(VARYING_SLOT_POS, vec4_t, GLSL_PRECISION_HIGH, "gl_Position");1513if (!state->es_shader ||1514state->stage == MESA_SHADER_VERTEX ||1515(state->stage == MESA_SHADER_GEOMETRY &&1516(state->OES_geometry_point_size_enable ||1517state->EXT_geometry_point_size_enable)) ||1518((state->stage == MESA_SHADER_TESS_CTRL ||1519state->stage == MESA_SHADER_TESS_EVAL) &&1520(state->OES_tessellation_point_size_enable ||1521state->EXT_tessellation_point_size_enable))) {1522add_varying(VARYING_SLOT_PSIZ,1523float_t,1524state->is_version(0, 300) ?1525GLSL_PRECISION_HIGH :1526GLSL_PRECISION_MEDIUM,1527"gl_PointSize");1528}1529if (state->stage == MESA_SHADER_VERTEX) {1530if (state->AMD_vertex_shader_viewport_index_enable ||1531state->ARB_shader_viewport_layer_array_enable ||1532state->NV_viewport_array2_enable) {1533add_varying(VARYING_SLOT_VIEWPORT, int_t, "gl_ViewportIndex", INTERP_MODE_FLAT);1534}15351536if (state->AMD_vertex_shader_layer_enable ||1537state->ARB_shader_viewport_layer_array_enable ||1538state->NV_viewport_array2_enable) {1539add_varying(VARYING_SLOT_LAYER, int_t, GLSL_PRECISION_HIGH,1540"gl_Layer", INTERP_MODE_FLAT);1541}15421543/* From the NV_viewport_array2 specification:1544*1545* "The variable gl_ViewportMask[] is available as an output variable1546* in the VTG languages. The array has ceil(v/32) elements where v is1547* the maximum number of viewports supported by the implementation."1548*1549* Since no drivers expose more than 16 viewports, we can simply set the1550* array size to 1 rather than computing it and dealing with varying1551* slot complication.1552*/1553if (state->NV_viewport_array2_enable)1554add_varying(VARYING_SLOT_VIEWPORT_MASK, array(int_t, 1),1555"gl_ViewportMask", INTERP_MODE_FLAT);1556}1557}15581559if (state->has_clip_distance()) {1560add_varying(VARYING_SLOT_CLIP_DIST0, array(float_t, 0),1561GLSL_PRECISION_HIGH, "gl_ClipDistance");1562}1563if (state->has_cull_distance()) {1564add_varying(VARYING_SLOT_CULL_DIST0, array(float_t, 0),1565GLSL_PRECISION_HIGH, "gl_CullDistance");1566}15671568if (compatibility) {1569add_varying(VARYING_SLOT_TEX0, array(vec4_t, 0), "gl_TexCoord");1570add_varying(VARYING_SLOT_FOGC, float_t, "gl_FogFragCoord");1571if (state->stage == MESA_SHADER_FRAGMENT) {1572add_varying(VARYING_SLOT_COL0, vec4_t, "gl_Color");1573add_varying(VARYING_SLOT_COL1, vec4_t, "gl_SecondaryColor");1574} else {1575add_varying(VARYING_SLOT_CLIP_VERTEX, vec4_t, "gl_ClipVertex");1576add_varying(VARYING_SLOT_COL0, vec4_t, "gl_FrontColor");1577add_varying(VARYING_SLOT_BFC0, vec4_t, "gl_BackColor");1578add_varying(VARYING_SLOT_COL1, vec4_t, "gl_FrontSecondaryColor");1579add_varying(VARYING_SLOT_BFC1, vec4_t, "gl_BackSecondaryColor");1580}1581}15821583/* Section 7.1 (Built-In Language Variables) of the GLSL 4.00 spec1584* says:1585*1586* "In the tessellation control language, built-in variables are1587* intrinsically declared as:1588*1589* in gl_PerVertex {1590* vec4 gl_Position;1591* float gl_PointSize;1592* float gl_ClipDistance[];1593* } gl_in[gl_MaxPatchVertices];"1594*/1595if (state->stage == MESA_SHADER_TESS_CTRL ||1596state->stage == MESA_SHADER_TESS_EVAL) {1597const glsl_type *per_vertex_in_type =1598this->per_vertex_in.construct_interface_instance();1599add_variable("gl_in", array(per_vertex_in_type, state->Const.MaxPatchVertices),1600GLSL_PRECISION_NONE, ir_var_shader_in, -1);1601}1602if (state->stage == MESA_SHADER_GEOMETRY) {1603const glsl_type *per_vertex_in_type =1604this->per_vertex_in.construct_interface_instance();1605add_variable("gl_in", array(per_vertex_in_type, 0),1606GLSL_PRECISION_NONE, ir_var_shader_in, -1);1607}1608if (state->stage == MESA_SHADER_TESS_CTRL) {1609const glsl_type *per_vertex_out_type =1610this->per_vertex_out.construct_interface_instance();1611add_variable("gl_out", array(per_vertex_out_type, 0),1612GLSL_PRECISION_NONE, ir_var_shader_out, -1);1613}1614if (state->stage == MESA_SHADER_VERTEX ||1615state->stage == MESA_SHADER_TESS_EVAL ||1616state->stage == MESA_SHADER_GEOMETRY) {1617const glsl_type *per_vertex_out_type =1618this->per_vertex_out.construct_interface_instance();1619const glsl_struct_field *fields = per_vertex_out_type->fields.structure;1620for (unsigned i = 0; i < per_vertex_out_type->length; i++) {1621ir_variable *var =1622add_variable(fields[i].name, fields[i].type, fields[i].precision,1623ir_var_shader_out, fields[i].location);1624var->data.interpolation = fields[i].interpolation;1625var->data.centroid = fields[i].centroid;1626var->data.sample = fields[i].sample;1627var->data.patch = fields[i].patch;1628var->init_interface_type(per_vertex_out_type);16291630var->data.invariant = fields[i].location == VARYING_SLOT_POS &&1631options->PositionAlwaysInvariant;1632}1633}1634}163516361637}; /* Anonymous namespace */163816391640void1641_mesa_glsl_initialize_variables(exec_list *instructions,1642struct _mesa_glsl_parse_state *state)1643{1644builtin_variable_generator gen(instructions, state);16451646gen.generate_constants();1647gen.generate_uniforms();1648gen.generate_special_vars();16491650gen.generate_varyings();16511652switch (state->stage) {1653case MESA_SHADER_VERTEX:1654gen.generate_vs_special_vars();1655break;1656case MESA_SHADER_TESS_CTRL:1657gen.generate_tcs_special_vars();1658break;1659case MESA_SHADER_TESS_EVAL:1660gen.generate_tes_special_vars();1661break;1662case MESA_SHADER_GEOMETRY:1663gen.generate_gs_special_vars();1664break;1665case MESA_SHADER_FRAGMENT:1666gen.generate_fs_special_vars();1667break;1668case MESA_SHADER_COMPUTE:1669gen.generate_cs_special_vars();1670break;1671default:1672break;1673}1674}167516761677