gallivm: Updated lp_build_const_mask_aos to input number of channels.
authorJames Benton <jbenton@vmware.com>
Wed, 11 Jul 2012 14:39:53 +0000 (15:39 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Wed, 28 Nov 2012 19:14:36 +0000 (19:14 +0000)
Also updated lp_build_const_mask_aos_swizzled to reflect this.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/gallium/auxiliary/gallivm/lp_bld_const.c
src/gallium/auxiliary/gallivm/lp_bld_const.h
src/gallium/auxiliary/gallivm/lp_bld_logic.c
src/gallium/auxiliary/gallivm/lp_bld_swizzle.c
src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c
src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c
src/gallium/drivers/llvmpipe/lp_state_setup.c

index 24ed23adc35d326f8a571ea935e9a55a33f36af2..0f5a8f8e851a7d54b32b6a54769327761f528272 100644 (file)
@@ -394,7 +394,8 @@ lp_build_const_aos(struct gallivm_state *gallivm,
 LLVMValueRef
 lp_build_const_mask_aos(struct gallivm_state *gallivm,
                         struct lp_type type,
-                        unsigned mask)
+                        unsigned mask,
+                        unsigned channels)
 {
    LLVMTypeRef elem_type = LLVMIntTypeInContext(gallivm->context, type.width);
    LLVMValueRef masks[LP_MAX_VECTOR_LENGTH];
@@ -402,8 +403,8 @@ lp_build_const_mask_aos(struct gallivm_state *gallivm,
 
    assert(type.length <= LP_MAX_VECTOR_LENGTH);
 
-   for (j = 0; j < type.length; j += 4) {
-      for( i = 0; i < 4; ++i) {
+   for (j = 0; j < type.length; j += channels) {
+      for( i = 0; i < channels; ++i) {
          masks[j + i] = LLVMConstInt(elem_type,
                                      mask & (1 << i) ? ~0ULL : 0,
                                      1);
@@ -419,17 +420,21 @@ lp_build_const_mask_aos(struct gallivm_state *gallivm,
  */
 LLVMValueRef
 lp_build_const_mask_aos_swizzled(struct gallivm_state *gallivm,
-                        struct lp_type type,
-                        unsigned mask,
-                        const unsigned char *swizzle)
+                                 struct lp_type type,
+                                 unsigned mask,
+                                 unsigned channels,
+                                 const unsigned char *swizzle)
 {
-   mask =
-           ((mask & (1 << swizzle[0])) >> swizzle[0])
-        | (((mask & (1 << swizzle[1])) >> swizzle[1]) << 1)
-        | (((mask & (1 << swizzle[2])) >> swizzle[2]) << 2)
-        | (((mask & (1 << swizzle[3])) >> swizzle[3]) << 3);
+   unsigned i, mask_swizzled;
+   mask_swizzled = 0;
+
+   for (i = 0; i < channels; ++i) {
+      if (swizzle[i] < 4) {
+         mask_swizzled |= ((mask & (1 << swizzle[i])) >> swizzle[i]) << i;
+      }
+   }
 
-   return lp_build_const_mask_aos(gallivm, type, mask);
+   return lp_build_const_mask_aos(gallivm, type, mask_swizzled, channels);
 }
 
 
index 2205616274f2d48d67e5b50af9bd84bfced9f6ef..b17c41931f4d31a503e9ade21001e111ca6d423d 100644 (file)
@@ -108,14 +108,16 @@ lp_build_const_aos(struct gallivm_state *gallivm, struct lp_type type,
 LLVMValueRef
 lp_build_const_mask_aos(struct gallivm_state *gallivm,
                         struct lp_type type,
-                        unsigned mask);
+                        unsigned mask,
+                        unsigned channels);
 
 
 LLVMValueRef
 lp_build_const_mask_aos_swizzled(struct gallivm_state *gallivm,
-                        struct lp_type type,
-                        unsigned mask,
-                        const unsigned char *swizzle);
+                                 struct lp_type type,
+                                 unsigned mask,
+                                 unsigned channels,
+                                 const unsigned char *swizzle);
 
 
 static INLINE LLVMValueRef
index 7a4a5bb11d30ceda6377ce6a0d45f0f6e3b86f39..8a77a43dae8dd7c6e20bf0ad34061ec1fc52d2c2 100644 (file)
@@ -603,7 +603,7 @@ lp_build_select_aos(struct lp_build_context *bld,
       return LLVMBuildShuffleVector(builder, a, b, LLVMConstVector(shuffles, n), "");
    }
    else {
-      LLVMValueRef mask_vec = lp_build_const_mask_aos(bld->gallivm, type, mask);
+      LLVMValueRef mask_vec = lp_build_const_mask_aos(bld->gallivm, type, mask, 4);
       return lp_build_select(bld, mask_vec, a, b);
    }
 }
index 3d70252e75ac6a25c3cbb897bfc621e78a203b79..4ae4f3752a8f5364c59e479fa296d134a8c0830e 100644 (file)
@@ -210,7 +210,7 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld,
 
       a = LLVMBuildAnd(builder, a,
                        lp_build_const_mask_aos(bld->gallivm,
-                                               type, 1 << channel), "");
+                                               type, 1 << channel, 4), "");
 
       /*
        * Build a type where each element is an integer that cover the four
index 625aac2697b43fe7a691b3276854b15f78d5b12a..44f684a1d0151d696acec34514ef830c06c35664 100644 (file)
@@ -329,6 +329,7 @@ lp_emit_store_aos(
       writemask = lp_build_const_mask_aos_swizzled(bld->bld_base.base.gallivm,
                                                    bld->bld_base.base.type,
                                                    reg->Register.WriteMask,
+                                                   TGSI_NUM_CHANNELS,
                                                    bld->swizzles);
 
       if (mask) {
index 66df662711ce8733b4d7d40e1a6f884208a00668..c615c2d6f5be7deb095f26e7bafd0bfaac287d92 100644 (file)
@@ -267,12 +267,15 @@ lp_build_blend_aos(struct gallivm_state *gallivm,
                    const unsigned char swizzle[4])
 {
    const struct pipe_rt_blend_state * state = &blend->rt[rt];
+   const struct util_format_description * desc;
    struct lp_build_blend_aos_context bld;
    LLVMValueRef src_factor, dst_factor;
    LLVMValueRef result;
    unsigned alpha_swizzle = swizzle[3];
    boolean fullcolormask;
 
+   desc = util_format_description(cbuf_format[rt]);
+
    /* Setup build context */
    memset(&bld, 0, sizeof bld);
    lp_build_context_init(&bld.base, gallivm, type);
@@ -333,7 +336,7 @@ lp_build_blend_aos(struct gallivm_state *gallivm,
    if (!fullcolormask) {
       LLVMValueRef color_mask;
 
-      color_mask = lp_build_const_mask_aos_swizzled(gallivm, bld.base.type, state->colormask, swizzle);
+      color_mask = lp_build_const_mask_aos_swizzled(gallivm, bld.base.type, state.colormask, desc->nr_channels, swizzle);
       lp_build_name(color_mask, "color_mask");
 
       /* Combine with input mask if necessary */
index 469a4595556fd99a03c27c865b6e1ca12c804f78..f44eed49fba8822b616ea56a8a68d13c93fc7b40 100644 (file)
@@ -472,7 +472,7 @@ emit_apply_cyl_wrap(struct gallivm_state *gallivm,
    /* Constants */
    pos_half = lp_build_const_vec(gallivm, type, +0.5f);
    neg_half = lp_build_const_vec(gallivm, type, -0.5f);
-   cyl_mask = lp_build_const_mask_aos(gallivm, type, cyl_wrap);
+   cyl_mask = lp_build_const_mask_aos(gallivm, type, cyl_wrap, 4);
 
    one = lp_build_const_vec(gallivm, type, 1.0f);
    one = LLVMBuildBitCast(builder, one, lp_build_int_vec_type(gallivm, type), "");