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 #ifdef VK_USE_PLATFORM_XCB_KHR
43 anv_x11_finish_wsi(physical_device
);
53 anv_finish_wsi(struct anv_physical_device
*physical_device
)
55 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
56 anv_wl_finish_wsi(physical_device
);
58 #ifdef VK_USE_PLATFORM_XCB_KHR
59 anv_x11_finish_wsi(physical_device
);
63 void anv_DestroySurfaceKHR(
65 VkSurfaceKHR _surface
,
66 const VkAllocationCallbacks
* pAllocator
)
68 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
69 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
71 anv_free2(&instance
->alloc
, pAllocator
, surface
);
74 VkResult
anv_GetPhysicalDeviceSurfaceSupportKHR(
75 VkPhysicalDevice physicalDevice
,
76 uint32_t queueFamilyIndex
,
77 VkSurfaceKHR _surface
,
80 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
81 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
82 struct anv_wsi_interface
*iface
= device
->wsi
[surface
->platform
];
84 return iface
->get_support(surface
, device
, queueFamilyIndex
, pSupported
);
87 VkResult
anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
88 VkPhysicalDevice physicalDevice
,
89 VkSurfaceKHR _surface
,
90 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
92 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
93 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
94 struct anv_wsi_interface
*iface
= device
->wsi
[surface
->platform
];
96 return iface
->get_capabilities(surface
, device
, pSurfaceCapabilities
);
99 VkResult
anv_GetPhysicalDeviceSurfaceFormatsKHR(
100 VkPhysicalDevice physicalDevice
,
101 VkSurfaceKHR _surface
,
102 uint32_t* pSurfaceFormatCount
,
103 VkSurfaceFormatKHR
* pSurfaceFormats
)
105 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
106 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
107 struct anv_wsi_interface
*iface
= device
->wsi
[surface
->platform
];
109 return iface
->get_formats(surface
, device
, pSurfaceFormatCount
,
113 VkResult
anv_GetPhysicalDeviceSurfacePresentModesKHR(
114 VkPhysicalDevice physicalDevice
,
115 VkSurfaceKHR _surface
,
116 uint32_t* pPresentModeCount
,
117 VkPresentModeKHR
* pPresentModes
)
119 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
120 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
121 struct anv_wsi_interface
*iface
= device
->wsi
[surface
->platform
];
123 return iface
->get_present_modes(surface
, device
, pPresentModeCount
,
127 VkResult
anv_CreateSwapchainKHR(
129 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
130 const VkAllocationCallbacks
* pAllocator
,
131 VkSwapchainKHR
* pSwapchain
)
133 ANV_FROM_HANDLE(anv_device
, device
, _device
);
134 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, pCreateInfo
->surface
);
135 struct anv_wsi_interface
*iface
=
136 device
->instance
->physicalDevice
.wsi
[surface
->platform
];
137 struct anv_swapchain
*swapchain
;
139 VkResult result
= iface
->create_swapchain(surface
, device
, pCreateInfo
,
140 pAllocator
, &swapchain
);
141 if (result
!= VK_SUCCESS
)
145 swapchain
->alloc
= *pAllocator
;
147 swapchain
->alloc
= device
->alloc
;
149 for (unsigned i
= 0; i
< ARRAY_SIZE(swapchain
->fences
); i
++)
150 swapchain
->fences
[i
] = VK_NULL_HANDLE
;
152 *pSwapchain
= anv_swapchain_to_handle(swapchain
);
157 void anv_DestroySwapchainKHR(
159 VkSwapchainKHR _swapchain
,
160 const VkAllocationCallbacks
* pAllocator
)
162 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
164 for (unsigned i
= 0; i
< ARRAY_SIZE(swapchain
->fences
); i
++) {
165 if (swapchain
->fences
[i
] != VK_NULL_HANDLE
)
166 anv_DestroyFence(device
, swapchain
->fences
[i
], pAllocator
);
169 swapchain
->destroy(swapchain
, pAllocator
);
172 VkResult
anv_GetSwapchainImagesKHR(
174 VkSwapchainKHR _swapchain
,
175 uint32_t* pSwapchainImageCount
,
176 VkImage
* pSwapchainImages
)
178 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
180 return swapchain
->get_images(swapchain
, pSwapchainImageCount
,
184 VkResult
anv_AcquireNextImageKHR(
186 VkSwapchainKHR _swapchain
,
188 VkSemaphore semaphore
,
190 uint32_t* pImageIndex
)
192 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
194 return swapchain
->acquire_next_image(swapchain
, timeout
, semaphore
,
198 VkResult
anv_QueuePresentKHR(
200 const VkPresentInfoKHR
* pPresentInfo
)
202 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
205 for (uint32_t i
= 0; i
< pPresentInfo
->swapchainCount
; i
++) {
206 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, pPresentInfo
->pSwapchains
[i
]);
208 assert(swapchain
->device
== queue
->device
);
210 if (swapchain
->fences
[0] == VK_NULL_HANDLE
) {
211 result
= anv_CreateFence(anv_device_to_handle(queue
->device
),
212 &(VkFenceCreateInfo
) {
213 .sType
= VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
,
215 }, &swapchain
->alloc
, &swapchain
->fences
[0]);
216 if (result
!= VK_SUCCESS
)
219 anv_ResetFences(anv_device_to_handle(queue
->device
),
220 1, &swapchain
->fences
[0]);
223 anv_QueueSubmit(_queue
, 0, NULL
, swapchain
->fences
[0]);
225 result
= swapchain
->queue_present(swapchain
, queue
,
226 pPresentInfo
->pImageIndices
[i
]);
227 /* TODO: What if one of them returns OUT_OF_DATE? */
228 if (result
!= VK_SUCCESS
)
231 VkFence last
= swapchain
->fences
[2];
232 swapchain
->fences
[2] = swapchain
->fences
[1];
233 swapchain
->fences
[1] = swapchain
->fences
[0];
234 swapchain
->fences
[0] = last
;
236 if (last
!= VK_NULL_HANDLE
) {
237 anv_WaitForFences(anv_device_to_handle(queue
->device
),