From 9e922444403d704f9ed0cf50e510fba53c736b57 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Mon, 3 Aug 2009 02:06:42 +0100 Subject: [PATCH] llvmpipe: Improve generated 8bit blending code. --- src/gallium/drivers/llvmpipe/lp_bld_blend.c | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/gallium/drivers/llvmpipe/lp_bld_blend.c b/src/gallium/drivers/llvmpipe/lp_bld_blend.c index ce8408b79bd..552e3bfd987 100644 --- a/src/gallium/drivers/llvmpipe/lp_bld_blend.c +++ b/src/gallium/drivers/llvmpipe/lp_bld_blend.c @@ -188,6 +188,35 @@ lp_build_blend_swizzle(struct lp_build_blend_context *bld, alpha = bld->base.undef; } + if(rgb_swizzle == LP_BUILD_BLEND_SWIZZLE_RGBA && + !bld->base.type.floating) { +#if 0 + /* Use a select */ + /* FIXME: Unfortunetaly select of vectors do not work */ + + for(j = 0; j < n; j += 4) + for(i = 0; i < 4; ++i) + swizzles[j + i] = LLVMConstInt(LLVMInt1Type(), i == alpha_swizzle ? 0 : 1, 0); + + return LLVMBuildSelect(bld->base.builder, LLVMConstVector(swizzles, n), rgb, alpha, ""); +#else + /* XXX: Use a bitmask, as byte shuffles often end up being translated + * into many PEXTRB. Ideally LLVM X86 code generation should pick this + * automatically for us. */ + + for(j = 0; j < n; j += 4) + for(i = 0; i < 4; ++i) + swizzles[j + i] = LLVMConstInt(LLVMIntType(bld->base.type.width), i == alpha_swizzle ? 0 : ~0, 0); + + /* TODO: Unfortunately constant propagation prevents from using PANDN. And + * on SSE4 we have even better -- PBLENDVB */ + return LLVMBuildOr(bld->base.builder, + LLVMBuildAnd(bld->base.builder, rgb, LLVMConstVector(swizzles, n), ""), + LLVMBuildAnd(bld->base.builder, alpha, LLVMBuildNot(bld->base.builder, LLVMConstVector(swizzles, n), ""), ""), + ""); +#endif + } + for(j = 0; j < n; j += 4) { for(i = 0; i < 4; ++i) { unsigned swizzle; -- 2.30.2