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