1 /*
2 * Copyright (C) 2022 Collabora, Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #ifndef __PAN_EARLYZS_H__
25 #define __PAN_EARLYZS_H__
26
27 #include <stdbool.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 /* Matches hardware Pixel Kill enum on Bifrost and Valhall */
34 enum pan_earlyzs {
35 PAN_EARLYZS_FORCE_EARLY = 0,
36 PAN_EARLYZS_WEAK_EARLY = 2,
37 PAN_EARLYZS_FORCE_LATE = 3
38 };
39
40 /* Early-ZS pair. */
41 struct pan_earlyzs_state {
42 /* Z/S test and update */
43 enum pan_earlyzs update : 2;
44
45 /* Pixel kill */
46 enum pan_earlyzs kill : 2;
47
48 /* So it fits in a byte */
49 unsigned padding : 4;
50 };
51
52 /* Internal lookup table. Users should treat as an opaque structure and only
53 * access through pan_earlyzs_get and pan_earlyzs_analyze. See pan_earlyzs_get
54 * for definition of the arrays.
55 */
56 struct pan_earlyzs_lut {
57 struct pan_earlyzs_state states[2][2][2];
58 };
59
60 /*
61 * Look up early-ZS state. This is in the draw hot path on Valhall, so this is
62 * defined inline in the header.
63 */
64 static inline struct pan_earlyzs_state
pan_earlyzs_get(struct pan_earlyzs_lut lut,bool writes_zs_or_oq,bool alpha_to_coverage,bool zs_always_passes)65 pan_earlyzs_get(struct pan_earlyzs_lut lut,
66 bool writes_zs_or_oq, bool alpha_to_coverage,
67 bool zs_always_passes)
68 {
69 return lut.states[writes_zs_or_oq][alpha_to_coverage][zs_always_passes];
70 }
71
72 struct pan_shader_info;
73
74 struct pan_earlyzs_lut pan_earlyzs_analyze(const struct pan_shader_info *s);
75
76 #ifdef __cplusplus
77 } /* extern C */
78 #endif
79
80 #endif
81