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_ZSA_H_
29 #define FD6_ZSA_H_
30
31 #include "pipe/p_context.h"
32 #include "pipe/p_state.h"
33
34 #include "freedreno_util.h"
35
36 #include "fd6_context.h"
37
38 BEGINC;
39
40 #define FD6_ZSA_NO_ALPHA (1 << 0)
41 #define FD6_ZSA_DEPTH_CLAMP (1 << 1)
42
43 struct fd6_zsa_stateobj {
44 struct pipe_depth_stencil_alpha_state base;
45
46 uint32_t rb_alpha_control;
47 uint32_t rb_depth_cntl;
48 uint32_t rb_stencil_control;
49 uint32_t rb_stencilmask;
50 uint32_t rb_stencilwrmask;
51
52 struct fd6_lrz_state lrz;
53 bool writes_zs : 1; /* writes depth and/or stencil */
54 bool writes_z : 1; /* writes depth */
55 bool invalidate_lrz : 1;
56 bool alpha_test : 1;
57
58 /* Track whether we've alread generated perf warns so that
59 * we don't flood the user with LRZ disable warns which can
60 * only be detected at draw time.
61 */
62 bool perf_warn_blend : 1;
63 bool perf_warn_zdir : 1;
64
65 struct fd_ringbuffer *stateobj[4];
66 };
67
68 static inline struct fd6_zsa_stateobj *
fd6_zsa_stateobj(struct pipe_depth_stencil_alpha_state * zsa)69 fd6_zsa_stateobj(struct pipe_depth_stencil_alpha_state *zsa)
70 {
71 return (struct fd6_zsa_stateobj *)zsa;
72 }
73
74 static inline struct fd_ringbuffer *
fd6_zsa_state(struct fd_context * ctx,bool no_alpha,bool depth_clamp)75 fd6_zsa_state(struct fd_context *ctx, bool no_alpha, bool depth_clamp) assert_dt
76 {
77 int variant = 0;
78 if (no_alpha)
79 variant |= FD6_ZSA_NO_ALPHA;
80 if (depth_clamp)
81 variant |= FD6_ZSA_DEPTH_CLAMP;
82 return fd6_zsa_stateobj(ctx->zsa)->stateobj[variant];
83 }
84
85 void *fd6_zsa_state_create(struct pipe_context *pctx,
86 const struct pipe_depth_stencil_alpha_state *cso);
87
88 void fd6_zsa_state_delete(struct pipe_context *pctx, void *hwcso);
89
90 ENDC;
91
92 #endif /* FD6_ZSA_H_ */
93