2 * Copyright © 2015 Intel Corporation
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:
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
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
24 #include "anv_private.h"
25 #include "wsi_common.h"
26 #include "vk_format_info.h"
29 static PFN_vkVoidFunction
30 anv_wsi_proc_addr(VkPhysicalDevice physicalDevice
, const char *pName
)
32 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
33 return anv_lookup_entrypoint(&physical_device
->info
, pName
);
37 anv_init_wsi(struct anv_physical_device
*physical_device
)
41 wsi_device_init(&physical_device
->wsi_device
,
42 anv_physical_device_to_handle(physical_device
),
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
)
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
);
66 anv_finish_wsi(struct anv_physical_device
*physical_device
)
68 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
69 wsi_wl_finish_wsi(&physical_device
->wsi_device
, &physical_device
->instance
->alloc
);
71 #ifdef VK_USE_PLATFORM_XCB_KHR
72 wsi_x11_finish_wsi(&physical_device
->wsi_device
, &physical_device
->instance
->alloc
);
76 void anv_DestroySurfaceKHR(
78 VkSurfaceKHR _surface
,
79 const VkAllocationCallbacks
* pAllocator
)
81 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
82 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
87 vk_free2(&instance
->alloc
, pAllocator
, surface
);
90 VkResult
anv_GetPhysicalDeviceSurfaceSupportKHR(
91 VkPhysicalDevice physicalDevice
,
92 uint32_t queueFamilyIndex
,
96 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
98 return wsi_common_get_surface_support(&device
->wsi_device
,
102 &device
->instance
->alloc
,
106 VkResult
anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
107 VkPhysicalDevice physicalDevice
,
108 VkSurfaceKHR surface
,
109 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
111 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
113 return wsi_common_get_surface_capabilities(&device
->wsi_device
,
115 pSurfaceCapabilities
);
118 VkResult
anv_GetPhysicalDeviceSurfaceCapabilities2KHR(
119 VkPhysicalDevice physicalDevice
,
120 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
121 VkSurfaceCapabilities2KHR
* pSurfaceCapabilities
)
123 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
125 return wsi_common_get_surface_capabilities2(&device
->wsi_device
,
127 pSurfaceCapabilities
);
130 VkResult
anv_GetPhysicalDeviceSurfaceFormatsKHR(
131 VkPhysicalDevice physicalDevice
,
132 VkSurfaceKHR surface
,
133 uint32_t* pSurfaceFormatCount
,
134 VkSurfaceFormatKHR
* pSurfaceFormats
)
136 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
138 return wsi_common_get_surface_formats(&device
->wsi_device
, surface
,
139 pSurfaceFormatCount
, pSurfaceFormats
);
142 VkResult
anv_GetPhysicalDeviceSurfaceFormats2KHR(
143 VkPhysicalDevice physicalDevice
,
144 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
145 uint32_t* pSurfaceFormatCount
,
146 VkSurfaceFormat2KHR
* pSurfaceFormats
)
148 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
150 return wsi_common_get_surface_formats2(&device
->wsi_device
, pSurfaceInfo
,
151 pSurfaceFormatCount
, pSurfaceFormats
);
154 VkResult
anv_GetPhysicalDeviceSurfacePresentModesKHR(
155 VkPhysicalDevice physicalDevice
,
156 VkSurfaceKHR surface
,
157 uint32_t* pPresentModeCount
,
158 VkPresentModeKHR
* pPresentModes
)
160 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
162 return wsi_common_get_surface_present_modes(&device
->wsi_device
, surface
,
167 VkResult
anv_CreateSwapchainKHR(
169 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
170 const VkAllocationCallbacks
* pAllocator
,
171 VkSwapchainKHR
* pSwapchain
)
173 ANV_FROM_HANDLE(anv_device
, device
, _device
);
174 struct wsi_device
*wsi_device
= &device
->instance
->physicalDevice
.wsi_device
;
175 const VkAllocationCallbacks
*alloc
;
180 alloc
= &device
->alloc
;
182 return wsi_common_create_swapchain(wsi_device
, _device
, device
->fd
,
183 pCreateInfo
, alloc
, pSwapchain
);
186 void anv_DestroySwapchainKHR(
188 VkSwapchainKHR swapchain
,
189 const VkAllocationCallbacks
* pAllocator
)
191 ANV_FROM_HANDLE(anv_device
, device
, _device
);
192 const VkAllocationCallbacks
*alloc
;
197 alloc
= &device
->alloc
;
199 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
202 VkResult
anv_GetSwapchainImagesKHR(
204 VkSwapchainKHR swapchain
,
205 uint32_t* pSwapchainImageCount
,
206 VkImage
* pSwapchainImages
)
208 return wsi_common_get_images(swapchain
,
209 pSwapchainImageCount
,
213 VkResult
anv_AcquireNextImageKHR(
215 VkSwapchainKHR swapchain
,
217 VkSemaphore semaphore
,
219 uint32_t* pImageIndex
)
221 ANV_FROM_HANDLE(anv_device
, device
, _device
);
222 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
224 VkResult result
= wsi_common_acquire_next_image(&pdevice
->wsi_device
,
231 /* Thanks to implicit sync, the image is ready immediately. However, we
232 * should wait for the current GPU state to finish.
234 if (fence
!= VK_NULL_HANDLE
)
235 anv_QueueSubmit(anv_queue_to_handle(&device
->queue
), 0, NULL
, fence
);
240 VkResult
anv_QueuePresentKHR(
242 const VkPresentInfoKHR
* pPresentInfo
)
244 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
245 struct anv_physical_device
*pdevice
=
246 &queue
->device
->instance
->physicalDevice
;
248 return wsi_common_queue_present(&pdevice
->wsi_device
,
249 anv_device_to_handle(queue
->device
),