632250fa2aa95ef80e330c7cd253b7eec22d55d1
[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 /* Has anything been written to this slice? */
48 bool initialized;
49 };
50
51 struct panfrost_bo {
52 struct pipe_reference reference;
53
54 /* Description of the mip levels */
55 struct panfrost_slice slices[MAX_MIP_LEVELS];
56
57 /* Mapping for the entire object (all levels) */
58 uint8_t *cpu;
59
60 /* GPU address for the object */
61 mali_ptr gpu;
62
63 /* Size of all entire trees */
64 size_t size;
65
66 /* Distance from tree to tree */
67 unsigned cubemap_stride;
68
69 /* Set if this bo was imported rather than allocated */
70 bool imported;
71
72 /* Internal layout (tiled?) */
73 enum panfrost_memory_layout layout;
74
75 /* If AFBC is enabled for this resource, we lug around an AFBC
76 * metadata buffer as well. The actual AFBC resource is also in
77 * afbc_slab (only defined for AFBC) at position afbc_main_offset
78 */
79
80 struct panfrost_memory afbc_slab;
81 int afbc_metadata_size;
82
83 /* If transaciton elimination is enabled, we have a dedicated
84 * buffer for that as well. */
85
86 bool has_checksum;
87 struct panfrost_memory checksum_slab;
88 int checksum_stride;
89
90 int gem_handle;
91 };
92
93 void
94 panfrost_bo_reference(struct panfrost_bo *bo);
95
96 void
97 panfrost_bo_unreference(struct pipe_screen *screen, struct panfrost_bo *bo);
98
99 struct panfrost_resource {
100 struct pipe_resource base;
101
102 struct panfrost_bo *bo;
103 struct renderonly_scanout *scanout;
104
105 struct panfrost_resource *separate_stencil;
106
107 struct util_range valid_buffer_range;
108 };
109
110 static inline struct panfrost_resource *
111 pan_resource(struct pipe_resource *p)
112 {
113 return (struct panfrost_resource *)p;
114 }
115
116 struct panfrost_gtransfer {
117 struct pipe_transfer base;
118 void *map;
119 };
120
121 static inline struct panfrost_gtransfer *
122 pan_transfer(struct pipe_transfer *p)
123 {
124 return (struct panfrost_gtransfer *)p;
125 }
126
127 void panfrost_resource_screen_init(struct panfrost_screen *screen);
128 void panfrost_resource_screen_deinit(struct panfrost_screen *screen);
129
130 void panfrost_resource_context_init(struct pipe_context *pctx);
131
132 /* AFBC */
133
134 bool
135 panfrost_format_supports_afbc(enum pipe_format format);
136
137 void
138 panfrost_enable_afbc(struct panfrost_context *ctx, struct panfrost_resource *rsrc, bool ds);
139
140 /* Blitting */
141
142 void
143 panfrost_blit(struct pipe_context *pipe,
144 const struct pipe_blit_info *info);
145
146 void
147 panfrost_blit_wallpaper(struct panfrost_context *ctx);
148
149 #endif /* PAN_RESOURCE_H */