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 #ifdef VK_USE_PLATFORM_XCB_KHR
32 result
= anv_x11_init_wsi(instance
);
33 if (result
!= VK_SUCCESS
)
37 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
38 result
= anv_wl_init_wsi(instance
);
39 if (result
!= VK_SUCCESS
) {
40 anv_x11_finish_wsi(instance
);
49 anv_finish_wsi(struct anv_instance
*instance
)
51 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
52 anv_wl_finish_wsi(instance
);
54 #ifdef VK_USE_PLATFORM_XCB_KHR
55 anv_x11_finish_wsi(instance
);
59 void anv_DestroySurfaceKHR(
61 VkSurfaceKHR _surface
,
62 const VkAllocationCallbacks
* pAllocator
)
64 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
65 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
67 anv_free2(&instance
->alloc
, pAllocator
, surface
);
70 VkResult
anv_GetPhysicalDeviceSurfaceSupportKHR(
71 VkPhysicalDevice physicalDevice
,
72 uint32_t queueFamilyIndex
,
73 VkSurfaceKHR _surface
,
76 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
77 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
78 struct anv_wsi_interface
*iface
= device
->instance
->wsi
[surface
->platform
];
80 return iface
->get_support(surface
, device
, queueFamilyIndex
, pSupported
);
83 VkResult
anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
84 VkPhysicalDevice physicalDevice
,
85 VkSurfaceKHR _surface
,
86 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
88 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
89 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
90 struct anv_wsi_interface
*iface
= device
->instance
->wsi
[surface
->platform
];
92 return iface
->get_capabilities(surface
, device
, pSurfaceCapabilities
);
95 VkResult
anv_GetPhysicalDeviceSurfaceFormatsKHR(
96 VkPhysicalDevice physicalDevice
,
97 VkSurfaceKHR _surface
,
98 uint32_t* pSurfaceFormatCount
,
99 VkSurfaceFormatKHR
* pSurfaceFormats
)
101 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
102 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
103 struct anv_wsi_interface
*iface
= device
->instance
->wsi
[surface
->platform
];
105 return iface
->get_formats(surface
, device
, pSurfaceFormatCount
,
109 VkResult
anv_GetPhysicalDeviceSurfacePresentModesKHR(
110 VkPhysicalDevice physicalDevice
,
111 VkSurfaceKHR _surface
,
112 uint32_t* pPresentModeCount
,
113 VkPresentModeKHR
* pPresentModes
)
115 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
116 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
117 struct anv_wsi_interface
*iface
= device
->instance
->wsi
[surface
->platform
];
119 return iface
->get_present_modes(surface
, device
, pPresentModeCount
,
123 VkResult
anv_CreateSwapchainKHR(
125 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
126 const VkAllocationCallbacks
* pAllocator
,
127 VkSwapchainKHR
* pSwapchain
)
129 ANV_FROM_HANDLE(anv_device
, device
, _device
);
130 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, pCreateInfo
->surface
);
131 struct anv_wsi_interface
*iface
= device
->instance
->wsi
[surface
->platform
];
132 struct anv_swapchain
*swapchain
;
134 VkResult result
= iface
->create_swapchain(surface
, device
, pCreateInfo
,
135 pAllocator
, &swapchain
);
136 if (result
!= VK_SUCCESS
)
140 swapchain
->alloc
= *pAllocator
;
142 swapchain
->alloc
= device
->alloc
;
144 for (unsigned i
= 0; i
< ARRAY_SIZE(swapchain
->fences
); i
++)
145 swapchain
->fences
[i
] = VK_NULL_HANDLE
;
147 *pSwapchain
= anv_swapchain_to_handle(swapchain
);
152 void anv_DestroySwapchainKHR(
154 VkSwapchainKHR _swapchain
,
155 const VkAllocationCallbacks
* pAllocator
)
157 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
159 for (unsigned i
= 0; i
< ARRAY_SIZE(swapchain
->fences
); i
++) {
160 if (swapchain
->fences
[i
] != VK_NULL_HANDLE
)
161 anv_DestroyFence(device
, swapchain
->fences
[i
], pAllocator
);
164 swapchain
->destroy(swapchain
, pAllocator
);
167 VkResult
anv_GetSwapchainImagesKHR(
169 VkSwapchainKHR _swapchain
,
170 uint32_t* pSwapchainImageCount
,
171 VkImage
* pSwapchainImages
)
173 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
175 return swapchain
->get_images(swapchain
, pSwapchainImageCount
,
179 VkResult
anv_AcquireNextImageKHR(
181 VkSwapchainKHR _swapchain
,
183 VkSemaphore semaphore
,
185 uint32_t* pImageIndex
)
187 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
189 return swapchain
->acquire_next_image(swapchain
, timeout
, semaphore
,
193 VkResult
anv_QueuePresentKHR(
195 const VkPresentInfoKHR
* pPresentInfo
)
197 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
200 for (uint32_t i
= 0; i
< pPresentInfo
->swapchainCount
; i
++) {
201 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, pPresentInfo
->pSwapchains
[i
]);
203 assert(swapchain
->device
== queue
->device
);
205 if (swapchain
->fences
[0] == VK_NULL_HANDLE
) {
206 result
= anv_CreateFence(anv_device_to_handle(queue
->device
),
207 &(VkFenceCreateInfo
) {
208 .sType
= VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
,
210 }, &swapchain
->alloc
, &swapchain
->fences
[0]);
211 if (result
!= VK_SUCCESS
)
214 anv_ResetFences(anv_device_to_handle(queue
->device
),
215 1, &swapchain
->fences
[0]);
218 anv_QueueSubmit(_queue
, 0, NULL
, swapchain
->fences
[0]);
220 result
= swapchain
->queue_present(swapchain
, queue
,
221 pPresentInfo
->pImageIndices
[i
]);
222 /* TODO: What if one of them returns OUT_OF_DATE? */
223 if (result
!= VK_SUCCESS
)
226 VkFence last
= swapchain
->fences
[2];
227 swapchain
->fences
[2] = swapchain
->fences
[1];
228 swapchain
->fences
[1] = swapchain
->fences
[0];
229 swapchain
->fences
[0] = last
;
231 if (last
!= VK_NULL_HANDLE
) {
232 anv_WaitForFences(anv_device_to_handle(queue
->device
),