7908976b60d3bc605eaaba42614bc8df8848f0f8
[mesa.git] / src / mesa / shader / prog_execute.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.3
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 *
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
38 #include "glheader.h"
39 #include "colormac.h"
40 #include "context.h"
41 #include "program.h"
42 #include "prog_execute.h"
43 #include "prog_instruction.h"
44 #include "prog_parameter.h"
45 #include "prog_print.h"
46 #include "slang_library_noise.h"
47
48
49 /* See comments below for info about this */
50 #define LAMBDA_ZERO 1
51
52 /* debug predicate */
53 #define DEBUG_PROG 0
54
55
56 /**
57 * Set x to positive or negative infinity.
58 */
59 #if defined(USE_IEEE) || defined(_WIN32)
60 #define SET_POS_INFINITY(x) ( *((GLuint *) (void *)&x) = 0x7F800000 )
61 #define SET_NEG_INFINITY(x) ( *((GLuint *) (void *)&x) = 0xFF800000 )
62 #elif defined(VMS)
63 #define SET_POS_INFINITY(x) x = __MAXFLOAT
64 #define SET_NEG_INFINITY(x) x = -__MAXFLOAT
65 #else
66 #define SET_POS_INFINITY(x) x = (GLfloat) HUGE_VAL
67 #define SET_NEG_INFINITY(x) x = (GLfloat) -HUGE_VAL
68 #endif
69
70 #define SET_FLOAT_BITS(x, bits) ((fi_type *) (void *) &(x))->i = bits
71
72
73 static const GLfloat ZeroVec[4] = { 0.0F, 0.0F, 0.0F, 0.0F };
74
75
76
77 /**
78 * Return a pointer to the 4-element float vector specified by the given
79 * source register.
80 */
81 static INLINE const GLfloat *
82 get_register_pointer(const struct prog_src_register *source,
83 const struct gl_program_machine *machine)
84 {
85 if (source->RelAddr) {
86 const GLint reg = source->Index + machine->AddressReg[0][0];
87 if (source->File == PROGRAM_ENV_PARAM)
88 if (reg < 0 || reg >= MAX_PROGRAM_ENV_PARAMS)
89 return ZeroVec;
90 else
91 return machine->EnvParams[reg];
92 else {
93 const struct gl_program_parameter_list *params;
94 ASSERT(source->File == PROGRAM_LOCAL_PARAM ||
95 source->File == PROGRAM_STATE_VAR);
96 params = machine->CurProgram->Parameters;
97 if (reg < 0 || reg >= params->NumParameters)
98 return ZeroVec;
99 else
100 return params->ParameterValues[reg];
101 }
102 }
103
104 switch (source->File) {
105 case PROGRAM_TEMPORARY:
106 ASSERT(source->Index < MAX_PROGRAM_TEMPS);
107 return machine->Temporaries[source->Index];
108
109 case PROGRAM_INPUT:
110 if (machine->CurProgram->Target == GL_VERTEX_PROGRAM_ARB) {
111 ASSERT(source->Index < VERT_ATTRIB_MAX);
112 return machine->VertAttribs[source->Index];
113 }
114 else {
115 ASSERT(source->Index < FRAG_ATTRIB_MAX);
116 return machine->Attribs[source->Index][machine->CurElement];
117 }
118
119 case PROGRAM_OUTPUT:
120 ASSERT(source->Index < MAX_PROGRAM_OUTPUTS);
121 return machine->Outputs[source->Index];
122
123 case PROGRAM_LOCAL_PARAM:
124 ASSERT(source->Index < MAX_PROGRAM_LOCAL_PARAMS);
125 return machine->CurProgram->LocalParams[source->Index];
126
127 case PROGRAM_ENV_PARAM:
128 ASSERT(source->Index < MAX_PROGRAM_ENV_PARAMS);
129 return machine->EnvParams[source->Index];
130
131 case PROGRAM_STATE_VAR:
132 /* Fallthrough */
133 case PROGRAM_CONSTANT:
134 /* Fallthrough */
135 case PROGRAM_UNIFORM:
136 /* Fallthrough */
137 case PROGRAM_NAMED_PARAM:
138 ASSERT(source->Index <
139 (GLint) machine->CurProgram->Parameters->NumParameters);
140 return machine->CurProgram->Parameters->ParameterValues[source->Index];
141
142 default:
143 _mesa_problem(NULL,
144 "Invalid input register file %d in get_register_pointer()",
145 source->File);
146 return NULL;
147 }
148 }
149
150
151 #if FEATURE_MESA_program_debug
152 static struct gl_program_machine *CurrentMachine = NULL;
153
154 /**
155 * For GL_MESA_program_debug.
156 * Return current value (4*GLfloat) of a program register.
157 * Called via ctx->Driver.GetProgramRegister().
158 */
159 void
160 _mesa_get_program_register(GLcontext *ctx, enum register_file file,
161 GLuint index, GLfloat val[4])
162 {
163 if (CurrentMachine) {
164 struct prog_src_register src;
165 const GLfloat *reg;
166 src.File = file;
167 src.Index = index;
168 reg = get_register_pointer(&src, CurrentMachine);
169 COPY_4V(val, reg);
170 }
171 }
172 #endif /* FEATURE_MESA_program_debug */
173
174
175 /**
176 * Fetch a 4-element float vector from the given source register.
177 * Apply swizzling and negating as needed.
178 */
179 static void
180 fetch_vector4(const struct prog_src_register *source,
181 const struct gl_program_machine *machine, GLfloat result[4])
182 {
183 const GLfloat *src = get_register_pointer(source, machine);
184 ASSERT(src);
185
186 if (source->Swizzle == SWIZZLE_NOOP) {
187 /* no swizzling */
188 COPY_4V(result, src);
189 }
190 else {
191 ASSERT(GET_SWZ(source->Swizzle, 0) <= 3);
192 ASSERT(GET_SWZ(source->Swizzle, 1) <= 3);
193 ASSERT(GET_SWZ(source->Swizzle, 2) <= 3);
194 ASSERT(GET_SWZ(source->Swizzle, 3) <= 3);
195 result[0] = src[GET_SWZ(source->Swizzle, 0)];
196 result[1] = src[GET_SWZ(source->Swizzle, 1)];
197 result[2] = src[GET_SWZ(source->Swizzle, 2)];
198 result[3] = src[GET_SWZ(source->Swizzle, 3)];
199 }
200
201 if (source->NegateBase) {
202 result[0] = -result[0];
203 result[1] = -result[1];
204 result[2] = -result[2];
205 result[3] = -result[3];
206 }
207 if (source->Abs) {
208 result[0] = FABSF(result[0]);
209 result[1] = FABSF(result[1]);
210 result[2] = FABSF(result[2]);
211 result[3] = FABSF(result[3]);
212 }
213 if (source->NegateAbs) {
214 result[0] = -result[0];
215 result[1] = -result[1];
216 result[2] = -result[2];
217 result[3] = -result[3];
218 }
219 }
220
221 #if 0
222 /**
223 * Fetch the derivative with respect to X for the given register.
224 * \return GL_TRUE if it was easily computed or GL_FALSE if we
225 * need to execute another instance of the program (ugh)!
226 */
227 static GLboolean
228 fetch_vector4_deriv(GLcontext * ctx,
229 const struct prog_src_register *source,
230 const SWspan * span,
231 char xOrY, GLint column, GLfloat result[4])
232 {
233 GLfloat src[4];
234
235 ASSERT(xOrY == 'X' || xOrY == 'Y');
236
237 switch (source->Index) {
238 case FRAG_ATTRIB_WPOS:
239 if (xOrY == 'X') {
240 src[0] = 1.0;
241 src[1] = 0.0;
242 src[2] = span->attrStepX[FRAG_ATTRIB_WPOS][2]
243 / ctx->DrawBuffer->_DepthMaxF;
244 src[3] = span->attrStepX[FRAG_ATTRIB_WPOS][3];
245 }
246 else {
247 src[0] = 0.0;
248 src[1] = 1.0;
249 src[2] = span->attrStepY[FRAG_ATTRIB_WPOS][2]
250 / ctx->DrawBuffer->_DepthMaxF;
251 src[3] = span->attrStepY[FRAG_ATTRIB_WPOS][3];
252 }
253 break;
254 case FRAG_ATTRIB_COL0:
255 case FRAG_ATTRIB_COL1:
256 if (xOrY == 'X') {
257 src[0] = span->attrStepX[source->Index][0] * (1.0F / CHAN_MAXF);
258 src[1] = span->attrStepX[source->Index][1] * (1.0F / CHAN_MAXF);
259 src[2] = span->attrStepX[source->Index][2] * (1.0F / CHAN_MAXF);
260 src[3] = span->attrStepX[source->Index][3] * (1.0F / CHAN_MAXF);
261 }
262 else {
263 src[0] = span->attrStepY[source->Index][0] * (1.0F / CHAN_MAXF);
264 src[1] = span->attrStepY[source->Index][1] * (1.0F / CHAN_MAXF);
265 src[2] = span->attrStepY[source->Index][2] * (1.0F / CHAN_MAXF);
266 src[3] = span->attrStepY[source->Index][3] * (1.0F / CHAN_MAXF);
267 }
268 break;
269 case FRAG_ATTRIB_FOGC:
270 if (xOrY == 'X') {
271 src[0] = span->attrStepX[FRAG_ATTRIB_FOGC][0] * (1.0F / CHAN_MAXF);
272 src[1] = 0.0;
273 src[2] = 0.0;
274 src[3] = 0.0;
275 }
276 else {
277 src[0] = span->attrStepY[FRAG_ATTRIB_FOGC][0] * (1.0F / CHAN_MAXF);
278 src[1] = 0.0;
279 src[2] = 0.0;
280 src[3] = 0.0;
281 }
282 break;
283 default:
284 assert(source->Index < FRAG_ATTRIB_MAX);
285 /* texcoord or varying */
286 if (xOrY == 'X') {
287 /* this is a little tricky - I think I've got it right */
288 const GLfloat invQ = 1.0f / (span->attrStart[source->Index][3]
289 +
290 span->attrStepX[source->Index][3] *
291 column);
292 src[0] = span->attrStepX[source->Index][0] * invQ;
293 src[1] = span->attrStepX[source->Index][1] * invQ;
294 src[2] = span->attrStepX[source->Index][2] * invQ;
295 src[3] = span->attrStepX[source->Index][3] * invQ;
296 }
297 else {
298 /* Tricky, as above, but in Y direction */
299 const GLfloat invQ = 1.0f / (span->attrStart[source->Index][3]
300 + span->attrStepY[source->Index][3]);
301 src[0] = span->attrStepY[source->Index][0] * invQ;
302 src[1] = span->attrStepY[source->Index][1] * invQ;
303 src[2] = span->attrStepY[source->Index][2] * invQ;
304 src[3] = span->attrStepY[source->Index][3] * invQ;
305 }
306 break;
307 }
308
309 result[0] = src[GET_SWZ(source->Swizzle, 0)];
310 result[1] = src[GET_SWZ(source->Swizzle, 1)];
311 result[2] = src[GET_SWZ(source->Swizzle, 2)];
312 result[3] = src[GET_SWZ(source->Swizzle, 3)];
313
314 if (source->NegateBase) {
315 result[0] = -result[0];
316 result[1] = -result[1];
317 result[2] = -result[2];
318 result[3] = -result[3];
319 }
320 if (source->Abs) {
321 result[0] = FABSF(result[0]);
322 result[1] = FABSF(result[1]);
323 result[2] = FABSF(result[2]);
324 result[3] = FABSF(result[3]);
325 }
326 if (source->NegateAbs) {
327 result[0] = -result[0];
328 result[1] = -result[1];
329 result[2] = -result[2];
330 result[3] = -result[3];
331 }
332 return GL_TRUE;
333 }
334 #endif
335
336
337 /**
338 * As above, but only return result[0] element.
339 */
340 static void
341 fetch_vector1(const struct prog_src_register *source,
342 const struct gl_program_machine *machine, GLfloat result[4])
343 {
344 const GLfloat *src = get_register_pointer(source, machine);
345 ASSERT(src);
346
347 result[0] = src[GET_SWZ(source->Swizzle, 0)];
348
349 if (source->NegateBase) {
350 result[0] = -result[0];
351 }
352 if (source->Abs) {
353 result[0] = FABSF(result[0]);
354 }
355 if (source->NegateAbs) {
356 result[0] = -result[0];
357 }
358 }
359
360
361 /**
362 * Test value against zero and return GT, LT, EQ or UN if NaN.
363 */
364 static INLINE GLuint
365 generate_cc(float value)
366 {
367 if (value != value)
368 return COND_UN; /* NaN */
369 if (value > 0.0F)
370 return COND_GT;
371 if (value < 0.0F)
372 return COND_LT;
373 return COND_EQ;
374 }
375
376
377 /**
378 * Test if the ccMaskRule is satisfied by the given condition code.
379 * Used to mask destination writes according to the current condition code.
380 */
381 static INLINE GLboolean
382 test_cc(GLuint condCode, GLuint ccMaskRule)
383 {
384 switch (ccMaskRule) {
385 case COND_EQ: return (condCode == COND_EQ);
386 case COND_NE: return (condCode != COND_EQ);
387 case COND_LT: return (condCode == COND_LT);
388 case COND_GE: return (condCode == COND_GT || condCode == COND_EQ);
389 case COND_LE: return (condCode == COND_LT || condCode == COND_EQ);
390 case COND_GT: return (condCode == COND_GT);
391 case COND_TR: return GL_TRUE;
392 case COND_FL: return GL_FALSE;
393 default: return GL_TRUE;
394 }
395 }
396
397
398 /**
399 * Evaluate the 4 condition codes against a predicate and return GL_TRUE
400 * or GL_FALSE to indicate result.
401 */
402 static INLINE GLboolean
403 eval_condition(const struct gl_program_machine *machine,
404 const struct prog_instruction *inst)
405 {
406 const GLuint swizzle = inst->DstReg.CondSwizzle;
407 const GLuint condMask = inst->DstReg.CondMask;
408 if (test_cc(machine->CondCodes[GET_SWZ(swizzle, 0)], condMask) ||
409 test_cc(machine->CondCodes[GET_SWZ(swizzle, 1)], condMask) ||
410 test_cc(machine->CondCodes[GET_SWZ(swizzle, 2)], condMask) ||
411 test_cc(machine->CondCodes[GET_SWZ(swizzle, 3)], condMask)) {
412 return GL_TRUE;
413 }
414 else {
415 return GL_FALSE;
416 }
417 }
418
419
420
421 /**
422 * Store 4 floats into a register. Observe the instructions saturate and
423 * set-condition-code flags.
424 */
425 static void
426 store_vector4(const struct prog_instruction *inst,
427 struct gl_program_machine *machine, const GLfloat value[4])
428 {
429 const struct prog_dst_register *dest = &(inst->DstReg);
430 const GLboolean clamp = inst->SaturateMode == SATURATE_ZERO_ONE;
431 GLfloat *dstReg;
432 GLfloat dummyReg[4];
433 GLfloat clampedValue[4];
434 GLuint writeMask = dest->WriteMask;
435
436 switch (dest->File) {
437 case PROGRAM_OUTPUT:
438 ASSERT(dest->Index < MAX_PROGRAM_OUTPUTS);
439 dstReg = machine->Outputs[dest->Index];
440 break;
441 case PROGRAM_TEMPORARY:
442 ASSERT(dest->Index < MAX_PROGRAM_TEMPS);
443 dstReg = machine->Temporaries[dest->Index];
444 break;
445 case PROGRAM_WRITE_ONLY:
446 dstReg = dummyReg;
447 return;
448 default:
449 _mesa_problem(NULL, "bad register file in store_vector4(fp)");
450 return;
451 }
452
453 #if 0
454 if (value[0] > 1.0e10 ||
455 IS_INF_OR_NAN(value[0]) ||
456 IS_INF_OR_NAN(value[1]) ||
457 IS_INF_OR_NAN(value[2]) || IS_INF_OR_NAN(value[3]))
458 printf("store %g %g %g %g\n", value[0], value[1], value[2], value[3]);
459 #endif
460
461 if (clamp) {
462 clampedValue[0] = CLAMP(value[0], 0.0F, 1.0F);
463 clampedValue[1] = CLAMP(value[1], 0.0F, 1.0F);
464 clampedValue[2] = CLAMP(value[2], 0.0F, 1.0F);
465 clampedValue[3] = CLAMP(value[3], 0.0F, 1.0F);
466 value = clampedValue;
467 }
468
469 if (dest->CondMask != COND_TR) {
470 /* condition codes may turn off some writes */
471 if (writeMask & WRITEMASK_X) {
472 if (!test_cc(machine->CondCodes[GET_SWZ(dest->CondSwizzle, 0)],
473 dest->CondMask))
474 writeMask &= ~WRITEMASK_X;
475 }
476 if (writeMask & WRITEMASK_Y) {
477 if (!test_cc(machine->CondCodes[GET_SWZ(dest->CondSwizzle, 1)],
478 dest->CondMask))
479 writeMask &= ~WRITEMASK_Y;
480 }
481 if (writeMask & WRITEMASK_Z) {
482 if (!test_cc(machine->CondCodes[GET_SWZ(dest->CondSwizzle, 2)],
483 dest->CondMask))
484 writeMask &= ~WRITEMASK_Z;
485 }
486 if (writeMask & WRITEMASK_W) {
487 if (!test_cc(machine->CondCodes[GET_SWZ(dest->CondSwizzle, 3)],
488 dest->CondMask))
489 writeMask &= ~WRITEMASK_W;
490 }
491 }
492
493 if (writeMask & WRITEMASK_X)
494 dstReg[0] = value[0];
495 if (writeMask & WRITEMASK_Y)
496 dstReg[1] = value[1];
497 if (writeMask & WRITEMASK_Z)
498 dstReg[2] = value[2];
499 if (writeMask & WRITEMASK_W)
500 dstReg[3] = value[3];
501
502 if (inst->CondUpdate) {
503 if (writeMask & WRITEMASK_X)
504 machine->CondCodes[0] = generate_cc(value[0]);
505 if (writeMask & WRITEMASK_Y)
506 machine->CondCodes[1] = generate_cc(value[1]);
507 if (writeMask & WRITEMASK_Z)
508 machine->CondCodes[2] = generate_cc(value[2]);
509 if (writeMask & WRITEMASK_W)
510 machine->CondCodes[3] = generate_cc(value[3]);
511 #if DEBUG_PROG
512 printf("CondCodes=(%s,%s,%s,%s) for:\n",
513 _mesa_condcode_string(machine->CondCodes[0]),
514 _mesa_condcode_string(machine->CondCodes[1]),
515 _mesa_condcode_string(machine->CondCodes[2]),
516 _mesa_condcode_string(machine->CondCodes[3]));
517 #endif
518 }
519 }
520
521
522 #if 0
523 /**
524 * Initialize a new machine state instance from an existing one, adding
525 * the partial derivatives onto the input registers.
526 * Used to implement DDX and DDY instructions in non-trivial cases.
527 */
528 static void
529 init_machine_deriv(GLcontext * ctx,
530 const struct gl_program_machine *machine,
531 const struct gl_fragment_program *program,
532 const SWspan * span, char xOrY,
533 struct gl_program_machine *dMachine)
534 {
535 GLuint attr;
536
537 ASSERT(xOrY == 'X' || xOrY == 'Y');
538
539 /* copy existing machine */
540 _mesa_memcpy(dMachine, machine, sizeof(struct gl_program_machine));
541
542 if (program->Base.Target == GL_FRAGMENT_PROGRAM_NV) {
543 /* XXX also need to do this when using valgrind */
544 /* Clear temporary registers (undefined for ARB_f_p) */
545 _mesa_bzero((void *) machine->Temporaries,
546 MAX_PROGRAM_TEMPS * 4 * sizeof(GLfloat));
547 }
548
549 /* Add derivatives */
550 if (program->Base.InputsRead & FRAG_BIT_WPOS) {
551 GLfloat *wpos = machine->Attribs[FRAG_ATTRIB_WPOS][machine->CurElement];
552 if (xOrY == 'X') {
553 wpos[0] += 1.0F;
554 wpos[1] += 0.0F;
555 wpos[2] += span->attrStepX[FRAG_ATTRIB_WPOS][2];
556 wpos[3] += span->attrStepX[FRAG_ATTRIB_WPOS][3];
557 }
558 else {
559 wpos[0] += 0.0F;
560 wpos[1] += 1.0F;
561 wpos[2] += span->attrStepY[FRAG_ATTRIB_WPOS][2];
562 wpos[3] += span->attrStepY[FRAG_ATTRIB_WPOS][3];
563 }
564 }
565
566 /* primary, secondary colors */
567 for (attr = FRAG_ATTRIB_COL0; attr <= FRAG_ATTRIB_COL1; attr++) {
568 if (program->Base.InputsRead & (1 << attr)) {
569 GLfloat *col = machine->Attribs[attr][machine->CurElement];
570 if (xOrY == 'X') {
571 col[0] += span->attrStepX[attr][0] * (1.0F / CHAN_MAXF);
572 col[1] += span->attrStepX[attr][1] * (1.0F / CHAN_MAXF);
573 col[2] += span->attrStepX[attr][2] * (1.0F / CHAN_MAXF);
574 col[3] += span->attrStepX[attr][3] * (1.0F / CHAN_MAXF);
575 }
576 else {
577 col[0] += span->attrStepY[attr][0] * (1.0F / CHAN_MAXF);
578 col[1] += span->attrStepY[attr][1] * (1.0F / CHAN_MAXF);
579 col[2] += span->attrStepY[attr][2] * (1.0F / CHAN_MAXF);
580 col[3] += span->attrStepY[attr][3] * (1.0F / CHAN_MAXF);
581 }
582 }
583 }
584 if (program->Base.InputsRead & FRAG_BIT_FOGC) {
585 GLfloat *fogc = machine->Attribs[FRAG_ATTRIB_FOGC][machine->CurElement];
586 if (xOrY == 'X') {
587 fogc[0] += span->attrStepX[FRAG_ATTRIB_FOGC][0];
588 }
589 else {
590 fogc[0] += span->attrStepY[FRAG_ATTRIB_FOGC][0];
591 }
592 }
593 /* texcoord and varying vars */
594 for (attr = FRAG_ATTRIB_TEX0; attr < FRAG_ATTRIB_MAX; attr++) {
595 if (program->Base.InputsRead & (1 << attr)) {
596 GLfloat *val = machine->Attribs[attr][machine->CurElement];
597 /* XXX perspective-correct interpolation */
598 if (xOrY == 'X') {
599 val[0] += span->attrStepX[attr][0];
600 val[1] += span->attrStepX[attr][1];
601 val[2] += span->attrStepX[attr][2];
602 val[3] += span->attrStepX[attr][3];
603 }
604 else {
605 val[0] += span->attrStepY[attr][0];
606 val[1] += span->attrStepY[attr][1];
607 val[2] += span->attrStepY[attr][2];
608 val[3] += span->attrStepY[attr][3];
609 }
610 }
611 }
612
613 /* init condition codes */
614 dMachine->CondCodes[0] = COND_EQ;
615 dMachine->CondCodes[1] = COND_EQ;
616 dMachine->CondCodes[2] = COND_EQ;
617 dMachine->CondCodes[3] = COND_EQ;
618 }
619 #endif
620
621
622 /**
623 * Execute the given vertex/fragment program.
624 *
625 * \param ctx rendering context
626 * \param program the program to execute
627 * \param machine machine state (must be initialized)
628 * \return GL_TRUE if program completed or GL_FALSE if program executed KIL.
629 */
630 GLboolean
631 _mesa_execute_program(GLcontext * ctx,
632 const struct gl_program *program,
633 struct gl_program_machine *machine)
634 {
635 const GLuint numInst = program->NumInstructions;
636 const GLuint maxExec = 10000;
637 GLint pc, numExec = 0;
638
639 machine->CurProgram = program;
640
641 if (DEBUG_PROG) {
642 printf("execute program %u --------------------\n", program->Id);
643 }
644
645 #if FEATURE_MESA_program_debug
646 CurrentMachine = machine;
647 #endif
648
649 if (program->Target == GL_VERTEX_PROGRAM_ARB) {
650 machine->EnvParams = ctx->VertexProgram.Parameters;
651 }
652 else {
653 machine->EnvParams = ctx->FragmentProgram.Parameters;
654 }
655
656 for (pc = 0; pc < numInst; pc++) {
657 const struct prog_instruction *inst = program->Instructions + pc;
658
659 #if FEATURE_MESA_program_debug
660 if (ctx->FragmentProgram.CallbackEnabled &&
661 ctx->FragmentProgram.Callback) {
662 ctx->FragmentProgram.CurrentPosition = inst->StringPos;
663 ctx->FragmentProgram.Callback(program->Target,
664 ctx->FragmentProgram.CallbackData);
665 }
666 #endif
667
668 if (DEBUG_PROG) {
669 _mesa_print_instruction(inst);
670 }
671
672 switch (inst->Opcode) {
673 case OPCODE_ABS:
674 {
675 GLfloat a[4], result[4];
676 fetch_vector4(&inst->SrcReg[0], machine, a);
677 result[0] = FABSF(a[0]);
678 result[1] = FABSF(a[1]);
679 result[2] = FABSF(a[2]);
680 result[3] = FABSF(a[3]);
681 store_vector4(inst, machine, result);
682 }
683 break;
684 case OPCODE_ADD:
685 {
686 GLfloat a[4], b[4], result[4];
687 fetch_vector4(&inst->SrcReg[0], machine, a);
688 fetch_vector4(&inst->SrcReg[1], machine, b);
689 result[0] = a[0] + b[0];
690 result[1] = a[1] + b[1];
691 result[2] = a[2] + b[2];
692 result[3] = a[3] + b[3];
693 store_vector4(inst, machine, result);
694 if (DEBUG_PROG) {
695 printf("ADD (%g %g %g %g) = (%g %g %g %g) + (%g %g %g %g)\n",
696 result[0], result[1], result[2], result[3],
697 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
698 }
699 }
700 break;
701 case OPCODE_ARL:
702 {
703 GLfloat t[4];
704 fetch_vector4(&inst->SrcReg[0], machine, t);
705 machine->AddressReg[0][0] = (GLint) FLOORF(t[0]);
706 }
707 break;
708 case OPCODE_BGNLOOP:
709 /* no-op */
710 break;
711 case OPCODE_ENDLOOP:
712 /* subtract 1 here since pc is incremented by for(pc) loop */
713 pc = inst->BranchTarget - 1; /* go to matching BNGLOOP */
714 break;
715 case OPCODE_BGNSUB: /* begin subroutine */
716 break;
717 case OPCODE_ENDSUB: /* end subroutine */
718 break;
719 case OPCODE_BRA: /* branch (conditional) */
720 /* fall-through */
721 case OPCODE_BRK: /* break out of loop (conditional) */
722 /* fall-through */
723 case OPCODE_CONT: /* continue loop (conditional) */
724 if (eval_condition(machine, inst)) {
725 /* take branch */
726 /* Subtract 1 here since we'll do pc++ at end of for-loop */
727 pc = inst->BranchTarget - 1;
728 }
729 break;
730 case OPCODE_BRK0: /* Break if zero */
731 /* fall-through */
732 case OPCODE_CONT0: /* Continue if zero */
733 {
734 GLfloat a[4];
735 fetch_vector1(&inst->SrcReg[0], machine, a);
736 if (a[0] == 0.0) {
737 /* take branch */
738 /* Subtract 1 here since we'll do pc++ at end of for-loop */
739 pc = inst->BranchTarget - 1;
740 }
741 }
742 break;
743 case OPCODE_BRK1: /* Break if non-zero */
744 /* fall-through */
745 case OPCODE_CONT1: /* Continue if non-zero */
746 {
747 GLfloat a[4];
748 fetch_vector1(&inst->SrcReg[0], machine, a);
749 if (a[0] != 0.0) {
750 /* take branch */
751 /* Subtract 1 here since we'll do pc++ at end of for-loop */
752 pc = inst->BranchTarget - 1;
753 }
754 }
755 break;
756 case OPCODE_CAL: /* Call subroutine (conditional) */
757 if (eval_condition(machine, inst)) {
758 /* call the subroutine */
759 if (machine->StackDepth >= MAX_PROGRAM_CALL_DEPTH) {
760 return GL_TRUE; /* Per GL_NV_vertex_program2 spec */
761 }
762 machine->CallStack[machine->StackDepth++] = pc + 1; /* next inst */
763 /* Subtract 1 here since we'll do pc++ at end of for-loop */
764 pc = inst->BranchTarget - 1;
765 }
766 break;
767 case OPCODE_CMP:
768 {
769 GLfloat a[4], b[4], c[4], result[4];
770 fetch_vector4(&inst->SrcReg[0], machine, a);
771 fetch_vector4(&inst->SrcReg[1], machine, b);
772 fetch_vector4(&inst->SrcReg[2], machine, c);
773 result[0] = a[0] < 0.0F ? b[0] : c[0];
774 result[1] = a[1] < 0.0F ? b[1] : c[1];
775 result[2] = a[2] < 0.0F ? b[2] : c[2];
776 result[3] = a[3] < 0.0F ? b[3] : c[3];
777 store_vector4(inst, machine, result);
778 }
779 break;
780 case OPCODE_COS:
781 {
782 GLfloat a[4], result[4];
783 fetch_vector1(&inst->SrcReg[0], machine, a);
784 result[0] = result[1] = result[2] = result[3]
785 = (GLfloat) _mesa_cos(a[0]);
786 store_vector4(inst, machine, result);
787 }
788 break;
789 case OPCODE_DDX: /* Partial derivative with respect to X */
790 {
791 #if 0
792 GLfloat a[4], aNext[4], result[4];
793 struct gl_program_machine dMachine;
794 if (!fetch_vector4_deriv(ctx, &inst->SrcReg[0], span, 'X',
795 column, result)) {
796 /* This is tricky. Make a copy of the current machine state,
797 * increment the input registers by the dx or dy partial
798 * derivatives, then re-execute the program up to the
799 * preceeding instruction, then fetch the source register.
800 * Finally, find the difference in the register values for
801 * the original and derivative runs.
802 */
803 fetch_vector4(&inst->SrcReg[0], machine, program, a);
804 init_machine_deriv(ctx, machine, program, span,
805 'X', &dMachine);
806 execute_program(ctx, program, pc, &dMachine, span, column);
807 fetch_vector4(&inst->SrcReg[0], &dMachine, program,
808 aNext);
809 result[0] = aNext[0] - a[0];
810 result[1] = aNext[1] - a[1];
811 result[2] = aNext[2] - a[2];
812 result[3] = aNext[3] - a[3];
813 }
814 store_vector4(inst, machine, result);
815 #else
816 store_vector4(inst, machine, ZeroVec);
817 #endif
818 }
819 break;
820 case OPCODE_DDY: /* Partial derivative with respect to Y */
821 {
822 #if 0
823 GLfloat a[4], aNext[4], result[4];
824 struct gl_program_machine dMachine;
825 if (!fetch_vector4_deriv(ctx, &inst->SrcReg[0], span, 'Y',
826 column, result)) {
827 init_machine_deriv(ctx, machine, program, span,
828 'Y', &dMachine);
829 fetch_vector4(&inst->SrcReg[0], machine, program, a);
830 execute_program(ctx, program, pc, &dMachine, span, column);
831 fetch_vector4(&inst->SrcReg[0], &dMachine, program,
832 aNext);
833 result[0] = aNext[0] - a[0];
834 result[1] = aNext[1] - a[1];
835 result[2] = aNext[2] - a[2];
836 result[3] = aNext[3] - a[3];
837 }
838 store_vector4(inst, machine, result);
839 #else
840 store_vector4(inst, machine, ZeroVec);
841 #endif
842 }
843 break;
844 case OPCODE_DP3:
845 {
846 GLfloat a[4], b[4], result[4];
847 fetch_vector4(&inst->SrcReg[0], machine, a);
848 fetch_vector4(&inst->SrcReg[1], machine, b);
849 result[0] = result[1] = result[2] = result[3] = DOT3(a, b);
850 store_vector4(inst, machine, result);
851 if (DEBUG_PROG) {
852 printf("DP3 %g = (%g %g %g) . (%g %g %g)\n",
853 result[0], a[0], a[1], a[2], b[0], b[1], b[2]);
854 }
855 }
856 break;
857 case OPCODE_DP4:
858 {
859 GLfloat a[4], b[4], result[4];
860 fetch_vector4(&inst->SrcReg[0], machine, a);
861 fetch_vector4(&inst->SrcReg[1], machine, b);
862 result[0] = result[1] = result[2] = result[3] = DOT4(a, b);
863 store_vector4(inst, machine, result);
864 if (DEBUG_PROG) {
865 printf("DP4 %g = (%g, %g %g %g) . (%g, %g %g %g)\n",
866 result[0], a[0], a[1], a[2], a[3],
867 b[0], b[1], b[2], b[3]);
868 }
869 }
870 break;
871 case OPCODE_DPH:
872 {
873 GLfloat a[4], b[4], result[4];
874 fetch_vector4(&inst->SrcReg[0], machine, a);
875 fetch_vector4(&inst->SrcReg[1], machine, b);
876 result[0] = result[1] = result[2] = result[3] =
877 a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + b[3];
878 store_vector4(inst, machine, result);
879 }
880 break;
881 case OPCODE_DST: /* Distance vector */
882 {
883 GLfloat a[4], b[4], result[4];
884 fetch_vector4(&inst->SrcReg[0], machine, a);
885 fetch_vector4(&inst->SrcReg[1], machine, b);
886 result[0] = 1.0F;
887 result[1] = a[1] * b[1];
888 result[2] = a[2];
889 result[3] = b[3];
890 store_vector4(inst, machine, result);
891 }
892 break;
893 case OPCODE_EXP:
894 {
895 GLfloat t[4], q[4], floor_t0;
896 fetch_vector1(&inst->SrcReg[0], machine, t);
897 floor_t0 = FLOORF(t[0]);
898 if (floor_t0 > FLT_MAX_EXP) {
899 SET_POS_INFINITY(q[0]);
900 SET_POS_INFINITY(q[2]);
901 }
902 else if (floor_t0 < FLT_MIN_EXP) {
903 q[0] = 0.0F;
904 q[2] = 0.0F;
905 }
906 else {
907 q[0] = LDEXPF(1.0, (int) floor_t0);
908 /* Note: GL_NV_vertex_program expects
909 * result.z = result.x * APPX(result.y)
910 * We do what the ARB extension says.
911 */
912 q[2] = pow(2.0, t[0]);
913 }
914 q[1] = t[0] - floor_t0;
915 q[3] = 1.0F;
916 store_vector4( inst, machine, q );
917 }
918 break;
919 case OPCODE_EX2: /* Exponential base 2 */
920 {
921 GLfloat a[4], result[4];
922 fetch_vector1(&inst->SrcReg[0], machine, a);
923 result[0] = result[1] = result[2] = result[3] =
924 (GLfloat) _mesa_pow(2.0, a[0]);
925 store_vector4(inst, machine, result);
926 }
927 break;
928 case OPCODE_FLR:
929 {
930 GLfloat a[4], result[4];
931 fetch_vector4(&inst->SrcReg[0], machine, a);
932 result[0] = FLOORF(a[0]);
933 result[1] = FLOORF(a[1]);
934 result[2] = FLOORF(a[2]);
935 result[3] = FLOORF(a[3]);
936 store_vector4(inst, machine, result);
937 }
938 break;
939 case OPCODE_FRC:
940 {
941 GLfloat a[4], result[4];
942 fetch_vector4(&inst->SrcReg[0], machine, a);
943 result[0] = a[0] - FLOORF(a[0]);
944 result[1] = a[1] - FLOORF(a[1]);
945 result[2] = a[2] - FLOORF(a[2]);
946 result[3] = a[3] - FLOORF(a[3]);
947 store_vector4(inst, machine, result);
948 }
949 break;
950 case OPCODE_IF:
951 {
952 GLboolean cond;
953 /* eval condition */
954 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
955 GLfloat a[4];
956 fetch_vector1(&inst->SrcReg[0], machine, a);
957 cond = (a[0] != 0.0);
958 }
959 else {
960 cond = eval_condition(machine, inst);
961 }
962 /* do if/else */
963 if (cond) {
964 /* do if-clause (just continue execution) */
965 }
966 else {
967 /* go to the instruction after ELSE or ENDIF */
968 assert(inst->BranchTarget >= 0);
969 pc = inst->BranchTarget - 1;
970 }
971 }
972 break;
973 case OPCODE_ELSE:
974 /* goto ENDIF */
975 assert(inst->BranchTarget >= 0);
976 pc = inst->BranchTarget - 1;
977 break;
978 case OPCODE_ENDIF:
979 /* nothing */
980 break;
981 case OPCODE_INT: /* float to int */
982 {
983 GLfloat a[4], result[4];
984 fetch_vector4(&inst->SrcReg[0], machine, a);
985 result[0] = (GLfloat) (GLint) a[0];
986 result[1] = (GLfloat) (GLint) a[1];
987 result[2] = (GLfloat) (GLint) a[2];
988 result[3] = (GLfloat) (GLint) a[3];
989 store_vector4(inst, machine, result);
990 }
991 break;
992 case OPCODE_KIL_NV: /* NV_f_p only (conditional) */
993 if (eval_condition(machine, inst)) {
994 return GL_FALSE;
995 }
996 break;
997 case OPCODE_KIL: /* ARB_f_p only */
998 {
999 GLfloat a[4];
1000 fetch_vector4(&inst->SrcReg[0], machine, a);
1001 if (a[0] < 0.0F || a[1] < 0.0F || a[2] < 0.0F || a[3] < 0.0F) {
1002 return GL_FALSE;
1003 }
1004 }
1005 break;
1006 case OPCODE_LG2: /* log base 2 */
1007 {
1008 GLfloat a[4], result[4];
1009 fetch_vector1(&inst->SrcReg[0], machine, a);
1010 result[0] = result[1] = result[2] = result[3] = LOG2(a[0]);
1011 store_vector4(inst, machine, result);
1012 }
1013 break;
1014 case OPCODE_LIT:
1015 {
1016 const GLfloat epsilon = 1.0F / 256.0F; /* from NV VP spec */
1017 GLfloat a[4], result[4];
1018 fetch_vector4(&inst->SrcReg[0], machine, a);
1019 a[0] = MAX2(a[0], 0.0F);
1020 a[1] = MAX2(a[1], 0.0F);
1021 /* XXX ARB version clamps a[3], NV version doesn't */
1022 a[3] = CLAMP(a[3], -(128.0F - epsilon), (128.0F - epsilon));
1023 result[0] = 1.0F;
1024 result[1] = a[0];
1025 /* XXX we could probably just use pow() here */
1026 if (a[0] > 0.0F) {
1027 if (a[1] == 0.0 && a[3] == 0.0)
1028 result[2] = 1.0;
1029 else
1030 result[2] = EXPF(a[3] * LOGF(a[1]));
1031 }
1032 else {
1033 result[2] = 0.0;
1034 }
1035 result[3] = 1.0F;
1036 store_vector4(inst, machine, result);
1037 if (DEBUG_PROG) {
1038 printf("LIT (%g %g %g %g) : (%g %g %g %g)\n",
1039 result[0], result[1], result[2], result[3],
1040 a[0], a[1], a[2], a[3]);
1041 }
1042 }
1043 break;
1044 case OPCODE_LOG:
1045 {
1046 GLfloat t[4], q[4], abs_t0;
1047 fetch_vector1(&inst->SrcReg[0], machine, t);
1048 abs_t0 = FABSF(t[0]);
1049 if (abs_t0 != 0.0F) {
1050 /* Since we really can't handle infinite values on VMS
1051 * like other OSes we'll use __MAXFLOAT to represent
1052 * infinity. This may need some tweaking.
1053 */
1054 #ifdef VMS
1055 if (abs_t0 == __MAXFLOAT)
1056 #else
1057 if (IS_INF_OR_NAN(abs_t0))
1058 #endif
1059 {
1060 SET_POS_INFINITY(q[0]);
1061 q[1] = 1.0F;
1062 SET_POS_INFINITY(q[2]);
1063 }
1064 else {
1065 int exponent;
1066 GLfloat mantissa = FREXPF(t[0], &exponent);
1067 q[0] = (GLfloat) (exponent - 1);
1068 q[1] = (GLfloat) (2.0 * mantissa); /* map [.5, 1) -> [1, 2) */
1069 q[2] = (GLfloat) (q[0] + LOG2(q[1]));
1070 }
1071 }
1072 else {
1073 SET_NEG_INFINITY(q[0]);
1074 q[1] = 1.0F;
1075 SET_NEG_INFINITY(q[2]);
1076 }
1077 q[3] = 1.0;
1078 store_vector4(inst, machine, q);
1079 }
1080 break;
1081 case OPCODE_LRP:
1082 {
1083 GLfloat a[4], b[4], c[4], result[4];
1084 fetch_vector4(&inst->SrcReg[0], machine, a);
1085 fetch_vector4(&inst->SrcReg[1], machine, b);
1086 fetch_vector4(&inst->SrcReg[2], machine, c);
1087 result[0] = a[0] * b[0] + (1.0F - a[0]) * c[0];
1088 result[1] = a[1] * b[1] + (1.0F - a[1]) * c[1];
1089 result[2] = a[2] * b[2] + (1.0F - a[2]) * c[2];
1090 result[3] = a[3] * b[3] + (1.0F - a[3]) * c[3];
1091 store_vector4(inst, machine, result);
1092 if (DEBUG_PROG) {
1093 printf("LRP (%g %g %g %g) = (%g %g %g %g), "
1094 "(%g %g %g %g), (%g %g %g %g)\n",
1095 result[0], result[1], result[2], result[3],
1096 a[0], a[1], a[2], a[3],
1097 b[0], b[1], b[2], b[3], c[0], c[1], c[2], c[3]);
1098 }
1099 }
1100 break;
1101 case OPCODE_MAD:
1102 {
1103 GLfloat a[4], b[4], c[4], result[4];
1104 fetch_vector4(&inst->SrcReg[0], machine, a);
1105 fetch_vector4(&inst->SrcReg[1], machine, b);
1106 fetch_vector4(&inst->SrcReg[2], machine, c);
1107 result[0] = a[0] * b[0] + c[0];
1108 result[1] = a[1] * b[1] + c[1];
1109 result[2] = a[2] * b[2] + c[2];
1110 result[3] = a[3] * b[3] + c[3];
1111 store_vector4(inst, machine, result);
1112 if (DEBUG_PROG) {
1113 printf("MAD (%g %g %g %g) = (%g %g %g %g) * "
1114 "(%g %g %g %g) + (%g %g %g %g)\n",
1115 result[0], result[1], result[2], result[3],
1116 a[0], a[1], a[2], a[3],
1117 b[0], b[1], b[2], b[3], c[0], c[1], c[2], c[3]);
1118 }
1119 }
1120 break;
1121 case OPCODE_MAX:
1122 {
1123 GLfloat a[4], b[4], result[4];
1124 fetch_vector4(&inst->SrcReg[0], machine, a);
1125 fetch_vector4(&inst->SrcReg[1], machine, b);
1126 result[0] = MAX2(a[0], b[0]);
1127 result[1] = MAX2(a[1], b[1]);
1128 result[2] = MAX2(a[2], b[2]);
1129 result[3] = MAX2(a[3], b[3]);
1130 store_vector4(inst, machine, result);
1131 if (DEBUG_PROG) {
1132 printf("MAX (%g %g %g %g) = (%g %g %g %g), (%g %g %g %g)\n",
1133 result[0], result[1], result[2], result[3],
1134 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
1135 }
1136 }
1137 break;
1138 case OPCODE_MIN:
1139 {
1140 GLfloat a[4], b[4], result[4];
1141 fetch_vector4(&inst->SrcReg[0], machine, a);
1142 fetch_vector4(&inst->SrcReg[1], machine, b);
1143 result[0] = MIN2(a[0], b[0]);
1144 result[1] = MIN2(a[1], b[1]);
1145 result[2] = MIN2(a[2], b[2]);
1146 result[3] = MIN2(a[3], b[3]);
1147 store_vector4(inst, machine, result);
1148 }
1149 break;
1150 case OPCODE_MOV:
1151 {
1152 GLfloat result[4];
1153 fetch_vector4(&inst->SrcReg[0], machine, result);
1154 store_vector4(inst, machine, result);
1155 if (DEBUG_PROG) {
1156 printf("MOV (%g %g %g %g)\n",
1157 result[0], result[1], result[2], result[3]);
1158 }
1159 }
1160 break;
1161 case OPCODE_MUL:
1162 {
1163 GLfloat a[4], b[4], result[4];
1164 fetch_vector4(&inst->SrcReg[0], machine, a);
1165 fetch_vector4(&inst->SrcReg[1], machine, b);
1166 result[0] = a[0] * b[0];
1167 result[1] = a[1] * b[1];
1168 result[2] = a[2] * b[2];
1169 result[3] = a[3] * b[3];
1170 store_vector4(inst, machine, result);
1171 if (DEBUG_PROG) {
1172 printf("MUL (%g %g %g %g) = (%g %g %g %g) * (%g %g %g %g)\n",
1173 result[0], result[1], result[2], result[3],
1174 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
1175 }
1176 }
1177 break;
1178 case OPCODE_NOISE1:
1179 {
1180 GLfloat a[4], result[4];
1181 fetch_vector1(&inst->SrcReg[0], machine, a);
1182 result[0] =
1183 result[1] =
1184 result[2] = result[3] = _slang_library_noise1(a[0]);
1185 store_vector4(inst, machine, result);
1186 }
1187 break;
1188 case OPCODE_NOISE2:
1189 {
1190 GLfloat a[4], result[4];
1191 fetch_vector4(&inst->SrcReg[0], machine, a);
1192 result[0] =
1193 result[1] =
1194 result[2] = result[3] = _slang_library_noise2(a[0], a[1]);
1195 store_vector4(inst, machine, result);
1196 }
1197 break;
1198 case OPCODE_NOISE3:
1199 {
1200 GLfloat a[4], result[4];
1201 fetch_vector4(&inst->SrcReg[0], machine, a);
1202 result[0] =
1203 result[1] =
1204 result[2] =
1205 result[3] = _slang_library_noise3(a[0], a[1], a[2]);
1206 store_vector4(inst, machine, result);
1207 }
1208 break;
1209 case OPCODE_NOISE4:
1210 {
1211 GLfloat a[4], result[4];
1212 fetch_vector4(&inst->SrcReg[0], machine, a);
1213 result[0] =
1214 result[1] =
1215 result[2] =
1216 result[3] = _slang_library_noise4(a[0], a[1], a[2], a[3]);
1217 store_vector4(inst, machine, result);
1218 }
1219 break;
1220 case OPCODE_NOP:
1221 break;
1222 case OPCODE_PK2H: /* pack two 16-bit floats in one 32-bit float */
1223 {
1224 GLfloat a[4], result[4];
1225 GLhalfNV hx, hy;
1226 GLuint *rawResult = (GLuint *) result;
1227 GLuint twoHalves;
1228 fetch_vector4(&inst->SrcReg[0], machine, a);
1229 hx = _mesa_float_to_half(a[0]);
1230 hy = _mesa_float_to_half(a[1]);
1231 twoHalves = hx | (hy << 16);
1232 rawResult[0] = rawResult[1] = rawResult[2] = rawResult[3]
1233 = twoHalves;
1234 store_vector4(inst, machine, result);
1235 }
1236 break;
1237 case OPCODE_PK2US: /* pack two GLushorts into one 32-bit float */
1238 {
1239 GLfloat a[4], result[4];
1240 GLuint usx, usy, *rawResult = (GLuint *) result;
1241 fetch_vector4(&inst->SrcReg[0], machine, a);
1242 a[0] = CLAMP(a[0], 0.0F, 1.0F);
1243 a[1] = CLAMP(a[1], 0.0F, 1.0F);
1244 usx = IROUND(a[0] * 65535.0F);
1245 usy = IROUND(a[1] * 65535.0F);
1246 rawResult[0] = rawResult[1] = rawResult[2] = rawResult[3]
1247 = usx | (usy << 16);
1248 store_vector4(inst, machine, result);
1249 }
1250 break;
1251 case OPCODE_PK4B: /* pack four GLbytes into one 32-bit float */
1252 {
1253 GLfloat a[4], result[4];
1254 GLuint ubx, uby, ubz, ubw, *rawResult = (GLuint *) result;
1255 fetch_vector4(&inst->SrcReg[0], machine, a);
1256 a[0] = CLAMP(a[0], -128.0F / 127.0F, 1.0F);
1257 a[1] = CLAMP(a[1], -128.0F / 127.0F, 1.0F);
1258 a[2] = CLAMP(a[2], -128.0F / 127.0F, 1.0F);
1259 a[3] = CLAMP(a[3], -128.0F / 127.0F, 1.0F);
1260 ubx = IROUND(127.0F * a[0] + 128.0F);
1261 uby = IROUND(127.0F * a[1] + 128.0F);
1262 ubz = IROUND(127.0F * a[2] + 128.0F);
1263 ubw = IROUND(127.0F * a[3] + 128.0F);
1264 rawResult[0] = rawResult[1] = rawResult[2] = rawResult[3]
1265 = ubx | (uby << 8) | (ubz << 16) | (ubw << 24);
1266 store_vector4(inst, machine, result);
1267 }
1268 break;
1269 case OPCODE_PK4UB: /* pack four GLubytes into one 32-bit float */
1270 {
1271 GLfloat a[4], result[4];
1272 GLuint ubx, uby, ubz, ubw, *rawResult = (GLuint *) result;
1273 fetch_vector4(&inst->SrcReg[0], machine, a);
1274 a[0] = CLAMP(a[0], 0.0F, 1.0F);
1275 a[1] = CLAMP(a[1], 0.0F, 1.0F);
1276 a[2] = CLAMP(a[2], 0.0F, 1.0F);
1277 a[3] = CLAMP(a[3], 0.0F, 1.0F);
1278 ubx = IROUND(255.0F * a[0]);
1279 uby = IROUND(255.0F * a[1]);
1280 ubz = IROUND(255.0F * a[2]);
1281 ubw = IROUND(255.0F * a[3]);
1282 rawResult[0] = rawResult[1] = rawResult[2] = rawResult[3]
1283 = ubx | (uby << 8) | (ubz << 16) | (ubw << 24);
1284 store_vector4(inst, machine, result);
1285 }
1286 break;
1287 case OPCODE_POW:
1288 {
1289 GLfloat a[4], b[4], result[4];
1290 fetch_vector1(&inst->SrcReg[0], machine, a);
1291 fetch_vector1(&inst->SrcReg[1], machine, b);
1292 result[0] = result[1] = result[2] = result[3]
1293 = (GLfloat) _mesa_pow(a[0], b[0]);
1294 store_vector4(inst, machine, result);
1295 }
1296 break;
1297 case OPCODE_RCP:
1298 {
1299 GLfloat a[4], result[4];
1300 fetch_vector1(&inst->SrcReg[0], machine, a);
1301 if (DEBUG_PROG) {
1302 if (a[0] == 0)
1303 printf("RCP(0)\n");
1304 else if (IS_INF_OR_NAN(a[0]))
1305 printf("RCP(inf)\n");
1306 }
1307 result[0] = result[1] = result[2] = result[3] = 1.0F / a[0];
1308 store_vector4(inst, machine, result);
1309 }
1310 break;
1311 case OPCODE_RET: /* return from subroutine (conditional) */
1312 if (eval_condition(machine, inst)) {
1313 if (machine->StackDepth == 0) {
1314 return GL_TRUE; /* Per GL_NV_vertex_program2 spec */
1315 }
1316 /* subtract one because of pc++ in the for loop */
1317 pc = machine->CallStack[--machine->StackDepth] - 1;
1318 }
1319 break;
1320 case OPCODE_RFL: /* reflection vector */
1321 {
1322 GLfloat axis[4], dir[4], result[4], tmpX, tmpW;
1323 fetch_vector4(&inst->SrcReg[0], machine, axis);
1324 fetch_vector4(&inst->SrcReg[1], machine, dir);
1325 tmpW = DOT3(axis, axis);
1326 tmpX = (2.0F * DOT3(axis, dir)) / tmpW;
1327 result[0] = tmpX * axis[0] - dir[0];
1328 result[1] = tmpX * axis[1] - dir[1];
1329 result[2] = tmpX * axis[2] - dir[2];
1330 /* result[3] is never written! XXX enforce in parser! */
1331 store_vector4(inst, machine, result);
1332 }
1333 break;
1334 case OPCODE_RSQ: /* 1 / sqrt() */
1335 {
1336 GLfloat a[4], result[4];
1337 fetch_vector1(&inst->SrcReg[0], machine, a);
1338 a[0] = FABSF(a[0]);
1339 result[0] = result[1] = result[2] = result[3] = INV_SQRTF(a[0]);
1340 store_vector4(inst, machine, result);
1341 if (DEBUG_PROG) {
1342 printf("RSQ %g = 1/sqrt(|%g|)\n", result[0], a[0]);
1343 }
1344 }
1345 break;
1346 case OPCODE_SCS: /* sine and cos */
1347 {
1348 GLfloat a[4], result[4];
1349 fetch_vector1(&inst->SrcReg[0], machine, a);
1350 result[0] = (GLfloat) _mesa_cos(a[0]);
1351 result[1] = (GLfloat) _mesa_sin(a[0]);
1352 result[2] = 0.0; /* undefined! */
1353 result[3] = 0.0; /* undefined! */
1354 store_vector4(inst, machine, result);
1355 }
1356 break;
1357 case OPCODE_SEQ: /* set on equal */
1358 {
1359 GLfloat a[4], b[4], result[4];
1360 fetch_vector4(&inst->SrcReg[0], machine, a);
1361 fetch_vector4(&inst->SrcReg[1], machine, b);
1362 result[0] = (a[0] == b[0]) ? 1.0F : 0.0F;
1363 result[1] = (a[1] == b[1]) ? 1.0F : 0.0F;
1364 result[2] = (a[2] == b[2]) ? 1.0F : 0.0F;
1365 result[3] = (a[3] == b[3]) ? 1.0F : 0.0F;
1366 store_vector4(inst, machine, result);
1367 if (DEBUG_PROG) {
1368 printf("SEQ (%g %g %g %g) = (%g %g %g %g) == (%g %g %g %g)\n",
1369 result[0], result[1], result[2], result[3],
1370 a[0], a[1], a[2], a[3],
1371 b[0], b[1], b[2], b[3]);
1372 }
1373 }
1374 break;
1375 case OPCODE_SFL: /* set false, operands ignored */
1376 {
1377 static const GLfloat result[4] = { 0.0F, 0.0F, 0.0F, 0.0F };
1378 store_vector4(inst, machine, result);
1379 }
1380 break;
1381 case OPCODE_SGE: /* set on greater or equal */
1382 {
1383 GLfloat a[4], b[4], result[4];
1384 fetch_vector4(&inst->SrcReg[0], machine, a);
1385 fetch_vector4(&inst->SrcReg[1], machine, b);
1386 result[0] = (a[0] >= b[0]) ? 1.0F : 0.0F;
1387 result[1] = (a[1] >= b[1]) ? 1.0F : 0.0F;
1388 result[2] = (a[2] >= b[2]) ? 1.0F : 0.0F;
1389 result[3] = (a[3] >= b[3]) ? 1.0F : 0.0F;
1390 store_vector4(inst, machine, result);
1391 if (DEBUG_PROG) {
1392 printf("SGE (%g %g %g %g) = (%g %g %g %g) >= (%g %g %g %g)\n",
1393 result[0], result[1], result[2], result[3],
1394 a[0], a[1], a[2], a[3],
1395 b[0], b[1], b[2], b[3]);
1396 }
1397 }
1398 break;
1399 case OPCODE_SGT: /* set on greater */
1400 {
1401 GLfloat a[4], b[4], result[4];
1402 fetch_vector4(&inst->SrcReg[0], machine, a);
1403 fetch_vector4(&inst->SrcReg[1], machine, b);
1404 result[0] = (a[0] > b[0]) ? 1.0F : 0.0F;
1405 result[1] = (a[1] > b[1]) ? 1.0F : 0.0F;
1406 result[2] = (a[2] > b[2]) ? 1.0F : 0.0F;
1407 result[3] = (a[3] > b[3]) ? 1.0F : 0.0F;
1408 store_vector4(inst, machine, result);
1409 if (DEBUG_PROG) {
1410 printf("SGT (%g %g %g %g) = (%g %g %g %g) > (%g %g %g %g)\n",
1411 result[0], result[1], result[2], result[3],
1412 a[0], a[1], a[2], a[3],
1413 b[0], b[1], b[2], b[3]);
1414 }
1415 }
1416 break;
1417 case OPCODE_SIN:
1418 {
1419 GLfloat a[4], result[4];
1420 fetch_vector1(&inst->SrcReg[0], machine, a);
1421 result[0] = result[1] = result[2] = result[3]
1422 = (GLfloat) _mesa_sin(a[0]);
1423 store_vector4(inst, machine, result);
1424 }
1425 break;
1426 case OPCODE_SLE: /* set on less or equal */
1427 {
1428 GLfloat a[4], b[4], result[4];
1429 fetch_vector4(&inst->SrcReg[0], machine, a);
1430 fetch_vector4(&inst->SrcReg[1], machine, b);
1431 result[0] = (a[0] <= b[0]) ? 1.0F : 0.0F;
1432 result[1] = (a[1] <= b[1]) ? 1.0F : 0.0F;
1433 result[2] = (a[2] <= b[2]) ? 1.0F : 0.0F;
1434 result[3] = (a[3] <= b[3]) ? 1.0F : 0.0F;
1435 store_vector4(inst, machine, result);
1436 if (DEBUG_PROG) {
1437 printf("SLE (%g %g %g %g) = (%g %g %g %g) <= (%g %g %g %g)\n",
1438 result[0], result[1], result[2], result[3],
1439 a[0], a[1], a[2], a[3],
1440 b[0], b[1], b[2], b[3]);
1441 }
1442 }
1443 break;
1444 case OPCODE_SLT: /* set on less */
1445 {
1446 GLfloat a[4], b[4], result[4];
1447 fetch_vector4(&inst->SrcReg[0], machine, a);
1448 fetch_vector4(&inst->SrcReg[1], machine, b);
1449 result[0] = (a[0] < b[0]) ? 1.0F : 0.0F;
1450 result[1] = (a[1] < b[1]) ? 1.0F : 0.0F;
1451 result[2] = (a[2] < b[2]) ? 1.0F : 0.0F;
1452 result[3] = (a[3] < b[3]) ? 1.0F : 0.0F;
1453 store_vector4(inst, machine, result);
1454 if (DEBUG_PROG) {
1455 printf("SLT (%g %g %g %g) = (%g %g %g %g) < (%g %g %g %g)\n",
1456 result[0], result[1], result[2], result[3],
1457 a[0], a[1], a[2], a[3],
1458 b[0], b[1], b[2], b[3]);
1459 }
1460 }
1461 break;
1462 case OPCODE_SNE: /* set on not equal */
1463 {
1464 GLfloat a[4], b[4], result[4];
1465 fetch_vector4(&inst->SrcReg[0], machine, a);
1466 fetch_vector4(&inst->SrcReg[1], machine, b);
1467 result[0] = (a[0] != b[0]) ? 1.0F : 0.0F;
1468 result[1] = (a[1] != b[1]) ? 1.0F : 0.0F;
1469 result[2] = (a[2] != b[2]) ? 1.0F : 0.0F;
1470 result[3] = (a[3] != b[3]) ? 1.0F : 0.0F;
1471 store_vector4(inst, machine, result);
1472 if (DEBUG_PROG) {
1473 printf("SNE (%g %g %g %g) = (%g %g %g %g) != (%g %g %g %g)\n",
1474 result[0], result[1], result[2], result[3],
1475 a[0], a[1], a[2], a[3],
1476 b[0], b[1], b[2], b[3]);
1477 }
1478 }
1479 break;
1480 case OPCODE_STR: /* set true, operands ignored */
1481 {
1482 static const GLfloat result[4] = { 1.0F, 1.0F, 1.0F, 1.0F };
1483 store_vector4(inst, machine, result);
1484 }
1485 break;
1486 case OPCODE_SUB:
1487 {
1488 GLfloat a[4], b[4], result[4];
1489 fetch_vector4(&inst->SrcReg[0], machine, a);
1490 fetch_vector4(&inst->SrcReg[1], machine, b);
1491 result[0] = a[0] - b[0];
1492 result[1] = a[1] - b[1];
1493 result[2] = a[2] - b[2];
1494 result[3] = a[3] - b[3];
1495 store_vector4(inst, machine, result);
1496 if (DEBUG_PROG) {
1497 printf("SUB (%g %g %g %g) = (%g %g %g %g) - (%g %g %g %g)\n",
1498 result[0], result[1], result[2], result[3],
1499 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
1500 }
1501 }
1502 break;
1503 case OPCODE_SWZ: /* extended swizzle */
1504 {
1505 const struct prog_src_register *source = &inst->SrcReg[0];
1506 const GLfloat *src = get_register_pointer(source, machine);
1507 GLfloat result[4];
1508 GLuint i;
1509 for (i = 0; i < 4; i++) {
1510 const GLuint swz = GET_SWZ(source->Swizzle, i);
1511 if (swz == SWIZZLE_ZERO)
1512 result[i] = 0.0;
1513 else if (swz == SWIZZLE_ONE)
1514 result[i] = 1.0;
1515 else {
1516 ASSERT(swz >= 0);
1517 ASSERT(swz <= 3);
1518 result[i] = src[swz];
1519 }
1520 if (source->NegateBase & (1 << i))
1521 result[i] = -result[i];
1522 }
1523 store_vector4(inst, machine, result);
1524 }
1525 break;
1526 case OPCODE_TEX: /* Both ARB and NV frag prog */
1527 /* Texel lookup */
1528 {
1529 /* Note: only use the precomputed lambda value when we're
1530 * sampling texture unit [K] with texcoord[K].
1531 * Otherwise, the lambda value may have no relation to the
1532 * instruction's texcoord or texture image. Using the wrong
1533 * lambda is usually bad news.
1534 * The rest of the time, just use zero (until we get a more
1535 * sophisticated way of computing lambda).
1536 */
1537 GLfloat coord[4], color[4], lambda;
1538 #if 0
1539 if (inst->SrcReg[0].File == PROGRAM_INPUT &&
1540 inst->SrcReg[0].Index == FRAG_ATTRIB_TEX0 + inst->TexSrcUnit)
1541 lambda = span->array->lambda[inst->TexSrcUnit][column];
1542 else
1543 #endif
1544 lambda = 0.0;
1545 fetch_vector4(&inst->SrcReg[0], machine, coord);
1546 machine->FetchTexelLod(ctx, coord, lambda, inst->TexSrcUnit,
1547 color);
1548 if (DEBUG_PROG) {
1549 printf("TEX (%g, %g, %g, %g) = texture[%d][%g, %g, %g, %g], "
1550 "lod %f\n",
1551 color[0], color[1], color[2], color[3],
1552 inst->TexSrcUnit,
1553 coord[0], coord[1], coord[2], coord[3], lambda);
1554 }
1555 store_vector4(inst, machine, color);
1556 }
1557 break;
1558 case OPCODE_TXB: /* GL_ARB_fragment_program only */
1559 /* Texel lookup with LOD bias */
1560 {
1561 const struct gl_texture_unit *texUnit
1562 = &ctx->Texture.Unit[inst->TexSrcUnit];
1563 GLfloat coord[4], color[4], lambda, bias;
1564 #if 0
1565 if (inst->SrcReg[0].File == PROGRAM_INPUT &&
1566 inst->SrcReg[0].Index == FRAG_ATTRIB_TEX0 + inst->TexSrcUnit)
1567 lambda = span->array->lambda[inst->TexSrcUnit][column];
1568 else
1569 #endif
1570 lambda = 0.0;
1571 fetch_vector4(&inst->SrcReg[0], machine, coord);
1572 /* coord[3] is the bias to add to lambda */
1573 bias = texUnit->LodBias + coord[3];
1574 if (texUnit->_Current)
1575 bias += texUnit->_Current->LodBias;
1576 machine->FetchTexelLod(ctx, coord, lambda + bias,
1577 inst->TexSrcUnit, color);
1578 store_vector4(inst, machine, color);
1579 }
1580 break;
1581 case OPCODE_TXD: /* GL_NV_fragment_program only */
1582 /* Texture lookup w/ partial derivatives for LOD */
1583 {
1584 GLfloat texcoord[4], dtdx[4], dtdy[4], color[4];
1585 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1586 fetch_vector4(&inst->SrcReg[1], machine, dtdx);
1587 fetch_vector4(&inst->SrcReg[2], machine, dtdy);
1588 machine->FetchTexelDeriv(ctx, texcoord, dtdx, dtdy,
1589 inst->TexSrcUnit, color);
1590 store_vector4(inst, machine, color);
1591 }
1592 break;
1593 case OPCODE_TXP: /* GL_ARB_fragment_program only */
1594 /* Texture lookup w/ projective divide */
1595 {
1596 GLfloat texcoord[4], color[4], lambda;
1597 #if 0
1598 if (inst->SrcReg[0].File == PROGRAM_INPUT &&
1599 inst->SrcReg[0].Index == FRAG_ATTRIB_TEX0 + inst->TexSrcUnit)
1600 lambda = span->array->lambda[inst->TexSrcUnit][column];
1601 else
1602 #endif
1603 lambda = 0.0;
1604 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1605 /* Not so sure about this test - if texcoord[3] is
1606 * zero, we'd probably be fine except for an ASSERT in
1607 * IROUND_POS() which gets triggered by the inf values created.
1608 */
1609 if (texcoord[3] != 0.0) {
1610 texcoord[0] /= texcoord[3];
1611 texcoord[1] /= texcoord[3];
1612 texcoord[2] /= texcoord[3];
1613 }
1614 machine->FetchTexelLod(ctx, texcoord, lambda,
1615 inst->TexSrcUnit, color);
1616 store_vector4(inst, machine, color);
1617 }
1618 break;
1619 case OPCODE_TXP_NV: /* GL_NV_fragment_program only */
1620 /* Texture lookup w/ projective divide */
1621 {
1622 GLfloat texcoord[4], color[4], lambda;
1623 #if 0
1624 if (inst->SrcReg[0].File == PROGRAM_INPUT &&
1625 inst->SrcReg[0].Index == FRAG_ATTRIB_TEX0 + inst->TexSrcUnit)
1626 lambda = span->array->lambda[inst->TexSrcUnit][column];
1627 else
1628 #endif
1629 lambda = 0.0;
1630 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1631 if (inst->TexSrcTarget != TEXTURE_CUBE_INDEX &&
1632 texcoord[3] != 0.0) {
1633 texcoord[0] /= texcoord[3];
1634 texcoord[1] /= texcoord[3];
1635 texcoord[2] /= texcoord[3];
1636 }
1637 machine->FetchTexelLod(ctx, texcoord, lambda,
1638 inst->TexSrcUnit, color);
1639 store_vector4(inst, machine, color);
1640 }
1641 break;
1642 case OPCODE_UP2H: /* unpack two 16-bit floats */
1643 {
1644 GLfloat a[4], result[4];
1645 const GLuint *rawBits = (const GLuint *) a;
1646 GLhalfNV hx, hy;
1647 fetch_vector1(&inst->SrcReg[0], machine, a);
1648 hx = rawBits[0] & 0xffff;
1649 hy = rawBits[0] >> 16;
1650 result[0] = result[2] = _mesa_half_to_float(hx);
1651 result[1] = result[3] = _mesa_half_to_float(hy);
1652 store_vector4(inst, machine, result);
1653 }
1654 break;
1655 case OPCODE_UP2US: /* unpack two GLushorts */
1656 {
1657 GLfloat a[4], result[4];
1658 const GLuint *rawBits = (const GLuint *) a;
1659 GLushort usx, usy;
1660 fetch_vector1(&inst->SrcReg[0], machine, a);
1661 usx = rawBits[0] & 0xffff;
1662 usy = rawBits[0] >> 16;
1663 result[0] = result[2] = usx * (1.0f / 65535.0f);
1664 result[1] = result[3] = usy * (1.0f / 65535.0f);
1665 store_vector4(inst, machine, result);
1666 }
1667 break;
1668 case OPCODE_UP4B: /* unpack four GLbytes */
1669 {
1670 GLfloat a[4], result[4];
1671 const GLuint *rawBits = (const GLuint *) a;
1672 fetch_vector1(&inst->SrcReg[0], machine, a);
1673 result[0] = (((rawBits[0] >> 0) & 0xff) - 128) / 127.0F;
1674 result[1] = (((rawBits[0] >> 8) & 0xff) - 128) / 127.0F;
1675 result[2] = (((rawBits[0] >> 16) & 0xff) - 128) / 127.0F;
1676 result[3] = (((rawBits[0] >> 24) & 0xff) - 128) / 127.0F;
1677 store_vector4(inst, machine, result);
1678 }
1679 break;
1680 case OPCODE_UP4UB: /* unpack four GLubytes */
1681 {
1682 GLfloat a[4], result[4];
1683 const GLuint *rawBits = (const GLuint *) a;
1684 fetch_vector1(&inst->SrcReg[0], machine, a);
1685 result[0] = ((rawBits[0] >> 0) & 0xff) / 255.0F;
1686 result[1] = ((rawBits[0] >> 8) & 0xff) / 255.0F;
1687 result[2] = ((rawBits[0] >> 16) & 0xff) / 255.0F;
1688 result[3] = ((rawBits[0] >> 24) & 0xff) / 255.0F;
1689 store_vector4(inst, machine, result);
1690 }
1691 break;
1692 case OPCODE_XPD: /* cross product */
1693 {
1694 GLfloat a[4], b[4], result[4];
1695 fetch_vector4(&inst->SrcReg[0], machine, a);
1696 fetch_vector4(&inst->SrcReg[1], machine, b);
1697 result[0] = a[1] * b[2] - a[2] * b[1];
1698 result[1] = a[2] * b[0] - a[0] * b[2];
1699 result[2] = a[0] * b[1] - a[1] * b[0];
1700 result[3] = 1.0;
1701 store_vector4(inst, machine, result);
1702 if (DEBUG_PROG) {
1703 printf("XPD (%g %g %g %g) = (%g %g %g) X (%g %g %g)\n",
1704 result[0], result[1], result[2], result[3],
1705 a[0], a[1], a[2], b[0], b[1], b[2]);
1706 }
1707 }
1708 break;
1709 case OPCODE_X2D: /* 2-D matrix transform */
1710 {
1711 GLfloat a[4], b[4], c[4], result[4];
1712 fetch_vector4(&inst->SrcReg[0], machine, a);
1713 fetch_vector4(&inst->SrcReg[1], machine, b);
1714 fetch_vector4(&inst->SrcReg[2], machine, c);
1715 result[0] = a[0] + b[0] * c[0] + b[1] * c[1];
1716 result[1] = a[1] + b[0] * c[2] + b[1] * c[3];
1717 result[2] = a[2] + b[0] * c[0] + b[1] * c[1];
1718 result[3] = a[3] + b[0] * c[2] + b[1] * c[3];
1719 store_vector4(inst, machine, result);
1720 }
1721 break;
1722 case OPCODE_PRINT:
1723 {
1724 if (inst->SrcReg[0].File != -1) {
1725 GLfloat a[4];
1726 fetch_vector4(&inst->SrcReg[0], machine, a);
1727 _mesa_printf("%s%g, %g, %g, %g\n", (const char *) inst->Data,
1728 a[0], a[1], a[2], a[3]);
1729 }
1730 else {
1731 _mesa_printf("%s\n", (const char *) inst->Data);
1732 }
1733 }
1734 break;
1735 case OPCODE_END:
1736 return GL_TRUE;
1737 default:
1738 _mesa_problem(ctx, "Bad opcode %d in _mesa_exec_fragment_program",
1739 inst->Opcode);
1740 return GL_TRUE; /* return value doesn't matter */
1741
1742 }
1743
1744 numExec++;
1745 if (numExec > maxExec) {
1746 _mesa_problem(ctx, "Infinite loop detected in fragment program");
1747 return GL_TRUE;
1748 }
1749
1750 } /* for pc */
1751
1752 #if FEATURE_MESA_program_debug
1753 CurrentMachine = NULL;
1754 #endif
1755
1756 return GL_TRUE;
1757 }