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
24 #include "anv_private.h"
25 #include "wsi_common.h"
26 #include "vk_format_info.h"
29 static PFN_vkVoidFunction
30 anv_wsi_proc_addr(VkPhysicalDevice physicalDevice
, const char *pName
)
32 ANV_FROM_HANDLE(anv_physical_device
, physical_device
, physicalDevice
);
33 return anv_lookup_entrypoint(&physical_device
->info
, pName
);
37 anv_init_wsi(struct anv_physical_device
*physical_device
)
39 return wsi_device_init(&physical_device
->wsi_device
,
40 anv_physical_device_to_handle(physical_device
),
42 &physical_device
->instance
->alloc
);
46 anv_finish_wsi(struct anv_physical_device
*physical_device
)
48 wsi_device_finish(&physical_device
->wsi_device
,
49 &physical_device
->instance
->alloc
);
52 void anv_DestroySurfaceKHR(
54 VkSurfaceKHR _surface
,
55 const VkAllocationCallbacks
* pAllocator
)
57 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
58 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
63 vk_free2(&instance
->alloc
, pAllocator
, surface
);
66 VkResult
anv_GetPhysicalDeviceSurfaceSupportKHR(
67 VkPhysicalDevice physicalDevice
,
68 uint32_t queueFamilyIndex
,
72 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
74 return wsi_common_get_surface_support(&device
->wsi_device
,
78 &device
->instance
->alloc
,
82 VkResult
anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
83 VkPhysicalDevice physicalDevice
,
85 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
87 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
89 return wsi_common_get_surface_capabilities(&device
->wsi_device
,
91 pSurfaceCapabilities
);
94 VkResult
anv_GetPhysicalDeviceSurfaceCapabilities2KHR(
95 VkPhysicalDevice physicalDevice
,
96 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
97 VkSurfaceCapabilities2KHR
* pSurfaceCapabilities
)
99 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
101 return wsi_common_get_surface_capabilities2(&device
->wsi_device
,
103 pSurfaceCapabilities
);
106 VkResult
anv_GetPhysicalDeviceSurfaceFormatsKHR(
107 VkPhysicalDevice physicalDevice
,
108 VkSurfaceKHR surface
,
109 uint32_t* pSurfaceFormatCount
,
110 VkSurfaceFormatKHR
* pSurfaceFormats
)
112 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
114 return wsi_common_get_surface_formats(&device
->wsi_device
, surface
,
115 pSurfaceFormatCount
, pSurfaceFormats
);
118 VkResult
anv_GetPhysicalDeviceSurfaceFormats2KHR(
119 VkPhysicalDevice physicalDevice
,
120 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
121 uint32_t* pSurfaceFormatCount
,
122 VkSurfaceFormat2KHR
* pSurfaceFormats
)
124 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
126 return wsi_common_get_surface_formats2(&device
->wsi_device
, pSurfaceInfo
,
127 pSurfaceFormatCount
, pSurfaceFormats
);
130 VkResult
anv_GetPhysicalDeviceSurfacePresentModesKHR(
131 VkPhysicalDevice physicalDevice
,
132 VkSurfaceKHR surface
,
133 uint32_t* pPresentModeCount
,
134 VkPresentModeKHR
* pPresentModes
)
136 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
138 return wsi_common_get_surface_present_modes(&device
->wsi_device
, surface
,
143 VkResult
anv_CreateSwapchainKHR(
145 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
146 const VkAllocationCallbacks
* pAllocator
,
147 VkSwapchainKHR
* pSwapchain
)
149 ANV_FROM_HANDLE(anv_device
, device
, _device
);
150 struct wsi_device
*wsi_device
= &device
->instance
->physicalDevice
.wsi_device
;
151 const VkAllocationCallbacks
*alloc
;
156 alloc
= &device
->alloc
;
158 return wsi_common_create_swapchain(wsi_device
, _device
, device
->fd
,
159 pCreateInfo
, alloc
, pSwapchain
);
162 void anv_DestroySwapchainKHR(
164 VkSwapchainKHR swapchain
,
165 const VkAllocationCallbacks
* pAllocator
)
167 ANV_FROM_HANDLE(anv_device
, device
, _device
);
168 const VkAllocationCallbacks
*alloc
;
173 alloc
= &device
->alloc
;
175 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
178 VkResult
anv_GetSwapchainImagesKHR(
180 VkSwapchainKHR swapchain
,
181 uint32_t* pSwapchainImageCount
,
182 VkImage
* pSwapchainImages
)
184 return wsi_common_get_images(swapchain
,
185 pSwapchainImageCount
,
189 VkResult
anv_AcquireNextImageKHR(
191 VkSwapchainKHR swapchain
,
193 VkSemaphore semaphore
,
195 uint32_t* pImageIndex
)
197 ANV_FROM_HANDLE(anv_device
, device
, _device
);
198 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
200 VkResult result
= wsi_common_acquire_next_image(&pdevice
->wsi_device
,
207 /* Thanks to implicit sync, the image is ready immediately. However, we
208 * should wait for the current GPU state to finish.
210 if (fence
!= VK_NULL_HANDLE
)
211 anv_QueueSubmit(anv_queue_to_handle(&device
->queue
), 0, NULL
, fence
);
216 VkResult
anv_QueuePresentKHR(
218 const VkPresentInfoKHR
* pPresentInfo
)
220 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
221 struct anv_physical_device
*pdevice
=
222 &queue
->device
->instance
->physicalDevice
;
224 return wsi_common_queue_present(&pdevice
->wsi_device
,
225 anv_device_to_handle(queue
->device
),