r300/compiler: Refactor fragment program fog rewrite to use rc_program
Signed-off-by: Nicolai Hähnle <nhaehnle@gmail.com>
This commit is contained in:
@@ -156,42 +156,27 @@ static void insert_WPOS_trailer(struct r300_fragment_program_compiler *compiler)
|
||||
static void rewriteFog(struct r300_fragment_program_compiler *compiler)
|
||||
{
|
||||
struct rX00_fragment_program_code *code = compiler->code;
|
||||
GLuint InputsRead = compiler->program->InputsRead;
|
||||
struct prog_src_register src;
|
||||
int i;
|
||||
|
||||
if (!(InputsRead & FRAG_BIT_FOGC)) {
|
||||
if (!(compiler->Base.Program.InputsRead & FRAG_BIT_FOGC)) {
|
||||
code->fog_attr = FRAG_ATTRIB_MAX;
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = FRAG_ATTRIB_TEX0; i <= FRAG_ATTRIB_TEX7; ++i)
|
||||
{
|
||||
if (!(InputsRead & (1 << i))) {
|
||||
InputsRead &= ~(1 << FRAG_ATTRIB_FOGC);
|
||||
InputsRead |= 1 << i;
|
||||
compiler->program->InputsRead = InputsRead;
|
||||
if (!(compiler->Base.Program.InputsRead & (1 << i))) {
|
||||
code->fog_attr = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
struct prog_instruction *inst;
|
||||
|
||||
inst = compiler->program->Instructions;
|
||||
while (inst->Opcode != OPCODE_END) {
|
||||
const int src_regs = _mesa_num_inst_src_regs(inst->Opcode);
|
||||
for (i = 0; i < src_regs; ++i) {
|
||||
if (inst->SrcReg[i].File == PROGRAM_INPUT && inst->SrcReg[i].Index == FRAG_ATTRIB_FOGC) {
|
||||
inst->SrcReg[i].Index = code->fog_attr;
|
||||
inst->SrcReg[i].Swizzle = combine_swizzles(
|
||||
MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ONE),
|
||||
inst->SrcReg[i].Swizzle);
|
||||
}
|
||||
}
|
||||
++inst;
|
||||
}
|
||||
}
|
||||
reset_srcreg(&src);
|
||||
src.File = PROGRAM_INPUT;
|
||||
src.Index = code->fog_attr;
|
||||
src.Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ONE);
|
||||
rc_move_input(&compiler->Base, FRAG_ATTRIB_FOGC, src);
|
||||
}
|
||||
|
||||
|
||||
@@ -248,10 +233,10 @@ void r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c)
|
||||
|
||||
insert_WPOS_trailer(c);
|
||||
|
||||
rewriteFog(c);
|
||||
|
||||
rc_mesa_to_rc_program(&c->Base, c->program);
|
||||
|
||||
rewriteFog(c);
|
||||
|
||||
rewrite_depth_out(c);
|
||||
|
||||
if (c->is_r500) {
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "radeon_program.h"
|
||||
|
||||
|
||||
void rc_init(struct radeon_compiler * c)
|
||||
{
|
||||
@@ -88,3 +90,33 @@ void rc_error(struct radeon_compiler * c, const char * fmt, ...)
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewrite the program such that everything that source the given input
|
||||
* register will source new_input instead.
|
||||
*/
|
||||
void rc_move_input(struct radeon_compiler * c, unsigned input, struct prog_src_register new_input)
|
||||
{
|
||||
struct rc_instruction * inst;
|
||||
|
||||
c->Program.InputsRead &= ~(1 << input);
|
||||
|
||||
for(inst = c->Program.Instructions.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 == input) {
|
||||
inst->I.SrcReg[i].File = new_input.File;
|
||||
inst->I.SrcReg[i].Index = new_input.Index;
|
||||
inst->I.SrcReg[i].Swizzle = combine_swizzles(new_input.Swizzle, inst->I.SrcReg[i].Swizzle);
|
||||
if (!inst->I.SrcReg[i].Abs) {
|
||||
inst->I.SrcReg[i].Negate ^= new_input.Negate;
|
||||
inst->I.SrcReg[i].Abs = new_input.Abs;
|
||||
}
|
||||
|
||||
c->Program.InputsRead |= 1 << new_input.Index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +64,8 @@ void rc_destroy(struct radeon_compiler * c);
|
||||
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);
|
||||
|
||||
struct r300_fragment_program_compiler {
|
||||
struct radeon_compiler Base;
|
||||
struct rX00_fragment_program_code *code;
|
||||
|
||||
Reference in New Issue
Block a user