-/* $Id: s_nvfragprog.c,v 1.12 2003/03/25 02:23:47 brianp Exp $ */
+/* $Id: s_nvfragprog.c,v 1.13 2003/04/05 00:38:10 brianp Exp $ */
/*
* Mesa 3-D graphics library
static void
fetch_vector4( const struct fp_src_register *source,
const struct fp_machine *machine,
+ const struct fragment_program *program,
GLfloat result[4] )
{
- const GLfloat *src = machine->Registers[source->Register];
+ const GLfloat *src;
+
+ if (source->IsParameter) {
+ src = program->Parameters[source->Register].Values;
+ }
+ else {
+ src = machine->Registers[source->Register];
+ }
result[0] = src[source->Swizzle[0]];
result[1] = src[source->Swizzle[1]];
static void
fetch_vector1( const struct fp_src_register *source,
const struct fp_machine *machine,
+ const struct fragment_program *program,
GLfloat result[4] )
{
- const GLfloat *src = machine->Registers[source->Register];
+ const GLfloat *src;
+
+ if (source->IsParameter) {
+ src = program->Parameters[source->Register].Values;
+ }
+ else {
+ src = machine->Registers[source->Register];
+ }
result[0] = src[source->Swizzle[0]];
case FP_OPCODE_ADD:
{
GLfloat a[4], b[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
result[0] = a[0] + b[0];
result[1] = a[1] + b[1];
result[2] = a[2] + b[2];
case FP_OPCODE_COS:
{
GLfloat a[4], result[4];
- fetch_vector1( &inst->SrcReg[0], machine, a );
+ fetch_vector1( &inst->SrcReg[0], machine, program, a );
result[0] = result[1] = result[2] = result[3] = _mesa_cos(a[0]);
store_vector4( inst, machine, result );
}
init_machine_deriv(ctx, machine, program, span,
'X', &dMachine);
execute_program(ctx, program, pc, &dMachine, span);
- fetch_vector4( &inst->SrcReg[0], &dMachine, aNext );
+ fetch_vector4( &inst->SrcReg[0], &dMachine, program, aNext );
result[0] = aNext[0] - a[0];
result[1] = aNext[1] - a[1];
result[2] = aNext[2] - a[2];
init_machine_deriv(ctx, machine, program, span,
'Y', &dMachine);
execute_program(ctx, program, pc, &dMachine, span);
- fetch_vector4( &inst->SrcReg[0], &dMachine, aNext );
+ fetch_vector4( &inst->SrcReg[0], &dMachine, program, aNext );
result[0] = aNext[0] - a[0];
result[1] = aNext[1] - a[1];
result[2] = aNext[2] - a[2];
case FP_OPCODE_DP3:
{
GLfloat a[4], b[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
result[0] = result[1] = result[2] = result[3] =
a[0] + b[0] + a[1] * b[1] + a[2] * b[2];
store_vector4( inst, machine, result );
case FP_OPCODE_DP4:
{
GLfloat a[4], b[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
result[0] = result[1] = result[2] = result[3] =
a[0] + b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
store_vector4( inst, machine, result );
case FP_OPCODE_DST: /* Distance vector */
{
GLfloat a[4], b[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
result[0] = 1.0F;
result[1] = a[1] * b[1];
result[2] = a[2];
case FP_OPCODE_EX2: /* Exponential base 2 */
{
GLfloat a[4], result[4];
- fetch_vector1( &inst->SrcReg[0], machine, a );
+ fetch_vector1( &inst->SrcReg[0], machine, program, a );
result[0] = result[1] = result[2] = result[3] =
(GLfloat) _mesa_pow(2.0, a[0]);
store_vector4( inst, machine, result );
case FP_OPCODE_FLR:
{
GLfloat a[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
result[0] = FLOORF(a[0]);
result[1] = FLOORF(a[1]);
result[2] = FLOORF(a[2]);
case FP_OPCODE_FRC:
{
GLfloat a[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
result[0] = a[0] - FLOORF(a[0]);
result[1] = a[1] - FLOORF(a[1]);
result[2] = a[2] - FLOORF(a[2]);
case FP_OPCODE_LG2: /* log base 2 */
{
GLfloat a[4], result[4];
- fetch_vector1( &inst->SrcReg[0], machine, a );
+ fetch_vector1( &inst->SrcReg[0], machine, program, a );
result[0] = result[1] = result[2] = result[3]
= LOG2(a[0]);
store_vector4( inst, machine, result );
case FP_OPCODE_LIT:
{
GLfloat a[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
if (a[0] < 0.0F)
a[0] = 0.0F;
if (a[1] < 0.0F)
case FP_OPCODE_LRP:
{
GLfloat a[4], b[4], c[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
- fetch_vector4( &inst->SrcReg[2], machine, c );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
+ fetch_vector4( &inst->SrcReg[2], machine, program, c );
result[0] = a[0] * b[0] + (1.0F - a[0]) * c[0];
result[1] = a[1] * b[1] + (1.0F - a[1]) * c[1];
result[2] = a[2] * b[2] + (1.0F - a[2]) * c[2];
case FP_OPCODE_MAD:
{
GLfloat a[4], b[4], c[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
- fetch_vector4( &inst->SrcReg[2], machine, c );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
+ fetch_vector4( &inst->SrcReg[2], machine, program, c );
result[0] = a[0] * b[0] + c[0];
result[1] = a[1] * b[1] + c[1];
result[2] = a[2] * b[2] + c[2];
case FP_OPCODE_MAX:
{
GLfloat a[4], b[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
result[0] = MAX2(a[0], b[0]);
result[1] = MAX2(a[1], b[1]);
result[2] = MAX2(a[2], b[2]);
case FP_OPCODE_MIN:
{
GLfloat a[4], b[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
result[0] = MIN2(a[0], b[0]);
result[1] = MIN2(a[1], b[1]);
result[2] = MIN2(a[2], b[2]);
case FP_OPCODE_MOV:
{
GLfloat result[4];
- fetch_vector4( &inst->SrcReg[0], machine, result );
+ fetch_vector4( &inst->SrcReg[0], machine, program, result );
store_vector4( inst, machine, result );
}
break;
case FP_OPCODE_MUL:
{
GLfloat a[4], b[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
result[0] = a[0] * b[0];
result[1] = a[1] * b[1];
result[2] = a[2] * b[2];
GLfloat a[4], result[4];
const GLuint *rawBits = (const GLuint *) a;
GLuint *rawResult = (GLuint *) result;
- fetch_vector4( &inst->SrcReg[0], machine, a );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
rawResult[0] = rawResult[1] = rawResult[2] = rawResult[3]
= rawBits[0] | (rawBits[1] << 16);
store_vector4( inst, machine, result );
{
GLfloat a[4], result[4];
GLuint usx, usy, *rawResult = (GLuint *) result;
- fetch_vector4( &inst->SrcReg[0], machine, a );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
a[0] = CLAMP(a[0], 0.0F, 1.0F);
a[1] = CLAMP(a[0], 0.0F, 1.0F);
usx = IROUND(a[0] * 65535.0F);
{
GLfloat a[4], result[4];
GLuint ubx, uby, ubz, ubw, *rawResult = (GLuint *) result;
- fetch_vector4( &inst->SrcReg[0], machine, a );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
a[0] = CLAMP(a[0], -128.0F / 127.0F, 1.0F);
a[1] = CLAMP(a[1], -128.0F / 127.0F, 1.0F);
a[2] = CLAMP(a[2], -128.0F / 127.0F, 1.0F);
{
GLfloat a[4], result[4];
GLuint ubx, uby, ubz, ubw, *rawResult = (GLuint *) result;
- fetch_vector4( &inst->SrcReg[0], machine, a );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
a[0] = CLAMP(a[0], 0.0F, 1.0F);
a[1] = CLAMP(a[1], 0.0F, 1.0F);
a[2] = CLAMP(a[2], 0.0F, 1.0F);
case FP_OPCODE_POW:
{
GLfloat a[4], b[4], result[4];
- fetch_vector1( &inst->SrcReg[0], machine, a );
- fetch_vector1( &inst->SrcReg[1], machine, b );
+ fetch_vector1( &inst->SrcReg[0], machine, program, a );
+ fetch_vector1( &inst->SrcReg[1], machine, program, b );
result[0] = result[1] = result[2] = result[3]
= _mesa_pow(a[0], b[0]);
store_vector4( inst, machine, result );
case FP_OPCODE_RCP:
{
GLfloat a[4], result[4];
- fetch_vector1( &inst->SrcReg[0], machine, a );
+ fetch_vector1( &inst->SrcReg[0], machine, program, a );
result[0] = result[1] = result[2] = result[3]
= 1.0F / a[0];
store_vector4( inst, machine, result );
case FP_OPCODE_RFL:
{
GLfloat axis[4], dir[4], result[4], tmp[4];
- fetch_vector4( &inst->SrcReg[0], machine, axis );
- fetch_vector4( &inst->SrcReg[1], machine, dir );
+ fetch_vector4( &inst->SrcReg[0], machine, program, axis );
+ fetch_vector4( &inst->SrcReg[1], machine, program, dir );
tmp[3] = axis[0] * axis[0]
+ axis[1] * axis[1]
+ axis[2] * axis[2];
case FP_OPCODE_RSQ: /* 1 / sqrt() */
{
GLfloat a[4], result[4];
- fetch_vector1( &inst->SrcReg[0], machine, a );
+ fetch_vector1( &inst->SrcReg[0], machine, program, a );
result[0] = result[1] = result[2] = result[3] = INV_SQRTF(a[0]);
store_vector4( inst, machine, result );
}
case FP_OPCODE_SEQ: /* set on equal */
{
GLfloat a[4], b[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
result[0] = (a[0] == b[0]) ? 1.0F : 0.0F;
result[1] = (a[1] == b[1]) ? 1.0F : 0.0F;
result[2] = (a[2] == b[2]) ? 1.0F : 0.0F;
case FP_OPCODE_SGE: /* set on greater or equal */
{
GLfloat a[4], b[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
result[0] = (a[0] >= b[0]) ? 1.0F : 0.0F;
result[1] = (a[1] >= b[1]) ? 1.0F : 0.0F;
result[2] = (a[2] >= b[2]) ? 1.0F : 0.0F;
case FP_OPCODE_SGT: /* set on greater */
{
GLfloat a[4], b[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
result[0] = (a[0] > b[0]) ? 1.0F : 0.0F;
result[1] = (a[1] > b[1]) ? 1.0F : 0.0F;
result[2] = (a[2] > b[2]) ? 1.0F : 0.0F;
case FP_OPCODE_SIN:
{
GLfloat a[4], result[4];
- fetch_vector1( &inst->SrcReg[0], machine, a );
+ fetch_vector1( &inst->SrcReg[0], machine, program, a );
result[0] = result[1] = result[2] = result[3] = _mesa_sin(a[0]);
store_vector4( inst, machine, result );
}
case FP_OPCODE_SLE: /* set on less or equal */
{
GLfloat a[4], b[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
result[0] = (a[0] <= b[0]) ? 1.0F : 0.0F;
result[1] = (a[1] <= b[1]) ? 1.0F : 0.0F;
result[2] = (a[2] <= b[2]) ? 1.0F : 0.0F;
case FP_OPCODE_SLT: /* set on less */
{
GLfloat a[4], b[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
result[0] = (a[0] < b[0]) ? 1.0F : 0.0F;
result[1] = (a[1] < b[1]) ? 1.0F : 0.0F;
result[2] = (a[2] < b[2]) ? 1.0F : 0.0F;
case FP_OPCODE_SNE: /* set on not equal */
{
GLfloat a[4], b[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
result[0] = (a[0] != b[0]) ? 1.0F : 0.0F;
result[1] = (a[1] != b[1]) ? 1.0F : 0.0F;
result[2] = (a[2] != b[2]) ? 1.0F : 0.0F;
case FP_OPCODE_SUB:
{
GLfloat a[4], b[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
result[0] = a[0] - b[0];
result[1] = a[1] - b[1];
result[2] = a[2] - b[2];
/* Texel lookup */
{
GLfloat texcoord[4], color[4];
- fetch_vector4( &inst->SrcReg[0], machine, texcoord );
+ fetch_vector4( &inst->SrcReg[0], machine, program, texcoord );
/* XXX: Undo perspective divide from interpolate_texcoords() */
fetch_texel( ctx, texcoord, inst->TexSrcUnit, color );
store_vector4( inst, machine, color );
/* Texture lookup w/ partial derivatives for LOD */
{
GLfloat texcoord[4], dtdx[4], dtdy[4], color[4];
- fetch_vector4( &inst->SrcReg[0], machine, texcoord );
- fetch_vector4( &inst->SrcReg[1], machine, dtdx );
- fetch_vector4( &inst->SrcReg[2], machine, dtdy );
+ fetch_vector4( &inst->SrcReg[0], machine, program, texcoord );
+ fetch_vector4( &inst->SrcReg[1], machine, program, dtdx );
+ fetch_vector4( &inst->SrcReg[2], machine, program, dtdy );
fetch_texel_deriv( ctx, texcoord, dtdx, dtdy, inst->TexSrcUnit,
color );
store_vector4( inst, machine, color );
/* Texture lookup w/ perspective divide */
{
GLfloat texcoord[4], color[4];
- fetch_vector4( &inst->SrcReg[0], machine, texcoord );
+ fetch_vector4( &inst->SrcReg[0], machine, program, texcoord );
/* Already did perspective divide in interpolate_texcoords() */
fetch_texel( ctx, texcoord, inst->TexSrcUnit, color );
store_vector4( inst, machine, color );
GLfloat a[4], result[4];
const GLuint *rawBits = (const GLuint *) a;
GLuint *rawResult = (GLuint *) result;
- fetch_vector1( &inst->SrcReg[0], machine, a );
+ fetch_vector1( &inst->SrcReg[0], machine, program, a );
rawResult[0] = rawBits[0] & 0xffff;
rawResult[1] = (rawBits[0] >> 16) & 0xffff;
rawResult[2] = rawBits[0] & 0xffff;
{
GLfloat a[4], result[4];
const GLuint *rawBits = (const GLuint *) a;
- fetch_vector1( &inst->SrcReg[0], machine, a );
+ fetch_vector1( &inst->SrcReg[0], machine, program, a );
result[0] = (GLfloat) ((rawBits[0] >> 0) & 0xffff) / 65535.0F;
result[1] = (GLfloat) ((rawBits[0] >> 16) & 0xffff) / 65535.0F;
result[2] = result[0];
{
GLfloat a[4], result[4];
const GLuint *rawBits = (const GLuint *) a;
- fetch_vector1( &inst->SrcReg[0], machine, a );
+ fetch_vector1( &inst->SrcReg[0], machine, program, a );
result[0] = (((rawBits[0] >> 0) & 0xff) - 128) / 127.0F;
result[0] = (((rawBits[0] >> 8) & 0xff) - 128) / 127.0F;
result[0] = (((rawBits[0] >> 16) & 0xff) - 128) / 127.0F;
{
GLfloat a[4], result[4];
const GLuint *rawBits = (const GLuint *) a;
- fetch_vector1( &inst->SrcReg[0], machine, a );
+ fetch_vector1( &inst->SrcReg[0], machine, program, a );
result[0] = ((rawBits[0] >> 0) & 0xff) / 255.0F;
result[0] = ((rawBits[0] >> 8) & 0xff) / 255.0F;
result[0] = ((rawBits[0] >> 16) & 0xff) / 255.0F;
case FP_OPCODE_X2D: /* 2-D matrix transform */
{
GLfloat a[4], b[4], c[4], result[4];
- fetch_vector4( &inst->SrcReg[0], machine, a );
- fetch_vector4( &inst->SrcReg[1], machine, b );
- fetch_vector4( &inst->SrcReg[2], machine, c );
+ fetch_vector4( &inst->SrcReg[0], machine, program, a );
+ fetch_vector4( &inst->SrcReg[1], machine, program, b );
+ fetch_vector4( &inst->SrcReg[2], machine, program, c );
result[0] = a[0] + b[0] * c[0] + b[1] * c[1];
result[1] = a[1] + b[0] * c[2] + b[1] * c[3];
result[2] = a[2] + b[0] * c[0] + b[1] * c[1];