Path: blob/21.2-virgl/src/gallium/drivers/llvmpipe/lp_bld_alpha.c
4570 views
/**************************************************************************1*2* Copyright 2009 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627/**28* Alpha testing to LLVM IR translation.29*30* @author Jose Fonseca <[email protected]>31*/3233#include "pipe/p_state.h"34#include "util/format/u_format.h"3536#include "gallivm/lp_bld_type.h"37#include "gallivm/lp_bld_const.h"38#include "gallivm/lp_bld_arit.h"39#include "gallivm/lp_bld_conv.h"40#include "gallivm/lp_bld_logic.h"41#include "gallivm/lp_bld_flow.h"42#include "gallivm/lp_bld_debug.h"4344#include "lp_bld_alpha.h"454647void48lp_build_alpha_test(struct gallivm_state *gallivm,49unsigned func,50struct lp_type type,51const struct util_format_description *cbuf_format_desc,52struct lp_build_mask_context *mask,53LLVMValueRef alpha,54LLVMValueRef ref,55boolean do_branch)56{57struct lp_build_context bld;58LLVMValueRef test;5960lp_build_context_init(&bld, gallivm, type);6162/*63* Alpha testing needs to be done in the color buffer precision.64*65* TODO: Ideally, instead of duplicating the color conversion code, we would do66* alpha testing after converting the output colors, but that's not very67* convenient, because it needs to be done before depth testing. Hopefully68* LLVM will detect and remove the duplicate expression.69*70* FIXME: This should be generalized to formats other than rgba8 variants.71*/72if (type.floating &&73util_format_is_rgba8_variant(cbuf_format_desc)) {74const unsigned dst_width = 8;7576alpha = lp_build_clamp(&bld, alpha, bld.zero, bld.one);77ref = lp_build_clamp(&bld, ref, bld.zero, bld.one);7879alpha = lp_build_clamped_float_to_unsigned_norm(gallivm, type, dst_width, alpha);80ref = lp_build_clamped_float_to_unsigned_norm(gallivm, type, dst_width, ref);8182type.floating = 0;83lp_build_context_init(&bld, gallivm, type);84}8586test = lp_build_cmp(&bld, func, alpha, ref);8788lp_build_name(test, "alpha_mask");8990lp_build_mask_update(mask, test);9192if (do_branch)93lp_build_mask_check(mask);94}959697