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 TEX_ARRAY1D TEX_ARRAY2D TEX_ARRAYSHADOW1D TEX_ARRAYSHADOW2D
162 %token VERTEX VTXATTRIB
165 %token <string> IDENTIFIER
166 %token <swiz_mask> MASK4 MASK3 MASK2 MASK1 SWIZZLE
170 %type <inst> instruction ALU_instruction TexInstruction
171 %type <inst> ARL_instruction VECTORop_instruction
172 %type <inst> SCALARop_instruction BINSCop_instruction BINop_instruction
173 %type <inst> TRIop_instruction SWZ_instruction SAMPLE_instruction
174 %type <inst> KIL_instruction
176 %type <dst_reg> dstReg maskedDstReg maskedAddrReg
177 %type <src_reg> srcReg scalarSrcReg swizzleSrcReg
178 %type <swiz_mask> scalarSuffix swizzleSuffix extendedSwizzle extSwizComp
179 %type <swiz_mask> optionalMask
180 %type <integer> extSwizSel
182 %type <sym> progParamArray
183 %type <integer> addrRegRelOffset addrRegPosOffset addrRegNegOffset
184 %type <src_reg> progParamArrayMem progParamArrayAbs progParamArrayRel
186 %type <swiz_mask> addrComponent addrWriteMask
188 %type <result> resultBinding resultColBinding
189 %type <integer> optFaceType optColorType
190 %type <integer> optResultFaceType optResultColorType
192 %type <integer> optTexImageUnitNum texImageUnitNum
193 %type <integer> optTexCoordUnitNum texCoordUnitNum
194 %type <integer> optLegacyTexUnitNum legacyTexUnitNum
195 %type <integer> texImageUnit texTarget
196 %type <integer> vtxAttribNum
198 %type <attrib> attribBinding vtxAttribItem fragAttribItem
200 %type <temp_sym> paramSingleInit paramSingleItemDecl
201 %type <integer> optArraySize
203 %type <state> stateSingleItem stateMultipleItem
204 %type <state> stateMaterialItem
205 %type <state> stateLightItem stateLightModelItem stateLightProdItem
206 %type <state> stateTexGenItem stateFogItem stateClipPlaneItem statePointItem
207 %type <state> stateMatrixItem stateMatrixRow stateMatrixRows
208 %type <state> stateTexEnvItem stateDepthItem
210 %type <state> stateLModProperty
211 %type <state> stateMatrixName optMatrixRows
213 %type <integer> stateMatProperty
214 %type <integer> stateLightProperty stateSpotProperty
215 %type <integer> stateLightNumber stateLProdProperty
216 %type <integer> stateTexGenType stateTexGenCoord
217 %type <integer> stateTexEnvProperty
218 %type <integer> stateFogProperty
219 %type <integer> stateClipPlaneNum
220 %type <integer> statePointProperty
222 %type <integer> stateOptMatModifier stateMatModifier stateMatrixRowNum
223 %type <integer> stateOptModMatNum stateModMatNum statePaletteMatNum
224 %type <integer> stateProgramMatNum
226 %type <integer> ambDiffSpecProperty
228 %type <state> programSingleItem progEnvParam progLocalParam
229 %type <state> programMultipleItem progEnvParams progLocalParams
231 %type <temp_sym> paramMultipleInit paramMultInitList paramMultipleItem
232 %type <temp_sym> paramSingleItemUse
234 %type <integer> progEnvParamNum progLocalParamNum
235 %type <state> progEnvParamNums progLocalParamNums
237 %type <vector> paramConstDecl paramConstUse
238 %type <vector> paramConstScalarDecl paramConstScalarUse paramConstVector
239 %type <real> signedFloatConstant
240 %type <negate> optionalSign
243 extern int yylex(YYSTYPE *yylval_param, YYLTYPE *yylloc_param,
249 program: language optionSequence statementSequence END
254 if (state->prog->Target != GL_VERTEX_PROGRAM_ARB) {
255 yyerror(& @1, state, "invalid fragment program header");
258 state->mode = ARB_vertex;
262 if (state->prog->Target != GL_FRAGMENT_PROGRAM_ARB) {
263 yyerror(& @1, state, "invalid vertex program header");
265 state->mode = ARB_fragment;
267 state->option.TexRect =
268 (state->ctx->Extensions.NV_texture_rectangle != GL_FALSE);
272 optionSequence: optionSequence option
276 option: OPTION IDENTIFIER ';'
280 if (state->mode == ARB_vertex) {
281 valid = _mesa_ARBvp_parse_option(state, $2);
282 } else if (state->mode == ARB_fragment) {
283 valid = _mesa_ARBfp_parse_option(state, $2);
288 const char *const err_str = (state->mode == ARB_vertex)
289 ? "invalid ARB vertex program option"
290 : "invalid ARB fragment program option";
292 yyerror(& @2, state, err_str);
298 statementSequence: statementSequence statement
302 statement: instruction ';'
305 if (state->inst_tail == NULL) {
306 state->inst_head = $1;
308 state->inst_tail->next = $1;
311 state->inst_tail = $1;
314 state->prog->NumInstructions++;
317 | namingStatement ';'
320 instruction: ALU_instruction
323 state->prog->NumAluInstructions++;
328 state->prog->NumTexInstructions++;
332 ALU_instruction: ARL_instruction
333 | VECTORop_instruction
334 | SCALARop_instruction
335 | BINSCop_instruction
341 TexInstruction: SAMPLE_instruction
345 ARL_instruction: ARL maskedAddrReg ',' scalarSrcReg
347 $$ = asm_instruction_ctor(OPCODE_ARL, & $2, & $4, NULL, NULL);
351 VECTORop_instruction: VECTOR_OP maskedDstReg ',' swizzleSrcReg
353 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL);
354 $$->Base.SaturateMode = $1.SaturateMode;
358 SCALARop_instruction: SCALAR_OP maskedDstReg ',' scalarSrcReg
360 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL);
361 $$->Base.SaturateMode = $1.SaturateMode;
365 BINSCop_instruction: BINSC_OP maskedDstReg ',' scalarSrcReg ',' scalarSrcReg
367 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, NULL);
368 $$->Base.SaturateMode = $1.SaturateMode;
373 BINop_instruction: BIN_OP maskedDstReg ',' swizzleSrcReg ',' swizzleSrcReg
375 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, NULL);
376 $$->Base.SaturateMode = $1.SaturateMode;
380 TRIop_instruction: TRI_OP maskedDstReg ','
381 swizzleSrcReg ',' swizzleSrcReg ',' swizzleSrcReg
383 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, & $8);
384 $$->Base.SaturateMode = $1.SaturateMode;
388 SAMPLE_instruction: SAMPLE_OP maskedDstReg ',' swizzleSrcReg ',' texImageUnit ',' texTarget
390 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL);
392 const GLbitfield tex_mask = (1U << $6);
393 GLbitfield shadow_tex = 0;
394 GLbitfield target_mask = 0;
397 $$->Base.SaturateMode = $1.SaturateMode;
398 $$->Base.TexSrcUnit = $6;
401 shadow_tex = tex_mask;
403 $$->Base.TexSrcTarget = -$8;
404 $$->Base.TexShadow = 1;
406 $$->Base.TexSrcTarget = $8;
409 target_mask = (1U << $$->Base.TexSrcTarget);
411 /* If this texture unit was previously accessed and that access
412 * had a different texture target, generate an error.
414 * If this texture unit was previously accessed and that access
415 * had a different shadow mode, generate an error.
417 if ((state->prog->TexturesUsed[$6] != 0)
418 && ((state->prog->TexturesUsed[$6] != target_mask)
419 || ((state->prog->ShadowSamplers & tex_mask)
422 "multiple targets used on one texture image unit");
427 state->prog->TexturesUsed[$6] |= target_mask;
428 state->prog->ShadowSamplers |= shadow_tex;
433 KIL_instruction: KIL swizzleSrcReg
435 $$ = asm_instruction_ctor(OPCODE_KIL, NULL, & $2, NULL, NULL);
436 state->fragment.UsesKill = 1;
440 texImageUnit: TEXTURE_UNIT optTexImageUnitNum
446 texTarget: TEX_1D { $$ = TEXTURE_1D_INDEX; }
447 | TEX_2D { $$ = TEXTURE_2D_INDEX; }
448 | TEX_3D { $$ = TEXTURE_3D_INDEX; }
449 | TEX_CUBE { $$ = TEXTURE_CUBE_INDEX; }
450 | TEX_RECT { $$ = TEXTURE_RECT_INDEX; }
451 | TEX_SHADOW1D { $$ = -TEXTURE_1D_INDEX; }
452 | TEX_SHADOW2D { $$ = -TEXTURE_2D_INDEX; }
453 | TEX_SHADOWRECT { $$ = -TEXTURE_RECT_INDEX; }
454 | TEX_ARRAY1D { $$ = TEXTURE_1D_ARRAY_INDEX; }
455 | TEX_ARRAY2D { $$ = TEXTURE_2D_ARRAY_INDEX; }
456 | TEX_ARRAYSHADOW1D { $$ = -TEXTURE_1D_ARRAY_INDEX; }
457 | TEX_ARRAYSHADOW2D { $$ = -TEXTURE_2D_ARRAY_INDEX; }
460 SWZ_instruction: SWZ maskedDstReg ',' srcReg ',' extendedSwizzle
462 /* FIXME: Is this correct? Should the extenedSwizzle be applied
463 * FIXME: to the existing swizzle?
465 $4.Base.Swizzle = $6.swizzle;
466 $4.Base.Negate = $6.mask;
468 $$ = asm_instruction_ctor(OPCODE_SWZ, & $2, & $4, NULL, NULL);
469 $$->Base.SaturateMode = $1.SaturateMode;
473 scalarSrcReg: optionalSign srcReg scalarSuffix
478 $$.Base.Negate = ~$$.Base.Negate;
481 $$.Base.Swizzle = _mesa_combine_swizzles($$.Base.Swizzle,
486 swizzleSrcReg: optionalSign srcReg swizzleSuffix
491 $$.Base.Negate = ~$$.Base.Negate;
494 $$.Base.Swizzle = _mesa_combine_swizzles($$.Base.Swizzle,
499 maskedDstReg: dstReg optionalMask
502 $$.WriteMask = $2.mask;
504 if ($$.File == PROGRAM_OUTPUT) {
505 /* Technically speaking, this should check that it is in
506 * vertex program mode. However, PositionInvariant can never be
507 * set in fragment program mode, so it is somewhat irrelevant.
509 if (state->option.PositionInvariant
510 && ($$.Index == VERT_RESULT_HPOS)) {
511 yyerror(& @1, state, "position-invariant programs cannot "
516 state->prog->OutputsWritten |= (1U << $$.Index);
521 maskedAddrReg: addrReg addrWriteMask
524 $$.File = PROGRAM_ADDRESS;
526 $$.WriteMask = $2.mask;
530 extendedSwizzle: extSwizComp ',' extSwizComp ',' extSwizComp ',' extSwizComp
532 $$.swizzle = MAKE_SWIZZLE4($1.swizzle, $3.swizzle,
533 $5.swizzle, $7.swizzle);
534 $$.mask = ($1.mask) | ($3.mask << 1) | ($5.mask << 2)
539 extSwizComp: optionalSign extSwizSel
542 $$.mask = ($1) ? 1 : 0;
548 if (($1 != 0) && ($1 != 1)) {
549 yyerror(& @1, state, "invalid extended swizzle selector");
553 $$ = ($1 == 0) ? SWIZZLE_ZERO : SWIZZLE_ONE;
557 if (strlen($1) > 1) {
558 yyerror(& @1, state, "invalid extended swizzle selector");
576 yyerror(& @1, state, "invalid extended swizzle selector");
583 srcReg: IDENTIFIER /* temporaryReg | progParamSingle */
585 struct asm_symbol *const s = (struct asm_symbol *)
586 _mesa_symbol_table_find_symbol(state->st, 0, $1);
589 yyerror(& @1, state, "invalid operand variable");
591 } else if ((s->type != at_param) && (s->type != at_temp)
592 && (s->type != at_attrib)) {
593 yyerror(& @1, state, "invalid operand variable");
595 } else if ((s->type == at_param) && s->param_is_array) {
596 yyerror(& @1, state, "non-array access to array PARAM");
603 $$.Base.File = PROGRAM_TEMPORARY;
604 $$.Base.Index = s->temp_binding;
607 $$.Base.File = s->param_binding_type;
608 $$.Base.Index = s->param_binding_begin;
611 $$.Base.File = PROGRAM_INPUT;
612 $$.Base.Index = s->attrib_binding;
613 state->prog->InputsRead |= (1U << $$.Base.Index);
615 if (!validate_inputs(& @1, state)) {
628 $$.Base.File = PROGRAM_INPUT;
630 state->prog->InputsRead |= (1U << $$.Base.Index);
632 if (!validate_inputs(& @1, state)) {
636 | progParamArray '[' progParamArrayMem ']'
638 if (! $3.Base.RelAddr
639 && ((unsigned) $3.Base.Index >= $1->param_binding_length)) {
640 yyerror(& @3, state, "out of bounds array access");
645 $$.Base.File = $1->param_binding_type;
647 if ($3.Base.RelAddr) {
648 $1->param_accessed_indirectly = 1;
651 $$.Base.Index = $3.Base.Index;
654 $$.Base.Index = $1->param_binding_begin + $3.Base.Index;
660 $$.Base.File = ($1.name != NULL)
661 ? $1.param_binding_type
663 $$.Base.Index = $1.param_binding_begin;
667 dstReg: resultBinding
670 $$.File = PROGRAM_OUTPUT;
673 | IDENTIFIER /* temporaryReg | vertexResultReg */
675 struct asm_symbol *const s = (struct asm_symbol *)
676 _mesa_symbol_table_find_symbol(state->st, 0, $1);
679 yyerror(& @1, state, "invalid operand variable");
681 } else if ((s->type != at_output) && (s->type != at_temp)) {
682 yyerror(& @1, state, "invalid operand variable");
689 $$.File = PROGRAM_TEMPORARY;
690 $$.Index = s->temp_binding;
693 $$.File = PROGRAM_OUTPUT;
694 $$.Index = s->output_binding;
697 $$.File = s->param_binding_type;
698 $$.Index = s->param_binding_begin;
704 progParamArray: IDENTIFIER
706 struct asm_symbol *const s = (struct asm_symbol *)
707 _mesa_symbol_table_find_symbol(state->st, 0, $1);
710 yyerror(& @1, state, "invalid operand variable");
712 } else if ((s->type != at_param) || !s->param_is_array) {
713 yyerror(& @1, state, "array access to non-PARAM variable");
721 progParamArrayMem: progParamArrayAbs | progParamArrayRel;
723 progParamArrayAbs: INTEGER
730 progParamArrayRel: addrReg addrComponent addrRegRelOffset
732 /* FINISHME: Add support for multiple address registers.
734 /* FINISHME: Add support for 4-component address registers.
742 addrRegRelOffset: { $$ = 0; }
743 | '+' addrRegPosOffset { $$ = $2; }
744 | '-' addrRegNegOffset { $$ = -$2; }
747 addrRegPosOffset: INTEGER
749 if (($1 < 0) || ($1 > 63)) {
751 "relative address offset too large (positive)");
759 addrRegNegOffset: INTEGER
761 if (($1 < 0) || ($1 > 64)) {
763 "relative address offset too large (negative)");
773 struct asm_symbol *const s = (struct asm_symbol *)
774 _mesa_symbol_table_find_symbol(state->st, 0, $1);
777 yyerror(& @1, state, "invalid array member");
779 } else if (s->type != at_address) {
781 "invalid variable for indexed array access");
791 if ($1.mask != WRITEMASK_X) {
792 yyerror(& @1, state, "invalid address component selector");
802 if ($1.mask != WRITEMASK_X) {
804 "address register write mask must be \".x\"");
817 | { $$.swizzle = SWIZZLE_NOOP; $$.mask = WRITEMASK_XYZW; }
820 optionalMask: MASK4 | MASK3 | MASK2 | MASK1
821 | { $$.swizzle = SWIZZLE_NOOP; $$.mask = WRITEMASK_XYZW; }
824 namingStatement: ATTRIB_statement
832 ATTRIB_statement: ATTRIB IDENTIFIER '=' attribBinding
834 struct asm_symbol *const s =
835 declare_variable(state, $2, at_attrib, & @2);
840 s->attrib_binding = $4;
841 state->InputsBound |= (1U << s->attrib_binding);
843 if (!validate_inputs(& @4, state)) {
850 attribBinding: VERTEX vtxAttribItem
854 | FRAGMENT fragAttribItem
860 vtxAttribItem: POSITION
862 $$ = VERT_ATTRIB_POS;
864 | WEIGHT vtxOptWeightNum
866 $$ = VERT_ATTRIB_WEIGHT;
870 $$ = VERT_ATTRIB_NORMAL;
874 if (!state->ctx->Extensions.EXT_secondary_color) {
875 yyerror(& @2, state, "GL_EXT_secondary_color not supported");
879 $$ = VERT_ATTRIB_COLOR0 + $2;
883 if (!state->ctx->Extensions.EXT_fog_coord) {
884 yyerror(& @1, state, "GL_EXT_fog_coord not supported");
888 $$ = VERT_ATTRIB_FOG;
890 | TEXCOORD optTexCoordUnitNum
892 $$ = VERT_ATTRIB_TEX0 + $2;
894 | MATRIXINDEX '[' vtxWeightNum ']'
896 yyerror(& @1, state, "GL_ARB_matrix_palette not supported");
899 | VTXATTRIB '[' vtxAttribNum ']'
901 $$ = VERT_ATTRIB_GENERIC0 + $3;
905 vtxAttribNum: INTEGER
907 if ((unsigned) $1 >= state->limits->MaxAttribs) {
908 yyerror(& @1, state, "invalid vertex attribute reference");
916 vtxOptWeightNum: | '[' vtxWeightNum ']';
917 vtxWeightNum: INTEGER;
919 fragAttribItem: POSITION
921 $$ = FRAG_ATTRIB_WPOS;
925 $$ = FRAG_ATTRIB_COL0 + $2;
929 $$ = FRAG_ATTRIB_FOGC;
931 | TEXCOORD optTexCoordUnitNum
933 $$ = FRAG_ATTRIB_TEX0 + $2;
937 PARAM_statement: PARAM_singleStmt | PARAM_multipleStmt;
939 PARAM_singleStmt: PARAM IDENTIFIER paramSingleInit
941 struct asm_symbol *const s =
942 declare_variable(state, $2, at_param, & @2);
947 s->param_binding_type = $3.param_binding_type;
948 s->param_binding_begin = $3.param_binding_begin;
949 s->param_binding_length = $3.param_binding_length;
950 s->param_is_array = 0;
955 PARAM_multipleStmt: PARAM IDENTIFIER '[' optArraySize ']' paramMultipleInit
957 if (($4 != 0) && ((unsigned) $4 != $6.param_binding_length)) {
959 "parameter array size and number of bindings must match");
962 struct asm_symbol *const s =
963 declare_variable(state, $2, $6.type, & @2);
968 s->param_binding_type = $6.param_binding_type;
969 s->param_binding_begin = $6.param_binding_begin;
970 s->param_binding_length = $6.param_binding_length;
971 s->param_is_array = 1;
983 if (($1 < 1) || ((unsigned) $1 >= state->limits->MaxParameters)) {
984 yyerror(& @1, state, "invalid parameter array size");
992 paramSingleInit: '=' paramSingleItemDecl
998 paramMultipleInit: '=' '{' paramMultInitList '}'
1004 paramMultInitList: paramMultipleItem
1005 | paramMultInitList ',' paramMultipleItem
1007 $1.param_binding_length += $3.param_binding_length;
1012 paramSingleItemDecl: stateSingleItem
1014 memset(& $$, 0, sizeof($$));
1015 $$.param_binding_begin = ~0;
1016 initialize_symbol_from_state(state->prog, & $$, $1);
1020 memset(& $$, 0, sizeof($$));
1021 $$.param_binding_begin = ~0;
1022 initialize_symbol_from_param(state->prog, & $$, $1);
1026 memset(& $$, 0, sizeof($$));
1027 $$.param_binding_begin = ~0;
1028 initialize_symbol_from_const(state->prog, & $$, & $1);
1032 paramSingleItemUse: stateSingleItem
1034 memset(& $$, 0, sizeof($$));
1035 $$.param_binding_begin = ~0;
1036 initialize_symbol_from_state(state->prog, & $$, $1);
1040 memset(& $$, 0, sizeof($$));
1041 $$.param_binding_begin = ~0;
1042 initialize_symbol_from_param(state->prog, & $$, $1);
1046 memset(& $$, 0, sizeof($$));
1047 $$.param_binding_begin = ~0;
1048 initialize_symbol_from_const(state->prog, & $$, & $1);
1052 paramMultipleItem: stateMultipleItem
1054 memset(& $$, 0, sizeof($$));
1055 $$.param_binding_begin = ~0;
1056 initialize_symbol_from_state(state->prog, & $$, $1);
1058 | programMultipleItem
1060 memset(& $$, 0, sizeof($$));
1061 $$.param_binding_begin = ~0;
1062 initialize_symbol_from_param(state->prog, & $$, $1);
1066 memset(& $$, 0, sizeof($$));
1067 $$.param_binding_begin = ~0;
1068 initialize_symbol_from_const(state->prog, & $$, & $1);
1072 stateMultipleItem: stateSingleItem { memcpy($$, $1, sizeof($$)); }
1073 | STATE stateMatrixRows { memcpy($$, $2, sizeof($$)); }
1076 stateSingleItem: STATE stateMaterialItem { memcpy($$, $2, sizeof($$)); }
1077 | STATE stateLightItem { memcpy($$, $2, sizeof($$)); }
1078 | STATE stateLightModelItem { memcpy($$, $2, sizeof($$)); }
1079 | STATE stateLightProdItem { memcpy($$, $2, sizeof($$)); }
1080 | STATE stateTexGenItem { memcpy($$, $2, sizeof($$)); }
1081 | STATE stateTexEnvItem { memcpy($$, $2, sizeof($$)); }
1082 | STATE stateFogItem { memcpy($$, $2, sizeof($$)); }
1083 | STATE stateClipPlaneItem { memcpy($$, $2, sizeof($$)); }
1084 | STATE statePointItem { memcpy($$, $2, sizeof($$)); }
1085 | STATE stateMatrixRow { memcpy($$, $2, sizeof($$)); }
1086 | STATE stateDepthItem { memcpy($$, $2, sizeof($$)); }
1089 stateMaterialItem: MATERIAL optFaceType stateMatProperty
1091 memset($$, 0, sizeof($$));
1092 $$[0] = STATE_MATERIAL;
1098 stateMatProperty: ambDiffSpecProperty
1104 $$ = STATE_EMISSION;
1108 $$ = STATE_SHININESS;
1112 stateLightItem: LIGHT '[' stateLightNumber ']' stateLightProperty
1114 memset($$, 0, sizeof($$));
1115 $$[0] = STATE_LIGHT;
1121 stateLightProperty: ambDiffSpecProperty
1127 $$ = STATE_POSITION;
1131 if (!state->ctx->Extensions.EXT_point_parameters) {
1132 yyerror(& @1, state, "GL_ARB_point_parameters not supported");
1136 $$ = STATE_ATTENUATION;
1138 | SPOT stateSpotProperty
1144 $$ = STATE_HALF_VECTOR;
1148 stateSpotProperty: DIRECTION
1150 $$ = STATE_SPOT_DIRECTION;
1154 stateLightModelItem: LIGHTMODEL stateLModProperty
1161 stateLModProperty: AMBIENT
1163 memset($$, 0, sizeof($$));
1164 $$[0] = STATE_LIGHTMODEL_AMBIENT;
1166 | optFaceType SCENECOLOR
1168 memset($$, 0, sizeof($$));
1169 $$[0] = STATE_LIGHTMODEL_SCENECOLOR;
1174 stateLightProdItem: LIGHTPROD '[' stateLightNumber ']' optFaceType stateLProdProperty
1176 memset($$, 0, sizeof($$));
1177 $$[0] = STATE_LIGHTPROD;
1184 stateLProdProperty: ambDiffSpecProperty;
1186 stateTexEnvItem: TEXENV optLegacyTexUnitNum stateTexEnvProperty
1188 memset($$, 0, sizeof($$));
1194 stateTexEnvProperty: COLOR
1196 $$ = STATE_TEXENV_COLOR;
1200 ambDiffSpecProperty: AMBIENT
1210 $$ = STATE_SPECULAR;
1214 stateLightNumber: INTEGER
1216 if ((unsigned) $1 >= state->MaxLights) {
1217 yyerror(& @1, state, "invalid light selector");
1225 stateTexGenItem: TEXGEN optTexCoordUnitNum stateTexGenType stateTexGenCoord
1227 memset($$, 0, sizeof($$));
1228 $$[0] = STATE_TEXGEN;
1234 stateTexGenType: EYE
1236 $$ = STATE_TEXGEN_EYE_S;
1240 $$ = STATE_TEXGEN_OBJECT_S;
1243 stateTexGenCoord: TEXGEN_S
1245 $$ = STATE_TEXGEN_EYE_S - STATE_TEXGEN_EYE_S;
1249 $$ = STATE_TEXGEN_EYE_T - STATE_TEXGEN_EYE_S;
1253 $$ = STATE_TEXGEN_EYE_R - STATE_TEXGEN_EYE_S;
1257 $$ = STATE_TEXGEN_EYE_Q - STATE_TEXGEN_EYE_S;
1261 stateFogItem: FOG stateFogProperty
1263 memset($$, 0, sizeof($$));
1268 stateFogProperty: COLOR
1270 $$ = STATE_FOG_COLOR;
1274 $$ = STATE_FOG_PARAMS;
1278 stateClipPlaneItem: CLIP '[' stateClipPlaneNum ']' PLANE
1280 memset($$, 0, sizeof($$));
1281 $$[0] = STATE_CLIPPLANE;
1286 stateClipPlaneNum: INTEGER
1288 if ((unsigned) $1 >= state->MaxClipPlanes) {
1289 yyerror(& @1, state, "invalid clip plane selector");
1297 statePointItem: POINT statePointProperty
1299 memset($$, 0, sizeof($$));
1304 statePointProperty: SIZE
1306 $$ = STATE_POINT_SIZE;
1310 $$ = STATE_POINT_ATTENUATION;
1314 stateMatrixRow: stateMatrixItem ROW '[' stateMatrixRowNum ']'
1324 stateMatrixRows: stateMatrixItem optMatrixRows
1339 | ROW '[' stateMatrixRowNum DOT_DOT stateMatrixRowNum ']'
1341 /* It seems logical that the matrix row range specifier would have
1342 * to specify a range or more than one row (i.e., $5 > $3).
1343 * However, the ARB_vertex_program spec says "a program will fail
1344 * to load if <a> is greater than <b>." This means that $3 == $5
1348 yyerror(& @3, state, "invalid matrix row range");
1357 stateMatrixItem: MATRIX stateMatrixName stateOptMatModifier
1365 stateOptMatModifier:
1375 stateMatModifier: INVERSE
1377 $$ = STATE_MATRIX_INVERSE;
1381 $$ = STATE_MATRIX_TRANSPOSE;
1385 $$ = STATE_MATRIX_INVTRANS;
1389 stateMatrixRowNum: INTEGER
1392 yyerror(& @1, state, "invalid matrix row reference");
1400 stateMatrixName: MODELVIEW stateOptModMatNum
1402 $$[0] = STATE_MODELVIEW_MATRIX;
1407 $$[0] = STATE_PROJECTION_MATRIX;
1412 $$[0] = STATE_MVP_MATRIX;
1415 | TEXTURE optTexCoordUnitNum
1417 $$[0] = STATE_TEXTURE_MATRIX;
1420 | PALETTE '[' statePaletteMatNum ']'
1422 yyerror(& @1, state, "GL_ARB_matrix_palette not supported");
1425 | MAT_PROGRAM '[' stateProgramMatNum ']'
1427 $$[0] = STATE_PROGRAM_MATRIX;
1441 stateModMatNum: INTEGER
1443 /* Since GL_ARB_vertex_blend isn't supported, only modelview matrix
1447 yyerror(& @1, state, "invalid modelview matrix index");
1454 statePaletteMatNum: INTEGER
1456 /* Since GL_ARB_matrix_palette isn't supported, just let any value
1457 * through here. The error will be generated later.
1462 stateProgramMatNum: INTEGER
1464 if ((unsigned) $1 >= state->MaxProgramMatrices) {
1465 yyerror(& @1, state, "invalid program matrix selector");
1473 stateDepthItem: DEPTH RANGE
1475 memset($$, 0, sizeof($$));
1476 $$[0] = STATE_DEPTH_RANGE;
1481 programSingleItem: progEnvParam | progLocalParam;
1483 programMultipleItem: progEnvParams | progLocalParams;
1485 progEnvParams: PROGRAM ENV '[' progEnvParamNums ']'
1487 memset($$, 0, sizeof($$));
1488 $$[0] = state->state_param_enum;
1495 progEnvParamNums: progEnvParamNum
1500 | progEnvParamNum DOT_DOT progEnvParamNum
1507 progEnvParam: PROGRAM ENV '[' progEnvParamNum ']'
1509 memset($$, 0, sizeof($$));
1510 $$[0] = state->state_param_enum;
1517 progLocalParams: PROGRAM LOCAL '[' progLocalParamNums ']'
1519 memset($$, 0, sizeof($$));
1520 $$[0] = state->state_param_enum;
1521 $$[1] = STATE_LOCAL;
1526 progLocalParamNums: progLocalParamNum
1531 | progLocalParamNum DOT_DOT progLocalParamNum
1538 progLocalParam: PROGRAM LOCAL '[' progLocalParamNum ']'
1540 memset($$, 0, sizeof($$));
1541 $$[0] = state->state_param_enum;
1542 $$[1] = STATE_LOCAL;
1548 progEnvParamNum: INTEGER
1550 if ((unsigned) $1 >= state->limits->MaxEnvParams) {
1551 yyerror(& @1, state, "invalid environment parameter reference");
1558 progLocalParamNum: INTEGER
1560 if ((unsigned) $1 >= state->limits->MaxLocalParams) {
1561 yyerror(& @1, state, "invalid local parameter reference");
1570 paramConstDecl: paramConstScalarDecl | paramConstVector;
1571 paramConstUse: paramConstScalarUse | paramConstVector;
1573 paramConstScalarDecl: signedFloatConstant
1583 paramConstScalarUse: REAL
1594 $$.data[0] = (float) $1;
1601 paramConstVector: '{' signedFloatConstant '}'
1609 | '{' signedFloatConstant ',' signedFloatConstant '}'
1617 | '{' signedFloatConstant ',' signedFloatConstant ','
1618 signedFloatConstant '}'
1626 | '{' signedFloatConstant ',' signedFloatConstant ','
1627 signedFloatConstant ',' signedFloatConstant '}'
1637 signedFloatConstant: optionalSign REAL
1639 $$ = ($1) ? -$2 : $2;
1641 | optionalSign INTEGER
1643 $$ = (float)(($1) ? -$2 : $2);
1647 optionalSign: '+' { $$ = FALSE; }
1648 | '-' { $$ = TRUE; }
1652 TEMP_statement: TEMP { $<integer>$ = $1; } varNameList
1655 ADDRESS_statement: ADDRESS { $<integer>$ = $1; } varNameList
1658 varNameList: varNameList ',' IDENTIFIER
1660 if (!declare_variable(state, $3, $<integer>0, & @3)) {
1666 if (!declare_variable(state, $1, $<integer>0, & @1)) {
1672 OUTPUT_statement: OUTPUT IDENTIFIER '=' resultBinding
1674 struct asm_symbol *const s =
1675 declare_variable(state, $2, at_output, & @2);
1680 s->output_binding = $4;
1685 resultBinding: RESULT POSITION
1687 if (state->mode == ARB_vertex) {
1688 $$ = VERT_RESULT_HPOS;
1690 yyerror(& @2, state, "invalid program result name");
1696 if (state->mode == ARB_vertex) {
1697 $$ = VERT_RESULT_FOGC;
1699 yyerror(& @2, state, "invalid program result name");
1703 | RESULT resultColBinding
1709 if (state->mode == ARB_vertex) {
1710 $$ = VERT_RESULT_PSIZ;
1712 yyerror(& @2, state, "invalid program result name");
1716 | RESULT TEXCOORD optTexCoordUnitNum
1718 if (state->mode == ARB_vertex) {
1719 $$ = VERT_RESULT_TEX0 + $3;
1721 yyerror(& @2, state, "invalid program result name");
1727 if (state->mode == ARB_fragment) {
1728 $$ = FRAG_RESULT_DEPTH;
1730 yyerror(& @2, state, "invalid program result name");
1736 resultColBinding: COLOR optResultFaceType optResultColorType
1744 $$ = (state->mode == ARB_vertex)
1746 : FRAG_RESULT_COLOR;
1750 if (state->mode == ARB_vertex) {
1751 $$ = VERT_RESULT_COL0;
1753 yyerror(& @1, state, "invalid program result name");
1759 if (state->mode == ARB_vertex) {
1760 $$ = VERT_RESULT_BFC0;
1762 yyerror(& @1, state, "invalid program result name");
1774 if (state->mode == ARB_vertex) {
1777 yyerror(& @1, state, "invalid program result name");
1783 if (state->mode == ARB_vertex) {
1786 yyerror(& @1, state, "invalid program result name");
1792 optFaceType: { $$ = 0; }
1797 optColorType: { $$ = 0; }
1798 | PRIMARY { $$ = 0; }
1799 | SECONDARY { $$ = 1; }
1802 optTexCoordUnitNum: { $$ = 0; }
1803 | '[' texCoordUnitNum ']' { $$ = $2; }
1806 optTexImageUnitNum: { $$ = 0; }
1807 | '[' texImageUnitNum ']' { $$ = $2; }
1810 optLegacyTexUnitNum: { $$ = 0; }
1811 | '[' legacyTexUnitNum ']' { $$ = $2; }
1814 texCoordUnitNum: INTEGER
1816 if ((unsigned) $1 >= state->MaxTextureCoordUnits) {
1817 yyerror(& @1, state, "invalid texture coordinate unit selector");
1825 texImageUnitNum: INTEGER
1827 if ((unsigned) $1 >= state->MaxTextureImageUnits) {
1828 yyerror(& @1, state, "invalid texture image unit selector");
1836 legacyTexUnitNum: INTEGER
1838 if ((unsigned) $1 >= state->MaxTextureUnits) {
1839 yyerror(& @1, state, "invalid texture unit selector");
1847 ALIAS_statement: ALIAS IDENTIFIER '=' IDENTIFIER
1849 struct asm_symbol *exist = (struct asm_symbol *)
1850 _mesa_symbol_table_find_symbol(state->st, 0, $2);
1851 struct asm_symbol *target = (struct asm_symbol *)
1852 _mesa_symbol_table_find_symbol(state->st, 0, $4);
1855 if (exist != NULL) {
1856 yyerror(& @2, state, "redeclared identifier");
1858 } else if (target == NULL) {
1859 yyerror(& @4, state,
1860 "undefined variable binding in ALIAS statement");
1863 _mesa_symbol_table_add_symbol(state->st, 0, $2, target);
1870 struct asm_instruction *
1871 asm_instruction_ctor(gl_inst_opcode op,
1872 const struct prog_dst_register *dst,
1873 const struct asm_src_register *src0,
1874 const struct asm_src_register *src1,
1875 const struct asm_src_register *src2)
1877 struct asm_instruction *inst = calloc(1, sizeof(struct asm_instruction));
1880 _mesa_init_instructions(& inst->Base, 1);
1881 inst->Base.Opcode = op;
1882 inst->Base.DstReg = *dst;
1884 inst->Base.SrcReg[0] = src0->Base;
1885 inst->SrcReg[0] = *src0;
1888 inst->Base.SrcReg[1] = src1->Base;
1889 inst->SrcReg[1] = *src1;
1891 init_src_reg(& inst->SrcReg[1]);
1895 inst->Base.SrcReg[2] = src2->Base;
1896 inst->SrcReg[2] = *src2;
1898 init_src_reg(& inst->SrcReg[2]);
1907 init_dst_reg(struct prog_dst_register *r)
1909 memset(r, 0, sizeof(*r));
1910 r->File = PROGRAM_UNDEFINED;
1911 r->WriteMask = WRITEMASK_XYZW;
1912 r->CondMask = COND_TR;
1913 r->CondSwizzle = SWIZZLE_NOOP;
1918 init_src_reg(struct asm_src_register *r)
1920 memset(r, 0, sizeof(*r));
1921 r->Base.File = PROGRAM_UNDEFINED;
1922 r->Base.Swizzle = SWIZZLE_NOOP;
1928 * Validate the set of inputs used by a program
1930 * Validates that legal sets of inputs are used by the program. In this case
1931 * "used" included both reading the input or binding the input to a name using
1932 * the \c ATTRIB command.
1935 * \c TRUE if the combination of inputs used is valid, \c FALSE otherwise.
1938 validate_inputs(struct YYLTYPE *locp, struct asm_parser_state *state)
1940 const int inputs = state->prog->InputsRead | state->InputsBound;
1942 if (((inputs & 0x0ffff) & (inputs >> 16)) != 0) {
1943 yyerror(locp, state, "illegal use of generic attribute and name attribute");
1952 declare_variable(struct asm_parser_state *state, char *name, enum asm_type t,
1953 struct YYLTYPE *locp)
1955 struct asm_symbol *s = NULL;
1956 struct asm_symbol *exist = (struct asm_symbol *)
1957 _mesa_symbol_table_find_symbol(state->st, 0, name);
1960 if (exist != NULL) {
1961 yyerror(locp, state, "redeclared identifier");
1963 s = calloc(1, sizeof(struct asm_symbol));
1969 if (state->prog->NumTemporaries >= state->limits->MaxTemps) {
1970 yyerror(locp, state, "too many temporaries declared");
1975 s->temp_binding = state->prog->NumTemporaries;
1976 state->prog->NumTemporaries++;
1980 if (state->prog->NumAddressRegs >= state->limits->MaxAddressRegs) {
1981 yyerror(locp, state, "too many address registers declared");
1986 /* FINISHME: Add support for multiple address registers.
1988 state->prog->NumAddressRegs++;
1995 _mesa_symbol_table_add_symbol(state->st, 0, s->name, s);
1996 s->next = state->sym;
2004 int add_state_reference(struct gl_program_parameter_list *param_list,
2005 const gl_state_index tokens[STATE_LENGTH])
2007 const GLuint size = 4; /* XXX fix */
2011 name = _mesa_program_state_string(tokens);
2012 index = _mesa_add_parameter(param_list, PROGRAM_STATE_VAR, name,
2014 NULL, (gl_state_index *) tokens, 0x0);
2015 param_list->StateFlags |= _mesa_program_state_flags(tokens);
2017 /* free name string here since we duplicated it in add_parameter() */
2025 initialize_symbol_from_state(struct gl_program *prog,
2026 struct asm_symbol *param_var,
2027 const gl_state_index tokens[STATE_LENGTH])
2030 gl_state_index state_tokens[STATE_LENGTH];
2033 memcpy(state_tokens, tokens, sizeof(state_tokens));
2035 param_var->type = at_param;
2036 param_var->param_binding_type = PROGRAM_STATE_VAR;
2038 /* If we are adding a STATE_MATRIX that has multiple rows, we need to
2039 * unroll it and call add_state_reference() for each row
2041 if ((state_tokens[0] == STATE_MODELVIEW_MATRIX ||
2042 state_tokens[0] == STATE_PROJECTION_MATRIX ||
2043 state_tokens[0] == STATE_MVP_MATRIX ||
2044 state_tokens[0] == STATE_TEXTURE_MATRIX ||
2045 state_tokens[0] == STATE_PROGRAM_MATRIX)
2046 && (state_tokens[2] != state_tokens[3])) {
2048 const int first_row = state_tokens[2];
2049 const int last_row = state_tokens[3];
2051 for (row = first_row; row <= last_row; row++) {
2052 state_tokens[2] = state_tokens[3] = row;
2054 idx = add_state_reference(prog->Parameters, state_tokens);
2055 if (param_var->param_binding_begin == ~0U)
2056 param_var->param_binding_begin = idx;
2057 param_var->param_binding_length++;
2061 idx = add_state_reference(prog->Parameters, state_tokens);
2062 if (param_var->param_binding_begin == ~0U)
2063 param_var->param_binding_begin = idx;
2064 param_var->param_binding_length++;
2072 initialize_symbol_from_param(struct gl_program *prog,
2073 struct asm_symbol *param_var,
2074 const gl_state_index tokens[STATE_LENGTH])
2077 gl_state_index state_tokens[STATE_LENGTH];
2080 memcpy(state_tokens, tokens, sizeof(state_tokens));
2082 assert((state_tokens[0] == STATE_VERTEX_PROGRAM)
2083 || (state_tokens[0] == STATE_FRAGMENT_PROGRAM));
2084 assert((state_tokens[1] == STATE_ENV)
2085 || (state_tokens[1] == STATE_LOCAL));
2087 param_var->type = at_param;
2088 param_var->param_binding_type = (state_tokens[1] == STATE_ENV)
2089 ? PROGRAM_ENV_PARAM : PROGRAM_LOCAL_PARAM;
2091 /* If we are adding a STATE_ENV or STATE_LOCAL that has multiple elements,
2092 * we need to unroll it and call add_state_reference() for each row
2094 if (state_tokens[2] != state_tokens[3]) {
2096 const int first_row = state_tokens[2];
2097 const int last_row = state_tokens[3];
2099 for (row = first_row; row <= last_row; row++) {
2100 state_tokens[2] = state_tokens[3] = row;
2102 idx = add_state_reference(prog->Parameters, state_tokens);
2103 if (param_var->param_binding_begin == ~0U)
2104 param_var->param_binding_begin = idx;
2105 param_var->param_binding_length++;
2109 idx = add_state_reference(prog->Parameters, state_tokens);
2110 if (param_var->param_binding_begin == ~0U)
2111 param_var->param_binding_begin = idx;
2112 param_var->param_binding_length++;
2120 initialize_symbol_from_const(struct gl_program *prog,
2121 struct asm_symbol *param_var,
2122 const struct asm_vector *vec)
2124 const int idx = _mesa_add_parameter(prog->Parameters, PROGRAM_CONSTANT,
2125 NULL, vec->count, GL_NONE, vec->data,
2128 param_var->type = at_param;
2129 param_var->param_binding_type = PROGRAM_CONSTANT;
2131 if (param_var->param_binding_begin == ~0U)
2132 param_var->param_binding_begin = idx;
2133 param_var->param_binding_length++;
2140 make_error_string(const char *fmt, ...)
2146 va_start(args, fmt);
2148 /* Call vsnprintf once to determine how large the final string is. Call it
2149 * again to do the actual formatting. from the vsnprintf manual page:
2151 * Upon successful return, these functions return the number of
2152 * characters printed (not including the trailing '\0' used to end
2153 * output to strings).
2155 length = 1 + vsnprintf(NULL, 0, fmt, args);
2157 str = _mesa_malloc(length);
2159 vsnprintf(str, length, fmt, args);
2169 yyerror(YYLTYPE *locp, struct asm_parser_state *state, const char *s)
2174 err_str = make_error_string("glProgramStringARB(%s)\n", s);
2176 _mesa_error(state->ctx, GL_INVALID_OPERATION, err_str);
2177 _mesa_free(err_str);
2180 err_str = make_error_string("line %u, char %u: error: %s\n",
2181 locp->first_line, locp->first_column, s);
2182 _mesa_set_program_error(state->ctx, locp->position, err_str);
2185 _mesa_free(err_str);
2191 _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
2192 GLsizei len, struct asm_parser_state *state)
2194 struct asm_instruction *inst;
2197 GLboolean result = GL_FALSE;
2199 struct asm_symbol *sym;
2202 state->prog->Target = target;
2203 state->prog->Parameters = _mesa_new_parameter_list();
2205 /* Make a copy of the program string and force it to be NUL-terminated.
2207 strz = (GLubyte *) _mesa_malloc(len + 1);
2209 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramStringARB");
2212 _mesa_memcpy (strz, str, len);
2215 state->prog->String = strz;
2217 state->st = _mesa_symbol_table_ctor();
2219 state->limits = (target == GL_VERTEX_PROGRAM_ARB)
2220 ? & ctx->Const.VertexProgram
2221 : & ctx->Const.FragmentProgram;
2223 state->MaxTextureImageUnits = 16;
2224 state->MaxTextureCoordUnits = 8;
2225 state->MaxTextureUnits = 8;
2226 state->MaxClipPlanes = 6;
2227 state->MaxLights = 8;
2228 state->MaxProgramMatrices = 8;
2230 state->state_param_enum = (target == GL_VERTEX_PROGRAM_ARB)
2231 ? STATE_VERTEX_PROGRAM : STATE_FRAGMENT_PROGRAM;
2233 _mesa_set_program_error(ctx, -1, NULL);
2235 _mesa_program_lexer_ctor(& state->scanner, state, (const char *) str, len);
2237 _mesa_program_lexer_dtor(state->scanner);
2240 if (ctx->Program.ErrorPos != -1) {
2244 if (! _mesa_layout_parameters(state)) {
2248 loc.first_column = 0;
2251 yyerror(& loc, state, "invalid PARAM usage");
2257 /* Add one instruction to store the "END" instruction.
2259 state->prog->Instructions =
2260 _mesa_alloc_instructions(state->prog->NumInstructions + 1);
2261 inst = state->inst_head;
2262 for (i = 0; i < state->prog->NumInstructions; i++) {
2263 struct asm_instruction *const temp = inst->next;
2265 state->prog->Instructions[i] = inst->Base;
2269 /* Finally, tag on an OPCODE_END instruction */
2271 const GLuint numInst = state->prog->NumInstructions;
2272 _mesa_init_instructions(state->prog->Instructions + numInst, 1);
2273 state->prog->Instructions[numInst].Opcode = OPCODE_END;
2275 state->prog->NumInstructions++;
2277 state->prog->NumParameters = state->prog->Parameters->NumParameters;
2278 state->prog->NumAttributes = _mesa_bitcount(state->prog->InputsRead);
2281 * Initialize native counts to logical counts. The device driver may
2282 * change them if program is translated into a hardware program.
2284 state->prog->NumNativeInstructions = state->prog->NumInstructions;
2285 state->prog->NumNativeTemporaries = state->prog->NumTemporaries;
2286 state->prog->NumNativeParameters = state->prog->NumParameters;
2287 state->prog->NumNativeAttributes = state->prog->NumAttributes;
2288 state->prog->NumNativeAddressRegs = state->prog->NumAddressRegs;
2293 for (inst = state->inst_head; inst != NULL; inst = temp) {
2298 state->inst_head = NULL;
2299 state->inst_tail = NULL;
2301 for (sym = state->sym; sym != NULL; sym = temp) {
2304 _mesa_free((void *) sym->name);
2309 _mesa_symbol_table_dtor(state->st);