Implement libresoc_DeviceWaitIdle() libresoc_QueueWaitIdle().
[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_alloc.h"
39 #include "vk_debug_report.h"
40 #include "util/xmlconfig.h"
41 #include "compiler/shader_enums.h"
42
43 #include "vk_object.h"
44 #include "libresoc_entrypoints.h"
45 #include "libresoc_extensions.h"
46 #include "libresoc_constants.h"
47 #include "libresoc_debug.h"
48
49 #define LIBRESOC_MAX_QUEUE_FAMILIES 1
50 struct libresoc_instance;
51 struct libresoc_device;
52 struct cache_entry;
53
54 struct libresoc_pipeline_cache {
55 struct vk_object_base base;
56 struct libresoc_device * device;
57 pthread_mutex_t mutex;
58 VkPipelineCacheCreateFlags flags;
59
60 uint32_t total_size;
61 uint32_t table_size;
62 uint32_t kernel_count;
63 struct cache_entry ** hash_table;
64 bool modified;
65
66 VkAllocationCallbacks alloc;
67 };
68
69
70 struct libresoc_shader_binary;
71 struct libresoc_shader_variant;
72
73 void
74 libresoc_pipeline_cache_init(struct libresoc_pipeline_cache *cache,
75 struct libresoc_device *device);
76 void
77 libresoc_pipeline_cache_finish(struct libresoc_pipeline_cache *cache);
78 bool
79 libresoc_pipeline_cache_load(struct libresoc_pipeline_cache *cache,
80 const void *data, size_t size);
81
82 bool
83 libresoc_create_shader_variants_from_pipeline_cache(struct libresoc_device *device,
84 struct libresoc_pipeline_cache *cache,
85 const unsigned char *sha1,
86 struct libresoc_shader_variant **variants,
87 bool *found_in_application_cache);
88
89 void
90 libresoc_pipeline_cache_insert_shaders(struct libresoc_device *device,
91 struct libresoc_pipeline_cache *cache,
92 const unsigned char *sha1,
93 struct libresoc_shader_variant **variants,
94 struct libresoc_shader_binary *const *binaries);
95 struct libresoc_device {
96
97 struct vk_device vk;
98 VkAllocationCallbacks alloc;
99
100 struct libresoc_instance *instance;
101
102 struct libresoc_device_extension_table enabled_extensions;
103 struct libresoc_device_dispatch_table dispatch;
104
105 struct libresoc_queue *queues[LIBRESOC_MAX_QUEUE_FAMILIES];
106 int queue_count[LIBRESOC_MAX_QUEUE_FAMILIES];
107 struct radeon_cmdbuf *empty_cs[LIBRESOC_MAX_QUEUE_FAMILIES];
108 struct libresoc_physical_device *physical_device;
109
110 /* Backup in-memory cache to be used if the app doesn't provide one */
111 struct libresoc_pipeline_cache * mem_cache;
112 /* Condition variable for legacy timelines, to notify waiters when a
113 * new point gets submitted. */
114 pthread_cond_t timeline_cond;
115 /* FIXME: stub */
116 };
117
118
119 struct libresoc_physical_device {
120 VK_LOADER_DATA _loader_data;
121
122 struct list_head link;
123 struct libresoc_instance *instance;
124
125 struct libresoc_device_extension_table supported_extensions;
126 struct libresoc_physical_device_dispatch_table dispatch;
127
128 char name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE];
129 uint8_t driver_uuid[VK_UUID_SIZE];
130 uint8_t device_uuid[VK_UUID_SIZE];
131 uint8_t cache_uuid[VK_UUID_SIZE];
132 /* FIXME: stub */
133 };
134
135 struct libresoc_app_info {
136 const char *app_name;
137 uint32_t app_version;
138 const char *engine_name;
139 uint32_t engine_version;
140 uint32_t api_version;
141 };
142
143 struct libresoc_instance {
144 struct vk_object_base base;
145
146 VkAllocationCallbacks alloc;
147
148 uint32_t apiVersion;
149
150 uint64_t debug_flags;
151 char * engineName;
152 uint32_t engineVersion;
153 struct libresoc_app_info app_info;
154
155 bool physical_devices_enumerated;
156 struct libresoc_instance_extension_table enabled_extensions;
157 struct libresoc_instance_dispatch_table dispatch;
158 struct libresoc_device_dispatch_table device_dispatch;
159 struct libresoc_physical_device_dispatch_table physical_device_dispatch;
160 int physical_device_count;
161 struct list_head physical_devices;
162
163 struct vk_debug_report_instance debug_report_callbacks;
164 };
165
166 struct libresoc_queue {
167 VK_LOADER_DATA _loader_data;
168
169 struct libresoc_device *device;
170
171 uint32_t queue_family_index;
172 int queue_idx;
173 VkDeviceQueueCreateFlags flags;
174
175 struct list_head pending_submissions;
176 pthread_mutex_t pending_mutex;
177 /* FIXME: stub */
178 };
179
180 struct libresoc_cmd_buffer {
181
182 struct libresoc_device *device;
183
184 /* FIXME: stub */
185 };
186
187 uint32_t libresoc_physical_device_api_version(struct libresoc_physical_device *dev);
188
189 int libresoc_get_instance_entrypoint_index(const char *name);
190 int libresoc_get_device_entrypoint_index(const char *name);
191 int libresoc_get_physical_device_entrypoint_index(const char *name);
192
193 const char *libresoc_get_instance_entry_name(int index);
194 const char *libresoc_get_physical_device_entry_name(int index);
195 const char *libresoc_get_device_entry_name(int index);
196
197 bool
198 libresoc_instance_entrypoint_is_enabled(int index, uint32_t core_version,
199 const struct libresoc_instance_extension_table *instance);
200 bool
201 libresoc_physical_device_entrypoint_is_enabled(int index, uint32_t core_version,
202 const struct libresoc_instance_extension_table *instance);
203 bool
204 libresoc_device_entrypoint_is_enabled(int index, uint32_t core_version,
205 const struct libresoc_instance_extension_table *instance,
206 const struct libresoc_device_extension_table *device);
207
208 void *libresoc_lookup_entrypoint(const char *name);
209
210 const char *
211 libresoc_get_debug_option_name(int id);
212
213 #define libresoc_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
214
215 VkResult __vk_errorf(struct libresoc_instance *instance, VkResult error,
216 const char *file, int line,
217 const char *format, ...);
218
219 #define vk_error(instance, error) __vk_errorf(instance, error, __FILE__, __LINE__, NULL);
220 #define vk_errorf(instance, error, format, ...) __vk_errorf(instance, error, __FILE__, __LINE__, format, ## __VA_ARGS__);
221
222 void libresoc_loge(const char *format, ...) libresoc_printflike(1, 2);
223 void libresoc_loge_v(const char *format, va_list va);
224
225 #define LIBRESOC_DEFINE_HANDLE_CASTS(__libresoc_type, __VkType) \
226 \
227 static inline struct __libresoc_type * \
228 __libresoc_type ## _from_handle(__VkType _handle) \
229 { \
230 return (struct __libresoc_type *) _handle; \
231 } \
232 \
233 static inline __VkType \
234 __libresoc_type ## _to_handle(struct __libresoc_type *_obj) \
235 { \
236 return (__VkType) _obj; \
237 }
238
239 #define LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(__libresoc_type, __VkType) \
240 \
241 static inline struct __libresoc_type * \
242 __libresoc_type ## _from_handle(__VkType _handle) \
243 { \
244 return (struct __libresoc_type *)(uintptr_t) _handle; \
245 } \
246 \
247 static inline __VkType \
248 __libresoc_type ## _to_handle(struct __libresoc_type *_obj) \
249 { \
250 return (__VkType)(uintptr_t) _obj; \
251 }
252
253 #define LIBRESOC_FROM_HANDLE(__libresoc_type, __name, __handle) \
254 struct __libresoc_type *__name = __libresoc_type ## _from_handle(__handle)
255
256 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_cmd_buffer, VkCommandBuffer)
257 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_device, VkDevice)
258 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_instance, VkInstance)
259 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_physical_device, VkPhysicalDevice)
260 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_queue, VkQueue)
261
262 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_cmd_pool, VkCommandPool)
263 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_buffer, VkBuffer)
264 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_buffer_view, VkBufferView)
265 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_descriptor_pool, VkDescriptorPool)
266 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_descriptor_set, VkDescriptorSet)
267 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_descriptor_set_layout, VkDescriptorSetLayout)
268 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_descriptor_update_template, VkDescriptorUpdateTemplate)
269 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_device_memory, VkDeviceMemory)
270 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_fence, VkFence)
271 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_event, VkEvent)
272 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_framebuffer, VkFramebuffer)
273 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_image, VkImage)
274 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_image_view, VkImageView);
275 LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_pipeline_cache, VkPipelineCache)
276 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_pipeline, VkPipeline)
277 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_pipeline_layout, VkPipelineLayout)
278 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_query_pool, VkQueryPool)
279 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_render_pass, VkRenderPass)
280 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_sampler, VkSampler)
281 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_sampler_ycbcr_conversion, VkSamplerYcbcrConversion)
282 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_shader_module, VkShaderModule)
283 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_semaphore, VkSemaphore)
284
285 #endif /* LIBRESOC_PRIVATE_H */