3b497a368bf5250b814512d5cfebdd1105b74183
[mesa.git] / src / libre-soc / vulkan / libresoc_private.h
1 /*
2 * Copyright © 2019 Raspberry Pi
3 *
4 * based in part on anv driver which is:
5 * Copyright © 2015 Intel Corporation
6 *
7 * based in part on radv driver which is:
8 * Copyright © 2016 Red Hat.
9 * Copyright © 2016 Bas Nieuwenhuizen
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice (including the next
19 * paragraph) shall be included in all copies or substantial portions of the
20 * Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 * IN THE SOFTWARE.
29 */
30 #ifndef LIBRESOC_PRIVATE_H
31 #define LIBRESOC_PRIVATE_H
32
33 #include <stdio.h>
34 #include <string.h>
35 #include <vulkan/vulkan.h>
36 #include <vulkan/vk_icd.h>
37
38 //#include "common/libresoc_device_info.h"
39
40 #include "vk_debug_report.h"
41 #include "util/xmlconfig.h"
42
43 #include "libresoc_entrypoints.h"
44 #include "libresoc_extensions.h"
45
46 struct libresoc_instance;
47
48 struct libresoc_device {
49 VK_LOADER_DATA _loader_data;
50
51 VkAllocationCallbacks alloc;
52
53 struct libresoc_instance *instance;
54
55 struct libresoc_device_extension_table enabled_extensions;
56 struct libresoc_device_dispatch_table dispatch;
57
58 /* FIXME: stub */
59 };
60
61
62 struct libresoc_physical_device {
63 VK_LOADER_DATA _loader_data;
64
65 struct libresoc_instance *instance;
66
67 struct libresoc_device_extension_table supported_extensions;
68 struct libresoc_physical_device_dispatch_table dispatch;
69
70 /* FIXME: stub */
71 };
72
73 struct libresoc_app_info {
74 const char *app_name;
75 uint32_t app_version;
76 const char *engine_name;
77 uint32_t engine_version;
78 uint32_t api_version;
79 };
80
81 struct libresoc_instance {
82 VK_LOADER_DATA _loader_data;
83
84 VkAllocationCallbacks alloc;
85
86 struct libresoc_app_info app_info;
87
88 struct libresoc_instance_extension_table enabled_extensions;
89 struct libresoc_instance_dispatch_table dispatch;
90 struct libresoc_device_dispatch_table device_dispatch;
91
92 int physicalDeviceCount;
93 struct libresoc_physical_device physicalDevice;
94
95 struct vk_debug_report_instance debug_report_callbacks;
96 };
97
98 struct libresoc_queue {
99 VK_LOADER_DATA _loader_data;
100
101 struct libresoc_device *device;
102
103 VkDeviceQueueCreateFlags flags;
104
105 /* FIXME: stub */
106 };
107
108 struct libresoc_cmd_buffer {
109 VK_LOADER_DATA _loader_data;
110
111 struct libresoc_device *device;
112
113 /* FIXME: stub */
114 };
115
116 uint32_t libresoc_physical_device_api_version(struct libresoc_physical_device *dev);
117
118 int libresoc_get_instance_entrypoint_index(const char *name);
119 int libresoc_get_device_entrypoint_index(const char *name);
120 int libresoc_get_physical_device_entrypoint_index(const char *name);
121
122 const char *libresoc_get_instance_entry_name(int index);
123 const char *libresoc_get_physical_device_entry_name(int index);
124 const char *libresoc_get_device_entry_name(int index);
125
126 bool
127 libresoc_instance_entrypoint_is_enabled(int index, uint32_t core_version,
128 const struct libresoc_instance_extension_table *instance);
129 bool
130 libresoc_physical_device_entrypoint_is_enabled(int index, uint32_t core_version,
131 const struct libresoc_instance_extension_table *instance);
132 bool
133 libresoc_device_entrypoint_is_enabled(int index, uint32_t core_version,
134 const struct libresoc_instance_extension_table *instance,
135 const struct libresoc_device_extension_table *device);
136
137 void *libresoc_lookup_entrypoint(const char *name);
138
139 #define libresoc_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
140
141 VkResult __vk_errorf(struct libresoc_instance *instance, VkResult error,
142 const char *file, int line,
143 const char *format, ...);
144
145 #define vk_error(instance, error) __vk_errorf(instance, error, __FILE__, __LINE__, NULL);
146 #define vk_errorf(instance, error, format, ...) __vk_errorf(instance, error, __FILE__, __LINE__, format, ## __VA_ARGS__);
147
148 void libresoc_loge(const char *format, ...) libresoc_printflike(1, 2);
149 void libresoc_loge_v(const char *format, va_list va);
150
151 #define LIBRESOC_DEFINE_HANDLE_CASTS(__libresoc_type, __VkType) \
152 \
153 static inline struct __libresoc_type * \
154 __libresoc_type ## _from_handle(__VkType _handle) \
155 { \
156 return (struct __libresoc_type *) _handle; \
157 } \
158 \
159 static inline __VkType \
160 __libresoc_type ## _to_handle(struct __libresoc_type *_obj) \
161 { \
162 return (__VkType) _obj; \
163 }
164
165 #define LIBRESOC_FROM_HANDLE(__libresoc_type, __name, __handle) \
166 struct __libresoc_type *__name = __libresoc_type ## _from_handle(__handle)
167
168 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_cmd_buffer, VkCommandBuffer)
169 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_device, VkDevice)
170 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_instance, VkInstance)
171 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_physical_device, VkPhysicalDevice)
172 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_queue, VkQueue)
173
174
175 #endif /* LIBRESOC_PRIVATE_H */