From 0ef469f3b57346ac6a41459aac3c7f19dd96f00c Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Sun, 18 Sep 2022 16:03:19 -0500 Subject: [PATCH] Common:Vk: Load VK_EXT_calibrated_timestamps --- common/Vulkan/Context.cpp | 42 +++++++++++++++++++++++++++++++++-- common/Vulkan/Context.h | 2 ++ common/Vulkan/EntryPoints.h | 4 ++++ common/Vulkan/EntryPoints.inl | 6 +++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/common/Vulkan/Context.cpp b/common/Vulkan/Context.cpp index db275d09ba..ee25737d54 100644 --- a/common/Vulkan/Context.cpp +++ b/common/Vulkan/Context.cpp @@ -446,6 +446,8 @@ namespace Vulkan SupportsExtension(VK_EXT_PROVOKING_VERTEX_EXTENSION_NAME, false); m_optional_extensions.vk_ext_memory_budget = SupportsExtension(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME, false); + m_optional_extensions.vk_ext_calibrated_timestamps = + SupportsExtension(VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME, false); m_optional_extensions.vk_khr_driver_properties = SupportsExtension(VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME, false); m_optional_extensions.vk_arm_rasterization_order_attachment_access = @@ -637,8 +639,8 @@ namespace Vulkan } m_gpu_timing_supported = (m_device_properties.limits.timestampComputeAndGraphics != 0 && - queue_family_properties[m_graphics_queue_family_index].timestampValidBits > 0 && - m_device_properties.limits.timestampPeriod > 0); + queue_family_properties[m_graphics_queue_family_index].timestampValidBits > 0 && + m_device_properties.limits.timestampPeriod > 0); DevCon.WriteLn("GPU timing is %s (TS=%u TS valid bits=%u, TS period=%f)", m_gpu_timing_supported ? "supported" : "not supported", static_cast(m_device_properties.limits.timestampComputeAndGraphics), @@ -684,8 +686,44 @@ namespace Vulkan // query vkGetPhysicalDeviceProperties2(m_physical_device, &properties2); + // VK_EXT_calibrated_timestamps checking + if (m_optional_extensions.vk_ext_calibrated_timestamps) + { + u32 count = 0; + vkGetPhysicalDeviceCalibrateableTimeDomainsEXT(m_physical_device, &count, nullptr); + std::unique_ptr time_domains = std::make_unique(count); + vkGetPhysicalDeviceCalibrateableTimeDomainsEXT(m_physical_device, &count, time_domains.get()); + const VkTimeDomainEXT* begin = &time_domains[0]; + const VkTimeDomainEXT* end = &time_domains[count]; + if (std::find(begin, end, VK_TIME_DOMAIN_DEVICE_EXT) == end) + m_optional_extensions.vk_ext_calibrated_timestamps = false; + VkTimeDomainEXT preferred_types[] = { +#ifdef _WIN32 + VK_TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_EXT, +#else +#ifdef CLOCK_MONOTONIC_RAW + VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT, +#endif + VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT, +#endif + }; + m_calibrated_timestamp_type = VK_TIME_DOMAIN_DEVICE_EXT; + for (VkTimeDomainEXT type : preferred_types) + { + if (std::find(begin, end, type) != end) + { + m_calibrated_timestamp_type = type; + break; + } + } + if (m_calibrated_timestamp_type == VK_TIME_DOMAIN_DEVICE_EXT) + m_optional_extensions.vk_ext_calibrated_timestamps = false; + } + Console.WriteLn("VK_EXT_provoking_vertex is %s", m_optional_extensions.vk_ext_provoking_vertex ? "supported" : "NOT supported"); + Console.WriteLn("VK_EXT_calibrated_timestamps is %s", + m_optional_extensions.vk_ext_calibrated_timestamps ? "supported" : "NOT supported"); Console.WriteLn("VK_ARM_rasterization_order_attachment_access is %s", m_optional_extensions.vk_arm_rasterization_order_attachment_access ? "supported" : "NOT supported"); } diff --git a/common/Vulkan/Context.h b/common/Vulkan/Context.h index 74488197c3..bdab29e221 100644 --- a/common/Vulkan/Context.h +++ b/common/Vulkan/Context.h @@ -50,6 +50,7 @@ namespace Vulkan { bool vk_ext_provoking_vertex : 1; bool vk_ext_memory_budget : 1; + bool vk_ext_calibrated_timestamps : 1; bool vk_khr_driver_properties : 1; bool vk_arm_rasterization_order_attachment_access : 1; bool vk_khr_fragment_shader_barycentric : 1; @@ -309,6 +310,7 @@ namespace Vulkan float m_accumulated_gpu_time = 0.0f; bool m_gpu_timing_enabled = false; bool m_gpu_timing_supported = false; + VkTimeDomainEXT m_calibrated_timestamp_type = VK_TIME_DOMAIN_DEVICE_EXT; std::array m_frame_resources; u64 m_next_fence_counter = 1; diff --git a/common/Vulkan/EntryPoints.h b/common/Vulkan/EntryPoints.h index 5bdc665068..0d78f9538d 100644 --- a/common/Vulkan/EntryPoints.h +++ b/common/Vulkan/EntryPoints.h @@ -231,3 +231,7 @@ extern "C" { #define vkAcquireFullScreenExclusiveModeEXT pcsx2_vkAcquireFullScreenExclusiveModeEXT #define vkReleaseFullScreenExclusiveModeEXT pcsx2_vkReleaseFullScreenExclusiveModeEXT #endif + +// VK_EXT_calibrated_timestamps +#define vkGetCalibratedTimestampsEXT pcsx2_vkGetCalibratedTimestampsEXT +#define vkGetPhysicalDeviceCalibrateableTimeDomainsEXT pcsx2_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT diff --git a/common/Vulkan/EntryPoints.inl b/common/Vulkan/EntryPoints.inl index 4e659ae7e9..346316b19a 100644 --- a/common/Vulkan/EntryPoints.inl +++ b/common/Vulkan/EntryPoints.inl @@ -104,6 +104,9 @@ VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceFeatures2, true) VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceProperties2, true) VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceMemoryProperties2, true) +// VK_EXT_calibrated_timestamps +VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceCalibrateableTimeDomainsEXT, false) + #endif // VULKAN_INSTANCE_ENTRY_POINT #ifdef VULKAN_DEVICE_ENTRY_POINT @@ -245,4 +248,7 @@ VULKAN_DEVICE_ENTRY_POINT(vkAcquireFullScreenExclusiveModeEXT, false) VULKAN_DEVICE_ENTRY_POINT(vkReleaseFullScreenExclusiveModeEXT, false) #endif +// VK_EXT_calibrated_timestamps +VULKAN_DEVICE_ENTRY_POINT(vkGetCalibratedTimestampsEXT, false) + #endif // VULKAN_DEVICE_ENTRY_POINT