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
)
136 swapchain
->alloc
= *pAllocator
;
138 swapchain
->alloc
= device
->alloc
;
140 for (unsigned i
= 0; i
< ARRAY_SIZE(swapchain
->fences
); i
++)
141 swapchain
->fences
[i
] = VK_NULL_HANDLE
;
143 *pSwapchain
= anv_swapchain_to_handle(swapchain
);
148 void anv_DestroySwapchainKHR(
150 VkSwapchainKHR _swapchain
,
151 const VkAllocationCallbacks
* pAllocator
)
153 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
155 for (unsigned i
= 0; i
< ARRAY_SIZE(swapchain
->fences
); i
++) {
156 if (swapchain
->fences
[i
] != VK_NULL_HANDLE
)
157 anv_DestroyFence(device
, swapchain
->fences
[i
], pAllocator
);
160 swapchain
->destroy(swapchain
, pAllocator
);
163 VkResult
anv_GetSwapchainImagesKHR(
165 VkSwapchainKHR _swapchain
,
166 uint32_t* pSwapchainImageCount
,
167 VkImage
* pSwapchainImages
)
169 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
171 return swapchain
->get_images(swapchain
, pSwapchainImageCount
,
175 VkResult
anv_AcquireNextImageKHR(
177 VkSwapchainKHR _swapchain
,
179 VkSemaphore semaphore
,
181 uint32_t* pImageIndex
)
183 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
185 return swapchain
->acquire_next_image(swapchain
, timeout
, semaphore
,
189 VkResult
anv_QueuePresentKHR(
191 const VkPresentInfoKHR
* pPresentInfo
)
193 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
196 for (uint32_t i
= 0; i
< pPresentInfo
->swapchainCount
; i
++) {
197 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, pPresentInfo
->pSwapchains
[i
]);
199 assert(swapchain
->device
== queue
->device
);
201 if (swapchain
->fences
[0] == VK_NULL_HANDLE
) {
202 result
= anv_CreateFence(anv_device_to_handle(queue
->device
),
203 &(VkFenceCreateInfo
) {
204 .sType
= VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
,
206 }, &swapchain
->alloc
, &swapchain
->fences
[0]);
207 if (result
!= VK_SUCCESS
)
210 anv_ResetFences(anv_device_to_handle(queue
->device
),
211 1, &swapchain
->fences
[0]);
214 anv_QueueSubmit(_queue
, 0, NULL
, swapchain
->fences
[0]);
216 result
= swapchain
->queue_present(swapchain
, queue
,
217 pPresentInfo
->pImageIndices
[i
]);
218 /* TODO: What if one of them returns OUT_OF_DATE? */
219 if (result
!= VK_SUCCESS
)
222 VkFence last
= swapchain
->fences
[2];
223 swapchain
->fences
[2] = swapchain
->fences
[1];
224 swapchain
->fences
[1] = swapchain
->fences
[0];
225 swapchain
->fences
[0] = last
;
227 if (last
!= VK_NULL_HANDLE
) {
228 anv_WaitForFences(anv_device_to_handle(queue
->device
),