radv: move is_local up to the winsys level.
[mesa.git] / src / amd / vulkan / radv_radeon_winsys.h
1 /*
2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
4 *
5 * Based on radeon_winsys.h which is:
6 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
7 * Copyright 2010 Marek Olšák <maraeo@gmail.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
18 * Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 * IN THE SOFTWARE.
27 */
28
29 #ifndef RADV_RADEON_WINSYS_H
30 #define RADV_RADEON_WINSYS_H
31
32 #include <stdint.h>
33 #include <stdbool.h>
34 #include <stdlib.h>
35 #include "main/macros.h"
36 #include "amd_family.h"
37
38 struct radeon_info;
39 struct ac_surf_info;
40 struct radeon_surf;
41
42 #define FREE(x) free(x)
43
44 enum radeon_bo_domain { /* bitfield */
45 RADEON_DOMAIN_GTT = 2,
46 RADEON_DOMAIN_VRAM = 4,
47 RADEON_DOMAIN_VRAM_GTT = RADEON_DOMAIN_VRAM | RADEON_DOMAIN_GTT
48 };
49
50 enum radeon_bo_flag { /* bitfield */
51 RADEON_FLAG_GTT_WC = (1 << 0),
52 RADEON_FLAG_CPU_ACCESS = (1 << 1),
53 RADEON_FLAG_NO_CPU_ACCESS = (1 << 2),
54 RADEON_FLAG_VIRTUAL = (1 << 3),
55 RADEON_FLAG_VA_UNCACHED = (1 << 4),
56 RADEON_FLAG_IMPLICIT_SYNC = (1 << 5),
57 RADEON_FLAG_NO_INTERPROCESS_SHARING = (1 << 6),
58 };
59
60 enum radeon_bo_usage { /* bitfield */
61 RADEON_USAGE_READ = 2,
62 RADEON_USAGE_WRITE = 4,
63 RADEON_USAGE_READWRITE = RADEON_USAGE_READ | RADEON_USAGE_WRITE
64 };
65
66 enum ring_type {
67 RING_GFX = 0,
68 RING_COMPUTE,
69 RING_DMA,
70 RING_UVD,
71 RING_VCE,
72 RING_LAST,
73 };
74
75 enum radeon_ctx_priority {
76 RADEON_CTX_PRIORITY_INVALID = -1,
77 RADEON_CTX_PRIORITY_LOW = 0,
78 RADEON_CTX_PRIORITY_MEDIUM,
79 RADEON_CTX_PRIORITY_HIGH,
80 RADEON_CTX_PRIORITY_REALTIME,
81 };
82
83 struct radeon_winsys_cs {
84 unsigned cdw; /* Number of used dwords. */
85 unsigned max_dw; /* Maximum number of dwords. */
86 uint32_t *buf; /* The base pointer of the chunk. */
87 };
88
89 #define RADEON_SURF_TYPE_MASK 0xFF
90 #define RADEON_SURF_TYPE_SHIFT 0
91 #define RADEON_SURF_TYPE_1D 0
92 #define RADEON_SURF_TYPE_2D 1
93 #define RADEON_SURF_TYPE_3D 2
94 #define RADEON_SURF_TYPE_CUBEMAP 3
95 #define RADEON_SURF_TYPE_1D_ARRAY 4
96 #define RADEON_SURF_TYPE_2D_ARRAY 5
97 #define RADEON_SURF_MODE_MASK 0xFF
98 #define RADEON_SURF_MODE_SHIFT 8
99
100 #define RADEON_SURF_GET(v, field) (((v) >> RADEON_SURF_ ## field ## _SHIFT) & RADEON_SURF_ ## field ## _MASK)
101 #define RADEON_SURF_SET(v, field) (((v) & RADEON_SURF_ ## field ## _MASK) << RADEON_SURF_ ## field ## _SHIFT)
102 #define RADEON_SURF_CLR(v, field) ((v) & ~(RADEON_SURF_ ## field ## _MASK << RADEON_SURF_ ## field ## _SHIFT))
103
104 enum radeon_bo_layout {
105 RADEON_LAYOUT_LINEAR = 0,
106 RADEON_LAYOUT_TILED,
107 RADEON_LAYOUT_SQUARETILED,
108
109 RADEON_LAYOUT_UNKNOWN
110 };
111
112 /* Tiling info for display code, DRI sharing, and other data. */
113 struct radeon_bo_metadata {
114 /* Tiling flags describing the texture layout for display code
115 * and DRI sharing.
116 */
117 union {
118 struct {
119 enum radeon_bo_layout microtile;
120 enum radeon_bo_layout macrotile;
121 unsigned pipe_config;
122 unsigned bankw;
123 unsigned bankh;
124 unsigned tile_split;
125 unsigned mtilea;
126 unsigned num_banks;
127 unsigned stride;
128 bool scanout;
129 } legacy;
130
131 struct {
132 /* surface flags */
133 unsigned swizzle_mode:5;
134 } gfx9;
135 } u;
136
137 /* Additional metadata associated with the buffer, in bytes.
138 * The maximum size is 64 * 4. This is opaque for the winsys & kernel.
139 * Supported by amdgpu only.
140 */
141 uint32_t size_metadata;
142 uint32_t metadata[64];
143 };
144
145 uint32_t syncobj_handle;
146 struct radeon_winsys_fence;
147
148 struct radeon_winsys_bo {
149 uint64_t va;
150 bool is_local;
151 };
152 struct radv_winsys_sem_counts {
153 uint32_t syncobj_count;
154 uint32_t sem_count;
155 uint32_t *syncobj;
156 struct radeon_winsys_sem **sem;
157 };
158
159 struct radv_winsys_sem_info {
160 bool cs_emit_signal;
161 bool cs_emit_wait;
162 struct radv_winsys_sem_counts wait;
163 struct radv_winsys_sem_counts signal;
164 };
165
166 struct radeon_winsys {
167 void (*destroy)(struct radeon_winsys *ws);
168
169 void (*query_info)(struct radeon_winsys *ws,
170 struct radeon_info *info);
171
172 bool (*read_registers)(struct radeon_winsys *ws, unsigned reg_offset,
173 unsigned num_registers, uint32_t *out);
174
175 const char *(*get_chip_name)(struct radeon_winsys *ws);
176
177 struct radeon_winsys_bo *(*buffer_create)(struct radeon_winsys *ws,
178 uint64_t size,
179 unsigned alignment,
180 enum radeon_bo_domain domain,
181 enum radeon_bo_flag flags);
182
183 void (*buffer_destroy)(struct radeon_winsys_bo *bo);
184 void *(*buffer_map)(struct radeon_winsys_bo *bo);
185
186 struct radeon_winsys_bo *(*buffer_from_fd)(struct radeon_winsys *ws,
187 int fd,
188 unsigned *stride, unsigned *offset);
189
190 bool (*buffer_get_fd)(struct radeon_winsys *ws,
191 struct radeon_winsys_bo *bo,
192 int *fd);
193
194 void (*buffer_unmap)(struct radeon_winsys_bo *bo);
195
196 void (*buffer_set_metadata)(struct radeon_winsys_bo *bo,
197 struct radeon_bo_metadata *md);
198
199 void (*buffer_virtual_bind)(struct radeon_winsys_bo *parent,
200 uint64_t offset, uint64_t size,
201 struct radeon_winsys_bo *bo, uint64_t bo_offset);
202 struct radeon_winsys_ctx *(*ctx_create)(struct radeon_winsys *ws,
203 enum radeon_ctx_priority priority);
204 void (*ctx_destroy)(struct radeon_winsys_ctx *ctx);
205
206 bool (*ctx_wait_idle)(struct radeon_winsys_ctx *ctx,
207 enum ring_type ring_type, int ring_index);
208
209 struct radeon_winsys_cs *(*cs_create)(struct radeon_winsys *ws,
210 enum ring_type ring_type);
211
212 void (*cs_destroy)(struct radeon_winsys_cs *cs);
213
214 void (*cs_reset)(struct radeon_winsys_cs *cs);
215
216 bool (*cs_finalize)(struct radeon_winsys_cs *cs);
217
218 void (*cs_grow)(struct radeon_winsys_cs * cs, size_t min_size);
219
220 int (*cs_submit)(struct radeon_winsys_ctx *ctx,
221 int queue_index,
222 struct radeon_winsys_cs **cs_array,
223 unsigned cs_count,
224 struct radeon_winsys_cs *initial_preamble_cs,
225 struct radeon_winsys_cs *continue_preamble_cs,
226 struct radv_winsys_sem_info *sem_info,
227 bool can_patch,
228 struct radeon_winsys_fence *fence);
229
230 void (*cs_add_buffer)(struct radeon_winsys_cs *cs,
231 struct radeon_winsys_bo *bo,
232 uint8_t priority);
233
234 void (*cs_execute_secondary)(struct radeon_winsys_cs *parent,
235 struct radeon_winsys_cs *child);
236
237 void (*cs_dump)(struct radeon_winsys_cs *cs, FILE* file, const int *trace_ids, int trace_id_count);
238
239 int (*surface_init)(struct radeon_winsys *ws,
240 const struct ac_surf_info *surf_info,
241 struct radeon_surf *surf);
242
243 int (*surface_best)(struct radeon_winsys *ws,
244 struct radeon_surf *surf);
245
246 struct radeon_winsys_fence *(*create_fence)();
247 void (*destroy_fence)(struct radeon_winsys_fence *fence);
248 bool (*fence_wait)(struct radeon_winsys *ws,
249 struct radeon_winsys_fence *fence,
250 bool absolute,
251 uint64_t timeout);
252
253 /* old semaphores - non shareable */
254 struct radeon_winsys_sem *(*create_sem)(struct radeon_winsys *ws);
255 void (*destroy_sem)(struct radeon_winsys_sem *sem);
256
257 /* new shareable sync objects */
258 int (*create_syncobj)(struct radeon_winsys *ws, uint32_t *handle);
259 void (*destroy_syncobj)(struct radeon_winsys *ws, uint32_t handle);
260
261 int (*export_syncobj)(struct radeon_winsys *ws, uint32_t syncobj, int *fd);
262 int (*import_syncobj)(struct radeon_winsys *ws, int fd, uint32_t *syncobj);
263
264 };
265
266 static inline void radeon_emit(struct radeon_winsys_cs *cs, uint32_t value)
267 {
268 cs->buf[cs->cdw++] = value;
269 }
270
271 static inline void radeon_emit_array(struct radeon_winsys_cs *cs,
272 const uint32_t *values, unsigned count)
273 {
274 memcpy(cs->buf + cs->cdw, values, count * 4);
275 cs->cdw += count;
276 }
277
278 static inline uint64_t radv_buffer_get_va(struct radeon_winsys_bo *bo)
279 {
280 return bo->va;
281 }
282
283 static inline void radv_cs_add_buffer(struct radeon_winsys *ws,
284 struct radeon_winsys_cs *cs,
285 struct radeon_winsys_bo *bo,
286 uint8_t priority)
287 {
288 if (bo->is_local)
289 return;
290
291 ws->cs_add_buffer(cs, bo, priority);
292 }
293
294 #endif /* RADV_RADEON_WINSYS_H */