gallivm: Pass condition masks as an unsigned bitmask.

Much more convenient than boolean arrays.
This commit is contained in:
José Fonseca 2010-09-02 11:32:09 +01:00
parent 079763f746
commit 6ed726b8fc
6 changed files with 42 additions and 28 deletions

View File

@ -382,9 +382,12 @@ lp_build_const_aos(struct lp_type type,
}
/**
* @param mask TGSI_WRITEMASK_xxx
*/
LLVMValueRef
lp_build_const_mask_aos(struct lp_type type,
const boolean cond[4])
unsigned mask)
{
LLVMTypeRef elem_type = LLVMIntType(type.width);
LLVMValueRef masks[LP_MAX_VECTOR_LENGTH];
@ -392,9 +395,13 @@ lp_build_const_mask_aos(struct lp_type type,
assert(type.length <= LP_MAX_VECTOR_LENGTH);
for(j = 0; j < type.length; j += 4)
for(i = 0; i < 4; ++i)
masks[j + i] = LLVMConstInt(elem_type, cond[i] ? ~0 : 0, 0);
for (j = 0; j < type.length; j += 4) {
for( i = 0; i < 4; ++i) {
masks[j + i] = LLVMConstInt(elem_type,
mask & (1 << i) ? ~0ULL : 0,
1);
}
}
return LLVMConstVector(masks, type.length);
}

View File

@ -104,7 +104,7 @@ lp_build_const_aos(struct lp_type type,
LLVMValueRef
lp_build_const_mask_aos(struct lp_type type,
const boolean cond[4]);
unsigned mask);
static INLINE LLVMValueRef

View File

@ -482,24 +482,30 @@ lp_build_select(struct lp_build_context *bld,
}
/**
* Return mask ? a : b;
*
* mask is a TGSI_WRITEMASK_xxx.
*/
LLVMValueRef
lp_build_select_aos(struct lp_build_context *bld,
unsigned mask,
LLVMValueRef a,
LLVMValueRef b,
const boolean cond[4])
LLVMValueRef b)
{
const struct lp_type type = bld->type;
const unsigned n = type.length;
unsigned i, j;
assert((mask & ~0xf) == 0);
assert(lp_check_value(type, a));
assert(lp_check_value(type, b));
if(a == b)
return a;
if(cond[0] && cond[1] && cond[2] && cond[3])
if((mask & 0xf) == 0xf)
return a;
if(!cond[0] && !cond[1] && !cond[2] && !cond[3])
if((mask & 0xf) == 0x0)
return b;
if(a == bld->undef || b == bld->undef)
return bld->undef;
@ -522,7 +528,9 @@ lp_build_select_aos(struct lp_build_context *bld,
for(j = 0; j < n; j += 4)
for(i = 0; i < 4; ++i)
shuffles[j + i] = LLVMConstInt(elem_type, (cond[i] ? 0 : n) + j + i, 0);
shuffles[j + i] = LLVMConstInt(elem_type,
(mask & (1 << i) ? 0 : n) + j + i,
0);
return LLVMBuildShuffleVector(bld->builder, a, b, LLVMConstVector(shuffles, n), "");
}
@ -531,16 +539,17 @@ lp_build_select_aos(struct lp_build_context *bld,
/* XXX: Unfortunately select of vectors do not work */
/* Use a select */
LLVMTypeRef elem_type = LLVMInt1Type();
LLVMValueRef cond[LP_MAX_VECTOR_LENGTH];
LLVMValueRef cond_vec[LP_MAX_VECTOR_LENGTH];
for(j = 0; j < n; j += 4)
for(i = 0; i < 4; ++i)
cond[j + i] = LLVMConstInt(elem_type, cond[i] ? 1 : 0, 0);
cond_vec[j + i] = LLVMConstInt(elem_type,
mask & (1 << i) ? 1 : 0, 0);
return LLVMBuildSelect(bld->builder, LLVMConstVector(cond, n), a, b, "");
return LLVMBuildSelect(bld->builder, LLVMConstVector(cond_vec, n), a, b, "");
#else
LLVMValueRef mask = lp_build_const_mask_aos(type, cond);
return lp_build_select(bld, mask, a, b);
LLVMValueRef mask_vec = lp_build_const_mask_aos(type, mask);
return lp_build_select(bld, mask_vec, a, b);
#endif
}
}

View File

@ -77,9 +77,9 @@ lp_build_select(struct lp_build_context *bld,
LLVMValueRef
lp_build_select_aos(struct lp_build_context *bld,
unsigned mask,
LLVMValueRef a,
LLVMValueRef b,
const boolean cond[4]);
LLVMValueRef b);
LLVMValueRef

View File

@ -139,13 +139,10 @@ lp_build_broadcast_aos(struct lp_build_context *bld,
{ 1, -2},
{-1, -2}
};
boolean cond[4];
unsigned i;
memset(cond, 0, sizeof cond);
cond[channel] = 1;
a = LLVMBuildAnd(bld->builder, a, lp_build_const_mask_aos(type, cond), "");
a = LLVMBuildAnd(bld->builder, a,
lp_build_const_mask_aos(type, 1 << channel), "");
/*
* Build a type where each element is an integer that cover the four
@ -282,7 +279,7 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
*/
LLVMValueRef res;
struct lp_type type4;
boolean cond[4];
unsigned cond = 0;
unsigned chan;
int shift;
@ -290,9 +287,11 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
* Start with a mixture of 1 and 0.
*/
for (chan = 0; chan < 4; ++chan) {
cond[chan] = swizzles[chan] == PIPE_SWIZZLE_ONE ? TRUE : FALSE;
if (swizzles[chan] == PIPE_SWIZZLE_ONE) {
cond |= 1 << chan;
}
}
res = lp_build_select_aos(bld, bld->one, bld->zero, cond);
res = lp_build_select_aos(bld, cond, bld->one, bld->zero);
/*
* Build a type where each element is an integer that cover the four

View File

@ -205,9 +205,8 @@ lp_build_blend_swizzle(struct lp_build_blend_aos_context *bld,
}
if (rgb != alpha) {
boolean cond[4] = {0, 0, 0, 0};
cond[alpha_swizzle] = 1;
swizzled_rgb = lp_build_select_aos(&bld->base, alpha, swizzled_rgb, cond);
swizzled_rgb = lp_build_select_aos(&bld->base, 1 << alpha_swizzle,
alpha, swizzled_rgb);
}
return swizzled_rgb;