• 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 VkResult
anv_init_wsi(struct anv_physical_device * physical_device)40 anv_init_wsi(struct anv_physical_device *physical_device)
41 {
42    VkResult result;
43 
44    result = wsi_device_init(&physical_device->wsi_device,
45                             anv_physical_device_to_handle(physical_device),
46                             anv_wsi_proc_addr,
47                             &physical_device->instance->vk.alloc,
48                             physical_device->master_fd,
49                             &physical_device->instance->dri_options,
50                             false);
51    if (result != VK_SUCCESS)
52       return result;
53 
54    physical_device->wsi_device.supports_modifiers = true;
55    physical_device->wsi_device.signal_semaphore_with_memory = true;
56    physical_device->wsi_device.signal_fence_with_memory = true;
57 
58    physical_device->vk.wsi_device = &physical_device->wsi_device;
59 
60    wsi_device_setup_syncobj_fd(&physical_device->wsi_device,
61                                physical_device->local_fd);
62 
63    return VK_SUCCESS;
64 }
65 
66 void
anv_finish_wsi(struct anv_physical_device * physical_device)67 anv_finish_wsi(struct anv_physical_device *physical_device)
68 {
69    physical_device->vk.wsi_device = NULL;
70    wsi_device_finish(&physical_device->wsi_device,
71                      &physical_device->instance->vk.alloc);
72 }
73 
anv_AcquireNextImage2KHR(VkDevice _device,const VkAcquireNextImageInfoKHR * pAcquireInfo,uint32_t * pImageIndex)74 VkResult anv_AcquireNextImage2KHR(
75    VkDevice _device,
76    const VkAcquireNextImageInfoKHR *pAcquireInfo,
77    uint32_t *pImageIndex)
78 {
79    VK_FROM_HANDLE(anv_device, device, _device);
80 
81    VkResult result =
82       wsi_common_acquire_next_image2(&device->physical->wsi_device,
83                                      _device, pAcquireInfo, pImageIndex);
84    if (result == VK_SUCCESS)
85       anv_measure_acquire(device);
86 
87    return result;
88 }
89 
anv_QueuePresentKHR(VkQueue _queue,const VkPresentInfoKHR * pPresentInfo)90 VkResult anv_QueuePresentKHR(
91     VkQueue                                  _queue,
92     const VkPresentInfoKHR*                  pPresentInfo)
93 {
94    ANV_FROM_HANDLE(anv_queue, queue, _queue);
95    struct anv_device *device = queue->device;
96    VkResult result;
97 
98    if (device->debug_frame_desc) {
99       device->debug_frame_desc->frame_id++;
100       if (device->physical->memory.need_clflush) {
101          intel_clflush_range(device->debug_frame_desc,
102                            sizeof(*device->debug_frame_desc));
103       }
104    }
105 
106    result = vk_queue_wait_before_present(&queue->vk, pPresentInfo);
107    if (result != VK_SUCCESS)
108       return result;
109 
110    result = wsi_common_queue_present(&device->physical->wsi_device,
111                                      anv_device_to_handle(queue->device),
112                                      _queue, 0,
113                                      pPresentInfo);
114 
115    u_trace_context_process(&device->ds.trace_context, true);
116 
117    return result;
118 }
119