#include "pipe/p_state.h"
#include "util/u_debug.h"
+#include "util/u_format.h"
#include "gallivm/lp_bld_type.h"
#include "gallivm/lp_bld_const.h"
LLVMValueRef
lp_build_blend_aos(struct gallivm_state *gallivm,
const struct pipe_blend_state *blend,
+ const enum pipe_format *cbuf_format,
struct lp_type type,
unsigned rt,
LLVMValueRef src,
LLVMValueRef dst,
LLVMValueRef const_,
- unsigned alpha_swizzle)
+ const unsigned char swizzle[4])
{
struct lp_build_blend_aos_context bld;
LLVMValueRef src_term;
LLVMValueRef dst_term;
-
- /* FIXME: color masking not implemented yet */
- assert(blend->rt[rt].colormask == 0xf);
-
- if(!blend->rt[rt].blend_enable)
- return src;
+ LLVMValueRef result;
+ unsigned alpha_swizzle = swizzle[3];
+ boolean fullcolormask;
/* Setup build context */
memset(&bld, 0, sizeof bld);
bld.dst = dst;
bld.const_ = const_;
- /* TODO: There are still a few optimization opportunities here. For certain
- * combinations it is possible to reorder the operations and therefore saving
- * some instructions. */
+ if (!blend->rt[rt].blend_enable) {
+ result = src;
+ } else {
+
+ /* TODO: There are still a few optimization opportunities here. For certain
+ * combinations it is possible to reorder the operations and therefore saving
+ * some instructions. */
+
+ src_term = lp_build_blend_factor(&bld, src, blend->rt[rt].rgb_src_factor,
+ blend->rt[rt].alpha_src_factor, alpha_swizzle);
+ dst_term = lp_build_blend_factor(&bld, dst, blend->rt[rt].rgb_dst_factor,
+ blend->rt[rt].alpha_dst_factor, alpha_swizzle);
+
+ lp_build_name(src_term, "src_term");
+ lp_build_name(dst_term, "dst_term");
+
+ if(blend->rt[rt].rgb_func == blend->rt[rt].alpha_func) {
+ result = lp_build_blend_func(&bld.base, blend->rt[rt].rgb_func, src_term, dst_term);
+ }
+ else {
+ /* Seperate RGB / A functions */
- src_term = lp_build_blend_factor(&bld, src, blend->rt[rt].rgb_src_factor,
- blend->rt[rt].alpha_src_factor, alpha_swizzle);
- dst_term = lp_build_blend_factor(&bld, dst, blend->rt[rt].rgb_dst_factor,
- blend->rt[rt].alpha_dst_factor, alpha_swizzle);
+ LLVMValueRef rgb;
+ LLVMValueRef alpha;
- lp_build_name(src_term, "src_term");
- lp_build_name(dst_term, "dst_term");
+ rgb = lp_build_blend_func(&bld.base, blend->rt[rt].rgb_func, src_term, dst_term);
+ alpha = lp_build_blend_func(&bld.base, blend->rt[rt].alpha_func, src_term, dst_term);
- if(blend->rt[rt].rgb_func == blend->rt[rt].alpha_func) {
- return lp_build_blend_func(&bld.base, blend->rt[rt].rgb_func, src_term, dst_term);
+ result = lp_build_blend_swizzle(&bld, rgb, alpha, LP_BUILD_BLEND_SWIZZLE_RGBA, alpha_swizzle);
+ }
}
- else {
- /* Seperate RGB / A functions */
- LLVMValueRef rgb;
- LLVMValueRef alpha;
+ /* Apply color masking if necessary */
+ fullcolormask = util_format_colormask_full(util_format_description(cbuf_format[rt]), blend->rt[rt].colormask);
- rgb = lp_build_blend_func(&bld.base, blend->rt[rt].rgb_func, src_term, dst_term);
- alpha = lp_build_blend_func(&bld.base, blend->rt[rt].alpha_func, src_term, dst_term);
+ if (!fullcolormask) {
+ LLVMValueRef mask;
+ unsigned mask_swizzle;
- return lp_build_blend_swizzle(&bld, rgb, alpha, LP_BUILD_BLEND_SWIZZLE_RGBA, alpha_swizzle);
+ /* Swizzle the color mask to ensure it matches target format */
+ 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);
+
+ mask = lp_build_const_mask_aos(gallivm, bld.base.type, mask_swizzle);
+
+ result = lp_build_select(&bld.base, mask, result, dst);
}
+
+ return result;
}
LLVMValueRef res_ptr;
LLVMBasicBlockRef block;
LLVMBuilderRef builder;
+ const enum pipe_format format = PIPE_FORMAT_R8G8B8A8_UNORM;
const unsigned rt = 0;
+ const unsigned char swizzle[4] = { 0, 1, 2, 3 };
vec_type = lp_build_vec_type(gallivm, type);
dst = LLVMBuildLoad(builder, dst_ptr, "dst");
con = LLVMBuildLoad(builder, const_ptr, "const");
- res = lp_build_blend_aos(gallivm, blend, type, rt, src, dst, con, 3);
+ res = lp_build_blend_aos(gallivm, blend, &format, type, rt, src, dst, con, swizzle);
lp_build_name(res, "res");