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
26 #ifndef PAN_RESOURCE_H
27 #define PAN_RESOURCE_H
28
29 #include "pan_screen.h"
30 #include "pan_minmax_cache.h"
31 #include "pan_texture.h"
32 #include "drm-uapi/drm.h"
33 #include "util/u_range.h"
34
35 #define LAYOUT_CONVERT_THRESHOLD 8
36 #define PAN_MAX_BATCHES 32
37
38 struct panfrost_resource {
39 struct pipe_resource base;
40 struct {
41 struct pipe_scissor_state extent;
42 struct {
43 bool enable;
44 unsigned stride;
45 unsigned size;
46 BITSET_WORD *data;
47 } tile_map;
48 } damage;
49
50 struct {
51 /** Number of batches accessing this resource. Used to check if
52 * a resource is in use. */
53 _Atomic unsigned nr_users;
54
55 /** Number of batches writing this resource. Note that only one
56 * batch per context may write a resource, so this is the
57 * number of contexts that have an active writer. */
58 _Atomic unsigned nr_writers;
59 } track;
60
61 struct renderonly_scanout *scanout;
62
63 struct panfrost_resource *separate_stencil;
64
65 struct util_range valid_buffer_range;
66
67 /* Description of the resource layout */
68 struct pan_image image;
69
70 struct {
71 /* Is the checksum for this image valid? Implicitly refers to
72 * the first slice; we only checksum non-mipmapped 2D images */
73 bool crc;
74
75 /* Has anything been written to this slice? */
76 BITSET_DECLARE(data, MAX_MIP_LEVELS);
77 } valid;
78
79 /* Whether the modifier can be changed */
80 bool modifier_constant;
81
82 /* Used to decide when to convert to another modifier */
83 uint16_t modifier_updates;
84
85 /* Cached min/max values for index buffers */
86 struct panfrost_minmax_cache *index_cache;
87 };
88
89 static inline struct panfrost_resource *
pan_resource(struct pipe_resource * p)90 pan_resource(struct pipe_resource *p)
91 {
92 return (struct panfrost_resource *)p;
93 }
94
95 struct panfrost_transfer {
96 struct pipe_transfer base;
97 void *map;
98 struct {
99 struct pipe_resource *rsrc;
100 struct pipe_box box;
101 } staging;
102 };
103
104 static inline struct panfrost_transfer *
pan_transfer(struct pipe_transfer * p)105 pan_transfer(struct pipe_transfer *p)
106 {
107 return (struct panfrost_transfer *)p;
108 }
109
110 void panfrost_resource_screen_init(struct pipe_screen *screen);
111
112 void panfrost_resource_screen_destroy(struct pipe_screen *screen);
113
114 void panfrost_resource_context_init(struct pipe_context *pctx);
115
116 /* Blitting */
117
118 void
119 panfrost_blit(struct pipe_context *pipe,
120 const struct pipe_blit_info *info);
121
122 void
123 panfrost_resource_set_damage_region(struct pipe_screen *screen,
124 struct pipe_resource *res,
125 unsigned int nrects,
126 const struct pipe_box *rects);
127
128 static inline enum mali_texture_dimension
panfrost_translate_texture_dimension(enum pipe_texture_target t)129 panfrost_translate_texture_dimension(enum pipe_texture_target t) {
130 switch (t)
131 {
132 case PIPE_BUFFER:
133 case PIPE_TEXTURE_1D:
134 case PIPE_TEXTURE_1D_ARRAY:
135 return MALI_TEXTURE_DIMENSION_1D;
136
137 case PIPE_TEXTURE_2D:
138 case PIPE_TEXTURE_2D_ARRAY:
139 case PIPE_TEXTURE_RECT:
140 return MALI_TEXTURE_DIMENSION_2D;
141
142 case PIPE_TEXTURE_3D:
143 return MALI_TEXTURE_DIMENSION_3D;
144
145 case PIPE_TEXTURE_CUBE:
146 case PIPE_TEXTURE_CUBE_ARRAY:
147 return MALI_TEXTURE_DIMENSION_CUBE;
148
149 default:
150 unreachable("Unknown target");
151 }
152 }
153
154 void
155 pan_resource_modifier_convert(struct panfrost_context *ctx,
156 struct panfrost_resource *rsrc,
157 uint64_t modifier, const char *reason);
158
159 void
160 pan_legalize_afbc_format(struct panfrost_context *ctx,
161 struct panfrost_resource *rsrc,
162 enum pipe_format format);
163
164 #endif /* PAN_RESOURCE_H */
165