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