Commit graph

81 commits

Author SHA1 Message Date
Alex Bates
ee3f6c5ab9 * Enables new warnings (which are made errors by -Werror)
* Wshadow warns when a variable shadows another
  * Wconversion warns on implicit int conversions
* Fixes warnings generated by them

Signed-off-by: Alex Bates <alex.bates@arm.com>
2025-12-17 09:55:55 +00:00
Iason Paraskevopoulos
5e225e0896 Detach proxies from queue
Instead of destroying the wayland buffers from the private data
we just remove the proxies from the queue.

Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
Change-Id: I0e9dd158feaffa697ea30b3c49d41661ec3d924c
2025-12-02 16:24:43 +00:00
Iason Paraskevopoulos
0866cfc352 Merge 'Fix a case where OOM condition was not checked' into 'main'
See merge request mesa/vulkan-wsi-layer!218
2025-12-02 14:36:52 +00:00
Iason Paraskevopoulos
d900831556 Fix queue destroy warning on the Wayland backend
Fixes an issue where the wl_queue used for the buffer events was
destroyed before destroying the wl_buffer objects.

Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
Change-Id: Ibe25f1f1f2100dda734c5f5788209ddf89c6d47d
2025-11-28 16:41:05 +00:00
Normunds Rieksts
e030203d82 Fix a case where OOM condition was not checked
Fixes a case where backing image memory creator allocation was not
checked for out of memory condition which results in failing OOM CTS
tests.

Change-Id: I6c203599eca5562f334d4e5e3f21c200dc667ee5
Signed-off-by: Normunds Rieksts <normunds.rieksts@arm.com>
2025-11-28 15:07:25 +00:00
Iason Paraskevopoulos
a0947a5ae8 Merge 'Fix and enhance Vulkan present timing and time domain handling' into 'main'
See merge request mesa/vulkan-wsi-layer!214
2025-11-25 10:12:34 +00:00
Ginu Jacob
71a0881d5c This change updates the present timing implementation with several fixes and improvements for better spec compliance:
* Updated present timing logic and corrected macros to match Vulkan specification values.
* Added support for vkGetPhysicalDeviceCalibrateableTimeDomainsKHR to include stage-local time domains.
* Updated handling of VK_TIME_DOMAIN_DEVICE_KHR to return timestamps in nanoseconds.
* Modified vkGetPastPresentationTimingEXT to allow retrieval of records without requiring presentIds.
* Improved vkQueuePresentKHR to terminate early when the present timing queue is full.
* Fixed VkPastPresentationTimingEXT::presentStageCount to correctly report the number of stages containing definitive results.

Signed-off-by: Ginu Jacob ginu.jacob@arm.com
2025-11-25 10:12:33 +00:00
Normunds Rieksts
2d4cbd5afa Decouple swapchain images and their memory from swapchain class
Decouples the swapchain images and their memory binder/allocator logic into separate classes. This allows us to reduce code duplication across different backends that use the same type of allocation logic and also allows us to make use of RAII to release the resources for swapchain images.

The swapchain_base and other swapchain classes have been refactored to handle the new swapchain images.

The patch makes the following adjustments:

* Introduces a new swapchain_image class that holds all swapchain image resources
* Introduces a swapchain image factory class that constructs swapchain images
* Introduces a Vulkan image handle class that is responsible for constructing VkImage handles
* Introduces a new interface that describes how swapchain backing memory is being allocated
* As part of this backing memory interface, introduces device and external (wsialloc) backing memory classes
* Introduces a new interface that holds swapchain image data like wl_buffers
* Refactors lots of swapchain image parts out of the base swapchain class and moves it into the respective backends to simplify the swapchain classes.
2025-11-20 13:55:45 +00:00
Lior Dekel
65078fb361 Adding debug interface
Added new debug file with function that exposes the
DRM modifier of a swapchain image buffer.
Building the layer with DEBUG=1 flag will result
building this file and tests can now get the modifier
value for assertions.

Signed-off-by: Lior Dekel <lior.dekel@arm.com>
Change-Id: I97a44dbda87b7cdb8984576aab613612f2f12a55
2025-11-04 12:20:24 +00:00
Normunds Rieksts
9d9172fcbb Add a workaround when wp_feedback events are not delivered
Adds a workaround for compositors that do not deliver
wp_presentation_feedback events when images are submitted to the
compositor in quick succession resulting in some of them being
discarded by handling it in buffer_release event instead.

Additionally fixes a double-free bug when presentation_feedback was
replaced using move semantics.

Change-Id: I97715ffbc45c3c869f84e57dca532d3a58ad3b67
Signed-off-by: Normunds Rieksts <normunds.rieksts@arm.com>
2025-10-31 10:35:08 +00:00
Nir Ekhauz
8c65fb2af7 Update the layer's readme and release notes with VK_KHR_present_wait2 support
1. Update the README file.
2. Remove the guards from the code.

Signed-off-by: Nir.Ekhauz <nir.ekhauz@arm.com>
Change-Id: Idf65baee25d09a3b4bc3b563455468bac4d5bddf
2025-09-18 10:20:43 +01:00
Nir Ekhauz
ee6d45430f Fix Wayland swapchain to support present_id2
Adding support for present_id2

Signed-off-by: Nir.Ekhauz <nir.ekhauz@arm.com>
Change-Id: Ie30caf423902fea9f2bc3341c3b61390b09c0f7c
2025-09-17 10:20:46 +01:00
Ginu Jacob
1346705513 Query pool reads for QUEUE_OPERATIONS_END_BIT_EXT skipped when not ready
In this change, the return status from query pool reads for
QUEUE_OPERATIONS_END_BIT_EXT are checked and skipped when not ready.
To cater for correctness of any later reads, the value returned is
cached and compared. Additionally, a fix is added to avoid data
corruption with presentation feedback object in present timing when
vector was used.

Signed-off-by: Ginu Jacob <ginu.jacob@arm.com>
Change-Id: I5f26b6a3c81eb73eff8a4073be7d7ffc81f9eef8
2025-09-11 15:47:13 +00:00
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
Iason Paraskevopoulos
b02e682d30 Update present timing types
Updates the present timing implementation and types to be aligned with
the latest commit.

Fixes an issue, where the queue used for the presentation feedback
events was destroyed before getting the last events.

Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
Change-Id: I1dba2fd0e4ad9ec8c02d71c58c93edceaa75d07e
2025-09-04 17:48:10 +01:00
Nir Ekhauz
5060dbbc3a Implement vkWaitForPresent2KHR
Add the entry point for VK_KHR_present_wait2.

Signed-off-by: Nir.Ekhauz <nir.ekhauz@arm.com>
Change-Id: I8b0ad681a6c02ea646d072e69b25113a8c8ad3ce
2025-08-28 15:46:50 +01:00
Nir Ekhauz
64c1c46609 Initial support for VK_KHR_present_wait2
Add support for present wait2 ext. for physical, surface and sc.

Signed-off-by: Nir.Ekhauz <nir.ekhauz@arm.com>
Change-Id: I0f7cdadb2d3ea0ecbc32b8b2efe9fc3bb4ba0369
2025-08-26 13:42:14 +01:00
Nir Ekhauz
7fac7b1339 Update the layer's readme and release notes with VK_KHR_present_id2 support
Removed experimental flags around this extension.

Signed-off-by: Nir.Ekhauz <nir.ekhauz@arm.com>
Change-Id: If314e8c05d0f0fd7405379fe1c714f0e56519b4b
2025-08-20 12:45:46 +01:00
Nir Ekhauz
472597ed42 Add initial support for VK_KHR_present_id2 in the layer
Add support for present id2 ext.

Signed-off-by: Nir.Ekhauz <nir.ekhauz@arm.com>
Change-Id: Ic4cf137158188e9b6db1fa999f2c61248456c139
2025-08-13 09:41:21 +01:00
Ginu Jacob
d807a089c3 Timestamp for VK_PRESENT_STAGE_IMAGE_FIRST_PIXEL_OUT_BIT_EXT in Wayland
In this change, support for the presentation stage
VK_PRESENT_STAGE_IMAGE_FIRST_PIXEL_OUT_BIT_EXT is added for the Wayland
backend.

Signed-off-by: Ginu Jacob <ginu.jacob@arm.com>
Change-Id: I866f8c55cfb6b69ba03761706d838ea17acf9651
2025-07-24 08:39:09 +00:00
Alex Bates
441d95f1bb Adds support for present timing on Wayland even if the compositor does not support wp_presentation. Previously, support for wp_presentation was assumed.
If the time domain used by the compositor matches one of the time domains supported by the ICD:

* Advertise `VK_PRESENT_STAGE_IMAGE_FIRST_PIXEL_VISIBLE_BIT_EXT` in `VkPresentTimingSurfaceCapabilitiesEXT`
* List `VK_PRESENT_STAGE_IMAGE_FIRST_PIXEL_VISIBLE_BIT_EXT` in `swapchain_time_domains`

Also handles the case where neither `VK_TIME_DOMAIN_CLOCK_MONOTONIC_KHR` or `VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_KHR` is supported for all backends.

Additionally fixes the issue where Wayland protocol was not dispatched correctly which resulted in Clock_ID event not being communicated back to the layer.

Signed-off-by: Alex Bates <alex.bates@arm.com>
Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
Signed-off-by: Normunds Rieksts <normunds.rieksts@arm.com>
2025-06-18 12:15:41 +00:00
Nir Ekhauz
0545f795de Document the VK_PRESENT_MODE_FIFO_LATEST_READY_EXT support for Headless and Wayland
1. Remove the guards.
2. Update the README.md file

Signed-off-by: Nir Ekhauz <nir.ekhauz@arm.com>
Change-Id: Iccf31b407c5cef4ebf2577f48cc378c6438ccf68
2025-06-08 15:32:22 +03:00
Normunds Rieksts
cedf53a2be Enables the present wait extension by default - experimental flag is no longer needed.
Fixes the following issues:

* For Wayland backend, populates the presentation feedback listener with all callbacks as it is considered a fault by the protocol to not implement those
* For Wayland backend presentation feedback listener, forwards the feedback_discarded event to present ID as there could be situations where previously submitted buffers are discarded, such as when swapchains are using the MAILBOX presentation mode.
* For all swapchains, communicate critical errors back to present wait extension as otherwise, all callers waiting that are waiting on present to be delivered in vkWaitForPresentKHR call will never exit.
* Expanded the implementation in vkWaitForPresentKHR to be able to return critical swapchain errors if they have occured during the wait time.
* Fix issues in present ID where infinite waits could result in the vkWaitForPresentKHR call returning immediately due to UINT64_MAX timeout resulting in overflowing the system clock used in std::condition_variable

Change-Id: I1e475c3073c05394db259657eae1da21764a5a5c
Signed-off-by: Normunds Rieksts <normunds.rieksts@arm.com>
Signed-off-by: Alex Bates <alex.bates@arm.com>
2025-06-06 16:41:12 +00:00
Rosen Zhelev
3aee47be65 Merge 'Support VK_PRESENT_MODE_FIFO_LATEST_READY_EXT for headless & wayland' into 'main'
See merge request mesa/vulkan-wsi-layer!160
2025-06-04 09:39:04 +01:00
Avi Shif
670f1e9476 Support VK_PRESENT_MODE_FIFO_LATEST_READY_EXT for headless & wayland
Enabling VK_PRESENT_MODE_FIFO_LATEST_READY_EXT for headless & wayland
This extension is handled the same as the MAILBOX ext.

Signed-off-by: Nir Ekhauz <nir.ekhauz@arm.com>
Change-Id: I010c3c9474a6d9c28964806ba5aa63549b622454
2025-06-04 09:39:03 +01:00
Ginu Jacob
5d4b84408a Acquiring timings for VK_PRESENT_STAGE_QUEUE_OPERATIONS_END_BIT_EXT 2025-05-28 15:59:16 +00:00
Rosen Zhelev
b2484fe518 Merge 'Introduce swapchain_image_creator' into 'main'
See merge request mesa/vulkan-wsi-layer!154
2025-05-16 16:22:43 +01:00
Normunds Rieksts
ab138f30ef Implement vkWaitForPresentKHR entrypoint 2025-05-09 16:04:39 +00: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
Iason Paraskevopoulos
b326e4b21f Add wsialloc wrapper class
Adds a class for owning and managing a wsialloc allocator, which removes
duplicated functionality from the wayland and display backends.

Change-Id: Ieb0c75481c2b1c0019e620a88fc0e153eba1e29a
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
2025-04-25 15:03:42 +01:00
Iason Paraskevopoulos
1e9cb8b1b3 Introduce swapchain_image_creator
Adds a new class named swapchain_image_creator, which will be
responsible for owning and extending image create info.

Change-Id: Icdda2304698e110d4c0d52caa6b7c1fe59c383a9
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
2025-04-25 15:03:42 +01:00
Fufu Fang
e765b38308 VK_EXT_present_timing updates for Wayland
This commit updates time domain used in the
VK_PRESENT_STAGE_IMAGE_FIRST_PIXEL_VISIBLE_BIT_EXT present stage
in the Wayland backend.

Change-Id: I0d158d0eea6608edd532fbebadb18713d5486d6b
Signed-off-by: Fufu Fang <fufu.fang@arm.com>
Signed-off-by: Alex Bates <alex.bates@arm.com>
2025-04-14 13:58:26 +00:00
Dennis Tsiang
2d1b682129 Use wp_presentation_feedback to update the presented ID value 2025-04-01 09:27:18 +00:00
Normunds Rieksts
a92fa2a8d9 Add support for querying swapchain timing properties
Adds initial support to the headless and Wayland backends to query
swapchain timing properties. This patch also moves all present timing
backend specific code into its own file and refactors the private_data
code that is specific to present timing entrypoints into a more common
format.

Change-Id: I377197a6e14b3cbd968e35735d43060d19dfe5bc
Signed-off-by: Normunds Rieksts <normunds.rieksts@arm.com>
2025-02-11 16:47:42 +00:00
Ginu Jacob
02ae04d08f Introduce an extensions abstraction in the layer
In this change, an abstraction layer is added to the swapchain
extensions. The extensions present_timing, present_id,
image_compression_control, frame_boundary, and swapchain_maintenance1
are moved to the new extensions abstraction framework.

Additionally, the compression control extension has been formalized in
the layer as it is part of Vulkan spec so compression control guards
have been removed.

Change-Id: Ib28739ca35dfbf5df987241a9010619279f3e1bb
Signed-off-by: Ginu Jacob <ginu.jacob@arm.com>
Signed-off-by: Normunds Rieksts <normunds.rieksts@arm.com>
2025-01-31 17:31:32 +00:00
Angeliki Agathi Tsintzira
5c3d3a9d7c Add -Wextra flag and fix warnings
With the addition of the -Wextra flag, additional compiler warnings
are enabled, which help identify potential issues in the code.
However, enabling -Wextra caused compilation failures due to the
-Werror flag, which treats warnings as errors. This commit enables
-Wextra and addresses all the warnings produced, ensuring the
code compiles successfully while maintaining higher code quality standards.

Change-Id: I0bbaead9b2b15530d2565a3dddf1ed676901269b
Signed-off-by: Angeliki Agathi Tsintzira <angelikiagathi.tsintzira@arm.com>
2025-01-20 10:19:25 +00:00
Angeliki Agathi Tsintzira
3051ca8b67 Add vkGetSwapchainTimeDomainPropertiesEXT support 2024-11-15 12:49:31 +00:00
Dennis Tsiang
dbf8ad01c0 Disable the FIFO present thread implementation on Wayland by default
The FIFO implementation in the Wayland backend that uses the
presentation thread is not technically Vulkan conformant. This commit
enables a true FIFO implementation that is conformant to the Vulkan
spec by blocking in the vkQueuePresent path. On Wayland this is
achieved by having the main thread wait for the frame_done event to be
sent by the compositor. This was already used in FIFO before but
previously it would be the presentation thread that would block.
This implementation is now used by default.

The downside of this approach is that it has a significant performance
impact due to blocking the main thread.

Users wishing to continue using the presentation thread
implementation to achieve better performance can still do so through
a new build option `ENABLE_WAYLAND_FIFO_PRESENTATION_THREAD`.

The README has also been updated to document the FIFO shortcomings.

Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
Change-Id: I8674f9ea330a45f97d32024f97057ffc25c76c7a
2024-10-21 12:24:40 +01:00
Normunds Rieksts
94dd9840c9 Implement support for marking frame boundaries 2024-10-01 15:18:22 +00:00
Normunds Rieksts
af44f50be3 Add support for VkPresentIdKHR structure
Adds support for handling the present IDs privided by the VkPresentIdKHR
structure that is exposed by the VK_KHR_present_id extension.

Change-Id: If2dfe2cf942f376729b5c0dec79bcfa0c0b49738
Signed-off-by: Normunds Rieksts <normunds.rieksts@arm.com>
2024-08-29 14:22:30 +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
Iason Paraskevopoulos
cbf6c9765c Separate image creation from create_and_bind_swapchain
Change-Id: Ifbc6a5fb57c962006550838667944b03654ce0e4
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
Signed-off-by: Fufu Fang <fufu.fang@arm.com>
2024-08-13 19:27:55 +01:00
Iason Paraskevopoulos
01b4e9aeff Add a function for empty queue submit operations
Adds a helper function in synchronization.hpp, which makes an empty
vkQueueSubmit in order to chain wait with signal semaphores and fences.
This function is used in submit_wait_request and
fence_sync::set_payload.

Introduces queue_submit_semaphores for grouping the signal and wait
semaphores.

Change-Id: I6107a29f3410fad8250f998b0e4c2052ed1923b8
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
Signed-off-by: Fufu Fang <fufu.fang@arm.com>
2024-08-13 19:27:55 +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
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
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
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