gallivm: Pass condition masks as an unsigned bitmask.
Much more convenient than boolean arrays.
This commit is contained in:
parent
079763f746
commit
6ed726b8fc
|
@ -382,9 +382,12 @@ lp_build_const_aos(struct lp_type type,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mask TGSI_WRITEMASK_xxx
|
||||||
|
*/
|
||||||
LLVMValueRef
|
LLVMValueRef
|
||||||
lp_build_const_mask_aos(struct lp_type type,
|
lp_build_const_mask_aos(struct lp_type type,
|
||||||
const boolean cond[4])
|
unsigned mask)
|
||||||
{
|
{
|
||||||
LLVMTypeRef elem_type = LLVMIntType(type.width);
|
LLVMTypeRef elem_type = LLVMIntType(type.width);
|
||||||
LLVMValueRef masks[LP_MAX_VECTOR_LENGTH];
|
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);
|
assert(type.length <= LP_MAX_VECTOR_LENGTH);
|
||||||
|
|
||||||
for(j = 0; j < type.length; j += 4)
|
for (j = 0; j < type.length; j += 4) {
|
||||||
for(i = 0; i < 4; ++i)
|
for( i = 0; i < 4; ++i) {
|
||||||
masks[j + i] = LLVMConstInt(elem_type, cond[i] ? ~0 : 0, 0);
|
masks[j + i] = LLVMConstInt(elem_type,
|
||||||
|
mask & (1 << i) ? ~0ULL : 0,
|
||||||
|
1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return LLVMConstVector(masks, type.length);
|
return LLVMConstVector(masks, type.length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ lp_build_const_aos(struct lp_type type,
|
||||||
|
|
||||||
LLVMValueRef
|
LLVMValueRef
|
||||||
lp_build_const_mask_aos(struct lp_type type,
|
lp_build_const_mask_aos(struct lp_type type,
|
||||||
const boolean cond[4]);
|
unsigned mask);
|
||||||
|
|
||||||
|
|
||||||
static INLINE LLVMValueRef
|
static INLINE LLVMValueRef
|
||||||
|
|
|
@ -482,24 +482,30 @@ lp_build_select(struct lp_build_context *bld,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return mask ? a : b;
|
||||||
|
*
|
||||||
|
* mask is a TGSI_WRITEMASK_xxx.
|
||||||
|
*/
|
||||||
LLVMValueRef
|
LLVMValueRef
|
||||||
lp_build_select_aos(struct lp_build_context *bld,
|
lp_build_select_aos(struct lp_build_context *bld,
|
||||||
|
unsigned mask,
|
||||||
LLVMValueRef a,
|
LLVMValueRef a,
|
||||||
LLVMValueRef b,
|
LLVMValueRef b)
|
||||||
const boolean cond[4])
|
|
||||||
{
|
{
|
||||||
const struct lp_type type = bld->type;
|
const struct lp_type type = bld->type;
|
||||||
const unsigned n = type.length;
|
const unsigned n = type.length;
|
||||||
unsigned i, j;
|
unsigned i, j;
|
||||||
|
|
||||||
|
assert((mask & ~0xf) == 0);
|
||||||
assert(lp_check_value(type, a));
|
assert(lp_check_value(type, a));
|
||||||
assert(lp_check_value(type, b));
|
assert(lp_check_value(type, b));
|
||||||
|
|
||||||
if(a == b)
|
if(a == b)
|
||||||
return a;
|
return a;
|
||||||
if(cond[0] && cond[1] && cond[2] && cond[3])
|
if((mask & 0xf) == 0xf)
|
||||||
return a;
|
return a;
|
||||||
if(!cond[0] && !cond[1] && !cond[2] && !cond[3])
|
if((mask & 0xf) == 0x0)
|
||||||
return b;
|
return b;
|
||||||
if(a == bld->undef || b == bld->undef)
|
if(a == bld->undef || b == bld->undef)
|
||||||
return 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(j = 0; j < n; j += 4)
|
||||||
for(i = 0; i < 4; ++i)
|
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), "");
|
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 */
|
/* XXX: Unfortunately select of vectors do not work */
|
||||||
/* Use a select */
|
/* Use a select */
|
||||||
LLVMTypeRef elem_type = LLVMInt1Type();
|
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(j = 0; j < n; j += 4)
|
||||||
for(i = 0; i < 4; ++i)
|
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
|
#else
|
||||||
LLVMValueRef mask = lp_build_const_mask_aos(type, cond);
|
LLVMValueRef mask_vec = lp_build_const_mask_aos(type, mask);
|
||||||
return lp_build_select(bld, mask, a, b);
|
return lp_build_select(bld, mask_vec, a, b);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,9 +77,9 @@ lp_build_select(struct lp_build_context *bld,
|
||||||
|
|
||||||
LLVMValueRef
|
LLVMValueRef
|
||||||
lp_build_select_aos(struct lp_build_context *bld,
|
lp_build_select_aos(struct lp_build_context *bld,
|
||||||
|
unsigned mask,
|
||||||
LLVMValueRef a,
|
LLVMValueRef a,
|
||||||
LLVMValueRef b,
|
LLVMValueRef b);
|
||||||
const boolean cond[4]);
|
|
||||||
|
|
||||||
|
|
||||||
LLVMValueRef
|
LLVMValueRef
|
||||||
|
|
|
@ -139,13 +139,10 @@ lp_build_broadcast_aos(struct lp_build_context *bld,
|
||||||
{ 1, -2},
|
{ 1, -2},
|
||||||
{-1, -2}
|
{-1, -2}
|
||||||
};
|
};
|
||||||
boolean cond[4];
|
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
memset(cond, 0, sizeof cond);
|
a = LLVMBuildAnd(bld->builder, a,
|
||||||
cond[channel] = 1;
|
lp_build_const_mask_aos(type, 1 << channel), "");
|
||||||
|
|
||||||
a = LLVMBuildAnd(bld->builder, a, lp_build_const_mask_aos(type, cond), "");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Build a type where each element is an integer that cover the four
|
* 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;
|
LLVMValueRef res;
|
||||||
struct lp_type type4;
|
struct lp_type type4;
|
||||||
boolean cond[4];
|
unsigned cond = 0;
|
||||||
unsigned chan;
|
unsigned chan;
|
||||||
int shift;
|
int shift;
|
||||||
|
|
||||||
|
@ -290,9 +287,11 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
|
||||||
* Start with a mixture of 1 and 0.
|
* Start with a mixture of 1 and 0.
|
||||||
*/
|
*/
|
||||||
for (chan = 0; chan < 4; ++chan) {
|
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
|
* Build a type where each element is an integer that cover the four
|
||||||
|
|
|
@ -205,9 +205,8 @@ lp_build_blend_swizzle(struct lp_build_blend_aos_context *bld,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rgb != alpha) {
|
if (rgb != alpha) {
|
||||||
boolean cond[4] = {0, 0, 0, 0};
|
swizzled_rgb = lp_build_select_aos(&bld->base, 1 << alpha_swizzle,
|
||||||
cond[alpha_swizzle] = 1;
|
alpha, swizzled_rgb);
|
||||||
swizzled_rgb = lp_build_select_aos(&bld->base, alpha, swizzled_rgb, cond);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return swizzled_rgb;
|
return swizzled_rgb;
|
||||||
|
|
Loading…
Reference in New Issue