2
* Copyright © 2020 Raspberry Pi Ltd
3
* based on intel anv code:
4
* Copyright © 2015 Intel Corporation
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:
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
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
26
#include "v3dv_private.h"
27
#include "drm-uapi/drm_fourcc.h"
28
#include "wsi_common_entrypoints.h"
30
#include "wsi_common.h"
31
#include "wsi_common_drm.h"
33
#include "vk_semaphore.h"
34
#include "vk_sync_dummy.h"
36
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
37
v3dv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
39
V3DV_FROM_HANDLE(v3dv_physical_device, pdevice, physicalDevice);
40
return vk_instance_get_proc_addr_unchecked(pdevice->vk.instance, pName);
44
v3dv_wsi_can_present_on_device(VkPhysicalDevice _pdevice, int fd)
46
V3DV_FROM_HANDLE(v3dv_physical_device, pdevice, _pdevice);
48
return wsi_common_drm_devices_equal(fd, pdevice->display_fd);
52
v3dv_wsi_init(struct v3dv_physical_device *physical_device)
56
result = wsi_device_init(&physical_device->wsi_device,
57
v3dv_physical_device_to_handle(physical_device),
59
&physical_device->vk.instance->alloc,
60
physical_device->master_fd, NULL, false);
62
if (result != VK_SUCCESS)
65
physical_device->wsi_device.supports_modifiers = true;
66
physical_device->wsi_device.can_present_on_device =
67
v3dv_wsi_can_present_on_device;
69
physical_device->vk.wsi_device = &physical_device->wsi_device;
75
v3dv_wsi_finish(struct v3dv_physical_device *physical_device)
77
physical_device->vk.wsi_device = NULL;
78
wsi_device_finish(&physical_device->wsi_device,
79
&physical_device->vk.instance->alloc);
83
constraint_surface_capabilities(VkSurfaceCapabilitiesKHR *caps)
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.
93
caps->supportedUsageFlags &= ~VK_IMAGE_USAGE_SAMPLED_BIT;
96
VKAPI_ATTR VkResult VKAPI_CALL
97
v3dv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
98
VkPhysicalDevice physicalDevice,
100
VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
103
result = wsi_GetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice,
105
pSurfaceCapabilities);
106
constraint_surface_capabilities(pSurfaceCapabilities);
110
VKAPI_ATTR VkResult VKAPI_CALL
111
v3dv_GetPhysicalDeviceSurfaceCapabilities2KHR(
112
VkPhysicalDevice physicalDevice,
113
const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
114
VkSurfaceCapabilities2KHR* pSurfaceCapabilities)
117
result = wsi_GetPhysicalDeviceSurfaceCapabilities2KHR(physicalDevice,
119
pSurfaceCapabilities);
120
constraint_surface_capabilities(&pSurfaceCapabilities->surfaceCapabilities);
124
VKAPI_ATTR VkResult VKAPI_CALL
125
v3dv_CreateSwapchainKHR(
127
const VkSwapchainCreateInfoKHR* pCreateInfo,
128
const VkAllocationCallbacks* pAllocator,
129
VkSwapchainKHR* pSwapchain)
131
V3DV_FROM_HANDLE(v3dv_device, device, _device);
132
struct v3dv_instance *instance = device->instance;
133
struct v3dv_physical_device *pdevice = &instance->physicalDevice;
135
ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, pCreateInfo->surface);
137
v3dv_physical_device_acquire_display(instance, pdevice, surface);
138
if (result != VK_SUCCESS)
141
return wsi_CreateSwapchainKHR(_device, pCreateInfo, pAllocator, pSwapchain);
145
v3dv_wsi_get_image_from_swapchain(VkSwapchainKHR swapchain, uint32_t index)
147
VkImage image = wsi_common_get_image(swapchain, index);
148
return v3dv_image_from_handle(image);
151
VKAPI_ATTR VkResult VKAPI_CALL
152
v3dv_AcquireNextImage2KHR(VkDevice _device,
153
const VkAcquireNextImageInfoKHR *pAcquireInfo,
154
uint32_t *pImageIndex)
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);
160
struct v3dv_physical_device *pdevice = device->pdevice;
162
VkResult result = wsi_common_acquire_next_image2(
163
&pdevice->wsi_device, _device, pAcquireInfo, pImageIndex);
165
/* signal fence/semaphore - image is available immediately */
166
if (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR) {
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 */,
173
if (sync_res != VK_SUCCESS)
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)