/*
* Mesa 3-D graphics library
- * Version: 6.1
+ * Version: 6.5
*
- * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
#include "macros.h"
#include "mtypes.h"
#include "nvvertexec.h"
-#include "nvvertprog.h"
+#include "program_instruction.h"
#include "program.h"
#include "math/m_matrix.h"
{
/* Input registers get initialized from the current vertex attribs */
MEMCPY(ctx->VertexProgram.Inputs, ctx->Current.Attrib,
- VERT_ATTRIB_MAX * 4 * sizeof(GLfloat));
+ MAX_VERTEX_PROGRAM_ATTRIBS * 4 * sizeof(GLfloat));
if (ctx->VertexProgram.Current->IsNVProgram) {
GLuint i;
}
else if (ctx->VertexProgram.TrackMatrixTransform[i] == GL_INVERSE_NV) {
_math_matrix_analyse(mat); /* update the inverse */
- assert((mat->flags & MAT_DIRTY_INVERSE) == 0);
+ ASSERT(!_math_matrix_is_dirty(mat));
load_matrix(ctx->VertexProgram.Parameters, i*4, mat->inv);
}
else if (ctx->VertexProgram.TrackMatrixTransform[i] == GL_TRANSPOSE_NV) {
assert(ctx->VertexProgram.TrackMatrixTransform[i]
== GL_INVERSE_TRANSPOSE_NV);
_math_matrix_analyse(mat); /* update the inverse */
- assert((mat->flags & MAT_DIRTY_INVERSE) == 0);
+ ASSERT(!_math_matrix_is_dirty(mat));
load_transpose_matrix(ctx->VertexProgram.Parameters, i*4, mat->inv);
}
}
}
else {
/* Using and ARB vertex program */
- if (ctx->VertexProgram.Current->Parameters) {
+ if (ctx->VertexProgram.Current->Base.Parameters) {
/* Grab the state GL state and put into registers */
_mesa_load_state_parameters(ctx,
- ctx->VertexProgram.Current->Parameters);
+ ctx->VertexProgram.Current->Base.Parameters);
}
}
}
* For debugging. Dump the current vertex program machine registers.
*/
void
-_mesa_dump_vp_state( const struct vertex_program_state *state )
+_mesa_dump_vp_state( const struct gl_vertex_program_state *state )
{
int i;
_mesa_printf("VertexIn:\n");
* source register.
*/
static INLINE const GLfloat *
-get_register_pointer( const struct vp_src_register *source,
- const struct vertex_program_state *state )
+get_register_pointer( const struct prog_src_register *source,
+ const struct gl_vertex_program_state *state )
{
if (source->RelAddr) {
const GLint reg = source->Index + state->AddressReg[0];
else if (source->File == PROGRAM_ENV_PARAM)
return state->Parameters[reg];
else
- return state->Current->Parameters->Parameters[reg].Values;
+ return state->Current->Base.Parameters->ParameterValues[reg];
}
else {
switch (source->File) {
case PROGRAM_INPUT:
ASSERT(source->Index < MAX_NV_VERTEX_PROGRAM_INPUTS);
return state->Inputs[source->Index];
+ case PROGRAM_OUTPUT:
+ /* This is only needed for the PRINT instruction */
+ ASSERT(source->Index < MAX_NV_VERTEX_PROGRAM_OUTPUTS);
+ return state->Outputs[source->Index];
case PROGRAM_LOCAL_PARAM:
ASSERT(source->Index < MAX_PROGRAM_LOCAL_PARAMS);
return state->Current->Base.LocalParams[source->Index];
ASSERT(source->Index < MAX_NV_VERTEX_PROGRAM_PARAMS);
return state->Parameters[source->Index];
case PROGRAM_STATE_VAR:
- ASSERT(source->Index < state->Current->Parameters->NumParameters);
- return state->Current->Parameters->Parameters[source->Index].Values;
+ ASSERT(source->Index < state->Current->Base.Parameters->NumParameters);
+ return state->Current->Base.Parameters->ParameterValues[source->Index];
default:
_mesa_problem(NULL,
"Bad source register file in get_register_pointer");
* Apply swizzling and negating as needed.
*/
static INLINE void
-fetch_vector4( const struct vp_src_register *source,
- const struct vertex_program_state *state,
+fetch_vector4( const struct prog_src_register *source,
+ const struct gl_vertex_program_state *state,
GLfloat result[4] )
{
const GLfloat *src = get_register_pointer(source, state);
- if (source->Negate) {
- result[0] = -src[source->Swizzle[0]];
- result[1] = -src[source->Swizzle[1]];
- result[2] = -src[source->Swizzle[2]];
- result[3] = -src[source->Swizzle[3]];
+ if (source->NegateBase) {
+ result[0] = -src[GET_SWZ(source->Swizzle, 0)];
+ result[1] = -src[GET_SWZ(source->Swizzle, 1)];
+ result[2] = -src[GET_SWZ(source->Swizzle, 2)];
+ result[3] = -src[GET_SWZ(source->Swizzle, 3)];
}
else {
- result[0] = src[source->Swizzle[0]];
- result[1] = src[source->Swizzle[1]];
- result[2] = src[source->Swizzle[2]];
- result[3] = src[source->Swizzle[3]];
+ result[0] = src[GET_SWZ(source->Swizzle, 0)];
+ result[1] = src[GET_SWZ(source->Swizzle, 1)];
+ result[2] = src[GET_SWZ(source->Swizzle, 2)];
+ result[3] = src[GET_SWZ(source->Swizzle, 3)];
}
}
* As above, but only return result[0] element.
*/
static INLINE void
-fetch_vector1( const struct vp_src_register *source,
- const struct vertex_program_state *state,
+fetch_vector1( const struct prog_src_register *source,
+ const struct gl_vertex_program_state *state,
GLfloat result[4] )
{
const GLfloat *src = get_register_pointer(source, state);
- if (source->Negate) {
- result[0] = -src[source->Swizzle[0]];
+ if (source->NegateBase) {
+ result[0] = -src[GET_SWZ(source->Swizzle, 0)];
}
else {
- result[0] = src[source->Swizzle[0]];
+ result[0] = src[GET_SWZ(source->Swizzle, 0)];
}
}
* Store 4 floats into a register.
*/
static void
-store_vector4( const struct vp_dst_register *dest,
- struct vertex_program_state *state,
+store_vector4( const struct prog_dst_register *dest,
+ struct gl_vertex_program_state *state,
const GLfloat value[4] )
{
GLfloat *dst;
return;
}
- if (dest->WriteMask[0])
+ if (dest->WriteMask & WRITEMASK_X)
dst[0] = value[0];
- if (dest->WriteMask[1])
+ if (dest->WriteMask & WRITEMASK_Y)
dst[1] = value[1];
- if (dest->WriteMask[2])
+ if (dest->WriteMask & WRITEMASK_Z)
dst[2] = value[2];
- if (dest->WriteMask[3])
+ if (dest->WriteMask & WRITEMASK_W)
dst[3] = value[3];
}
* Set x to positive or negative infinity.
*/
#if defined(USE_IEEE) || defined(_WIN32)
-#define SET_POS_INFINITY(x) ( *((GLuint *) &x) = 0x7F800000 )
-#define SET_NEG_INFINITY(x) ( *((GLuint *) &x) = 0xFF800000 )
+#define SET_POS_INFINITY(x) ( *((GLuint *) (void *)&x) = 0x7F800000 )
+#define SET_NEG_INFINITY(x) ( *((GLuint *) (void *)&x) = 0xFF800000 )
#elif defined(VMS)
#define SET_POS_INFINITY(x) x = __MAXFLOAT
#define SET_NEG_INFINITY(x) x = -__MAXFLOAT
#define SET_NEG_INFINITY(x) x = (GLfloat) -HUGE_VAL
#endif
-#define SET_FLOAT_BITS(x, bits) ((fi_type *) &(x))->i = bits
+#define SET_FLOAT_BITS(x, bits) ((fi_type *) (void *) &(x))->i = bits
/**
* Execute the given vertex program
*/
void
-_mesa_exec_vertex_program(GLcontext *ctx, const struct vertex_program *program)
+_mesa_exec_vertex_program(GLcontext *ctx, const struct gl_vertex_program *program)
{
- struct vertex_program_state *state = &ctx->VertexProgram;
- const struct vp_instruction *inst;
+ struct gl_vertex_program_state *state = &ctx->VertexProgram;
+ const struct prog_instruction *inst;
ctx->_CurrentProgram = GL_VERTEX_PROGRAM_ARB; /* or NV, doesn't matter */
- /* If the program is position invariant, multiply the input
- * position and the MVP matrix and stick it into the output pos slot
+ /* If the program is position invariant, multiply the input position
+ * by the MVP matrix and store in the vertex position result register.
*/
if (ctx->VertexProgram.Current->IsPositionInvariant) {
- TRANSFORM_POINT( ctx->VertexProgram.Outputs[0],
+ TRANSFORM_POINT( ctx->VertexProgram.Outputs[VERT_RESULT_HPOS],
ctx->_ModelProjectMatrix.m,
- ctx->VertexProgram.Inputs[0]);
+ ctx->VertexProgram.Inputs[VERT_ATTRIB_POS]);
/* XXX: This could go elsewhere */
- ctx->VertexProgram.Current->OutputsWritten |= 0x1;
+ ctx->VertexProgram.Current->Base.OutputsWritten |= VERT_BIT_POS;
}
- for (inst = program->Instructions; ; inst++) {
+
+ for (inst = program->Base.Instructions; ; inst++) {
if (ctx->VertexProgram.CallbackEnabled &&
ctx->VertexProgram.Callback) {
}
switch (inst->Opcode) {
- case VP_OPCODE_MOV:
+ case OPCODE_MOV:
{
GLfloat t[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, t );
}
break;
- case VP_OPCODE_LIT:
+ case OPCODE_LIT:
{
- const GLfloat epsilon = 1.0e-5F; /* XXX fix? */
+ const GLfloat epsilon = 1.0F / 256.0F; /* per NV spec */
GLfloat t[4], lit[4];
fetch_vector4( &inst->SrcReg[0], state, t );
- if (t[3] < -(128.0F - epsilon))
- t[3] = - (128.0F - epsilon);
- else if (t[3] > 128.0F - epsilon)
- t[3] = 128.0F - epsilon;
- if (t[0] < 0.0)
- t[0] = 0.0;
- if (t[1] < 0.0)
- t[1] = 0.0;
+ t[0] = MAX2(t[0], 0.0F);
+ t[1] = MAX2(t[1], 0.0F);
+ t[3] = CLAMP(t[3], -(128.0F - epsilon), (128.0F - epsilon));
lit[0] = 1.0;
lit[1] = t[0];
- lit[2] = (t[0] > 0.0) ? (GLfloat) exp(t[3] * log(t[1])) : 0.0F;
+ lit[2] = (t[0] > 0.0) ? (GLfloat) _mesa_pow(t[1], t[3]) : 0.0F;
lit[3] = 1.0;
store_vector4( &inst->DstReg, state, lit );
}
break;
- case VP_OPCODE_RCP:
+ case OPCODE_RCP:
{
GLfloat t[4];
fetch_vector1( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, t );
}
break;
- case VP_OPCODE_RSQ:
+ case OPCODE_RSQ:
{
GLfloat t[4];
fetch_vector1( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, t );
}
break;
- case VP_OPCODE_EXP:
+ case OPCODE_EXP:
{
GLfloat t[4], q[4], floor_t0;
fetch_vector1( &inst->SrcReg[0], state, t );
- floor_t0 = (float) floor(t[0]);
+ floor_t0 = FLOORF(t[0]);
if (floor_t0 > FLT_MAX_EXP) {
SET_POS_INFINITY(q[0]);
SET_POS_INFINITY(q[2]);
GLint ii = (GLint) floor_t0;
ii = (ii < 23) + 0x3f800000;
SET_FLOAT_BITS(q[0], ii);
- q[0] = *((GLfloat *) &ii);
+ q[0] = *((GLfloat *) (void *)&ii);
#else
q[0] = (GLfloat) pow(2.0, floor_t0);
#endif
store_vector4( &inst->DstReg, state, q );
}
break;
- case VP_OPCODE_LOG:
+ case OPCODE_LOG:
{
GLfloat t[4], q[4], abs_t0;
fetch_vector1( &inst->SrcReg[0], state, t );
- abs_t0 = (GLfloat) fabs(t[0]);
+ abs_t0 = FABSF(t[0]);
if (abs_t0 != 0.0F) {
/* Since we really can't handle infinite values on VMS
* like other OSes we'll use __MAXFLOAT to represent
}
else {
int exponent;
- double mantissa = frexp(t[0], &exponent);
+ GLfloat mantissa = FREXPF(t[0], &exponent);
q[0] = (GLfloat) (exponent - 1);
q[1] = (GLfloat) (2.0 * mantissa); /* map [.5, 1) -> [1, 2) */
q[2] = (GLfloat) (q[0] + LOG2(q[1]));
store_vector4( &inst->DstReg, state, q );
}
break;
- case VP_OPCODE_MUL:
+ case OPCODE_MUL:
{
GLfloat t[4], u[4], prod[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, prod );
}
break;
- case VP_OPCODE_ADD:
+ case OPCODE_ADD:
{
GLfloat t[4], u[4], sum[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, sum );
}
break;
- case VP_OPCODE_DP3:
+ case OPCODE_DP3:
{
GLfloat t[4], u[4], dot[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, dot );
}
break;
- case VP_OPCODE_DP4:
+ case OPCODE_DP4:
{
GLfloat t[4], u[4], dot[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, dot );
}
break;
- case VP_OPCODE_DST:
+ case OPCODE_DST:
{
GLfloat t[4], u[4], dst[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, dst );
}
break;
- case VP_OPCODE_MIN:
+ case OPCODE_MIN:
{
GLfloat t[4], u[4], min[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, min );
}
break;
- case VP_OPCODE_MAX:
+ case OPCODE_MAX:
{
GLfloat t[4], u[4], max[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, max );
}
break;
- case VP_OPCODE_SLT:
+ case OPCODE_SLT:
{
GLfloat t[4], u[4], slt[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, slt );
}
break;
- case VP_OPCODE_SGE:
+ case OPCODE_SGE:
{
GLfloat t[4], u[4], sge[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, sge );
}
break;
- case VP_OPCODE_MAD:
+ case OPCODE_MAD:
{
GLfloat t[4], u[4], v[4], sum[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, sum );
}
break;
- case VP_OPCODE_ARL:
+ case OPCODE_ARL:
{
GLfloat t[4];
fetch_vector4( &inst->SrcReg[0], state, t );
- state->AddressReg[0] = (GLint) floor(t[0]);
+ state->AddressReg[0] = (GLint) FLOORF(t[0]);
}
break;
- case VP_OPCODE_DPH:
+ case OPCODE_DPH:
{
GLfloat t[4], u[4], dot[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, dot );
}
break;
- case VP_OPCODE_RCC:
+ case OPCODE_RCC:
{
GLfloat t[4], u;
fetch_vector1( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, t );
}
break;
- case VP_OPCODE_SUB: /* GL_NV_vertex_program1_1 */
+ case OPCODE_SUB: /* GL_NV_vertex_program1_1 */
{
GLfloat t[4], u[4], sum[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, sum );
}
break;
- case VP_OPCODE_ABS: /* GL_NV_vertex_program1_1 */
+ case OPCODE_ABS: /* GL_NV_vertex_program1_1 */
{
GLfloat t[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, t );
}
break;
- case VP_OPCODE_FLR: /* GL_ARB_vertex_program */
+ case OPCODE_FLR: /* GL_ARB_vertex_program */
{
GLfloat t[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, t );
}
break;
- case VP_OPCODE_FRC: /* GL_ARB_vertex_program */
+ case OPCODE_FRC: /* GL_ARB_vertex_program */
{
GLfloat t[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, t );
}
break;
- case VP_OPCODE_EX2: /* GL_ARB_vertex_program */
+ case OPCODE_EX2: /* GL_ARB_vertex_program */
{
GLfloat t[4];
fetch_vector1( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, t );
}
break;
- case VP_OPCODE_LG2: /* GL_ARB_vertex_program */
+ case OPCODE_LG2: /* GL_ARB_vertex_program */
{
GLfloat t[4];
fetch_vector1( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, t );
}
break;
- case VP_OPCODE_POW: /* GL_ARB_vertex_program */
+ case OPCODE_POW: /* GL_ARB_vertex_program */
{
GLfloat t[4], u[4];
fetch_vector1( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, t );
}
break;
- case VP_OPCODE_XPD: /* GL_ARB_vertex_program */
+ case OPCODE_XPD: /* GL_ARB_vertex_program */
{
GLfloat t[4], u[4], cross[4];
fetch_vector4( &inst->SrcReg[0], state, t );
store_vector4( &inst->DstReg, state, cross );
}
break;
- case VP_OPCODE_SWZ: /* GL_ARB_vertex_program */
+ case OPCODE_SWZ: /* GL_ARB_vertex_program */
{
- const struct vp_src_register *source = &inst->SrcReg[0];
+ const struct prog_src_register *source = &inst->SrcReg[0];
const GLfloat *src = get_register_pointer(source, state);
GLfloat result[4];
GLuint i;
/* do extended swizzling here */
- for (i = 0; i < 3; i++) {
- if (source->Swizzle[i] == SWIZZLE_ZERO)
+ for (i = 0; i < 4; i++) {
+ if (GET_SWZ(source->Swizzle, i) == SWIZZLE_ZERO)
result[i] = 0.0;
- else if (source->Swizzle[i] == SWIZZLE_ONE)
- result[i] = -1.0;
+ else if (GET_SWZ(source->Swizzle, i) == SWIZZLE_ONE)
+ result[i] = 1.0;
else
- result[i] = -src[source->Swizzle[i]];
- if (source->Negate)
+ result[i] = src[GET_SWZ(source->Swizzle, i)];
+ if (source->NegateBase & (1 << i))
result[i] = -result[i];
}
store_vector4( &inst->DstReg, state, result );
}
break;
-
- case VP_OPCODE_END:
+ case OPCODE_PRINT:
+ if (inst->SrcReg[0].File) {
+ GLfloat t[4];
+ fetch_vector4( &inst->SrcReg[0], state, t );
+ _mesa_printf("%s%g, %g, %g, %g\n",
+ (char *) inst->Data, t[0], t[1], t[2], t[3]);
+ }
+ else {
+ _mesa_printf("%s\n", (char *) inst->Data);
+ }
+ break;
+ case OPCODE_END:
ctx->_CurrentProgram = 0;
return;
default:
For example:
-void simple_add( struct vp_instruction *inst )
+void simple_add( struct prog_instruction *inst )
{
GLfloat *sum = machine->Registers[inst->DstReg.Register];
GLfloat *a = machine->Registers[inst->SrcReg[0].Register];