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 if (result
!= VK_SUCCESS
)
55 physical_device
->wsi_device
.supports_modifiers
= true;
56 physical_device
->wsi_device
.image_get_modifier
= anv_wsi_image_get_modifier
;
62 anv_finish_wsi(struct anv_physical_device
*physical_device
)
64 wsi_device_finish(&physical_device
->wsi_device
,
65 &physical_device
->instance
->alloc
);
68 void anv_DestroySurfaceKHR(
70 VkSurfaceKHR _surface
,
71 const VkAllocationCallbacks
* pAllocator
)
73 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
74 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
79 vk_free2(&instance
->alloc
, pAllocator
, surface
);
82 VkResult
anv_GetPhysicalDeviceSurfaceSupportKHR(
83 VkPhysicalDevice physicalDevice
,
84 uint32_t queueFamilyIndex
,
88 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
90 return wsi_common_get_surface_support(&device
->wsi_device
,
94 &device
->instance
->alloc
,
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_GetPhysicalDeviceSurfaceFormatsKHR(
123 VkPhysicalDevice physicalDevice
,
124 VkSurfaceKHR surface
,
125 uint32_t* pSurfaceFormatCount
,
126 VkSurfaceFormatKHR
* pSurfaceFormats
)
128 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
130 return wsi_common_get_surface_formats(&device
->wsi_device
, surface
,
131 pSurfaceFormatCount
, pSurfaceFormats
);
134 VkResult
anv_GetPhysicalDeviceSurfaceFormats2KHR(
135 VkPhysicalDevice physicalDevice
,
136 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
137 uint32_t* pSurfaceFormatCount
,
138 VkSurfaceFormat2KHR
* pSurfaceFormats
)
140 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
142 return wsi_common_get_surface_formats2(&device
->wsi_device
, pSurfaceInfo
,
143 pSurfaceFormatCount
, pSurfaceFormats
);
146 VkResult
anv_GetPhysicalDeviceSurfacePresentModesKHR(
147 VkPhysicalDevice physicalDevice
,
148 VkSurfaceKHR surface
,
149 uint32_t* pPresentModeCount
,
150 VkPresentModeKHR
* pPresentModes
)
152 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
154 return wsi_common_get_surface_present_modes(&device
->wsi_device
, surface
,
159 VkResult
anv_CreateSwapchainKHR(
161 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
162 const VkAllocationCallbacks
* pAllocator
,
163 VkSwapchainKHR
* pSwapchain
)
165 ANV_FROM_HANDLE(anv_device
, device
, _device
);
166 struct wsi_device
*wsi_device
= &device
->instance
->physicalDevice
.wsi_device
;
167 const VkAllocationCallbacks
*alloc
;
172 alloc
= &device
->alloc
;
174 return wsi_common_create_swapchain(wsi_device
, _device
, device
->fd
,
175 pCreateInfo
, alloc
, pSwapchain
);
178 void anv_DestroySwapchainKHR(
180 VkSwapchainKHR swapchain
,
181 const VkAllocationCallbacks
* pAllocator
)
183 ANV_FROM_HANDLE(anv_device
, device
, _device
);
184 const VkAllocationCallbacks
*alloc
;
189 alloc
= &device
->alloc
;
191 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
194 VkResult
anv_GetSwapchainImagesKHR(
196 VkSwapchainKHR swapchain
,
197 uint32_t* pSwapchainImageCount
,
198 VkImage
* pSwapchainImages
)
200 return wsi_common_get_images(swapchain
,
201 pSwapchainImageCount
,
205 VkResult
anv_AcquireNextImageKHR(
207 VkSwapchainKHR swapchain
,
209 VkSemaphore semaphore
,
211 uint32_t* pImageIndex
)
213 ANV_FROM_HANDLE(anv_device
, device
, _device
);
214 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
216 VkResult result
= wsi_common_acquire_next_image(&pdevice
->wsi_device
,
223 /* Thanks to implicit sync, the image is ready immediately. However, we
224 * should wait for the current GPU state to finish.
226 if (fence
!= VK_NULL_HANDLE
)
227 anv_QueueSubmit(anv_queue_to_handle(&device
->queue
), 0, NULL
, fence
);
232 VkResult
anv_QueuePresentKHR(
234 const VkPresentInfoKHR
* pPresentInfo
)
236 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
237 struct anv_physical_device
*pdevice
=
238 &queue
->device
->instance
->physicalDevice
;
240 return wsi_common_queue_present(&pdevice
->wsi_device
,
241 anv_device_to_handle(queue
->device
),