Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 1 | %{ |
| 2 | /* |
| 3 | * Copyright © 2009 Intel Corporation |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the next |
| 13 | * paragraph) shall be included in all copies or substantial portions of the |
| 14 | * Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | |
| 28 | #include "main/mtypes.h" |
| 29 | #include "prog_parameter.h" |
| 30 | #include "prog_parameter_layout.h" |
| 31 | #include "prog_statevars.h" |
| 32 | #include "prog_instruction.h" |
| 33 | |
| 34 | #include "symbol_table.h" |
| 35 | #include "program_parser.h" |
| 36 | |
| 37 | extern void *yy_scan_string(char *); |
| 38 | extern void yy_delete_buffer(void *); |
| 39 | |
| 40 | static struct asm_symbol *declare_variable(struct asm_parser_state *state, |
| 41 | char *name, enum asm_type t, struct YYLTYPE *locp); |
| 42 | |
| 43 | static int initialize_symbol_from_state(struct gl_program *prog, |
| 44 | struct asm_symbol *param_var, const gl_state_index tokens[STATE_LENGTH]); |
| 45 | |
| 46 | static int initialize_symbol_from_param(struct gl_program *prog, |
| 47 | struct asm_symbol *param_var, const gl_state_index tokens[STATE_LENGTH]); |
| 48 | |
| 49 | static int initialize_symbol_from_const(struct gl_program *prog, |
| 50 | struct asm_symbol *param_var, const struct asm_vector *vec); |
| 51 | |
| 52 | static int yyparse(struct asm_parser_state *state); |
| 53 | |
| 54 | static void yyerror(struct YYLTYPE *locp, struct asm_parser_state *state, |
| 55 | const char *s); |
| 56 | |
| 57 | static int validate_inputs(struct YYLTYPE *locp, |
| 58 | struct asm_parser_state *state); |
| 59 | |
| 60 | static void init_dst_reg(struct prog_dst_register *r); |
| 61 | |
| 62 | static void init_src_reg(struct asm_src_register *r); |
| 63 | |
| 64 | static struct asm_instruction *asm_instruction_ctor(gl_inst_opcode op, |
| 65 | const struct prog_dst_register *dst, const struct asm_src_register *src0, |
| 66 | const struct asm_src_register *src1, const struct asm_src_register *src2); |
| 67 | |
| 68 | #ifndef FALSE |
| 69 | #define FALSE 0 |
| 70 | #define TRUE (!FALSE) |
| 71 | #endif |
| 72 | |
| 73 | #define YYLLOC_DEFAULT(Current, Rhs, N) \ |
| 74 | do { \ |
| 75 | if (YYID(N)) { \ |
| 76 | (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \ |
| 77 | (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \ |
| 78 | (Current).position = YYRHSLOC(Rhs, 1).position; \ |
| 79 | (Current).last_line = YYRHSLOC(Rhs, N).last_line; \ |
| 80 | (Current).last_column = YYRHSLOC(Rhs, N).last_column; \ |
| 81 | } else { \ |
| 82 | (Current).first_line = YYRHSLOC(Rhs, 0).last_line; \ |
| 83 | (Current).last_line = (Current).first_line; \ |
| 84 | (Current).first_column = YYRHSLOC(Rhs, 0).last_column; \ |
| 85 | (Current).last_column = (Current).first_column; \ |
| 86 | (Current).position = YYRHSLOC(Rhs, 0).position \ |
| 87 | + (Current).first_column; \ |
| 88 | } \ |
| 89 | } while(YYID(0)) |
| 90 | |
| 91 | #define YYLEX_PARAM state->scanner |
| 92 | %} |
| 93 | |
| 94 | %pure-parser |
| 95 | %locations |
| 96 | %parse-param { struct asm_parser_state *state } |
| 97 | %error-verbose |
| 98 | %lex-param { void *scanner } |
| 99 | |
| 100 | %union { |
| 101 | struct asm_instruction *inst; |
| 102 | struct asm_symbol *sym; |
| 103 | struct asm_symbol temp_sym; |
| 104 | struct asm_swizzle_mask swiz_mask; |
| 105 | struct asm_src_register src_reg; |
| 106 | struct prog_dst_register dst_reg; |
| 107 | struct prog_instruction temp_inst; |
| 108 | char *string; |
| 109 | unsigned result; |
| 110 | unsigned attrib; |
| 111 | int integer; |
| 112 | float real; |
| 113 | unsigned state[5]; |
| 114 | int negate; |
| 115 | struct asm_vector vector; |
| 116 | gl_inst_opcode opcode; |
| 117 | } |
| 118 | |
| 119 | %token ARBvp_10 ARBfp_10 |
| 120 | |
| 121 | /* Tokens for assembler pseudo-ops */ |
| 122 | %token <integer> ADDRESS |
| 123 | %token ALIAS ATTRIB |
| 124 | %token OPTION OUTPUT |
| 125 | %token PARAM |
| 126 | %token <integer> TEMP |
| 127 | %token END |
| 128 | |
| 129 | /* Tokens for instructions */ |
| 130 | %token <temp_inst> BIN_OP BINSC_OP SAMPLE_OP SCALAR_OP TRI_OP VECTOR_OP |
| 131 | %token <temp_inst> ARL KIL SWZ |
| 132 | |
| 133 | %token <integer> INTEGER |
| 134 | %token <real> REAL |
| 135 | |
| 136 | %token AMBIENT ATTENUATION |
| 137 | %token BACK |
| 138 | %token CLIP COLOR |
| 139 | %token DEPTH DIFFUSE DIRECTION |
| 140 | %token EMISSION ENV EYE |
| 141 | %token FOG FOGCOORD FRAGMENT FRONT |
| 142 | %token HALF |
| 143 | %token INVERSE INVTRANS |
| 144 | %token LIGHT LIGHTMODEL LIGHTPROD LOCAL |
| 145 | %token MATERIAL MAT_PROGRAM MATRIX MATRIXINDEX MODELVIEW MVP |
| 146 | %token NORMAL |
| 147 | %token OBJECT |
| 148 | %token PALETTE PARAMS PLANE POINT POINTSIZE POSITION PRIMARY PROGRAM PROJECTION |
| 149 | %token RANGE RESULT ROW |
| 150 | %token SCENECOLOR SECONDARY SHININESS SIZE SPECULAR SPOT STATE |
| 151 | %token TEXCOORD TEXENV TEXGEN TEXGEN_Q TEXGEN_R TEXGEN_S TEXGEN_T TEXTURE TRANSPOSE |
| 152 | %token TEXTURE_UNIT TEX_1D TEX_2D TEX_3D TEX_CUBE TEX_RECT |
| 153 | %token VERTEX VTXATTRIB |
| 154 | %token WEIGHT |
| 155 | |
| 156 | %token <string> IDENTIFIER |
| 157 | %token <swiz_mask> MASK4 MASK3 MASK2 MASK1 SWIZZLE |
| 158 | %token DOT_DOT |
| 159 | %token DOT |
| 160 | |
| 161 | %type <inst> instruction ALU_instruction TexInstruction |
| 162 | %type <inst> ARL_instruction VECTORop_instruction |
| 163 | %type <inst> SCALARop_instruction BINSCop_instruction BINop_instruction |
| 164 | %type <inst> TRIop_instruction SWZ_instruction SAMPLE_instruction |
| 165 | %type <inst> KIL_instruction |
| 166 | |
| 167 | %type <dst_reg> dstReg maskedDstReg maskedAddrReg |
| 168 | %type <src_reg> srcReg scalarSrcReg swizzleSrcReg |
| 169 | %type <swiz_mask> scalarSuffix swizzleSuffix extendedSwizzle extSwizComp |
| 170 | %type <swiz_mask> optionalMask |
| 171 | %type <integer> extSwizSel |
| 172 | |
| 173 | %type <sym> progParamArray |
| 174 | %type <integer> addrRegRelOffset addrRegPosOffset addrRegNegOffset |
| 175 | %type <src_reg> progParamArrayMem progParamArrayAbs progParamArrayRel |
| 176 | %type <sym> addrReg |
| 177 | %type <swiz_mask> addrComponent addrWriteMask |
| 178 | |
| 179 | %type <result> resultBinding resultColBinding |
| 180 | %type <integer> optFaceType optColorType |
| 181 | %type <integer> optResultFaceType optResultColorType |
| 182 | |
| 183 | %type <integer> optTexImageUnitNum texImageUnitNum |
| 184 | %type <integer> optTexCoordUnitNum texCoordUnitNum |
| 185 | %type <integer> optLegacyTexUnitNum legacyTexUnitNum |
| 186 | %type <integer> texImageUnit texTarget |
| 187 | %type <integer> vtxAttribNum |
| 188 | |
| 189 | %type <attrib> attribBinding vtxAttribItem fragAttribItem |
| 190 | |
| 191 | %type <temp_sym> paramSingleInit paramSingleItemDecl |
| 192 | %type <integer> optArraySize |
| 193 | |
| 194 | %type <state> stateSingleItem stateMultipleItem |
| 195 | %type <state> stateMaterialItem |
| 196 | %type <state> stateLightItem stateLightModelItem stateLightProdItem |
| 197 | %type <state> stateTexGenItem stateFogItem stateClipPlaneItem statePointItem |
| 198 | %type <state> stateMatrixItem stateMatrixRow stateMatrixRows |
| 199 | %type <state> stateTexEnvItem |
| 200 | |
| 201 | %type <state> stateLModProperty |
| 202 | %type <state> stateMatrixName optMatrixRows |
| 203 | |
| 204 | %type <integer> stateMatProperty |
| 205 | %type <integer> stateLightProperty stateSpotProperty |
| 206 | %type <integer> stateLightNumber stateLProdProperty |
| 207 | %type <integer> stateTexGenType stateTexGenCoord |
| 208 | %type <integer> stateTexEnvProperty |
| 209 | %type <integer> stateFogProperty |
| 210 | %type <integer> stateClipPlaneNum |
| 211 | %type <integer> statePointProperty |
| 212 | |
| 213 | %type <integer> stateOptMatModifier stateMatModifier stateMatrixRowNum |
| 214 | %type <integer> stateOptModMatNum stateModMatNum statePaletteMatNum |
| 215 | %type <integer> stateProgramMatNum |
| 216 | |
| 217 | %type <integer> ambDiffSpecProperty |
| 218 | |
| 219 | %type <state> programSingleItem progEnvParam progLocalParam |
| 220 | %type <state> programMultipleItem progEnvParams progLocalParams |
| 221 | |
| 222 | %type <temp_sym> paramMultipleInit paramMultInitList paramMultipleItem |
| 223 | %type <temp_sym> paramSingleItemUse |
| 224 | |
| 225 | %type <integer> progEnvParamNum progLocalParamNum |
| 226 | %type <state> progEnvParamNums progLocalParamNums |
| 227 | |
| 228 | %type <vector> paramConstDecl paramConstUse |
| 229 | %type <vector> paramConstScalarDecl paramConstScalarUse paramConstVector |
| 230 | %type <real> signedFloatConstant |
| 231 | %type <negate> optionalSign |
| 232 | |
| 233 | %{ |
| 234 | extern int yylex(YYSTYPE *yylval_param, YYLTYPE *yylloc_param, |
| 235 | void *yyscanner); |
| 236 | %} |
| 237 | |
| 238 | %% |
| 239 | |
| 240 | program: language optionSequence statementSequence END |
| 241 | ; |
| 242 | |
| 243 | language: ARBvp_10 |
| 244 | { |
| 245 | if (state->prog->Target != GL_VERTEX_PROGRAM_ARB) { |
| 246 | yyerror(& @1, state, "invalid fragment program header"); |
| 247 | |
| 248 | } |
| 249 | state->mode = ARB_vertex; |
| 250 | } |
| 251 | | ARBfp_10 |
| 252 | { |
| 253 | if (state->prog->Target != GL_FRAGMENT_PROGRAM_ARB) { |
| 254 | yyerror(& @1, state, "invalid vertex program header"); |
| 255 | } |
| 256 | state->mode = ARB_fragment; |
| 257 | } |
| 258 | ; |
| 259 | |
| 260 | optionSequence: optionSequence option |
| 261 | | |
| 262 | ; |
| 263 | |
| 264 | option: OPTION IDENTIFIER ';' |
| 265 | { |
| 266 | int valid = 0; |
| 267 | |
| 268 | if (state->mode == ARB_vertex) { |
| 269 | valid = _mesa_ARBvp_parse_option(state, $2); |
| 270 | } else if (state->mode == ARB_fragment) { |
| 271 | valid = _mesa_ARBfp_parse_option(state, $2); |
| 272 | } |
| 273 | |
| 274 | |
| 275 | if (!valid) { |
| 276 | yyerror(& @2, state, "invalid option string"); |
| 277 | YYERROR; |
| 278 | } |
| 279 | } |
| 280 | ; |
| 281 | |
| 282 | statementSequence: statementSequence statement |
| 283 | | |
| 284 | ; |
| 285 | |
| 286 | statement: instruction ';' |
| 287 | { |
| 288 | if ($1 != NULL) { |
| 289 | if (state->inst_tail == NULL) { |
| 290 | state->inst_head = $1; |
| 291 | } else { |
| 292 | state->inst_tail->next = $1; |
| 293 | } |
| 294 | |
| 295 | state->inst_tail = $1; |
| 296 | $1->next = NULL; |
| 297 | |
| 298 | state->prog->NumInstructions++; |
| 299 | } |
| 300 | } |
| 301 | | namingStatement ';' |
| 302 | ; |
| 303 | |
| 304 | instruction: ALU_instruction |
Ian Romanick | 0db5ef0 | 2009-07-22 16:21:54 -0700 | [diff] [blame^] | 305 | { |
| 306 | $$ = $1; |
| 307 | state->prog->NumAluInstructions++; |
| 308 | } |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 309 | | TexInstruction |
Ian Romanick | 0db5ef0 | 2009-07-22 16:21:54 -0700 | [diff] [blame^] | 310 | { |
| 311 | $$ = $1; |
| 312 | state->prog->NumTexInstructions++; |
| 313 | } |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 314 | ; |
| 315 | |
| 316 | ALU_instruction: ARL_instruction |
| 317 | | VECTORop_instruction |
| 318 | | SCALARop_instruction |
| 319 | | BINSCop_instruction |
| 320 | | BINop_instruction |
| 321 | | TRIop_instruction |
| 322 | | SWZ_instruction |
| 323 | ; |
| 324 | |
| 325 | TexInstruction: SAMPLE_instruction |
| 326 | | KIL_instruction |
| 327 | ; |
| 328 | |
| 329 | ARL_instruction: ARL maskedAddrReg ',' scalarSrcReg |
| 330 | { |
| 331 | $$ = asm_instruction_ctor(OPCODE_ARL, & $2, & $4, NULL, NULL); |
| 332 | } |
| 333 | ; |
| 334 | |
| 335 | VECTORop_instruction: VECTOR_OP maskedDstReg ',' swizzleSrcReg |
| 336 | { |
| 337 | $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL); |
| 338 | $$->Base.SaturateMode = $1.SaturateMode; |
| 339 | } |
| 340 | ; |
| 341 | |
| 342 | SCALARop_instruction: SCALAR_OP maskedDstReg ',' scalarSrcReg |
| 343 | { |
| 344 | $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL); |
| 345 | $$->Base.SaturateMode = $1.SaturateMode; |
| 346 | } |
| 347 | ; |
| 348 | |
| 349 | BINSCop_instruction: BINSC_OP maskedDstReg ',' scalarSrcReg ',' scalarSrcReg |
| 350 | { |
| 351 | $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, NULL); |
| 352 | $$->Base.SaturateMode = $1.SaturateMode; |
| 353 | } |
| 354 | ; |
| 355 | |
| 356 | |
| 357 | BINop_instruction: BIN_OP maskedDstReg ',' swizzleSrcReg ',' swizzleSrcReg |
| 358 | { |
| 359 | $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, NULL); |
| 360 | $$->Base.SaturateMode = $1.SaturateMode; |
| 361 | } |
| 362 | ; |
| 363 | |
| 364 | TRIop_instruction: TRI_OP maskedDstReg ',' |
| 365 | swizzleSrcReg ',' swizzleSrcReg ',' swizzleSrcReg |
| 366 | { |
| 367 | $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, & $8); |
| 368 | $$->Base.SaturateMode = $1.SaturateMode; |
| 369 | } |
| 370 | ; |
| 371 | |
| 372 | SAMPLE_instruction: SAMPLE_OP maskedDstReg ',' swizzleSrcReg ',' texImageUnit ',' texTarget |
| 373 | { |
| 374 | $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL); |
| 375 | if ($$ != NULL) { |
| 376 | $$->Base.SaturateMode = $1.SaturateMode; |
| 377 | $$->Base.TexSrcUnit = $6; |
| 378 | $$->Base.TexSrcTarget = $8; |
Ian Romanick | 0db5ef0 | 2009-07-22 16:21:54 -0700 | [diff] [blame^] | 379 | |
| 380 | state->prog->TexturesUsed[$6] |= (1U << $8); |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | ; |
| 384 | |
| 385 | KIL_instruction: KIL swizzleSrcReg |
| 386 | { |
| 387 | $$ = asm_instruction_ctor(OPCODE_KIL, NULL, & $2, NULL, NULL); |
Ian Romanick | 0db5ef0 | 2009-07-22 16:21:54 -0700 | [diff] [blame^] | 388 | state->fragment.UsesKill = 1; |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 389 | } |
| 390 | ; |
| 391 | |
| 392 | texImageUnit: TEXTURE_UNIT optTexImageUnitNum |
| 393 | { |
| 394 | $$ = $2; |
| 395 | } |
| 396 | ; |
| 397 | |
| 398 | texTarget: TEX_1D { $$ = TEXTURE_1D_INDEX; } |
| 399 | | TEX_2D { $$ = TEXTURE_2D_INDEX; } |
| 400 | | TEX_3D { $$ = TEXTURE_3D_INDEX; } |
| 401 | | TEX_CUBE { $$ = TEXTURE_CUBE_INDEX; } |
| 402 | | TEX_RECT { $$ = TEXTURE_RECT_INDEX; } |
| 403 | ; |
| 404 | |
| 405 | SWZ_instruction: SWZ maskedDstReg ',' srcReg ',' extendedSwizzle |
| 406 | { |
| 407 | /* FIXME: Is this correct? Should the extenedSwizzle be applied |
| 408 | * FIXME: to the existing swizzle? |
| 409 | */ |
| 410 | $4.Base.Swizzle = $6.swizzle; |
| 411 | |
| 412 | $$ = asm_instruction_ctor(OPCODE_SWZ, & $2, & $4, NULL, NULL); |
| 413 | $$->Base.SaturateMode = $1.SaturateMode; |
| 414 | } |
| 415 | ; |
| 416 | |
| 417 | scalarSrcReg: optionalSign srcReg scalarSuffix |
| 418 | { |
| 419 | $$ = $2; |
| 420 | |
| 421 | if ($1) { |
| 422 | $$.Base.Negate = ~$$.Base.Negate; |
| 423 | } |
| 424 | |
| 425 | $$.Base.Swizzle = _mesa_combine_swizzles($$.Base.Swizzle, |
| 426 | $3.swizzle); |
| 427 | } |
| 428 | ; |
| 429 | |
| 430 | swizzleSrcReg: optionalSign srcReg swizzleSuffix |
| 431 | { |
| 432 | $$ = $2; |
| 433 | |
| 434 | if ($1) { |
| 435 | $$.Base.Negate = ~$$.Base.Negate; |
| 436 | } |
| 437 | |
| 438 | $$.Base.Swizzle = _mesa_combine_swizzles($$.Base.Swizzle, |
| 439 | $3.swizzle); |
| 440 | } |
| 441 | ; |
| 442 | |
| 443 | maskedDstReg: dstReg optionalMask |
| 444 | { |
| 445 | $$ = $1; |
| 446 | $$.WriteMask = $2.mask; |
| 447 | |
| 448 | if ($$.File == PROGRAM_OUTPUT) { |
| 449 | /* Technically speaking, this should check that it is in |
| 450 | * vertex program mode. However, PositionInvariant can never be |
| 451 | * set in fragment program mode, so it is somewhat irrelevant. |
| 452 | */ |
| 453 | if (state->option.PositionInvariant |
| 454 | && ($$.Index == VERT_RESULT_HPOS)) { |
| 455 | yyerror(& @1, state, "position-invariant programs cannot " |
| 456 | "write position"); |
| 457 | YYERROR; |
| 458 | } |
| 459 | |
| 460 | state->prog->OutputsWritten |= (1U << $$.Index); |
| 461 | } |
| 462 | } |
| 463 | ; |
| 464 | |
| 465 | maskedAddrReg: addrReg addrWriteMask |
| 466 | { |
| 467 | init_dst_reg(& $$); |
| 468 | $$.File = PROGRAM_ADDRESS; |
| 469 | $$.Index = 0; |
| 470 | $$.WriteMask = $2.mask; |
| 471 | } |
| 472 | ; |
| 473 | |
| 474 | extendedSwizzle: extSwizComp ',' extSwizComp ',' extSwizComp ',' extSwizComp |
| 475 | { |
| 476 | $$.swizzle = MAKE_SWIZZLE4($1.swizzle, $3.swizzle, |
| 477 | $5.swizzle, $7.swizzle); |
| 478 | $$.mask = ($1.mask) | ($3.mask << 1) | ($5.mask << 2) |
| 479 | | ($7.mask << 3); |
| 480 | } |
| 481 | ; |
| 482 | |
| 483 | extSwizComp: optionalSign extSwizSel |
| 484 | { |
| 485 | $$.swizzle = $2; |
| 486 | $$.mask = ($1) ? 1 : 0; |
| 487 | } |
| 488 | ; |
| 489 | |
| 490 | extSwizSel: INTEGER |
| 491 | { |
| 492 | if (($1 != 0) && ($1 != 1)) { |
| 493 | yyerror(& @1, state, "invalid extended swizzle selector"); |
| 494 | YYERROR; |
| 495 | } |
| 496 | |
| 497 | $$ = ($1 == 0) ? SWIZZLE_ZERO : SWIZZLE_ONE; |
| 498 | } |
| 499 | | IDENTIFIER |
| 500 | { |
| 501 | if (strlen($1) > 1) { |
| 502 | yyerror(& @1, state, "invalid extended swizzle selector"); |
| 503 | YYERROR; |
| 504 | } |
| 505 | |
| 506 | switch ($1[0]) { |
| 507 | case 'x': |
| 508 | $$ = SWIZZLE_X; |
| 509 | break; |
| 510 | case 'y': |
| 511 | $$ = SWIZZLE_Y; |
| 512 | break; |
| 513 | case 'z': |
| 514 | $$ = SWIZZLE_Z; |
| 515 | break; |
| 516 | case 'w': |
| 517 | $$ = SWIZZLE_W; |
| 518 | break; |
| 519 | default: |
| 520 | yyerror(& @1, state, "invalid extended swizzle selector"); |
| 521 | YYERROR; |
| 522 | break; |
| 523 | } |
| 524 | } |
| 525 | ; |
| 526 | |
| 527 | srcReg: IDENTIFIER /* temporaryReg | progParamSingle */ |
| 528 | { |
| 529 | struct asm_symbol *const s = (struct asm_symbol *) |
| 530 | _mesa_symbol_table_find_symbol(state->st, 0, $1); |
| 531 | |
| 532 | if (s == NULL) { |
| 533 | yyerror(& @1, state, "invalid operand variable"); |
| 534 | YYERROR; |
| 535 | } else if ((s->type != at_param) && (s->type != at_temp) |
| 536 | && (s->type != at_attrib)) { |
| 537 | yyerror(& @1, state, "invalid operand variable"); |
| 538 | YYERROR; |
| 539 | } else if ((s->type == at_param) && s->param_is_array) { |
| 540 | yyerror(& @1, state, "non-array access to array PARAM"); |
| 541 | YYERROR; |
| 542 | } |
| 543 | |
| 544 | init_src_reg(& $$); |
| 545 | switch (s->type) { |
| 546 | case at_temp: |
| 547 | $$.Base.File = PROGRAM_TEMPORARY; |
| 548 | $$.Base.Index = s->temp_binding; |
| 549 | break; |
| 550 | case at_param: |
| 551 | $$.Base.File = s->param_binding_type; |
| 552 | $$.Base.Index = s->param_binding_begin; |
| 553 | break; |
| 554 | case at_attrib: |
| 555 | $$.Base.File = PROGRAM_INPUT; |
| 556 | $$.Base.Index = s->attrib_binding; |
| 557 | state->prog->InputsRead |= (1U << $$.Base.Index); |
| 558 | |
| 559 | if (!validate_inputs(& @1, state)) { |
| 560 | YYERROR; |
| 561 | } |
| 562 | break; |
| 563 | |
| 564 | default: |
| 565 | YYERROR; |
| 566 | break; |
| 567 | } |
| 568 | } |
| 569 | | attribBinding |
| 570 | { |
| 571 | init_src_reg(& $$); |
| 572 | $$.Base.File = PROGRAM_INPUT; |
| 573 | $$.Base.Index = $1; |
| 574 | state->prog->InputsRead |= (1U << $$.Base.Index); |
| 575 | |
| 576 | if (!validate_inputs(& @1, state)) { |
| 577 | YYERROR; |
| 578 | } |
| 579 | } |
| 580 | | progParamArray '[' progParamArrayMem ']' |
| 581 | { |
| 582 | if (! $3.Base.RelAddr |
| 583 | && ($3.Base.Index >= $1->param_binding_length)) { |
| 584 | yyerror(& @3, state, "out of bounds array access"); |
| 585 | YYERROR; |
| 586 | } |
| 587 | |
| 588 | init_src_reg(& $$); |
| 589 | $$.Base.File = $1->param_binding_type; |
| 590 | |
| 591 | if ($3.Base.RelAddr) { |
| 592 | $1->param_accessed_indirectly = 1; |
| 593 | |
| 594 | $$.Base.RelAddr = 1; |
| 595 | $$.Base.Index = $3.Base.Index; |
| 596 | $$.Symbol = $1; |
| 597 | } else { |
| 598 | $$.Base.Index = $1->param_binding_begin + $3.Base.Index; |
| 599 | } |
| 600 | } |
| 601 | | paramSingleItemUse |
| 602 | { |
| 603 | init_src_reg(& $$); |
Ian Romanick | 69d3d19 | 2009-07-22 10:51:18 -0700 | [diff] [blame] | 604 | $$.Base.File = ($1.name != NULL) |
| 605 | ? $1.param_binding_type |
| 606 | : PROGRAM_CONSTANT; |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 607 | $$.Base.Index = $1.param_binding_begin; |
| 608 | } |
| 609 | ; |
| 610 | |
| 611 | dstReg: resultBinding |
| 612 | { |
| 613 | init_dst_reg(& $$); |
| 614 | $$.File = PROGRAM_OUTPUT; |
| 615 | $$.Index = $1; |
| 616 | } |
| 617 | | IDENTIFIER /* temporaryReg | vertexResultReg */ |
| 618 | { |
| 619 | struct asm_symbol *const s = (struct asm_symbol *) |
| 620 | _mesa_symbol_table_find_symbol(state->st, 0, $1); |
| 621 | |
| 622 | if (s == NULL) { |
| 623 | yyerror(& @1, state, "invalid operand variable"); |
| 624 | YYERROR; |
| 625 | } else if ((s->type != at_output) && (s->type != at_temp)) { |
| 626 | yyerror(& @1, state, "invalid operand variable"); |
| 627 | YYERROR; |
| 628 | } |
| 629 | |
| 630 | init_dst_reg(& $$); |
| 631 | if (s->type == at_temp) { |
| 632 | $$.File = PROGRAM_TEMPORARY; |
| 633 | $$.Index = s->temp_binding; |
| 634 | } else { |
| 635 | $$.File = s->param_binding_type; |
| 636 | $$.Index = s->param_binding_begin; |
| 637 | } |
| 638 | } |
| 639 | ; |
| 640 | |
| 641 | progParamArray: IDENTIFIER |
| 642 | { |
| 643 | struct asm_symbol *const s = (struct asm_symbol *) |
| 644 | _mesa_symbol_table_find_symbol(state->st, 0, $1); |
| 645 | |
| 646 | if (s == NULL) { |
| 647 | yyerror(& @1, state, "invalid operand variable"); |
| 648 | YYERROR; |
| 649 | } else if ((s->type != at_param) || !s->param_is_array) { |
| 650 | yyerror(& @1, state, "array access to non-PARAM variable"); |
| 651 | YYERROR; |
| 652 | } else { |
| 653 | $$ = s; |
| 654 | } |
| 655 | } |
| 656 | ; |
| 657 | |
| 658 | progParamArrayMem: progParamArrayAbs | progParamArrayRel; |
| 659 | |
| 660 | progParamArrayAbs: INTEGER |
| 661 | { |
| 662 | init_src_reg(& $$); |
| 663 | $$.Base.Index = $1; |
| 664 | } |
| 665 | ; |
| 666 | |
| 667 | progParamArrayRel: addrReg addrComponent addrRegRelOffset |
| 668 | { |
| 669 | /* FINISHME: Add support for multiple address registers. |
| 670 | */ |
| 671 | /* FINISHME: Add support for 4-component address registers. |
| 672 | */ |
| 673 | init_src_reg(& $$); |
| 674 | $$.Base.RelAddr = 1; |
| 675 | $$.Base.Index = $3; |
| 676 | } |
| 677 | ; |
| 678 | |
| 679 | addrRegRelOffset: { $$ = 0; } |
| 680 | | '+' addrRegPosOffset { $$ = $2; } |
| 681 | | '-' addrRegNegOffset { $$ = -$2; } |
| 682 | ; |
| 683 | |
| 684 | addrRegPosOffset: INTEGER |
| 685 | { |
| 686 | if (($1 < 0) || ($1 > 63)) { |
| 687 | yyerror(& @1, state, |
| 688 | "relative address offset too large (positive)"); |
| 689 | YYERROR; |
| 690 | } else { |
| 691 | $$ = $1; |
| 692 | } |
| 693 | } |
| 694 | ; |
| 695 | |
| 696 | addrRegNegOffset: INTEGER |
| 697 | { |
| 698 | if (($1 < 0) || ($1 > 64)) { |
| 699 | yyerror(& @1, state, |
| 700 | "relative address offset too large (negative)"); |
| 701 | YYERROR; |
| 702 | } else { |
| 703 | $$ = $1; |
| 704 | } |
| 705 | } |
| 706 | ; |
| 707 | |
| 708 | addrReg: IDENTIFIER |
| 709 | { |
| 710 | struct asm_symbol *const s = (struct asm_symbol *) |
| 711 | _mesa_symbol_table_find_symbol(state->st, 0, $1); |
| 712 | |
| 713 | if (s == NULL) { |
| 714 | yyerror(& @1, state, "invalid array member"); |
| 715 | YYERROR; |
| 716 | } else if (s->type != at_address) { |
| 717 | yyerror(& @1, state, |
| 718 | "invalid variable for indexed array access"); |
| 719 | YYERROR; |
| 720 | } else { |
| 721 | $$ = s; |
| 722 | } |
| 723 | } |
| 724 | ; |
| 725 | |
| 726 | addrComponent: MASK1 |
| 727 | { |
| 728 | if ($1.mask != WRITEMASK_X) { |
| 729 | yyerror(& @1, state, "invalid address component selector"); |
| 730 | YYERROR; |
| 731 | } else { |
| 732 | $$ = $1; |
| 733 | } |
| 734 | } |
| 735 | ; |
| 736 | |
| 737 | addrWriteMask: MASK1 |
| 738 | { |
| 739 | if ($1.mask != WRITEMASK_X) { |
| 740 | yyerror(& @1, state, |
| 741 | "address register write mask must be \".x\""); |
| 742 | YYERROR; |
| 743 | } else { |
| 744 | $$ = $1; |
| 745 | } |
| 746 | } |
| 747 | ; |
| 748 | |
| 749 | scalarSuffix: MASK1; |
| 750 | |
| 751 | swizzleSuffix: MASK1 |
| 752 | | MASK4 |
| 753 | | SWIZZLE |
| 754 | | { $$.swizzle = SWIZZLE_NOOP; $$.mask = WRITEMASK_XYZW; } |
| 755 | ; |
| 756 | |
| 757 | optionalMask: MASK4 | MASK3 | MASK2 | MASK1 |
| 758 | | { $$.swizzle = SWIZZLE_NOOP; $$.mask = WRITEMASK_XYZW; } |
| 759 | ; |
| 760 | |
| 761 | namingStatement: ATTRIB_statement |
| 762 | | PARAM_statement |
| 763 | | TEMP_statement |
| 764 | | ADDRESS_statement |
| 765 | | OUTPUT_statement |
| 766 | | ALIAS_statement |
| 767 | ; |
| 768 | |
| 769 | ATTRIB_statement: ATTRIB IDENTIFIER '=' attribBinding |
| 770 | { |
| 771 | struct asm_symbol *const s = |
| 772 | declare_variable(state, $2, at_attrib, & @2); |
| 773 | |
| 774 | if (s == NULL) { |
| 775 | YYERROR; |
| 776 | } else { |
| 777 | s->attrib_binding = $4; |
| 778 | state->InputsBound |= (1U << s->attrib_binding); |
| 779 | |
| 780 | if (!validate_inputs(& @4, state)) { |
| 781 | YYERROR; |
| 782 | } |
| 783 | } |
| 784 | } |
| 785 | ; |
| 786 | |
| 787 | attribBinding: VERTEX vtxAttribItem |
| 788 | { |
| 789 | $$ = $2; |
| 790 | } |
| 791 | | FRAGMENT fragAttribItem |
| 792 | { |
| 793 | $$ = $2; |
| 794 | } |
| 795 | ; |
| 796 | |
| 797 | vtxAttribItem: POSITION |
| 798 | { |
| 799 | $$ = VERT_ATTRIB_POS; |
| 800 | } |
| 801 | | WEIGHT vtxOptWeightNum |
| 802 | { |
| 803 | $$ = VERT_ATTRIB_WEIGHT; |
| 804 | } |
| 805 | | NORMAL |
| 806 | { |
| 807 | $$ = VERT_ATTRIB_NORMAL; |
| 808 | } |
| 809 | | COLOR optColorType |
| 810 | { |
| 811 | $$ = VERT_ATTRIB_COLOR0 + $2; |
| 812 | } |
| 813 | | FOGCOORD |
| 814 | { |
| 815 | $$ = VERT_ATTRIB_FOG; |
| 816 | } |
| 817 | | TEXCOORD optTexCoordUnitNum |
| 818 | { |
| 819 | $$ = VERT_ATTRIB_TEX0 + $2; |
| 820 | } |
| 821 | | MATRIXINDEX '[' vtxWeightNum ']' |
| 822 | { |
| 823 | YYERROR; |
| 824 | } |
| 825 | | VTXATTRIB '[' vtxAttribNum ']' |
| 826 | { |
| 827 | $$ = VERT_ATTRIB_GENERIC0 + $3; |
| 828 | } |
| 829 | ; |
| 830 | |
| 831 | vtxAttribNum: INTEGER |
| 832 | { |
| 833 | if ($1 >= state->limits->MaxAttribs) { |
| 834 | yyerror(& @1, state, "invalid vertex attribute reference"); |
| 835 | YYERROR; |
| 836 | } |
| 837 | |
| 838 | $$ = $1; |
| 839 | } |
| 840 | ; |
| 841 | |
| 842 | vtxOptWeightNum: | '[' vtxWeightNum ']'; |
| 843 | vtxWeightNum: INTEGER; |
| 844 | |
| 845 | fragAttribItem: POSITION |
| 846 | { |
| 847 | $$ = FRAG_ATTRIB_WPOS; |
| 848 | } |
| 849 | | COLOR optColorType |
| 850 | { |
| 851 | $$ = FRAG_ATTRIB_COL0 + $2; |
| 852 | } |
| 853 | | FOGCOORD |
| 854 | { |
| 855 | $$ = FRAG_ATTRIB_FOGC; |
| 856 | } |
| 857 | | TEXCOORD optTexCoordUnitNum |
| 858 | { |
| 859 | $$ = FRAG_ATTRIB_TEX0 + $2; |
| 860 | } |
| 861 | ; |
| 862 | |
| 863 | PARAM_statement: PARAM_singleStmt | PARAM_multipleStmt; |
| 864 | |
| 865 | PARAM_singleStmt: PARAM IDENTIFIER paramSingleInit |
| 866 | { |
| 867 | struct asm_symbol *const s = |
| 868 | declare_variable(state, $2, at_param, & @2); |
| 869 | |
| 870 | if (s == NULL) { |
| 871 | YYERROR; |
| 872 | } else { |
| 873 | s->param_binding_type = $3.param_binding_type; |
| 874 | s->param_binding_begin = $3.param_binding_begin; |
| 875 | s->param_binding_length = $3.param_binding_length; |
| 876 | s->param_is_array = 0; |
| 877 | } |
| 878 | } |
| 879 | ; |
| 880 | |
| 881 | PARAM_multipleStmt: PARAM IDENTIFIER '[' optArraySize ']' paramMultipleInit |
| 882 | { |
| 883 | if (($4 != 0) && ($4 != $6.param_binding_length)) { |
| 884 | yyerror(& @4, state, |
| 885 | "parameter array size and number of bindings must match"); |
| 886 | YYERROR; |
| 887 | } else { |
| 888 | struct asm_symbol *const s = |
| 889 | declare_variable(state, $2, $6.type, & @2); |
| 890 | |
| 891 | if (s == NULL) { |
| 892 | YYERROR; |
| 893 | } else { |
| 894 | s->param_binding_type = $6.param_binding_type; |
| 895 | s->param_binding_begin = $6.param_binding_begin; |
| 896 | s->param_binding_length = $6.param_binding_length; |
| 897 | s->param_is_array = 1; |
| 898 | } |
| 899 | } |
| 900 | } |
| 901 | ; |
| 902 | |
| 903 | optArraySize: |
| 904 | { |
| 905 | $$ = 0; |
| 906 | } |
| 907 | | INTEGER |
| 908 | { |
| 909 | if (($1 < 1) || ($1 >= state->limits->MaxParameters)) { |
| 910 | yyerror(& @1, state, "invalid parameter array size"); |
| 911 | YYERROR; |
| 912 | } else { |
| 913 | $$ = $1; |
| 914 | } |
| 915 | } |
| 916 | ; |
| 917 | |
| 918 | paramSingleInit: '=' paramSingleItemDecl |
| 919 | { |
| 920 | $$ = $2; |
| 921 | } |
| 922 | ; |
| 923 | |
| 924 | paramMultipleInit: '=' '{' paramMultInitList '}' |
| 925 | { |
| 926 | $$ = $3; |
| 927 | } |
| 928 | ; |
| 929 | |
| 930 | paramMultInitList: paramMultipleItem |
| 931 | | paramMultInitList ',' paramMultipleItem |
| 932 | { |
| 933 | $1.param_binding_length += $3.param_binding_length; |
| 934 | $$ = $1; |
| 935 | } |
| 936 | ; |
| 937 | |
| 938 | paramSingleItemDecl: stateSingleItem |
| 939 | { |
| 940 | memset(& $$, 0, sizeof($$)); |
| 941 | $$.param_binding_begin = ~0; |
| 942 | initialize_symbol_from_state(state->prog, & $$, $1); |
| 943 | } |
| 944 | | programSingleItem |
| 945 | { |
| 946 | memset(& $$, 0, sizeof($$)); |
| 947 | $$.param_binding_begin = ~0; |
| 948 | initialize_symbol_from_param(state->prog, & $$, $1); |
| 949 | } |
| 950 | | paramConstDecl |
| 951 | { |
| 952 | memset(& $$, 0, sizeof($$)); |
| 953 | $$.param_binding_begin = ~0; |
| 954 | initialize_symbol_from_const(state->prog, & $$, & $1); |
| 955 | } |
| 956 | ; |
| 957 | |
| 958 | paramSingleItemUse: stateSingleItem |
| 959 | { |
| 960 | memset(& $$, 0, sizeof($$)); |
| 961 | $$.param_binding_begin = ~0; |
| 962 | initialize_symbol_from_state(state->prog, & $$, $1); |
| 963 | } |
| 964 | | programSingleItem |
| 965 | { |
| 966 | memset(& $$, 0, sizeof($$)); |
| 967 | $$.param_binding_begin = ~0; |
| 968 | initialize_symbol_from_param(state->prog, & $$, $1); |
| 969 | } |
| 970 | | paramConstUse |
| 971 | { |
| 972 | memset(& $$, 0, sizeof($$)); |
| 973 | $$.param_binding_begin = ~0; |
| 974 | initialize_symbol_from_const(state->prog, & $$, & $1); |
| 975 | } |
| 976 | ; |
| 977 | |
| 978 | paramMultipleItem: stateMultipleItem |
| 979 | { |
| 980 | memset(& $$, 0, sizeof($$)); |
| 981 | $$.param_binding_begin = ~0; |
| 982 | initialize_symbol_from_state(state->prog, & $$, $1); |
| 983 | } |
| 984 | | programMultipleItem |
| 985 | { |
| 986 | memset(& $$, 0, sizeof($$)); |
| 987 | $$.param_binding_begin = ~0; |
| 988 | initialize_symbol_from_param(state->prog, & $$, $1); |
| 989 | } |
| 990 | | paramConstDecl |
| 991 | { |
| 992 | memset(& $$, 0, sizeof($$)); |
| 993 | $$.param_binding_begin = ~0; |
| 994 | initialize_symbol_from_const(state->prog, & $$, & $1); |
| 995 | } |
| 996 | ; |
| 997 | |
| 998 | stateMultipleItem: stateSingleItem { memcpy($$, $1, sizeof($$)); } |
| 999 | | STATE stateMatrixRows { memcpy($$, $2, sizeof($$)); } |
| 1000 | ; |
| 1001 | |
| 1002 | stateSingleItem: STATE stateMaterialItem { memcpy($$, $2, sizeof($$)); } |
| 1003 | | STATE stateLightItem { memcpy($$, $2, sizeof($$)); } |
| 1004 | | STATE stateLightModelItem { memcpy($$, $2, sizeof($$)); } |
| 1005 | | STATE stateLightProdItem { memcpy($$, $2, sizeof($$)); } |
| 1006 | | STATE stateTexGenItem { memcpy($$, $2, sizeof($$)); } |
| 1007 | | STATE stateTexEnvItem { memcpy($$, $2, sizeof($$)); } |
| 1008 | | STATE stateFogItem { memcpy($$, $2, sizeof($$)); } |
| 1009 | | STATE stateClipPlaneItem { memcpy($$, $2, sizeof($$)); } |
| 1010 | | STATE statePointItem { memcpy($$, $2, sizeof($$)); } |
| 1011 | | STATE stateMatrixRow { memcpy($$, $2, sizeof($$)); } |
| 1012 | ; |
| 1013 | |
| 1014 | stateMaterialItem: MATERIAL optFaceType stateMatProperty |
| 1015 | { |
| 1016 | memset($$, 0, sizeof($$)); |
| 1017 | $$[0] = STATE_MATERIAL; |
| 1018 | $$[1] = $2; |
| 1019 | $$[2] = $3; |
| 1020 | } |
| 1021 | ; |
| 1022 | |
| 1023 | stateMatProperty: ambDiffSpecProperty |
| 1024 | { |
| 1025 | $$ = $1; |
| 1026 | } |
| 1027 | | EMISSION |
| 1028 | { |
| 1029 | $$ = STATE_EMISSION; |
| 1030 | } |
| 1031 | | SHININESS |
| 1032 | { |
| 1033 | $$ = STATE_SHININESS; |
| 1034 | } |
| 1035 | ; |
| 1036 | |
| 1037 | stateLightItem: LIGHT '[' stateLightNumber ']' stateLightProperty |
| 1038 | { |
| 1039 | memset($$, 0, sizeof($$)); |
| 1040 | $$[0] = STATE_LIGHT; |
| 1041 | $$[1] = $3; |
| 1042 | $$[2] = $5; |
| 1043 | } |
| 1044 | ; |
| 1045 | |
| 1046 | stateLightProperty: ambDiffSpecProperty |
| 1047 | { |
| 1048 | $$ = $1; |
| 1049 | } |
| 1050 | | POSITION |
| 1051 | { |
| 1052 | $$ = STATE_POSITION; |
| 1053 | } |
| 1054 | | ATTENUATION |
| 1055 | { |
| 1056 | $$ = STATE_ATTENUATION; |
| 1057 | } |
| 1058 | | SPOT stateSpotProperty |
| 1059 | { |
| 1060 | $$ = $2; |
| 1061 | } |
| 1062 | | HALF |
| 1063 | { |
| 1064 | $$ = STATE_HALF_VECTOR; |
| 1065 | } |
| 1066 | ; |
| 1067 | |
| 1068 | stateSpotProperty: DIRECTION |
| 1069 | { |
| 1070 | $$ = STATE_SPOT_DIRECTION; |
| 1071 | } |
| 1072 | ; |
| 1073 | |
| 1074 | stateLightModelItem: LIGHTMODEL stateLModProperty |
| 1075 | { |
| 1076 | $$[0] = $2[0]; |
| 1077 | $$[1] = $2[1]; |
| 1078 | } |
| 1079 | ; |
| 1080 | |
| 1081 | stateLModProperty: AMBIENT |
| 1082 | { |
| 1083 | memset($$, 0, sizeof($$)); |
| 1084 | $$[0] = STATE_LIGHTMODEL_AMBIENT; |
| 1085 | } |
| 1086 | | optFaceType SCENECOLOR |
| 1087 | { |
| 1088 | memset($$, 0, sizeof($$)); |
| 1089 | $$[0] = STATE_LIGHTMODEL_SCENECOLOR; |
| 1090 | $$[1] = $1; |
| 1091 | } |
| 1092 | ; |
| 1093 | |
| 1094 | stateLightProdItem: LIGHTPROD '[' stateLightNumber ']' optFaceType stateLProdProperty |
| 1095 | { |
| 1096 | memset($$, 0, sizeof($$)); |
| 1097 | $$[0] = STATE_LIGHTPROD; |
| 1098 | $$[1] = $3; |
| 1099 | $$[2] = $5; |
| 1100 | $$[3] = $6; |
| 1101 | } |
| 1102 | ; |
| 1103 | |
| 1104 | stateLProdProperty: ambDiffSpecProperty; |
| 1105 | |
| 1106 | stateTexEnvItem: TEXENV optLegacyTexUnitNum stateTexEnvProperty |
| 1107 | { |
| 1108 | memset($$, 0, sizeof($$)); |
| 1109 | $$[0] = $3; |
| 1110 | $$[1] = $2; |
| 1111 | } |
| 1112 | ; |
| 1113 | |
| 1114 | stateTexEnvProperty: COLOR |
| 1115 | { |
| 1116 | $$ = STATE_TEXENV_COLOR; |
| 1117 | } |
| 1118 | ; |
| 1119 | |
| 1120 | ambDiffSpecProperty: AMBIENT |
| 1121 | { |
| 1122 | $$ = STATE_AMBIENT; |
| 1123 | } |
| 1124 | | DIFFUSE |
| 1125 | { |
| 1126 | $$ = STATE_DIFFUSE; |
| 1127 | } |
| 1128 | | SPECULAR |
| 1129 | { |
| 1130 | $$ = STATE_SPECULAR; |
| 1131 | } |
| 1132 | ; |
| 1133 | |
| 1134 | stateLightNumber: INTEGER |
| 1135 | { |
| 1136 | if ($1 >= state->MaxLights) { |
| 1137 | yyerror(& @1, state, "invalid light selector"); |
| 1138 | YYERROR; |
| 1139 | } |
| 1140 | |
| 1141 | $$ = $1; |
| 1142 | } |
| 1143 | ; |
| 1144 | |
| 1145 | stateTexGenItem: TEXGEN optTexCoordUnitNum stateTexGenType stateTexGenCoord |
| 1146 | { |
| 1147 | memset($$, 0, sizeof($$)); |
| 1148 | $$[0] = STATE_TEXGEN; |
| 1149 | $$[1] = $2; |
| 1150 | $$[2] = $3 + $4; |
| 1151 | } |
| 1152 | ; |
| 1153 | |
| 1154 | stateTexGenType: EYE |
| 1155 | { |
| 1156 | $$ = STATE_TEXGEN_EYE_S; |
| 1157 | } |
| 1158 | | OBJECT |
| 1159 | { |
| 1160 | $$ = STATE_TEXGEN_OBJECT_S; |
| 1161 | } |
| 1162 | ; |
| 1163 | stateTexGenCoord: TEXGEN_S |
| 1164 | { |
| 1165 | $$ = STATE_TEXGEN_EYE_S - STATE_TEXGEN_EYE_S; |
| 1166 | } |
| 1167 | | TEXGEN_T |
| 1168 | { |
| 1169 | $$ = STATE_TEXGEN_EYE_T - STATE_TEXGEN_EYE_S; |
| 1170 | } |
| 1171 | | TEXGEN_R |
| 1172 | { |
| 1173 | $$ = STATE_TEXGEN_EYE_R - STATE_TEXGEN_EYE_S; |
| 1174 | } |
| 1175 | | TEXGEN_Q |
| 1176 | { |
| 1177 | $$ = STATE_TEXGEN_EYE_Q - STATE_TEXGEN_EYE_S; |
| 1178 | } |
| 1179 | ; |
| 1180 | |
| 1181 | stateFogItem: FOG stateFogProperty |
| 1182 | { |
| 1183 | memset($$, 0, sizeof($$)); |
| 1184 | $$[0] = $2; |
| 1185 | } |
| 1186 | ; |
| 1187 | |
| 1188 | stateFogProperty: COLOR |
| 1189 | { |
| 1190 | $$ = STATE_FOG_COLOR; |
| 1191 | } |
| 1192 | | PARAMS |
| 1193 | { |
| 1194 | $$ = STATE_FOG_PARAMS; |
| 1195 | } |
| 1196 | ; |
| 1197 | |
| 1198 | stateClipPlaneItem: CLIP '[' stateClipPlaneNum ']' PLANE |
| 1199 | { |
| 1200 | memset($$, 0, sizeof($$)); |
| 1201 | $$[0] = STATE_CLIPPLANE; |
| 1202 | $$[1] = $3; |
| 1203 | } |
| 1204 | ; |
| 1205 | |
| 1206 | stateClipPlaneNum: INTEGER |
| 1207 | { |
| 1208 | if ($1 >= state->MaxClipPlanes) { |
| 1209 | yyerror(& @1, state, "invalid clip plane selector"); |
| 1210 | YYERROR; |
| 1211 | } |
| 1212 | |
| 1213 | $$ = $1; |
| 1214 | } |
| 1215 | ; |
| 1216 | |
| 1217 | statePointItem: POINT statePointProperty |
| 1218 | { |
| 1219 | memset($$, 0, sizeof($$)); |
| 1220 | $$[0] = $2; |
| 1221 | } |
| 1222 | ; |
| 1223 | |
| 1224 | statePointProperty: SIZE |
| 1225 | { |
| 1226 | $$ = STATE_POINT_SIZE; |
| 1227 | } |
| 1228 | | ATTENUATION |
| 1229 | { |
| 1230 | $$ = STATE_POINT_ATTENUATION; |
| 1231 | } |
| 1232 | ; |
| 1233 | |
| 1234 | stateMatrixRow: stateMatrixItem ROW '[' stateMatrixRowNum ']' |
| 1235 | { |
| 1236 | $$[0] = $1[0]; |
| 1237 | $$[1] = $1[1]; |
| 1238 | $$[2] = $4; |
| 1239 | $$[3] = $4; |
| 1240 | $$[4] = $1[2]; |
| 1241 | } |
| 1242 | ; |
| 1243 | |
| 1244 | stateMatrixRows: stateMatrixItem optMatrixRows |
| 1245 | { |
| 1246 | $$[0] = $1[0]; |
| 1247 | $$[1] = $1[1]; |
| 1248 | $$[2] = $2[2]; |
| 1249 | $$[3] = $2[3]; |
| 1250 | $$[4] = $1[2]; |
| 1251 | } |
| 1252 | ; |
| 1253 | |
| 1254 | optMatrixRows: |
| 1255 | { |
| 1256 | $$[2] = 0; |
| 1257 | $$[3] = 3; |
| 1258 | } |
| 1259 | | ROW '[' stateMatrixRowNum DOT_DOT stateMatrixRowNum ']' |
| 1260 | { |
| 1261 | /* It seems logical that the matrix row range specifier would have |
| 1262 | * to specify a range or more than one row (i.e., $5 > $3). |
| 1263 | * However, the ARB_vertex_program spec says "a program will fail |
| 1264 | * to load if <a> is greater than <b>." This means that $3 == $5 |
| 1265 | * is valid. |
| 1266 | */ |
| 1267 | if ($3 > $5) { |
| 1268 | yyerror(& @3, state, "invalid matrix row range"); |
| 1269 | YYERROR; |
| 1270 | } |
| 1271 | |
| 1272 | $$[2] = $3; |
| 1273 | $$[3] = $5; |
| 1274 | } |
| 1275 | ; |
| 1276 | |
| 1277 | stateMatrixItem: MATRIX stateMatrixName stateOptMatModifier |
| 1278 | { |
| 1279 | $$[0] = $2[0]; |
| 1280 | $$[1] = $2[1]; |
| 1281 | $$[2] = $3; |
| 1282 | } |
| 1283 | ; |
| 1284 | |
| 1285 | stateOptMatModifier: |
| 1286 | { |
| 1287 | $$ = 0; |
| 1288 | } |
| 1289 | | stateMatModifier |
| 1290 | { |
| 1291 | $$ = $1; |
| 1292 | } |
| 1293 | ; |
| 1294 | |
| 1295 | stateMatModifier: INVERSE |
| 1296 | { |
| 1297 | $$ = STATE_MATRIX_INVERSE; |
| 1298 | } |
| 1299 | | TRANSPOSE |
| 1300 | { |
| 1301 | $$ = STATE_MATRIX_TRANSPOSE; |
| 1302 | } |
| 1303 | | INVTRANS |
| 1304 | { |
| 1305 | $$ = STATE_MATRIX_INVTRANS; |
| 1306 | } |
| 1307 | ; |
| 1308 | |
| 1309 | stateMatrixRowNum: INTEGER |
| 1310 | { |
| 1311 | if ($1 > 3) { |
| 1312 | yyerror(& @1, state, "invalid matrix row reference"); |
| 1313 | YYERROR; |
| 1314 | } |
| 1315 | |
| 1316 | $$ = $1; |
| 1317 | } |
| 1318 | ; |
| 1319 | |
| 1320 | stateMatrixName: MODELVIEW stateOptModMatNum |
| 1321 | { |
| 1322 | $$[0] = STATE_MODELVIEW_MATRIX; |
| 1323 | $$[1] = $2; |
| 1324 | } |
| 1325 | | PROJECTION |
| 1326 | { |
| 1327 | $$[0] = STATE_PROJECTION_MATRIX; |
| 1328 | $$[1] = 0; |
| 1329 | } |
| 1330 | | MVP |
| 1331 | { |
| 1332 | $$[0] = STATE_MVP_MATRIX; |
| 1333 | $$[1] = 0; |
| 1334 | } |
| 1335 | | TEXTURE optTexCoordUnitNum |
| 1336 | { |
| 1337 | $$[0] = STATE_TEXTURE_MATRIX; |
| 1338 | $$[1] = $2; |
| 1339 | } |
| 1340 | | PALETTE '[' statePaletteMatNum ']' |
| 1341 | { |
| 1342 | YYERROR; |
| 1343 | } |
| 1344 | | MAT_PROGRAM '[' stateProgramMatNum ']' |
| 1345 | { |
| 1346 | $$[0] = STATE_PROGRAM_MATRIX; |
| 1347 | $$[1] = $3; |
| 1348 | } |
| 1349 | ; |
| 1350 | |
| 1351 | stateOptModMatNum: |
| 1352 | { |
| 1353 | $$ = 0; |
| 1354 | } |
| 1355 | | stateModMatNum |
| 1356 | { |
| 1357 | $$ = $1; |
| 1358 | } |
| 1359 | ; |
| 1360 | stateModMatNum: INTEGER |
| 1361 | { |
| 1362 | /* Since GL_ARB_vertex_blend isn't supported, only modelview matrix |
| 1363 | * zero is valid. |
| 1364 | */ |
| 1365 | if ($1 != 0) { |
| 1366 | yyerror(& @1, state, "invalid modelview matrix index"); |
| 1367 | YYERROR; |
| 1368 | } |
| 1369 | |
| 1370 | $$ = $1; |
| 1371 | } |
| 1372 | ; |
| 1373 | statePaletteMatNum: INTEGER |
| 1374 | { |
| 1375 | /* Since GL_ARB_matrix_palette isn't supported, just let any value |
| 1376 | * through here. The error will be generated later. |
| 1377 | */ |
| 1378 | $$ = $1; |
| 1379 | } |
| 1380 | ; |
| 1381 | stateProgramMatNum: INTEGER |
| 1382 | { |
| 1383 | if ($1 >= state->MaxProgramMatrices) { |
| 1384 | yyerror(& @1, state, "invalid program matrix selector"); |
| 1385 | YYERROR; |
| 1386 | } |
| 1387 | |
| 1388 | $$ = $1; |
| 1389 | } |
| 1390 | ; |
| 1391 | |
| 1392 | |
| 1393 | |
| 1394 | programSingleItem: progEnvParam | progLocalParam; |
| 1395 | |
| 1396 | programMultipleItem: progEnvParams | progLocalParams; |
| 1397 | |
| 1398 | progEnvParams: PROGRAM ENV '[' progEnvParamNums ']' |
| 1399 | { |
| 1400 | memset($$, 0, sizeof($$)); |
| 1401 | $$[0] = state->state_param_enum; |
| 1402 | $$[1] = STATE_ENV; |
| 1403 | $$[2] = $4[0]; |
| 1404 | $$[3] = $4[1]; |
| 1405 | } |
| 1406 | ; |
| 1407 | |
| 1408 | progEnvParamNums: progEnvParamNum |
| 1409 | { |
| 1410 | $$[0] = $1; |
| 1411 | $$[1] = $1; |
| 1412 | } |
| 1413 | | progEnvParamNum DOT_DOT progEnvParamNum |
| 1414 | { |
| 1415 | $$[0] = $1; |
| 1416 | $$[1] = $3; |
| 1417 | } |
| 1418 | ; |
| 1419 | |
| 1420 | progEnvParam: PROGRAM ENV '[' progEnvParamNum ']' |
| 1421 | { |
| 1422 | memset($$, 0, sizeof($$)); |
| 1423 | $$[0] = state->state_param_enum; |
| 1424 | $$[1] = STATE_ENV; |
| 1425 | $$[2] = $4; |
| 1426 | $$[3] = $4; |
| 1427 | } |
| 1428 | ; |
| 1429 | |
| 1430 | progLocalParams: PROGRAM LOCAL '[' progLocalParamNums ']' |
| 1431 | { |
| 1432 | memset($$, 0, sizeof($$)); |
| 1433 | $$[0] = state->state_param_enum; |
| 1434 | $$[1] = STATE_LOCAL; |
| 1435 | $$[2] = $4[0]; |
| 1436 | $$[3] = $4[1]; |
| 1437 | } |
| 1438 | |
| 1439 | progLocalParamNums: progLocalParamNum |
| 1440 | { |
| 1441 | $$[0] = $1; |
| 1442 | $$[1] = $1; |
| 1443 | } |
| 1444 | | progLocalParamNum DOT_DOT progLocalParamNum |
| 1445 | { |
| 1446 | $$[0] = $1; |
| 1447 | $$[1] = $3; |
| 1448 | } |
| 1449 | ; |
| 1450 | |
| 1451 | progLocalParam: PROGRAM LOCAL '[' progLocalParamNum ']' |
| 1452 | { |
| 1453 | memset($$, 0, sizeof($$)); |
| 1454 | $$[0] = state->state_param_enum; |
| 1455 | $$[1] = STATE_LOCAL; |
| 1456 | $$[2] = $4; |
| 1457 | $$[3] = $4; |
| 1458 | } |
| 1459 | ; |
| 1460 | |
| 1461 | progEnvParamNum: INTEGER |
| 1462 | { |
| 1463 | if ($1 >= state->limits->MaxEnvParams) { |
| 1464 | yyerror(& @1, state, "invalid environment parameter reference"); |
| 1465 | YYERROR; |
| 1466 | } |
| 1467 | $$ = $1; |
| 1468 | } |
| 1469 | ; |
| 1470 | |
| 1471 | progLocalParamNum: INTEGER |
| 1472 | { |
| 1473 | if ($1 >= state->limits->MaxLocalParams) { |
| 1474 | yyerror(& @1, state, "invalid local parameter reference"); |
| 1475 | YYERROR; |
| 1476 | } |
| 1477 | $$ = $1; |
| 1478 | } |
| 1479 | ; |
| 1480 | |
| 1481 | |
| 1482 | |
| 1483 | paramConstDecl: paramConstScalarDecl | paramConstVector; |
| 1484 | paramConstUse: paramConstScalarUse | paramConstVector; |
| 1485 | |
| 1486 | paramConstScalarDecl: signedFloatConstant |
| 1487 | { |
| 1488 | $$.count = 1; |
| 1489 | $$.data[0] = $1; |
| 1490 | } |
| 1491 | ; |
| 1492 | |
| 1493 | paramConstScalarUse: REAL |
| 1494 | { |
| 1495 | $$.count = 1; |
| 1496 | $$.data[0] = $1; |
| 1497 | } |
| 1498 | | INTEGER |
| 1499 | { |
| 1500 | $$.count = 1; |
| 1501 | $$.data[0] = (float) $1; |
| 1502 | } |
| 1503 | ; |
| 1504 | |
| 1505 | paramConstVector: '{' signedFloatConstant '}' |
| 1506 | { |
| 1507 | $$.count = 1; |
| 1508 | $$.data[0] = $2; |
| 1509 | } |
| 1510 | | '{' signedFloatConstant ',' signedFloatConstant '}' |
| 1511 | { |
| 1512 | $$.count = 2; |
| 1513 | $$.data[0] = $2; |
| 1514 | $$.data[1] = $4; |
| 1515 | } |
| 1516 | | '{' signedFloatConstant ',' signedFloatConstant ',' |
| 1517 | signedFloatConstant '}' |
| 1518 | { |
| 1519 | $$.count = 3; |
| 1520 | $$.data[0] = $2; |
| 1521 | $$.data[1] = $4; |
| 1522 | $$.data[1] = $6; |
| 1523 | } |
| 1524 | | '{' signedFloatConstant ',' signedFloatConstant ',' |
| 1525 | signedFloatConstant ',' signedFloatConstant '}' |
| 1526 | { |
| 1527 | $$.count = 4; |
| 1528 | $$.data[0] = $2; |
| 1529 | $$.data[1] = $4; |
| 1530 | $$.data[1] = $6; |
| 1531 | $$.data[1] = $8; |
| 1532 | } |
| 1533 | ; |
| 1534 | |
| 1535 | signedFloatConstant: optionalSign REAL |
| 1536 | { |
| 1537 | $$ = ($1) ? -$2 : $2; |
| 1538 | } |
| 1539 | | optionalSign INTEGER |
| 1540 | { |
| 1541 | $$ = (float)(($1) ? -$2 : $2); |
| 1542 | } |
| 1543 | ; |
| 1544 | |
| 1545 | optionalSign: '+' { $$ = FALSE; } |
| 1546 | | '-' { $$ = TRUE; } |
| 1547 | | { $$ = FALSE; } |
| 1548 | ; |
| 1549 | |
| 1550 | TEMP_statement: TEMP { $<integer>$ = $1; } varNameList |
| 1551 | ; |
| 1552 | |
| 1553 | ADDRESS_statement: ADDRESS { $<integer>$ = $1; } varNameList |
| 1554 | ; |
| 1555 | |
| 1556 | varNameList: varNameList ',' IDENTIFIER |
| 1557 | { |
| 1558 | if (!declare_variable(state, $3, $<integer>0, & @3)) { |
| 1559 | YYERROR; |
| 1560 | } |
| 1561 | } |
| 1562 | | IDENTIFIER |
| 1563 | { |
| 1564 | if (!declare_variable(state, $1, $<integer>0, & @1)) { |
| 1565 | YYERROR; |
| 1566 | } |
| 1567 | } |
| 1568 | ; |
| 1569 | |
| 1570 | OUTPUT_statement: OUTPUT IDENTIFIER '=' resultBinding |
| 1571 | { |
| 1572 | struct asm_symbol *const s = |
| 1573 | declare_variable(state, $2, at_output, & @2); |
| 1574 | |
| 1575 | if (s == NULL) { |
| 1576 | YYERROR; |
| 1577 | } else { |
| 1578 | s->output_binding = $4; |
| 1579 | } |
| 1580 | } |
| 1581 | ; |
| 1582 | |
| 1583 | resultBinding: RESULT POSITION |
| 1584 | { |
| 1585 | if (state->mode == ARB_vertex) { |
| 1586 | $$ = VERT_RESULT_HPOS; |
| 1587 | } else { |
| 1588 | yyerror(& @2, state, "invalid program result name"); |
| 1589 | YYERROR; |
| 1590 | } |
| 1591 | } |
| 1592 | | RESULT FOGCOORD |
| 1593 | { |
| 1594 | if (state->mode == ARB_vertex) { |
| 1595 | $$ = VERT_RESULT_FOGC; |
| 1596 | } else { |
| 1597 | yyerror(& @2, state, "invalid program result name"); |
| 1598 | YYERROR; |
| 1599 | } |
| 1600 | } |
| 1601 | | RESULT resultColBinding |
| 1602 | { |
| 1603 | $$ = $2; |
| 1604 | } |
| 1605 | | RESULT POINTSIZE |
| 1606 | { |
| 1607 | if (state->mode == ARB_vertex) { |
| 1608 | $$ = VERT_RESULT_PSIZ; |
| 1609 | } else { |
| 1610 | yyerror(& @2, state, "invalid program result name"); |
| 1611 | YYERROR; |
| 1612 | } |
| 1613 | } |
| 1614 | | RESULT TEXCOORD optTexCoordUnitNum |
| 1615 | { |
| 1616 | if (state->mode == ARB_vertex) { |
| 1617 | $$ = VERT_RESULT_TEX0 + $3; |
| 1618 | } else { |
| 1619 | yyerror(& @2, state, "invalid program result name"); |
| 1620 | YYERROR; |
| 1621 | } |
| 1622 | } |
| 1623 | | RESULT DEPTH |
| 1624 | { |
| 1625 | if (state->mode == ARB_fragment) { |
| 1626 | $$ = FRAG_RESULT_DEPTH; |
| 1627 | } else { |
| 1628 | yyerror(& @2, state, "invalid program result name"); |
| 1629 | YYERROR; |
| 1630 | } |
| 1631 | } |
| 1632 | ; |
| 1633 | |
| 1634 | resultColBinding: COLOR optResultFaceType optResultColorType |
| 1635 | { |
| 1636 | $$ = $2 + $3; |
| 1637 | } |
| 1638 | ; |
| 1639 | |
| 1640 | optResultFaceType: |
| 1641 | { |
| 1642 | $$ = (state->mode == ARB_vertex) |
| 1643 | ? VERT_RESULT_COL0 |
| 1644 | : FRAG_RESULT_COLOR; |
| 1645 | } |
| 1646 | | FRONT |
| 1647 | { |
| 1648 | if (state->mode == ARB_vertex) { |
| 1649 | $$ = VERT_RESULT_COL0; |
| 1650 | } else { |
| 1651 | yyerror(& @1, state, "invalid program result name"); |
| 1652 | YYERROR; |
| 1653 | } |
| 1654 | } |
| 1655 | | BACK |
| 1656 | { |
| 1657 | if (state->mode == ARB_vertex) { |
| 1658 | $$ = VERT_RESULT_BFC0; |
| 1659 | } else { |
| 1660 | yyerror(& @1, state, "invalid program result name"); |
| 1661 | YYERROR; |
| 1662 | } |
| 1663 | } |
| 1664 | ; |
| 1665 | |
| 1666 | optResultColorType: |
| 1667 | { |
| 1668 | $$ = 0; |
| 1669 | } |
| 1670 | | PRIMARY |
| 1671 | { |
| 1672 | if (state->mode == ARB_vertex) { |
| 1673 | $$ = 0; |
| 1674 | } else { |
| 1675 | yyerror(& @1, state, "invalid program result name"); |
| 1676 | YYERROR; |
| 1677 | } |
| 1678 | } |
| 1679 | | SECONDARY |
| 1680 | { |
| 1681 | if (state->mode == ARB_vertex) { |
| 1682 | $$ = 1; |
| 1683 | } else { |
| 1684 | yyerror(& @1, state, "invalid program result name"); |
| 1685 | YYERROR; |
| 1686 | } |
| 1687 | } |
| 1688 | ; |
| 1689 | |
| 1690 | optFaceType: { $$ = 0; } |
| 1691 | | FRONT { $$ = 0; } |
| 1692 | | BACK { $$ = 1; } |
| 1693 | ; |
| 1694 | |
| 1695 | optColorType: { $$ = 0; } |
| 1696 | | PRIMARY { $$ = 0; } |
| 1697 | | SECONDARY { $$ = 1; } |
| 1698 | ; |
| 1699 | |
| 1700 | optTexCoordUnitNum: { $$ = 0; } |
| 1701 | | '[' texCoordUnitNum ']' { $$ = $2; } |
| 1702 | ; |
| 1703 | |
| 1704 | optTexImageUnitNum: { $$ = 0; } |
| 1705 | | '[' texImageUnitNum ']' { $$ = $2; } |
| 1706 | ; |
| 1707 | |
| 1708 | optLegacyTexUnitNum: { $$ = 0; } |
| 1709 | | '[' legacyTexUnitNum ']' { $$ = $2; } |
| 1710 | ; |
| 1711 | |
| 1712 | texCoordUnitNum: INTEGER |
| 1713 | { |
| 1714 | if ($1 >= state->MaxTextureCoordUnits) { |
| 1715 | yyerror(& @1, state, "invalid texture coordinate unit selector"); |
| 1716 | YYERROR; |
| 1717 | } |
| 1718 | |
| 1719 | $$ = $1; |
| 1720 | } |
| 1721 | ; |
| 1722 | |
| 1723 | texImageUnitNum: INTEGER |
| 1724 | { |
| 1725 | if ($1 >= state->MaxTextureImageUnits) { |
| 1726 | yyerror(& @1, state, "invalid texture image unit selector"); |
| 1727 | YYERROR; |
| 1728 | } |
| 1729 | |
| 1730 | $$ = $1; |
| 1731 | } |
| 1732 | ; |
| 1733 | |
| 1734 | legacyTexUnitNum: INTEGER |
| 1735 | { |
| 1736 | if ($1 >= state->MaxTextureUnits) { |
| 1737 | yyerror(& @1, state, "invalid texture unit selector"); |
| 1738 | YYERROR; |
| 1739 | } |
| 1740 | |
| 1741 | $$ = $1; |
| 1742 | } |
| 1743 | ; |
| 1744 | |
| 1745 | ALIAS_statement: ALIAS IDENTIFIER '=' IDENTIFIER |
| 1746 | { |
| 1747 | struct asm_symbol *exist = (struct asm_symbol *) |
| 1748 | _mesa_symbol_table_find_symbol(state->st, 0, $2); |
| 1749 | struct asm_symbol *target = (struct asm_symbol *) |
| 1750 | _mesa_symbol_table_find_symbol(state->st, 0, $4); |
| 1751 | |
| 1752 | |
| 1753 | if (exist != NULL) { |
| 1754 | yyerror(& @2, state, "redeclared identifier"); |
| 1755 | YYERROR; |
| 1756 | } else if (target == NULL) { |
| 1757 | yyerror(& @4, state, |
| 1758 | "undefined variable binding in ALIAS statement"); |
| 1759 | YYERROR; |
| 1760 | } else { |
| 1761 | _mesa_symbol_table_add_symbol(state->st, 0, $2, target); |
| 1762 | } |
| 1763 | } |
| 1764 | ; |
| 1765 | |
| 1766 | %% |
| 1767 | |
| 1768 | struct asm_instruction * |
| 1769 | asm_instruction_ctor(gl_inst_opcode op, |
| 1770 | const struct prog_dst_register *dst, |
| 1771 | const struct asm_src_register *src0, |
| 1772 | const struct asm_src_register *src1, |
| 1773 | const struct asm_src_register *src2) |
| 1774 | { |
| 1775 | struct asm_instruction *inst = calloc(1, sizeof(struct asm_instruction)); |
| 1776 | |
| 1777 | if (inst) { |
| 1778 | _mesa_init_instructions(inst, 1); |
| 1779 | inst->Base.Opcode = op; |
| 1780 | inst->Base.DstReg = *dst; |
| 1781 | |
| 1782 | inst->Base.SrcReg[0] = src0->Base; |
| 1783 | inst->SrcReg[0] = *src0; |
| 1784 | |
| 1785 | if (src1 != NULL) { |
| 1786 | inst->Base.SrcReg[1] = src1->Base; |
| 1787 | inst->SrcReg[1] = *src1; |
Ian Romanick | aec4291 | 2009-07-22 12:29:48 -0700 | [diff] [blame] | 1788 | } else { |
| 1789 | init_src_reg(& inst->SrcReg[1]); |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | if (src2 != NULL) { |
| 1793 | inst->Base.SrcReg[2] = src2->Base; |
| 1794 | inst->SrcReg[2] = *src2; |
Ian Romanick | aec4291 | 2009-07-22 12:29:48 -0700 | [diff] [blame] | 1795 | } else { |
| 1796 | init_src_reg(& inst->SrcReg[2]); |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | return inst; |
| 1801 | } |
| 1802 | |
| 1803 | |
| 1804 | void |
| 1805 | init_dst_reg(struct prog_dst_register *r) |
| 1806 | { |
| 1807 | memset(r, 0, sizeof(*r)); |
| 1808 | r->File = PROGRAM_UNDEFINED; |
| 1809 | r->WriteMask = WRITEMASK_XYZW; |
| 1810 | r->CondMask = COND_TR; |
| 1811 | r->CondSwizzle = SWIZZLE_NOOP; |
| 1812 | } |
| 1813 | |
| 1814 | |
| 1815 | void |
| 1816 | init_src_reg(struct asm_src_register *r) |
| 1817 | { |
| 1818 | memset(r, 0, sizeof(*r)); |
| 1819 | r->Base.File = PROGRAM_UNDEFINED; |
| 1820 | r->Base.Swizzle = SWIZZLE_NOOP; |
| 1821 | r->Symbol = NULL; |
| 1822 | } |
| 1823 | |
| 1824 | |
| 1825 | /** |
| 1826 | * Validate the set of inputs used by a program |
| 1827 | * |
| 1828 | * Validates that legal sets of inputs are used by the program. In this case |
| 1829 | * "used" included both reading the input or binding the input to a name using |
| 1830 | * the \c ATTRIB command. |
| 1831 | * |
| 1832 | * \return |
| 1833 | * \c TRUE if the combination of inputs used is valid, \c FALSE otherwise. |
| 1834 | */ |
| 1835 | int |
| 1836 | validate_inputs(struct YYLTYPE *locp, struct asm_parser_state *state) |
| 1837 | { |
| 1838 | const int inputs = state->prog->InputsRead | state->InputsBound; |
| 1839 | |
| 1840 | if (((inputs & 0x0ffff) & (inputs >> 16)) != 0) { |
| 1841 | yyerror(locp, state, "illegal use of generic attribute and name attribute"); |
| 1842 | return 0; |
| 1843 | } |
| 1844 | |
| 1845 | return 1; |
| 1846 | } |
| 1847 | |
| 1848 | |
| 1849 | struct asm_symbol * |
| 1850 | declare_variable(struct asm_parser_state *state, char *name, enum asm_type t, |
| 1851 | struct YYLTYPE *locp) |
| 1852 | { |
| 1853 | struct asm_symbol *s = NULL; |
| 1854 | struct asm_symbol *exist = (struct asm_symbol *) |
| 1855 | _mesa_symbol_table_find_symbol(state->st, 0, name); |
| 1856 | |
| 1857 | |
| 1858 | if (exist != NULL) { |
| 1859 | yyerror(locp, state, "redeclared identifier"); |
| 1860 | } else { |
| 1861 | s = calloc(1, sizeof(struct asm_symbol)); |
| 1862 | s->name = name; |
| 1863 | s->type = t; |
| 1864 | |
| 1865 | switch (t) { |
| 1866 | case at_temp: |
| 1867 | if (state->prog->NumTemporaries >= state->limits->MaxTemps) { |
| 1868 | yyerror(locp, state, "too many temporaries declared"); |
| 1869 | free(s); |
| 1870 | return NULL; |
| 1871 | } |
| 1872 | |
| 1873 | s->temp_binding = state->prog->NumTemporaries; |
| 1874 | state->prog->NumTemporaries++; |
| 1875 | break; |
| 1876 | |
| 1877 | case at_address: |
| 1878 | if (state->prog->NumAddressRegs >= state->limits->MaxAddressRegs) { |
| 1879 | yyerror(locp, state, "too many address registers declared"); |
| 1880 | free(s); |
| 1881 | return NULL; |
| 1882 | } |
| 1883 | |
| 1884 | /* FINISHME: Add support for multiple address registers. |
| 1885 | */ |
| 1886 | state->prog->NumAddressRegs++; |
| 1887 | break; |
| 1888 | |
| 1889 | default: |
| 1890 | break; |
| 1891 | } |
| 1892 | |
| 1893 | _mesa_symbol_table_add_symbol(state->st, 0, s->name, s); |
| 1894 | } |
| 1895 | |
| 1896 | return s; |
| 1897 | } |
| 1898 | |
| 1899 | |
| 1900 | int add_state_reference(struct gl_program_parameter_list *param_list, |
| 1901 | const gl_state_index tokens[STATE_LENGTH]) |
| 1902 | { |
| 1903 | const GLuint size = 4; /* XXX fix */ |
| 1904 | char *name; |
| 1905 | GLint index; |
| 1906 | |
| 1907 | name = _mesa_program_state_string(tokens); |
| 1908 | index = _mesa_add_parameter(param_list, PROGRAM_STATE_VAR, name, |
| 1909 | size, GL_NONE, |
| 1910 | NULL, (gl_state_index *) tokens, 0x0); |
| 1911 | param_list->StateFlags |= _mesa_program_state_flags(tokens); |
| 1912 | |
| 1913 | /* free name string here since we duplicated it in add_parameter() */ |
| 1914 | _mesa_free(name); |
| 1915 | |
| 1916 | return index; |
| 1917 | } |
| 1918 | |
| 1919 | |
| 1920 | int |
| 1921 | initialize_symbol_from_state(struct gl_program *prog, |
| 1922 | struct asm_symbol *param_var, |
| 1923 | const gl_state_index tokens[STATE_LENGTH]) |
| 1924 | { |
| 1925 | int idx = -1; |
| 1926 | gl_state_index state_tokens[STATE_LENGTH]; |
| 1927 | |
| 1928 | |
| 1929 | memcpy(state_tokens, tokens, sizeof(state_tokens)); |
| 1930 | |
| 1931 | param_var->type = at_param; |
Ian Romanick | 28b1303 | 2009-07-22 16:03:32 -0700 | [diff] [blame] | 1932 | param_var->param_binding_type = PROGRAM_STATE_VAR; |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 1933 | |
| 1934 | /* If we are adding a STATE_MATRIX that has multiple rows, we need to |
| 1935 | * unroll it and call add_state_reference() for each row |
| 1936 | */ |
| 1937 | if ((state_tokens[0] == STATE_MODELVIEW_MATRIX || |
| 1938 | state_tokens[0] == STATE_PROJECTION_MATRIX || |
| 1939 | state_tokens[0] == STATE_MVP_MATRIX || |
| 1940 | state_tokens[0] == STATE_TEXTURE_MATRIX || |
| 1941 | state_tokens[0] == STATE_PROGRAM_MATRIX) |
| 1942 | && (state_tokens[2] != state_tokens[3])) { |
| 1943 | int row; |
| 1944 | const int first_row = state_tokens[2]; |
| 1945 | const int last_row = state_tokens[3]; |
| 1946 | |
| 1947 | for (row = first_row; row <= last_row; row++) { |
| 1948 | state_tokens[2] = state_tokens[3] = row; |
| 1949 | |
| 1950 | idx = add_state_reference(prog->Parameters, state_tokens); |
| 1951 | if (param_var->param_binding_begin == ~0U) |
| 1952 | param_var->param_binding_begin = idx; |
| 1953 | param_var->param_binding_length++; |
| 1954 | } |
| 1955 | } |
| 1956 | else { |
| 1957 | idx = add_state_reference(prog->Parameters, state_tokens); |
| 1958 | if (param_var->param_binding_begin == ~0U) |
| 1959 | param_var->param_binding_begin = idx; |
| 1960 | param_var->param_binding_length++; |
| 1961 | } |
| 1962 | |
| 1963 | return idx; |
| 1964 | } |
| 1965 | |
| 1966 | |
| 1967 | int |
| 1968 | initialize_symbol_from_param(struct gl_program *prog, |
| 1969 | struct asm_symbol *param_var, |
| 1970 | const gl_state_index tokens[STATE_LENGTH]) |
| 1971 | { |
| 1972 | int idx = -1; |
| 1973 | gl_state_index state_tokens[STATE_LENGTH]; |
| 1974 | |
| 1975 | |
| 1976 | memcpy(state_tokens, tokens, sizeof(state_tokens)); |
| 1977 | |
| 1978 | assert((state_tokens[0] == STATE_VERTEX_PROGRAM) |
| 1979 | || (state_tokens[0] == STATE_FRAGMENT_PROGRAM)); |
| 1980 | assert((state_tokens[1] == STATE_ENV) |
| 1981 | || (state_tokens[1] == STATE_LOCAL)); |
| 1982 | |
| 1983 | param_var->type = at_param; |
Ian Romanick | 28b1303 | 2009-07-22 16:03:32 -0700 | [diff] [blame] | 1984 | param_var->param_binding_type = (state_tokens[1] == STATE_ENV) |
| 1985 | ? PROGRAM_ENV_PARAM : PROGRAM_LOCAL_PARAM; |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 1986 | |
| 1987 | /* If we are adding a STATE_ENV or STATE_LOCAL that has multiple elements, |
| 1988 | * we need to unroll it and call add_state_reference() for each row |
| 1989 | */ |
| 1990 | if (state_tokens[2] != state_tokens[3]) { |
| 1991 | int row; |
| 1992 | const int first_row = state_tokens[2]; |
| 1993 | const int last_row = state_tokens[3]; |
| 1994 | |
| 1995 | for (row = first_row; row <= last_row; row++) { |
| 1996 | state_tokens[2] = state_tokens[3] = row; |
| 1997 | |
| 1998 | idx = add_state_reference(prog->Parameters, state_tokens); |
| 1999 | if (param_var->param_binding_begin == ~0U) |
| 2000 | param_var->param_binding_begin = idx; |
| 2001 | param_var->param_binding_length++; |
| 2002 | } |
| 2003 | } |
| 2004 | else { |
| 2005 | idx = add_state_reference(prog->Parameters, state_tokens); |
| 2006 | if (param_var->param_binding_begin == ~0U) |
| 2007 | param_var->param_binding_begin = idx; |
| 2008 | param_var->param_binding_length++; |
| 2009 | } |
| 2010 | |
| 2011 | return idx; |
| 2012 | } |
| 2013 | |
| 2014 | |
| 2015 | int |
| 2016 | initialize_symbol_from_const(struct gl_program *prog, |
| 2017 | struct asm_symbol *param_var, |
| 2018 | const struct asm_vector *vec) |
| 2019 | { |
| 2020 | const int idx = _mesa_add_parameter(prog->Parameters, PROGRAM_CONSTANT, |
| 2021 | NULL, vec->count, GL_NONE, vec->data, |
| 2022 | NULL, 0x0); |
| 2023 | |
| 2024 | param_var->type = at_param; |
Ian Romanick | 28b1303 | 2009-07-22 16:03:32 -0700 | [diff] [blame] | 2025 | param_var->param_binding_type = PROGRAM_CONSTANT; |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 2026 | |
| 2027 | if (param_var->param_binding_begin == ~0U) |
| 2028 | param_var->param_binding_begin = idx; |
| 2029 | param_var->param_binding_length++; |
| 2030 | |
| 2031 | return idx; |
| 2032 | } |
| 2033 | |
| 2034 | |
Ian Romanick | 44843c7 | 2009-07-22 15:06:49 -0700 | [diff] [blame] | 2035 | char * |
| 2036 | make_error_string(const char *fmt, ...) |
| 2037 | { |
| 2038 | int length; |
| 2039 | char *str; |
| 2040 | va_list args; |
| 2041 | |
| 2042 | va_start(args, fmt); |
| 2043 | |
| 2044 | /* Call vsnprintf once to determine how large the final string is. Call it |
| 2045 | * again to do the actual formatting. from the vsnprintf manual page: |
| 2046 | * |
| 2047 | * Upon successful return, these functions return the number of |
| 2048 | * characters printed (not including the trailing '\0' used to end |
| 2049 | * output to strings). |
| 2050 | */ |
| 2051 | length = 1 + vsnprintf(NULL, 0, fmt, args); |
| 2052 | |
| 2053 | str = _mesa_malloc(length); |
| 2054 | if (str) { |
| 2055 | vsnprintf(str, length, fmt, args); |
| 2056 | } |
| 2057 | |
| 2058 | va_end(args); |
| 2059 | |
| 2060 | return str; |
| 2061 | } |
| 2062 | |
| 2063 | |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 2064 | void |
| 2065 | yyerror(YYLTYPE *locp, struct asm_parser_state *state, const char *s) |
| 2066 | { |
Ian Romanick | 44843c7 | 2009-07-22 15:06:49 -0700 | [diff] [blame] | 2067 | char *err_str; |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 2068 | |
Ian Romanick | 44843c7 | 2009-07-22 15:06:49 -0700 | [diff] [blame] | 2069 | |
| 2070 | err_str = make_error_string("glProgramStringARB(%s)\n", s); |
| 2071 | if (err_str) { |
| 2072 | _mesa_error(state->ctx, GL_INVALID_OPERATION, err_str); |
| 2073 | _mesa_free(err_str); |
| 2074 | } |
| 2075 | |
| 2076 | err_str = make_error_string("line %u, char %u: error: %s\n", |
| 2077 | locp->first_line, locp->first_column, s); |
| 2078 | _mesa_set_program_error(state->ctx, locp->position, err_str); |
| 2079 | |
| 2080 | if (err_str) { |
| 2081 | _mesa_free(err_str); |
| 2082 | } |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 2083 | } |
| 2084 | |
Ian Romanick | 44843c7 | 2009-07-22 15:06:49 -0700 | [diff] [blame] | 2085 | |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 2086 | GLboolean |
| 2087 | _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str, |
| 2088 | GLsizei len, struct asm_parser_state *state) |
| 2089 | { |
| 2090 | struct gl_program_constants limits; |
| 2091 | struct asm_instruction *inst; |
| 2092 | unsigned i; |
| 2093 | GLubyte *strz; |
| 2094 | |
Ian Romanick | 44843c7 | 2009-07-22 15:06:49 -0700 | [diff] [blame] | 2095 | state->ctx = ctx; |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 2096 | state->prog->Target = target; |
| 2097 | state->prog->Parameters = _mesa_new_parameter_list(); |
| 2098 | |
| 2099 | /* Make a copy of the program string and force it to be NUL-terminated. |
| 2100 | */ |
| 2101 | strz = (GLubyte *) _mesa_malloc(len + 1); |
| 2102 | if (strz == NULL) { |
| 2103 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramStringARB"); |
| 2104 | return GL_FALSE; |
| 2105 | } |
| 2106 | _mesa_memcpy (strz, str, len); |
| 2107 | strz[len] = '\0'; |
| 2108 | |
| 2109 | state->prog->String = strz; |
| 2110 | |
| 2111 | state->st = _mesa_symbol_table_ctor(); |
| 2112 | |
| 2113 | /* All of these limits should come from ctx. |
| 2114 | */ |
| 2115 | limits.MaxInstructions = 128; |
| 2116 | limits.MaxAluInstructions = 128; |
| 2117 | limits.MaxTexInstructions = 128; |
| 2118 | limits.MaxTexIndirections = 128; |
| 2119 | limits.MaxAttribs = 16; |
| 2120 | limits.MaxTemps = 128; |
| 2121 | limits.MaxAddressRegs = 1; |
| 2122 | limits.MaxParameters = 128; |
| 2123 | limits.MaxLocalParams = 256; |
| 2124 | limits.MaxEnvParams = 128; |
| 2125 | limits.MaxNativeInstructions = 128; |
| 2126 | limits.MaxNativeAluInstructions = 128; |
| 2127 | limits.MaxNativeTexInstructions = 128; |
| 2128 | limits.MaxNativeTexIndirections = 128; |
| 2129 | limits.MaxNativeAttribs = 16; |
| 2130 | limits.MaxNativeTemps = 128; |
| 2131 | limits.MaxNativeAddressRegs = 1; |
| 2132 | limits.MaxNativeParameters = 128; |
| 2133 | limits.MaxUniformComponents = 0; |
| 2134 | |
| 2135 | state->limits = & limits; |
| 2136 | |
| 2137 | state->MaxTextureImageUnits = 16; |
| 2138 | state->MaxTextureCoordUnits = 8; |
| 2139 | state->MaxTextureUnits = 8; |
| 2140 | state->MaxClipPlanes = 6; |
| 2141 | state->MaxLights = 8; |
| 2142 | state->MaxProgramMatrices = 8; |
| 2143 | |
| 2144 | state->state_param_enum = (target == GL_VERTEX_PROGRAM_ARB) |
| 2145 | ? STATE_VERTEX_PROGRAM : STATE_FRAGMENT_PROGRAM; |
| 2146 | |
| 2147 | _mesa_set_program_error(ctx, -1, NULL); |
| 2148 | |
| 2149 | _mesa_program_lexer_ctor(& state->scanner, state, (const char *) str, len); |
| 2150 | yyparse(state); |
| 2151 | _mesa_program_lexer_dtor(state->scanner); |
| 2152 | |
| 2153 | |
Ian Romanick | 44843c7 | 2009-07-22 15:06:49 -0700 | [diff] [blame] | 2154 | if (ctx->Program.ErrorPos != -1) { |
| 2155 | return GL_FALSE; |
| 2156 | } |
| 2157 | |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 2158 | if (! _mesa_layout_parameters(state)) { |
Ian Romanick | 44843c7 | 2009-07-22 15:06:49 -0700 | [diff] [blame] | 2159 | struct YYLTYPE loc; |
| 2160 | |
| 2161 | loc.first_line = 0; |
| 2162 | loc.first_column = 0; |
| 2163 | loc.position = len; |
| 2164 | |
| 2165 | yyerror(& loc, state, "invalid PARAM usage"); |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 2166 | return GL_FALSE; |
| 2167 | } |
| 2168 | |
| 2169 | |
| 2170 | |
| 2171 | /* Add one instruction to store the "END" instruction. |
| 2172 | */ |
| 2173 | state->prog->Instructions = |
| 2174 | _mesa_alloc_instructions(state->prog->NumInstructions + 1); |
| 2175 | inst = state->inst_head; |
| 2176 | for (i = 0; i < state->prog->NumInstructions; i++) { |
| 2177 | struct asm_instruction *const temp = inst->next; |
| 2178 | |
| 2179 | state->prog->Instructions[i] = inst->Base; |
| 2180 | _mesa_free(inst); |
| 2181 | |
| 2182 | inst = temp; |
| 2183 | } |
| 2184 | |
| 2185 | /* Finally, tag on an OPCODE_END instruction */ |
| 2186 | { |
| 2187 | const GLuint numInst = state->prog->NumInstructions; |
| 2188 | _mesa_init_instructions(state->prog->Instructions + numInst, 1); |
| 2189 | state->prog->Instructions[numInst].Opcode = OPCODE_END; |
| 2190 | } |
| 2191 | state->prog->NumInstructions++; |
| 2192 | |
Ian Romanick | c2ee82d | 2009-07-22 15:27:31 -0700 | [diff] [blame] | 2193 | state->prog->NumParameters = state->prog->Parameters->NumParameters; |
| 2194 | |
Ian Romanick | 770cebb | 2009-07-20 17:44:36 -0700 | [diff] [blame] | 2195 | /* |
| 2196 | * Initialize native counts to logical counts. The device driver may |
| 2197 | * change them if program is translated into a hardware program. |
| 2198 | */ |
| 2199 | state->prog->NumNativeInstructions = state->prog->NumInstructions; |
| 2200 | state->prog->NumNativeTemporaries = state->prog->NumTemporaries; |
| 2201 | state->prog->NumNativeParameters = state->prog->NumParameters; |
| 2202 | state->prog->NumNativeAttributes = state->prog->NumAttributes; |
| 2203 | state->prog->NumNativeAddressRegs = state->prog->NumAddressRegs; |
| 2204 | |
| 2205 | return GL_TRUE; |
| 2206 | } |