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_physical_device
*physical_device
)
31 memset(physical_device
->wsi
, 0, sizeof(physical_device
->wsi
));
33 #ifdef VK_USE_PLATFORM_XCB_KHR
34 result
= anv_x11_init_wsi(physical_device
);
35 if (result
!= VK_SUCCESS
)
39 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
40 result
= anv_wl_init_wsi(physical_device
);
41 if (result
!= VK_SUCCESS
) {
42 anv_x11_finish_wsi(physical_device
);
51 anv_finish_wsi(struct anv_physical_device
*physical_device
)
53 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
54 anv_wl_finish_wsi(physical_device
);
56 #ifdef VK_USE_PLATFORM_XCB_KHR
57 anv_x11_finish_wsi(physical_device
);
61 void anv_DestroySurfaceKHR(
63 VkSurfaceKHR _surface
,
64 const VkAllocationCallbacks
* pAllocator
)
66 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
67 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
69 anv_free2(&instance
->alloc
, pAllocator
, surface
);
72 VkResult
anv_GetPhysicalDeviceSurfaceSupportKHR(
73 VkPhysicalDevice physicalDevice
,
74 uint32_t queueFamilyIndex
,
75 VkSurfaceKHR _surface
,
78 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
79 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
80 struct anv_wsi_interface
*iface
= device
->wsi
[surface
->platform
];
82 return iface
->get_support(surface
, device
, queueFamilyIndex
, pSupported
);
85 VkResult
anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
86 VkPhysicalDevice physicalDevice
,
87 VkSurfaceKHR _surface
,
88 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
90 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
91 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
92 struct anv_wsi_interface
*iface
= device
->wsi
[surface
->platform
];
94 return iface
->get_capabilities(surface
, device
, pSurfaceCapabilities
);
97 VkResult
anv_GetPhysicalDeviceSurfaceFormatsKHR(
98 VkPhysicalDevice physicalDevice
,
99 VkSurfaceKHR _surface
,
100 uint32_t* pSurfaceFormatCount
,
101 VkSurfaceFormatKHR
* pSurfaceFormats
)
103 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
104 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
105 struct anv_wsi_interface
*iface
= device
->wsi
[surface
->platform
];
107 return iface
->get_formats(surface
, device
, pSurfaceFormatCount
,
111 VkResult
anv_GetPhysicalDeviceSurfacePresentModesKHR(
112 VkPhysicalDevice physicalDevice
,
113 VkSurfaceKHR _surface
,
114 uint32_t* pPresentModeCount
,
115 VkPresentModeKHR
* pPresentModes
)
117 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
118 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
119 struct anv_wsi_interface
*iface
= device
->wsi
[surface
->platform
];
121 return iface
->get_present_modes(surface
, device
, pPresentModeCount
,
125 VkResult
anv_CreateSwapchainKHR(
127 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
128 const VkAllocationCallbacks
* pAllocator
,
129 VkSwapchainKHR
* pSwapchain
)
131 ANV_FROM_HANDLE(anv_device
, device
, _device
);
132 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, pCreateInfo
->surface
);
133 struct anv_wsi_interface
*iface
=
134 device
->instance
->physicalDevice
.wsi
[surface
->platform
];
135 struct anv_swapchain
*swapchain
;
137 VkResult result
= iface
->create_swapchain(surface
, device
, pCreateInfo
,
138 pAllocator
, &swapchain
);
139 if (result
!= VK_SUCCESS
)
143 swapchain
->alloc
= *pAllocator
;
145 swapchain
->alloc
= device
->alloc
;
147 for (unsigned i
= 0; i
< ARRAY_SIZE(swapchain
->fences
); i
++)
148 swapchain
->fences
[i
] = VK_NULL_HANDLE
;
150 *pSwapchain
= anv_swapchain_to_handle(swapchain
);
155 void anv_DestroySwapchainKHR(
157 VkSwapchainKHR _swapchain
,
158 const VkAllocationCallbacks
* pAllocator
)
160 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
162 for (unsigned i
= 0; i
< ARRAY_SIZE(swapchain
->fences
); i
++) {
163 if (swapchain
->fences
[i
] != VK_NULL_HANDLE
)
164 anv_DestroyFence(device
, swapchain
->fences
[i
], pAllocator
);
167 swapchain
->destroy(swapchain
, pAllocator
);
170 VkResult
anv_GetSwapchainImagesKHR(
172 VkSwapchainKHR _swapchain
,
173 uint32_t* pSwapchainImageCount
,
174 VkImage
* pSwapchainImages
)
176 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
178 return swapchain
->get_images(swapchain
, pSwapchainImageCount
,
182 VkResult
anv_AcquireNextImageKHR(
184 VkSwapchainKHR _swapchain
,
186 VkSemaphore semaphore
,
188 uint32_t* pImageIndex
)
190 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
192 return swapchain
->acquire_next_image(swapchain
, timeout
, semaphore
,
196 VkResult
anv_QueuePresentKHR(
198 const VkPresentInfoKHR
* pPresentInfo
)
200 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
203 for (uint32_t i
= 0; i
< pPresentInfo
->swapchainCount
; i
++) {
204 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, pPresentInfo
->pSwapchains
[i
]);
206 assert(swapchain
->device
== queue
->device
);
208 if (swapchain
->fences
[0] == VK_NULL_HANDLE
) {
209 result
= anv_CreateFence(anv_device_to_handle(queue
->device
),
210 &(VkFenceCreateInfo
) {
211 .sType
= VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
,
213 }, &swapchain
->alloc
, &swapchain
->fences
[0]);
214 if (result
!= VK_SUCCESS
)
217 anv_ResetFences(anv_device_to_handle(queue
->device
),
218 1, &swapchain
->fences
[0]);
221 anv_QueueSubmit(_queue
, 0, NULL
, swapchain
->fences
[0]);
223 result
= swapchain
->queue_present(swapchain
, queue
,
224 pPresentInfo
->pImageIndices
[i
]);
225 /* TODO: What if one of them returns OUT_OF_DATE? */
226 if (result
!= VK_SUCCESS
)
229 VkFence last
= swapchain
->fences
[2];
230 swapchain
->fences
[2] = swapchain
->fences
[1];
231 swapchain
->fences
[1] = swapchain
->fences
[0];
232 swapchain
->fences
[0] = last
;
234 if (last
!= VK_NULL_HANDLE
) {
235 anv_WaitForFences(anv_device_to_handle(queue
->device
),