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 memset(instance
->wsi_impl
, 0, sizeof(instance
->wsi_impl
));
33 result
= anv_x11_init_wsi(instance
);
34 if (result
!= VK_SUCCESS
)
37 #ifdef HAVE_WAYLAND_PLATFORM
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 HAVE_WAYLAND_PLATFORM
52 anv_wl_finish_wsi(instance
);
54 anv_x11_finish_wsi(instance
);
58 anv_GetPhysicalDeviceSurfaceSupportKHR(
59 VkPhysicalDevice physicalDevice
,
60 uint32_t queueFamilyIndex
,
61 const VkSurfaceDescriptionKHR
* pSurfaceDescription
,
64 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
66 assert(pSurfaceDescription
->sType
==
67 VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_KHR
);
69 VkSurfaceDescriptionWindowKHR
*window
= (void *)pSurfaceDescription
;
71 struct anv_wsi_implementation
*impl
=
72 physical_device
->instance
->wsi_impl
[window
->platform
];
75 return impl
->get_window_supported(impl
, physical_device
,
84 anv_GetSurfacePropertiesKHR(
86 const VkSurfaceDescriptionKHR
* pSurfaceDescription
,
87 VkSurfacePropertiesKHR
* pSurfaceProperties
)
89 ANV_FROM_HANDLE(anv_device
, device
, _device
);
91 assert(pSurfaceDescription
->sType
==
92 VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_KHR
);
93 VkSurfaceDescriptionWindowKHR
*window
=
94 (VkSurfaceDescriptionWindowKHR
*)pSurfaceDescription
;
96 struct anv_wsi_implementation
*impl
=
97 device
->instance
->wsi_impl
[window
->platform
];
101 return impl
->get_surface_properties(impl
, device
, window
,
106 anv_GetSurfaceFormatsKHR(
108 const VkSurfaceDescriptionKHR
* pSurfaceDescription
,
110 VkSurfaceFormatKHR
* pSurfaceFormats
)
112 ANV_FROM_HANDLE(anv_device
, device
, _device
);
114 assert(pSurfaceDescription
->sType
==
115 VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_KHR
);
116 VkSurfaceDescriptionWindowKHR
*window
=
117 (VkSurfaceDescriptionWindowKHR
*)pSurfaceDescription
;
119 struct anv_wsi_implementation
*impl
=
120 device
->instance
->wsi_impl
[window
->platform
];
124 return impl
->get_surface_formats(impl
, device
, window
,
125 pCount
, pSurfaceFormats
);
129 anv_GetSurfacePresentModesKHR(
131 const VkSurfaceDescriptionKHR
* pSurfaceDescription
,
133 VkPresentModeKHR
* pPresentModes
)
135 ANV_FROM_HANDLE(anv_device
, device
, _device
);
137 assert(pSurfaceDescription
->sType
==
138 VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_KHR
);
139 VkSurfaceDescriptionWindowKHR
*window
=
140 (VkSurfaceDescriptionWindowKHR
*)pSurfaceDescription
;
142 struct anv_wsi_implementation
*impl
=
143 device
->instance
->wsi_impl
[window
->platform
];
147 return impl
->get_surface_present_modes(impl
, device
, window
,
148 pCount
, pPresentModes
);
153 anv_CreateSwapchainKHR(
155 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
156 VkSwapchainKHR
* pSwapchain
)
158 ANV_FROM_HANDLE(anv_device
, device
, _device
);
159 struct anv_swapchain
*swapchain
;
162 assert(pCreateInfo
->pSurfaceDescription
->sType
==
163 VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_KHR
);
164 VkSurfaceDescriptionWindowKHR
*window
=
165 (VkSurfaceDescriptionWindowKHR
*)pCreateInfo
->pSurfaceDescription
;
167 struct anv_wsi_implementation
*impl
=
168 device
->instance
->wsi_impl
[window
->platform
];
172 result
= impl
->create_swapchain(impl
, device
, pCreateInfo
, &swapchain
);
174 if (result
== VK_SUCCESS
)
175 *pSwapchain
= anv_swapchain_to_handle(swapchain
);
181 anv_DestroySwapchainKHR(
183 VkSwapchainKHR swapChain
)
185 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, swapChain
);
187 assert(swapchain
->device
== anv_device_from_handle(device
));
189 return swapchain
->destroy(swapchain
);
193 anv_GetSwapchainImagesKHR(
195 VkSwapchainKHR _swapchain
,
197 VkImage
* pSwapchainImages
)
199 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
201 assert(swapchain
->device
== anv_device_from_handle(device
));
203 return swapchain
->get_images(swapchain
, pCount
, pSwapchainImages
);
207 anv_AcquireNextImageKHR(
209 VkSwapchainKHR _swapchain
,
211 VkSemaphore semaphore
,
212 uint32_t* pImageIndex
)
214 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
216 assert(swapchain
->device
== anv_device_from_handle(device
));
218 return swapchain
->acquire_next_image(swapchain
,
219 timeout
, semaphore
, pImageIndex
);
225 VkPresentInfoKHR
* pPresentInfo
)
227 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
230 for (uint32_t i
= 0; i
< pPresentInfo
->swapchainCount
; i
++) {
231 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, pPresentInfo
->swapchains
[i
]);
233 assert(swapchain
->device
== queue
->device
);
235 result
= swapchain
->queue_present(swapchain
, queue
,
236 pPresentInfo
->imageIndices
[i
]);
237 /* TODO: What if one of them returns OUT_OF_DATE? */
238 if (result
!= VK_SUCCESS
)