diff --git a/layer/calibrated_timestamps_api.cpp b/layer/calibrated_timestamps_api.cpp index 553dedd..9573218 100644 --- a/layer/calibrated_timestamps_api.cpp +++ b/layer/calibrated_timestamps_api.cpp @@ -31,18 +31,13 @@ #include #include +#if VULKAN_WSI_LAYER_EXPERIMENTAL VWL_VKAPI_CALL(VkResult) -wsi_layer_vkGetCalibratedTimestampsEXT(VkDevice device, uint32_t timestampCount, +wsi_layer_vkGetCalibratedTimestampsKHR(VkDevice device, uint32_t timestampCount, const VkCalibratedTimestampInfoKHR *pTimestampInfos, uint64_t *pTimestamps, uint64_t *pMaxDeviation) VWL_API_POST { auto &device_data = layer::device_private_data::get(device); - auto get_calibrated_timestamps = - device_data.disp.get_fn("PFN_vkGetCalibratedTimestampsEXT").has_value() ? - device_data.disp.get_fn("vkGetCalibratedTimestampsEXT") : - device_data.disp.get_fn("vkGetCalibratedTimestampsKHR"); - assert(get_calibrated_timestamps.has_value()); -#if VULKAN_WSI_LAYER_EXPERIMENTAL struct stage_local_index_and_offset { uint32_t index; @@ -90,7 +85,8 @@ wsi_layer_vkGetCalibratedTimestampsEXT(VkDevice device, uint32_t timestampCount, time_stamp_info[i].timeDomain = calibrated_time.time_domain; } } - TRY_LOG_CALL((*get_calibrated_timestamps)(device, timestampCount, &time_stamp_info[0], pTimestamps, pMaxDeviation)); + TRY_LOG_CALL(device_data.disp.GetCalibratedTimestampsKHR(device, timestampCount, &time_stamp_info[0], pTimestamps, + pMaxDeviation)); /* Loop through the calibration_index_and_offset vector and update the timestamps that are stage local with its respective offset. */ @@ -99,14 +95,13 @@ wsi_layer_vkGetCalibratedTimestampsEXT(VkDevice device, uint32_t timestampCount, pTimestamps[iter.index] += iter.calibration_offset; } return VK_SUCCESS; -#endif /* VULKAN_WSI_LAYER_EXPERIMENTAL */ - return (*get_calibrated_timestamps)(device, timestampCount, pTimestampInfos, pTimestamps, pMaxDeviation); } VWL_VKAPI_CALL(VkResult) -wsi_layer_vkGetCalibratedTimestampsKHR(VkDevice device, uint32_t timestampCount, +wsi_layer_vkGetCalibratedTimestampsEXT(VkDevice device, uint32_t timestampCount, const VkCalibratedTimestampInfoKHR *pTimestampInfos, uint64_t *pTimestamps, uint64_t *pMaxDeviation) VWL_API_POST { - return wsi_layer_vkGetCalibratedTimestampsEXT(device, timestampCount, pTimestampInfos, pTimestamps, pMaxDeviation); -} \ No newline at end of file + return wsi_layer_vkGetCalibratedTimestampsKHR(device, timestampCount, pTimestampInfos, pTimestamps, pMaxDeviation); +} +#endif /* VULKAN_WSI_LAYER_EXPERIMENTAL */ diff --git a/layer/calibrated_timestamps_api.hpp b/layer/calibrated_timestamps_api.hpp index 4179f0f..f31080e 100644 --- a/layer/calibrated_timestamps_api.hpp +++ b/layer/calibrated_timestamps_api.hpp @@ -32,6 +32,7 @@ #pragma once #include "util/macros.hpp" +#if VULKAN_WSI_LAYER_EXPERIMENTAL VWL_VKAPI_CALL(VkResult) wsi_layer_vkGetCalibratedTimestampsEXT(VkDevice device, uint32_t timestampCount, const VkCalibratedTimestampInfoKHR *pTimestampInfos, uint64_t *pTimestamps, @@ -40,4 +41,5 @@ wsi_layer_vkGetCalibratedTimestampsEXT(VkDevice device, uint32_t timestampCount, VWL_VKAPI_CALL(VkResult) wsi_layer_vkGetCalibratedTimestampsKHR(VkDevice device, uint32_t timestampCount, const VkCalibratedTimestampInfoKHR *pTimestampInfos, uint64_t *pTimestamps, - uint64_t *pMaxDeviation) VWL_API_POST; \ No newline at end of file + uint64_t *pMaxDeviation) VWL_API_POST; +#endif diff --git a/layer/layer.cpp b/layer/layer.cpp index b8f5d56..a5f138a 100644 --- a/layer/layer.cpp +++ b/layer/layer.cpp @@ -562,6 +562,12 @@ wsi_layer_vkGetDeviceProcAddr(VkDevice device, const char *funcName) VWL_API_POS GET_PROC_ADDR(vkGetSwapchainTimingPropertiesEXT); GET_PROC_ADDR(vkGetSwapchainTimeDomainPropertiesEXT); GET_PROC_ADDR(vkGetPastPresentationTimingEXT); + GET_PROC_ADDR(vkGetCalibratedTimestampsKHR); + if (layer::device_private_data::get(device).is_device_extension_enabled( + VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME)) + { + GET_PROC_ADDR(vkGetCalibratedTimestampsEXT); + } } #endif GET_PROC_ADDR(vkDestroyDevice); @@ -582,14 +588,6 @@ wsi_layer_vkGetDeviceProcAddr(VkDevice device, const char *funcName) VWL_API_POS { GET_PROC_ADDR(vkReleaseSwapchainImagesEXT); } - if (layer::device_private_data::get(device).is_device_extension_enabled(VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME)) - { - GET_PROC_ADDR(vkGetCalibratedTimestampsEXT); - } - if (layer::device_private_data::get(device).is_device_extension_enabled(VK_KHR_CALIBRATED_TIMESTAMPS_EXTENSION_NAME)) - { - GET_PROC_ADDR(vkGetCalibratedTimestampsKHR); - } #if VULKAN_WSI_LAYER_EXPERIMENTAL if (layer::device_private_data::get(device).is_device_extension_enabled(VK_KHR_PRESENT_WAIT_EXTENSION_NAME)) { diff --git a/layer/private_data.hpp b/layer/private_data.hpp index 309da46..d64ed13 100644 --- a/layer/private_data.hpp +++ b/layer/private_data.hpp @@ -436,7 +436,9 @@ private: false, GetImageSparseMemoryRequirements2KHR) \ /* VK_EXT_swapchain_maintenance1 */ \ EP(ReleaseSwapchainImagesEXT, VK_EXT_SWAPCHAIN_MAINTENANCE_1_EXTENSION_NAME, VK_API_VERSION_1_1, false, ) \ + /* VK_EXT_calibrated_timestamps */ \ EP(GetCalibratedTimestampsEXT, VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME, API_VERSION_MAX, false, ) \ + /* VK_KHR_calibrated_timestamps */ \ EP(GetCalibratedTimestampsKHR, VK_KHR_CALIBRATED_TIMESTAMPS_EXTENSION_NAME, API_VERSION_MAX, false, ) \ /* Custom entrypoints */ \ DEVICE_ENTRYPOINTS_LIST_EXPANSION(EP) diff --git a/wsi/extensions/present_timing.hpp b/wsi/extensions/present_timing.hpp index a80e3ce..b7b89c0 100644 --- a/wsi/extensions/present_timing.hpp +++ b/wsi/extensions/present_timing.hpp @@ -90,8 +90,8 @@ struct swapchain_calibrated_time class swapchain_time_domain { public: - swapchain_time_domain(VkPresentStageFlagsEXT presentStages) - : m_present_stages(presentStages) + swapchain_time_domain(VkPresentStageFlagsEXT present_stage) + : m_present_stage(present_stage) { } @@ -101,18 +101,18 @@ public: VkPresentStageFlagsEXT get_present_stages() { - return m_present_stages; + return m_present_stage; } private: - VkPresentStageFlagsEXT m_present_stages; + VkPresentStageFlagsEXT m_present_stage; }; class vulkan_time_domain : public swapchain_time_domain { public: - vulkan_time_domain(VkPresentStageFlagsEXT presentStages, VkTimeDomainKHR time_domain) - : swapchain_time_domain(presentStages) + vulkan_time_domain(VkPresentStageFlagsEXT present_stage, VkTimeDomainKHR time_domain) + : swapchain_time_domain(present_stage) , m_time_domain(time_domain) { } @@ -148,7 +148,14 @@ public: */ bool add_time_domain(util::unique_ptr time_domain); - VkResult calibrate(VkPresentStageFlagBitsEXT presentStages, swapchain_calibrated_time *calibrated_time); + /** + * @brief The calibrate returns a Vulkan time domain + an offset + * + * @param present_stage The present stage to calibrate + * @param calibrated_time The calibrated time output + * @return VK_SUCCESS when calibrated successfully VK_ERROR_OUT_OF_HOST_MEMORY otherwise. + */ + VkResult calibrate(VkPresentStageFlagBitsEXT present_stage, swapchain_calibrated_time *calibrated_time); /** * @brief Get swapchain time domain properties.