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_signal_semaphore_for_memory(VkDevice _device
,
38 VkSemaphore _semaphore
,
39 VkDeviceMemory _memory
)
41 ANV_FROM_HANDLE(anv_device
, device
, _device
);
42 ANV_FROM_HANDLE(anv_semaphore
, semaphore
, _semaphore
);
43 ANV_FROM_HANDLE(anv_device_memory
, memory
, _memory
);
45 /* Put a BO semaphore with the image BO in the temporary. For BO binary
46 * semaphores, we always set EXEC_OBJECT_WRITE so this creates a WaR
47 * hazard with the display engine's read to ensure that no one writes to
48 * the image before the read is complete.
50 anv_semaphore_reset_temporary(device
, semaphore
);
52 struct anv_semaphore_impl
*impl
= &semaphore
->temporary
;
53 impl
->type
= ANV_SEMAPHORE_TYPE_WSI_BO
;
54 impl
->bo
= anv_bo_ref(memory
->bo
);
58 anv_wsi_signal_fence_for_memory(VkDevice _device
,
60 VkDeviceMemory _memory
)
62 ANV_FROM_HANDLE(anv_device
, device
, _device
);
63 ANV_FROM_HANDLE(anv_fence
, fence
, _fence
);
64 ANV_FROM_HANDLE(anv_device_memory
, memory
, _memory
);
66 /* Put a BO fence with the image BO in the temporary. For BO fences, we
67 * always just wait until the BO isn't busy and reads from the BO should
70 anv_fence_reset_temporary(device
, fence
);
72 struct anv_fence_impl
*impl
= &fence
->temporary
;
73 impl
->type
= ANV_FENCE_TYPE_WSI_BO
;
74 impl
->bo
.bo
= anv_bo_ref(memory
->bo
);
75 impl
->bo
.state
= ANV_BO_FENCE_STATE_SUBMITTED
;
79 anv_init_wsi(struct anv_physical_device
*physical_device
)
83 result
= wsi_device_init(&physical_device
->wsi_device
,
84 anv_physical_device_to_handle(physical_device
),
86 &physical_device
->instance
->alloc
,
87 physical_device
->master_fd
,
88 &physical_device
->instance
->dri_options
);
89 if (result
!= VK_SUCCESS
)
92 physical_device
->wsi_device
.supports_modifiers
= true;
93 physical_device
->wsi_device
.signal_semaphore_for_memory
=
94 anv_wsi_signal_semaphore_for_memory
;
95 physical_device
->wsi_device
.signal_fence_for_memory
=
96 anv_wsi_signal_fence_for_memory
;
102 anv_finish_wsi(struct anv_physical_device
*physical_device
)
104 wsi_device_finish(&physical_device
->wsi_device
,
105 &physical_device
->instance
->alloc
);
108 void anv_DestroySurfaceKHR(
109 VkInstance _instance
,
110 VkSurfaceKHR _surface
,
111 const VkAllocationCallbacks
* pAllocator
)
113 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
114 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
119 vk_free2(&instance
->alloc
, pAllocator
, surface
);
122 VkResult
anv_GetPhysicalDeviceSurfaceSupportKHR(
123 VkPhysicalDevice physicalDevice
,
124 uint32_t queueFamilyIndex
,
125 VkSurfaceKHR surface
,
126 VkBool32
* pSupported
)
128 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
130 return wsi_common_get_surface_support(&device
->wsi_device
,
136 VkResult
anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
137 VkPhysicalDevice physicalDevice
,
138 VkSurfaceKHR surface
,
139 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
141 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
143 return wsi_common_get_surface_capabilities(&device
->wsi_device
,
145 pSurfaceCapabilities
);
148 VkResult
anv_GetPhysicalDeviceSurfaceCapabilities2KHR(
149 VkPhysicalDevice physicalDevice
,
150 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
151 VkSurfaceCapabilities2KHR
* pSurfaceCapabilities
)
153 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
155 return wsi_common_get_surface_capabilities2(&device
->wsi_device
,
157 pSurfaceCapabilities
);
160 VkResult
anv_GetPhysicalDeviceSurfaceCapabilities2EXT(
161 VkPhysicalDevice physicalDevice
,
162 VkSurfaceKHR surface
,
163 VkSurfaceCapabilities2EXT
* pSurfaceCapabilities
)
165 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
167 return wsi_common_get_surface_capabilities2ext(&device
->wsi_device
,
169 pSurfaceCapabilities
);
172 VkResult
anv_GetPhysicalDeviceSurfaceFormatsKHR(
173 VkPhysicalDevice physicalDevice
,
174 VkSurfaceKHR surface
,
175 uint32_t* pSurfaceFormatCount
,
176 VkSurfaceFormatKHR
* pSurfaceFormats
)
178 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
180 return wsi_common_get_surface_formats(&device
->wsi_device
, surface
,
181 pSurfaceFormatCount
, pSurfaceFormats
);
184 VkResult
anv_GetPhysicalDeviceSurfaceFormats2KHR(
185 VkPhysicalDevice physicalDevice
,
186 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
187 uint32_t* pSurfaceFormatCount
,
188 VkSurfaceFormat2KHR
* pSurfaceFormats
)
190 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
192 return wsi_common_get_surface_formats2(&device
->wsi_device
, pSurfaceInfo
,
193 pSurfaceFormatCount
, pSurfaceFormats
);
196 VkResult
anv_GetPhysicalDeviceSurfacePresentModesKHR(
197 VkPhysicalDevice physicalDevice
,
198 VkSurfaceKHR surface
,
199 uint32_t* pPresentModeCount
,
200 VkPresentModeKHR
* pPresentModes
)
202 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
204 return wsi_common_get_surface_present_modes(&device
->wsi_device
, surface
,
209 VkResult
anv_CreateSwapchainKHR(
211 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
212 const VkAllocationCallbacks
* pAllocator
,
213 VkSwapchainKHR
* pSwapchain
)
215 ANV_FROM_HANDLE(anv_device
, device
, _device
);
216 struct wsi_device
*wsi_device
= &device
->physical
->wsi_device
;
217 const VkAllocationCallbacks
*alloc
;
222 alloc
= &device
->vk
.alloc
;
224 return wsi_common_create_swapchain(wsi_device
, _device
,
225 pCreateInfo
, alloc
, pSwapchain
);
228 void anv_DestroySwapchainKHR(
230 VkSwapchainKHR swapchain
,
231 const VkAllocationCallbacks
* pAllocator
)
233 ANV_FROM_HANDLE(anv_device
, device
, _device
);
234 const VkAllocationCallbacks
*alloc
;
239 alloc
= &device
->vk
.alloc
;
241 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
244 VkResult
anv_GetSwapchainImagesKHR(
246 VkSwapchainKHR swapchain
,
247 uint32_t* pSwapchainImageCount
,
248 VkImage
* pSwapchainImages
)
250 return wsi_common_get_images(swapchain
,
251 pSwapchainImageCount
,
255 VkResult
anv_AcquireNextImageKHR(
257 VkSwapchainKHR swapchain
,
259 VkSemaphore semaphore
,
261 uint32_t* pImageIndex
)
263 VkAcquireNextImageInfoKHR acquire_info
= {
264 .sType
= VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR
,
265 .swapchain
= swapchain
,
267 .semaphore
= semaphore
,
272 return anv_AcquireNextImage2KHR(device
, &acquire_info
, pImageIndex
);
275 VkResult
anv_AcquireNextImage2KHR(
277 const VkAcquireNextImageInfoKHR
* pAcquireInfo
,
278 uint32_t* pImageIndex
)
280 ANV_FROM_HANDLE(anv_device
, device
, _device
);
282 return wsi_common_acquire_next_image2(&device
->physical
->wsi_device
,
283 _device
, pAcquireInfo
, pImageIndex
);
286 VkResult
anv_QueuePresentKHR(
288 const VkPresentInfoKHR
* pPresentInfo
)
290 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
292 return wsi_common_queue_present(&queue
->device
->physical
->wsi_device
,
293 anv_device_to_handle(queue
->device
),
298 VkResult
anv_GetDeviceGroupPresentCapabilitiesKHR(
300 VkDeviceGroupPresentCapabilitiesKHR
* pCapabilities
)
302 memset(pCapabilities
->presentMask
, 0,
303 sizeof(pCapabilities
->presentMask
));
304 pCapabilities
->presentMask
[0] = 0x1;
305 pCapabilities
->modes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
310 VkResult
anv_GetDeviceGroupSurfacePresentModesKHR(
312 VkSurfaceKHR surface
,
313 VkDeviceGroupPresentModeFlagsKHR
* pModes
)
315 *pModes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
320 VkResult
anv_GetPhysicalDevicePresentRectanglesKHR(
321 VkPhysicalDevice physicalDevice
,
322 VkSurfaceKHR surface
,
323 uint32_t* pRectCount
,
326 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
328 return wsi_common_get_present_rectangles(&device
->wsi_device
,