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