blob: 56d174c6ce593fd6371980a9cad86f1a5bb9b2d1 [file] [log] [blame]
Brian13e3b212007-02-22 16:09:40 -07001/*
2 * Mesa 3-D graphics library
Brian Paulf4361542008-11-11 10:47:10 -07003 * Version: 7.3
Brian13e3b212007-02-22 16:09:40 -07004 *
Brian Paulf4361542008-11-11 10:47:10 -07005 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
Brian13e3b212007-02-22 16:09:40 -07006 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25/**
26 * \file prog_execute.c
27 * Software interpreter for vertex/fragment programs.
28 * \author Brian Paul
29 */
30
31/*
32 * NOTE: we do everything in single-precision floating point; we don't
33 * currently observe the single/half/fixed-precision qualifiers.
34 *
35 */
36
37
Brian Paulbbd28712008-09-18 12:26:54 -060038#include "main/glheader.h"
39#include "main/colormac.h"
40#include "main/context.h"
Brian13e3b212007-02-22 16:09:40 -070041#include "program.h"
42#include "prog_execute.h"
43#include "prog_instruction.h"
44#include "prog_parameter.h"
45#include "prog_print.h"
Brian Paul702b5b02008-12-15 18:37:39 -070046#include "prog_noise.h"
Brian13e3b212007-02-22 16:09:40 -070047
48
Brian13e3b212007-02-22 16:09:40 -070049/* debug predicate */
50#define DEBUG_PROG 0
51
52
Brianf183a2d2007-02-23 17:14:30 -070053/**
54 * Set x to positive or negative infinity.
55 */
56#if defined(USE_IEEE) || defined(_WIN32)
Roland Scheidegger72362a52009-12-07 21:47:49 +010057#define SET_POS_INFINITY(x) \
58 do { \
59 fi_type fi; \
60 fi.i = 0x7F800000; \
61 x = fi.f; \
62 } while (0)
63#define SET_NEG_INFINITY(x) \
64 do { \
65 fi_type fi; \
66 fi.i = 0xFF800000; \
67 x = fi.f; \
68 } while (0)
Brianf183a2d2007-02-23 17:14:30 -070069#elif defined(VMS)
70#define SET_POS_INFINITY(x) x = __MAXFLOAT
71#define SET_NEG_INFINITY(x) x = -__MAXFLOAT
72#else
73#define SET_POS_INFINITY(x) x = (GLfloat) HUGE_VAL
74#define SET_NEG_INFINITY(x) x = (GLfloat) -HUGE_VAL
75#endif
76
77#define SET_FLOAT_BITS(x, bits) ((fi_type *) (void *) &(x))->i = bits
78
79
80static const GLfloat ZeroVec[4] = { 0.0F, 0.0F, 0.0F, 0.0F };
81
82
83
Brian13e3b212007-02-22 16:09:40 -070084/**
85 * Return a pointer to the 4-element float vector specified by the given
86 * source register.
87 */
88static INLINE const GLfloat *
Brian Paulf4361542008-11-11 10:47:10 -070089get_src_register_pointer(const struct prog_src_register *source,
90 const struct gl_program_machine *machine)
Brian13e3b212007-02-22 16:09:40 -070091{
Brian Paulf4361542008-11-11 10:47:10 -070092 const struct gl_program *prog = machine->CurProgram;
93 GLint reg = source->Index;
94
Brianf183a2d2007-02-23 17:14:30 -070095 if (source->RelAddr) {
Brian Paulf4361542008-11-11 10:47:10 -070096 /* add address register value to src index/offset */
97 reg += machine->AddressReg[0][0];
98 if (reg < 0) {
99 return ZeroVec;
Brianf183a2d2007-02-23 17:14:30 -0700100 }
101 }
102
Brian13e3b212007-02-22 16:09:40 -0700103 switch (source->File) {
104 case PROGRAM_TEMPORARY:
Brian Paulf4361542008-11-11 10:47:10 -0700105 if (reg >= MAX_PROGRAM_TEMPS)
106 return ZeroVec;
107 return machine->Temporaries[reg];
Brian13e3b212007-02-22 16:09:40 -0700108
109 case PROGRAM_INPUT:
Brian Paulf4361542008-11-11 10:47:10 -0700110 if (prog->Target == GL_VERTEX_PROGRAM_ARB) {
111 if (reg >= VERT_ATTRIB_MAX)
112 return ZeroVec;
113 return machine->VertAttribs[reg];
Brian13e3b212007-02-22 16:09:40 -0700114 }
115 else {
Brian Paulf4361542008-11-11 10:47:10 -0700116 if (reg >= FRAG_ATTRIB_MAX)
117 return ZeroVec;
118 return machine->Attribs[reg][machine->CurElement];
Brian13e3b212007-02-22 16:09:40 -0700119 }
120
121 case PROGRAM_OUTPUT:
Brian Paulf4361542008-11-11 10:47:10 -0700122 if (reg >= MAX_PROGRAM_OUTPUTS)
123 return ZeroVec;
124 return machine->Outputs[reg];
Brian13e3b212007-02-22 16:09:40 -0700125
126 case PROGRAM_LOCAL_PARAM:
Brian Paulf4361542008-11-11 10:47:10 -0700127 if (reg >= MAX_PROGRAM_LOCAL_PARAMS)
128 return ZeroVec;
129 return machine->CurProgram->LocalParams[reg];
Brian13e3b212007-02-22 16:09:40 -0700130
131 case PROGRAM_ENV_PARAM:
Brian Paulf4361542008-11-11 10:47:10 -0700132 if (reg >= MAX_PROGRAM_ENV_PARAMS)
133 return ZeroVec;
134 return machine->EnvParams[reg];
Brian13e3b212007-02-22 16:09:40 -0700135
136 case PROGRAM_STATE_VAR:
137 /* Fallthrough */
138 case PROGRAM_CONSTANT:
139 /* Fallthrough */
140 case PROGRAM_UNIFORM:
141 /* Fallthrough */
142 case PROGRAM_NAMED_PARAM:
Brian Paulf4361542008-11-11 10:47:10 -0700143 if (reg >= (GLint) prog->Parameters->NumParameters)
144 return ZeroVec;
145 return prog->Parameters->ParameterValues[reg];
Brian13e3b212007-02-22 16:09:40 -0700146
147 default:
Brian33eac562007-02-25 18:52:41 -0700148 _mesa_problem(NULL,
Brian Paulf4361542008-11-11 10:47:10 -0700149 "Invalid src register file %d in get_src_register_pointer()",
150 source->File);
Brian13e3b212007-02-22 16:09:40 -0700151 return NULL;
152 }
153}
154
155
Brian Paulf4361542008-11-11 10:47:10 -0700156/**
157 * Return a pointer to the 4-element float vector specified by the given
158 * destination register.
159 */
160static INLINE GLfloat *
161get_dst_register_pointer(const struct prog_dst_register *dest,
162 struct gl_program_machine *machine)
163{
164 static GLfloat dummyReg[4];
165 GLint reg = dest->Index;
166
167 if (dest->RelAddr) {
168 /* add address register value to src index/offset */
169 reg += machine->AddressReg[0][0];
170 if (reg < 0) {
171 return dummyReg;
172 }
173 }
174
175 switch (dest->File) {
176 case PROGRAM_TEMPORARY:
177 if (reg >= MAX_PROGRAM_TEMPS)
178 return dummyReg;
179 return machine->Temporaries[reg];
180
181 case PROGRAM_OUTPUT:
182 if (reg >= MAX_PROGRAM_OUTPUTS)
183 return dummyReg;
184 return machine->Outputs[reg];
185
186 case PROGRAM_WRITE_ONLY:
187 return dummyReg;
188
189 default:
190 _mesa_problem(NULL,
191 "Invalid dest register file %d in get_dst_register_pointer()",
192 dest->File);
193 return NULL;
194 }
195}
196
197
198
Brian13e3b212007-02-22 16:09:40 -0700199/**
200 * Fetch a 4-element float vector from the given source register.
201 * Apply swizzling and negating as needed.
202 */
203static void
Brian33eac562007-02-25 18:52:41 -0700204fetch_vector4(const struct prog_src_register *source,
Briane80d9012007-02-23 16:53:24 -0700205 const struct gl_program_machine *machine, GLfloat result[4])
Brian13e3b212007-02-22 16:09:40 -0700206{
Brian Paulf4361542008-11-11 10:47:10 -0700207 const GLfloat *src = get_src_register_pointer(source, machine);
Brian13e3b212007-02-22 16:09:40 -0700208 ASSERT(src);
209
210 if (source->Swizzle == SWIZZLE_NOOP) {
211 /* no swizzling */
212 COPY_4V(result, src);
213 }
214 else {
215 ASSERT(GET_SWZ(source->Swizzle, 0) <= 3);
216 ASSERT(GET_SWZ(source->Swizzle, 1) <= 3);
217 ASSERT(GET_SWZ(source->Swizzle, 2) <= 3);
218 ASSERT(GET_SWZ(source->Swizzle, 3) <= 3);
219 result[0] = src[GET_SWZ(source->Swizzle, 0)];
220 result[1] = src[GET_SWZ(source->Swizzle, 1)];
221 result[2] = src[GET_SWZ(source->Swizzle, 2)];
222 result[3] = src[GET_SWZ(source->Swizzle, 3)];
223 }
224
Brian13e3b212007-02-22 16:09:40 -0700225 if (source->Abs) {
226 result[0] = FABSF(result[0]);
227 result[1] = FABSF(result[1]);
228 result[2] = FABSF(result[2]);
229 result[3] = FABSF(result[3]);
230 }
Brian Paul7db7ff82009-04-14 22:14:30 -0600231 if (source->Negate) {
232 ASSERT(source->Negate == NEGATE_XYZW);
Brian13e3b212007-02-22 16:09:40 -0700233 result[0] = -result[0];
234 result[1] = -result[1];
235 result[2] = -result[2];
236 result[3] = -result[3];
237 }
Brian Paul92009542009-06-03 15:43:53 -0600238
239#ifdef NAN_CHECK
240 assert(!IS_INF_OR_NAN(result[0]));
241 assert(!IS_INF_OR_NAN(result[0]));
242 assert(!IS_INF_OR_NAN(result[0]));
243 assert(!IS_INF_OR_NAN(result[0]));
244#endif
Brian13e3b212007-02-22 16:09:40 -0700245}
246
Brian62da6a12007-05-02 18:44:34 -0600247
Brian13e3b212007-02-22 16:09:40 -0700248/**
Brian Paul37eef7b2008-11-07 09:33:55 -0700249 * Fetch a 4-element uint vector from the given source register.
250 * Apply swizzling but not negation/abs.
251 */
252static void
253fetch_vector4ui(const struct prog_src_register *source,
254 const struct gl_program_machine *machine, GLuint result[4])
255{
Brian Paulf4361542008-11-11 10:47:10 -0700256 const GLuint *src = (GLuint *) get_src_register_pointer(source, machine);
Brian Paul37eef7b2008-11-07 09:33:55 -0700257 ASSERT(src);
258
259 if (source->Swizzle == SWIZZLE_NOOP) {
260 /* no swizzling */
261 COPY_4V(result, src);
262 }
263 else {
264 ASSERT(GET_SWZ(source->Swizzle, 0) <= 3);
265 ASSERT(GET_SWZ(source->Swizzle, 1) <= 3);
266 ASSERT(GET_SWZ(source->Swizzle, 2) <= 3);
267 ASSERT(GET_SWZ(source->Swizzle, 3) <= 3);
268 result[0] = src[GET_SWZ(source->Swizzle, 0)];
269 result[1] = src[GET_SWZ(source->Swizzle, 1)];
270 result[2] = src[GET_SWZ(source->Swizzle, 2)];
271 result[3] = src[GET_SWZ(source->Swizzle, 3)];
272 }
273
Brian Paul7db7ff82009-04-14 22:14:30 -0600274 /* Note: no Negate or Abs here */
Brian Paul37eef7b2008-11-07 09:33:55 -0700275}
276
277
278
279/**
Brian62da6a12007-05-02 18:44:34 -0600280 * Fetch the derivative with respect to X or Y for the given register.
281 * XXX this currently only works for fragment program input attribs.
Brian13e3b212007-02-22 16:09:40 -0700282 */
Brian62da6a12007-05-02 18:44:34 -0600283static void
Briane80d9012007-02-23 16:53:24 -0700284fetch_vector4_deriv(GLcontext * ctx,
285 const struct prog_src_register *source,
Brian62da6a12007-05-02 18:44:34 -0600286 const struct gl_program_machine *machine,
287 char xOrY, GLfloat result[4])
Brian13e3b212007-02-22 16:09:40 -0700288{
Brian Paul37eef7b2008-11-07 09:33:55 -0700289 if (source->File == PROGRAM_INPUT &&
290 source->Index < (GLint) machine->NumDeriv) {
Brian62da6a12007-05-02 18:44:34 -0600291 const GLint col = machine->CurElement;
292 const GLfloat w = machine->Attribs[FRAG_ATTRIB_WPOS][col][3];
293 const GLfloat invQ = 1.0f / w;
294 GLfloat deriv[4];
Brian13e3b212007-02-22 16:09:40 -0700295
Brian13e3b212007-02-22 16:09:40 -0700296 if (xOrY == 'X') {
Brian62da6a12007-05-02 18:44:34 -0600297 deriv[0] = machine->DerivX[source->Index][0] * invQ;
298 deriv[1] = machine->DerivX[source->Index][1] * invQ;
299 deriv[2] = machine->DerivX[source->Index][2] * invQ;
300 deriv[3] = machine->DerivX[source->Index][3] * invQ;
Brian13e3b212007-02-22 16:09:40 -0700301 }
302 else {
Brian62da6a12007-05-02 18:44:34 -0600303 deriv[0] = machine->DerivY[source->Index][0] * invQ;
304 deriv[1] = machine->DerivY[source->Index][1] * invQ;
305 deriv[2] = machine->DerivY[source->Index][2] * invQ;
306 deriv[3] = machine->DerivY[source->Index][3] * invQ;
Brian13e3b212007-02-22 16:09:40 -0700307 }
Brian13e3b212007-02-22 16:09:40 -0700308
Brian62da6a12007-05-02 18:44:34 -0600309 result[0] = deriv[GET_SWZ(source->Swizzle, 0)];
310 result[1] = deriv[GET_SWZ(source->Swizzle, 1)];
311 result[2] = deriv[GET_SWZ(source->Swizzle, 2)];
312 result[3] = deriv[GET_SWZ(source->Swizzle, 3)];
313
Brian62da6a12007-05-02 18:44:34 -0600314 if (source->Abs) {
315 result[0] = FABSF(result[0]);
316 result[1] = FABSF(result[1]);
317 result[2] = FABSF(result[2]);
318 result[3] = FABSF(result[3]);
319 }
Brian Paul7db7ff82009-04-14 22:14:30 -0600320 if (source->Negate) {
321 ASSERT(source->Negate == NEGATE_XYZW);
Brian62da6a12007-05-02 18:44:34 -0600322 result[0] = -result[0];
323 result[1] = -result[1];
324 result[2] = -result[2];
325 result[3] = -result[3];
326 }
Brian13e3b212007-02-22 16:09:40 -0700327 }
Brian62da6a12007-05-02 18:44:34 -0600328 else {
329 ASSIGN_4V(result, 0.0, 0.0, 0.0, 0.0);
Brian13e3b212007-02-22 16:09:40 -0700330 }
Brian13e3b212007-02-22 16:09:40 -0700331}
Brian13e3b212007-02-22 16:09:40 -0700332
333
334/**
335 * As above, but only return result[0] element.
336 */
337static void
Brian33eac562007-02-25 18:52:41 -0700338fetch_vector1(const struct prog_src_register *source,
Briane80d9012007-02-23 16:53:24 -0700339 const struct gl_program_machine *machine, GLfloat result[4])
Brian13e3b212007-02-22 16:09:40 -0700340{
Brian Paulf4361542008-11-11 10:47:10 -0700341 const GLfloat *src = get_src_register_pointer(source, machine);
Brian13e3b212007-02-22 16:09:40 -0700342 ASSERT(src);
343
344 result[0] = src[GET_SWZ(source->Swizzle, 0)];
345
Brian13e3b212007-02-22 16:09:40 -0700346 if (source->Abs) {
347 result[0] = FABSF(result[0]);
348 }
Brian Paul7db7ff82009-04-14 22:14:30 -0600349 if (source->Negate) {
Brian13e3b212007-02-22 16:09:40 -0700350 result[0] = -result[0];
351 }
352}
353
354
355/**
Brian999b5562007-11-23 12:01:57 -0700356 * Fetch texel from texture. Use partial derivatives when possible.
357 */
358static INLINE void
359fetch_texel(GLcontext *ctx,
360 const struct gl_program_machine *machine,
361 const struct prog_instruction *inst,
362 const GLfloat texcoord[4], GLfloat lodBias,
363 GLfloat color[4])
364{
Brian Paulade50832008-05-14 16:09:46 -0600365 const GLuint unit = machine->Samplers[inst->TexSrcUnit];
366
Brian999b5562007-11-23 12:01:57 -0700367 /* Note: we only have the right derivatives for fragment input attribs.
368 */
369 if (machine->NumDeriv > 0 &&
370 inst->SrcReg[0].File == PROGRAM_INPUT &&
371 inst->SrcReg[0].Index == FRAG_ATTRIB_TEX0 + inst->TexSrcUnit) {
372 /* simple texture fetch for which we should have derivatives */
373 GLuint attr = inst->SrcReg[0].Index;
374 machine->FetchTexelDeriv(ctx, texcoord,
375 machine->DerivX[attr],
376 machine->DerivY[attr],
Brian Paulade50832008-05-14 16:09:46 -0600377 lodBias, unit, color);
Brian999b5562007-11-23 12:01:57 -0700378 }
379 else {
Brian Paulade50832008-05-14 16:09:46 -0600380 machine->FetchTexelLod(ctx, texcoord, lodBias, unit, color);
Brian999b5562007-11-23 12:01:57 -0700381 }
382}
383
384
385/**
Brian13e3b212007-02-22 16:09:40 -0700386 * Test value against zero and return GT, LT, EQ or UN if NaN.
387 */
388static INLINE GLuint
Briane80d9012007-02-23 16:53:24 -0700389generate_cc(float value)
Brian13e3b212007-02-22 16:09:40 -0700390{
391 if (value != value)
Briane80d9012007-02-23 16:53:24 -0700392 return COND_UN; /* NaN */
Brian13e3b212007-02-22 16:09:40 -0700393 if (value > 0.0F)
394 return COND_GT;
395 if (value < 0.0F)
396 return COND_LT;
397 return COND_EQ;
398}
399
400
401/**
402 * Test if the ccMaskRule is satisfied by the given condition code.
403 * Used to mask destination writes according to the current condition code.
404 */
405static INLINE GLboolean
406test_cc(GLuint condCode, GLuint ccMaskRule)
407{
408 switch (ccMaskRule) {
409 case COND_EQ: return (condCode == COND_EQ);
410 case COND_NE: return (condCode != COND_EQ);
411 case COND_LT: return (condCode == COND_LT);
412 case COND_GE: return (condCode == COND_GT || condCode == COND_EQ);
413 case COND_LE: return (condCode == COND_LT || condCode == COND_EQ);
414 case COND_GT: return (condCode == COND_GT);
415 case COND_TR: return GL_TRUE;
416 case COND_FL: return GL_FALSE;
417 default: return GL_TRUE;
418 }
419}
420
421
422/**
423 * Evaluate the 4 condition codes against a predicate and return GL_TRUE
424 * or GL_FALSE to indicate result.
425 */
426static INLINE GLboolean
427eval_condition(const struct gl_program_machine *machine,
428 const struct prog_instruction *inst)
429{
430 const GLuint swizzle = inst->DstReg.CondSwizzle;
431 const GLuint condMask = inst->DstReg.CondMask;
432 if (test_cc(machine->CondCodes[GET_SWZ(swizzle, 0)], condMask) ||
433 test_cc(machine->CondCodes[GET_SWZ(swizzle, 1)], condMask) ||
434 test_cc(machine->CondCodes[GET_SWZ(swizzle, 2)], condMask) ||
435 test_cc(machine->CondCodes[GET_SWZ(swizzle, 3)], condMask)) {
436 return GL_TRUE;
437 }
438 else {
439 return GL_FALSE;
440 }
441}
442
443
444
445/**
446 * Store 4 floats into a register. Observe the instructions saturate and
447 * set-condition-code flags.
448 */
449static void
Briane80d9012007-02-23 16:53:24 -0700450store_vector4(const struct prog_instruction *inst,
451 struct gl_program_machine *machine, const GLfloat value[4])
Brian13e3b212007-02-22 16:09:40 -0700452{
Brian Paulf4361542008-11-11 10:47:10 -0700453 const struct prog_dst_register *dstReg = &(inst->DstReg);
Brian13e3b212007-02-22 16:09:40 -0700454 const GLboolean clamp = inst->SaturateMode == SATURATE_ZERO_ONE;
Brian Paulf4361542008-11-11 10:47:10 -0700455 GLuint writeMask = dstReg->WriteMask;
Brian13e3b212007-02-22 16:09:40 -0700456 GLfloat clampedValue[4];
Brian Paulf4361542008-11-11 10:47:10 -0700457 GLfloat *dst = get_dst_register_pointer(dstReg, machine);
Brian13e3b212007-02-22 16:09:40 -0700458
459#if 0
460 if (value[0] > 1.0e10 ||
461 IS_INF_OR_NAN(value[0]) ||
462 IS_INF_OR_NAN(value[1]) ||
Briane80d9012007-02-23 16:53:24 -0700463 IS_INF_OR_NAN(value[2]) || IS_INF_OR_NAN(value[3]))
Brian13e3b212007-02-22 16:09:40 -0700464 printf("store %g %g %g %g\n", value[0], value[1], value[2], value[3]);
465#endif
466
467 if (clamp) {
468 clampedValue[0] = CLAMP(value[0], 0.0F, 1.0F);
469 clampedValue[1] = CLAMP(value[1], 0.0F, 1.0F);
470 clampedValue[2] = CLAMP(value[2], 0.0F, 1.0F);
471 clampedValue[3] = CLAMP(value[3], 0.0F, 1.0F);
472 value = clampedValue;
473 }
474
Brian Paulf4361542008-11-11 10:47:10 -0700475 if (dstReg->CondMask != COND_TR) {
Brian13e3b212007-02-22 16:09:40 -0700476 /* condition codes may turn off some writes */
477 if (writeMask & WRITEMASK_X) {
Brian Paulf4361542008-11-11 10:47:10 -0700478 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 0)],
479 dstReg->CondMask))
Brian13e3b212007-02-22 16:09:40 -0700480 writeMask &= ~WRITEMASK_X;
481 }
482 if (writeMask & WRITEMASK_Y) {
Brian Paulf4361542008-11-11 10:47:10 -0700483 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 1)],
484 dstReg->CondMask))
Brian13e3b212007-02-22 16:09:40 -0700485 writeMask &= ~WRITEMASK_Y;
486 }
487 if (writeMask & WRITEMASK_Z) {
Brian Paulf4361542008-11-11 10:47:10 -0700488 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 2)],
489 dstReg->CondMask))
Brian13e3b212007-02-22 16:09:40 -0700490 writeMask &= ~WRITEMASK_Z;
491 }
492 if (writeMask & WRITEMASK_W) {
Brian Paulf4361542008-11-11 10:47:10 -0700493 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 3)],
494 dstReg->CondMask))
Brian13e3b212007-02-22 16:09:40 -0700495 writeMask &= ~WRITEMASK_W;
496 }
497 }
498
Brian Paul92009542009-06-03 15:43:53 -0600499#ifdef NAN_CHECK
500 assert(!IS_INF_OR_NAN(value[0]));
501 assert(!IS_INF_OR_NAN(value[0]));
502 assert(!IS_INF_OR_NAN(value[0]));
503 assert(!IS_INF_OR_NAN(value[0]));
504#endif
505
Brian13e3b212007-02-22 16:09:40 -0700506 if (writeMask & WRITEMASK_X)
Brian Paulf4361542008-11-11 10:47:10 -0700507 dst[0] = value[0];
Brian13e3b212007-02-22 16:09:40 -0700508 if (writeMask & WRITEMASK_Y)
Brian Paulf4361542008-11-11 10:47:10 -0700509 dst[1] = value[1];
Brian13e3b212007-02-22 16:09:40 -0700510 if (writeMask & WRITEMASK_Z)
Brian Paulf4361542008-11-11 10:47:10 -0700511 dst[2] = value[2];
Brian13e3b212007-02-22 16:09:40 -0700512 if (writeMask & WRITEMASK_W)
Brian Paulf4361542008-11-11 10:47:10 -0700513 dst[3] = value[3];
Brian13e3b212007-02-22 16:09:40 -0700514
515 if (inst->CondUpdate) {
516 if (writeMask & WRITEMASK_X)
517 machine->CondCodes[0] = generate_cc(value[0]);
518 if (writeMask & WRITEMASK_Y)
519 machine->CondCodes[1] = generate_cc(value[1]);
520 if (writeMask & WRITEMASK_Z)
521 machine->CondCodes[2] = generate_cc(value[2]);
522 if (writeMask & WRITEMASK_W)
523 machine->CondCodes[3] = generate_cc(value[3]);
Briana01616e2007-03-28 11:01:28 -0600524#if DEBUG_PROG
525 printf("CondCodes=(%s,%s,%s,%s) for:\n",
526 _mesa_condcode_string(machine->CondCodes[0]),
527 _mesa_condcode_string(machine->CondCodes[1]),
528 _mesa_condcode_string(machine->CondCodes[2]),
529 _mesa_condcode_string(machine->CondCodes[3]));
530#endif
Brian13e3b212007-02-22 16:09:40 -0700531 }
532}
533
534
Brian13e3b212007-02-22 16:09:40 -0700535/**
Brian Paul37eef7b2008-11-07 09:33:55 -0700536 * Store 4 uints into a register. Observe the set-condition-code flags.
537 */
538static void
539store_vector4ui(const struct prog_instruction *inst,
540 struct gl_program_machine *machine, const GLuint value[4])
541{
Brian Paulf4361542008-11-11 10:47:10 -0700542 const struct prog_dst_register *dstReg = &(inst->DstReg);
543 GLuint writeMask = dstReg->WriteMask;
544 GLuint *dst = (GLuint *) get_dst_register_pointer(dstReg, machine);
Brian Paul37eef7b2008-11-07 09:33:55 -0700545
Brian Paulf4361542008-11-11 10:47:10 -0700546 if (dstReg->CondMask != COND_TR) {
Brian Paul37eef7b2008-11-07 09:33:55 -0700547 /* condition codes may turn off some writes */
548 if (writeMask & WRITEMASK_X) {
Brian Paulf4361542008-11-11 10:47:10 -0700549 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 0)],
550 dstReg->CondMask))
Brian Paul37eef7b2008-11-07 09:33:55 -0700551 writeMask &= ~WRITEMASK_X;
552 }
553 if (writeMask & WRITEMASK_Y) {
Brian Paulf4361542008-11-11 10:47:10 -0700554 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 1)],
555 dstReg->CondMask))
Brian Paul37eef7b2008-11-07 09:33:55 -0700556 writeMask &= ~WRITEMASK_Y;
557 }
558 if (writeMask & WRITEMASK_Z) {
Brian Paulf4361542008-11-11 10:47:10 -0700559 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 2)],
560 dstReg->CondMask))
Brian Paul37eef7b2008-11-07 09:33:55 -0700561 writeMask &= ~WRITEMASK_Z;
562 }
563 if (writeMask & WRITEMASK_W) {
Brian Paulf4361542008-11-11 10:47:10 -0700564 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 3)],
565 dstReg->CondMask))
Brian Paul37eef7b2008-11-07 09:33:55 -0700566 writeMask &= ~WRITEMASK_W;
567 }
568 }
569
570 if (writeMask & WRITEMASK_X)
Brian Paulf4361542008-11-11 10:47:10 -0700571 dst[0] = value[0];
Brian Paul37eef7b2008-11-07 09:33:55 -0700572 if (writeMask & WRITEMASK_Y)
Brian Paulf4361542008-11-11 10:47:10 -0700573 dst[1] = value[1];
Brian Paul37eef7b2008-11-07 09:33:55 -0700574 if (writeMask & WRITEMASK_Z)
Brian Paulf4361542008-11-11 10:47:10 -0700575 dst[2] = value[2];
Brian Paul37eef7b2008-11-07 09:33:55 -0700576 if (writeMask & WRITEMASK_W)
Brian Paulf4361542008-11-11 10:47:10 -0700577 dst[3] = value[3];
Brian Paul37eef7b2008-11-07 09:33:55 -0700578
579 if (inst->CondUpdate) {
580 if (writeMask & WRITEMASK_X)
581 machine->CondCodes[0] = generate_cc(value[0]);
582 if (writeMask & WRITEMASK_Y)
583 machine->CondCodes[1] = generate_cc(value[1]);
584 if (writeMask & WRITEMASK_Z)
585 machine->CondCodes[2] = generate_cc(value[2]);
586 if (writeMask & WRITEMASK_W)
587 machine->CondCodes[3] = generate_cc(value[3]);
588#if DEBUG_PROG
589 printf("CondCodes=(%s,%s,%s,%s) for:\n",
590 _mesa_condcode_string(machine->CondCodes[0]),
591 _mesa_condcode_string(machine->CondCodes[1]),
592 _mesa_condcode_string(machine->CondCodes[2]),
593 _mesa_condcode_string(machine->CondCodes[3]));
594#endif
595 }
596}
597
598
599
600/**
Brian13e3b212007-02-22 16:09:40 -0700601 * Execute the given vertex/fragment program.
602 *
Brian3c1c9992007-02-25 19:11:44 -0700603 * \param ctx rendering context
604 * \param program the program to execute
605 * \param machine machine state (must be initialized)
Brian13e3b212007-02-22 16:09:40 -0700606 * \return GL_TRUE if program completed or GL_FALSE if program executed KIL.
607 */
608GLboolean
Briane80d9012007-02-23 16:53:24 -0700609_mesa_execute_program(GLcontext * ctx,
Brian8b34b7d2007-02-25 18:26:50 -0700610 const struct gl_program *program,
Brian085d7d52007-02-25 18:23:37 -0700611 struct gl_program_machine *machine)
Brian13e3b212007-02-22 16:09:40 -0700612{
Brian8b34b7d2007-02-25 18:26:50 -0700613 const GLuint numInst = program->NumInstructions;
Briancfd00112007-02-25 18:30:45 -0700614 const GLuint maxExec = 10000;
José Fonseca452a5922008-05-31 18:14:09 +0900615 GLuint pc, numExec = 0;
Brian13e3b212007-02-22 16:09:40 -0700616
617 machine->CurProgram = program;
618
619 if (DEBUG_PROG) {
620 printf("execute program %u --------------------\n", program->Id);
621 }
622
Brian33eac562007-02-25 18:52:41 -0700623 if (program->Target == GL_VERTEX_PROGRAM_ARB) {
624 machine->EnvParams = ctx->VertexProgram.Parameters;
625 }
626 else {
627 machine->EnvParams = ctx->FragmentProgram.Parameters;
628 }
629
Brian8b34b7d2007-02-25 18:26:50 -0700630 for (pc = 0; pc < numInst; pc++) {
Brian13e3b212007-02-22 16:09:40 -0700631 const struct prog_instruction *inst = program->Instructions + pc;
632
Brian13e3b212007-02-22 16:09:40 -0700633 if (DEBUG_PROG) {
634 _mesa_print_instruction(inst);
635 }
636
637 switch (inst->Opcode) {
Briane80d9012007-02-23 16:53:24 -0700638 case OPCODE_ABS:
639 {
640 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700641 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -0700642 result[0] = FABSF(a[0]);
643 result[1] = FABSF(a[1]);
644 result[2] = FABSF(a[2]);
645 result[3] = FABSF(a[3]);
646 store_vector4(inst, machine, result);
647 }
648 break;
649 case OPCODE_ADD:
650 {
651 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700652 fetch_vector4(&inst->SrcReg[0], machine, a);
653 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -0700654 result[0] = a[0] + b[0];
655 result[1] = a[1] + b[1];
656 result[2] = a[2] + b[2];
657 result[3] = a[3] + b[3];
658 store_vector4(inst, machine, result);
659 if (DEBUG_PROG) {
660 printf("ADD (%g %g %g %g) = (%g %g %g %g) + (%g %g %g %g)\n",
661 result[0], result[1], result[2], result[3],
662 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -0700663 }
Briane80d9012007-02-23 16:53:24 -0700664 }
665 break;
Brian Paul37eef7b2008-11-07 09:33:55 -0700666 case OPCODE_AND: /* bitwise AND */
667 {
668 GLuint a[4], b[4], result[4];
669 fetch_vector4ui(&inst->SrcReg[0], machine, a);
670 fetch_vector4ui(&inst->SrcReg[1], machine, b);
671 result[0] = a[0] & b[0];
672 result[1] = a[1] & b[1];
673 result[2] = a[2] & b[2];
674 result[3] = a[3] & b[3];
675 store_vector4ui(inst, machine, result);
676 }
677 break;
Brianf183a2d2007-02-23 17:14:30 -0700678 case OPCODE_ARL:
679 {
680 GLfloat t[4];
Brian33eac562007-02-25 18:52:41 -0700681 fetch_vector4(&inst->SrcReg[0], machine, t);
Brian Paula9475cc2008-12-12 18:03:48 -0700682 machine->AddressReg[0][0] = IFLOOR(t[0]);
Brianf183a2d2007-02-23 17:14:30 -0700683 }
684 break;
Briane80d9012007-02-23 16:53:24 -0700685 case OPCODE_BGNLOOP:
686 /* no-op */
Brian Paule8ea2d22009-12-22 12:57:31 -0700687 ASSERT(program->Instructions[inst->BranchTarget].Opcode
688 == OPCODE_ENDLOOP);
Briane80d9012007-02-23 16:53:24 -0700689 break;
690 case OPCODE_ENDLOOP:
691 /* subtract 1 here since pc is incremented by for(pc) loop */
Brian Paule8ea2d22009-12-22 12:57:31 -0700692 ASSERT(program->Instructions[inst->BranchTarget].Opcode
693 == OPCODE_BGNLOOP);
Briane80d9012007-02-23 16:53:24 -0700694 pc = inst->BranchTarget - 1; /* go to matching BNGLOOP */
695 break;
696 case OPCODE_BGNSUB: /* begin subroutine */
697 break;
698 case OPCODE_ENDSUB: /* end subroutine */
699 break;
700 case OPCODE_BRA: /* branch (conditional) */
Briane80d9012007-02-23 16:53:24 -0700701 if (eval_condition(machine, inst)) {
702 /* take branch */
Brian Pauldb721152009-12-22 14:15:30 -0700703 /* Subtract 1 here since we'll do pc++ below */
704 pc = inst->BranchTarget - 1;
705 }
706 break;
707 case OPCODE_BRK: /* break out of loop (conditional) */
708 ASSERT(program->Instructions[inst->BranchTarget].Opcode
709 == OPCODE_ENDLOOP);
710 if (eval_condition(machine, inst)) {
711 /* break out of loop */
712 /* pc++ at end of for-loop will put us after the ENDLOOP inst */
713 pc = inst->BranchTarget;
714 }
715 break;
716 case OPCODE_CONT: /* continue loop (conditional) */
717 ASSERT(program->Instructions[inst->BranchTarget].Opcode
718 == OPCODE_ENDLOOP);
719 if (eval_condition(machine, inst)) {
720 /* continue at ENDLOOP */
Briane80d9012007-02-23 16:53:24 -0700721 /* Subtract 1 here since we'll do pc++ at end of for-loop */
722 pc = inst->BranchTarget - 1;
723 }
724 break;
725 case OPCODE_CAL: /* Call subroutine (conditional) */
726 if (eval_condition(machine, inst)) {
727 /* call the subroutine */
728 if (machine->StackDepth >= MAX_PROGRAM_CALL_DEPTH) {
729 return GL_TRUE; /* Per GL_NV_vertex_program2 spec */
Brian13e3b212007-02-22 16:09:40 -0700730 }
Briana0275b02007-03-27 11:02:20 -0600731 machine->CallStack[machine->StackDepth++] = pc + 1; /* next inst */
Brian31dc7a32007-03-27 15:21:35 -0600732 /* Subtract 1 here since we'll do pc++ at end of for-loop */
733 pc = inst->BranchTarget - 1;
Briane80d9012007-02-23 16:53:24 -0700734 }
735 break;
736 case OPCODE_CMP:
737 {
738 GLfloat a[4], b[4], c[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700739 fetch_vector4(&inst->SrcReg[0], machine, a);
740 fetch_vector4(&inst->SrcReg[1], machine, b);
741 fetch_vector4(&inst->SrcReg[2], machine, c);
Briane80d9012007-02-23 16:53:24 -0700742 result[0] = a[0] < 0.0F ? b[0] : c[0];
743 result[1] = a[1] < 0.0F ? b[1] : c[1];
744 result[2] = a[2] < 0.0F ? b[2] : c[2];
745 result[3] = a[3] < 0.0F ? b[3] : c[3];
746 store_vector4(inst, machine, result);
747 }
748 break;
749 case OPCODE_COS:
750 {
751 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700752 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -0700753 result[0] = result[1] = result[2] = result[3]
754 = (GLfloat) _mesa_cos(a[0]);
755 store_vector4(inst, machine, result);
756 }
757 break;
758 case OPCODE_DDX: /* Partial derivative with respect to X */
759 {
Brian62da6a12007-05-02 18:44:34 -0600760 GLfloat result[4];
761 fetch_vector4_deriv(ctx, &inst->SrcReg[0], machine,
762 'X', result);
Briane80d9012007-02-23 16:53:24 -0700763 store_vector4(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -0700764 }
765 break;
766 case OPCODE_DDY: /* Partial derivative with respect to Y */
767 {
Brian62da6a12007-05-02 18:44:34 -0600768 GLfloat result[4];
769 fetch_vector4_deriv(ctx, &inst->SrcReg[0], machine,
770 'Y', result);
Briane80d9012007-02-23 16:53:24 -0700771 store_vector4(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -0700772 }
773 break;
Brian Paul65cb74e2008-11-07 09:41:00 -0700774 case OPCODE_DP2:
775 {
776 GLfloat a[4], b[4], result[4];
777 fetch_vector4(&inst->SrcReg[0], machine, a);
778 fetch_vector4(&inst->SrcReg[1], machine, b);
779 result[0] = result[1] = result[2] = result[3] = DOT2(a, b);
780 store_vector4(inst, machine, result);
781 if (DEBUG_PROG) {
782 printf("DP2 %g = (%g %g) . (%g %g)\n",
783 result[0], a[0], a[1], b[0], b[1]);
784 }
785 }
786 break;
787 case OPCODE_DP2A:
788 {
789 GLfloat a[4], b[4], c, result[4];
790 fetch_vector4(&inst->SrcReg[0], machine, a);
791 fetch_vector4(&inst->SrcReg[1], machine, b);
792 fetch_vector1(&inst->SrcReg[1], machine, &c);
793 result[0] = result[1] = result[2] = result[3] = DOT2(a, b) + c;
794 store_vector4(inst, machine, result);
795 if (DEBUG_PROG) {
796 printf("DP2A %g = (%g %g) . (%g %g) + %g\n",
797 result[0], a[0], a[1], b[0], b[1], c);
798 }
799 }
800 break;
Briane80d9012007-02-23 16:53:24 -0700801 case OPCODE_DP3:
802 {
803 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700804 fetch_vector4(&inst->SrcReg[0], machine, a);
805 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -0700806 result[0] = result[1] = result[2] = result[3] = DOT3(a, b);
807 store_vector4(inst, machine, result);
808 if (DEBUG_PROG) {
809 printf("DP3 %g = (%g %g %g) . (%g %g %g)\n",
810 result[0], a[0], a[1], a[2], b[0], b[1], b[2]);
Brian13e3b212007-02-22 16:09:40 -0700811 }
Briane80d9012007-02-23 16:53:24 -0700812 }
813 break;
814 case OPCODE_DP4:
815 {
816 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700817 fetch_vector4(&inst->SrcReg[0], machine, a);
818 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -0700819 result[0] = result[1] = result[2] = result[3] = DOT4(a, b);
820 store_vector4(inst, machine, result);
821 if (DEBUG_PROG) {
822 printf("DP4 %g = (%g, %g %g %g) . (%g, %g %g %g)\n",
823 result[0], a[0], a[1], a[2], a[3],
824 b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -0700825 }
Briane80d9012007-02-23 16:53:24 -0700826 }
827 break;
828 case OPCODE_DPH:
829 {
830 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700831 fetch_vector4(&inst->SrcReg[0], machine, a);
832 fetch_vector4(&inst->SrcReg[1], machine, b);
Brian Paul65cb74e2008-11-07 09:41:00 -0700833 result[0] = result[1] = result[2] = result[3] = DOT3(a, b) + b[3];
Briane80d9012007-02-23 16:53:24 -0700834 store_vector4(inst, machine, result);
835 }
836 break;
837 case OPCODE_DST: /* Distance vector */
838 {
839 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700840 fetch_vector4(&inst->SrcReg[0], machine, a);
841 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -0700842 result[0] = 1.0F;
843 result[1] = a[1] * b[1];
844 result[2] = a[2];
845 result[3] = b[3];
846 store_vector4(inst, machine, result);
847 }
848 break;
Brianf183a2d2007-02-23 17:14:30 -0700849 case OPCODE_EXP:
Brianf183a2d2007-02-23 17:14:30 -0700850 {
851 GLfloat t[4], q[4], floor_t0;
Brian33eac562007-02-25 18:52:41 -0700852 fetch_vector1(&inst->SrcReg[0], machine, t);
Brianf183a2d2007-02-23 17:14:30 -0700853 floor_t0 = FLOORF(t[0]);
854 if (floor_t0 > FLT_MAX_EXP) {
855 SET_POS_INFINITY(q[0]);
856 SET_POS_INFINITY(q[2]);
857 }
858 else if (floor_t0 < FLT_MIN_EXP) {
859 q[0] = 0.0F;
860 q[2] = 0.0F;
861 }
862 else {
Brian761728a2007-02-24 11:14:57 -0700863 q[0] = LDEXPF(1.0, (int) floor_t0);
864 /* Note: GL_NV_vertex_program expects
865 * result.z = result.x * APPX(result.y)
866 * We do what the ARB extension says.
867 */
Brian Paulb8a200a2009-04-03 10:29:11 -0600868 q[2] = (GLfloat) _mesa_pow(2.0, t[0]);
Brianf183a2d2007-02-23 17:14:30 -0700869 }
870 q[1] = t[0] - floor_t0;
871 q[3] = 1.0F;
872 store_vector4( inst, machine, q );
873 }
874 break;
Briane80d9012007-02-23 16:53:24 -0700875 case OPCODE_EX2: /* Exponential base 2 */
876 {
Brian Paul035de6a2009-06-03 15:42:52 -0600877 GLfloat a[4], result[4], val;
Brian33eac562007-02-25 18:52:41 -0700878 fetch_vector1(&inst->SrcReg[0], machine, a);
Brian Paul035de6a2009-06-03 15:42:52 -0600879 val = (GLfloat) _mesa_pow(2.0, a[0]);
880 /*
881 if (IS_INF_OR_NAN(val))
882 val = 1.0e10;
883 */
884 result[0] = result[1] = result[2] = result[3] = val;
Briane80d9012007-02-23 16:53:24 -0700885 store_vector4(inst, machine, result);
886 }
887 break;
888 case OPCODE_FLR:
889 {
890 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700891 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -0700892 result[0] = FLOORF(a[0]);
893 result[1] = FLOORF(a[1]);
894 result[2] = FLOORF(a[2]);
895 result[3] = FLOORF(a[3]);
896 store_vector4(inst, machine, result);
897 }
898 break;
899 case OPCODE_FRC:
900 {
901 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700902 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -0700903 result[0] = a[0] - FLOORF(a[0]);
904 result[1] = a[1] - FLOORF(a[1]);
905 result[2] = a[2] - FLOORF(a[2]);
906 result[3] = a[3] - FLOORF(a[3]);
907 store_vector4(inst, machine, result);
908 }
909 break;
910 case OPCODE_IF:
Brian63556fa2007-03-23 14:47:46 -0600911 {
912 GLboolean cond;
913 /* eval condition */
914 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
915 GLfloat a[4];
916 fetch_vector1(&inst->SrcReg[0], machine, a);
917 cond = (a[0] != 0.0);
918 }
919 else {
920 cond = eval_condition(machine, inst);
921 }
Briana7f73662007-04-20 08:11:51 -0600922 if (DEBUG_PROG) {
923 printf("IF: %d\n", cond);
924 }
Brian63556fa2007-03-23 14:47:46 -0600925 /* do if/else */
926 if (cond) {
927 /* do if-clause (just continue execution) */
928 }
929 else {
930 /* go to the instruction after ELSE or ENDIF */
931 assert(inst->BranchTarget >= 0);
932 pc = inst->BranchTarget - 1;
933 }
Briane80d9012007-02-23 16:53:24 -0700934 }
935 break;
936 case OPCODE_ELSE:
937 /* goto ENDIF */
938 assert(inst->BranchTarget >= 0);
939 pc = inst->BranchTarget - 1;
940 break;
941 case OPCODE_ENDIF:
942 /* nothing */
943 break;
Briane80d9012007-02-23 16:53:24 -0700944 case OPCODE_KIL_NV: /* NV_f_p only (conditional) */
945 if (eval_condition(machine, inst)) {
946 return GL_FALSE;
947 }
948 break;
949 case OPCODE_KIL: /* ARB_f_p only */
950 {
951 GLfloat a[4];
Brian33eac562007-02-25 18:52:41 -0700952 fetch_vector4(&inst->SrcReg[0], machine, a);
Brian Paulc0633dd2009-08-31 14:57:59 -0600953 if (DEBUG_PROG) {
954 printf("KIL if (%g %g %g %g) <= 0.0\n",
955 a[0], a[1], a[2], a[3]);
956 }
957
Briane80d9012007-02-23 16:53:24 -0700958 if (a[0] < 0.0F || a[1] < 0.0F || a[2] < 0.0F || a[3] < 0.0F) {
Brian13e3b212007-02-22 16:09:40 -0700959 return GL_FALSE;
960 }
Briane80d9012007-02-23 16:53:24 -0700961 }
962 break;
963 case OPCODE_LG2: /* log base 2 */
964 {
Brian Paul035de6a2009-06-03 15:42:52 -0600965 GLfloat a[4], result[4], val;
Brian33eac562007-02-25 18:52:41 -0700966 fetch_vector1(&inst->SrcReg[0], machine, a);
Ian Romanick962fa6b2008-12-18 14:11:06 -0800967 /* The fast LOG2 macro doesn't meet the precision requirements.
968 */
Brian Paul035de6a2009-06-03 15:42:52 -0600969 if (a[0] == 0.0F) {
Vinson Lee18883cd2009-10-01 13:33:20 -0600970 val = -FLT_MAX;
Brian Paul035de6a2009-06-03 15:42:52 -0600971 }
972 else {
973 val = log(a[0]) * 1.442695F;
974 }
975 result[0] = result[1] = result[2] = result[3] = val;
Briane80d9012007-02-23 16:53:24 -0700976 store_vector4(inst, machine, result);
977 }
978 break;
979 case OPCODE_LIT:
980 {
981 const GLfloat epsilon = 1.0F / 256.0F; /* from NV VP spec */
982 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700983 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -0700984 a[0] = MAX2(a[0], 0.0F);
985 a[1] = MAX2(a[1], 0.0F);
986 /* XXX ARB version clamps a[3], NV version doesn't */
987 a[3] = CLAMP(a[3], -(128.0F - epsilon), (128.0F - epsilon));
988 result[0] = 1.0F;
989 result[1] = a[0];
990 /* XXX we could probably just use pow() here */
991 if (a[0] > 0.0F) {
992 if (a[1] == 0.0 && a[3] == 0.0)
993 result[2] = 1.0;
994 else
Brian Paulb8a200a2009-04-03 10:29:11 -0600995 result[2] = (GLfloat) _mesa_pow(a[1], a[3]);
Brian13e3b212007-02-22 16:09:40 -0700996 }
Briane80d9012007-02-23 16:53:24 -0700997 else {
998 result[2] = 0.0;
Brian13e3b212007-02-22 16:09:40 -0700999 }
Briane80d9012007-02-23 16:53:24 -07001000 result[3] = 1.0F;
1001 store_vector4(inst, machine, result);
1002 if (DEBUG_PROG) {
1003 printf("LIT (%g %g %g %g) : (%g %g %g %g)\n",
1004 result[0], result[1], result[2], result[3],
1005 a[0], a[1], a[2], a[3]);
Brian13e3b212007-02-22 16:09:40 -07001006 }
Briane80d9012007-02-23 16:53:24 -07001007 }
1008 break;
Brianf183a2d2007-02-23 17:14:30 -07001009 case OPCODE_LOG:
1010 {
1011 GLfloat t[4], q[4], abs_t0;
Brian33eac562007-02-25 18:52:41 -07001012 fetch_vector1(&inst->SrcReg[0], machine, t);
Brianf183a2d2007-02-23 17:14:30 -07001013 abs_t0 = FABSF(t[0]);
1014 if (abs_t0 != 0.0F) {
1015 /* Since we really can't handle infinite values on VMS
1016 * like other OSes we'll use __MAXFLOAT to represent
1017 * infinity. This may need some tweaking.
1018 */
1019#ifdef VMS
1020 if (abs_t0 == __MAXFLOAT)
1021#else
1022 if (IS_INF_OR_NAN(abs_t0))
1023#endif
1024 {
1025 SET_POS_INFINITY(q[0]);
1026 q[1] = 1.0F;
1027 SET_POS_INFINITY(q[2]);
1028 }
1029 else {
1030 int exponent;
1031 GLfloat mantissa = FREXPF(t[0], &exponent);
1032 q[0] = (GLfloat) (exponent - 1);
1033 q[1] = (GLfloat) (2.0 * mantissa); /* map [.5, 1) -> [1, 2) */
Ian Romanick962fa6b2008-12-18 14:11:06 -08001034
1035 /* The fast LOG2 macro doesn't meet the precision
1036 * requirements.
1037 */
1038 q[2] = (log(t[0]) * 1.442695F);
Brianf183a2d2007-02-23 17:14:30 -07001039 }
1040 }
1041 else {
1042 SET_NEG_INFINITY(q[0]);
1043 q[1] = 1.0F;
1044 SET_NEG_INFINITY(q[2]);
1045 }
1046 q[3] = 1.0;
1047 store_vector4(inst, machine, q);
1048 }
1049 break;
Briane80d9012007-02-23 16:53:24 -07001050 case OPCODE_LRP:
1051 {
1052 GLfloat a[4], b[4], c[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001053 fetch_vector4(&inst->SrcReg[0], machine, a);
1054 fetch_vector4(&inst->SrcReg[1], machine, b);
1055 fetch_vector4(&inst->SrcReg[2], machine, c);
Briane80d9012007-02-23 16:53:24 -07001056 result[0] = a[0] * b[0] + (1.0F - a[0]) * c[0];
1057 result[1] = a[1] * b[1] + (1.0F - a[1]) * c[1];
1058 result[2] = a[2] * b[2] + (1.0F - a[2]) * c[2];
1059 result[3] = a[3] * b[3] + (1.0F - a[3]) * c[3];
1060 store_vector4(inst, machine, result);
1061 if (DEBUG_PROG) {
1062 printf("LRP (%g %g %g %g) = (%g %g %g %g), "
1063 "(%g %g %g %g), (%g %g %g %g)\n",
1064 result[0], result[1], result[2], result[3],
1065 a[0], a[1], a[2], a[3],
1066 b[0], b[1], b[2], b[3], c[0], c[1], c[2], c[3]);
Brian13e3b212007-02-22 16:09:40 -07001067 }
Briane80d9012007-02-23 16:53:24 -07001068 }
1069 break;
1070 case OPCODE_MAD:
1071 {
1072 GLfloat a[4], b[4], c[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001073 fetch_vector4(&inst->SrcReg[0], machine, a);
1074 fetch_vector4(&inst->SrcReg[1], machine, b);
1075 fetch_vector4(&inst->SrcReg[2], machine, c);
Briane80d9012007-02-23 16:53:24 -07001076 result[0] = a[0] * b[0] + c[0];
1077 result[1] = a[1] * b[1] + c[1];
1078 result[2] = a[2] * b[2] + c[2];
1079 result[3] = a[3] * b[3] + c[3];
1080 store_vector4(inst, machine, result);
1081 if (DEBUG_PROG) {
1082 printf("MAD (%g %g %g %g) = (%g %g %g %g) * "
1083 "(%g %g %g %g) + (%g %g %g %g)\n",
1084 result[0], result[1], result[2], result[3],
1085 a[0], a[1], a[2], a[3],
1086 b[0], b[1], b[2], b[3], c[0], c[1], c[2], c[3]);
Brian13e3b212007-02-22 16:09:40 -07001087 }
Briane80d9012007-02-23 16:53:24 -07001088 }
1089 break;
1090 case OPCODE_MAX:
1091 {
1092 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001093 fetch_vector4(&inst->SrcReg[0], machine, a);
1094 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001095 result[0] = MAX2(a[0], b[0]);
1096 result[1] = MAX2(a[1], b[1]);
1097 result[2] = MAX2(a[2], b[2]);
1098 result[3] = MAX2(a[3], b[3]);
1099 store_vector4(inst, machine, result);
1100 if (DEBUG_PROG) {
1101 printf("MAX (%g %g %g %g) = (%g %g %g %g), (%g %g %g %g)\n",
1102 result[0], result[1], result[2], result[3],
1103 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -07001104 }
Briane80d9012007-02-23 16:53:24 -07001105 }
1106 break;
1107 case OPCODE_MIN:
1108 {
1109 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001110 fetch_vector4(&inst->SrcReg[0], machine, a);
1111 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001112 result[0] = MIN2(a[0], b[0]);
1113 result[1] = MIN2(a[1], b[1]);
1114 result[2] = MIN2(a[2], b[2]);
1115 result[3] = MIN2(a[3], b[3]);
1116 store_vector4(inst, machine, result);
1117 }
1118 break;
1119 case OPCODE_MOV:
1120 {
1121 GLfloat result[4];
Brian33eac562007-02-25 18:52:41 -07001122 fetch_vector4(&inst->SrcReg[0], machine, result);
Briane80d9012007-02-23 16:53:24 -07001123 store_vector4(inst, machine, result);
1124 if (DEBUG_PROG) {
1125 printf("MOV (%g %g %g %g)\n",
1126 result[0], result[1], result[2], result[3]);
Brian13e3b212007-02-22 16:09:40 -07001127 }
Briane80d9012007-02-23 16:53:24 -07001128 }
1129 break;
1130 case OPCODE_MUL:
1131 {
1132 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001133 fetch_vector4(&inst->SrcReg[0], machine, a);
1134 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001135 result[0] = a[0] * b[0];
1136 result[1] = a[1] * b[1];
1137 result[2] = a[2] * b[2];
1138 result[3] = a[3] * b[3];
1139 store_vector4(inst, machine, result);
1140 if (DEBUG_PROG) {
1141 printf("MUL (%g %g %g %g) = (%g %g %g %g) * (%g %g %g %g)\n",
1142 result[0], result[1], result[2], result[3],
1143 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -07001144 }
Briane80d9012007-02-23 16:53:24 -07001145 }
1146 break;
1147 case OPCODE_NOISE1:
1148 {
1149 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001150 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001151 result[0] =
Brian13e3b212007-02-22 16:09:40 -07001152 result[1] =
Brian Paul702b5b02008-12-15 18:37:39 -07001153 result[2] =
1154 result[3] = _mesa_noise1(a[0]);
Briane80d9012007-02-23 16:53:24 -07001155 store_vector4(inst, machine, result);
1156 }
1157 break;
1158 case OPCODE_NOISE2:
1159 {
1160 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001161 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001162 result[0] =
Brian13e3b212007-02-22 16:09:40 -07001163 result[1] =
Brian Paul702b5b02008-12-15 18:37:39 -07001164 result[2] = result[3] = _mesa_noise2(a[0], a[1]);
Briane80d9012007-02-23 16:53:24 -07001165 store_vector4(inst, machine, result);
1166 }
1167 break;
1168 case OPCODE_NOISE3:
1169 {
1170 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001171 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001172 result[0] =
Brian13e3b212007-02-22 16:09:40 -07001173 result[1] =
1174 result[2] =
Brian Paul702b5b02008-12-15 18:37:39 -07001175 result[3] = _mesa_noise3(a[0], a[1], a[2]);
Briane80d9012007-02-23 16:53:24 -07001176 store_vector4(inst, machine, result);
1177 }
1178 break;
1179 case OPCODE_NOISE4:
1180 {
1181 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001182 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001183 result[0] =
Brian13e3b212007-02-22 16:09:40 -07001184 result[1] =
1185 result[2] =
Brian Paul702b5b02008-12-15 18:37:39 -07001186 result[3] = _mesa_noise4(a[0], a[1], a[2], a[3]);
Briane80d9012007-02-23 16:53:24 -07001187 store_vector4(inst, machine, result);
1188 }
1189 break;
1190 case OPCODE_NOP:
1191 break;
Brian Paul37eef7b2008-11-07 09:33:55 -07001192 case OPCODE_NOT: /* bitwise NOT */
1193 {
1194 GLuint a[4], result[4];
1195 fetch_vector4ui(&inst->SrcReg[0], machine, a);
1196 result[0] = ~a[0];
1197 result[1] = ~a[1];
1198 result[2] = ~a[2];
1199 result[3] = ~a[3];
1200 store_vector4ui(inst, machine, result);
1201 }
1202 break;
Brian Paulf6ead502008-11-07 08:51:31 -07001203 case OPCODE_NRM3: /* 3-component normalization */
1204 {
1205 GLfloat a[4], result[4];
1206 GLfloat tmp;
1207 fetch_vector4(&inst->SrcReg[0], machine, a);
1208 tmp = a[0] * a[0] + a[1] * a[1] + a[2] * a[2];
1209 if (tmp != 0.0F)
Brian Paul22459e72008-11-07 12:59:36 -07001210 tmp = INV_SQRTF(tmp);
Brian Paulf6ead502008-11-07 08:51:31 -07001211 result[0] = tmp * a[0];
1212 result[1] = tmp * a[1];
1213 result[2] = tmp * a[2];
1214 result[3] = 0.0; /* undefined, but prevent valgrind warnings */
1215 store_vector4(inst, machine, result);
1216 }
1217 break;
1218 case OPCODE_NRM4: /* 4-component normalization */
1219 {
1220 GLfloat a[4], result[4];
1221 GLfloat tmp;
1222 fetch_vector4(&inst->SrcReg[0], machine, a);
1223 tmp = a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3];
1224 if (tmp != 0.0F)
Brian Paul22459e72008-11-07 12:59:36 -07001225 tmp = INV_SQRTF(tmp);
Brian Paulf6ead502008-11-07 08:51:31 -07001226 result[0] = tmp * a[0];
1227 result[1] = tmp * a[1];
1228 result[2] = tmp * a[2];
1229 result[3] = tmp * a[3];
1230 store_vector4(inst, machine, result);
1231 }
1232 break;
Brian Paul37eef7b2008-11-07 09:33:55 -07001233 case OPCODE_OR: /* bitwise OR */
1234 {
1235 GLuint a[4], b[4], result[4];
1236 fetch_vector4ui(&inst->SrcReg[0], machine, a);
1237 fetch_vector4ui(&inst->SrcReg[1], machine, b);
1238 result[0] = a[0] | b[0];
1239 result[1] = a[1] | b[1];
1240 result[2] = a[2] | b[2];
1241 result[3] = a[3] | b[3];
1242 store_vector4ui(inst, machine, result);
1243 }
1244 break;
Briane80d9012007-02-23 16:53:24 -07001245 case OPCODE_PK2H: /* pack two 16-bit floats in one 32-bit float */
1246 {
Brian Paul37eef7b2008-11-07 09:33:55 -07001247 GLfloat a[4];
1248 GLuint result[4];
Briane80d9012007-02-23 16:53:24 -07001249 GLhalfNV hx, hy;
Brian33eac562007-02-25 18:52:41 -07001250 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001251 hx = _mesa_float_to_half(a[0]);
1252 hy = _mesa_float_to_half(a[1]);
Brian Paul37eef7b2008-11-07 09:33:55 -07001253 result[0] =
1254 result[1] =
1255 result[2] =
1256 result[3] = hx | (hy << 16);
1257 store_vector4ui(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -07001258 }
1259 break;
1260 case OPCODE_PK2US: /* pack two GLushorts into one 32-bit float */
1261 {
Brian Paul37eef7b2008-11-07 09:33:55 -07001262 GLfloat a[4];
1263 GLuint result[4], usx, usy;
Brian33eac562007-02-25 18:52:41 -07001264 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001265 a[0] = CLAMP(a[0], 0.0F, 1.0F);
1266 a[1] = CLAMP(a[1], 0.0F, 1.0F);
1267 usx = IROUND(a[0] * 65535.0F);
1268 usy = IROUND(a[1] * 65535.0F);
Brian Paul37eef7b2008-11-07 09:33:55 -07001269 result[0] =
1270 result[1] =
1271 result[2] =
1272 result[3] = usx | (usy << 16);
1273 store_vector4ui(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -07001274 }
1275 break;
1276 case OPCODE_PK4B: /* pack four GLbytes into one 32-bit float */
1277 {
Brian Paul37eef7b2008-11-07 09:33:55 -07001278 GLfloat a[4];
1279 GLuint result[4], ubx, uby, ubz, ubw;
Brian33eac562007-02-25 18:52:41 -07001280 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001281 a[0] = CLAMP(a[0], -128.0F / 127.0F, 1.0F);
1282 a[1] = CLAMP(a[1], -128.0F / 127.0F, 1.0F);
1283 a[2] = CLAMP(a[2], -128.0F / 127.0F, 1.0F);
1284 a[3] = CLAMP(a[3], -128.0F / 127.0F, 1.0F);
1285 ubx = IROUND(127.0F * a[0] + 128.0F);
1286 uby = IROUND(127.0F * a[1] + 128.0F);
1287 ubz = IROUND(127.0F * a[2] + 128.0F);
1288 ubw = IROUND(127.0F * a[3] + 128.0F);
Brian Paul37eef7b2008-11-07 09:33:55 -07001289 result[0] =
1290 result[1] =
1291 result[2] =
1292 result[3] = ubx | (uby << 8) | (ubz << 16) | (ubw << 24);
1293 store_vector4ui(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -07001294 }
1295 break;
1296 case OPCODE_PK4UB: /* pack four GLubytes into one 32-bit float */
1297 {
Brian Paul37eef7b2008-11-07 09:33:55 -07001298 GLfloat a[4];
1299 GLuint result[4], ubx, uby, ubz, ubw;
Brian33eac562007-02-25 18:52:41 -07001300 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001301 a[0] = CLAMP(a[0], 0.0F, 1.0F);
1302 a[1] = CLAMP(a[1], 0.0F, 1.0F);
1303 a[2] = CLAMP(a[2], 0.0F, 1.0F);
1304 a[3] = CLAMP(a[3], 0.0F, 1.0F);
1305 ubx = IROUND(255.0F * a[0]);
1306 uby = IROUND(255.0F * a[1]);
1307 ubz = IROUND(255.0F * a[2]);
1308 ubw = IROUND(255.0F * a[3]);
Brian Paul37eef7b2008-11-07 09:33:55 -07001309 result[0] =
1310 result[1] =
1311 result[2] =
1312 result[3] = ubx | (uby << 8) | (ubz << 16) | (ubw << 24);
1313 store_vector4ui(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -07001314 }
1315 break;
1316 case OPCODE_POW:
1317 {
1318 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001319 fetch_vector1(&inst->SrcReg[0], machine, a);
1320 fetch_vector1(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001321 result[0] = result[1] = result[2] = result[3]
1322 = (GLfloat) _mesa_pow(a[0], b[0]);
1323 store_vector4(inst, machine, result);
1324 }
1325 break;
1326 case OPCODE_RCP:
1327 {
1328 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001329 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001330 if (DEBUG_PROG) {
1331 if (a[0] == 0)
1332 printf("RCP(0)\n");
1333 else if (IS_INF_OR_NAN(a[0]))
1334 printf("RCP(inf)\n");
Brian13e3b212007-02-22 16:09:40 -07001335 }
Briane80d9012007-02-23 16:53:24 -07001336 result[0] = result[1] = result[2] = result[3] = 1.0F / a[0];
1337 store_vector4(inst, machine, result);
1338 }
1339 break;
1340 case OPCODE_RET: /* return from subroutine (conditional) */
1341 if (eval_condition(machine, inst)) {
1342 if (machine->StackDepth == 0) {
1343 return GL_TRUE; /* Per GL_NV_vertex_program2 spec */
Brian13e3b212007-02-22 16:09:40 -07001344 }
Briana0275b02007-03-27 11:02:20 -06001345 /* subtract one because of pc++ in the for loop */
1346 pc = machine->CallStack[--machine->StackDepth] - 1;
Briane80d9012007-02-23 16:53:24 -07001347 }
1348 break;
1349 case OPCODE_RFL: /* reflection vector */
1350 {
1351 GLfloat axis[4], dir[4], result[4], tmpX, tmpW;
Brian33eac562007-02-25 18:52:41 -07001352 fetch_vector4(&inst->SrcReg[0], machine, axis);
1353 fetch_vector4(&inst->SrcReg[1], machine, dir);
Briane80d9012007-02-23 16:53:24 -07001354 tmpW = DOT3(axis, axis);
1355 tmpX = (2.0F * DOT3(axis, dir)) / tmpW;
1356 result[0] = tmpX * axis[0] - dir[0];
1357 result[1] = tmpX * axis[1] - dir[1];
1358 result[2] = tmpX * axis[2] - dir[2];
1359 /* result[3] is never written! XXX enforce in parser! */
1360 store_vector4(inst, machine, result);
1361 }
1362 break;
1363 case OPCODE_RSQ: /* 1 / sqrt() */
1364 {
1365 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001366 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001367 a[0] = FABSF(a[0]);
1368 result[0] = result[1] = result[2] = result[3] = INV_SQRTF(a[0]);
1369 store_vector4(inst, machine, result);
1370 if (DEBUG_PROG) {
1371 printf("RSQ %g = 1/sqrt(|%g|)\n", result[0], a[0]);
Brian13e3b212007-02-22 16:09:40 -07001372 }
Briane80d9012007-02-23 16:53:24 -07001373 }
1374 break;
1375 case OPCODE_SCS: /* sine and cos */
1376 {
1377 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001378 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001379 result[0] = (GLfloat) _mesa_cos(a[0]);
1380 result[1] = (GLfloat) _mesa_sin(a[0]);
1381 result[2] = 0.0; /* undefined! */
1382 result[3] = 0.0; /* undefined! */
1383 store_vector4(inst, machine, result);
1384 }
1385 break;
1386 case OPCODE_SEQ: /* set on equal */
1387 {
1388 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001389 fetch_vector4(&inst->SrcReg[0], machine, a);
1390 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001391 result[0] = (a[0] == b[0]) ? 1.0F : 0.0F;
1392 result[1] = (a[1] == b[1]) ? 1.0F : 0.0F;
1393 result[2] = (a[2] == b[2]) ? 1.0F : 0.0F;
1394 result[3] = (a[3] == b[3]) ? 1.0F : 0.0F;
1395 store_vector4(inst, machine, result);
Brian28ab1122007-03-06 12:15:30 -07001396 if (DEBUG_PROG) {
1397 printf("SEQ (%g %g %g %g) = (%g %g %g %g) == (%g %g %g %g)\n",
1398 result[0], result[1], result[2], result[3],
1399 a[0], a[1], a[2], a[3],
1400 b[0], b[1], b[2], b[3]);
1401 }
Briane80d9012007-02-23 16:53:24 -07001402 }
1403 break;
1404 case OPCODE_SFL: /* set false, operands ignored */
1405 {
1406 static const GLfloat result[4] = { 0.0F, 0.0F, 0.0F, 0.0F };
1407 store_vector4(inst, machine, result);
1408 }
1409 break;
1410 case OPCODE_SGE: /* set on greater or equal */
1411 {
1412 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001413 fetch_vector4(&inst->SrcReg[0], machine, a);
1414 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001415 result[0] = (a[0] >= b[0]) ? 1.0F : 0.0F;
1416 result[1] = (a[1] >= b[1]) ? 1.0F : 0.0F;
1417 result[2] = (a[2] >= b[2]) ? 1.0F : 0.0F;
1418 result[3] = (a[3] >= b[3]) ? 1.0F : 0.0F;
1419 store_vector4(inst, machine, result);
Brian28ab1122007-03-06 12:15:30 -07001420 if (DEBUG_PROG) {
1421 printf("SGE (%g %g %g %g) = (%g %g %g %g) >= (%g %g %g %g)\n",
1422 result[0], result[1], result[2], result[3],
1423 a[0], a[1], a[2], a[3],
1424 b[0], b[1], b[2], b[3]);
1425 }
Briane80d9012007-02-23 16:53:24 -07001426 }
1427 break;
1428 case OPCODE_SGT: /* set on greater */
1429 {
1430 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001431 fetch_vector4(&inst->SrcReg[0], machine, a);
1432 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001433 result[0] = (a[0] > b[0]) ? 1.0F : 0.0F;
1434 result[1] = (a[1] > b[1]) ? 1.0F : 0.0F;
1435 result[2] = (a[2] > b[2]) ? 1.0F : 0.0F;
1436 result[3] = (a[3] > b[3]) ? 1.0F : 0.0F;
1437 store_vector4(inst, machine, result);
1438 if (DEBUG_PROG) {
Brian28ab1122007-03-06 12:15:30 -07001439 printf("SGT (%g %g %g %g) = (%g %g %g %g) > (%g %g %g %g)\n",
1440 result[0], result[1], result[2], result[3],
1441 a[0], a[1], a[2], a[3],
1442 b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -07001443 }
Briane80d9012007-02-23 16:53:24 -07001444 }
1445 break;
1446 case OPCODE_SIN:
1447 {
1448 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001449 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001450 result[0] = result[1] = result[2] = result[3]
1451 = (GLfloat) _mesa_sin(a[0]);
1452 store_vector4(inst, machine, result);
1453 }
1454 break;
1455 case OPCODE_SLE: /* set on less or equal */
1456 {
1457 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001458 fetch_vector4(&inst->SrcReg[0], machine, a);
1459 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001460 result[0] = (a[0] <= b[0]) ? 1.0F : 0.0F;
1461 result[1] = (a[1] <= b[1]) ? 1.0F : 0.0F;
1462 result[2] = (a[2] <= b[2]) ? 1.0F : 0.0F;
1463 result[3] = (a[3] <= b[3]) ? 1.0F : 0.0F;
1464 store_vector4(inst, machine, result);
Brian28ab1122007-03-06 12:15:30 -07001465 if (DEBUG_PROG) {
1466 printf("SLE (%g %g %g %g) = (%g %g %g %g) <= (%g %g %g %g)\n",
1467 result[0], result[1], result[2], result[3],
1468 a[0], a[1], a[2], a[3],
1469 b[0], b[1], b[2], b[3]);
1470 }
Briane80d9012007-02-23 16:53:24 -07001471 }
1472 break;
1473 case OPCODE_SLT: /* set on less */
1474 {
1475 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001476 fetch_vector4(&inst->SrcReg[0], machine, a);
1477 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001478 result[0] = (a[0] < b[0]) ? 1.0F : 0.0F;
1479 result[1] = (a[1] < b[1]) ? 1.0F : 0.0F;
1480 result[2] = (a[2] < b[2]) ? 1.0F : 0.0F;
1481 result[3] = (a[3] < b[3]) ? 1.0F : 0.0F;
1482 store_vector4(inst, machine, result);
Brian28ab1122007-03-06 12:15:30 -07001483 if (DEBUG_PROG) {
1484 printf("SLT (%g %g %g %g) = (%g %g %g %g) < (%g %g %g %g)\n",
1485 result[0], result[1], result[2], result[3],
1486 a[0], a[1], a[2], a[3],
1487 b[0], b[1], b[2], b[3]);
1488 }
Briane80d9012007-02-23 16:53:24 -07001489 }
1490 break;
1491 case OPCODE_SNE: /* set on not equal */
1492 {
1493 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001494 fetch_vector4(&inst->SrcReg[0], machine, a);
1495 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001496 result[0] = (a[0] != b[0]) ? 1.0F : 0.0F;
1497 result[1] = (a[1] != b[1]) ? 1.0F : 0.0F;
1498 result[2] = (a[2] != b[2]) ? 1.0F : 0.0F;
1499 result[3] = (a[3] != b[3]) ? 1.0F : 0.0F;
1500 store_vector4(inst, machine, result);
Brian28ab1122007-03-06 12:15:30 -07001501 if (DEBUG_PROG) {
1502 printf("SNE (%g %g %g %g) = (%g %g %g %g) != (%g %g %g %g)\n",
1503 result[0], result[1], result[2], result[3],
1504 a[0], a[1], a[2], a[3],
1505 b[0], b[1], b[2], b[3]);
1506 }
Briane80d9012007-02-23 16:53:24 -07001507 }
1508 break;
Brian Paulf6ead502008-11-07 08:51:31 -07001509 case OPCODE_SSG: /* set sign (-1, 0 or +1) */
1510 {
1511 GLfloat a[4], result[4];
1512 fetch_vector4(&inst->SrcReg[0], machine, a);
1513 result[0] = (GLfloat) ((a[0] > 0.0F) - (a[0] < 0.0F));
1514 result[1] = (GLfloat) ((a[1] > 0.0F) - (a[1] < 0.0F));
1515 result[2] = (GLfloat) ((a[2] > 0.0F) - (a[2] < 0.0F));
1516 result[3] = (GLfloat) ((a[3] > 0.0F) - (a[3] < 0.0F));
1517 store_vector4(inst, machine, result);
1518 }
1519 break;
Briane80d9012007-02-23 16:53:24 -07001520 case OPCODE_STR: /* set true, operands ignored */
1521 {
1522 static const GLfloat result[4] = { 1.0F, 1.0F, 1.0F, 1.0F };
1523 store_vector4(inst, machine, result);
1524 }
1525 break;
1526 case OPCODE_SUB:
1527 {
1528 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001529 fetch_vector4(&inst->SrcReg[0], machine, a);
1530 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001531 result[0] = a[0] - b[0];
1532 result[1] = a[1] - b[1];
1533 result[2] = a[2] - b[2];
1534 result[3] = a[3] - b[3];
1535 store_vector4(inst, machine, result);
1536 if (DEBUG_PROG) {
1537 printf("SUB (%g %g %g %g) = (%g %g %g %g) - (%g %g %g %g)\n",
1538 result[0], result[1], result[2], result[3],
1539 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -07001540 }
Briane80d9012007-02-23 16:53:24 -07001541 }
1542 break;
1543 case OPCODE_SWZ: /* extended swizzle */
1544 {
1545 const struct prog_src_register *source = &inst->SrcReg[0];
Brian Paulf4361542008-11-11 10:47:10 -07001546 const GLfloat *src = get_src_register_pointer(source, machine);
Briane80d9012007-02-23 16:53:24 -07001547 GLfloat result[4];
1548 GLuint i;
1549 for (i = 0; i < 4; i++) {
1550 const GLuint swz = GET_SWZ(source->Swizzle, i);
1551 if (swz == SWIZZLE_ZERO)
1552 result[i] = 0.0;
1553 else if (swz == SWIZZLE_ONE)
1554 result[i] = 1.0;
Brian13e3b212007-02-22 16:09:40 -07001555 else {
Briane80d9012007-02-23 16:53:24 -07001556 ASSERT(swz >= 0);
1557 ASSERT(swz <= 3);
1558 result[i] = src[swz];
Brian13e3b212007-02-22 16:09:40 -07001559 }
Brian Paul7db7ff82009-04-14 22:14:30 -06001560 if (source->Negate & (1 << i))
Briane80d9012007-02-23 16:53:24 -07001561 result[i] = -result[i];
Brian13e3b212007-02-22 16:09:40 -07001562 }
Briane80d9012007-02-23 16:53:24 -07001563 store_vector4(inst, machine, result);
1564 }
1565 break;
1566 case OPCODE_TEX: /* Both ARB and NV frag prog */
Brian999b5562007-11-23 12:01:57 -07001567 /* Simple texel lookup */
Briane80d9012007-02-23 16:53:24 -07001568 {
Brian999b5562007-11-23 12:01:57 -07001569 GLfloat texcoord[4], color[4];
1570 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1571
1572 fetch_texel(ctx, machine, inst, texcoord, 0.0, color);
1573
Briane80d9012007-02-23 16:53:24 -07001574 if (DEBUG_PROG) {
Brian999b5562007-11-23 12:01:57 -07001575 printf("TEX (%g, %g, %g, %g) = texture[%d][%g, %g, %g, %g]\n",
Briane80d9012007-02-23 16:53:24 -07001576 color[0], color[1], color[2], color[3],
1577 inst->TexSrcUnit,
Brian999b5562007-11-23 12:01:57 -07001578 texcoord[0], texcoord[1], texcoord[2], texcoord[3]);
Briane80d9012007-02-23 16:53:24 -07001579 }
1580 store_vector4(inst, machine, color);
1581 }
1582 break;
1583 case OPCODE_TXB: /* GL_ARB_fragment_program only */
1584 /* Texel lookup with LOD bias */
1585 {
Brian999b5562007-11-23 12:01:57 -07001586 GLfloat texcoord[4], color[4], lodBias;
1587
1588 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1589
1590 /* texcoord[3] is the bias to add to lambda */
Brian Paul890f37d2009-09-23 13:34:30 -06001591 lodBias = texcoord[3];
Brian999b5562007-11-23 12:01:57 -07001592
1593 fetch_texel(ctx, machine, inst, texcoord, lodBias, color);
1594
Briane80d9012007-02-23 16:53:24 -07001595 store_vector4(inst, machine, color);
1596 }
1597 break;
1598 case OPCODE_TXD: /* GL_NV_fragment_program only */
1599 /* Texture lookup w/ partial derivatives for LOD */
1600 {
1601 GLfloat texcoord[4], dtdx[4], dtdy[4], color[4];
Brian33eac562007-02-25 18:52:41 -07001602 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1603 fetch_vector4(&inst->SrcReg[1], machine, dtdx);
1604 fetch_vector4(&inst->SrcReg[2], machine, dtdy);
Briane80d9012007-02-23 16:53:24 -07001605 machine->FetchTexelDeriv(ctx, texcoord, dtdx, dtdy,
Brian999b5562007-11-23 12:01:57 -07001606 0.0, /* lodBias */
Briane80d9012007-02-23 16:53:24 -07001607 inst->TexSrcUnit, color);
1608 store_vector4(inst, machine, color);
1609 }
1610 break;
1611 case OPCODE_TXP: /* GL_ARB_fragment_program only */
1612 /* Texture lookup w/ projective divide */
1613 {
Brian999b5562007-11-23 12:01:57 -07001614 GLfloat texcoord[4], color[4];
1615
Brian33eac562007-02-25 18:52:41 -07001616 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
Briane80d9012007-02-23 16:53:24 -07001617 /* Not so sure about this test - if texcoord[3] is
1618 * zero, we'd probably be fine except for an ASSERT in
1619 * IROUND_POS() which gets triggered by the inf values created.
1620 */
1621 if (texcoord[3] != 0.0) {
1622 texcoord[0] /= texcoord[3];
1623 texcoord[1] /= texcoord[3];
1624 texcoord[2] /= texcoord[3];
1625 }
Brian999b5562007-11-23 12:01:57 -07001626
1627 fetch_texel(ctx, machine, inst, texcoord, 0.0, color);
1628
Briane80d9012007-02-23 16:53:24 -07001629 store_vector4(inst, machine, color);
1630 }
1631 break;
1632 case OPCODE_TXP_NV: /* GL_NV_fragment_program only */
Brian999b5562007-11-23 12:01:57 -07001633 /* Texture lookup w/ projective divide, as above, but do not
1634 * do the divide by w if sampling from a cube map.
1635 */
Briane80d9012007-02-23 16:53:24 -07001636 {
Brian999b5562007-11-23 12:01:57 -07001637 GLfloat texcoord[4], color[4];
1638
Brian33eac562007-02-25 18:52:41 -07001639 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
Briane80d9012007-02-23 16:53:24 -07001640 if (inst->TexSrcTarget != TEXTURE_CUBE_INDEX &&
1641 texcoord[3] != 0.0) {
1642 texcoord[0] /= texcoord[3];
1643 texcoord[1] /= texcoord[3];
1644 texcoord[2] /= texcoord[3];
1645 }
Brian999b5562007-11-23 12:01:57 -07001646
1647 fetch_texel(ctx, machine, inst, texcoord, 0.0, color);
1648
Briane80d9012007-02-23 16:53:24 -07001649 store_vector4(inst, machine, color);
1650 }
1651 break;
Brian Paul035c0cf2008-11-06 17:14:33 -07001652 case OPCODE_TRUNC: /* truncate toward zero */
1653 {
1654 GLfloat a[4], result[4];
1655 fetch_vector4(&inst->SrcReg[0], machine, a);
1656 result[0] = (GLfloat) (GLint) a[0];
1657 result[1] = (GLfloat) (GLint) a[1];
1658 result[2] = (GLfloat) (GLint) a[2];
1659 result[3] = (GLfloat) (GLint) a[3];
1660 store_vector4(inst, machine, result);
1661 }
1662 break;
Briane80d9012007-02-23 16:53:24 -07001663 case OPCODE_UP2H: /* unpack two 16-bit floats */
1664 {
1665 GLfloat a[4], result[4];
Roland Scheidegger72362a52009-12-07 21:47:49 +01001666 fi_type fi;
Briane80d9012007-02-23 16:53:24 -07001667 GLhalfNV hx, hy;
Brian33eac562007-02-25 18:52:41 -07001668 fetch_vector1(&inst->SrcReg[0], machine, a);
Roland Scheidegger72362a52009-12-07 21:47:49 +01001669 fi.f = a[0];
1670 hx = fi.i & 0xffff;
1671 hy = fi.i >> 16;
Briane80d9012007-02-23 16:53:24 -07001672 result[0] = result[2] = _mesa_half_to_float(hx);
1673 result[1] = result[3] = _mesa_half_to_float(hy);
1674 store_vector4(inst, machine, result);
1675 }
1676 break;
1677 case OPCODE_UP2US: /* unpack two GLushorts */
1678 {
1679 GLfloat a[4], result[4];
Roland Scheidegger72362a52009-12-07 21:47:49 +01001680 fi_type fi;
Briane80d9012007-02-23 16:53:24 -07001681 GLushort usx, usy;
Brian33eac562007-02-25 18:52:41 -07001682 fetch_vector1(&inst->SrcReg[0], machine, a);
Roland Scheidegger72362a52009-12-07 21:47:49 +01001683 fi.f = a[0];
1684 usx = fi.i & 0xffff;
1685 usy = fi.i >> 16;
Briane80d9012007-02-23 16:53:24 -07001686 result[0] = result[2] = usx * (1.0f / 65535.0f);
1687 result[1] = result[3] = usy * (1.0f / 65535.0f);
1688 store_vector4(inst, machine, result);
1689 }
1690 break;
1691 case OPCODE_UP4B: /* unpack four GLbytes */
1692 {
1693 GLfloat a[4], result[4];
Roland Scheidegger72362a52009-12-07 21:47:49 +01001694 fi_type fi;
Brian33eac562007-02-25 18:52:41 -07001695 fetch_vector1(&inst->SrcReg[0], machine, a);
Roland Scheidegger72362a52009-12-07 21:47:49 +01001696 fi.f = a[0];
1697 result[0] = (((fi.i >> 0) & 0xff) - 128) / 127.0F;
1698 result[1] = (((fi.i >> 8) & 0xff) - 128) / 127.0F;
1699 result[2] = (((fi.i >> 16) & 0xff) - 128) / 127.0F;
1700 result[3] = (((fi.i >> 24) & 0xff) - 128) / 127.0F;
Briane80d9012007-02-23 16:53:24 -07001701 store_vector4(inst, machine, result);
1702 }
1703 break;
1704 case OPCODE_UP4UB: /* unpack four GLubytes */
1705 {
1706 GLfloat a[4], result[4];
Roland Scheidegger72362a52009-12-07 21:47:49 +01001707 fi_type fi;
Brian33eac562007-02-25 18:52:41 -07001708 fetch_vector1(&inst->SrcReg[0], machine, a);
Roland Scheidegger72362a52009-12-07 21:47:49 +01001709 fi.f = a[0];
1710 result[0] = ((fi.i >> 0) & 0xff) / 255.0F;
1711 result[1] = ((fi.i >> 8) & 0xff) / 255.0F;
1712 result[2] = ((fi.i >> 16) & 0xff) / 255.0F;
1713 result[3] = ((fi.i >> 24) & 0xff) / 255.0F;
Briane80d9012007-02-23 16:53:24 -07001714 store_vector4(inst, machine, result);
1715 }
1716 break;
Brian Paul37eef7b2008-11-07 09:33:55 -07001717 case OPCODE_XOR: /* bitwise XOR */
1718 {
1719 GLuint a[4], b[4], result[4];
1720 fetch_vector4ui(&inst->SrcReg[0], machine, a);
1721 fetch_vector4ui(&inst->SrcReg[1], machine, b);
1722 result[0] = a[0] ^ b[0];
1723 result[1] = a[1] ^ b[1];
1724 result[2] = a[2] ^ b[2];
1725 result[3] = a[3] ^ b[3];
1726 store_vector4ui(inst, machine, result);
1727 }
1728 break;
Briane80d9012007-02-23 16:53:24 -07001729 case OPCODE_XPD: /* cross product */
1730 {
1731 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001732 fetch_vector4(&inst->SrcReg[0], machine, a);
1733 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001734 result[0] = a[1] * b[2] - a[2] * b[1];
1735 result[1] = a[2] * b[0] - a[0] * b[2];
1736 result[2] = a[0] * b[1] - a[1] * b[0];
1737 result[3] = 1.0;
1738 store_vector4(inst, machine, result);
Brian9637c962007-03-07 17:40:57 -07001739 if (DEBUG_PROG) {
1740 printf("XPD (%g %g %g %g) = (%g %g %g) X (%g %g %g)\n",
1741 result[0], result[1], result[2], result[3],
1742 a[0], a[1], a[2], b[0], b[1], b[2]);
1743 }
Briane80d9012007-02-23 16:53:24 -07001744 }
1745 break;
1746 case OPCODE_X2D: /* 2-D matrix transform */
1747 {
1748 GLfloat a[4], b[4], c[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001749 fetch_vector4(&inst->SrcReg[0], machine, a);
1750 fetch_vector4(&inst->SrcReg[1], machine, b);
1751 fetch_vector4(&inst->SrcReg[2], machine, c);
Briane80d9012007-02-23 16:53:24 -07001752 result[0] = a[0] + b[0] * c[0] + b[1] * c[1];
1753 result[1] = a[1] + b[0] * c[2] + b[1] * c[3];
1754 result[2] = a[2] + b[0] * c[0] + b[1] * c[1];
1755 result[3] = a[3] + b[0] * c[2] + b[1] * c[3];
1756 store_vector4(inst, machine, result);
1757 }
1758 break;
1759 case OPCODE_PRINT:
1760 {
1761 if (inst->SrcReg[0].File != -1) {
1762 GLfloat a[4];
Brian33eac562007-02-25 18:52:41 -07001763 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001764 _mesa_printf("%s%g, %g, %g, %g\n", (const char *) inst->Data,
1765 a[0], a[1], a[2], a[3]);
1766 }
1767 else {
1768 _mesa_printf("%s\n", (const char *) inst->Data);
1769 }
1770 }
1771 break;
1772 case OPCODE_END:
1773 return GL_TRUE;
1774 default:
Alan Hourihane936dba12008-04-22 20:28:35 +01001775 _mesa_problem(ctx, "Bad opcode %d in _mesa_execute_program",
Briane80d9012007-02-23 16:53:24 -07001776 inst->Opcode);
1777 return GL_TRUE; /* return value doesn't matter */
Brian13e3b212007-02-22 16:09:40 -07001778 }
Briane80d9012007-02-23 16:53:24 -07001779
Briancfd00112007-02-25 18:30:45 -07001780 numExec++;
1781 if (numExec > maxExec) {
Brian13e3b212007-02-22 16:09:40 -07001782 _mesa_problem(ctx, "Infinite loop detected in fragment program");
1783 return GL_TRUE;
Brian13e3b212007-02-22 16:09:40 -07001784 }
Briane80d9012007-02-23 16:53:24 -07001785
1786 } /* for pc */
Brian13e3b212007-02-22 16:09:40 -07001787
Brian13e3b212007-02-22 16:09:40 -07001788 return GL_TRUE;
1789}