vulkan/wsi: Add a hooks for signaling semaphores and fences
[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 /* This is guaranteed to not collide with anything because it's in the
34 * VK_KHR_swapchain namespace but not actually used by the extension.
35 */
36 #define VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA (VkStructureType)1000001002
37 #define VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA (VkStructureType)1000001003
38 #define VK_STRUCTURE_TYPE_WSI_FORMAT_MODIFIER_PROPERTIES_LIST_MESA (VkStructureType)1000001004
39 #define VK_STRUCTURE_TYPE_WSI_SURFACE_SUPPORTED_COUNTERS_MESA (VkStructureType)1000001005
40 #define VK_STRUCTURE_TYPE_WSI_MEMORY_SIGNAL_SUBMIT_INFO_MESA (VkStructureType)1000001006
41
42 struct wsi_image_create_info {
43 VkStructureType sType;
44 const void *pNext;
45 bool scanout;
46
47 uint32_t modifier_count;
48 const uint64_t *modifiers;
49 };
50
51 struct wsi_memory_allocate_info {
52 VkStructureType sType;
53 const void *pNext;
54 bool implicit_sync;
55 };
56
57 struct wsi_format_modifier_properties {
58 uint64_t modifier;
59 uint32_t modifier_plane_count;
60 };
61
62 /* Chain in for vkGetPhysicalDeviceFormatProperties2KHR */
63 struct wsi_format_modifier_properties_list {
64 VkStructureType sType;
65 const void *pNext;
66
67 uint32_t modifier_count;
68 struct wsi_format_modifier_properties *modifier_properties;
69 };
70
71 /* To be chained into VkSurfaceCapabilities2KHR */
72 struct wsi_surface_supported_counters {
73 VkStructureType sType;
74 const void *pNext;
75
76 VkSurfaceCounterFlagsEXT supported_surface_counters;
77
78 };
79
80 /* To be chained into VkSubmitInfo */
81 struct wsi_memory_signal_submit_info {
82 VkStructureType sType;
83 const void *pNext;
84 VkDeviceMemory memory;
85 };
86
87 struct wsi_fence {
88 VkDevice device;
89 const struct wsi_device *wsi_device;
90 VkDisplayKHR display;
91 const VkAllocationCallbacks *alloc;
92 VkResult (*wait)(struct wsi_fence *fence, uint64_t abs_timeout);
93 void (*destroy)(struct wsi_fence *fence);
94 };
95
96 struct wsi_interface;
97
98 struct driOptionCache;
99
100 #define VK_ICD_WSI_PLATFORM_MAX (VK_ICD_WSI_PLATFORM_DISPLAY + 1)
101
102 struct wsi_device {
103 /* Allocator for the instance */
104 VkAllocationCallbacks instance_alloc;
105
106 VkPhysicalDevice pdevice;
107 VkPhysicalDeviceMemoryProperties memory_props;
108 uint32_t queue_family_count;
109
110 VkPhysicalDevicePCIBusInfoPropertiesEXT pci_bus_info;
111
112 bool supports_modifiers;
113 uint32_t maxImageDimension2D;
114 VkPresentModeKHR override_present_mode;
115
116 /* Whether to enable adaptive sync for a swapchain if implemented and
117 * available. Not all window systems might support this. */
118 bool enable_adaptive_sync;
119
120 struct {
121 /* Override the minimum number of images on the swapchain.
122 * 0 = no override */
123 uint32_t override_minImageCount;
124
125 /* Forces strict number of image on the swapchain using application
126 * provided VkSwapchainCreateInfoKH::RminImageCount.
127 */
128 bool strict_imageCount;
129 } x11;
130
131 uint64_t (*image_get_modifier)(VkImage image);
132
133 /* Signals the semaphore such that any wait on the semaphore will wait on
134 * any reads or writes on the give memory object. This is used to
135 * implement the semaphore signal operation in vkAcquireNextImage.
136 */
137 void (*signal_semaphore_for_memory)(VkDevice device,
138 VkSemaphore semaphore,
139 VkDeviceMemory memory);
140
141 /* Signals the fence such that any wait on the fence will wait on any reads
142 * or writes on the give memory object. This is used to implement the
143 * semaphore signal operation in vkAcquireNextImage.
144 */
145 void (*signal_fence_for_memory)(VkDevice device,
146 VkFence fence,
147 VkDeviceMemory memory);
148
149 #define WSI_CB(cb) PFN_vk##cb cb
150 WSI_CB(AllocateMemory);
151 WSI_CB(AllocateCommandBuffers);
152 WSI_CB(BindBufferMemory);
153 WSI_CB(BindImageMemory);
154 WSI_CB(BeginCommandBuffer);
155 WSI_CB(CmdCopyImageToBuffer);
156 WSI_CB(CreateBuffer);
157 WSI_CB(CreateCommandPool);
158 WSI_CB(CreateFence);
159 WSI_CB(CreateImage);
160 WSI_CB(DestroyBuffer);
161 WSI_CB(DestroyCommandPool);
162 WSI_CB(DestroyFence);
163 WSI_CB(DestroyImage);
164 WSI_CB(EndCommandBuffer);
165 WSI_CB(FreeMemory);
166 WSI_CB(FreeCommandBuffers);
167 WSI_CB(GetBufferMemoryRequirements);
168 WSI_CB(GetImageMemoryRequirements);
169 WSI_CB(GetImageSubresourceLayout);
170 WSI_CB(GetMemoryFdKHR);
171 WSI_CB(GetPhysicalDeviceFormatProperties);
172 WSI_CB(GetPhysicalDeviceFormatProperties2KHR);
173 WSI_CB(ResetFences);
174 WSI_CB(QueueSubmit);
175 WSI_CB(WaitForFences);
176 #undef WSI_CB
177
178 struct wsi_interface * wsi[VK_ICD_WSI_PLATFORM_MAX];
179 };
180
181 typedef PFN_vkVoidFunction (VKAPI_PTR *WSI_FN_GetPhysicalDeviceProcAddr)(VkPhysicalDevice physicalDevice, const char* pName);
182
183 VkResult
184 wsi_device_init(struct wsi_device *wsi,
185 VkPhysicalDevice pdevice,
186 WSI_FN_GetPhysicalDeviceProcAddr proc_addr,
187 const VkAllocationCallbacks *alloc,
188 int display_fd,
189 const struct driOptionCache *dri_options);
190
191 void
192 wsi_device_finish(struct wsi_device *wsi,
193 const VkAllocationCallbacks *alloc);
194
195 #define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \
196 \
197 static inline __VkIcdType * \
198 __VkIcdType ## _from_handle(__VkType _handle) \
199 { \
200 return (__VkIcdType *)(uintptr_t) _handle; \
201 } \
202 \
203 static inline __VkType \
204 __VkIcdType ## _to_handle(__VkIcdType *_obj) \
205 { \
206 return (__VkType)(uintptr_t) _obj; \
207 }
208
209 #define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
210 __VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
211
212 ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase, VkSurfaceKHR)
213
214 VkResult
215 wsi_common_get_surface_support(struct wsi_device *wsi_device,
216 uint32_t queueFamilyIndex,
217 VkSurfaceKHR surface,
218 VkBool32* pSupported);
219
220 VkResult
221 wsi_common_get_surface_capabilities(struct wsi_device *wsi_device,
222 VkSurfaceKHR surface,
223 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities);
224
225 VkResult
226 wsi_common_get_surface_capabilities2(struct wsi_device *wsi_device,
227 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
228 VkSurfaceCapabilities2KHR *pSurfaceCapabilities);
229
230 VkResult
231 wsi_common_get_surface_formats(struct wsi_device *wsi_device,
232 VkSurfaceKHR surface,
233 uint32_t *pSurfaceFormatCount,
234 VkSurfaceFormatKHR *pSurfaceFormats);
235
236 VkResult
237 wsi_common_get_surface_formats2(struct wsi_device *wsi_device,
238 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
239 uint32_t *pSurfaceFormatCount,
240 VkSurfaceFormat2KHR *pSurfaceFormats);
241
242 VkResult
243 wsi_common_get_surface_present_modes(struct wsi_device *wsi_device,
244 VkSurfaceKHR surface,
245 uint32_t *pPresentModeCount,
246 VkPresentModeKHR *pPresentModes);
247
248 VkResult
249 wsi_common_get_present_rectangles(struct wsi_device *wsi,
250 VkSurfaceKHR surface,
251 uint32_t* pRectCount,
252 VkRect2D* pRects);
253
254 VkResult
255 wsi_common_get_surface_capabilities2ext(
256 struct wsi_device *wsi_device,
257 VkSurfaceKHR surface,
258 VkSurfaceCapabilities2EXT *pSurfaceCapabilities);
259
260 VkResult
261 wsi_common_get_images(VkSwapchainKHR _swapchain,
262 uint32_t *pSwapchainImageCount,
263 VkImage *pSwapchainImages);
264
265 VkResult
266 wsi_common_acquire_next_image2(const struct wsi_device *wsi,
267 VkDevice device,
268 const VkAcquireNextImageInfoKHR *pAcquireInfo,
269 uint32_t *pImageIndex);
270
271 VkResult
272 wsi_common_create_swapchain(struct wsi_device *wsi,
273 VkDevice device,
274 const VkSwapchainCreateInfoKHR *pCreateInfo,
275 const VkAllocationCallbacks *pAllocator,
276 VkSwapchainKHR *pSwapchain);
277 void
278 wsi_common_destroy_swapchain(VkDevice device,
279 VkSwapchainKHR swapchain,
280 const VkAllocationCallbacks *pAllocator);
281
282 VkResult
283 wsi_common_queue_present(const struct wsi_device *wsi,
284 VkDevice device_h,
285 VkQueue queue_h,
286 int queue_family_index,
287 const VkPresentInfoKHR *pPresentInfo);
288
289 uint64_t
290 wsi_common_get_current_time(void);
291
292 #endif