xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/panfrost/pan_resource.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * © Copyright2018-2019 Alyssa Rosenzweig
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 
25 #ifndef PAN_RESOURCE_H
26 #define PAN_RESOURCE_H
27 
28 #include "drm-uapi/drm.h"
29 #include "util/u_range.h"
30 #include "pan_minmax_cache.h"
31 #include "pan_screen.h"
32 #include "pan_texture.h"
33 
34 #define LAYOUT_CONVERT_THRESHOLD 8
35 #define PAN_MAX_BATCHES          32
36 
37 #define PAN_BIND_SHARED_MASK                                                   \
38    (PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_SCANOUT | PIPE_BIND_SHARED)
39 
40 struct panfrost_resource {
41    struct pipe_resource base;
42    struct {
43       struct pipe_scissor_state extent;
44       struct {
45          bool enable;
46          unsigned stride;
47          unsigned size;
48          BITSET_WORD *data;
49       } tile_map;
50    } damage;
51 
52    struct renderonly_scanout *scanout;
53 
54    struct panfrost_resource *separate_stencil;
55 
56    struct util_range valid_buffer_range;
57 
58    /* Description of the resource layout */
59    struct pan_image image;
60 
61    struct panfrost_bo *bo;
62 
63    struct {
64       /* Is the checksum for this image valid? Implicitly refers to
65        * the first slice; we only checksum non-mipmapped 2D images */
66       bool crc;
67 
68       /* Has anything been written to this slice? */
69       BITSET_DECLARE(data, PAN_MAX_MIP_LEVELS);
70    } valid;
71 
72    /* Whether the modifier can be changed */
73    bool modifier_constant;
74 
75    /* Used to decide when to convert to another modifier */
76    uint16_t modifier_updates;
77 
78    /* Do all pixels have the same stencil value? */
79    bool constant_stencil;
80 
81    /* The stencil value if constant_stencil is set */
82    uint8_t stencil_value;
83 
84    /* Cached min/max values for index buffers */
85    struct panfrost_minmax_cache *index_cache;
86 };
87 
88 static inline struct panfrost_resource *
pan_resource(struct pipe_resource * p)89 pan_resource(struct pipe_resource *p)
90 {
91    return (struct panfrost_resource *)p;
92 }
93 
94 struct panfrost_transfer {
95    struct pipe_transfer base;
96    void *map;
97    struct {
98       struct pipe_resource *rsrc;
99       struct pipe_box box;
100    } staging;
101 };
102 
103 static inline struct panfrost_transfer *
pan_transfer(struct pipe_transfer * p)104 pan_transfer(struct pipe_transfer *p)
105 {
106    return (struct panfrost_transfer *)p;
107 }
108 
109 void panfrost_resource_screen_init(struct pipe_screen *screen);
110 
111 void panfrost_resource_screen_destroy(struct pipe_screen *screen);
112 
113 void panfrost_resource_context_init(struct pipe_context *pctx);
114 
115 /* Blitting */
116 
117 enum panfrost_blitter_op /* bitmask */
118 {
119    PAN_SAVE_TEXTURES = 1,
120    PAN_SAVE_FRAMEBUFFER = 2,
121    PAN_SAVE_FRAGMENT_STATE = 4,
122    PAN_SAVE_FRAGMENT_CONSTANT = 8,
123    PAN_DISABLE_RENDER_COND = 16,
124 };
125 
126 enum {
127    PAN_RENDER_BLIT =
128       PAN_SAVE_TEXTURES | PAN_SAVE_FRAMEBUFFER | PAN_SAVE_FRAGMENT_STATE,
129    PAN_RENDER_BLIT_COND = PAN_SAVE_TEXTURES | PAN_SAVE_FRAMEBUFFER |
130                           PAN_SAVE_FRAGMENT_STATE | PAN_DISABLE_RENDER_COND,
131    PAN_RENDER_BASE = PAN_SAVE_FRAMEBUFFER | PAN_SAVE_FRAGMENT_STATE,
132    PAN_RENDER_COND =
133       PAN_SAVE_FRAMEBUFFER | PAN_SAVE_FRAGMENT_STATE | PAN_DISABLE_RENDER_COND,
134    PAN_RENDER_CLEAR = PAN_SAVE_FRAGMENT_STATE | PAN_SAVE_FRAGMENT_CONSTANT,
135 };
136 
137 void panfrost_blitter_save(struct panfrost_context *ctx,
138                            const enum panfrost_blitter_op blitter_op);
139 
140 void panfrost_blit(struct pipe_context *pipe,
141                    const struct pipe_blit_info *info);
142 
143 void panfrost_resource_set_damage_region(struct pipe_screen *screen,
144                                          struct pipe_resource *res,
145                                          unsigned int nrects,
146                                          const struct pipe_box *rects);
147 
148 void panfrost_set_image_view_planes(struct pan_image_view *iview,
149                                     struct pipe_resource *texture);
150 
151 static inline enum mali_texture_dimension
panfrost_translate_texture_dimension(enum pipe_texture_target t)152 panfrost_translate_texture_dimension(enum pipe_texture_target t)
153 {
154    switch (t) {
155    case PIPE_BUFFER:
156    case PIPE_TEXTURE_1D:
157    case PIPE_TEXTURE_1D_ARRAY:
158       return MALI_TEXTURE_DIMENSION_1D;
159 
160    case PIPE_TEXTURE_2D:
161    case PIPE_TEXTURE_2D_ARRAY:
162    case PIPE_TEXTURE_RECT:
163       return MALI_TEXTURE_DIMENSION_2D;
164 
165    case PIPE_TEXTURE_3D:
166       return MALI_TEXTURE_DIMENSION_3D;
167 
168    case PIPE_TEXTURE_CUBE:
169    case PIPE_TEXTURE_CUBE_ARRAY:
170       return MALI_TEXTURE_DIMENSION_CUBE;
171 
172    default:
173       unreachable("Unknown target");
174    }
175 }
176 
177 struct pipe_resource *
178 panfrost_resource_create_with_modifier(struct pipe_screen *screen,
179                                        const struct pipe_resource *template,
180                                        uint64_t modifier);
181 
182 struct panfrost_bo *panfrost_get_afbc_superblock_sizes(
183    struct panfrost_context *ctx, struct panfrost_resource *rsrc,
184    unsigned first_level, unsigned last_level, unsigned *out_offsets);
185 
186 bool panfrost_should_pack_afbc(struct panfrost_device *dev,
187                                const struct panfrost_resource *rsrc);
188 
189 void panfrost_pack_afbc(struct panfrost_context *ctx,
190                         struct panfrost_resource *prsrc);
191 
192 void pan_resource_modifier_convert(struct panfrost_context *ctx,
193                                    struct panfrost_resource *rsrc,
194                                    uint64_t modifier, bool copy_resource,
195                                    const char *reason);
196 
197 void pan_legalize_format(struct panfrost_context *ctx,
198                          struct panfrost_resource *rsrc,
199                          enum pipe_format format, bool write,
200                          bool discard);
201 void pan_dump_resource(struct panfrost_context *ctx,
202                        struct panfrost_resource *rsc);
203 
204 void panfrost_blit_no_afbc_legalization(struct pipe_context *pipe,
205                                         const struct pipe_blit_info *info);
206 
207 #endif /* PAN_RESOURCE_H */
208