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
,
97 VkResult
anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
98 VkPhysicalDevice physicalDevice
,
100 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
102 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
104 return wsi_common_get_surface_capabilities(&device
->wsi_device
,
106 pSurfaceCapabilities
);
109 VkResult
anv_GetPhysicalDeviceSurfaceCapabilities2KHR(
110 VkPhysicalDevice physicalDevice
,
111 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
112 VkSurfaceCapabilities2KHR
* pSurfaceCapabilities
)
114 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
116 return wsi_common_get_surface_capabilities2(&device
->wsi_device
,
118 pSurfaceCapabilities
);
121 VkResult
anv_GetPhysicalDeviceSurfaceCapabilities2EXT(
122 VkPhysicalDevice physicalDevice
,
123 VkSurfaceKHR surface
,
124 VkSurfaceCapabilities2EXT
* pSurfaceCapabilities
)
126 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
128 return wsi_common_get_surface_capabilities2ext(&device
->wsi_device
,
130 pSurfaceCapabilities
);
133 VkResult
anv_GetPhysicalDeviceSurfaceFormatsKHR(
134 VkPhysicalDevice physicalDevice
,
135 VkSurfaceKHR surface
,
136 uint32_t* pSurfaceFormatCount
,
137 VkSurfaceFormatKHR
* pSurfaceFormats
)
139 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
141 return wsi_common_get_surface_formats(&device
->wsi_device
, surface
,
142 pSurfaceFormatCount
, pSurfaceFormats
);
145 VkResult
anv_GetPhysicalDeviceSurfaceFormats2KHR(
146 VkPhysicalDevice physicalDevice
,
147 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
148 uint32_t* pSurfaceFormatCount
,
149 VkSurfaceFormat2KHR
* pSurfaceFormats
)
151 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
153 return wsi_common_get_surface_formats2(&device
->wsi_device
, pSurfaceInfo
,
154 pSurfaceFormatCount
, pSurfaceFormats
);
157 VkResult
anv_GetPhysicalDeviceSurfacePresentModesKHR(
158 VkPhysicalDevice physicalDevice
,
159 VkSurfaceKHR surface
,
160 uint32_t* pPresentModeCount
,
161 VkPresentModeKHR
* pPresentModes
)
163 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
165 return wsi_common_get_surface_present_modes(&device
->wsi_device
, surface
,
170 VkResult
anv_CreateSwapchainKHR(
172 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
173 const VkAllocationCallbacks
* pAllocator
,
174 VkSwapchainKHR
* pSwapchain
)
176 ANV_FROM_HANDLE(anv_device
, device
, _device
);
177 struct wsi_device
*wsi_device
= &device
->instance
->physicalDevice
.wsi_device
;
178 const VkAllocationCallbacks
*alloc
;
183 alloc
= &device
->alloc
;
185 return wsi_common_create_swapchain(wsi_device
, _device
,
186 pCreateInfo
, alloc
, pSwapchain
);
189 void anv_DestroySwapchainKHR(
191 VkSwapchainKHR swapchain
,
192 const VkAllocationCallbacks
* pAllocator
)
194 ANV_FROM_HANDLE(anv_device
, device
, _device
);
195 const VkAllocationCallbacks
*alloc
;
200 alloc
= &device
->alloc
;
202 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
205 VkResult
anv_GetSwapchainImagesKHR(
207 VkSwapchainKHR swapchain
,
208 uint32_t* pSwapchainImageCount
,
209 VkImage
* pSwapchainImages
)
211 return wsi_common_get_images(swapchain
,
212 pSwapchainImageCount
,
216 VkResult
anv_AcquireNextImageKHR(
218 VkSwapchainKHR swapchain
,
220 VkSemaphore semaphore
,
222 uint32_t* pImageIndex
)
224 VkAcquireNextImageInfoKHR acquire_info
= {
225 .sType
= VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR
,
226 .swapchain
= swapchain
,
228 .semaphore
= semaphore
,
233 return anv_AcquireNextImage2KHR(device
, &acquire_info
, pImageIndex
);
236 VkResult
anv_AcquireNextImage2KHR(
238 const VkAcquireNextImageInfoKHR
* pAcquireInfo
,
239 uint32_t* pImageIndex
)
241 ANV_FROM_HANDLE(anv_device
, device
, _device
);
242 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
244 VkResult result
= wsi_common_acquire_next_image2(&pdevice
->wsi_device
,
249 /* Thanks to implicit sync, the image is ready immediately. However, we
250 * should wait for the current GPU state to finish.
252 if (pAcquireInfo
->fence
!= VK_NULL_HANDLE
) {
253 anv_QueueSubmit(anv_queue_to_handle(&device
->queue
), 0, NULL
,
254 pAcquireInfo
->fence
);
260 VkResult
anv_QueuePresentKHR(
262 const VkPresentInfoKHR
* pPresentInfo
)
264 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
265 struct anv_physical_device
*pdevice
=
266 &queue
->device
->instance
->physicalDevice
;
268 return wsi_common_queue_present(&pdevice
->wsi_device
,
269 anv_device_to_handle(queue
->device
),
274 VkResult
anv_GetDeviceGroupPresentCapabilitiesKHR(
276 VkDeviceGroupPresentCapabilitiesKHR
* pCapabilities
)
278 memset(pCapabilities
->presentMask
, 0,
279 sizeof(pCapabilities
->presentMask
));
280 pCapabilities
->presentMask
[0] = 0x1;
281 pCapabilities
->modes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
286 VkResult
anv_GetDeviceGroupSurfacePresentModesKHR(
288 VkSurfaceKHR surface
,
289 VkDeviceGroupPresentModeFlagsKHR
* pModes
)
291 *pModes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
296 VkResult
anv_GetPhysicalDevicePresentRectanglesKHR(
297 VkPhysicalDevice physicalDevice
,
298 VkSurfaceKHR surface
,
299 uint32_t* pRectCount
,
302 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
304 return wsi_common_get_present_rectangles(&device
->wsi_device
,