2 * Copyright © 2019 Raspberry Pi
4 * based in part on anv driver which is:
5 * Copyright © 2015 Intel Corporation
7 * based in part on libresoc driver which is:
8 * Copyright © 2016 Red Hat.
9 * Copyright © 2016 Bas Nieuwenhuizen
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:
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
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
30 #ifndef LIBRESOC_PRIVATE_H
31 #define LIBRESOC_PRIVATE_H
35 #include <vulkan/vulkan.h>
36 #include <vulkan/vk_icd.h>
39 #include "vk_debug_report.h"
40 #include "util/xmlconfig.h"
41 #include "compiler/shader_enums.h"
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"
49 #define LIBRESOC_MAX_QUEUE_FAMILIES 1
50 struct libresoc_instance
;
51 struct libresoc_device
;
54 struct libresoc_pipeline_cache
{
55 struct vk_object_base base
;
56 struct libresoc_device
* device
;
57 pthread_mutex_t mutex
;
58 VkPipelineCacheCreateFlags flags
;
62 uint32_t kernel_count
;
63 struct cache_entry
** hash_table
;
66 VkAllocationCallbacks alloc
;
70 struct libresoc_shader_binary
;
71 struct libresoc_shader_variant
;
74 libresoc_pipeline_cache_init(struct libresoc_pipeline_cache
*cache
,
75 struct libresoc_device
*device
);
77 libresoc_pipeline_cache_finish(struct libresoc_pipeline_cache
*cache
);
79 libresoc_pipeline_cache_load(struct libresoc_pipeline_cache
*cache
,
80 const void *data
, size_t size
);
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
);
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
{
98 VkAllocationCallbacks alloc
;
100 struct libresoc_instance
*instance
;
102 struct libresoc_device_extension_table enabled_extensions
;
103 struct libresoc_device_dispatch_table dispatch
;
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
;
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
;
119 struct libresoc_physical_device
{
120 VK_LOADER_DATA _loader_data
;
122 struct list_head link
;
123 struct libresoc_instance
*instance
;
125 struct libresoc_device_extension_table supported_extensions
;
126 struct libresoc_physical_device_dispatch_table dispatch
;
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
];
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
;
143 struct libresoc_instance
{
144 struct vk_object_base base
;
146 VkAllocationCallbacks alloc
;
150 uint64_t debug_flags
;
152 uint32_t engineVersion
;
153 struct libresoc_app_info app_info
;
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
;
163 struct vk_debug_report_instance debug_report_callbacks
;
166 struct libresoc_queue
{
167 VK_LOADER_DATA _loader_data
;
169 struct libresoc_device
*device
;
171 uint32_t queue_family_index
;
173 VkDeviceQueueCreateFlags flags
;
175 struct list_head pending_submissions
;
176 pthread_mutex_t pending_mutex
;
180 struct libresoc_cmd_buffer
{
182 struct libresoc_device
*device
;
187 uint32_t libresoc_physical_device_api_version(struct libresoc_physical_device
*dev
);
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
);
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
);
198 libresoc_instance_entrypoint_is_enabled(int index
, uint32_t core_version
,
199 const struct libresoc_instance_extension_table
*instance
);
201 libresoc_physical_device_entrypoint_is_enabled(int index
, uint32_t core_version
,
202 const struct libresoc_instance_extension_table
*instance
);
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
);
208 void *libresoc_lookup_entrypoint(const char *name
);
211 libresoc_get_debug_option_name(int id
);
213 #define libresoc_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
215 VkResult
__vk_errorf(struct libresoc_instance
*instance
, VkResult error
,
216 const char *file
, int line
,
217 const char *format
, ...);
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__);
222 void libresoc_loge(const char *format
, ...) libresoc_printflike(1, 2);
223 void libresoc_loge_v(const char *format
, va_list va
);
225 #define LIBRESOC_DEFINE_HANDLE_CASTS(__libresoc_type, __VkType) \
227 static inline struct __libresoc_type * \
228 __libresoc_type ## _from_handle(__VkType _handle) \
230 return (struct __libresoc_type *) _handle; \
233 static inline __VkType \
234 __libresoc_type ## _to_handle(struct __libresoc_type *_obj) \
236 return (__VkType) _obj; \
239 #define LIBRESOC_DEFINE_NONDISP_HANDLE_CASTS(__libresoc_type, __VkType) \
241 static inline struct __libresoc_type * \
242 __libresoc_type ## _from_handle(__VkType _handle) \
244 return (struct __libresoc_type *)(uintptr_t) _handle; \
247 static inline __VkType \
248 __libresoc_type ## _to_handle(struct __libresoc_type *_obj) \
250 return (__VkType)(uintptr_t) _obj; \
253 #define LIBRESOC_FROM_HANDLE(__libresoc_type, __name, __handle) \
254 struct __libresoc_type *__name = __libresoc_type ## _from_handle(__handle)
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
)
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)
285 #endif /* LIBRESOC_PRIVATE_H */