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 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
30 #define WSI_CB(x) .x = anv_##x
31 static const struct wsi_callbacks wsi_cbs
= {
32 WSI_CB(GetPhysicalDeviceFormatProperties
),
36 static PFN_vkVoidFunction
37 anv_wsi_proc_addr(VkPhysicalDevice physicalDevice
, const char *pName
)
39 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
40 return anv_lookup_entrypoint(&physical_device
->info
, pName
);
44 anv_wsi_queue_get_family_index(VkQueue queue
)
50 anv_init_wsi(struct anv_physical_device
*physical_device
)
54 wsi_device_init(&physical_device
->wsi_device
,
55 anv_physical_device_to_handle(physical_device
),
58 physical_device
->wsi_device
.queue_get_family_index
=
59 anv_wsi_queue_get_family_index
;
61 #ifdef VK_USE_PLATFORM_XCB_KHR
62 result
= wsi_x11_init_wsi(&physical_device
->wsi_device
, &physical_device
->instance
->alloc
);
63 if (result
!= VK_SUCCESS
)
67 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
68 result
= wsi_wl_init_wsi(&physical_device
->wsi_device
, &physical_device
->instance
->alloc
,
69 anv_physical_device_to_handle(physical_device
),
71 if (result
!= VK_SUCCESS
) {
72 #ifdef VK_USE_PLATFORM_XCB_KHR
73 wsi_x11_finish_wsi(&physical_device
->wsi_device
, &physical_device
->instance
->alloc
);
83 anv_finish_wsi(struct anv_physical_device
*physical_device
)
85 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
86 wsi_wl_finish_wsi(&physical_device
->wsi_device
, &physical_device
->instance
->alloc
);
88 #ifdef VK_USE_PLATFORM_XCB_KHR
89 wsi_x11_finish_wsi(&physical_device
->wsi_device
, &physical_device
->instance
->alloc
);
93 void anv_DestroySurfaceKHR(
95 VkSurfaceKHR _surface
,
96 const VkAllocationCallbacks
* pAllocator
)
98 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
99 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
104 vk_free2(&instance
->alloc
, pAllocator
, surface
);
107 VkResult
anv_GetPhysicalDeviceSurfaceSupportKHR(
108 VkPhysicalDevice physicalDevice
,
109 uint32_t queueFamilyIndex
,
110 VkSurfaceKHR _surface
,
111 VkBool32
* pSupported
)
113 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
114 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
115 struct wsi_interface
*iface
= device
->wsi_device
.wsi
[surface
->platform
];
117 return iface
->get_support(surface
, &device
->wsi_device
,
118 &device
->instance
->alloc
,
119 queueFamilyIndex
, device
->local_fd
, true, pSupported
);
122 VkResult
anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
123 VkPhysicalDevice physicalDevice
,
124 VkSurfaceKHR _surface
,
125 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
127 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
128 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
129 struct wsi_interface
*iface
= device
->wsi_device
.wsi
[surface
->platform
];
131 return iface
->get_capabilities(surface
, pSurfaceCapabilities
);
134 VkResult
anv_GetPhysicalDeviceSurfaceCapabilities2KHR(
135 VkPhysicalDevice physicalDevice
,
136 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
137 VkSurfaceCapabilities2KHR
* pSurfaceCapabilities
)
139 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
140 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, pSurfaceInfo
->surface
);
141 struct wsi_interface
*iface
= device
->wsi_device
.wsi
[surface
->platform
];
143 return iface
->get_capabilities2(surface
, pSurfaceInfo
->pNext
,
144 pSurfaceCapabilities
);
147 VkResult
anv_GetPhysicalDeviceSurfaceFormatsKHR(
148 VkPhysicalDevice physicalDevice
,
149 VkSurfaceKHR _surface
,
150 uint32_t* pSurfaceFormatCount
,
151 VkSurfaceFormatKHR
* pSurfaceFormats
)
153 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
154 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
155 struct wsi_interface
*iface
= device
->wsi_device
.wsi
[surface
->platform
];
157 return iface
->get_formats(surface
, &device
->wsi_device
, pSurfaceFormatCount
,
161 VkResult
anv_GetPhysicalDeviceSurfaceFormats2KHR(
162 VkPhysicalDevice physicalDevice
,
163 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
164 uint32_t* pSurfaceFormatCount
,
165 VkSurfaceFormat2KHR
* pSurfaceFormats
)
167 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
168 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, pSurfaceInfo
->surface
);
169 struct wsi_interface
*iface
= device
->wsi_device
.wsi
[surface
->platform
];
171 return iface
->get_formats2(surface
, &device
->wsi_device
, pSurfaceInfo
->pNext
,
172 pSurfaceFormatCount
, pSurfaceFormats
);
175 VkResult
anv_GetPhysicalDeviceSurfacePresentModesKHR(
176 VkPhysicalDevice physicalDevice
,
177 VkSurfaceKHR _surface
,
178 uint32_t* pPresentModeCount
,
179 VkPresentModeKHR
* pPresentModes
)
181 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
182 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
183 struct wsi_interface
*iface
= device
->wsi_device
.wsi
[surface
->platform
];
185 return iface
->get_present_modes(surface
, pPresentModeCount
,
189 VkResult
anv_CreateSwapchainKHR(
191 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
192 const VkAllocationCallbacks
* pAllocator
,
193 VkSwapchainKHR
* pSwapchain
)
195 ANV_FROM_HANDLE(anv_device
, device
, _device
);
196 struct wsi_device
*wsi_device
= &device
->instance
->physicalDevice
.wsi_device
;
197 const VkAllocationCallbacks
*alloc
;
202 alloc
= &device
->alloc
;
204 return wsi_common_create_swapchain(wsi_device
, _device
, device
->fd
,
205 pCreateInfo
, alloc
, pSwapchain
);
208 void anv_DestroySwapchainKHR(
210 VkSwapchainKHR swapchain
,
211 const VkAllocationCallbacks
* pAllocator
)
213 ANV_FROM_HANDLE(anv_device
, device
, _device
);
214 const VkAllocationCallbacks
*alloc
;
219 alloc
= &device
->alloc
;
221 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
224 VkResult
anv_GetSwapchainImagesKHR(
226 VkSwapchainKHR swapchain
,
227 uint32_t* pSwapchainImageCount
,
228 VkImage
* pSwapchainImages
)
230 return wsi_common_get_images(swapchain
,
231 pSwapchainImageCount
,
235 VkResult
anv_AcquireNextImageKHR(
237 VkSwapchainKHR swapchain
,
239 VkSemaphore semaphore
,
241 uint32_t* pImageIndex
)
243 ANV_FROM_HANDLE(anv_device
, device
, _device
);
244 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
246 VkResult result
= wsi_common_acquire_next_image(&pdevice
->wsi_device
,
253 /* Thanks to implicit sync, the image is ready immediately. However, we
254 * should wait for the current GPU state to finish.
256 if (fence
!= VK_NULL_HANDLE
)
257 anv_QueueSubmit(anv_queue_to_handle(&device
->queue
), 0, NULL
, fence
);
262 VkResult
anv_QueuePresentKHR(
264 const VkPresentInfoKHR
* pPresentInfo
)
266 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
267 struct anv_physical_device
*pdevice
=
268 &queue
->device
->instance
->physicalDevice
;
270 return wsi_common_queue_present(&pdevice
->wsi_device
,
271 anv_device_to_handle(queue
->device
),