r300/fragprog: Move some of the attribute handling out of the compiler
authorNicolai Hähnle <nhaehnle@gmail.com>
Fri, 24 Jul 2009 23:19:04 +0000 (01:19 +0200)
committerNicolai Hähnle <nhaehnle@gmail.com>
Mon, 27 Jul 2009 20:51:38 +0000 (22:51 +0200)
Attribute indices will probably be different in Gallium, so make the compiler
independent of magic values.

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.h
src/mesa/drivers/dri/r300/r300_fragprog_common.c

index 3c63da817665d5afdc17f5be56d431c0b105ddaa..d39b82be71cb5cb7df5539f637e8eaa32b86f318 100644 (file)
 
 static void nqssadce_init(struct nqssadce_state* s)
 {
-       s->Outputs[FRAG_RESULT_COLOR].Sourced = WRITEMASK_XYZW;
-       s->Outputs[FRAG_RESULT_DEPTH].Sourced = WRITEMASK_W;
+       struct r300_fragment_program_compiler * c = s->UserData;
+       s->Outputs[c->OutputColor].Sourced = WRITEMASK_XYZW;
+       s->Outputs[c->OutputDepth].Sourced = WRITEMASK_W;
 }
 
-/**
- * Transform the program to support fragment.position.
- *
- * Introduce a small fragment at the start of the program that will be
- * the only code that directly reads the FRAG_ATTRIB_WPOS input.
- * All other code pieces that reference that input will be rewritten
- * to read from a newly allocated temporary.
- *
- */
-static void insert_WPOS_trailer(struct r300_fragment_program_compiler *compiler)
-{
-       int i;
-
-       if (!(compiler->Base.Program.InputsRead & FRAG_BIT_WPOS)) {
-               compiler->code->wpos_attr = FRAG_ATTRIB_MAX;
-               return;
-       }
-
-       for (i = FRAG_ATTRIB_TEX0; i <= FRAG_ATTRIB_TEX7; ++i)
-       {
-               if (!(compiler->Base.Program.InputsRead & (1 << i))) {
-                       compiler->code->wpos_attr = i;
-                       break;
-               }
-       }
-
-       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
- * is done here.
- *
- * See also the counterpart rewriting for vertex programs.
- */
-static void rewriteFog(struct r300_fragment_program_compiler *compiler)
-{
-       struct rX00_fragment_program_code *code = compiler->code;
-       struct prog_src_register src;
-       int i;
-
-       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 (!(compiler->Base.Program.InputsRead & (1 << i))) {
-                       code->fog_attr = i;
-                       break;
-               }
-       }
-
-       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);
-}
-
-
 static void rewrite_depth_out(struct r300_fragment_program_compiler * c)
 {
        struct rc_instruction *rci;
@@ -109,7 +47,7 @@ static void rewrite_depth_out(struct r300_fragment_program_compiler * c)
        for (rci = c->Base.Program.Instructions.Next; rci != &c->Base.Program.Instructions; rci = rci->Next) {
                struct prog_instruction * inst = &rci->I;
 
-               if (inst->DstReg.File != PROGRAM_OUTPUT || inst->DstReg.Index != FRAG_RESULT_DEPTH)
+               if (inst->DstReg.File != PROGRAM_OUTPUT || inst->DstReg.Index != c->OutputDepth)
                        continue;
 
                if (inst->DstReg.WriteMask & WRITEMASK_Z) {
@@ -146,10 +84,6 @@ static void rewrite_depth_out(struct r300_fragment_program_compiler * c)
 
 void r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c)
 {
-       insert_WPOS_trailer(c);
-
-       rewriteFog(c);
-
        rewrite_depth_out(c);
 
        if (c->is_r500) {
@@ -181,14 +115,14 @@ void r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c)
                        .IsNativeSwizzle = &r500FPIsNativeSwizzle,
                        .BuildSwizzle = &r500FPBuildSwizzle
                };
-               radeonNqssaDce(&c->Base, &nqssadce, 0);
+               radeonNqssaDce(&c->Base, &nqssadce, c);
        } else {
                struct radeon_nqssadce_descr nqssadce = {
                        .Init = &nqssadce_init,
                        .IsNativeSwizzle = &r300FPIsNativeSwizzle,
                        .BuildSwizzle = &r300FPBuildSwizzle
                };
-               radeonNqssaDce(&c->Base, &nqssadce, 0);
+               radeonNqssaDce(&c->Base, &nqssadce, c);
        }
 
        if (c->Base.Debug) {
index b9e1a7959af437430ad50f537e99f34728660f6b..34f87183169a4372ab83108ea06b0395fac6560d 100644 (file)
@@ -76,6 +76,8 @@ struct r300_fragment_program_compiler {
        struct rX00_fragment_program_code *code;
        struct r300_fragment_program_external_state state;
        GLboolean is_r500;
+       unsigned OutputDepth;
+       unsigned OutputColor;
 };
 
 void r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c);
index 05f46ad0607132f912b07fca5030371ab9e5b39b..00807245752dade97afec6b0426e49b07d5bbc7c 100644 (file)
@@ -86,6 +86,69 @@ static void build_state(
 }
 
 
+/**
+ * Transform the program to support fragment.position.
+ *
+ * Introduce a small fragment at the start of the program that will be
+ * the only code that directly reads the FRAG_ATTRIB_WPOS input.
+ * All other code pieces that reference that input will be rewritten
+ * to read from a newly allocated temporary.
+ *
+ */
+static void insert_WPOS_trailer(struct r300_fragment_program_compiler *compiler)
+{
+       int i;
+
+       if (!(compiler->Base.Program.InputsRead & FRAG_BIT_WPOS)) {
+               compiler->code->wpos_attr = FRAG_ATTRIB_MAX;
+               return;
+       }
+
+       for (i = FRAG_ATTRIB_TEX0; i <= FRAG_ATTRIB_TEX7; ++i)
+       {
+               if (!(compiler->Base.Program.InputsRead & (1 << i))) {
+                       compiler->code->wpos_attr = i;
+                       break;
+               }
+       }
+
+       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
+ * is done here.
+ *
+ * See also the counterpart rewriting for vertex programs.
+ */
+static void rewriteFog(struct r300_fragment_program_compiler *compiler)
+{
+       struct rX00_fragment_program_code *code = compiler->code;
+       struct prog_src_register src;
+       int i;
+
+       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 (!(compiler->Base.Program.InputsRead & (1 << i))) {
+                       code->fog_attr = i;
+                       break;
+               }
+       }
+
+       memset(&src, 0, sizeof(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);
+}
+
+
 static void translate_fragment_program(GLcontext *ctx, struct r300_fragment_program_cont *cont, struct r300_fragment_program *fp)
 {
        r300ContextPtr r300 = R300_CONTEXT(ctx);
@@ -97,6 +160,8 @@ static void translate_fragment_program(GLcontext *ctx, struct r300_fragment_prog
        compiler.code = &fp->code;
        compiler.state = fp->state;
        compiler.is_r500 = (r300->radeon.radeonScreen->chip_family >= CHIP_FAMILY_RV515) ? GL_TRUE : GL_FALSE;
+       compiler.OutputDepth = FRAG_RESULT_DEPTH;
+       compiler.OutputColor = FRAG_RESULT_COLOR;
 
        if (compiler.Base.Debug) {
                fflush(stdout);
@@ -107,6 +172,10 @@ static void translate_fragment_program(GLcontext *ctx, struct r300_fragment_prog
 
        rc_mesa_to_rc_program(&compiler.Base, &cont->Base.Base);
 
+       insert_WPOS_trailer(&compiler);
+
+       rewriteFog(&compiler);
+
        r3xx_compile_fragment_program(&compiler);
        fp->error = compiler.Base.Error;