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_device
.wsi
, 0, sizeof(physical_device
->wsi_device
.wsi
));
33 #ifdef VK_USE_PLATFORM_XCB_KHR
34 result
= anv_x11_init_wsi(&physical_device
->wsi_device
, &physical_device
->instance
->alloc
);
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
->wsi_device
, &physical_device
->instance
->alloc
);
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
->wsi_device
, &physical_device
->instance
->alloc
);
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 vk_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_device
.wsi
[surface
->platform
];
84 return iface
->get_support(surface
, &device
->wsi_device
,
85 &device
->instance
->alloc
,
86 queueFamilyIndex
, pSupported
);
89 VkResult
anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
90 VkPhysicalDevice physicalDevice
,
91 VkSurfaceKHR _surface
,
92 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
94 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
95 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
96 struct anv_wsi_interface
*iface
= device
->wsi_device
.wsi
[surface
->platform
];
98 return iface
->get_capabilities(surface
, pSurfaceCapabilities
);
101 VkResult
anv_GetPhysicalDeviceSurfaceFormatsKHR(
102 VkPhysicalDevice physicalDevice
,
103 VkSurfaceKHR _surface
,
104 uint32_t* pSurfaceFormatCount
,
105 VkSurfaceFormatKHR
* pSurfaceFormats
)
107 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
108 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
109 struct anv_wsi_interface
*iface
= device
->wsi_device
.wsi
[surface
->platform
];
111 return iface
->get_formats(surface
, &device
->wsi_device
, pSurfaceFormatCount
,
115 VkResult
anv_GetPhysicalDeviceSurfacePresentModesKHR(
116 VkPhysicalDevice physicalDevice
,
117 VkSurfaceKHR _surface
,
118 uint32_t* pPresentModeCount
,
119 VkPresentModeKHR
* pPresentModes
)
121 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
122 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, _surface
);
123 struct anv_wsi_interface
*iface
= device
->wsi_device
.wsi
[surface
->platform
];
125 return iface
->get_present_modes(surface
, pPresentModeCount
,
129 VkResult
anv_CreateSwapchainKHR(
131 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
132 const VkAllocationCallbacks
* pAllocator
,
133 VkSwapchainKHR
* pSwapchain
)
135 ANV_FROM_HANDLE(anv_device
, device
, _device
);
136 ANV_FROM_HANDLE(_VkIcdSurfaceBase
, surface
, pCreateInfo
->surface
);
137 struct anv_wsi_interface
*iface
=
138 device
->instance
->physicalDevice
.wsi_device
.wsi
[surface
->platform
];
139 struct anv_swapchain
*swapchain
;
141 VkResult result
= iface
->create_swapchain(surface
, device
, pCreateInfo
,
142 pAllocator
, &swapchain
);
143 if (result
!= VK_SUCCESS
)
147 swapchain
->alloc
= *pAllocator
;
149 swapchain
->alloc
= device
->alloc
;
151 for (unsigned i
= 0; i
< ARRAY_SIZE(swapchain
->fences
); i
++)
152 swapchain
->fences
[i
] = VK_NULL_HANDLE
;
154 *pSwapchain
= anv_swapchain_to_handle(swapchain
);
159 void anv_DestroySwapchainKHR(
161 VkSwapchainKHR _swapchain
,
162 const VkAllocationCallbacks
* pAllocator
)
164 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
166 for (unsigned i
= 0; i
< ARRAY_SIZE(swapchain
->fences
); i
++) {
167 if (swapchain
->fences
[i
] != VK_NULL_HANDLE
)
168 anv_DestroyFence(device
, swapchain
->fences
[i
], pAllocator
);
171 swapchain
->destroy(swapchain
, pAllocator
);
174 VkResult
anv_GetSwapchainImagesKHR(
176 VkSwapchainKHR _swapchain
,
177 uint32_t* pSwapchainImageCount
,
178 VkImage
* pSwapchainImages
)
180 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
182 return swapchain
->get_images(swapchain
, pSwapchainImageCount
,
186 VkResult
anv_AcquireNextImageKHR(
188 VkSwapchainKHR _swapchain
,
190 VkSemaphore semaphore
,
192 uint32_t* pImageIndex
)
194 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, _swapchain
);
196 return swapchain
->acquire_next_image(swapchain
, timeout
, semaphore
,
200 VkResult
anv_QueuePresentKHR(
202 const VkPresentInfoKHR
* pPresentInfo
)
204 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
207 for (uint32_t i
= 0; i
< pPresentInfo
->swapchainCount
; i
++) {
208 ANV_FROM_HANDLE(anv_swapchain
, swapchain
, pPresentInfo
->pSwapchains
[i
]);
210 assert(swapchain
->device
== queue
->device
);
212 if (swapchain
->fences
[0] == VK_NULL_HANDLE
) {
213 result
= anv_CreateFence(anv_device_to_handle(queue
->device
),
214 &(VkFenceCreateInfo
) {
215 .sType
= VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
,
217 }, &swapchain
->alloc
, &swapchain
->fences
[0]);
218 if (result
!= VK_SUCCESS
)
221 anv_ResetFences(anv_device_to_handle(queue
->device
),
222 1, &swapchain
->fences
[0]);
225 anv_QueueSubmit(_queue
, 0, NULL
, swapchain
->fences
[0]);
227 result
= swapchain
->queue_present(swapchain
,
228 pPresentInfo
->pImageIndices
[i
]);
229 /* TODO: What if one of them returns OUT_OF_DATE? */
230 if (result
!= VK_SUCCESS
)
233 VkFence last
= swapchain
->fences
[2];
234 swapchain
->fences
[2] = swapchain
->fences
[1];
235 swapchain
->fences
[1] = swapchain
->fences
[0];
236 swapchain
->fences
[0] = last
;
238 if (last
!= VK_NULL_HANDLE
) {
239 anv_WaitForFences(anv_device_to_handle(queue
->device
),