gallivm: Added lp_build_const_mask_aos_swizzled
authorJames Benton <jbenton@vmware.com>
Wed, 25 Apr 2012 10:19:07 +0000 (11:19 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Wed, 2 May 2012 09:24:34 +0000 (10:24 +0100)
Allows the creation of const aos masks which have the mask swizzled
to match the correct format.

Updated existing mask creation code to use the swizzled version where
necessary (tgsi register masks and llvmpipe aos blending).

Signed-off-by: José 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_tgsi_aos.c
src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c

index 6d8b7c26fc8344f37e588dc9d3133e4bce26fb9e..77ec1a70860554b0ae3adb0c7c448f9b88a2b382 100644 (file)
@@ -409,3 +409,22 @@ lp_build_const_mask_aos(struct gallivm_state *gallivm,
 
    return LLVMConstVector(masks, type.length);
 }
+
+
+/**
+ * Performs lp_build_const_mask_aos, but first swizzles the mask
+ */
+LLVMValueRef
+lp_build_const_mask_aos_swizzled(struct gallivm_state *gallivm,
+                        struct lp_type type,
+                        unsigned mask,
+                        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);
+
+   return lp_build_const_mask_aos(gallivm, type, mask);
+}
index 69718eb4b3d1116ec1da2e6ca0aeef5d302cb3db..fd398516952405ed2236dc5233fc97a02c7c2460 100644 (file)
@@ -111,6 +111,13 @@ lp_build_const_mask_aos(struct gallivm_state *gallivm,
                         unsigned mask);
 
 
+LLVMValueRef
+lp_build_const_mask_aos_swizzled(struct gallivm_state *gallivm,
+                        struct lp_type type,
+                        unsigned mask,
+                        const unsigned char *swizzle);
+
+
 static INLINE LLVMValueRef
 lp_build_const_int32(struct gallivm_state *gallivm, int i)
 {
index 19652d13f3cbe73b7b6140615e460e5922852501..24bc13a9be87471d68f6d4cfdfe7861164d04638 100644 (file)
@@ -325,8 +325,10 @@ lp_emit_store_aos(
    if (reg->Register.WriteMask != TGSI_WRITEMASK_XYZW) {
       LLVMValueRef writemask;
 
-      writemask = lp_build_const_mask_aos(bld->bld_base.base.gallivm, bld->bld_base.base.type,
-                                          reg->Register.WriteMask);
+      writemask = lp_build_const_mask_aos_swizzled(bld->bld_base.base.gallivm,
+                                                   bld->bld_base.base.type,
+                                                   reg->Register.WriteMask,
+                                                   bld->swizzles);
 
       if (mask) {
          mask = LLVMBuildAnd(builder, mask, writemask, "");
index e67286baf5eb5173327ab29290b9e67030b32bd4..59d5f545966086e32f458776e1284add3b9a7978 100644 (file)
@@ -380,16 +380,8 @@ lp_build_blend_aos(struct gallivm_state *gallivm,
 
    if (!fullcolormask) {
       LLVMValueRef color_mask;
-      unsigned color_mask_swizzle;
 
-      /* Swizzle the color mask to ensure it matches target format */
-      color_mask_swizzle =
-               ((blend->rt[rt].colormask & (1 << swizzle[0])) >> swizzle[0])
-            | (((blend->rt[rt].colormask & (1 << swizzle[1])) >> swizzle[1]) << 1)
-            | (((blend->rt[rt].colormask & (1 << swizzle[2])) >> swizzle[2]) << 2)
-            | (((blend->rt[rt].colormask & (1 << swizzle[3])) >> swizzle[3]) << 3);
-
-      color_mask = lp_build_const_mask_aos(gallivm, bld.base.type, color_mask_swizzle);
+      color_mask = lp_build_const_mask_aos_swizzled(gallivm, bld.base.type, blend->rt[rt].colormask, swizzle);
       lp_build_name(color_mask, "color_mask");
 
       /* Combine with input mask if necessary */