diff options
author | James Benton <[email protected]> | 2012-04-18 15:25:34 +0100 |
---|---|---|
committer | José Fonseca <[email protected]> | 2012-05-02 10:12:48 +0100 |
commit | 0b0f4628d6fb8276a9f1c336a785a838b602bca8 (patch) | |
tree | d2034e3fb529499e3a0c389ec40ad2c815996ca9 /src/gallium/drivers | |
parent | 85d09d1c61d3e5ab2c2ae6fc74a30ea6a572f25e (diff) |
llvmpipe: Added support for color masks in AoS blending.
Signed-off-by: José Fonseca <[email protected]>
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r-- | src/gallium/drivers/llvmpipe/lp_bld_blend.h | 3 | ||||
-rw-r--r-- | src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c | 75 | ||||
-rw-r--r-- | src/gallium/drivers/llvmpipe/lp_state_fs.c | 9 | ||||
-rw-r--r-- | src/gallium/drivers/llvmpipe/lp_test_blend.c | 4 |
4 files changed, 58 insertions, 33 deletions
diff --git a/src/gallium/drivers/llvmpipe/lp_bld_blend.h b/src/gallium/drivers/llvmpipe/lp_bld_blend.h index f82ae30bb7d..00838a66342 100644 --- a/src/gallium/drivers/llvmpipe/lp_bld_blend.h +++ b/src/gallium/drivers/llvmpipe/lp_bld_blend.h @@ -64,12 +64,13 @@ lp_build_blend_func(struct lp_build_context *bld, 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]); void diff --git a/src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c b/src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c index c342346a36e..678dac81f28 100644 --- a/src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c +++ b/src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c @@ -45,6 +45,7 @@ #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" @@ -303,22 +304,20 @@ lp_build_blend_func(struct lp_build_context *bld, 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); @@ -327,30 +326,56 @@ lp_build_blend_aos(struct gallivm_state *gallivm, 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; } diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 482f4e38632..582c6db15d5 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -924,6 +924,7 @@ generate_variant(struct llvmpipe_context *lp, const struct lp_fragment_shader_variant_key *key) { struct lp_fragment_shader_variant *variant; + const struct util_format_description *cbuf0_format_desc; boolean fullcolormask; variant = CALLOC_STRUCT(lp_fragment_shader_variant); @@ -942,12 +943,8 @@ generate_variant(struct llvmpipe_context *lp, */ fullcolormask = FALSE; if (key->nr_cbufs == 1) { - const struct util_format_description *format_desc; - format_desc = util_format_description(key->cbuf_format[0]); - if ((~key->blend.rt[0].colormask & - util_format_colormask(format_desc)) == 0) { - fullcolormask = TRUE; - } + cbuf0_format_desc = util_format_description(key->cbuf_format[0]); + fullcolormask = util_format_colormask_full(cbuf0_format_desc, key->blend.rt[0].colormask); } variant->opaque = diff --git a/src/gallium/drivers/llvmpipe/lp_test_blend.c b/src/gallium/drivers/llvmpipe/lp_test_blend.c index b3ca134131d..af66ac388f7 100644 --- a/src/gallium/drivers/llvmpipe/lp_test_blend.c +++ b/src/gallium/drivers/llvmpipe/lp_test_blend.c @@ -179,7 +179,9 @@ add_blend_test(struct gallivm_state *gallivm, 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); @@ -205,7 +207,7 @@ add_blend_test(struct gallivm_state *gallivm, 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"); |