xref: /aosp_15_r20/external/mesa3d/src/panfrost/lib/pan_desc.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright (C) 2021 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  * Authors:
24  *   Alyssa Rosenzweig <[email protected]>
25  *   Boris Brezillon <[email protected]>
26  */
27 
28 #ifndef __PAN_DESC_H
29 #define __PAN_DESC_H
30 
31 #include "genxml/gen_macros.h"
32 
33 #include "pan_texture.h"
34 
35 struct pan_compute_dim {
36    uint32_t x, y, z;
37 };
38 
39 struct pan_fb_color_attachment {
40    const struct pan_image_view *view;
41    bool *crc_valid;
42    bool clear;
43    bool preload;
44    bool discard;
45    uint32_t clear_value[4];
46 };
47 
48 struct pan_fb_zs_attachment {
49    struct {
50       const struct pan_image_view *zs, *s;
51    } view;
52 
53    struct {
54       bool z, s;
55    } clear;
56 
57    struct {
58       bool z, s;
59    } discard;
60 
61    struct {
62       bool z, s;
63    } preload;
64 
65    struct {
66       float depth;
67       uint8_t stencil;
68    } clear_value;
69 };
70 
71 struct pan_tiler_context {
72    union {
73       struct {
74          mali_ptr desc;
75       } valhall;
76       struct {
77          mali_ptr desc;
78       } bifrost;
79       struct {
80          /* Sum of vertex counts (for non-indexed draws), index counts, or ~0 if
81           * any indirect draws are used. Helps tune hierarchy masks.
82           */
83          uint32_t vertex_count;
84          bool disable;
85          bool no_hierarchical_tiling;
86          mali_ptr polygon_list;
87          struct {
88             mali_ptr start;
89             unsigned size;
90          } heap;
91       } midgard;
92    };
93 };
94 
95 struct pan_tls_info {
96    struct {
97       mali_ptr ptr;
98       unsigned size;
99    } tls;
100 
101    struct {
102       unsigned instances;
103       mali_ptr ptr;
104       unsigned size;
105    } wls;
106 };
107 
108 struct pan_fb_bifrost_info {
109    struct {
110       struct panfrost_ptr dcds;
111       unsigned modes[3];
112    } pre_post;
113 };
114 
115 struct pan_fb_info {
116    unsigned width, height;
117    struct {
118       /* Max values are inclusive */
119       unsigned minx, miny, maxx, maxy;
120    } extent;
121    unsigned nr_samples;
122    unsigned force_samples; /* samples used for rasterization */
123    unsigned rt_count;
124    struct pan_fb_color_attachment rts[8];
125    struct pan_fb_zs_attachment zs;
126 
127    struct {
128       unsigned stride;
129       mali_ptr base;
130    } tile_map;
131 
132    union {
133       struct pan_fb_bifrost_info bifrost;
134    };
135 
136    /* Optimal tile buffer size. */
137    unsigned tile_buf_budget;
138 
139    /* Sample position array. */
140    mali_ptr sample_positions;
141 
142    /* Only used on Valhall */
143    bool sprite_coord_origin;
144    bool first_provoking_vertex;
145 };
146 
147 static inline unsigned
pan_wls_instances(const struct pan_compute_dim * dim)148 pan_wls_instances(const struct pan_compute_dim *dim)
149 {
150    return util_next_power_of_two(dim->x) * util_next_power_of_two(dim->y) *
151           util_next_power_of_two(dim->z);
152 }
153 
154 static inline unsigned
pan_wls_adjust_size(unsigned wls_size)155 pan_wls_adjust_size(unsigned wls_size)
156 {
157    return util_next_power_of_two(MAX2(wls_size, 128));
158 }
159 
160 #ifdef PAN_ARCH
161 
162 #if PAN_ARCH >= 5
163 static inline enum mali_sample_pattern
pan_sample_pattern(unsigned samples)164 pan_sample_pattern(unsigned samples)
165 {
166    switch (samples) {
167    case 1:
168       return MALI_SAMPLE_PATTERN_SINGLE_SAMPLED;
169    case 4:
170       return MALI_SAMPLE_PATTERN_ROTATED_4X_GRID;
171    case 8:
172       return MALI_SAMPLE_PATTERN_D3D_8X_GRID;
173    case 16:
174       return MALI_SAMPLE_PATTERN_D3D_16X_GRID;
175    default:
176       unreachable("Unsupported sample count");
177    }
178 }
179 #endif
180 
181 void GENX(pan_emit_tls)(const struct pan_tls_info *info, void *out);
182 
183 int GENX(pan_select_crc_rt)(const struct pan_fb_info *fb, unsigned tile_size);
184 
185 unsigned GENX(pan_emit_fbd)(const struct pan_fb_info *fb, unsigned layer_idx,
186                             const struct pan_tls_info *tls,
187                             const struct pan_tiler_context *tiler_ctx,
188                             void *out);
189 
190 #if PAN_ARCH <= 9
191 void GENX(pan_emit_fragment_job_payload)(const struct pan_fb_info *fb,
192                                          mali_ptr fbd, void *out);
193 #endif
194 
195 #endif /* ifdef PAN_ARCH */
196 
197 #endif
198