mirror of
https://gitlab.freedesktop.org/mesa/vulkan-wsi-layer.git
synced 2025-12-20 15:00:09 +01:00
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>
124 lines
4.7 KiB
C++
124 lines
4.7 KiB
C++
/*
|
|
* Copyright (c) 2025 Arm Limited.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to
|
|
* deal in the Software without restriction, including without limitation the
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*/
|
|
|
|
/**
|
|
* @file present_timing.cpp
|
|
*
|
|
* @brief Contains the functionality to implement features for present timing extension.
|
|
*/
|
|
#if VULKAN_WSI_LAYER_EXPERIMENTAL
|
|
#include <cstdint>
|
|
#include <array>
|
|
#include <algorithm>
|
|
#include "present_timing_handler.hpp"
|
|
#include "layer/private_data.hpp"
|
|
|
|
wsi_ext_present_timing_headless::wsi_ext_present_timing_headless(const util::allocator &allocator, VkDevice device,
|
|
uint32_t num_images)
|
|
: wsi::wsi_ext_present_timing(allocator, device, num_images)
|
|
{
|
|
}
|
|
|
|
util::unique_ptr<wsi_ext_present_timing_headless> wsi_ext_present_timing_headless::create(
|
|
const VkDevice &device, const util::allocator &allocator, uint32_t num_images)
|
|
{
|
|
|
|
auto &dev_data = layer::device_private_data::get(device);
|
|
|
|
/*
|
|
* Select the hardware raw monotonic clock domain (unaffected by NTP or adjtime adjustments)
|
|
* when the driver supports it; otherwise use the standard monotonic clock.
|
|
*/
|
|
std::array monotonic_domains = {
|
|
std::tuple{ VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT, false },
|
|
std::tuple{ VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT, false },
|
|
};
|
|
auto result =
|
|
wsi::check_time_domain_support(dev_data.physical_device, monotonic_domains.data(), monotonic_domains.size());
|
|
if (result != VK_SUCCESS)
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
VkTimeDomainEXT monotonic_domain_to_use = VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT;
|
|
bool monotonic_time_domain_supported = false;
|
|
for (auto [domain, supported] : monotonic_domains)
|
|
{
|
|
monotonic_domain_to_use = domain;
|
|
if (supported)
|
|
{
|
|
monotonic_time_domain_supported = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
util::vector<util::unique_ptr<wsi::vulkan_time_domain>> domains(allocator);
|
|
if (!domains.try_push_back(allocator.make_unique<wsi::vulkan_time_domain>(
|
|
VK_PRESENT_STAGE_QUEUE_OPERATIONS_END_BIT_EXT, VK_TIME_DOMAIN_DEVICE_KHR)))
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
if (monotonic_time_domain_supported)
|
|
{
|
|
if (!domains.try_push_back(allocator.make_unique<wsi::vulkan_time_domain>(VK_PRESENT_STAGE_IMAGE_LATCHED_BIT_EXT,
|
|
monotonic_domain_to_use)))
|
|
{
|
|
return nullptr;
|
|
}
|
|
if (!domains.try_push_back(allocator.make_unique<wsi::vulkan_time_domain>(
|
|
VK_PRESENT_STAGE_IMAGE_FIRST_PIXEL_OUT_BIT_EXT, monotonic_domain_to_use)))
|
|
{
|
|
return nullptr;
|
|
}
|
|
if (!domains.try_push_back(allocator.make_unique<wsi::vulkan_time_domain>(
|
|
VK_PRESENT_STAGE_IMAGE_FIRST_PIXEL_VISIBLE_BIT_EXT, monotonic_domain_to_use)))
|
|
{
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
return wsi_ext_present_timing::create<wsi_ext_present_timing_headless>(allocator, domains.data(), domains.size(),
|
|
device, num_images);
|
|
}
|
|
|
|
VkResult wsi_ext_present_timing_headless::get_swapchain_timing_properties(
|
|
uint64_t &timing_properties_counter, VkSwapchainTimingPropertiesEXT &timing_properties)
|
|
{
|
|
/*
|
|
* The headless backend does not have a limit on how fast the swapchain can be presented.
|
|
* We set the refresh duration to 1, because on some platforms, 0 is returned until after
|
|
* at least one image had been presented. On these platforms, 0 is used to indicate timing
|
|
* properties are currently unavailable.
|
|
*/
|
|
const uint64_t fixed_refresh_duration_ns = 1;
|
|
|
|
timing_properties_counter = 1;
|
|
timing_properties.refreshDuration = fixed_refresh_duration_ns;
|
|
timing_properties.variableRefreshDelay = UINT64_MAX;
|
|
|
|
return VK_SUCCESS;
|
|
}
|
|
|
|
#endif
|