r300/compiler: Refactor fragment program fog rewrite to use rc_program
authorNicolai Hähnle <nhaehnle@gmail.com>
Fri, 24 Jul 2009 21:06:54 +0000 (23:06 +0200)
committerNicolai Hähnle <nhaehnle@gmail.com>
Mon, 27 Jul 2009 20:51:36 +0000 (22:51 +0200)
Signed-off-by: Nicolai Hähnle <nhaehnle@gmail.com>
src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c
src/mesa/drivers/dri/r300/compiler/radeon_compiler.c
src/mesa/drivers/dri/r300/compiler/radeon_compiler.h

index 08283c814747ca4311932787e42527408173578c..2ffee79b4fce7daaf8a0a61c0f5dae008ba07771 100644 (file)
@@ -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) {
index 684961021a1729ff94e17b7d725b7604bbb34d92..15823064f2c339f78e70e91d278cbecbe7010365 100644 (file)
@@ -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;
+                       }
+               }
+       }
+}
index d9ee43017dc069a48bc5cf60f77700700a8bae46..1a09522b012da15f6d73bb7d44d8b31c5512d84d 100644 (file)
@@ -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;