1 /*
2 * Copyright © 2015 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24 #include "anv_private.h"
25 #include "anv_measure.h"
26 #include "wsi_common.h"
27 #include "vk_fence.h"
28 #include "vk_queue.h"
29 #include "vk_semaphore.h"
30 #include "vk_util.h"
31
32 #include "common/intel_debug_identifier.h"
33
34 static PFN_vkVoidFunction
anv_wsi_proc_addr(VkPhysicalDevice physicalDevice,const char * pName)35 anv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
36 {
37 ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
38 return vk_instance_get_proc_addr_unchecked(&pdevice->instance->vk, pName);
39 }
40
41 VkResult
anv_init_wsi(struct anv_physical_device * physical_device)42 anv_init_wsi(struct anv_physical_device *physical_device)
43 {
44 VkResult result;
45
46 result = wsi_device_init(&physical_device->wsi_device,
47 anv_physical_device_to_handle(physical_device),
48 anv_wsi_proc_addr,
49 &physical_device->instance->vk.alloc,
50 physical_device->master_fd,
51 &physical_device->instance->dri_options,
52 &(struct wsi_device_options){.sw_device = false});
53 if (result != VK_SUCCESS)
54 return result;
55
56 physical_device->wsi_device.supports_modifiers = true;
57 physical_device->wsi_device.signal_semaphore_with_memory = true;
58 physical_device->wsi_device.signal_fence_with_memory = true;
59
60 physical_device->vk.wsi_device = &physical_device->wsi_device;
61
62 wsi_device_setup_syncobj_fd(&physical_device->wsi_device,
63 physical_device->local_fd);
64
65 return VK_SUCCESS;
66 }
67
68 void
anv_finish_wsi(struct anv_physical_device * physical_device)69 anv_finish_wsi(struct anv_physical_device *physical_device)
70 {
71 physical_device->vk.wsi_device = NULL;
72 wsi_device_finish(&physical_device->wsi_device,
73 &physical_device->instance->vk.alloc);
74 }
75
anv_AcquireNextImage2KHR(VkDevice _device,const VkAcquireNextImageInfoKHR * pAcquireInfo,uint32_t * pImageIndex)76 VkResult anv_AcquireNextImage2KHR(
77 VkDevice _device,
78 const VkAcquireNextImageInfoKHR *pAcquireInfo,
79 uint32_t *pImageIndex)
80 {
81 VK_FROM_HANDLE(anv_device, device, _device);
82
83 VkResult result =
84 wsi_common_acquire_next_image2(&device->physical->wsi_device,
85 _device, pAcquireInfo, pImageIndex);
86 if (result == VK_SUCCESS)
87 anv_measure_acquire(device);
88
89 return result;
90 }
91
anv_QueuePresentKHR(VkQueue _queue,const VkPresentInfoKHR * pPresentInfo)92 VkResult anv_QueuePresentKHR(
93 VkQueue _queue,
94 const VkPresentInfoKHR* pPresentInfo)
95 {
96 ANV_FROM_HANDLE(anv_queue, queue, _queue);
97 struct anv_device *device = queue->device;
98 VkResult result;
99
100 if (device->debug_frame_desc) {
101 device->debug_frame_desc->frame_id++;
102 #ifdef SUPPORT_INTEL_INTEGRATED_GPUS
103 if (device->physical->memory.need_flush) {
104 intel_flush_range(device->debug_frame_desc,
105 sizeof(*device->debug_frame_desc));
106 }
107 #endif
108 }
109
110 result = vk_queue_wait_before_present(&queue->vk, pPresentInfo);
111 if (result != VK_SUCCESS)
112 return result;
113
114 result = wsi_common_queue_present(&device->physical->wsi_device,
115 anv_device_to_handle(queue->device),
116 _queue, 0,
117 pPresentInfo);
118
119 intel_ds_device_process(&device->ds, true);
120
121 return result;
122 }
123