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 "relative address offset too large (positive)");
818 addrRegNegOffset: INTEGER
820 if (($1 < 0) || ($1 > 64)) {
822 "relative address offset too large (negative)");
832 struct asm_symbol *const s = (struct asm_symbol *)
833 _mesa_symbol_table_find_symbol(state->st, 0, $1);
836 yyerror(& @1, state, "invalid array member");
838 } else if (s->type != at_address) {
840 "invalid variable for indexed array access");
850 if ($1.mask != WRITEMASK_X) {
851 yyerror(& @1, state, "invalid address component selector");
861 if ($1.mask != WRITEMASK_X) {
863 "address register write mask must be \".x\"");
876 | { $$.swizzle = SWIZZLE_NOOP; $$.mask = WRITEMASK_XYZW; }
879 optionalMask: MASK4 | MASK3 | MASK2 | MASK1
880 | { $$.swizzle = SWIZZLE_NOOP; $$.mask = WRITEMASK_XYZW; }
883 namingStatement: ATTRIB_statement
891 ATTRIB_statement: ATTRIB IDENTIFIER '=' attribBinding
893 struct asm_symbol *const s =
894 declare_variable(state, $2, at_attrib, & @2);
899 s->attrib_binding = $4;
900 state->InputsBound |= (1U << s->attrib_binding);
902 if (!validate_inputs(& @4, state)) {
909 attribBinding: VERTEX vtxAttribItem
913 | FRAGMENT fragAttribItem
919 vtxAttribItem: POSITION
921 $$ = VERT_ATTRIB_POS;
923 | WEIGHT vtxOptWeightNum
925 $$ = VERT_ATTRIB_WEIGHT;
929 $$ = VERT_ATTRIB_NORMAL;
933 if (!state->ctx->Extensions.EXT_secondary_color) {
934 yyerror(& @2, state, "GL_EXT_secondary_color not supported");
938 $$ = VERT_ATTRIB_COLOR0 + $2;
942 if (!state->ctx->Extensions.EXT_fog_coord) {
943 yyerror(& @1, state, "GL_EXT_fog_coord not supported");
947 $$ = VERT_ATTRIB_FOG;
949 | TEXCOORD optTexCoordUnitNum
951 $$ = VERT_ATTRIB_TEX0 + $2;
953 | MATRIXINDEX '[' vtxWeightNum ']'
955 yyerror(& @1, state, "GL_ARB_matrix_palette not supported");
958 | VTXATTRIB '[' vtxAttribNum ']'
960 $$ = VERT_ATTRIB_GENERIC0 + $3;
964 vtxAttribNum: INTEGER
966 if ((unsigned) $1 >= state->limits->MaxAttribs) {
967 yyerror(& @1, state, "invalid vertex attribute reference");
975 vtxOptWeightNum: | '[' vtxWeightNum ']';
976 vtxWeightNum: INTEGER;
978 fragAttribItem: POSITION
980 $$ = FRAG_ATTRIB_WPOS;
984 $$ = FRAG_ATTRIB_COL0 + $2;
988 $$ = FRAG_ATTRIB_FOGC;
990 | TEXCOORD optTexCoordUnitNum
992 $$ = FRAG_ATTRIB_TEX0 + $2;
996 PARAM_statement: PARAM_singleStmt | PARAM_multipleStmt;
998 PARAM_singleStmt: PARAM IDENTIFIER paramSingleInit
1000 struct asm_symbol *const s =
1001 declare_variable(state, $2, at_param, & @2);
1006 s->param_binding_type = $3.param_binding_type;
1007 s->param_binding_begin = $3.param_binding_begin;
1008 s->param_binding_length = $3.param_binding_length;
1009 s->param_is_array = 0;
1014 PARAM_multipleStmt: PARAM IDENTIFIER '[' optArraySize ']' paramMultipleInit
1016 if (($4 != 0) && ((unsigned) $4 != $6.param_binding_length)) {
1017 yyerror(& @4, state,
1018 "parameter array size and number of bindings must match");
1021 struct asm_symbol *const s =
1022 declare_variable(state, $2, $6.type, & @2);
1027 s->param_binding_type = $6.param_binding_type;
1028 s->param_binding_begin = $6.param_binding_begin;
1029 s->param_binding_length = $6.param_binding_length;
1030 s->param_is_array = 1;
1042 if (($1 < 1) || ((unsigned) $1 >= state->limits->MaxParameters)) {
1043 yyerror(& @1, state, "invalid parameter array size");
1051 paramSingleInit: '=' paramSingleItemDecl
1057 paramMultipleInit: '=' '{' paramMultInitList '}'
1063 paramMultInitList: paramMultipleItem
1064 | paramMultInitList ',' paramMultipleItem
1066 $1.param_binding_length += $3.param_binding_length;
1071 paramSingleItemDecl: stateSingleItem
1073 memset(& $$, 0, sizeof($$));
1074 $$.param_binding_begin = ~0;
1075 initialize_symbol_from_state(state->prog, & $$, $1);
1079 memset(& $$, 0, sizeof($$));
1080 $$.param_binding_begin = ~0;
1081 initialize_symbol_from_param(state->prog, & $$, $1);
1085 memset(& $$, 0, sizeof($$));
1086 $$.param_binding_begin = ~0;
1087 initialize_symbol_from_const(state->prog, & $$, & $1);
1091 paramSingleItemUse: stateSingleItem
1093 memset(& $$, 0, sizeof($$));
1094 $$.param_binding_begin = ~0;
1095 initialize_symbol_from_state(state->prog, & $$, $1);
1099 memset(& $$, 0, sizeof($$));
1100 $$.param_binding_begin = ~0;
1101 initialize_symbol_from_param(state->prog, & $$, $1);
1105 memset(& $$, 0, sizeof($$));
1106 $$.param_binding_begin = ~0;
1107 initialize_symbol_from_const(state->prog, & $$, & $1);
1111 paramMultipleItem: stateMultipleItem
1113 memset(& $$, 0, sizeof($$));
1114 $$.param_binding_begin = ~0;
1115 initialize_symbol_from_state(state->prog, & $$, $1);
1117 | programMultipleItem
1119 memset(& $$, 0, sizeof($$));
1120 $$.param_binding_begin = ~0;
1121 initialize_symbol_from_param(state->prog, & $$, $1);
1125 memset(& $$, 0, sizeof($$));
1126 $$.param_binding_begin = ~0;
1127 initialize_symbol_from_const(state->prog, & $$, & $1);
1131 stateMultipleItem: stateSingleItem { memcpy($$, $1, sizeof($$)); }
1132 | STATE stateMatrixRows { memcpy($$, $2, sizeof($$)); }
1135 stateSingleItem: STATE stateMaterialItem { memcpy($$, $2, sizeof($$)); }
1136 | STATE stateLightItem { memcpy($$, $2, sizeof($$)); }
1137 | STATE stateLightModelItem { memcpy($$, $2, sizeof($$)); }
1138 | STATE stateLightProdItem { memcpy($$, $2, sizeof($$)); }
1139 | STATE stateTexGenItem { memcpy($$, $2, sizeof($$)); }
1140 | STATE stateTexEnvItem { memcpy($$, $2, sizeof($$)); }
1141 | STATE stateFogItem { memcpy($$, $2, sizeof($$)); }
1142 | STATE stateClipPlaneItem { memcpy($$, $2, sizeof($$)); }
1143 | STATE statePointItem { memcpy($$, $2, sizeof($$)); }
1144 | STATE stateMatrixRow { memcpy($$, $2, sizeof($$)); }
1145 | STATE stateDepthItem { memcpy($$, $2, sizeof($$)); }
1148 stateMaterialItem: MATERIAL optFaceType stateMatProperty
1150 memset($$, 0, sizeof($$));
1151 $$[0] = STATE_MATERIAL;
1157 stateMatProperty: ambDiffSpecProperty
1163 $$ = STATE_EMISSION;
1167 $$ = STATE_SHININESS;
1171 stateLightItem: LIGHT '[' stateLightNumber ']' stateLightProperty
1173 memset($$, 0, sizeof($$));
1174 $$[0] = STATE_LIGHT;
1180 stateLightProperty: ambDiffSpecProperty
1186 $$ = STATE_POSITION;
1190 if (!state->ctx->Extensions.EXT_point_parameters) {
1191 yyerror(& @1, state, "GL_ARB_point_parameters not supported");
1195 $$ = STATE_ATTENUATION;
1197 | SPOT stateSpotProperty
1203 $$ = STATE_HALF_VECTOR;
1207 stateSpotProperty: DIRECTION
1209 $$ = STATE_SPOT_DIRECTION;
1213 stateLightModelItem: LIGHTMODEL stateLModProperty
1220 stateLModProperty: AMBIENT
1222 memset($$, 0, sizeof($$));
1223 $$[0] = STATE_LIGHTMODEL_AMBIENT;
1225 | optFaceType SCENECOLOR
1227 memset($$, 0, sizeof($$));
1228 $$[0] = STATE_LIGHTMODEL_SCENECOLOR;
1233 stateLightProdItem: LIGHTPROD '[' stateLightNumber ']' optFaceType stateLProdProperty
1235 memset($$, 0, sizeof($$));
1236 $$[0] = STATE_LIGHTPROD;
1243 stateLProdProperty: ambDiffSpecProperty;
1245 stateTexEnvItem: TEXENV optLegacyTexUnitNum stateTexEnvProperty
1247 memset($$, 0, sizeof($$));
1253 stateTexEnvProperty: COLOR
1255 $$ = STATE_TEXENV_COLOR;
1259 ambDiffSpecProperty: AMBIENT
1269 $$ = STATE_SPECULAR;
1273 stateLightNumber: INTEGER
1275 if ((unsigned) $1 >= state->MaxLights) {
1276 yyerror(& @1, state, "invalid light selector");
1284 stateTexGenItem: TEXGEN optTexCoordUnitNum stateTexGenType stateTexGenCoord
1286 memset($$, 0, sizeof($$));
1287 $$[0] = STATE_TEXGEN;
1293 stateTexGenType: EYE
1295 $$ = STATE_TEXGEN_EYE_S;
1299 $$ = STATE_TEXGEN_OBJECT_S;
1302 stateTexGenCoord: TEXGEN_S
1304 $$ = STATE_TEXGEN_EYE_S - STATE_TEXGEN_EYE_S;
1308 $$ = STATE_TEXGEN_EYE_T - STATE_TEXGEN_EYE_S;
1312 $$ = STATE_TEXGEN_EYE_R - STATE_TEXGEN_EYE_S;
1316 $$ = STATE_TEXGEN_EYE_Q - STATE_TEXGEN_EYE_S;
1320 stateFogItem: FOG stateFogProperty
1322 memset($$, 0, sizeof($$));
1327 stateFogProperty: COLOR
1329 $$ = STATE_FOG_COLOR;
1333 $$ = STATE_FOG_PARAMS;
1337 stateClipPlaneItem: CLIP '[' stateClipPlaneNum ']' PLANE
1339 memset($$, 0, sizeof($$));
1340 $$[0] = STATE_CLIPPLANE;
1345 stateClipPlaneNum: INTEGER
1347 if ((unsigned) $1 >= state->MaxClipPlanes) {
1348 yyerror(& @1, state, "invalid clip plane selector");
1356 statePointItem: POINT_TOK statePointProperty
1358 memset($$, 0, sizeof($$));
1363 statePointProperty: SIZE_TOK
1365 $$ = STATE_POINT_SIZE;
1369 $$ = STATE_POINT_ATTENUATION;
1373 stateMatrixRow: stateMatrixItem ROW '[' stateMatrixRowNum ']'
1383 stateMatrixRows: stateMatrixItem optMatrixRows
1398 | ROW '[' stateMatrixRowNum DOT_DOT stateMatrixRowNum ']'
1400 /* It seems logical that the matrix row range specifier would have
1401 * to specify a range or more than one row (i.e., $5 > $3).
1402 * However, the ARB_vertex_program spec says "a program will fail
1403 * to load if <a> is greater than <b>." This means that $3 == $5
1407 yyerror(& @3, state, "invalid matrix row range");
1416 stateMatrixItem: MATRIX stateMatrixName stateOptMatModifier
1424 stateOptMatModifier:
1434 stateMatModifier: INVERSE
1436 $$ = STATE_MATRIX_INVERSE;
1440 $$ = STATE_MATRIX_TRANSPOSE;
1444 $$ = STATE_MATRIX_INVTRANS;
1448 stateMatrixRowNum: INTEGER
1451 yyerror(& @1, state, "invalid matrix row reference");
1459 stateMatrixName: MODELVIEW stateOptModMatNum
1461 $$[0] = STATE_MODELVIEW_MATRIX;
1466 $$[0] = STATE_PROJECTION_MATRIX;
1471 $$[0] = STATE_MVP_MATRIX;
1474 | TEXTURE optTexCoordUnitNum
1476 $$[0] = STATE_TEXTURE_MATRIX;
1479 | PALETTE '[' statePaletteMatNum ']'
1481 yyerror(& @1, state, "GL_ARB_matrix_palette not supported");
1484 | MAT_PROGRAM '[' stateProgramMatNum ']'
1486 $$[0] = STATE_PROGRAM_MATRIX;
1495 | '[' stateModMatNum ']'
1500 stateModMatNum: INTEGER
1502 /* Since GL_ARB_vertex_blend isn't supported, only modelview matrix
1506 yyerror(& @1, state, "invalid modelview matrix index");
1513 statePaletteMatNum: INTEGER
1515 /* Since GL_ARB_matrix_palette isn't supported, just let any value
1516 * through here. The error will be generated later.
1521 stateProgramMatNum: INTEGER
1523 if ((unsigned) $1 >= state->MaxProgramMatrices) {
1524 yyerror(& @1, state, "invalid program matrix selector");
1532 stateDepthItem: DEPTH RANGE
1534 memset($$, 0, sizeof($$));
1535 $$[0] = STATE_DEPTH_RANGE;
1540 programSingleItem: progEnvParam | progLocalParam;
1542 programMultipleItem: progEnvParams | progLocalParams;
1544 progEnvParams: PROGRAM ENV '[' progEnvParamNums ']'
1546 memset($$, 0, sizeof($$));
1547 $$[0] = state->state_param_enum;
1554 progEnvParamNums: progEnvParamNum
1559 | progEnvParamNum DOT_DOT progEnvParamNum
1566 progEnvParam: PROGRAM ENV '[' progEnvParamNum ']'
1568 memset($$, 0, sizeof($$));
1569 $$[0] = state->state_param_enum;
1576 progLocalParams: PROGRAM LOCAL '[' progLocalParamNums ']'
1578 memset($$, 0, sizeof($$));
1579 $$[0] = state->state_param_enum;
1580 $$[1] = STATE_LOCAL;
1585 progLocalParamNums: progLocalParamNum
1590 | progLocalParamNum DOT_DOT progLocalParamNum
1597 progLocalParam: PROGRAM LOCAL '[' progLocalParamNum ']'
1599 memset($$, 0, sizeof($$));
1600 $$[0] = state->state_param_enum;
1601 $$[1] = STATE_LOCAL;
1607 progEnvParamNum: INTEGER
1609 if ((unsigned) $1 >= state->limits->MaxEnvParams) {
1610 yyerror(& @1, state, "invalid environment parameter reference");
1617 progLocalParamNum: INTEGER
1619 if ((unsigned) $1 >= state->limits->MaxLocalParams) {
1620 yyerror(& @1, state, "invalid local parameter reference");
1629 paramConstDecl: paramConstScalarDecl | paramConstVector;
1630 paramConstUse: paramConstScalarUse | paramConstVector;
1632 paramConstScalarDecl: signedFloatConstant
1642 paramConstScalarUse: REAL
1653 $$.data[0] = (float) $1;
1654 $$.data[1] = (float) $1;
1655 $$.data[2] = (float) $1;
1656 $$.data[3] = (float) $1;
1660 paramConstVector: '{' signedFloatConstant '}'
1668 | '{' signedFloatConstant ',' signedFloatConstant '}'
1676 | '{' signedFloatConstant ',' signedFloatConstant ','
1677 signedFloatConstant '}'
1685 | '{' signedFloatConstant ',' signedFloatConstant ','
1686 signedFloatConstant ',' signedFloatConstant '}'
1696 signedFloatConstant: optionalSign REAL
1698 $$ = ($1) ? -$2 : $2;
1700 | optionalSign INTEGER
1702 $$ = (float)(($1) ? -$2 : $2);
1706 optionalSign: '+' { $$ = FALSE; }
1707 | '-' { $$ = TRUE; }
1711 TEMP_statement: TEMP { $<integer>$ = $1; } varNameList
1714 ADDRESS_statement: ADDRESS { $<integer>$ = $1; } varNameList
1717 varNameList: varNameList ',' IDENTIFIER
1719 if (!declare_variable(state, $3, $<integer>0, & @3)) {
1725 if (!declare_variable(state, $1, $<integer>0, & @1)) {
1731 OUTPUT_statement: OUTPUT IDENTIFIER '=' resultBinding
1733 struct asm_symbol *const s =
1734 declare_variable(state, $2, at_output, & @2);
1739 s->output_binding = $4;
1744 resultBinding: RESULT POSITION
1746 if (state->mode == ARB_vertex) {
1747 $$ = VERT_RESULT_HPOS;
1749 yyerror(& @2, state, "invalid program result name");
1755 if (state->mode == ARB_vertex) {
1756 $$ = VERT_RESULT_FOGC;
1758 yyerror(& @2, state, "invalid program result name");
1762 | RESULT resultColBinding
1768 if (state->mode == ARB_vertex) {
1769 $$ = VERT_RESULT_PSIZ;
1771 yyerror(& @2, state, "invalid program result name");
1775 | RESULT TEXCOORD optTexCoordUnitNum
1777 if (state->mode == ARB_vertex) {
1778 $$ = VERT_RESULT_TEX0 + $3;
1780 yyerror(& @2, state, "invalid program result name");
1786 if (state->mode == ARB_fragment) {
1787 $$ = FRAG_RESULT_DEPTH;
1789 yyerror(& @2, state, "invalid program result name");
1795 resultColBinding: COLOR optResultFaceType optResultColorType
1803 $$ = (state->mode == ARB_vertex)
1805 : FRAG_RESULT_COLOR;
1809 if (state->mode == ARB_vertex) {
1810 $$ = VERT_RESULT_COL0;
1812 yyerror(& @1, state, "invalid program result name");
1818 if (state->mode == ARB_vertex) {
1819 $$ = VERT_RESULT_BFC0;
1821 yyerror(& @1, state, "invalid program result name");
1833 if (state->mode == ARB_vertex) {
1836 yyerror(& @1, state, "invalid program result name");
1842 if (state->mode == ARB_vertex) {
1845 yyerror(& @1, state, "invalid program result name");
1851 optFaceType: { $$ = 0; }
1856 optColorType: { $$ = 0; }
1857 | PRIMARY { $$ = 0; }
1858 | SECONDARY { $$ = 1; }
1861 optTexCoordUnitNum: { $$ = 0; }
1862 | '[' texCoordUnitNum ']' { $$ = $2; }
1865 optTexImageUnitNum: { $$ = 0; }
1866 | '[' texImageUnitNum ']' { $$ = $2; }
1869 optLegacyTexUnitNum: { $$ = 0; }
1870 | '[' legacyTexUnitNum ']' { $$ = $2; }
1873 texCoordUnitNum: INTEGER
1875 if ((unsigned) $1 >= state->MaxTextureCoordUnits) {
1876 yyerror(& @1, state, "invalid texture coordinate unit selector");
1884 texImageUnitNum: INTEGER
1886 if ((unsigned) $1 >= state->MaxTextureImageUnits) {
1887 yyerror(& @1, state, "invalid texture image unit selector");
1895 legacyTexUnitNum: INTEGER
1897 if ((unsigned) $1 >= state->MaxTextureUnits) {
1898 yyerror(& @1, state, "invalid texture unit selector");
1906 ALIAS_statement: ALIAS IDENTIFIER '=' IDENTIFIER
1908 struct asm_symbol *exist = (struct asm_symbol *)
1909 _mesa_symbol_table_find_symbol(state->st, 0, $2);
1910 struct asm_symbol *target = (struct asm_symbol *)
1911 _mesa_symbol_table_find_symbol(state->st, 0, $4);
1914 if (exist != NULL) {
1915 yyerror(& @2, state, "redeclared identifier");
1917 } else if (target == NULL) {
1918 yyerror(& @4, state,
1919 "undefined variable binding in ALIAS statement");
1922 _mesa_symbol_table_add_symbol(state->st, 0, $2, target);
1929 struct asm_instruction *
1930 asm_instruction_ctor(gl_inst_opcode op,
1931 const struct prog_dst_register *dst,
1932 const struct asm_src_register *src0,
1933 const struct asm_src_register *src1,
1934 const struct asm_src_register *src2)
1936 struct asm_instruction *inst = calloc(1, sizeof(struct asm_instruction));
1939 _mesa_init_instructions(& inst->Base, 1);
1940 inst->Base.Opcode = op;
1942 /* In the core ARB extensions only the KIL instruction doesn't have a
1943 * destination register.
1946 init_dst_reg(& inst->Base.DstReg);
1948 inst->Base.DstReg = *dst;
1951 inst->Base.SrcReg[0] = src0->Base;
1952 inst->SrcReg[0] = *src0;
1955 inst->Base.SrcReg[1] = src1->Base;
1956 inst->SrcReg[1] = *src1;
1958 init_src_reg(& inst->SrcReg[1]);
1962 inst->Base.SrcReg[2] = src2->Base;
1963 inst->SrcReg[2] = *src2;
1965 init_src_reg(& inst->SrcReg[2]);
1974 init_dst_reg(struct prog_dst_register *r)
1976 memset(r, 0, sizeof(*r));
1977 r->File = PROGRAM_UNDEFINED;
1978 r->WriteMask = WRITEMASK_XYZW;
1979 r->CondMask = COND_TR;
1980 r->CondSwizzle = SWIZZLE_NOOP;
1985 init_src_reg(struct asm_src_register *r)
1987 memset(r, 0, sizeof(*r));
1988 r->Base.File = PROGRAM_UNDEFINED;
1989 r->Base.Swizzle = SWIZZLE_NOOP;
1995 * Validate the set of inputs used by a program
1997 * Validates that legal sets of inputs are used by the program. In this case
1998 * "used" included both reading the input or binding the input to a name using
1999 * the \c ATTRIB command.
2002 * \c TRUE if the combination of inputs used is valid, \c FALSE otherwise.
2005 validate_inputs(struct YYLTYPE *locp, struct asm_parser_state *state)
2007 const int inputs = state->prog->InputsRead | state->InputsBound;
2009 if (((inputs & 0x0ffff) & (inputs >> 16)) != 0) {
2010 yyerror(locp, state, "illegal use of generic attribute and name attribute");
2019 declare_variable(struct asm_parser_state *state, char *name, enum asm_type t,
2020 struct YYLTYPE *locp)
2022 struct asm_symbol *s = NULL;
2023 struct asm_symbol *exist = (struct asm_symbol *)
2024 _mesa_symbol_table_find_symbol(state->st, 0, name);
2027 if (exist != NULL) {
2028 yyerror(locp, state, "redeclared identifier");
2030 s = calloc(1, sizeof(struct asm_symbol));
2036 if (state->prog->NumTemporaries >= state->limits->MaxTemps) {
2037 yyerror(locp, state, "too many temporaries declared");
2042 s->temp_binding = state->prog->NumTemporaries;
2043 state->prog->NumTemporaries++;
2047 if (state->prog->NumAddressRegs >= state->limits->MaxAddressRegs) {
2048 yyerror(locp, state, "too many address registers declared");
2053 /* FINISHME: Add support for multiple address registers.
2055 state->prog->NumAddressRegs++;
2062 _mesa_symbol_table_add_symbol(state->st, 0, s->name, s);
2063 s->next = state->sym;
2071 int add_state_reference(struct gl_program_parameter_list *param_list,
2072 const gl_state_index tokens[STATE_LENGTH])
2074 const GLuint size = 4; /* XXX fix */
2078 name = _mesa_program_state_string(tokens);
2079 index = _mesa_add_parameter(param_list, PROGRAM_STATE_VAR, name,
2080 size, GL_NONE, NULL, tokens, 0x0);
2081 param_list->StateFlags |= _mesa_program_state_flags(tokens);
2083 /* free name string here since we duplicated it in add_parameter() */
2091 initialize_symbol_from_state(struct gl_program *prog,
2092 struct asm_symbol *param_var,
2093 const gl_state_index tokens[STATE_LENGTH])
2096 gl_state_index state_tokens[STATE_LENGTH];
2099 memcpy(state_tokens, tokens, sizeof(state_tokens));
2101 param_var->type = at_param;
2102 param_var->param_binding_type = PROGRAM_STATE_VAR;
2104 /* If we are adding a STATE_MATRIX that has multiple rows, we need to
2105 * unroll it and call add_state_reference() for each row
2107 if ((state_tokens[0] == STATE_MODELVIEW_MATRIX ||
2108 state_tokens[0] == STATE_PROJECTION_MATRIX ||
2109 state_tokens[0] == STATE_MVP_MATRIX ||
2110 state_tokens[0] == STATE_TEXTURE_MATRIX ||
2111 state_tokens[0] == STATE_PROGRAM_MATRIX)
2112 && (state_tokens[2] != state_tokens[3])) {
2114 const int first_row = state_tokens[2];
2115 const int last_row = state_tokens[3];
2117 for (row = first_row; row <= last_row; row++) {
2118 state_tokens[2] = state_tokens[3] = row;
2120 idx = add_state_reference(prog->Parameters, state_tokens);
2121 if (param_var->param_binding_begin == ~0U)
2122 param_var->param_binding_begin = idx;
2123 param_var->param_binding_length++;
2127 idx = add_state_reference(prog->Parameters, state_tokens);
2128 if (param_var->param_binding_begin == ~0U)
2129 param_var->param_binding_begin = idx;
2130 param_var->param_binding_length++;
2138 initialize_symbol_from_param(struct gl_program *prog,
2139 struct asm_symbol *param_var,
2140 const gl_state_index tokens[STATE_LENGTH])
2143 gl_state_index state_tokens[STATE_LENGTH];
2146 memcpy(state_tokens, tokens, sizeof(state_tokens));
2148 assert((state_tokens[0] == STATE_VERTEX_PROGRAM)
2149 || (state_tokens[0] == STATE_FRAGMENT_PROGRAM));
2150 assert((state_tokens[1] == STATE_ENV)
2151 || (state_tokens[1] == STATE_LOCAL));
2153 param_var->type = at_param;
2154 param_var->param_binding_type = (state_tokens[1] == STATE_ENV)
2155 ? PROGRAM_ENV_PARAM : PROGRAM_LOCAL_PARAM;
2157 /* If we are adding a STATE_ENV or STATE_LOCAL that has multiple elements,
2158 * we need to unroll it and call add_state_reference() for each row
2160 if (state_tokens[2] != state_tokens[3]) {
2162 const int first_row = state_tokens[2];
2163 const int last_row = state_tokens[3];
2165 for (row = first_row; row <= last_row; row++) {
2166 state_tokens[2] = state_tokens[3] = row;
2168 idx = add_state_reference(prog->Parameters, state_tokens);
2169 if (param_var->param_binding_begin == ~0U)
2170 param_var->param_binding_begin = idx;
2171 param_var->param_binding_length++;
2175 idx = add_state_reference(prog->Parameters, state_tokens);
2176 if (param_var->param_binding_begin == ~0U)
2177 param_var->param_binding_begin = idx;
2178 param_var->param_binding_length++;
2186 initialize_symbol_from_const(struct gl_program *prog,
2187 struct asm_symbol *param_var,
2188 const struct asm_vector *vec)
2190 const int idx = _mesa_add_parameter(prog->Parameters, PROGRAM_CONSTANT,
2191 NULL, vec->count, GL_NONE, vec->data,
2194 param_var->type = at_param;
2195 param_var->param_binding_type = PROGRAM_CONSTANT;
2197 if (param_var->param_binding_begin == ~0U)
2198 param_var->param_binding_begin = idx;
2199 param_var->param_binding_length++;
2206 make_error_string(const char *fmt, ...)
2212 va_start(args, fmt);
2214 /* Call vsnprintf once to determine how large the final string is. Call it
2215 * again to do the actual formatting. from the vsnprintf manual page:
2217 * Upon successful return, these functions return the number of
2218 * characters printed (not including the trailing '\0' used to end
2219 * output to strings).
2221 length = 1 + vsnprintf(NULL, 0, fmt, args);
2223 str = _mesa_malloc(length);
2225 vsnprintf(str, length, fmt, args);
2235 yyerror(YYLTYPE *locp, struct asm_parser_state *state, const char *s)
2240 err_str = make_error_string("glProgramStringARB(%s)\n", s);
2242 _mesa_error(state->ctx, GL_INVALID_OPERATION, err_str);
2243 _mesa_free(err_str);
2246 err_str = make_error_string("line %u, char %u: error: %s\n",
2247 locp->first_line, locp->first_column, s);
2248 _mesa_set_program_error(state->ctx, locp->position, err_str);
2251 _mesa_free(err_str);
2257 _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
2258 GLsizei len, struct asm_parser_state *state)
2260 struct asm_instruction *inst;
2263 GLboolean result = GL_FALSE;
2265 struct asm_symbol *sym;
2268 state->prog->Target = target;
2269 state->prog->Parameters = _mesa_new_parameter_list();
2271 /* Make a copy of the program string and force it to be NUL-terminated.
2273 strz = (GLubyte *) _mesa_malloc(len + 1);
2275 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramStringARB");
2278 _mesa_memcpy (strz, str, len);
2281 state->prog->String = strz;
2283 state->st = _mesa_symbol_table_ctor();
2285 state->limits = (target == GL_VERTEX_PROGRAM_ARB)
2286 ? & ctx->Const.VertexProgram
2287 : & ctx->Const.FragmentProgram;
2289 state->MaxTextureImageUnits = ctx->Const.MaxTextureImageUnits;
2290 state->MaxTextureCoordUnits = ctx->Const.MaxTextureCoordUnits;
2291 state->MaxTextureUnits = ctx->Const.MaxTextureUnits;
2292 state->MaxClipPlanes = ctx->Const.MaxClipPlanes;
2293 state->MaxLights = ctx->Const.MaxLights;
2294 state->MaxProgramMatrices = ctx->Const.MaxProgramMatrices;
2296 state->state_param_enum = (target == GL_VERTEX_PROGRAM_ARB)
2297 ? STATE_VERTEX_PROGRAM : STATE_FRAGMENT_PROGRAM;
2299 _mesa_set_program_error(ctx, -1, NULL);
2301 _mesa_program_lexer_ctor(& state->scanner, state, (const char *) str, len);
2303 _mesa_program_lexer_dtor(state->scanner);
2306 if (ctx->Program.ErrorPos != -1) {
2310 if (! _mesa_layout_parameters(state)) {
2314 loc.first_column = 0;
2317 yyerror(& loc, state, "invalid PARAM usage");
2323 /* Add one instruction to store the "END" instruction.
2325 state->prog->Instructions =
2326 _mesa_alloc_instructions(state->prog->NumInstructions + 1);
2327 inst = state->inst_head;
2328 for (i = 0; i < state->prog->NumInstructions; i++) {
2329 struct asm_instruction *const temp = inst->next;
2331 state->prog->Instructions[i] = inst->Base;
2335 /* Finally, tag on an OPCODE_END instruction */
2337 const GLuint numInst = state->prog->NumInstructions;
2338 _mesa_init_instructions(state->prog->Instructions + numInst, 1);
2339 state->prog->Instructions[numInst].Opcode = OPCODE_END;
2341 state->prog->NumInstructions++;
2343 state->prog->NumParameters = state->prog->Parameters->NumParameters;
2344 state->prog->NumAttributes = _mesa_bitcount(state->prog->InputsRead);
2347 * Initialize native counts to logical counts. The device driver may
2348 * change them if program is translated into a hardware program.
2350 state->prog->NumNativeInstructions = state->prog->NumInstructions;
2351 state->prog->NumNativeTemporaries = state->prog->NumTemporaries;
2352 state->prog->NumNativeParameters = state->prog->NumParameters;
2353 state->prog->NumNativeAttributes = state->prog->NumAttributes;
2354 state->prog->NumNativeAddressRegs = state->prog->NumAddressRegs;
2359 for (inst = state->inst_head; inst != NULL; inst = temp) {
2364 state->inst_head = NULL;
2365 state->inst_tail = NULL;
2367 for (sym = state->sym; sym != NULL; sym = temp) {
2370 _mesa_free((void *) sym->name);
2375 _mesa_symbol_table_dtor(state->st);