vulkan/wsi: Drop some unneeded cruft from the API
[mesa.git] / src / intel / vulkan / anv_wsi.c
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
24 #include "anv_private.h"
25 #include "wsi_common.h"
26 #include "vk_format_info.h"
27 #include "vk_util.h"
28
29 static PFN_vkVoidFunction
30 anv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
31 {
32 ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
33 return anv_lookup_entrypoint(&physical_device->info, pName);
34 }
35
36 VkResult
37 anv_init_wsi(struct anv_physical_device *physical_device)
38 {
39 VkResult result;
40
41 wsi_device_init(&physical_device->wsi_device,
42 anv_physical_device_to_handle(physical_device),
43 anv_wsi_proc_addr);
44
45 #ifdef VK_USE_PLATFORM_XCB_KHR
46 result = wsi_x11_init_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
47 if (result != VK_SUCCESS)
48 return result;
49 #endif
50
51 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
52 result = wsi_wl_init_wsi(&physical_device->wsi_device, &physical_device->instance->alloc,
53 anv_physical_device_to_handle(physical_device));
54 if (result != VK_SUCCESS) {
55 #ifdef VK_USE_PLATFORM_XCB_KHR
56 wsi_x11_finish_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
57 #endif
58 return result;
59 }
60 #endif
61
62 return VK_SUCCESS;
63 }
64
65 void
66 anv_finish_wsi(struct anv_physical_device *physical_device)
67 {
68 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
69 wsi_wl_finish_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
70 #endif
71 #ifdef VK_USE_PLATFORM_XCB_KHR
72 wsi_x11_finish_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
73 #endif
74 }
75
76 void anv_DestroySurfaceKHR(
77 VkInstance _instance,
78 VkSurfaceKHR _surface,
79 const VkAllocationCallbacks* pAllocator)
80 {
81 ANV_FROM_HANDLE(anv_instance, instance, _instance);
82 ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
83
84 if (!surface)
85 return;
86
87 vk_free2(&instance->alloc, pAllocator, surface);
88 }
89
90 VkResult anv_GetPhysicalDeviceSurfaceSupportKHR(
91 VkPhysicalDevice physicalDevice,
92 uint32_t queueFamilyIndex,
93 VkSurfaceKHR surface,
94 VkBool32* pSupported)
95 {
96 ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
97
98 return wsi_common_get_surface_support(&device->wsi_device,
99 device->local_fd,
100 queueFamilyIndex,
101 surface,
102 &device->instance->alloc,
103 pSupported);
104 }
105
106 VkResult anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
107 VkPhysicalDevice physicalDevice,
108 VkSurfaceKHR surface,
109 VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
110 {
111 ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
112
113 return wsi_common_get_surface_capabilities(&device->wsi_device,
114 surface,
115 pSurfaceCapabilities);
116 }
117
118 VkResult anv_GetPhysicalDeviceSurfaceCapabilities2KHR(
119 VkPhysicalDevice physicalDevice,
120 const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
121 VkSurfaceCapabilities2KHR* pSurfaceCapabilities)
122 {
123 ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
124
125 return wsi_common_get_surface_capabilities2(&device->wsi_device,
126 pSurfaceInfo,
127 pSurfaceCapabilities);
128 }
129
130 VkResult anv_GetPhysicalDeviceSurfaceFormatsKHR(
131 VkPhysicalDevice physicalDevice,
132 VkSurfaceKHR surface,
133 uint32_t* pSurfaceFormatCount,
134 VkSurfaceFormatKHR* pSurfaceFormats)
135 {
136 ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
137
138 return wsi_common_get_surface_formats(&device->wsi_device, surface,
139 pSurfaceFormatCount, pSurfaceFormats);
140 }
141
142 VkResult anv_GetPhysicalDeviceSurfaceFormats2KHR(
143 VkPhysicalDevice physicalDevice,
144 const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
145 uint32_t* pSurfaceFormatCount,
146 VkSurfaceFormat2KHR* pSurfaceFormats)
147 {
148 ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
149
150 return wsi_common_get_surface_formats2(&device->wsi_device, pSurfaceInfo,
151 pSurfaceFormatCount, pSurfaceFormats);
152 }
153
154 VkResult anv_GetPhysicalDeviceSurfacePresentModesKHR(
155 VkPhysicalDevice physicalDevice,
156 VkSurfaceKHR surface,
157 uint32_t* pPresentModeCount,
158 VkPresentModeKHR* pPresentModes)
159 {
160 ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
161
162 return wsi_common_get_surface_present_modes(&device->wsi_device, surface,
163 pPresentModeCount,
164 pPresentModes);
165 }
166
167 VkResult anv_CreateSwapchainKHR(
168 VkDevice _device,
169 const VkSwapchainCreateInfoKHR* pCreateInfo,
170 const VkAllocationCallbacks* pAllocator,
171 VkSwapchainKHR* pSwapchain)
172 {
173 ANV_FROM_HANDLE(anv_device, device, _device);
174 struct wsi_device *wsi_device = &device->instance->physicalDevice.wsi_device;
175 const VkAllocationCallbacks *alloc;
176
177 if (pAllocator)
178 alloc = pAllocator;
179 else
180 alloc = &device->alloc;
181
182 return wsi_common_create_swapchain(wsi_device, _device, device->fd,
183 pCreateInfo, alloc, pSwapchain);
184 }
185
186 void anv_DestroySwapchainKHR(
187 VkDevice _device,
188 VkSwapchainKHR swapchain,
189 const VkAllocationCallbacks* pAllocator)
190 {
191 ANV_FROM_HANDLE(anv_device, device, _device);
192 const VkAllocationCallbacks *alloc;
193
194 if (pAllocator)
195 alloc = pAllocator;
196 else
197 alloc = &device->alloc;
198
199 wsi_common_destroy_swapchain(_device, swapchain, alloc);
200 }
201
202 VkResult anv_GetSwapchainImagesKHR(
203 VkDevice device,
204 VkSwapchainKHR swapchain,
205 uint32_t* pSwapchainImageCount,
206 VkImage* pSwapchainImages)
207 {
208 return wsi_common_get_images(swapchain,
209 pSwapchainImageCount,
210 pSwapchainImages);
211 }
212
213 VkResult anv_AcquireNextImageKHR(
214 VkDevice _device,
215 VkSwapchainKHR swapchain,
216 uint64_t timeout,
217 VkSemaphore semaphore,
218 VkFence fence,
219 uint32_t* pImageIndex)
220 {
221 ANV_FROM_HANDLE(anv_device, device, _device);
222 struct anv_physical_device *pdevice = &device->instance->physicalDevice;
223
224 VkResult result = wsi_common_acquire_next_image(&pdevice->wsi_device,
225 _device,
226 swapchain,
227 timeout,
228 semaphore,
229 pImageIndex);
230
231 /* Thanks to implicit sync, the image is ready immediately. However, we
232 * should wait for the current GPU state to finish.
233 */
234 if (fence != VK_NULL_HANDLE)
235 anv_QueueSubmit(anv_queue_to_handle(&device->queue), 0, NULL, fence);
236
237 return result;
238 }
239
240 VkResult anv_QueuePresentKHR(
241 VkQueue _queue,
242 const VkPresentInfoKHR* pPresentInfo)
243 {
244 ANV_FROM_HANDLE(anv_queue, queue, _queue);
245 struct anv_physical_device *pdevice =
246 &queue->device->instance->physicalDevice;
247
248 return wsi_common_queue_present(&pdevice->wsi_device,
249 anv_device_to_handle(queue->device),
250 _queue, 0,
251 pPresentInfo);
252 }