7b9abec1c948344e715ff15fc4c5585d74892149
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 _mesa_printf(" %s[%d].%s%s%s%s ", file_string
[fp
[a
].DstReg
.File
], fp
[a
].DstReg
.Index
,
129 GET_BIT(fp
[a
].DstReg
.WriteMask
, 0) ? "x" : "",
130 GET_BIT(fp
[a
].DstReg
.WriteMask
, 1) ? "y" : "",
131 GET_BIT(fp
[a
].DstReg
.WriteMask
, 2) ? "z" : "",
132 GET_BIT(fp
[a
].DstReg
.WriteMask
, 3) ? "w" : "");
134 _mesa_printf(" %s[%d] ", file_string
[fp
[a
].DstReg
.File
], fp
[a
].DstReg
.Index
);
137 /* Examine each bit of negatebase here as this may be a SWZ instruction
139 if (fp
[a
].SrcReg
[0].File
!= 0xf) {
140 if (fp
[a
].SrcReg
[0].Swizzle
!= SWIZZLE_NOOP
||
141 fp
[a
].SrcReg
[0].NegateBase
)
142 _mesa_printf("%s[%d].%s%c%s%c%s%c%s%c ", file_string
[fp
[a
].SrcReg
[0].File
], fp
[a
].SrcReg
[0].Index
,
143 GET_BIT(fp
[a
].SrcReg
[0].NegateBase
, 0) ? "-" : "",
144 swz
[GET_SWZ(fp
[a
].SrcReg
[0].Swizzle
, 0)],
145 GET_BIT(fp
[a
].SrcReg
[0].NegateBase
, 0) ? "-" : "",
146 swz
[GET_SWZ(fp
[a
].SrcReg
[0].Swizzle
, 1)],
147 GET_BIT(fp
[a
].SrcReg
[0].NegateBase
, 0) ? "-" : "",
148 swz
[GET_SWZ(fp
[a
].SrcReg
[0].Swizzle
, 2)],
149 GET_BIT(fp
[a
].SrcReg
[0].NegateBase
, 0) ? "-" : "",
150 swz
[GET_SWZ(fp
[a
].SrcReg
[0].Swizzle
, 3)]);
152 _mesa_printf("%s[%d] ", file_string
[fp
[a
].SrcReg
[0].File
], fp
[a
].SrcReg
[0].Index
);
155 if (fp
[a
].SrcReg
[1].File
!= 0xf) {
156 if (fp
[a
].SrcReg
[1].Swizzle
!= SWIZZLE_NOOP
||
157 fp
[a
].SrcReg
[1].NegateBase
)
158 _mesa_printf("%s[%d].%s%c%c%c%c ", file_string
[fp
[a
].SrcReg
[1].File
], fp
[a
].SrcReg
[1].Index
,
159 fp
[a
].SrcReg
[1].NegateBase
? "-" : "",
160 swz
[GET_SWZ(fp
[a
].SrcReg
[1].Swizzle
, 0)],
161 swz
[GET_SWZ(fp
[a
].SrcReg
[1].Swizzle
, 1)],
162 swz
[GET_SWZ(fp
[a
].SrcReg
[1].Swizzle
, 2)],
163 swz
[GET_SWZ(fp
[a
].SrcReg
[1].Swizzle
, 3)]);
165 _mesa_printf("%s[%d] ", file_string
[fp
[a
].SrcReg
[1].File
], fp
[a
].SrcReg
[1].Index
);
168 if (fp
[a
].SrcReg
[2].File
!= 0xf) {
169 if (fp
[a
].SrcReg
[2].Swizzle
!= SWIZZLE_NOOP
||
170 fp
[a
].SrcReg
[2].NegateBase
)
171 _mesa_printf("%s[%d].%s%c%c%c%c ", file_string
[fp
[a
].SrcReg
[2].File
], fp
[a
].SrcReg
[2].Index
,
172 fp
[a
].SrcReg
[1].NegateBase
? "-" : "",
173 swz
[GET_SWZ(fp
[a
].SrcReg
[2].Swizzle
, 0)],
174 swz
[GET_SWZ(fp
[a
].SrcReg
[2].Swizzle
, 1)],
175 swz
[GET_SWZ(fp
[a
].SrcReg
[2].Swizzle
, 2)],
176 swz
[GET_SWZ(fp
[a
].SrcReg
[2].Swizzle
, 3)]);
178 _mesa_printf("%s[%d] ", file_string
[fp
[a
].SrcReg
[2].File
], fp
[a
].SrcReg
[2].Index
);
187 _mesa_parse_arb_fragment_program(GLcontext
* ctx
, GLenum target
,
188 const GLubyte
* str
, GLsizei len
,
189 struct fragment_program
*program
)
192 struct arb_program ap
;
195 /* set the program target before parsing */
196 ap
.Base
.Target
= GL_FRAGMENT_PROGRAM_ARB
;
198 if (!_mesa_parse_arb_program(ctx
, str
, len
, &ap
)) {
199 /* Error in the program. Just return. */
203 /* Copy the relevant contents of the arb_program struct into the
204 * fragment_program struct.
206 program
->Base
.String
= ap
.Base
.String
;
207 program
->Base
.NumInstructions
= ap
.Base
.NumInstructions
;
208 program
->Base
.NumTemporaries
= ap
.Base
.NumTemporaries
;
209 program
->Base
.NumParameters
= ap
.Base
.NumParameters
;
210 program
->Base
.NumAttributes
= ap
.Base
.NumAttributes
;
211 program
->Base
.NumAddressRegs
= ap
.Base
.NumAddressRegs
;
212 program
->NumAluInstructions
= ap
.NumAluInstructions
;
213 program
->NumTexInstructions
= ap
.NumTexInstructions
;
214 program
->NumTexIndirections
= ap
.NumTexIndirections
;
216 program
->InputsRead
= ap
.InputsRead
;
217 program
->OutputsWritten
= ap
.OutputsWritten
;
218 for (i
= 0; i
< MAX_TEXTURE_IMAGE_UNITS
; i
++)
219 program
->TexturesUsed
[i
] = ap
.TexturesUsed
[i
];
221 if (program
->Parameters
) {
222 /* free previous program's parameters */
223 _mesa_free_parameter_list(program
->Parameters
);
225 program
->Parameters
= ap
.Parameters
;
226 program
->FogOption
= ap
.FogOption
;
229 _mesa_debug_fp_inst(ap
.Base
.NumInstructions
, ap
.FPInstructions
);
232 program
->Instructions
= ap
.FPInstructions
;