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);
297 const char *const err_str = (state->mode == ARB_vertex)
298 ? "invalid ARB vertex program option"
299 : "invalid ARB fragment program option";
301 yyerror(& @2, state, err_str);
307 statementSequence: statementSequence statement
311 statement: instruction ';'
314 if (state->inst_tail == NULL) {
315 state->inst_head = $1;
317 state->inst_tail->next = $1;
320 state->inst_tail = $1;
323 state->prog->NumInstructions++;
326 | namingStatement ';'
329 instruction: ALU_instruction
332 state->prog->NumAluInstructions++;
337 state->prog->NumTexInstructions++;
341 ALU_instruction: ARL_instruction
342 | VECTORop_instruction
343 | SCALARop_instruction
344 | BINSCop_instruction
350 TexInstruction: SAMPLE_instruction
354 ARL_instruction: ARL maskedAddrReg ',' scalarSrcReg
356 $$ = asm_instruction_ctor(OPCODE_ARL, & $2, & $4, NULL, NULL);
360 VECTORop_instruction: VECTOR_OP maskedDstReg ',' swizzleSrcReg
362 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL);
363 $$->Base.SaturateMode = $1.SaturateMode;
367 SCALARop_instruction: SCALAR_OP maskedDstReg ',' scalarSrcReg
369 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL);
370 $$->Base.SaturateMode = $1.SaturateMode;
374 BINSCop_instruction: BINSC_OP maskedDstReg ',' scalarSrcReg ',' scalarSrcReg
376 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, NULL);
377 $$->Base.SaturateMode = $1.SaturateMode;
382 BINop_instruction: BIN_OP maskedDstReg ',' swizzleSrcReg ',' swizzleSrcReg
384 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, NULL);
385 $$->Base.SaturateMode = $1.SaturateMode;
389 TRIop_instruction: TRI_OP maskedDstReg ','
390 swizzleSrcReg ',' swizzleSrcReg ',' swizzleSrcReg
392 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, & $8);
393 $$->Base.SaturateMode = $1.SaturateMode;
397 SAMPLE_instruction: SAMPLE_OP maskedDstReg ',' swizzleSrcReg ',' texImageUnit ',' texTarget
399 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL);
401 const GLbitfield tex_mask = (1U << $6);
402 GLbitfield shadow_tex = 0;
403 GLbitfield target_mask = 0;
406 $$->Base.SaturateMode = $1.SaturateMode;
407 $$->Base.TexSrcUnit = $6;
410 shadow_tex = tex_mask;
412 $$->Base.TexSrcTarget = -$8;
413 $$->Base.TexShadow = 1;
415 $$->Base.TexSrcTarget = $8;
418 target_mask = (1U << $$->Base.TexSrcTarget);
420 /* If this texture unit was previously accessed and that access
421 * had a different texture target, generate an error.
423 * If this texture unit was previously accessed and that access
424 * had a different shadow mode, generate an error.
426 if ((state->prog->TexturesUsed[$6] != 0)
427 && ((state->prog->TexturesUsed[$6] != target_mask)
428 || ((state->prog->ShadowSamplers & tex_mask)
431 "multiple targets used on one texture image unit");
436 state->prog->TexturesUsed[$6] |= target_mask;
437 state->prog->ShadowSamplers |= shadow_tex;
442 KIL_instruction: KIL swizzleSrcReg
444 $$ = asm_instruction_ctor(OPCODE_KIL, NULL, & $2, NULL, NULL);
445 state->fragment.UsesKill = 1;
449 texImageUnit: TEXTURE_UNIT optTexImageUnitNum
455 texTarget: TEX_1D { $$ = TEXTURE_1D_INDEX; }
456 | TEX_2D { $$ = TEXTURE_2D_INDEX; }
457 | TEX_3D { $$ = TEXTURE_3D_INDEX; }
458 | TEX_CUBE { $$ = TEXTURE_CUBE_INDEX; }
459 | TEX_RECT { $$ = TEXTURE_RECT_INDEX; }
460 | TEX_SHADOW1D { $$ = -TEXTURE_1D_INDEX; }
461 | TEX_SHADOW2D { $$ = -TEXTURE_2D_INDEX; }
462 | TEX_SHADOWRECT { $$ = -TEXTURE_RECT_INDEX; }
463 | TEX_ARRAY1D { $$ = TEXTURE_1D_ARRAY_INDEX; }
464 | TEX_ARRAY2D { $$ = TEXTURE_2D_ARRAY_INDEX; }
465 | TEX_ARRAYSHADOW1D { $$ = -TEXTURE_1D_ARRAY_INDEX; }
466 | TEX_ARRAYSHADOW2D { $$ = -TEXTURE_2D_ARRAY_INDEX; }
469 SWZ_instruction: SWZ maskedDstReg ',' srcReg ',' extendedSwizzle
471 /* FIXME: Is this correct? Should the extenedSwizzle be applied
472 * FIXME: to the existing swizzle?
474 $4.Base.Swizzle = $6.swizzle;
475 $4.Base.Negate = $6.mask;
477 $$ = asm_instruction_ctor(OPCODE_SWZ, & $2, & $4, NULL, NULL);
478 $$->Base.SaturateMode = $1.SaturateMode;
482 scalarSrcReg: optionalSign srcReg scalarSuffix
487 $$.Base.Negate = ~$$.Base.Negate;
490 $$.Base.Swizzle = _mesa_combine_swizzles($$.Base.Swizzle,
495 swizzleSrcReg: optionalSign srcReg swizzleSuffix
500 $$.Base.Negate = ~$$.Base.Negate;
503 $$.Base.Swizzle = _mesa_combine_swizzles($$.Base.Swizzle,
508 maskedDstReg: dstReg optionalMask
511 $$.WriteMask = $2.mask;
513 if ($$.File == PROGRAM_OUTPUT) {
514 /* Technically speaking, this should check that it is in
515 * vertex program mode. However, PositionInvariant can never be
516 * set in fragment program mode, so it is somewhat irrelevant.
518 if (state->option.PositionInvariant
519 && ($$.Index == VERT_RESULT_HPOS)) {
520 yyerror(& @1, state, "position-invariant programs cannot "
525 state->prog->OutputsWritten |= (1U << $$.Index);
530 maskedAddrReg: addrReg addrWriteMask
533 $$.File = PROGRAM_ADDRESS;
535 $$.WriteMask = $2.mask;
539 extendedSwizzle: extSwizComp ',' extSwizComp ',' extSwizComp ',' extSwizComp
541 const unsigned xyzw_valid =
543 | ($3.xyzw_valid << 1)
544 | ($5.xyzw_valid << 2)
545 | ($7.xyzw_valid << 3);
546 const unsigned rgba_valid =
548 | ($3.rgba_valid << 1)
549 | ($5.rgba_valid << 2)
550 | ($7.rgba_valid << 3);
552 /* All of the swizzle components have to be valid in either RGBA
553 * or XYZW. Note that 0 and 1 are valid in both, so both masks
554 * can have some bits set.
556 * We somewhat deviate from the spec here. It would be really hard
557 * to figure out which component is the error, and there probably
558 * isn't a lot of benefit.
560 if ((rgba_valid != 0x0f) && (xyzw_valid != 0x0f)) {
561 yyerror(& @1, state, "cannot combine RGBA and XYZW swizzle "
566 $$.swizzle = MAKE_SWIZZLE4($1.swz, $3.swz, $5.swz, $7.swz);
567 $$.mask = ($1.negate) | ($3.negate << 1) | ($5.negate << 2)
572 extSwizComp: optionalSign extSwizSel
575 $$.negate = ($1) ? 1 : 0;
581 if (($1 != 0) && ($1 != 1)) {
582 yyerror(& @1, state, "invalid extended swizzle selector");
586 $$.swz = ($1 == 0) ? SWIZZLE_ZERO : SWIZZLE_ONE;
588 /* 0 and 1 are valid for both RGBA swizzle names and XYZW
598 if (strlen($1) > 1) {
599 yyerror(& @1, state, "invalid extended swizzle selector");
642 yyerror(& @1, state, "invalid extended swizzle selector");
649 srcReg: IDENTIFIER /* temporaryReg | progParamSingle */
651 struct asm_symbol *const s = (struct asm_symbol *)
652 _mesa_symbol_table_find_symbol(state->st, 0, $1);
657 yyerror(& @1, state, "invalid operand variable");
659 } else if ((s->type != at_param) && (s->type != at_temp)
660 && (s->type != at_attrib)) {
661 yyerror(& @1, state, "invalid operand variable");
663 } else if ((s->type == at_param) && s->param_is_array) {
664 yyerror(& @1, state, "non-array access to array PARAM");
671 $$.Base.File = PROGRAM_TEMPORARY;
672 $$.Base.Index = s->temp_binding;
675 $$.Base.File = s->param_binding_type;
676 $$.Base.Index = s->param_binding_begin;
679 $$.Base.File = PROGRAM_INPUT;
680 $$.Base.Index = s->attrib_binding;
681 state->prog->InputsRead |= (1U << $$.Base.Index);
683 if (!validate_inputs(& @1, state)) {
696 $$.Base.File = PROGRAM_INPUT;
698 state->prog->InputsRead |= (1U << $$.Base.Index);
700 if (!validate_inputs(& @1, state)) {
704 | progParamArray '[' progParamArrayMem ']'
706 if (! $3.Base.RelAddr
707 && ((unsigned) $3.Base.Index >= $1->param_binding_length)) {
708 yyerror(& @3, state, "out of bounds array access");
713 $$.Base.File = $1->param_binding_type;
715 if ($3.Base.RelAddr) {
716 $1->param_accessed_indirectly = 1;
719 $$.Base.Index = $3.Base.Index;
722 $$.Base.Index = $1->param_binding_begin + $3.Base.Index;
728 $$.Base.File = ($1.name != NULL)
729 ? $1.param_binding_type
731 $$.Base.Index = $1.param_binding_begin;
735 dstReg: resultBinding
738 $$.File = PROGRAM_OUTPUT;
741 | IDENTIFIER /* temporaryReg | vertexResultReg */
743 struct asm_symbol *const s = (struct asm_symbol *)
744 _mesa_symbol_table_find_symbol(state->st, 0, $1);
749 yyerror(& @1, state, "invalid operand variable");
751 } else if ((s->type != at_output) && (s->type != at_temp)) {
752 yyerror(& @1, state, "invalid operand variable");
759 $$.File = PROGRAM_TEMPORARY;
760 $$.Index = s->temp_binding;
763 $$.File = PROGRAM_OUTPUT;
764 $$.Index = s->output_binding;
767 $$.File = s->param_binding_type;
768 $$.Index = s->param_binding_begin;
774 progParamArray: IDENTIFIER
776 struct asm_symbol *const s = (struct asm_symbol *)
777 _mesa_symbol_table_find_symbol(state->st, 0, $1);
782 yyerror(& @1, state, "invalid operand variable");
784 } else if ((s->type != at_param) || !s->param_is_array) {
785 yyerror(& @1, state, "array access to non-PARAM variable");
793 progParamArrayMem: progParamArrayAbs | progParamArrayRel;
795 progParamArrayAbs: INTEGER
802 progParamArrayRel: addrReg addrComponent addrRegRelOffset
804 /* FINISHME: Add support for multiple address registers.
806 /* FINISHME: Add support for 4-component address registers.
814 addrRegRelOffset: { $$ = 0; }
815 | '+' addrRegPosOffset { $$ = $2; }
816 | '-' addrRegNegOffset { $$ = -$2; }
819 addrRegPosOffset: INTEGER
821 if (($1 < 0) || ($1 > 63)) {
823 "relative address offset too large (positive)");
831 addrRegNegOffset: INTEGER
833 if (($1 < 0) || ($1 > 64)) {
835 "relative address offset too large (negative)");
845 struct asm_symbol *const s = (struct asm_symbol *)
846 _mesa_symbol_table_find_symbol(state->st, 0, $1);
851 yyerror(& @1, state, "invalid array member");
853 } else if (s->type != at_address) {
855 "invalid variable for indexed array access");
865 if ($1.mask != WRITEMASK_X) {
866 yyerror(& @1, state, "invalid address component selector");
876 if ($1.mask != WRITEMASK_X) {
878 "address register write mask must be \".x\"");
891 | { $$.swizzle = SWIZZLE_NOOP; $$.mask = WRITEMASK_XYZW; }
894 optionalMask: MASK4 | MASK3 | MASK2 | MASK1
895 | { $$.swizzle = SWIZZLE_NOOP; $$.mask = WRITEMASK_XYZW; }
898 namingStatement: ATTRIB_statement
906 ATTRIB_statement: ATTRIB IDENTIFIER '=' attribBinding
908 struct asm_symbol *const s =
909 declare_variable(state, $2, at_attrib, & @2);
915 s->attrib_binding = $4;
916 state->InputsBound |= (1U << s->attrib_binding);
918 if (!validate_inputs(& @4, state)) {
925 attribBinding: VERTEX vtxAttribItem
929 | FRAGMENT fragAttribItem
935 vtxAttribItem: POSITION
937 $$ = VERT_ATTRIB_POS;
939 | WEIGHT vtxOptWeightNum
941 $$ = VERT_ATTRIB_WEIGHT;
945 $$ = VERT_ATTRIB_NORMAL;
949 if (!state->ctx->Extensions.EXT_secondary_color) {
950 yyerror(& @2, state, "GL_EXT_secondary_color not supported");
954 $$ = VERT_ATTRIB_COLOR0 + $2;
958 if (!state->ctx->Extensions.EXT_fog_coord) {
959 yyerror(& @1, state, "GL_EXT_fog_coord not supported");
963 $$ = VERT_ATTRIB_FOG;
965 | TEXCOORD optTexCoordUnitNum
967 $$ = VERT_ATTRIB_TEX0 + $2;
969 | MATRIXINDEX '[' vtxWeightNum ']'
971 yyerror(& @1, state, "GL_ARB_matrix_palette not supported");
974 | VTXATTRIB '[' vtxAttribNum ']'
976 $$ = VERT_ATTRIB_GENERIC0 + $3;
980 vtxAttribNum: INTEGER
982 if ((unsigned) $1 >= state->limits->MaxAttribs) {
983 yyerror(& @1, state, "invalid vertex attribute reference");
991 vtxOptWeightNum: | '[' vtxWeightNum ']';
992 vtxWeightNum: INTEGER;
994 fragAttribItem: POSITION
996 $$ = FRAG_ATTRIB_WPOS;
1000 $$ = FRAG_ATTRIB_COL0 + $2;
1004 $$ = FRAG_ATTRIB_FOGC;
1006 | TEXCOORD optTexCoordUnitNum
1008 $$ = FRAG_ATTRIB_TEX0 + $2;
1012 PARAM_statement: PARAM_singleStmt | PARAM_multipleStmt;
1014 PARAM_singleStmt: PARAM IDENTIFIER paramSingleInit
1016 struct asm_symbol *const s =
1017 declare_variable(state, $2, at_param, & @2);
1023 s->param_binding_type = $3.param_binding_type;
1024 s->param_binding_begin = $3.param_binding_begin;
1025 s->param_binding_length = $3.param_binding_length;
1026 s->param_is_array = 0;
1031 PARAM_multipleStmt: PARAM IDENTIFIER '[' optArraySize ']' paramMultipleInit
1033 if (($4 != 0) && ((unsigned) $4 != $6.param_binding_length)) {
1035 yyerror(& @4, state,
1036 "parameter array size and number of bindings must match");
1039 struct asm_symbol *const s =
1040 declare_variable(state, $2, $6.type, & @2);
1046 s->param_binding_type = $6.param_binding_type;
1047 s->param_binding_begin = $6.param_binding_begin;
1048 s->param_binding_length = $6.param_binding_length;
1049 s->param_is_array = 1;
1061 if (($1 < 1) || ((unsigned) $1 > state->limits->MaxParameters)) {
1062 yyerror(& @1, state, "invalid parameter array size");
1070 paramSingleInit: '=' paramSingleItemDecl
1076 paramMultipleInit: '=' '{' paramMultInitList '}'
1082 paramMultInitList: paramMultipleItem
1083 | paramMultInitList ',' paramMultipleItem
1085 $1.param_binding_length += $3.param_binding_length;
1090 paramSingleItemDecl: stateSingleItem
1092 memset(& $$, 0, sizeof($$));
1093 $$.param_binding_begin = ~0;
1094 initialize_symbol_from_state(state->prog, & $$, $1);
1098 memset(& $$, 0, sizeof($$));
1099 $$.param_binding_begin = ~0;
1100 initialize_symbol_from_param(state->prog, & $$, $1);
1104 memset(& $$, 0, sizeof($$));
1105 $$.param_binding_begin = ~0;
1106 initialize_symbol_from_const(state->prog, & $$, & $1);
1110 paramSingleItemUse: stateSingleItem
1112 memset(& $$, 0, sizeof($$));
1113 $$.param_binding_begin = ~0;
1114 initialize_symbol_from_state(state->prog, & $$, $1);
1118 memset(& $$, 0, sizeof($$));
1119 $$.param_binding_begin = ~0;
1120 initialize_symbol_from_param(state->prog, & $$, $1);
1124 memset(& $$, 0, sizeof($$));
1125 $$.param_binding_begin = ~0;
1126 initialize_symbol_from_const(state->prog, & $$, & $1);
1130 paramMultipleItem: stateMultipleItem
1132 memset(& $$, 0, sizeof($$));
1133 $$.param_binding_begin = ~0;
1134 initialize_symbol_from_state(state->prog, & $$, $1);
1136 | programMultipleItem
1138 memset(& $$, 0, sizeof($$));
1139 $$.param_binding_begin = ~0;
1140 initialize_symbol_from_param(state->prog, & $$, $1);
1144 memset(& $$, 0, sizeof($$));
1145 $$.param_binding_begin = ~0;
1146 initialize_symbol_from_const(state->prog, & $$, & $1);
1150 stateMultipleItem: stateSingleItem { memcpy($$, $1, sizeof($$)); }
1151 | STATE stateMatrixRows { memcpy($$, $2, sizeof($$)); }
1154 stateSingleItem: STATE stateMaterialItem { memcpy($$, $2, sizeof($$)); }
1155 | STATE stateLightItem { memcpy($$, $2, sizeof($$)); }
1156 | STATE stateLightModelItem { memcpy($$, $2, sizeof($$)); }
1157 | STATE stateLightProdItem { memcpy($$, $2, sizeof($$)); }
1158 | STATE stateTexGenItem { memcpy($$, $2, sizeof($$)); }
1159 | STATE stateTexEnvItem { memcpy($$, $2, sizeof($$)); }
1160 | STATE stateFogItem { memcpy($$, $2, sizeof($$)); }
1161 | STATE stateClipPlaneItem { memcpy($$, $2, sizeof($$)); }
1162 | STATE statePointItem { memcpy($$, $2, sizeof($$)); }
1163 | STATE stateMatrixRow { memcpy($$, $2, sizeof($$)); }
1164 | STATE stateDepthItem { memcpy($$, $2, sizeof($$)); }
1167 stateMaterialItem: MATERIAL optFaceType stateMatProperty
1169 memset($$, 0, sizeof($$));
1170 $$[0] = STATE_MATERIAL;
1176 stateMatProperty: ambDiffSpecProperty
1182 $$ = STATE_EMISSION;
1186 $$ = STATE_SHININESS;
1190 stateLightItem: LIGHT '[' stateLightNumber ']' stateLightProperty
1192 memset($$, 0, sizeof($$));
1193 $$[0] = STATE_LIGHT;
1199 stateLightProperty: ambDiffSpecProperty
1205 $$ = STATE_POSITION;
1209 if (!state->ctx->Extensions.EXT_point_parameters) {
1210 yyerror(& @1, state, "GL_ARB_point_parameters not supported");
1214 $$ = STATE_ATTENUATION;
1216 | SPOT stateSpotProperty
1222 $$ = STATE_HALF_VECTOR;
1226 stateSpotProperty: DIRECTION
1228 $$ = STATE_SPOT_DIRECTION;
1232 stateLightModelItem: LIGHTMODEL stateLModProperty
1239 stateLModProperty: AMBIENT
1241 memset($$, 0, sizeof($$));
1242 $$[0] = STATE_LIGHTMODEL_AMBIENT;
1244 | optFaceType SCENECOLOR
1246 memset($$, 0, sizeof($$));
1247 $$[0] = STATE_LIGHTMODEL_SCENECOLOR;
1252 stateLightProdItem: LIGHTPROD '[' stateLightNumber ']' optFaceType stateLProdProperty
1254 memset($$, 0, sizeof($$));
1255 $$[0] = STATE_LIGHTPROD;
1262 stateLProdProperty: ambDiffSpecProperty;
1264 stateTexEnvItem: TEXENV optLegacyTexUnitNum stateTexEnvProperty
1266 memset($$, 0, sizeof($$));
1272 stateTexEnvProperty: COLOR
1274 $$ = STATE_TEXENV_COLOR;
1278 ambDiffSpecProperty: AMBIENT
1288 $$ = STATE_SPECULAR;
1292 stateLightNumber: INTEGER
1294 if ((unsigned) $1 >= state->MaxLights) {
1295 yyerror(& @1, state, "invalid light selector");
1303 stateTexGenItem: TEXGEN optTexCoordUnitNum stateTexGenType stateTexGenCoord
1305 memset($$, 0, sizeof($$));
1306 $$[0] = STATE_TEXGEN;
1312 stateTexGenType: EYE
1314 $$ = STATE_TEXGEN_EYE_S;
1318 $$ = STATE_TEXGEN_OBJECT_S;
1321 stateTexGenCoord: TEXGEN_S
1323 $$ = STATE_TEXGEN_EYE_S - STATE_TEXGEN_EYE_S;
1327 $$ = STATE_TEXGEN_EYE_T - STATE_TEXGEN_EYE_S;
1331 $$ = STATE_TEXGEN_EYE_R - STATE_TEXGEN_EYE_S;
1335 $$ = STATE_TEXGEN_EYE_Q - STATE_TEXGEN_EYE_S;
1339 stateFogItem: FOG stateFogProperty
1341 memset($$, 0, sizeof($$));
1346 stateFogProperty: COLOR
1348 $$ = STATE_FOG_COLOR;
1352 $$ = STATE_FOG_PARAMS;
1356 stateClipPlaneItem: CLIP '[' stateClipPlaneNum ']' PLANE
1358 memset($$, 0, sizeof($$));
1359 $$[0] = STATE_CLIPPLANE;
1364 stateClipPlaneNum: INTEGER
1366 if ((unsigned) $1 >= state->MaxClipPlanes) {
1367 yyerror(& @1, state, "invalid clip plane selector");
1375 statePointItem: POINT_TOK statePointProperty
1377 memset($$, 0, sizeof($$));
1382 statePointProperty: SIZE_TOK
1384 $$ = STATE_POINT_SIZE;
1388 $$ = STATE_POINT_ATTENUATION;
1392 stateMatrixRow: stateMatrixItem ROW '[' stateMatrixRowNum ']'
1402 stateMatrixRows: stateMatrixItem optMatrixRows
1417 | ROW '[' stateMatrixRowNum DOT_DOT stateMatrixRowNum ']'
1419 /* It seems logical that the matrix row range specifier would have
1420 * to specify a range or more than one row (i.e., $5 > $3).
1421 * However, the ARB_vertex_program spec says "a program will fail
1422 * to load if <a> is greater than <b>." This means that $3 == $5
1426 yyerror(& @3, state, "invalid matrix row range");
1435 stateMatrixItem: MATRIX stateMatrixName stateOptMatModifier
1443 stateOptMatModifier:
1453 stateMatModifier: INVERSE
1455 $$ = STATE_MATRIX_INVERSE;
1459 $$ = STATE_MATRIX_TRANSPOSE;
1463 $$ = STATE_MATRIX_INVTRANS;
1467 stateMatrixRowNum: INTEGER
1470 yyerror(& @1, state, "invalid matrix row reference");
1478 stateMatrixName: MODELVIEW stateOptModMatNum
1480 $$[0] = STATE_MODELVIEW_MATRIX;
1485 $$[0] = STATE_PROJECTION_MATRIX;
1490 $$[0] = STATE_MVP_MATRIX;
1493 | TEXTURE optTexCoordUnitNum
1495 $$[0] = STATE_TEXTURE_MATRIX;
1498 | PALETTE '[' statePaletteMatNum ']'
1500 yyerror(& @1, state, "GL_ARB_matrix_palette not supported");
1503 | MAT_PROGRAM '[' stateProgramMatNum ']'
1505 $$[0] = STATE_PROGRAM_MATRIX;
1514 | '[' stateModMatNum ']'
1519 stateModMatNum: INTEGER
1521 /* Since GL_ARB_vertex_blend isn't supported, only modelview matrix
1525 yyerror(& @1, state, "invalid modelview matrix index");
1532 statePaletteMatNum: INTEGER
1534 /* Since GL_ARB_matrix_palette isn't supported, just let any value
1535 * through here. The error will be generated later.
1540 stateProgramMatNum: INTEGER
1542 if ((unsigned) $1 >= state->MaxProgramMatrices) {
1543 yyerror(& @1, state, "invalid program matrix selector");
1551 stateDepthItem: DEPTH RANGE
1553 memset($$, 0, sizeof($$));
1554 $$[0] = STATE_DEPTH_RANGE;
1559 programSingleItem: progEnvParam | progLocalParam;
1561 programMultipleItem: progEnvParams | progLocalParams;
1563 progEnvParams: PROGRAM ENV '[' progEnvParamNums ']'
1565 memset($$, 0, sizeof($$));
1566 $$[0] = state->state_param_enum;
1573 progEnvParamNums: progEnvParamNum
1578 | progEnvParamNum DOT_DOT progEnvParamNum
1585 progEnvParam: PROGRAM ENV '[' progEnvParamNum ']'
1587 memset($$, 0, sizeof($$));
1588 $$[0] = state->state_param_enum;
1595 progLocalParams: PROGRAM LOCAL '[' progLocalParamNums ']'
1597 memset($$, 0, sizeof($$));
1598 $$[0] = state->state_param_enum;
1599 $$[1] = STATE_LOCAL;
1604 progLocalParamNums: progLocalParamNum
1609 | progLocalParamNum DOT_DOT progLocalParamNum
1616 progLocalParam: PROGRAM LOCAL '[' progLocalParamNum ']'
1618 memset($$, 0, sizeof($$));
1619 $$[0] = state->state_param_enum;
1620 $$[1] = STATE_LOCAL;
1626 progEnvParamNum: INTEGER
1628 if ((unsigned) $1 >= state->limits->MaxEnvParams) {
1629 yyerror(& @1, state, "invalid environment parameter reference");
1636 progLocalParamNum: INTEGER
1638 if ((unsigned) $1 >= state->limits->MaxLocalParams) {
1639 yyerror(& @1, state, "invalid local parameter reference");
1648 paramConstDecl: paramConstScalarDecl | paramConstVector;
1649 paramConstUse: paramConstScalarUse | paramConstVector;
1651 paramConstScalarDecl: signedFloatConstant
1661 paramConstScalarUse: REAL
1672 $$.data[0] = (float) $1;
1673 $$.data[1] = (float) $1;
1674 $$.data[2] = (float) $1;
1675 $$.data[3] = (float) $1;
1679 paramConstVector: '{' signedFloatConstant '}'
1687 | '{' signedFloatConstant ',' signedFloatConstant '}'
1695 | '{' signedFloatConstant ',' signedFloatConstant ','
1696 signedFloatConstant '}'
1704 | '{' signedFloatConstant ',' signedFloatConstant ','
1705 signedFloatConstant ',' signedFloatConstant '}'
1715 signedFloatConstant: optionalSign REAL
1717 $$ = ($1) ? -$2 : $2;
1719 | optionalSign INTEGER
1721 $$ = (float)(($1) ? -$2 : $2);
1725 optionalSign: '+' { $$ = FALSE; }
1726 | '-' { $$ = TRUE; }
1730 TEMP_statement: TEMP { $<integer>$ = $1; } varNameList
1733 ADDRESS_statement: ADDRESS { $<integer>$ = $1; } varNameList
1736 varNameList: varNameList ',' IDENTIFIER
1738 if (!declare_variable(state, $3, $<integer>0, & @3)) {
1745 if (!declare_variable(state, $1, $<integer>0, & @1)) {
1752 OUTPUT_statement: OUTPUT IDENTIFIER '=' resultBinding
1754 struct asm_symbol *const s =
1755 declare_variable(state, $2, at_output, & @2);
1761 s->output_binding = $4;
1766 resultBinding: RESULT POSITION
1768 if (state->mode == ARB_vertex) {
1769 $$ = VERT_RESULT_HPOS;
1771 yyerror(& @2, state, "invalid program result name");
1777 if (state->mode == ARB_vertex) {
1778 $$ = VERT_RESULT_FOGC;
1780 yyerror(& @2, state, "invalid program result name");
1784 | RESULT resultColBinding
1790 if (state->mode == ARB_vertex) {
1791 $$ = VERT_RESULT_PSIZ;
1793 yyerror(& @2, state, "invalid program result name");
1797 | RESULT TEXCOORD optTexCoordUnitNum
1799 if (state->mode == ARB_vertex) {
1800 $$ = VERT_RESULT_TEX0 + $3;
1802 yyerror(& @2, state, "invalid program result name");
1808 if (state->mode == ARB_fragment) {
1809 $$ = FRAG_RESULT_DEPTH;
1811 yyerror(& @2, state, "invalid program result name");
1817 resultColBinding: COLOR optResultFaceType optResultColorType
1825 $$ = (state->mode == ARB_vertex)
1827 : FRAG_RESULT_COLOR;
1831 if (state->mode == ARB_vertex) {
1832 $$ = VERT_RESULT_COL0;
1834 yyerror(& @1, state, "invalid program result name");
1840 if (state->mode == ARB_vertex) {
1841 $$ = VERT_RESULT_BFC0;
1843 yyerror(& @1, state, "invalid program result name");
1855 if (state->mode == ARB_vertex) {
1858 yyerror(& @1, state, "invalid program result name");
1864 if (state->mode == ARB_vertex) {
1867 yyerror(& @1, state, "invalid program result name");
1873 optFaceType: { $$ = 0; }
1878 optColorType: { $$ = 0; }
1879 | PRIMARY { $$ = 0; }
1880 | SECONDARY { $$ = 1; }
1883 optTexCoordUnitNum: { $$ = 0; }
1884 | '[' texCoordUnitNum ']' { $$ = $2; }
1887 optTexImageUnitNum: { $$ = 0; }
1888 | '[' texImageUnitNum ']' { $$ = $2; }
1891 optLegacyTexUnitNum: { $$ = 0; }
1892 | '[' legacyTexUnitNum ']' { $$ = $2; }
1895 texCoordUnitNum: INTEGER
1897 if ((unsigned) $1 >= state->MaxTextureCoordUnits) {
1898 yyerror(& @1, state, "invalid texture coordinate unit selector");
1906 texImageUnitNum: INTEGER
1908 if ((unsigned) $1 >= state->MaxTextureImageUnits) {
1909 yyerror(& @1, state, "invalid texture image unit selector");
1917 legacyTexUnitNum: INTEGER
1919 if ((unsigned) $1 >= state->MaxTextureUnits) {
1920 yyerror(& @1, state, "invalid texture unit selector");
1928 ALIAS_statement: ALIAS IDENTIFIER '=' IDENTIFIER
1930 struct asm_symbol *exist = (struct asm_symbol *)
1931 _mesa_symbol_table_find_symbol(state->st, 0, $2);
1932 struct asm_symbol *target = (struct asm_symbol *)
1933 _mesa_symbol_table_find_symbol(state->st, 0, $4);
1938 if (exist != NULL) {
1940 yyerror(& @2, state, "redeclared identifier");
1942 } else if (target == NULL) {
1944 yyerror(& @4, state,
1945 "undefined variable binding in ALIAS statement");
1948 _mesa_symbol_table_add_symbol(state->st, 0, $2, target);
1955 struct asm_instruction *
1956 asm_instruction_ctor(gl_inst_opcode op,
1957 const struct prog_dst_register *dst,
1958 const struct asm_src_register *src0,
1959 const struct asm_src_register *src1,
1960 const struct asm_src_register *src2)
1962 struct asm_instruction *inst = calloc(1, sizeof(struct asm_instruction));
1965 _mesa_init_instructions(& inst->Base, 1);
1966 inst->Base.Opcode = op;
1968 /* In the core ARB extensions only the KIL instruction doesn't have a
1969 * destination register.
1972 init_dst_reg(& inst->Base.DstReg);
1974 inst->Base.DstReg = *dst;
1977 inst->Base.SrcReg[0] = src0->Base;
1978 inst->SrcReg[0] = *src0;
1981 inst->Base.SrcReg[1] = src1->Base;
1982 inst->SrcReg[1] = *src1;
1984 init_src_reg(& inst->SrcReg[1]);
1988 inst->Base.SrcReg[2] = src2->Base;
1989 inst->SrcReg[2] = *src2;
1991 init_src_reg(& inst->SrcReg[2]);
2000 init_dst_reg(struct prog_dst_register *r)
2002 memset(r, 0, sizeof(*r));
2003 r->File = PROGRAM_UNDEFINED;
2004 r->WriteMask = WRITEMASK_XYZW;
2005 r->CondMask = COND_TR;
2006 r->CondSwizzle = SWIZZLE_NOOP;
2011 init_src_reg(struct asm_src_register *r)
2013 memset(r, 0, sizeof(*r));
2014 r->Base.File = PROGRAM_UNDEFINED;
2015 r->Base.Swizzle = SWIZZLE_NOOP;
2021 * Validate the set of inputs used by a program
2023 * Validates that legal sets of inputs are used by the program. In this case
2024 * "used" included both reading the input or binding the input to a name using
2025 * the \c ATTRIB command.
2028 * \c TRUE if the combination of inputs used is valid, \c FALSE otherwise.
2031 validate_inputs(struct YYLTYPE *locp, struct asm_parser_state *state)
2033 const int inputs = state->prog->InputsRead | state->InputsBound;
2035 if (((inputs & 0x0ffff) & (inputs >> 16)) != 0) {
2036 yyerror(locp, state, "illegal use of generic attribute and name attribute");
2045 declare_variable(struct asm_parser_state *state, char *name, enum asm_type t,
2046 struct YYLTYPE *locp)
2048 struct asm_symbol *s = NULL;
2049 struct asm_symbol *exist = (struct asm_symbol *)
2050 _mesa_symbol_table_find_symbol(state->st, 0, name);
2053 if (exist != NULL) {
2054 yyerror(locp, state, "redeclared identifier");
2056 s = calloc(1, sizeof(struct asm_symbol));
2062 if (state->prog->NumTemporaries >= state->limits->MaxTemps) {
2063 yyerror(locp, state, "too many temporaries declared");
2068 s->temp_binding = state->prog->NumTemporaries;
2069 state->prog->NumTemporaries++;
2073 if (state->prog->NumAddressRegs >= state->limits->MaxAddressRegs) {
2074 yyerror(locp, state, "too many address registers declared");
2079 /* FINISHME: Add support for multiple address registers.
2081 state->prog->NumAddressRegs++;
2088 _mesa_symbol_table_add_symbol(state->st, 0, s->name, s);
2089 s->next = state->sym;
2097 int add_state_reference(struct gl_program_parameter_list *param_list,
2098 const gl_state_index tokens[STATE_LENGTH])
2100 const GLuint size = 4; /* XXX fix */
2104 name = _mesa_program_state_string(tokens);
2105 index = _mesa_add_parameter(param_list, PROGRAM_STATE_VAR, name,
2106 size, GL_NONE, NULL, tokens, 0x0);
2107 param_list->StateFlags |= _mesa_program_state_flags(tokens);
2109 /* free name string here since we duplicated it in add_parameter() */
2117 initialize_symbol_from_state(struct gl_program *prog,
2118 struct asm_symbol *param_var,
2119 const gl_state_index tokens[STATE_LENGTH])
2122 gl_state_index state_tokens[STATE_LENGTH];
2125 memcpy(state_tokens, tokens, sizeof(state_tokens));
2127 param_var->type = at_param;
2128 param_var->param_binding_type = PROGRAM_STATE_VAR;
2130 /* If we are adding a STATE_MATRIX that has multiple rows, we need to
2131 * unroll it and call add_state_reference() for each row
2133 if ((state_tokens[0] == STATE_MODELVIEW_MATRIX ||
2134 state_tokens[0] == STATE_PROJECTION_MATRIX ||
2135 state_tokens[0] == STATE_MVP_MATRIX ||
2136 state_tokens[0] == STATE_TEXTURE_MATRIX ||
2137 state_tokens[0] == STATE_PROGRAM_MATRIX)
2138 && (state_tokens[2] != state_tokens[3])) {
2140 const int first_row = state_tokens[2];
2141 const int last_row = state_tokens[3];
2143 for (row = first_row; row <= last_row; row++) {
2144 state_tokens[2] = state_tokens[3] = row;
2146 idx = add_state_reference(prog->Parameters, state_tokens);
2147 if (param_var->param_binding_begin == ~0U)
2148 param_var->param_binding_begin = idx;
2149 param_var->param_binding_length++;
2153 idx = add_state_reference(prog->Parameters, state_tokens);
2154 if (param_var->param_binding_begin == ~0U)
2155 param_var->param_binding_begin = idx;
2156 param_var->param_binding_length++;
2164 initialize_symbol_from_param(struct gl_program *prog,
2165 struct asm_symbol *param_var,
2166 const gl_state_index tokens[STATE_LENGTH])
2169 gl_state_index state_tokens[STATE_LENGTH];
2172 memcpy(state_tokens, tokens, sizeof(state_tokens));
2174 assert((state_tokens[0] == STATE_VERTEX_PROGRAM)
2175 || (state_tokens[0] == STATE_FRAGMENT_PROGRAM));
2176 assert((state_tokens[1] == STATE_ENV)
2177 || (state_tokens[1] == STATE_LOCAL));
2179 param_var->type = at_param;
2180 param_var->param_binding_type = (state_tokens[1] == STATE_ENV)
2181 ? PROGRAM_ENV_PARAM : PROGRAM_LOCAL_PARAM;
2183 /* If we are adding a STATE_ENV or STATE_LOCAL that has multiple elements,
2184 * we need to unroll it and call add_state_reference() for each row
2186 if (state_tokens[2] != state_tokens[3]) {
2188 const int first_row = state_tokens[2];
2189 const int last_row = state_tokens[3];
2191 for (row = first_row; row <= last_row; row++) {
2192 state_tokens[2] = state_tokens[3] = row;
2194 idx = add_state_reference(prog->Parameters, state_tokens);
2195 if (param_var->param_binding_begin == ~0U)
2196 param_var->param_binding_begin = idx;
2197 param_var->param_binding_length++;
2201 idx = add_state_reference(prog->Parameters, state_tokens);
2202 if (param_var->param_binding_begin == ~0U)
2203 param_var->param_binding_begin = idx;
2204 param_var->param_binding_length++;
2212 initialize_symbol_from_const(struct gl_program *prog,
2213 struct asm_symbol *param_var,
2214 const struct asm_vector *vec)
2216 const int idx = _mesa_add_parameter(prog->Parameters, PROGRAM_CONSTANT,
2217 NULL, vec->count, GL_NONE, vec->data,
2220 param_var->type = at_param;
2221 param_var->param_binding_type = PROGRAM_CONSTANT;
2223 if (param_var->param_binding_begin == ~0U)
2224 param_var->param_binding_begin = idx;
2225 param_var->param_binding_length++;
2232 make_error_string(const char *fmt, ...)
2238 va_start(args, fmt);
2240 /* Call vsnprintf once to determine how large the final string is. Call it
2241 * again to do the actual formatting. from the vsnprintf manual page:
2243 * Upon successful return, these functions return the number of
2244 * characters printed (not including the trailing '\0' used to end
2245 * output to strings).
2247 length = 1 + vsnprintf(NULL, 0, fmt, args);
2249 str = _mesa_malloc(length);
2251 vsnprintf(str, length, fmt, args);
2261 yyerror(YYLTYPE *locp, struct asm_parser_state *state, const char *s)
2266 err_str = make_error_string("glProgramStringARB(%s)\n", s);
2268 _mesa_error(state->ctx, GL_INVALID_OPERATION, err_str);
2269 _mesa_free(err_str);
2272 err_str = make_error_string("line %u, char %u: error: %s\n",
2273 locp->first_line, locp->first_column, s);
2274 _mesa_set_program_error(state->ctx, locp->position, err_str);
2277 _mesa_free(err_str);
2283 _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
2284 GLsizei len, struct asm_parser_state *state)
2286 struct asm_instruction *inst;
2289 GLboolean result = GL_FALSE;
2291 struct asm_symbol *sym;
2294 state->prog->Target = target;
2295 state->prog->Parameters = _mesa_new_parameter_list();
2297 /* Make a copy of the program string and force it to be NUL-terminated.
2299 strz = (GLubyte *) _mesa_malloc(len + 1);
2301 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramStringARB");
2304 _mesa_memcpy (strz, str, len);
2307 state->prog->String = strz;
2309 state->st = _mesa_symbol_table_ctor();
2311 state->limits = (target == GL_VERTEX_PROGRAM_ARB)
2312 ? & ctx->Const.VertexProgram
2313 : & ctx->Const.FragmentProgram;
2315 state->MaxTextureImageUnits = ctx->Const.MaxTextureImageUnits;
2316 state->MaxTextureCoordUnits = ctx->Const.MaxTextureCoordUnits;
2317 state->MaxTextureUnits = ctx->Const.MaxTextureUnits;
2318 state->MaxClipPlanes = ctx->Const.MaxClipPlanes;
2319 state->MaxLights = ctx->Const.MaxLights;
2320 state->MaxProgramMatrices = ctx->Const.MaxProgramMatrices;
2322 state->state_param_enum = (target == GL_VERTEX_PROGRAM_ARB)
2323 ? STATE_VERTEX_PROGRAM : STATE_FRAGMENT_PROGRAM;
2325 _mesa_set_program_error(ctx, -1, NULL);
2327 _mesa_program_lexer_ctor(& state->scanner, state, (const char *) str, len);
2329 _mesa_program_lexer_dtor(state->scanner);
2332 if (ctx->Program.ErrorPos != -1) {
2336 if (! _mesa_layout_parameters(state)) {
2340 loc.first_column = 0;
2343 yyerror(& loc, state, "invalid PARAM usage");
2349 /* Add one instruction to store the "END" instruction.
2351 state->prog->Instructions =
2352 _mesa_alloc_instructions(state->prog->NumInstructions + 1);
2353 inst = state->inst_head;
2354 for (i = 0; i < state->prog->NumInstructions; i++) {
2355 struct asm_instruction *const temp = inst->next;
2357 state->prog->Instructions[i] = inst->Base;
2361 /* Finally, tag on an OPCODE_END instruction */
2363 const GLuint numInst = state->prog->NumInstructions;
2364 _mesa_init_instructions(state->prog->Instructions + numInst, 1);
2365 state->prog->Instructions[numInst].Opcode = OPCODE_END;
2367 state->prog->NumInstructions++;
2369 state->prog->NumParameters = state->prog->Parameters->NumParameters;
2370 state->prog->NumAttributes = _mesa_bitcount(state->prog->InputsRead);
2373 * Initialize native counts to logical counts. The device driver may
2374 * change them if program is translated into a hardware program.
2376 state->prog->NumNativeInstructions = state->prog->NumInstructions;
2377 state->prog->NumNativeTemporaries = state->prog->NumTemporaries;
2378 state->prog->NumNativeParameters = state->prog->NumParameters;
2379 state->prog->NumNativeAttributes = state->prog->NumAttributes;
2380 state->prog->NumNativeAddressRegs = state->prog->NumAddressRegs;
2385 for (inst = state->inst_head; inst != NULL; inst = temp) {
2390 state->inst_head = NULL;
2391 state->inst_tail = NULL;
2393 for (sym = state->sym; sym != NULL; sym = temp) {
2396 _mesa_free((void *) sym->name);
2401 _mesa_symbol_table_dtor(state->st);