blob: e9308b57fc4b08e9c88add1e00196aa55cd37c11 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#ifndef U_BLEND_H
#define U_BLEND_H
#include "pipe/p_state.h"
#include "compiler/shader_enums.h"
/**
* When faking RGBX render target formats with RGBA ones, the blender is still
* supposed to treat the destination's alpha channel as 1 instead of the
* garbage that's there. Return a blend factor that will take that into
* account.
*/
static inline int
util_blend_dst_alpha_to_one(int factor)
{
switch (factor) {
case PIPE_BLENDFACTOR_DST_ALPHA:
return PIPE_BLENDFACTOR_ONE;
case PIPE_BLENDFACTOR_INV_DST_ALPHA:
return PIPE_BLENDFACTOR_ZERO;
default:
return factor;
}
}
/** To lower blending to software shaders, the Gallium blend mode has to
* be translated to something API-agnostic, as defined in shader_enums.h
* */
static inline enum blend_func
util_blend_func_to_shader(enum pipe_blend_func func)
{
switch (func) {
case PIPE_BLEND_ADD:
return BLEND_FUNC_ADD;
case PIPE_BLEND_SUBTRACT:
return BLEND_FUNC_SUBTRACT;
case PIPE_BLEND_REVERSE_SUBTRACT:
return BLEND_FUNC_REVERSE_SUBTRACT;
case PIPE_BLEND_MIN:
return BLEND_FUNC_MIN;
case PIPE_BLEND_MAX:
return BLEND_FUNC_MAX;
default:
unreachable("Invalid blend function");
}
}
static inline enum blend_factor
util_blend_factor_to_shader(enum pipe_blendfactor factor)
{
switch (factor) {
case PIPE_BLENDFACTOR_ZERO:
case PIPE_BLENDFACTOR_ONE:
return BLEND_FACTOR_ZERO;
case PIPE_BLENDFACTOR_SRC_COLOR:
case PIPE_BLENDFACTOR_INV_SRC_COLOR:
return BLEND_FACTOR_SRC_COLOR;
case PIPE_BLENDFACTOR_SRC_ALPHA:
case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
return BLEND_FACTOR_SRC_ALPHA;
case PIPE_BLENDFACTOR_DST_ALPHA:
case PIPE_BLENDFACTOR_INV_DST_ALPHA:
return BLEND_FACTOR_DST_ALPHA;
case PIPE_BLENDFACTOR_DST_COLOR:
case PIPE_BLENDFACTOR_INV_DST_COLOR:
return BLEND_FACTOR_DST_COLOR;
case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
return BLEND_FACTOR_SRC_ALPHA_SATURATE;
case PIPE_BLENDFACTOR_CONST_COLOR:
case PIPE_BLENDFACTOR_INV_CONST_COLOR:
return BLEND_FACTOR_CONSTANT_COLOR;
case PIPE_BLENDFACTOR_CONST_ALPHA:
case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
return BLEND_FACTOR_CONSTANT_ALPHA;
case PIPE_BLENDFACTOR_SRC1_COLOR:
case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
return BLEND_FACTOR_SRC1_COLOR;
case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
case PIPE_BLENDFACTOR_SRC1_ALPHA:
return BLEND_FACTOR_SRC1_ALPHA;
default:
unreachable("Invalid factor");
}
}
static inline bool
util_blend_factor_is_inverted(enum pipe_blendfactor factor)
{
switch (factor) {
case PIPE_BLENDFACTOR_ONE:
case PIPE_BLENDFACTOR_INV_SRC_COLOR:
case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
case PIPE_BLENDFACTOR_INV_DST_ALPHA:
case PIPE_BLENDFACTOR_INV_DST_COLOR:
case PIPE_BLENDFACTOR_INV_CONST_COLOR:
case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
return true;
default:
return false;
}
}
/* To determine if the destination needs to be read while blending */
static inline bool
util_blend_factor_uses_dest(enum pipe_blendfactor factor, bool alpha)
{
switch (factor) {
case PIPE_BLENDFACTOR_DST_ALPHA:
case PIPE_BLENDFACTOR_DST_COLOR:
case PIPE_BLENDFACTOR_INV_DST_ALPHA:
case PIPE_BLENDFACTOR_INV_DST_COLOR:
return true;
case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
return !alpha;
default:
return false;
}
}
static inline bool
util_blend_uses_dest(struct pipe_rt_blend_state rt)
{
return rt.blend_enable &&
(util_blend_factor_uses_dest((enum pipe_blendfactor)rt.rgb_src_factor, false) ||
util_blend_factor_uses_dest((enum pipe_blendfactor)rt.alpha_src_factor, true) ||
rt.rgb_dst_factor != PIPE_BLENDFACTOR_ZERO ||
rt.alpha_dst_factor != PIPE_BLENDFACTOR_ZERO);
}
#endif /* U_BLEND_H */
|