blob: aea4b074b3926ffdd029df0d3a45071031a72577 [file] [log] [blame]
Brian13e3b212007-02-22 16:09:40 -07001/*
2 * Mesa 3-D graphics library
Brian Paulf4361542008-11-11 10:47:10 -07003 * Version: 7.3
Brian13e3b212007-02-22 16:09:40 -07004 *
Brian Paulf4361542008-11-11 10:47:10 -07005 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
Brian13e3b212007-02-22 16:09:40 -07006 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25/**
26 * \file prog_execute.c
27 * Software interpreter for vertex/fragment programs.
28 * \author Brian Paul
29 */
30
31/*
32 * NOTE: we do everything in single-precision floating point; we don't
33 * currently observe the single/half/fixed-precision qualifiers.
34 *
35 */
36
37
Brian Paulbbd28712008-09-18 12:26:54 -060038#include "main/glheader.h"
39#include "main/colormac.h"
40#include "main/context.h"
Brian13e3b212007-02-22 16:09:40 -070041#include "prog_execute.h"
42#include "prog_instruction.h"
43#include "prog_parameter.h"
44#include "prog_print.h"
Brian Paul702b5b02008-12-15 18:37:39 -070045#include "prog_noise.h"
Brian13e3b212007-02-22 16:09:40 -070046
47
Brian13e3b212007-02-22 16:09:40 -070048/* debug predicate */
49#define DEBUG_PROG 0
50
51
Brianf183a2d2007-02-23 17:14:30 -070052/**
53 * Set x to positive or negative infinity.
54 */
55#if defined(USE_IEEE) || defined(_WIN32)
Roland Scheidegger72362a52009-12-07 21:47:49 +010056#define SET_POS_INFINITY(x) \
57 do { \
58 fi_type fi; \
59 fi.i = 0x7F800000; \
60 x = fi.f; \
61 } while (0)
62#define SET_NEG_INFINITY(x) \
63 do { \
64 fi_type fi; \
65 fi.i = 0xFF800000; \
66 x = fi.f; \
67 } while (0)
Brianf183a2d2007-02-23 17:14:30 -070068#elif defined(VMS)
69#define SET_POS_INFINITY(x) x = __MAXFLOAT
70#define SET_NEG_INFINITY(x) x = -__MAXFLOAT
71#else
72#define SET_POS_INFINITY(x) x = (GLfloat) HUGE_VAL
73#define SET_NEG_INFINITY(x) x = (GLfloat) -HUGE_VAL
74#endif
75
76#define SET_FLOAT_BITS(x, bits) ((fi_type *) (void *) &(x))->i = bits
77
78
79static const GLfloat ZeroVec[4] = { 0.0F, 0.0F, 0.0F, 0.0F };
80
81
82
Brian13e3b212007-02-22 16:09:40 -070083/**
84 * Return a pointer to the 4-element float vector specified by the given
85 * source register.
86 */
87static INLINE const GLfloat *
Brian Paulf4361542008-11-11 10:47:10 -070088get_src_register_pointer(const struct prog_src_register *source,
89 const struct gl_program_machine *machine)
Brian13e3b212007-02-22 16:09:40 -070090{
Brian Paulf4361542008-11-11 10:47:10 -070091 const struct gl_program *prog = machine->CurProgram;
92 GLint reg = source->Index;
93
Brianf183a2d2007-02-23 17:14:30 -070094 if (source->RelAddr) {
Brian Paulf4361542008-11-11 10:47:10 -070095 /* add address register value to src index/offset */
96 reg += machine->AddressReg[0][0];
97 if (reg < 0) {
98 return ZeroVec;
Brianf183a2d2007-02-23 17:14:30 -070099 }
100 }
101
Brian13e3b212007-02-22 16:09:40 -0700102 switch (source->File) {
103 case PROGRAM_TEMPORARY:
Brian Paulf4361542008-11-11 10:47:10 -0700104 if (reg >= MAX_PROGRAM_TEMPS)
105 return ZeroVec;
106 return machine->Temporaries[reg];
Brian13e3b212007-02-22 16:09:40 -0700107
108 case PROGRAM_INPUT:
Brian Paulf4361542008-11-11 10:47:10 -0700109 if (prog->Target == GL_VERTEX_PROGRAM_ARB) {
110 if (reg >= VERT_ATTRIB_MAX)
111 return ZeroVec;
112 return machine->VertAttribs[reg];
Brian13e3b212007-02-22 16:09:40 -0700113 }
114 else {
Brian Paulf4361542008-11-11 10:47:10 -0700115 if (reg >= FRAG_ATTRIB_MAX)
116 return ZeroVec;
117 return machine->Attribs[reg][machine->CurElement];
Brian13e3b212007-02-22 16:09:40 -0700118 }
119
120 case PROGRAM_OUTPUT:
Brian Paulf4361542008-11-11 10:47:10 -0700121 if (reg >= MAX_PROGRAM_OUTPUTS)
122 return ZeroVec;
123 return machine->Outputs[reg];
Brian13e3b212007-02-22 16:09:40 -0700124
125 case PROGRAM_LOCAL_PARAM:
Brian Paulf4361542008-11-11 10:47:10 -0700126 if (reg >= MAX_PROGRAM_LOCAL_PARAMS)
127 return ZeroVec;
128 return machine->CurProgram->LocalParams[reg];
Brian13e3b212007-02-22 16:09:40 -0700129
130 case PROGRAM_ENV_PARAM:
Brian Paulf4361542008-11-11 10:47:10 -0700131 if (reg >= MAX_PROGRAM_ENV_PARAMS)
132 return ZeroVec;
133 return machine->EnvParams[reg];
Brian13e3b212007-02-22 16:09:40 -0700134
135 case PROGRAM_STATE_VAR:
136 /* Fallthrough */
137 case PROGRAM_CONSTANT:
138 /* Fallthrough */
139 case PROGRAM_UNIFORM:
140 /* Fallthrough */
141 case PROGRAM_NAMED_PARAM:
Brian Paulf4361542008-11-11 10:47:10 -0700142 if (reg >= (GLint) prog->Parameters->NumParameters)
143 return ZeroVec;
144 return prog->Parameters->ParameterValues[reg];
Brian13e3b212007-02-22 16:09:40 -0700145
146 default:
Brian33eac562007-02-25 18:52:41 -0700147 _mesa_problem(NULL,
Brian Paulf4361542008-11-11 10:47:10 -0700148 "Invalid src register file %d in get_src_register_pointer()",
149 source->File);
Brian13e3b212007-02-22 16:09:40 -0700150 return NULL;
151 }
152}
153
154
Brian Paulf4361542008-11-11 10:47:10 -0700155/**
156 * Return a pointer to the 4-element float vector specified by the given
157 * destination register.
158 */
159static INLINE GLfloat *
160get_dst_register_pointer(const struct prog_dst_register *dest,
161 struct gl_program_machine *machine)
162{
163 static GLfloat dummyReg[4];
164 GLint reg = dest->Index;
165
166 if (dest->RelAddr) {
167 /* add address register value to src index/offset */
168 reg += machine->AddressReg[0][0];
169 if (reg < 0) {
170 return dummyReg;
171 }
172 }
173
174 switch (dest->File) {
175 case PROGRAM_TEMPORARY:
176 if (reg >= MAX_PROGRAM_TEMPS)
177 return dummyReg;
178 return machine->Temporaries[reg];
179
180 case PROGRAM_OUTPUT:
181 if (reg >= MAX_PROGRAM_OUTPUTS)
182 return dummyReg;
183 return machine->Outputs[reg];
184
185 case PROGRAM_WRITE_ONLY:
186 return dummyReg;
187
188 default:
189 _mesa_problem(NULL,
190 "Invalid dest register file %d in get_dst_register_pointer()",
191 dest->File);
192 return NULL;
193 }
194}
195
196
197
Brian13e3b212007-02-22 16:09:40 -0700198/**
199 * Fetch a 4-element float vector from the given source register.
200 * Apply swizzling and negating as needed.
201 */
202static void
Brian33eac562007-02-25 18:52:41 -0700203fetch_vector4(const struct prog_src_register *source,
Briane80d9012007-02-23 16:53:24 -0700204 const struct gl_program_machine *machine, GLfloat result[4])
Brian13e3b212007-02-22 16:09:40 -0700205{
Brian Paulf4361542008-11-11 10:47:10 -0700206 const GLfloat *src = get_src_register_pointer(source, machine);
Brian13e3b212007-02-22 16:09:40 -0700207 ASSERT(src);
208
209 if (source->Swizzle == SWIZZLE_NOOP) {
210 /* no swizzling */
211 COPY_4V(result, src);
212 }
213 else {
214 ASSERT(GET_SWZ(source->Swizzle, 0) <= 3);
215 ASSERT(GET_SWZ(source->Swizzle, 1) <= 3);
216 ASSERT(GET_SWZ(source->Swizzle, 2) <= 3);
217 ASSERT(GET_SWZ(source->Swizzle, 3) <= 3);
218 result[0] = src[GET_SWZ(source->Swizzle, 0)];
219 result[1] = src[GET_SWZ(source->Swizzle, 1)];
220 result[2] = src[GET_SWZ(source->Swizzle, 2)];
221 result[3] = src[GET_SWZ(source->Swizzle, 3)];
222 }
223
Brian13e3b212007-02-22 16:09:40 -0700224 if (source->Abs) {
225 result[0] = FABSF(result[0]);
226 result[1] = FABSF(result[1]);
227 result[2] = FABSF(result[2]);
228 result[3] = FABSF(result[3]);
229 }
Brian Paul7db7ff82009-04-14 22:14:30 -0600230 if (source->Negate) {
231 ASSERT(source->Negate == NEGATE_XYZW);
Brian13e3b212007-02-22 16:09:40 -0700232 result[0] = -result[0];
233 result[1] = -result[1];
234 result[2] = -result[2];
235 result[3] = -result[3];
236 }
Brian Paul92009542009-06-03 15:43:53 -0600237
238#ifdef NAN_CHECK
239 assert(!IS_INF_OR_NAN(result[0]));
240 assert(!IS_INF_OR_NAN(result[0]));
241 assert(!IS_INF_OR_NAN(result[0]));
242 assert(!IS_INF_OR_NAN(result[0]));
243#endif
Brian13e3b212007-02-22 16:09:40 -0700244}
245
Brian62da6a12007-05-02 18:44:34 -0600246
Brian13e3b212007-02-22 16:09:40 -0700247/**
Brian Paul37eef7b2008-11-07 09:33:55 -0700248 * Fetch a 4-element uint vector from the given source register.
249 * Apply swizzling but not negation/abs.
250 */
251static void
252fetch_vector4ui(const struct prog_src_register *source,
253 const struct gl_program_machine *machine, GLuint result[4])
254{
Brian Paulf4361542008-11-11 10:47:10 -0700255 const GLuint *src = (GLuint *) get_src_register_pointer(source, machine);
Brian Paul37eef7b2008-11-07 09:33:55 -0700256 ASSERT(src);
257
258 if (source->Swizzle == SWIZZLE_NOOP) {
259 /* no swizzling */
260 COPY_4V(result, src);
261 }
262 else {
263 ASSERT(GET_SWZ(source->Swizzle, 0) <= 3);
264 ASSERT(GET_SWZ(source->Swizzle, 1) <= 3);
265 ASSERT(GET_SWZ(source->Swizzle, 2) <= 3);
266 ASSERT(GET_SWZ(source->Swizzle, 3) <= 3);
267 result[0] = src[GET_SWZ(source->Swizzle, 0)];
268 result[1] = src[GET_SWZ(source->Swizzle, 1)];
269 result[2] = src[GET_SWZ(source->Swizzle, 2)];
270 result[3] = src[GET_SWZ(source->Swizzle, 3)];
271 }
272
Brian Paul7db7ff82009-04-14 22:14:30 -0600273 /* Note: no Negate or Abs here */
Brian Paul37eef7b2008-11-07 09:33:55 -0700274}
275
276
277
278/**
Brian62da6a12007-05-02 18:44:34 -0600279 * Fetch the derivative with respect to X or Y for the given register.
280 * XXX this currently only works for fragment program input attribs.
Brian13e3b212007-02-22 16:09:40 -0700281 */
Brian62da6a12007-05-02 18:44:34 -0600282static void
Briane80d9012007-02-23 16:53:24 -0700283fetch_vector4_deriv(GLcontext * ctx,
284 const struct prog_src_register *source,
Brian62da6a12007-05-02 18:44:34 -0600285 const struct gl_program_machine *machine,
286 char xOrY, GLfloat result[4])
Brian13e3b212007-02-22 16:09:40 -0700287{
Brian Paul37eef7b2008-11-07 09:33:55 -0700288 if (source->File == PROGRAM_INPUT &&
289 source->Index < (GLint) machine->NumDeriv) {
Brian62da6a12007-05-02 18:44:34 -0600290 const GLint col = machine->CurElement;
291 const GLfloat w = machine->Attribs[FRAG_ATTRIB_WPOS][col][3];
292 const GLfloat invQ = 1.0f / w;
293 GLfloat deriv[4];
Brian13e3b212007-02-22 16:09:40 -0700294
Brian13e3b212007-02-22 16:09:40 -0700295 if (xOrY == 'X') {
Brian62da6a12007-05-02 18:44:34 -0600296 deriv[0] = machine->DerivX[source->Index][0] * invQ;
297 deriv[1] = machine->DerivX[source->Index][1] * invQ;
298 deriv[2] = machine->DerivX[source->Index][2] * invQ;
299 deriv[3] = machine->DerivX[source->Index][3] * invQ;
Brian13e3b212007-02-22 16:09:40 -0700300 }
301 else {
Brian62da6a12007-05-02 18:44:34 -0600302 deriv[0] = machine->DerivY[source->Index][0] * invQ;
303 deriv[1] = machine->DerivY[source->Index][1] * invQ;
304 deriv[2] = machine->DerivY[source->Index][2] * invQ;
305 deriv[3] = machine->DerivY[source->Index][3] * invQ;
Brian13e3b212007-02-22 16:09:40 -0700306 }
Brian13e3b212007-02-22 16:09:40 -0700307
Brian62da6a12007-05-02 18:44:34 -0600308 result[0] = deriv[GET_SWZ(source->Swizzle, 0)];
309 result[1] = deriv[GET_SWZ(source->Swizzle, 1)];
310 result[2] = deriv[GET_SWZ(source->Swizzle, 2)];
311 result[3] = deriv[GET_SWZ(source->Swizzle, 3)];
312
Brian62da6a12007-05-02 18:44:34 -0600313 if (source->Abs) {
314 result[0] = FABSF(result[0]);
315 result[1] = FABSF(result[1]);
316 result[2] = FABSF(result[2]);
317 result[3] = FABSF(result[3]);
318 }
Brian Paul7db7ff82009-04-14 22:14:30 -0600319 if (source->Negate) {
320 ASSERT(source->Negate == NEGATE_XYZW);
Brian62da6a12007-05-02 18:44:34 -0600321 result[0] = -result[0];
322 result[1] = -result[1];
323 result[2] = -result[2];
324 result[3] = -result[3];
325 }
Brian13e3b212007-02-22 16:09:40 -0700326 }
Brian62da6a12007-05-02 18:44:34 -0600327 else {
328 ASSIGN_4V(result, 0.0, 0.0, 0.0, 0.0);
Brian13e3b212007-02-22 16:09:40 -0700329 }
Brian13e3b212007-02-22 16:09:40 -0700330}
Brian13e3b212007-02-22 16:09:40 -0700331
332
333/**
334 * As above, but only return result[0] element.
335 */
336static void
Brian33eac562007-02-25 18:52:41 -0700337fetch_vector1(const struct prog_src_register *source,
Briane80d9012007-02-23 16:53:24 -0700338 const struct gl_program_machine *machine, GLfloat result[4])
Brian13e3b212007-02-22 16:09:40 -0700339{
Brian Paulf4361542008-11-11 10:47:10 -0700340 const GLfloat *src = get_src_register_pointer(source, machine);
Brian13e3b212007-02-22 16:09:40 -0700341 ASSERT(src);
342
343 result[0] = src[GET_SWZ(source->Swizzle, 0)];
344
Brian13e3b212007-02-22 16:09:40 -0700345 if (source->Abs) {
346 result[0] = FABSF(result[0]);
347 }
Brian Paul7db7ff82009-04-14 22:14:30 -0600348 if (source->Negate) {
Brian13e3b212007-02-22 16:09:40 -0700349 result[0] = -result[0];
350 }
351}
352
353
Brian Paul8d1a01d2010-01-22 15:36:28 -0700354static GLuint
355fetch_vector1ui(const struct prog_src_register *source,
356 const struct gl_program_machine *machine)
357{
358 const GLuint *src = (GLuint *) get_src_register_pointer(source, machine);
359 GLuint result;
360
361 ASSERT(src);
362
363 result = src[GET_SWZ(source->Swizzle, 0)];
364
365 if (source->Abs) {
366 result = FABSF(result);
367 }
368 if (source->Negate) {
369 result = -result;
370 }
371
372 return result;
373}
374
375
Brian13e3b212007-02-22 16:09:40 -0700376/**
Brian999b5562007-11-23 12:01:57 -0700377 * Fetch texel from texture. Use partial derivatives when possible.
378 */
379static INLINE void
380fetch_texel(GLcontext *ctx,
381 const struct gl_program_machine *machine,
382 const struct prog_instruction *inst,
383 const GLfloat texcoord[4], GLfloat lodBias,
384 GLfloat color[4])
385{
Brian Paulade50832008-05-14 16:09:46 -0600386 const GLuint unit = machine->Samplers[inst->TexSrcUnit];
387
Brian999b5562007-11-23 12:01:57 -0700388 /* Note: we only have the right derivatives for fragment input attribs.
389 */
390 if (machine->NumDeriv > 0 &&
391 inst->SrcReg[0].File == PROGRAM_INPUT &&
392 inst->SrcReg[0].Index == FRAG_ATTRIB_TEX0 + inst->TexSrcUnit) {
393 /* simple texture fetch for which we should have derivatives */
394 GLuint attr = inst->SrcReg[0].Index;
395 machine->FetchTexelDeriv(ctx, texcoord,
396 machine->DerivX[attr],
397 machine->DerivY[attr],
Brian Paulade50832008-05-14 16:09:46 -0600398 lodBias, unit, color);
Brian999b5562007-11-23 12:01:57 -0700399 }
400 else {
Brian Paulade50832008-05-14 16:09:46 -0600401 machine->FetchTexelLod(ctx, texcoord, lodBias, unit, color);
Brian999b5562007-11-23 12:01:57 -0700402 }
403}
404
405
406/**
Brian13e3b212007-02-22 16:09:40 -0700407 * Test value against zero and return GT, LT, EQ or UN if NaN.
408 */
409static INLINE GLuint
Briane80d9012007-02-23 16:53:24 -0700410generate_cc(float value)
Brian13e3b212007-02-22 16:09:40 -0700411{
412 if (value != value)
Briane80d9012007-02-23 16:53:24 -0700413 return COND_UN; /* NaN */
Brian13e3b212007-02-22 16:09:40 -0700414 if (value > 0.0F)
415 return COND_GT;
416 if (value < 0.0F)
417 return COND_LT;
418 return COND_EQ;
419}
420
421
422/**
423 * Test if the ccMaskRule is satisfied by the given condition code.
424 * Used to mask destination writes according to the current condition code.
425 */
426static INLINE GLboolean
427test_cc(GLuint condCode, GLuint ccMaskRule)
428{
429 switch (ccMaskRule) {
430 case COND_EQ: return (condCode == COND_EQ);
431 case COND_NE: return (condCode != COND_EQ);
432 case COND_LT: return (condCode == COND_LT);
433 case COND_GE: return (condCode == COND_GT || condCode == COND_EQ);
434 case COND_LE: return (condCode == COND_LT || condCode == COND_EQ);
435 case COND_GT: return (condCode == COND_GT);
436 case COND_TR: return GL_TRUE;
437 case COND_FL: return GL_FALSE;
438 default: return GL_TRUE;
439 }
440}
441
442
443/**
444 * Evaluate the 4 condition codes against a predicate and return GL_TRUE
445 * or GL_FALSE to indicate result.
446 */
447static INLINE GLboolean
448eval_condition(const struct gl_program_machine *machine,
449 const struct prog_instruction *inst)
450{
451 const GLuint swizzle = inst->DstReg.CondSwizzle;
452 const GLuint condMask = inst->DstReg.CondMask;
453 if (test_cc(machine->CondCodes[GET_SWZ(swizzle, 0)], condMask) ||
454 test_cc(machine->CondCodes[GET_SWZ(swizzle, 1)], condMask) ||
455 test_cc(machine->CondCodes[GET_SWZ(swizzle, 2)], condMask) ||
456 test_cc(machine->CondCodes[GET_SWZ(swizzle, 3)], condMask)) {
457 return GL_TRUE;
458 }
459 else {
460 return GL_FALSE;
461 }
462}
463
464
465
466/**
467 * Store 4 floats into a register. Observe the instructions saturate and
468 * set-condition-code flags.
469 */
470static void
Briane80d9012007-02-23 16:53:24 -0700471store_vector4(const struct prog_instruction *inst,
472 struct gl_program_machine *machine, const GLfloat value[4])
Brian13e3b212007-02-22 16:09:40 -0700473{
Brian Paulf4361542008-11-11 10:47:10 -0700474 const struct prog_dst_register *dstReg = &(inst->DstReg);
Brian13e3b212007-02-22 16:09:40 -0700475 const GLboolean clamp = inst->SaturateMode == SATURATE_ZERO_ONE;
Brian Paulf4361542008-11-11 10:47:10 -0700476 GLuint writeMask = dstReg->WriteMask;
Brian13e3b212007-02-22 16:09:40 -0700477 GLfloat clampedValue[4];
Brian Paulf4361542008-11-11 10:47:10 -0700478 GLfloat *dst = get_dst_register_pointer(dstReg, machine);
Brian13e3b212007-02-22 16:09:40 -0700479
480#if 0
481 if (value[0] > 1.0e10 ||
482 IS_INF_OR_NAN(value[0]) ||
483 IS_INF_OR_NAN(value[1]) ||
Briane80d9012007-02-23 16:53:24 -0700484 IS_INF_OR_NAN(value[2]) || IS_INF_OR_NAN(value[3]))
Brian13e3b212007-02-22 16:09:40 -0700485 printf("store %g %g %g %g\n", value[0], value[1], value[2], value[3]);
486#endif
487
488 if (clamp) {
489 clampedValue[0] = CLAMP(value[0], 0.0F, 1.0F);
490 clampedValue[1] = CLAMP(value[1], 0.0F, 1.0F);
491 clampedValue[2] = CLAMP(value[2], 0.0F, 1.0F);
492 clampedValue[3] = CLAMP(value[3], 0.0F, 1.0F);
493 value = clampedValue;
494 }
495
Brian Paulf4361542008-11-11 10:47:10 -0700496 if (dstReg->CondMask != COND_TR) {
Brian13e3b212007-02-22 16:09:40 -0700497 /* condition codes may turn off some writes */
498 if (writeMask & WRITEMASK_X) {
Brian Paulf4361542008-11-11 10:47:10 -0700499 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 0)],
500 dstReg->CondMask))
Brian13e3b212007-02-22 16:09:40 -0700501 writeMask &= ~WRITEMASK_X;
502 }
503 if (writeMask & WRITEMASK_Y) {
Brian Paulf4361542008-11-11 10:47:10 -0700504 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 1)],
505 dstReg->CondMask))
Brian13e3b212007-02-22 16:09:40 -0700506 writeMask &= ~WRITEMASK_Y;
507 }
508 if (writeMask & WRITEMASK_Z) {
Brian Paulf4361542008-11-11 10:47:10 -0700509 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 2)],
510 dstReg->CondMask))
Brian13e3b212007-02-22 16:09:40 -0700511 writeMask &= ~WRITEMASK_Z;
512 }
513 if (writeMask & WRITEMASK_W) {
Brian Paulf4361542008-11-11 10:47:10 -0700514 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 3)],
515 dstReg->CondMask))
Brian13e3b212007-02-22 16:09:40 -0700516 writeMask &= ~WRITEMASK_W;
517 }
518 }
519
Brian Paul92009542009-06-03 15:43:53 -0600520#ifdef NAN_CHECK
521 assert(!IS_INF_OR_NAN(value[0]));
522 assert(!IS_INF_OR_NAN(value[0]));
523 assert(!IS_INF_OR_NAN(value[0]));
524 assert(!IS_INF_OR_NAN(value[0]));
525#endif
526
Brian13e3b212007-02-22 16:09:40 -0700527 if (writeMask & WRITEMASK_X)
Brian Paulf4361542008-11-11 10:47:10 -0700528 dst[0] = value[0];
Brian13e3b212007-02-22 16:09:40 -0700529 if (writeMask & WRITEMASK_Y)
Brian Paulf4361542008-11-11 10:47:10 -0700530 dst[1] = value[1];
Brian13e3b212007-02-22 16:09:40 -0700531 if (writeMask & WRITEMASK_Z)
Brian Paulf4361542008-11-11 10:47:10 -0700532 dst[2] = value[2];
Brian13e3b212007-02-22 16:09:40 -0700533 if (writeMask & WRITEMASK_W)
Brian Paulf4361542008-11-11 10:47:10 -0700534 dst[3] = value[3];
Brian13e3b212007-02-22 16:09:40 -0700535
536 if (inst->CondUpdate) {
537 if (writeMask & WRITEMASK_X)
538 machine->CondCodes[0] = generate_cc(value[0]);
539 if (writeMask & WRITEMASK_Y)
540 machine->CondCodes[1] = generate_cc(value[1]);
541 if (writeMask & WRITEMASK_Z)
542 machine->CondCodes[2] = generate_cc(value[2]);
543 if (writeMask & WRITEMASK_W)
544 machine->CondCodes[3] = generate_cc(value[3]);
Briana01616e2007-03-28 11:01:28 -0600545#if DEBUG_PROG
546 printf("CondCodes=(%s,%s,%s,%s) for:\n",
547 _mesa_condcode_string(machine->CondCodes[0]),
548 _mesa_condcode_string(machine->CondCodes[1]),
549 _mesa_condcode_string(machine->CondCodes[2]),
550 _mesa_condcode_string(machine->CondCodes[3]));
551#endif
Brian13e3b212007-02-22 16:09:40 -0700552 }
553}
554
555
Brian13e3b212007-02-22 16:09:40 -0700556/**
Brian Paul37eef7b2008-11-07 09:33:55 -0700557 * Store 4 uints into a register. Observe the set-condition-code flags.
558 */
559static void
560store_vector4ui(const struct prog_instruction *inst,
561 struct gl_program_machine *machine, const GLuint value[4])
562{
Brian Paulf4361542008-11-11 10:47:10 -0700563 const struct prog_dst_register *dstReg = &(inst->DstReg);
564 GLuint writeMask = dstReg->WriteMask;
565 GLuint *dst = (GLuint *) get_dst_register_pointer(dstReg, machine);
Brian Paul37eef7b2008-11-07 09:33:55 -0700566
Brian Paulf4361542008-11-11 10:47:10 -0700567 if (dstReg->CondMask != COND_TR) {
Brian Paul37eef7b2008-11-07 09:33:55 -0700568 /* condition codes may turn off some writes */
569 if (writeMask & WRITEMASK_X) {
Brian Paulf4361542008-11-11 10:47:10 -0700570 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 0)],
571 dstReg->CondMask))
Brian Paul37eef7b2008-11-07 09:33:55 -0700572 writeMask &= ~WRITEMASK_X;
573 }
574 if (writeMask & WRITEMASK_Y) {
Brian Paulf4361542008-11-11 10:47:10 -0700575 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 1)],
576 dstReg->CondMask))
Brian Paul37eef7b2008-11-07 09:33:55 -0700577 writeMask &= ~WRITEMASK_Y;
578 }
579 if (writeMask & WRITEMASK_Z) {
Brian Paulf4361542008-11-11 10:47:10 -0700580 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 2)],
581 dstReg->CondMask))
Brian Paul37eef7b2008-11-07 09:33:55 -0700582 writeMask &= ~WRITEMASK_Z;
583 }
584 if (writeMask & WRITEMASK_W) {
Brian Paulf4361542008-11-11 10:47:10 -0700585 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 3)],
586 dstReg->CondMask))
Brian Paul37eef7b2008-11-07 09:33:55 -0700587 writeMask &= ~WRITEMASK_W;
588 }
589 }
590
591 if (writeMask & WRITEMASK_X)
Brian Paulf4361542008-11-11 10:47:10 -0700592 dst[0] = value[0];
Brian Paul37eef7b2008-11-07 09:33:55 -0700593 if (writeMask & WRITEMASK_Y)
Brian Paulf4361542008-11-11 10:47:10 -0700594 dst[1] = value[1];
Brian Paul37eef7b2008-11-07 09:33:55 -0700595 if (writeMask & WRITEMASK_Z)
Brian Paulf4361542008-11-11 10:47:10 -0700596 dst[2] = value[2];
Brian Paul37eef7b2008-11-07 09:33:55 -0700597 if (writeMask & WRITEMASK_W)
Brian Paulf4361542008-11-11 10:47:10 -0700598 dst[3] = value[3];
Brian Paul37eef7b2008-11-07 09:33:55 -0700599
600 if (inst->CondUpdate) {
601 if (writeMask & WRITEMASK_X)
Karl Schultzb30898f2010-02-13 17:31:58 -0700602 machine->CondCodes[0] = generate_cc((float)value[0]);
Brian Paul37eef7b2008-11-07 09:33:55 -0700603 if (writeMask & WRITEMASK_Y)
Karl Schultzb30898f2010-02-13 17:31:58 -0700604 machine->CondCodes[1] = generate_cc((float)value[1]);
Brian Paul37eef7b2008-11-07 09:33:55 -0700605 if (writeMask & WRITEMASK_Z)
Karl Schultzb30898f2010-02-13 17:31:58 -0700606 machine->CondCodes[2] = generate_cc((float)value[2]);
Brian Paul37eef7b2008-11-07 09:33:55 -0700607 if (writeMask & WRITEMASK_W)
Karl Schultzb30898f2010-02-13 17:31:58 -0700608 machine->CondCodes[3] = generate_cc((float)value[3]);
Brian Paul37eef7b2008-11-07 09:33:55 -0700609#if DEBUG_PROG
610 printf("CondCodes=(%s,%s,%s,%s) for:\n",
611 _mesa_condcode_string(machine->CondCodes[0]),
612 _mesa_condcode_string(machine->CondCodes[1]),
613 _mesa_condcode_string(machine->CondCodes[2]),
614 _mesa_condcode_string(machine->CondCodes[3]));
615#endif
616 }
617}
618
619
620
621/**
Brian13e3b212007-02-22 16:09:40 -0700622 * Execute the given vertex/fragment program.
623 *
Brian3c1c9992007-02-25 19:11:44 -0700624 * \param ctx rendering context
625 * \param program the program to execute
626 * \param machine machine state (must be initialized)
Brian13e3b212007-02-22 16:09:40 -0700627 * \return GL_TRUE if program completed or GL_FALSE if program executed KIL.
628 */
629GLboolean
Briane80d9012007-02-23 16:53:24 -0700630_mesa_execute_program(GLcontext * ctx,
Brian8b34b7d2007-02-25 18:26:50 -0700631 const struct gl_program *program,
Brian085d7d52007-02-25 18:23:37 -0700632 struct gl_program_machine *machine)
Brian13e3b212007-02-22 16:09:40 -0700633{
Brian8b34b7d2007-02-25 18:26:50 -0700634 const GLuint numInst = program->NumInstructions;
Briancfd00112007-02-25 18:30:45 -0700635 const GLuint maxExec = 10000;
José Fonseca452a5922008-05-31 18:14:09 +0900636 GLuint pc, numExec = 0;
Brian13e3b212007-02-22 16:09:40 -0700637
638 machine->CurProgram = program;
639
640 if (DEBUG_PROG) {
641 printf("execute program %u --------------------\n", program->Id);
642 }
643
Brian33eac562007-02-25 18:52:41 -0700644 if (program->Target == GL_VERTEX_PROGRAM_ARB) {
645 machine->EnvParams = ctx->VertexProgram.Parameters;
646 }
647 else {
648 machine->EnvParams = ctx->FragmentProgram.Parameters;
649 }
650
Brian8b34b7d2007-02-25 18:26:50 -0700651 for (pc = 0; pc < numInst; pc++) {
Brian13e3b212007-02-22 16:09:40 -0700652 const struct prog_instruction *inst = program->Instructions + pc;
653
Brian13e3b212007-02-22 16:09:40 -0700654 if (DEBUG_PROG) {
655 _mesa_print_instruction(inst);
656 }
657
658 switch (inst->Opcode) {
Briane80d9012007-02-23 16:53:24 -0700659 case OPCODE_ABS:
660 {
661 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700662 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -0700663 result[0] = FABSF(a[0]);
664 result[1] = FABSF(a[1]);
665 result[2] = FABSF(a[2]);
666 result[3] = FABSF(a[3]);
667 store_vector4(inst, machine, result);
668 }
669 break;
670 case OPCODE_ADD:
671 {
672 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700673 fetch_vector4(&inst->SrcReg[0], machine, a);
674 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -0700675 result[0] = a[0] + b[0];
676 result[1] = a[1] + b[1];
677 result[2] = a[2] + b[2];
678 result[3] = a[3] + b[3];
679 store_vector4(inst, machine, result);
680 if (DEBUG_PROG) {
681 printf("ADD (%g %g %g %g) = (%g %g %g %g) + (%g %g %g %g)\n",
682 result[0], result[1], result[2], result[3],
683 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -0700684 }
Briane80d9012007-02-23 16:53:24 -0700685 }
686 break;
Brian Paul37eef7b2008-11-07 09:33:55 -0700687 case OPCODE_AND: /* bitwise AND */
688 {
689 GLuint a[4], b[4], result[4];
690 fetch_vector4ui(&inst->SrcReg[0], machine, a);
691 fetch_vector4ui(&inst->SrcReg[1], machine, b);
692 result[0] = a[0] & b[0];
693 result[1] = a[1] & b[1];
694 result[2] = a[2] & b[2];
695 result[3] = a[3] & b[3];
696 store_vector4ui(inst, machine, result);
697 }
698 break;
Brianf183a2d2007-02-23 17:14:30 -0700699 case OPCODE_ARL:
700 {
701 GLfloat t[4];
Brian33eac562007-02-25 18:52:41 -0700702 fetch_vector4(&inst->SrcReg[0], machine, t);
Brian Paula9475cc2008-12-12 18:03:48 -0700703 machine->AddressReg[0][0] = IFLOOR(t[0]);
Brian Paula636f5b2010-02-05 14:58:46 -0700704 if (DEBUG_PROG) {
705 printf("ARL %d\n", machine->AddressReg[0][0]);
706 }
Brianf183a2d2007-02-23 17:14:30 -0700707 }
708 break;
Briane80d9012007-02-23 16:53:24 -0700709 case OPCODE_BGNLOOP:
710 /* no-op */
Brian Paule8ea2d22009-12-22 12:57:31 -0700711 ASSERT(program->Instructions[inst->BranchTarget].Opcode
712 == OPCODE_ENDLOOP);
Briane80d9012007-02-23 16:53:24 -0700713 break;
714 case OPCODE_ENDLOOP:
715 /* subtract 1 here since pc is incremented by for(pc) loop */
Brian Paule8ea2d22009-12-22 12:57:31 -0700716 ASSERT(program->Instructions[inst->BranchTarget].Opcode
717 == OPCODE_BGNLOOP);
Briane80d9012007-02-23 16:53:24 -0700718 pc = inst->BranchTarget - 1; /* go to matching BNGLOOP */
719 break;
720 case OPCODE_BGNSUB: /* begin subroutine */
721 break;
722 case OPCODE_ENDSUB: /* end subroutine */
723 break;
724 case OPCODE_BRA: /* branch (conditional) */
Briane80d9012007-02-23 16:53:24 -0700725 if (eval_condition(machine, inst)) {
726 /* take branch */
Brian Pauldb721152009-12-22 14:15:30 -0700727 /* Subtract 1 here since we'll do pc++ below */
728 pc = inst->BranchTarget - 1;
729 }
730 break;
731 case OPCODE_BRK: /* break out of loop (conditional) */
732 ASSERT(program->Instructions[inst->BranchTarget].Opcode
733 == OPCODE_ENDLOOP);
734 if (eval_condition(machine, inst)) {
735 /* break out of loop */
736 /* pc++ at end of for-loop will put us after the ENDLOOP inst */
737 pc = inst->BranchTarget;
738 }
739 break;
740 case OPCODE_CONT: /* continue loop (conditional) */
741 ASSERT(program->Instructions[inst->BranchTarget].Opcode
742 == OPCODE_ENDLOOP);
743 if (eval_condition(machine, inst)) {
744 /* continue at ENDLOOP */
Briane80d9012007-02-23 16:53:24 -0700745 /* Subtract 1 here since we'll do pc++ at end of for-loop */
746 pc = inst->BranchTarget - 1;
747 }
748 break;
749 case OPCODE_CAL: /* Call subroutine (conditional) */
750 if (eval_condition(machine, inst)) {
751 /* call the subroutine */
752 if (machine->StackDepth >= MAX_PROGRAM_CALL_DEPTH) {
753 return GL_TRUE; /* Per GL_NV_vertex_program2 spec */
Brian13e3b212007-02-22 16:09:40 -0700754 }
Briana0275b02007-03-27 11:02:20 -0600755 machine->CallStack[machine->StackDepth++] = pc + 1; /* next inst */
Brian31dc7a32007-03-27 15:21:35 -0600756 /* Subtract 1 here since we'll do pc++ at end of for-loop */
757 pc = inst->BranchTarget - 1;
Briane80d9012007-02-23 16:53:24 -0700758 }
759 break;
760 case OPCODE_CMP:
761 {
762 GLfloat a[4], b[4], c[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700763 fetch_vector4(&inst->SrcReg[0], machine, a);
764 fetch_vector4(&inst->SrcReg[1], machine, b);
765 fetch_vector4(&inst->SrcReg[2], machine, c);
Briane80d9012007-02-23 16:53:24 -0700766 result[0] = a[0] < 0.0F ? b[0] : c[0];
767 result[1] = a[1] < 0.0F ? b[1] : c[1];
768 result[2] = a[2] < 0.0F ? b[2] : c[2];
769 result[3] = a[3] < 0.0F ? b[3] : c[3];
770 store_vector4(inst, machine, result);
771 }
772 break;
773 case OPCODE_COS:
774 {
775 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700776 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -0700777 result[0] = result[1] = result[2] = result[3]
778 = (GLfloat) _mesa_cos(a[0]);
779 store_vector4(inst, machine, result);
780 }
781 break;
782 case OPCODE_DDX: /* Partial derivative with respect to X */
783 {
Brian62da6a12007-05-02 18:44:34 -0600784 GLfloat result[4];
785 fetch_vector4_deriv(ctx, &inst->SrcReg[0], machine,
786 'X', result);
Briane80d9012007-02-23 16:53:24 -0700787 store_vector4(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -0700788 }
789 break;
790 case OPCODE_DDY: /* Partial derivative with respect to Y */
791 {
Brian62da6a12007-05-02 18:44:34 -0600792 GLfloat result[4];
793 fetch_vector4_deriv(ctx, &inst->SrcReg[0], machine,
794 'Y', result);
Briane80d9012007-02-23 16:53:24 -0700795 store_vector4(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -0700796 }
797 break;
Brian Paul65cb74e2008-11-07 09:41:00 -0700798 case OPCODE_DP2:
799 {
800 GLfloat a[4], b[4], result[4];
801 fetch_vector4(&inst->SrcReg[0], machine, a);
802 fetch_vector4(&inst->SrcReg[1], machine, b);
803 result[0] = result[1] = result[2] = result[3] = DOT2(a, b);
804 store_vector4(inst, machine, result);
805 if (DEBUG_PROG) {
806 printf("DP2 %g = (%g %g) . (%g %g)\n",
807 result[0], a[0], a[1], b[0], b[1]);
808 }
809 }
810 break;
811 case OPCODE_DP2A:
812 {
813 GLfloat a[4], b[4], c, result[4];
814 fetch_vector4(&inst->SrcReg[0], machine, a);
815 fetch_vector4(&inst->SrcReg[1], machine, b);
816 fetch_vector1(&inst->SrcReg[1], machine, &c);
817 result[0] = result[1] = result[2] = result[3] = DOT2(a, b) + c;
818 store_vector4(inst, machine, result);
819 if (DEBUG_PROG) {
820 printf("DP2A %g = (%g %g) . (%g %g) + %g\n",
821 result[0], a[0], a[1], b[0], b[1], c);
822 }
823 }
824 break;
Briane80d9012007-02-23 16:53:24 -0700825 case OPCODE_DP3:
826 {
827 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700828 fetch_vector4(&inst->SrcReg[0], machine, a);
829 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -0700830 result[0] = result[1] = result[2] = result[3] = DOT3(a, b);
831 store_vector4(inst, machine, result);
832 if (DEBUG_PROG) {
833 printf("DP3 %g = (%g %g %g) . (%g %g %g)\n",
834 result[0], a[0], a[1], a[2], b[0], b[1], b[2]);
Brian13e3b212007-02-22 16:09:40 -0700835 }
Briane80d9012007-02-23 16:53:24 -0700836 }
837 break;
838 case OPCODE_DP4:
839 {
840 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700841 fetch_vector4(&inst->SrcReg[0], machine, a);
842 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -0700843 result[0] = result[1] = result[2] = result[3] = DOT4(a, b);
844 store_vector4(inst, machine, result);
845 if (DEBUG_PROG) {
846 printf("DP4 %g = (%g, %g %g %g) . (%g, %g %g %g)\n",
847 result[0], a[0], a[1], a[2], a[3],
848 b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -0700849 }
Briane80d9012007-02-23 16:53:24 -0700850 }
851 break;
852 case OPCODE_DPH:
853 {
854 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700855 fetch_vector4(&inst->SrcReg[0], machine, a);
856 fetch_vector4(&inst->SrcReg[1], machine, b);
Brian Paul65cb74e2008-11-07 09:41:00 -0700857 result[0] = result[1] = result[2] = result[3] = DOT3(a, b) + b[3];
Briane80d9012007-02-23 16:53:24 -0700858 store_vector4(inst, machine, result);
859 }
860 break;
861 case OPCODE_DST: /* Distance vector */
862 {
863 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700864 fetch_vector4(&inst->SrcReg[0], machine, a);
865 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -0700866 result[0] = 1.0F;
867 result[1] = a[1] * b[1];
868 result[2] = a[2];
869 result[3] = b[3];
870 store_vector4(inst, machine, result);
871 }
872 break;
Brianf183a2d2007-02-23 17:14:30 -0700873 case OPCODE_EXP:
Brianf183a2d2007-02-23 17:14:30 -0700874 {
875 GLfloat t[4], q[4], floor_t0;
Brian33eac562007-02-25 18:52:41 -0700876 fetch_vector1(&inst->SrcReg[0], machine, t);
Brianf183a2d2007-02-23 17:14:30 -0700877 floor_t0 = FLOORF(t[0]);
878 if (floor_t0 > FLT_MAX_EXP) {
879 SET_POS_INFINITY(q[0]);
880 SET_POS_INFINITY(q[2]);
881 }
882 else if (floor_t0 < FLT_MIN_EXP) {
883 q[0] = 0.0F;
884 q[2] = 0.0F;
885 }
886 else {
Brian761728a2007-02-24 11:14:57 -0700887 q[0] = LDEXPF(1.0, (int) floor_t0);
888 /* Note: GL_NV_vertex_program expects
889 * result.z = result.x * APPX(result.y)
890 * We do what the ARB extension says.
891 */
Brian Paulb8a200a2009-04-03 10:29:11 -0600892 q[2] = (GLfloat) _mesa_pow(2.0, t[0]);
Brianf183a2d2007-02-23 17:14:30 -0700893 }
894 q[1] = t[0] - floor_t0;
895 q[3] = 1.0F;
896 store_vector4( inst, machine, q );
897 }
898 break;
Briane80d9012007-02-23 16:53:24 -0700899 case OPCODE_EX2: /* Exponential base 2 */
900 {
Brian Paul035de6a2009-06-03 15:42:52 -0600901 GLfloat a[4], result[4], val;
Brian33eac562007-02-25 18:52:41 -0700902 fetch_vector1(&inst->SrcReg[0], machine, a);
Brian Paul035de6a2009-06-03 15:42:52 -0600903 val = (GLfloat) _mesa_pow(2.0, a[0]);
904 /*
905 if (IS_INF_OR_NAN(val))
906 val = 1.0e10;
907 */
908 result[0] = result[1] = result[2] = result[3] = val;
Briane80d9012007-02-23 16:53:24 -0700909 store_vector4(inst, machine, result);
910 }
911 break;
912 case OPCODE_FLR:
913 {
914 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700915 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -0700916 result[0] = FLOORF(a[0]);
917 result[1] = FLOORF(a[1]);
918 result[2] = FLOORF(a[2]);
919 result[3] = FLOORF(a[3]);
920 store_vector4(inst, machine, result);
921 }
922 break;
923 case OPCODE_FRC:
924 {
925 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -0700926 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -0700927 result[0] = a[0] - FLOORF(a[0]);
928 result[1] = a[1] - FLOORF(a[1]);
929 result[2] = a[2] - FLOORF(a[2]);
930 result[3] = a[3] - FLOORF(a[3]);
931 store_vector4(inst, machine, result);
932 }
933 break;
934 case OPCODE_IF:
Brian63556fa2007-03-23 14:47:46 -0600935 {
936 GLboolean cond;
Brian Paulddd97292009-12-22 14:21:07 -0700937 ASSERT(program->Instructions[inst->BranchTarget].Opcode
938 == OPCODE_ELSE ||
939 program->Instructions[inst->BranchTarget].Opcode
940 == OPCODE_ENDIF);
Brian63556fa2007-03-23 14:47:46 -0600941 /* eval condition */
942 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
943 GLfloat a[4];
944 fetch_vector1(&inst->SrcReg[0], machine, a);
945 cond = (a[0] != 0.0);
946 }
947 else {
948 cond = eval_condition(machine, inst);
949 }
Briana7f73662007-04-20 08:11:51 -0600950 if (DEBUG_PROG) {
951 printf("IF: %d\n", cond);
952 }
Brian63556fa2007-03-23 14:47:46 -0600953 /* do if/else */
954 if (cond) {
955 /* do if-clause (just continue execution) */
956 }
957 else {
958 /* go to the instruction after ELSE or ENDIF */
959 assert(inst->BranchTarget >= 0);
Brian Paulddd97292009-12-22 14:21:07 -0700960 pc = inst->BranchTarget;
Brian63556fa2007-03-23 14:47:46 -0600961 }
Briane80d9012007-02-23 16:53:24 -0700962 }
963 break;
964 case OPCODE_ELSE:
965 /* goto ENDIF */
Brian Paulddd97292009-12-22 14:21:07 -0700966 ASSERT(program->Instructions[inst->BranchTarget].Opcode
967 == OPCODE_ENDIF);
Briane80d9012007-02-23 16:53:24 -0700968 assert(inst->BranchTarget >= 0);
Brian Paulddd97292009-12-22 14:21:07 -0700969 pc = inst->BranchTarget;
Briane80d9012007-02-23 16:53:24 -0700970 break;
971 case OPCODE_ENDIF:
972 /* nothing */
973 break;
Briane80d9012007-02-23 16:53:24 -0700974 case OPCODE_KIL_NV: /* NV_f_p only (conditional) */
975 if (eval_condition(machine, inst)) {
976 return GL_FALSE;
977 }
978 break;
979 case OPCODE_KIL: /* ARB_f_p only */
980 {
981 GLfloat a[4];
Brian33eac562007-02-25 18:52:41 -0700982 fetch_vector4(&inst->SrcReg[0], machine, a);
Brian Paulc0633dd2009-08-31 14:57:59 -0600983 if (DEBUG_PROG) {
984 printf("KIL if (%g %g %g %g) <= 0.0\n",
985 a[0], a[1], a[2], a[3]);
986 }
987
Briane80d9012007-02-23 16:53:24 -0700988 if (a[0] < 0.0F || a[1] < 0.0F || a[2] < 0.0F || a[3] < 0.0F) {
Brian13e3b212007-02-22 16:09:40 -0700989 return GL_FALSE;
990 }
Briane80d9012007-02-23 16:53:24 -0700991 }
992 break;
993 case OPCODE_LG2: /* log base 2 */
994 {
Brian Paul035de6a2009-06-03 15:42:52 -0600995 GLfloat a[4], result[4], val;
Brian33eac562007-02-25 18:52:41 -0700996 fetch_vector1(&inst->SrcReg[0], machine, a);
Ian Romanick962fa6b2008-12-18 14:11:06 -0800997 /* The fast LOG2 macro doesn't meet the precision requirements.
998 */
Brian Paul035de6a2009-06-03 15:42:52 -0600999 if (a[0] == 0.0F) {
Vinson Lee18883cd2009-10-01 13:33:20 -06001000 val = -FLT_MAX;
Brian Paul035de6a2009-06-03 15:42:52 -06001001 }
1002 else {
Karl Schultzb30898f2010-02-13 17:31:58 -07001003 val = (float)(log(a[0]) * 1.442695F);
Brian Paul035de6a2009-06-03 15:42:52 -06001004 }
1005 result[0] = result[1] = result[2] = result[3] = val;
Briane80d9012007-02-23 16:53:24 -07001006 store_vector4(inst, machine, result);
1007 }
1008 break;
1009 case OPCODE_LIT:
1010 {
1011 const GLfloat epsilon = 1.0F / 256.0F; /* from NV VP spec */
1012 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001013 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001014 a[0] = MAX2(a[0], 0.0F);
1015 a[1] = MAX2(a[1], 0.0F);
1016 /* XXX ARB version clamps a[3], NV version doesn't */
1017 a[3] = CLAMP(a[3], -(128.0F - epsilon), (128.0F - epsilon));
1018 result[0] = 1.0F;
1019 result[1] = a[0];
1020 /* XXX we could probably just use pow() here */
1021 if (a[0] > 0.0F) {
1022 if (a[1] == 0.0 && a[3] == 0.0)
Brian Paul20fbb242010-01-27 17:03:04 -07001023 result[2] = 1.0F;
Briane80d9012007-02-23 16:53:24 -07001024 else
Brian Paulb8a200a2009-04-03 10:29:11 -06001025 result[2] = (GLfloat) _mesa_pow(a[1], a[3]);
Brian13e3b212007-02-22 16:09:40 -07001026 }
Briane80d9012007-02-23 16:53:24 -07001027 else {
Brian Paul20fbb242010-01-27 17:03:04 -07001028 result[2] = 0.0F;
Brian13e3b212007-02-22 16:09:40 -07001029 }
Briane80d9012007-02-23 16:53:24 -07001030 result[3] = 1.0F;
1031 store_vector4(inst, machine, result);
1032 if (DEBUG_PROG) {
1033 printf("LIT (%g %g %g %g) : (%g %g %g %g)\n",
1034 result[0], result[1], result[2], result[3],
1035 a[0], a[1], a[2], a[3]);
Brian13e3b212007-02-22 16:09:40 -07001036 }
Briane80d9012007-02-23 16:53:24 -07001037 }
1038 break;
Brianf183a2d2007-02-23 17:14:30 -07001039 case OPCODE_LOG:
1040 {
1041 GLfloat t[4], q[4], abs_t0;
Brian33eac562007-02-25 18:52:41 -07001042 fetch_vector1(&inst->SrcReg[0], machine, t);
Brianf183a2d2007-02-23 17:14:30 -07001043 abs_t0 = FABSF(t[0]);
1044 if (abs_t0 != 0.0F) {
1045 /* Since we really can't handle infinite values on VMS
1046 * like other OSes we'll use __MAXFLOAT to represent
1047 * infinity. This may need some tweaking.
1048 */
1049#ifdef VMS
1050 if (abs_t0 == __MAXFLOAT)
1051#else
1052 if (IS_INF_OR_NAN(abs_t0))
1053#endif
1054 {
1055 SET_POS_INFINITY(q[0]);
1056 q[1] = 1.0F;
1057 SET_POS_INFINITY(q[2]);
1058 }
1059 else {
1060 int exponent;
1061 GLfloat mantissa = FREXPF(t[0], &exponent);
1062 q[0] = (GLfloat) (exponent - 1);
1063 q[1] = (GLfloat) (2.0 * mantissa); /* map [.5, 1) -> [1, 2) */
Ian Romanick962fa6b2008-12-18 14:11:06 -08001064
1065 /* The fast LOG2 macro doesn't meet the precision
1066 * requirements.
1067 */
Karl Schultzb30898f2010-02-13 17:31:58 -07001068 q[2] = (float)(log(t[0]) * 1.442695F);
Brianf183a2d2007-02-23 17:14:30 -07001069 }
1070 }
1071 else {
1072 SET_NEG_INFINITY(q[0]);
1073 q[1] = 1.0F;
1074 SET_NEG_INFINITY(q[2]);
1075 }
1076 q[3] = 1.0;
1077 store_vector4(inst, machine, q);
1078 }
1079 break;
Briane80d9012007-02-23 16:53:24 -07001080 case OPCODE_LRP:
1081 {
1082 GLfloat a[4], b[4], c[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001083 fetch_vector4(&inst->SrcReg[0], machine, a);
1084 fetch_vector4(&inst->SrcReg[1], machine, b);
1085 fetch_vector4(&inst->SrcReg[2], machine, c);
Briane80d9012007-02-23 16:53:24 -07001086 result[0] = a[0] * b[0] + (1.0F - a[0]) * c[0];
1087 result[1] = a[1] * b[1] + (1.0F - a[1]) * c[1];
1088 result[2] = a[2] * b[2] + (1.0F - a[2]) * c[2];
1089 result[3] = a[3] * b[3] + (1.0F - a[3]) * c[3];
1090 store_vector4(inst, machine, result);
1091 if (DEBUG_PROG) {
1092 printf("LRP (%g %g %g %g) = (%g %g %g %g), "
1093 "(%g %g %g %g), (%g %g %g %g)\n",
1094 result[0], result[1], result[2], result[3],
1095 a[0], a[1], a[2], a[3],
1096 b[0], b[1], b[2], b[3], c[0], c[1], c[2], c[3]);
Brian13e3b212007-02-22 16:09:40 -07001097 }
Briane80d9012007-02-23 16:53:24 -07001098 }
1099 break;
1100 case OPCODE_MAD:
1101 {
1102 GLfloat a[4], b[4], c[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001103 fetch_vector4(&inst->SrcReg[0], machine, a);
1104 fetch_vector4(&inst->SrcReg[1], machine, b);
1105 fetch_vector4(&inst->SrcReg[2], machine, c);
Briane80d9012007-02-23 16:53:24 -07001106 result[0] = a[0] * b[0] + c[0];
1107 result[1] = a[1] * b[1] + c[1];
1108 result[2] = a[2] * b[2] + c[2];
1109 result[3] = a[3] * b[3] + c[3];
1110 store_vector4(inst, machine, result);
1111 if (DEBUG_PROG) {
1112 printf("MAD (%g %g %g %g) = (%g %g %g %g) * "
1113 "(%g %g %g %g) + (%g %g %g %g)\n",
1114 result[0], result[1], result[2], result[3],
1115 a[0], a[1], a[2], a[3],
1116 b[0], b[1], b[2], b[3], c[0], c[1], c[2], c[3]);
Brian13e3b212007-02-22 16:09:40 -07001117 }
Briane80d9012007-02-23 16:53:24 -07001118 }
1119 break;
1120 case OPCODE_MAX:
1121 {
1122 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001123 fetch_vector4(&inst->SrcReg[0], machine, a);
1124 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001125 result[0] = MAX2(a[0], b[0]);
1126 result[1] = MAX2(a[1], b[1]);
1127 result[2] = MAX2(a[2], b[2]);
1128 result[3] = MAX2(a[3], b[3]);
1129 store_vector4(inst, machine, result);
1130 if (DEBUG_PROG) {
1131 printf("MAX (%g %g %g %g) = (%g %g %g %g), (%g %g %g %g)\n",
1132 result[0], result[1], result[2], result[3],
1133 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -07001134 }
Briane80d9012007-02-23 16:53:24 -07001135 }
1136 break;
1137 case OPCODE_MIN:
1138 {
1139 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001140 fetch_vector4(&inst->SrcReg[0], machine, a);
1141 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001142 result[0] = MIN2(a[0], b[0]);
1143 result[1] = MIN2(a[1], b[1]);
1144 result[2] = MIN2(a[2], b[2]);
1145 result[3] = MIN2(a[3], b[3]);
1146 store_vector4(inst, machine, result);
1147 }
1148 break;
1149 case OPCODE_MOV:
1150 {
1151 GLfloat result[4];
Brian33eac562007-02-25 18:52:41 -07001152 fetch_vector4(&inst->SrcReg[0], machine, result);
Briane80d9012007-02-23 16:53:24 -07001153 store_vector4(inst, machine, result);
1154 if (DEBUG_PROG) {
1155 printf("MOV (%g %g %g %g)\n",
1156 result[0], result[1], result[2], result[3]);
Brian13e3b212007-02-22 16:09:40 -07001157 }
Briane80d9012007-02-23 16:53:24 -07001158 }
1159 break;
1160 case OPCODE_MUL:
1161 {
1162 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001163 fetch_vector4(&inst->SrcReg[0], machine, a);
1164 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001165 result[0] = a[0] * b[0];
1166 result[1] = a[1] * b[1];
1167 result[2] = a[2] * b[2];
1168 result[3] = a[3] * b[3];
1169 store_vector4(inst, machine, result);
1170 if (DEBUG_PROG) {
1171 printf("MUL (%g %g %g %g) = (%g %g %g %g) * (%g %g %g %g)\n",
1172 result[0], result[1], result[2], result[3],
1173 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -07001174 }
Briane80d9012007-02-23 16:53:24 -07001175 }
1176 break;
1177 case OPCODE_NOISE1:
1178 {
1179 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001180 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001181 result[0] =
Brian13e3b212007-02-22 16:09:40 -07001182 result[1] =
Brian Paul702b5b02008-12-15 18:37:39 -07001183 result[2] =
1184 result[3] = _mesa_noise1(a[0]);
Briane80d9012007-02-23 16:53:24 -07001185 store_vector4(inst, machine, result);
1186 }
1187 break;
1188 case OPCODE_NOISE2:
1189 {
1190 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001191 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001192 result[0] =
Brian13e3b212007-02-22 16:09:40 -07001193 result[1] =
Brian Paul702b5b02008-12-15 18:37:39 -07001194 result[2] = result[3] = _mesa_noise2(a[0], a[1]);
Briane80d9012007-02-23 16:53:24 -07001195 store_vector4(inst, machine, result);
1196 }
1197 break;
1198 case OPCODE_NOISE3:
1199 {
1200 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001201 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001202 result[0] =
Brian13e3b212007-02-22 16:09:40 -07001203 result[1] =
1204 result[2] =
Brian Paul702b5b02008-12-15 18:37:39 -07001205 result[3] = _mesa_noise3(a[0], a[1], a[2]);
Briane80d9012007-02-23 16:53:24 -07001206 store_vector4(inst, machine, result);
1207 }
1208 break;
1209 case OPCODE_NOISE4:
1210 {
1211 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001212 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001213 result[0] =
Brian13e3b212007-02-22 16:09:40 -07001214 result[1] =
1215 result[2] =
Brian Paul702b5b02008-12-15 18:37:39 -07001216 result[3] = _mesa_noise4(a[0], a[1], a[2], a[3]);
Briane80d9012007-02-23 16:53:24 -07001217 store_vector4(inst, machine, result);
1218 }
1219 break;
1220 case OPCODE_NOP:
1221 break;
Brian Paul37eef7b2008-11-07 09:33:55 -07001222 case OPCODE_NOT: /* bitwise NOT */
1223 {
1224 GLuint a[4], result[4];
1225 fetch_vector4ui(&inst->SrcReg[0], machine, a);
1226 result[0] = ~a[0];
1227 result[1] = ~a[1];
1228 result[2] = ~a[2];
1229 result[3] = ~a[3];
1230 store_vector4ui(inst, machine, result);
1231 }
1232 break;
Brian Paulf6ead502008-11-07 08:51:31 -07001233 case OPCODE_NRM3: /* 3-component normalization */
1234 {
1235 GLfloat a[4], result[4];
1236 GLfloat tmp;
1237 fetch_vector4(&inst->SrcReg[0], machine, a);
1238 tmp = a[0] * a[0] + a[1] * a[1] + a[2] * a[2];
1239 if (tmp != 0.0F)
Brian Paul22459e72008-11-07 12:59:36 -07001240 tmp = INV_SQRTF(tmp);
Brian Paulf6ead502008-11-07 08:51:31 -07001241 result[0] = tmp * a[0];
1242 result[1] = tmp * a[1];
1243 result[2] = tmp * a[2];
1244 result[3] = 0.0; /* undefined, but prevent valgrind warnings */
1245 store_vector4(inst, machine, result);
1246 }
1247 break;
1248 case OPCODE_NRM4: /* 4-component normalization */
1249 {
1250 GLfloat a[4], result[4];
1251 GLfloat tmp;
1252 fetch_vector4(&inst->SrcReg[0], machine, a);
1253 tmp = a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3];
1254 if (tmp != 0.0F)
Brian Paul22459e72008-11-07 12:59:36 -07001255 tmp = INV_SQRTF(tmp);
Brian Paulf6ead502008-11-07 08:51:31 -07001256 result[0] = tmp * a[0];
1257 result[1] = tmp * a[1];
1258 result[2] = tmp * a[2];
1259 result[3] = tmp * a[3];
1260 store_vector4(inst, machine, result);
1261 }
1262 break;
Brian Paul37eef7b2008-11-07 09:33:55 -07001263 case OPCODE_OR: /* bitwise OR */
1264 {
1265 GLuint a[4], b[4], result[4];
1266 fetch_vector4ui(&inst->SrcReg[0], machine, a);
1267 fetch_vector4ui(&inst->SrcReg[1], machine, b);
1268 result[0] = a[0] | b[0];
1269 result[1] = a[1] | b[1];
1270 result[2] = a[2] | b[2];
1271 result[3] = a[3] | b[3];
1272 store_vector4ui(inst, machine, result);
1273 }
1274 break;
Briane80d9012007-02-23 16:53:24 -07001275 case OPCODE_PK2H: /* pack two 16-bit floats in one 32-bit float */
1276 {
Brian Paul37eef7b2008-11-07 09:33:55 -07001277 GLfloat a[4];
1278 GLuint result[4];
Briane80d9012007-02-23 16:53:24 -07001279 GLhalfNV hx, hy;
Brian33eac562007-02-25 18:52:41 -07001280 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001281 hx = _mesa_float_to_half(a[0]);
1282 hy = _mesa_float_to_half(a[1]);
Brian Paul37eef7b2008-11-07 09:33:55 -07001283 result[0] =
1284 result[1] =
1285 result[2] =
1286 result[3] = hx | (hy << 16);
1287 store_vector4ui(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -07001288 }
1289 break;
1290 case OPCODE_PK2US: /* pack two GLushorts into one 32-bit float */
1291 {
Brian Paul37eef7b2008-11-07 09:33:55 -07001292 GLfloat a[4];
1293 GLuint result[4], usx, usy;
Brian33eac562007-02-25 18:52:41 -07001294 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001295 a[0] = CLAMP(a[0], 0.0F, 1.0F);
1296 a[1] = CLAMP(a[1], 0.0F, 1.0F);
1297 usx = IROUND(a[0] * 65535.0F);
1298 usy = IROUND(a[1] * 65535.0F);
Brian Paul37eef7b2008-11-07 09:33:55 -07001299 result[0] =
1300 result[1] =
1301 result[2] =
1302 result[3] = usx | (usy << 16);
1303 store_vector4ui(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -07001304 }
1305 break;
1306 case OPCODE_PK4B: /* pack four GLbytes into one 32-bit float */
1307 {
Brian Paul37eef7b2008-11-07 09:33:55 -07001308 GLfloat a[4];
1309 GLuint result[4], ubx, uby, ubz, ubw;
Brian33eac562007-02-25 18:52:41 -07001310 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001311 a[0] = CLAMP(a[0], -128.0F / 127.0F, 1.0F);
1312 a[1] = CLAMP(a[1], -128.0F / 127.0F, 1.0F);
1313 a[2] = CLAMP(a[2], -128.0F / 127.0F, 1.0F);
1314 a[3] = CLAMP(a[3], -128.0F / 127.0F, 1.0F);
1315 ubx = IROUND(127.0F * a[0] + 128.0F);
1316 uby = IROUND(127.0F * a[1] + 128.0F);
1317 ubz = IROUND(127.0F * a[2] + 128.0F);
1318 ubw = IROUND(127.0F * a[3] + 128.0F);
Brian Paul37eef7b2008-11-07 09:33:55 -07001319 result[0] =
1320 result[1] =
1321 result[2] =
1322 result[3] = ubx | (uby << 8) | (ubz << 16) | (ubw << 24);
1323 store_vector4ui(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -07001324 }
1325 break;
1326 case OPCODE_PK4UB: /* pack four GLubytes into one 32-bit float */
1327 {
Brian Paul37eef7b2008-11-07 09:33:55 -07001328 GLfloat a[4];
1329 GLuint result[4], ubx, uby, ubz, ubw;
Brian33eac562007-02-25 18:52:41 -07001330 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001331 a[0] = CLAMP(a[0], 0.0F, 1.0F);
1332 a[1] = CLAMP(a[1], 0.0F, 1.0F);
1333 a[2] = CLAMP(a[2], 0.0F, 1.0F);
1334 a[3] = CLAMP(a[3], 0.0F, 1.0F);
1335 ubx = IROUND(255.0F * a[0]);
1336 uby = IROUND(255.0F * a[1]);
1337 ubz = IROUND(255.0F * a[2]);
1338 ubw = IROUND(255.0F * a[3]);
Brian Paul37eef7b2008-11-07 09:33:55 -07001339 result[0] =
1340 result[1] =
1341 result[2] =
1342 result[3] = ubx | (uby << 8) | (ubz << 16) | (ubw << 24);
1343 store_vector4ui(inst, machine, result);
Briane80d9012007-02-23 16:53:24 -07001344 }
1345 break;
1346 case OPCODE_POW:
1347 {
1348 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001349 fetch_vector1(&inst->SrcReg[0], machine, a);
1350 fetch_vector1(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001351 result[0] = result[1] = result[2] = result[3]
1352 = (GLfloat) _mesa_pow(a[0], b[0]);
1353 store_vector4(inst, machine, result);
1354 }
1355 break;
1356 case OPCODE_RCP:
1357 {
1358 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001359 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001360 if (DEBUG_PROG) {
1361 if (a[0] == 0)
1362 printf("RCP(0)\n");
1363 else if (IS_INF_OR_NAN(a[0]))
1364 printf("RCP(inf)\n");
Brian13e3b212007-02-22 16:09:40 -07001365 }
Briane80d9012007-02-23 16:53:24 -07001366 result[0] = result[1] = result[2] = result[3] = 1.0F / a[0];
1367 store_vector4(inst, machine, result);
1368 }
1369 break;
1370 case OPCODE_RET: /* return from subroutine (conditional) */
1371 if (eval_condition(machine, inst)) {
1372 if (machine->StackDepth == 0) {
1373 return GL_TRUE; /* Per GL_NV_vertex_program2 spec */
Brian13e3b212007-02-22 16:09:40 -07001374 }
Briana0275b02007-03-27 11:02:20 -06001375 /* subtract one because of pc++ in the for loop */
1376 pc = machine->CallStack[--machine->StackDepth] - 1;
Briane80d9012007-02-23 16:53:24 -07001377 }
1378 break;
1379 case OPCODE_RFL: /* reflection vector */
1380 {
1381 GLfloat axis[4], dir[4], result[4], tmpX, tmpW;
Brian33eac562007-02-25 18:52:41 -07001382 fetch_vector4(&inst->SrcReg[0], machine, axis);
1383 fetch_vector4(&inst->SrcReg[1], machine, dir);
Briane80d9012007-02-23 16:53:24 -07001384 tmpW = DOT3(axis, axis);
1385 tmpX = (2.0F * DOT3(axis, dir)) / tmpW;
1386 result[0] = tmpX * axis[0] - dir[0];
1387 result[1] = tmpX * axis[1] - dir[1];
1388 result[2] = tmpX * axis[2] - dir[2];
1389 /* result[3] is never written! XXX enforce in parser! */
1390 store_vector4(inst, machine, result);
1391 }
1392 break;
1393 case OPCODE_RSQ: /* 1 / sqrt() */
1394 {
1395 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001396 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001397 a[0] = FABSF(a[0]);
1398 result[0] = result[1] = result[2] = result[3] = INV_SQRTF(a[0]);
1399 store_vector4(inst, machine, result);
1400 if (DEBUG_PROG) {
1401 printf("RSQ %g = 1/sqrt(|%g|)\n", result[0], a[0]);
Brian13e3b212007-02-22 16:09:40 -07001402 }
Briane80d9012007-02-23 16:53:24 -07001403 }
1404 break;
1405 case OPCODE_SCS: /* sine and cos */
1406 {
1407 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001408 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001409 result[0] = (GLfloat) _mesa_cos(a[0]);
1410 result[1] = (GLfloat) _mesa_sin(a[0]);
1411 result[2] = 0.0; /* undefined! */
1412 result[3] = 0.0; /* undefined! */
1413 store_vector4(inst, machine, result);
1414 }
1415 break;
1416 case OPCODE_SEQ: /* set on equal */
1417 {
1418 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001419 fetch_vector4(&inst->SrcReg[0], machine, a);
1420 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001421 result[0] = (a[0] == b[0]) ? 1.0F : 0.0F;
1422 result[1] = (a[1] == b[1]) ? 1.0F : 0.0F;
1423 result[2] = (a[2] == b[2]) ? 1.0F : 0.0F;
1424 result[3] = (a[3] == b[3]) ? 1.0F : 0.0F;
1425 store_vector4(inst, machine, result);
Brian28ab1122007-03-06 12:15:30 -07001426 if (DEBUG_PROG) {
1427 printf("SEQ (%g %g %g %g) = (%g %g %g %g) == (%g %g %g %g)\n",
1428 result[0], result[1], result[2], result[3],
1429 a[0], a[1], a[2], a[3],
1430 b[0], b[1], b[2], b[3]);
1431 }
Briane80d9012007-02-23 16:53:24 -07001432 }
1433 break;
1434 case OPCODE_SFL: /* set false, operands ignored */
1435 {
1436 static const GLfloat result[4] = { 0.0F, 0.0F, 0.0F, 0.0F };
1437 store_vector4(inst, machine, result);
1438 }
1439 break;
1440 case OPCODE_SGE: /* set on greater or equal */
1441 {
1442 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001443 fetch_vector4(&inst->SrcReg[0], machine, a);
1444 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001445 result[0] = (a[0] >= b[0]) ? 1.0F : 0.0F;
1446 result[1] = (a[1] >= b[1]) ? 1.0F : 0.0F;
1447 result[2] = (a[2] >= b[2]) ? 1.0F : 0.0F;
1448 result[3] = (a[3] >= b[3]) ? 1.0F : 0.0F;
1449 store_vector4(inst, machine, result);
Brian28ab1122007-03-06 12:15:30 -07001450 if (DEBUG_PROG) {
1451 printf("SGE (%g %g %g %g) = (%g %g %g %g) >= (%g %g %g %g)\n",
1452 result[0], result[1], result[2], result[3],
1453 a[0], a[1], a[2], a[3],
1454 b[0], b[1], b[2], b[3]);
1455 }
Briane80d9012007-02-23 16:53:24 -07001456 }
1457 break;
1458 case OPCODE_SGT: /* set on greater */
1459 {
1460 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001461 fetch_vector4(&inst->SrcReg[0], machine, a);
1462 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001463 result[0] = (a[0] > b[0]) ? 1.0F : 0.0F;
1464 result[1] = (a[1] > b[1]) ? 1.0F : 0.0F;
1465 result[2] = (a[2] > b[2]) ? 1.0F : 0.0F;
1466 result[3] = (a[3] > b[3]) ? 1.0F : 0.0F;
1467 store_vector4(inst, machine, result);
1468 if (DEBUG_PROG) {
Brian28ab1122007-03-06 12:15:30 -07001469 printf("SGT (%g %g %g %g) = (%g %g %g %g) > (%g %g %g %g)\n",
1470 result[0], result[1], result[2], result[3],
1471 a[0], a[1], a[2], a[3],
1472 b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -07001473 }
Briane80d9012007-02-23 16:53:24 -07001474 }
1475 break;
1476 case OPCODE_SIN:
1477 {
1478 GLfloat a[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001479 fetch_vector1(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001480 result[0] = result[1] = result[2] = result[3]
1481 = (GLfloat) _mesa_sin(a[0]);
1482 store_vector4(inst, machine, result);
1483 }
1484 break;
1485 case OPCODE_SLE: /* set on less or equal */
1486 {
1487 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001488 fetch_vector4(&inst->SrcReg[0], machine, a);
1489 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001490 result[0] = (a[0] <= b[0]) ? 1.0F : 0.0F;
1491 result[1] = (a[1] <= b[1]) ? 1.0F : 0.0F;
1492 result[2] = (a[2] <= b[2]) ? 1.0F : 0.0F;
1493 result[3] = (a[3] <= b[3]) ? 1.0F : 0.0F;
1494 store_vector4(inst, machine, result);
Brian28ab1122007-03-06 12:15:30 -07001495 if (DEBUG_PROG) {
1496 printf("SLE (%g %g %g %g) = (%g %g %g %g) <= (%g %g %g %g)\n",
1497 result[0], result[1], result[2], result[3],
1498 a[0], a[1], a[2], a[3],
1499 b[0], b[1], b[2], b[3]);
1500 }
Briane80d9012007-02-23 16:53:24 -07001501 }
1502 break;
1503 case OPCODE_SLT: /* set on less */
1504 {
1505 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001506 fetch_vector4(&inst->SrcReg[0], machine, a);
1507 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001508 result[0] = (a[0] < b[0]) ? 1.0F : 0.0F;
1509 result[1] = (a[1] < b[1]) ? 1.0F : 0.0F;
1510 result[2] = (a[2] < b[2]) ? 1.0F : 0.0F;
1511 result[3] = (a[3] < b[3]) ? 1.0F : 0.0F;
1512 store_vector4(inst, machine, result);
Brian28ab1122007-03-06 12:15:30 -07001513 if (DEBUG_PROG) {
1514 printf("SLT (%g %g %g %g) = (%g %g %g %g) < (%g %g %g %g)\n",
1515 result[0], result[1], result[2], result[3],
1516 a[0], a[1], a[2], a[3],
1517 b[0], b[1], b[2], b[3]);
1518 }
Briane80d9012007-02-23 16:53:24 -07001519 }
1520 break;
1521 case OPCODE_SNE: /* set on not equal */
1522 {
1523 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001524 fetch_vector4(&inst->SrcReg[0], machine, a);
1525 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001526 result[0] = (a[0] != b[0]) ? 1.0F : 0.0F;
1527 result[1] = (a[1] != b[1]) ? 1.0F : 0.0F;
1528 result[2] = (a[2] != b[2]) ? 1.0F : 0.0F;
1529 result[3] = (a[3] != b[3]) ? 1.0F : 0.0F;
1530 store_vector4(inst, machine, result);
Brian28ab1122007-03-06 12:15:30 -07001531 if (DEBUG_PROG) {
1532 printf("SNE (%g %g %g %g) = (%g %g %g %g) != (%g %g %g %g)\n",
1533 result[0], result[1], result[2], result[3],
1534 a[0], a[1], a[2], a[3],
1535 b[0], b[1], b[2], b[3]);
1536 }
Briane80d9012007-02-23 16:53:24 -07001537 }
1538 break;
Brian Paulf6ead502008-11-07 08:51:31 -07001539 case OPCODE_SSG: /* set sign (-1, 0 or +1) */
1540 {
1541 GLfloat a[4], result[4];
1542 fetch_vector4(&inst->SrcReg[0], machine, a);
1543 result[0] = (GLfloat) ((a[0] > 0.0F) - (a[0] < 0.0F));
1544 result[1] = (GLfloat) ((a[1] > 0.0F) - (a[1] < 0.0F));
1545 result[2] = (GLfloat) ((a[2] > 0.0F) - (a[2] < 0.0F));
1546 result[3] = (GLfloat) ((a[3] > 0.0F) - (a[3] < 0.0F));
1547 store_vector4(inst, machine, result);
1548 }
1549 break;
Briane80d9012007-02-23 16:53:24 -07001550 case OPCODE_STR: /* set true, operands ignored */
1551 {
1552 static const GLfloat result[4] = { 1.0F, 1.0F, 1.0F, 1.0F };
1553 store_vector4(inst, machine, result);
1554 }
1555 break;
1556 case OPCODE_SUB:
1557 {
1558 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001559 fetch_vector4(&inst->SrcReg[0], machine, a);
1560 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001561 result[0] = a[0] - b[0];
1562 result[1] = a[1] - b[1];
1563 result[2] = a[2] - b[2];
1564 result[3] = a[3] - b[3];
1565 store_vector4(inst, machine, result);
1566 if (DEBUG_PROG) {
1567 printf("SUB (%g %g %g %g) = (%g %g %g %g) - (%g %g %g %g)\n",
1568 result[0], result[1], result[2], result[3],
1569 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
Brian13e3b212007-02-22 16:09:40 -07001570 }
Briane80d9012007-02-23 16:53:24 -07001571 }
1572 break;
1573 case OPCODE_SWZ: /* extended swizzle */
1574 {
1575 const struct prog_src_register *source = &inst->SrcReg[0];
Brian Paulf4361542008-11-11 10:47:10 -07001576 const GLfloat *src = get_src_register_pointer(source, machine);
Briane80d9012007-02-23 16:53:24 -07001577 GLfloat result[4];
1578 GLuint i;
1579 for (i = 0; i < 4; i++) {
1580 const GLuint swz = GET_SWZ(source->Swizzle, i);
1581 if (swz == SWIZZLE_ZERO)
1582 result[i] = 0.0;
1583 else if (swz == SWIZZLE_ONE)
1584 result[i] = 1.0;
Brian13e3b212007-02-22 16:09:40 -07001585 else {
Briane80d9012007-02-23 16:53:24 -07001586 ASSERT(swz >= 0);
1587 ASSERT(swz <= 3);
1588 result[i] = src[swz];
Brian13e3b212007-02-22 16:09:40 -07001589 }
Brian Paul7db7ff82009-04-14 22:14:30 -06001590 if (source->Negate & (1 << i))
Briane80d9012007-02-23 16:53:24 -07001591 result[i] = -result[i];
Brian13e3b212007-02-22 16:09:40 -07001592 }
Briane80d9012007-02-23 16:53:24 -07001593 store_vector4(inst, machine, result);
1594 }
1595 break;
1596 case OPCODE_TEX: /* Both ARB and NV frag prog */
Brian999b5562007-11-23 12:01:57 -07001597 /* Simple texel lookup */
Briane80d9012007-02-23 16:53:24 -07001598 {
Brian999b5562007-11-23 12:01:57 -07001599 GLfloat texcoord[4], color[4];
1600 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1601
1602 fetch_texel(ctx, machine, inst, texcoord, 0.0, color);
1603
Briane80d9012007-02-23 16:53:24 -07001604 if (DEBUG_PROG) {
Brian999b5562007-11-23 12:01:57 -07001605 printf("TEX (%g, %g, %g, %g) = texture[%d][%g, %g, %g, %g]\n",
Briane80d9012007-02-23 16:53:24 -07001606 color[0], color[1], color[2], color[3],
1607 inst->TexSrcUnit,
Brian999b5562007-11-23 12:01:57 -07001608 texcoord[0], texcoord[1], texcoord[2], texcoord[3]);
Briane80d9012007-02-23 16:53:24 -07001609 }
1610 store_vector4(inst, machine, color);
1611 }
1612 break;
1613 case OPCODE_TXB: /* GL_ARB_fragment_program only */
1614 /* Texel lookup with LOD bias */
1615 {
Brian999b5562007-11-23 12:01:57 -07001616 GLfloat texcoord[4], color[4], lodBias;
1617
1618 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1619
1620 /* texcoord[3] is the bias to add to lambda */
Brian Paul890f37d2009-09-23 13:34:30 -06001621 lodBias = texcoord[3];
Brian999b5562007-11-23 12:01:57 -07001622
1623 fetch_texel(ctx, machine, inst, texcoord, lodBias, color);
1624
Briane80d9012007-02-23 16:53:24 -07001625 store_vector4(inst, machine, color);
1626 }
1627 break;
1628 case OPCODE_TXD: /* GL_NV_fragment_program only */
1629 /* Texture lookup w/ partial derivatives for LOD */
1630 {
1631 GLfloat texcoord[4], dtdx[4], dtdy[4], color[4];
Brian33eac562007-02-25 18:52:41 -07001632 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1633 fetch_vector4(&inst->SrcReg[1], machine, dtdx);
1634 fetch_vector4(&inst->SrcReg[2], machine, dtdy);
Briane80d9012007-02-23 16:53:24 -07001635 machine->FetchTexelDeriv(ctx, texcoord, dtdx, dtdy,
Brian999b5562007-11-23 12:01:57 -07001636 0.0, /* lodBias */
Briane80d9012007-02-23 16:53:24 -07001637 inst->TexSrcUnit, color);
1638 store_vector4(inst, machine, color);
1639 }
1640 break;
1641 case OPCODE_TXP: /* GL_ARB_fragment_program only */
1642 /* Texture lookup w/ projective divide */
1643 {
Brian999b5562007-11-23 12:01:57 -07001644 GLfloat texcoord[4], color[4];
1645
Brian33eac562007-02-25 18:52:41 -07001646 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
Briane80d9012007-02-23 16:53:24 -07001647 /* Not so sure about this test - if texcoord[3] is
1648 * zero, we'd probably be fine except for an ASSERT in
1649 * IROUND_POS() which gets triggered by the inf values created.
1650 */
1651 if (texcoord[3] != 0.0) {
1652 texcoord[0] /= texcoord[3];
1653 texcoord[1] /= texcoord[3];
1654 texcoord[2] /= texcoord[3];
1655 }
Brian999b5562007-11-23 12:01:57 -07001656
1657 fetch_texel(ctx, machine, inst, texcoord, 0.0, color);
1658
Briane80d9012007-02-23 16:53:24 -07001659 store_vector4(inst, machine, color);
1660 }
1661 break;
1662 case OPCODE_TXP_NV: /* GL_NV_fragment_program only */
Brian999b5562007-11-23 12:01:57 -07001663 /* Texture lookup w/ projective divide, as above, but do not
1664 * do the divide by w if sampling from a cube map.
1665 */
Briane80d9012007-02-23 16:53:24 -07001666 {
Brian999b5562007-11-23 12:01:57 -07001667 GLfloat texcoord[4], color[4];
1668
Brian33eac562007-02-25 18:52:41 -07001669 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
Briane80d9012007-02-23 16:53:24 -07001670 if (inst->TexSrcTarget != TEXTURE_CUBE_INDEX &&
1671 texcoord[3] != 0.0) {
1672 texcoord[0] /= texcoord[3];
1673 texcoord[1] /= texcoord[3];
1674 texcoord[2] /= texcoord[3];
1675 }
Brian999b5562007-11-23 12:01:57 -07001676
1677 fetch_texel(ctx, machine, inst, texcoord, 0.0, color);
1678
Briane80d9012007-02-23 16:53:24 -07001679 store_vector4(inst, machine, color);
1680 }
1681 break;
Brian Paul035c0cf2008-11-06 17:14:33 -07001682 case OPCODE_TRUNC: /* truncate toward zero */
1683 {
1684 GLfloat a[4], result[4];
1685 fetch_vector4(&inst->SrcReg[0], machine, a);
1686 result[0] = (GLfloat) (GLint) a[0];
1687 result[1] = (GLfloat) (GLint) a[1];
1688 result[2] = (GLfloat) (GLint) a[2];
1689 result[3] = (GLfloat) (GLint) a[3];
1690 store_vector4(inst, machine, result);
1691 }
1692 break;
Briane80d9012007-02-23 16:53:24 -07001693 case OPCODE_UP2H: /* unpack two 16-bit floats */
1694 {
Brian Paul8d1a01d2010-01-22 15:36:28 -07001695 const GLuint raw = fetch_vector1ui(&inst->SrcReg[0], machine);
1696 GLfloat result[4];
Brian Paul7b5ad232010-01-22 16:09:03 -07001697 GLushort hx, hy;
Brian Paul8d1a01d2010-01-22 15:36:28 -07001698 hx = raw & 0xffff;
1699 hy = raw >> 16;
Briane80d9012007-02-23 16:53:24 -07001700 result[0] = result[2] = _mesa_half_to_float(hx);
1701 result[1] = result[3] = _mesa_half_to_float(hy);
1702 store_vector4(inst, machine, result);
1703 }
1704 break;
1705 case OPCODE_UP2US: /* unpack two GLushorts */
1706 {
Brian Paul8d1a01d2010-01-22 15:36:28 -07001707 const GLuint raw = fetch_vector1ui(&inst->SrcReg[0], machine);
1708 GLfloat result[4];
Briane80d9012007-02-23 16:53:24 -07001709 GLushort usx, usy;
Brian Paul8d1a01d2010-01-22 15:36:28 -07001710 usx = raw & 0xffff;
1711 usy = raw >> 16;
Briane80d9012007-02-23 16:53:24 -07001712 result[0] = result[2] = usx * (1.0f / 65535.0f);
1713 result[1] = result[3] = usy * (1.0f / 65535.0f);
1714 store_vector4(inst, machine, result);
1715 }
1716 break;
1717 case OPCODE_UP4B: /* unpack four GLbytes */
1718 {
Brian Paul8d1a01d2010-01-22 15:36:28 -07001719 const GLuint raw = fetch_vector1ui(&inst->SrcReg[0], machine);
1720 GLfloat result[4];
1721 result[0] = (((raw >> 0) & 0xff) - 128) / 127.0F;
1722 result[1] = (((raw >> 8) & 0xff) - 128) / 127.0F;
1723 result[2] = (((raw >> 16) & 0xff) - 128) / 127.0F;
1724 result[3] = (((raw >> 24) & 0xff) - 128) / 127.0F;
Briane80d9012007-02-23 16:53:24 -07001725 store_vector4(inst, machine, result);
1726 }
1727 break;
1728 case OPCODE_UP4UB: /* unpack four GLubytes */
1729 {
Brian Paul8d1a01d2010-01-22 15:36:28 -07001730 const GLuint raw = fetch_vector1ui(&inst->SrcReg[0], machine);
1731 GLfloat result[4];
1732 result[0] = ((raw >> 0) & 0xff) / 255.0F;
1733 result[1] = ((raw >> 8) & 0xff) / 255.0F;
1734 result[2] = ((raw >> 16) & 0xff) / 255.0F;
1735 result[3] = ((raw >> 24) & 0xff) / 255.0F;
Briane80d9012007-02-23 16:53:24 -07001736 store_vector4(inst, machine, result);
1737 }
1738 break;
Brian Paul37eef7b2008-11-07 09:33:55 -07001739 case OPCODE_XOR: /* bitwise XOR */
1740 {
1741 GLuint a[4], b[4], result[4];
1742 fetch_vector4ui(&inst->SrcReg[0], machine, a);
1743 fetch_vector4ui(&inst->SrcReg[1], machine, b);
1744 result[0] = a[0] ^ b[0];
1745 result[1] = a[1] ^ b[1];
1746 result[2] = a[2] ^ b[2];
1747 result[3] = a[3] ^ b[3];
1748 store_vector4ui(inst, machine, result);
1749 }
1750 break;
Briane80d9012007-02-23 16:53:24 -07001751 case OPCODE_XPD: /* cross product */
1752 {
1753 GLfloat a[4], b[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001754 fetch_vector4(&inst->SrcReg[0], machine, a);
1755 fetch_vector4(&inst->SrcReg[1], machine, b);
Briane80d9012007-02-23 16:53:24 -07001756 result[0] = a[1] * b[2] - a[2] * b[1];
1757 result[1] = a[2] * b[0] - a[0] * b[2];
1758 result[2] = a[0] * b[1] - a[1] * b[0];
1759 result[3] = 1.0;
1760 store_vector4(inst, machine, result);
Brian9637c962007-03-07 17:40:57 -07001761 if (DEBUG_PROG) {
1762 printf("XPD (%g %g %g %g) = (%g %g %g) X (%g %g %g)\n",
1763 result[0], result[1], result[2], result[3],
1764 a[0], a[1], a[2], b[0], b[1], b[2]);
1765 }
Briane80d9012007-02-23 16:53:24 -07001766 }
1767 break;
1768 case OPCODE_X2D: /* 2-D matrix transform */
1769 {
1770 GLfloat a[4], b[4], c[4], result[4];
Brian33eac562007-02-25 18:52:41 -07001771 fetch_vector4(&inst->SrcReg[0], machine, a);
1772 fetch_vector4(&inst->SrcReg[1], machine, b);
1773 fetch_vector4(&inst->SrcReg[2], machine, c);
Briane80d9012007-02-23 16:53:24 -07001774 result[0] = a[0] + b[0] * c[0] + b[1] * c[1];
1775 result[1] = a[1] + b[0] * c[2] + b[1] * c[3];
1776 result[2] = a[2] + b[0] * c[0] + b[1] * c[1];
1777 result[3] = a[3] + b[0] * c[2] + b[1] * c[3];
1778 store_vector4(inst, machine, result);
1779 }
1780 break;
1781 case OPCODE_PRINT:
1782 {
1783 if (inst->SrcReg[0].File != -1) {
1784 GLfloat a[4];
Brian33eac562007-02-25 18:52:41 -07001785 fetch_vector4(&inst->SrcReg[0], machine, a);
Briane80d9012007-02-23 16:53:24 -07001786 _mesa_printf("%s%g, %g, %g, %g\n", (const char *) inst->Data,
1787 a[0], a[1], a[2], a[3]);
1788 }
1789 else {
1790 _mesa_printf("%s\n", (const char *) inst->Data);
1791 }
1792 }
1793 break;
1794 case OPCODE_END:
1795 return GL_TRUE;
1796 default:
Alan Hourihane936dba12008-04-22 20:28:35 +01001797 _mesa_problem(ctx, "Bad opcode %d in _mesa_execute_program",
Briane80d9012007-02-23 16:53:24 -07001798 inst->Opcode);
1799 return GL_TRUE; /* return value doesn't matter */
Brian13e3b212007-02-22 16:09:40 -07001800 }
Briane80d9012007-02-23 16:53:24 -07001801
Briancfd00112007-02-25 18:30:45 -07001802 numExec++;
1803 if (numExec > maxExec) {
Brian13e3b212007-02-22 16:09:40 -07001804 _mesa_problem(ctx, "Infinite loop detected in fragment program");
1805 return GL_TRUE;
Brian13e3b212007-02-22 16:09:40 -07001806 }
Briane80d9012007-02-23 16:53:24 -07001807
1808 } /* for pc */
Brian13e3b212007-02-22 16:09:40 -07001809
Brian13e3b212007-02-22 16:09:40 -07001810 return GL_TRUE;
1811}