• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <alyssa.rosenzweig@collabora.com>
25  *   Boris Brezillon <boris.brezillon@collabora.com>
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          uint64_t desc;
75          /* A tiler descriptor can only handle a limited amount of layers.
76           * If the number of layers is bigger than this, several tiler
77           * descriptors will be issued, each with a different layer_offset.
78           */
79          uint8_t layer_offset;
80       } valhall;
81       struct {
82          uint64_t desc;
83       } bifrost;
84       struct {
85          /* Sum of vertex counts (for non-indexed draws), index counts, or ~0 if
86           * any indirect draws are used. Helps tune hierarchy masks.
87           */
88          uint32_t vertex_count;
89          bool disable;
90          bool no_hierarchical_tiling;
91          uint64_t polygon_list;
92          struct {
93             uint64_t start;
94             unsigned size;
95          } heap;
96       } midgard;
97    };
98 };
99 
100 struct pan_tls_info {
101    struct {
102       uint64_t ptr;
103       unsigned size;
104    } tls;
105 
106    struct {
107       unsigned instances;
108       uint64_t ptr;
109       unsigned size;
110    } wls;
111 };
112 
113 struct pan_fb_bifrost_info {
114    struct {
115       struct panfrost_ptr dcds;
116       unsigned modes[3];
117    } pre_post;
118 };
119 
120 struct pan_fb_info {
121    unsigned width, height;
122    struct {
123       /* Max values are inclusive */
124       unsigned minx, miny, maxx, maxy;
125    } extent;
126    unsigned nr_samples;
127    unsigned force_samples; /* samples used for rasterization */
128    unsigned rt_count;
129    struct pan_fb_color_attachment rts[8];
130    struct pan_fb_zs_attachment zs;
131 
132    struct {
133       unsigned stride;
134       uint64_t base;
135    } tile_map;
136 
137    union {
138       struct pan_fb_bifrost_info bifrost;
139    };
140 
141    /* Optimal tile buffer size. */
142    unsigned tile_buf_budget;
143    unsigned tile_size;
144    unsigned cbuf_allocation;
145 
146    /* Sample position array. */
147    uint64_t sample_positions;
148 
149    /* Only used on Valhall */
150    bool sprite_coord_origin;
151    bool first_provoking_vertex;
152 };
153 
154 static inline unsigned
pan_wls_instances(const struct pan_compute_dim * dim)155 pan_wls_instances(const struct pan_compute_dim *dim)
156 {
157    return util_next_power_of_two(dim->x) * util_next_power_of_two(dim->y) *
158           util_next_power_of_two(dim->z);
159 }
160 
161 static inline unsigned
pan_wls_adjust_size(unsigned wls_size)162 pan_wls_adjust_size(unsigned wls_size)
163 {
164    return util_next_power_of_two(MAX2(wls_size, 128));
165 }
166 
167 #ifdef PAN_ARCH
168 
169 #if PAN_ARCH >= 5
170 static inline enum mali_sample_pattern
pan_sample_pattern(unsigned samples)171 pan_sample_pattern(unsigned samples)
172 {
173    switch (samples) {
174    case 1:
175       return MALI_SAMPLE_PATTERN_SINGLE_SAMPLED;
176    case 4:
177       return MALI_SAMPLE_PATTERN_ROTATED_4X_GRID;
178    case 8:
179       return MALI_SAMPLE_PATTERN_D3D_8X_GRID;
180    case 16:
181       return MALI_SAMPLE_PATTERN_D3D_16X_GRID;
182    default:
183       unreachable("Unsupported sample count");
184    }
185 }
186 #endif
187 
188 void GENX(pan_select_tile_size)(struct pan_fb_info *fb);
189 
190 void GENX(pan_emit_tls)(const struct pan_tls_info *info,
191                         struct mali_local_storage_packed *out);
192 
193 int GENX(pan_select_crc_rt)(const struct pan_fb_info *fb, unsigned tile_size);
194 
195 unsigned GENX(pan_emit_fbd)(const struct pan_fb_info *fb, unsigned layer_idx,
196                             const struct pan_tls_info *tls,
197                             const struct pan_tiler_context *tiler_ctx,
198                             void *out);
199 
200 #if PAN_ARCH <= 9
201 void GENX(pan_emit_fragment_job_payload)(const struct pan_fb_info *fb,
202                                          uint64_t fbd, void *out);
203 #endif
204 
205 #endif /* ifdef PAN_ARCH */
206 
207 #endif
208