panfrost: Add gem_handle to panfrost_memory and 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
34 struct panfrost_bo {
35 /* Address to the BO in question */
36
37 uint8_t *cpu[MAX_MIP_LEVELS];
38
39 /* Not necessarily a GPU mapping of cpu! In case of texture tiling, gpu
40 * points to the GPU-side, tiled texture, while cpu points to the
41 * CPU-side, untiled texture from mesa */
42
43 mali_ptr gpu[MAX_MIP_LEVELS];
44
45 /* Memory entry corresponding to gpu above */
46 struct panfrost_memory_entry *entry[MAX_MIP_LEVELS];
47
48 /* Set if this bo was imported rather than allocated */
49 bool imported;
50
51 /* Number of bytes of the imported allocation */
52 size_t imported_size;
53
54 /* Set for tiled, clear for linear. */
55 bool tiled;
56
57 /* Is something other than level 0 ever written? */
58 bool is_mipmap;
59
60 /* If AFBC is enabled for this resource, we lug around an AFBC
61 * metadata buffer as well. The actual AFBC resource is also in
62 * afbc_slab (only defined for AFBC) at position afbc_main_offset */
63
64 bool has_afbc;
65 struct panfrost_memory afbc_slab;
66 int afbc_metadata_size;
67
68 /* Similarly for TE */
69 bool has_checksum;
70 struct panfrost_memory checksum_slab;
71 int checksum_stride;
72
73 int gem_handle;
74 };
75
76 struct panfrost_resource {
77 struct pipe_resource base;
78
79 struct panfrost_bo *bo;
80 struct renderonly_scanout *scanout;
81
82 struct panfrost_resource *separate_stencil;
83 };
84
85 static inline struct panfrost_resource *
86 pan_resource(struct pipe_resource *p)
87 {
88 return (struct panfrost_resource *)p;
89 }
90
91 void panfrost_resource_screen_init(struct panfrost_screen *screen);
92
93 void panfrost_resource_context_init(struct pipe_context *pctx);
94
95 #endif /* PAN_RESOURCE_H */