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 &physical_device
->instance
->dri_options
);
54 if (result
!= VK_SUCCESS
)
57 physical_device
->wsi_device
.supports_modifiers
= true;
58 physical_device
->wsi_device
.image_get_modifier
= anv_wsi_image_get_modifier
;
64 anv_finish_wsi(struct anv_physical_device
*physical_device
)
66 wsi_device_finish(&physical_device
->wsi_device
,
67 &physical_device
->instance
->alloc
);
70 void anv_DestroySurfaceKHR(
72 VkSurfaceKHR _surface
,
73 const VkAllocationCallbacks
* pAllocator
)
75 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
76 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
81 vk_free2(&instance
->alloc
, pAllocator
, surface
);
84 VkResult
anv_GetPhysicalDeviceSurfaceSupportKHR(
85 VkPhysicalDevice physicalDevice
,
86 uint32_t queueFamilyIndex
,
90 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
92 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
,
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. Regardless of the
252 * result of the presentation, we need to signal the semaphore & fence.
255 if (pAcquireInfo
->semaphore
!= VK_NULL_HANDLE
) {
256 /* Put a dummy semaphore in temporary, this is the fastest way to avoid
257 * any kind of work yet still provide some kind of synchronization. This
258 * only works because the Mesa WSI code always returns an image
259 * immediately if available.
261 ANV_FROM_HANDLE(anv_semaphore
, semaphore
, pAcquireInfo
->semaphore
);
262 anv_semaphore_reset_temporary(device
, semaphore
);
264 struct anv_semaphore_impl
*impl
= &semaphore
->temporary
;
266 impl
->type
= ANV_SEMAPHORE_TYPE_DUMMY
;
269 if (pAcquireInfo
->fence
!= VK_NULL_HANDLE
) {
270 result
= anv_QueueSubmit(anv_queue_to_handle(&device
->queue
),
271 0, NULL
, pAcquireInfo
->fence
);
277 VkResult
anv_QueuePresentKHR(
279 const VkPresentInfoKHR
* pPresentInfo
)
281 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
282 struct anv_physical_device
*pdevice
=
283 &queue
->device
->instance
->physicalDevice
;
285 return wsi_common_queue_present(&pdevice
->wsi_device
,
286 anv_device_to_handle(queue
->device
),
291 VkResult
anv_GetDeviceGroupPresentCapabilitiesKHR(
293 VkDeviceGroupPresentCapabilitiesKHR
* pCapabilities
)
295 memset(pCapabilities
->presentMask
, 0,
296 sizeof(pCapabilities
->presentMask
));
297 pCapabilities
->presentMask
[0] = 0x1;
298 pCapabilities
->modes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
303 VkResult
anv_GetDeviceGroupSurfacePresentModesKHR(
305 VkSurfaceKHR surface
,
306 VkDeviceGroupPresentModeFlagsKHR
* pModes
)
308 *pModes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
313 VkResult
anv_GetPhysicalDevicePresentRectanglesKHR(
314 VkPhysicalDevice physicalDevice
,
315 VkSurfaceKHR surface
,
316 uint32_t* pRectCount
,
319 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
321 return wsi_common_get_present_rectangles(&device
->wsi_device
,