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