From 8982056fa8d4c06fbe6658f2f9387d085bdbe01c Mon Sep 17 00:00:00 2001 From: anonymix007 <48598263+anonymix007@users.noreply.github.com> Date: Sun, 30 Nov 2025 18:11:03 +0300 Subject: [PATCH] vulkan/runtime: Implement VK_TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_KHR This change adds win32 VK_TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_KHR support to vk_device_get_timestamp. Meanwhile, vk_clock_gettime is left untouched preparing for deprecation (anv is the only user). The latter also only has the host clock part and doesn't handle error cases in a robust manner. v2 (zzyiwei): - vk_device_get_timestamp updates - use DETECT_OS_WINDOWS - add commit messages Reviewed-by: Yiwei Zhang Reviewed-by: Yonggang Luo Part-of: --- src/vulkan/runtime/vk_device.c | 14 ++++++++++++-- src/vulkan/runtime/vk_physical_device.c | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/vulkan/runtime/vk_device.c b/src/vulkan/runtime/vk_device.c index a2ffe734ff9..620d11eabf9 100644 --- a/src/vulkan/runtime/vk_device.c +++ b/src/vulkan/runtime/vk_device.c @@ -35,6 +35,7 @@ #include "vk_sync_timeline.h" #include "vk_util.h" #include "util/compiler.h" +#include "util/detect_os.h" #include "util/u_debug.h" #include "util/hash_table.h" #include "util/perf/cpu_trace.h" @@ -250,6 +251,7 @@ vk_device_init(struct vk_device *device, const VkTimeDomainKHR calibrate_domains[] = { VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_KHR, VK_TIME_DOMAIN_CLOCK_MONOTONIC_KHR, + VK_TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_KHR, }; for (uint32_t i = 0; i < ARRAY_SIZE(calibrate_domains); i++) { const VkTimeDomainKHR domain = calibrate_domains[i]; @@ -810,7 +812,15 @@ vk_device_get_timestamp(struct vk_device *device, VkTimeDomainKHR domain, } /* device is not used for host time domains */ -#ifndef _WIN32 +#if DETECT_OS_WINDOWS + if (domain == VK_TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_KHR) { + LARGE_INTEGER ts; + if (QueryPerformanceCounter(&ts)) { + *timestamp = ts.QuadPart; + return VK_SUCCESS; + } + } +#else /* !DETECT_OS_WINDOWS */ clockid_t clockid; struct timespec ts; @@ -840,7 +850,7 @@ vk_device_get_timestamp(struct vk_device *device, VkTimeDomainKHR domain, return VK_SUCCESS; fail: -#endif /* _WIN32 */ +#endif /* DETECT_OS_WINDOWS */ return VK_ERROR_FEATURE_NOT_PRESENT; } diff --git a/src/vulkan/runtime/vk_physical_device.c b/src/vulkan/runtime/vk_physical_device.c index ad11a03810a..83f358e112c 100644 --- a/src/vulkan/runtime/vk_physical_device.c +++ b/src/vulkan/runtime/vk_physical_device.c @@ -297,6 +297,7 @@ vk_common_GetPhysicalDeviceCalibrateableTimeDomainsKHR( const VkTimeDomainKHR host_time_domains[] = { VK_TIME_DOMAIN_CLOCK_MONOTONIC_KHR, VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_KHR, + VK_TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_KHR, }; for (uint32_t i = 0; i < ARRAY_SIZE(host_time_domains); i++) { const VkTimeDomainKHR domain = host_time_domains[i];