panfrost: Move BO meta-data out of panfrost_bo
[mesa.git] / src / gallium / drivers / panfrost / pan_resource.h
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 <panfrost-job.h>
30 #include "pan_screen.h"
31 #include "pan_allocate.h"
32 #include "drm-uapi/drm.h"
33 #include "util/u_range.h"
34
35 /* Describes the memory layout of a BO */
36
37 enum panfrost_memory_layout {
38 PAN_LINEAR,
39 PAN_TILED,
40 PAN_AFBC
41 };
42
43 struct panfrost_slice {
44 unsigned offset;
45 unsigned stride;
46
47 /* If there is a header preceding each slice, how big is
48 * that header? Used for AFBC */
49 unsigned header_size;
50
51 /* If checksumming is enabled following the slice, what
52 * is its offset/stride? */
53 unsigned checksum_offset;
54 unsigned checksum_stride;
55
56 /* Has anything been written to this slice? */
57 bool initialized;
58 };
59
60 struct panfrost_bo {
61 struct pipe_reference reference;
62
63 /* Mapping for the entire object (all levels) */
64 uint8_t *cpu;
65
66 /* GPU address for the object */
67 mali_ptr gpu;
68
69 /* Size of all entire trees */
70 size_t size;
71
72 int gem_handle;
73 };
74
75 void
76 panfrost_bo_reference(struct panfrost_bo *bo);
77
78 void
79 panfrost_bo_unreference(struct pipe_screen *screen, struct panfrost_bo *bo);
80
81 struct panfrost_resource {
82 struct pipe_resource base;
83
84 struct panfrost_bo *bo;
85 struct renderonly_scanout *scanout;
86
87 struct panfrost_resource *separate_stencil;
88
89 struct util_range valid_buffer_range;
90
91 /* Description of the mip levels */
92 struct panfrost_slice slices[MAX_MIP_LEVELS];
93
94 /* Distance from tree to tree */
95 unsigned cubemap_stride;
96
97 /* Internal layout (tiled?) */
98 enum panfrost_memory_layout layout;
99
100 /* Is transaciton elimination enabled? */
101 bool checksummed;
102 };
103
104 static inline struct panfrost_resource *
105 pan_resource(struct pipe_resource *p)
106 {
107 return (struct panfrost_resource *)p;
108 }
109
110 struct panfrost_gtransfer {
111 struct pipe_transfer base;
112 void *map;
113 };
114
115 static inline struct panfrost_gtransfer *
116 pan_transfer(struct pipe_transfer *p)
117 {
118 return (struct panfrost_gtransfer *)p;
119 }
120
121 mali_ptr
122 panfrost_get_texture_address(
123 struct panfrost_resource *rsrc,
124 unsigned level, unsigned face);
125
126 void panfrost_resource_screen_init(struct panfrost_screen *screen);
127 void panfrost_resource_screen_deinit(struct panfrost_screen *screen);
128
129 void panfrost_resource_context_init(struct pipe_context *pctx);
130
131 /* AFBC */
132
133 bool
134 panfrost_format_supports_afbc(enum pipe_format format);
135
136 unsigned
137 panfrost_afbc_header_size(unsigned width, unsigned height);
138
139 /* Blitting */
140
141 void
142 panfrost_blit(struct pipe_context *pipe,
143 const struct pipe_blit_info *info);
144
145 void
146 panfrost_blit_wallpaper(struct panfrost_context *ctx);
147
148 #endif /* PAN_RESOURCE_H */