llvmpipe: force constant interpolation of flatshade colors
authorKeith Whitwell <keithw@vmware.com>
Mon, 11 Jan 2010 12:06:51 +0000 (12:06 +0000)
committerKeith Whitwell <keithw@vmware.com>
Mon, 11 Jan 2010 12:12:59 +0000 (12:12 +0000)
Nice speedup for gears.

src/gallium/drivers/llvmpipe/lp_bld_interp.c
src/gallium/drivers/llvmpipe/lp_bld_interp.h
src/gallium/drivers/llvmpipe/lp_state.h
src/gallium/drivers/llvmpipe/lp_state_derived.c
src/gallium/drivers/llvmpipe/lp_state_fs.c

index daedf40..a6acaea 100644 (file)
@@ -316,6 +316,7 @@ pos_update(struct lp_build_interp_soa_context *bld, int quad_index)
 void
 lp_build_interp_soa_init(struct lp_build_interp_soa_context *bld,
                          const struct tgsi_token *tokens,
+                         boolean flatshade,
                          LLVMBuilderRef builder,
                          struct lp_type type,
                          LLVMValueRef a0_ptr,
@@ -358,7 +359,15 @@ lp_build_interp_soa_init(struct lp_build_interp_soa_context *bld,
 
             for( attrib = first; attrib <= last; ++attrib ) {
                bld->mask[1 + attrib] = mask;
-               bld->mode[1 + attrib] = decl->Declaration.Interpolate;
+
+               /* XXX: have mesa set INTERP_CONSTANT in the fragment
+                * shader.
+                */
+               if (decl->Semantic.Name == TGSI_SEMANTIC_COLOR &&
+                   flatshade)
+                  bld->mode[1 + attrib] = TGSI_INTERPOLATE_CONSTANT;
+               else
+                  bld->mode[1 + attrib] = decl->Declaration.Interpolate;
             }
 
             bld->num_attribs = MAX2(bld->num_attribs, 1 + last + 1);
index e2b3bc1..ca958cd 100644 (file)
@@ -79,6 +79,7 @@ struct lp_build_interp_soa_context
 void
 lp_build_interp_soa_init(struct lp_build_interp_soa_context *bld,
                          const struct tgsi_token *tokens,
+                         boolean flatshade,
                          LLVMBuilderRef builder,
                          struct lp_type type,
                          LLVMValueRef a0_ptr,
index cb240cb..4c6747b 100644 (file)
@@ -66,12 +66,12 @@ struct lp_fragment_shader;
 
 struct lp_fragment_shader_variant_key
 {
-   enum pipe_format zsbuf_format;
-   unsigned nr_cbufs;
-
    struct pipe_depth_state depth;
    struct pipe_alpha_state alpha;
    struct pipe_blend_state blend;
+   enum pipe_format zsbuf_format;
+   unsigned nr_cbufs:8;
+   unsigned flatshade:1;
 
    struct {
       ubyte colormask;
index af02fcf..632cafa 100644 (file)
@@ -159,6 +159,7 @@ void llvmpipe_update_derived( struct llvmpipe_context *llvmpipe )
    if (llvmpipe->dirty & (LP_NEW_FS |
                           LP_NEW_BLEND |
                           LP_NEW_DEPTH_STENCIL_ALPHA |
+                          LP_NEW_RASTERIZER |
                           LP_NEW_SAMPLER |
                           LP_NEW_TEXTURE))
       llvmpipe_update_fs( llvmpipe );
index 01912d6..7ce7202 100644 (file)
@@ -718,7 +718,10 @@ generate_fragment(struct llvmpipe_context *lp,
 
    generate_pos0(builder, x, y, &x0, &y0);
 
-   lp_build_interp_soa_init(&interp, shader->base.tokens, builder, fs_type,
+   lp_build_interp_soa_init(&interp, 
+                            shader->base.tokens,
+                            key->flatshade,
+                            builder, fs_type,
                             a0_ptr, dadx_ptr, dady_ptr,
                             x0, y0);
 
@@ -958,6 +961,8 @@ make_variant_key(struct llvmpipe_context *lp,
       key->alpha.func = lp->depth_stencil->alpha.func;
    /* alpha.ref_value is passed in jit_context */
 
+   key->flatshade = lp->rasterizer->flatshade;
+
    if (lp->framebuffer.nr_cbufs) {
       memcpy(&key->blend, lp->blend, sizeof key->blend);
    }