mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-24 08:50:13 +01:00
llvmpipe: Added support for color masks in AoS blending.
Signed-off-by: José Fonseca <jfonseca@vmware.com>
This commit is contained in:
parent
85d09d1c61
commit
0b0f4628d6
5 changed files with 71 additions and 33 deletions
|
|
@ -549,6 +549,19 @@ util_format_colormask(const struct util_format_description *desc)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if color mask covers every channel for the specified format
|
||||
*
|
||||
* @param desc a format description to check colormask with
|
||||
* @param colormask a bit mask for channels, matches format of PIPE_MASK_RGBA
|
||||
*/
|
||||
static INLINE boolean
|
||||
util_format_colormask_full(const struct util_format_description *desc, unsigned colormask)
|
||||
{
|
||||
return (~colormask & util_format_colormask(desc)) == 0;
|
||||
}
|
||||
|
||||
|
||||
boolean
|
||||
util_format_is_float(enum pipe_format format);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
||||
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);
|
||||
/* TODO: There are still a few optimization opportunities here. For certain
|
||||
* combinations it is possible to reorder the operations and therefore saving
|
||||
* some instructions. */
|
||||
|
||||
lp_build_name(src_term, "src_term");
|
||||
lp_build_name(dst_term, "dst_term");
|
||||
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);
|
||||
|
||||
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);
|
||||
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 */
|
||||
|
||||
LLVMValueRef rgb;
|
||||
LLVMValueRef alpha;
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 =
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue