Commit graph

115 commits

Author SHA1 Message Date
Dennis Wildmark
6c3f4e9326 Refactor framebuffer format support
Add support for format modifiers in framebuffers using
drmModeAddFB2WithModifiers.
Add compilation flag to force VK_KHR_display to not support format
modifiers for framebuffers.

Change-Id: Ie8eb2e96e543a15ab3534a7e73425f277a4b7d58
Signed-off-by: Dennis Wildmark <dennis.wildmark@arm.com>
2024-04-16 14:40:31 +02:00
Dennis Wildmark
23cd21c99c VK_KHR_display swapchain implementation
Implementation of VK_KHR_display swapchain class. VK_KHR_display is
another WSI backend that provides surfaces to render directly to a
display. The swapchain class is responsible for creating and managing a
swapchain based on the specific type of surface provided by
VK_KHR_display.

Change-Id: I9b103c20c3444b1ca75f3df7edf6b66fc87a0992
Signed-off-by: Dennis Wildmark <dennis.wildmark@arm.com>
2024-03-27 09:35:02 +00:00
Dennis Wildmark
46c770bea6 Make drm_display singleton
Make the drm_display class a singleton and automatically initialize the
display. Add environment variable for configuring display device.

Change-Id: I869fbf7414bc4a2270b3583577050b7cd8c5b184
Signed-off-by: Dennis Wildmark <dennis.wildmark@arm.com>
2024-03-27 10:33:54 +01:00
Dennis Wildmark
19cd4376d1 VK_KHR_display surface_properties implementation
Implementation of the surface_properties interface for VK_KHR_display.

Signed-off-by: Dennis Wildmark <dennis.wildmark@arm.com>
Change-Id: Idd3b53bec0d0a829478d51b4263db767c872d0e5
2024-02-26 12:07:45 +00:00
Dennis Wildmark
2837bab5c4 Refactor dispatch table to fix extension entry point visibility
Add functionality to the dispatch tables enabling the layer to hide
entrypoints from user. Add filtering to
vkGetDeviceProcAddr/vkGetInstanceProcAddr to only return pointers to
entrypoints which belongs to user enabled extensions.

Signed-off-by: Dennis Wildmark <dennis.wildmark@arm.com>
Change-Id: Ieec305cc9479363de0b8e1618c671c08f7af3997
2024-02-14 14:33:40 +00:00
Normunds Rieksts
bf7d090fdc Fix validation issues with fence import
When fences are imported with a handle type with copy payload transference semantics then the flags must contain VK_FENCE_IMPORT_TEMPORARY_BIT

Change-Id: I950a01465ed68e7c5b35ea17a778ee7327639108
Signed-off-by: Normunds Rieksts normunds.rieksts@arm.com
2024-02-08 14:03:41 +00:00
Dennis Tsiang
7fda25462e Fix issues flagged by static analysis
Add error handling to snprintf.

Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
Change-Id: Id0c0478254c57cb62af6f9cadde16f73b071f466
2024-01-05 12:41:47 +00:00
Dennis Tsiang
760d2f220d Fix validation error when importing sync fds
Vulkan spec mandates that if handleType of VkImportSemaphoreFdInfoKHR
refers to a handle type with copy payload transference semantics
(which VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT is), then flags
must contain VK_SEMAPHORE_IMPORT_TEMPORARY_BIT.

Change-Id: I426bc4749da48aa12aee55eaa3a1739c7226e8e8
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
2023-11-01 14:44:13 +00:00
Jiyu Yang
619f5f0e1e add missing <system_error> include
fix build error with GCC 13:

```
wsi/swapchain_base.cpp:150:35: error: expected unqualified-id before ‘&’ token
150 |    catch (const std::system_error &)
    |
```

Signed-off-by: Jiyu Yang <jiyu.yang@nxp.com>
2023-10-31 08:54:05 +00:00
Jiyu Yang
5f1733d88b fix Use after free
Signed-off-by: Jiyu Yang <jiyu.yang@nxp.com>
2023-10-31 08:54:05 +00:00
Daniel Levin
b1621015c7 Use wayland-scanner public-code 2023-10-31 08:52:32 +00:00
Daniel Levin
35f74ee41a Use find_program instead of pkg_get_variable for wayland-scanner 2023-10-31 08:49:27 +00:00
Daniel Levin
d3e284cd7e Fix formatting long as %d in util/log.cpp
Changed log level type from long to int, since value is
expected to be a small integer in range [0-3].

Since codebase requires C++17 also replaced strtol with
std::from_chars(), which will parse string as int, and skip updating
the defaut value if VULKAN_WSI_DEBUG_LEVEL env var does not represent
int.

Signed-off-by: Daniel Levin <daniel.levin@amd.com>
2023-10-19 08:23:09 +00:00
Angeliki Agathi Tsintzira
188ffe6a26 Enable instance extensions
Modify the layer so that instance extensions needed for Wayland are only enabled when Wayland is selected.

In the past, the layer was changed to explicitly enable the instance extensions it needs in the intercepted calls to vkCreateInstance. Therefore, the layers always enabled the extension VK_KHR_external_memory_capabilities, despite this is only required by Wayland.

In this patch, this extension is only enabled when Wayland is enabled, i.e. when VK_KHR_wayland_surface is part of the extensions passed to vkCreateInstance.

Signed-off-by: Angeliki Agathi Tsintzira <angelikiagathi.tsintzira@arm.com>
Change-Id: I57e98b36e42012ba46769e9dd760a628a09b9ba5
2023-09-28 09:35:19 +01:00
Dennis Tsiang
07c1a4aa21 Avoid returning VK_ERROR_DEVICE_LOST
VK_ERROR_DEVICE_LOST implies that the GPU device has entered an
unrecoverable state and further API usage is considered invalid. Thus,
it should be used sparingly. For the layer code, we were returning
VK_ERROR_DEVICE_LOST for implementation specific errors as sort of a
catch all, even when the GPU was still usable. Instead, it would be
better to return other error codes to denote a failure somewhere.

For the page_flip_thread, if we receive a VK_TIMEOUT waiting for the
image's present fence, then we continously retry. All
other error codes will still be propagated.

For the wayland swapchain, instead of returning VK_ERROR_DEVICE_LOST
when we encounter an error in the dispatch_queue call, return
VK_ERROR_SURFACE_LOST_KHR, as this is more suitable.

Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
Change-Id: Iccc3e75b60fe9296b10963e7f0b3041fbcd29198
2023-04-20 09:33:20 +01:00
Normunds Rieksts
43d806de38 Replace VK_LAYER_EXPORT with VWL_VKAPI_EXPORT 2023-04-17 10:59:19 +00:00
Dennis Tsiang
5befc4cb7d Move memory handle type setting into allocate_wsialloc
This keeps it closer to where the rest of the external_memory
parameters are set.

Change-Id: Ibc46e90cebc6d715003772cc78294e164085cfa6
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
2023-02-16 09:44:58 +00:00
Nir Ekhauz
5b973740b0 Change vulkan wsi project to use "main" branch
Signed-off-by: Nir Ekhauz <nir.ekhauz@arm.com>
Change-Id: I82fa871371bf025a5c181f3b55812a2bee80d566
2023-02-12 13:39:28 +02:00
Dennis Tsiang
c33a17f103 Use strtol instead of std::atoi in logging
strtol does not throw exceptions.

Change-Id: I6d6d3c32c2b61ed0307370bbfc3ce333adb5c504
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
2023-02-07 14:23:49 +00:00
Normunds Rieksts
2ad81d6b97 Fix a bug in queue submission
Fixes a bug in queue submission where the wrong amount of
VkPipelineStageFlags were passed to vkQueueSubmit when the number of
semaphores to wait on were more than 1.

Change-Id: Ic66e0c6a5e4f60659a0fb31c64c565820d4708a8
Signed-off-by: Normunds Rieksts <normunds.rieksts@arm.com>
2023-01-10 15:45:09 +00:00
Normunds Rieksts
566a6ee68d Extend TRY macro to print out error messages
Extends the TRY macros exposed by the helper header to be able to print
out error messages.

Change-Id: I61c607376304ba744a95dd6782bb29653235096a
Signed-off-by: Normunds Rieksts <normunds.rieksts@arm.com>
2022-11-24 11:24:34 +00:00
Dennis Tsiang
92a3da6ad2 Fix issues reported by static analysis tools
Fix CERT C/CPP issues flagged by static analysis tools.

Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
Change-Id: I6758bb83bd0647e4e6b7ccbf84e94f05ba90e160
2022-11-11 14:27:03 +00:00
Ben Davis
48310faa25 Add pre-commit hook to check for copyright header
Change-Id: I1d3b9d51305d257c9c322caf4cf4d97667fb687b
Signed-off-by: Ben Davis <ben.davis@arm.com>
2022-10-31 13:42:51 +00:00
Dennis Tsiang
292a3c14d7 Decouple creation, allocation and binding of images from Wayland backend
A lot of the steps involved in creating a VkImage, allocating backing
memory, and binding the VkImage to the memory do not rely specifically
on Wayland features and could be common to other WSI backends.

This commit attempts to decouple the create_and_bind_swapchain_image()
function in the wsi/wayland/swapchain.cpp from Wayland and wsialloc
specific parts, and instead move the independent parts related to
external memory management to a new external_memory class. This will
allow the independent code to be re-used in future WSI backends.

Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
Change-Id: I8c13ccbbfaef0d345fcd06192e6de484dd53645f
2022-10-21 15:28:09 +00:00
Normunds Rieksts
25073787e6 Add codebase guidelines to the project 2022-10-20 08:02:35 +00:00
Lior Dekel
908518c92e Adding VK_KHR_shared_presentable_image basic support
To comply with ICDs that expose the
VK_KHR_shared_presentable_image extension, the Layer needs to
handle VkSharedPresentSurfaceCapabilitiesKHR struct (holds
sType=VK_STRUCTURE_TYPE_SHARED_PRESENT_SURFACE_CAPABILITIES_KHR)
for queries on the VkSurfaces managed by the Layer.
A simple implementation that sets the minimum required flags is
provided in this commit.
Since no WSI layer swapchain will support the shared presentable modes,
no other functionality is required. VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
must be included in the sharedPresentSupportedUsageFlags field but
implementations may support additional usages.

Signed-off-by: Lior Dekel <lior.dekel@arm.com>
Change-Id: I73b29e54a84376c663b3cada989c910d1ba27293
2022-09-13 13:46:39 +03:00
Ben Davis
962472c729 Add Pre-commit config and add to CI pipeline 2022-08-25 10:24:47 +00:00
Aron Virginas-Tar
8444165b25 Update WSI layer to use C++17 2022-08-19 08:56:59 +00:00
Dennis Tsiang
128fafb083 Increase max swapchain image count
3 is not enough for performance testing. Let us double the maximum
number we can make.

Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
Change-Id: I11a055ede33c9d10311109085e59d3f8c1fbcb7e
2022-08-15 14:58:25 +01:00
Aron Virginas-Tar
e40628a135 Remove duplication of create_aliased_image_handle implementations
Signed-off-by: Aron Virginas-Tar <aron.virginas-tar@arm.com>
Change-Id: I37043259e349874a9a7eb495a0e3b939c144798f
2022-08-03 13:43:38 +00:00
Aron Virginas-Tar
36b640c468 Fix issue found by static analysis
Replaced call to unsafe function strcpy() with call to snprintf().

Signed-off-by: Aron Virginas-Tar <aron.virginas-tar@arm.com>
Change-Id: I0de5f869200e74b6d0c8224da2e41d6c4b8b6f4d
2022-08-03 13:39:26 +00:00
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
Lior Dekel
91583f1af2 Create common functions in surface_capabilities class
Signed-off-by: Lior Dekel <lior.dekel@arm.com>
Change-Id: Ia5053b202f4e64fd7a255ede513653a951ab3d41
2022-07-13 14:14:51 +00: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
Iason Paraskevopoulos
626e40ba96 Add WSI integration guide
Adds a guide on implementing a WSI backend and extra documentation in
a few functions in swapchain_base.

Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
Change-Id: Ibdc702a05605989940966aae168331268c1ce2ba
2022-06-15 10:33:32 +01: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
Dennis Tsiang
e78252429a Fix FD ownership issue in Wayland Vulkan import
When a file descriptor is imported in Vulkan as a dma buf the Vulkan
implementation takes ownership. We use this property to manage the
lifetime of file descriptors allocated by WSIALLOC by importing them as
VkDeviceMemory. After import the WSI Layer doesn't need to close any
file descriptors and instead only needs to destroy the VkDeviceMemory
object.

However after import the original file descriptor should not be used by
the application. Currently the WSI Layer Wayland implementation violates
this by using the FD to pass to the compositor. This commit fixes the
issue by initiating the Wayland requests before importing the fd.
Internally libwayland will duplicate the fd.

Change-Id: I3ca877f90f0139cf23b8b39c6024e8815b82d692
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
2022-01-24 17:23:03 +00:00
Ben Davis
79b5d296c2 Remove DEBUG build option
Users should use CMAKE_BUILD_TYPE to set the build type

Change-Id: I526b3a96f798a39ceca11674bf1e0b6964a3da7d
Signed-off-by: Ben Davis <ben.davis@arm.com>
2021-12-15 09:35:50 +00:00
Rosen Zhelev
5bed7d0c9b wayland: Fix nulltpr dereference on deprecated swapchains
Fixes a nulltpr dereference when a buffer release event is processed on
deprecated swapchains. In such a case some of the swapchain images are
invalid and associated resources have been freed.

Change-Id: I8f1c66e42e900d63c8c43cb53068a8aee9ea25a9
Signed-off-by: Rosen Zhelev <rosen.zhelev@arm.com>
2021-12-13 09:57:53 +00:00
Fufu Fang
c6a38f53c2 Casting operands to a wider type to prevent integer overflow
Previously the calculation for total_size was done in 32-bits, as the
operands were all 32-bit signed or unsigned integers. This led to
integer overflow when the extent being allocated is too large.
total_size is finally cast to size_t, as the kernel UAPI for ION uses
size_t.

Change-Id: I7a76b2c18be25fda0bf6ef70cd8a6fe717c2903c
Signed-off-by: Fufu Fang <fufu.fang@arm.com>
2021-12-10 12:11:30 +00:00
Dennis Tsiang
c06709c840 Include modifiers in params creation
Include the modifiers in the call to zwp_linux_buffer_params_v1_add

Change-Id: If4407af5f402a418b69a670d316fe56cce9f2a14
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
2021-12-09 11:52:23 +00:00
Dennis Tsiang
0c7dcc9be9 Fix bug in has_descendant_started_presenting in headless backend
If there exists two swapchains where one is a descendant of another, we
need to return VK_ERROR_OUT_OF_DATE_KHR error if the application tries
to present from the ancestor when the descendant has started presenting.

The has_descendant_started_presenting() function checks whether the
descendant has started presenting by looking for pending images in the
descendant's list of swapchain images. However, the descendant could
have already presented its pending image(s) before the ancestor arrives
at this check. In this scenario, the descendant will have marked the
swapchain image(s) as now free, and therefore when the ancestor looks
for pending images it will fail to find any. This causes the function to
incorrectly return false.

This bug can be resolved by creating a new boolean member variable to
track whether the swapchain has started presenting.

Change-Id: Ibc3399a4bb05f89940f0b595d25aa07b8e2a2cb8
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
Signed-off-by: Normunds Rieksts <normunds.rieksts@arm.com>
2021-12-06 13:06:33 +00:00
Ben Davis
8dacefb892 Check for required protocols in vkGetPhysicalDeviceWaylandPresentationSupportKHR
Add additional checks ensuring required protocols are supported.
Currently Version 3 of zwp_linux_dmabuf_v1 and Version 1 of
zwp_linux_explicit_synchronization_v1 are required.

Change-Id: Ie1ed37a22254eb14ebdb9cc7d3a35fc99fcb4481
Signed-off-by: Ben Davis <ben.davis@arm.com>
2021-12-02 14:26:45 +00:00
Fufu Fang
a41dce418c Improve error handling when copying extension name
The extension list now calls abort() if an extension name exceeding
the length limit is copied.

Change-Id: I105946b647ebd0087dc892d7c8a227628da31966
Signed-off-by: Fufu Fang <fufu.fang@arm.com>
2021-11-29 09:18:11 +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