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