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 /* image created when detiling a resource whose
57 constant modifier we cannot change */
58 struct panfrost_resource *shadow_image;
59
60 struct util_range valid_buffer_range;
61
62 /* Description of the resource layout */
63 struct pan_image image;
64
65 struct panfrost_bo *bo;
66
67 struct {
68 /* Is the checksum for this image valid? Implicitly refers to
69 * the first slice; we only checksum non-mipmapped 2D images */
70 bool crc;
71
72 /* Has anything been written to this slice? */
73 BITSET_DECLARE(data, PAN_MAX_MIP_LEVELS);
74 } valid;
75
76 /* Whether the modifier can be changed */
77 bool modifier_constant;
78
79 /* Used to decide when to convert to another modifier */
80 uint16_t modifier_updates;
81
82 /* Do all pixels have the same stencil value? */
83 bool constant_stencil;
84
85 /* The stencil value if constant_stencil is set */
86 uint8_t stencil_value;
87
88 /* Cached min/max values for index buffers */
89 struct panfrost_minmax_cache *index_cache;
90 };
91
92 static inline struct panfrost_resource *
pan_resource(struct pipe_resource * p)93 pan_resource(struct pipe_resource *p)
94 {
95 return (struct panfrost_resource *)p;
96 }
97
98 struct panfrost_transfer {
99 struct pipe_transfer base;
100 void *map;
101 struct {
102 struct pipe_resource *rsrc;
103 struct pipe_box box;
104 } staging;
105 };
106
107 static inline struct panfrost_transfer *
pan_transfer(struct pipe_transfer * p)108 pan_transfer(struct pipe_transfer *p)
109 {
110 return (struct panfrost_transfer *)p;
111 }
112
113 void panfrost_resource_screen_init(struct pipe_screen *screen);
114
115 void panfrost_resource_screen_destroy(struct pipe_screen *screen);
116
117 void panfrost_resource_context_init(struct pipe_context *pctx);
118
119 /* Blitting */
120
121 enum panfrost_blitter_op /* bitmask */
122 {
123 PAN_SAVE_TEXTURES = 1,
124 PAN_SAVE_FRAMEBUFFER = 2,
125 PAN_SAVE_FRAGMENT_STATE = 4,
126 PAN_SAVE_FRAGMENT_CONSTANT = 8,
127 PAN_DISABLE_RENDER_COND = 16,
128 };
129
130 enum {
131 PAN_RENDER_BLIT =
132 PAN_SAVE_TEXTURES | PAN_SAVE_FRAMEBUFFER | PAN_SAVE_FRAGMENT_STATE,
133 PAN_RENDER_BLIT_COND = PAN_SAVE_TEXTURES | PAN_SAVE_FRAMEBUFFER |
134 PAN_SAVE_FRAGMENT_STATE | PAN_DISABLE_RENDER_COND,
135 PAN_RENDER_BASE = PAN_SAVE_FRAMEBUFFER | PAN_SAVE_FRAGMENT_STATE,
136 PAN_RENDER_COND =
137 PAN_SAVE_FRAMEBUFFER | PAN_SAVE_FRAGMENT_STATE | PAN_DISABLE_RENDER_COND,
138 PAN_RENDER_CLEAR = PAN_SAVE_FRAGMENT_STATE | PAN_SAVE_FRAGMENT_CONSTANT,
139 };
140
141 void panfrost_blitter_save(struct panfrost_context *ctx,
142 const enum panfrost_blitter_op blitter_op);
143
144 void panfrost_blit(struct pipe_context *pipe,
145 const struct pipe_blit_info *info);
146
147 void panfrost_resource_set_damage_region(struct pipe_screen *screen,
148 struct pipe_resource *res,
149 unsigned int nrects,
150 const struct pipe_box *rects);
151
152 void panfrost_set_image_view_planes(struct pan_image_view *iview,
153 struct pipe_resource *texture);
154
155 static inline enum mali_texture_dimension
panfrost_translate_texture_dimension(enum pipe_texture_target t)156 panfrost_translate_texture_dimension(enum pipe_texture_target t)
157 {
158 switch (t) {
159 case PIPE_BUFFER:
160 case PIPE_TEXTURE_1D:
161 case PIPE_TEXTURE_1D_ARRAY:
162 return MALI_TEXTURE_DIMENSION_1D;
163
164 case PIPE_TEXTURE_2D:
165 case PIPE_TEXTURE_2D_ARRAY:
166 case PIPE_TEXTURE_RECT:
167 return MALI_TEXTURE_DIMENSION_2D;
168
169 case PIPE_TEXTURE_3D:
170 return MALI_TEXTURE_DIMENSION_3D;
171
172 case PIPE_TEXTURE_CUBE:
173 case PIPE_TEXTURE_CUBE_ARRAY:
174 return MALI_TEXTURE_DIMENSION_CUBE;
175
176 default:
177 unreachable("Unknown target");
178 }
179 }
180
181 struct pipe_resource *
182 panfrost_resource_create_with_modifier(struct pipe_screen *screen,
183 const struct pipe_resource *template,
184 uint64_t modifier);
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