• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org>
3  * Copyright © 2018 Google, Inc.
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  * Authors:
25  *    Rob Clark <robclark@freedesktop.org>
26  */
27 
28 #ifndef FD6_BLEND_H_
29 #define FD6_BLEND_H_
30 
31 #include "pipe/p_context.h"
32 #include "pipe/p_state.h"
33 
34 #include "freedreno_context.h"
35 #include "freedreno_util.h"
36 
37 /**
38  * Since the sample-mask is part of the hw blend state, we need to have state
39  * variants per sample-mask value.  But we don't expect the sample-mask state
40  * to change frequently.
41  */
42 struct fd6_blend_variant {
43    unsigned sample_mask;
44    struct fd_ringbuffer *stateobj;
45 };
46 
47 struct fd6_blend_stateobj {
48    struct pipe_blend_state base;
49 
50    bool use_dual_src_blend;
51 
52    struct fd_context *ctx;
53    bool reads_dest;
54    struct util_dynarray variants;
55 };
56 
57 static inline struct fd6_blend_stateobj *
fd6_blend_stateobj(struct pipe_blend_state * blend)58 fd6_blend_stateobj(struct pipe_blend_state *blend)
59 {
60    return (struct fd6_blend_stateobj *)blend;
61 }
62 
63 struct fd6_blend_variant *
64 __fd6_setup_blend_variant(struct fd6_blend_stateobj *blend,
65                           unsigned sample_mask);
66 
67 static inline struct fd6_blend_variant *
fd6_blend_variant(struct pipe_blend_state * cso,unsigned nr_samples,unsigned sample_mask)68 fd6_blend_variant(struct pipe_blend_state *cso, unsigned nr_samples,
69                   unsigned sample_mask)
70 {
71    struct fd6_blend_stateobj *blend = fd6_blend_stateobj(cso);
72    unsigned mask = BITFIELD_MASK(nr_samples);
73 
74    util_dynarray_foreach (&blend->variants, struct fd6_blend_variant *, vp) {
75       struct fd6_blend_variant *v = *vp;
76 
77       /* mask out sample-mask bits that we don't care about to avoid
78        * creating unnecessary variants
79        */
80       if ((mask & v->sample_mask) == (mask & sample_mask)) {
81          return v;
82       }
83    }
84 
85    return __fd6_setup_blend_variant(blend, sample_mask);
86 }
87 
88 void *fd6_blend_state_create(struct pipe_context *pctx,
89                              const struct pipe_blend_state *cso);
90 void fd6_blend_state_delete(struct pipe_context *, void *hwcso);
91 
92 #endif /* FD6_BLEND_H_ */
93