• 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 BEGINC;
38 
39 /**
40  * Since the sample-mask is part of the hw blend state, we need to have state
41  * variants per sample-mask value.  But we don't expect the sample-mask state
42  * to change frequently.
43  */
44 struct fd6_blend_variant {
45    unsigned sample_mask;
46    struct fd_ringbuffer *stateobj;
47 };
48 
49 struct fd6_blend_stateobj {
50    struct pipe_blend_state base;
51 
52    bool use_dual_src_blend;
53 
54    struct fd_context *ctx;
55    bool reads_dest;
56    uint32_t all_mrt_write_mask;
57    struct util_dynarray variants;
58 };
59 
60 static inline struct fd6_blend_stateobj *
fd6_blend_stateobj(struct pipe_blend_state * blend)61 fd6_blend_stateobj(struct pipe_blend_state *blend)
62 {
63    return (struct fd6_blend_stateobj *)blend;
64 }
65 
66 struct fd6_blend_variant *
67 __fd6_setup_blend_variant(struct fd6_blend_stateobj *blend,
68                           unsigned sample_mask);
69 
70 static inline struct fd6_blend_variant *
fd6_blend_variant(struct pipe_blend_state * cso,unsigned nr_samples,unsigned sample_mask)71 fd6_blend_variant(struct pipe_blend_state *cso, unsigned nr_samples,
72                   unsigned sample_mask)
73 {
74    struct fd6_blend_stateobj *blend = fd6_blend_stateobj(cso);
75    unsigned mask = BITFIELD_MASK(nr_samples);
76 
77    util_dynarray_foreach (&blend->variants, struct fd6_blend_variant *, vp) {
78       struct fd6_blend_variant *v = *vp;
79 
80       /* mask out sample-mask bits that we don't care about to avoid
81        * creating unnecessary variants
82        */
83       if ((mask & v->sample_mask) == (mask & sample_mask)) {
84          return v;
85       }
86    }
87 
88    return __fd6_setup_blend_variant(blend, sample_mask);
89 }
90 
91 void *fd6_blend_state_create(struct pipe_context *pctx,
92                              const struct pipe_blend_state *cso);
93 void fd6_blend_state_delete(struct pipe_context *, void *hwcso);
94 
95 ENDC;
96 
97 #endif /* FD6_BLEND_H_ */
98