2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 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.
28 * \file arbfragparse.c
29 * ARB_fragment_program parser.
39 #include "arbprogparse.h"
40 #include "arbfragparse.h"
43 _mesa_debug_fp_inst(GLint num
, struct fp_instruction
*fp
)
47 static const char *opcode_string
[] = {
48 "ABS", /* ARB_f_p only */
50 "CMP", /* ARB_f_p only */
52 "DDX", /* NV_f_p only */
53 "DDY", /* NV_f_p only */
56 "DPH", /* ARB_f_p only */
58 "END", /* private opcode */
62 "KIL", /* ARB_f_p only */
63 "KIL_NV", /* NV_f_p only */
72 "PK2H", /* NV_f_p only */
73 "PK2US", /* NV_f_p only */
74 "PK4B", /* NV_f_p only */
75 "PK4UB", /* NV_f_p only */
77 "PRINT", /* Mesa only */
79 "RFL", /* NV_f_p only */
81 "SCS", /* ARB_f_p only */
82 "SEQ", /* NV_f_p only */
83 "SFL", /* NV_f_p only */
84 "SGE", /* NV_f_p only */
85 "SGT", /* NV_f_p only */
87 "SLE", /* NV_f_p only */
89 "SNE", /* NV_f_p only */
90 "STR", /* NV_f_p only */
92 "SWZ", /* ARB_f_p only */
94 "TXB", /* ARB_f_p only */
95 "TXD", /* NV_f_p only */
96 "TXP", /* ARB_f_p only */
97 "TXP_NV", /* NV_f_p only */
98 "UP2H", /* NV_f_p only */
99 "UP2US", /* NV_f_p only */
100 "UP4B", /* NV_f_p only */
101 "UP4UB", /* NV_f_p only */
102 "X2D", /* NV_f_p only - 2d mat mul */
103 "XPD", /* ARB_f_p only - cross product */
106 static const char *file_string
[] = {
118 static const char swz
[] = "xyzw01??";
120 for (a
=0; a
<num
; a
++) {
121 _mesa_printf("%s", opcode_string
[fp
[a
].Opcode
]);
124 _mesa_printf("_SAT");
126 if (fp
[a
].DstReg
.File
!= 0xf) {
127 if (fp
[a
].DstReg
.WriteMask
!= 0xf ||
128 fp
[a
].SrcReg
[0].NegateBase
)
129 _mesa_printf(" %s[%d].%s%s%s%s ", file_string
[fp
[a
].DstReg
.File
], fp
[a
].DstReg
.Index
,
130 GET_BIT(fp
[a
].DstReg
.WriteMask
, 0) ? "x" : "",
131 GET_BIT(fp
[a
].DstReg
.WriteMask
, 1) ? "y" : "",
132 GET_BIT(fp
[a
].DstReg
.WriteMask
, 2) ? "z" : "",
133 GET_BIT(fp
[a
].DstReg
.WriteMask
, 3) ? "w" : "");
135 _mesa_printf(" %s[%d] ", file_string
[fp
[a
].DstReg
.File
], fp
[a
].DstReg
.Index
);
138 if (fp
[a
].SrcReg
[0].File
!= 0xf) {
139 if (fp
[a
].SrcReg
[0].Swizzle
!= SWIZZLE_NOOP
||
140 fp
[a
].SrcReg
[0].NegateBase
)
141 _mesa_printf("%s[%d].%s%c%c%c%c ", file_string
[fp
[a
].SrcReg
[0].File
], fp
[a
].SrcReg
[0].Index
,
142 fp
[a
].SrcReg
[0].NegateBase
? "-" : "",
143 swz
[GET_SWZ(fp
[a
].SrcReg
[0].Swizzle
, 0)],
144 swz
[GET_SWZ(fp
[a
].SrcReg
[0].Swizzle
, 1)],
145 swz
[GET_SWZ(fp
[a
].SrcReg
[0].Swizzle
, 2)],
146 swz
[GET_SWZ(fp
[a
].SrcReg
[0].Swizzle
, 3)]);
148 _mesa_printf("%s[%d] ", file_string
[fp
[a
].SrcReg
[0].File
], fp
[a
].SrcReg
[0].Index
);
151 if (fp
[a
].SrcReg
[1].File
!= 0xf) {
152 if (fp
[a
].SrcReg
[1].Swizzle
!= SWIZZLE_NOOP
||
153 fp
[a
].SrcReg
[1].NegateBase
)
154 _mesa_printf("%s[%d].%s%c%c%c%c ", file_string
[fp
[a
].SrcReg
[1].File
], fp
[a
].SrcReg
[1].Index
,
155 fp
[a
].SrcReg
[1].NegateBase
? "-" : "",
156 swz
[GET_SWZ(fp
[a
].SrcReg
[1].Swizzle
, 0)],
157 swz
[GET_SWZ(fp
[a
].SrcReg
[1].Swizzle
, 1)],
158 swz
[GET_SWZ(fp
[a
].SrcReg
[1].Swizzle
, 2)],
159 swz
[GET_SWZ(fp
[a
].SrcReg
[1].Swizzle
, 3)]);
161 _mesa_printf("%s[%d] ", file_string
[fp
[a
].SrcReg
[1].File
], fp
[a
].SrcReg
[1].Index
);
164 if (fp
[a
].SrcReg
[2].File
!= 0xf) {
165 if (fp
[a
].SrcReg
[2].Swizzle
!= SWIZZLE_NOOP
||
166 fp
[a
].SrcReg
[2].NegateBase
)
167 _mesa_printf("%s[%d].%s%c%c%c%c ", file_string
[fp
[a
].SrcReg
[2].File
], fp
[a
].SrcReg
[2].Index
,
168 fp
[a
].SrcReg
[1].NegateBase
? "-" : "",
169 swz
[GET_SWZ(fp
[a
].SrcReg
[2].Swizzle
, 0)],
170 swz
[GET_SWZ(fp
[a
].SrcReg
[2].Swizzle
, 1)],
171 swz
[GET_SWZ(fp
[a
].SrcReg
[2].Swizzle
, 2)],
172 swz
[GET_SWZ(fp
[a
].SrcReg
[2].Swizzle
, 3)]);
174 _mesa_printf("%s[%d] ", file_string
[fp
[a
].SrcReg
[2].File
], fp
[a
].SrcReg
[2].Index
);
182 _mesa_parse_arb_fragment_program(GLcontext
* ctx
, GLenum target
,
183 const GLubyte
* str
, GLsizei len
,
184 struct fragment_program
*program
)
187 struct arb_program ap
;
190 /* set the program target before parsing */
191 ap
.Base
.Target
= GL_FRAGMENT_PROGRAM_ARB
;
193 retval
= _mesa_parse_arb_program(ctx
, str
, len
, &ap
);
195 /* XXX: Parse error. Cleanup things and return */
198 program
->Instructions
= (struct fp_instruction
*) _mesa_malloc (
199 sizeof(struct fp_instruction
) );
200 program
->Instructions
[0].Opcode
= FP_OPCODE_END
;
204 /* copy the relvant contents of the arb_program struct into the
205 * fragment_program struct
207 program
->Base
.String
= ap
.Base
.String
;
208 program
->Base
.NumInstructions
= ap
.Base
.NumInstructions
;
209 program
->Base
.NumTemporaries
= ap
.Base
.NumTemporaries
;
210 program
->Base
.NumParameters
= ap
.Base
.NumParameters
;
211 program
->Base
.NumAttributes
= ap
.Base
.NumAttributes
;
212 program
->Base
.NumAddressRegs
= ap
.Base
.NumAddressRegs
;
214 program
->InputsRead
= ap
.InputsRead
;
215 program
->OutputsWritten
= ap
.OutputsWritten
;
216 for (a
=0; a
<MAX_TEXTURE_IMAGE_UNITS
; a
++)
217 program
->TexturesUsed
[a
] = ap
.TexturesUsed
[a
];
218 program
->NumAluInstructions
= ap
.NumAluInstructions
;
219 program
->NumTexInstructions
= ap
.NumTexInstructions
;
220 program
->NumTexIndirections
= ap
.NumTexIndirections
;
221 program
->Parameters
= ap
.Parameters
;
222 program
->FogOption
= ap
.FogOption
;
225 _mesa_debug_fp_inst(ap
.Base
.NumInstructions
, ap
.FPInstructions
);
228 program
->Instructions
= ap
.FPInstructions
;