5aba3eb4142e058bd67c20e23a7d980ec52e601b
[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 "vk_object.h"
44 #include "libresoc_entrypoints.h"
45 #include "libresoc_extensions.h"
46
47 struct libresoc_instance;
48
49 struct libresoc_device {
50 VK_LOADER_DATA _loader_data;
51
52 VkAllocationCallbacks alloc;
53
54 struct libresoc_instance *instance;
55
56 struct libresoc_device_extension_table enabled_extensions;
57 struct libresoc_device_dispatch_table dispatch;
58
59 /* FIXME: stub */
60 };
61
62
63 struct libresoc_physical_device {
64 VK_LOADER_DATA _loader_data;
65
66 struct libresoc_instance *instance;
67
68 struct libresoc_device_extension_table supported_extensions;
69 struct libresoc_physical_device_dispatch_table dispatch;
70
71 /* FIXME: stub */
72 };
73
74 struct libresoc_app_info {
75 const char *app_name;
76 uint32_t app_version;
77 const char *engine_name;
78 uint32_t engine_version;
79 uint32_t api_version;
80 };
81
82 struct libresoc_instance {
83 struct vk_object_base base;
84 VK_LOADER_DATA _loader_data;
85
86 VkAllocationCallbacks alloc;
87
88 struct libresoc_app_info app_info;
89
90 struct libresoc_instance_extension_table enabled_extensions;
91 struct libresoc_instance_dispatch_table dispatch;
92 struct libresoc_device_dispatch_table device_dispatch;
93
94 int physical_device_count;
95 struct libresoc_physical_device physical_device;
96
97 struct vk_debug_report_instance debug_report_callbacks;
98 };
99
100 struct libresoc_queue {
101 VK_LOADER_DATA _loader_data;
102
103 struct libresoc_device *device;
104
105 VkDeviceQueueCreateFlags flags;
106
107 /* FIXME: stub */
108 };
109
110 struct libresoc_cmd_buffer {
111 VK_LOADER_DATA _loader_data;
112
113 struct libresoc_device *device;
114
115 /* FIXME: stub */
116 };
117
118 uint32_t libresoc_physical_device_api_version(struct libresoc_physical_device *dev);
119
120 int libresoc_get_instance_entrypoint_index(const char *name);
121 int libresoc_get_device_entrypoint_index(const char *name);
122 int libresoc_get_physical_device_entrypoint_index(const char *name);
123
124 const char *libresoc_get_instance_entry_name(int index);
125 const char *libresoc_get_physical_device_entry_name(int index);
126 const char *libresoc_get_device_entry_name(int index);
127
128 bool
129 libresoc_instance_entrypoint_is_enabled(int index, uint32_t core_version,
130 const struct libresoc_instance_extension_table *instance);
131 bool
132 libresoc_physical_device_entrypoint_is_enabled(int index, uint32_t core_version,
133 const struct libresoc_instance_extension_table *instance);
134 bool
135 libresoc_device_entrypoint_is_enabled(int index, uint32_t core_version,
136 const struct libresoc_instance_extension_table *instance,
137 const struct libresoc_device_extension_table *device);
138
139 void *libresoc_lookup_entrypoint(const char *name);
140
141 #define libresoc_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
142
143 VkResult __vk_errorf(struct libresoc_instance *instance, VkResult error,
144 const char *file, int line,
145 const char *format, ...);
146
147 #define vk_error(instance, error) __vk_errorf(instance, error, __FILE__, __LINE__, NULL);
148 #define vk_errorf(instance, error, format, ...) __vk_errorf(instance, error, __FILE__, __LINE__, format, ## __VA_ARGS__);
149
150 void libresoc_loge(const char *format, ...) libresoc_printflike(1, 2);
151 void libresoc_loge_v(const char *format, va_list va);
152
153 #define LIBRESOC_DEFINE_HANDLE_CASTS(__libresoc_type, __VkType) \
154 \
155 static inline struct __libresoc_type * \
156 __libresoc_type ## _from_handle(__VkType _handle) \
157 { \
158 return (struct __libresoc_type *) _handle; \
159 } \
160 \
161 static inline __VkType \
162 __libresoc_type ## _to_handle(struct __libresoc_type *_obj) \
163 { \
164 return (__VkType) _obj; \
165 }
166
167 #define LIBRESOC_FROM_HANDLE(__libresoc_type, __name, __handle) \
168 struct __libresoc_type *__name = __libresoc_type ## _from_handle(__handle)
169
170 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_cmd_buffer, VkCommandBuffer)
171 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_device, VkDevice)
172 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_instance, VkInstance)
173 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_physical_device, VkPhysicalDevice)
174 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_queue, VkQueue)
175
176
177 #endif /* LIBRESOC_PRIVATE_H */