mesa: allow relative indexing into all register files and indirect dst register indexing

(cherry picked from commit f4361540f8)

Conflicts:

	src/mesa/shader/prog_execute.c
This commit is contained in:
Brian Paul
2009-01-06 08:42:40 -07:00
parent 6b05708ce2
commit 20156ce5da
3 changed files with 111 additions and 93 deletions
+103 -82
View File
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 7.0.3
* Version: 7.3
*
* Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
* Copyright (C) 1999-2008 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"),
@@ -76,56 +76,52 @@ static const GLfloat ZeroVec[4] = { 0.0F, 0.0F, 0.0F, 0.0F };
* source register.
*/
static INLINE const GLfloat *
get_register_pointer(const struct prog_src_register *source,
const struct gl_program_machine *machine)
get_src_register_pointer(const struct prog_src_register *source,
const struct gl_program_machine *machine)
{
const struct gl_program *prog = machine->CurProgram;
GLint reg = source->Index;
if (source->RelAddr) {
const GLint reg = source->Index + machine->AddressReg[0][0];
if (source->File == PROGRAM_ENV_PARAM) {
if (reg < 0 || reg >= MAX_PROGRAM_ENV_PARAMS)
return ZeroVec;
else
return machine->EnvParams[reg];
}
else {
const struct gl_program_parameter_list *params;
ASSERT(source->File == PROGRAM_LOCAL_PARAM ||
source->File == PROGRAM_CONSTANT ||
source->File == PROGRAM_STATE_VAR);
params = machine->CurProgram->Parameters;
if (reg < 0 || reg >= (GLint)params->NumParameters)
return ZeroVec;
else
return params->ParameterValues[reg];
/* add address register value to src index/offset */
reg += machine->AddressReg[0][0];
if (reg < 0) {
return ZeroVec;
}
}
switch (source->File) {
case PROGRAM_TEMPORARY:
ASSERT(source->Index < MAX_PROGRAM_TEMPS);
return machine->Temporaries[source->Index];
if (reg >= MAX_PROGRAM_TEMPS)
return ZeroVec;
return machine->Temporaries[reg];
case PROGRAM_INPUT:
if (machine->CurProgram->Target == GL_VERTEX_PROGRAM_ARB) {
ASSERT(source->Index < VERT_ATTRIB_MAX);
return machine->VertAttribs[source->Index];
if (prog->Target == GL_VERTEX_PROGRAM_ARB) {
if (reg >= VERT_ATTRIB_MAX)
return ZeroVec;
return machine->VertAttribs[reg];
}
else {
ASSERT(source->Index < FRAG_ATTRIB_MAX);
return machine->Attribs[source->Index][machine->CurElement];
if (reg >= FRAG_ATTRIB_MAX)
return ZeroVec;
return machine->Attribs[reg][machine->CurElement];
}
case PROGRAM_OUTPUT:
ASSERT(source->Index < MAX_PROGRAM_OUTPUTS);
return machine->Outputs[source->Index];
if (reg >= MAX_PROGRAM_OUTPUTS)
return ZeroVec;
return machine->Outputs[reg];
case PROGRAM_LOCAL_PARAM:
ASSERT(source->Index < MAX_PROGRAM_LOCAL_PARAMS);
return machine->CurProgram->LocalParams[source->Index];
if (reg >= MAX_PROGRAM_LOCAL_PARAMS)
return ZeroVec;
return machine->CurProgram->LocalParams[reg];
case PROGRAM_ENV_PARAM:
ASSERT(source->Index < MAX_PROGRAM_ENV_PARAMS);
return machine->EnvParams[source->Index];
if (reg >= MAX_PROGRAM_ENV_PARAMS)
return ZeroVec;
return machine->EnvParams[reg];
case PROGRAM_STATE_VAR:
/* Fallthrough */
@@ -134,19 +130,62 @@ get_register_pointer(const struct prog_src_register *source,
case PROGRAM_UNIFORM:
/* Fallthrough */
case PROGRAM_NAMED_PARAM:
ASSERT(source->Index <
(GLint) machine->CurProgram->Parameters->NumParameters);
return machine->CurProgram->Parameters->ParameterValues[source->Index];
if (reg >= (GLint) prog->Parameters->NumParameters)
return ZeroVec;
return prog->Parameters->ParameterValues[reg];
default:
_mesa_problem(NULL,
"Invalid input register file %d in get_register_pointer()",
source->File);
"Invalid src register file %d in get_src_register_pointer()",
source->File);
return NULL;
}
}
/**
* Return a pointer to the 4-element float vector specified by the given
* destination register.
*/
static INLINE GLfloat *
get_dst_register_pointer(const struct prog_dst_register *dest,
struct gl_program_machine *machine)
{
static GLfloat dummyReg[4];
GLint reg = dest->Index;
if (dest->RelAddr) {
/* add address register value to src index/offset */
reg += machine->AddressReg[0][0];
if (reg < 0) {
return dummyReg;
}
}
switch (dest->File) {
case PROGRAM_TEMPORARY:
if (reg >= MAX_PROGRAM_TEMPS)
return dummyReg;
return machine->Temporaries[reg];
case PROGRAM_OUTPUT:
if (reg >= MAX_PROGRAM_OUTPUTS)
return dummyReg;
return machine->Outputs[reg];
case PROGRAM_WRITE_ONLY:
return dummyReg;
default:
_mesa_problem(NULL,
"Invalid dest register file %d in get_dst_register_pointer()",
dest->File);
return NULL;
}
}
#if FEATURE_MESA_program_debug
static struct gl_program_machine *CurrentMachine = NULL;
@@ -160,12 +199,12 @@ _mesa_get_program_register(GLcontext *ctx, enum register_file file,
GLuint index, GLfloat val[4])
{
if (CurrentMachine) {
struct prog_src_register src;
const GLfloat *reg;
src.File = file;
src.Index = index;
reg = get_register_pointer(&src, CurrentMachine);
COPY_4V(val, reg);
struct prog_src_register srcReg;
const GLfloat *src;
srcReg.File = file;
srcReg.Index = index;
src = get_src_register_pointer(&srcReg, CurrentMachine);
COPY_4V(val, src);
}
}
#endif /* FEATURE_MESA_program_debug */
@@ -179,7 +218,7 @@ static void
fetch_vector4(const struct prog_src_register *source,
const struct gl_program_machine *machine, GLfloat result[4])
{
const GLfloat *src = get_register_pointer(source, machine);
const GLfloat *src = get_src_register_pointer(source, machine);
ASSERT(src);
if (source->Swizzle == SWIZZLE_NOOP) {
@@ -284,7 +323,7 @@ static void
fetch_vector1(const struct prog_src_register *source,
const struct gl_program_machine *machine, GLfloat result[4])
{
const GLfloat *src = get_register_pointer(source, machine);
const GLfloat *src = get_src_register_pointer(source, machine);
ASSERT(src);
result[0] = src[GET_SWZ(source->Swizzle, 0)];
@@ -399,29 +438,11 @@ static void
store_vector4(const struct prog_instruction *inst,
struct gl_program_machine *machine, const GLfloat value[4])
{
const struct prog_dst_register *dest = &(inst->DstReg);
const struct prog_dst_register *dstReg = &(inst->DstReg);
const GLboolean clamp = inst->SaturateMode == SATURATE_ZERO_ONE;
GLfloat *dstReg;
GLfloat dummyReg[4];
GLuint writeMask = dstReg->WriteMask;
GLfloat clampedValue[4];
GLuint writeMask = dest->WriteMask;
switch (dest->File) {
case PROGRAM_OUTPUT:
ASSERT(dest->Index < MAX_PROGRAM_OUTPUTS);
dstReg = machine->Outputs[dest->Index];
break;
case PROGRAM_TEMPORARY:
ASSERT(dest->Index < MAX_PROGRAM_TEMPS);
dstReg = machine->Temporaries[dest->Index];
break;
case PROGRAM_WRITE_ONLY:
dstReg = dummyReg;
return;
default:
_mesa_problem(NULL, "bad register file in store_vector4(fp)");
return;
}
GLfloat *dst = get_dst_register_pointer(dstReg, machine);
#if 0
if (value[0] > 1.0e10 ||
@@ -439,38 +460,38 @@ store_vector4(const struct prog_instruction *inst,
value = clampedValue;
}
if (dest->CondMask != COND_TR) {
if (dstReg->CondMask != COND_TR) {
/* condition codes may turn off some writes */
if (writeMask & WRITEMASK_X) {
if (!test_cc(machine->CondCodes[GET_SWZ(dest->CondSwizzle, 0)],
dest->CondMask))
if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 0)],
dstReg->CondMask))
writeMask &= ~WRITEMASK_X;
}
if (writeMask & WRITEMASK_Y) {
if (!test_cc(machine->CondCodes[GET_SWZ(dest->CondSwizzle, 1)],
dest->CondMask))
if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 1)],
dstReg->CondMask))
writeMask &= ~WRITEMASK_Y;
}
if (writeMask & WRITEMASK_Z) {
if (!test_cc(machine->CondCodes[GET_SWZ(dest->CondSwizzle, 2)],
dest->CondMask))
if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 2)],
dstReg->CondMask))
writeMask &= ~WRITEMASK_Z;
}
if (writeMask & WRITEMASK_W) {
if (!test_cc(machine->CondCodes[GET_SWZ(dest->CondSwizzle, 3)],
dest->CondMask))
if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 3)],
dstReg->CondMask))
writeMask &= ~WRITEMASK_W;
}
}
if (writeMask & WRITEMASK_X)
dstReg[0] = value[0];
dst[0] = value[0];
if (writeMask & WRITEMASK_Y)
dstReg[1] = value[1];
dst[1] = value[1];
if (writeMask & WRITEMASK_Z)
dstReg[2] = value[2];
dst[2] = value[2];
if (writeMask & WRITEMASK_W)
dstReg[3] = value[3];
dst[3] = value[3];
if (inst->CondUpdate) {
if (writeMask & WRITEMASK_X)
@@ -1314,7 +1335,7 @@ _mesa_execute_program(GLcontext * ctx,
case OPCODE_SWZ: /* extended swizzle */
{
const struct prog_src_register *source = &inst->SrcReg[0];
const GLfloat *src = get_register_pointer(source, machine);
const GLfloat *src = get_src_register_pointer(source, machine);
GLfloat result[4];
GLuint i;
for (i = 0; i < 4; i++) {
+5 -8
View File
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 6.5.3
* Version: 7.3
*
* Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
* Copyright (C) 1999-2008 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"),
@@ -280,13 +280,10 @@ struct prog_src_register
*/
struct prog_dst_register
{
/**
* One of the PROGRAM_* register file values.
*/
GLuint File:4;
GLuint File:4; /**< One of the PROGRAM_* register file values */
GLuint Index:8;
GLuint WriteMask:4;
GLuint RelAddr:1;
/**
* \name Conditional destination update control.
@@ -318,7 +315,7 @@ struct prog_dst_register
GLuint CondSrc:1;
/*@}*/
GLuint pad:31;
GLuint pad:30;
};
+3 -3
View File
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 6.5.3
* Version: 7.3
*
* Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
* Copyright (C) 1999-2008 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"),
@@ -419,7 +419,7 @@ print_dst_reg(const struct prog_dst_register *dstReg, gl_prog_print_mode mode,
{
_mesa_printf("%s%s",
reg_string((enum register_file) dstReg->File,
dstReg->Index, mode, GL_FALSE, prog),
dstReg->Index, mode, dstReg->RelAddr, prog),
writemask_string(dstReg->WriteMask));
if (dstReg->CondMask != COND_TR) {