Path: blob/21.2-virgl/src/panfrost/lib/pan_blend.h
4560 views
/*1* Copyright (C) 2018 Alyssa Rosenzweig2* Copyright (C) 2019-2021 Collabora, Ltd.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*/2324#ifndef __PAN_BLEND_H__25#define __PAN_BLEND_H__2627#include "util/u_dynarray.h"28#include "util/format/u_format.h"29#include "compiler/shader_enums.h"30#include "compiler/nir/nir.h"3132#include "panfrost/util/pan_ir.h"3334struct MALI_BLEND_EQUATION;35struct panfrost_device;3637struct pan_blend_equation {38unsigned blend_enable : 1;39enum blend_func rgb_func : 3;40unsigned rgb_invert_src_factor : 1;41enum blend_factor rgb_src_factor : 4;42unsigned rgb_invert_dst_factor : 1;43enum blend_factor rgb_dst_factor : 4;44enum blend_func alpha_func : 3;45unsigned alpha_invert_src_factor : 1;46enum blend_factor alpha_src_factor : 4;47unsigned alpha_invert_dst_factor : 1;48enum blend_factor alpha_dst_factor : 4;49unsigned color_mask : 4;50};5152struct pan_blend_rt_state {53/* RT format */54enum pipe_format format;5556/* Number of samples */57unsigned nr_samples;5859struct pan_blend_equation equation;60};6162struct pan_blend_state {63bool logicop_enable;64enum pipe_logicop logicop_func;65float constants[4];66unsigned rt_count;67struct pan_blend_rt_state rts[8];68};6970struct pan_blend_shader_key {71enum pipe_format format;72nir_alu_type src0_type, src1_type;73unsigned rt : 3;74unsigned has_constants : 1;75unsigned logicop_enable : 1;76unsigned logicop_func:4;77unsigned nr_samples : 5;78struct pan_blend_equation equation;79};8081struct pan_blend_shader_variant {82struct list_head node;83float constants[4];84struct util_dynarray binary;85unsigned first_tag;86unsigned work_reg_count;87};8889#define PAN_BLEND_SHADER_MAX_VARIANTS 169091struct pan_blend_shader {92struct pan_blend_shader_key key;93unsigned nvariants;94struct list_head variants;95};9697bool98pan_blend_reads_dest(const struct pan_blend_equation eq);99100bool101pan_blend_can_fixed_function(const struct pan_blend_equation equation);102103bool104pan_blend_is_opaque(const struct pan_blend_equation eq);105106unsigned107pan_blend_constant_mask(const struct pan_blend_equation eq);108109/* Fixed-function blending only supports a single constant, so if multiple bits110* are set in constant_mask, the constants must match. Therefore we may pick111* just the first constant. */112113static inline float114pan_blend_get_constant(unsigned mask, const float *constants)115{116return mask ? constants[ffs(mask) - 1] : 0.0;117}118119/* v6 doesn't support blend constants in FF blend equations whatsoever, and v7120* only uses the constant from RT 0 (TODO: what if it's the same constant? or a121* constant is shared?) */122123static inline bool124pan_blend_supports_constant(unsigned arch, unsigned rt)125{126return !((arch == 6) || (arch == 7 && rt > 0));127}128129bool130pan_blend_is_homogenous_constant(unsigned mask, const float *constants);131132void133pan_blend_to_fixed_function_equation(const struct pan_blend_equation eq,134struct MALI_BLEND_EQUATION *equation);135136nir_shader *137pan_blend_create_shader(const struct panfrost_device *dev,138const struct pan_blend_state *state,139nir_alu_type src0_type,140nir_alu_type src1_type,141unsigned rt);142143uint64_t144pan_blend_get_bifrost_desc(const struct panfrost_device *dev,145enum pipe_format fmt, unsigned rt,146unsigned force_size);147148/* Take blend_shaders.lock before calling this function and release it when149* you're done with the shader variant object.150*/151struct pan_blend_shader_variant *152pan_blend_get_shader_locked(const struct panfrost_device *dev,153const struct pan_blend_state *state,154nir_alu_type src0_type,155nir_alu_type src1_type,156unsigned rt);157158void159pan_blend_shaders_init(struct panfrost_device *dev);160161void162pan_blend_shaders_cleanup(struct panfrost_device *dev);163164#endif165166167