blob: 7ea792f6193c181daa00c578531b58a73a0eaec0 [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 "prog_execute.h"
42#include "prog_instruction.h"
43#include "prog_parameter.h"
44#include "prog_print.h"
Brian Paul702b5b02008-12-15 18:37:39 -070045#include "prog_noise.h"
Brian13e3b212007-02-22 16:09:40 -070046
47
Brian13e3b212007-02-22 16:09:40 -070048/* debug predicate */
49#define DEBUG_PROG 0
50
51
Brianf183a2d2007-02-23 17:14:30 -070052/**
53 * Set x to positive or negative infinity.
54 */
55#if defined(USE_IEEE) || defined(_WIN32)
Roland Scheidegger72362a52009-12-07 21:47:49 +010056#define SET_POS_INFINITY(x) \
57 do { \
58 fi_type fi; \
59 fi.i = 0x7F800000; \
60 x = fi.f; \
61 } while (0)
62#define SET_NEG_INFINITY(x) \
63 do { \
64 fi_type fi; \
65 fi.i = 0xFF800000; \
66 x = fi.f; \
67 } while (0)
Brianf183a2d2007-02-23 17:14:30 -070068#elif defined(VMS)
69#define SET_POS_INFINITY(x) x = __MAXFLOAT
70#define SET_NEG_INFINITY(x) x = -__MAXFLOAT
71#else
72#define SET_POS_INFINITY(x) x = (GLfloat) HUGE_VAL
73#define SET_NEG_INFINITY(x) x = (GLfloat) -HUGE_VAL
74#endif
75
76#define SET_FLOAT_BITS(x, bits) ((fi_type *) (void *) &(x))->i = bits
77
78
79static const GLfloat ZeroVec[4] = { 0.0F, 0.0F, 0.0F, 0.0F };
80
81
82
Brian13e3b212007-02-22 16:09:40 -070083/**
84 * Return a pointer to the 4-element float vector specified by the given
85 * source register.
86 */
87static INLINE const GLfloat *
Brian Paulf4361542008-11-11 10:47:10 -070088get_src_register_pointer(const struct prog_src_register *source,
89 const struct gl_program_machine *machine)
Brian13e3b212007-02-22 16:09:40 -070090{
Brian Paulf4361542008-11-11 10:47:10 -070091 const struct gl_program *prog = machine->CurProgram;
92 GLint reg = source->Index;
93
Brianf183a2d2007-02-23 17:14:30 -070094 if (source->RelAddr) {
Brian Paulf4361542008-11-11 10:47:10 -070095 /* add address register value to src index/offset */
96 reg += machine->AddressReg[0][0];
97 if (reg < 0) {
98 return ZeroVec;
Brianf183a2d2007-02-23 17:14:30 -070099 }
100 }
101
Brian13e3b212007-02-22 16:09:40 -0700102 switch (source->File) {
103 case PROGRAM_TEMPORARY:
Brian Paulf4361542008-11-11 10:47:10 -0700104 if (reg >= MAX_PROGRAM_TEMPS)
105 return ZeroVec;
106 return machine->Temporaries[reg];
Brian13e3b212007-02-22 16:09:40 -0700107
108 case PROGRAM_INPUT:
Brian Paulf4361542008-11-11 10:47:10 -0700109 if (prog->Target == GL_VERTEX_PROGRAM_ARB) {
110 if (reg >= VERT_ATTRIB_MAX)
111 return ZeroVec;
112 return machine->VertAttribs[reg];
Brian13e3b212007-02-22 16:09:40 -0700113 }
114 else {
Brian Paulf4361542008-11-11 10:47:10 -0700115 if (reg >= FRAG_ATTRIB_MAX)
116 return ZeroVec;
117 return machine->Attribs[reg][machine->CurElement];
Brian13e3b212007-02-22 16:09:40 -0700118 }
119
120 case PROGRAM_OUTPUT:
Brian Paulf4361542008-11-11 10:47:10 -0700121 if (reg >= MAX_PROGRAM_OUTPUTS)
122 return ZeroVec;
123 return machine->Outputs[reg];
Brian13e3b212007-02-22 16:09:40 -0700124
125 case PROGRAM_LOCAL_PARAM:
Brian Paulf4361542008-11-11 10:47:10 -0700126 if (reg >= MAX_PROGRAM_LOCAL_PARAMS)
127 return ZeroVec;
128 return machine->CurProgram->LocalParams[reg];
Brian13e3b212007-02-22 16:09:40 -0700129
130 case PROGRAM_ENV_PARAM:
Brian Paulf4361542008-11-11 10:47:10 -0700131 if (reg >= MAX_PROGRAM_ENV_PARAMS)
132 return ZeroVec;
133 return machine->EnvParams[reg];
Brian13e3b212007-02-22 16:09:40 -0700134
135 case PROGRAM_STATE_VAR:
136 /* Fallthrough */
137 case PROGRAM_CONSTANT:
138 /* Fallthrough */
139 case PROGRAM_UNIFORM:
140 /* Fallthrough */
141 case PROGRAM_NAMED_PARAM:
Brian Paulf4361542008-11-11 10:47:10 -0700142 if (reg >= (GLint) prog->Parameters->NumParameters)
143 return ZeroVec;
144 return prog->Parameters->ParameterValues[reg];
Brian13e3b212007-02-22 16:09:40 -0700145
146 default:
Brian33eac562007-02-25 18:52:41 -0700147 _mesa_problem(NULL,
Brian Paulf4361542008-11-11 10:47:10 -0700148 "Invalid src register file %d in get_src_register_pointer()",
149 source->File);
Brian13e3b212007-02-22 16:09:40 -0700150 return NULL;
151 }
152}
153
154
Brian Paulf4361542008-11-11 10:47:10 -0700155/**
156 * Return a pointer to the 4-element float vector specified by the given
157 * destination register.
158 */
159static INLINE GLfloat *
160get_dst_register_pointer(const struct prog_dst_register *dest,
161 struct gl_program_machine *machine)
162{
163 static GLfloat dummyReg[4];
164 GLint reg = dest->Index;
165
166 if (dest->RelAddr) {
167 /* add address register value to src index/offset */
168 reg += machine->AddressReg[0][0];
169 if (reg < 0) {
170 return dummyReg;
171 }
172 }
173
174 switch (dest->File) {
175 case PROGRAM_TEMPORARY:
176 if (reg >= MAX_PROGRAM_TEMPS)
177 return dummyReg;
178 return machine->Temporaries[reg];
179
180 case PROGRAM_OUTPUT:
181 if (reg >= MAX_PROGRAM_OUTPUTS)
182 return dummyReg;
183 return machine->Outputs[reg];
184
185 case PROGRAM_WRITE_ONLY:
186 return dummyReg;
187
188 default:
189 _mesa_problem(NULL,
190 "Invalid dest register file %d in get_dst_register_pointer()",
191 dest->File);
192 return NULL;
193 }
194}
195
196
197
Brian13e3b212007-02-22 16:09:40 -0700198/**
199 * Fetch a 4-element float vector from the given source register.
200 * Apply swizzling and negating as needed.
201 */
202static void
Brian33eac562007-02-25 18:52:41 -0700203fetch_vector4(const struct prog_src_register *source,
Briane80d9012007-02-23 16:53:24 -0700204 const struct gl_program_machine *machine, GLfloat result[4])
Brian13e3b212007-02-22 16:09:40 -0700205{
Brian Paulf4361542008-11-11 10:47:10 -0700206 const GLfloat *src = get_src_register_pointer(source, machine);
Brian13e3b212007-02-22 16:09:40 -0700207 ASSERT(src);
208
209 if (source->Swizzle == SWIZZLE_NOOP) {
210 /* no swizzling */
211 COPY_4V(result, src);
212 }
213 else {
214 ASSERT(GET_SWZ(source->Swizzle, 0) <= 3);
215 ASSERT(GET_SWZ(source->Swizzle, 1) <= 3);
216 ASSERT(GET_SWZ(source->Swizzle, 2) <= 3);
217 ASSERT(GET_SWZ(source->Swizzle, 3) <= 3);
218 result[0] = src[GET_SWZ(source->Swizzle, 0)];
219 result[1] = src[GET_SWZ(source->Swizzle, 1)];
220 result[2] = src[GET_SWZ(source->Swizzle, 2)];
221 result[3] = src[GET_SWZ(source->Swizzle, 3)];
222 }
223
Brian13e3b212007-02-22 16:09:40 -0700224 if (source->Abs) {
225 result[0] = FABSF(result[0]);
226 result[1] = FABSF(result[1]);
227 result[2] = FABSF(result[2]);
228 result[3] = FABSF(result[3]);
229 }
Brian Paul7db7ff82009-04-14 22:14:30 -0600230 if (source->Negate) {
231 ASSERT(source->Negate == NEGATE_XYZW);
Brian13e3b212007-02-22 16:09:40 -0700232 result[0] = -result[0];
233 result[1] = -result[1];
234 result[2] = -result[2];
235 result[3] = -result[3];
236 }
Brian Paul92009542009-06-03 15:43:53 -0600237
238#ifdef NAN_CHECK
239 assert(!IS_INF_OR_NAN(result[0]));
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#endif
Brian13e3b212007-02-22 16:09:40 -0700244}
245
Brian62da6a12007-05-02 18:44:34 -0600246
Brian13e3b212007-02-22 16:09:40 -0700247/**
Brian Paul37eef7b2008-11-07 09:33:55 -0700248 * Fetch a 4-element uint vector from the given source register.
249 * Apply swizzling but not negation/abs.
250 */
251static void
252fetch_vector4ui(const struct prog_src_register *source,
253 const struct gl_program_machine *machine, GLuint result[4])
254{
Brian Paulf4361542008-11-11 10:47:10 -0700255 const GLuint *src = (GLuint *) get_src_register_pointer(source, machine);
Brian Paul37eef7b2008-11-07 09:33:55 -0700256 ASSERT(src);
257
258 if (source->Swizzle == SWIZZLE_NOOP) {
259 /* no swizzling */
260 COPY_4V(result, src);
261 }
262 else {
263 ASSERT(GET_SWZ(source->Swizzle, 0) <= 3);
264 ASSERT(GET_SWZ(source->Swizzle, 1) <= 3);
265 ASSERT(GET_SWZ(source->Swizzle, 2) <= 3);
266 ASSERT(GET_SWZ(source->Swizzle, 3) <= 3);
267 result[0] = src[GET_SWZ(source->Swizzle, 0)];
268 result[1] = src[GET_SWZ(source->Swizzle, 1)];
269 result[2] = src[GET_SWZ(source->Swizzle, 2)];
270 result[3] = src[GET_SWZ(source->Swizzle, 3)];
271 }
272
Brian Paul7db7ff82009-04-14 22:14:30 -0600273 /* Note: no Negate or Abs here */
Brian Paul37eef7b2008-11-07 09:33:55 -0700274}
275
276
277
278/**
Brian62da6a12007-05-02 18:44:34 -0600279 * Fetch the derivative with respect to X or Y for the given register.
280 * XXX this currently only works for fragment program input attribs.
Brian13e3b212007-02-22 16:09:40 -0700281 */
Brian62da6a12007-05-02 18:44:34 -0600282static void
Briane80d9012007-02-23 16:53:24 -0700283fetch_vector4_deriv(GLcontext * ctx,
284 const struct prog_src_register *source,
Brian62da6a12007-05-02 18:44:34 -0600285 const struct gl_program_machine *machine,
286 char xOrY, GLfloat result[4])
Brian13e3b212007-02-22 16:09:40 -0700287{
Brian Paul37eef7b2008-11-07 09:33:55 -0700288 if (source->File == PROGRAM_INPUT &&
289 source->Index < (GLint) machine->NumDeriv) {
Brian62da6a12007-05-02 18:44:34 -0600290 const GLint col = machine->CurElement;
291 const GLfloat w = machine->Attribs[FRAG_ATTRIB_WPOS][col][3];
292 const GLfloat invQ = 1.0f / w;
293 GLfloat deriv[4];
Brian13e3b212007-02-22 16:09:40 -0700294
Brian13e3b212007-02-22 16:09:40 -0700295 if (xOrY == 'X') {
Brian62da6a12007-05-02 18:44:34 -0600296 deriv[0] = machine->DerivX[source->Index][0] * invQ;
297 deriv[1] = machine->DerivX[source->Index][1] * invQ;
298 deriv[2] = machine->DerivX[source->Index][2] * invQ;
299 deriv[3] = machine->DerivX[source->Index][3] * invQ;
Brian13e3b212007-02-22 16:09:40 -0700300 }
301 else {
Brian62da6a12007-05-02 18:44:34 -0600302 deriv[0] = machine->DerivY[source->Index][0] * invQ;
303 deriv[1] = machine->DerivY[source->Index][1] * invQ;
304 deriv[2] = machine->DerivY[source->Index][2] * invQ;
305 deriv[3] = machine->DerivY[source->Index][3] * invQ;
Brian13e3b212007-02-22 16:09:40 -0700306 }
Brian13e3b212007-02-22 16:09:40 -0700307
Brian62da6a12007-05-02 18:44:34 -0600308 result[0] = deriv[GET_SWZ(source->Swizzle, 0)];
309 result[1] = deriv[GET_SWZ(source->Swizzle, 1)];
310 result[2] = deriv[GET_SWZ(source->Swizzle, 2)];
311 result[3] = deriv[GET_SWZ(source->Swizzle, 3)];
312
Brian62da6a12007-05-02 18:44:34 -0600313 if (source->Abs) {
314 result[0] = FABSF(result[0]);
315 result[1] = FABSF(result[1]);
316 result[2] = FABSF(result[2]);
317 result[3] = FABSF(result[3]);
318 }
Brian Paul7db7ff82009-04-14 22:14:30 -0600319 if (source->Negate) {
320 ASSERT(source->Negate == NEGATE_XYZW);
Brian62da6a12007-05-02 18:44:34 -0600321 result[0] = -result[0];
322 result[1] = -result[1];
323 result[2] = -result[2];
324 result[3] = -result[3];
325 }
Brian13e3b212007-02-22 16:09:40 -0700326 }
Brian62da6a12007-05-02 18:44:34 -0600327 else {
328 ASSIGN_4V(result, 0.0, 0.0, 0.0, 0.0);
Brian13e3b212007-02-22 16:09:40 -0700329 }
Brian13e3b212007-02-22 16:09:40 -0700330}
Brian13e3b212007-02-22 16:09:40 -0700331
332
333/**
334 * As above, but only return result[0] element.
335 */
336static void
Brian33eac562007-02-25 18:52:41 -0700337fetch_vector1(const struct prog_src_register *source,
Briane80d9012007-02-23 16:53:24 -0700338 const struct gl_program_machine *machine, GLfloat result[4])
Brian13e3b212007-02-22 16:09:40 -0700339{
Brian Paulf4361542008-11-11 10:47:10 -0700340 const GLfloat *src = get_src_register_pointer(source, machine);
Brian13e3b212007-02-22 16:09:40 -0700341 ASSERT(src);
342
343 result[0] = src[GET_SWZ(source->Swizzle, 0)];
344
Brian13e3b212007-02-22 16:09:40 -0700345 if (source->Abs) {
346 result[0] = FABSF(result[0]);
347 }
Brian Paul7db7ff82009-04-14 22:14:30 -0600348 if (source->Negate) {
Brian13e3b212007-02-22 16:09:40 -0700349 result[0] = -result[0];
350 }
351}
352
353
354/**
Brian999b5562007-11-23 12:01:57 -0700355 * Fetch texel from texture. Use partial derivatives when possible.
356 */
357static INLINE void
358fetch_texel(GLcontext *ctx,
359 const struct gl_program_machine *machine,
360 const struct prog_instruction *inst,
361 const GLfloat texcoord[4], GLfloat lodBias,
362 GLfloat color[4])
363{
Brian Paulade50832008-05-14 16:09:46 -0600364 const GLuint unit = machine->Samplers[inst->TexSrcUnit];
365
Brian999b5562007-11-23 12:01:57 -0700366 /* Note: we only have the right derivatives for fragment input attribs.
367 */
368 if (machine->NumDeriv > 0 &&
369 inst->SrcReg[0].File == PROGRAM_INPUT &&
370 inst->SrcReg[0].Index == FRAG_ATTRIB_TEX0 + inst->TexSrcUnit) {
371 /* simple texture fetch for which we should have derivatives */
372 GLuint attr = inst->SrcReg[0].Index;
373 machine->FetchTexelDeriv(ctx, texcoord,
374 machine->DerivX[attr],
375 machine->DerivY[attr],
Brian Paulade50832008-05-14 16:09:46 -0600376 lodBias, unit, color);
Brian999b5562007-11-23 12:01:57 -0700377 }
378 else {
Brian Paulade50832008-05-14 16:09:46 -0600379 machine->FetchTexelLod(ctx, texcoord, lodBias, unit, color);
Brian999b5562007-11-23 12:01:57 -0700380 }
381}
382
383
384/**
Brian13e3b212007-02-22 16:09:40 -0700385 * Test value against zero and return GT, LT, EQ or UN if NaN.
386 */
387static INLINE GLuint
Briane80d9012007-02-23 16:53:24 -0700388generate_cc(float value)
Brian13e3b212007-02-22 16:09:40 -0700389{
390 if (value != value)
Briane80d9012007-02-23 16:53:24 -0700391 return COND_UN; /* NaN */
Brian13e3b212007-02-22 16:09:40 -0700392 if (value > 0.0F)
393 return COND_GT;
394 if (value < 0.0F)
395 return COND_LT;
396 return COND_EQ;
397}
398
399
400/**
401 * Test if the ccMaskRule is satisfied by the given condition code.
402 * Used to mask destination writes according to the current condition code.
403 */
404static INLINE GLboolean
405test_cc(GLuint condCode, GLuint ccMaskRule)
406{
407 switch (ccMaskRule) {
408 case COND_EQ: return (condCode == COND_EQ);
409 case COND_NE: return (condCode != COND_EQ);
410 case COND_LT: return (condCode == COND_LT);
411 case COND_GE: return (condCode == COND_GT || condCode == COND_EQ);
412 case COND_LE: return (condCode == COND_LT || condCode == COND_EQ);
413 case COND_GT: return (condCode == COND_GT);
414 case COND_TR: return GL_TRUE;
415 case COND_FL: return GL_FALSE;
416 default: return GL_TRUE;
417 }
418}
419
420
421/**
422 * Evaluate the 4 condition codes against a predicate and return GL_TRUE
423 * or GL_FALSE to indicate result.
424 */
425static INLINE GLboolean
426eval_condition(const struct gl_program_machine *machine,
427 const struct prog_instruction *inst)
428{
429 const GLuint swizzle = inst->DstReg.CondSwizzle;
430 const GLuint condMask = inst->DstReg.CondMask;
431 if (test_cc(machine->CondCodes[GET_SWZ(swizzle, 0)], condMask) ||
432 test_cc(machine->CondCodes[GET_SWZ(swizzle, 1)], condMask) ||
433 test_cc(machine->CondCodes[GET_SWZ(swizzle, 2)], condMask) ||
434 test_cc(machine->CondCodes[GET_SWZ(swizzle, 3)], condMask)) {
435 return GL_TRUE;
436 }
437 else {
438 return GL_FALSE;
439 }
440}
441
442
443
444/**
445 * Store 4 floats into a register. Observe the instructions saturate and
446 * set-condition-code flags.
447 */
448static void
Briane80d9012007-02-23 16:53:24 -0700449store_vector4(const struct prog_instruction *inst,
450 struct gl_program_machine *machine, const GLfloat value[4])
Brian13e3b212007-02-22 16:09:40 -0700451{
Brian Paulf4361542008-11-11 10:47:10 -0700452 const struct prog_dst_register *dstReg = &(inst->DstReg);
Brian13e3b212007-02-22 16:09:40 -0700453 const GLboolean clamp = inst->SaturateMode == SATURATE_ZERO_ONE;
Brian Paulf4361542008-11-11 10:47:10 -0700454 GLuint writeMask = dstReg->WriteMask;
Brian13e3b212007-02-22 16:09:40 -0700455 GLfloat clampedValue[4];
Brian Paulf4361542008-11-11 10:47:10 -0700456 GLfloat *dst = get_dst_register_pointer(dstReg, machine);
Brian13e3b212007-02-22 16:09:40 -0700457
458#if 0
459 if (value[0] > 1.0e10 ||
460 IS_INF_OR_NAN(value[0]) ||
461 IS_INF_OR_NAN(value[1]) ||
Briane80d9012007-02-23 16:53:24 -0700462 IS_INF_OR_NAN(value[2]) || IS_INF_OR_NAN(value[3]))
Brian13e3b212007-02-22 16:09:40 -0700463 printf("store %g %g %g %g\n", value[0], value[1], value[2], value[3]);
464#endif
465
466 if (clamp) {
467 clampedValue[0] = CLAMP(value[0], 0.0F, 1.0F);
468 clampedValue[1] = CLAMP(value[1], 0.0F, 1.0F);
469 clampedValue[2] = CLAMP(value[2], 0.0F, 1.0F);
470 clampedValue[3] = CLAMP(value[3], 0.0F, 1.0F);
471 value = clampedValue;
472 }
473
Brian Paulf4361542008-11-11 10:47:10 -0700474 if (dstReg->CondMask != COND_TR) {
Brian13e3b212007-02-22 16:09:40 -0700475 /* condition codes may turn off some writes */
476 if (writeMask & WRITEMASK_X) {
Brian Paulf4361542008-11-11 10:47:10 -0700477 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 0)],
478 dstReg->CondMask))
Brian13e3b212007-02-22 16:09:40 -0700479 writeMask &= ~WRITEMASK_X;
480 }
481 if (writeMask & WRITEMASK_Y) {
Brian Paulf4361542008-11-11 10:47:10 -0700482 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 1)],
483 dstReg->CondMask))
Brian13e3b212007-02-22 16:09:40 -0700484 writeMask &= ~WRITEMASK_Y;
485 }
486 if (writeMask & WRITEMASK_Z) {
Brian Paulf4361542008-11-11 10:47:10 -0700487 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 2)],
488 dstReg->CondMask))
Brian13e3b212007-02-22 16:09:40 -0700489 writeMask &= ~WRITEMASK_Z;
490 }
491 if (writeMask & WRITEMASK_W) {
Brian Paulf4361542008-11-11 10:47:10 -0700492 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 3)],
493 dstReg->CondMask))
Brian13e3b212007-02-22 16:09:40 -0700494 writeMask &= ~WRITEMASK_W;
495 }
496 }
497
Brian Paul92009542009-06-03 15:43:53 -0600498#ifdef NAN_CHECK
499 assert(!IS_INF_OR_NAN(value[0]));
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#endif
504
Brian13e3b212007-02-22 16:09:40 -0700505 if (writeMask & WRITEMASK_X)
Brian Paulf4361542008-11-11 10:47:10 -0700506 dst[0] = value[0];
Brian13e3b212007-02-22 16:09:40 -0700507 if (writeMask & WRITEMASK_Y)
Brian Paulf4361542008-11-11 10:47:10 -0700508 dst[1] = value[1];
Brian13e3b212007-02-22 16:09:40 -0700509 if (writeMask & WRITEMASK_Z)
Brian Paulf4361542008-11-11 10:47:10 -0700510 dst[2] = value[2];
Brian13e3b212007-02-22 16:09:40 -0700511 if (writeMask & WRITEMASK_W)
Brian Paulf4361542008-11-11 10:47:10 -0700512 dst[3] = value[3];
Brian13e3b212007-02-22 16:09:40 -0700513
514 if (inst->CondUpdate) {
515 if (writeMask & WRITEMASK_X)
516 machine->CondCodes[0] = generate_cc(value[0]);
517 if (writeMask & WRITEMASK_Y)
518 machine->CondCodes[1] = generate_cc(value[1]);
519 if (writeMask & WRITEMASK_Z)
520 machine->CondCodes[2] = generate_cc(value[2]);
521 if (writeMask & WRITEMASK_W)
522 machine->CondCodes[3] = generate_cc(value[3]);
Briana01616e2007-03-28 11:01:28 -0600523#if DEBUG_PROG
524 printf("CondCodes=(%s,%s,%s,%s) for:\n",
525 _mesa_condcode_string(machine->CondCodes[0]),
526 _mesa_condcode_string(machine->CondCodes[1]),
527 _mesa_condcode_string(machine->CondCodes[2]),
528 _mesa_condcode_string(machine->CondCodes[3]));
529#endif
Brian13e3b212007-02-22 16:09:40 -0700530 }
531}
532
533
Brian13e3b212007-02-22 16:09:40 -0700534/**
Brian Paul37eef7b2008-11-07 09:33:55 -0700535 * Store 4 uints into a register. Observe the set-condition-code flags.
536 */
537static void
538store_vector4ui(const struct prog_instruction *inst,
539 struct gl_program_machine *machine, const GLuint value[4])
540{
Brian Paulf4361542008-11-11 10:47:10 -0700541 const struct prog_dst_register *dstReg = &(inst->DstReg);
542 GLuint writeMask = dstReg->WriteMask;
543 GLuint *dst = (GLuint *) get_dst_register_pointer(dstReg, machine);
Brian Paul37eef7b2008-11-07 09:33:55 -0700544
Brian Paulf4361542008-11-11 10:47:10 -0700545 if (dstReg->CondMask != COND_TR) {
Brian Paul37eef7b2008-11-07 09:33:55 -0700546 /* condition codes may turn off some writes */
547 if (writeMask & WRITEMASK_X) {
Brian Paulf4361542008-11-11 10:47:10 -0700548 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 0)],
549 dstReg->CondMask))
Brian Paul37eef7b2008-11-07 09:33:55 -0700550 writeMask &= ~WRITEMASK_X;
551 }
552 if (writeMask & WRITEMASK_Y) {
Brian Paulf4361542008-11-11 10:47:10 -0700553 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 1)],
554 dstReg->CondMask))
Brian Paul37eef7b2008-11-07 09:33:55 -0700555 writeMask &= ~WRITEMASK_Y;
556 }
557 if (writeMask & WRITEMASK_Z) {
Brian Paulf4361542008-11-11 10:47:10 -0700558 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 2)],
559 dstReg->CondMask))
Brian Paul37eef7b2008-11-07 09:33:55 -0700560 writeMask &= ~WRITEMASK_Z;
561 }
562 if (writeMask & WRITEMASK_W) {
Brian Paulf4361542008-11-11 10:47:10 -0700563 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 3)],
564 dstReg->CondMask))
Brian Paul37eef7b2008-11-07 09:33:55 -0700565 writeMask &= ~WRITEMASK_W;
566 }
567 }
568
569 if (writeMask & WRITEMASK_X)
Brian Paulf4361542008-11-11 10:47:10 -0700570 dst[0] = value[0];
Brian Paul37eef7b2008-11-07 09:33:55 -0700571 if (writeMask & WRITEMASK_Y)
Brian Paulf4361542008-11-11 10:47:10 -0700572 dst[1] = value[1];
Brian Paul37eef7b2008-11-07 09:33:55 -0700573 if (writeMask & WRITEMASK_Z)
Brian Paulf4361542008-11-11 10:47:10 -0700574 dst[2] = value[2];
Brian Paul37eef7b2008-11-07 09:33:55 -0700575 if (writeMask & WRITEMASK_W)
Brian Paulf4361542008-11-11 10:47:10 -0700576 dst[3] = value[3];
Brian Paul37eef7b2008-11-07 09:33:55 -0700577
578 if (inst->CondUpdate) {
579 if (writeMask & WRITEMASK_X)
580 machine->CondCodes[0] = generate_cc(value[0]);
581 if (writeMask & WRITEMASK_Y)
582 machine->CondCodes[1] = generate_cc(value[1]);
583 if (writeMask & WRITEMASK_Z)
584 machine->CondCodes[2] = generate_cc(value[2]);
585 if (writeMask & WRITEMASK_W)
586 machine->CondCodes[3] = generate_cc(value[3]);
587#if DEBUG_PROG
588 printf("CondCodes=(%s,%s,%s,%s) for:\n",
589 _mesa_condcode_string(machine->CondCodes[0]),
590 _mesa_condcode_string(machine->CondCodes[1]),
591 _mesa_condcode_string(machine->CondCodes[2]),
592 _mesa_condcode_string(machine->CondCodes[3]));
593#endif
594 }
595}
596
597
598
599/**
Brian13e3b212007-02-22 16:09:40 -0700600 * Execute the given vertex/fragment program.
601 *
Brian3c1c9992007-02-25 19:11:44 -0700602 * \param ctx rendering context
603 * \param program the program to execute
604 * \param machine machine state (must be initialized)
Brian13e3b212007-02-22 16:09:40 -0700605 * \return GL_TRUE if program completed or GL_FALSE if program executed KIL.
606 */
607GLboolean
Briane80d9012007-02-23 16:53:24 -0700608_mesa_execute_program(GLcontext * ctx,
Brian8b34b7d2007-02-25 18:26:50 -0700609 const struct gl_program *program,
Brian085d7d52007-02-25 18:23:37 -0700610 struct gl_program_machine *machine)
Brian13e3b212007-02-22 16:09:40 -0700611{
Brian8b34b7d2007-02-25 18:26:50 -0700612 const GLuint numInst = program->NumInstructions;
Briancfd00112007-02-25 18:30:45 -0700613 const GLuint maxExec = 10000;
José Fonseca452a5922008-05-31 18:14:09 +0900614 GLuint pc, numExec = 0;
Brian13e3b212007-02-22 16:09:40 -0700615
616 machine->CurProgram = program;
617
618 if (DEBUG_PROG) {
619 printf("execute program %u --------------------\n", program->Id);
620 }
621
Brian33eac562007-02-25 18:52:41 -0700622 if (program->Target == GL_VERTEX_PROGRAM_ARB) {
623 machine->EnvParams = ctx->VertexProgram.Parameters;
624 }
625 else {
626 machine->EnvParams = ctx->FragmentProgram.Parameters;
627 }
628
Brian8b34b7d2007-02-25 18:26:50 -0700629 for (pc = 0; pc < numInst; pc++) {
Brian13e3b212007-02-22 16:09:40 -0700630 const struct prog_instruction *inst = program->Instructions + pc;
631
Brian13e3b212007-02-22 16:09:40 -0700632 if (DEBUG_PROG) {
633 _mesa_print_instruction(inst);
634 }
635
636 switch (inst->Opcode) {
Briane80d9012007-02-23 16:53:24 -0700637 case OPCODE_ABS:
638 {
639 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700640 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -0700641 result[0] = FABSF(a[0]);
642 result[1] = FABSF(a[1]);
643 result[2] = FABSF(a[2]);
644 result[3] = FABSF(a[3]);
645 store_vector4(inst, machine, result);
646 }
647 break;
648 case OPCODE_ADD:
649 {
650 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700651 fetch_vector4(&inst->SrcReg[0], machine, a);
652 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -0700653 result[0] = a[0] + b[0];
654 result[1] = a[1] + b[1];
655 result[2] = a[2] + b[2];
656 result[3] = a[3] + b[3];
657 store_vector4(inst, machine, result);
658 if (DEBUG_PROG) {
659 printf("ADD (%g %g %g %g) = (%g %g %g %g) + (%g %g %g %g)\n",
660 result[0], result[1], result[2], result[3],
661 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -0700662 }
Briane80d9012007-02-23 16:53:24 -0700663 }
664 break;
Brian Paul37eef7b2008-11-07 09:33:55 -0700665 case OPCODE_AND: /* bitwise AND */
666 {
667 GLuint a[4], b[4], result[4];
668 fetch_vector4ui(&inst->SrcReg[0], machine, a);
669 fetch_vector4ui(&inst->SrcReg[1], machine, b);
670 result[0] = a[0] & b[0];
671 result[1] = a[1] & b[1];
672 result[2] = a[2] & b[2];
673 result[3] = a[3] & b[3];
674 store_vector4ui(inst, machine, result);
675 }
676 break;
Brianf183a2d2007-02-23 17:14:30 -0700677 case OPCODE_ARL:
678 {
679 GLfloat t[4];
Brian33eac562007-02-25 18:52:41 -0700680 fetch_vector4(&inst->SrcReg[0], machine, t);
Brian Paula9475cc2008-12-12 18:03:48 -0700681 machine->AddressReg[0][0] = IFLOOR(t[0]);
Brianf183a2d2007-02-23 17:14:30 -0700682 }
683 break;
Briane80d9012007-02-23 16:53:24 -0700684 case OPCODE_BGNLOOP:
685 /* no-op */
Brian Paule8ea2d22009-12-22 12:57:31 -0700686 ASSERT(program->Instructions[inst->BranchTarget].Opcode
687 == OPCODE_ENDLOOP);
Briane80d9012007-02-23 16:53:24 -0700688 break;
689 case OPCODE_ENDLOOP:
690 /* subtract 1 here since pc is incremented by for(pc) loop */
Brian Paule8ea2d22009-12-22 12:57:31 -0700691 ASSERT(program->Instructions[inst->BranchTarget].Opcode
692 == OPCODE_BGNLOOP);
Briane80d9012007-02-23 16:53:24 -0700693 pc = inst->BranchTarget - 1; /* go to matching BNGLOOP */
694 break;
695 case OPCODE_BGNSUB: /* begin subroutine */
696 break;
697 case OPCODE_ENDSUB: /* end subroutine */
698 break;
699 case OPCODE_BRA: /* branch (conditional) */
Briane80d9012007-02-23 16:53:24 -0700700 if (eval_condition(machine, inst)) {
701 /* take branch */
Brian Pauldb721152009-12-22 14:15:30 -0700702 /* Subtract 1 here since we'll do pc++ below */
703 pc = inst->BranchTarget - 1;
704 }
705 break;
706 case OPCODE_BRK: /* break out of loop (conditional) */
707 ASSERT(program->Instructions[inst->BranchTarget].Opcode
708 == OPCODE_ENDLOOP);
709 if (eval_condition(machine, inst)) {
710 /* break out of loop */
711 /* pc++ at end of for-loop will put us after the ENDLOOP inst */
712 pc = inst->BranchTarget;
713 }
714 break;
715 case OPCODE_CONT: /* continue loop (conditional) */
716 ASSERT(program->Instructions[inst->BranchTarget].Opcode
717 == OPCODE_ENDLOOP);
718 if (eval_condition(machine, inst)) {
719 /* continue at ENDLOOP */
Briane80d9012007-02-23 16:53:24 -0700720 /* Subtract 1 here since we'll do pc++ at end of for-loop */
721 pc = inst->BranchTarget - 1;
722 }
723 break;
724 case OPCODE_CAL: /* Call subroutine (conditional) */
725 if (eval_condition(machine, inst)) {
726 /* call the subroutine */
727 if (machine->StackDepth >= MAX_PROGRAM_CALL_DEPTH) {
728 return GL_TRUE; /* Per GL_NV_vertex_program2 spec */
Brian13e3b212007-02-22 16:09:40 -0700729 }
Briana0275b02007-03-27 11:02:20 -0600730 machine->CallStack[machine->StackDepth++] = pc + 1; /* next inst */
Brian31dc7a32007-03-27 15:21:35 -0600731 /* Subtract 1 here since we'll do pc++ at end of for-loop */
732 pc = inst->BranchTarget - 1;
Briane80d9012007-02-23 16:53:24 -0700733 }
734 break;
735 case OPCODE_CMP:
736 {
737 GLfloat a[4], b[4], c[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700738 fetch_vector4(&inst->SrcReg[0], machine, a);
739 fetch_vector4(&inst->SrcReg[1], machine, b);
740 fetch_vector4(&inst->SrcReg[2], machine, c);
Briane80d9012007-02-23 16:53:24 -0700741 result[0] = a[0] < 0.0F ? b[0] : c[0];
742 result[1] = a[1] < 0.0F ? b[1] : c[1];
743 result[2] = a[2] < 0.0F ? b[2] : c[2];
744 result[3] = a[3] < 0.0F ? b[3] : c[3];
745 store_vector4(inst, machine, result);
746 }
747 break;
748 case OPCODE_COS:
749 {
750 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700751 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -0700752 result[0] = result[1] = result[2] = result[3]
753 = (GLfloat) _mesa_cos(a[0]);
754 store_vector4(inst, machine, result);
755 }
756 break;
757 case OPCODE_DDX: /* Partial derivative with respect to X */
758 {
Brian62da6a12007-05-02 18:44:34 -0600759 GLfloat result[4];
760 fetch_vector4_deriv(ctx, &inst->SrcReg[0], machine,
761 'X', result);
Briane80d9012007-02-23 16:53:24 -0700762 store_vector4(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -0700763 }
764 break;
765 case OPCODE_DDY: /* Partial derivative with respect to Y */
766 {
Brian62da6a12007-05-02 18:44:34 -0600767 GLfloat result[4];
768 fetch_vector4_deriv(ctx, &inst->SrcReg[0], machine,
769 'Y', result);
Briane80d9012007-02-23 16:53:24 -0700770 store_vector4(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -0700771 }
772 break;
Brian Paul65cb74e2008-11-07 09:41:00 -0700773 case OPCODE_DP2:
774 {
775 GLfloat a[4], b[4], result[4];
776 fetch_vector4(&inst->SrcReg[0], machine, a);
777 fetch_vector4(&inst->SrcReg[1], machine, b);
778 result[0] = result[1] = result[2] = result[3] = DOT2(a, b);
779 store_vector4(inst, machine, result);
780 if (DEBUG_PROG) {
781 printf("DP2 %g = (%g %g) . (%g %g)\n",
782 result[0], a[0], a[1], b[0], b[1]);
783 }
784 }
785 break;
786 case OPCODE_DP2A:
787 {
788 GLfloat a[4], b[4], c, result[4];
789 fetch_vector4(&inst->SrcReg[0], machine, a);
790 fetch_vector4(&inst->SrcReg[1], machine, b);
791 fetch_vector1(&inst->SrcReg[1], machine, &c);
792 result[0] = result[1] = result[2] = result[3] = DOT2(a, b) + c;
793 store_vector4(inst, machine, result);
794 if (DEBUG_PROG) {
795 printf("DP2A %g = (%g %g) . (%g %g) + %g\n",
796 result[0], a[0], a[1], b[0], b[1], c);
797 }
798 }
799 break;
Briane80d9012007-02-23 16:53:24 -0700800 case OPCODE_DP3:
801 {
802 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700803 fetch_vector4(&inst->SrcReg[0], machine, a);
804 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -0700805 result[0] = result[1] = result[2] = result[3] = DOT3(a, b);
806 store_vector4(inst, machine, result);
807 if (DEBUG_PROG) {
808 printf("DP3 %g = (%g %g %g) . (%g %g %g)\n",
809 result[0], a[0], a[1], a[2], b[0], b[1], b[2]);
Brian13e3b212007-02-22 16:09:40 -0700810 }
Briane80d9012007-02-23 16:53:24 -0700811 }
812 break;
813 case OPCODE_DP4:
814 {
815 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700816 fetch_vector4(&inst->SrcReg[0], machine, a);
817 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -0700818 result[0] = result[1] = result[2] = result[3] = DOT4(a, b);
819 store_vector4(inst, machine, result);
820 if (DEBUG_PROG) {
821 printf("DP4 %g = (%g, %g %g %g) . (%g, %g %g %g)\n",
822 result[0], a[0], a[1], a[2], a[3],
823 b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -0700824 }
Briane80d9012007-02-23 16:53:24 -0700825 }
826 break;
827 case OPCODE_DPH:
828 {
829 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700830 fetch_vector4(&inst->SrcReg[0], machine, a);
831 fetch_vector4(&inst->SrcReg[1], machine, b);
Brian Paul65cb74e2008-11-07 09:41:00 -0700832 result[0] = result[1] = result[2] = result[3] = DOT3(a, b) + b[3];
Briane80d9012007-02-23 16:53:24 -0700833 store_vector4(inst, machine, result);
834 }
835 break;
836 case OPCODE_DST: /* Distance vector */
837 {
838 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700839 fetch_vector4(&inst->SrcReg[0], machine, a);
840 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -0700841 result[0] = 1.0F;
842 result[1] = a[1] * b[1];
843 result[2] = a[2];
844 result[3] = b[3];
845 store_vector4(inst, machine, result);
846 }
847 break;
Brianf183a2d2007-02-23 17:14:30 -0700848 case OPCODE_EXP:
Brianf183a2d2007-02-23 17:14:30 -0700849 {
850 GLfloat t[4], q[4], floor_t0;
Brian33eac562007-02-25 18:52:41 -0700851 fetch_vector1(&inst->SrcReg[0], machine, t);
Brianf183a2d2007-02-23 17:14:30 -0700852 floor_t0 = FLOORF(t[0]);
853 if (floor_t0 > FLT_MAX_EXP) {
854 SET_POS_INFINITY(q[0]);
855 SET_POS_INFINITY(q[2]);
856 }
857 else if (floor_t0 < FLT_MIN_EXP) {
858 q[0] = 0.0F;
859 q[2] = 0.0F;
860 }
861 else {
Brian761728a2007-02-24 11:14:57 -0700862 q[0] = LDEXPF(1.0, (int) floor_t0);
863 /* Note: GL_NV_vertex_program expects
864 * result.z = result.x * APPX(result.y)
865 * We do what the ARB extension says.
866 */
Brian Paulb8a200a2009-04-03 10:29:11 -0600867 q[2] = (GLfloat) _mesa_pow(2.0, t[0]);
Brianf183a2d2007-02-23 17:14:30 -0700868 }
869 q[1] = t[0] - floor_t0;
870 q[3] = 1.0F;
871 store_vector4( inst, machine, q );
872 }
873 break;
Briane80d9012007-02-23 16:53:24 -0700874 case OPCODE_EX2: /* Exponential base 2 */
875 {
Brian Paul035de6a2009-06-03 15:42:52 -0600876 GLfloat a[4], result[4], val;
Brian33eac562007-02-25 18:52:41 -0700877 fetch_vector1(&inst->SrcReg[0], machine, a);
Brian Paul035de6a2009-06-03 15:42:52 -0600878 val = (GLfloat) _mesa_pow(2.0, a[0]);
879 /*
880 if (IS_INF_OR_NAN(val))
881 val = 1.0e10;
882 */
883 result[0] = result[1] = result[2] = result[3] = val;
Briane80d9012007-02-23 16:53:24 -0700884 store_vector4(inst, machine, result);
885 }
886 break;
887 case OPCODE_FLR:
888 {
889 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700890 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -0700891 result[0] = FLOORF(a[0]);
892 result[1] = FLOORF(a[1]);
893 result[2] = FLOORF(a[2]);
894 result[3] = FLOORF(a[3]);
895 store_vector4(inst, machine, result);
896 }
897 break;
898 case OPCODE_FRC:
899 {
900 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700901 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -0700902 result[0] = a[0] - FLOORF(a[0]);
903 result[1] = a[1] - FLOORF(a[1]);
904 result[2] = a[2] - FLOORF(a[2]);
905 result[3] = a[3] - FLOORF(a[3]);
906 store_vector4(inst, machine, result);
907 }
908 break;
909 case OPCODE_IF:
Brian63556fa2007-03-23 14:47:46 -0600910 {
911 GLboolean cond;
Brian Paulddd97292009-12-22 14:21:07 -0700912 ASSERT(program->Instructions[inst->BranchTarget].Opcode
913 == OPCODE_ELSE ||
914 program->Instructions[inst->BranchTarget].Opcode
915 == OPCODE_ENDIF);
Brian63556fa2007-03-23 14:47:46 -0600916 /* eval condition */
917 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
918 GLfloat a[4];
919 fetch_vector1(&inst->SrcReg[0], machine, a);
920 cond = (a[0] != 0.0);
921 }
922 else {
923 cond = eval_condition(machine, inst);
924 }
Briana7f73662007-04-20 08:11:51 -0600925 if (DEBUG_PROG) {
926 printf("IF: %d\n", cond);
927 }
Brian63556fa2007-03-23 14:47:46 -0600928 /* do if/else */
929 if (cond) {
930 /* do if-clause (just continue execution) */
931 }
932 else {
933 /* go to the instruction after ELSE or ENDIF */
934 assert(inst->BranchTarget >= 0);
Brian Paulddd97292009-12-22 14:21:07 -0700935 pc = inst->BranchTarget;
Brian63556fa2007-03-23 14:47:46 -0600936 }
Briane80d9012007-02-23 16:53:24 -0700937 }
938 break;
939 case OPCODE_ELSE:
940 /* goto ENDIF */
Brian Paulddd97292009-12-22 14:21:07 -0700941 ASSERT(program->Instructions[inst->BranchTarget].Opcode
942 == OPCODE_ENDIF);
Briane80d9012007-02-23 16:53:24 -0700943 assert(inst->BranchTarget >= 0);
Brian Paulddd97292009-12-22 14:21:07 -0700944 pc = inst->BranchTarget;
Briane80d9012007-02-23 16:53:24 -0700945 break;
946 case OPCODE_ENDIF:
947 /* nothing */
948 break;
Briane80d9012007-02-23 16:53:24 -0700949 case OPCODE_KIL_NV: /* NV_f_p only (conditional) */
950 if (eval_condition(machine, inst)) {
951 return GL_FALSE;
952 }
953 break;
954 case OPCODE_KIL: /* ARB_f_p only */
955 {
956 GLfloat a[4];
Brian33eac562007-02-25 18:52:41 -0700957 fetch_vector4(&inst->SrcReg[0], machine, a);
Brian Paulc0633dd2009-08-31 14:57:59 -0600958 if (DEBUG_PROG) {
959 printf("KIL if (%g %g %g %g) <= 0.0\n",
960 a[0], a[1], a[2], a[3]);
961 }
962
Briane80d9012007-02-23 16:53:24 -0700963 if (a[0] < 0.0F || a[1] < 0.0F || a[2] < 0.0F || a[3] < 0.0F) {
Brian13e3b212007-02-22 16:09:40 -0700964 return GL_FALSE;
965 }
Briane80d9012007-02-23 16:53:24 -0700966 }
967 break;
968 case OPCODE_LG2: /* log base 2 */
969 {
Brian Paul035de6a2009-06-03 15:42:52 -0600970 GLfloat a[4], result[4], val;
Brian33eac562007-02-25 18:52:41 -0700971 fetch_vector1(&inst->SrcReg[0], machine, a);
Ian Romanick962fa6b2008-12-18 14:11:06 -0800972 /* The fast LOG2 macro doesn't meet the precision requirements.
973 */
Brian Paul035de6a2009-06-03 15:42:52 -0600974 if (a[0] == 0.0F) {
Vinson Lee18883cd2009-10-01 13:33:20 -0600975 val = -FLT_MAX;
Brian Paul035de6a2009-06-03 15:42:52 -0600976 }
977 else {
978 val = log(a[0]) * 1.442695F;
979 }
980 result[0] = result[1] = result[2] = result[3] = val;
Briane80d9012007-02-23 16:53:24 -0700981 store_vector4(inst, machine, result);
982 }
983 break;
984 case OPCODE_LIT:
985 {
986 const GLfloat epsilon = 1.0F / 256.0F; /* from NV VP spec */
987 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700988 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -0700989 a[0] = MAX2(a[0], 0.0F);
990 a[1] = MAX2(a[1], 0.0F);
991 /* XXX ARB version clamps a[3], NV version doesn't */
992 a[3] = CLAMP(a[3], -(128.0F - epsilon), (128.0F - epsilon));
993 result[0] = 1.0F;
994 result[1] = a[0];
995 /* XXX we could probably just use pow() here */
996 if (a[0] > 0.0F) {
997 if (a[1] == 0.0 && a[3] == 0.0)
998 result[2] = 1.0;
999 else
Brian Paulb8a200a2009-04-03 10:29:11 -06001000 result[2] = (GLfloat) _mesa_pow(a[1], a[3]);
Brian13e3b212007-02-22 16:09:40 -07001001 }
Briane80d9012007-02-23 16:53:24 -07001002 else {
1003 result[2] = 0.0;
Brian13e3b212007-02-22 16:09:40 -07001004 }
Briane80d9012007-02-23 16:53:24 -07001005 result[3] = 1.0F;
1006 store_vector4(inst, machine, result);
1007 if (DEBUG_PROG) {
1008 printf("LIT (%g %g %g %g) : (%g %g %g %g)\n",
1009 result[0], result[1], result[2], result[3],
1010 a[0], a[1], a[2], a[3]);
Brian13e3b212007-02-22 16:09:40 -07001011 }
Briane80d9012007-02-23 16:53:24 -07001012 }
1013 break;
Brianf183a2d2007-02-23 17:14:30 -07001014 case OPCODE_LOG:
1015 {
1016 GLfloat t[4], q[4], abs_t0;
Brian33eac562007-02-25 18:52:41 -07001017 fetch_vector1(&inst->SrcReg[0], machine, t);
Brianf183a2d2007-02-23 17:14:30 -07001018 abs_t0 = FABSF(t[0]);
1019 if (abs_t0 != 0.0F) {
1020 /* Since we really can't handle infinite values on VMS
1021 * like other OSes we'll use __MAXFLOAT to represent
1022 * infinity. This may need some tweaking.
1023 */
1024#ifdef VMS
1025 if (abs_t0 == __MAXFLOAT)
1026#else
1027 if (IS_INF_OR_NAN(abs_t0))
1028#endif
1029 {
1030 SET_POS_INFINITY(q[0]);
1031 q[1] = 1.0F;
1032 SET_POS_INFINITY(q[2]);
1033 }
1034 else {
1035 int exponent;
1036 GLfloat mantissa = FREXPF(t[0], &exponent);
1037 q[0] = (GLfloat) (exponent - 1);
1038 q[1] = (GLfloat) (2.0 * mantissa); /* map [.5, 1) -> [1, 2) */
Ian Romanick962fa6b2008-12-18 14:11:06 -08001039
1040 /* The fast LOG2 macro doesn't meet the precision
1041 * requirements.
1042 */
1043 q[2] = (log(t[0]) * 1.442695F);
Brianf183a2d2007-02-23 17:14:30 -07001044 }
1045 }
1046 else {
1047 SET_NEG_INFINITY(q[0]);
1048 q[1] = 1.0F;
1049 SET_NEG_INFINITY(q[2]);
1050 }
1051 q[3] = 1.0;
1052 store_vector4(inst, machine, q);
1053 }
1054 break;
Briane80d9012007-02-23 16:53:24 -07001055 case OPCODE_LRP:
1056 {
1057 GLfloat a[4], b[4], c[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001058 fetch_vector4(&inst->SrcReg[0], machine, a);
1059 fetch_vector4(&inst->SrcReg[1], machine, b);
1060 fetch_vector4(&inst->SrcReg[2], machine, c);
Briane80d9012007-02-23 16:53:24 -07001061 result[0] = a[0] * b[0] + (1.0F - a[0]) * c[0];
1062 result[1] = a[1] * b[1] + (1.0F - a[1]) * c[1];
1063 result[2] = a[2] * b[2] + (1.0F - a[2]) * c[2];
1064 result[3] = a[3] * b[3] + (1.0F - a[3]) * c[3];
1065 store_vector4(inst, machine, result);
1066 if (DEBUG_PROG) {
1067 printf("LRP (%g %g %g %g) = (%g %g %g %g), "
1068 "(%g %g %g %g), (%g %g %g %g)\n",
1069 result[0], result[1], result[2], result[3],
1070 a[0], a[1], a[2], a[3],
1071 b[0], b[1], b[2], b[3], c[0], c[1], c[2], c[3]);
Brian13e3b212007-02-22 16:09:40 -07001072 }
Briane80d9012007-02-23 16:53:24 -07001073 }
1074 break;
1075 case OPCODE_MAD:
1076 {
1077 GLfloat a[4], b[4], c[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001078 fetch_vector4(&inst->SrcReg[0], machine, a);
1079 fetch_vector4(&inst->SrcReg[1], machine, b);
1080 fetch_vector4(&inst->SrcReg[2], machine, c);
Briane80d9012007-02-23 16:53:24 -07001081 result[0] = a[0] * b[0] + c[0];
1082 result[1] = a[1] * b[1] + c[1];
1083 result[2] = a[2] * b[2] + c[2];
1084 result[3] = a[3] * b[3] + c[3];
1085 store_vector4(inst, machine, result);
1086 if (DEBUG_PROG) {
1087 printf("MAD (%g %g %g %g) = (%g %g %g %g) * "
1088 "(%g %g %g %g) + (%g %g %g %g)\n",
1089 result[0], result[1], result[2], result[3],
1090 a[0], a[1], a[2], a[3],
1091 b[0], b[1], b[2], b[3], c[0], c[1], c[2], c[3]);
Brian13e3b212007-02-22 16:09:40 -07001092 }
Briane80d9012007-02-23 16:53:24 -07001093 }
1094 break;
1095 case OPCODE_MAX:
1096 {
1097 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001098 fetch_vector4(&inst->SrcReg[0], machine, a);
1099 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001100 result[0] = MAX2(a[0], b[0]);
1101 result[1] = MAX2(a[1], b[1]);
1102 result[2] = MAX2(a[2], b[2]);
1103 result[3] = MAX2(a[3], b[3]);
1104 store_vector4(inst, machine, result);
1105 if (DEBUG_PROG) {
1106 printf("MAX (%g %g %g %g) = (%g %g %g %g), (%g %g %g %g)\n",
1107 result[0], result[1], result[2], result[3],
1108 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -07001109 }
Briane80d9012007-02-23 16:53:24 -07001110 }
1111 break;
1112 case OPCODE_MIN:
1113 {
1114 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001115 fetch_vector4(&inst->SrcReg[0], machine, a);
1116 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001117 result[0] = MIN2(a[0], b[0]);
1118 result[1] = MIN2(a[1], b[1]);
1119 result[2] = MIN2(a[2], b[2]);
1120 result[3] = MIN2(a[3], b[3]);
1121 store_vector4(inst, machine, result);
1122 }
1123 break;
1124 case OPCODE_MOV:
1125 {
1126 GLfloat result[4];
Brian33eac562007-02-25 18:52:41 -07001127 fetch_vector4(&inst->SrcReg[0], machine, result);
Briane80d9012007-02-23 16:53:24 -07001128 store_vector4(inst, machine, result);
1129 if (DEBUG_PROG) {
1130 printf("MOV (%g %g %g %g)\n",
1131 result[0], result[1], result[2], result[3]);
Brian13e3b212007-02-22 16:09:40 -07001132 }
Briane80d9012007-02-23 16:53:24 -07001133 }
1134 break;
1135 case OPCODE_MUL:
1136 {
1137 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001138 fetch_vector4(&inst->SrcReg[0], machine, a);
1139 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001140 result[0] = a[0] * b[0];
1141 result[1] = a[1] * b[1];
1142 result[2] = a[2] * b[2];
1143 result[3] = a[3] * b[3];
1144 store_vector4(inst, machine, result);
1145 if (DEBUG_PROG) {
1146 printf("MUL (%g %g %g %g) = (%g %g %g %g) * (%g %g %g %g)\n",
1147 result[0], result[1], result[2], result[3],
1148 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -07001149 }
Briane80d9012007-02-23 16:53:24 -07001150 }
1151 break;
1152 case OPCODE_NOISE1:
1153 {
1154 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001155 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001156 result[0] =
Brian13e3b212007-02-22 16:09:40 -07001157 result[1] =
Brian Paul702b5b02008-12-15 18:37:39 -07001158 result[2] =
1159 result[3] = _mesa_noise1(a[0]);
Briane80d9012007-02-23 16:53:24 -07001160 store_vector4(inst, machine, result);
1161 }
1162 break;
1163 case OPCODE_NOISE2:
1164 {
1165 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001166 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001167 result[0] =
Brian13e3b212007-02-22 16:09:40 -07001168 result[1] =
Brian Paul702b5b02008-12-15 18:37:39 -07001169 result[2] = result[3] = _mesa_noise2(a[0], a[1]);
Briane80d9012007-02-23 16:53:24 -07001170 store_vector4(inst, machine, result);
1171 }
1172 break;
1173 case OPCODE_NOISE3:
1174 {
1175 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001176 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001177 result[0] =
Brian13e3b212007-02-22 16:09:40 -07001178 result[1] =
1179 result[2] =
Brian Paul702b5b02008-12-15 18:37:39 -07001180 result[3] = _mesa_noise3(a[0], a[1], a[2]);
Briane80d9012007-02-23 16:53:24 -07001181 store_vector4(inst, machine, result);
1182 }
1183 break;
1184 case OPCODE_NOISE4:
1185 {
1186 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001187 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001188 result[0] =
Brian13e3b212007-02-22 16:09:40 -07001189 result[1] =
1190 result[2] =
Brian Paul702b5b02008-12-15 18:37:39 -07001191 result[3] = _mesa_noise4(a[0], a[1], a[2], a[3]);
Briane80d9012007-02-23 16:53:24 -07001192 store_vector4(inst, machine, result);
1193 }
1194 break;
1195 case OPCODE_NOP:
1196 break;
Brian Paul37eef7b2008-11-07 09:33:55 -07001197 case OPCODE_NOT: /* bitwise NOT */
1198 {
1199 GLuint a[4], result[4];
1200 fetch_vector4ui(&inst->SrcReg[0], machine, a);
1201 result[0] = ~a[0];
1202 result[1] = ~a[1];
1203 result[2] = ~a[2];
1204 result[3] = ~a[3];
1205 store_vector4ui(inst, machine, result);
1206 }
1207 break;
Brian Paulf6ead502008-11-07 08:51:31 -07001208 case OPCODE_NRM3: /* 3-component normalization */
1209 {
1210 GLfloat a[4], result[4];
1211 GLfloat tmp;
1212 fetch_vector4(&inst->SrcReg[0], machine, a);
1213 tmp = a[0] * a[0] + a[1] * a[1] + a[2] * a[2];
1214 if (tmp != 0.0F)
Brian Paul22459e72008-11-07 12:59:36 -07001215 tmp = INV_SQRTF(tmp);
Brian Paulf6ead502008-11-07 08:51:31 -07001216 result[0] = tmp * a[0];
1217 result[1] = tmp * a[1];
1218 result[2] = tmp * a[2];
1219 result[3] = 0.0; /* undefined, but prevent valgrind warnings */
1220 store_vector4(inst, machine, result);
1221 }
1222 break;
1223 case OPCODE_NRM4: /* 4-component normalization */
1224 {
1225 GLfloat a[4], result[4];
1226 GLfloat tmp;
1227 fetch_vector4(&inst->SrcReg[0], machine, a);
1228 tmp = a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3];
1229 if (tmp != 0.0F)
Brian Paul22459e72008-11-07 12:59:36 -07001230 tmp = INV_SQRTF(tmp);
Brian Paulf6ead502008-11-07 08:51:31 -07001231 result[0] = tmp * a[0];
1232 result[1] = tmp * a[1];
1233 result[2] = tmp * a[2];
1234 result[3] = tmp * a[3];
1235 store_vector4(inst, machine, result);
1236 }
1237 break;
Brian Paul37eef7b2008-11-07 09:33:55 -07001238 case OPCODE_OR: /* bitwise OR */
1239 {
1240 GLuint a[4], b[4], result[4];
1241 fetch_vector4ui(&inst->SrcReg[0], machine, a);
1242 fetch_vector4ui(&inst->SrcReg[1], machine, b);
1243 result[0] = a[0] | b[0];
1244 result[1] = a[1] | b[1];
1245 result[2] = a[2] | b[2];
1246 result[3] = a[3] | b[3];
1247 store_vector4ui(inst, machine, result);
1248 }
1249 break;
Briane80d9012007-02-23 16:53:24 -07001250 case OPCODE_PK2H: /* pack two 16-bit floats in one 32-bit float */
1251 {
Brian Paul37eef7b2008-11-07 09:33:55 -07001252 GLfloat a[4];
1253 GLuint result[4];
Briane80d9012007-02-23 16:53:24 -07001254 GLhalfNV hx, hy;
Brian33eac562007-02-25 18:52:41 -07001255 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001256 hx = _mesa_float_to_half(a[0]);
1257 hy = _mesa_float_to_half(a[1]);
Brian Paul37eef7b2008-11-07 09:33:55 -07001258 result[0] =
1259 result[1] =
1260 result[2] =
1261 result[3] = hx | (hy << 16);
1262 store_vector4ui(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -07001263 }
1264 break;
1265 case OPCODE_PK2US: /* pack two GLushorts into one 32-bit float */
1266 {
Brian Paul37eef7b2008-11-07 09:33:55 -07001267 GLfloat a[4];
1268 GLuint result[4], usx, usy;
Brian33eac562007-02-25 18:52:41 -07001269 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001270 a[0] = CLAMP(a[0], 0.0F, 1.0F);
1271 a[1] = CLAMP(a[1], 0.0F, 1.0F);
1272 usx = IROUND(a[0] * 65535.0F);
1273 usy = IROUND(a[1] * 65535.0F);
Brian Paul37eef7b2008-11-07 09:33:55 -07001274 result[0] =
1275 result[1] =
1276 result[2] =
1277 result[3] = usx | (usy << 16);
1278 store_vector4ui(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -07001279 }
1280 break;
1281 case OPCODE_PK4B: /* pack four GLbytes into one 32-bit float */
1282 {
Brian Paul37eef7b2008-11-07 09:33:55 -07001283 GLfloat a[4];
1284 GLuint result[4], ubx, uby, ubz, ubw;
Brian33eac562007-02-25 18:52:41 -07001285 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001286 a[0] = CLAMP(a[0], -128.0F / 127.0F, 1.0F);
1287 a[1] = CLAMP(a[1], -128.0F / 127.0F, 1.0F);
1288 a[2] = CLAMP(a[2], -128.0F / 127.0F, 1.0F);
1289 a[3] = CLAMP(a[3], -128.0F / 127.0F, 1.0F);
1290 ubx = IROUND(127.0F * a[0] + 128.0F);
1291 uby = IROUND(127.0F * a[1] + 128.0F);
1292 ubz = IROUND(127.0F * a[2] + 128.0F);
1293 ubw = IROUND(127.0F * a[3] + 128.0F);
Brian Paul37eef7b2008-11-07 09:33:55 -07001294 result[0] =
1295 result[1] =
1296 result[2] =
1297 result[3] = ubx | (uby << 8) | (ubz << 16) | (ubw << 24);
1298 store_vector4ui(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -07001299 }
1300 break;
1301 case OPCODE_PK4UB: /* pack four GLubytes into one 32-bit float */
1302 {
Brian Paul37eef7b2008-11-07 09:33:55 -07001303 GLfloat a[4];
1304 GLuint result[4], ubx, uby, ubz, ubw;
Brian33eac562007-02-25 18:52:41 -07001305 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001306 a[0] = CLAMP(a[0], 0.0F, 1.0F);
1307 a[1] = CLAMP(a[1], 0.0F, 1.0F);
1308 a[2] = CLAMP(a[2], 0.0F, 1.0F);
1309 a[3] = CLAMP(a[3], 0.0F, 1.0F);
1310 ubx = IROUND(255.0F * a[0]);
1311 uby = IROUND(255.0F * a[1]);
1312 ubz = IROUND(255.0F * a[2]);
1313 ubw = IROUND(255.0F * a[3]);
Brian Paul37eef7b2008-11-07 09:33:55 -07001314 result[0] =
1315 result[1] =
1316 result[2] =
1317 result[3] = ubx | (uby << 8) | (ubz << 16) | (ubw << 24);
1318 store_vector4ui(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -07001319 }
1320 break;
1321 case OPCODE_POW:
1322 {
1323 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001324 fetch_vector1(&inst->SrcReg[0], machine, a);
1325 fetch_vector1(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001326 result[0] = result[1] = result[2] = result[3]
1327 = (GLfloat) _mesa_pow(a[0], b[0]);
1328 store_vector4(inst, machine, result);
1329 }
1330 break;
1331 case OPCODE_RCP:
1332 {
1333 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001334 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001335 if (DEBUG_PROG) {
1336 if (a[0] == 0)
1337 printf("RCP(0)\n");
1338 else if (IS_INF_OR_NAN(a[0]))
1339 printf("RCP(inf)\n");
Brian13e3b212007-02-22 16:09:40 -07001340 }
Briane80d9012007-02-23 16:53:24 -07001341 result[0] = result[1] = result[2] = result[3] = 1.0F / a[0];
1342 store_vector4(inst, machine, result);
1343 }
1344 break;
1345 case OPCODE_RET: /* return from subroutine (conditional) */
1346 if (eval_condition(machine, inst)) {
1347 if (machine->StackDepth == 0) {
1348 return GL_TRUE; /* Per GL_NV_vertex_program2 spec */
Brian13e3b212007-02-22 16:09:40 -07001349 }
Briana0275b02007-03-27 11:02:20 -06001350 /* subtract one because of pc++ in the for loop */
1351 pc = machine->CallStack[--machine->StackDepth] - 1;
Briane80d9012007-02-23 16:53:24 -07001352 }
1353 break;
1354 case OPCODE_RFL: /* reflection vector */
1355 {
1356 GLfloat axis[4], dir[4], result[4], tmpX, tmpW;
Brian33eac562007-02-25 18:52:41 -07001357 fetch_vector4(&inst->SrcReg[0], machine, axis);
1358 fetch_vector4(&inst->SrcReg[1], machine, dir);
Briane80d9012007-02-23 16:53:24 -07001359 tmpW = DOT3(axis, axis);
1360 tmpX = (2.0F * DOT3(axis, dir)) / tmpW;
1361 result[0] = tmpX * axis[0] - dir[0];
1362 result[1] = tmpX * axis[1] - dir[1];
1363 result[2] = tmpX * axis[2] - dir[2];
1364 /* result[3] is never written! XXX enforce in parser! */
1365 store_vector4(inst, machine, result);
1366 }
1367 break;
1368 case OPCODE_RSQ: /* 1 / sqrt() */
1369 {
1370 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001371 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001372 a[0] = FABSF(a[0]);
1373 result[0] = result[1] = result[2] = result[3] = INV_SQRTF(a[0]);
1374 store_vector4(inst, machine, result);
1375 if (DEBUG_PROG) {
1376 printf("RSQ %g = 1/sqrt(|%g|)\n", result[0], a[0]);
Brian13e3b212007-02-22 16:09:40 -07001377 }
Briane80d9012007-02-23 16:53:24 -07001378 }
1379 break;
1380 case OPCODE_SCS: /* sine and cos */
1381 {
1382 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001383 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001384 result[0] = (GLfloat) _mesa_cos(a[0]);
1385 result[1] = (GLfloat) _mesa_sin(a[0]);
1386 result[2] = 0.0; /* undefined! */
1387 result[3] = 0.0; /* undefined! */
1388 store_vector4(inst, machine, result);
1389 }
1390 break;
1391 case OPCODE_SEQ: /* set on equal */
1392 {
1393 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001394 fetch_vector4(&inst->SrcReg[0], machine, a);
1395 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001396 result[0] = (a[0] == b[0]) ? 1.0F : 0.0F;
1397 result[1] = (a[1] == b[1]) ? 1.0F : 0.0F;
1398 result[2] = (a[2] == b[2]) ? 1.0F : 0.0F;
1399 result[3] = (a[3] == b[3]) ? 1.0F : 0.0F;
1400 store_vector4(inst, machine, result);
Brian28ab1122007-03-06 12:15:30 -07001401 if (DEBUG_PROG) {
1402 printf("SEQ (%g %g %g %g) = (%g %g %g %g) == (%g %g %g %g)\n",
1403 result[0], result[1], result[2], result[3],
1404 a[0], a[1], a[2], a[3],
1405 b[0], b[1], b[2], b[3]);
1406 }
Briane80d9012007-02-23 16:53:24 -07001407 }
1408 break;
1409 case OPCODE_SFL: /* set false, operands ignored */
1410 {
1411 static const GLfloat result[4] = { 0.0F, 0.0F, 0.0F, 0.0F };
1412 store_vector4(inst, machine, result);
1413 }
1414 break;
1415 case OPCODE_SGE: /* set on greater or equal */
1416 {
1417 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001418 fetch_vector4(&inst->SrcReg[0], machine, a);
1419 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001420 result[0] = (a[0] >= b[0]) ? 1.0F : 0.0F;
1421 result[1] = (a[1] >= b[1]) ? 1.0F : 0.0F;
1422 result[2] = (a[2] >= b[2]) ? 1.0F : 0.0F;
1423 result[3] = (a[3] >= b[3]) ? 1.0F : 0.0F;
1424 store_vector4(inst, machine, result);
Brian28ab1122007-03-06 12:15:30 -07001425 if (DEBUG_PROG) {
1426 printf("SGE (%g %g %g %g) = (%g %g %g %g) >= (%g %g %g %g)\n",
1427 result[0], result[1], result[2], result[3],
1428 a[0], a[1], a[2], a[3],
1429 b[0], b[1], b[2], b[3]);
1430 }
Briane80d9012007-02-23 16:53:24 -07001431 }
1432 break;
1433 case OPCODE_SGT: /* set on greater */
1434 {
1435 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001436 fetch_vector4(&inst->SrcReg[0], machine, a);
1437 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001438 result[0] = (a[0] > b[0]) ? 1.0F : 0.0F;
1439 result[1] = (a[1] > b[1]) ? 1.0F : 0.0F;
1440 result[2] = (a[2] > b[2]) ? 1.0F : 0.0F;
1441 result[3] = (a[3] > b[3]) ? 1.0F : 0.0F;
1442 store_vector4(inst, machine, result);
1443 if (DEBUG_PROG) {
Brian28ab1122007-03-06 12:15:30 -07001444 printf("SGT (%g %g %g %g) = (%g %g %g %g) > (%g %g %g %g)\n",
1445 result[0], result[1], result[2], result[3],
1446 a[0], a[1], a[2], a[3],
1447 b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -07001448 }
Briane80d9012007-02-23 16:53:24 -07001449 }
1450 break;
1451 case OPCODE_SIN:
1452 {
1453 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001454 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001455 result[0] = result[1] = result[2] = result[3]
1456 = (GLfloat) _mesa_sin(a[0]);
1457 store_vector4(inst, machine, result);
1458 }
1459 break;
1460 case OPCODE_SLE: /* set on less or equal */
1461 {
1462 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001463 fetch_vector4(&inst->SrcReg[0], machine, a);
1464 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001465 result[0] = (a[0] <= b[0]) ? 1.0F : 0.0F;
1466 result[1] = (a[1] <= b[1]) ? 1.0F : 0.0F;
1467 result[2] = (a[2] <= b[2]) ? 1.0F : 0.0F;
1468 result[3] = (a[3] <= b[3]) ? 1.0F : 0.0F;
1469 store_vector4(inst, machine, result);
Brian28ab1122007-03-06 12:15:30 -07001470 if (DEBUG_PROG) {
1471 printf("SLE (%g %g %g %g) = (%g %g %g %g) <= (%g %g %g %g)\n",
1472 result[0], result[1], result[2], result[3],
1473 a[0], a[1], a[2], a[3],
1474 b[0], b[1], b[2], b[3]);
1475 }
Briane80d9012007-02-23 16:53:24 -07001476 }
1477 break;
1478 case OPCODE_SLT: /* set on less */
1479 {
1480 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001481 fetch_vector4(&inst->SrcReg[0], machine, a);
1482 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001483 result[0] = (a[0] < b[0]) ? 1.0F : 0.0F;
1484 result[1] = (a[1] < b[1]) ? 1.0F : 0.0F;
1485 result[2] = (a[2] < b[2]) ? 1.0F : 0.0F;
1486 result[3] = (a[3] < b[3]) ? 1.0F : 0.0F;
1487 store_vector4(inst, machine, result);
Brian28ab1122007-03-06 12:15:30 -07001488 if (DEBUG_PROG) {
1489 printf("SLT (%g %g %g %g) = (%g %g %g %g) < (%g %g %g %g)\n",
1490 result[0], result[1], result[2], result[3],
1491 a[0], a[1], a[2], a[3],
1492 b[0], b[1], b[2], b[3]);
1493 }
Briane80d9012007-02-23 16:53:24 -07001494 }
1495 break;
1496 case OPCODE_SNE: /* set on not equal */
1497 {
1498 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001499 fetch_vector4(&inst->SrcReg[0], machine, a);
1500 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001501 result[0] = (a[0] != b[0]) ? 1.0F : 0.0F;
1502 result[1] = (a[1] != b[1]) ? 1.0F : 0.0F;
1503 result[2] = (a[2] != b[2]) ? 1.0F : 0.0F;
1504 result[3] = (a[3] != b[3]) ? 1.0F : 0.0F;
1505 store_vector4(inst, machine, result);
Brian28ab1122007-03-06 12:15:30 -07001506 if (DEBUG_PROG) {
1507 printf("SNE (%g %g %g %g) = (%g %g %g %g) != (%g %g %g %g)\n",
1508 result[0], result[1], result[2], result[3],
1509 a[0], a[1], a[2], a[3],
1510 b[0], b[1], b[2], b[3]);
1511 }
Briane80d9012007-02-23 16:53:24 -07001512 }
1513 break;
Brian Paulf6ead502008-11-07 08:51:31 -07001514 case OPCODE_SSG: /* set sign (-1, 0 or +1) */
1515 {
1516 GLfloat a[4], result[4];
1517 fetch_vector4(&inst->SrcReg[0], machine, a);
1518 result[0] = (GLfloat) ((a[0] > 0.0F) - (a[0] < 0.0F));
1519 result[1] = (GLfloat) ((a[1] > 0.0F) - (a[1] < 0.0F));
1520 result[2] = (GLfloat) ((a[2] > 0.0F) - (a[2] < 0.0F));
1521 result[3] = (GLfloat) ((a[3] > 0.0F) - (a[3] < 0.0F));
1522 store_vector4(inst, machine, result);
1523 }
1524 break;
Briane80d9012007-02-23 16:53:24 -07001525 case OPCODE_STR: /* set true, operands ignored */
1526 {
1527 static const GLfloat result[4] = { 1.0F, 1.0F, 1.0F, 1.0F };
1528 store_vector4(inst, machine, result);
1529 }
1530 break;
1531 case OPCODE_SUB:
1532 {
1533 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001534 fetch_vector4(&inst->SrcReg[0], machine, a);
1535 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001536 result[0] = a[0] - b[0];
1537 result[1] = a[1] - b[1];
1538 result[2] = a[2] - b[2];
1539 result[3] = a[3] - b[3];
1540 store_vector4(inst, machine, result);
1541 if (DEBUG_PROG) {
1542 printf("SUB (%g %g %g %g) = (%g %g %g %g) - (%g %g %g %g)\n",
1543 result[0], result[1], result[2], result[3],
1544 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -07001545 }
Briane80d9012007-02-23 16:53:24 -07001546 }
1547 break;
1548 case OPCODE_SWZ: /* extended swizzle */
1549 {
1550 const struct prog_src_register *source = &inst->SrcReg[0];
Brian Paulf4361542008-11-11 10:47:10 -07001551 const GLfloat *src = get_src_register_pointer(source, machine);
Briane80d9012007-02-23 16:53:24 -07001552 GLfloat result[4];
1553 GLuint i;
1554 for (i = 0; i < 4; i++) {
1555 const GLuint swz = GET_SWZ(source->Swizzle, i);
1556 if (swz == SWIZZLE_ZERO)
1557 result[i] = 0.0;
1558 else if (swz == SWIZZLE_ONE)
1559 result[i] = 1.0;
Brian13e3b212007-02-22 16:09:40 -07001560 else {
Briane80d9012007-02-23 16:53:24 -07001561 ASSERT(swz >= 0);
1562 ASSERT(swz <= 3);
1563 result[i] = src[swz];
Brian13e3b212007-02-22 16:09:40 -07001564 }
Brian Paul7db7ff82009-04-14 22:14:30 -06001565 if (source->Negate & (1 << i))
Briane80d9012007-02-23 16:53:24 -07001566 result[i] = -result[i];
Brian13e3b212007-02-22 16:09:40 -07001567 }
Briane80d9012007-02-23 16:53:24 -07001568 store_vector4(inst, machine, result);
1569 }
1570 break;
1571 case OPCODE_TEX: /* Both ARB and NV frag prog */
Brian999b5562007-11-23 12:01:57 -07001572 /* Simple texel lookup */
Briane80d9012007-02-23 16:53:24 -07001573 {
Brian999b5562007-11-23 12:01:57 -07001574 GLfloat texcoord[4], color[4];
1575 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1576
1577 fetch_texel(ctx, machine, inst, texcoord, 0.0, color);
1578
Briane80d9012007-02-23 16:53:24 -07001579 if (DEBUG_PROG) {
Brian999b5562007-11-23 12:01:57 -07001580 printf("TEX (%g, %g, %g, %g) = texture[%d][%g, %g, %g, %g]\n",
Briane80d9012007-02-23 16:53:24 -07001581 color[0], color[1], color[2], color[3],
1582 inst->TexSrcUnit,
Brian999b5562007-11-23 12:01:57 -07001583 texcoord[0], texcoord[1], texcoord[2], texcoord[3]);
Briane80d9012007-02-23 16:53:24 -07001584 }
1585 store_vector4(inst, machine, color);
1586 }
1587 break;
1588 case OPCODE_TXB: /* GL_ARB_fragment_program only */
1589 /* Texel lookup with LOD bias */
1590 {
Brian999b5562007-11-23 12:01:57 -07001591 GLfloat texcoord[4], color[4], lodBias;
1592
1593 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1594
1595 /* texcoord[3] is the bias to add to lambda */
Brian Paul890f37d2009-09-23 13:34:30 -06001596 lodBias = texcoord[3];
Brian999b5562007-11-23 12:01:57 -07001597
1598 fetch_texel(ctx, machine, inst, texcoord, lodBias, color);
1599
Briane80d9012007-02-23 16:53:24 -07001600 store_vector4(inst, machine, color);
1601 }
1602 break;
1603 case OPCODE_TXD: /* GL_NV_fragment_program only */
1604 /* Texture lookup w/ partial derivatives for LOD */
1605 {
1606 GLfloat texcoord[4], dtdx[4], dtdy[4], color[4];
Brian33eac562007-02-25 18:52:41 -07001607 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1608 fetch_vector4(&inst->SrcReg[1], machine, dtdx);
1609 fetch_vector4(&inst->SrcReg[2], machine, dtdy);
Briane80d9012007-02-23 16:53:24 -07001610 machine->FetchTexelDeriv(ctx, texcoord, dtdx, dtdy,
Brian999b5562007-11-23 12:01:57 -07001611 0.0, /* lodBias */
Briane80d9012007-02-23 16:53:24 -07001612 inst->TexSrcUnit, color);
1613 store_vector4(inst, machine, color);
1614 }
1615 break;
1616 case OPCODE_TXP: /* GL_ARB_fragment_program only */
1617 /* Texture lookup w/ projective divide */
1618 {
Brian999b5562007-11-23 12:01:57 -07001619 GLfloat texcoord[4], color[4];
1620
Brian33eac562007-02-25 18:52:41 -07001621 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
Briane80d9012007-02-23 16:53:24 -07001622 /* Not so sure about this test - if texcoord[3] is
1623 * zero, we'd probably be fine except for an ASSERT in
1624 * IROUND_POS() which gets triggered by the inf values created.
1625 */
1626 if (texcoord[3] != 0.0) {
1627 texcoord[0] /= texcoord[3];
1628 texcoord[1] /= texcoord[3];
1629 texcoord[2] /= texcoord[3];
1630 }
Brian999b5562007-11-23 12:01:57 -07001631
1632 fetch_texel(ctx, machine, inst, texcoord, 0.0, color);
1633
Briane80d9012007-02-23 16:53:24 -07001634 store_vector4(inst, machine, color);
1635 }
1636 break;
1637 case OPCODE_TXP_NV: /* GL_NV_fragment_program only */
Brian999b5562007-11-23 12:01:57 -07001638 /* Texture lookup w/ projective divide, as above, but do not
1639 * do the divide by w if sampling from a cube map.
1640 */
Briane80d9012007-02-23 16:53:24 -07001641 {
Brian999b5562007-11-23 12:01:57 -07001642 GLfloat texcoord[4], color[4];
1643
Brian33eac562007-02-25 18:52:41 -07001644 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
Briane80d9012007-02-23 16:53:24 -07001645 if (inst->TexSrcTarget != TEXTURE_CUBE_INDEX &&
1646 texcoord[3] != 0.0) {
1647 texcoord[0] /= texcoord[3];
1648 texcoord[1] /= texcoord[3];
1649 texcoord[2] /= texcoord[3];
1650 }
Brian999b5562007-11-23 12:01:57 -07001651
1652 fetch_texel(ctx, machine, inst, texcoord, 0.0, color);
1653
Briane80d9012007-02-23 16:53:24 -07001654 store_vector4(inst, machine, color);
1655 }
1656 break;
Brian Paul035c0cf2008-11-06 17:14:33 -07001657 case OPCODE_TRUNC: /* truncate toward zero */
1658 {
1659 GLfloat a[4], result[4];
1660 fetch_vector4(&inst->SrcReg[0], machine, a);
1661 result[0] = (GLfloat) (GLint) a[0];
1662 result[1] = (GLfloat) (GLint) a[1];
1663 result[2] = (GLfloat) (GLint) a[2];
1664 result[3] = (GLfloat) (GLint) a[3];
1665 store_vector4(inst, machine, result);
1666 }
1667 break;
Briane80d9012007-02-23 16:53:24 -07001668 case OPCODE_UP2H: /* unpack two 16-bit floats */
1669 {
1670 GLfloat a[4], result[4];
Roland Scheidegger72362a52009-12-07 21:47:49 +01001671 fi_type fi;
Briane80d9012007-02-23 16:53:24 -07001672 GLhalfNV hx, hy;
Brian33eac562007-02-25 18:52:41 -07001673 fetch_vector1(&inst->SrcReg[0], machine, a);
Roland Scheidegger72362a52009-12-07 21:47:49 +01001674 fi.f = a[0];
1675 hx = fi.i & 0xffff;
1676 hy = fi.i >> 16;
Briane80d9012007-02-23 16:53:24 -07001677 result[0] = result[2] = _mesa_half_to_float(hx);
1678 result[1] = result[3] = _mesa_half_to_float(hy);
1679 store_vector4(inst, machine, result);
1680 }
1681 break;
1682 case OPCODE_UP2US: /* unpack two GLushorts */
1683 {
1684 GLfloat a[4], result[4];
Roland Scheidegger72362a52009-12-07 21:47:49 +01001685 fi_type fi;
Briane80d9012007-02-23 16:53:24 -07001686 GLushort usx, usy;
Brian33eac562007-02-25 18:52:41 -07001687 fetch_vector1(&inst->SrcReg[0], machine, a);
Roland Scheidegger72362a52009-12-07 21:47:49 +01001688 fi.f = a[0];
1689 usx = fi.i & 0xffff;
1690 usy = fi.i >> 16;
Briane80d9012007-02-23 16:53:24 -07001691 result[0] = result[2] = usx * (1.0f / 65535.0f);
1692 result[1] = result[3] = usy * (1.0f / 65535.0f);
1693 store_vector4(inst, machine, result);
1694 }
1695 break;
1696 case OPCODE_UP4B: /* unpack four GLbytes */
1697 {
1698 GLfloat a[4], result[4];
Roland Scheidegger72362a52009-12-07 21:47:49 +01001699 fi_type fi;
Brian33eac562007-02-25 18:52:41 -07001700 fetch_vector1(&inst->SrcReg[0], machine, a);
Roland Scheidegger72362a52009-12-07 21:47:49 +01001701 fi.f = a[0];
1702 result[0] = (((fi.i >> 0) & 0xff) - 128) / 127.0F;
1703 result[1] = (((fi.i >> 8) & 0xff) - 128) / 127.0F;
1704 result[2] = (((fi.i >> 16) & 0xff) - 128) / 127.0F;
1705 result[3] = (((fi.i >> 24) & 0xff) - 128) / 127.0F;
Briane80d9012007-02-23 16:53:24 -07001706 store_vector4(inst, machine, result);
1707 }
1708 break;
1709 case OPCODE_UP4UB: /* unpack four GLubytes */
1710 {
1711 GLfloat a[4], result[4];
Roland Scheidegger72362a52009-12-07 21:47:49 +01001712 fi_type fi;
Brian33eac562007-02-25 18:52:41 -07001713 fetch_vector1(&inst->SrcReg[0], machine, a);
Roland Scheidegger72362a52009-12-07 21:47:49 +01001714 fi.f = a[0];
1715 result[0] = ((fi.i >> 0) & 0xff) / 255.0F;
1716 result[1] = ((fi.i >> 8) & 0xff) / 255.0F;
1717 result[2] = ((fi.i >> 16) & 0xff) / 255.0F;
1718 result[3] = ((fi.i >> 24) & 0xff) / 255.0F;
Briane80d9012007-02-23 16:53:24 -07001719 store_vector4(inst, machine, result);
1720 }
1721 break;
Brian Paul37eef7b2008-11-07 09:33:55 -07001722 case OPCODE_XOR: /* bitwise XOR */
1723 {
1724 GLuint a[4], b[4], result[4];
1725 fetch_vector4ui(&inst->SrcReg[0], machine, a);
1726 fetch_vector4ui(&inst->SrcReg[1], machine, b);
1727 result[0] = a[0] ^ b[0];
1728 result[1] = a[1] ^ b[1];
1729 result[2] = a[2] ^ b[2];
1730 result[3] = a[3] ^ b[3];
1731 store_vector4ui(inst, machine, result);
1732 }
1733 break;
Briane80d9012007-02-23 16:53:24 -07001734 case OPCODE_XPD: /* cross product */
1735 {
1736 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001737 fetch_vector4(&inst->SrcReg[0], machine, a);
1738 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001739 result[0] = a[1] * b[2] - a[2] * b[1];
1740 result[1] = a[2] * b[0] - a[0] * b[2];
1741 result[2] = a[0] * b[1] - a[1] * b[0];
1742 result[3] = 1.0;
1743 store_vector4(inst, machine, result);
Brian9637c962007-03-07 17:40:57 -07001744 if (DEBUG_PROG) {
1745 printf("XPD (%g %g %g %g) = (%g %g %g) X (%g %g %g)\n",
1746 result[0], result[1], result[2], result[3],
1747 a[0], a[1], a[2], b[0], b[1], b[2]);
1748 }
Briane80d9012007-02-23 16:53:24 -07001749 }
1750 break;
1751 case OPCODE_X2D: /* 2-D matrix transform */
1752 {
1753 GLfloat a[4], b[4], c[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001754 fetch_vector4(&inst->SrcReg[0], machine, a);
1755 fetch_vector4(&inst->SrcReg[1], machine, b);
1756 fetch_vector4(&inst->SrcReg[2], machine, c);
Briane80d9012007-02-23 16:53:24 -07001757 result[0] = a[0] + b[0] * c[0] + b[1] * c[1];
1758 result[1] = a[1] + b[0] * c[2] + b[1] * c[3];
1759 result[2] = a[2] + b[0] * c[0] + b[1] * c[1];
1760 result[3] = a[3] + b[0] * c[2] + b[1] * c[3];
1761 store_vector4(inst, machine, result);
1762 }
1763 break;
1764 case OPCODE_PRINT:
1765 {
1766 if (inst->SrcReg[0].File != -1) {
1767 GLfloat a[4];
Brian33eac562007-02-25 18:52:41 -07001768 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001769 _mesa_printf("%s%g, %g, %g, %g\n", (const char *) inst->Data,
1770 a[0], a[1], a[2], a[3]);
1771 }
1772 else {
1773 _mesa_printf("%s\n", (const char *) inst->Data);
1774 }
1775 }
1776 break;
1777 case OPCODE_END:
1778 return GL_TRUE;
1779 default:
Alan Hourihane936dba12008-04-22 20:28:35 +01001780 _mesa_problem(ctx, "Bad opcode %d in _mesa_execute_program",
Briane80d9012007-02-23 16:53:24 -07001781 inst->Opcode);
1782 return GL_TRUE; /* return value doesn't matter */
Brian13e3b212007-02-22 16:09:40 -07001783 }
Briane80d9012007-02-23 16:53:24 -07001784
Briancfd00112007-02-25 18:30:45 -07001785 numExec++;
1786 if (numExec > maxExec) {
Brian13e3b212007-02-22 16:09:40 -07001787 _mesa_problem(ctx, "Infinite loop detected in fragment program");
1788 return GL_TRUE;
Brian13e3b212007-02-22 16:09:40 -07001789 }
Briane80d9012007-02-23 16:53:24 -07001790
1791 } /* for pc */
Brian13e3b212007-02-22 16:09:40 -07001792
Brian13e3b212007-02-22 16:09:40 -07001793 return GL_TRUE;
1794}