Path: blob/21.2-virgl/src/gallium/drivers/swr/rasterizer/jitter/blend_jit.h
4574 views
/****************************************************************************1* Copyright (C) 2014-2015 Intel Corporation. All Rights Reserved.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*22* @file blend_jit.h23*24* @brief Definition of the blend jitter25*26* Notes:27*28******************************************************************************/29#pragma once3031#include "common/formats.h"32#include "core/state.h"3334struct RENDER_TARGET_BLEND_COMPILE_STATE35{36bool blendEnable;37bool logicOpEnable;38SWR_BLEND_FACTOR sourceAlphaBlendFactor;39SWR_BLEND_FACTOR destAlphaBlendFactor;40SWR_BLEND_FACTOR sourceBlendFactor;41SWR_BLEND_FACTOR destBlendFactor;42SWR_BLEND_OP colorBlendFunc;43SWR_BLEND_OP alphaBlendFunc;44SWR_LOGIC_OP logicOpFunc;45};4647enum ALPHA_TEST_FORMAT48{49ALPHA_TEST_UNORM8,50ALPHA_TEST_FLOAT3251};5253//////////////////////////////////////////////////////////////////////////54/// BLEND_DESC55//////////////////////////////////////////////////////////////////////////56struct BLEND_DESC57{58union59{60struct61{62uint32_t alphaTestEnable : 1;63uint32_t independentAlphaBlendEnable : 1;64uint32_t alphaToCoverageEnable : 1;65uint32_t oMaskEnable : 1;66uint32_t inputCoverageEnable : 1;67uint32_t sampleMaskEnable : 1;68uint32_t numSamples : 5;69uint32_t _reserved : 21;70};71uint32_t bits;72};73};74#define BLEND_ENABLE_MASK 0x3D // a2c | oMaskEnable | inputCoverageEnable | sampleMaskEnable75//////////////////////////////////////////////////////////////////////////76/// State required for blend jit77//////////////////////////////////////////////////////////////////////////78struct BLEND_COMPILE_STATE79{80SWR_FORMAT format; // format of render target being blended81RENDER_TARGET_BLEND_COMPILE_STATE blendState;82BLEND_DESC desc;8384SWR_ZFUNCTION alphaTestFunction;85ALPHA_TEST_FORMAT alphaTestFormat;8687bool operator==(const BLEND_COMPILE_STATE& other) const88{89return memcmp(this, &other, sizeof(BLEND_COMPILE_STATE)) == 0;90}9192// Canonicalize state to reduce unnecessary JIT compiles93void Canonicalize()94{95if (!desc.alphaTestEnable)96{97alphaTestFormat = (ALPHA_TEST_FORMAT)0;98alphaTestFunction = (SWR_ZFUNCTION)0;99}100101if (!blendState.blendEnable)102{103blendState.sourceAlphaBlendFactor = (SWR_BLEND_FACTOR)0;104blendState.destAlphaBlendFactor = (SWR_BLEND_FACTOR)0;105blendState.sourceBlendFactor = (SWR_BLEND_FACTOR)0;106blendState.destBlendFactor = (SWR_BLEND_FACTOR)0;107blendState.colorBlendFunc = (SWR_BLEND_OP)0;108blendState.alphaBlendFunc = (SWR_BLEND_OP)0;109}110111if (!blendState.logicOpEnable)112{113blendState.logicOpFunc = (SWR_LOGIC_OP)0;114}115116if (!blendState.blendEnable && !blendState.logicOpEnable)117{118format = (SWR_FORMAT)0;119}120121if (!desc.independentAlphaBlendEnable)122{123blendState.sourceAlphaBlendFactor = (SWR_BLEND_FACTOR)0;124blendState.destAlphaBlendFactor = (SWR_BLEND_FACTOR)0;125blendState.alphaBlendFunc = (SWR_BLEND_OP)0;126}127}128};129130131