1 /*
2 * Copyright © 2016 Rob Clark <[email protected]>
3 * Copyright © 2018 Google, Inc.
4 * SPDX-License-Identifier: MIT
5 *
6 * Authors:
7 * Rob Clark <[email protected]>
8 */
9
10 #ifndef FD6_BLEND_H_
11 #define FD6_BLEND_H_
12
13 #include "pipe/p_context.h"
14 #include "pipe/p_state.h"
15
16 #include "freedreno_context.h"
17 #include "freedreno_util.h"
18
19 /**
20 * Since the sample-mask is part of the hw blend state, we need to have state
21 * variants per sample-mask value. But we don't expect the sample-mask state
22 * to change frequently.
23 */
24 struct fd6_blend_variant {
25 unsigned sample_mask;
26 struct fd_ringbuffer *stateobj;
27 };
28
29 struct fd6_blend_stateobj {
30 struct pipe_blend_state base;
31
32 bool use_dual_src_blend;
33
34 struct fd_context *ctx;
35 bool reads_dest;
36 uint32_t all_mrt_write_mask;
37 struct util_dynarray variants;
38 };
39
40 static inline struct fd6_blend_stateobj *
fd6_blend_stateobj(struct pipe_blend_state * blend)41 fd6_blend_stateobj(struct pipe_blend_state *blend)
42 {
43 return (struct fd6_blend_stateobj *)blend;
44 }
45
46 template <chip CHIP>
47 struct fd6_blend_variant *
48 __fd6_setup_blend_variant(struct fd6_blend_stateobj *blend,
49 unsigned sample_mask);
50
51 template <chip CHIP>
52 static inline struct fd6_blend_variant *
fd6_blend_variant(struct pipe_blend_state * cso,unsigned nr_samples,unsigned sample_mask)53 fd6_blend_variant(struct pipe_blend_state *cso, unsigned nr_samples,
54 unsigned sample_mask)
55 {
56 struct fd6_blend_stateobj *blend = fd6_blend_stateobj(cso);
57 unsigned mask = BITFIELD_MASK(nr_samples);
58
59 util_dynarray_foreach (&blend->variants, struct fd6_blend_variant *, vp) {
60 struct fd6_blend_variant *v = *vp;
61
62 /* mask out sample-mask bits that we don't care about to avoid
63 * creating unnecessary variants
64 */
65 if ((mask & v->sample_mask) == (mask & sample_mask)) {
66 return v;
67 }
68 }
69
70 return __fd6_setup_blend_variant<CHIP>(blend, sample_mask);
71 }
72
73 void *fd6_blend_state_create(struct pipe_context *pctx,
74 const struct pipe_blend_state *cso);
75 void fd6_blend_state_delete(struct pipe_context *, void *hwcso);
76
77 #endif /* FD6_BLEND_H_ */
78