shcore: Use CRT allocation functions.
[wine.git] / dlls / winevulkan / vulkan_private.h
blob9e43512580c1981a58c40da54ac50599225a599a
1 /* Wine Vulkan ICD private data structures
3 * Copyright 2017 Roderick Colenbrander
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #ifndef __WINE_VULKAN_PRIVATE_H
21 #define __WINE_VULKAN_PRIVATE_H
23 #define WINE_VK_HOST
24 #define VK_NO_PROTOTYPES
26 #include <pthread.h>
28 #include "vulkan_loader.h"
29 #include "vulkan_thunks.h"
31 /* Some extensions have callbacks for those we need to be able to
32 * get the wine wrapper for a native handle
34 struct wine_vk_mapping
36 struct list link;
37 uint64_t native_handle;
38 uint64_t wine_wrapped_handle;
41 struct wine_cmd_buffer
43 struct wine_device *device; /* parent */
45 VkCommandBuffer handle; /* client command buffer */
46 VkCommandBuffer command_buffer; /* native command buffer */
48 struct wine_vk_mapping mapping;
51 static inline struct wine_cmd_buffer *wine_cmd_buffer_from_handle(VkCommandBuffer handle)
53 return (struct wine_cmd_buffer *)(uintptr_t)handle->base.unix_handle;
56 struct wine_device
58 struct vulkan_device_funcs funcs;
59 struct wine_phys_dev *phys_dev; /* parent */
61 VkDevice handle; /* client device */
62 VkDevice device; /* native device */
64 struct wine_queue *queues;
65 uint32_t queue_count;
67 struct wine_vk_mapping mapping;
70 static inline struct wine_device *wine_device_from_handle(VkDevice handle)
72 return (struct wine_device *)(uintptr_t)handle->base.unix_handle;
75 struct wine_debug_utils_messenger;
77 struct wine_debug_report_callback
79 struct wine_instance *instance; /* parent */
80 VkDebugReportCallbackEXT debug_callback; /* native callback object */
82 /* application callback + data */
83 PFN_vkDebugReportCallbackEXT user_callback;
84 void *user_data;
86 struct wine_vk_mapping mapping;
89 struct wine_instance
91 struct vulkan_instance_funcs funcs;
93 VkInstance handle; /* client instance */
94 VkInstance instance; /* native instance */
96 /* We cache devices as we need to wrap them as they are
97 * dispatchable objects.
99 struct wine_phys_dev **phys_devs;
100 uint32_t phys_dev_count;
102 VkBool32 enable_wrapper_list;
103 struct list wrappers;
104 pthread_rwlock_t wrapper_lock;
106 struct wine_debug_utils_messenger *utils_messengers;
107 uint32_t utils_messenger_count;
109 struct wine_debug_report_callback default_callback;
111 unsigned int quirks;
113 struct wine_vk_mapping mapping;
116 static inline struct wine_instance *wine_instance_from_handle(VkInstance handle)
118 return (struct wine_instance *)(uintptr_t)handle->base.unix_handle;
121 struct wine_phys_dev
123 struct wine_instance *instance; /* parent */
125 VkPhysicalDevice handle; /* client physical device */
126 VkPhysicalDevice phys_dev; /* native physical device */
128 VkPhysicalDeviceMemoryProperties memory_properties;
129 VkExtensionProperties *extensions;
130 uint32_t extension_count;
132 uint32_t external_memory_align;
134 struct wine_vk_mapping mapping;
137 static inline struct wine_phys_dev *wine_phys_dev_from_handle(VkPhysicalDevice handle)
139 return (struct wine_phys_dev *)(uintptr_t)handle->base.unix_handle;
142 struct wine_queue
144 struct wine_device *device; /* parent */
146 VkQueue handle; /* client queue */
147 VkQueue queue; /* native queue */
149 uint32_t family_index;
150 uint32_t queue_index;
151 VkDeviceQueueCreateFlags flags;
153 struct wine_vk_mapping mapping;
156 static inline struct wine_queue *wine_queue_from_handle(VkQueue handle)
158 return (struct wine_queue *)(uintptr_t)handle->base.unix_handle;
161 struct wine_cmd_pool
163 VkCommandPool handle;
164 VkCommandPool command_pool;
166 struct wine_vk_mapping mapping;
169 static inline struct wine_cmd_pool *wine_cmd_pool_from_handle(VkCommandPool handle)
171 struct vk_command_pool *client_ptr = command_pool_from_handle(handle);
172 return (struct wine_cmd_pool *)(uintptr_t)client_ptr->unix_handle;
175 struct wine_device_memory
177 VkDeviceMemory memory;
178 void *mapping;
181 static inline struct wine_device_memory *wine_device_memory_from_handle(VkDeviceMemory handle)
183 return (struct wine_device_memory *)(uintptr_t)handle;
186 struct wine_debug_utils_messenger
188 struct wine_instance *instance; /* parent */
189 VkDebugUtilsMessengerEXT debug_messenger; /* native messenger */
191 /* application callback + data */
192 PFN_vkDebugUtilsMessengerCallbackEXT user_callback;
193 void *user_data;
195 struct wine_vk_mapping mapping;
198 static inline struct wine_debug_utils_messenger *wine_debug_utils_messenger_from_handle(
199 VkDebugUtilsMessengerEXT handle)
201 return (struct wine_debug_utils_messenger *)(uintptr_t)handle;
204 static inline VkDebugUtilsMessengerEXT wine_debug_utils_messenger_to_handle(
205 struct wine_debug_utils_messenger *debug_messenger)
207 return (VkDebugUtilsMessengerEXT)(uintptr_t)debug_messenger;
210 static inline struct wine_debug_report_callback *wine_debug_report_callback_from_handle(
211 VkDebugReportCallbackEXT handle)
213 return (struct wine_debug_report_callback *)(uintptr_t)handle;
216 static inline VkDebugReportCallbackEXT wine_debug_report_callback_to_handle(
217 struct wine_debug_report_callback *debug_messenger)
219 return (VkDebugReportCallbackEXT)(uintptr_t)debug_messenger;
222 struct wine_surface
224 VkSurfaceKHR surface; /* native surface */
225 VkSurfaceKHR driver_surface; /* wine driver surface */
227 struct wine_vk_mapping mapping;
230 static inline struct wine_surface *wine_surface_from_handle(VkSurfaceKHR handle)
232 return (struct wine_surface *)(uintptr_t)handle;
235 static inline VkSurfaceKHR wine_surface_to_handle(struct wine_surface *surface)
237 return (VkSurfaceKHR)(uintptr_t)surface;
240 BOOL wine_vk_device_extension_supported(const char *name) DECLSPEC_HIDDEN;
241 BOOL wine_vk_instance_extension_supported(const char *name) DECLSPEC_HIDDEN;
243 BOOL wine_vk_is_type_wrapped(VkObjectType type) DECLSPEC_HIDDEN;
245 NTSTATUS init_vulkan(void *args) DECLSPEC_HIDDEN;
247 NTSTATUS vk_is_available_instance_function(void *arg) DECLSPEC_HIDDEN;
248 NTSTATUS vk_is_available_device_function(void *arg) DECLSPEC_HIDDEN;
249 NTSTATUS vk_is_available_instance_function32(void *arg) DECLSPEC_HIDDEN;
250 NTSTATUS vk_is_available_device_function32(void *arg) DECLSPEC_HIDDEN;
252 struct conversion_context
254 char buffer[2048];
255 uint32_t used;
256 struct list alloc_entries;
259 static inline void init_conversion_context(struct conversion_context *pool)
261 pool->used = 0;
262 list_init(&pool->alloc_entries);
265 static inline void free_conversion_context(struct conversion_context *pool)
267 struct list *entry, *next;
268 LIST_FOR_EACH_SAFE(entry, next, &pool->alloc_entries)
269 free(entry);
272 static inline void *conversion_context_alloc(struct conversion_context *pool, size_t size)
274 if (pool->used + size <= sizeof(pool->buffer))
276 void *ret = pool->buffer + pool->used;
277 pool->used += (size + sizeof(UINT64) - 1) & ~(sizeof(UINT64) - 1);
278 return ret;
280 else
282 struct list *entry;
283 if (!(entry = malloc(sizeof(*entry) + size)))
284 return NULL;
285 list_add_tail(&pool->alloc_entries, entry);
286 return entry + 1;
290 struct wine_deferred_operation
292 VkDeferredOperationKHR deferred_operation; /* native handle */
294 struct conversion_context ctx; /* to keep params alive. */
296 struct wine_vk_mapping mapping;
299 static inline struct wine_deferred_operation *wine_deferred_operation_from_handle(
300 VkDeferredOperationKHR handle)
302 return (struct wine_deferred_operation *)(uintptr_t)handle;
305 static inline VkDeferredOperationKHR wine_deferred_operation_to_handle(
306 struct wine_deferred_operation *deferred_operation)
308 return (VkDeferredOperationKHR)(uintptr_t)deferred_operation;
311 typedef UINT32 PTR32;
313 typedef struct
315 VkStructureType sType;
316 PTR32 pNext;
317 } VkBaseInStructure32;
319 typedef struct
321 VkStructureType sType;
322 PTR32 pNext;
323 } VkBaseOutStructure32;
325 static inline void *find_next_struct32(void *s, VkStructureType t)
327 VkBaseOutStructure32 *header;
329 for (header = s; header; header = UlongToPtr(header->pNext))
331 if (header->sType == t)
332 return header;
335 return NULL;
338 static inline void *find_next_struct(const void *s, VkStructureType t)
340 VkBaseOutStructure *header;
342 for (header = (VkBaseOutStructure *)s; header; header = header->pNext)
344 if (header->sType == t)
345 return header;
348 return NULL;
351 #endif /* __WINE_VULKAN_PRIVATE_H */