vulkan/wsi: use function ptr definitions from the spec.
[mesa.git] / src / vulkan / wsi / wsi_common.h
1 /*
2 * Copyright © 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23 #ifndef WSI_COMMON_H
24 #define WSI_COMMON_H
25
26 #include <stdint.h>
27 #include <stdbool.h>
28
29 #include "vk_alloc.h"
30 #include <vulkan/vulkan.h>
31 #include <vulkan/vk_icd.h>
32
33 struct wsi_device;
34 struct wsi_image_fns {
35 VkResult (*create_wsi_image)(VkDevice device_h,
36 const VkSwapchainCreateInfoKHR *pCreateInfo,
37 const VkAllocationCallbacks *pAllocator,
38 bool needs_linear_copy,
39 bool linear,
40 VkImage *image_p,
41 VkDeviceMemory *memory_p,
42 uint32_t *size_p,
43 uint32_t *offset_p,
44 uint32_t *row_pitch_p,
45 int *fd_p);
46 void (*free_wsi_image)(VkDevice device,
47 const VkAllocationCallbacks *pAllocator,
48 VkImage image_h,
49 VkDeviceMemory memory_h);
50 };
51
52 struct wsi_swapchain {
53
54 VkDevice device;
55 VkAllocationCallbacks alloc;
56 const struct wsi_image_fns *image_fns;
57 VkFence fences[3];
58 VkCommandBuffer *cmd_buffers;
59 VkCommandPool cmd_pools[3];
60 VkPresentModeKHR present_mode;
61 uint32_t image_count;
62 bool needs_linear_copy;
63
64 VkResult (*destroy)(struct wsi_swapchain *swapchain,
65 const VkAllocationCallbacks *pAllocator);
66 VkResult (*get_images)(struct wsi_swapchain *swapchain,
67 uint32_t *pCount, VkImage *pSwapchainImages);
68 VkResult (*acquire_next_image)(struct wsi_swapchain *swap_chain,
69 uint64_t timeout, VkSemaphore semaphore,
70 uint32_t *image_index);
71 VkResult (*queue_present)(struct wsi_swapchain *swap_chain,
72 uint32_t image_index,
73 const VkPresentRegionKHR *damage);
74 void (*get_image_and_linear)(struct wsi_swapchain *swapchain,
75 int imageIndex,
76 VkImage *image,
77 VkImage *linear_image);
78 };
79
80 struct wsi_interface {
81 VkResult (*get_support)(VkIcdSurfaceBase *surface,
82 struct wsi_device *wsi_device,
83 const VkAllocationCallbacks *alloc,
84 uint32_t queueFamilyIndex,
85 int local_fd,
86 bool can_handle_different_gpu,
87 VkBool32* pSupported);
88 VkResult (*get_capabilities)(VkIcdSurfaceBase *surface,
89 VkSurfaceCapabilitiesKHR* pSurfaceCapabilities);
90 VkResult (*get_capabilities2)(VkIcdSurfaceBase *surface,
91 const void *info_next,
92 VkSurfaceCapabilities2KHR* pSurfaceCapabilities);
93 VkResult (*get_formats)(VkIcdSurfaceBase *surface,
94 struct wsi_device *wsi_device,
95 uint32_t* pSurfaceFormatCount,
96 VkSurfaceFormatKHR* pSurfaceFormats);
97 VkResult (*get_formats2)(VkIcdSurfaceBase *surface,
98 struct wsi_device *wsi_device,
99 const void *info_next,
100 uint32_t* pSurfaceFormatCount,
101 VkSurfaceFormat2KHR* pSurfaceFormats);
102 VkResult (*get_present_modes)(VkIcdSurfaceBase *surface,
103 uint32_t* pPresentModeCount,
104 VkPresentModeKHR* pPresentModes);
105 VkResult (*create_swapchain)(VkIcdSurfaceBase *surface,
106 VkDevice device,
107 struct wsi_device *wsi_device,
108 int local_fd,
109 const VkSwapchainCreateInfoKHR* pCreateInfo,
110 const VkAllocationCallbacks* pAllocator,
111 const struct wsi_image_fns *image_fns,
112 struct wsi_swapchain **swapchain);
113 };
114
115 #define VK_ICD_WSI_PLATFORM_MAX 5
116
117 struct wsi_device {
118 struct wsi_interface * wsi[VK_ICD_WSI_PLATFORM_MAX];
119 };
120
121 #define WSI_CB(cb) PFN_vk##cb cb
122 struct wsi_callbacks {
123 WSI_CB(GetPhysicalDeviceFormatProperties);
124 };
125 #undef WSI_CB
126
127 #define WSI_DEFINE_NONDISP_HANDLE_CASTS(__wsi_type, __VkType) \
128 \
129 static inline struct __wsi_type * \
130 __wsi_type ## _from_handle(__VkType _handle) \
131 { \
132 return (struct __wsi_type *)(uintptr_t) _handle; \
133 } \
134 \
135 static inline __VkType \
136 __wsi_type ## _to_handle(struct __wsi_type *_obj) \
137 { \
138 return (__VkType)(uintptr_t) _obj; \
139 }
140
141 WSI_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain, VkSwapchainKHR)
142
143 #define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \
144 \
145 static inline __VkIcdType * \
146 __VkIcdType ## _from_handle(__VkType _handle) \
147 { \
148 return (__VkIcdType *)(uintptr_t) _handle; \
149 } \
150 \
151 static inline __VkType \
152 __VkIcdType ## _to_handle(__VkIcdType *_obj) \
153 { \
154 return (__VkType)(uintptr_t) _obj; \
155 }
156
157 #define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
158 __VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
159
160 ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase, VkSurfaceKHR)
161
162 VkResult wsi_x11_init_wsi(struct wsi_device *wsi_device,
163 const VkAllocationCallbacks *alloc);
164 void wsi_x11_finish_wsi(struct wsi_device *wsi_device,
165 const VkAllocationCallbacks *alloc);
166 VkResult wsi_wl_init_wsi(struct wsi_device *wsi_device,
167 const VkAllocationCallbacks *alloc,
168 VkPhysicalDevice physical_device,
169 const struct wsi_callbacks *cbs);
170 void wsi_wl_finish_wsi(struct wsi_device *wsi_device,
171 const VkAllocationCallbacks *alloc);
172
173
174 #endif