llvmpipe: Skip blending when mask is zero.
authorJosé Fonseca <jfonseca@vmware.com>
Thu, 10 Sep 2009 11:01:42 +0000 (12:01 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Thu, 10 Sep 2009 11:01:42 +0000 (12:01 +0100)
This increases quake3 timedemo fps another 10%.

src/gallium/drivers/llvmpipe/lp_bld_flow.c
src/gallium/drivers/llvmpipe/lp_state_fs.c

index 125259322602deafaef4d65a33c09093f7a29620..69ed014ff3da08cc03b29afd6aa55b9d9259c901 100644 (file)
@@ -386,6 +386,22 @@ lp_build_flow_skip_end(struct lp_build_flow_context *flow)
 }
 
 
+static void
+lp_build_mask_check(struct lp_build_mask_context *mask)
+{
+   LLVMBuilderRef builder = mask->flow->builder;
+   LLVMValueRef cond;
+
+   cond = LLVMBuildICmp(builder,
+                        LLVMIntEQ,
+                        LLVMBuildBitCast(builder, mask->value, mask->reg_type, ""),
+                        LLVMConstNull(mask->reg_type),
+                        "");
+
+   lp_build_flow_skip_cond_break(mask->flow, cond);
+}
+
+
 void
 lp_build_mask_begin(struct lp_build_mask_context *mask,
                     struct lp_build_flow_context *flow,
@@ -401,6 +417,8 @@ lp_build_mask_begin(struct lp_build_mask_context *mask,
    lp_build_flow_scope_begin(flow);
    lp_build_flow_scope_declare(flow, &mask->value);
    lp_build_flow_skip_begin(flow);
+
+   lp_build_mask_check(mask);
 }
 
 
@@ -408,18 +426,9 @@ void
 lp_build_mask_update(struct lp_build_mask_context *mask,
                      LLVMValueRef value)
 {
-   LLVMBuilderRef builder = mask->flow->builder;
-   LLVMValueRef cond;
-
-   mask->value = LLVMBuildAnd(builder, mask->value, value, "");
-
-   cond = LLVMBuildICmp(builder,
-                        LLVMIntEQ,
-                        LLVMBuildBitCast(builder, mask->value, mask->reg_type, ""),
-                        LLVMConstNull(mask->reg_type),
-                        "");
+   mask->value = LLVMBuildAnd( mask->flow->builder, mask->value, value, "");
 
-   lp_build_flow_skip_cond_break(mask->flow, cond);
+   lp_build_mask_check(mask);
 }
 
 
index 2e60da60cd1477506073b669eaa6b8c953aceb91..354d9916c7bae5f18d4ff46a12cf2e92a6e8a748 100644 (file)
@@ -319,6 +319,8 @@ generate_blend(const struct pipe_blend_state *blend,
                LLVMValueRef dst_ptr)
 {
    struct lp_build_context bld;
+   struct lp_build_flow_context *flow;
+   struct lp_build_mask_context mask_ctx;
    LLVMTypeRef vec_type;
    LLVMTypeRef int_vec_type;
    LLVMValueRef const_ptr;
@@ -327,11 +329,14 @@ generate_blend(const struct pipe_blend_state *blend,
    LLVMValueRef res[4];
    unsigned chan;
 
+   lp_build_context_init(&bld, builder, type);
+
+   flow = lp_build_flow_create(builder);
+   lp_build_mask_begin(&mask_ctx, flow, type, mask);
+
    vec_type = lp_build_vec_type(type);
    int_vec_type = lp_build_int_vec_type(type);
 
-   lp_build_context_init(&bld, builder, type);
-
    const_ptr = lp_jit_context_blend_color(builder, context_ptr);
    const_ptr = LLVMBuildBitCast(builder, const_ptr,
                                 LLVMPointerType(vec_type, 0), "");
@@ -354,6 +359,9 @@ generate_blend(const struct pipe_blend_state *blend,
       res[chan] = lp_build_select(&bld, mask, res[chan], dst[chan]);
       LLVMBuildStore(builder, res[chan], LLVMBuildGEP(builder, dst_ptr, &index, 1, ""));
    }
+
+   lp_build_mask_end(&mask_ctx);
+   lp_build_flow_destroy(flow);
 }