summaryrefslogtreecommitdiff
path: root/src/intel/vulkan/anv_wsi.c
blob: 28609d7dcb8a1759abed5c29f4407f5c8b690790 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * Copyright © 2015 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#include "anv_private.h"
#include "anv_measure.h"
#include "wsi_common.h"
#include "vk_fence.h"
#include "vk_queue.h"
#include "vk_semaphore.h"
#include "vk_util.h"

#include "common/intel_debug_identifier.h"

static PFN_vkVoidFunction
anv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
{
   ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
   return vk_instance_get_proc_addr_unchecked(&pdevice->instance->vk, pName);
}

VkResult
anv_init_wsi(struct anv_physical_device *physical_device)
{
   VkResult result;

   result = wsi_device_init(&physical_device->wsi_device,
                            anv_physical_device_to_handle(physical_device),
                            anv_wsi_proc_addr,
                            &physical_device->instance->vk.alloc,
                            physical_device->master_fd,
                            &physical_device->instance->dri_options,
                            &(struct wsi_device_options){.sw_device = false});
   if (result != VK_SUCCESS)
      return result;

   struct wsi_device *wsi_device = &physical_device->wsi_device;
   wsi_device->supports_modifiers = true;
   /* Only allow protected content on display */
   for (uint32_t i = 0; i < ARRAY_SIZE(wsi_device->supports_protected); i++) {
      wsi_device->supports_protected[i] =
         physical_device->has_protected_contexts &&
         i == VK_ICD_WSI_PLATFORM_DISPLAY;
   }

   physical_device->vk.wsi_device = wsi_device;

   wsi_device_setup_syncobj_fd(wsi_device, physical_device->local_fd);

   return VK_SUCCESS;
}

void
anv_finish_wsi(struct anv_physical_device *physical_device)
{
   physical_device->vk.wsi_device = NULL;
   wsi_device_finish(&physical_device->wsi_device,
                     &physical_device->instance->vk.alloc);
}

VkResult anv_AcquireNextImage2KHR(
   VkDevice _device,
   const VkAcquireNextImageInfoKHR *pAcquireInfo,
   uint32_t *pImageIndex)
{
   VK_FROM_HANDLE(anv_device, device, _device);

   VkResult result =
      wsi_common_acquire_next_image2(&device->physical->wsi_device,
                                     _device, pAcquireInfo, pImageIndex);
   if (result == VK_SUCCESS)
      anv_measure_acquire(device);

   return result;
}

VkResult anv_QueuePresentKHR(
    VkQueue                                  _queue,
    const VkPresentInfoKHR*                  pPresentInfo)
{
   ANV_FROM_HANDLE(anv_queue, queue, _queue);
   struct anv_device *device = queue->device;
   VkResult result;

   if (device->debug_frame_desc) {
      device->debug_frame_desc->frame_id++;
   }

   if (u_trace_should_process(&device->ds.trace_context))
      anv_queue_trace(queue, NULL, true /* frame */, false /* begin */);

   result = wsi_common_queue_present(&device->physical->wsi_device,
                                     &queue->vk, pPresentInfo);

   if (u_trace_should_process(&device->ds.trace_context))
      anv_queue_trace(queue, NULL, true /* frame */, true /* begin */);

   return result;
}