Implement GetDeviceQueue()
[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 /* FIXME: stub */
113 };
114
115
116 struct libresoc_physical_device {
117 VK_LOADER_DATA _loader_data;
118
119 struct list_head link;
120 struct libresoc_instance *instance;
121
122 struct libresoc_device_extension_table supported_extensions;
123 struct libresoc_physical_device_dispatch_table dispatch;
124
125 char name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE];
126 uint8_t driver_uuid[VK_UUID_SIZE];
127 uint8_t device_uuid[VK_UUID_SIZE];
128 uint8_t cache_uuid[VK_UUID_SIZE];
129 /* FIXME: stub */
130 };
131
132 struct libresoc_app_info {
133 const char *app_name;
134 uint32_t app_version;
135 const char *engine_name;
136 uint32_t engine_version;
137 uint32_t api_version;
138 };
139
140 struct libresoc_instance {
141 struct vk_object_base base;
142
143 VkAllocationCallbacks alloc;
144
145 uint32_t apiVersion;
146
147 uint64_t debug_flags;
148 char * engineName;
149 uint32_t engineVersion;
150 struct libresoc_app_info app_info;
151
152 bool physical_devices_enumerated;
153 struct libresoc_instance_extension_table enabled_extensions;
154 struct libresoc_instance_dispatch_table dispatch;
155 struct libresoc_device_dispatch_table device_dispatch;
156 struct libresoc_physical_device_dispatch_table physical_device_dispatch;
157 int physical_device_count;
158 struct list_head physical_devices;
159
160 struct vk_debug_report_instance debug_report_callbacks;
161 };
162
163 struct libresoc_queue {
164 VK_LOADER_DATA _loader_data;
165
166 struct libresoc_device *device;
167
168 uint32_t queue_family_index;
169 int queue_idx;
170 VkDeviceQueueCreateFlags flags;
171
172 /* FIXME: stub */
173 };
174
175 struct libresoc_cmd_buffer {
176
177 struct libresoc_device *device;
178
179 /* FIXME: stub */
180 };
181
182 uint32_t libresoc_physical_device_api_version(struct libresoc_physical_device *dev);
183
184 int libresoc_get_instance_entrypoint_index(const char *name);
185 int libresoc_get_device_entrypoint_index(const char *name);
186 int libresoc_get_physical_device_entrypoint_index(const char *name);
187
188 const char *libresoc_get_instance_entry_name(int index);
189 const char *libresoc_get_physical_device_entry_name(int index);
190 const char *libresoc_get_device_entry_name(int index);
191
192 bool
193 libresoc_instance_entrypoint_is_enabled(int index, uint32_t core_version,
194 const struct libresoc_instance_extension_table *instance);
195 bool
196 libresoc_physical_device_entrypoint_is_enabled(int index, uint32_t core_version,
197 const struct libresoc_instance_extension_table *instance);
198 bool
199 libresoc_device_entrypoint_is_enabled(int index, uint32_t core_version,
200 const struct libresoc_instance_extension_table *instance,
201 const struct libresoc_device_extension_table *device);
202
203 void *libresoc_lookup_entrypoint(const char *name);
204
205 const char *
206 libresoc_get_debug_option_name(int id);
207
208 #define libresoc_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
209
210 VkResult __vk_errorf(struct libresoc_instance *instance, VkResult error,
211 const char *file, int line,
212 const char *format, ...);
213
214 #define vk_error(instance, error) __vk_errorf(instance, error, __FILE__, __LINE__, NULL);
215 #define vk_errorf(instance, error, format, ...) __vk_errorf(instance, error, __FILE__, __LINE__, format, ## __VA_ARGS__);
216
217 void libresoc_loge(const char *format, ...) libresoc_printflike(1, 2);
218 void libresoc_loge_v(const char *format, va_list va);
219
220 #define LIBRESOC_DEFINE_HANDLE_CASTS(__libresoc_type, __VkType) \
221 \
222 static inline struct __libresoc_type * \
223 __libresoc_type ## _from_handle(__VkType _handle) \
224 { \
225 return (struct __libresoc_type *) _handle; \
226 } \
227 \
228 static inline __VkType \
229 __libresoc_type ## _to_handle(struct __libresoc_type *_obj) \
230 { \
231 return (__VkType) _obj; \
232 }
233
234 #define LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(__libresoc_type, __VkType) \
235 \
236 static inline struct __libresoc_type * \
237 __libresoc_type ## _from_handle(__VkType _handle) \
238 { \
239 return (struct __libresoc_type *)(uintptr_t) _handle; \
240 } \
241 \
242 static inline __VkType \
243 __libresoc_type ## _to_handle(struct __libresoc_type *_obj) \
244 { \
245 return (__VkType)(uintptr_t) _obj; \
246 }
247
248 #define LIBRESOC_FROM_HANDLE(__libresoc_type, __name, __handle) \
249 struct __libresoc_type *__name = __libresoc_type ## _from_handle(__handle)
250
251 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_cmd_buffer, VkCommandBuffer)
252 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_device, VkDevice)
253 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_instance, VkInstance)
254 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_physical_device, VkPhysicalDevice)
255 LIBRESOC_DEFINE_HANDLE_CASTS(libresoc_queue, VkQueue)
256
257 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_cmd_pool, VkCommandPool)
258 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_buffer, VkBuffer)
259 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_buffer_view, VkBufferView)
260 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_descriptor_pool, VkDescriptorPool)
261 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_descriptor_set, VkDescriptorSet)
262 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_descriptor_set_layout, VkDescriptorSetLayout)
263 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_descriptor_update_template, VkDescriptorUpdateTemplate)
264 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_device_memory, VkDeviceMemory)
265 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_fence, VkFence)
266 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_event, VkEvent)
267 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_framebuffer, VkFramebuffer)
268 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_image, VkImage)
269 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_image_view, VkImageView);
270 LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_pipeline_cache, VkPipelineCache)
271 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_pipeline, VkPipeline)
272 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_pipeline_layout, VkPipelineLayout)
273 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_query_pool, VkQueryPool)
274 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_render_pass, VkRenderPass)
275 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_sampler, VkSampler)
276 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_sampler_ycbcr_conversion, VkSamplerYcbcrConversion)
277 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_shader_module, VkShaderModule)
278 //LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(libresoc_semaphore, VkSemaphore)
279
280 #endif /* LIBRESOC_PRIVATE_H */