vulkan: Add vk_clock_gettime and vk_time_max_deviation
These two new function are based on {anv,radv}_clock_gettime and some other common code between radv and anv. These new functions allow these drivers to share code and more drivers can use it in the future. v2: Drop the anv/radv changes in this commit (Yiwei Zhang) v3: Add #ifndef _WIN32 Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org> Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> (v1) Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> (v1) Signed-off-by: Igor Torrente <igor.torrente@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18281>
This commit is contained in:
@@ -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
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user