Debian Codegraph @

src/panfrost/lib/pan_blend.h

raw
1 /*
2 * Copyright (C) 2018 Alyssa Rosenzweig
3 * Copyright (C) 2019-2021 Collabora, Ltd.
4 * SPDX-License-Identifier: MIT
5 */
6
7 #ifndef __PAN_BLEND_H__
8 #define __PAN_BLEND_H__
9
10 #include "genxml/gen_macros.h"
11
12 #include "compiler/nir/nir.h"
13 #include "util/blend.h"
14 #include "util/format/u_format.h"
15
16 struct MALI_BLEND_EQUATION;
17
18 struct pan_blend_equation {
19 unsigned blend_enable : 1;
20 unsigned is_float : 1;
21 enum pipe_blend_func rgb_func : 3;
22 enum pipe_blendfactor rgb_src_factor : 5;
23 enum pipe_blendfactor rgb_dst_factor : 5;
24 enum pipe_blend_func alpha_func : 3;
25 enum pipe_blendfactor alpha_src_factor : 5;
26 enum pipe_blendfactor alpha_dst_factor : 5;
27 unsigned color_mask : 4;
28 };
29
30 struct pan_blend_rt_state {
31 /* RT format */
32 enum pipe_format format;
33
34 /* Number of samples */
35 unsigned nr_samples;
36
37 struct pan_blend_equation equation;
38 };
39
40 struct pan_blend_state {
41 bool alpha_to_one;
42 bool logicop_enable;
43 enum pipe_logicop logicop_func;
44 float constants[4];
45 unsigned rt_count;
46 struct pan_blend_rt_state rts[8];
47 };
48
49 struct pan_blend_shader_key {
50 enum pipe_format format;
51 nir_alu_type src0_type, src1_type;
52 uint32_t rt : 3;
53 uint32_t logicop_enable : 1;
54 uint32_t logicop_func : 4;
55 uint32_t nr_samples : 5;
56 uint32_t alpha_to_one : 1;
57 uint32_t padding : 17;
58 struct pan_blend_equation equation;
59 };
60
61 bool pan_blend_reads_dest(const struct pan_blend_equation eq);
62
63 bool pan_blend_can_fixed_function(unsigned arch,
64 const struct pan_blend_equation equation,
65 bool supports_2src);
66
67 bool pan_blend_is_opaque(const struct pan_blend_equation eq);
68
69 bool pan_blend_alpha_zero_nop(const struct pan_blend_equation eq);
70
71 bool pan_blend_alpha_one_store(const struct pan_blend_equation eq);
72
73 unsigned pan_blend_constant_mask(const struct pan_blend_equation eq);
74
75 void pan_blend_optimize_equation(struct pan_blend_equation *eq,
76 enum pipe_format format,
77 const float *constants);
78
79 /* Fixed-function blending only supports a single constant, so if multiple bits
80 * are set in constant_mask, the constants must match. Therefore we may pick
81 * just the first constant. */
82
83 static inline float
84 pan_blend_get_constant(unsigned mask, const float *constants)
85 {
86 return mask ? constants[ffs(mask) - 1] : 0.0;
87 }
88
89 /* v6 doesn't support blend constants in FF blend equations whatsoever, and v7
90 * only uses the constant from RT 0 (TODO: what if it's the same constant? or a
91 * constant is shared?) */
92
93 static inline bool
94 pan_blend_supports_constant(unsigned arch, unsigned rt)
95 {
96 return !((arch == 6) || (arch == 7 && rt > 0));
97 }
98
99 /* The SOURCE_2 value is new in Bifrost */
100
101 static inline bool
102 pan_blend_supports_2src(unsigned arch)
103 {
104 return (arch >= 6);
105 }
106
107 bool pan_blend_is_homogenous_constant(unsigned mask, const float *constants);
108
109 uint16_t pan_pack_blend_constant(enum pipe_format format, float cons);
110
111 void pan_blend_to_fixed_function_equation(const struct pan_blend_equation eq,
112 struct MALI_BLEND_EQUATION *equation);
113
114 enum mali_register_file_format pan_blend_type_from_nir(nir_alu_type nir_type);
115 uint32_t pan_pack_blend(const struct pan_blend_equation equation);
116
117 #ifdef PAN_ARCH
118
119 enum pipe_format GENX(pan_blend_shader_fmt)(enum pipe_format format);
120
121 nir_shader *GENX(pan_blend_create_shader)(const struct pan_blend_state *state,
122 nir_alu_type src0_type,
123 nir_alu_type src1_type, unsigned rt);
124
125 #if PAN_ARCH >= 6
126 uint64_t GENX(pan_blend_get_internal_desc)(enum pipe_format fmt, unsigned rt,
127 unsigned force_size, bool dithered);
128
129 #if PAN_ARCH < 9
130 enum mali_register_file_format
131 GENX(pan_fixup_blend_type)(nir_alu_type T_size, enum pipe_format format);
132 #endif
133 #endif
134
135 #endif
136
137 #endif