2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * NVIDIA fragment program parser.
32 * Regarding GL_NV_fragment_program:
34 * Portions of this software may use or implement intellectual
35 * property owned and licensed by NVIDIA Corporation. NVIDIA disclaims
36 * any and all warranties with respect to such intellectual property,
37 * including any use thereof or modifications thereto.
40 #include "main/glheader.h"
41 #include "main/context.h"
42 #include "main/imports.h"
43 #include "main/macros.h"
45 #include "prog_parameter.h"
46 #include "prog_print.h"
47 #include "prog_instruction.h"
48 #include "nvfragparse.h"
57 #define INPUT_1V_T 7 /* one source vector, plus textureId */
58 #define INPUT_3V_T 8 /* one source vector, plus textureId */
60 #define INPUT_1V_S 10 /* a string and a vector register */
63 #define OUTPUT_NONE 22
65 /* IRIX defines some of these */
72 /* Optional suffixes */
73 #define _R FLOAT32 /* float */
74 #define _H FLOAT16 /* half-float */
75 #define _X FIXED12 /* fixed */
76 #define _C 0x08 /* set cond codes */
77 #define _S 0x10 /* saturate, clamp result to [0,1] */
79 struct instruction_pattern
{
81 enum prog_opcode opcode
;
87 static const struct instruction_pattern Instructions
[] = {
88 { "ADD", OPCODE_ADD
, INPUT_2V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
89 { "COS", OPCODE_COS
, INPUT_1S
, OUTPUT_S
, _R
| _H
| _C
| _S
},
90 { "DDX", OPCODE_DDX
, INPUT_1V
, OUTPUT_V
, _R
| _H
| _C
| _S
},
91 { "DDY", OPCODE_DDY
, INPUT_1V
, OUTPUT_V
, _R
| _H
| _C
| _S
},
92 { "DP3", OPCODE_DP3
, INPUT_2V
, OUTPUT_S
, _R
| _H
| _X
| _C
| _S
},
93 { "DP4", OPCODE_DP4
, INPUT_2V
, OUTPUT_S
, _R
| _H
| _X
| _C
| _S
},
94 { "DST", OPCODE_DP4
, INPUT_2V
, OUTPUT_V
, _R
| _H
| _C
| _S
},
95 { "EX2", OPCODE_DP4
, INPUT_1S
, OUTPUT_S
, _R
| _H
| _C
| _S
},
96 { "FLR", OPCODE_FLR
, INPUT_1V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
97 { "FRC", OPCODE_FRC
, INPUT_1V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
98 { "KIL", OPCODE_KIL_NV
, INPUT_CC
, OUTPUT_NONE
, 0 },
99 { "LG2", OPCODE_LG2
, INPUT_1S
, OUTPUT_S
, _R
| _H
| _C
| _S
},
100 { "LIT", OPCODE_LIT
, INPUT_1V
, OUTPUT_V
, _R
| _H
| _C
| _S
},
101 { "LRP", OPCODE_LRP
, INPUT_3V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
102 { "MAD", OPCODE_MAD
, INPUT_3V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
103 { "MAX", OPCODE_MAX
, INPUT_2V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
104 { "MIN", OPCODE_MIN
, INPUT_2V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
105 { "MOV", OPCODE_MOV
, INPUT_1V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
106 { "MUL", OPCODE_MUL
, INPUT_2V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
107 { "PK2H", OPCODE_PK2H
, INPUT_1V
, OUTPUT_S
, 0 },
108 { "PK2US", OPCODE_PK2US
, INPUT_1V
, OUTPUT_S
, 0 },
109 { "PK4B", OPCODE_PK4B
, INPUT_1V
, OUTPUT_S
, 0 },
110 { "PK4UB", OPCODE_PK4UB
, INPUT_1V
, OUTPUT_S
, 0 },
111 { "POW", OPCODE_POW
, INPUT_2S
, OUTPUT_S
, _R
| _H
| _C
| _S
},
112 { "RCP", OPCODE_RCP
, INPUT_1S
, OUTPUT_S
, _R
| _H
| _C
| _S
},
113 { "RFL", OPCODE_RFL
, INPUT_2V
, OUTPUT_V
, _R
| _H
| _C
| _S
},
114 { "RSQ", OPCODE_RSQ
, INPUT_1S
, OUTPUT_S
, _R
| _H
| _C
| _S
},
115 { "SEQ", OPCODE_SEQ
, INPUT_2V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
116 { "SFL", OPCODE_SFL
, INPUT_2V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
117 { "SGE", OPCODE_SGE
, INPUT_2V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
118 { "SGT", OPCODE_SGT
, INPUT_2V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
119 { "SIN", OPCODE_SIN
, INPUT_1S
, OUTPUT_S
, _R
| _H
| _C
| _S
},
120 { "SLE", OPCODE_SLE
, INPUT_2V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
121 { "SLT", OPCODE_SLT
, INPUT_2V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
122 { "SNE", OPCODE_SNE
, INPUT_2V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
123 { "STR", OPCODE_STR
, INPUT_2V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
124 { "SUB", OPCODE_SUB
, INPUT_2V
, OUTPUT_V
, _R
| _H
| _X
| _C
| _S
},
125 { "TEX", OPCODE_TEX
, INPUT_1V_T
, OUTPUT_V
, _C
| _S
},
126 { "TXD", OPCODE_TXD
, INPUT_3V_T
, OUTPUT_V
, _C
| _S
},
127 { "TXP", OPCODE_TXP_NV
, INPUT_1V_T
, OUTPUT_V
, _C
| _S
},
128 { "UP2H", OPCODE_UP2H
, INPUT_1S
, OUTPUT_V
, _C
| _S
},
129 { "UP2US", OPCODE_UP2US
, INPUT_1S
, OUTPUT_V
, _C
| _S
},
130 { "UP4B", OPCODE_UP4B
, INPUT_1S
, OUTPUT_V
, _C
| _S
},
131 { "UP4UB", OPCODE_UP4UB
, INPUT_1S
, OUTPUT_V
, _C
| _S
},
132 { "X2D", OPCODE_X2D
, INPUT_3V
, OUTPUT_V
, _R
| _H
| _C
| _S
},
133 { "PRINT", OPCODE_PRINT
, INPUT_1V_S
, OUTPUT_NONE
, 0 },
134 { NULL
, (enum prog_opcode
) -1, 0, 0, 0 }
139 * Information needed or computed during parsing.
140 * Remember, we can't modify the target program object until we've
141 * _successfully_ parsed the program text.
144 struct gl_context
*ctx
;
145 const GLubyte
*start
; /* start of program string */
146 const GLubyte
*pos
; /* current position */
147 const GLubyte
*curLine
;
148 struct gl_fragment_program
*program
; /* current program */
150 struct gl_program_parameter_list
*parameters
;
152 GLuint numInst
; /* number of instructions parsed */
153 GLuint inputsRead
; /* bitmask of input registers used */
154 GLuint outputsWritten
; /* bitmask of 1 << FRAG_OUTPUT_* bits */
155 GLuint texturesUsed
[MAX_TEXTURE_IMAGE_UNITS
];
161 * Called whenever we find an error during parsing.
164 record_error(struct parse_state
*parseState
, const char *msg
, int lineNo
)
168 const GLubyte
*lineStr
;
169 lineStr
= _mesa_find_line_column(parseState
->start
,
170 parseState
->pos
, &line
, &column
);
171 _mesa_debug(parseState
->ctx
,
172 "nvfragparse.c(%d): line %d, column %d:%s (%s)\n",
173 lineNo
, line
, column
, (char *) lineStr
, msg
);
174 free((void *) lineStr
);
179 /* Check that no error was already recorded. Only record the first one. */
180 if (parseState
->ctx
->Program
.ErrorString
[0] == 0) {
181 _mesa_set_program_error(parseState
->ctx
,
182 parseState
->pos
- parseState
->start
,
188 #define RETURN_ERROR \
190 record_error(parseState, "Unexpected end of input.", __LINE__); \
194 #define RETURN_ERROR1(msg) \
196 record_error(parseState, msg, __LINE__); \
200 #define RETURN_ERROR2(msg1, msg2) \
203 sprintf(err, "%s %s", msg1, msg2); \
204 record_error(parseState, err, __LINE__); \
212 * Search a list of instruction structures for a match.
214 static struct instruction_pattern
215 MatchInstruction(const GLubyte
*token
)
217 const struct instruction_pattern
*inst
;
218 struct instruction_pattern result
;
221 result
.opcode
= MAX_OPCODE
; /* i.e. invalid instruction */
226 for (inst
= Instructions
; inst
->name
; inst
++) {
227 if (strncmp((const char *) token
, inst
->name
, 3) == 0) {
233 if (token
[i
] == 'R') {
234 result
.suffixes
|= _R
;
237 else if (token
[i
] == 'H') {
238 result
.suffixes
|= _H
;
241 else if (token
[i
] == 'X') {
242 result
.suffixes
|= _X
;
245 if (token
[i
] == 'C') {
246 result
.suffixes
|= _C
;
249 if (token
[i
] == '_' && token
[i
+1] == 'S' &&
250 token
[i
+2] == 'A' && token
[i
+3] == 'T') {
251 result
.suffixes
|= _S
;
263 /**********************************************************************/
266 static GLboolean
IsLetter(GLubyte b
)
268 return (b
>= 'a' && b
<= 'z') ||
269 (b
>= 'A' && b
<= 'Z') ||
275 static GLboolean
IsDigit(GLubyte b
)
277 return b
>= '0' && b
<= '9';
281 static GLboolean
IsWhitespace(GLubyte b
)
283 return b
== ' ' || b
== '\t' || b
== '\n' || b
== '\r';
288 * Starting at 'str' find the next token. A token can be an integer,
289 * an identifier or punctuation symbol.
290 * \return <= 0 we found an error, else, return number of characters parsed.
293 GetToken(struct parse_state
*parseState
, GLubyte
*token
)
295 const GLubyte
*str
= parseState
->pos
;
300 /* skip whitespace and comments */
301 while (str
[i
] && (IsWhitespace(str
[i
]) || str
[i
] == '#')) {
304 while (str
[i
] && (str
[i
] != '\n' && str
[i
] != '\r')) {
307 if (str
[i
] == '\n' || str
[i
] == '\r')
308 parseState
->curLine
= str
+ i
+ 1;
311 /* skip whitespace */
312 if (str
[i
] == '\n' || str
[i
] == '\r')
313 parseState
->curLine
= str
+ i
+ 1;
321 /* try matching an integer */
322 while (str
[i
] && IsDigit(str
[i
])) {
323 token
[j
++] = str
[i
++];
325 if (j
> 0 || !str
[i
]) {
330 /* try matching an identifier */
331 if (IsLetter(str
[i
])) {
332 while (str
[i
] && (IsLetter(str
[i
]) || IsDigit(str
[i
]))) {
333 token
[j
++] = str
[i
++];
339 /* punctuation character */
353 * Get next token from input stream and increment stream pointer past token.
356 Parse_Token(struct parse_state
*parseState
, GLubyte
*token
)
359 i
= GetToken(parseState
, token
);
361 parseState
->pos
+= (-i
);
364 parseState
->pos
+= i
;
370 * Get next token from input stream but don't increment stream pointer.
373 Peek_Token(struct parse_state
*parseState
, GLubyte
*token
)
376 i
= GetToken(parseState
, token
);
378 parseState
->pos
+= (-i
);
381 len
= (GLint
) strlen((const char *) token
);
382 parseState
->pos
+= (i
- len
);
387 /**********************************************************************/
389 static const char *InputRegisters
[MAX_NV_FRAGMENT_PROGRAM_INPUTS
+ 1] = {
390 "WPOS", "COL0", "COL1", "FOGC",
391 "TEX0", "TEX1", "TEX2", "TEX3", "TEX4", "TEX5", "TEX6", "TEX7", NULL
396 /**********************************************************************/
399 * Try to match 'pattern' as the next token after any whitespace/comments.
402 Parse_String(struct parse_state
*parseState
, const char *pattern
)
407 /* skip whitespace and comments */
408 while (IsWhitespace(*parseState
->pos
) || *parseState
->pos
== '#') {
409 if (*parseState
->pos
== '#') {
410 while (*parseState
->pos
&& (*parseState
->pos
!= '\n' && *parseState
->pos
!= '\r')) {
411 parseState
->pos
+= 1;
413 if (*parseState
->pos
== '\n' || *parseState
->pos
== '\r')
414 parseState
->curLine
= parseState
->pos
+ 1;
417 /* skip whitespace */
418 if (*parseState
->pos
== '\n' || *parseState
->pos
== '\r')
419 parseState
->curLine
= parseState
->pos
+ 1;
420 parseState
->pos
+= 1;
424 /* Try to match the pattern */
426 for (i
= 0; pattern
[i
]; i
++) {
427 if (*m
!= (GLubyte
) pattern
[i
])
433 return GL_TRUE
; /* success */
438 Parse_Identifier(struct parse_state
*parseState
, GLubyte
*ident
)
440 if (!Parse_Token(parseState
, ident
))
442 if (IsLetter(ident
[0]))
445 RETURN_ERROR1("Expected an identfier");
450 * Parse a floating point constant, or a defined symbol name.
452 * Output: number[0 .. 3] will get the value.
455 Parse_ScalarConstant(struct parse_state
*parseState
, GLfloat
*number
)
459 *number
= (GLfloat
) _mesa_strtof((const char *) parseState
->pos
, &end
);
461 if (end
&& end
> (char *) parseState
->pos
) {
463 parseState
->pos
= (GLubyte
*) end
;
470 /* should be an identifier */
472 const GLfloat
*constant
;
473 if (!Parse_Identifier(parseState
, ident
))
474 RETURN_ERROR1("Expected an identifier");
475 constant
= (GLfloat
*)_mesa_lookup_parameter_value(parseState
->parameters
,
477 (const char *) ident
);
478 /* XXX Check that it's a constant and not a parameter */
480 RETURN_ERROR1("Undefined symbol");
483 COPY_4V(number
, constant
);
492 * Parse a vector constant, one of:
495 * { float, float, float }
496 * { float, float, float, float }
499 Parse_VectorConstant(struct parse_state
*parseState
, GLfloat
*vec
)
501 /* "{" was already consumed */
503 ASSIGN_4V(vec
, 0.0, 0.0, 0.0, 1.0);
505 if (!Parse_ScalarConstant(parseState
, vec
+0)) /* X */
508 if (Parse_String(parseState
, "}")) {
512 if (!Parse_String(parseState
, ","))
513 RETURN_ERROR1("Expected comma in vector constant");
515 if (!Parse_ScalarConstant(parseState
, vec
+1)) /* Y */
518 if (Parse_String(parseState
, "}")) {
522 if (!Parse_String(parseState
, ","))
523 RETURN_ERROR1("Expected comma in vector constant");
525 if (!Parse_ScalarConstant(parseState
, vec
+2)) /* Z */
528 if (Parse_String(parseState
, "}")) {
532 if (!Parse_String(parseState
, ","))
533 RETURN_ERROR1("Expected comma in vector constant");
535 if (!Parse_ScalarConstant(parseState
, vec
+3)) /* W */
538 if (!Parse_String(parseState
, "}"))
539 RETURN_ERROR1("Expected closing brace in vector constant");
546 * Parse <number>, <varname> or {a, b, c, d}.
547 * Return number of values in the vector or scalar, or zero if parse error.
550 Parse_VectorOrScalarConstant(struct parse_state
*parseState
, GLfloat
*vec
)
552 if (Parse_String(parseState
, "{")) {
553 return Parse_VectorConstant(parseState
, vec
);
556 GLboolean b
= Parse_ScalarConstant(parseState
, vec
);
558 vec
[1] = vec
[2] = vec
[3] = vec
[0];
566 * Parse a texture image source:
567 * [TEX0 | TEX1 | .. | TEX15] , [1D | 2D | 3D | CUBE | RECT]
570 Parse_TextureImageId(struct parse_state
*parseState
,
571 GLubyte
*texUnit
, GLubyte
*texTarget
)
573 GLubyte imageSrc
[100];
576 if (!Parse_Token(parseState
, imageSrc
))
579 if (imageSrc
[0] != 'T' ||
580 imageSrc
[1] != 'E' ||
581 imageSrc
[2] != 'X') {
582 RETURN_ERROR1("Expected TEX# source");
584 unit
= atoi((const char *) imageSrc
+ 3);
585 if ((unit
< 0 || unit
>= MAX_TEXTURE_IMAGE_UNITS
) ||
586 (unit
== 0 && (imageSrc
[3] != '0' || imageSrc
[4] != 0))) {
587 RETURN_ERROR1("Invalied TEX# source index");
591 if (!Parse_String(parseState
, ","))
592 RETURN_ERROR1("Expected ,");
594 if (Parse_String(parseState
, "1D")) {
595 *texTarget
= TEXTURE_1D_INDEX
;
597 else if (Parse_String(parseState
, "2D")) {
598 *texTarget
= TEXTURE_2D_INDEX
;
600 else if (Parse_String(parseState
, "3D")) {
601 *texTarget
= TEXTURE_3D_INDEX
;
603 else if (Parse_String(parseState
, "CUBE")) {
604 *texTarget
= TEXTURE_CUBE_INDEX
;
606 else if (Parse_String(parseState
, "RECT")) {
607 *texTarget
= TEXTURE_RECT_INDEX
;
610 RETURN_ERROR1("Invalid texture target token");
613 /* update record of referenced texture units */
614 parseState
->texturesUsed
[*texUnit
] |= (1 << *texTarget
);
615 if (_mesa_bitcount(parseState
->texturesUsed
[*texUnit
]) > 1) {
616 RETURN_ERROR1("Only one texture target can be used per texture unit.");
624 * Parse a scalar suffix like .x, .y, .z or .w or parse a swizzle suffix
625 * like .wxyz, .xxyy, etc and return the swizzle indexes.
628 Parse_SwizzleSuffix(const GLubyte
*token
, GLuint swizzle
[4])
631 /* single letter swizzle (scalar) */
633 ASSIGN_4V(swizzle
, 0, 0, 0, 0);
634 else if (token
[0] == 'y')
635 ASSIGN_4V(swizzle
, 1, 1, 1, 1);
636 else if (token
[0] == 'z')
637 ASSIGN_4V(swizzle
, 2, 2, 2, 2);
638 else if (token
[0] == 'w')
639 ASSIGN_4V(swizzle
, 3, 3, 3, 3);
644 /* 4-component swizzle (vector) */
646 for (k
= 0; k
< 4 && token
[k
]; k
++) {
649 else if (token
[k
] == 'y')
651 else if (token
[k
] == 'z')
653 else if (token
[k
] == 'w')
666 Parse_CondCodeMask(struct parse_state
*parseState
,
667 struct prog_dst_register
*dstReg
)
669 if (Parse_String(parseState
, "EQ"))
670 dstReg
->CondMask
= COND_EQ
;
671 else if (Parse_String(parseState
, "GE"))
672 dstReg
->CondMask
= COND_GE
;
673 else if (Parse_String(parseState
, "GT"))
674 dstReg
->CondMask
= COND_GT
;
675 else if (Parse_String(parseState
, "LE"))
676 dstReg
->CondMask
= COND_LE
;
677 else if (Parse_String(parseState
, "LT"))
678 dstReg
->CondMask
= COND_LT
;
679 else if (Parse_String(parseState
, "NE"))
680 dstReg
->CondMask
= COND_NE
;
681 else if (Parse_String(parseState
, "TR"))
682 dstReg
->CondMask
= COND_TR
;
683 else if (Parse_String(parseState
, "FL"))
684 dstReg
->CondMask
= COND_FL
;
686 RETURN_ERROR1("Invalid condition code mask");
688 /* look for optional .xyzw swizzle */
689 if (Parse_String(parseState
, ".")) {
693 if (!Parse_Token(parseState
, token
)) /* get xyzw suffix */
696 if (!Parse_SwizzleSuffix(token
, swz
))
697 RETURN_ERROR1("Invalid swizzle suffix");
699 dstReg
->CondSwizzle
= MAKE_SWIZZLE4(swz
[0], swz
[1], swz
[2], swz
[3]);
707 * Parse a temporary register: Rnn or Hnn
710 Parse_TempReg(struct parse_state
*parseState
, GLint
*tempRegNum
)
714 /* Should be 'R##' or 'H##' */
715 if (!Parse_Token(parseState
, token
))
717 if (token
[0] != 'R' && token
[0] != 'H')
718 RETURN_ERROR1("Expected R## or H##");
720 if (IsDigit(token
[1])) {
721 GLint reg
= atoi((const char *) (token
+ 1));
724 if (reg
>= MAX_NV_FRAGMENT_PROGRAM_TEMPS
)
725 RETURN_ERROR1("Invalid temporary register name");
729 RETURN_ERROR1("Invalid temporary register name");
737 * Parse a write-only dummy register: RC or HC.
740 Parse_DummyReg(struct parse_state
*parseState
, GLint
*regNum
)
742 if (Parse_String(parseState
, "RC")) {
745 else if (Parse_String(parseState
, "HC")) {
749 RETURN_ERROR1("Invalid write-only register name");
757 * Parse a program local parameter register "p[##]"
760 Parse_ProgramParamReg(struct parse_state
*parseState
, GLint
*regNum
)
764 if (!Parse_String(parseState
, "p["))
765 RETURN_ERROR1("Expected p[");
767 if (!Parse_Token(parseState
, token
))
770 if (IsDigit(token
[0])) {
771 /* a numbered program parameter register */
772 GLint reg
= atoi((const char *) token
);
773 if (reg
>= MAX_NV_FRAGMENT_PROGRAM_PARAMS
)
774 RETURN_ERROR1("Invalid constant program number");
781 if (!Parse_String(parseState
, "]"))
782 RETURN_ERROR1("Expected ]");
789 * Parse f[name] - fragment input register
792 Parse_FragReg(struct parse_state
*parseState
, GLint
*tempRegNum
)
798 if (!Parse_String(parseState
, "f["))
799 RETURN_ERROR1("Expected f[");
801 /* get <name> and look for match */
802 if (!Parse_Token(parseState
, token
)) {
805 for (j
= 0; InputRegisters
[j
]; j
++) {
806 if (strcmp((const char *) token
, InputRegisters
[j
]) == 0) {
808 parseState
->inputsRead
|= (1 << j
);
812 if (!InputRegisters
[j
]) {
813 /* unknown input register label */
814 RETURN_ERROR2("Invalid register name", token
);
818 if (!Parse_String(parseState
, "]"))
819 RETURN_ERROR1("Expected ]");
826 Parse_OutputReg(struct parse_state
*parseState
, GLint
*outputRegNum
)
831 if (!Parse_String(parseState
, "o["))
832 RETURN_ERROR1("Expected o[");
834 /* Get output reg name */
835 if (!Parse_Token(parseState
, token
))
838 /* try to match an output register name */
839 if (strcmp((char *) token
, "COLR") == 0 ||
840 strcmp((char *) token
, "COLH") == 0) {
841 /* note that we don't distinguish between COLR and COLH */
842 *outputRegNum
= FRAG_RESULT_COLOR
;
843 parseState
->outputsWritten
|= (1 << FRAG_RESULT_COLOR
);
845 else if (strcmp((char *) token
, "DEPR") == 0) {
846 *outputRegNum
= FRAG_RESULT_DEPTH
;
847 parseState
->outputsWritten
|= (1 << FRAG_RESULT_DEPTH
);
850 RETURN_ERROR1("Invalid output register name");
854 if (!Parse_String(parseState
, "]"))
855 RETURN_ERROR1("Expected ]");
862 Parse_MaskedDstReg(struct parse_state
*parseState
,
863 struct prog_dst_register
*dstReg
)
868 /* Dst reg can be R<n>, H<n>, o[n], RC or HC */
869 if (!Peek_Token(parseState
, token
))
872 if (strcmp((const char *) token
, "RC") == 0 ||
873 strcmp((const char *) token
, "HC") == 0) {
874 /* a write-only register */
875 dstReg
->File
= PROGRAM_WRITE_ONLY
;
876 if (!Parse_DummyReg(parseState
, &idx
))
880 else if (token
[0] == 'R' || token
[0] == 'H') {
881 /* a temporary register */
882 dstReg
->File
= PROGRAM_TEMPORARY
;
883 if (!Parse_TempReg(parseState
, &idx
))
887 else if (token
[0] == 'o') {
888 /* an output register */
889 dstReg
->File
= PROGRAM_OUTPUT
;
890 if (!Parse_OutputReg(parseState
, &idx
))
895 RETURN_ERROR1("Invalid destination register name");
898 /* Parse optional write mask */
899 if (Parse_String(parseState
, ".")) {
903 if (!Parse_Token(parseState
, token
)) /* get xyzw writemask */
906 dstReg
->WriteMask
= 0;
908 if (token
[k
] == 'x') {
909 dstReg
->WriteMask
|= WRITEMASK_X
;
912 if (token
[k
] == 'y') {
913 dstReg
->WriteMask
|= WRITEMASK_Y
;
916 if (token
[k
] == 'z') {
917 dstReg
->WriteMask
|= WRITEMASK_Z
;
920 if (token
[k
] == 'w') {
921 dstReg
->WriteMask
|= WRITEMASK_W
;
925 RETURN_ERROR1("Invalid writemask character");
930 dstReg
->WriteMask
= WRITEMASK_XYZW
;
933 /* optional condition code mask */
934 if (Parse_String(parseState
, "(")) {
935 /* ("EQ" | "GE" | "GT" | "LE" | "LT" | "NE" | "TR" | "FL".x|y|z|w) */
936 /* ("EQ" | "GE" | "GT" | "LE" | "LT" | "NE" | "TR" | "FL".[xyzw]) */
937 if (!Parse_CondCodeMask(parseState
, dstReg
))
940 if (!Parse_String(parseState
, ")")) /* consume ")" */
941 RETURN_ERROR1("Expected )");
946 /* no cond code mask */
947 dstReg
->CondMask
= COND_TR
;
948 dstReg
->CondSwizzle
= SWIZZLE_NOOP
;
955 * Parse a vector source (register, constant, etc):
956 * <vectorSrc> ::= <absVectorSrc>
958 * <absVectorSrc> ::= <negate> "|" <baseVectorSrc> "|"
961 Parse_VectorSrc(struct parse_state
*parseState
,
962 struct prog_src_register
*srcReg
)
967 GLuint negateBase
, negateAbs
;
970 * First, take care of +/- and absolute value stuff.
972 if (Parse_String(parseState
, "-"))
974 else if (Parse_String(parseState
, "+"))
977 if (Parse_String(parseState
, "|")) {
978 srcReg
->Abs
= GL_TRUE
;
979 negateAbs
= (sign
< 0.0F
) ? NEGATE_XYZW
: NEGATE_NONE
;
981 if (Parse_String(parseState
, "-"))
982 negateBase
= NEGATE_XYZW
;
983 else if (Parse_String(parseState
, "+"))
984 negateBase
= NEGATE_NONE
;
986 negateBase
= NEGATE_NONE
;
989 srcReg
->Abs
= GL_FALSE
;
990 negateAbs
= NEGATE_NONE
;
991 negateBase
= (sign
< 0.0F
) ? NEGATE_XYZW
: NEGATE_NONE
;
994 srcReg
->Negate
= srcReg
->Abs
? negateAbs
: negateBase
;
996 /* This should be the real src vector/register name */
997 if (!Peek_Token(parseState
, token
))
1000 /* Src reg can be Rn, Hn, f[n], p[n], a named parameter, a scalar
1001 * literal or vector literal.
1003 if (token
[0] == 'R' || token
[0] == 'H') {
1004 srcReg
->File
= PROGRAM_TEMPORARY
;
1005 if (!Parse_TempReg(parseState
, &idx
))
1007 srcReg
->Index
= idx
;
1009 else if (token
[0] == 'f') {
1010 /* XXX this might be an identifier! */
1011 srcReg
->File
= PROGRAM_INPUT
;
1012 if (!Parse_FragReg(parseState
, &idx
))
1014 srcReg
->Index
= idx
;
1016 else if (token
[0] == 'p') {
1017 /* XXX this might be an identifier! */
1018 srcReg
->File
= PROGRAM_LOCAL_PARAM
;
1019 if (!Parse_ProgramParamReg(parseState
, &idx
))
1021 srcReg
->Index
= idx
;
1023 else if (IsLetter(token
[0])){
1026 if (!Parse_Identifier(parseState
, ident
))
1028 paramIndex
= _mesa_lookup_parameter_index(parseState
->parameters
,
1029 -1, (const char *) ident
);
1030 if (paramIndex
< 0) {
1031 RETURN_ERROR2("Undefined constant or parameter: ", ident
);
1033 srcReg
->File
= PROGRAM_NAMED_PARAM
;
1034 srcReg
->Index
= paramIndex
;
1036 else if (IsDigit(token
[0]) || token
[0] == '-' || token
[0] == '+' || token
[0] == '.'){
1037 /* literal scalar constant */
1040 if (!Parse_ScalarConstant(parseState
, values
))
1042 paramIndex
= _mesa_add_unnamed_constant(parseState
->parameters
,
1043 (gl_constant_value
*) values
,
1045 srcReg
->File
= PROGRAM_NAMED_PARAM
;
1046 srcReg
->Index
= paramIndex
;
1048 else if (token
[0] == '{'){
1049 /* literal vector constant */
1052 (void) Parse_String(parseState
, "{");
1053 if (!Parse_VectorConstant(parseState
, values
))
1055 paramIndex
= _mesa_add_unnamed_constant(parseState
->parameters
,
1056 (gl_constant_value
*) values
,
1058 srcReg
->File
= PROGRAM_NAMED_PARAM
;
1059 srcReg
->Index
= paramIndex
;
1062 RETURN_ERROR2("Invalid source register name", token
);
1065 /* init swizzle fields */
1066 srcReg
->Swizzle
= SWIZZLE_NOOP
;
1068 /* Look for optional swizzle suffix */
1069 if (Parse_String(parseState
, ".")) {
1072 if (!Parse_Token(parseState
, token
))
1075 if (!Parse_SwizzleSuffix(token
, swz
))
1076 RETURN_ERROR1("Invalid swizzle suffix");
1078 srcReg
->Swizzle
= MAKE_SWIZZLE4(swz
[0], swz
[1], swz
[2], swz
[3]);
1081 /* Finish absolute value */
1082 if (srcReg
->Abs
&& !Parse_String(parseState
, "|")) {
1083 RETURN_ERROR1("Expected |");
1091 Parse_ScalarSrcReg(struct parse_state
*parseState
,
1092 struct prog_src_register
*srcReg
)
1095 GLfloat sign
= 1.0F
;
1096 GLboolean needSuffix
= GL_TRUE
;
1098 GLuint negateBase
, negateAbs
;
1101 * First, take care of +/- and absolute value stuff.
1103 if (Parse_String(parseState
, "-"))
1105 else if (Parse_String(parseState
, "+"))
1108 if (Parse_String(parseState
, "|")) {
1109 srcReg
->Abs
= GL_TRUE
;
1110 negateAbs
= (sign
< 0.0F
) ? NEGATE_XYZW
: NEGATE_NONE
;
1112 if (Parse_String(parseState
, "-"))
1113 negateBase
= NEGATE_XYZW
;
1114 else if (Parse_String(parseState
, "+"))
1115 negateBase
= NEGATE_NONE
;
1117 negateBase
= NEGATE_NONE
;
1120 srcReg
->Abs
= GL_FALSE
;
1121 negateAbs
= NEGATE_NONE
;
1122 negateBase
= (sign
< 0.0F
) ? NEGATE_XYZW
: NEGATE_NONE
;
1125 srcReg
->Negate
= srcReg
->Abs
? negateAbs
: negateBase
;
1127 if (!Peek_Token(parseState
, token
))
1130 /* Src reg can be R<n>, H<n> or a named fragment attrib */
1131 if (token
[0] == 'R' || token
[0] == 'H') {
1132 srcReg
->File
= PROGRAM_TEMPORARY
;
1133 if (!Parse_TempReg(parseState
, &idx
))
1135 srcReg
->Index
= idx
;
1137 else if (token
[0] == 'f') {
1138 srcReg
->File
= PROGRAM_INPUT
;
1139 if (!Parse_FragReg(parseState
, &idx
))
1141 srcReg
->Index
= idx
;
1143 else if (token
[0] == '{') {
1144 /* vector literal */
1147 (void) Parse_String(parseState
, "{");
1148 if (!Parse_VectorConstant(parseState
, values
))
1150 paramIndex
= _mesa_add_unnamed_constant(parseState
->parameters
,
1151 (gl_constant_value
*) values
,
1153 srcReg
->File
= PROGRAM_NAMED_PARAM
;
1154 srcReg
->Index
= paramIndex
;
1156 else if (IsLetter(token
[0])){
1157 /* named param/constant */
1160 if (!Parse_Identifier(parseState
, ident
))
1162 paramIndex
= _mesa_lookup_parameter_index(parseState
->parameters
,
1163 -1, (const char *) ident
);
1164 if (paramIndex
< 0) {
1165 RETURN_ERROR2("Undefined constant or parameter: ", ident
);
1167 srcReg
->File
= PROGRAM_NAMED_PARAM
;
1168 srcReg
->Index
= paramIndex
;
1170 else if (IsDigit(token
[0])) {
1171 /* scalar literal */
1174 if (!Parse_ScalarConstant(parseState
, values
))
1176 paramIndex
= _mesa_add_unnamed_constant(parseState
->parameters
,
1177 (gl_constant_value
*) values
,
1179 srcReg
->Index
= paramIndex
;
1180 srcReg
->File
= PROGRAM_NAMED_PARAM
;
1181 needSuffix
= GL_FALSE
;
1184 RETURN_ERROR2("Invalid scalar source argument", token
);
1187 srcReg
->Swizzle
= 0;
1189 /* parse .[xyzw] suffix */
1190 if (!Parse_String(parseState
, "."))
1191 RETURN_ERROR1("Expected .");
1193 if (!Parse_Token(parseState
, token
))
1196 if (token
[0] == 'x' && token
[1] == 0) {
1197 srcReg
->Swizzle
= 0;
1199 else if (token
[0] == 'y' && token
[1] == 0) {
1200 srcReg
->Swizzle
= 1;
1202 else if (token
[0] == 'z' && token
[1] == 0) {
1203 srcReg
->Swizzle
= 2;
1205 else if (token
[0] == 'w' && token
[1] == 0) {
1206 srcReg
->Swizzle
= 3;
1209 RETURN_ERROR1("Invalid scalar source suffix");
1213 /* Finish absolute value */
1214 if (srcReg
->Abs
&& !Parse_String(parseState
, "|")) {
1215 RETURN_ERROR1("Expected |");
1223 Parse_PrintInstruction(struct parse_state
*parseState
,
1224 struct prog_instruction
*inst
)
1231 /* The first argument is a literal string 'just like this' */
1232 if (!Parse_String(parseState
, "'"))
1233 RETURN_ERROR1("Expected '");
1235 str
= parseState
->pos
;
1236 for (len
= 0; str
[len
] != '\''; len
++) /* find closing quote */
1238 parseState
->pos
+= len
+ 1;
1239 msg
= malloc(len
+ 1);
1241 memcpy(msg
, str
, len
);
1245 if (Parse_String(parseState
, ",")) {
1246 /* got an optional register to print */
1248 GetToken(parseState
, token
);
1249 if (token
[0] == 'o') {
1251 if (!Parse_OutputReg(parseState
, &idx
))
1253 inst
->SrcReg
[0].Index
= idx
;
1254 inst
->SrcReg
[0].File
= PROGRAM_OUTPUT
;
1258 if (!Parse_VectorSrc(parseState
, &inst
->SrcReg
[0]))
1263 inst
->SrcReg
[0].File
= PROGRAM_UNDEFINED
;
1266 inst
->SrcReg
[0].Swizzle
= SWIZZLE_NOOP
;
1267 inst
->SrcReg
[0].Abs
= GL_FALSE
;
1268 inst
->SrcReg
[0].Negate
= NEGATE_NONE
;
1275 Parse_InstructionSequence(struct parse_state
*parseState
,
1276 struct prog_instruction program
[])
1279 struct prog_instruction
*inst
= program
+ parseState
->numInst
;
1280 struct instruction_pattern instMatch
;
1283 /* Initialize the instruction */
1284 _mesa_init_instructions(inst
, 1);
1286 /* special instructions */
1287 if (Parse_String(parseState
, "DEFINE")) {
1289 GLfloat value
[7]; /* yes, 7 to be safe */
1290 if (!Parse_Identifier(parseState
, id
))
1292 /* XXX make sure id is not a reserved identifer, like R9 */
1293 if (!Parse_String(parseState
, "="))
1294 RETURN_ERROR1("Expected =");
1295 if (!Parse_VectorOrScalarConstant(parseState
, value
))
1297 if (!Parse_String(parseState
, ";"))
1298 RETURN_ERROR1("Expected ;");
1299 if (_mesa_lookup_parameter_index(parseState
->parameters
,
1300 -1, (const char *) id
) >= 0) {
1301 RETURN_ERROR2(id
, "already defined");
1303 _mesa_add_named_parameter(parseState
->parameters
,
1305 (gl_constant_value
*) value
);
1307 else if (Parse_String(parseState
, "DECLARE")) {
1309 GLfloat value
[7] = {0, 0, 0, 0, 0, 0, 0}; /* yes, to be safe */
1310 if (!Parse_Identifier(parseState
, id
))
1312 /* XXX make sure id is not a reserved identifer, like R9 */
1313 if (Parse_String(parseState
, "=")) {
1314 if (!Parse_VectorOrScalarConstant(parseState
, value
))
1317 if (!Parse_String(parseState
, ";"))
1318 RETURN_ERROR1("Expected ;");
1319 if (_mesa_lookup_parameter_index(parseState
->parameters
,
1320 -1, (const char *) id
) >= 0) {
1321 RETURN_ERROR2(id
, "already declared");
1323 _mesa_add_named_parameter(parseState
->parameters
,
1325 (gl_constant_value
*) value
);
1327 else if (Parse_String(parseState
, "END")) {
1328 inst
->Opcode
= OPCODE_END
;
1329 parseState
->numInst
++;
1330 if (Parse_Token(parseState
, token
)) {
1331 RETURN_ERROR1("Code after END opcode.");
1336 /* general/arithmetic instruction */
1339 if (!Parse_Token(parseState
, token
)) {
1340 RETURN_ERROR1("Missing END instruction.");
1343 /* try to find matching instuction */
1344 instMatch
= MatchInstruction(token
);
1345 if (instMatch
.opcode
>= MAX_OPCODE
) {
1346 /* bad instruction name */
1347 RETURN_ERROR2("Unexpected token: ", token
);
1350 inst
->Opcode
= instMatch
.opcode
;
1351 inst
->Precision
= instMatch
.suffixes
& (_R
| _H
| _X
);
1352 inst
->SaturateMode
= (instMatch
.suffixes
& (_S
))
1353 ? SATURATE_ZERO_ONE
: SATURATE_OFF
;
1354 inst
->CondUpdate
= (instMatch
.suffixes
& (_C
)) ? GL_TRUE
: GL_FALSE
;
1357 * parse the input and output operands
1359 if (instMatch
.outputs
== OUTPUT_S
|| instMatch
.outputs
== OUTPUT_V
) {
1360 if (!Parse_MaskedDstReg(parseState
, &inst
->DstReg
))
1362 if (!Parse_String(parseState
, ","))
1363 RETURN_ERROR1("Expected ,");
1365 else if (instMatch
.outputs
== OUTPUT_NONE
) {
1366 if (instMatch
.opcode
== OPCODE_KIL_NV
) {
1367 /* This is a little weird, the cond code info is in
1368 * the dest register.
1370 if (!Parse_CondCodeMask(parseState
, &inst
->DstReg
))
1374 ASSERT(instMatch
.opcode
== OPCODE_PRINT
);
1378 if (instMatch
.inputs
== INPUT_1V
) {
1379 if (!Parse_VectorSrc(parseState
, &inst
->SrcReg
[0]))
1382 else if (instMatch
.inputs
== INPUT_2V
) {
1383 if (!Parse_VectorSrc(parseState
, &inst
->SrcReg
[0]))
1385 if (!Parse_String(parseState
, ","))
1386 RETURN_ERROR1("Expected ,");
1387 if (!Parse_VectorSrc(parseState
, &inst
->SrcReg
[1]))
1390 else if (instMatch
.inputs
== INPUT_3V
) {
1391 if (!Parse_VectorSrc(parseState
, &inst
->SrcReg
[0]))
1393 if (!Parse_String(parseState
, ","))
1394 RETURN_ERROR1("Expected ,");
1395 if (!Parse_VectorSrc(parseState
, &inst
->SrcReg
[1]))
1397 if (!Parse_String(parseState
, ","))
1398 RETURN_ERROR1("Expected ,");
1399 if (!Parse_VectorSrc(parseState
, &inst
->SrcReg
[2]))
1402 else if (instMatch
.inputs
== INPUT_1S
) {
1403 if (!Parse_ScalarSrcReg(parseState
, &inst
->SrcReg
[0]))
1406 else if (instMatch
.inputs
== INPUT_2S
) {
1407 if (!Parse_ScalarSrcReg(parseState
, &inst
->SrcReg
[0]))
1409 if (!Parse_String(parseState
, ","))
1410 RETURN_ERROR1("Expected ,");
1411 if (!Parse_ScalarSrcReg(parseState
, &inst
->SrcReg
[1]))
1414 else if (instMatch
.inputs
== INPUT_CC
) {
1417 else if (instMatch
.inputs
== INPUT_1V_T
) {
1419 if (!Parse_VectorSrc(parseState
, &inst
->SrcReg
[0]))
1421 if (!Parse_String(parseState
, ","))
1422 RETURN_ERROR1("Expected ,");
1423 if (!Parse_TextureImageId(parseState
, &unit
, &idx
))
1425 inst
->TexSrcUnit
= unit
;
1426 inst
->TexSrcTarget
= idx
;
1428 else if (instMatch
.inputs
== INPUT_3V_T
) {
1430 if (!Parse_VectorSrc(parseState
, &inst
->SrcReg
[0]))
1432 if (!Parse_String(parseState
, ","))
1433 RETURN_ERROR1("Expected ,");
1434 if (!Parse_VectorSrc(parseState
, &inst
->SrcReg
[1]))
1436 if (!Parse_String(parseState
, ","))
1437 RETURN_ERROR1("Expected ,");
1438 if (!Parse_VectorSrc(parseState
, &inst
->SrcReg
[2]))
1440 if (!Parse_String(parseState
, ","))
1441 RETURN_ERROR1("Expected ,");
1442 if (!Parse_TextureImageId(parseState
, &unit
, &idx
))
1444 inst
->TexSrcUnit
= unit
;
1445 inst
->TexSrcTarget
= idx
;
1447 else if (instMatch
.inputs
== INPUT_1V_S
) {
1448 if (!Parse_PrintInstruction(parseState
, inst
))
1452 /* end of statement semicolon */
1453 if (!Parse_String(parseState
, ";"))
1454 RETURN_ERROR1("Expected ;");
1456 parseState
->numInst
++;
1458 if (parseState
->numInst
>= MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS
)
1459 RETURN_ERROR1("Program too long");
1468 * Parse/compile the 'str' returning the compiled 'program'.
1469 * ctx->Program.ErrorPos will be -1 if successful. Otherwise, ErrorPos
1470 * indicates the position of the error in 'str'.
1473 _mesa_parse_nv_fragment_program(struct gl_context
*ctx
, GLenum dstTarget
,
1474 const GLubyte
*str
, GLsizei len
,
1475 struct gl_fragment_program
*program
)
1477 struct parse_state parseState
;
1478 struct prog_instruction instBuffer
[MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS
];
1479 struct prog_instruction
*newInst
;
1481 GLubyte
*programString
;
1483 /* Make a null-terminated copy of the program string */
1484 programString
= malloc(len
+ 1);
1485 if (!programString
) {
1486 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glLoadProgramNV");
1489 memcpy(programString
, str
, len
);
1490 programString
[len
] = 0;
1492 /* Get ready to parse */
1493 memset(&parseState
, 0, sizeof(struct parse_state
));
1494 parseState
.ctx
= ctx
;
1495 parseState
.start
= programString
;
1496 parseState
.program
= program
;
1497 parseState
.numInst
= 0;
1498 parseState
.curLine
= programString
;
1499 parseState
.parameters
= _mesa_new_parameter_list();
1501 /* Reset error state */
1502 _mesa_set_program_error(ctx
, -1, NULL
);
1504 /* check the program header */
1505 if (strncmp((const char *) programString
, "!!FP1.0", 7) == 0) {
1506 target
= GL_FRAGMENT_PROGRAM_NV
;
1507 parseState
.pos
= programString
+ 7;
1509 else if (strncmp((const char *) programString
, "!!FCP1.0", 8) == 0) {
1510 /* fragment / register combiner program - not supported */
1511 _mesa_set_program_error(ctx
, 0, "Invalid fragment program header");
1512 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glLoadProgramNV(bad header)");
1516 /* invalid header */
1517 _mesa_set_program_error(ctx
, 0, "Invalid fragment program header");
1518 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glLoadProgramNV(bad header)");
1522 /* make sure target and header match */
1523 if (target
!= dstTarget
) {
1524 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1525 "glLoadProgramNV(target mismatch 0x%x != 0x%x)",
1530 if (Parse_InstructionSequence(&parseState
, instBuffer
)) {
1532 /* successful parse! */
1534 if (parseState
.outputsWritten
== 0) {
1535 /* must write at least one output! */
1536 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1537 "Invalid fragment program - no outputs written.");
1541 /* copy the compiled instructions */
1542 assert(parseState
.numInst
<= MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS
);
1543 newInst
= _mesa_alloc_instructions(parseState
.numInst
);
1545 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glLoadProgramNV");
1546 return; /* out of memory */
1548 _mesa_copy_instructions(newInst
, instBuffer
, parseState
.numInst
);
1550 /* install the program */
1551 program
->Base
.Target
= target
;
1552 free(program
->Base
.String
);
1553 program
->Base
.String
= programString
;
1554 program
->Base
.Format
= GL_PROGRAM_FORMAT_ASCII_ARB
;
1555 free(program
->Base
.Instructions
);
1556 program
->Base
.Instructions
= newInst
;
1557 program
->Base
.NumInstructions
= parseState
.numInst
;
1558 program
->Base
.InputsRead
= parseState
.inputsRead
;
1559 program
->Base
.OutputsWritten
= parseState
.outputsWritten
;
1560 for (u
= 0; u
< ctx
->Const
.MaxTextureImageUnits
; u
++)
1561 program
->Base
.TexturesUsed
[u
] = parseState
.texturesUsed
[u
];
1563 /* save program parameters */
1564 program
->Base
.Parameters
= parseState
.parameters
;
1566 /* allocate registers for declared program parameters */
1568 _mesa_assign_program_registers(&(program
->SymbolTable
));
1572 printf("--- glLoadProgramNV(%d) result ---\n", program
->Base
.Id
);
1573 _mesa_fprint_program_opt(stdout
, &program
->Base
, PROG_PRINT_NV
, 0);
1574 printf("----------------------------------\n");
1579 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glLoadProgramNV");
1580 /* NOTE: _mesa_set_program_error would have been called already */
1586 _mesa_nv_fragment_input_register_name(GLuint i
)
1588 ASSERT(i
< MAX_NV_FRAGMENT_PROGRAM_INPUTS
);
1589 return InputRegisters
[i
];