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
,
95 &device
->instance
->alloc
,
99 VkResult
anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
100 VkPhysicalDevice physicalDevice
,
101 VkSurfaceKHR surface
,
102 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
104 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
106 return wsi_common_get_surface_capabilities(&device
->wsi_device
,
108 pSurfaceCapabilities
);
111 VkResult
anv_GetPhysicalDeviceSurfaceCapabilities2KHR(
112 VkPhysicalDevice physicalDevice
,
113 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
114 VkSurfaceCapabilities2KHR
* pSurfaceCapabilities
)
116 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
118 return wsi_common_get_surface_capabilities2(&device
->wsi_device
,
120 pSurfaceCapabilities
);
123 VkResult
anv_GetPhysicalDeviceSurfaceCapabilities2EXT(
124 VkPhysicalDevice physicalDevice
,
125 VkSurfaceKHR surface
,
126 VkSurfaceCapabilities2EXT
* pSurfaceCapabilities
)
128 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
130 return wsi_common_get_surface_capabilities2ext(&device
->wsi_device
,
132 pSurfaceCapabilities
);
135 VkResult
anv_GetPhysicalDeviceSurfaceFormatsKHR(
136 VkPhysicalDevice physicalDevice
,
137 VkSurfaceKHR surface
,
138 uint32_t* pSurfaceFormatCount
,
139 VkSurfaceFormatKHR
* pSurfaceFormats
)
141 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
143 return wsi_common_get_surface_formats(&device
->wsi_device
, surface
,
144 pSurfaceFormatCount
, pSurfaceFormats
);
147 VkResult
anv_GetPhysicalDeviceSurfaceFormats2KHR(
148 VkPhysicalDevice physicalDevice
,
149 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
150 uint32_t* pSurfaceFormatCount
,
151 VkSurfaceFormat2KHR
* pSurfaceFormats
)
153 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
155 return wsi_common_get_surface_formats2(&device
->wsi_device
, pSurfaceInfo
,
156 pSurfaceFormatCount
, pSurfaceFormats
);
159 VkResult
anv_GetPhysicalDeviceSurfacePresentModesKHR(
160 VkPhysicalDevice physicalDevice
,
161 VkSurfaceKHR surface
,
162 uint32_t* pPresentModeCount
,
163 VkPresentModeKHR
* pPresentModes
)
165 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
167 return wsi_common_get_surface_present_modes(&device
->wsi_device
, surface
,
172 VkResult
anv_CreateSwapchainKHR(
174 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
175 const VkAllocationCallbacks
* pAllocator
,
176 VkSwapchainKHR
* pSwapchain
)
178 ANV_FROM_HANDLE(anv_device
, device
, _device
);
179 struct wsi_device
*wsi_device
= &device
->instance
->physicalDevice
.wsi_device
;
180 const VkAllocationCallbacks
*alloc
;
185 alloc
= &device
->alloc
;
187 return wsi_common_create_swapchain(wsi_device
, _device
, device
->fd
,
188 pCreateInfo
, alloc
, pSwapchain
);
191 void anv_DestroySwapchainKHR(
193 VkSwapchainKHR swapchain
,
194 const VkAllocationCallbacks
* pAllocator
)
196 ANV_FROM_HANDLE(anv_device
, device
, _device
);
197 const VkAllocationCallbacks
*alloc
;
202 alloc
= &device
->alloc
;
204 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
207 VkResult
anv_GetSwapchainImagesKHR(
209 VkSwapchainKHR swapchain
,
210 uint32_t* pSwapchainImageCount
,
211 VkImage
* pSwapchainImages
)
213 return wsi_common_get_images(swapchain
,
214 pSwapchainImageCount
,
218 VkResult
anv_AcquireNextImageKHR(
220 VkSwapchainKHR swapchain
,
222 VkSemaphore semaphore
,
224 uint32_t* pImageIndex
)
226 VkAcquireNextImageInfoKHR acquire_info
= {
227 .sType
= VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR
,
228 .swapchain
= swapchain
,
230 .semaphore
= semaphore
,
235 return anv_AcquireNextImage2KHR(device
, &acquire_info
, pImageIndex
);
238 VkResult
anv_AcquireNextImage2KHR(
240 const VkAcquireNextImageInfoKHR
* pAcquireInfo
,
241 uint32_t* pImageIndex
)
243 ANV_FROM_HANDLE(anv_device
, device
, _device
);
244 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
246 VkResult result
= wsi_common_acquire_next_image2(&pdevice
->wsi_device
,
251 /* Thanks to implicit sync, the image is ready immediately. However, we
252 * should wait for the current GPU state to finish.
254 if (pAcquireInfo
->fence
!= VK_NULL_HANDLE
) {
255 anv_QueueSubmit(anv_queue_to_handle(&device
->queue
), 0, NULL
,
256 pAcquireInfo
->fence
);
262 VkResult
anv_QueuePresentKHR(
264 const VkPresentInfoKHR
* pPresentInfo
)
266 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
267 struct anv_physical_device
*pdevice
=
268 &queue
->device
->instance
->physicalDevice
;
270 return wsi_common_queue_present(&pdevice
->wsi_device
,
271 anv_device_to_handle(queue
->device
),
276 VkResult
anv_GetDeviceGroupPresentCapabilitiesKHR(
278 VkDeviceGroupPresentCapabilitiesKHR
* pCapabilities
)
280 memset(pCapabilities
->presentMask
, 0,
281 sizeof(pCapabilities
->presentMask
));
282 pCapabilities
->presentMask
[0] = 0x1;
283 pCapabilities
->modes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
288 VkResult
anv_GetDeviceGroupSurfacePresentModesKHR(
290 VkSurfaceKHR surface
,
291 VkDeviceGroupPresentModeFlagsKHR
* pModes
)
293 *pModes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;