Commit graph

58 commits

Author SHA1 Message Date
Maged Elnaggar
fb23a9b14e Support VK_KHR_swapchain_mutable_format extension
- Add support for VK_KHR_swapchain_mutable_format extension to the Layer.
- Expose support for the VK_KHR_swapchain_mutable_format extension.
- Improve find_extension helper API to be spec-correct, const-correct,
  and clearer by using the right base type (VkBaseInStructure for input,
  VkBaseOutStructure for output),
  and concise docs explaining it returns the first matching struct or nullptr.
- Correctly use image_create_info instead of m_image_create_info in
  create_swapchain_image function for Wayland.

Signed-off-by: Maged Elnaggar <maged.elnaggar@arm.com>
Change-Id: Id40b28977e63ba76012d3a8f693327f757d75dcd
2025-09-11 09:28:03 +01:00
Maged Elnaggar
78b21da4ef Adding exception-safe custom mutex to the WSI layer
Introduce util::mutex, util::recursive_mutex
and util::unique_lock; switch WSI layer call sites to it.
All locks are acquired via try_lock(), no system_error leaks.

Signed-off-by: Maged Elnaggar <maged.elnaggar@arm.com>
Change-Id: Ide9ef4318be7cc47e9577059695cc298f8b8e579
2025-09-05 16:06:38 +01:00
Maged Elnaggar
d1ade3d218 Append WSI layer warning flags
- switch CMAKE_CXX_FLAGS and C_FLAGS to string(APPEND)
- concatenate flags without semicolons or list issues
- preserve existing: -Wall -Werror -Wextra -pthread -fPIC
- add new diagnostics:
  Wdouble-promotion, Wnon-virtual-dtor,
  Wdelete-non-virtual-dtor, Woverloaded-virtual,
  Wcast-qual, Wmissing-field-initializers,
  Werror=return-type, Wmissing-format-attribute
- add C-only check: -Wstrict-prototypes

Change-Id: Icae6cf649b9ab88c1d0bc736b91b4bc50e24c9dd
Signed-off-by: Maged Elnaggar <maged.elnaggar@arm.com>
2025-08-05 13:34:59 +01:00
Iason Paraskevopoulos
281049aa78 Merge remote-tracking branch 'main' into add_swapchain_image_creator
Change-Id: I22a4c697c8b1181127242848f37ea081243f0d03
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
2025-04-25 15:30:01 +01:00
Iason Paraskevopoulos
ca3820a0ba Add external memory extension
Adds a swapchain create info extension for creating an image using
external memory. This removes the need for modifying the
image_create_info in the display and wayland backends. There is still
code duplication left in these backends though, because swapchain
allocation needs to know the selected format. This will be removed when
the swapchain images will be created from the swapchain image creator.

Moves the definition of drm_format_pair to drm_utils.

Removes two step initialization from swapchain_wsi_allocator.

Change-Id: I0c937a59cc62e7e3134f0af4728fdda3739237bd
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
2025-04-25 15:28:39 +01:00
Dennis Tsiang
2d1b682129 Use wp_presentation_feedback to update the presented ID value 2025-04-01 09:27:18 +00:00
Normunds Rieksts
2924e17553 Add DRM support for ABGR210101010 format 2025-01-28 17:07:50 +00:00
Iason Paraskevopoulos
cd19e3827b Add dma_buf_heaps wsialloc implementation
Change-Id: I738f8cbfb1aec52a122689ebaeb7f5b898ba200a
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
2024-10-31 10:40:09 +00:00
Iason Paraskevopoulos
8619f42973 Add helper functions to wsialloc
Moves out the non ion specific code from the wsialloc ion implementation
to a new wsialloc_helpers file.

Change-Id: I7ca816b27eb7e68fd1f138ec7bda006b204c0cbe
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
2024-10-31 10:40:09 +00:00
Iason Paraskevopoulos
7ebafbfb79 Add stdexcept in custom_allocator.hpp 2024-10-25 09:57:24 +00:00
Maged Elnaggar
57fedd8cdb Enable -Werror on Vulkan WSI Layer 2024-10-22 09:14:54 +00:00
ginujacob
9abd1af3ce Handle VkPresentTimingsInfoEXT
Implements the entrypoint vkSetSwapchainPresentTimingQueueSizeEXT and
handles VkPresentTimingsInfoEXT. The presentation timing queue is
also implemented the present id from parsing VkPresentTimingsInfoEXT is
stored in the queue.

Signed-off-by: ginujacob <ginu.jacob@arm.com>
Change-Id: I81b6113b54db5e59f7018ef9a22e80af6dcdd568
2024-10-11 18:56:31 +01:00
Normunds Rieksts
94dd9840c9 Implement support for marking frame boundaries 2024-10-01 15:18:22 +00:00
Dennis Tsiang
b565608724 Fix wsign-compare warning
Compiler warning was being flagged between the integer comparisons as
we were comparing a int with a size_t. This commit resolves the
warning by updating the int to a size_t.

Change-Id: Ibcb72ac9abb6c8e18bc8aa1e33efadc9ef79a564
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
2024-09-05 10:30:05 +01:00
Angeliki Agathi Tsintzira
1fa0ac21f3 Fix the number of planes calculation
Previously, the number of planes was incorrectly calculated.
The number of planes for non-linear images was the format
planes from wsialloc instead of the memory planes expected
by the implementation.

Additionally, the VK_IMAGE_CREATE_DISJOINT_BIT was based on
the format planes during image creation, instead of using the
allocation planes from wsialloc.

This commit corrects these issues by ensuring the plane count
and disjoint bit is set based on the appropriate memory planes.

Signed-off-by: Angeliki Agathi Tsintzira <angelikiagathi.tsintzira@arm.com>
Change-Id: I47ca4a0c710cdf21d94705c57f08de4f04b3a761
2024-08-13 19:27:55 +01:00
Dennis Wildmark
8da77f2b8b VK_KHR_display surface_properties implementation
Implementation of the surface_properties interface for VK_KHR_display.

Change-Id: Idd3b53bec0d0a829478d51b4263db767c872d0e5
Signed-off-by: Dennis Wildmark <dennis.wildmark@arm.com>
Signed-off-by: Fufu Fang <fufu.fang@arm.com>
2024-08-12 11:44:22 +00:00
Dennis Tsiang
4423a52816 Update clang-format rules
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
Change-Id: I76f87648a8ddaeddb6774123d263957b845d10a1
2024-07-04 10:30:42 +01:00
Iason Paraskevopoulos
b02486ff87 Extend wsialloc_alloc with disjoint information
Extends wsialloc_alloc to return whether or not the allocation will be
disjoint.

Groups wsialloc_alloc's return values to a struct.

Change-Id: I7542e37d8af16ce7989ab235c02305d562f3c667
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
2024-06-10 10:00:49 +01: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
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
Normunds Rieksts
43d806de38 Replace VK_LAYER_EXPORT with VWL_VKAPI_EXPORT 2023-04-17 10:59:19 +00: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
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
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
Aron Virginas-Tar
8444165b25 Update WSI layer to use C++17 2022-08-19 08:56:59 +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
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
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
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
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
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
Dennis Tsiang
1701c1fea4 Add versioning to wsialloc interface
The wsialloc interface now has explicit versioning which is used to
ensure that wsialloc implementations are compatible with the interface.
wsialloc implementations should define which version they are using and
upon version mismatch compilation will fail.

Also:
- add new WSIALLOC_MAX_PLANE macro to define the maximum number of
planes that the wsialloc should support.

Change-Id: I211fc4341f249deff0c005d946c483ba47366600
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
2021-11-15 13:59:10 +00:00
Normunds Rieksts
86fa15a8a2 Fix OOM issue
Fixes an issue where there was a chance that an exception would be
thrown when out of memory rather than returning an
appropriate VkResult code.

Additionally introduces a noncopyable utility class that can be used to
mark classes that should not have copy semantics

Change-Id: I1f84dc9bb1ea96db2a88a90d56adbee78b17c5e3
Signed-off-by: Normunds Rieksts <normunds.rieksts@arm.com>
2021-11-11 18:27:31 +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
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
Dennis Tsiang
b348247fbe Fix formatting issues
All files in the project should have an empty line at the EOF. Necessary
for some pre-processing tools.

Change-Id: Ic4502588f2733f669fc1edc898258f8589c484c6
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
2021-10-29 08:51:25 +00:00
Ben Davis
e00a2d8e40 Fix issues found by static analysis
Change-Id: I222ec3b352aa220b6c08df3a71de48178b67f06d
Signed-off-by: Ben Davis <ben.davis@arm.com>
2021-10-11 17:31:57 +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
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
Dennis Tsiang
03bc497ea4 Add ring buffer utility
Add new utility class implementation ring_buffer and replace existing
struct implementation.

Change-Id: I725033738bff73d33f938e64cc96ca9acb8a910c
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
Signed-off-by: David Harvey-Macaulay <david.harvey-macaulay@arm.com>
2021-08-26 13:42:23 +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
Normunds Rieksts
293ae2ab13 Implement a vendor agnostic wsialloc interface
Refactors the wsialloc interface in the layer.
This patch ensures that wsialloc interface could be ported
to different GPU architectures and systems that could
have different requirements

Change-Id: I6593f2373abc75fb2074700d156ba3797d7ff058
Signed-off-by: Normunds Rieksts <normunds.rieksts@arm.com>
Signed-off-by: Rosen Zhelev <rosen.zhelev@arm.com>
2021-07-28 15:39:11 +00:00
Dennis Tsiang
f22b7e33b9 Add documentation for unique_ptr and deleter class
Add brief documentation to explain what the custom util::unique_ptr and
deleter class is used for.

Change-Id: I7f4d456a34d55c09ad470b7c34e32b069203ca6b
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
2021-07-26 16:40:27 +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
Dennis Tsiang
241e05d3e4 Resolve segfault in wsialloc_delete
A segfault can occur if wsialloc_delete is called but m_wsi_allocator's
ion field has not been allocated yet, as the function attempts to access
the ion properties.

This commit resolves the issue by changing m_wsi_allocator to an opaque
struct and removing the fd property, which was not being used.
wsialloc_new is then changed to return a pointer to the struct and
the swapchain then carries this pointer around, which will be
initialised to nullptr in the swapchain constructor.

Change-Id: I202e967cff4555babf0ddcd387275b74470b09d5
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
2021-05-05 15:44:32 +01:00