2019-05-24 15:57:50 +01:00
|
|
|
/*
|
2024-11-28 06:36:17 +00:00
|
|
|
* Copyright (c) 2017-2019, 2021-2025 Arm Limited.
|
2019-05-24 15:57:50 +01:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <array>
|
|
|
|
|
#include <cassert>
|
|
|
|
|
#include <cstdlib>
|
2021-07-21 20:19:52 +01:00
|
|
|
#include <cstring>
|
2019-05-24 15:57:50 +01:00
|
|
|
#include <map>
|
2025-09-05 15:06:38 +00:00
|
|
|
#include <util/custom_mutex.hpp>
|
2019-05-24 15:57:50 +01:00
|
|
|
|
|
|
|
|
#include <vulkan/vk_icd.h>
|
|
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
|
|
|
|
|
|
#include <layer/private_data.hpp>
|
|
|
|
|
|
|
|
|
|
#include "surface_properties.hpp"
|
2021-07-21 20:19:52 +01:00
|
|
|
#include "surface.hpp"
|
2021-11-03 11:25:48 +00:00
|
|
|
#include "util/macros.hpp"
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2025-06-18 12:15:41 +00:00
|
|
|
#if VULKAN_WSI_LAYER_EXPERIMENTAL
|
|
|
|
|
#include "present_timing_handler.hpp"
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-05-24 15:57:50 +01:00
|
|
|
namespace wsi
|
|
|
|
|
{
|
|
|
|
|
namespace headless
|
|
|
|
|
{
|
|
|
|
|
|
2022-02-28 16:21:06 +00:00
|
|
|
constexpr int max_core_1_0_formats = VK_FORMAT_ASTC_12x12_SRGB_BLOCK + 1;
|
|
|
|
|
|
2024-04-09 13:53:58 +01:00
|
|
|
void surface_properties::populate_present_mode_compatibilities()
|
|
|
|
|
{
|
2024-05-13 12:20:49 +01:00
|
|
|
std::array compatible_present_modes_list = {
|
2024-04-09 13:53:58 +01:00
|
|
|
present_mode_compatibility{
|
2024-05-13 12:20:49 +01:00
|
|
|
VK_PRESENT_MODE_FIFO_KHR, 2, { VK_PRESENT_MODE_FIFO_KHR, VK_PRESENT_MODE_FIFO_RELAXED_KHR } },
|
2024-04-09 13:53:58 +01:00
|
|
|
present_mode_compatibility{
|
2024-05-13 12:20:49 +01:00
|
|
|
VK_PRESENT_MODE_FIFO_RELAXED_KHR, 2, { VK_PRESENT_MODE_FIFO_RELAXED_KHR, VK_PRESENT_MODE_FIFO_KHR } },
|
2024-04-09 13:53:58 +01:00
|
|
|
present_mode_compatibility{
|
|
|
|
|
VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR, 1, { VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR } },
|
|
|
|
|
present_mode_compatibility{
|
2025-06-08 15:32:22 +03:00
|
|
|
VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR, 1, { VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR } },
|
2025-06-04 08:39:03 +00:00
|
|
|
present_mode_compatibility{ VK_PRESENT_MODE_FIFO_LATEST_READY_EXT, 1, { VK_PRESENT_MODE_FIFO_LATEST_READY_EXT } }
|
2024-04-09 13:53:58 +01:00
|
|
|
};
|
2024-05-13 12:20:49 +01:00
|
|
|
m_compatible_present_modes =
|
|
|
|
|
compatible_present_modes<compatible_present_modes_list.size()>(compatible_present_modes_list);
|
2024-04-09 13:53:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
surface_properties::surface_properties()
|
2025-06-08 15:32:22 +03:00
|
|
|
: m_supported_modes({ VK_PRESENT_MODE_FIFO_KHR, VK_PRESENT_MODE_FIFO_RELAXED_KHR,
|
|
|
|
|
VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR, VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR,
|
|
|
|
|
VK_PRESENT_MODE_FIFO_LATEST_READY_EXT })
|
2024-04-09 13:53:58 +01:00
|
|
|
{
|
2025-09-10 13:31:35 +00:00
|
|
|
this->surface_properties::populate_present_mode_compatibilities();
|
2024-04-09 13:53:58 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-19 10:19:39 +01:00
|
|
|
surface_properties &surface_properties::get_instance()
|
2019-11-21 15:23:59 +00:00
|
|
|
{
|
|
|
|
|
static surface_properties instance;
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 16:21:06 +00:00
|
|
|
VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_device,
|
2019-05-24 15:57:50 +01:00
|
|
|
VkSurfaceCapabilitiesKHR *surface_capabilities)
|
|
|
|
|
{
|
2022-07-05 18:08:35 +03:00
|
|
|
get_surface_capabilities_common(physical_device, surface_capabilities);
|
2024-04-09 13:53:58 +01:00
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2024-04-09 13:53:58 +01:00
|
|
|
VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_device,
|
|
|
|
|
const VkPhysicalDeviceSurfaceInfo2KHR *surface_info,
|
|
|
|
|
VkSurfaceCapabilities2KHR *surface_capabilities)
|
|
|
|
|
{
|
2024-05-13 12:20:49 +01:00
|
|
|
TRY(check_surface_present_mode_query_is_supported(surface_info, m_supported_modes));
|
2024-04-09 13:53:58 +01:00
|
|
|
get_surface_capabilities_common(physical_device, &surface_capabilities->surfaceCapabilities);
|
2024-05-13 12:20:49 +01:00
|
|
|
m_compatible_present_modes.get_surface_present_mode_compatibility_common(surface_info, surface_capabilities);
|
2024-04-22 14:52:05 +01:00
|
|
|
|
|
|
|
|
auto surface_scaling_capabilities = util::find_extension<VkSurfacePresentScalingCapabilitiesEXT>(
|
|
|
|
|
VK_STRUCTURE_TYPE_SURFACE_PRESENT_SCALING_CAPABILITIES_EXT, surface_capabilities);
|
|
|
|
|
if (surface_scaling_capabilities != nullptr)
|
|
|
|
|
{
|
|
|
|
|
get_surface_present_scaling_and_gravity(surface_scaling_capabilities);
|
|
|
|
|
surface_scaling_capabilities->minScaledImageExtent = surface_capabilities->surfaceCapabilities.minImageExtent;
|
|
|
|
|
surface_scaling_capabilities->maxScaledImageExtent = surface_capabilities->surfaceCapabilities.maxImageExtent;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-13 08:41:21 +00:00
|
|
|
auto present_id2_surface_cap = util::find_extension<VkSurfaceCapabilitiesPresentId2KHR>(
|
|
|
|
|
VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_PRESENT_ID_2_KHR, surface_capabilities->pNext);
|
|
|
|
|
if (present_id2_surface_cap != nullptr)
|
|
|
|
|
{
|
|
|
|
|
present_id2_surface_cap->presentId2Supported = VK_TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-26 12:42:14 +00:00
|
|
|
auto present_wait2_surface_cap = util::find_extension<VkSurfaceCapabilitiesPresentWait2KHR>(
|
|
|
|
|
VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_PRESENT_WAIT_2_KHR, surface_capabilities->pNext);
|
|
|
|
|
if (present_wait2_surface_cap != nullptr)
|
|
|
|
|
{
|
|
|
|
|
present_wait2_surface_cap->presentWait2Supported = VK_TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-24 15:57:50 +01:00
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 16:21:06 +00:00
|
|
|
static uint32_t fill_supported_formats(VkPhysicalDevice physical_device,
|
2022-03-18 12:05:46 +00:00
|
|
|
std::array<surface_format_properties, max_core_1_0_formats> &formats)
|
2019-05-24 15:57:50 +01:00
|
|
|
{
|
|
|
|
|
uint32_t format_count = 0;
|
2020-06-28 21:41:21 +01:00
|
|
|
for (int id = 0; id < max_core_1_0_formats; id++)
|
2019-05-24 15:57:50 +01:00
|
|
|
{
|
2022-03-18 12:05:46 +00:00
|
|
|
formats[format_count] = surface_format_properties{ static_cast<VkFormat>(id) };
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2022-03-18 12:05:46 +00:00
|
|
|
VkPhysicalDeviceImageFormatInfo2KHR format_info = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2_KHR,
|
|
|
|
|
nullptr,
|
|
|
|
|
static_cast<VkFormat>(id),
|
|
|
|
|
VK_IMAGE_TYPE_2D,
|
|
|
|
|
VK_IMAGE_TILING_OPTIMAL,
|
|
|
|
|
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
|
|
|
|
|
0 };
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2022-03-18 12:05:46 +00:00
|
|
|
VkResult res = formats[format_count].check_device_support(physical_device, format_info);
|
|
|
|
|
|
|
|
|
|
if (res == VK_SUCCESS)
|
2019-05-24 15:57:50 +01:00
|
|
|
{
|
2022-03-18 12:05:46 +00:00
|
|
|
if (layer::instance_private_data::get(physical_device).has_image_compression_support(physical_device))
|
|
|
|
|
{
|
|
|
|
|
formats[format_count].add_device_compression_support(physical_device, format_info);
|
|
|
|
|
}
|
2019-05-24 15:57:50 +01:00
|
|
|
format_count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 16:21:06 +00:00
|
|
|
return format_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult surface_properties::get_surface_formats(VkPhysicalDevice physical_device, uint32_t *surface_format_count,
|
2022-03-03 11:21:07 +00:00
|
|
|
VkSurfaceFormatKHR *surface_formats,
|
|
|
|
|
VkSurfaceFormat2KHR *extended_surface_formats)
|
2022-02-28 16:21:06 +00:00
|
|
|
{
|
|
|
|
|
/* Construct a list of all formats supported by the driver - for color attachment */
|
2022-03-18 12:05:46 +00:00
|
|
|
std::array<surface_format_properties, max_core_1_0_formats> formats{};
|
2022-02-28 16:21:06 +00:00
|
|
|
auto format_count = fill_supported_formats(physical_device, formats);
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2022-03-18 12:05:46 +00:00
|
|
|
return surface_properties_formats_helper(formats.begin(), formats.begin() + format_count, surface_format_count,
|
|
|
|
|
surface_formats, extended_surface_formats);
|
2019-05-24 15:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult surface_properties::get_surface_present_modes(VkPhysicalDevice physical_device, VkSurfaceKHR surface,
|
|
|
|
|
uint32_t *present_mode_count, VkPresentModeKHR *present_modes)
|
|
|
|
|
{
|
|
|
|
|
UNUSED(physical_device);
|
|
|
|
|
UNUSED(surface);
|
2024-05-13 12:20:49 +01:00
|
|
|
return get_surface_present_modes_common(present_mode_count, present_modes, m_supported_modes);
|
2019-05-24 15:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(VkResult)
|
|
|
|
|
CreateHeadlessSurfaceEXT(VkInstance instance, const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
|
|
|
|
|
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) VWL_API_POST
|
2021-07-21 20:19:52 +01:00
|
|
|
{
|
|
|
|
|
auto &instance_data = layer::instance_private_data::get(instance);
|
|
|
|
|
util::allocator allocator{ instance_data.get_allocator(), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT, pAllocator };
|
|
|
|
|
auto wsi_surface = util::unique_ptr<wsi::surface>(allocator.make_unique<surface>());
|
|
|
|
|
if (wsi_surface == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
|
}
|
|
|
|
|
VkResult res = instance_data.disp.CreateHeadlessSurfaceEXT(instance, pCreateInfo, pAllocator, pSurface);
|
|
|
|
|
if (res == VK_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
res = instance_data.add_surface(*pSurface, wsi_surface);
|
|
|
|
|
if (res != VK_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
instance_data.disp.DestroySurfaceKHR(instance, *pSurface, pAllocator);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PFN_vkVoidFunction surface_properties::get_proc_addr(const char *name)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp(name, "vkCreateHeadlessSurfaceEXT") == 0)
|
|
|
|
|
{
|
|
|
|
|
return reinterpret_cast<PFN_vkVoidFunction>(CreateHeadlessSurfaceEXT);
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-27 15:21:58 +00:00
|
|
|
VkResult surface_properties::get_required_instance_extensions(util::extension_list &extension_list,
|
|
|
|
|
const uint32_t api_version)
|
2023-09-19 10:19:39 +01:00
|
|
|
{
|
2025-06-27 15:21:58 +00:00
|
|
|
VkResult result = VK_SUCCESS;
|
|
|
|
|
/* Enable extensions that were promoted to core in Vulkan 1.1 when using API versions < 1.1 */
|
|
|
|
|
if (api_version < VK_API_VERSION_1_1)
|
|
|
|
|
{
|
|
|
|
|
const std::array required_extensions_pre_vulkan_1_1{
|
|
|
|
|
VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
|
|
|
|
|
VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME,
|
|
|
|
|
VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME,
|
|
|
|
|
};
|
|
|
|
|
result = extension_list.add(required_extensions_pre_vulkan_1_1.data(), required_extensions_pre_vulkan_1_1.size());
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2023-09-19 10:19:39 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-08 13:32:12 +00:00
|
|
|
bool surface_properties::is_surface_extension_enabled(const layer::instance_private_data &instance_data)
|
|
|
|
|
{
|
|
|
|
|
return instance_data.is_instance_extension_enabled(VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-22 14:52:05 +01:00
|
|
|
void surface_properties::get_surface_present_scaling_and_gravity(
|
|
|
|
|
VkSurfacePresentScalingCapabilitiesEXT *scaling_capabilities)
|
|
|
|
|
{
|
|
|
|
|
scaling_capabilities->supportedPresentScaling = 0;
|
|
|
|
|
scaling_capabilities->supportedPresentGravityX = 0;
|
|
|
|
|
scaling_capabilities->supportedPresentGravityY = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-09 09:32:42 +01:00
|
|
|
bool surface_properties::is_compatible_present_modes(VkPresentModeKHR present_mode_a, VkPresentModeKHR present_mode_b)
|
|
|
|
|
{
|
2024-05-13 12:20:49 +01:00
|
|
|
return m_compatible_present_modes.is_compatible_present_modes(present_mode_a, present_mode_b);
|
2024-05-09 09:32:42 +01:00
|
|
|
}
|
|
|
|
|
|
2024-08-21 12:59:49 +01:00
|
|
|
#if VULKAN_WSI_LAYER_EXPERIMENTAL
|
2025-06-18 12:15:41 +00:00
|
|
|
VkResult surface_properties::get_present_timing_surface_caps(
|
|
|
|
|
VkPhysicalDevice physical_device, VkPresentTimingSurfaceCapabilitiesEXT *present_timing_surface_caps)
|
2024-08-21 12:59:49 +01:00
|
|
|
{
|
|
|
|
|
present_timing_surface_caps->presentTimingSupported = VK_TRUE;
|
2025-09-15 11:40:06 +00:00
|
|
|
present_timing_surface_caps->presentAtAbsoluteTimeSupported = VK_FALSE;
|
2025-07-30 12:27:09 +00:00
|
|
|
present_timing_surface_caps->presentAtRelativeTimeSupported = VK_FALSE;
|
2025-06-18 12:15:41 +00:00
|
|
|
|
|
|
|
|
VkPresentStageFlagsEXT monotonic_present_stages_supported = 0;
|
|
|
|
|
std::array monotonic_domains = {
|
|
|
|
|
std::tuple{ VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT, false },
|
|
|
|
|
std::tuple{ VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT, false },
|
|
|
|
|
};
|
|
|
|
|
TRY(wsi::check_time_domain_support(physical_device, monotonic_domains.data(), monotonic_domains.size()));
|
|
|
|
|
|
|
|
|
|
auto it_monotonic_supported = std::find_if(monotonic_domains.begin(), monotonic_domains.end(),
|
|
|
|
|
[](auto &domain) { return std::get<1>(domain); });
|
|
|
|
|
if (it_monotonic_supported != monotonic_domains.end())
|
|
|
|
|
{
|
2025-09-04 16:48:10 +00:00
|
|
|
monotonic_present_stages_supported |= VK_PRESENT_STAGE_REQUEST_DEQUEUED_BIT_EXT |
|
2025-06-18 12:15:41 +00:00
|
|
|
VK_PRESENT_STAGE_IMAGE_FIRST_PIXEL_OUT_BIT_EXT |
|
|
|
|
|
VK_PRESENT_STAGE_IMAGE_FIRST_PIXEL_VISIBLE_BIT_EXT;
|
2025-09-15 11:40:06 +00:00
|
|
|
present_timing_surface_caps->presentAtAbsoluteTimeSupported = VK_TRUE;
|
|
|
|
|
present_timing_surface_caps->presentAtRelativeTimeSupported = VK_TRUE;
|
2025-06-18 12:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
2024-08-21 12:59:49 +01:00
|
|
|
present_timing_surface_caps->presentStageQueries =
|
2025-06-18 12:15:41 +00:00
|
|
|
VK_PRESENT_STAGE_QUEUE_OPERATIONS_END_BIT_EXT | monotonic_present_stages_supported;
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
2024-08-21 12:59:49 +01:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-05-24 15:57:50 +01:00
|
|
|
} /* namespace headless */
|
|
|
|
|
} /* namespace wsi */
|