r300/vertprog: Refactor wpos rewrite using rc_program
authorNicolai Hähnle <nhaehnle@gmail.com>
Fri, 24 Jul 2009 22:49:25 +0000 (00:49 +0200)
committerNicolai Hähnle <nhaehnle@gmail.com>
Mon, 27 Jul 2009 20:51:37 +0000 (22:51 +0200)
Signed-off-by: Nicolai Hähnle <nhaehnle@gmail.com>
src/mesa/drivers/dri/r300/compiler/r3xx_vertprog.c
src/mesa/drivers/dri/r300/compiler/radeon_compiler.c
src/mesa/drivers/dri/r300/compiler/radeon_compiler.h

index 38ee9575a324939db260867c9c4870644dec0357..c05b488645b7520091fa8167a2196a9b14877ed2 100644 (file)
@@ -578,62 +578,6 @@ static GLboolean transform_source_conflicts(
        return GL_TRUE;
 }
 
-static void insert_wpos(struct gl_program *prog, GLuint temp_index, int tex_id)
-{
-       struct prog_instruction *vpi;
-
-       _mesa_insert_instructions(prog, prog->NumInstructions - 1, 2);
-
-       vpi = &prog->Instructions[prog->NumInstructions - 3];
-
-       vpi->Opcode = OPCODE_MOV;
-
-       vpi->DstReg.File = PROGRAM_OUTPUT;
-       vpi->DstReg.Index = VERT_RESULT_HPOS;
-       vpi->DstReg.WriteMask = WRITEMASK_XYZW;
-       vpi->DstReg.CondMask = COND_TR;
-
-       vpi->SrcReg[0].File = PROGRAM_TEMPORARY;
-       vpi->SrcReg[0].Index = temp_index;
-       vpi->SrcReg[0].Swizzle = SWIZZLE_XYZW;
-
-       ++vpi;
-
-       vpi->Opcode = OPCODE_MOV;
-
-       vpi->DstReg.File = PROGRAM_OUTPUT;
-       vpi->DstReg.Index = VERT_RESULT_TEX0 + tex_id;
-       vpi->DstReg.WriteMask = WRITEMASK_XYZW;
-       vpi->DstReg.CondMask = COND_TR;
-
-       vpi->SrcReg[0].File = PROGRAM_TEMPORARY;
-       vpi->SrcReg[0].Index = temp_index;
-       vpi->SrcReg[0].Swizzle = SWIZZLE_XYZW;
-
-       ++vpi;
-
-       vpi->Opcode = OPCODE_END;
-}
-
-static void pos_as_texcoord(struct gl_program *prog, int tex_id)
-{
-       struct prog_instruction *vpi;
-       GLuint tempregi = prog->NumTemporaries;
-
-       prog->NumTemporaries++;
-
-       for (vpi = prog->Instructions; vpi->Opcode != OPCODE_END; vpi++) {
-               if (vpi->DstReg.File == PROGRAM_OUTPUT && vpi->DstReg.Index == VERT_RESULT_HPOS) {
-                       vpi->DstReg.File = PROGRAM_TEMPORARY;
-                       vpi->DstReg.Index = tempregi;
-               }
-       }
-
-       insert_wpos(prog, tempregi, tex_id);
-
-       prog->OutputsWritten |= 1 << (VERT_RESULT_TEX0 + tex_id);
-}
-
 static void addArtificialOutputs(struct r300_vertex_program_compiler * compiler)
 {
        int i;
@@ -684,15 +628,19 @@ static GLboolean swizzleIsNative(GLuint opcode, struct prog_src_register reg)
 
 void r3xx_compile_vertex_program(struct r300_vertex_program_compiler* compiler)
 {
-       if (compiler->state.WPosAttr != FRAG_ATTRIB_MAX) {
-               pos_as_texcoord(compiler->program, compiler->state.WPosAttr - FRAG_ATTRIB_TEX0);
-       }
-
        rc_mesa_to_rc_program(&compiler->Base, compiler->program);
        compiler->program = 0;
 
+       if (compiler->state.WPosAttr != FRAG_ATTRIB_MAX) {
+               rc_copy_output(&compiler->Base,
+                       VERT_RESULT_HPOS,
+                       compiler->state.WPosAttr - FRAG_ATTRIB_TEX0 + VERT_RESULT_TEX0);
+       }
+
        if (compiler->state.FogAttr != FRAG_ATTRIB_MAX) {
-               rc_move_output(&compiler->Base, VERT_RESULT_FOGC, compiler->state.FogAttr - FRAG_ATTRIB_TEX0 + VERT_RESULT_TEX0, WRITEMASK_X);
+               rc_move_output(&compiler->Base,
+                       VERT_RESULT_FOGC,
+                       compiler->state.FogAttr - FRAG_ATTRIB_TEX0 + VERT_RESULT_TEX0, WRITEMASK_X);
        }
 
        addArtificialOutputs(compiler);
index 6e7361d56865ea54c5e0c9989682190fd678064b..da950d52894feb68be9349a06aec0562df96ffb6 100644 (file)
@@ -148,6 +148,47 @@ void rc_move_output(struct radeon_compiler * c, unsigned output, unsigned new_ou
 }
 
 
+/**
+ * Rewrite the program such that a given output is duplicated.
+ */
+void rc_copy_output(struct radeon_compiler * c, unsigned output, unsigned dup_output)
+{
+       unsigned tempreg = rc_find_free_temporary(c);
+       struct rc_instruction * inst;
+
+       for(inst = c->Program.Instructions.Next; inst != &c->Program.Instructions; inst = inst->Next) {
+               const unsigned numdsts = _mesa_num_inst_dst_regs(inst->I.Opcode);
+
+               if (numdsts) {
+                       if (inst->I.DstReg.File == PROGRAM_OUTPUT && inst->I.DstReg.Index == output) {
+                               inst->I.DstReg.File = PROGRAM_TEMPORARY;
+                               inst->I.DstReg.Index = tempreg;
+                       }
+               }
+       }
+
+       inst = rc_insert_new_instruction(c, c->Program.Instructions.Prev);
+       inst->I.Opcode = OPCODE_MOV;
+       inst->I.DstReg.File = PROGRAM_OUTPUT;
+       inst->I.DstReg.Index = output;
+
+       inst->I.SrcReg[0].File = PROGRAM_TEMPORARY;
+       inst->I.SrcReg[0].Index = tempreg;
+       inst->I.SrcReg[0].Swizzle = SWIZZLE_XYZW;
+
+       inst = rc_insert_new_instruction(c, c->Program.Instructions.Prev);
+       inst->I.Opcode = OPCODE_MOV;
+       inst->I.DstReg.File = PROGRAM_OUTPUT;
+       inst->I.DstReg.Index = dup_output;
+
+       inst->I.SrcReg[0].File = PROGRAM_TEMPORARY;
+       inst->I.SrcReg[0].Index = tempreg;
+       inst->I.SrcReg[0].Swizzle = SWIZZLE_XYZW;
+
+       c->Program.OutputsWritten |= 1 << dup_output;
+}
+
+
 /**
  * Introduce standard code fragment to deal with fragment.position.
  */
index 34f4240d534d89ab4aea38c011a6c7d497200c36..a4ff2ca86ab0651db4043b6f378b94fe062c7ff3 100644 (file)
@@ -66,6 +66,7 @@ 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_move_output(struct radeon_compiler * c, unsigned output, unsigned new_output, unsigned writemask);
+void rc_copy_output(struct radeon_compiler * c, unsigned output, unsigned dup_output);
 void rc_transform_fragment_wpos(struct radeon_compiler * c, unsigned wpos, unsigned new_input);
 
 struct r300_fragment_program_compiler {