r300/fragprog: Refactor wpos rewrite to use rc_program

Signed-off-by: Nicolai Hähnle <nhaehnle@gmail.com>
This commit is contained in:
Nicolai Hähnle 2009-07-24 23:28:08 +02:00
parent 9dc1be4158
commit 273af68570
3 changed files with 80 additions and 84 deletions

View file

@ -50,102 +50,24 @@ static void nqssadce_init(struct nqssadce_state* s)
*/
static void insert_WPOS_trailer(struct r300_fragment_program_compiler *compiler)
{
GLuint InputsRead = compiler->program->InputsRead;
int i;
if (!(InputsRead & FRAG_BIT_WPOS)) {
if (!(compiler->Base.Program.InputsRead & FRAG_BIT_WPOS)) {
compiler->code->wpos_attr = FRAG_ATTRIB_MAX;
return;
}
static gl_state_index tokens[STATE_LENGTH] = {
STATE_INTERNAL, STATE_R300_WINDOW_DIMENSION, 0, 0, 0
};
struct prog_instruction *fpi;
GLuint window_index;
int i = 0;
for (i = FRAG_ATTRIB_TEX0; i <= FRAG_ATTRIB_TEX7; ++i)
{
if (!(InputsRead & (1 << i))) {
InputsRead &= ~(1 << FRAG_ATTRIB_WPOS);
InputsRead |= 1 << i;
compiler->program->InputsRead = InputsRead;
if (!(compiler->Base.Program.InputsRead & (1 << i))) {
compiler->code->wpos_attr = i;
break;
}
}
GLuint tempregi = _mesa_find_free_register(compiler->program, PROGRAM_TEMPORARY);
_mesa_insert_instructions(compiler->program, 0, 3);
fpi = compiler->program->Instructions;
i = 0;
/* perspective divide */
fpi[i].Opcode = OPCODE_RCP;
fpi[i].DstReg.File = PROGRAM_TEMPORARY;
fpi[i].DstReg.Index = tempregi;
fpi[i].DstReg.WriteMask = WRITEMASK_W;
fpi[i].DstReg.CondMask = COND_TR;
fpi[i].SrcReg[0].File = PROGRAM_INPUT;
fpi[i].SrcReg[0].Index = compiler->code->wpos_attr;
fpi[i].SrcReg[0].Swizzle = SWIZZLE_WWWW;
i++;
fpi[i].Opcode = OPCODE_MUL;
fpi[i].DstReg.File = PROGRAM_TEMPORARY;
fpi[i].DstReg.Index = tempregi;
fpi[i].DstReg.WriteMask = WRITEMASK_XYZ;
fpi[i].DstReg.CondMask = COND_TR;
fpi[i].SrcReg[0].File = PROGRAM_INPUT;
fpi[i].SrcReg[0].Index = compiler->code->wpos_attr;
fpi[i].SrcReg[0].Swizzle = SWIZZLE_XYZW;
fpi[i].SrcReg[1].File = PROGRAM_TEMPORARY;
fpi[i].SrcReg[1].Index = tempregi;
fpi[i].SrcReg[1].Swizzle = SWIZZLE_WWWW;
i++;
/* viewport transformation */
window_index = _mesa_add_state_reference(compiler->program->Parameters, tokens);
fpi[i].Opcode = OPCODE_MAD;
fpi[i].DstReg.File = PROGRAM_TEMPORARY;
fpi[i].DstReg.Index = tempregi;
fpi[i].DstReg.WriteMask = WRITEMASK_XYZ;
fpi[i].DstReg.CondMask = COND_TR;
fpi[i].SrcReg[0].File = PROGRAM_TEMPORARY;
fpi[i].SrcReg[0].Index = tempregi;
fpi[i].SrcReg[0].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ZERO);
fpi[i].SrcReg[1].File = PROGRAM_STATE_VAR;
fpi[i].SrcReg[1].Index = window_index;
fpi[i].SrcReg[1].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ZERO);
fpi[i].SrcReg[2].File = PROGRAM_STATE_VAR;
fpi[i].SrcReg[2].Index = window_index;
fpi[i].SrcReg[2].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ZERO);
i++;
for (; i < compiler->program->NumInstructions; ++i) {
int reg;
for (reg = 0; reg < 3; reg++) {
if (fpi[i].SrcReg[reg].File == PROGRAM_INPUT &&
fpi[i].SrcReg[reg].Index == FRAG_ATTRIB_WPOS) {
fpi[i].SrcReg[reg].File = PROGRAM_TEMPORARY;
fpi[i].SrcReg[reg].Index = tempregi;
}
}
}
rc_transform_fragment_wpos(&compiler->Base, FRAG_ATTRIB_WPOS, compiler->code->wpos_attr);
}
/**
* Rewrite fragment.fogcoord to use a texture coordinate slot.
* Note that fogcoord is forced into an X001 pattern, and this enforcement
@ -231,10 +153,10 @@ void r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c)
fflush(stdout);
}
insert_WPOS_trailer(c);
rc_mesa_to_rc_program(&c->Base, c->program);
insert_WPOS_trailer(c);
rewriteFog(c);
rewrite_depth_out(c);

View file

@ -120,3 +120,76 @@ void rc_move_input(struct radeon_compiler * c, unsigned input, struct prog_src_r
}
}
}
/**
* Introduce standard code fragment to deal with fragment.position.
*/
void rc_transform_fragment_wpos(struct radeon_compiler * c, unsigned wpos, unsigned new_input)
{
unsigned tempregi = rc_find_free_temporary(c);
c->Program.InputsRead &= ~(1 << wpos);
c->Program.InputsRead |= 1 << new_input;
/* perspective divide */
struct rc_instruction * inst_rcp = rc_insert_new_instruction(c, &c->Program.Instructions);
inst_rcp->I.Opcode = OPCODE_RCP;
inst_rcp->I.DstReg.File = PROGRAM_TEMPORARY;
inst_rcp->I.DstReg.Index = tempregi;
inst_rcp->I.DstReg.WriteMask = WRITEMASK_W;
inst_rcp->I.SrcReg[0].File = PROGRAM_INPUT;
inst_rcp->I.SrcReg[0].Index = new_input;
inst_rcp->I.SrcReg[0].Swizzle = SWIZZLE_WWWW;
struct rc_instruction * inst_mul = rc_insert_new_instruction(c, inst_rcp);
inst_mul->I.Opcode = OPCODE_MUL;
inst_mul->I.DstReg.File = PROGRAM_TEMPORARY;
inst_mul->I.DstReg.Index = tempregi;
inst_mul->I.DstReg.WriteMask = WRITEMASK_XYZ;
inst_mul->I.SrcReg[0].File = PROGRAM_INPUT;
inst_mul->I.SrcReg[0].Index = new_input;
inst_mul->I.SrcReg[1].File = PROGRAM_TEMPORARY;
inst_mul->I.SrcReg[1].Index = tempregi;
inst_mul->I.SrcReg[1].Swizzle = SWIZZLE_WWWW;
/* viewport transformation */
struct rc_instruction * inst_mad = rc_insert_new_instruction(c, inst_mul);
inst_mad->I.Opcode = OPCODE_MAD;
inst_mad->I.DstReg.File = PROGRAM_TEMPORARY;
inst_mad->I.DstReg.Index = tempregi;
inst_mad->I.DstReg.WriteMask = WRITEMASK_XYZ;
inst_mad->I.SrcReg[0].File = PROGRAM_TEMPORARY;
inst_mad->I.SrcReg[0].Index = tempregi;
inst_mad->I.SrcReg[0].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ZERO);
inst_mad->I.SrcReg[1].File = PROGRAM_STATE_VAR;
inst_mad->I.SrcReg[1].Index = rc_constants_add_state(&c->Program.Constants, RC_STATE_R300_WINDOW_DIMENSION, 0);
inst_mad->I.SrcReg[1].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ZERO);
inst_mad->I.SrcReg[2].File = PROGRAM_STATE_VAR;
inst_mad->I.SrcReg[2].Index = inst_mad->I.SrcReg[1].Index;
inst_mad->I.SrcReg[2].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ZERO);
struct rc_instruction * inst;
for (inst = inst_mad->Next; inst != &c->Program.Instructions; inst = inst->Next) {
const unsigned numsrcs = _mesa_num_inst_src_regs(inst->I.Opcode);
unsigned i;
for(i = 0; i < numsrcs; i++) {
if (inst->I.SrcReg[i].File == PROGRAM_INPUT &&
inst->I.SrcReg[i].Index == wpos) {
inst->I.SrcReg[i].File = PROGRAM_TEMPORARY;
inst->I.SrcReg[i].Index = tempregi;
}
}
}
}

View file

@ -65,6 +65,7 @@ void rc_debug(struct radeon_compiler * c, const char * fmt, ...);
void rc_error(struct radeon_compiler * c, const char * fmt, ...);
void rc_move_input(struct radeon_compiler * c, unsigned input, struct prog_src_register new_input);
void rc_transform_fragment_wpos(struct radeon_compiler * c, unsigned wpos, unsigned new_input);
struct r300_fragment_program_compiler {
struct radeon_compiler Base;