llvmpipe: Centralize mask update logic.
authorJosé Fonseca <jfonseca@vmware.com>
Fri, 21 Aug 2009 06:42:29 +0000 (07:42 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Sat, 29 Aug 2009 08:21:37 +0000 (09:21 +0100)
src/gallium/drivers/llvmpipe/lp_bld_alpha.c
src/gallium/drivers/llvmpipe/lp_bld_alpha.h
src/gallium/drivers/llvmpipe/lp_bld_logic.c
src/gallium/drivers/llvmpipe/lp_bld_logic.h
src/gallium/drivers/llvmpipe/lp_bld_tgsi.h
src/gallium/drivers/llvmpipe/lp_bld_tgsi_soa.c
src/gallium/drivers/llvmpipe/lp_state_fs.c

index a3faa22b9978608091edf8c7a8c254c234f42a6f..58f6f6cd8ff265b0a5ab5df4cea9d79b5a20ba13 100644 (file)
 #include "lp_bld_alpha.h"
 
 
-LLVMValueRef
+void
 lp_build_alpha_test(LLVMBuilderRef builder,
                     const struct pipe_alpha_state *state,
                     union lp_type type,
-                    LLVMValueRef alpha,
-                    LLVMValueRef mask)
+                    LLVMValueRef *mask,
+                    LLVMValueRef alpha)
 {
    struct lp_build_context bld;
 
@@ -58,11 +58,6 @@ lp_build_alpha_test(LLVMBuilderRef builder,
 
       lp_build_name(test, "alpha_mask");
 
-      if(mask)
-         mask = LLVMBuildAnd(builder, mask, test, "");
-      else
-         mask = test;
+      lp_build_mask_and(builder, mask, test);
    }
-
-   return mask;
 }
index f3fa8b605348bf95e3ecb664b81aed25b04bd4a2..f372210a7a0201b1d61d80fde3bb2de0a93deda1 100644 (file)
@@ -41,12 +41,12 @@ struct pipe_alpha_state;
 union lp_type;
 
 
-LLVMValueRef
+void
 lp_build_alpha_test(LLVMBuilderRef builder,
                     const struct pipe_alpha_state *state,
                     union lp_type type,
-                    LLVMValueRef alpha,
-                    LLVMValueRef mask);
+                    LLVMValueRef *mask,
+                    LLVMValueRef alpha);
 
 
 #endif /* !LP_BLD_ALPHA_H */
index 5b8efb05778a8249564537fa12efe011e4f7f146..1ce9a9109e89f2e00b2596c615d0729436cab9a2 100644 (file)
 #include "lp_bld_logic.h"
 
 
+void
+lp_build_mask_and(LLVMBuilderRef builder,
+                  LLVMValueRef *mask,
+                  LLVMValueRef value)
+{
+   if(*mask)
+      *mask = LLVMBuildAnd(builder, *mask, value, "");
+   else
+      *mask = value;
+}
+
+
 LLVMValueRef
 lp_build_cmp(struct lp_build_context *bld,
              unsigned func,
index 0989f9f20784a0c9e48eedc746304823c51e17d0..8ba73b94eda05f0328ce34bb1d4b2ddde19e9ced 100644 (file)
@@ -44,6 +44,15 @@ union lp_type type;
 struct lp_build_context;
 
 
+/**
+ * Bitwise AND the mask with the given value, if a previous mask was set.
+ */
+void
+lp_build_mask_and(LLVMBuilderRef builder,
+                  LLVMValueRef *mask,
+                  LLVMValueRef value);
+
+
 /**
  * @param func is one of PIPE_FUNC_xxx
  */
index b61b2dc5bfdf387ea414d39801468eedfda6affb..7ad711e396d2fcc633b7a9c9b8b0fb4a606fdd1d 100644 (file)
@@ -40,10 +40,11 @@ lp_build_tgsi_fetch_texel_soa( struct tgsi_sampler **samplers,
                                uint32_t unit,
                                float *store );
 
-LLVMValueRef
+void
 lp_build_tgsi_soa(LLVMBuilderRef builder,
                   const struct tgsi_token *tokens,
                   union lp_type type,
+                  LLVMValueRef *mask,
                   LLVMValueRef *pos,
                   LLVMValueRef a0_ptr,
                   LLVMValueRef dadx_ptr,
index 01328c1c48a0686f3df017f9908b08e180e4878a..e392a50005fe79e60d72c482af9ec3f0cc3a3595 100644 (file)
@@ -88,7 +88,7 @@ struct lp_build_tgsi_soa_context
    LLVMValueRef immediates[LP_MAX_IMMEDIATES][NUM_CHANNELS];
    LLVMValueRef temps[LP_MAX_TEMPS][NUM_CHANNELS];
 
-   LLVMValueRef mask;
+   LLVMValueRef *mask;
 
    /** Coords/texels store */
    LLVMValueRef store_ptr;
@@ -395,10 +395,7 @@ emit_kil(
 
          mask = lp_build_cmp(&bld->base, PIPE_FUNC_GEQUAL, terms[chan_index], bld->base.zero);
 
-         if(bld->mask)
-            bld->mask = LLVMBuildAnd(bld->base.builder, bld->mask, mask, "");
-         else
-            bld->mask = mask;
+         lp_build_mask_and(bld->base.builder, bld->mask, mask);
       }
    }
 }
@@ -1409,19 +1406,12 @@ emit_declaration(
    }
 }
 
-/**
- * Translate a TGSI vertex/fragment shader to SSE2 code.
- * Slightly different things are done for vertex vs. fragment shaders.
- *
- * \param tokens  the TGSI input shader
- * \param bld  the output SSE code/function
- * \param immediates  buffer to place immediates, later passed to SSE bld
- * \param return  1 for success, 0 if translation failed
- */
-LLVMValueRef
+
+void
 lp_build_tgsi_soa(LLVMBuilderRef builder,
                   const struct tgsi_token *tokens,
                   union lp_type type,
+                  LLVMValueRef *mask,
                   LLVMValueRef *pos,
                   LLVMValueRef a0_ptr,
                   LLVMValueRef dadx_ptr,
@@ -1438,6 +1428,7 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
    /* Setup build context */
    memset(&bld, 0, sizeof bld);
    lp_build_context_init(&bld.base, builder, type);
+   bld.mask = mask;
    bld.x = pos[0];
    bld.y = pos[1];
    bld.w = pos[3];
@@ -1490,7 +1481,5 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
    }
 
    tgsi_parse_free( &parse );
-
-   return bld.mask;
 }
 
index 702be429164cbadb97bda0a73eb3d7300820af5f..22274676df66fc34c429f75d7a13d6d523097d7f 100644 (file)
@@ -210,11 +210,13 @@ shader_generate(struct llvmpipe_screen *screen,
 
    setup_pos_vector(builder, x, y, a0_ptr, dadx_ptr, dady_ptr, pos);
 
+   mask = LLVMBuildLoad(builder, mask_ptr, "");
+
    memset(outputs, 0, sizeof outputs);
 
-   mask = lp_build_tgsi_soa(builder, tokens, type,
-                            pos, a0_ptr, dadx_ptr, dady_ptr,
-                            consts_ptr, outputs, samplers_ptr);
+   lp_build_tgsi_soa(builder, tokens, type, &mask,
+                     pos, a0_ptr, dadx_ptr, dady_ptr,
+                     consts_ptr, outputs, samplers_ptr);
 
    for (attrib = 0; attrib < shader->info.num_outputs; ++attrib) {
       for(chan = 0; chan < NUM_CHANNELS; ++chan) {
@@ -233,7 +235,8 @@ shader_generate(struct llvmpipe_screen *screen,
                   /* Alpha test */
                   /* XXX: should the alpha reference value be passed separately? */
                   if(cbuf == 0 && chan == 3)
-                     mask = lp_build_alpha_test(builder, alpha, type, outputs[attrib][chan], mask);
+                     lp_build_alpha_test(builder, &key->alpha, type, &mask,
+                                         outputs[attrib][chan]);
 
                   break;
                }