2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
26 * \file prog_execute.c
27 * Software interpreter for vertex/fragment programs.
32 * NOTE: we do everything in single-precision floating point; we don't
33 * currently observe the single/half/fixed-precision qualifiers.
38 #include "main/glheader.h"
39 #include "main/colormac.h"
40 #include "main/macros.h"
41 #include "prog_execute.h"
42 #include "prog_instruction.h"
43 #include "prog_parameter.h"
44 #include "prog_print.h"
45 #include "prog_noise.h"
53 * Set x to positive or negative infinity.
55 #define SET_POS_INFINITY(x) \
61 #define SET_NEG_INFINITY(x) \
68 #define SET_FLOAT_BITS(x, bits) ((fi_type *) (void *) &(x))->i = bits
71 static const GLfloat ZeroVec
[4] = { 0.0F
, 0.0F
, 0.0F
, 0.0F
};
75 * Return a pointer to the 4-element float vector specified by the given
78 static inline const GLfloat
*
79 get_src_register_pointer(const struct prog_src_register
*source
,
80 const struct gl_program_machine
*machine
)
82 const struct gl_program
*prog
= machine
->CurProgram
;
83 GLint reg
= source
->Index
;
85 if (source
->RelAddr
) {
86 /* add address register value to src index/offset */
87 reg
+= machine
->AddressReg
[0][0];
93 switch (source
->File
) {
94 case PROGRAM_TEMPORARY
:
95 if (reg
>= MAX_PROGRAM_TEMPS
)
97 return machine
->Temporaries
[reg
];
100 if (prog
->Target
== GL_VERTEX_PROGRAM_ARB
) {
101 if (reg
>= VERT_ATTRIB_MAX
)
103 return machine
->VertAttribs
[reg
];
106 if (reg
>= VARYING_SLOT_MAX
)
108 return machine
->Attribs
[reg
][machine
->CurElement
];
112 if (reg
>= MAX_PROGRAM_OUTPUTS
)
114 return machine
->Outputs
[reg
];
116 case PROGRAM_STATE_VAR
:
118 case PROGRAM_CONSTANT
:
120 case PROGRAM_UNIFORM
:
121 if (reg
>= (GLint
) prog
->Parameters
->NumParameters
)
123 return (GLfloat
*) prog
->Parameters
->ParameterValues
[reg
];
125 case PROGRAM_SYSTEM_VALUE
:
126 assert(reg
< (GLint
) Elements(machine
->SystemValues
));
127 return machine
->SystemValues
[reg
];
131 "Invalid src register file %d in get_src_register_pointer()",
139 * Return a pointer to the 4-element float vector specified by the given
140 * destination register.
142 static inline GLfloat
*
143 get_dst_register_pointer(const struct prog_dst_register
*dest
,
144 struct gl_program_machine
*machine
)
146 static GLfloat dummyReg
[4];
147 GLint reg
= dest
->Index
;
150 /* add address register value to src index/offset */
151 reg
+= machine
->AddressReg
[0][0];
157 switch (dest
->File
) {
158 case PROGRAM_TEMPORARY
:
159 if (reg
>= MAX_PROGRAM_TEMPS
)
161 return machine
->Temporaries
[reg
];
164 if (reg
>= MAX_PROGRAM_OUTPUTS
)
166 return machine
->Outputs
[reg
];
170 "Invalid dest register file %d in get_dst_register_pointer()",
179 * Fetch a 4-element float vector from the given source register.
180 * Apply swizzling and negating as needed.
183 fetch_vector4(const struct prog_src_register
*source
,
184 const struct gl_program_machine
*machine
, GLfloat result
[4])
186 const GLfloat
*src
= get_src_register_pointer(source
, machine
);
188 if (source
->Swizzle
== SWIZZLE_NOOP
) {
190 COPY_4V(result
, src
);
193 assert(GET_SWZ(source
->Swizzle
, 0) <= 3);
194 assert(GET_SWZ(source
->Swizzle
, 1) <= 3);
195 assert(GET_SWZ(source
->Swizzle
, 2) <= 3);
196 assert(GET_SWZ(source
->Swizzle
, 3) <= 3);
197 result
[0] = src
[GET_SWZ(source
->Swizzle
, 0)];
198 result
[1] = src
[GET_SWZ(source
->Swizzle
, 1)];
199 result
[2] = src
[GET_SWZ(source
->Swizzle
, 2)];
200 result
[3] = src
[GET_SWZ(source
->Swizzle
, 3)];
204 result
[0] = FABSF(result
[0]);
205 result
[1] = FABSF(result
[1]);
206 result
[2] = FABSF(result
[2]);
207 result
[3] = FABSF(result
[3]);
209 if (source
->Negate
) {
210 assert(source
->Negate
== NEGATE_XYZW
);
211 result
[0] = -result
[0];
212 result
[1] = -result
[1];
213 result
[2] = -result
[2];
214 result
[3] = -result
[3];
218 assert(!IS_INF_OR_NAN(result
[0]));
219 assert(!IS_INF_OR_NAN(result
[0]));
220 assert(!IS_INF_OR_NAN(result
[0]));
221 assert(!IS_INF_OR_NAN(result
[0]));
227 * Fetch the derivative with respect to X or Y for the given register.
228 * XXX this currently only works for fragment program input attribs.
231 fetch_vector4_deriv(struct gl_context
* ctx
,
232 const struct prog_src_register
*source
,
233 const struct gl_program_machine
*machine
,
234 char xOrY
, GLfloat result
[4])
236 if (source
->File
== PROGRAM_INPUT
&&
237 source
->Index
< (GLint
) machine
->NumDeriv
) {
238 const GLint col
= machine
->CurElement
;
239 const GLfloat w
= machine
->Attribs
[VARYING_SLOT_POS
][col
][3];
240 const GLfloat invQ
= 1.0f
/ w
;
244 deriv
[0] = machine
->DerivX
[source
->Index
][0] * invQ
;
245 deriv
[1] = machine
->DerivX
[source
->Index
][1] * invQ
;
246 deriv
[2] = machine
->DerivX
[source
->Index
][2] * invQ
;
247 deriv
[3] = machine
->DerivX
[source
->Index
][3] * invQ
;
250 deriv
[0] = machine
->DerivY
[source
->Index
][0] * invQ
;
251 deriv
[1] = machine
->DerivY
[source
->Index
][1] * invQ
;
252 deriv
[2] = machine
->DerivY
[source
->Index
][2] * invQ
;
253 deriv
[3] = machine
->DerivY
[source
->Index
][3] * invQ
;
256 result
[0] = deriv
[GET_SWZ(source
->Swizzle
, 0)];
257 result
[1] = deriv
[GET_SWZ(source
->Swizzle
, 1)];
258 result
[2] = deriv
[GET_SWZ(source
->Swizzle
, 2)];
259 result
[3] = deriv
[GET_SWZ(source
->Swizzle
, 3)];
262 result
[0] = FABSF(result
[0]);
263 result
[1] = FABSF(result
[1]);
264 result
[2] = FABSF(result
[2]);
265 result
[3] = FABSF(result
[3]);
267 if (source
->Negate
) {
268 assert(source
->Negate
== NEGATE_XYZW
);
269 result
[0] = -result
[0];
270 result
[1] = -result
[1];
271 result
[2] = -result
[2];
272 result
[3] = -result
[3];
276 ASSIGN_4V(result
, 0.0, 0.0, 0.0, 0.0);
282 * As above, but only return result[0] element.
285 fetch_vector1(const struct prog_src_register
*source
,
286 const struct gl_program_machine
*machine
, GLfloat result
[4])
288 const GLfloat
*src
= get_src_register_pointer(source
, machine
);
290 result
[0] = src
[GET_SWZ(source
->Swizzle
, 0)];
293 result
[0] = FABSF(result
[0]);
295 if (source
->Negate
) {
296 result
[0] = -result
[0];
302 * Fetch texel from texture. Use partial derivatives when possible.
305 fetch_texel(struct gl_context
*ctx
,
306 const struct gl_program_machine
*machine
,
307 const struct prog_instruction
*inst
,
308 const GLfloat texcoord
[4], GLfloat lodBias
,
311 const GLuint unit
= machine
->Samplers
[inst
->TexSrcUnit
];
313 /* Note: we only have the right derivatives for fragment input attribs.
315 if (machine
->NumDeriv
> 0 &&
316 inst
->SrcReg
[0].File
== PROGRAM_INPUT
&&
317 inst
->SrcReg
[0].Index
== VARYING_SLOT_TEX0
+ inst
->TexSrcUnit
) {
318 /* simple texture fetch for which we should have derivatives */
319 GLuint attr
= inst
->SrcReg
[0].Index
;
320 machine
->FetchTexelDeriv(ctx
, texcoord
,
321 machine
->DerivX
[attr
],
322 machine
->DerivY
[attr
],
323 lodBias
, unit
, color
);
326 machine
->FetchTexelLod(ctx
, texcoord
, lodBias
, unit
, color
);
332 * Test value against zero and return GT, LT, EQ or UN if NaN.
335 generate_cc(float value
)
338 return COND_UN
; /* NaN */
348 * Test if the ccMaskRule is satisfied by the given condition code.
349 * Used to mask destination writes according to the current condition code.
351 static inline GLboolean
352 test_cc(GLuint condCode
, GLuint ccMaskRule
)
354 switch (ccMaskRule
) {
355 case COND_EQ
: return (condCode
== COND_EQ
);
356 case COND_NE
: return (condCode
!= COND_EQ
);
357 case COND_LT
: return (condCode
== COND_LT
);
358 case COND_GE
: return (condCode
== COND_GT
|| condCode
== COND_EQ
);
359 case COND_LE
: return (condCode
== COND_LT
|| condCode
== COND_EQ
);
360 case COND_GT
: return (condCode
== COND_GT
);
361 case COND_TR
: return GL_TRUE
;
362 case COND_FL
: return GL_FALSE
;
363 default: return GL_TRUE
;
369 * Evaluate the 4 condition codes against a predicate and return GL_TRUE
370 * or GL_FALSE to indicate result.
372 static inline GLboolean
373 eval_condition(const struct gl_program_machine
*machine
,
374 const struct prog_instruction
*inst
)
376 const GLuint swizzle
= inst
->DstReg
.CondSwizzle
;
377 const GLuint condMask
= inst
->DstReg
.CondMask
;
378 if (test_cc(machine
->CondCodes
[GET_SWZ(swizzle
, 0)], condMask
) ||
379 test_cc(machine
->CondCodes
[GET_SWZ(swizzle
, 1)], condMask
) ||
380 test_cc(machine
->CondCodes
[GET_SWZ(swizzle
, 2)], condMask
) ||
381 test_cc(machine
->CondCodes
[GET_SWZ(swizzle
, 3)], condMask
)) {
392 * Store 4 floats into a register. Observe the instructions saturate and
393 * set-condition-code flags.
396 store_vector4(const struct prog_instruction
*inst
,
397 struct gl_program_machine
*machine
, const GLfloat value
[4])
399 const struct prog_dst_register
*dstReg
= &(inst
->DstReg
);
400 const GLboolean clamp
= inst
->SaturateMode
== SATURATE_ZERO_ONE
;
401 GLuint writeMask
= dstReg
->WriteMask
;
402 GLfloat clampedValue
[4];
403 GLfloat
*dst
= get_dst_register_pointer(dstReg
, machine
);
406 if (value
[0] > 1.0e10
||
407 IS_INF_OR_NAN(value
[0]) ||
408 IS_INF_OR_NAN(value
[1]) ||
409 IS_INF_OR_NAN(value
[2]) || IS_INF_OR_NAN(value
[3]))
410 printf("store %g %g %g %g\n", value
[0], value
[1], value
[2], value
[3]);
414 clampedValue
[0] = CLAMP(value
[0], 0.0F
, 1.0F
);
415 clampedValue
[1] = CLAMP(value
[1], 0.0F
, 1.0F
);
416 clampedValue
[2] = CLAMP(value
[2], 0.0F
, 1.0F
);
417 clampedValue
[3] = CLAMP(value
[3], 0.0F
, 1.0F
);
418 value
= clampedValue
;
421 if (dstReg
->CondMask
!= COND_TR
) {
422 /* condition codes may turn off some writes */
423 if (writeMask
& WRITEMASK_X
) {
424 if (!test_cc(machine
->CondCodes
[GET_SWZ(dstReg
->CondSwizzle
, 0)],
426 writeMask
&= ~WRITEMASK_X
;
428 if (writeMask
& WRITEMASK_Y
) {
429 if (!test_cc(machine
->CondCodes
[GET_SWZ(dstReg
->CondSwizzle
, 1)],
431 writeMask
&= ~WRITEMASK_Y
;
433 if (writeMask
& WRITEMASK_Z
) {
434 if (!test_cc(machine
->CondCodes
[GET_SWZ(dstReg
->CondSwizzle
, 2)],
436 writeMask
&= ~WRITEMASK_Z
;
438 if (writeMask
& WRITEMASK_W
) {
439 if (!test_cc(machine
->CondCodes
[GET_SWZ(dstReg
->CondSwizzle
, 3)],
441 writeMask
&= ~WRITEMASK_W
;
446 assert(!IS_INF_OR_NAN(value
[0]));
447 assert(!IS_INF_OR_NAN(value
[0]));
448 assert(!IS_INF_OR_NAN(value
[0]));
449 assert(!IS_INF_OR_NAN(value
[0]));
452 if (writeMask
& WRITEMASK_X
)
454 if (writeMask
& WRITEMASK_Y
)
456 if (writeMask
& WRITEMASK_Z
)
458 if (writeMask
& WRITEMASK_W
)
461 if (inst
->CondUpdate
) {
462 if (writeMask
& WRITEMASK_X
)
463 machine
->CondCodes
[0] = generate_cc(value
[0]);
464 if (writeMask
& WRITEMASK_Y
)
465 machine
->CondCodes
[1] = generate_cc(value
[1]);
466 if (writeMask
& WRITEMASK_Z
)
467 machine
->CondCodes
[2] = generate_cc(value
[2]);
468 if (writeMask
& WRITEMASK_W
)
469 machine
->CondCodes
[3] = generate_cc(value
[3]);
471 printf("CondCodes=(%s,%s,%s,%s) for:\n",
472 _mesa_condcode_string(machine
->CondCodes
[0]),
473 _mesa_condcode_string(machine
->CondCodes
[1]),
474 _mesa_condcode_string(machine
->CondCodes
[2]),
475 _mesa_condcode_string(machine
->CondCodes
[3]));
482 * Execute the given vertex/fragment program.
484 * \param ctx rendering context
485 * \param program the program to execute
486 * \param machine machine state (must be initialized)
487 * \return GL_TRUE if program completed or GL_FALSE if program executed KIL.
490 _mesa_execute_program(struct gl_context
* ctx
,
491 const struct gl_program
*program
,
492 struct gl_program_machine
*machine
)
494 const GLuint numInst
= program
->NumInstructions
;
495 const GLuint maxExec
= 65536;
496 GLuint pc
, numExec
= 0;
498 machine
->CurProgram
= program
;
501 printf("execute program %u --------------------\n", program
->Id
);
504 if (program
->Target
== GL_VERTEX_PROGRAM_ARB
) {
505 machine
->EnvParams
= ctx
->VertexProgram
.Parameters
;
508 machine
->EnvParams
= ctx
->FragmentProgram
.Parameters
;
511 for (pc
= 0; pc
< numInst
; pc
++) {
512 const struct prog_instruction
*inst
= program
->Instructions
+ pc
;
515 _mesa_print_instruction(inst
);
518 switch (inst
->Opcode
) {
521 GLfloat a
[4], result
[4];
522 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
523 result
[0] = FABSF(a
[0]);
524 result
[1] = FABSF(a
[1]);
525 result
[2] = FABSF(a
[2]);
526 result
[3] = FABSF(a
[3]);
527 store_vector4(inst
, machine
, result
);
532 GLfloat a
[4], b
[4], result
[4];
533 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
534 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
535 result
[0] = a
[0] + b
[0];
536 result
[1] = a
[1] + b
[1];
537 result
[2] = a
[2] + b
[2];
538 result
[3] = a
[3] + b
[3];
539 store_vector4(inst
, machine
, result
);
541 printf("ADD (%g %g %g %g) = (%g %g %g %g) + (%g %g %g %g)\n",
542 result
[0], result
[1], result
[2], result
[3],
543 a
[0], a
[1], a
[2], a
[3], b
[0], b
[1], b
[2], b
[3]);
550 fetch_vector4(&inst
->SrcReg
[0], machine
, t
);
551 machine
->AddressReg
[0][0] = IFLOOR(t
[0]);
553 printf("ARL %d\n", machine
->AddressReg
[0][0]);
559 assert(program
->Instructions
[inst
->BranchTarget
].Opcode
563 /* subtract 1 here since pc is incremented by for(pc) loop */
564 assert(program
->Instructions
[inst
->BranchTarget
].Opcode
566 pc
= inst
->BranchTarget
- 1; /* go to matching BNGLOOP */
568 case OPCODE_BGNSUB
: /* begin subroutine */
570 case OPCODE_ENDSUB
: /* end subroutine */
572 case OPCODE_BRK
: /* break out of loop (conditional) */
573 assert(program
->Instructions
[inst
->BranchTarget
].Opcode
575 if (eval_condition(machine
, inst
)) {
576 /* break out of loop */
577 /* pc++ at end of for-loop will put us after the ENDLOOP inst */
578 pc
= inst
->BranchTarget
;
581 case OPCODE_CONT
: /* continue loop (conditional) */
582 assert(program
->Instructions
[inst
->BranchTarget
].Opcode
584 if (eval_condition(machine
, inst
)) {
585 /* continue at ENDLOOP */
586 /* Subtract 1 here since we'll do pc++ at end of for-loop */
587 pc
= inst
->BranchTarget
- 1;
590 case OPCODE_CAL
: /* Call subroutine (conditional) */
591 if (eval_condition(machine
, inst
)) {
592 /* call the subroutine */
593 if (machine
->StackDepth
>= MAX_PROGRAM_CALL_DEPTH
) {
594 return GL_TRUE
; /* Per GL_NV_vertex_program2 spec */
596 machine
->CallStack
[machine
->StackDepth
++] = pc
+ 1; /* next inst */
597 /* Subtract 1 here since we'll do pc++ at end of for-loop */
598 pc
= inst
->BranchTarget
- 1;
603 GLfloat a
[4], b
[4], c
[4], result
[4];
604 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
605 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
606 fetch_vector4(&inst
->SrcReg
[2], machine
, c
);
607 result
[0] = a
[0] < 0.0F
? b
[0] : c
[0];
608 result
[1] = a
[1] < 0.0F
? b
[1] : c
[1];
609 result
[2] = a
[2] < 0.0F
? b
[2] : c
[2];
610 result
[3] = a
[3] < 0.0F
? b
[3] : c
[3];
611 store_vector4(inst
, machine
, result
);
613 printf("CMP (%g %g %g %g) = (%g %g %g %g) < 0 ? (%g %g %g %g) : (%g %g %g %g)\n",
614 result
[0], result
[1], result
[2], result
[3],
615 a
[0], a
[1], a
[2], a
[3],
616 b
[0], b
[1], b
[2], b
[3],
617 c
[0], c
[1], c
[2], c
[3]);
623 GLfloat a
[4], result
[4];
624 fetch_vector1(&inst
->SrcReg
[0], machine
, a
);
625 result
[0] = result
[1] = result
[2] = result
[3]
626 = (GLfloat
) cos(a
[0]);
627 store_vector4(inst
, machine
, result
);
630 case OPCODE_DDX
: /* Partial derivative with respect to X */
633 fetch_vector4_deriv(ctx
, &inst
->SrcReg
[0], machine
,
635 store_vector4(inst
, machine
, result
);
638 case OPCODE_DDY
: /* Partial derivative with respect to Y */
641 fetch_vector4_deriv(ctx
, &inst
->SrcReg
[0], machine
,
643 store_vector4(inst
, machine
, result
);
648 GLfloat a
[4], b
[4], result
[4];
649 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
650 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
651 result
[0] = result
[1] = result
[2] = result
[3] = DOT2(a
, b
);
652 store_vector4(inst
, machine
, result
);
654 printf("DP2 %g = (%g %g) . (%g %g)\n",
655 result
[0], a
[0], a
[1], b
[0], b
[1]);
661 GLfloat a
[4], b
[4], result
[4];
662 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
663 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
664 result
[0] = result
[1] = result
[2] = result
[3] = DOT3(a
, b
);
665 store_vector4(inst
, machine
, result
);
667 printf("DP3 %g = (%g %g %g) . (%g %g %g)\n",
668 result
[0], a
[0], a
[1], a
[2], b
[0], b
[1], b
[2]);
674 GLfloat a
[4], b
[4], result
[4];
675 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
676 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
677 result
[0] = result
[1] = result
[2] = result
[3] = DOT4(a
, b
);
678 store_vector4(inst
, machine
, result
);
680 printf("DP4 %g = (%g, %g %g %g) . (%g, %g %g %g)\n",
681 result
[0], a
[0], a
[1], a
[2], a
[3],
682 b
[0], b
[1], b
[2], b
[3]);
688 GLfloat a
[4], b
[4], result
[4];
689 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
690 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
691 result
[0] = result
[1] = result
[2] = result
[3] = DOT3(a
, b
) + b
[3];
692 store_vector4(inst
, machine
, result
);
695 case OPCODE_DST
: /* Distance vector */
697 GLfloat a
[4], b
[4], result
[4];
698 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
699 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
701 result
[1] = a
[1] * b
[1];
704 store_vector4(inst
, machine
, result
);
709 GLfloat t
[4], q
[4], floor_t0
;
710 fetch_vector1(&inst
->SrcReg
[0], machine
, t
);
711 floor_t0
= FLOORF(t
[0]);
712 if (floor_t0
> FLT_MAX_EXP
) {
713 SET_POS_INFINITY(q
[0]);
714 SET_POS_INFINITY(q
[2]);
716 else if (floor_t0
< FLT_MIN_EXP
) {
721 q
[0] = LDEXPF(1.0, (int) floor_t0
);
722 /* Note: GL_NV_vertex_program expects
723 * result.z = result.x * APPX(result.y)
724 * We do what the ARB extension says.
726 q
[2] = (GLfloat
) pow(2.0, t
[0]);
728 q
[1] = t
[0] - floor_t0
;
730 store_vector4( inst
, machine
, q
);
733 case OPCODE_EX2
: /* Exponential base 2 */
735 GLfloat a
[4], result
[4], val
;
736 fetch_vector1(&inst
->SrcReg
[0], machine
, a
);
737 val
= (GLfloat
) pow(2.0, a
[0]);
739 if (IS_INF_OR_NAN(val))
742 result
[0] = result
[1] = result
[2] = result
[3] = val
;
743 store_vector4(inst
, machine
, result
);
748 GLfloat a
[4], result
[4];
749 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
750 result
[0] = FLOORF(a
[0]);
751 result
[1] = FLOORF(a
[1]);
752 result
[2] = FLOORF(a
[2]);
753 result
[3] = FLOORF(a
[3]);
754 store_vector4(inst
, machine
, result
);
759 GLfloat a
[4], result
[4];
760 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
761 result
[0] = a
[0] - FLOORF(a
[0]);
762 result
[1] = a
[1] - FLOORF(a
[1]);
763 result
[2] = a
[2] - FLOORF(a
[2]);
764 result
[3] = a
[3] - FLOORF(a
[3]);
765 store_vector4(inst
, machine
, result
);
771 assert(program
->Instructions
[inst
->BranchTarget
].Opcode
773 program
->Instructions
[inst
->BranchTarget
].Opcode
776 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
778 fetch_vector1(&inst
->SrcReg
[0], machine
, a
);
779 cond
= (a
[0] != 0.0);
782 cond
= eval_condition(machine
, inst
);
785 printf("IF: %d\n", cond
);
789 /* do if-clause (just continue execution) */
792 /* go to the instruction after ELSE or ENDIF */
793 assert(inst
->BranchTarget
>= 0);
794 pc
= inst
->BranchTarget
;
800 assert(program
->Instructions
[inst
->BranchTarget
].Opcode
802 assert(inst
->BranchTarget
>= 0);
803 pc
= inst
->BranchTarget
;
808 case OPCODE_KIL_NV
: /* NV_f_p only (conditional) */
809 if (eval_condition(machine
, inst
)) {
813 case OPCODE_KIL
: /* ARB_f_p only */
816 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
818 printf("KIL if (%g %g %g %g) <= 0.0\n",
819 a
[0], a
[1], a
[2], a
[3]);
822 if (a
[0] < 0.0F
|| a
[1] < 0.0F
|| a
[2] < 0.0F
|| a
[3] < 0.0F
) {
827 case OPCODE_LG2
: /* log base 2 */
829 GLfloat a
[4], result
[4], val
;
830 fetch_vector1(&inst
->SrcReg
[0], machine
, a
);
831 /* The fast LOG2 macro doesn't meet the precision requirements.
837 val
= (float)(log(a
[0]) * 1.442695F
);
839 result
[0] = result
[1] = result
[2] = result
[3] = val
;
840 store_vector4(inst
, machine
, result
);
845 const GLfloat epsilon
= 1.0F
/ 256.0F
; /* from NV VP spec */
846 GLfloat a
[4], result
[4];
847 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
848 a
[0] = MAX2(a
[0], 0.0F
);
849 a
[1] = MAX2(a
[1], 0.0F
);
850 /* XXX ARB version clamps a[3], NV version doesn't */
851 a
[3] = CLAMP(a
[3], -(128.0F
- epsilon
), (128.0F
- epsilon
));
854 /* XXX we could probably just use pow() here */
856 if (a
[1] == 0.0 && a
[3] == 0.0)
859 result
[2] = (GLfloat
) pow(a
[1], a
[3]);
865 store_vector4(inst
, machine
, result
);
867 printf("LIT (%g %g %g %g) : (%g %g %g %g)\n",
868 result
[0], result
[1], result
[2], result
[3],
869 a
[0], a
[1], a
[2], a
[3]);
875 GLfloat t
[4], q
[4], abs_t0
;
876 fetch_vector1(&inst
->SrcReg
[0], machine
, t
);
877 abs_t0
= FABSF(t
[0]);
878 if (abs_t0
!= 0.0F
) {
879 if (IS_INF_OR_NAN(abs_t0
))
881 SET_POS_INFINITY(q
[0]);
883 SET_POS_INFINITY(q
[2]);
887 GLfloat mantissa
= FREXPF(t
[0], &exponent
);
888 q
[0] = (GLfloat
) (exponent
- 1);
889 q
[1] = (GLfloat
) (2.0 * mantissa
); /* map [.5, 1) -> [1, 2) */
891 /* The fast LOG2 macro doesn't meet the precision
894 q
[2] = (float)(log(t
[0]) * 1.442695F
);
898 SET_NEG_INFINITY(q
[0]);
900 SET_NEG_INFINITY(q
[2]);
903 store_vector4(inst
, machine
, q
);
908 GLfloat a
[4], b
[4], c
[4], result
[4];
909 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
910 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
911 fetch_vector4(&inst
->SrcReg
[2], machine
, c
);
912 result
[0] = a
[0] * b
[0] + (1.0F
- a
[0]) * c
[0];
913 result
[1] = a
[1] * b
[1] + (1.0F
- a
[1]) * c
[1];
914 result
[2] = a
[2] * b
[2] + (1.0F
- a
[2]) * c
[2];
915 result
[3] = a
[3] * b
[3] + (1.0F
- a
[3]) * c
[3];
916 store_vector4(inst
, machine
, result
);
918 printf("LRP (%g %g %g %g) = (%g %g %g %g), "
919 "(%g %g %g %g), (%g %g %g %g)\n",
920 result
[0], result
[1], result
[2], result
[3],
921 a
[0], a
[1], a
[2], a
[3],
922 b
[0], b
[1], b
[2], b
[3], c
[0], c
[1], c
[2], c
[3]);
928 GLfloat a
[4], b
[4], c
[4], result
[4];
929 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
930 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
931 fetch_vector4(&inst
->SrcReg
[2], machine
, c
);
932 result
[0] = a
[0] * b
[0] + c
[0];
933 result
[1] = a
[1] * b
[1] + c
[1];
934 result
[2] = a
[2] * b
[2] + c
[2];
935 result
[3] = a
[3] * b
[3] + c
[3];
936 store_vector4(inst
, machine
, result
);
938 printf("MAD (%g %g %g %g) = (%g %g %g %g) * "
939 "(%g %g %g %g) + (%g %g %g %g)\n",
940 result
[0], result
[1], result
[2], result
[3],
941 a
[0], a
[1], a
[2], a
[3],
942 b
[0], b
[1], b
[2], b
[3], c
[0], c
[1], c
[2], c
[3]);
948 GLfloat a
[4], b
[4], result
[4];
949 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
950 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
951 result
[0] = MAX2(a
[0], b
[0]);
952 result
[1] = MAX2(a
[1], b
[1]);
953 result
[2] = MAX2(a
[2], b
[2]);
954 result
[3] = MAX2(a
[3], b
[3]);
955 store_vector4(inst
, machine
, result
);
957 printf("MAX (%g %g %g %g) = (%g %g %g %g), (%g %g %g %g)\n",
958 result
[0], result
[1], result
[2], result
[3],
959 a
[0], a
[1], a
[2], a
[3], b
[0], b
[1], b
[2], b
[3]);
965 GLfloat a
[4], b
[4], result
[4];
966 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
967 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
968 result
[0] = MIN2(a
[0], b
[0]);
969 result
[1] = MIN2(a
[1], b
[1]);
970 result
[2] = MIN2(a
[2], b
[2]);
971 result
[3] = MIN2(a
[3], b
[3]);
972 store_vector4(inst
, machine
, result
);
978 fetch_vector4(&inst
->SrcReg
[0], machine
, result
);
979 store_vector4(inst
, machine
, result
);
981 printf("MOV (%g %g %g %g)\n",
982 result
[0], result
[1], result
[2], result
[3]);
988 GLfloat a
[4], b
[4], result
[4];
989 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
990 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
991 result
[0] = a
[0] * b
[0];
992 result
[1] = a
[1] * b
[1];
993 result
[2] = a
[2] * b
[2];
994 result
[3] = a
[3] * b
[3];
995 store_vector4(inst
, machine
, result
);
997 printf("MUL (%g %g %g %g) = (%g %g %g %g) * (%g %g %g %g)\n",
998 result
[0], result
[1], result
[2], result
[3],
999 a
[0], a
[1], a
[2], a
[3], b
[0], b
[1], b
[2], b
[3]);
1005 GLfloat a
[4], result
[4];
1006 fetch_vector1(&inst
->SrcReg
[0], machine
, a
);
1010 result
[3] = _mesa_noise1(a
[0]);
1011 store_vector4(inst
, machine
, result
);
1016 GLfloat a
[4], result
[4];
1017 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
1020 result
[2] = result
[3] = _mesa_noise2(a
[0], a
[1]);
1021 store_vector4(inst
, machine
, result
);
1026 GLfloat a
[4], result
[4];
1027 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
1031 result
[3] = _mesa_noise3(a
[0], a
[1], a
[2]);
1032 store_vector4(inst
, machine
, result
);
1037 GLfloat a
[4], result
[4];
1038 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
1042 result
[3] = _mesa_noise4(a
[0], a
[1], a
[2], a
[3]);
1043 store_vector4(inst
, machine
, result
);
1050 GLfloat a
[4], b
[4], result
[4];
1051 fetch_vector1(&inst
->SrcReg
[0], machine
, a
);
1052 fetch_vector1(&inst
->SrcReg
[1], machine
, b
);
1053 result
[0] = result
[1] = result
[2] = result
[3]
1054 = (GLfloat
) pow(a
[0], b
[0]);
1055 store_vector4(inst
, machine
, result
);
1061 GLfloat a
[4], result
[4];
1062 fetch_vector1(&inst
->SrcReg
[0], machine
, a
);
1066 else if (IS_INF_OR_NAN(a
[0]))
1067 printf("RCP(inf)\n");
1069 result
[0] = result
[1] = result
[2] = result
[3] = 1.0F
/ a
[0];
1070 store_vector4(inst
, machine
, result
);
1073 case OPCODE_RET
: /* return from subroutine (conditional) */
1074 if (eval_condition(machine
, inst
)) {
1075 if (machine
->StackDepth
== 0) {
1076 return GL_TRUE
; /* Per GL_NV_vertex_program2 spec */
1078 /* subtract one because of pc++ in the for loop */
1079 pc
= machine
->CallStack
[--machine
->StackDepth
] - 1;
1082 case OPCODE_RSQ
: /* 1 / sqrt() */
1084 GLfloat a
[4], result
[4];
1085 fetch_vector1(&inst
->SrcReg
[0], machine
, a
);
1087 result
[0] = result
[1] = result
[2] = result
[3] = INV_SQRTF(a
[0]);
1088 store_vector4(inst
, machine
, result
);
1090 printf("RSQ %g = 1/sqrt(|%g|)\n", result
[0], a
[0]);
1094 case OPCODE_SCS
: /* sine and cos */
1096 GLfloat a
[4], result
[4];
1097 fetch_vector1(&inst
->SrcReg
[0], machine
, a
);
1098 result
[0] = (GLfloat
) cos(a
[0]);
1099 result
[1] = (GLfloat
) sin(a
[0]);
1100 result
[2] = 0.0; /* undefined! */
1101 result
[3] = 0.0; /* undefined! */
1102 store_vector4(inst
, machine
, result
);
1105 case OPCODE_SEQ
: /* set on equal */
1107 GLfloat a
[4], b
[4], result
[4];
1108 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
1109 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
1110 result
[0] = (a
[0] == b
[0]) ? 1.0F
: 0.0F
;
1111 result
[1] = (a
[1] == b
[1]) ? 1.0F
: 0.0F
;
1112 result
[2] = (a
[2] == b
[2]) ? 1.0F
: 0.0F
;
1113 result
[3] = (a
[3] == b
[3]) ? 1.0F
: 0.0F
;
1114 store_vector4(inst
, machine
, result
);
1116 printf("SEQ (%g %g %g %g) = (%g %g %g %g) == (%g %g %g %g)\n",
1117 result
[0], result
[1], result
[2], result
[3],
1118 a
[0], a
[1], a
[2], a
[3],
1119 b
[0], b
[1], b
[2], b
[3]);
1123 case OPCODE_SGE
: /* set on greater or equal */
1125 GLfloat a
[4], b
[4], result
[4];
1126 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
1127 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
1128 result
[0] = (a
[0] >= b
[0]) ? 1.0F
: 0.0F
;
1129 result
[1] = (a
[1] >= b
[1]) ? 1.0F
: 0.0F
;
1130 result
[2] = (a
[2] >= b
[2]) ? 1.0F
: 0.0F
;
1131 result
[3] = (a
[3] >= b
[3]) ? 1.0F
: 0.0F
;
1132 store_vector4(inst
, machine
, result
);
1134 printf("SGE (%g %g %g %g) = (%g %g %g %g) >= (%g %g %g %g)\n",
1135 result
[0], result
[1], result
[2], result
[3],
1136 a
[0], a
[1], a
[2], a
[3],
1137 b
[0], b
[1], b
[2], b
[3]);
1141 case OPCODE_SGT
: /* set on greater */
1143 GLfloat a
[4], b
[4], result
[4];
1144 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
1145 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
1146 result
[0] = (a
[0] > b
[0]) ? 1.0F
: 0.0F
;
1147 result
[1] = (a
[1] > b
[1]) ? 1.0F
: 0.0F
;
1148 result
[2] = (a
[2] > b
[2]) ? 1.0F
: 0.0F
;
1149 result
[3] = (a
[3] > b
[3]) ? 1.0F
: 0.0F
;
1150 store_vector4(inst
, machine
, result
);
1152 printf("SGT (%g %g %g %g) = (%g %g %g %g) > (%g %g %g %g)\n",
1153 result
[0], result
[1], result
[2], result
[3],
1154 a
[0], a
[1], a
[2], a
[3],
1155 b
[0], b
[1], b
[2], b
[3]);
1161 GLfloat a
[4], result
[4];
1162 fetch_vector1(&inst
->SrcReg
[0], machine
, a
);
1163 result
[0] = result
[1] = result
[2] = result
[3]
1164 = (GLfloat
) sin(a
[0]);
1165 store_vector4(inst
, machine
, result
);
1168 case OPCODE_SLE
: /* set on less or equal */
1170 GLfloat a
[4], b
[4], result
[4];
1171 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
1172 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
1173 result
[0] = (a
[0] <= b
[0]) ? 1.0F
: 0.0F
;
1174 result
[1] = (a
[1] <= b
[1]) ? 1.0F
: 0.0F
;
1175 result
[2] = (a
[2] <= b
[2]) ? 1.0F
: 0.0F
;
1176 result
[3] = (a
[3] <= b
[3]) ? 1.0F
: 0.0F
;
1177 store_vector4(inst
, machine
, result
);
1179 printf("SLE (%g %g %g %g) = (%g %g %g %g) <= (%g %g %g %g)\n",
1180 result
[0], result
[1], result
[2], result
[3],
1181 a
[0], a
[1], a
[2], a
[3],
1182 b
[0], b
[1], b
[2], b
[3]);
1186 case OPCODE_SLT
: /* set on less */
1188 GLfloat a
[4], b
[4], result
[4];
1189 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
1190 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
1191 result
[0] = (a
[0] < b
[0]) ? 1.0F
: 0.0F
;
1192 result
[1] = (a
[1] < b
[1]) ? 1.0F
: 0.0F
;
1193 result
[2] = (a
[2] < b
[2]) ? 1.0F
: 0.0F
;
1194 result
[3] = (a
[3] < b
[3]) ? 1.0F
: 0.0F
;
1195 store_vector4(inst
, machine
, result
);
1197 printf("SLT (%g %g %g %g) = (%g %g %g %g) < (%g %g %g %g)\n",
1198 result
[0], result
[1], result
[2], result
[3],
1199 a
[0], a
[1], a
[2], a
[3],
1200 b
[0], b
[1], b
[2], b
[3]);
1204 case OPCODE_SNE
: /* set on not equal */
1206 GLfloat a
[4], b
[4], result
[4];
1207 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
1208 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
1209 result
[0] = (a
[0] != b
[0]) ? 1.0F
: 0.0F
;
1210 result
[1] = (a
[1] != b
[1]) ? 1.0F
: 0.0F
;
1211 result
[2] = (a
[2] != b
[2]) ? 1.0F
: 0.0F
;
1212 result
[3] = (a
[3] != b
[3]) ? 1.0F
: 0.0F
;
1213 store_vector4(inst
, machine
, result
);
1215 printf("SNE (%g %g %g %g) = (%g %g %g %g) != (%g %g %g %g)\n",
1216 result
[0], result
[1], result
[2], result
[3],
1217 a
[0], a
[1], a
[2], a
[3],
1218 b
[0], b
[1], b
[2], b
[3]);
1222 case OPCODE_SSG
: /* set sign (-1, 0 or +1) */
1224 GLfloat a
[4], result
[4];
1225 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
1226 result
[0] = (GLfloat
) ((a
[0] > 0.0F
) - (a
[0] < 0.0F
));
1227 result
[1] = (GLfloat
) ((a
[1] > 0.0F
) - (a
[1] < 0.0F
));
1228 result
[2] = (GLfloat
) ((a
[2] > 0.0F
) - (a
[2] < 0.0F
));
1229 result
[3] = (GLfloat
) ((a
[3] > 0.0F
) - (a
[3] < 0.0F
));
1230 store_vector4(inst
, machine
, result
);
1235 GLfloat a
[4], b
[4], result
[4];
1236 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
1237 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
1238 result
[0] = a
[0] - b
[0];
1239 result
[1] = a
[1] - b
[1];
1240 result
[2] = a
[2] - b
[2];
1241 result
[3] = a
[3] - b
[3];
1242 store_vector4(inst
, machine
, result
);
1244 printf("SUB (%g %g %g %g) = (%g %g %g %g) - (%g %g %g %g)\n",
1245 result
[0], result
[1], result
[2], result
[3],
1246 a
[0], a
[1], a
[2], a
[3], b
[0], b
[1], b
[2], b
[3]);
1250 case OPCODE_SWZ
: /* extended swizzle */
1252 const struct prog_src_register
*source
= &inst
->SrcReg
[0];
1253 const GLfloat
*src
= get_src_register_pointer(source
, machine
);
1256 for (i
= 0; i
< 4; i
++) {
1257 const GLuint swz
= GET_SWZ(source
->Swizzle
, i
);
1258 if (swz
== SWIZZLE_ZERO
)
1260 else if (swz
== SWIZZLE_ONE
)
1264 result
[i
] = src
[swz
];
1266 if (source
->Negate
& (1 << i
))
1267 result
[i
] = -result
[i
];
1269 store_vector4(inst
, machine
, result
);
1272 case OPCODE_TEX
: /* Both ARB and NV frag prog */
1273 /* Simple texel lookup */
1275 GLfloat texcoord
[4], color
[4];
1276 fetch_vector4(&inst
->SrcReg
[0], machine
, texcoord
);
1278 /* For TEX, texcoord.Q should not be used and its value should not
1279 * matter (at most, we pass coord.xyz to texture3D() in GLSL).
1280 * Set Q=1 so that FetchTexelDeriv() doesn't get a garbage value
1281 * which is effectively what happens when the texcoord swizzle
1286 fetch_texel(ctx
, machine
, inst
, texcoord
, 0.0, color
);
1289 printf("TEX (%g, %g, %g, %g) = texture[%d][%g, %g, %g, %g]\n",
1290 color
[0], color
[1], color
[2], color
[3],
1292 texcoord
[0], texcoord
[1], texcoord
[2], texcoord
[3]);
1294 store_vector4(inst
, machine
, color
);
1297 case OPCODE_TXB
: /* GL_ARB_fragment_program only */
1298 /* Texel lookup with LOD bias */
1300 GLfloat texcoord
[4], color
[4], lodBias
;
1302 fetch_vector4(&inst
->SrcReg
[0], machine
, texcoord
);
1304 /* texcoord[3] is the bias to add to lambda */
1305 lodBias
= texcoord
[3];
1307 fetch_texel(ctx
, machine
, inst
, texcoord
, lodBias
, color
);
1310 printf("TXB (%g, %g, %g, %g) = texture[%d][%g %g %g %g]"
1312 color
[0], color
[1], color
[2], color
[3],
1321 store_vector4(inst
, machine
, color
);
1324 case OPCODE_TXD
: /* GL_NV_fragment_program only */
1325 /* Texture lookup w/ partial derivatives for LOD */
1327 GLfloat texcoord
[4], dtdx
[4], dtdy
[4], color
[4];
1328 fetch_vector4(&inst
->SrcReg
[0], machine
, texcoord
);
1329 fetch_vector4(&inst
->SrcReg
[1], machine
, dtdx
);
1330 fetch_vector4(&inst
->SrcReg
[2], machine
, dtdy
);
1331 machine
->FetchTexelDeriv(ctx
, texcoord
, dtdx
, dtdy
,
1333 inst
->TexSrcUnit
, color
);
1334 store_vector4(inst
, machine
, color
);
1338 /* Texel lookup with explicit LOD */
1340 GLfloat texcoord
[4], color
[4], lod
;
1342 fetch_vector4(&inst
->SrcReg
[0], machine
, texcoord
);
1344 /* texcoord[3] is the LOD */
1347 machine
->FetchTexelLod(ctx
, texcoord
, lod
,
1348 machine
->Samplers
[inst
->TexSrcUnit
], color
);
1350 store_vector4(inst
, machine
, color
);
1353 case OPCODE_TXP
: /* GL_ARB_fragment_program only */
1354 /* Texture lookup w/ projective divide */
1356 GLfloat texcoord
[4], color
[4];
1358 fetch_vector4(&inst
->SrcReg
[0], machine
, texcoord
);
1359 /* Not so sure about this test - if texcoord[3] is
1360 * zero, we'd probably be fine except for an assert in
1361 * IROUND_POS() which gets triggered by the inf values created.
1363 if (texcoord
[3] != 0.0) {
1364 texcoord
[0] /= texcoord
[3];
1365 texcoord
[1] /= texcoord
[3];
1366 texcoord
[2] /= texcoord
[3];
1369 fetch_texel(ctx
, machine
, inst
, texcoord
, 0.0, color
);
1371 store_vector4(inst
, machine
, color
);
1374 case OPCODE_TXP_NV
: /* GL_NV_fragment_program only */
1375 /* Texture lookup w/ projective divide, as above, but do not
1376 * do the divide by w if sampling from a cube map.
1379 GLfloat texcoord
[4], color
[4];
1381 fetch_vector4(&inst
->SrcReg
[0], machine
, texcoord
);
1382 if (inst
->TexSrcTarget
!= TEXTURE_CUBE_INDEX
&&
1383 texcoord
[3] != 0.0) {
1384 texcoord
[0] /= texcoord
[3];
1385 texcoord
[1] /= texcoord
[3];
1386 texcoord
[2] /= texcoord
[3];
1389 fetch_texel(ctx
, machine
, inst
, texcoord
, 0.0, color
);
1391 store_vector4(inst
, machine
, color
);
1394 case OPCODE_TRUNC
: /* truncate toward zero */
1396 GLfloat a
[4], result
[4];
1397 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
1398 result
[0] = (GLfloat
) (GLint
) a
[0];
1399 result
[1] = (GLfloat
) (GLint
) a
[1];
1400 result
[2] = (GLfloat
) (GLint
) a
[2];
1401 result
[3] = (GLfloat
) (GLint
) a
[3];
1402 store_vector4(inst
, machine
, result
);
1405 case OPCODE_XPD
: /* cross product */
1407 GLfloat a
[4], b
[4], result
[4];
1408 fetch_vector4(&inst
->SrcReg
[0], machine
, a
);
1409 fetch_vector4(&inst
->SrcReg
[1], machine
, b
);
1410 result
[0] = a
[1] * b
[2] - a
[2] * b
[1];
1411 result
[1] = a
[2] * b
[0] - a
[0] * b
[2];
1412 result
[2] = a
[0] * b
[1] - a
[1] * b
[0];
1414 store_vector4(inst
, machine
, result
);
1416 printf("XPD (%g %g %g %g) = (%g %g %g) X (%g %g %g)\n",
1417 result
[0], result
[1], result
[2], result
[3],
1418 a
[0], a
[1], a
[2], b
[0], b
[1], b
[2]);
1425 _mesa_problem(ctx
, "Bad opcode %d in _mesa_execute_program",
1427 return GL_TRUE
; /* return value doesn't matter */
1431 if (numExec
> maxExec
) {
1432 static GLboolean reported
= GL_FALSE
;
1434 _mesa_problem(ctx
, "Infinite loop detected in fragment program");