2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
29 #include "nvfragprog.h"
32 #include "s_nvfragprog.h"
34 #include "s_texture.h"
37 /* if 1, print some debugging info */
45 fetch_texel( GLcontext
*ctx
, const GLfloat texcoord
[4], GLfloat lambda
,
46 GLuint unit
, GLfloat color
[4] )
49 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
51 swrast
->TextureSample
[unit
](ctx
, unit
, ctx
->Texture
.Unit
[unit
]._Current
,
52 1, (const GLfloat (*)[4]) texcoord
,
54 color
[0] = CHAN_TO_FLOAT(rgba
[0]);
55 color
[1] = CHAN_TO_FLOAT(rgba
[1]);
56 color
[2] = CHAN_TO_FLOAT(rgba
[2]);
57 color
[3] = CHAN_TO_FLOAT(rgba
[3]);
62 * Fetch a texel with the given partial derivatives to compute a level
63 * of detail in the mipmap.
66 fetch_texel_deriv( GLcontext
*ctx
, const GLfloat texcoord
[4],
67 const GLfloat texdx
[4], const GLfloat texdy
[4],
68 GLuint unit
, GLfloat color
[4] )
70 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
71 const struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[unit
]._Current
;
72 const struct gl_texture_image
*texImg
= texObj
->Image
[texObj
->BaseLevel
];
73 const GLfloat texW
= (GLfloat
) texImg
->WidthScale
;
74 const GLfloat texH
= (GLfloat
) texImg
->HeightScale
;
77 GLfloat lambda
= _swrast_compute_lambda(texdx
[0], texdy
[0], /* ds/dx, ds/dy */
78 texdx
[1], texdy
[1], /* dt/dx, dt/dy */
79 texdx
[3], texdy
[2], /* dq/dx, dq/dy */
81 texcoord
[0], texcoord
[1], texcoord
[3],
84 swrast
->TextureSample
[unit
](ctx
, unit
, ctx
->Texture
.Unit
[unit
]._Current
,
85 1, (const GLfloat (*)[4]) texcoord
,
87 color
[0] = CHAN_TO_FLOAT(rgba
[0]);
88 color
[1] = CHAN_TO_FLOAT(rgba
[1]);
89 color
[2] = CHAN_TO_FLOAT(rgba
[2]);
90 color
[3] = CHAN_TO_FLOAT(rgba
[3]);
96 * Fetch a 4-element float vector from the given source register.
97 * Apply swizzling and negating as needed.
100 fetch_vector4( const struct fp_src_register
*source
,
101 const struct fp_machine
*machine
,
102 const struct fragment_program
*program
,
107 if (source
->IsParameter
) {
108 src
= program
->Parameters
[source
->Register
].Values
;
111 src
= machine
->Registers
[source
->Register
];
114 result
[0] = src
[source
->Swizzle
[0]];
115 result
[1] = src
[source
->Swizzle
[1]];
116 result
[2] = src
[source
->Swizzle
[2]];
117 result
[3] = src
[source
->Swizzle
[3]];
119 if (source
->NegateBase
) {
120 result
[0] = -result
[0];
121 result
[1] = -result
[1];
122 result
[2] = -result
[2];
123 result
[3] = -result
[3];
126 result
[0] = FABSF(result
[0]);
127 result
[1] = FABSF(result
[1]);
128 result
[2] = FABSF(result
[2]);
129 result
[3] = FABSF(result
[3]);
131 if (source
->NegateAbs
) {
132 result
[0] = -result
[0];
133 result
[1] = -result
[1];
134 result
[2] = -result
[2];
135 result
[3] = -result
[3];
141 * Fetch the derivative with respect to X for the given register.
142 * \return GL_TRUE if it was easily computed or GL_FALSE if we
143 * need to execute another instance of the program (ugh)!
146 fetch_vector4_deriv( const struct fp_src_register
*source
,
147 const struct sw_span
*span
,
148 char xOrY
, GLfloat result
[4] )
152 ASSERT(xOrY
== 'X' || xOrY
== 'Y');
154 switch (source
->Register
) {
155 case FRAG_ATTRIB_WPOS
:
169 case FRAG_ATTRIB_COL0
:
171 src
[0] = span
->drdx
* (1.0F
/ CHAN_MAXF
);
172 src
[1] = span
->dgdx
* (1.0F
/ CHAN_MAXF
);
173 src
[2] = span
->dbdx
* (1.0F
/ CHAN_MAXF
);
174 src
[3] = span
->dadx
* (1.0F
/ CHAN_MAXF
);
177 src
[0] = span
->drdy
* (1.0F
/ CHAN_MAXF
);
178 src
[1] = span
->dgdy
* (1.0F
/ CHAN_MAXF
);
179 src
[2] = span
->dbdy
* (1.0F
/ CHAN_MAXF
);
180 src
[3] = span
->dady
* (1.0F
/ CHAN_MAXF
);
183 case FRAG_ATTRIB_COL1
:
185 src
[0] = span
->dsrdx
* (1.0F
/ CHAN_MAXF
);
186 src
[1] = span
->dsgdx
* (1.0F
/ CHAN_MAXF
);
187 src
[2] = span
->dsbdx
* (1.0F
/ CHAN_MAXF
);
188 src
[3] = 0.0; /* XXX need this */
191 src
[0] = span
->dsrdy
* (1.0F
/ CHAN_MAXF
);
192 src
[1] = span
->dsgdy
* (1.0F
/ CHAN_MAXF
);
193 src
[2] = span
->dsbdy
* (1.0F
/ CHAN_MAXF
);
194 src
[3] = 0.0; /* XXX need this */
197 case FRAG_ATTRIB_FOGC
:
199 src
[0] = span
->dfogdx
;
205 src
[0] = span
->dfogdy
;
211 case FRAG_ATTRIB_TEX0
:
212 case FRAG_ATTRIB_TEX1
:
213 case FRAG_ATTRIB_TEX2
:
214 case FRAG_ATTRIB_TEX3
:
215 case FRAG_ATTRIB_TEX4
:
216 case FRAG_ATTRIB_TEX5
:
217 case FRAG_ATTRIB_TEX6
:
218 case FRAG_ATTRIB_TEX7
:
220 const GLuint u
= source
->Register
- FRAG_ATTRIB_TEX0
;
221 src
[0] = span
->texStepX
[u
][0] * (1.0F
/ CHAN_MAXF
);
222 src
[1] = span
->texStepX
[u
][1] * (1.0F
/ CHAN_MAXF
);
223 src
[2] = span
->texStepX
[u
][2] * (1.0F
/ CHAN_MAXF
);
224 src
[3] = span
->texStepX
[u
][3] * (1.0F
/ CHAN_MAXF
);
227 const GLuint u
= source
->Register
- FRAG_ATTRIB_TEX0
;
228 src
[0] = span
->texStepY
[u
][0] * (1.0F
/ CHAN_MAXF
);
229 src
[1] = span
->texStepY
[u
][1] * (1.0F
/ CHAN_MAXF
);
230 src
[2] = span
->texStepY
[u
][2] * (1.0F
/ CHAN_MAXF
);
231 src
[3] = span
->texStepY
[u
][3] * (1.0F
/ CHAN_MAXF
);
238 result
[0] = src
[source
->Swizzle
[0]];
239 result
[1] = src
[source
->Swizzle
[1]];
240 result
[2] = src
[source
->Swizzle
[2]];
241 result
[3] = src
[source
->Swizzle
[3]];
243 if (source
->NegateBase
) {
244 result
[0] = -result
[0];
245 result
[1] = -result
[1];
246 result
[2] = -result
[2];
247 result
[3] = -result
[3];
250 result
[0] = FABSF(result
[0]);
251 result
[1] = FABSF(result
[1]);
252 result
[2] = FABSF(result
[2]);
253 result
[3] = FABSF(result
[3]);
255 if (source
->NegateAbs
) {
256 result
[0] = -result
[0];
257 result
[1] = -result
[1];
258 result
[2] = -result
[2];
259 result
[3] = -result
[3];
266 * As above, but only return result[0] element.
269 fetch_vector1( const struct fp_src_register
*source
,
270 const struct fp_machine
*machine
,
271 const struct fragment_program
*program
,
276 if (source
->IsParameter
) {
277 src
= program
->Parameters
[source
->Register
].Values
;
280 src
= machine
->Registers
[source
->Register
];
283 result
[0] = src
[source
->Swizzle
[0]];
285 if (source
->NegateBase
) {
286 result
[0] = -result
[0];
289 result
[0] = FABSF(result
[0]);
291 if (source
->NegateAbs
) {
292 result
[0] = -result
[0];
298 * Test value against zero and return GT, LT, EQ or UN if NaN.
301 generate_cc( float value
)
304 return COND_UN
; /* NaN */
313 * Test if the ccMaskRule is satisfied by the given condition code.
314 * Used to mask destination writes according to the current condition codee.
316 static INLINE GLboolean
317 test_cc(GLuint condCode
, GLuint ccMaskRule
)
319 switch (ccMaskRule
) {
320 case COND_EQ
: return (condCode
== COND_EQ
);
321 case COND_NE
: return (condCode
!= COND_EQ
);
322 case COND_LT
: return (condCode
== COND_LT
);
323 case COND_GE
: return (condCode
== COND_GT
|| condCode
== COND_EQ
);
324 case COND_LE
: return (condCode
== COND_LT
|| condCode
== COND_EQ
);
325 case COND_GT
: return (condCode
== COND_GT
);
326 case COND_TR
: return GL_TRUE
;
327 case COND_FL
: return GL_FALSE
;
328 default: return GL_TRUE
;
334 * Store 4 floats into a register. Observe the instructions saturate and
335 * set-condition-code flags.
338 store_vector4( const struct fp_instruction
*inst
,
339 struct fp_machine
*machine
,
340 const GLfloat value
[4] )
342 const struct fp_dst_register
*dest
= &(inst
->DstReg
);
343 const GLboolean clamp
= inst
->Saturate
;
344 const GLboolean updateCC
= inst
->UpdateCondRegister
;
345 GLfloat
*dstReg
= machine
->Registers
[dest
->Register
];
346 GLfloat clampedValue
[4];
347 const GLboolean
*writeMask
= dest
->WriteMask
;
348 GLboolean condWriteMask
[4];
351 if (value
[0] > 1.0e10
||
352 IS_INF_OR_NAN(value
[0]) ||
353 IS_INF_OR_NAN(value
[1]) ||
354 IS_INF_OR_NAN(value
[2]) ||
355 IS_INF_OR_NAN(value
[3]) )
356 printf("store %g %g %g %g\n", value
[0], value
[1], value
[2], value
[3]);
360 clampedValue
[0] = CLAMP(value
[0], 0.0F
, 1.0F
);
361 clampedValue
[1] = CLAMP(value
[1], 0.0F
, 1.0F
);
362 clampedValue
[2] = CLAMP(value
[2], 0.0F
, 1.0F
);
363 clampedValue
[3] = CLAMP(value
[3], 0.0F
, 1.0F
);
364 value
= clampedValue
;
367 if (dest
->CondMask
!= COND_TR
) {
368 condWriteMask
[0] = writeMask
[0]
369 && test_cc(machine
->CondCodes
[dest
->CondSwizzle
[0]], dest
->CondMask
);
370 condWriteMask
[1] = writeMask
[1]
371 && test_cc(machine
->CondCodes
[dest
->CondSwizzle
[1]], dest
->CondMask
);
372 condWriteMask
[2] = writeMask
[2]
373 && test_cc(machine
->CondCodes
[dest
->CondSwizzle
[2]], dest
->CondMask
);
374 condWriteMask
[3] = writeMask
[3]
375 && test_cc(machine
->CondCodes
[dest
->CondSwizzle
[3]], dest
->CondMask
);
376 writeMask
= condWriteMask
;
380 dstReg
[0] = value
[0];
382 machine
->CondCodes
[0] = generate_cc(value
[0]);
385 dstReg
[1] = value
[1];
387 machine
->CondCodes
[1] = generate_cc(value
[1]);
390 dstReg
[2] = value
[2];
392 machine
->CondCodes
[2] = generate_cc(value
[2]);
395 dstReg
[3] = value
[3];
397 machine
->CondCodes
[3] = generate_cc(value
[3]);
403 * Initialize a new machine state instance from an existing one, adding
404 * the partial derivatives onto the input registers.
405 * Used to implement DDX and DDY instructions in non-trivial cases.
408 init_machine_deriv( GLcontext
*ctx
,
409 const struct fp_machine
*machine
,
410 const struct fragment_program
*program
,
411 const struct sw_span
*span
, char xOrY
,
412 struct fp_machine
*dMachine
)
416 ASSERT(xOrY
== 'X' || xOrY
== 'Y');
418 /* copy existing machine */
419 _mesa_memcpy(dMachine
, machine
, sizeof(struct fp_machine
));
421 /* Clear temporary registers */
422 _mesa_bzero((GLfloat
*) (machine
->Registers
+ FP_TEMP_REG_START
) ,
423 MAX_NV_FRAGMENT_PROGRAM_TEMPS
* 4 * sizeof(GLfloat
));
425 /* Add derivatives */
426 if (program
->InputsRead
& (1 << FRAG_ATTRIB_WPOS
)) {
427 GLfloat
*wpos
= (GLfloat
*) machine
->Registers
[FP_INPUT_REG_START
+FRAG_ATTRIB_WPOS
];
431 wpos
[2] += span
->dzdx
;
432 wpos
[3] += span
->dwdx
;
437 wpos
[2] += span
->dzdy
;
438 wpos
[3] += span
->dwdy
;
441 if (program
->InputsRead
& (1 << FRAG_ATTRIB_COL0
)) {
442 GLfloat
*col0
= (GLfloat
*) machine
->Registers
[FP_INPUT_REG_START
+FRAG_ATTRIB_COL0
];
444 col0
[0] += span
->drdx
* (1.0F
/ CHAN_MAXF
);
445 col0
[1] += span
->dgdx
* (1.0F
/ CHAN_MAXF
);
446 col0
[2] += span
->dbdx
* (1.0F
/ CHAN_MAXF
);
447 col0
[3] += span
->dadx
* (1.0F
/ CHAN_MAXF
);
450 col0
[0] += span
->drdy
* (1.0F
/ CHAN_MAXF
);
451 col0
[1] += span
->dgdy
* (1.0F
/ CHAN_MAXF
);
452 col0
[2] += span
->dbdy
* (1.0F
/ CHAN_MAXF
);
453 col0
[3] += span
->dady
* (1.0F
/ CHAN_MAXF
);
456 if (program
->InputsRead
& (1 << FRAG_ATTRIB_COL1
)) {
457 GLfloat
*col1
= (GLfloat
*) machine
->Registers
[FP_INPUT_REG_START
+FRAG_ATTRIB_COL1
];
459 col1
[0] += span
->dsrdx
* (1.0F
/ CHAN_MAXF
);
460 col1
[1] += span
->dsgdx
* (1.0F
/ CHAN_MAXF
);
461 col1
[2] += span
->dsbdx
* (1.0F
/ CHAN_MAXF
);
462 col1
[3] += 0.0; /*XXX fix */
465 col1
[0] += span
->dsrdy
* (1.0F
/ CHAN_MAXF
);
466 col1
[1] += span
->dsgdy
* (1.0F
/ CHAN_MAXF
);
467 col1
[2] += span
->dsbdy
* (1.0F
/ CHAN_MAXF
);
468 col1
[3] += 0.0; /*XXX fix */
471 if (program
->InputsRead
& (1 << FRAG_ATTRIB_FOGC
)) {
472 GLfloat
*fogc
= (GLfloat
*) machine
->Registers
[FP_INPUT_REG_START
+FRAG_ATTRIB_FOGC
];
474 fogc
[0] += span
->dfogdx
;
477 fogc
[0] += span
->dfogdy
;
480 for (u
= 0; u
< ctx
->Const
.MaxTextureCoordUnits
; u
++) {
481 if (program
->InputsRead
& (1 << (FRAG_ATTRIB_TEX0
+ u
))) {
482 GLfloat
*tex
= (GLfloat
*) machine
->Registers
[FP_INPUT_REG_START
+FRAG_ATTRIB_TEX0
+u
];
484 tex
[0] += span
->texStepX
[u
][0];
485 tex
[1] += span
->texStepX
[u
][1];
486 tex
[2] += span
->texStepX
[u
][2];
487 tex
[3] += span
->texStepX
[u
][3];
490 tex
[0] += span
->texStepY
[u
][0];
491 tex
[1] += span
->texStepY
[u
][1];
492 tex
[2] += span
->texStepY
[u
][2];
493 tex
[3] += span
->texStepY
[u
][3];
498 /* init condition codes */
499 dMachine
->CondCodes
[0] = COND_EQ
;
500 dMachine
->CondCodes
[1] = COND_EQ
;
501 dMachine
->CondCodes
[2] = COND_EQ
;
502 dMachine
->CondCodes
[3] = COND_EQ
;
507 * Execute the given vertex program.
508 * NOTE: we do everything in single-precision floating point; we don't
509 * currently observe the single/half/fixed-precision qualifiers.
510 * \param ctx - rendering context
511 * \param program - the fragment program to execute
512 * \param machine - machine state (register file)
513 * \param maxInst - max number of instructions to execute
514 * \return GL_TRUE if program completed or GL_FALSE if program executed KIL.
517 execute_program( GLcontext
*ctx
,
518 const struct fragment_program
*program
, GLuint maxInst
,
519 struct fp_machine
*machine
, const struct sw_span
*span
,
525 printf("execute fragment program --------------------\n");
528 for (pc
= 0; pc
< maxInst
; pc
++) {
529 const struct fp_instruction
*inst
= program
->Instructions
+ pc
;
530 switch (inst
->Opcode
) {
533 GLfloat a
[4], b
[4], result
[4];
534 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
535 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
536 result
[0] = a
[0] + b
[0];
537 result
[1] = a
[1] + b
[1];
538 result
[2] = a
[2] + b
[2];
539 result
[3] = a
[3] + b
[3];
540 store_vector4( inst
, machine
, result
);
545 GLfloat a
[4], result
[4];
546 fetch_vector1( &inst
->SrcReg
[0], machine
, program
, a
);
547 result
[0] = result
[1] = result
[2] = result
[3] = _mesa_cos(a
[0]);
548 store_vector4( inst
, machine
, result
);
551 case FP_OPCODE_DDX
: /* Partial derivative with respect to X */
553 GLfloat a
[4], aNext
[4], result
[4];
554 struct fp_machine dMachine
;
555 if (!fetch_vector4_deriv(&inst
->SrcReg
[0], span
, 'X', result
)) {
556 /* This is tricky. Make a copy of the current machine state,
557 * increment the input registers by the dx or dy partial
558 * derivatives, then re-execute the program up to the
559 * preceeding instruction, then fetch the source register.
560 * Finally, find the difference in the register values for
561 * the original and derivative runs.
563 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
564 init_machine_deriv(ctx
, machine
, program
, span
,
566 execute_program(ctx
, program
, pc
, &dMachine
, span
, column
);
567 fetch_vector4( &inst
->SrcReg
[0], &dMachine
, program
, aNext
);
568 result
[0] = aNext
[0] - a
[0];
569 result
[1] = aNext
[1] - a
[1];
570 result
[2] = aNext
[2] - a
[2];
571 result
[3] = aNext
[3] - a
[3];
573 store_vector4( inst
, machine
, result
);
576 case FP_OPCODE_DDY
: /* Partial derivative with respect to Y */
578 GLfloat a
[4], aNext
[4], result
[4];
579 struct fp_machine dMachine
;
580 if (!fetch_vector4_deriv(&inst
->SrcReg
[0], span
, 'Y', result
)) {
581 init_machine_deriv(ctx
, machine
, program
, span
,
583 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
584 execute_program(ctx
, program
, pc
, &dMachine
, span
, column
);
585 fetch_vector4( &inst
->SrcReg
[0], &dMachine
, program
, aNext
);
586 result
[0] = aNext
[0] - a
[0];
587 result
[1] = aNext
[1] - a
[1];
588 result
[2] = aNext
[2] - a
[2];
589 result
[3] = aNext
[3] - a
[3];
591 store_vector4( inst
, machine
, result
);
596 GLfloat a
[4], b
[4], result
[4];
597 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
598 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
599 result
[0] = result
[1] = result
[2] = result
[3] =
600 a
[0] * b
[0] + a
[1] * b
[1] + a
[2] * b
[2];
601 store_vector4( inst
, machine
, result
);
603 printf("DP3 %g = (%g %g %g) . (%g %g %g)\n",
604 result
[0], a
[0], a
[1], a
[2], b
[0], b
[1], b
[2]);
610 GLfloat a
[4], b
[4], result
[4];
611 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
612 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
613 result
[0] = result
[1] = result
[2] = result
[3] =
614 a
[0] * b
[0] + a
[1] * b
[1] + a
[2] * b
[2] + a
[3] * b
[3];
615 store_vector4( inst
, machine
, result
);
618 case FP_OPCODE_DST
: /* Distance vector */
620 GLfloat a
[4], b
[4], result
[4];
621 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
622 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
624 result
[1] = a
[1] * b
[1];
627 store_vector4( inst
, machine
, result
);
630 case FP_OPCODE_EX2
: /* Exponential base 2 */
632 GLfloat a
[4], result
[4];
633 fetch_vector1( &inst
->SrcReg
[0], machine
, program
, a
);
634 result
[0] = result
[1] = result
[2] = result
[3] =
635 (GLfloat
) _mesa_pow(2.0, a
[0]);
636 store_vector4( inst
, machine
, result
);
641 GLfloat a
[4], result
[4];
642 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
643 result
[0] = FLOORF(a
[0]);
644 result
[1] = FLOORF(a
[1]);
645 result
[2] = FLOORF(a
[2]);
646 result
[3] = FLOORF(a
[3]);
647 store_vector4( inst
, machine
, result
);
652 GLfloat a
[4], result
[4];
653 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
654 result
[0] = a
[0] - FLOORF(a
[0]);
655 result
[1] = a
[1] - FLOORF(a
[1]);
656 result
[2] = a
[2] - FLOORF(a
[2]);
657 result
[3] = a
[3] - FLOORF(a
[3]);
658 store_vector4( inst
, machine
, result
);
663 const GLuint
*swizzle
= inst
->DstReg
.CondSwizzle
;
664 const GLuint condMask
= inst
->DstReg
.CondMask
;
665 if (test_cc(machine
->CondCodes
[swizzle
[0]], condMask
) ||
666 test_cc(machine
->CondCodes
[swizzle
[1]], condMask
) ||
667 test_cc(machine
->CondCodes
[swizzle
[2]], condMask
) ||
668 test_cc(machine
->CondCodes
[swizzle
[3]], condMask
)) {
673 case FP_OPCODE_LG2
: /* log base 2 */
675 GLfloat a
[4], result
[4];
676 fetch_vector1( &inst
->SrcReg
[0], machine
, program
, a
);
677 result
[0] = result
[1] = result
[2] = result
[3]
679 store_vector4( inst
, machine
, result
);
684 GLfloat a
[4], result
[4];
685 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
692 result
[2] = (a
[0] > 0.0) ? _mesa_pow(2.0, a
[3]) : 0.0F
;
694 store_vector4( inst
, machine
, result
);
699 GLfloat a
[4], b
[4], c
[4], result
[4];
700 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
701 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
702 fetch_vector4( &inst
->SrcReg
[2], machine
, program
, c
);
703 result
[0] = a
[0] * b
[0] + (1.0F
- a
[0]) * c
[0];
704 result
[1] = a
[1] * b
[1] + (1.0F
- a
[1]) * c
[1];
705 result
[2] = a
[2] * b
[2] + (1.0F
- a
[2]) * c
[2];
706 result
[3] = a
[3] * b
[3] + (1.0F
- a
[3]) * c
[3];
707 store_vector4( inst
, machine
, result
);
712 GLfloat a
[4], b
[4], c
[4], result
[4];
713 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
714 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
715 fetch_vector4( &inst
->SrcReg
[2], machine
, program
, c
);
716 result
[0] = a
[0] * b
[0] + c
[0];
717 result
[1] = a
[1] * b
[1] + c
[1];
718 result
[2] = a
[2] * b
[2] + c
[2];
719 result
[3] = a
[3] * b
[3] + c
[3];
720 store_vector4( inst
, machine
, result
);
725 GLfloat a
[4], b
[4], result
[4];
726 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
727 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
728 result
[0] = MAX2(a
[0], b
[0]);
729 result
[1] = MAX2(a
[1], b
[1]);
730 result
[2] = MAX2(a
[2], b
[2]);
731 result
[3] = MAX2(a
[3], b
[3]);
732 store_vector4( inst
, machine
, result
);
737 GLfloat a
[4], b
[4], result
[4];
738 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
739 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
740 result
[0] = MIN2(a
[0], b
[0]);
741 result
[1] = MIN2(a
[1], b
[1]);
742 result
[2] = MIN2(a
[2], b
[2]);
743 result
[3] = MIN2(a
[3], b
[3]);
744 store_vector4( inst
, machine
, result
);
750 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, result
);
751 store_vector4( inst
, machine
, result
);
756 GLfloat a
[4], b
[4], result
[4];
757 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
758 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
759 result
[0] = a
[0] * b
[0];
760 result
[1] = a
[1] * b
[1];
761 result
[2] = a
[2] * b
[2];
762 result
[3] = a
[3] * b
[3];
763 store_vector4( inst
, machine
, result
);
765 printf("MUL (%g %g %g %g) = (%g %g %g %g) * (%g %g %g %g)\n",
766 result
[0], result
[1], result
[2], result
[3],
767 a
[0], a
[1], a
[2], a
[3],
768 b
[0], b
[1], b
[2], b
[3]);
772 case FP_OPCODE_PK2H
: /* pack two 16-bit floats */
773 /* XXX this is probably wrong */
775 GLfloat a
[4], result
[4];
776 const GLuint
*rawBits
= (const GLuint
*) a
;
777 GLuint
*rawResult
= (GLuint
*) result
;
778 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
779 rawResult
[0] = rawResult
[1] = rawResult
[2] = rawResult
[3]
780 = rawBits
[0] | (rawBits
[1] << 16);
781 store_vector4( inst
, machine
, result
);
784 case FP_OPCODE_PK2US
: /* pack two GLushorts */
786 GLfloat a
[4], result
[4];
787 GLuint usx
, usy
, *rawResult
= (GLuint
*) result
;
788 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
789 a
[0] = CLAMP(a
[0], 0.0F
, 1.0F
);
790 a
[1] = CLAMP(a
[0], 0.0F
, 1.0F
);
791 usx
= IROUND(a
[0] * 65535.0F
);
792 usy
= IROUND(a
[1] * 65535.0F
);
793 rawResult
[0] = rawResult
[1] = rawResult
[2] = rawResult
[3]
795 store_vector4( inst
, machine
, result
);
798 case FP_OPCODE_PK4B
: /* pack four GLbytes */
800 GLfloat a
[4], result
[4];
801 GLuint ubx
, uby
, ubz
, ubw
, *rawResult
= (GLuint
*) result
;
802 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
803 a
[0] = CLAMP(a
[0], -128.0F
/ 127.0F
, 1.0F
);
804 a
[1] = CLAMP(a
[1], -128.0F
/ 127.0F
, 1.0F
);
805 a
[2] = CLAMP(a
[2], -128.0F
/ 127.0F
, 1.0F
);
806 a
[3] = CLAMP(a
[3], -128.0F
/ 127.0F
, 1.0F
);
807 ubx
= IROUND(127.0F
* a
[0] + 128.0F
);
808 uby
= IROUND(127.0F
* a
[1] + 128.0F
);
809 ubz
= IROUND(127.0F
* a
[2] + 128.0F
);
810 ubw
= IROUND(127.0F
* a
[3] + 128.0F
);
811 rawResult
[0] = rawResult
[1] = rawResult
[2] = rawResult
[3]
812 = ubx
| (uby
<< 8) | (ubz
<< 16) | (ubw
<< 24);
813 store_vector4( inst
, machine
, result
);
816 case FP_OPCODE_PK4UB
: /* pack four GLubytes */
818 GLfloat a
[4], result
[4];
819 GLuint ubx
, uby
, ubz
, ubw
, *rawResult
= (GLuint
*) result
;
820 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
821 a
[0] = CLAMP(a
[0], 0.0F
, 1.0F
);
822 a
[1] = CLAMP(a
[1], 0.0F
, 1.0F
);
823 a
[2] = CLAMP(a
[2], 0.0F
, 1.0F
);
824 a
[3] = CLAMP(a
[3], 0.0F
, 1.0F
);
825 ubx
= IROUND(255.0F
* a
[0]);
826 uby
= IROUND(255.0F
* a
[1]);
827 ubz
= IROUND(255.0F
* a
[2]);
828 ubw
= IROUND(255.0F
* a
[3]);
829 rawResult
[0] = rawResult
[1] = rawResult
[2] = rawResult
[3]
830 = ubx
| (uby
<< 8) | (ubz
<< 16) | (ubw
<< 24);
831 store_vector4( inst
, machine
, result
);
836 GLfloat a
[4], b
[4], result
[4];
837 fetch_vector1( &inst
->SrcReg
[0], machine
, program
, a
);
838 fetch_vector1( &inst
->SrcReg
[1], machine
, program
, b
);
839 result
[0] = result
[1] = result
[2] = result
[3]
840 = _mesa_pow(a
[0], b
[0]);
841 store_vector4( inst
, machine
, result
);
846 GLfloat a
[4], result
[4];
847 fetch_vector1( &inst
->SrcReg
[0], machine
, program
, a
);
851 else if (IS_INF_OR_NAN(a
[0]))
852 printf("RCP(inf)\n");
854 result
[0] = result
[1] = result
[2] = result
[3]
856 store_vector4( inst
, machine
, result
);
861 GLfloat axis
[4], dir
[4], result
[4], tmp
[4];
862 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, axis
);
863 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, dir
);
864 tmp
[3] = axis
[0] * axis
[0]
867 tmp
[0] = (2.0F
* (axis
[0] * dir
[0] +
869 axis
[2] * dir
[2])) / tmp
[3];
870 result
[0] = tmp
[0] * axis
[0] - dir
[0];
871 result
[1] = tmp
[0] * axis
[1] - dir
[1];
872 result
[2] = tmp
[0] * axis
[2] - dir
[2];
873 /* result[3] is never written! XXX enforce in parser! */
874 store_vector4( inst
, machine
, result
);
877 case FP_OPCODE_RSQ
: /* 1 / sqrt() */
879 GLfloat a
[4], result
[4];
880 fetch_vector1( &inst
->SrcReg
[0], machine
, program
, a
);
881 result
[0] = result
[1] = result
[2] = result
[3] = INV_SQRTF(a
[0]);
882 store_vector4( inst
, machine
, result
);
884 printf("RSQ %g = 1/sqrt(%g)\n", result
[0], a
[0]);
888 case FP_OPCODE_SEQ
: /* set on equal */
890 GLfloat a
[4], b
[4], result
[4];
891 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
892 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
893 result
[0] = (a
[0] == b
[0]) ? 1.0F
: 0.0F
;
894 result
[1] = (a
[1] == b
[1]) ? 1.0F
: 0.0F
;
895 result
[2] = (a
[2] == b
[2]) ? 1.0F
: 0.0F
;
896 result
[3] = (a
[3] == b
[3]) ? 1.0F
: 0.0F
;
897 store_vector4( inst
, machine
, result
);
900 case FP_OPCODE_SFL
: /* set false, operands ignored */
902 static const GLfloat result
[4] = { 0.0F
, 0.0F
, 0.0F
, 0.0F
};
903 store_vector4( inst
, machine
, result
);
906 case FP_OPCODE_SGE
: /* set on greater or equal */
908 GLfloat a
[4], b
[4], result
[4];
909 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
910 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
911 result
[0] = (a
[0] >= b
[0]) ? 1.0F
: 0.0F
;
912 result
[1] = (a
[1] >= b
[1]) ? 1.0F
: 0.0F
;
913 result
[2] = (a
[2] >= b
[2]) ? 1.0F
: 0.0F
;
914 result
[3] = (a
[3] >= b
[3]) ? 1.0F
: 0.0F
;
915 store_vector4( inst
, machine
, result
);
918 case FP_OPCODE_SGT
: /* set on greater */
920 GLfloat a
[4], b
[4], result
[4];
921 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
922 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
923 result
[0] = (a
[0] > b
[0]) ? 1.0F
: 0.0F
;
924 result
[1] = (a
[1] > b
[1]) ? 1.0F
: 0.0F
;
925 result
[2] = (a
[2] > b
[2]) ? 1.0F
: 0.0F
;
926 result
[3] = (a
[3] > b
[3]) ? 1.0F
: 0.0F
;
927 store_vector4( inst
, machine
, result
);
932 GLfloat a
[4], result
[4];
933 fetch_vector1( &inst
->SrcReg
[0], machine
, program
, a
);
934 result
[0] = result
[1] = result
[2] = result
[3] = _mesa_sin(a
[0]);
935 store_vector4( inst
, machine
, result
);
938 case FP_OPCODE_SLE
: /* set on less or equal */
940 GLfloat a
[4], b
[4], result
[4];
941 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
942 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
943 result
[0] = (a
[0] <= b
[0]) ? 1.0F
: 0.0F
;
944 result
[1] = (a
[1] <= b
[1]) ? 1.0F
: 0.0F
;
945 result
[2] = (a
[2] <= b
[2]) ? 1.0F
: 0.0F
;
946 result
[3] = (a
[3] <= b
[3]) ? 1.0F
: 0.0F
;
947 store_vector4( inst
, machine
, result
);
950 case FP_OPCODE_SLT
: /* set on less */
952 GLfloat a
[4], b
[4], result
[4];
953 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
954 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
955 result
[0] = (a
[0] < b
[0]) ? 1.0F
: 0.0F
;
956 result
[1] = (a
[1] < b
[1]) ? 1.0F
: 0.0F
;
957 result
[2] = (a
[2] < b
[2]) ? 1.0F
: 0.0F
;
958 result
[3] = (a
[3] < b
[3]) ? 1.0F
: 0.0F
;
959 store_vector4( inst
, machine
, result
);
962 case FP_OPCODE_SNE
: /* set on not equal */
964 GLfloat a
[4], b
[4], result
[4];
965 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
966 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
967 result
[0] = (a
[0] != b
[0]) ? 1.0F
: 0.0F
;
968 result
[1] = (a
[1] != b
[1]) ? 1.0F
: 0.0F
;
969 result
[2] = (a
[2] != b
[2]) ? 1.0F
: 0.0F
;
970 result
[3] = (a
[3] != b
[3]) ? 1.0F
: 0.0F
;
971 store_vector4( inst
, machine
, result
);
974 case FP_OPCODE_STR
: /* set true, operands ignored */
976 static const GLfloat result
[4] = { 1.0F
, 1.0F
, 1.0F
, 1.0F
};
977 store_vector4( inst
, machine
, result
);
982 GLfloat a
[4], b
[4], result
[4];
983 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
984 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
985 result
[0] = a
[0] - b
[0];
986 result
[1] = a
[1] - b
[1];
987 result
[2] = a
[2] - b
[2];
988 result
[3] = a
[3] - b
[3];
989 store_vector4( inst
, machine
, result
);
995 GLfloat texcoord
[4], color
[4];
996 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, texcoord
);
997 /* XXX: Undo perspective divide from interpolate_texcoords() */
998 fetch_texel( ctx
, texcoord
,
999 span
->array
->lambda
[inst
->TexSrcUnit
][column
],
1000 inst
->TexSrcUnit
, color
);
1001 store_vector4( inst
, machine
, color
);
1005 /* Texture lookup w/ partial derivatives for LOD */
1007 GLfloat texcoord
[4], dtdx
[4], dtdy
[4], color
[4];
1008 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, texcoord
);
1009 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, dtdx
);
1010 fetch_vector4( &inst
->SrcReg
[2], machine
, program
, dtdy
);
1011 fetch_texel_deriv( ctx
, texcoord
, dtdx
, dtdy
, inst
->TexSrcUnit
,
1013 store_vector4( inst
, machine
, color
);
1017 /* Texture lookup w/ perspective divide */
1019 GLfloat texcoord
[4], color
[4];
1020 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, texcoord
);
1021 /* Already did perspective divide in interpolate_texcoords() */
1022 fetch_texel( ctx
, texcoord
,
1023 span
->array
->lambda
[inst
->TexSrcUnit
][column
],
1024 inst
->TexSrcUnit
, color
);
1025 store_vector4( inst
, machine
, color
);
1028 case FP_OPCODE_UP2H
: /* unpack two 16-bit floats */
1029 /* XXX this is probably wrong */
1031 GLfloat a
[4], result
[4];
1032 const GLuint
*rawBits
= (const GLuint
*) a
;
1033 GLuint
*rawResult
= (GLuint
*) result
;
1034 fetch_vector1( &inst
->SrcReg
[0], machine
, program
, a
);
1035 rawResult
[0] = rawBits
[0] & 0xffff;
1036 rawResult
[1] = (rawBits
[0] >> 16) & 0xffff;
1037 rawResult
[2] = rawBits
[0] & 0xffff;
1038 rawResult
[3] = (rawBits
[0] >> 16) & 0xffff;
1039 store_vector4( inst
, machine
, result
);
1042 case FP_OPCODE_UP2US
: /* unpack two GLushorts */
1044 GLfloat a
[4], result
[4];
1045 const GLuint
*rawBits
= (const GLuint
*) a
;
1046 fetch_vector1( &inst
->SrcReg
[0], machine
, program
, a
);
1047 result
[0] = (GLfloat
) ((rawBits
[0] >> 0) & 0xffff) / 65535.0F
;
1048 result
[1] = (GLfloat
) ((rawBits
[0] >> 16) & 0xffff) / 65535.0F
;
1049 result
[2] = result
[0];
1050 result
[3] = result
[1];
1051 store_vector4( inst
, machine
, result
);
1054 case FP_OPCODE_UP4B
: /* unpack four GLbytes */
1056 GLfloat a
[4], result
[4];
1057 const GLuint
*rawBits
= (const GLuint
*) a
;
1058 fetch_vector1( &inst
->SrcReg
[0], machine
, program
, a
);
1059 result
[0] = (((rawBits
[0] >> 0) & 0xff) - 128) / 127.0F
;
1060 result
[0] = (((rawBits
[0] >> 8) & 0xff) - 128) / 127.0F
;
1061 result
[0] = (((rawBits
[0] >> 16) & 0xff) - 128) / 127.0F
;
1062 result
[0] = (((rawBits
[0] >> 24) & 0xff) - 128) / 127.0F
;
1063 store_vector4( inst
, machine
, result
);
1066 case FP_OPCODE_UP4UB
: /* unpack four GLubytes */
1068 GLfloat a
[4], result
[4];
1069 const GLuint
*rawBits
= (const GLuint
*) a
;
1070 fetch_vector1( &inst
->SrcReg
[0], machine
, program
, a
);
1071 result
[0] = ((rawBits
[0] >> 0) & 0xff) / 255.0F
;
1072 result
[0] = ((rawBits
[0] >> 8) & 0xff) / 255.0F
;
1073 result
[0] = ((rawBits
[0] >> 16) & 0xff) / 255.0F
;
1074 result
[0] = ((rawBits
[0] >> 24) & 0xff) / 255.0F
;
1075 store_vector4( inst
, machine
, result
);
1078 case FP_OPCODE_X2D
: /* 2-D matrix transform */
1080 GLfloat a
[4], b
[4], c
[4], result
[4];
1081 fetch_vector4( &inst
->SrcReg
[0], machine
, program
, a
);
1082 fetch_vector4( &inst
->SrcReg
[1], machine
, program
, b
);
1083 fetch_vector4( &inst
->SrcReg
[2], machine
, program
, c
);
1084 result
[0] = a
[0] + b
[0] * c
[0] + b
[1] * c
[1];
1085 result
[1] = a
[1] + b
[0] * c
[2] + b
[1] * c
[3];
1086 result
[2] = a
[2] + b
[0] * c
[0] + b
[1] * c
[1];
1087 result
[3] = a
[3] + b
[0] * c
[2] + b
[1] * c
[3];
1088 store_vector4( inst
, machine
, result
);
1094 _mesa_problem(ctx
, "Bad opcode %d in _mesa_exec_fragment_program",
1096 return GL_TRUE
; /* return value doesn't matter */
1104 init_machine( GLcontext
*ctx
, struct fp_machine
*machine
,
1105 const struct fragment_program
*program
,
1106 const struct sw_span
*span
, GLuint col
)
1110 /* Clear temporary registers */
1111 _mesa_bzero(machine
->Registers
+ FP_TEMP_REG_START
,
1112 MAX_NV_FRAGMENT_PROGRAM_TEMPS
* 4 * sizeof(GLfloat
));
1114 /* Load program local parameters */
1115 for (j
= 0; j
< MAX_NV_FRAGMENT_PROGRAM_PARAMS
; j
++) {
1116 COPY_4V(machine
->Registers
[FP_PROG_REG_START
+ j
],
1117 program
->Base
.LocalParams
[j
]);
1120 /* Load input registers */
1121 if (program
->InputsRead
& (1 << FRAG_ATTRIB_WPOS
)) {
1122 GLfloat
*wpos
= machine
->Registers
[FP_INPUT_REG_START
+FRAG_ATTRIB_WPOS
];
1123 wpos
[0] = span
->x
+ col
;
1125 wpos
[2] = (GLfloat
) span
->array
->z
[col
] / ctx
->DepthMaxF
;
1126 wpos
[3] = span
->w
+ col
* span
->dwdx
;
1128 if (program
->InputsRead
& (1 << FRAG_ATTRIB_COL0
)) {
1129 GLfloat
*col0
= machine
->Registers
[FP_INPUT_REG_START
+FRAG_ATTRIB_COL0
];
1130 col0
[0] = CHAN_TO_FLOAT(span
->array
->rgba
[col
][RCOMP
]);
1131 col0
[1] = CHAN_TO_FLOAT(span
->array
->rgba
[col
][GCOMP
]);
1132 col0
[2] = CHAN_TO_FLOAT(span
->array
->rgba
[col
][BCOMP
]);
1133 col0
[3] = CHAN_TO_FLOAT(span
->array
->rgba
[col
][ACOMP
]);
1135 if (program
->InputsRead
& (1 << FRAG_ATTRIB_COL1
)) {
1136 GLfloat
*col1
= machine
->Registers
[FP_INPUT_REG_START
+FRAG_ATTRIB_COL1
];
1137 col1
[0] = CHAN_TO_FLOAT(span
->array
->spec
[col
][RCOMP
]);
1138 col1
[1] = CHAN_TO_FLOAT(span
->array
->spec
[col
][GCOMP
]);
1139 col1
[2] = CHAN_TO_FLOAT(span
->array
->spec
[col
][BCOMP
]);
1140 col1
[3] = CHAN_TO_FLOAT(span
->array
->spec
[col
][ACOMP
]);
1142 if (program
->InputsRead
& (1 << FRAG_ATTRIB_FOGC
)) {
1143 GLfloat
*fogc
= machine
->Registers
[FP_INPUT_REG_START
+FRAG_ATTRIB_FOGC
];
1144 fogc
[0] = span
->array
->fog
[col
];
1149 for (u
= 0; u
< ctx
->Const
.MaxTextureCoordUnits
; u
++) {
1150 if (program
->InputsRead
& (1 << (FRAG_ATTRIB_TEX0
+ u
))) {
1151 GLfloat
*tex
= machine
->Registers
[FP_INPUT_REG_START
+FRAG_ATTRIB_TEX0
+u
];
1152 ASSERT(ctx
->Texture
._EnabledCoordUnits
& (1 << u
));
1153 COPY_4V(tex
, span
->array
->texcoords
[u
][col
]);
1154 ASSERT(tex
[0] != 0 || tex
[1] != 0 || tex
[2] != 0);
1158 /* init condition codes */
1159 machine
->CondCodes
[0] = COND_EQ
;
1160 machine
->CondCodes
[1] = COND_EQ
;
1161 machine
->CondCodes
[2] = COND_EQ
;
1162 machine
->CondCodes
[3] = COND_EQ
;
1167 _swrast_exec_nv_fragment_program( GLcontext
*ctx
, struct sw_span
*span
)
1169 const struct fragment_program
*program
= ctx
->FragmentProgram
.Current
;
1172 for (i
= 0; i
< span
->end
; i
++) {
1173 if (span
->array
->mask
[i
]) {
1174 init_machine(ctx
, &ctx
->FragmentProgram
.Machine
,
1175 ctx
->FragmentProgram
.Current
, span
, i
);
1177 if (!execute_program(ctx
, program
, ~0,
1178 &ctx
->FragmentProgram
.Machine
, span
, i
)) {
1179 span
->array
->mask
[i
] = GL_FALSE
; /* killed fragment */
1182 /* Store output registers */
1184 const GLfloat
*colOut
1185 = ctx
->FragmentProgram
.Machine
.Registers
[FP_OUTPUT_REG_START
];
1186 UNCLAMPED_FLOAT_TO_CHAN(span
->array
->rgba
[i
][RCOMP
], colOut
[0]);
1187 UNCLAMPED_FLOAT_TO_CHAN(span
->array
->rgba
[i
][GCOMP
], colOut
[1]);
1188 UNCLAMPED_FLOAT_TO_CHAN(span
->array
->rgba
[i
][BCOMP
], colOut
[2]);
1189 UNCLAMPED_FLOAT_TO_CHAN(span
->array
->rgba
[i
][ACOMP
], colOut
[3]);
1192 if (program
->OutputsWritten
& (1 << FRAG_OUTPUT_DEPR
))
1193 span
->array
->z
[i
] = IROUND(ctx
->FragmentProgram
.Machine
.Registers
[FP_OUTPUT_REG_START
+ 2][0] * ctx
->DepthMaxF
);