diff --git a/src/vulkan/runtime/vk_device.c b/src/vulkan/runtime/vk_device.c index 09b58939a22..3c0db44e24a 100644 --- a/src/vulkan/runtime/vk_device.c +++ b/src/vulkan/runtime/vk_device.c @@ -527,6 +527,27 @@ vk_common_DeviceWaitIdle(VkDevice _device) return VK_SUCCESS; } +#ifndef _WIN32 + +uint64_t +vk_clock_gettime(clockid_t clock_id) +{ + struct timespec current; + int ret; + + ret = clock_gettime(clock_id, ¤t); +#ifdef CLOCK_MONOTONIC_RAW + if (ret < 0 && clock_id == CLOCK_MONOTONIC_RAW) + ret = clock_gettime(CLOCK_MONOTONIC, ¤t); +#endif + if (ret < 0) + return 0; + + return (uint64_t)current.tv_sec * 1000000000ULL + current.tv_nsec; +} + +#endif //!_WIN32 + #define CORE_FEATURE(feature) features->feature = core->feature bool diff --git a/src/vulkan/runtime/vk_device.h b/src/vulkan/runtime/vk_device.h index a4083656b2d..b8fdc14abc6 100644 --- a/src/vulkan/runtime/vk_device.h +++ b/src/vulkan/runtime/vk_device.h @@ -350,6 +350,56 @@ vk_device_check_status(struct vk_device *device) return result; } +#ifndef _WIN32 + +uint64_t +vk_clock_gettime(clockid_t clock_id); + +static inline uint64_t +vk_time_max_deviation(uint64_t begin, uint64_t end, uint64_t max_clock_period) +{ + /* + * The maximum deviation is the sum of the interval over which we + * perform the sampling and the maximum period of any sampled + * clock. That's because the maximum skew between any two sampled + * clock edges is when the sampled clock with the largest period is + * sampled at the end of that period but right at the beginning of the + * sampling interval and some other clock is sampled right at the + * beginning of its sampling period and right at the end of the + * sampling interval. Let's assume the GPU has the longest clock + * period and that the application is sampling GPU and monotonic: + * + * s e + * w x y z 0 1 2 3 4 5 6 7 8 9 a b c d e f + * Raw -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_- + * + * g + * 0 1 2 3 + * GPU -----_____-----_____-----_____-----_____ + * + * m + * x y z 0 1 2 3 4 5 6 7 8 9 a b c + * Monotonic -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_- + * + * Interval <-----------------> + * Deviation <--------------------------> + * + * s = read(raw) 2 + * g = read(GPU) 1 + * m = read(monotonic) 2 + * e = read(raw) b + * + * We round the sample interval up by one tick to cover sampling error + * in the interval clock + */ + + uint64_t sample_interval = end - begin + 1; + + return sample_interval + max_clock_period; +} + +#endif //!_WIN32 + PFN_vkVoidFunction vk_device_get_proc_addr(const struct vk_device *device, const char *name);