Commit graph

132 commits

Author SHA1 Message Date
Matteo Franchin
425b885f6e Fix issues found by static analysis
All of the issues that this patch fixes should not occur in practice,
but make the code a bit more robust. For example, this patch
default-initializes structures passed to Vulkan for initialization.
Normally, initialization should be done by the Vulkan entrypoint,
so it should be fine not initializing the structure as long as the
Vulkan API entrypoint exits with success status. It is still a good
idea to default-initialize anyway to make the behaviour deterministic
in cases where something is wrong in the system. All changes made
should have a negligible impact on performance for typical
applications.

Change-Id: Ia606ad2d3ea1627f9dfef0cadf93c7468ab568d8
Signed-off-by: Matteo Franchin <matteo.franchin@arm.com>
2022-07-21 19:05:53 +01:00
Rosen Zhelev
711836af6c Update Khronos headers API version
Change-Id: Ifa3f945a1216677c9410c09f4b4341a70d918514
Signed-off-by: Rosen Zhelev <rosen.zhelev@arm.com>
2022-07-12 15:01:19 +00:00
Iason Paraskevopoulos
32c5ad9d1b Remove swapchain from device_data after destruction
Fixes an issue, where the swapchain addresses weren't removed from the
device_private_data::swapchains member after swapchain destruction. This
could cause clashes with swapchains handled by different components
(e.g. ICD).

Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
Change-Id: I0e05734368ef6100b67ded973283f99ef248e540
2022-07-07 08:33:57 +00:00
Matteo Franchin
dd1f3f24cc Enable instance extensions required by layer
The layer needs functionality that is not part of Vulkan 1.0 and is
provided by either Vulkan 1.1 or separate Vulkan extensions.
The layer used to solve this issue by bumping the API version passed
by the application in VkCreateInfo to 1.1 if this was set to 1.0.
This workaround does not seem to be working anymore with recent
versions of the loader. Fortunately, the loader now allows layers
to change the extension lists passed by the application.
This patch changes the layer to use this approach and removes the
API bump logic.

Documentation is updated accordingly.

Change-Id: I61c426311612c7f288a0f7d969782d6c5365acf5
Signed-off-by: Matteo Franchin <matteo.franchin@arm.com>
2022-05-30 13:51:20 +01:00
Dennis Tsiang
2bc2109194 Add support for VK_EXT_image_compression_control_swapchain
Implement support for VK_EXT_image_compression_control_swapchain
for both the Wayland and the headless windowing systems.
The extension can be conditionally enabled through the new build option
BUILD_WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN. Compiling with this
option enabled requires recent Vulkan headers (1.3.213)
Note also that support in the layer is enabled conditionally to
the ICD supporting VK_EXT_image_compression_control.

Update the WSIALLOC interface to version 2 and add support to
prefer selection of a format with the highest fixed rate compression
from the formats provided. This is used to pick a fixed rate
compression when VK_IMAGE_COMPRESSION_FIXED_RATE_EXPLICIT_EXT is
specified during swapchain creation.

Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
Signed-off-by: Rosen Zhelev <rosen.zhelev@arm.com>
Signed-off-by: Normunds Rieksts <normunds.rieksts@arm.com>
Signed-off-by: Matteo Franchin <matteo.franchin@arm.com>
Change-Id: Ie37e6901042a65f2a408e428a705b5a24227b262
2022-05-25 16:49:52 +01:00
Iason Paraskevopoulos
2aa963ba92 Implement VK_KHR_get_surface_capabilities2 entrypoints
Adds support for the VK_KHR_get_surface_capabilities2 extension.

Change-Id: Iae882a41819baf413a0ba949ec44d6e722ebca5a
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
2022-03-10 10:28:33 +00:00
Iason Paraskevopoulos
feee8f5d36 Use common code for get_surface_formats implementations
Adds a template function for setting the supported surface formats for
a surface. This function is used in the get_surface_formats
implementation of both the WSI backends, which previously were
implementing the same logic independently.

Removes the unused surface argument from get_surface_formats and
get_surface_capabilities.

Change-Id: Ib220166675d1c24aeef230cf9f510abba9e42a61
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
2022-03-10 10:22:22 +00:00
David Harvey-Macaulay
ba0684b5e0 Mark fences and semaphores as already signalled in AcquireNextImage
The VK_KHR_external_[fence|semaphore]_fd extensions allow sync
primitives to be signalled without the use of QueueSubmit. Using these
extensions in AcquireNextImage instead of using QueueSubmit offers two
advantages: (1) there is no waiting for work to complete in the queue
before the primitives are signalled and (2) there is no data race if
the application happens to call QueueSubmit on the same queue at the
same time.

The QueueSubmit method of signalling sync primitives continues to be
used for ICDs that do not support the external FD extensions.

Signed-off-by: David Harvey-Macaulay <david.harvey-macaulay@arm.com>
Change-Id: Ib4a922d44430110e2353a4e0221e27017e72abab
2022-02-08 15:27:29 +00:00
David Harvey-Macaulay
9f1c4c1733 Remove ENABLE_WSI_LAYER option
By removing this option, the layer will be enabled by default.

Signed-off-by: David Harvey-Macaulay <david.harvey-macaulay@arm.com>
Change-Id: I6d62e770d914098ad6f0d7d74fb45ce3f8fdbc01
2021-11-26 09:10:04 +00:00
Iason Paraskevopoulos
96657394ec Store enabled instance and device extensions
Stores the enabled instance and device extensions during
vkCreateInstance and vkCreateDevice respectively. This fixes an issue
where function pointers for functions of disabled extensions were
returned during vkGetInstanceProcAddr/vkGetDeviceProcAddr.

Adds functionality for adding extensions that belong to a subset of
other extensions in util::extension_list.

Adds function for checking if the proper surface extension has been
enabled in each WSI backend.

Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
Change-Id: If5e23e0d07c9f09006be18c410c4e1d4c3a1e676
2021-11-17 11:51:30 +00:00
Iason Paraskevopoulos
0c8259a994 Merge master branch into multiple_swapchains_present_req
Change-Id: I153e7a78609651bbfdf4fc0b6675d0ea97763905
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
2021-11-12 12:21:10 +00:00
Ben Davis
6ef056b517 Update code to use modern c++ style
Fix warnings given by clang-tidy 8 with checks 'bugprone-*,modernize-*'

Change-Id: I2e5660c5872728f957869c66b1143cfcc76bc20e
Signed-off-by: Ben Davis <ben.davis@arm.com>
2021-11-11 10:15:22 +00:00
Iason Paraskevopoulos
1da8a30a6d Merge master branch into multiple_swapchains_present_req
Change-Id: Ibc6c094d85795e532e59184252896ecd05b50019
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
2021-11-10 15:38:07 +00:00
Dennis Tsiang
080d5d2bf7 Set default visiblity of functions to hidden
Reduce the number of functions that are exported by the layer. This
helps resolve dynamic linking issues where multiple functions are named
the same in different shared libraries. Also add function specifiers and
calling conventions to all extern "C" functions.

Change-Id: I07b33ff8d066e33c5dbdf0cbc13aa7835a78220b
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
2021-11-08 13:42:20 +00:00
Iason Paraskevopoulos
937552cc18 Use device allocator for stage flags vector
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
Change-Id: I2b7882e10eca2f4cfbd3668b6265d5b6093c4272
2021-11-05 11:40:45 +00:00
Iason Paraskevopoulos
17204773df Handle present request for multiple swapchains
Adds an additional semaphore for every swapchain image to be waited for
before the present engine access an image. During a present request with
multiple swapchains, these semaphores are grouped together and are
signaled after the incoming pWaitSemaphores signal.

Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
Change-Id: I94cabbf5f7d9a45dceef60eec7773b48ccc32078
2021-11-01 17:28:43 +00:00
Iason Paraskevopoulos
212a7314c3 Update json manifest
Updates the api_version to 1.2 in the json manifest. Also, adds the
entrypoints node in the device extensions as it is mandated by the
loader's documentation when an extension adds Vulkan API functions.

Removes support for intercepting vkEnumerateInstanceLayerProperties,
vkEnumerateInstanceExtensionProperties and
vkEnumerateDeviceExtensionProperties as the loader can get the
information they provide from the layer's json manifest in its
terminator functions.

Change-Id: I2c304d1d2ea17d3ea0c723694f8fc4c8a92054a0
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
2021-10-07 13:22:00 +00:00
Dennis Tsiang
b4db2258ab Add support for some Vulkan 1.1 structs
This commit adds support for VkBindImageMemorySwapchainInfoKHR and
VkImageSwapchainCreateInfoKHR.

Change-Id: I3d87cd7df380e59ceb386f08437c5d6f09dcee1f
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
2021-09-23 15:35:51 +01:00
David Harvey-Macaulay
8808cc35ba Return vkDestroyDevice from vkGetDeviceProcAddr
The vkDestroyDevice entrypoint was listed as a instance level
entrypoint, that is, to be returned by vkGetInstanceProcAddr; however,
vkDestroyDevice is a device level entrypoint. Consequently, the layer
implementation was not called by the loader upon application calls to
vkDestroyDevice and this caused memory leaks within the layer.

Change-Id: I9d5807ff17965281580cd80eb74b07fb038073b1
Signed-off-by: David Harvey-Macaulay <david.harvey-macaulay@arm.com>
2021-09-17 12:29:15 +00:00
Rosen Zhelev
d7aabddf40 Use explicit synchronization for Wayland surfaces
This change adds the use of zwp_linux_explicit_synchronization_v1 to
attach a Sync FD fence on presented image submitted to the compositor.

The change introduces the wsi/synchronization.hpp header and
implementation of the synchronization primitives used by WSI
implementations. Currently only Vulkan fences and fences exportable to
Sync FD are supported.

Change-Id: Ic7d6b712cc8ae8d171f799af51a70be62585b8a1
Signed-off-by: Rosen Zhelev <rosen.zhelev@arm.com>
2021-09-14 10:52:28 +01:00
Rosen Zhelev
c7be05e3ff Implement objects associated with VkSurface
Defines an abstract wsi::surface object to be implemented by each WSI
backend. This object is then associated with the corresponding VkSurface
object in the instance specific data.

To keep track of these objects the layer now intercepts
vkDestroySurfaceKHR, while specific surface creation entrypoints are
intercepted by individual WSI backends.

In addition this change should allow for fixing incompatibility issues
with layers that wrap VkSurface which breaks casting to the Loader's ICD
VkSurface type.

Make greater use of util::unique_ptr and allow for such pointers to be
constructable when casting derived types.

Change-Id: I163e9c47088ad9989583ebce1319b1fc05559d73
Signed-off-by: Rosen Zhelev <rosen.zhelev@arm.com>
2021-08-17 16:42:21 +01:00
Ben Davis
bcd934f2aa Add vulkan 1.1 function entrypoints
Implement vkGetDeviceGroupSurfacePresentModesKHR,
vkGetDeviceGroupPresentCapabilitiesKHR, vkAcquireNextImage2KHR and
vkGetPhysicalDevicePresentRectanglesKHR function entrypoints in the
layer.

We assume that if the layer should not handle the surface the device or
instance should handle it as appropriate and fallback to this
implmentation.

Change-Id: Iafc585d8738ad80413ad616d834d966f92c4f8cb
Signed-off-by: Ben Davis <ben.davis@arm.com>
2021-08-09 11:38:04 +01:00
Normunds Rieksts
d63261cce5 Remove usages of generic allocator in the layer
Remove all the leftover instances in layer that still use the
generic allocator rather than the VkAllocationCallbacks

Add additional memory utility that allows to release memory
allocated by custom allocators using RAII

Change-Id: I43594ddd3c506048ca0f02e31b64597a7abc481b
Signed-off-by: Normunds Rieksts <normunds.rieksts@arm.com>
2021-07-22 19:05:26 +01:00
Fufu Fang
b64498c021 Refactoring of extension_list
Unused methods removed. Specialised methods moved out
of the extension_list utility and closer to the point
of usage.

Signed-off-by: Fufu Fang <fufu.fang@arm.com>
Change-Id: I8e6d2786881b5306de21797cfdda46d0e678da8d
2021-07-06 10:37:40 +01:00
Normunds Rieksts
af2af23333 Ensure allocations happen through custom allocators
Document instance_private_data and device_private_data.

Add additional utility containers (util::unordered_set,
util::unordered_map) that ensure that the storage containers
we use allow the use of the Vulkan allocation callbacks.
Additionally, ensure that these allocations don't throw in
case host runs out of memory but rather return the appropriate
Vulkan error code.
Also keep a copy the allocators so they can be used in other layer
functionality to facilitate following the Vulkan specification around
memory allocation.

Add additional utility util::optional that currently makes it easier
to handle errors in the containers described above.

Fix some small issues with the vkCreateInstance/vkCreateDevice
handling and ensure that vkDestroyDevice is called in the layer
handler.

Change-Id: Ic9d8ece405c82e743a2c016cc3dabf984cf77fc1
Signed-off-by: Normunds Rieksts <normunds.rieksts@arm.com>
2021-06-28 11:51:33 +01:00
Iason Paraskevopoulos
926cd66fcd Add support for multiplane swapchain images in Wayland
Updates wsialloc and wsi::wayland::swapchain to support multiplane
image allocations.

Uses the custom allocator for allocations in Wayland image creation.

Change-Id: I1950b14b75711a76521bbf1967c3c835d006f8a8
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
2021-04-23 09:47:31 +01:00
Iason Paraskevopoulos
8dc4d923ff Adds initial support for VK_KHR_wayland_surface.
Very basic Wayland support is implemented by importing
memory with VK_EXT_image_drm_format_modifiers.
The current implementation requires an external system
memory allocator. An API for this allocator is defined
in util/wsialloc/wsialloc.h and an implementation using
the ION memory allocator is included.

Outstanding issues:
 * This is an initial prototype for Wayland support and
   has many outstanding TODOs which need addressing to
   properly use the Wayland protocol.
 * Using ICD Exported memory instead of a system allocator
   is not implemented.

Wayland support is still experimental and outstanding issues
will be fixed in future commits.

Change-Id: I1b0d5991e15ff1cf25ebbab3392a631b021e8c17
Signed-off-by: Rosen Zhelev <rosen.zhelev@arm.com>
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
2021-02-09 18:22:09 +00:00
Joe Jenner-Bailey
950cdd406a layer: improve how layer handles Vulkan extensions
In vkCreateInstance:

- ppEnabledExtensionNames is checked to determine which window-system
  platforms the layer should enable support for.
- support in the layer is always enabled if possible, even if this may
  be provided by the ICDs. Platforms not supported by the layer should
  still be correctly supported by the ICDs (untested.)
- pApplicationInfo is changed to bump the Vulkan API version
  in order to enable instance extensions that are necessary for some
  of the platforms implemented in the layer.

In vkCreateDevice:

- ppEnabledExtensionNames is extended with device extensions required
  by the layer.
- if the extensions are not supported by the physical device, the
  layer fails to initialize the device.

Change-Id: Ibdd69fca38e7909d5b8f0ac7698805ea5f425ac6
Signed-off-by: Joe Jenner-Bailey <joe.jenner-bailey@arm.com>
Signed-off-by: Matteo Franchin <matteo.franchin@arm.com>
2021-02-05 11:22:32 +00:00
Iason Paraskevopoulos
e5f77f7347 Fix layer's memory errors
Fixes the wrong allocation of extensions properties.

Adds a call to the dispacher's DestroyInstance function before the
destruction of the instance.

Change-Id: I169bb3ba670d89e30af1f6ce47c536477978c169
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
2020-11-26 10:24:45 +00:00
Rosen
3262341839 Move WSI type specific calls
Move all WSI type specific calls to WSI factory methods. This
removes headless references in layer/ and allows for simpler
support of multiple windowing systems.

Change-Id: I757a7a3bb4267783420b52cceb3bde8ce233297e
Signed-off-by: Rosen Zhelev <rosen.zhelev@arm.com>
2019-11-21 15:23:59 +00:00
Matteo Franchin
7670a0ac84 Fix small issues in documentation and code
A couple of details in the installation instructions needed updating.
Also fixed a warning message due to a missing return statement (the
return value is currently not used in calls to the function).

Signed-off-by: Matteo Franchin <matteo.franchin@arm.com>
Change-Id: I715b954579253e664ebe01f757587e0602ad82e7
2019-09-11 13:26:22 +00:00
Matteo Franchin
9b698b4a2f Initial sources for the vulkan-wsi-layer project
This commit adds the initial sources for the vulkan-wsi-layer project:
a Vulkan layer which implements some of the Vulkan window system
integration extensions such as VK_KHR_swapchain.
The layer is designed to be GPU vendor agnostic when used as part of the
Vulkan ICD/loader architecture.

The project currently implements support for VK_EXT_headless_surface and
its dependencies. We hope to extend support for further platforms such
as Wayland and direct-to-display rendering in the future.

This initial commit collects contributions from different individuals
employed by Arm.

More information on the project (building instructions, how to
contribute, etc.) can be found on the README.md file at the top of the
project tree.

Signed-off-by: Matteo Franchin <matteo.franchin@arm.com>
2019-05-31 15:48:05 +01:00