~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to src/broadcom/vulkan/v3dv_wsi.c

  • Committer: mmach
  • Date: 2022-09-22 19:56:13 UTC
  • Revision ID: netbit73@gmail.com-20220922195613-wtik9mmy20tmor0i
2022-09-22 21:17:09

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2020 Raspberry Pi Ltd
3
 
 * based on intel anv code:
4
 
 * Copyright © 2015 Intel Corporation
5
 
 
6
 
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 
 * copy of this software and associated documentation files (the "Software"),
8
 
 * to deal in the Software without restriction, including without limitation
9
 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
 
 * and/or sell copies of the Software, and to permit persons to whom the
11
 
 * Software is furnished to do so, subject to the following conditions:
12
 
 *
13
 
 * The above copyright notice and this permission notice (including the next
14
 
 * paragraph) shall be included in all copies or substantial portions of the
15
 
 * Software.
16
 
 *
17
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20
 
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23
 
 * IN THE SOFTWARE.
24
 
 */
25
 
 
26
 
#include "v3dv_private.h"
27
 
#include "drm-uapi/drm_fourcc.h"
28
 
#include "wsi_common_entrypoints.h"
29
 
#include "vk_util.h"
30
 
#include "wsi_common.h"
31
 
#include "wsi_common_drm.h"
32
 
#include "vk_fence.h"
33
 
#include "vk_semaphore.h"
34
 
#include "vk_sync_dummy.h"
35
 
 
36
 
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
37
 
v3dv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
38
 
{
39
 
   V3DV_FROM_HANDLE(v3dv_physical_device, pdevice, physicalDevice);
40
 
   return vk_instance_get_proc_addr_unchecked(pdevice->vk.instance, pName);
41
 
}
42
 
 
43
 
static bool
44
 
v3dv_wsi_can_present_on_device(VkPhysicalDevice _pdevice, int fd)
45
 
{
46
 
   V3DV_FROM_HANDLE(v3dv_physical_device, pdevice, _pdevice);
47
 
 
48
 
   return wsi_common_drm_devices_equal(fd, pdevice->display_fd);
49
 
}
50
 
 
51
 
VkResult
52
 
v3dv_wsi_init(struct v3dv_physical_device *physical_device)
53
 
{
54
 
   VkResult result;
55
 
 
56
 
   result = wsi_device_init(&physical_device->wsi_device,
57
 
                            v3dv_physical_device_to_handle(physical_device),
58
 
                            v3dv_wsi_proc_addr,
59
 
                            &physical_device->vk.instance->alloc,
60
 
                            physical_device->master_fd, NULL, false);
61
 
 
62
 
   if (result != VK_SUCCESS)
63
 
      return result;
64
 
 
65
 
   physical_device->wsi_device.supports_modifiers = true;
66
 
   physical_device->wsi_device.can_present_on_device =
67
 
      v3dv_wsi_can_present_on_device;
68
 
 
69
 
   physical_device->vk.wsi_device = &physical_device->wsi_device;
70
 
 
71
 
   return VK_SUCCESS;
72
 
}
73
 
 
74
 
void
75
 
v3dv_wsi_finish(struct v3dv_physical_device *physical_device)
76
 
{
77
 
   physical_device->vk.wsi_device = NULL;
78
 
   wsi_device_finish(&physical_device->wsi_device,
79
 
                     &physical_device->vk.instance->alloc);
80
 
}
81
 
 
82
 
static void
83
 
constraint_surface_capabilities(VkSurfaceCapabilitiesKHR *caps)
84
 
{
85
 
   /* Our display pipeline requires that images are linear, so we cannot
86
 
    * ensure that our swapchain images can be sampled. If we are running under
87
 
    * a compositor in windowed mode, the DRM modifier negotiation should
88
 
    * probably end up selecting an UIF layout for the swapchain images but it
89
 
    * may still choose linear and send images directly for scanout if the
90
 
    * surface is in fullscreen mode for example. If we are not running under
91
 
    * a compositor, then we would always need them to be linear anyway.
92
 
    */
93
 
   caps->supportedUsageFlags &= ~VK_IMAGE_USAGE_SAMPLED_BIT;
94
 
}
95
 
 
96
 
VKAPI_ATTR VkResult VKAPI_CALL
97
 
v3dv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
98
 
    VkPhysicalDevice                            physicalDevice,
99
 
    VkSurfaceKHR                                surface,
100
 
    VkSurfaceCapabilitiesKHR*                   pSurfaceCapabilities)
101
 
{
102
 
   VkResult result;
103
 
   result = wsi_GetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice,
104
 
                                                        surface,
105
 
                                                        pSurfaceCapabilities);
106
 
   constraint_surface_capabilities(pSurfaceCapabilities);
107
 
   return result;
108
 
}
109
 
 
110
 
VKAPI_ATTR VkResult VKAPI_CALL
111
 
v3dv_GetPhysicalDeviceSurfaceCapabilities2KHR(
112
 
    VkPhysicalDevice                            physicalDevice,
113
 
    const VkPhysicalDeviceSurfaceInfo2KHR*      pSurfaceInfo,
114
 
    VkSurfaceCapabilities2KHR*                  pSurfaceCapabilities)
115
 
{
116
 
   VkResult result;
117
 
   result = wsi_GetPhysicalDeviceSurfaceCapabilities2KHR(physicalDevice,
118
 
                                                         pSurfaceInfo,
119
 
                                                         pSurfaceCapabilities);
120
 
   constraint_surface_capabilities(&pSurfaceCapabilities->surfaceCapabilities);
121
 
   return result;
122
 
}
123
 
 
124
 
VKAPI_ATTR VkResult VKAPI_CALL
125
 
v3dv_CreateSwapchainKHR(
126
 
    VkDevice                                     _device,
127
 
    const VkSwapchainCreateInfoKHR*              pCreateInfo,
128
 
    const VkAllocationCallbacks*                 pAllocator,
129
 
    VkSwapchainKHR*                              pSwapchain)
130
 
{
131
 
   V3DV_FROM_HANDLE(v3dv_device, device, _device);
132
 
   struct v3dv_instance *instance = device->instance;
133
 
   struct v3dv_physical_device *pdevice = &instance->physicalDevice;
134
 
 
135
 
   ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, pCreateInfo->surface);
136
 
   VkResult result =
137
 
      v3dv_physical_device_acquire_display(instance, pdevice, surface);
138
 
   if (result != VK_SUCCESS)
139
 
      return result;
140
 
 
141
 
   return wsi_CreateSwapchainKHR(_device, pCreateInfo, pAllocator, pSwapchain);
142
 
}
143
 
 
144
 
struct v3dv_image *
145
 
v3dv_wsi_get_image_from_swapchain(VkSwapchainKHR swapchain, uint32_t index)
146
 
{
147
 
   VkImage image = wsi_common_get_image(swapchain, index);
148
 
   return v3dv_image_from_handle(image);
149
 
}
150
 
 
151
 
VKAPI_ATTR VkResult VKAPI_CALL
152
 
v3dv_AcquireNextImage2KHR(VkDevice _device,
153
 
                          const VkAcquireNextImageInfoKHR *pAcquireInfo,
154
 
                          uint32_t *pImageIndex)
155
 
{
156
 
   V3DV_FROM_HANDLE(v3dv_device, device, _device);
157
 
   VK_FROM_HANDLE(vk_fence, fence, pAcquireInfo->fence);
158
 
   VK_FROM_HANDLE(vk_semaphore, semaphore, pAcquireInfo->semaphore);
159
 
 
160
 
   struct v3dv_physical_device *pdevice = device->pdevice;
161
 
 
162
 
   VkResult result = wsi_common_acquire_next_image2(
163
 
      &pdevice->wsi_device, _device, pAcquireInfo, pImageIndex);
164
 
 
165
 
   /* signal fence/semaphore - image is available immediately */
166
 
   if (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR) {
167
 
      VkResult sync_res;
168
 
      if (fence) {
169
 
         vk_fence_reset_temporary(&device->vk, fence);
170
 
         sync_res = vk_sync_create(&device->vk, &vk_sync_dummy_type,
171
 
                                   0 /* flags */, 1 /* initial_value */,
172
 
                                   &fence->temporary);
173
 
         if (sync_res != VK_SUCCESS)
174
 
            return sync_res;
175
 
      }
176
 
 
177
 
      if (semaphore) {
178
 
         vk_semaphore_reset_temporary(&device->vk, semaphore);
179
 
         sync_res = vk_sync_create(&device->vk, &vk_sync_dummy_type,
180
 
                                   0 /* flags */, 1 /* initial_value */,
181
 
                                   &semaphore->temporary);
182
 
         if (sync_res != VK_SUCCESS)
183
 
            return sync_res;
184
 
      }
185
 
   }
186
 
 
187
 
   return result;
188
 
}