3 * Copyright © 2009 Intel Corporation
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:
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
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.
28 #include "main/mtypes.h"
29 #include "main/imports.h"
31 #include "prog_parameter.h"
32 #include "prog_parameter_layout.h"
33 #include "prog_statevars.h"
34 #include "prog_instruction.h"
36 #include "symbol_table.h"
37 #include "program_parser.h"
39 extern void *yy_scan_string(char *);
40 extern void yy_delete_buffer(void *);
42 static struct asm_symbol *declare_variable(struct asm_parser_state *state,
43 char *name, enum asm_type t, struct YYLTYPE *locp);
45 static int add_state_reference(struct gl_program_parameter_list *param_list,
46 const gl_state_index tokens[STATE_LENGTH]);
48 static int initialize_symbol_from_state(struct gl_program *prog,
49 struct asm_symbol *param_var, const gl_state_index tokens[STATE_LENGTH]);
51 static int initialize_symbol_from_param(struct gl_program *prog,
52 struct asm_symbol *param_var, const gl_state_index tokens[STATE_LENGTH]);
54 static int initialize_symbol_from_const(struct gl_program *prog,
55 struct asm_symbol *param_var, const struct asm_vector *vec);
57 static int yyparse(struct asm_parser_state *state);
59 static char *make_error_string(const char *fmt, ...);
61 static void yyerror(struct YYLTYPE *locp, struct asm_parser_state *state,
64 static int validate_inputs(struct YYLTYPE *locp,
65 struct asm_parser_state *state);
67 static void init_dst_reg(struct prog_dst_register *r);
69 static void init_src_reg(struct asm_src_register *r);
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);
80 #define YYLLOC_DEFAULT(Current, Rhs, 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; \
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; \
98 #define YYLEX_PARAM state->scanner
103 %parse-param { struct asm_parser_state *state }
105 %lex-param { void *scanner }
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;
120 gl_state_index state[STATE_LENGTH];
122 struct asm_vector vector;
123 gl_inst_opcode opcode;
127 unsigned rgba_valid:1;
128 unsigned xyzw_valid:1;
133 %token ARBvp_10 ARBfp_10
135 /* Tokens for assembler pseudo-ops */
136 %token <integer> ADDRESS
140 %token <integer> TEMP
143 /* Tokens for instructions */
144 %token <temp_inst> BIN_OP BINSC_OP SAMPLE_OP SCALAR_OP TRI_OP VECTOR_OP
145 %token <temp_inst> ARL KIL SWZ
147 %token <integer> INTEGER
150 %token AMBIENT ATTENUATION
153 %token DEPTH DIFFUSE DIRECTION
154 %token EMISSION ENV EYE
155 %token FOG FOGCOORD FRAGMENT FRONT
157 %token INVERSE INVTRANS
158 %token LIGHT LIGHTMODEL LIGHTPROD LOCAL
159 %token MATERIAL MAT_PROGRAM MATRIX MATRIXINDEX MODELVIEW MVP
162 %token PALETTE PARAMS PLANE POINT_TOK POINTSIZE POSITION PRIMARY PROGRAM PROJECTION
163 %token RANGE RESULT ROW
164 %token SCENECOLOR SECONDARY SHININESS SIZE_TOK SPECULAR SPOT STATE
165 %token TEXCOORD TEXENV TEXGEN TEXGEN_Q TEXGEN_R TEXGEN_S TEXGEN_T TEXTURE TRANSPOSE
166 %token TEXTURE_UNIT TEX_1D TEX_2D TEX_3D TEX_CUBE TEX_RECT
167 %token TEX_SHADOW1D TEX_SHADOW2D TEX_SHADOWRECT
168 %token TEX_ARRAY1D TEX_ARRAY2D TEX_ARRAYSHADOW1D TEX_ARRAYSHADOW2D
169 %token VERTEX VTXATTRIB
172 %token <string> IDENTIFIER
173 %token <swiz_mask> MASK4 MASK3 MASK2 MASK1 SWIZZLE
177 %type <inst> instruction ALU_instruction TexInstruction
178 %type <inst> ARL_instruction VECTORop_instruction
179 %type <inst> SCALARop_instruction BINSCop_instruction BINop_instruction
180 %type <inst> TRIop_instruction SWZ_instruction SAMPLE_instruction
181 %type <inst> KIL_instruction
183 %type <dst_reg> dstReg maskedDstReg maskedAddrReg
184 %type <src_reg> srcReg scalarSrcReg swizzleSrcReg
185 %type <swiz_mask> scalarSuffix swizzleSuffix extendedSwizzle
186 %type <ext_swizzle> extSwizComp extSwizSel
187 %type <swiz_mask> optionalMask
189 %type <sym> progParamArray
190 %type <integer> addrRegRelOffset addrRegPosOffset addrRegNegOffset
191 %type <src_reg> progParamArrayMem progParamArrayAbs progParamArrayRel
193 %type <swiz_mask> addrComponent addrWriteMask
195 %type <result> resultBinding resultColBinding
196 %type <integer> optFaceType optColorType
197 %type <integer> optResultFaceType optResultColorType
199 %type <integer> optTexImageUnitNum texImageUnitNum
200 %type <integer> optTexCoordUnitNum texCoordUnitNum
201 %type <integer> optLegacyTexUnitNum legacyTexUnitNum
202 %type <integer> texImageUnit texTarget
203 %type <integer> vtxAttribNum
205 %type <attrib> attribBinding vtxAttribItem fragAttribItem
207 %type <temp_sym> paramSingleInit paramSingleItemDecl
208 %type <integer> optArraySize
210 %type <state> stateSingleItem stateMultipleItem
211 %type <state> stateMaterialItem
212 %type <state> stateLightItem stateLightModelItem stateLightProdItem
213 %type <state> stateTexGenItem stateFogItem stateClipPlaneItem statePointItem
214 %type <state> stateMatrixItem stateMatrixRow stateMatrixRows
215 %type <state> stateTexEnvItem stateDepthItem
217 %type <state> stateLModProperty
218 %type <state> stateMatrixName optMatrixRows
220 %type <integer> stateMatProperty
221 %type <integer> stateLightProperty stateSpotProperty
222 %type <integer> stateLightNumber stateLProdProperty
223 %type <integer> stateTexGenType stateTexGenCoord
224 %type <integer> stateTexEnvProperty
225 %type <integer> stateFogProperty
226 %type <integer> stateClipPlaneNum
227 %type <integer> statePointProperty
229 %type <integer> stateOptMatModifier stateMatModifier stateMatrixRowNum
230 %type <integer> stateOptModMatNum stateModMatNum statePaletteMatNum
231 %type <integer> stateProgramMatNum
233 %type <integer> ambDiffSpecProperty
235 %type <state> programSingleItem progEnvParam progLocalParam
236 %type <state> programMultipleItem progEnvParams progLocalParams
238 %type <temp_sym> paramMultipleInit paramMultInitList paramMultipleItem
239 %type <temp_sym> paramSingleItemUse
241 %type <integer> progEnvParamNum progLocalParamNum
242 %type <state> progEnvParamNums progLocalParamNums
244 %type <vector> paramConstDecl paramConstUse
245 %type <vector> paramConstScalarDecl paramConstScalarUse paramConstVector
246 %type <real> signedFloatConstant
247 %type <negate> optionalSign
250 extern int yylex(YYSTYPE *yylval_param, YYLTYPE *yylloc_param,
256 program: language optionSequence statementSequence END
261 if (state->prog->Target != GL_VERTEX_PROGRAM_ARB) {
262 yyerror(& @1, state, "invalid fragment program header");
265 state->mode = ARB_vertex;
269 if (state->prog->Target != GL_FRAGMENT_PROGRAM_ARB) {
270 yyerror(& @1, state, "invalid vertex program header");
272 state->mode = ARB_fragment;
274 state->option.TexRect =
275 (state->ctx->Extensions.NV_texture_rectangle != GL_FALSE);
279 optionSequence: optionSequence option
283 option: OPTION IDENTIFIER ';'
287 if (state->mode == ARB_vertex) {
288 valid = _mesa_ARBvp_parse_option(state, $2);
289 } else if (state->mode == ARB_fragment) {
290 valid = _mesa_ARBfp_parse_option(state, $2);
295 const char *const err_str = (state->mode == ARB_vertex)
296 ? "invalid ARB vertex program option"
297 : "invalid ARB fragment program option";
299 yyerror(& @2, state, err_str);
305 statementSequence: statementSequence statement
309 statement: instruction ';'
312 if (state->inst_tail == NULL) {
313 state->inst_head = $1;
315 state->inst_tail->next = $1;
318 state->inst_tail = $1;
321 state->prog->NumInstructions++;
324 | namingStatement ';'
327 instruction: ALU_instruction
330 state->prog->NumAluInstructions++;
335 state->prog->NumTexInstructions++;
339 ALU_instruction: ARL_instruction
340 | VECTORop_instruction
341 | SCALARop_instruction
342 | BINSCop_instruction
348 TexInstruction: SAMPLE_instruction
352 ARL_instruction: ARL maskedAddrReg ',' scalarSrcReg
354 $$ = asm_instruction_ctor(OPCODE_ARL, & $2, & $4, NULL, NULL);
358 VECTORop_instruction: VECTOR_OP maskedDstReg ',' swizzleSrcReg
360 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL);
361 $$->Base.SaturateMode = $1.SaturateMode;
365 SCALARop_instruction: SCALAR_OP maskedDstReg ',' scalarSrcReg
367 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL);
368 $$->Base.SaturateMode = $1.SaturateMode;
372 BINSCop_instruction: BINSC_OP maskedDstReg ',' scalarSrcReg ',' scalarSrcReg
374 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, NULL);
375 $$->Base.SaturateMode = $1.SaturateMode;
380 BINop_instruction: BIN_OP maskedDstReg ',' swizzleSrcReg ',' swizzleSrcReg
382 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, NULL);
383 $$->Base.SaturateMode = $1.SaturateMode;
387 TRIop_instruction: TRI_OP maskedDstReg ','
388 swizzleSrcReg ',' swizzleSrcReg ',' swizzleSrcReg
390 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, & $8);
391 $$->Base.SaturateMode = $1.SaturateMode;
395 SAMPLE_instruction: SAMPLE_OP maskedDstReg ',' swizzleSrcReg ',' texImageUnit ',' texTarget
397 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL);
399 const GLbitfield tex_mask = (1U << $6);
400 GLbitfield shadow_tex = 0;
401 GLbitfield target_mask = 0;
404 $$->Base.SaturateMode = $1.SaturateMode;
405 $$->Base.TexSrcUnit = $6;
408 shadow_tex = tex_mask;
410 $$->Base.TexSrcTarget = -$8;
411 $$->Base.TexShadow = 1;
413 $$->Base.TexSrcTarget = $8;
416 target_mask = (1U << $$->Base.TexSrcTarget);
418 /* If this texture unit was previously accessed and that access
419 * had a different texture target, generate an error.
421 * If this texture unit was previously accessed and that access
422 * had a different shadow mode, generate an error.
424 if ((state->prog->TexturesUsed[$6] != 0)
425 && ((state->prog->TexturesUsed[$6] != target_mask)
426 || ((state->prog->ShadowSamplers & tex_mask)
429 "multiple targets used on one texture image unit");
434 state->prog->TexturesUsed[$6] |= target_mask;
435 state->prog->ShadowSamplers |= shadow_tex;
440 KIL_instruction: KIL swizzleSrcReg
442 $$ = asm_instruction_ctor(OPCODE_KIL, NULL, & $2, NULL, NULL);
443 state->fragment.UsesKill = 1;
447 texImageUnit: TEXTURE_UNIT optTexImageUnitNum
453 texTarget: TEX_1D { $$ = TEXTURE_1D_INDEX; }
454 | TEX_2D { $$ = TEXTURE_2D_INDEX; }
455 | TEX_3D { $$ = TEXTURE_3D_INDEX; }
456 | TEX_CUBE { $$ = TEXTURE_CUBE_INDEX; }
457 | TEX_RECT { $$ = TEXTURE_RECT_INDEX; }
458 | TEX_SHADOW1D { $$ = -TEXTURE_1D_INDEX; }
459 | TEX_SHADOW2D { $$ = -TEXTURE_2D_INDEX; }
460 | TEX_SHADOWRECT { $$ = -TEXTURE_RECT_INDEX; }
461 | TEX_ARRAY1D { $$ = TEXTURE_1D_ARRAY_INDEX; }
462 | TEX_ARRAY2D { $$ = TEXTURE_2D_ARRAY_INDEX; }
463 | TEX_ARRAYSHADOW1D { $$ = -TEXTURE_1D_ARRAY_INDEX; }
464 | TEX_ARRAYSHADOW2D { $$ = -TEXTURE_2D_ARRAY_INDEX; }
467 SWZ_instruction: SWZ maskedDstReg ',' srcReg ',' extendedSwizzle
469 /* FIXME: Is this correct? Should the extenedSwizzle be applied
470 * FIXME: to the existing swizzle?
472 $4.Base.Swizzle = $6.swizzle;
473 $4.Base.Negate = $6.mask;
475 $$ = asm_instruction_ctor(OPCODE_SWZ, & $2, & $4, NULL, NULL);
476 $$->Base.SaturateMode = $1.SaturateMode;
480 scalarSrcReg: optionalSign srcReg scalarSuffix
485 $$.Base.Negate = ~$$.Base.Negate;
488 $$.Base.Swizzle = _mesa_combine_swizzles($$.Base.Swizzle,
493 swizzleSrcReg: optionalSign srcReg swizzleSuffix
498 $$.Base.Negate = ~$$.Base.Negate;
501 $$.Base.Swizzle = _mesa_combine_swizzles($$.Base.Swizzle,
506 maskedDstReg: dstReg optionalMask
509 $$.WriteMask = $2.mask;
511 if ($$.File == PROGRAM_OUTPUT) {
512 /* Technically speaking, this should check that it is in
513 * vertex program mode. However, PositionInvariant can never be
514 * set in fragment program mode, so it is somewhat irrelevant.
516 if (state->option.PositionInvariant
517 && ($$.Index == VERT_RESULT_HPOS)) {
518 yyerror(& @1, state, "position-invariant programs cannot "
523 state->prog->OutputsWritten |= (1U << $$.Index);
528 maskedAddrReg: addrReg addrWriteMask
531 $$.File = PROGRAM_ADDRESS;
533 $$.WriteMask = $2.mask;
537 extendedSwizzle: extSwizComp ',' extSwizComp ',' extSwizComp ',' extSwizComp
539 const unsigned xyzw_valid =
541 | ($3.xyzw_valid << 1)
542 | ($5.xyzw_valid << 2)
543 | ($7.xyzw_valid << 3);
544 const unsigned rgba_valid =
546 | ($3.rgba_valid << 1)
547 | ($5.rgba_valid << 2)
548 | ($7.rgba_valid << 3);
550 /* All of the swizzle components have to be valid in either RGBA
551 * or XYZW. Note that 0 and 1 are valid in both, so both masks
552 * can have some bits set.
554 * We somewhat deviate from the spec here. It would be really hard
555 * to figure out which component is the error, and there probably
556 * isn't a lot of benefit.
558 if ((rgba_valid != 0x0f) && (xyzw_valid != 0x0f)) {
559 yyerror(& @1, state, "cannot combine RGBA and XYZW swizzle "
564 $$.swizzle = MAKE_SWIZZLE4($1.swz, $3.swz, $5.swz, $7.swz);
565 $$.mask = ($1.negate) | ($3.negate << 1) | ($5.negate << 2)
570 extSwizComp: optionalSign extSwizSel
573 $$.negate = ($1) ? 1 : 0;
579 if (($1 != 0) && ($1 != 1)) {
580 yyerror(& @1, state, "invalid extended swizzle selector");
584 $$.swz = ($1 == 0) ? SWIZZLE_ZERO : SWIZZLE_ONE;
586 /* 0 and 1 are valid for both RGBA swizzle names and XYZW
594 if (strlen($1) > 1) {
595 yyerror(& @1, state, "invalid extended swizzle selector");
635 yyerror(& @1, state, "invalid extended swizzle selector");
642 srcReg: IDENTIFIER /* temporaryReg | progParamSingle */
644 struct asm_symbol *const s = (struct asm_symbol *)
645 _mesa_symbol_table_find_symbol(state->st, 0, $1);
648 yyerror(& @1, state, "invalid operand variable");
650 } else if ((s->type != at_param) && (s->type != at_temp)
651 && (s->type != at_attrib)) {
652 yyerror(& @1, state, "invalid operand variable");
654 } else if ((s->type == at_param) && s->param_is_array) {
655 yyerror(& @1, state, "non-array access to array PARAM");
662 $$.Base.File = PROGRAM_TEMPORARY;
663 $$.Base.Index = s->temp_binding;
666 $$.Base.File = s->param_binding_type;
667 $$.Base.Index = s->param_binding_begin;
670 $$.Base.File = PROGRAM_INPUT;
671 $$.Base.Index = s->attrib_binding;
672 state->prog->InputsRead |= (1U << $$.Base.Index);
674 if (!validate_inputs(& @1, state)) {
687 $$.Base.File = PROGRAM_INPUT;
689 state->prog->InputsRead |= (1U << $$.Base.Index);
691 if (!validate_inputs(& @1, state)) {
695 | progParamArray '[' progParamArrayMem ']'
697 if (! $3.Base.RelAddr
698 && ((unsigned) $3.Base.Index >= $1->param_binding_length)) {
699 yyerror(& @3, state, "out of bounds array access");
704 $$.Base.File = $1->param_binding_type;
706 if ($3.Base.RelAddr) {
707 $1->param_accessed_indirectly = 1;
710 $$.Base.Index = $3.Base.Index;
713 $$.Base.Index = $1->param_binding_begin + $3.Base.Index;
719 $$.Base.File = ($1.name != NULL)
720 ? $1.param_binding_type
722 $$.Base.Index = $1.param_binding_begin;
726 dstReg: resultBinding
729 $$.File = PROGRAM_OUTPUT;
732 | IDENTIFIER /* temporaryReg | vertexResultReg */
734 struct asm_symbol *const s = (struct asm_symbol *)
735 _mesa_symbol_table_find_symbol(state->st, 0, $1);
738 yyerror(& @1, state, "invalid operand variable");
740 } else if ((s->type != at_output) && (s->type != at_temp)) {
741 yyerror(& @1, state, "invalid operand variable");
748 $$.File = PROGRAM_TEMPORARY;
749 $$.Index = s->temp_binding;
752 $$.File = PROGRAM_OUTPUT;
753 $$.Index = s->output_binding;
756 $$.File = s->param_binding_type;
757 $$.Index = s->param_binding_begin;
763 progParamArray: IDENTIFIER
765 struct asm_symbol *const s = (struct asm_symbol *)
766 _mesa_symbol_table_find_symbol(state->st, 0, $1);
769 yyerror(& @1, state, "invalid operand variable");
771 } else if ((s->type != at_param) || !s->param_is_array) {
772 yyerror(& @1, state, "array access to non-PARAM variable");
780 progParamArrayMem: progParamArrayAbs | progParamArrayRel;
782 progParamArrayAbs: INTEGER
789 progParamArrayRel: addrReg addrComponent addrRegRelOffset
791 /* FINISHME: Add support for multiple address registers.
793 /* FINISHME: Add support for 4-component address registers.
801 addrRegRelOffset: { $$ = 0; }
802 | '+' addrRegPosOffset { $$ = $2; }
803 | '-' addrRegNegOffset { $$ = -$2; }
806 addrRegPosOffset: INTEGER
808 if (($1 < 0) || ($1 > 63)) {
810 _mesa_snprintf(s, sizeof(s),
811 "relative address offset too large (%d)", $1);
812 yyerror(& @1, state, s);
820 addrRegNegOffset: INTEGER
822 if (($1 < 0) || ($1 > 64)) {
824 _mesa_snprintf(s, sizeof(s),
825 "relative address offset too large (%d)", $1);
826 yyerror(& @1, state, s);
836 struct asm_symbol *const s = (struct asm_symbol *)
837 _mesa_symbol_table_find_symbol(state->st, 0, $1);
840 yyerror(& @1, state, "invalid array member");
842 } else if (s->type != at_address) {
844 "invalid variable for indexed array access");
854 if ($1.mask != WRITEMASK_X) {
855 yyerror(& @1, state, "invalid address component selector");
865 if ($1.mask != WRITEMASK_X) {
867 "address register write mask must be \".x\"");
880 | { $$.swizzle = SWIZZLE_NOOP; $$.mask = WRITEMASK_XYZW; }
883 optionalMask: MASK4 | MASK3 | MASK2 | MASK1
884 | { $$.swizzle = SWIZZLE_NOOP; $$.mask = WRITEMASK_XYZW; }
887 namingStatement: ATTRIB_statement
895 ATTRIB_statement: ATTRIB IDENTIFIER '=' attribBinding
897 struct asm_symbol *const s =
898 declare_variable(state, $2, at_attrib, & @2);
903 s->attrib_binding = $4;
904 state->InputsBound |= (1U << s->attrib_binding);
906 if (!validate_inputs(& @4, state)) {
913 attribBinding: VERTEX vtxAttribItem
917 | FRAGMENT fragAttribItem
923 vtxAttribItem: POSITION
925 $$ = VERT_ATTRIB_POS;
927 | WEIGHT vtxOptWeightNum
929 $$ = VERT_ATTRIB_WEIGHT;
933 $$ = VERT_ATTRIB_NORMAL;
937 if (!state->ctx->Extensions.EXT_secondary_color) {
938 yyerror(& @2, state, "GL_EXT_secondary_color not supported");
942 $$ = VERT_ATTRIB_COLOR0 + $2;
946 if (!state->ctx->Extensions.EXT_fog_coord) {
947 yyerror(& @1, state, "GL_EXT_fog_coord not supported");
951 $$ = VERT_ATTRIB_FOG;
953 | TEXCOORD optTexCoordUnitNum
955 $$ = VERT_ATTRIB_TEX0 + $2;
957 | MATRIXINDEX '[' vtxWeightNum ']'
959 yyerror(& @1, state, "GL_ARB_matrix_palette not supported");
962 | VTXATTRIB '[' vtxAttribNum ']'
964 $$ = VERT_ATTRIB_GENERIC0 + $3;
968 vtxAttribNum: INTEGER
970 if ((unsigned) $1 >= state->limits->MaxAttribs) {
971 yyerror(& @1, state, "invalid vertex attribute reference");
979 vtxOptWeightNum: | '[' vtxWeightNum ']';
980 vtxWeightNum: INTEGER;
982 fragAttribItem: POSITION
984 $$ = FRAG_ATTRIB_WPOS;
988 $$ = FRAG_ATTRIB_COL0 + $2;
992 $$ = FRAG_ATTRIB_FOGC;
994 | TEXCOORD optTexCoordUnitNum
996 $$ = FRAG_ATTRIB_TEX0 + $2;
1000 PARAM_statement: PARAM_singleStmt | PARAM_multipleStmt;
1002 PARAM_singleStmt: PARAM IDENTIFIER paramSingleInit
1004 struct asm_symbol *const s =
1005 declare_variable(state, $2, at_param, & @2);
1010 s->param_binding_type = $3.param_binding_type;
1011 s->param_binding_begin = $3.param_binding_begin;
1012 s->param_binding_length = $3.param_binding_length;
1013 s->param_is_array = 0;
1018 PARAM_multipleStmt: PARAM IDENTIFIER '[' optArraySize ']' paramMultipleInit
1020 if (($4 != 0) && ((unsigned) $4 != $6.param_binding_length)) {
1021 yyerror(& @4, state,
1022 "parameter array size and number of bindings must match");
1025 struct asm_symbol *const s =
1026 declare_variable(state, $2, $6.type, & @2);
1031 s->param_binding_type = $6.param_binding_type;
1032 s->param_binding_begin = $6.param_binding_begin;
1033 s->param_binding_length = $6.param_binding_length;
1034 s->param_is_array = 1;
1046 if (($1 < 1) || ((unsigned) $1 >= state->limits->MaxParameters)) {
1047 yyerror(& @1, state, "invalid parameter array size");
1055 paramSingleInit: '=' paramSingleItemDecl
1061 paramMultipleInit: '=' '{' paramMultInitList '}'
1067 paramMultInitList: paramMultipleItem
1068 | paramMultInitList ',' paramMultipleItem
1070 $1.param_binding_length += $3.param_binding_length;
1075 paramSingleItemDecl: stateSingleItem
1077 memset(& $$, 0, sizeof($$));
1078 $$.param_binding_begin = ~0;
1079 initialize_symbol_from_state(state->prog, & $$, $1);
1083 memset(& $$, 0, sizeof($$));
1084 $$.param_binding_begin = ~0;
1085 initialize_symbol_from_param(state->prog, & $$, $1);
1089 memset(& $$, 0, sizeof($$));
1090 $$.param_binding_begin = ~0;
1091 initialize_symbol_from_const(state->prog, & $$, & $1);
1095 paramSingleItemUse: stateSingleItem
1097 memset(& $$, 0, sizeof($$));
1098 $$.param_binding_begin = ~0;
1099 initialize_symbol_from_state(state->prog, & $$, $1);
1103 memset(& $$, 0, sizeof($$));
1104 $$.param_binding_begin = ~0;
1105 initialize_symbol_from_param(state->prog, & $$, $1);
1109 memset(& $$, 0, sizeof($$));
1110 $$.param_binding_begin = ~0;
1111 initialize_symbol_from_const(state->prog, & $$, & $1);
1115 paramMultipleItem: stateMultipleItem
1117 memset(& $$, 0, sizeof($$));
1118 $$.param_binding_begin = ~0;
1119 initialize_symbol_from_state(state->prog, & $$, $1);
1121 | programMultipleItem
1123 memset(& $$, 0, sizeof($$));
1124 $$.param_binding_begin = ~0;
1125 initialize_symbol_from_param(state->prog, & $$, $1);
1129 memset(& $$, 0, sizeof($$));
1130 $$.param_binding_begin = ~0;
1131 initialize_symbol_from_const(state->prog, & $$, & $1);
1135 stateMultipleItem: stateSingleItem { memcpy($$, $1, sizeof($$)); }
1136 | STATE stateMatrixRows { memcpy($$, $2, sizeof($$)); }
1139 stateSingleItem: STATE stateMaterialItem { memcpy($$, $2, sizeof($$)); }
1140 | STATE stateLightItem { memcpy($$, $2, sizeof($$)); }
1141 | STATE stateLightModelItem { memcpy($$, $2, sizeof($$)); }
1142 | STATE stateLightProdItem { memcpy($$, $2, sizeof($$)); }
1143 | STATE stateTexGenItem { memcpy($$, $2, sizeof($$)); }
1144 | STATE stateTexEnvItem { memcpy($$, $2, sizeof($$)); }
1145 | STATE stateFogItem { memcpy($$, $2, sizeof($$)); }
1146 | STATE stateClipPlaneItem { memcpy($$, $2, sizeof($$)); }
1147 | STATE statePointItem { memcpy($$, $2, sizeof($$)); }
1148 | STATE stateMatrixRow { memcpy($$, $2, sizeof($$)); }
1149 | STATE stateDepthItem { memcpy($$, $2, sizeof($$)); }
1152 stateMaterialItem: MATERIAL optFaceType stateMatProperty
1154 memset($$, 0, sizeof($$));
1155 $$[0] = STATE_MATERIAL;
1161 stateMatProperty: ambDiffSpecProperty
1167 $$ = STATE_EMISSION;
1171 $$ = STATE_SHININESS;
1175 stateLightItem: LIGHT '[' stateLightNumber ']' stateLightProperty
1177 memset($$, 0, sizeof($$));
1178 $$[0] = STATE_LIGHT;
1184 stateLightProperty: ambDiffSpecProperty
1190 $$ = STATE_POSITION;
1194 if (!state->ctx->Extensions.EXT_point_parameters) {
1195 yyerror(& @1, state, "GL_ARB_point_parameters not supported");
1199 $$ = STATE_ATTENUATION;
1201 | SPOT stateSpotProperty
1207 $$ = STATE_HALF_VECTOR;
1211 stateSpotProperty: DIRECTION
1213 $$ = STATE_SPOT_DIRECTION;
1217 stateLightModelItem: LIGHTMODEL stateLModProperty
1224 stateLModProperty: AMBIENT
1226 memset($$, 0, sizeof($$));
1227 $$[0] = STATE_LIGHTMODEL_AMBIENT;
1229 | optFaceType SCENECOLOR
1231 memset($$, 0, sizeof($$));
1232 $$[0] = STATE_LIGHTMODEL_SCENECOLOR;
1237 stateLightProdItem: LIGHTPROD '[' stateLightNumber ']' optFaceType stateLProdProperty
1239 memset($$, 0, sizeof($$));
1240 $$[0] = STATE_LIGHTPROD;
1247 stateLProdProperty: ambDiffSpecProperty;
1249 stateTexEnvItem: TEXENV optLegacyTexUnitNum stateTexEnvProperty
1251 memset($$, 0, sizeof($$));
1257 stateTexEnvProperty: COLOR
1259 $$ = STATE_TEXENV_COLOR;
1263 ambDiffSpecProperty: AMBIENT
1273 $$ = STATE_SPECULAR;
1277 stateLightNumber: INTEGER
1279 if ((unsigned) $1 >= state->MaxLights) {
1280 yyerror(& @1, state, "invalid light selector");
1288 stateTexGenItem: TEXGEN optTexCoordUnitNum stateTexGenType stateTexGenCoord
1290 memset($$, 0, sizeof($$));
1291 $$[0] = STATE_TEXGEN;
1297 stateTexGenType: EYE
1299 $$ = STATE_TEXGEN_EYE_S;
1303 $$ = STATE_TEXGEN_OBJECT_S;
1306 stateTexGenCoord: TEXGEN_S
1308 $$ = STATE_TEXGEN_EYE_S - STATE_TEXGEN_EYE_S;
1312 $$ = STATE_TEXGEN_EYE_T - STATE_TEXGEN_EYE_S;
1316 $$ = STATE_TEXGEN_EYE_R - STATE_TEXGEN_EYE_S;
1320 $$ = STATE_TEXGEN_EYE_Q - STATE_TEXGEN_EYE_S;
1324 stateFogItem: FOG stateFogProperty
1326 memset($$, 0, sizeof($$));
1331 stateFogProperty: COLOR
1333 $$ = STATE_FOG_COLOR;
1337 $$ = STATE_FOG_PARAMS;
1341 stateClipPlaneItem: CLIP '[' stateClipPlaneNum ']' PLANE
1343 memset($$, 0, sizeof($$));
1344 $$[0] = STATE_CLIPPLANE;
1349 stateClipPlaneNum: INTEGER
1351 if ((unsigned) $1 >= state->MaxClipPlanes) {
1352 yyerror(& @1, state, "invalid clip plane selector");
1360 statePointItem: POINT_TOK statePointProperty
1362 memset($$, 0, sizeof($$));
1367 statePointProperty: SIZE_TOK
1369 $$ = STATE_POINT_SIZE;
1373 $$ = STATE_POINT_ATTENUATION;
1377 stateMatrixRow: stateMatrixItem ROW '[' stateMatrixRowNum ']'
1387 stateMatrixRows: stateMatrixItem optMatrixRows
1402 | ROW '[' stateMatrixRowNum DOT_DOT stateMatrixRowNum ']'
1404 /* It seems logical that the matrix row range specifier would have
1405 * to specify a range or more than one row (i.e., $5 > $3).
1406 * However, the ARB_vertex_program spec says "a program will fail
1407 * to load if <a> is greater than <b>." This means that $3 == $5
1411 yyerror(& @3, state, "invalid matrix row range");
1420 stateMatrixItem: MATRIX stateMatrixName stateOptMatModifier
1428 stateOptMatModifier:
1438 stateMatModifier: INVERSE
1440 $$ = STATE_MATRIX_INVERSE;
1444 $$ = STATE_MATRIX_TRANSPOSE;
1448 $$ = STATE_MATRIX_INVTRANS;
1452 stateMatrixRowNum: INTEGER
1455 yyerror(& @1, state, "invalid matrix row reference");
1463 stateMatrixName: MODELVIEW stateOptModMatNum
1465 $$[0] = STATE_MODELVIEW_MATRIX;
1470 $$[0] = STATE_PROJECTION_MATRIX;
1475 $$[0] = STATE_MVP_MATRIX;
1478 | TEXTURE optTexCoordUnitNum
1480 $$[0] = STATE_TEXTURE_MATRIX;
1483 | PALETTE '[' statePaletteMatNum ']'
1485 yyerror(& @1, state, "GL_ARB_matrix_palette not supported");
1488 | MAT_PROGRAM '[' stateProgramMatNum ']'
1490 $$[0] = STATE_PROGRAM_MATRIX;
1499 | '[' stateModMatNum ']'
1504 stateModMatNum: INTEGER
1506 /* Since GL_ARB_vertex_blend isn't supported, only modelview matrix
1510 yyerror(& @1, state, "invalid modelview matrix index");
1517 statePaletteMatNum: INTEGER
1519 /* Since GL_ARB_matrix_palette isn't supported, just let any value
1520 * through here. The error will be generated later.
1525 stateProgramMatNum: INTEGER
1527 if ((unsigned) $1 >= state->MaxProgramMatrices) {
1528 yyerror(& @1, state, "invalid program matrix selector");
1536 stateDepthItem: DEPTH RANGE
1538 memset($$, 0, sizeof($$));
1539 $$[0] = STATE_DEPTH_RANGE;
1544 programSingleItem: progEnvParam | progLocalParam;
1546 programMultipleItem: progEnvParams | progLocalParams;
1548 progEnvParams: PROGRAM ENV '[' progEnvParamNums ']'
1550 memset($$, 0, sizeof($$));
1551 $$[0] = state->state_param_enum;
1558 progEnvParamNums: progEnvParamNum
1563 | progEnvParamNum DOT_DOT progEnvParamNum
1570 progEnvParam: PROGRAM ENV '[' progEnvParamNum ']'
1572 memset($$, 0, sizeof($$));
1573 $$[0] = state->state_param_enum;
1580 progLocalParams: PROGRAM LOCAL '[' progLocalParamNums ']'
1582 memset($$, 0, sizeof($$));
1583 $$[0] = state->state_param_enum;
1584 $$[1] = STATE_LOCAL;
1589 progLocalParamNums: progLocalParamNum
1594 | progLocalParamNum DOT_DOT progLocalParamNum
1601 progLocalParam: PROGRAM LOCAL '[' progLocalParamNum ']'
1603 memset($$, 0, sizeof($$));
1604 $$[0] = state->state_param_enum;
1605 $$[1] = STATE_LOCAL;
1611 progEnvParamNum: INTEGER
1613 if ((unsigned) $1 >= state->limits->MaxEnvParams) {
1614 yyerror(& @1, state, "invalid environment parameter reference");
1621 progLocalParamNum: INTEGER
1623 if ((unsigned) $1 >= state->limits->MaxLocalParams) {
1624 yyerror(& @1, state, "invalid local parameter reference");
1633 paramConstDecl: paramConstScalarDecl | paramConstVector;
1634 paramConstUse: paramConstScalarUse | paramConstVector;
1636 paramConstScalarDecl: signedFloatConstant
1646 paramConstScalarUse: REAL
1657 $$.data[0] = (float) $1;
1658 $$.data[1] = (float) $1;
1659 $$.data[2] = (float) $1;
1660 $$.data[3] = (float) $1;
1664 paramConstVector: '{' signedFloatConstant '}'
1672 | '{' signedFloatConstant ',' signedFloatConstant '}'
1680 | '{' signedFloatConstant ',' signedFloatConstant ','
1681 signedFloatConstant '}'
1689 | '{' signedFloatConstant ',' signedFloatConstant ','
1690 signedFloatConstant ',' signedFloatConstant '}'
1700 signedFloatConstant: optionalSign REAL
1702 $$ = ($1) ? -$2 : $2;
1704 | optionalSign INTEGER
1706 $$ = (float)(($1) ? -$2 : $2);
1710 optionalSign: '+' { $$ = FALSE; }
1711 | '-' { $$ = TRUE; }
1715 TEMP_statement: TEMP { $<integer>$ = $1; } varNameList
1718 ADDRESS_statement: ADDRESS { $<integer>$ = $1; } varNameList
1721 varNameList: varNameList ',' IDENTIFIER
1723 if (!declare_variable(state, $3, $<integer>0, & @3)) {
1729 if (!declare_variable(state, $1, $<integer>0, & @1)) {
1735 OUTPUT_statement: OUTPUT IDENTIFIER '=' resultBinding
1737 struct asm_symbol *const s =
1738 declare_variable(state, $2, at_output, & @2);
1743 s->output_binding = $4;
1748 resultBinding: RESULT POSITION
1750 if (state->mode == ARB_vertex) {
1751 $$ = VERT_RESULT_HPOS;
1753 yyerror(& @2, state, "invalid program result name");
1759 if (state->mode == ARB_vertex) {
1760 $$ = VERT_RESULT_FOGC;
1762 yyerror(& @2, state, "invalid program result name");
1766 | RESULT resultColBinding
1772 if (state->mode == ARB_vertex) {
1773 $$ = VERT_RESULT_PSIZ;
1775 yyerror(& @2, state, "invalid program result name");
1779 | RESULT TEXCOORD optTexCoordUnitNum
1781 if (state->mode == ARB_vertex) {
1782 $$ = VERT_RESULT_TEX0 + $3;
1784 yyerror(& @2, state, "invalid program result name");
1790 if (state->mode == ARB_fragment) {
1791 $$ = FRAG_RESULT_DEPTH;
1793 yyerror(& @2, state, "invalid program result name");
1799 resultColBinding: COLOR optResultFaceType optResultColorType
1807 $$ = (state->mode == ARB_vertex)
1809 : FRAG_RESULT_COLOR;
1813 if (state->mode == ARB_vertex) {
1814 $$ = VERT_RESULT_COL0;
1816 yyerror(& @1, state, "invalid program result name");
1822 if (state->mode == ARB_vertex) {
1823 $$ = VERT_RESULT_BFC0;
1825 yyerror(& @1, state, "invalid program result name");
1837 if (state->mode == ARB_vertex) {
1840 yyerror(& @1, state, "invalid program result name");
1846 if (state->mode == ARB_vertex) {
1849 yyerror(& @1, state, "invalid program result name");
1855 optFaceType: { $$ = 0; }
1860 optColorType: { $$ = 0; }
1861 | PRIMARY { $$ = 0; }
1862 | SECONDARY { $$ = 1; }
1865 optTexCoordUnitNum: { $$ = 0; }
1866 | '[' texCoordUnitNum ']' { $$ = $2; }
1869 optTexImageUnitNum: { $$ = 0; }
1870 | '[' texImageUnitNum ']' { $$ = $2; }
1873 optLegacyTexUnitNum: { $$ = 0; }
1874 | '[' legacyTexUnitNum ']' { $$ = $2; }
1877 texCoordUnitNum: INTEGER
1879 if ((unsigned) $1 >= state->MaxTextureCoordUnits) {
1880 yyerror(& @1, state, "invalid texture coordinate unit selector");
1888 texImageUnitNum: INTEGER
1890 if ((unsigned) $1 >= state->MaxTextureImageUnits) {
1891 yyerror(& @1, state, "invalid texture image unit selector");
1899 legacyTexUnitNum: INTEGER
1901 if ((unsigned) $1 >= state->MaxTextureUnits) {
1902 yyerror(& @1, state, "invalid texture unit selector");
1910 ALIAS_statement: ALIAS IDENTIFIER '=' IDENTIFIER
1912 struct asm_symbol *exist = (struct asm_symbol *)
1913 _mesa_symbol_table_find_symbol(state->st, 0, $2);
1914 struct asm_symbol *target = (struct asm_symbol *)
1915 _mesa_symbol_table_find_symbol(state->st, 0, $4);
1918 if (exist != NULL) {
1919 yyerror(& @2, state, "redeclared identifier");
1921 } else if (target == NULL) {
1922 yyerror(& @4, state,
1923 "undefined variable binding in ALIAS statement");
1926 _mesa_symbol_table_add_symbol(state->st, 0, $2, target);
1933 struct asm_instruction *
1934 asm_instruction_ctor(gl_inst_opcode op,
1935 const struct prog_dst_register *dst,
1936 const struct asm_src_register *src0,
1937 const struct asm_src_register *src1,
1938 const struct asm_src_register *src2)
1940 struct asm_instruction *inst = calloc(1, sizeof(struct asm_instruction));
1943 _mesa_init_instructions(& inst->Base, 1);
1944 inst->Base.Opcode = op;
1946 /* In the core ARB extensions only the KIL instruction doesn't have a
1947 * destination register.
1950 init_dst_reg(& inst->Base.DstReg);
1952 inst->Base.DstReg = *dst;
1955 inst->Base.SrcReg[0] = src0->Base;
1956 inst->SrcReg[0] = *src0;
1959 inst->Base.SrcReg[1] = src1->Base;
1960 inst->SrcReg[1] = *src1;
1962 init_src_reg(& inst->SrcReg[1]);
1966 inst->Base.SrcReg[2] = src2->Base;
1967 inst->SrcReg[2] = *src2;
1969 init_src_reg(& inst->SrcReg[2]);
1978 init_dst_reg(struct prog_dst_register *r)
1980 memset(r, 0, sizeof(*r));
1981 r->File = PROGRAM_UNDEFINED;
1982 r->WriteMask = WRITEMASK_XYZW;
1983 r->CondMask = COND_TR;
1984 r->CondSwizzle = SWIZZLE_NOOP;
1989 init_src_reg(struct asm_src_register *r)
1991 memset(r, 0, sizeof(*r));
1992 r->Base.File = PROGRAM_UNDEFINED;
1993 r->Base.Swizzle = SWIZZLE_NOOP;
1999 * Validate the set of inputs used by a program
2001 * Validates that legal sets of inputs are used by the program. In this case
2002 * "used" included both reading the input or binding the input to a name using
2003 * the \c ATTRIB command.
2006 * \c TRUE if the combination of inputs used is valid, \c FALSE otherwise.
2009 validate_inputs(struct YYLTYPE *locp, struct asm_parser_state *state)
2011 const int inputs = state->prog->InputsRead | state->InputsBound;
2013 if (((inputs & 0x0ffff) & (inputs >> 16)) != 0) {
2014 yyerror(locp, state, "illegal use of generic attribute and name attribute");
2023 declare_variable(struct asm_parser_state *state, char *name, enum asm_type t,
2024 struct YYLTYPE *locp)
2026 struct asm_symbol *s = NULL;
2027 struct asm_symbol *exist = (struct asm_symbol *)
2028 _mesa_symbol_table_find_symbol(state->st, 0, name);
2031 if (exist != NULL) {
2032 yyerror(locp, state, "redeclared identifier");
2034 s = calloc(1, sizeof(struct asm_symbol));
2040 if (state->prog->NumTemporaries >= state->limits->MaxTemps) {
2041 yyerror(locp, state, "too many temporaries declared");
2046 s->temp_binding = state->prog->NumTemporaries;
2047 state->prog->NumTemporaries++;
2051 if (state->prog->NumAddressRegs >= state->limits->MaxAddressRegs) {
2052 yyerror(locp, state, "too many address registers declared");
2057 /* FINISHME: Add support for multiple address registers.
2059 state->prog->NumAddressRegs++;
2066 _mesa_symbol_table_add_symbol(state->st, 0, s->name, s);
2067 s->next = state->sym;
2075 int add_state_reference(struct gl_program_parameter_list *param_list,
2076 const gl_state_index tokens[STATE_LENGTH])
2078 const GLuint size = 4; /* XXX fix */
2082 name = _mesa_program_state_string(tokens);
2083 index = _mesa_add_parameter(param_list, PROGRAM_STATE_VAR, name,
2084 size, GL_NONE, NULL, tokens, 0x0);
2085 param_list->StateFlags |= _mesa_program_state_flags(tokens);
2087 /* free name string here since we duplicated it in add_parameter() */
2095 initialize_symbol_from_state(struct gl_program *prog,
2096 struct asm_symbol *param_var,
2097 const gl_state_index tokens[STATE_LENGTH])
2100 gl_state_index state_tokens[STATE_LENGTH];
2103 memcpy(state_tokens, tokens, sizeof(state_tokens));
2105 param_var->type = at_param;
2106 param_var->param_binding_type = PROGRAM_STATE_VAR;
2108 /* If we are adding a STATE_MATRIX that has multiple rows, we need to
2109 * unroll it and call add_state_reference() for each row
2111 if ((state_tokens[0] == STATE_MODELVIEW_MATRIX ||
2112 state_tokens[0] == STATE_PROJECTION_MATRIX ||
2113 state_tokens[0] == STATE_MVP_MATRIX ||
2114 state_tokens[0] == STATE_TEXTURE_MATRIX ||
2115 state_tokens[0] == STATE_PROGRAM_MATRIX)
2116 && (state_tokens[2] != state_tokens[3])) {
2118 const int first_row = state_tokens[2];
2119 const int last_row = state_tokens[3];
2121 for (row = first_row; row <= last_row; row++) {
2122 state_tokens[2] = state_tokens[3] = row;
2124 idx = add_state_reference(prog->Parameters, state_tokens);
2125 if (param_var->param_binding_begin == ~0U)
2126 param_var->param_binding_begin = idx;
2127 param_var->param_binding_length++;
2131 idx = add_state_reference(prog->Parameters, state_tokens);
2132 if (param_var->param_binding_begin == ~0U)
2133 param_var->param_binding_begin = idx;
2134 param_var->param_binding_length++;
2142 initialize_symbol_from_param(struct gl_program *prog,
2143 struct asm_symbol *param_var,
2144 const gl_state_index tokens[STATE_LENGTH])
2147 gl_state_index state_tokens[STATE_LENGTH];
2150 memcpy(state_tokens, tokens, sizeof(state_tokens));
2152 assert((state_tokens[0] == STATE_VERTEX_PROGRAM)
2153 || (state_tokens[0] == STATE_FRAGMENT_PROGRAM));
2154 assert((state_tokens[1] == STATE_ENV)
2155 || (state_tokens[1] == STATE_LOCAL));
2157 param_var->type = at_param;
2158 param_var->param_binding_type = (state_tokens[1] == STATE_ENV)
2159 ? PROGRAM_ENV_PARAM : PROGRAM_LOCAL_PARAM;
2161 /* If we are adding a STATE_ENV or STATE_LOCAL that has multiple elements,
2162 * we need to unroll it and call add_state_reference() for each row
2164 if (state_tokens[2] != state_tokens[3]) {
2166 const int first_row = state_tokens[2];
2167 const int last_row = state_tokens[3];
2169 for (row = first_row; row <= last_row; row++) {
2170 state_tokens[2] = state_tokens[3] = row;
2172 idx = add_state_reference(prog->Parameters, state_tokens);
2173 if (param_var->param_binding_begin == ~0U)
2174 param_var->param_binding_begin = idx;
2175 param_var->param_binding_length++;
2179 idx = add_state_reference(prog->Parameters, state_tokens);
2180 if (param_var->param_binding_begin == ~0U)
2181 param_var->param_binding_begin = idx;
2182 param_var->param_binding_length++;
2190 initialize_symbol_from_const(struct gl_program *prog,
2191 struct asm_symbol *param_var,
2192 const struct asm_vector *vec)
2194 const int idx = _mesa_add_parameter(prog->Parameters, PROGRAM_CONSTANT,
2195 NULL, vec->count, GL_NONE, vec->data,
2198 param_var->type = at_param;
2199 param_var->param_binding_type = PROGRAM_CONSTANT;
2201 if (param_var->param_binding_begin == ~0U)
2202 param_var->param_binding_begin = idx;
2203 param_var->param_binding_length++;
2210 make_error_string(const char *fmt, ...)
2216 va_start(args, fmt);
2218 /* Call vsnprintf once to determine how large the final string is. Call it
2219 * again to do the actual formatting. from the vsnprintf manual page:
2221 * Upon successful return, these functions return the number of
2222 * characters printed (not including the trailing '\0' used to end
2223 * output to strings).
2225 length = 1 + vsnprintf(NULL, 0, fmt, args);
2227 str = _mesa_malloc(length);
2229 vsnprintf(str, length, fmt, args);
2239 yyerror(YYLTYPE *locp, struct asm_parser_state *state, const char *s)
2244 err_str = make_error_string("glProgramStringARB(%s)\n", s);
2246 _mesa_error(state->ctx, GL_INVALID_OPERATION, err_str);
2247 _mesa_free(err_str);
2250 err_str = make_error_string("line %u, char %u: error: %s\n",
2251 locp->first_line, locp->first_column, s);
2252 _mesa_set_program_error(state->ctx, locp->position, err_str);
2255 _mesa_free(err_str);
2261 _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
2262 GLsizei len, struct asm_parser_state *state)
2264 struct asm_instruction *inst;
2267 GLboolean result = GL_FALSE;
2269 struct asm_symbol *sym;
2272 state->prog->Target = target;
2273 state->prog->Parameters = _mesa_new_parameter_list();
2275 /* Make a copy of the program string and force it to be NUL-terminated.
2277 strz = (GLubyte *) _mesa_malloc(len + 1);
2279 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramStringARB");
2282 _mesa_memcpy (strz, str, len);
2285 state->prog->String = strz;
2287 state->st = _mesa_symbol_table_ctor();
2289 state->limits = (target == GL_VERTEX_PROGRAM_ARB)
2290 ? & ctx->Const.VertexProgram
2291 : & ctx->Const.FragmentProgram;
2293 state->MaxTextureImageUnits = ctx->Const.MaxTextureImageUnits;
2294 state->MaxTextureCoordUnits = ctx->Const.MaxTextureCoordUnits;
2295 state->MaxTextureUnits = ctx->Const.MaxTextureUnits;
2296 state->MaxClipPlanes = ctx->Const.MaxClipPlanes;
2297 state->MaxLights = ctx->Const.MaxLights;
2298 state->MaxProgramMatrices = ctx->Const.MaxProgramMatrices;
2300 state->state_param_enum = (target == GL_VERTEX_PROGRAM_ARB)
2301 ? STATE_VERTEX_PROGRAM : STATE_FRAGMENT_PROGRAM;
2303 _mesa_set_program_error(ctx, -1, NULL);
2305 _mesa_program_lexer_ctor(& state->scanner, state, (const char *) str, len);
2307 _mesa_program_lexer_dtor(state->scanner);
2310 if (ctx->Program.ErrorPos != -1) {
2314 if (! _mesa_layout_parameters(state)) {
2318 loc.first_column = 0;
2321 yyerror(& loc, state, "invalid PARAM usage");
2327 /* Add one instruction to store the "END" instruction.
2329 state->prog->Instructions =
2330 _mesa_alloc_instructions(state->prog->NumInstructions + 1);
2331 inst = state->inst_head;
2332 for (i = 0; i < state->prog->NumInstructions; i++) {
2333 struct asm_instruction *const temp = inst->next;
2335 state->prog->Instructions[i] = inst->Base;
2339 /* Finally, tag on an OPCODE_END instruction */
2341 const GLuint numInst = state->prog->NumInstructions;
2342 _mesa_init_instructions(state->prog->Instructions + numInst, 1);
2343 state->prog->Instructions[numInst].Opcode = OPCODE_END;
2345 state->prog->NumInstructions++;
2347 state->prog->NumParameters = state->prog->Parameters->NumParameters;
2348 state->prog->NumAttributes = _mesa_bitcount(state->prog->InputsRead);
2351 * Initialize native counts to logical counts. The device driver may
2352 * change them if program is translated into a hardware program.
2354 state->prog->NumNativeInstructions = state->prog->NumInstructions;
2355 state->prog->NumNativeTemporaries = state->prog->NumTemporaries;
2356 state->prog->NumNativeParameters = state->prog->NumParameters;
2357 state->prog->NumNativeAttributes = state->prog->NumAttributes;
2358 state->prog->NumNativeAddressRegs = state->prog->NumAddressRegs;
2363 for (inst = state->inst_head; inst != NULL; inst = temp) {
2368 state->inst_head = NULL;
2369 state->inst_tail = NULL;
2371 for (sym = state->sym; sym != NULL; sym = temp) {
2374 _mesa_free((void *) sym->name);
2379 _mesa_symbol_table_dtor(state->st);