Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/panfrost/lib/pan_blend.h
4560 views
1
/*
2
* Copyright (C) 2018 Alyssa Rosenzweig
3
* Copyright (C) 2019-2021 Collabora, Ltd.
4
*
5
* Permission is hereby granted, free of charge, to any person obtaining a
6
* copy of this software and associated documentation files (the "Software"),
7
* to deal in the Software without restriction, including without limitation
8
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
* and/or sell copies of the Software, and to permit persons to whom the
10
* Software is furnished to do so, subject to the following conditions:
11
*
12
* The above copyright notice and this permission notice (including the next
13
* paragraph) shall be included in all copies or substantial portions of the
14
* Software.
15
*
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
* SOFTWARE.
23
*/
24
25
#ifndef __PAN_BLEND_H__
26
#define __PAN_BLEND_H__
27
28
#include "util/u_dynarray.h"
29
#include "util/format/u_format.h"
30
#include "compiler/shader_enums.h"
31
#include "compiler/nir/nir.h"
32
33
#include "panfrost/util/pan_ir.h"
34
35
struct MALI_BLEND_EQUATION;
36
struct panfrost_device;
37
38
struct pan_blend_equation {
39
unsigned blend_enable : 1;
40
enum blend_func rgb_func : 3;
41
unsigned rgb_invert_src_factor : 1;
42
enum blend_factor rgb_src_factor : 4;
43
unsigned rgb_invert_dst_factor : 1;
44
enum blend_factor rgb_dst_factor : 4;
45
enum blend_func alpha_func : 3;
46
unsigned alpha_invert_src_factor : 1;
47
enum blend_factor alpha_src_factor : 4;
48
unsigned alpha_invert_dst_factor : 1;
49
enum blend_factor alpha_dst_factor : 4;
50
unsigned color_mask : 4;
51
};
52
53
struct pan_blend_rt_state {
54
/* RT format */
55
enum pipe_format format;
56
57
/* Number of samples */
58
unsigned nr_samples;
59
60
struct pan_blend_equation equation;
61
};
62
63
struct pan_blend_state {
64
bool logicop_enable;
65
enum pipe_logicop logicop_func;
66
float constants[4];
67
unsigned rt_count;
68
struct pan_blend_rt_state rts[8];
69
};
70
71
struct pan_blend_shader_key {
72
enum pipe_format format;
73
nir_alu_type src0_type, src1_type;
74
unsigned rt : 3;
75
unsigned has_constants : 1;
76
unsigned logicop_enable : 1;
77
unsigned logicop_func:4;
78
unsigned nr_samples : 5;
79
struct pan_blend_equation equation;
80
};
81
82
struct pan_blend_shader_variant {
83
struct list_head node;
84
float constants[4];
85
struct util_dynarray binary;
86
unsigned first_tag;
87
unsigned work_reg_count;
88
};
89
90
#define PAN_BLEND_SHADER_MAX_VARIANTS 16
91
92
struct pan_blend_shader {
93
struct pan_blend_shader_key key;
94
unsigned nvariants;
95
struct list_head variants;
96
};
97
98
bool
99
pan_blend_reads_dest(const struct pan_blend_equation eq);
100
101
bool
102
pan_blend_can_fixed_function(const struct pan_blend_equation equation);
103
104
bool
105
pan_blend_is_opaque(const struct pan_blend_equation eq);
106
107
unsigned
108
pan_blend_constant_mask(const struct pan_blend_equation eq);
109
110
/* Fixed-function blending only supports a single constant, so if multiple bits
111
* are set in constant_mask, the constants must match. Therefore we may pick
112
* just the first constant. */
113
114
static inline float
115
pan_blend_get_constant(unsigned mask, const float *constants)
116
{
117
return mask ? constants[ffs(mask) - 1] : 0.0;
118
}
119
120
/* v6 doesn't support blend constants in FF blend equations whatsoever, and v7
121
* only uses the constant from RT 0 (TODO: what if it's the same constant? or a
122
* constant is shared?) */
123
124
static inline bool
125
pan_blend_supports_constant(unsigned arch, unsigned rt)
126
{
127
return !((arch == 6) || (arch == 7 && rt > 0));
128
}
129
130
bool
131
pan_blend_is_homogenous_constant(unsigned mask, const float *constants);
132
133
void
134
pan_blend_to_fixed_function_equation(const struct pan_blend_equation eq,
135
struct MALI_BLEND_EQUATION *equation);
136
137
nir_shader *
138
pan_blend_create_shader(const struct panfrost_device *dev,
139
const struct pan_blend_state *state,
140
nir_alu_type src0_type,
141
nir_alu_type src1_type,
142
unsigned rt);
143
144
uint64_t
145
pan_blend_get_bifrost_desc(const struct panfrost_device *dev,
146
enum pipe_format fmt, unsigned rt,
147
unsigned force_size);
148
149
/* Take blend_shaders.lock before calling this function and release it when
150
* you're done with the shader variant object.
151
*/
152
struct pan_blend_shader_variant *
153
pan_blend_get_shader_locked(const struct panfrost_device *dev,
154
const struct pan_blend_state *state,
155
nir_alu_type src0_type,
156
nir_alu_type src1_type,
157
unsigned rt);
158
159
void
160
pan_blend_shaders_init(struct panfrost_device *dev);
161
162
void
163
pan_blend_shaders_cleanup(struct panfrost_device *dev);
164
165
#endif
166
167