1 /* 2 * Copyright © 2009 Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 */ 23 24 #ifndef PROGRAM_PARSER_H 25 #define PROGRAM_PARSER_H 26 27 #include "main/config.h" 28 #include "program/prog_instruction.h" 29 #include "program/prog_parameter.h" 30 31 struct gl_context; 32 33 enum asm_type { 34 at_none, 35 at_address, 36 at_attrib, 37 at_param, 38 at_temp, 39 at_output 40 }; 41 42 struct asm_symbol { 43 struct asm_symbol *next; /**< List linkage for freeing. */ 44 const char *name; 45 enum asm_type type; 46 unsigned attrib_binding; 47 unsigned output_binding; /**< Output / result register number. */ 48 49 /** 50 * One of PROGRAM_STATE_VAR or PROGRAM_CONSTANT. 51 */ 52 unsigned param_binding_type; 53 54 /** 55 * Offset into the program_parameter_list where the tokens representing our 56 * bound state (or constants) start. 57 */ 58 unsigned param_binding_begin; 59 60 /** 61 * Constants put into the parameter list may be swizzled. This 62 * field contain's the symbol's swizzle. (SWIZZLE_X/Y/Z/W) 63 */ 64 unsigned param_binding_swizzle; 65 66 /* This is how many entries in the program_parameter_list we take up 67 * with our state tokens or constants. Note that this is _not_ the same as 68 * the number of param registers we eventually use. 69 */ 70 unsigned param_binding_length; 71 72 /** 73 * Index of the temp register assigned to this variable. 74 */ 75 unsigned temp_binding; 76 77 /** 78 * Flag whether or not a PARAM is an array 79 */ 80 unsigned param_is_array:1; 81 82 83 /** 84 * Flag whether or not a PARAM array is accessed indirectly 85 */ 86 unsigned param_accessed_indirectly:1; 87 88 89 /** 90 * \brief Is first pass of parameter layout done with this variable? 91 * 92 * The parameter layout routine operates in two passes. This flag tracks 93 * whether or not the first pass has handled this variable. 94 * 95 * \sa _mesa_layout_parameters 96 */ 97 unsigned pass1_done:1; 98 }; 99 100 101 struct asm_vector { 102 unsigned count; 103 gl_constant_value data[4]; 104 }; 105 106 107 struct asm_swizzle_mask { 108 unsigned swizzle:12; 109 unsigned mask:4; 110 }; 111 112 113 struct asm_src_register { 114 struct prog_src_register Base; 115 116 /** 117 * Symbol associated with indirect access to parameter arrays. 118 * 119 * If \c Base::RelAddr is 1, this will point to the symbol for the parameter 120 * that is being dereferenced. Further, \c Base::Index will be the offset 121 * from the address register being used. 122 */ 123 struct asm_symbol *Symbol; 124 }; 125 126 127 struct asm_instruction { 128 struct prog_instruction Base; 129 struct asm_instruction *next; 130 struct asm_src_register SrcReg[3]; 131 }; 132 133 134 struct asm_parser_state { 135 struct gl_context *ctx; 136 struct gl_program *prog; 137 138 /** Memory context to attach instructions to. */ 139 void *mem_ctx; 140 141 /** 142 * Per-program target limits 143 */ 144 struct gl_program_constants *limits; 145 146 struct _mesa_symbol_table *st; 147 148 /** 149 * Linked list of symbols 150 * 151 * This list is \b only used when cleaning up compiler state and freeing 152 * memory. 153 */ 154 struct asm_symbol *sym; 155 156 /** 157 * State for the lexer. 158 */ 159 void *scanner; 160 161 /** 162 * Linked list of instructions generated during parsing. 163 */ 164 /*@{*/ 165 struct asm_instruction *inst_head; 166 struct asm_instruction *inst_tail; 167 /*@}*/ 168 169 170 /** 171 * Selected limits copied from gl_constants 172 * 173 * These are limits from the GL context, but various bits in the program 174 * must be validated against these values. 175 */ 176 /*@{*/ 177 unsigned MaxTextureCoordUnits; 178 unsigned MaxTextureImageUnits; 179 unsigned MaxTextureUnits; 180 unsigned MaxClipPlanes; 181 unsigned MaxLights; 182 unsigned MaxProgramMatrices; 183 unsigned MaxDrawBuffers; 184 /*@}*/ 185 186 /** 187 * Value to use in state vector accessors for environment and local 188 * parameters 189 */ 190 unsigned state_param_enum_env; 191 unsigned state_param_enum_local; 192 193 194 /** 195 * Input attributes bound to specific names 196 * 197 * This is only needed so that errors can be properly produced when 198 * multiple ATTRIB statements bind illegal combinations of vertex 199 * attributes. 200 */ 201 GLbitfield64 InputsBound; 202 203 enum { 204 invalid_mode = 0, 205 ARB_vertex, 206 ARB_fragment 207 } mode; 208 209 struct { 210 unsigned PositionInvariant:1; 211 unsigned Fog:2; /* gl_fog_mode */ 212 unsigned PrecisionHint:2; 213 unsigned DrawBuffers:1; 214 unsigned Shadow:1; 215 unsigned TexRect:1; 216 unsigned TexArray:1; 217 unsigned OriginUpperLeft:1; 218 unsigned PixelCenterInteger:1; 219 } option; 220 221 struct { 222 unsigned UsesKill:1; 223 } fragment; 224 }; 225 226 #define OPTION_NICEST 1 227 #define OPTION_FASTEST 2 228 229 typedef struct YYLTYPE { 230 int first_line; 231 int first_column; 232 int last_line; 233 int last_column; 234 int position; 235 } YYLTYPE; 236 237 #define YYLTYPE_IS_DECLARED 1 238 #define YYLTYPE_IS_TRIVIAL 1 239 240 241 extern GLboolean _mesa_parse_arb_program(struct gl_context *ctx, GLenum target, 242 const GLubyte *str, GLsizei len, struct asm_parser_state *state); 243 244 245 246 /* From program_lexer.l. */ 247 extern void _mesa_program_lexer_dtor(void *scanner); 248 249 extern void _mesa_program_lexer_ctor(void **scanner, 250 struct asm_parser_state *state, const char *string, size_t len); 251 252 253 /** 254 *\name From program_parse_extra.c 255 */ 256 /*@{*/ 257 258 /** 259 * Parses and processes an option string to an ARB vertex program 260 * 261 * \return 262 * Non-zero on success, zero on failure. 263 */ 264 extern int _mesa_ARBvp_parse_option(struct asm_parser_state *state, 265 const char *option); 266 267 /** 268 * Parses and processes an option string to an ARB fragment program 269 * 270 * \return 271 * Non-zero on success, zero on failure. 272 */ 273 extern int _mesa_ARBfp_parse_option(struct asm_parser_state *state, 274 const char *option); 275 276 /** 277 * Parses and processes instruction suffixes 278 * 279 * Instruction suffixes, such as \c _SAT, are processed. The relevant bits 280 * are set in \c inst. If suffixes are encountered that are either not known 281 * or not supported by the modes and options set in \c state, zero will be 282 * returned. 283 * 284 * \return 285 * Non-zero on success, zero on failure. 286 */ 287 extern int _mesa_parse_instruction_suffix(const struct asm_parser_state *state, 288 const char *suffix, struct prog_instruction *inst); 289 290 /*@}*/ 291 292 #endif /* PROGRAM_PARSER_H */ 293