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 static VkQueue
anv_wsi_get_prime_blit_queue(VkDevice _device)42 anv_wsi_get_prime_blit_queue(VkDevice _device)
43 {
44 ANV_FROM_HANDLE(anv_device, device, _device);
45
46 vk_foreach_queue(_queue, &device->vk) {
47 struct anv_queue *queue = (struct anv_queue *)_queue;
48 if (queue->family->queueFlags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT))
49 return vk_queue_to_handle(_queue);
50 }
51 return NULL;
52 }
53
54 VkResult
anv_init_wsi(struct anv_physical_device * physical_device)55 anv_init_wsi(struct anv_physical_device *physical_device)
56 {
57 VkResult result;
58
59 result = wsi_device_init(&physical_device->wsi_device,
60 anv_physical_device_to_handle(physical_device),
61 anv_wsi_proc_addr,
62 &physical_device->instance->vk.alloc,
63 physical_device->master_fd,
64 &physical_device->instance->dri_options,
65 &(struct wsi_device_options){.sw_device = false});
66 if (result != VK_SUCCESS)
67 return result;
68
69 physical_device->wsi_device.supports_modifiers = true;
70 physical_device->wsi_device.get_blit_queue = anv_wsi_get_prime_blit_queue;
71 if (physical_device->info.kmd_type == INTEL_KMD_TYPE_I915) {
72 physical_device->wsi_device.signal_semaphore_with_memory = true;
73 physical_device->wsi_device.signal_fence_with_memory = true;
74 }
75
76 physical_device->vk.wsi_device = &physical_device->wsi_device;
77
78 wsi_device_setup_syncobj_fd(&physical_device->wsi_device,
79 physical_device->local_fd);
80
81 return VK_SUCCESS;
82 }
83
84 void
anv_finish_wsi(struct anv_physical_device * physical_device)85 anv_finish_wsi(struct anv_physical_device *physical_device)
86 {
87 physical_device->vk.wsi_device = NULL;
88 wsi_device_finish(&physical_device->wsi_device,
89 &physical_device->instance->vk.alloc);
90 }
91
anv_AcquireNextImage2KHR(VkDevice _device,const VkAcquireNextImageInfoKHR * pAcquireInfo,uint32_t * pImageIndex)92 VkResult anv_AcquireNextImage2KHR(
93 VkDevice _device,
94 const VkAcquireNextImageInfoKHR *pAcquireInfo,
95 uint32_t *pImageIndex)
96 {
97 VK_FROM_HANDLE(anv_device, device, _device);
98
99 VkResult result =
100 wsi_common_acquire_next_image2(&device->physical->wsi_device,
101 _device, pAcquireInfo, pImageIndex);
102 if (result == VK_SUCCESS)
103 anv_measure_acquire(device);
104
105 return result;
106 }
107
anv_QueuePresentKHR(VkQueue _queue,const VkPresentInfoKHR * pPresentInfo)108 VkResult anv_QueuePresentKHR(
109 VkQueue _queue,
110 const VkPresentInfoKHR* pPresentInfo)
111 {
112 ANV_FROM_HANDLE(anv_queue, queue, _queue);
113 struct anv_device *device = queue->device;
114 VkResult result;
115
116 if (device->debug_frame_desc) {
117 device->debug_frame_desc->frame_id++;
118 }
119
120 if (u_trace_should_process(&device->ds.trace_context))
121 anv_queue_trace(queue, NULL, true /* frame */, false /* begin */);
122
123 result = vk_queue_wait_before_present(&queue->vk, pPresentInfo);
124 if (result != VK_SUCCESS)
125 return result;
126
127 result = wsi_common_queue_present(&device->physical->wsi_device,
128 anv_device_to_handle(queue->device),
129 _queue, 0,
130 pPresentInfo);
131
132 if (u_trace_should_process(&device->ds.trace_context))
133 anv_queue_trace(queue, NULL, true /* frame */, true /* begin */);
134
135 return result;
136 }
137