Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/vulkan/util/vk_object.h
7130 views
1
/*
2
* Copyright © 2020 Intel Corporation
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
20
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
* IN THE SOFTWARE.
22
*/
23
#ifndef VK_OBJECT_H
24
#define VK_OBJECT_H
25
26
#include <vulkan/vulkan.h>
27
#include <vulkan/vk_icd.h>
28
29
#include "c11/threads.h"
30
#include "util/macros.h"
31
#include "util/sparse_array.h"
32
33
#ifdef __cplusplus
34
extern "C" {
35
#endif
36
37
struct hash_table;
38
39
struct vk_device;
40
41
struct vk_object_base {
42
VK_LOADER_DATA _loader_data;
43
VkObjectType type;
44
45
struct vk_device *device;
46
47
/* For VK_EXT_private_data */
48
struct util_sparse_array private_data;
49
};
50
51
void vk_object_base_init(UNUSED struct vk_device *device,
52
struct vk_object_base *base,
53
UNUSED VkObjectType obj_type);
54
void vk_object_base_finish(UNUSED struct vk_object_base *base);
55
void vk_object_base_reset(struct vk_object_base *base);
56
57
static inline void
58
vk_object_base_assert_valid(ASSERTED struct vk_object_base *base,
59
ASSERTED VkObjectType obj_type)
60
{
61
assert(base == NULL || base->type == obj_type);
62
}
63
64
static inline struct vk_object_base *
65
vk_object_base_from_u64_handle(uint64_t handle, VkObjectType obj_type)
66
{
67
struct vk_object_base *base = (struct vk_object_base *)(uintptr_t)handle;
68
vk_object_base_assert_valid(base, obj_type);
69
return base;
70
}
71
72
#define VK_DEFINE_HANDLE_CASTS(__driver_type, __base, __VkType, __VK_TYPE) \
73
static inline struct __driver_type * \
74
__driver_type ## _from_handle(__VkType _handle) \
75
{ \
76
struct vk_object_base *base = (struct vk_object_base *)_handle; \
77
vk_object_base_assert_valid(base, __VK_TYPE); \
78
STATIC_ASSERT(offsetof(struct __driver_type, __base) == 0); \
79
return (struct __driver_type *) base; \
80
} \
81
\
82
static inline __VkType \
83
__driver_type ## _to_handle(struct __driver_type *_obj) \
84
{ \
85
vk_object_base_assert_valid(&_obj->__base, __VK_TYPE); \
86
return (__VkType) _obj; \
87
}
88
89
#define VK_DEFINE_NONDISP_HANDLE_CASTS(__driver_type, __base, __VkType, __VK_TYPE) \
90
static inline struct __driver_type * \
91
__driver_type ## _from_handle(__VkType _handle) \
92
{ \
93
struct vk_object_base *base = \
94
(struct vk_object_base *)(uintptr_t)_handle; \
95
vk_object_base_assert_valid(base, __VK_TYPE); \
96
STATIC_ASSERT(offsetof(struct __driver_type, __base) == 0); \
97
return (struct __driver_type *)base; \
98
} \
99
\
100
static inline __VkType \
101
__driver_type ## _to_handle(struct __driver_type *_obj) \
102
{ \
103
vk_object_base_assert_valid(&_obj->__base, __VK_TYPE); \
104
return (__VkType)(uintptr_t) _obj; \
105
}
106
107
#define VK_FROM_HANDLE(__driver_type, __name, __handle) \
108
struct __driver_type *__name = __driver_type ## _from_handle(__handle)
109
110
/* Helpers for vk object (de)allocation and (de)initialization */
111
void *
112
vk_object_alloc(struct vk_device *device,
113
const VkAllocationCallbacks *alloc,
114
size_t size,
115
VkObjectType vk_obj_type);
116
117
void *
118
vk_object_zalloc(struct vk_device *device,
119
const VkAllocationCallbacks *alloc,
120
size_t size,
121
VkObjectType vk_obj_type);
122
123
struct vk_multialloc;
124
125
void *
126
vk_object_multialloc(struct vk_device *device,
127
struct vk_multialloc *ma,
128
const VkAllocationCallbacks *alloc,
129
VkObjectType vk_obj_type);
130
131
void *
132
vk_object_multizalloc(struct vk_device *device,
133
struct vk_multialloc *ma,
134
const VkAllocationCallbacks *alloc,
135
VkObjectType vk_obj_type);
136
137
void
138
vk_object_free(struct vk_device *device,
139
const VkAllocationCallbacks *alloc,
140
void *data);
141
142
143
struct vk_private_data_slot {
144
struct vk_object_base base;
145
uint32_t index;
146
};
147
VK_DEFINE_NONDISP_HANDLE_CASTS(vk_private_data_slot, base,
148
VkPrivateDataSlotEXT,
149
VK_OBJECT_TYPE_PRIVATE_DATA_SLOT_EXT);
150
151
VkResult
152
vk_private_data_slot_create(struct vk_device *device,
153
const VkPrivateDataSlotCreateInfoEXT* pCreateInfo,
154
const VkAllocationCallbacks* pAllocator,
155
VkPrivateDataSlotEXT* pPrivateDataSlot);
156
void
157
vk_private_data_slot_destroy(struct vk_device *device,
158
VkPrivateDataSlotEXT privateDataSlot,
159
const VkAllocationCallbacks *pAllocator);
160
VkResult
161
vk_object_base_set_private_data(struct vk_device *device,
162
VkObjectType objectType,
163
uint64_t objectHandle,
164
VkPrivateDataSlotEXT privateDataSlot,
165
uint64_t data);
166
void
167
vk_object_base_get_private_data(struct vk_device *device,
168
VkObjectType objectType,
169
uint64_t objectHandle,
170
VkPrivateDataSlotEXT privateDataSlot,
171
uint64_t *pData);
172
173
#ifdef __cplusplus
174
}
175
#endif
176
177
#endif /* VK_OBJECT_H */
178
179