1 /*
2 * Copyright © 2016 Red Hat
3 * based on intel anv code:
4 * Copyright © 2015 Intel Corporation
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26 #include "tu_private.h"
27
28 #include "vk_util.h"
29 #include "wsi_common.h"
30 #include "drm-uapi/drm_fourcc.h"
31
32 static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
tu_wsi_proc_addr(VkPhysicalDevice physicalDevice,const char * pName)33 tu_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
34 {
35 TU_FROM_HANDLE(tu_physical_device, pdevice, physicalDevice);
36 return vk_instance_get_proc_addr_unchecked(&pdevice->instance->vk, pName);
37 }
38
39 VkResult
tu_wsi_init(struct tu_physical_device * physical_device)40 tu_wsi_init(struct tu_physical_device *physical_device)
41 {
42 VkResult result;
43
44 result = wsi_device_init(&physical_device->wsi_device,
45 tu_physical_device_to_handle(physical_device),
46 tu_wsi_proc_addr,
47 &physical_device->instance->vk.alloc,
48 physical_device->master_fd, NULL,
49 false);
50 if (result != VK_SUCCESS)
51 return result;
52
53 physical_device->wsi_device.supports_modifiers = true;
54 physical_device->vk.wsi_device = &physical_device->wsi_device;
55
56 return VK_SUCCESS;
57 }
58
59 void
tu_wsi_finish(struct tu_physical_device * physical_device)60 tu_wsi_finish(struct tu_physical_device *physical_device)
61 {
62 physical_device->vk.wsi_device = NULL;
63 wsi_device_finish(&physical_device->wsi_device,
64 &physical_device->instance->vk.alloc);
65 }
66
67 VKAPI_ATTR VkResult VKAPI_CALL
tu_AcquireNextImage2KHR(VkDevice _device,const VkAcquireNextImageInfoKHR * pAcquireInfo,uint32_t * pImageIndex)68 tu_AcquireNextImage2KHR(VkDevice _device,
69 const VkAcquireNextImageInfoKHR *pAcquireInfo,
70 uint32_t *pImageIndex)
71 {
72 TU_FROM_HANDLE(tu_device, device, _device);
73 TU_FROM_HANDLE(tu_syncobj, fence, pAcquireInfo->fence);
74 TU_FROM_HANDLE(tu_syncobj, semaphore, pAcquireInfo->semaphore);
75
76 struct tu_physical_device *pdevice = device->physical_device;
77
78 VkResult result = wsi_common_acquire_next_image2(
79 &pdevice->wsi_device, _device, pAcquireInfo, pImageIndex);
80
81 /* signal fence/semaphore - image is available immediately */
82 tu_signal_fences(device, fence, semaphore);
83
84 return result;
85 }
86
87 VKAPI_ATTR VkResult VKAPI_CALL
tu_QueuePresentKHR(VkQueue _queue,const VkPresentInfoKHR * pPresentInfo)88 tu_QueuePresentKHR(VkQueue _queue, const VkPresentInfoKHR *pPresentInfo)
89 {
90 TU_FROM_HANDLE(tu_queue, queue, _queue);
91
92 u_trace_context_process(&queue->device->trace_context, true);
93
94 return wsi_common_queue_present(
95 &queue->device->physical_device->wsi_device,
96 tu_device_to_handle(queue->device), _queue, queue->vk.queue_family_index,
97 pPresentInfo);
98 }
99