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 <midgard_pack.h>
30 #include "pan_screen.h"
31 #include "pan_pool.h"
32 #include "pan_minmax_cache.h"
33 #include "pan_texture.h"
34 #include "pan_partial_update.h"
35 #include "drm-uapi/drm.h"
36 #include "util/u_range.h"
37
38 #define LAYOUT_CONVERT_THRESHOLD 8
39
40 struct panfrost_resource {
41 struct pipe_resource base;
42 struct {
43 struct pipe_scissor_state extent;
44 struct pan_rect *inverted_rects;
45 unsigned inverted_len;
46 } damage;
47
48 struct panfrost_bo *bo;
49 struct renderonly_scanout *scanout;
50
51 struct panfrost_resource *separate_stencil;
52
53 struct util_range valid_buffer_range;
54
55 /* Description of the mip levels */
56 struct panfrost_slice slices[MAX_MIP_LEVELS];
57
58 /* Distance from tree to tree */
59 unsigned cubemap_stride;
60
61 /* DRM fourcc code: linear, 16x16 u-interleaved, AFBC */
62 uint64_t modifier;
63
64 /* Whether the modifier can be changed */
65 bool modifier_constant;
66
67 /* Is transaciton elimination enabled? */
68 bool checksummed;
69
70 /* Used to decide when to convert to another modifier */
71 uint16_t modifier_updates;
72
73 enum pipe_format internal_format;
74
75 /* Cached min/max values for index buffers */
76 struct panfrost_minmax_cache *index_cache;
77 };
78
79 static inline struct panfrost_resource *
pan_resource(struct pipe_resource * p)80 pan_resource(struct pipe_resource *p)
81 {
82 return (struct panfrost_resource *)p;
83 }
84
85 struct panfrost_transfer {
86 struct pipe_transfer base;
87 void *map;
88 struct {
89 struct pipe_resource *rsrc;
90 struct pipe_box box;
91 } staging;
92 };
93
94 static inline struct panfrost_transfer *
pan_transfer(struct pipe_transfer * p)95 pan_transfer(struct pipe_transfer *p)
96 {
97 return (struct panfrost_transfer *)p;
98 }
99
100 mali_ptr
101 panfrost_get_texture_address(
102 struct panfrost_resource *rsrc,
103 unsigned level, unsigned face, unsigned sample);
104
105 void panfrost_resource_screen_init(struct pipe_screen *screen);
106
107 void panfrost_resource_context_init(struct pipe_context *pctx);
108
109 /* Blitting */
110
111 void
112 panfrost_blit(struct pipe_context *pipe,
113 const struct pipe_blit_info *info);
114
115 void
116 panfrost_resource_set_damage_region(struct pipe_screen *screen,
117 struct pipe_resource *res,
118 unsigned int nrects,
119 const struct pipe_box *rects);
120
121 static inline enum mali_texture_dimension
panfrost_translate_texture_dimension(enum pipe_texture_target t)122 panfrost_translate_texture_dimension(enum pipe_texture_target t) {
123 switch (t)
124 {
125 case PIPE_BUFFER:
126 case PIPE_TEXTURE_1D:
127 case PIPE_TEXTURE_1D_ARRAY:
128 return MALI_TEXTURE_DIMENSION_1D;
129
130 case PIPE_TEXTURE_2D:
131 case PIPE_TEXTURE_2D_ARRAY:
132 case PIPE_TEXTURE_RECT:
133 return MALI_TEXTURE_DIMENSION_2D;
134
135 case PIPE_TEXTURE_3D:
136 return MALI_TEXTURE_DIMENSION_3D;
137
138 case PIPE_TEXTURE_CUBE:
139 case PIPE_TEXTURE_CUBE_ARRAY:
140 return MALI_TEXTURE_DIMENSION_CUBE;
141
142 default:
143 unreachable("Unknown target");
144 }
145 }
146
147
148 #endif /* PAN_RESOURCE_H */
149