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 VERTEX VTXATTRIB
163 %token <string> IDENTIFIER
164 %token <swiz_mask> MASK4 MASK3 MASK2 MASK1 SWIZZLE
168 %type <inst> instruction ALU_instruction TexInstruction
169 %type <inst> ARL_instruction VECTORop_instruction
170 %type <inst> SCALARop_instruction BINSCop_instruction BINop_instruction
171 %type <inst> TRIop_instruction SWZ_instruction SAMPLE_instruction
172 %type <inst> KIL_instruction
174 %type <dst_reg> dstReg maskedDstReg maskedAddrReg
175 %type <src_reg> srcReg scalarSrcReg swizzleSrcReg
176 %type <swiz_mask> scalarSuffix swizzleSuffix extendedSwizzle extSwizComp
177 %type <swiz_mask> optionalMask
178 %type <integer> extSwizSel
180 %type <sym> progParamArray
181 %type <integer> addrRegRelOffset addrRegPosOffset addrRegNegOffset
182 %type <src_reg> progParamArrayMem progParamArrayAbs progParamArrayRel
184 %type <swiz_mask> addrComponent addrWriteMask
186 %type <result> resultBinding resultColBinding
187 %type <integer> optFaceType optColorType
188 %type <integer> optResultFaceType optResultColorType
190 %type <integer> optTexImageUnitNum texImageUnitNum
191 %type <integer> optTexCoordUnitNum texCoordUnitNum
192 %type <integer> optLegacyTexUnitNum legacyTexUnitNum
193 %type <integer> texImageUnit texTarget
194 %type <integer> vtxAttribNum
196 %type <attrib> attribBinding vtxAttribItem fragAttribItem
198 %type <temp_sym> paramSingleInit paramSingleItemDecl
199 %type <integer> optArraySize
201 %type <state> stateSingleItem stateMultipleItem
202 %type <state> stateMaterialItem
203 %type <state> stateLightItem stateLightModelItem stateLightProdItem
204 %type <state> stateTexGenItem stateFogItem stateClipPlaneItem statePointItem
205 %type <state> stateMatrixItem stateMatrixRow stateMatrixRows
206 %type <state> stateTexEnvItem
208 %type <state> stateLModProperty
209 %type <state> stateMatrixName optMatrixRows
211 %type <integer> stateMatProperty
212 %type <integer> stateLightProperty stateSpotProperty
213 %type <integer> stateLightNumber stateLProdProperty
214 %type <integer> stateTexGenType stateTexGenCoord
215 %type <integer> stateTexEnvProperty
216 %type <integer> stateFogProperty
217 %type <integer> stateClipPlaneNum
218 %type <integer> statePointProperty
220 %type <integer> stateOptMatModifier stateMatModifier stateMatrixRowNum
221 %type <integer> stateOptModMatNum stateModMatNum statePaletteMatNum
222 %type <integer> stateProgramMatNum
224 %type <integer> ambDiffSpecProperty
226 %type <state> programSingleItem progEnvParam progLocalParam
227 %type <state> programMultipleItem progEnvParams progLocalParams
229 %type <temp_sym> paramMultipleInit paramMultInitList paramMultipleItem
230 %type <temp_sym> paramSingleItemUse
232 %type <integer> progEnvParamNum progLocalParamNum
233 %type <state> progEnvParamNums progLocalParamNums
235 %type <vector> paramConstDecl paramConstUse
236 %type <vector> paramConstScalarDecl paramConstScalarUse paramConstVector
237 %type <real> signedFloatConstant
238 %type <negate> optionalSign
241 extern int yylex(YYSTYPE *yylval_param, YYLTYPE *yylloc_param,
247 program: language optionSequence statementSequence END
252 if (state->prog->Target != GL_VERTEX_PROGRAM_ARB) {
253 yyerror(& @1, state, "invalid fragment program header");
256 state->mode = ARB_vertex;
260 if (state->prog->Target != GL_FRAGMENT_PROGRAM_ARB) {
261 yyerror(& @1, state, "invalid vertex program header");
263 state->mode = ARB_fragment;
267 optionSequence: optionSequence option
271 option: OPTION IDENTIFIER ';'
275 if (state->mode == ARB_vertex) {
276 valid = _mesa_ARBvp_parse_option(state, $2);
277 } else if (state->mode == ARB_fragment) {
278 valid = _mesa_ARBfp_parse_option(state, $2);
283 yyerror(& @2, state, "invalid option string");
289 statementSequence: statementSequence statement
293 statement: instruction ';'
296 if (state->inst_tail == NULL) {
297 state->inst_head = $1;
299 state->inst_tail->next = $1;
302 state->inst_tail = $1;
305 state->prog->NumInstructions++;
308 | namingStatement ';'
311 instruction: ALU_instruction
314 state->prog->NumAluInstructions++;
319 state->prog->NumTexInstructions++;
323 ALU_instruction: ARL_instruction
324 | VECTORop_instruction
325 | SCALARop_instruction
326 | BINSCop_instruction
332 TexInstruction: SAMPLE_instruction
336 ARL_instruction: ARL maskedAddrReg ',' scalarSrcReg
338 $$ = asm_instruction_ctor(OPCODE_ARL, & $2, & $4, NULL, NULL);
342 VECTORop_instruction: VECTOR_OP maskedDstReg ',' swizzleSrcReg
344 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL);
345 $$->Base.SaturateMode = $1.SaturateMode;
349 SCALARop_instruction: SCALAR_OP maskedDstReg ',' scalarSrcReg
351 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL);
352 $$->Base.SaturateMode = $1.SaturateMode;
356 BINSCop_instruction: BINSC_OP maskedDstReg ',' scalarSrcReg ',' scalarSrcReg
358 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, NULL);
359 $$->Base.SaturateMode = $1.SaturateMode;
364 BINop_instruction: BIN_OP maskedDstReg ',' swizzleSrcReg ',' swizzleSrcReg
366 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, NULL);
367 $$->Base.SaturateMode = $1.SaturateMode;
371 TRIop_instruction: TRI_OP maskedDstReg ','
372 swizzleSrcReg ',' swizzleSrcReg ',' swizzleSrcReg
374 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, & $6, & $8);
375 $$->Base.SaturateMode = $1.SaturateMode;
379 SAMPLE_instruction: SAMPLE_OP maskedDstReg ',' swizzleSrcReg ',' texImageUnit ',' texTarget
381 $$ = asm_instruction_ctor($1.Opcode, & $2, & $4, NULL, NULL);
383 $$->Base.SaturateMode = $1.SaturateMode;
384 $$->Base.TexSrcUnit = $6;
385 $$->Base.TexSrcTarget = $8;
387 state->prog->TexturesUsed[$6] |= (1U << $8);
392 KIL_instruction: KIL swizzleSrcReg
394 $$ = asm_instruction_ctor(OPCODE_KIL, NULL, & $2, NULL, NULL);
395 state->fragment.UsesKill = 1;
399 texImageUnit: TEXTURE_UNIT optTexImageUnitNum
405 texTarget: TEX_1D { $$ = TEXTURE_1D_INDEX; }
406 | TEX_2D { $$ = TEXTURE_2D_INDEX; }
407 | TEX_3D { $$ = TEXTURE_3D_INDEX; }
408 | TEX_CUBE { $$ = TEXTURE_CUBE_INDEX; }
409 | TEX_RECT { $$ = TEXTURE_RECT_INDEX; }
412 SWZ_instruction: SWZ maskedDstReg ',' srcReg ',' extendedSwizzle
414 /* FIXME: Is this correct? Should the extenedSwizzle be applied
415 * FIXME: to the existing swizzle?
417 $4.Base.Swizzle = $6.swizzle;
419 $$ = asm_instruction_ctor(OPCODE_SWZ, & $2, & $4, NULL, NULL);
420 $$->Base.SaturateMode = $1.SaturateMode;
424 scalarSrcReg: optionalSign srcReg scalarSuffix
429 $$.Base.Negate = ~$$.Base.Negate;
432 $$.Base.Swizzle = _mesa_combine_swizzles($$.Base.Swizzle,
437 swizzleSrcReg: optionalSign srcReg swizzleSuffix
442 $$.Base.Negate = ~$$.Base.Negate;
445 $$.Base.Swizzle = _mesa_combine_swizzles($$.Base.Swizzle,
450 maskedDstReg: dstReg optionalMask
453 $$.WriteMask = $2.mask;
455 if ($$.File == PROGRAM_OUTPUT) {
456 /* Technically speaking, this should check that it is in
457 * vertex program mode. However, PositionInvariant can never be
458 * set in fragment program mode, so it is somewhat irrelevant.
460 if (state->option.PositionInvariant
461 && ($$.Index == VERT_RESULT_HPOS)) {
462 yyerror(& @1, state, "position-invariant programs cannot "
467 state->prog->OutputsWritten |= (1U << $$.Index);
472 maskedAddrReg: addrReg addrWriteMask
475 $$.File = PROGRAM_ADDRESS;
477 $$.WriteMask = $2.mask;
481 extendedSwizzle: extSwizComp ',' extSwizComp ',' extSwizComp ',' extSwizComp
483 $$.swizzle = MAKE_SWIZZLE4($1.swizzle, $3.swizzle,
484 $5.swizzle, $7.swizzle);
485 $$.mask = ($1.mask) | ($3.mask << 1) | ($5.mask << 2)
490 extSwizComp: optionalSign extSwizSel
493 $$.mask = ($1) ? 1 : 0;
499 if (($1 != 0) && ($1 != 1)) {
500 yyerror(& @1, state, "invalid extended swizzle selector");
504 $$ = ($1 == 0) ? SWIZZLE_ZERO : SWIZZLE_ONE;
508 if (strlen($1) > 1) {
509 yyerror(& @1, state, "invalid extended swizzle selector");
527 yyerror(& @1, state, "invalid extended swizzle selector");
534 srcReg: IDENTIFIER /* temporaryReg | progParamSingle */
536 struct asm_symbol *const s = (struct asm_symbol *)
537 _mesa_symbol_table_find_symbol(state->st, 0, $1);
540 yyerror(& @1, state, "invalid operand variable");
542 } else if ((s->type != at_param) && (s->type != at_temp)
543 && (s->type != at_attrib)) {
544 yyerror(& @1, state, "invalid operand variable");
546 } else if ((s->type == at_param) && s->param_is_array) {
547 yyerror(& @1, state, "non-array access to array PARAM");
554 $$.Base.File = PROGRAM_TEMPORARY;
555 $$.Base.Index = s->temp_binding;
558 $$.Base.File = s->param_binding_type;
559 $$.Base.Index = s->param_binding_begin;
562 $$.Base.File = PROGRAM_INPUT;
563 $$.Base.Index = s->attrib_binding;
564 state->prog->InputsRead |= (1U << $$.Base.Index);
566 if (!validate_inputs(& @1, state)) {
579 $$.Base.File = PROGRAM_INPUT;
581 state->prog->InputsRead |= (1U << $$.Base.Index);
583 if (!validate_inputs(& @1, state)) {
587 | progParamArray '[' progParamArrayMem ']'
589 if (! $3.Base.RelAddr
590 && ((unsigned) $3.Base.Index >= $1->param_binding_length)) {
591 yyerror(& @3, state, "out of bounds array access");
596 $$.Base.File = $1->param_binding_type;
598 if ($3.Base.RelAddr) {
599 $1->param_accessed_indirectly = 1;
602 $$.Base.Index = $3.Base.Index;
605 $$.Base.Index = $1->param_binding_begin + $3.Base.Index;
611 $$.Base.File = ($1.name != NULL)
612 ? $1.param_binding_type
614 $$.Base.Index = $1.param_binding_begin;
618 dstReg: resultBinding
621 $$.File = PROGRAM_OUTPUT;
624 | IDENTIFIER /* temporaryReg | vertexResultReg */
626 struct asm_symbol *const s = (struct asm_symbol *)
627 _mesa_symbol_table_find_symbol(state->st, 0, $1);
630 yyerror(& @1, state, "invalid operand variable");
632 } else if ((s->type != at_output) && (s->type != at_temp)) {
633 yyerror(& @1, state, "invalid operand variable");
638 if (s->type == at_temp) {
639 $$.File = PROGRAM_TEMPORARY;
640 $$.Index = s->temp_binding;
642 $$.File = s->param_binding_type;
643 $$.Index = s->param_binding_begin;
648 progParamArray: IDENTIFIER
650 struct asm_symbol *const s = (struct asm_symbol *)
651 _mesa_symbol_table_find_symbol(state->st, 0, $1);
654 yyerror(& @1, state, "invalid operand variable");
656 } else if ((s->type != at_param) || !s->param_is_array) {
657 yyerror(& @1, state, "array access to non-PARAM variable");
665 progParamArrayMem: progParamArrayAbs | progParamArrayRel;
667 progParamArrayAbs: INTEGER
674 progParamArrayRel: addrReg addrComponent addrRegRelOffset
676 /* FINISHME: Add support for multiple address registers.
678 /* FINISHME: Add support for 4-component address registers.
686 addrRegRelOffset: { $$ = 0; }
687 | '+' addrRegPosOffset { $$ = $2; }
688 | '-' addrRegNegOffset { $$ = -$2; }
691 addrRegPosOffset: INTEGER
693 if (($1 < 0) || ($1 > 63)) {
695 "relative address offset too large (positive)");
703 addrRegNegOffset: INTEGER
705 if (($1 < 0) || ($1 > 64)) {
707 "relative address offset too large (negative)");
717 struct asm_symbol *const s = (struct asm_symbol *)
718 _mesa_symbol_table_find_symbol(state->st, 0, $1);
721 yyerror(& @1, state, "invalid array member");
723 } else if (s->type != at_address) {
725 "invalid variable for indexed array access");
735 if ($1.mask != WRITEMASK_X) {
736 yyerror(& @1, state, "invalid address component selector");
746 if ($1.mask != WRITEMASK_X) {
748 "address register write mask must be \".x\"");
761 | { $$.swizzle = SWIZZLE_NOOP; $$.mask = WRITEMASK_XYZW; }
764 optionalMask: MASK4 | MASK3 | MASK2 | MASK1
765 | { $$.swizzle = SWIZZLE_NOOP; $$.mask = WRITEMASK_XYZW; }
768 namingStatement: ATTRIB_statement
776 ATTRIB_statement: ATTRIB IDENTIFIER '=' attribBinding
778 struct asm_symbol *const s =
779 declare_variable(state, $2, at_attrib, & @2);
784 s->attrib_binding = $4;
785 state->InputsBound |= (1U << s->attrib_binding);
787 if (!validate_inputs(& @4, state)) {
794 attribBinding: VERTEX vtxAttribItem
798 | FRAGMENT fragAttribItem
804 vtxAttribItem: POSITION
806 $$ = VERT_ATTRIB_POS;
808 | WEIGHT vtxOptWeightNum
810 $$ = VERT_ATTRIB_WEIGHT;
814 $$ = VERT_ATTRIB_NORMAL;
818 $$ = VERT_ATTRIB_COLOR0 + $2;
822 $$ = VERT_ATTRIB_FOG;
824 | TEXCOORD optTexCoordUnitNum
826 $$ = VERT_ATTRIB_TEX0 + $2;
828 | MATRIXINDEX '[' vtxWeightNum ']'
832 | VTXATTRIB '[' vtxAttribNum ']'
834 $$ = VERT_ATTRIB_GENERIC0 + $3;
838 vtxAttribNum: INTEGER
840 if ((unsigned) $1 >= state->limits->MaxAttribs) {
841 yyerror(& @1, state, "invalid vertex attribute reference");
849 vtxOptWeightNum: | '[' vtxWeightNum ']';
850 vtxWeightNum: INTEGER;
852 fragAttribItem: POSITION
854 $$ = FRAG_ATTRIB_WPOS;
858 $$ = FRAG_ATTRIB_COL0 + $2;
862 $$ = FRAG_ATTRIB_FOGC;
864 | TEXCOORD optTexCoordUnitNum
866 $$ = FRAG_ATTRIB_TEX0 + $2;
870 PARAM_statement: PARAM_singleStmt | PARAM_multipleStmt;
872 PARAM_singleStmt: PARAM IDENTIFIER paramSingleInit
874 struct asm_symbol *const s =
875 declare_variable(state, $2, at_param, & @2);
880 s->param_binding_type = $3.param_binding_type;
881 s->param_binding_begin = $3.param_binding_begin;
882 s->param_binding_length = $3.param_binding_length;
883 s->param_is_array = 0;
888 PARAM_multipleStmt: PARAM IDENTIFIER '[' optArraySize ']' paramMultipleInit
890 if (($4 != 0) && ((unsigned) $4 != $6.param_binding_length)) {
892 "parameter array size and number of bindings must match");
895 struct asm_symbol *const s =
896 declare_variable(state, $2, $6.type, & @2);
901 s->param_binding_type = $6.param_binding_type;
902 s->param_binding_begin = $6.param_binding_begin;
903 s->param_binding_length = $6.param_binding_length;
904 s->param_is_array = 1;
916 if (($1 < 1) || ((unsigned) $1 >= state->limits->MaxParameters)) {
917 yyerror(& @1, state, "invalid parameter array size");
925 paramSingleInit: '=' paramSingleItemDecl
931 paramMultipleInit: '=' '{' paramMultInitList '}'
937 paramMultInitList: paramMultipleItem
938 | paramMultInitList ',' paramMultipleItem
940 $1.param_binding_length += $3.param_binding_length;
945 paramSingleItemDecl: stateSingleItem
947 memset(& $$, 0, sizeof($$));
948 $$.param_binding_begin = ~0;
949 initialize_symbol_from_state(state->prog, & $$, $1);
953 memset(& $$, 0, sizeof($$));
954 $$.param_binding_begin = ~0;
955 initialize_symbol_from_param(state->prog, & $$, $1);
959 memset(& $$, 0, sizeof($$));
960 $$.param_binding_begin = ~0;
961 initialize_symbol_from_const(state->prog, & $$, & $1);
965 paramSingleItemUse: stateSingleItem
967 memset(& $$, 0, sizeof($$));
968 $$.param_binding_begin = ~0;
969 initialize_symbol_from_state(state->prog, & $$, $1);
973 memset(& $$, 0, sizeof($$));
974 $$.param_binding_begin = ~0;
975 initialize_symbol_from_param(state->prog, & $$, $1);
979 memset(& $$, 0, sizeof($$));
980 $$.param_binding_begin = ~0;
981 initialize_symbol_from_const(state->prog, & $$, & $1);
985 paramMultipleItem: stateMultipleItem
987 memset(& $$, 0, sizeof($$));
988 $$.param_binding_begin = ~0;
989 initialize_symbol_from_state(state->prog, & $$, $1);
991 | programMultipleItem
993 memset(& $$, 0, sizeof($$));
994 $$.param_binding_begin = ~0;
995 initialize_symbol_from_param(state->prog, & $$, $1);
999 memset(& $$, 0, sizeof($$));
1000 $$.param_binding_begin = ~0;
1001 initialize_symbol_from_const(state->prog, & $$, & $1);
1005 stateMultipleItem: stateSingleItem { memcpy($$, $1, sizeof($$)); }
1006 | STATE stateMatrixRows { memcpy($$, $2, sizeof($$)); }
1009 stateSingleItem: STATE stateMaterialItem { memcpy($$, $2, sizeof($$)); }
1010 | STATE stateLightItem { memcpy($$, $2, sizeof($$)); }
1011 | STATE stateLightModelItem { memcpy($$, $2, sizeof($$)); }
1012 | STATE stateLightProdItem { memcpy($$, $2, sizeof($$)); }
1013 | STATE stateTexGenItem { memcpy($$, $2, sizeof($$)); }
1014 | STATE stateTexEnvItem { memcpy($$, $2, sizeof($$)); }
1015 | STATE stateFogItem { memcpy($$, $2, sizeof($$)); }
1016 | STATE stateClipPlaneItem { memcpy($$, $2, sizeof($$)); }
1017 | STATE statePointItem { memcpy($$, $2, sizeof($$)); }
1018 | STATE stateMatrixRow { memcpy($$, $2, sizeof($$)); }
1021 stateMaterialItem: MATERIAL optFaceType stateMatProperty
1023 memset($$, 0, sizeof($$));
1024 $$[0] = STATE_MATERIAL;
1030 stateMatProperty: ambDiffSpecProperty
1036 $$ = STATE_EMISSION;
1040 $$ = STATE_SHININESS;
1044 stateLightItem: LIGHT '[' stateLightNumber ']' stateLightProperty
1046 memset($$, 0, sizeof($$));
1047 $$[0] = STATE_LIGHT;
1053 stateLightProperty: ambDiffSpecProperty
1059 $$ = STATE_POSITION;
1063 $$ = STATE_ATTENUATION;
1065 | SPOT stateSpotProperty
1071 $$ = STATE_HALF_VECTOR;
1075 stateSpotProperty: DIRECTION
1077 $$ = STATE_SPOT_DIRECTION;
1081 stateLightModelItem: LIGHTMODEL stateLModProperty
1088 stateLModProperty: AMBIENT
1090 memset($$, 0, sizeof($$));
1091 $$[0] = STATE_LIGHTMODEL_AMBIENT;
1093 | optFaceType SCENECOLOR
1095 memset($$, 0, sizeof($$));
1096 $$[0] = STATE_LIGHTMODEL_SCENECOLOR;
1101 stateLightProdItem: LIGHTPROD '[' stateLightNumber ']' optFaceType stateLProdProperty
1103 memset($$, 0, sizeof($$));
1104 $$[0] = STATE_LIGHTPROD;
1111 stateLProdProperty: ambDiffSpecProperty;
1113 stateTexEnvItem: TEXENV optLegacyTexUnitNum stateTexEnvProperty
1115 memset($$, 0, sizeof($$));
1121 stateTexEnvProperty: COLOR
1123 $$ = STATE_TEXENV_COLOR;
1127 ambDiffSpecProperty: AMBIENT
1137 $$ = STATE_SPECULAR;
1141 stateLightNumber: INTEGER
1143 if ((unsigned) $1 >= state->MaxLights) {
1144 yyerror(& @1, state, "invalid light selector");
1152 stateTexGenItem: TEXGEN optTexCoordUnitNum stateTexGenType stateTexGenCoord
1154 memset($$, 0, sizeof($$));
1155 $$[0] = STATE_TEXGEN;
1161 stateTexGenType: EYE
1163 $$ = STATE_TEXGEN_EYE_S;
1167 $$ = STATE_TEXGEN_OBJECT_S;
1170 stateTexGenCoord: TEXGEN_S
1172 $$ = STATE_TEXGEN_EYE_S - STATE_TEXGEN_EYE_S;
1176 $$ = STATE_TEXGEN_EYE_T - STATE_TEXGEN_EYE_S;
1180 $$ = STATE_TEXGEN_EYE_R - STATE_TEXGEN_EYE_S;
1184 $$ = STATE_TEXGEN_EYE_Q - STATE_TEXGEN_EYE_S;
1188 stateFogItem: FOG stateFogProperty
1190 memset($$, 0, sizeof($$));
1195 stateFogProperty: COLOR
1197 $$ = STATE_FOG_COLOR;
1201 $$ = STATE_FOG_PARAMS;
1205 stateClipPlaneItem: CLIP '[' stateClipPlaneNum ']' PLANE
1207 memset($$, 0, sizeof($$));
1208 $$[0] = STATE_CLIPPLANE;
1213 stateClipPlaneNum: INTEGER
1215 if ((unsigned) $1 >= state->MaxClipPlanes) {
1216 yyerror(& @1, state, "invalid clip plane selector");
1224 statePointItem: POINT statePointProperty
1226 memset($$, 0, sizeof($$));
1231 statePointProperty: SIZE
1233 $$ = STATE_POINT_SIZE;
1237 $$ = STATE_POINT_ATTENUATION;
1241 stateMatrixRow: stateMatrixItem ROW '[' stateMatrixRowNum ']'
1251 stateMatrixRows: stateMatrixItem optMatrixRows
1266 | ROW '[' stateMatrixRowNum DOT_DOT stateMatrixRowNum ']'
1268 /* It seems logical that the matrix row range specifier would have
1269 * to specify a range or more than one row (i.e., $5 > $3).
1270 * However, the ARB_vertex_program spec says "a program will fail
1271 * to load if <a> is greater than <b>." This means that $3 == $5
1275 yyerror(& @3, state, "invalid matrix row range");
1284 stateMatrixItem: MATRIX stateMatrixName stateOptMatModifier
1292 stateOptMatModifier:
1302 stateMatModifier: INVERSE
1304 $$ = STATE_MATRIX_INVERSE;
1308 $$ = STATE_MATRIX_TRANSPOSE;
1312 $$ = STATE_MATRIX_INVTRANS;
1316 stateMatrixRowNum: INTEGER
1319 yyerror(& @1, state, "invalid matrix row reference");
1327 stateMatrixName: MODELVIEW stateOptModMatNum
1329 $$[0] = STATE_MODELVIEW_MATRIX;
1334 $$[0] = STATE_PROJECTION_MATRIX;
1339 $$[0] = STATE_MVP_MATRIX;
1342 | TEXTURE optTexCoordUnitNum
1344 $$[0] = STATE_TEXTURE_MATRIX;
1347 | PALETTE '[' statePaletteMatNum ']'
1351 | MAT_PROGRAM '[' stateProgramMatNum ']'
1353 $$[0] = STATE_PROGRAM_MATRIX;
1367 stateModMatNum: INTEGER
1369 /* Since GL_ARB_vertex_blend isn't supported, only modelview matrix
1373 yyerror(& @1, state, "invalid modelview matrix index");
1380 statePaletteMatNum: INTEGER
1382 /* Since GL_ARB_matrix_palette isn't supported, just let any value
1383 * through here. The error will be generated later.
1388 stateProgramMatNum: INTEGER
1390 if ((unsigned) $1 >= state->MaxProgramMatrices) {
1391 yyerror(& @1, state, "invalid program matrix selector");
1401 programSingleItem: progEnvParam | progLocalParam;
1403 programMultipleItem: progEnvParams | progLocalParams;
1405 progEnvParams: PROGRAM ENV '[' progEnvParamNums ']'
1407 memset($$, 0, sizeof($$));
1408 $$[0] = state->state_param_enum;
1415 progEnvParamNums: progEnvParamNum
1420 | progEnvParamNum DOT_DOT progEnvParamNum
1427 progEnvParam: PROGRAM ENV '[' progEnvParamNum ']'
1429 memset($$, 0, sizeof($$));
1430 $$[0] = state->state_param_enum;
1437 progLocalParams: PROGRAM LOCAL '[' progLocalParamNums ']'
1439 memset($$, 0, sizeof($$));
1440 $$[0] = state->state_param_enum;
1441 $$[1] = STATE_LOCAL;
1446 progLocalParamNums: progLocalParamNum
1451 | progLocalParamNum DOT_DOT progLocalParamNum
1458 progLocalParam: PROGRAM LOCAL '[' progLocalParamNum ']'
1460 memset($$, 0, sizeof($$));
1461 $$[0] = state->state_param_enum;
1462 $$[1] = STATE_LOCAL;
1468 progEnvParamNum: INTEGER
1470 if ((unsigned) $1 >= state->limits->MaxEnvParams) {
1471 yyerror(& @1, state, "invalid environment parameter reference");
1478 progLocalParamNum: INTEGER
1480 if ((unsigned) $1 >= state->limits->MaxLocalParams) {
1481 yyerror(& @1, state, "invalid local parameter reference");
1490 paramConstDecl: paramConstScalarDecl | paramConstVector;
1491 paramConstUse: paramConstScalarUse | paramConstVector;
1493 paramConstScalarDecl: signedFloatConstant
1500 paramConstScalarUse: REAL
1508 $$.data[0] = (float) $1;
1512 paramConstVector: '{' signedFloatConstant '}'
1520 | '{' signedFloatConstant ',' signedFloatConstant '}'
1528 | '{' signedFloatConstant ',' signedFloatConstant ','
1529 signedFloatConstant '}'
1537 | '{' signedFloatConstant ',' signedFloatConstant ','
1538 signedFloatConstant ',' signedFloatConstant '}'
1548 signedFloatConstant: optionalSign REAL
1550 $$ = ($1) ? -$2 : $2;
1552 | optionalSign INTEGER
1554 $$ = (float)(($1) ? -$2 : $2);
1558 optionalSign: '+' { $$ = FALSE; }
1559 | '-' { $$ = TRUE; }
1563 TEMP_statement: TEMP { $<integer>$ = $1; } varNameList
1566 ADDRESS_statement: ADDRESS { $<integer>$ = $1; } varNameList
1569 varNameList: varNameList ',' IDENTIFIER
1571 if (!declare_variable(state, $3, $<integer>0, & @3)) {
1577 if (!declare_variable(state, $1, $<integer>0, & @1)) {
1583 OUTPUT_statement: OUTPUT IDENTIFIER '=' resultBinding
1585 struct asm_symbol *const s =
1586 declare_variable(state, $2, at_output, & @2);
1591 s->output_binding = $4;
1596 resultBinding: RESULT POSITION
1598 if (state->mode == ARB_vertex) {
1599 $$ = VERT_RESULT_HPOS;
1601 yyerror(& @2, state, "invalid program result name");
1607 if (state->mode == ARB_vertex) {
1608 $$ = VERT_RESULT_FOGC;
1610 yyerror(& @2, state, "invalid program result name");
1614 | RESULT resultColBinding
1620 if (state->mode == ARB_vertex) {
1621 $$ = VERT_RESULT_PSIZ;
1623 yyerror(& @2, state, "invalid program result name");
1627 | RESULT TEXCOORD optTexCoordUnitNum
1629 if (state->mode == ARB_vertex) {
1630 $$ = VERT_RESULT_TEX0 + $3;
1632 yyerror(& @2, state, "invalid program result name");
1638 if (state->mode == ARB_fragment) {
1639 $$ = FRAG_RESULT_DEPTH;
1641 yyerror(& @2, state, "invalid program result name");
1647 resultColBinding: COLOR optResultFaceType optResultColorType
1655 $$ = (state->mode == ARB_vertex)
1657 : FRAG_RESULT_COLOR;
1661 if (state->mode == ARB_vertex) {
1662 $$ = VERT_RESULT_COL0;
1664 yyerror(& @1, state, "invalid program result name");
1670 if (state->mode == ARB_vertex) {
1671 $$ = VERT_RESULT_BFC0;
1673 yyerror(& @1, state, "invalid program result name");
1685 if (state->mode == ARB_vertex) {
1688 yyerror(& @1, state, "invalid program result name");
1694 if (state->mode == ARB_vertex) {
1697 yyerror(& @1, state, "invalid program result name");
1703 optFaceType: { $$ = 0; }
1708 optColorType: { $$ = 0; }
1709 | PRIMARY { $$ = 0; }
1710 | SECONDARY { $$ = 1; }
1713 optTexCoordUnitNum: { $$ = 0; }
1714 | '[' texCoordUnitNum ']' { $$ = $2; }
1717 optTexImageUnitNum: { $$ = 0; }
1718 | '[' texImageUnitNum ']' { $$ = $2; }
1721 optLegacyTexUnitNum: { $$ = 0; }
1722 | '[' legacyTexUnitNum ']' { $$ = $2; }
1725 texCoordUnitNum: INTEGER
1727 if ((unsigned) $1 >= state->MaxTextureCoordUnits) {
1728 yyerror(& @1, state, "invalid texture coordinate unit selector");
1736 texImageUnitNum: INTEGER
1738 if ((unsigned) $1 >= state->MaxTextureImageUnits) {
1739 yyerror(& @1, state, "invalid texture image unit selector");
1747 legacyTexUnitNum: INTEGER
1749 if ((unsigned) $1 >= state->MaxTextureUnits) {
1750 yyerror(& @1, state, "invalid texture unit selector");
1758 ALIAS_statement: ALIAS IDENTIFIER '=' IDENTIFIER
1760 struct asm_symbol *exist = (struct asm_symbol *)
1761 _mesa_symbol_table_find_symbol(state->st, 0, $2);
1762 struct asm_symbol *target = (struct asm_symbol *)
1763 _mesa_symbol_table_find_symbol(state->st, 0, $4);
1766 if (exist != NULL) {
1767 yyerror(& @2, state, "redeclared identifier");
1769 } else if (target == NULL) {
1770 yyerror(& @4, state,
1771 "undefined variable binding in ALIAS statement");
1774 _mesa_symbol_table_add_symbol(state->st, 0, $2, target);
1781 struct asm_instruction *
1782 asm_instruction_ctor(gl_inst_opcode op,
1783 const struct prog_dst_register *dst,
1784 const struct asm_src_register *src0,
1785 const struct asm_src_register *src1,
1786 const struct asm_src_register *src2)
1788 struct asm_instruction *inst = calloc(1, sizeof(struct asm_instruction));
1791 _mesa_init_instructions(& inst->Base, 1);
1792 inst->Base.Opcode = op;
1793 inst->Base.DstReg = *dst;
1795 inst->Base.SrcReg[0] = src0->Base;
1796 inst->SrcReg[0] = *src0;
1799 inst->Base.SrcReg[1] = src1->Base;
1800 inst->SrcReg[1] = *src1;
1802 init_src_reg(& inst->SrcReg[1]);
1806 inst->Base.SrcReg[2] = src2->Base;
1807 inst->SrcReg[2] = *src2;
1809 init_src_reg(& inst->SrcReg[2]);
1818 init_dst_reg(struct prog_dst_register *r)
1820 memset(r, 0, sizeof(*r));
1821 r->File = PROGRAM_UNDEFINED;
1822 r->WriteMask = WRITEMASK_XYZW;
1823 r->CondMask = COND_TR;
1824 r->CondSwizzle = SWIZZLE_NOOP;
1829 init_src_reg(struct asm_src_register *r)
1831 memset(r, 0, sizeof(*r));
1832 r->Base.File = PROGRAM_UNDEFINED;
1833 r->Base.Swizzle = SWIZZLE_NOOP;
1839 * Validate the set of inputs used by a program
1841 * Validates that legal sets of inputs are used by the program. In this case
1842 * "used" included both reading the input or binding the input to a name using
1843 * the \c ATTRIB command.
1846 * \c TRUE if the combination of inputs used is valid, \c FALSE otherwise.
1849 validate_inputs(struct YYLTYPE *locp, struct asm_parser_state *state)
1851 const int inputs = state->prog->InputsRead | state->InputsBound;
1853 if (((inputs & 0x0ffff) & (inputs >> 16)) != 0) {
1854 yyerror(locp, state, "illegal use of generic attribute and name attribute");
1863 declare_variable(struct asm_parser_state *state, char *name, enum asm_type t,
1864 struct YYLTYPE *locp)
1866 struct asm_symbol *s = NULL;
1867 struct asm_symbol *exist = (struct asm_symbol *)
1868 _mesa_symbol_table_find_symbol(state->st, 0, name);
1871 if (exist != NULL) {
1872 yyerror(locp, state, "redeclared identifier");
1874 s = calloc(1, sizeof(struct asm_symbol));
1880 if (state->prog->NumTemporaries >= state->limits->MaxTemps) {
1881 yyerror(locp, state, "too many temporaries declared");
1886 s->temp_binding = state->prog->NumTemporaries;
1887 state->prog->NumTemporaries++;
1891 if (state->prog->NumAddressRegs >= state->limits->MaxAddressRegs) {
1892 yyerror(locp, state, "too many address registers declared");
1897 /* FINISHME: Add support for multiple address registers.
1899 state->prog->NumAddressRegs++;
1906 _mesa_symbol_table_add_symbol(state->st, 0, s->name, s);
1913 int add_state_reference(struct gl_program_parameter_list *param_list,
1914 const gl_state_index tokens[STATE_LENGTH])
1916 const GLuint size = 4; /* XXX fix */
1920 name = _mesa_program_state_string(tokens);
1921 index = _mesa_add_parameter(param_list, PROGRAM_STATE_VAR, name,
1923 NULL, (gl_state_index *) tokens, 0x0);
1924 param_list->StateFlags |= _mesa_program_state_flags(tokens);
1926 /* free name string here since we duplicated it in add_parameter() */
1934 initialize_symbol_from_state(struct gl_program *prog,
1935 struct asm_symbol *param_var,
1936 const gl_state_index tokens[STATE_LENGTH])
1939 gl_state_index state_tokens[STATE_LENGTH];
1942 memcpy(state_tokens, tokens, sizeof(state_tokens));
1944 param_var->type = at_param;
1945 param_var->param_binding_type = PROGRAM_STATE_VAR;
1947 /* If we are adding a STATE_MATRIX that has multiple rows, we need to
1948 * unroll it and call add_state_reference() for each row
1950 if ((state_tokens[0] == STATE_MODELVIEW_MATRIX ||
1951 state_tokens[0] == STATE_PROJECTION_MATRIX ||
1952 state_tokens[0] == STATE_MVP_MATRIX ||
1953 state_tokens[0] == STATE_TEXTURE_MATRIX ||
1954 state_tokens[0] == STATE_PROGRAM_MATRIX)
1955 && (state_tokens[2] != state_tokens[3])) {
1957 const int first_row = state_tokens[2];
1958 const int last_row = state_tokens[3];
1960 for (row = first_row; row <= last_row; row++) {
1961 state_tokens[2] = state_tokens[3] = row;
1963 idx = add_state_reference(prog->Parameters, state_tokens);
1964 if (param_var->param_binding_begin == ~0U)
1965 param_var->param_binding_begin = idx;
1966 param_var->param_binding_length++;
1970 idx = add_state_reference(prog->Parameters, state_tokens);
1971 if (param_var->param_binding_begin == ~0U)
1972 param_var->param_binding_begin = idx;
1973 param_var->param_binding_length++;
1981 initialize_symbol_from_param(struct gl_program *prog,
1982 struct asm_symbol *param_var,
1983 const gl_state_index tokens[STATE_LENGTH])
1986 gl_state_index state_tokens[STATE_LENGTH];
1989 memcpy(state_tokens, tokens, sizeof(state_tokens));
1991 assert((state_tokens[0] == STATE_VERTEX_PROGRAM)
1992 || (state_tokens[0] == STATE_FRAGMENT_PROGRAM));
1993 assert((state_tokens[1] == STATE_ENV)
1994 || (state_tokens[1] == STATE_LOCAL));
1996 param_var->type = at_param;
1997 param_var->param_binding_type = (state_tokens[1] == STATE_ENV)
1998 ? PROGRAM_ENV_PARAM : PROGRAM_LOCAL_PARAM;
2000 /* If we are adding a STATE_ENV or STATE_LOCAL that has multiple elements,
2001 * we need to unroll it and call add_state_reference() for each row
2003 if (state_tokens[2] != state_tokens[3]) {
2005 const int first_row = state_tokens[2];
2006 const int last_row = state_tokens[3];
2008 for (row = first_row; row <= last_row; row++) {
2009 state_tokens[2] = state_tokens[3] = row;
2011 idx = add_state_reference(prog->Parameters, state_tokens);
2012 if (param_var->param_binding_begin == ~0U)
2013 param_var->param_binding_begin = idx;
2014 param_var->param_binding_length++;
2018 idx = add_state_reference(prog->Parameters, state_tokens);
2019 if (param_var->param_binding_begin == ~0U)
2020 param_var->param_binding_begin = idx;
2021 param_var->param_binding_length++;
2029 initialize_symbol_from_const(struct gl_program *prog,
2030 struct asm_symbol *param_var,
2031 const struct asm_vector *vec)
2033 const int idx = _mesa_add_parameter(prog->Parameters, PROGRAM_CONSTANT,
2034 NULL, vec->count, GL_NONE, vec->data,
2037 param_var->type = at_param;
2038 param_var->param_binding_type = PROGRAM_CONSTANT;
2040 if (param_var->param_binding_begin == ~0U)
2041 param_var->param_binding_begin = idx;
2042 param_var->param_binding_length++;
2049 make_error_string(const char *fmt, ...)
2055 va_start(args, fmt);
2057 /* Call vsnprintf once to determine how large the final string is. Call it
2058 * again to do the actual formatting. from the vsnprintf manual page:
2060 * Upon successful return, these functions return the number of
2061 * characters printed (not including the trailing '\0' used to end
2062 * output to strings).
2064 length = 1 + vsnprintf(NULL, 0, fmt, args);
2066 str = _mesa_malloc(length);
2068 vsnprintf(str, length, fmt, args);
2078 yyerror(YYLTYPE *locp, struct asm_parser_state *state, const char *s)
2083 err_str = make_error_string("glProgramStringARB(%s)\n", s);
2085 _mesa_error(state->ctx, GL_INVALID_OPERATION, err_str);
2086 _mesa_free(err_str);
2089 err_str = make_error_string("line %u, char %u: error: %s\n",
2090 locp->first_line, locp->first_column, s);
2091 _mesa_set_program_error(state->ctx, locp->position, err_str);
2094 _mesa_free(err_str);
2100 _mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str,
2101 GLsizei len, struct asm_parser_state *state)
2103 struct gl_program_constants limits;
2104 struct asm_instruction *inst;
2109 state->prog->Target = target;
2110 state->prog->Parameters = _mesa_new_parameter_list();
2112 /* Make a copy of the program string and force it to be NUL-terminated.
2114 strz = (GLubyte *) _mesa_malloc(len + 1);
2116 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramStringARB");
2119 _mesa_memcpy (strz, str, len);
2122 state->prog->String = strz;
2124 state->st = _mesa_symbol_table_ctor();
2126 /* All of these limits should come from ctx.
2128 limits.MaxInstructions = 128;
2129 limits.MaxAluInstructions = 128;
2130 limits.MaxTexInstructions = 128;
2131 limits.MaxTexIndirections = 128;
2132 limits.MaxAttribs = 16;
2133 limits.MaxTemps = 128;
2134 limits.MaxAddressRegs = 1;
2135 limits.MaxParameters = 128;
2136 limits.MaxLocalParams = 256;
2137 limits.MaxEnvParams = 128;
2138 limits.MaxNativeInstructions = 128;
2139 limits.MaxNativeAluInstructions = 128;
2140 limits.MaxNativeTexInstructions = 128;
2141 limits.MaxNativeTexIndirections = 128;
2142 limits.MaxNativeAttribs = 16;
2143 limits.MaxNativeTemps = 128;
2144 limits.MaxNativeAddressRegs = 1;
2145 limits.MaxNativeParameters = 128;
2146 limits.MaxUniformComponents = 0;
2148 state->limits = & limits;
2150 state->MaxTextureImageUnits = 16;
2151 state->MaxTextureCoordUnits = 8;
2152 state->MaxTextureUnits = 8;
2153 state->MaxClipPlanes = 6;
2154 state->MaxLights = 8;
2155 state->MaxProgramMatrices = 8;
2157 state->state_param_enum = (target == GL_VERTEX_PROGRAM_ARB)
2158 ? STATE_VERTEX_PROGRAM : STATE_FRAGMENT_PROGRAM;
2160 _mesa_set_program_error(ctx, -1, NULL);
2162 _mesa_program_lexer_ctor(& state->scanner, state, (const char *) str, len);
2164 _mesa_program_lexer_dtor(state->scanner);
2167 if (ctx->Program.ErrorPos != -1) {
2171 if (! _mesa_layout_parameters(state)) {
2175 loc.first_column = 0;
2178 yyerror(& loc, state, "invalid PARAM usage");
2184 /* Add one instruction to store the "END" instruction.
2186 state->prog->Instructions =
2187 _mesa_alloc_instructions(state->prog->NumInstructions + 1);
2188 inst = state->inst_head;
2189 for (i = 0; i < state->prog->NumInstructions; i++) {
2190 struct asm_instruction *const temp = inst->next;
2192 state->prog->Instructions[i] = inst->Base;
2198 /* Finally, tag on an OPCODE_END instruction */
2200 const GLuint numInst = state->prog->NumInstructions;
2201 _mesa_init_instructions(state->prog->Instructions + numInst, 1);
2202 state->prog->Instructions[numInst].Opcode = OPCODE_END;
2204 state->prog->NumInstructions++;
2206 state->prog->NumParameters = state->prog->Parameters->NumParameters;
2209 * Initialize native counts to logical counts. The device driver may
2210 * change them if program is translated into a hardware program.
2212 state->prog->NumNativeInstructions = state->prog->NumInstructions;
2213 state->prog->NumNativeTemporaries = state->prog->NumTemporaries;
2214 state->prog->NumNativeParameters = state->prog->NumParameters;
2215 state->prog->NumNativeAttributes = state->prog->NumAttributes;
2216 state->prog->NumNativeAddressRegs = state->prog->NumAddressRegs;