panfrost: Rename panfrost_stage_attributes()
[mesa.git] / src / gallium / drivers / panfrost / pan_bo.h
1 /*
2 * © Copyright 2019 Alyssa Rosenzweig
3 * © Copyright 2019 Collabora, Ltd.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 */
25
26 #ifndef __PAN_BO_H__
27 #define __PAN_BO_H__
28
29 #include <panfrost-misc.h>
30 #include "pipe/p_state.h"
31 #include "util/list.h"
32
33 struct panfrost_screen;
34
35 /* Flags for allocated memory */
36
37 /* This memory region is executable */
38 #define PAN_BO_EXECUTE (1 << 0)
39
40 /* This memory region should be lazily allocated and grow-on-page-fault. Must
41 * be used in conjunction with INVISIBLE */
42 #define PAN_BO_GROWABLE (1 << 1)
43
44 /* This memory region should not be mapped to the CPU */
45 #define PAN_BO_INVISIBLE (1 << 2)
46
47 /* This memory region will be used for varyings and needs to have the cache
48 * bits twiddled accordingly */
49 #define PAN_BO_COHERENT_LOCAL (1 << 3)
50
51 /* This region may not be used immediately and will not mmap on allocate
52 * (semantically distinct from INVISIBLE, which cannot never be mmaped) */
53 #define PAN_BO_DELAY_MMAP (1 << 4)
54
55 /* Some BOs shouldn't be returned back to the reuse BO cache, use this flag to
56 * let the BO logic know about this contraint. */
57 #define PAN_BO_DONT_REUSE (1 << 5)
58
59 /* BO has been imported */
60 #define PAN_BO_IMPORTED (1 << 6)
61
62 /* BO has been exported */
63 #define PAN_BO_EXPORTED (1 << 7)
64
65 /* GPU access flags */
66
67 /* BO is either shared (can be accessed by more than one GPU batch) or private
68 * (reserved by a specific GPU job). */
69 #define PAN_BO_ACCESS_PRIVATE (0 << 0)
70 #define PAN_BO_ACCESS_SHARED (1 << 0)
71
72 /* BO is being read/written by the GPU */
73 #define PAN_BO_ACCESS_READ (1 << 1)
74 #define PAN_BO_ACCESS_WRITE (1 << 2)
75 #define PAN_BO_ACCESS_RW (PAN_BO_ACCESS_READ | PAN_BO_ACCESS_WRITE)
76
77 /* BO is accessed by the vertex/tiler job. */
78 #define PAN_BO_ACCESS_VERTEX_TILER (1 << 3)
79
80 /* BO is accessed by the fragment job. */
81 #define PAN_BO_ACCESS_FRAGMENT (1 << 4)
82
83 struct panfrost_bo {
84 /* Must be first for casting */
85 struct list_head bucket_link;
86
87 /* Used to link the BO to the BO cache LRU list. */
88 struct list_head lru_link;
89
90 /* Store the time this BO was use last, so the BO cache logic can evict
91 * stale BOs.
92 */
93 time_t last_used;
94
95 struct pipe_reference reference;
96
97 struct panfrost_screen *screen;
98
99 /* Mapping for the entire object (all levels) */
100 uint8_t *cpu;
101
102 /* GPU address for the object */
103 mali_ptr gpu;
104
105 /* Size of all entire trees */
106 size_t size;
107
108 int gem_handle;
109
110 uint32_t flags;
111
112 /* Combination of PAN_BO_ACCESS_{READ,WRITE} flags encoding pending
113 * GPU accesses to this BO. Useful to avoid calling the WAIT_BO ioctl
114 * when the BO is idle.
115 */
116 uint32_t gpu_access;
117 };
118
119 /* If a BO is accessed for a particular shader stage, will it be in the primary
120 * batch (vertex/tiler) or the secondary batch (fragment)? Anything but
121 * fragment will be primary, e.g. compute jobs will be considered
122 * "vertex/tiler" by analogy */
123
124 static inline uint32_t
125 panfrost_bo_access_for_stage(enum pipe_shader_type stage)
126 {
127 assert(stage == PIPE_SHADER_FRAGMENT ||
128 stage == PIPE_SHADER_VERTEX ||
129 stage == PIPE_SHADER_COMPUTE);
130
131 return stage == PIPE_SHADER_FRAGMENT ?
132 PAN_BO_ACCESS_FRAGMENT :
133 PAN_BO_ACCESS_VERTEX_TILER;
134 }
135
136 bool
137 panfrost_bo_wait(struct panfrost_bo *bo, int64_t timeout_ns,
138 uint32_t access_type);
139 void
140 panfrost_bo_reference(struct panfrost_bo *bo);
141 void
142 panfrost_bo_unreference(struct panfrost_bo *bo);
143 struct panfrost_bo *
144 panfrost_bo_create(struct panfrost_screen *screen, size_t size,
145 uint32_t flags);
146 void
147 panfrost_bo_mmap(struct panfrost_bo *bo);
148 struct panfrost_bo *
149 panfrost_bo_import(struct panfrost_screen *screen, int fd);
150 int
151 panfrost_bo_export(struct panfrost_bo *bo);
152 void
153 panfrost_bo_cache_evict_all(struct panfrost_screen *screen);
154
155 #endif /* __PAN_BO_H__ */