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_wsi_image_get_modifier(VkImage _image
)
39 ANV_FROM_HANDLE(anv_image
, image
, _image
);
40 return image
->drm_format_mod
;
44 anv_init_wsi(struct anv_physical_device
*physical_device
)
48 result
= wsi_device_init(&physical_device
->wsi_device
,
49 anv_physical_device_to_handle(physical_device
),
51 &physical_device
->instance
->alloc
,
52 physical_device
->master_fd
);
53 if (result
!= VK_SUCCESS
)
56 physical_device
->wsi_device
.supports_modifiers
= true;
57 physical_device
->wsi_device
.image_get_modifier
= anv_wsi_image_get_modifier
;
63 anv_finish_wsi(struct anv_physical_device
*physical_device
)
65 wsi_device_finish(&physical_device
->wsi_device
,
66 &physical_device
->instance
->alloc
);
69 void anv_DestroySurfaceKHR(
71 VkSurfaceKHR _surface
,
72 const VkAllocationCallbacks
* pAllocator
)
74 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
75 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
80 vk_free2(&instance
->alloc
, pAllocator
, surface
);
83 VkResult
anv_GetPhysicalDeviceSurfaceSupportKHR(
84 VkPhysicalDevice physicalDevice
,
85 uint32_t queueFamilyIndex
,
89 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
91 return wsi_common_get_surface_support(&device
->wsi_device
,
98 VkResult
anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
99 VkPhysicalDevice physicalDevice
,
100 VkSurfaceKHR surface
,
101 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
103 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
105 return wsi_common_get_surface_capabilities(&device
->wsi_device
,
107 pSurfaceCapabilities
);
110 VkResult
anv_GetPhysicalDeviceSurfaceCapabilities2KHR(
111 VkPhysicalDevice physicalDevice
,
112 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
113 VkSurfaceCapabilities2KHR
* pSurfaceCapabilities
)
115 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
117 return wsi_common_get_surface_capabilities2(&device
->wsi_device
,
119 pSurfaceCapabilities
);
122 VkResult
anv_GetPhysicalDeviceSurfaceCapabilities2EXT(
123 VkPhysicalDevice physicalDevice
,
124 VkSurfaceKHR surface
,
125 VkSurfaceCapabilities2EXT
* pSurfaceCapabilities
)
127 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
129 return wsi_common_get_surface_capabilities2ext(&device
->wsi_device
,
131 pSurfaceCapabilities
);
134 VkResult
anv_GetPhysicalDeviceSurfaceFormatsKHR(
135 VkPhysicalDevice physicalDevice
,
136 VkSurfaceKHR surface
,
137 uint32_t* pSurfaceFormatCount
,
138 VkSurfaceFormatKHR
* pSurfaceFormats
)
140 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
142 return wsi_common_get_surface_formats(&device
->wsi_device
, surface
,
143 pSurfaceFormatCount
, pSurfaceFormats
);
146 VkResult
anv_GetPhysicalDeviceSurfaceFormats2KHR(
147 VkPhysicalDevice physicalDevice
,
148 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
149 uint32_t* pSurfaceFormatCount
,
150 VkSurfaceFormat2KHR
* pSurfaceFormats
)
152 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
154 return wsi_common_get_surface_formats2(&device
->wsi_device
, pSurfaceInfo
,
155 pSurfaceFormatCount
, pSurfaceFormats
);
158 VkResult
anv_GetPhysicalDeviceSurfacePresentModesKHR(
159 VkPhysicalDevice physicalDevice
,
160 VkSurfaceKHR surface
,
161 uint32_t* pPresentModeCount
,
162 VkPresentModeKHR
* pPresentModes
)
164 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
166 return wsi_common_get_surface_present_modes(&device
->wsi_device
, surface
,
171 VkResult
anv_CreateSwapchainKHR(
173 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
174 const VkAllocationCallbacks
* pAllocator
,
175 VkSwapchainKHR
* pSwapchain
)
177 ANV_FROM_HANDLE(anv_device
, device
, _device
);
178 struct wsi_device
*wsi_device
= &device
->instance
->physicalDevice
.wsi_device
;
179 const VkAllocationCallbacks
*alloc
;
184 alloc
= &device
->alloc
;
186 return wsi_common_create_swapchain(wsi_device
, _device
, device
->fd
,
187 pCreateInfo
, alloc
, pSwapchain
);
190 void anv_DestroySwapchainKHR(
192 VkSwapchainKHR swapchain
,
193 const VkAllocationCallbacks
* pAllocator
)
195 ANV_FROM_HANDLE(anv_device
, device
, _device
);
196 const VkAllocationCallbacks
*alloc
;
201 alloc
= &device
->alloc
;
203 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
206 VkResult
anv_GetSwapchainImagesKHR(
208 VkSwapchainKHR swapchain
,
209 uint32_t* pSwapchainImageCount
,
210 VkImage
* pSwapchainImages
)
212 return wsi_common_get_images(swapchain
,
213 pSwapchainImageCount
,
217 VkResult
anv_AcquireNextImageKHR(
219 VkSwapchainKHR swapchain
,
221 VkSemaphore semaphore
,
223 uint32_t* pImageIndex
)
225 VkAcquireNextImageInfoKHR acquire_info
= {
226 .sType
= VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR
,
227 .swapchain
= swapchain
,
229 .semaphore
= semaphore
,
234 return anv_AcquireNextImage2KHR(device
, &acquire_info
, pImageIndex
);
237 VkResult
anv_AcquireNextImage2KHR(
239 const VkAcquireNextImageInfoKHR
* pAcquireInfo
,
240 uint32_t* pImageIndex
)
242 ANV_FROM_HANDLE(anv_device
, device
, _device
);
243 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
245 VkResult result
= wsi_common_acquire_next_image2(&pdevice
->wsi_device
,
250 /* Thanks to implicit sync, the image is ready immediately. However, we
251 * should wait for the current GPU state to finish.
253 if (pAcquireInfo
->fence
!= VK_NULL_HANDLE
) {
254 anv_QueueSubmit(anv_queue_to_handle(&device
->queue
), 0, NULL
,
255 pAcquireInfo
->fence
);
261 VkResult
anv_QueuePresentKHR(
263 const VkPresentInfoKHR
* pPresentInfo
)
265 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
266 struct anv_physical_device
*pdevice
=
267 &queue
->device
->instance
->physicalDevice
;
269 return wsi_common_queue_present(&pdevice
->wsi_device
,
270 anv_device_to_handle(queue
->device
),
275 VkResult
anv_GetDeviceGroupPresentCapabilitiesKHR(
277 VkDeviceGroupPresentCapabilitiesKHR
* pCapabilities
)
279 memset(pCapabilities
->presentMask
, 0,
280 sizeof(pCapabilities
->presentMask
));
281 pCapabilities
->presentMask
[0] = 0x1;
282 pCapabilities
->modes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
287 VkResult
anv_GetDeviceGroupSurfacePresentModesKHR(
289 VkSurfaceKHR surface
,
290 VkDeviceGroupPresentModeFlagsKHR
* pModes
)
292 *pModes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
297 VkResult
anv_GetPhysicalDevicePresentRectanglesKHR(
298 VkPhysicalDevice physicalDevice
,
299 VkSurfaceKHR surface
,
300 uint32_t* pRectCount
,
303 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
305 return wsi_common_get_present_rectangles(&device
->wsi_device
,