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
,
90 if (result
!= VK_SUCCESS
)
93 physical_device
->wsi_device
.supports_modifiers
= true;
94 physical_device
->wsi_device
.signal_semaphore_for_memory
=
95 anv_wsi_signal_semaphore_for_memory
;
96 physical_device
->wsi_device
.signal_fence_for_memory
=
97 anv_wsi_signal_fence_for_memory
;
103 anv_finish_wsi(struct anv_physical_device
*physical_device
)
105 wsi_device_finish(&physical_device
->wsi_device
,
106 &physical_device
->instance
->alloc
);
109 void anv_DestroySurfaceKHR(
110 VkInstance _instance
,
111 VkSurfaceKHR _surface
,
112 const VkAllocationCallbacks
* pAllocator
)
114 ANV_FROM_HANDLE(anv_instance
, instance
, _instance
);
115 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
120 vk_free2(&instance
->alloc
, pAllocator
, surface
);
123 VkResult
anv_GetPhysicalDeviceSurfaceSupportKHR(
124 VkPhysicalDevice physicalDevice
,
125 uint32_t queueFamilyIndex
,
126 VkSurfaceKHR surface
,
127 VkBool32
* pSupported
)
129 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
131 return wsi_common_get_surface_support(&device
->wsi_device
,
137 VkResult
anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
138 VkPhysicalDevice physicalDevice
,
139 VkSurfaceKHR surface
,
140 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
142 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
144 return wsi_common_get_surface_capabilities(&device
->wsi_device
,
146 pSurfaceCapabilities
);
149 VkResult
anv_GetPhysicalDeviceSurfaceCapabilities2KHR(
150 VkPhysicalDevice physicalDevice
,
151 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
152 VkSurfaceCapabilities2KHR
* pSurfaceCapabilities
)
154 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
156 return wsi_common_get_surface_capabilities2(&device
->wsi_device
,
158 pSurfaceCapabilities
);
161 VkResult
anv_GetPhysicalDeviceSurfaceCapabilities2EXT(
162 VkPhysicalDevice physicalDevice
,
163 VkSurfaceKHR surface
,
164 VkSurfaceCapabilities2EXT
* pSurfaceCapabilities
)
166 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
168 return wsi_common_get_surface_capabilities2ext(&device
->wsi_device
,
170 pSurfaceCapabilities
);
173 VkResult
anv_GetPhysicalDeviceSurfaceFormatsKHR(
174 VkPhysicalDevice physicalDevice
,
175 VkSurfaceKHR surface
,
176 uint32_t* pSurfaceFormatCount
,
177 VkSurfaceFormatKHR
* pSurfaceFormats
)
179 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
181 return wsi_common_get_surface_formats(&device
->wsi_device
, surface
,
182 pSurfaceFormatCount
, pSurfaceFormats
);
185 VkResult
anv_GetPhysicalDeviceSurfaceFormats2KHR(
186 VkPhysicalDevice physicalDevice
,
187 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
188 uint32_t* pSurfaceFormatCount
,
189 VkSurfaceFormat2KHR
* pSurfaceFormats
)
191 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
193 return wsi_common_get_surface_formats2(&device
->wsi_device
, pSurfaceInfo
,
194 pSurfaceFormatCount
, pSurfaceFormats
);
197 VkResult
anv_GetPhysicalDeviceSurfacePresentModesKHR(
198 VkPhysicalDevice physicalDevice
,
199 VkSurfaceKHR surface
,
200 uint32_t* pPresentModeCount
,
201 VkPresentModeKHR
* pPresentModes
)
203 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
205 return wsi_common_get_surface_present_modes(&device
->wsi_device
, surface
,
210 VkResult
anv_CreateSwapchainKHR(
212 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
213 const VkAllocationCallbacks
* pAllocator
,
214 VkSwapchainKHR
* pSwapchain
)
216 ANV_FROM_HANDLE(anv_device
, device
, _device
);
217 struct wsi_device
*wsi_device
= &device
->physical
->wsi_device
;
218 const VkAllocationCallbacks
*alloc
;
223 alloc
= &device
->vk
.alloc
;
225 return wsi_common_create_swapchain(wsi_device
, _device
,
226 pCreateInfo
, alloc
, pSwapchain
);
229 void anv_DestroySwapchainKHR(
231 VkSwapchainKHR swapchain
,
232 const VkAllocationCallbacks
* pAllocator
)
234 ANV_FROM_HANDLE(anv_device
, device
, _device
);
235 const VkAllocationCallbacks
*alloc
;
240 alloc
= &device
->vk
.alloc
;
242 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
245 VkResult
anv_GetSwapchainImagesKHR(
247 VkSwapchainKHR swapchain
,
248 uint32_t* pSwapchainImageCount
,
249 VkImage
* pSwapchainImages
)
251 return wsi_common_get_images(swapchain
,
252 pSwapchainImageCount
,
256 VkResult
anv_AcquireNextImageKHR(
258 VkSwapchainKHR swapchain
,
260 VkSemaphore semaphore
,
262 uint32_t* pImageIndex
)
264 VkAcquireNextImageInfoKHR acquire_info
= {
265 .sType
= VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR
,
266 .swapchain
= swapchain
,
268 .semaphore
= semaphore
,
273 return anv_AcquireNextImage2KHR(device
, &acquire_info
, pImageIndex
);
276 VkResult
anv_AcquireNextImage2KHR(
278 const VkAcquireNextImageInfoKHR
* pAcquireInfo
,
279 uint32_t* pImageIndex
)
281 ANV_FROM_HANDLE(anv_device
, device
, _device
);
283 return wsi_common_acquire_next_image2(&device
->physical
->wsi_device
,
284 _device
, pAcquireInfo
, pImageIndex
);
287 VkResult
anv_QueuePresentKHR(
289 const VkPresentInfoKHR
* pPresentInfo
)
291 ANV_FROM_HANDLE(anv_queue
, queue
, _queue
);
292 struct anv_device
*device
= queue
->device
;
294 if (device
->debug_frame_desc
) {
295 device
->debug_frame_desc
->frame_id
++;
296 if (!device
->info
.has_llc
) {
297 gen_clflush_range(device
->debug_frame_desc
,
298 sizeof(*device
->debug_frame_desc
));
302 return wsi_common_queue_present(&queue
->device
->physical
->wsi_device
,
303 anv_device_to_handle(queue
->device
),
308 VkResult
anv_GetDeviceGroupPresentCapabilitiesKHR(
310 VkDeviceGroupPresentCapabilitiesKHR
* pCapabilities
)
312 memset(pCapabilities
->presentMask
, 0,
313 sizeof(pCapabilities
->presentMask
));
314 pCapabilities
->presentMask
[0] = 0x1;
315 pCapabilities
->modes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
320 VkResult
anv_GetDeviceGroupSurfacePresentModesKHR(
322 VkSurfaceKHR surface
,
323 VkDeviceGroupPresentModeFlagsKHR
* pModes
)
325 *pModes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
330 VkResult
anv_GetPhysicalDevicePresentRectanglesKHR(
331 VkPhysicalDevice physicalDevice
,
332 VkSurfaceKHR surface
,
333 uint32_t* pRectCount
,
336 ANV_FROM_HANDLE(anv_physical_device
, device
, physicalDevice
);
338 return wsi_common_get_present_rectangles(&device
->wsi_device
,