Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/virtio/vulkan/vn_common.h
4560 views
1
/*
2
* Copyright 2019 Google LLC
3
* SPDX-License-Identifier: MIT
4
*
5
* based in part on anv and radv which are:
6
* Copyright © 2015 Intel Corporation
7
* Copyright © 2016 Red Hat.
8
* Copyright © 2016 Bas Nieuwenhuizen
9
*/
10
11
#ifndef VN_COMMON_H
12
#define VN_COMMON_H
13
14
#include <assert.h>
15
#include <inttypes.h>
16
#include <limits.h>
17
#include <stdatomic.h>
18
#include <stdbool.h>
19
#include <stddef.h>
20
#include <stdint.h>
21
#include <stdlib.h>
22
#include <string.h>
23
#include <vulkan/vulkan.h>
24
25
#include "c11/threads.h"
26
#include "util/bitscan.h"
27
#include "util/compiler.h"
28
#include "util/list.h"
29
#include "util/macros.h"
30
#include "util/os_time.h"
31
#include "util/u_math.h"
32
#include "util/xmlconfig.h"
33
#include "vk_alloc.h"
34
#include "vk_debug_report.h"
35
#include "vk_device.h"
36
#include "vk_instance.h"
37
#include "vk_object.h"
38
#include "vk_physical_device.h"
39
#include "vk_util.h"
40
41
#include "vn_entrypoints.h"
42
43
#define VN_DEFAULT_ALIGN 8
44
45
#define VN_DEBUG(category) (unlikely(vn_debug & VN_DEBUG_##category))
46
47
#define vn_error(instance, error) \
48
(VN_DEBUG(RESULT) ? vn_log_result((instance), (error), __func__) : (error))
49
#define vn_result(instance, result) \
50
((result) >= VK_SUCCESS ? (result) : vn_error((instance), (result)))
51
52
struct vn_instance;
53
struct vn_physical_device;
54
struct vn_device;
55
struct vn_queue;
56
struct vn_fence;
57
struct vn_semaphore;
58
struct vn_device_memory;
59
struct vn_buffer;
60
struct vn_buffer_view;
61
struct vn_image;
62
struct vn_image_view;
63
struct vn_sampler;
64
struct vn_sampler_ycbcr_conversion;
65
struct vn_descriptor_set_layout;
66
struct vn_descriptor_pool;
67
struct vn_descriptor_set;
68
struct vn_descriptor_update_template;
69
struct vn_render_pass;
70
struct vn_framebuffer;
71
struct vn_event;
72
struct vn_query_pool;
73
struct vn_shader_module;
74
struct vn_pipeline_layout;
75
struct vn_pipeline_cache;
76
struct vn_pipeline;
77
struct vn_command_pool;
78
struct vn_command_buffer;
79
80
struct vn_cs_encoder;
81
struct vn_cs_decoder;
82
83
struct vn_renderer;
84
struct vn_renderer_shmem;
85
struct vn_renderer_bo;
86
struct vn_renderer_sync;
87
88
enum vn_debug {
89
VN_DEBUG_INIT = 1ull << 0,
90
VN_DEBUG_RESULT = 1ull << 1,
91
VN_DEBUG_VTEST = 1ull << 2,
92
VN_DEBUG_WSI = 1ull << 3,
93
};
94
95
typedef uint64_t vn_object_id;
96
97
/* base class of vn_instance */
98
struct vn_instance_base {
99
struct vk_instance base;
100
vn_object_id id;
101
};
102
103
/* base class of vn_physical_device */
104
struct vn_physical_device_base {
105
struct vk_physical_device base;
106
vn_object_id id;
107
};
108
109
/* base class of vn_device */
110
struct vn_device_base {
111
struct vk_device base;
112
vn_object_id id;
113
};
114
115
/* base class of other driver objects */
116
struct vn_object_base {
117
struct vk_object_base base;
118
vn_object_id id;
119
};
120
121
extern uint64_t vn_debug;
122
123
void
124
vn_debug_init(void);
125
126
void
127
vn_log(struct vn_instance *instance, const char *format, ...)
128
PRINTFLIKE(2, 3);
129
130
VkResult
131
vn_log_result(struct vn_instance *instance,
132
VkResult result,
133
const char *where);
134
135
void
136
vn_relax(uint32_t *iter);
137
138
static_assert(sizeof(vn_object_id) >= sizeof(uintptr_t), "");
139
140
static inline VkResult
141
vn_instance_base_init(
142
struct vn_instance_base *instance,
143
const struct vk_instance_extension_table *supported_extensions,
144
const struct vk_instance_dispatch_table *dispatch_table,
145
const VkInstanceCreateInfo *info,
146
const VkAllocationCallbacks *alloc)
147
{
148
VkResult result = vk_instance_init(&instance->base, supported_extensions,
149
dispatch_table, info, alloc);
150
instance->id = (uintptr_t)instance;
151
return result;
152
}
153
154
static inline void
155
vn_instance_base_fini(struct vn_instance_base *instance)
156
{
157
vk_instance_finish(&instance->base);
158
}
159
160
static inline VkResult
161
vn_physical_device_base_init(
162
struct vn_physical_device_base *physical_dev,
163
struct vn_instance_base *instance,
164
const struct vk_device_extension_table *supported_extensions,
165
const struct vk_physical_device_dispatch_table *dispatch_table)
166
{
167
VkResult result =
168
vk_physical_device_init(&physical_dev->base, &instance->base,
169
supported_extensions, dispatch_table);
170
physical_dev->id = (uintptr_t)physical_dev;
171
return result;
172
}
173
174
static inline void
175
vn_physical_device_base_fini(struct vn_physical_device_base *physical_dev)
176
{
177
vk_physical_device_finish(&physical_dev->base);
178
}
179
180
static inline VkResult
181
vn_device_base_init(struct vn_device_base *dev,
182
struct vn_physical_device_base *physical_dev,
183
const struct vk_device_dispatch_table *dispatch_table,
184
const VkDeviceCreateInfo *info,
185
const VkAllocationCallbacks *alloc)
186
{
187
VkResult result = vk_device_init(&dev->base, &physical_dev->base,
188
dispatch_table, info, alloc);
189
dev->id = (uintptr_t)dev;
190
return result;
191
}
192
193
static inline void
194
vn_device_base_fini(struct vn_device_base *dev)
195
{
196
vk_device_finish(&dev->base);
197
}
198
199
static inline void
200
vn_object_base_init(struct vn_object_base *obj,
201
VkObjectType type,
202
struct vn_device_base *dev)
203
{
204
vk_object_base_init(&dev->base, &obj->base, type);
205
obj->id = (uintptr_t)obj;
206
}
207
208
static inline void
209
vn_object_base_fini(struct vn_object_base *obj)
210
{
211
vk_object_base_finish(&obj->base);
212
}
213
214
static inline void
215
vn_object_set_id(void *obj, vn_object_id id, VkObjectType type)
216
{
217
assert(((const struct vk_object_base *)obj)->type == type);
218
switch (type) {
219
case VK_OBJECT_TYPE_INSTANCE:
220
((struct vn_instance_base *)obj)->id = id;
221
break;
222
case VK_OBJECT_TYPE_PHYSICAL_DEVICE:
223
((struct vn_physical_device_base *)obj)->id = id;
224
break;
225
case VK_OBJECT_TYPE_DEVICE:
226
((struct vn_device_base *)obj)->id = id;
227
break;
228
default:
229
((struct vn_object_base *)obj)->id = id;
230
break;
231
}
232
}
233
234
static inline vn_object_id
235
vn_object_get_id(const void *obj, VkObjectType type)
236
{
237
assert(((const struct vk_object_base *)obj)->type == type);
238
switch (type) {
239
case VK_OBJECT_TYPE_INSTANCE:
240
return ((struct vn_instance_base *)obj)->id;
241
case VK_OBJECT_TYPE_PHYSICAL_DEVICE:
242
return ((struct vn_physical_device_base *)obj)->id;
243
case VK_OBJECT_TYPE_DEVICE:
244
return ((struct vn_device_base *)obj)->id;
245
default:
246
return ((struct vn_object_base *)obj)->id;
247
}
248
}
249
250
#endif /* VN_COMMON_H */
251
252