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
27 anv_init_wsi(struct anv_instance
*instance
)
31 result
= anv_x11_init_wsi(instance
);
32 if (result
!= VK_SUCCESS
)
35 #ifdef HAVE_WAYLAND_PLATFORM
36 result
= anv_wl_init_wsi(instance
);
37 if (result
!= VK_SUCCESS
) {
38 anv_x11_finish_wsi(instance
);
47 anv_finish_wsi(struct anv_instance
*instance
)
49 #ifdef HAVE_WAYLAND_PLATFORM
50 anv_wl_finish_wsi(instance
);
52 anv_x11_finish_wsi(instance
);
55 void anv_DestroySurfaceKHR(
57 VkSurfaceKHR _surface
,
58 const VkAllocationCallbacks
* pAllocator
)
60 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
61 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
63 anv_free2(&instance
->alloc
, pAllocator
, surface
);
66 VkResult
anv_GetPhysicalDeviceSurfaceSupportKHR(
67 VkPhysicalDevice physicalDevice
,
68 uint32_t queueFamilyIndex
,
69 VkSurfaceKHR _surface
,
72 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
73 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
74 struct anv_wsi_interface
*iface
= device
->instance
->wsi
[surface
->platform
];
76 return iface
->get_support(surface
, device
, queueFamilyIndex
, pSupported
);
79 VkResult
anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
80 VkPhysicalDevice physicalDevice
,
81 VkSurfaceKHR _surface
,
82 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
84 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
85 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
86 struct anv_wsi_interface
*iface
= device
->instance
->wsi
[surface
->platform
];
88 return iface
->get_capabilities(surface
, device
, pSurfaceCapabilities
);
91 VkResult
anv_GetPhysicalDeviceSurfaceFormatsKHR(
92 VkPhysicalDevice physicalDevice
,
93 VkSurfaceKHR _surface
,
94 uint32_t* pSurfaceFormatCount
,
95 VkSurfaceFormatKHR
* pSurfaceFormats
)
97 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
98 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
99 struct anv_wsi_interface
*iface
= device
->instance
->wsi
[surface
->platform
];
101 return iface
->get_formats(surface
, device
, pSurfaceFormatCount
,
105 VkResult
anv_GetPhysicalDeviceSurfacePresentModesKHR(
106 VkPhysicalDevice physicalDevice
,
107 VkSurfaceKHR _surface
,
108 uint32_t* pPresentModeCount
,
109 VkPresentModeKHR
* pPresentModes
)
111 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
112 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
113 struct anv_wsi_interface
*iface
= device
->instance
->wsi
[surface
->platform
];
115 return iface
->get_present_modes(surface
, device
, pPresentModeCount
,
119 VkResult
anv_CreateSwapchainKHR(
121 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
122 const VkAllocationCallbacks
* pAllocator
,
123 VkSwapchainKHR
* pSwapchain
)
125 ANV_FROM_HANDLE(anv_device
, device
, _device
);
126 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, pCreateInfo
->surface
);
127 struct anv_wsi_interface
*iface
= device
->instance
->wsi
[surface
->platform
];
128 struct anv_swapchain
*swapchain
;
130 VkResult result
= iface
->create_swapchain(surface
, device
, pCreateInfo
,
131 pAllocator
, &swapchain
);
132 if (result
!= VK_SUCCESS
)
135 *pSwapchain
= anv_swapchain_to_handle(swapchain
);
140 void anv_DestroySwapchainKHR(
142 VkSwapchainKHR _swapchain
,
143 const VkAllocationCallbacks
* pAllocator
)
145 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
147 swapchain
->destroy(swapchain
, pAllocator
);
150 VkResult
anv_GetSwapchainImagesKHR(
152 VkSwapchainKHR _swapchain
,
153 uint32_t* pSwapchainImageCount
,
154 VkImage
* pSwapchainImages
)
156 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
158 return swapchain
->get_images(swapchain
, pSwapchainImageCount
,
162 VkResult
anv_AcquireNextImageKHR(
164 VkSwapchainKHR _swapchain
,
166 VkSemaphore semaphore
,
168 uint32_t* pImageIndex
)
170 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
172 return swapchain
->acquire_next_image(swapchain
, timeout
, semaphore
,
176 VkResult
anv_QueuePresentKHR(
178 const VkPresentInfoKHR
* pPresentInfo
)
180 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
183 for (uint32_t i
= 0; i
< pPresentInfo
->swapchainCount
; i
++) {
184 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, pPresentInfo
->pSwapchains
[i
]);
186 assert(swapchain
->device
== queue
->device
);
188 result
= swapchain
->queue_present(swapchain
, queue
,
189 pPresentInfo
->pImageIndices
[i
]);
190 /* TODO: What if one of them returns OUT_OF_DATE? */
191 if (result
!= VK_SUCCESS
)