gallivm: Don't generate Phis for execution mask.
authorJosé Fonseca <jfonseca@vmware.com>
Sat, 9 Oct 2010 11:55:31 +0000 (12:55 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Sat, 9 Oct 2010 11:55:31 +0000 (12:55 +0100)
src/gallium/auxiliary/gallivm/lp_bld_flow.c
src/gallium/auxiliary/gallivm/lp_bld_flow.h
src/gallium/drivers/llvmpipe/lp_bld_depth.c
src/gallium/drivers/llvmpipe/lp_state_fs.c

index 1ec33c742e235dba1b7697e1c99bbfb56723bec1..a5d65e9b3968256b8856c88fed3f3a0382c5c173 100644 (file)
@@ -454,12 +454,15 @@ void
 lp_build_mask_check(struct lp_build_mask_context *mask)
 {
    LLVMBuilderRef builder = mask->flow->builder;
+   LLVMValueRef value;
    LLVMValueRef cond;
 
+   value = lp_build_mask_value(mask);
+
    /* cond = (mask == 0) */
    cond = LLVMBuildICmp(builder,
                         LLVMIntEQ,
-                        LLVMBuildBitCast(builder, mask->value, mask->reg_type, ""),
+                        LLVMBuildBitCast(builder, value, mask->reg_type, ""),
                         LLVMConstNull(mask->reg_type),
                         "");
 
@@ -485,14 +488,23 @@ lp_build_mask_begin(struct lp_build_mask_context *mask,
 
    mask->flow = flow;
    mask->reg_type = LLVMIntType(type.width * type.length);
-   mask->value = value;
+   mask->var = lp_build_alloca(flow->builder,
+                               lp_build_int_vec_type(type),
+                               "execution_mask");
+
+   LLVMBuildStore(flow->builder, value, mask->var);
 
-   lp_build_flow_scope_begin(flow);
-   lp_build_flow_scope_declare(flow, &mask->value);
    lp_build_flow_skip_begin(flow);
 }
 
 
+LLVMValueRef
+lp_build_mask_value(struct lp_build_mask_context *mask)
+{
+   return LLVMBuildLoad(mask->flow->builder, mask->var, "");
+}
+
+
 /**
  * Update boolean mask with given value (bitwise AND).
  * Typically used to update the quad's pixel alive/killed mask
@@ -502,7 +514,10 @@ void
 lp_build_mask_update(struct lp_build_mask_context *mask,
                      LLVMValueRef value)
 {
-   mask->value = LLVMBuildAnd( mask->flow->builder, mask->value, value, "");
+   value = LLVMBuildAnd(mask->flow->builder,
+                        lp_build_mask_value(mask),
+                        value, "");
+   LLVMBuildStore(mask->flow->builder, value, mask->var);
 }
 
 
@@ -513,8 +528,7 @@ LLVMValueRef
 lp_build_mask_end(struct lp_build_mask_context *mask)
 {
    lp_build_flow_skip_end(mask->flow);
-   lp_build_flow_scope_end(mask->flow);
-   return mask->value;
+   return lp_build_mask_value(mask);
 }
 
 
index 095c781ec546df69f3affab1d6bba6d62bacc6be..0fc6317b3393f96af319a2d0ccab6ca009c0dbeb 100644 (file)
@@ -77,7 +77,7 @@ struct lp_build_mask_context
 
    LLVMTypeRef reg_type;
 
-   LLVMValueRef value;
+   LLVMValueRef var;
 };
 
 
@@ -87,6 +87,9 @@ lp_build_mask_begin(struct lp_build_mask_context *mask,
                     struct lp_type type,
                     LLVMValueRef value);
 
+LLVMValueRef
+lp_build_mask_value(struct lp_build_mask_context *mask);
+
 /**
  * Bitwise AND the mask with the given value, if a previous mask was set.
  */
index 8d9be2ebbbf379426b57beb90d8f9a4f78fc5278..e768493103e164e7af3509bc0ac4e9ba57bbee41 100644 (file)
@@ -473,7 +473,7 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder,
    LLVMValueRef stencil_vals = NULL;
    LLVMValueRef z_bitmask = NULL, stencil_shift = NULL;
    LLVMValueRef z_pass = NULL, s_pass_mask = NULL;
-   LLVMValueRef orig_mask = mask->value;
+   LLVMValueRef orig_mask = lp_build_mask_value(mask);
    LLVMValueRef front_facing = NULL;
 
    /* Prototype a simpler path:
@@ -527,7 +527,7 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder,
          type.sign = 1;
          lp_build_context_init(&bld, builder, type);
 
-         z_dst = lp_build_select(&bld, mask->value, z_src, z_dst);
+         z_dst = lp_build_select(&bld, lp_build_mask_value(mask), z_src, z_dst);
          z_dst = LLVMBuildShl(builder, z_dst, const_8_int, "z_dst");
          *zs_value = z_dst;
       }
@@ -710,7 +710,7 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder,
       }
 
       if (depth->writemask) {
-         LLVMValueRef zselectmask = mask->value;
+         LLVMValueRef zselectmask = lp_build_mask_value(mask);
 
          /* mask off bits that failed Z test */
          zselectmask = LLVMBuildAnd(builder, zselectmask, z_pass, "");
@@ -810,7 +810,7 @@ lp_build_deferred_depth_write(LLVMBuilderRef builder,
    lp_build_context_init(&bld, builder, type);
 
    z_dst = LLVMBuildLoad(builder, zs_dst_ptr, "zsbufval");
-   z_dst = lp_build_select(&bld, mask->value, zs_value, z_dst);
+   z_dst = lp_build_select(&bld, lp_build_mask_value(mask), zs_value, z_dst);
 
    LLVMBuildStore(builder, z_dst, zs_dst_ptr);
 }
index f45f36f633206957a7d3ebc15c05490f080d23af..cf07cb4976414debefd341d440988821b16493e1 100644 (file)
@@ -422,16 +422,14 @@ generate_fs(struct llvmpipe_context *lp,
    }
 
    if (counter)
-      lp_build_occlusion_count(builder, type, mask.value, counter);
+      lp_build_occlusion_count(builder, type,
+                               lp_build_mask_value(&mask), counter);
 
-   lp_build_mask_end(&mask);
+   *pmask = lp_build_mask_end(&mask);
 
    lp_build_flow_scope_end(flow);
 
    lp_build_flow_destroy(flow);
-
-   *pmask = mask.value;
-
 }