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;
122 struct asm_vector vector;
123 gl_inst_opcode opcode;
126 %token ARBvp_10 ARBfp_10
128 /* Tokens for assembler pseudo-ops */
129 %token <integer> ADDRESS
133 %token <integer> TEMP
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
140 %token <integer> INTEGER
143 %token AMBIENT ATTENUATION
146 %token DEPTH DIFFUSE DIRECTION
147 %token EMISSION ENV EYE
148 %token FOG FOGCOORD FRAGMENT FRONT
150 %token INVERSE INVTRANS
151 %token LIGHT LIGHTMODEL LIGHTPROD LOCAL
152 %token MATERIAL MAT_PROGRAM MATRIX MATRIXINDEX MODELVIEW MVP
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 VERTEX VTXATTRIB
164 %token <string> IDENTIFIER
165 %token <swiz_mask> MASK4 MASK3 MASK2 MASK1 SWIZZLE
169 %type <inst> instruction ALU_instruction TexInstruction
170 %type <inst> ARL_instruction VECTORop_instruction
171 %type <inst> SCALARop_instruction BINSCop_instruction BINop_instruction
172 %type <inst> TRIop_instruction SWZ_instruction SAMPLE_instruction
173 %type <inst> KIL_instruction
175 %type <dst_reg> dstReg maskedDstReg maskedAddrReg
176 %type <src_reg> srcReg scalarSrcReg swizzleSrcReg
177 %type <swiz_mask> scalarSuffix swizzleSuffix extendedSwizzle extSwizComp
178 %type <swiz_mask> optionalMask
179 %type <integer> extSwizSel
181 %type <sym> progParamArray
182 %type <integer> addrRegRelOffset addrRegPosOffset addrRegNegOffset
183 %type <src_reg> progParamArrayMem progParamArrayAbs progParamArrayRel
185 %type <swiz_mask> addrComponent addrWriteMask
187 %type <result> resultBinding resultColBinding
188 %type <integer> optFaceType optColorType
189 %type <integer> optResultFaceType optResultColorType
191 %type <integer> optTexImageUnitNum texImageUnitNum
192 %type <integer> optTexCoordUnitNum texCoordUnitNum
193 %type <integer> optLegacyTexUnitNum legacyTexUnitNum
194 %type <integer> texImageUnit texTarget
195 %type <integer> vtxAttribNum
197 %type <attrib> attribBinding vtxAttribItem fragAttribItem
199 %type <temp_sym> paramSingleInit paramSingleItemDecl
200 %type <integer> optArraySize
202 %type <state> stateSingleItem stateMultipleItem
203 %type <state> stateMaterialItem
204 %type <state> stateLightItem stateLightModelItem stateLightProdItem
205 %type <state> stateTexGenItem stateFogItem stateClipPlaneItem statePointItem
206 %type <state> stateMatrixItem stateMatrixRow stateMatrixRows
207 %type <state> stateTexEnvItem
209 %type <state> stateLModProperty
210 %type <state> stateMatrixName optMatrixRows
212 %type <integer> stateMatProperty
213 %type <integer> stateLightProperty stateSpotProperty
214 %type <integer> stateLightNumber stateLProdProperty
215 %type <integer> stateTexGenType stateTexGenCoord
216 %type <integer> stateTexEnvProperty
217 %type <integer> stateFogProperty
218 %type <integer> stateClipPlaneNum
219 %type <integer> statePointProperty
221 %type <integer> stateOptMatModifier stateMatModifier stateMatrixRowNum
222 %type <integer> stateOptModMatNum stateModMatNum statePaletteMatNum
223 %type <integer> stateProgramMatNum
225 %type <integer> ambDiffSpecProperty
227 %type <state> programSingleItem progEnvParam progLocalParam
228 %type <state> programMultipleItem progEnvParams progLocalParams
230 %type <temp_sym> paramMultipleInit paramMultInitList paramMultipleItem
231 %type <temp_sym> paramSingleItemUse
233 %type <integer> progEnvParamNum progLocalParamNum
234 %type <state> progEnvParamNums progLocalParamNums
236 %type <vector> paramConstDecl paramConstUse
237 %type <vector> paramConstScalarDecl paramConstScalarUse paramConstVector
238 %type <real> signedFloatConstant
239 %type <negate> optionalSign
242 extern int yylex(YYSTYPE *yylval_param, YYLTYPE *yylloc_param,
248 program: language optionSequence statementSequence END
253 if (state->prog->Target != GL_VERTEX_PROGRAM_ARB) {
254 yyerror(& @1, state, "invalid fragment program header");
257 state->mode = ARB_vertex;
261 if (state->prog->Target != GL_FRAGMENT_PROGRAM_ARB) {
262 yyerror(& @1, state, "invalid vertex program header");
264 state->mode = ARB_fragment;
266 state->option.TexRect =
267 (state->ctx->Extensions.NV_texture_rectangle != GL_FALSE);
271 optionSequence: optionSequence option
275 option: OPTION IDENTIFIER ';'
279 if (state->mode == ARB_vertex) {
280 valid = _mesa_ARBvp_parse_option(state, $2);
281 } else if (state->mode == ARB_fragment) {
282 valid = _mesa_ARBfp_parse_option(state, $2);
287 yyerror(& @2, state, "invalid option string");
293 statementSequence: statementSequence statement
297 statement: instruction ';'
300 if (state->inst_tail == NULL) {
301 state->inst_head = $1;
303 state->inst_tail->next = $1;
306 state->inst_tail = $1;
309 state->prog->NumInstructions++;
312 | namingStatement ';'
315 instruction: ALU_instruction
318 state->prog->NumAluInstructions++;
323 state->prog->NumTexInstructions++;
327 ALU_instruction: ARL_instruction
328 | VECTORop_instruction
329 | SCALARop_instruction
330 | BINSCop_instruction
336 TexInstruction: SAMPLE_instruction
340 ARL_instruction: ARL maskedAddrReg ',' scalarSrcReg
342 $$ = asm_instruction_ctor(OPCODE_ARL, & $2, & $4, NULL, NULL);
346 VECTORop_instruction: VECTOR_OP maskedDstReg ',' swizzleSrcReg
348 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL);
349 $$->Base.SaturateMode = $1.SaturateMode;
353 SCALARop_instruction: SCALAR_OP maskedDstReg ',' scalarSrcReg
355 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL);
356 $$->Base.SaturateMode = $1.SaturateMode;
360 BINSCop_instruction: BINSC_OP maskedDstReg ',' scalarSrcReg ',' scalarSrcReg
362 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, NULL);
363 $$->Base.SaturateMode = $1.SaturateMode;
368 BINop_instruction: BIN_OP maskedDstReg ',' swizzleSrcReg ',' swizzleSrcReg
370 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, NULL);
371 $$->Base.SaturateMode = $1.SaturateMode;
375 TRIop_instruction: TRI_OP maskedDstReg ','
376 swizzleSrcReg ',' swizzleSrcReg ',' swizzleSrcReg
378 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, & $8);
379 $$->Base.SaturateMode = $1.SaturateMode;
383 SAMPLE_instruction: SAMPLE_OP maskedDstReg ',' swizzleSrcReg ',' texImageUnit ',' texTarget
385 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL);
387 const GLbitfield tex_mask = (1U << $6);
388 GLbitfield shadow_tex = 0;
389 GLbitfield target_mask = 0;
392 $$->Base.SaturateMode = $1.SaturateMode;
393 $$->Base.TexSrcUnit = $6;
396 shadow_tex = tex_mask;
398 $$->Base.TexSrcTarget = -$8;
399 $$->Base.TexShadow = 1;
401 $$->Base.TexSrcTarget = $8;
404 target_mask = (1U << $$->Base.TexSrcTarget);
406 /* If this texture unit was previously accessed and that access
407 * had a different texture target, generate an error.
409 * If this texture unit was previously accessed and that access
410 * had a different shadow mode, generate an error.
412 if ((state->prog->TexturesUsed[$6] != 0)
413 && ((state->prog->TexturesUsed[$6] != target_mask)
414 || ((state->prog->ShadowSamplers & tex_mask)
417 "multiple targets used on one texture image unit");
422 state->prog->TexturesUsed[$6] |= target_mask;
423 state->prog->ShadowSamplers |= shadow_tex;
428 KIL_instruction: KIL swizzleSrcReg
430 $$ = asm_instruction_ctor(OPCODE_KIL, NULL, & $2, NULL, NULL);
431 state->fragment.UsesKill = 1;
435 texImageUnit: TEXTURE_UNIT optTexImageUnitNum
441 texTarget: TEX_1D { $$ = TEXTURE_1D_INDEX; }
442 | TEX_2D { $$ = TEXTURE_2D_INDEX; }
443 | TEX_3D { $$ = TEXTURE_3D_INDEX; }
444 | TEX_CUBE { $$ = TEXTURE_CUBE_INDEX; }
445 | TEX_RECT { $$ = TEXTURE_RECT_INDEX; }
446 | TEX_SHADOW1D { $$ = -TEXTURE_1D_INDEX; }
447 | TEX_SHADOW2D { $$ = -TEXTURE_2D_INDEX; }
448 | TEX_SHADOWRECT { $$ = -TEXTURE_RECT_INDEX; }
451 SWZ_instruction: SWZ maskedDstReg ',' srcReg ',' extendedSwizzle
453 /* FIXME: Is this correct? Should the extenedSwizzle be applied
454 * FIXME: to the existing swizzle?
456 $4.Base.Swizzle = $6.swizzle;
458 $$ = asm_instruction_ctor(OPCODE_SWZ, & $2, & $4, NULL, NULL);
459 $$->Base.SaturateMode = $1.SaturateMode;
463 scalarSrcReg: optionalSign srcReg scalarSuffix
468 $$.Base.Negate = ~$$.Base.Negate;
471 $$.Base.Swizzle = _mesa_combine_swizzles($$.Base.Swizzle,
476 swizzleSrcReg: optionalSign srcReg swizzleSuffix
481 $$.Base.Negate = ~$$.Base.Negate;
484 $$.Base.Swizzle = _mesa_combine_swizzles($$.Base.Swizzle,
489 maskedDstReg: dstReg optionalMask
492 $$.WriteMask = $2.mask;
494 if ($$.File == PROGRAM_OUTPUT) {
495 /* Technically speaking, this should check that it is in
496 * vertex program mode. However, PositionInvariant can never be
497 * set in fragment program mode, so it is somewhat irrelevant.
499 if (state->option.PositionInvariant
500 && ($$.Index == VERT_RESULT_HPOS)) {
501 yyerror(& @1, state, "position-invariant programs cannot "
506 state->prog->OutputsWritten |= (1U << $$.Index);
511 maskedAddrReg: addrReg addrWriteMask
514 $$.File = PROGRAM_ADDRESS;
516 $$.WriteMask = $2.mask;
520 extendedSwizzle: extSwizComp ',' extSwizComp ',' extSwizComp ',' extSwizComp
522 $$.swizzle = MAKE_SWIZZLE4($1.swizzle, $3.swizzle,
523 $5.swizzle, $7.swizzle);
524 $$.mask = ($1.mask) | ($3.mask << 1) | ($5.mask << 2)
529 extSwizComp: optionalSign extSwizSel
532 $$.mask = ($1) ? 1 : 0;
538 if (($1 != 0) && ($1 != 1)) {
539 yyerror(& @1, state, "invalid extended swizzle selector");
543 $$ = ($1 == 0) ? SWIZZLE_ZERO : SWIZZLE_ONE;
547 if (strlen($1) > 1) {
548 yyerror(& @1, state, "invalid extended swizzle selector");
566 yyerror(& @1, state, "invalid extended swizzle selector");
573 srcReg: IDENTIFIER /* temporaryReg | progParamSingle */
575 struct asm_symbol *const s = (struct asm_symbol *)
576 _mesa_symbol_table_find_symbol(state->st, 0, $1);
579 yyerror(& @1, state, "invalid operand variable");
581 } else if ((s->type != at_param) && (s->type != at_temp)
582 && (s->type != at_attrib)) {
583 yyerror(& @1, state, "invalid operand variable");
585 } else if ((s->type == at_param) && s->param_is_array) {
586 yyerror(& @1, state, "non-array access to array PARAM");
593 $$.Base.File = PROGRAM_TEMPORARY;
594 $$.Base.Index = s->temp_binding;
597 $$.Base.File = s->param_binding_type;
598 $$.Base.Index = s->param_binding_begin;
601 $$.Base.File = PROGRAM_INPUT;
602 $$.Base.Index = s->attrib_binding;
603 state->prog->InputsRead |= (1U << $$.Base.Index);
605 if (!validate_inputs(& @1, state)) {
618 $$.Base.File = PROGRAM_INPUT;
620 state->prog->InputsRead |= (1U << $$.Base.Index);
622 if (!validate_inputs(& @1, state)) {
626 | progParamArray '[' progParamArrayMem ']'
628 if (! $3.Base.RelAddr
629 && ((unsigned) $3.Base.Index >= $1->param_binding_length)) {
630 yyerror(& @3, state, "out of bounds array access");
635 $$.Base.File = $1->param_binding_type;
637 if ($3.Base.RelAddr) {
638 $1->param_accessed_indirectly = 1;
641 $$.Base.Index = $3.Base.Index;
644 $$.Base.Index = $1->param_binding_begin + $3.Base.Index;
650 $$.Base.File = ($1.name != NULL)
651 ? $1.param_binding_type
653 $$.Base.Index = $1.param_binding_begin;
657 dstReg: resultBinding
660 $$.File = PROGRAM_OUTPUT;
663 | IDENTIFIER /* temporaryReg | vertexResultReg */
665 struct asm_symbol *const s = (struct asm_symbol *)
666 _mesa_symbol_table_find_symbol(state->st, 0, $1);
669 yyerror(& @1, state, "invalid operand variable");
671 } else if ((s->type != at_output) && (s->type != at_temp)) {
672 yyerror(& @1, state, "invalid operand variable");
677 if (s->type == at_temp) {
678 $$.File = PROGRAM_TEMPORARY;
679 $$.Index = s->temp_binding;
681 $$.File = s->param_binding_type;
682 $$.Index = s->param_binding_begin;
687 progParamArray: IDENTIFIER
689 struct asm_symbol *const s = (struct asm_symbol *)
690 _mesa_symbol_table_find_symbol(state->st, 0, $1);
693 yyerror(& @1, state, "invalid operand variable");
695 } else if ((s->type != at_param) || !s->param_is_array) {
696 yyerror(& @1, state, "array access to non-PARAM variable");
704 progParamArrayMem: progParamArrayAbs | progParamArrayRel;
706 progParamArrayAbs: INTEGER
713 progParamArrayRel: addrReg addrComponent addrRegRelOffset
715 /* FINISHME: Add support for multiple address registers.
717 /* FINISHME: Add support for 4-component address registers.
725 addrRegRelOffset: { $$ = 0; }
726 | '+' addrRegPosOffset { $$ = $2; }
727 | '-' addrRegNegOffset { $$ = -$2; }
730 addrRegPosOffset: INTEGER
732 if (($1 < 0) || ($1 > 63)) {
734 "relative address offset too large (positive)");
742 addrRegNegOffset: INTEGER
744 if (($1 < 0) || ($1 > 64)) {
746 "relative address offset too large (negative)");
756 struct asm_symbol *const s = (struct asm_symbol *)
757 _mesa_symbol_table_find_symbol(state->st, 0, $1);
760 yyerror(& @1, state, "invalid array member");
762 } else if (s->type != at_address) {
764 "invalid variable for indexed array access");
774 if ($1.mask != WRITEMASK_X) {
775 yyerror(& @1, state, "invalid address component selector");
785 if ($1.mask != WRITEMASK_X) {
787 "address register write mask must be \".x\"");
800 | { $$.swizzle = SWIZZLE_NOOP; $$.mask = WRITEMASK_XYZW; }
803 optionalMask: MASK4 | MASK3 | MASK2 | MASK1
804 | { $$.swizzle = SWIZZLE_NOOP; $$.mask = WRITEMASK_XYZW; }
807 namingStatement: ATTRIB_statement
815 ATTRIB_statement: ATTRIB IDENTIFIER '=' attribBinding
817 struct asm_symbol *const s =
818 declare_variable(state, $2, at_attrib, & @2);
823 s->attrib_binding = $4;
824 state->InputsBound |= (1U << s->attrib_binding);
826 if (!validate_inputs(& @4, state)) {
833 attribBinding: VERTEX vtxAttribItem
837 | FRAGMENT fragAttribItem
843 vtxAttribItem: POSITION
845 $$ = VERT_ATTRIB_POS;
847 | WEIGHT vtxOptWeightNum
849 $$ = VERT_ATTRIB_WEIGHT;
853 $$ = VERT_ATTRIB_NORMAL;
857 if (!state->ctx->Extensions.EXT_secondary_color) {
858 yyerror(& @2, state, "GL_EXT_secondary_color not supported");
862 $$ = VERT_ATTRIB_COLOR0 + $2;
866 if (!state->ctx->Extensions.EXT_fog_coord) {
867 yyerror(& @1, state, "GL_EXT_fog_coord not supported");
871 $$ = VERT_ATTRIB_FOG;
873 | TEXCOORD optTexCoordUnitNum
875 $$ = VERT_ATTRIB_TEX0 + $2;
877 | MATRIXINDEX '[' vtxWeightNum ']'
879 yyerror(& @1, state, "GL_ARB_matrix_palette not supported");
882 | VTXATTRIB '[' vtxAttribNum ']'
884 $$ = VERT_ATTRIB_GENERIC0 + $3;
888 vtxAttribNum: INTEGER
890 if ((unsigned) $1 >= state->limits->MaxAttribs) {
891 yyerror(& @1, state, "invalid vertex attribute reference");
899 vtxOptWeightNum: | '[' vtxWeightNum ']';
900 vtxWeightNum: INTEGER;
902 fragAttribItem: POSITION
904 $$ = FRAG_ATTRIB_WPOS;
908 $$ = FRAG_ATTRIB_COL0 + $2;
912 $$ = FRAG_ATTRIB_FOGC;
914 | TEXCOORD optTexCoordUnitNum
916 $$ = FRAG_ATTRIB_TEX0 + $2;
920 PARAM_statement: PARAM_singleStmt | PARAM_multipleStmt;
922 PARAM_singleStmt: PARAM IDENTIFIER paramSingleInit
924 struct asm_symbol *const s =
925 declare_variable(state, $2, at_param, & @2);
930 s->param_binding_type = $3.param_binding_type;
931 s->param_binding_begin = $3.param_binding_begin;
932 s->param_binding_length = $3.param_binding_length;
933 s->param_is_array = 0;
938 PARAM_multipleStmt: PARAM IDENTIFIER '[' optArraySize ']' paramMultipleInit
940 if (($4 != 0) && ((unsigned) $4 != $6.param_binding_length)) {
942 "parameter array size and number of bindings must match");
945 struct asm_symbol *const s =
946 declare_variable(state, $2, $6.type, & @2);
951 s->param_binding_type = $6.param_binding_type;
952 s->param_binding_begin = $6.param_binding_begin;
953 s->param_binding_length = $6.param_binding_length;
954 s->param_is_array = 1;
966 if (($1 < 1) || ((unsigned) $1 >= state->limits->MaxParameters)) {
967 yyerror(& @1, state, "invalid parameter array size");
975 paramSingleInit: '=' paramSingleItemDecl
981 paramMultipleInit: '=' '{' paramMultInitList '}'
987 paramMultInitList: paramMultipleItem
988 | paramMultInitList ',' paramMultipleItem
990 $1.param_binding_length += $3.param_binding_length;
995 paramSingleItemDecl: stateSingleItem
997 memset(& $$, 0, sizeof($$));
998 $$.param_binding_begin = ~0;
999 initialize_symbol_from_state(state->prog, & $$, $1);
1003 memset(& $$, 0, sizeof($$));
1004 $$.param_binding_begin = ~0;
1005 initialize_symbol_from_param(state->prog, & $$, $1);
1009 memset(& $$, 0, sizeof($$));
1010 $$.param_binding_begin = ~0;
1011 initialize_symbol_from_const(state->prog, & $$, & $1);
1015 paramSingleItemUse: stateSingleItem
1017 memset(& $$, 0, sizeof($$));
1018 $$.param_binding_begin = ~0;
1019 initialize_symbol_from_state(state->prog, & $$, $1);
1023 memset(& $$, 0, sizeof($$));
1024 $$.param_binding_begin = ~0;
1025 initialize_symbol_from_param(state->prog, & $$, $1);
1029 memset(& $$, 0, sizeof($$));
1030 $$.param_binding_begin = ~0;
1031 initialize_symbol_from_const(state->prog, & $$, & $1);
1035 paramMultipleItem: stateMultipleItem
1037 memset(& $$, 0, sizeof($$));
1038 $$.param_binding_begin = ~0;
1039 initialize_symbol_from_state(state->prog, & $$, $1);
1041 | programMultipleItem
1043 memset(& $$, 0, sizeof($$));
1044 $$.param_binding_begin = ~0;
1045 initialize_symbol_from_param(state->prog, & $$, $1);
1049 memset(& $$, 0, sizeof($$));
1050 $$.param_binding_begin = ~0;
1051 initialize_symbol_from_const(state->prog, & $$, & $1);
1055 stateMultipleItem: stateSingleItem { memcpy($$, $1, sizeof($$)); }
1056 | STATE stateMatrixRows { memcpy($$, $2, sizeof($$)); }
1059 stateSingleItem: STATE stateMaterialItem { memcpy($$, $2, sizeof($$)); }
1060 | STATE stateLightItem { memcpy($$, $2, sizeof($$)); }
1061 | STATE stateLightModelItem { memcpy($$, $2, sizeof($$)); }
1062 | STATE stateLightProdItem { memcpy($$, $2, sizeof($$)); }
1063 | STATE stateTexGenItem { memcpy($$, $2, sizeof($$)); }
1064 | STATE stateTexEnvItem { memcpy($$, $2, sizeof($$)); }
1065 | STATE stateFogItem { memcpy($$, $2, sizeof($$)); }
1066 | STATE stateClipPlaneItem { memcpy($$, $2, sizeof($$)); }
1067 | STATE statePointItem { memcpy($$, $2, sizeof($$)); }
1068 | STATE stateMatrixRow { memcpy($$, $2, sizeof($$)); }
1071 stateMaterialItem: MATERIAL optFaceType stateMatProperty
1073 memset($$, 0, sizeof($$));
1074 $$[0] = STATE_MATERIAL;
1080 stateMatProperty: ambDiffSpecProperty
1086 $$ = STATE_EMISSION;
1090 $$ = STATE_SHININESS;
1094 stateLightItem: LIGHT '[' stateLightNumber ']' stateLightProperty
1096 memset($$, 0, sizeof($$));
1097 $$[0] = STATE_LIGHT;
1103 stateLightProperty: ambDiffSpecProperty
1109 $$ = STATE_POSITION;
1113 if (!state->ctx->Extensions.EXT_point_parameters) {
1114 yyerror(& @1, state, "GL_ARB_point_parameters not supported");
1118 $$ = STATE_ATTENUATION;
1120 | SPOT stateSpotProperty
1126 $$ = STATE_HALF_VECTOR;
1130 stateSpotProperty: DIRECTION
1132 $$ = STATE_SPOT_DIRECTION;
1136 stateLightModelItem: LIGHTMODEL stateLModProperty
1143 stateLModProperty: AMBIENT
1145 memset($$, 0, sizeof($$));
1146 $$[0] = STATE_LIGHTMODEL_AMBIENT;
1148 | optFaceType SCENECOLOR
1150 memset($$, 0, sizeof($$));
1151 $$[0] = STATE_LIGHTMODEL_SCENECOLOR;
1156 stateLightProdItem: LIGHTPROD '[' stateLightNumber ']' optFaceType stateLProdProperty
1158 memset($$, 0, sizeof($$));
1159 $$[0] = STATE_LIGHTPROD;
1166 stateLProdProperty: ambDiffSpecProperty;
1168 stateTexEnvItem: TEXENV optLegacyTexUnitNum stateTexEnvProperty
1170 memset($$, 0, sizeof($$));
1176 stateTexEnvProperty: COLOR
1178 $$ = STATE_TEXENV_COLOR;
1182 ambDiffSpecProperty: AMBIENT
1192 $$ = STATE_SPECULAR;
1196 stateLightNumber: INTEGER
1198 if ((unsigned) $1 >= state->MaxLights) {
1199 yyerror(& @1, state, "invalid light selector");
1207 stateTexGenItem: TEXGEN optTexCoordUnitNum stateTexGenType stateTexGenCoord
1209 memset($$, 0, sizeof($$));
1210 $$[0] = STATE_TEXGEN;
1216 stateTexGenType: EYE
1218 $$ = STATE_TEXGEN_EYE_S;
1222 $$ = STATE_TEXGEN_OBJECT_S;
1225 stateTexGenCoord: TEXGEN_S
1227 $$ = STATE_TEXGEN_EYE_S - STATE_TEXGEN_EYE_S;
1231 $$ = STATE_TEXGEN_EYE_T - STATE_TEXGEN_EYE_S;
1235 $$ = STATE_TEXGEN_EYE_R - STATE_TEXGEN_EYE_S;
1239 $$ = STATE_TEXGEN_EYE_Q - STATE_TEXGEN_EYE_S;
1243 stateFogItem: FOG stateFogProperty
1245 memset($$, 0, sizeof($$));
1250 stateFogProperty: COLOR
1252 $$ = STATE_FOG_COLOR;
1256 $$ = STATE_FOG_PARAMS;
1260 stateClipPlaneItem: CLIP '[' stateClipPlaneNum ']' PLANE
1262 memset($$, 0, sizeof($$));
1263 $$[0] = STATE_CLIPPLANE;
1268 stateClipPlaneNum: INTEGER
1270 if ((unsigned) $1 >= state->MaxClipPlanes) {
1271 yyerror(& @1, state, "invalid clip plane selector");
1279 statePointItem: POINT statePointProperty
1281 memset($$, 0, sizeof($$));
1286 statePointProperty: SIZE
1288 $$ = STATE_POINT_SIZE;
1292 $$ = STATE_POINT_ATTENUATION;
1296 stateMatrixRow: stateMatrixItem ROW '[' stateMatrixRowNum ']'
1306 stateMatrixRows: stateMatrixItem optMatrixRows
1321 | ROW '[' stateMatrixRowNum DOT_DOT stateMatrixRowNum ']'
1323 /* It seems logical that the matrix row range specifier would have
1324 * to specify a range or more than one row (i.e., $5 > $3).
1325 * However, the ARB_vertex_program spec says "a program will fail
1326 * to load if <a> is greater than <b>." This means that $3 == $5
1330 yyerror(& @3, state, "invalid matrix row range");
1339 stateMatrixItem: MATRIX stateMatrixName stateOptMatModifier
1347 stateOptMatModifier:
1357 stateMatModifier: INVERSE
1359 $$ = STATE_MATRIX_INVERSE;
1363 $$ = STATE_MATRIX_TRANSPOSE;
1367 $$ = STATE_MATRIX_INVTRANS;
1371 stateMatrixRowNum: INTEGER
1374 yyerror(& @1, state, "invalid matrix row reference");
1382 stateMatrixName: MODELVIEW stateOptModMatNum
1384 $$[0] = STATE_MODELVIEW_MATRIX;
1389 $$[0] = STATE_PROJECTION_MATRIX;
1394 $$[0] = STATE_MVP_MATRIX;
1397 | TEXTURE optTexCoordUnitNum
1399 $$[0] = STATE_TEXTURE_MATRIX;
1402 | PALETTE '[' statePaletteMatNum ']'
1404 yyerror(& @1, state, "GL_ARB_matrix_palette not supported");
1407 | MAT_PROGRAM '[' stateProgramMatNum ']'
1409 $$[0] = STATE_PROGRAM_MATRIX;
1423 stateModMatNum: INTEGER
1425 /* Since GL_ARB_vertex_blend isn't supported, only modelview matrix
1429 yyerror(& @1, state, "invalid modelview matrix index");
1436 statePaletteMatNum: INTEGER
1438 /* Since GL_ARB_matrix_palette isn't supported, just let any value
1439 * through here. The error will be generated later.
1444 stateProgramMatNum: INTEGER
1446 if ((unsigned) $1 >= state->MaxProgramMatrices) {
1447 yyerror(& @1, state, "invalid program matrix selector");
1457 programSingleItem: progEnvParam | progLocalParam;
1459 programMultipleItem: progEnvParams | progLocalParams;
1461 progEnvParams: PROGRAM ENV '[' progEnvParamNums ']'
1463 memset($$, 0, sizeof($$));
1464 $$[0] = state->state_param_enum;
1471 progEnvParamNums: progEnvParamNum
1476 | progEnvParamNum DOT_DOT progEnvParamNum
1483 progEnvParam: PROGRAM ENV '[' progEnvParamNum ']'
1485 memset($$, 0, sizeof($$));
1486 $$[0] = state->state_param_enum;
1493 progLocalParams: PROGRAM LOCAL '[' progLocalParamNums ']'
1495 memset($$, 0, sizeof($$));
1496 $$[0] = state->state_param_enum;
1497 $$[1] = STATE_LOCAL;
1502 progLocalParamNums: progLocalParamNum
1507 | progLocalParamNum DOT_DOT progLocalParamNum
1514 progLocalParam: PROGRAM LOCAL '[' progLocalParamNum ']'
1516 memset($$, 0, sizeof($$));
1517 $$[0] = state->state_param_enum;
1518 $$[1] = STATE_LOCAL;
1524 progEnvParamNum: INTEGER
1526 if ((unsigned) $1 >= state->limits->MaxEnvParams) {
1527 yyerror(& @1, state, "invalid environment parameter reference");
1534 progLocalParamNum: INTEGER
1536 if ((unsigned) $1 >= state->limits->MaxLocalParams) {
1537 yyerror(& @1, state, "invalid local parameter reference");
1546 paramConstDecl: paramConstScalarDecl | paramConstVector;
1547 paramConstUse: paramConstScalarUse | paramConstVector;
1549 paramConstScalarDecl: signedFloatConstant
1556 paramConstScalarUse: REAL
1564 $$.data[0] = (float) $1;
1568 paramConstVector: '{' signedFloatConstant '}'
1576 | '{' signedFloatConstant ',' signedFloatConstant '}'
1584 | '{' signedFloatConstant ',' signedFloatConstant ','
1585 signedFloatConstant '}'
1593 | '{' signedFloatConstant ',' signedFloatConstant ','
1594 signedFloatConstant ',' signedFloatConstant '}'
1604 signedFloatConstant: optionalSign REAL
1606 $$ = ($1) ? -$2 : $2;
1608 | optionalSign INTEGER
1610 $$ = (float)(($1) ? -$2 : $2);
1614 optionalSign: '+' { $$ = FALSE; }
1615 | '-' { $$ = TRUE; }
1619 TEMP_statement: TEMP { $<integer>$ = $1; } varNameList
1622 ADDRESS_statement: ADDRESS { $<integer>$ = $1; } varNameList
1625 varNameList: varNameList ',' IDENTIFIER
1627 if (!declare_variable(state, $3, $<integer>0, & @3)) {
1633 if (!declare_variable(state, $1, $<integer>0, & @1)) {
1639 OUTPUT_statement: OUTPUT IDENTIFIER '=' resultBinding
1641 struct asm_symbol *const s =
1642 declare_variable(state, $2, at_output, & @2);
1647 s->output_binding = $4;
1652 resultBinding: RESULT POSITION
1654 if (state->mode == ARB_vertex) {
1655 $$ = VERT_RESULT_HPOS;
1657 yyerror(& @2, state, "invalid program result name");
1663 if (state->mode == ARB_vertex) {
1664 $$ = VERT_RESULT_FOGC;
1666 yyerror(& @2, state, "invalid program result name");
1670 | RESULT resultColBinding
1676 if (state->mode == ARB_vertex) {
1677 $$ = VERT_RESULT_PSIZ;
1679 yyerror(& @2, state, "invalid program result name");
1683 | RESULT TEXCOORD optTexCoordUnitNum
1685 if (state->mode == ARB_vertex) {
1686 $$ = VERT_RESULT_TEX0 + $3;
1688 yyerror(& @2, state, "invalid program result name");
1694 if (state->mode == ARB_fragment) {
1695 $$ = FRAG_RESULT_DEPTH;
1697 yyerror(& @2, state, "invalid program result name");
1703 resultColBinding: COLOR optResultFaceType optResultColorType
1711 $$ = (state->mode == ARB_vertex)
1713 : FRAG_RESULT_COLOR;
1717 if (state->mode == ARB_vertex) {
1718 $$ = VERT_RESULT_COL0;
1720 yyerror(& @1, state, "invalid program result name");
1726 if (state->mode == ARB_vertex) {
1727 $$ = VERT_RESULT_BFC0;
1729 yyerror(& @1, state, "invalid program result name");
1741 if (state->mode == ARB_vertex) {
1744 yyerror(& @1, state, "invalid program result name");
1750 if (state->mode == ARB_vertex) {
1753 yyerror(& @1, state, "invalid program result name");
1759 optFaceType: { $$ = 0; }
1764 optColorType: { $$ = 0; }
1765 | PRIMARY { $$ = 0; }
1766 | SECONDARY { $$ = 1; }
1769 optTexCoordUnitNum: { $$ = 0; }
1770 | '[' texCoordUnitNum ']' { $$ = $2; }
1773 optTexImageUnitNum: { $$ = 0; }
1774 | '[' texImageUnitNum ']' { $$ = $2; }
1777 optLegacyTexUnitNum: { $$ = 0; }
1778 | '[' legacyTexUnitNum ']' { $$ = $2; }
1781 texCoordUnitNum: INTEGER
1783 if ((unsigned) $1 >= state->MaxTextureCoordUnits) {
1784 yyerror(& @1, state, "invalid texture coordinate unit selector");
1792 texImageUnitNum: INTEGER
1794 if ((unsigned) $1 >= state->MaxTextureImageUnits) {
1795 yyerror(& @1, state, "invalid texture image unit selector");
1803 legacyTexUnitNum: INTEGER
1805 if ((unsigned) $1 >= state->MaxTextureUnits) {
1806 yyerror(& @1, state, "invalid texture unit selector");
1814 ALIAS_statement: ALIAS IDENTIFIER '=' IDENTIFIER
1816 struct asm_symbol *exist = (struct asm_symbol *)
1817 _mesa_symbol_table_find_symbol(state->st, 0, $2);
1818 struct asm_symbol *target = (struct asm_symbol *)
1819 _mesa_symbol_table_find_symbol(state->st, 0, $4);
1822 if (exist != NULL) {
1823 yyerror(& @2, state, "redeclared identifier");
1825 } else if (target == NULL) {
1826 yyerror(& @4, state,
1827 "undefined variable binding in ALIAS statement");
1830 _mesa_symbol_table_add_symbol(state->st, 0, $2, target);
1837 struct asm_instruction *
1838 asm_instruction_ctor(gl_inst_opcode op,
1839 const struct prog_dst_register *dst,
1840 const struct asm_src_register *src0,
1841 const struct asm_src_register *src1,
1842 const struct asm_src_register *src2)
1844 struct asm_instruction *inst = calloc(1, sizeof(struct asm_instruction));
1847 _mesa_init_instructions(& inst->Base, 1);
1848 inst->Base.Opcode = op;
1849 inst->Base.DstReg = *dst;
1851 inst->Base.SrcReg[0] = src0->Base;
1852 inst->SrcReg[0] = *src0;
1855 inst->Base.SrcReg[1] = src1->Base;
1856 inst->SrcReg[1] = *src1;
1858 init_src_reg(& inst->SrcReg[1]);
1862 inst->Base.SrcReg[2] = src2->Base;
1863 inst->SrcReg[2] = *src2;
1865 init_src_reg(& inst->SrcReg[2]);
1874 init_dst_reg(struct prog_dst_register *r)
1876 memset(r, 0, sizeof(*r));
1877 r->File = PROGRAM_UNDEFINED;
1878 r->WriteMask = WRITEMASK_XYZW;
1879 r->CondMask = COND_TR;
1880 r->CondSwizzle = SWIZZLE_NOOP;
1885 init_src_reg(struct asm_src_register *r)
1887 memset(r, 0, sizeof(*r));
1888 r->Base.File = PROGRAM_UNDEFINED;
1889 r->Base.Swizzle = SWIZZLE_NOOP;
1895 * Validate the set of inputs used by a program
1897 * Validates that legal sets of inputs are used by the program. In this case
1898 * "used" included both reading the input or binding the input to a name using
1899 * the \c ATTRIB command.
1902 * \c TRUE if the combination of inputs used is valid, \c FALSE otherwise.
1905 validate_inputs(struct YYLTYPE *locp, struct asm_parser_state *state)
1907 const int inputs = state->prog->InputsRead | state->InputsBound;
1909 if (((inputs & 0x0ffff) & (inputs >> 16)) != 0) {
1910 yyerror(locp, state, "illegal use of generic attribute and name attribute");
1919 declare_variable(struct asm_parser_state *state, char *name, enum asm_type t,
1920 struct YYLTYPE *locp)
1922 struct asm_symbol *s = NULL;
1923 struct asm_symbol *exist = (struct asm_symbol *)
1924 _mesa_symbol_table_find_symbol(state->st, 0, name);
1927 if (exist != NULL) {
1928 yyerror(locp, state, "redeclared identifier");
1930 s = calloc(1, sizeof(struct asm_symbol));
1936 if (state->prog->NumTemporaries >= state->limits->MaxTemps) {
1937 yyerror(locp, state, "too many temporaries declared");
1942 s->temp_binding = state->prog->NumTemporaries;
1943 state->prog->NumTemporaries++;
1947 if (state->prog->NumAddressRegs >= state->limits->MaxAddressRegs) {
1948 yyerror(locp, state, "too many address registers declared");
1953 /* FINISHME: Add support for multiple address registers.
1955 state->prog->NumAddressRegs++;
1962 _mesa_symbol_table_add_symbol(state->st, 0, s->name, s);
1963 s->next = state->sym;
1971 int add_state_reference(struct gl_program_parameter_list *param_list,
1972 const gl_state_index tokens[STATE_LENGTH])
1974 const GLuint size = 4; /* XXX fix */
1978 name = _mesa_program_state_string(tokens);
1979 index = _mesa_add_parameter(param_list, PROGRAM_STATE_VAR, name,
1981 NULL, (gl_state_index *) tokens, 0x0);
1982 param_list->StateFlags |= _mesa_program_state_flags(tokens);
1984 /* free name string here since we duplicated it in add_parameter() */
1992 initialize_symbol_from_state(struct gl_program *prog,
1993 struct asm_symbol *param_var,
1994 const gl_state_index tokens[STATE_LENGTH])
1997 gl_state_index state_tokens[STATE_LENGTH];
2000 memcpy(state_tokens, tokens, sizeof(state_tokens));
2002 param_var->type = at_param;
2003 param_var->param_binding_type = PROGRAM_STATE_VAR;
2005 /* If we are adding a STATE_MATRIX that has multiple rows, we need to
2006 * unroll it and call add_state_reference() for each row
2008 if ((state_tokens[0] == STATE_MODELVIEW_MATRIX ||
2009 state_tokens[0] == STATE_PROJECTION_MATRIX ||
2010 state_tokens[0] == STATE_MVP_MATRIX ||
2011 state_tokens[0] == STATE_TEXTURE_MATRIX ||
2012 state_tokens[0] == STATE_PROGRAM_MATRIX)
2013 && (state_tokens[2] != state_tokens[3])) {
2015 const int first_row = state_tokens[2];
2016 const int last_row = state_tokens[3];
2018 for (row = first_row; row <= last_row; row++) {
2019 state_tokens[2] = state_tokens[3] = row;
2021 idx = add_state_reference(prog->Parameters, state_tokens);
2022 if (param_var->param_binding_begin == ~0U)
2023 param_var->param_binding_begin = idx;
2024 param_var->param_binding_length++;
2028 idx = add_state_reference(prog->Parameters, state_tokens);
2029 if (param_var->param_binding_begin == ~0U)
2030 param_var->param_binding_begin = idx;
2031 param_var->param_binding_length++;
2039 initialize_symbol_from_param(struct gl_program *prog,
2040 struct asm_symbol *param_var,
2041 const gl_state_index tokens[STATE_LENGTH])
2044 gl_state_index state_tokens[STATE_LENGTH];
2047 memcpy(state_tokens, tokens, sizeof(state_tokens));
2049 assert((state_tokens[0] == STATE_VERTEX_PROGRAM)
2050 || (state_tokens[0] == STATE_FRAGMENT_PROGRAM));
2051 assert((state_tokens[1] == STATE_ENV)
2052 || (state_tokens[1] == STATE_LOCAL));
2054 param_var->type = at_param;
2055 param_var->param_binding_type = (state_tokens[1] == STATE_ENV)
2056 ? PROGRAM_ENV_PARAM : PROGRAM_LOCAL_PARAM;
2058 /* If we are adding a STATE_ENV or STATE_LOCAL that has multiple elements,
2059 * we need to unroll it and call add_state_reference() for each row
2061 if (state_tokens[2] != state_tokens[3]) {
2063 const int first_row = state_tokens[2];
2064 const int last_row = state_tokens[3];
2066 for (row = first_row; row <= last_row; row++) {
2067 state_tokens[2] = state_tokens[3] = row;
2069 idx = add_state_reference(prog->Parameters, state_tokens);
2070 if (param_var->param_binding_begin == ~0U)
2071 param_var->param_binding_begin = idx;
2072 param_var->param_binding_length++;
2076 idx = add_state_reference(prog->Parameters, state_tokens);
2077 if (param_var->param_binding_begin == ~0U)
2078 param_var->param_binding_begin = idx;
2079 param_var->param_binding_length++;
2087 initialize_symbol_from_const(struct gl_program *prog,
2088 struct asm_symbol *param_var,
2089 const struct asm_vector *vec)
2091 const int idx = _mesa_add_parameter(prog->Parameters, PROGRAM_CONSTANT,
2092 NULL, vec->count, GL_NONE, vec->data,
2095 param_var->type = at_param;
2096 param_var->param_binding_type = PROGRAM_CONSTANT;
2098 if (param_var->param_binding_begin == ~0U)
2099 param_var->param_binding_begin = idx;
2100 param_var->param_binding_length++;
2107 make_error_string(const char *fmt, ...)
2113 va_start(args, fmt);
2115 /* Call vsnprintf once to determine how large the final string is. Call it
2116 * again to do the actual formatting. from the vsnprintf manual page:
2118 * Upon successful return, these functions return the number of
2119 * characters printed (not including the trailing '\0' used to end
2120 * output to strings).
2122 length = 1 + vsnprintf(NULL, 0, fmt, args);
2124 str = _mesa_malloc(length);
2126 vsnprintf(str, length, fmt, args);
2136 yyerror(YYLTYPE *locp, struct asm_parser_state *state, const char *s)
2141 err_str = make_error_string("glProgramStringARB(%s)\n", s);
2143 _mesa_error(state->ctx, GL_INVALID_OPERATION, err_str);
2144 _mesa_free(err_str);
2147 err_str = make_error_string("line %u, char %u: error: %s\n",
2148 locp->first_line, locp->first_column, s);
2149 _mesa_set_program_error(state->ctx, locp->position, err_str);
2152 _mesa_free(err_str);
2158 _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
2159 GLsizei len, struct asm_parser_state *state)
2161 struct gl_program_constants limits;
2162 struct asm_instruction *inst;
2165 GLboolean result = GL_FALSE;
2167 struct asm_symbol *sym;
2170 state->prog->Target = target;
2171 state->prog->Parameters = _mesa_new_parameter_list();
2173 /* Make a copy of the program string and force it to be NUL-terminated.
2175 strz = (GLubyte *) _mesa_malloc(len + 1);
2177 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramStringARB");
2180 _mesa_memcpy (strz, str, len);
2183 state->prog->String = strz;
2185 state->st = _mesa_symbol_table_ctor();
2187 /* All of these limits should come from ctx.
2189 limits.MaxInstructions = 128;
2190 limits.MaxAluInstructions = 128;
2191 limits.MaxTexInstructions = 128;
2192 limits.MaxTexIndirections = 128;
2193 limits.MaxAttribs = 16;
2194 limits.MaxTemps = 128;
2195 limits.MaxAddressRegs = 1;
2196 limits.MaxParameters = 128;
2197 limits.MaxLocalParams = 256;
2198 limits.MaxEnvParams = 128;
2199 limits.MaxNativeInstructions = 128;
2200 limits.MaxNativeAluInstructions = 128;
2201 limits.MaxNativeTexInstructions = 128;
2202 limits.MaxNativeTexIndirections = 128;
2203 limits.MaxNativeAttribs = 16;
2204 limits.MaxNativeTemps = 128;
2205 limits.MaxNativeAddressRegs = 1;
2206 limits.MaxNativeParameters = 128;
2207 limits.MaxUniformComponents = 0;
2209 state->limits = & limits;
2211 state->MaxTextureImageUnits = 16;
2212 state->MaxTextureCoordUnits = 8;
2213 state->MaxTextureUnits = 8;
2214 state->MaxClipPlanes = 6;
2215 state->MaxLights = 8;
2216 state->MaxProgramMatrices = 8;
2218 state->state_param_enum = (target == GL_VERTEX_PROGRAM_ARB)
2219 ? STATE_VERTEX_PROGRAM : STATE_FRAGMENT_PROGRAM;
2221 _mesa_set_program_error(ctx, -1, NULL);
2223 _mesa_program_lexer_ctor(& state->scanner, state, (const char *) str, len);
2225 _mesa_program_lexer_dtor(state->scanner);
2228 if (ctx->Program.ErrorPos != -1) {
2232 if (! _mesa_layout_parameters(state)) {
2236 loc.first_column = 0;
2239 yyerror(& loc, state, "invalid PARAM usage");
2245 /* Add one instruction to store the "END" instruction.
2247 state->prog->Instructions =
2248 _mesa_alloc_instructions(state->prog->NumInstructions + 1);
2249 inst = state->inst_head;
2250 for (i = 0; i < state->prog->NumInstructions; i++) {
2251 struct asm_instruction *const temp = inst->next;
2253 state->prog->Instructions[i] = inst->Base;
2257 /* Finally, tag on an OPCODE_END instruction */
2259 const GLuint numInst = state->prog->NumInstructions;
2260 _mesa_init_instructions(state->prog->Instructions + numInst, 1);
2261 state->prog->Instructions[numInst].Opcode = OPCODE_END;
2263 state->prog->NumInstructions++;
2265 state->prog->NumParameters = state->prog->Parameters->NumParameters;
2268 * Initialize native counts to logical counts. The device driver may
2269 * change them if program is translated into a hardware program.
2271 state->prog->NumNativeInstructions = state->prog->NumInstructions;
2272 state->prog->NumNativeTemporaries = state->prog->NumTemporaries;
2273 state->prog->NumNativeParameters = state->prog->NumParameters;
2274 state->prog->NumNativeAttributes = state->prog->NumAttributes;
2275 state->prog->NumNativeAddressRegs = state->prog->NumAddressRegs;
2280 for (inst = state->inst_head; inst != NULL; inst = temp) {
2285 state->inst_head = NULL;
2286 state->inst_tail = NULL;
2288 for (sym = state->sym; sym != NULL; sym = temp) {
2291 _mesa_free((void *) sym->name);
2296 _mesa_symbol_table_dtor(state->st);