From 6865ff18baf256a80e283d8ca323102e31954ef1 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Mon, 15 Dec 2025 23:53:53 -0800 Subject: [PATCH] kk: support VK_(KHR|EXT)_calibrated_timestamps Use common implementation. Reviewed-by: Aitor Camacho Part-of: --- docs/features.txt | 4 +- src/kosmickrisp/vulkan/kk_device.c | 55 ++++----------------- src/kosmickrisp/vulkan/kk_physical_device.c | 27 +--------- 3 files changed, 14 insertions(+), 72 deletions(-) diff --git a/docs/features.txt b/docs/features.txt index ea2f18e64c0..5e907be8ff9 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -538,7 +538,7 @@ Khronos extensions that are not part of any Vulkan version: VK_KHR_acceleration_structure DONE (anv/gfx12.5+, lvp, radv/gfx10.3+, tu/a740+, vn) VK_KHR_android_surface not started - VK_KHR_calibrated_timestamps DONE (anv, hk, nvk, panvk/v10+, radv, tu/a750+, vn) + VK_KHR_calibrated_timestamps DONE (anv, hk, kk, nvk, panvk/v10+, radv, tu/a750+, vn) VK_KHR_compute_shader_derivatives DONE (anv, lvp, nvk, radv, tu/a7xx+, vn) VK_KHR_cooperative_matrix DONE (anv, nvk/Turing+, radv/gfx11+, vn) VK_KHR_depth_clamp_zero_one DONE (anv, nvk, panvk, radv, vn) @@ -600,7 +600,7 @@ Khronos extensions that are not part of any Vulkan version: VK_EXT_blend_operation_advanced DONE (vn) VK_EXT_border_color_swizzle DONE (anv, hasvk, hk, lvp, nvk, panvk, pvr, radv/gfx10+, tu, v3dv, vn) VK_EXT_buffer_device_address DONE (anv, dzn/sm6.6+, hasvk, hk, nvk, panvk, radv, vn) - VK_EXT_calibrated_timestamps DONE (anv, hasvk, hk, nvk, panvk/v10+, lvp, radv, vn, tu/a750+) + VK_EXT_calibrated_timestamps DONE (anv, hasvk, hk, kk, nvk, panvk/v10+, lvp, radv, vn, tu/a750+) VK_EXT_color_write_enable DONE (anv, hasvk, hk, lvp, nvk, pvr, radv, tu, v3dv, vn) VK_EXT_conditional_rendering DONE (anv, hasvk, lvp, nvk, radv, tu, vn) VK_EXT_conservative_rasterization DONE (anv, nvk, radv, vn, tu/a7xx+) diff --git a/src/kosmickrisp/vulkan/kk_device.c b/src/kosmickrisp/vulkan/kk_device.c index 93e959ce746..c81f92adbdb 100644 --- a/src/kosmickrisp/vulkan/kk_device.c +++ b/src/kosmickrisp/vulkan/kk_device.c @@ -163,6 +163,15 @@ kk_parse_device_environment_options(struct kk_device *dev) } } +static VkResult +kk_get_timestamp(struct vk_device *device, uint64_t *timestamp) +{ + struct kk_device *dev = container_of(device, struct kk_device, vk); + + *timestamp = mtl_device_get_gpu_timestamp(dev->mtl_handle); + return VK_SUCCESS; +} + VKAPI_ATTR VkResult VKAPI_CALL kk_CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, @@ -204,6 +213,7 @@ kk_CreateDevice(VkPhysicalDevice physicalDevice, dev->mtl_handle = pdev->mtl_dev_handle; dev->vk.command_buffer_ops = &kk_cmd_buffer_ops; dev->vk.command_dispatch_table = &dev->vk.dispatch_table; + dev->vk.get_timestamp = kk_get_timestamp; /* We need to initialize the device residency set before any bo is created. */ simple_mtx_init(&dev->residency_set.mutex, mtx_plain); @@ -287,51 +297,6 @@ kk_DestroyDevice(VkDevice _device, const VkAllocationCallbacks *pAllocator) vk_free(&dev->vk.alloc, dev); } -VKAPI_ATTR VkResult VKAPI_CALL -kk_GetCalibratedTimestampsKHR( - VkDevice _device, uint32_t timestampCount, - const VkCalibratedTimestampInfoKHR *pTimestampInfos, uint64_t *pTimestamps, - uint64_t *pMaxDeviation) -{ - uint64_t max_clock_period = 0; - uint64_t begin, end; - int d; - -#ifdef CLOCK_MONOTONIC_RAW - begin = vk_clock_gettime(CLOCK_MONOTONIC_RAW); -#else - begin = vk_clock_gettime(CLOCK_MONOTONIC); -#endif - - for (d = 0; d < timestampCount; d++) { - switch (pTimestampInfos[d].timeDomain) { - case VK_TIME_DOMAIN_CLOCK_MONOTONIC_KHR: - pTimestamps[d] = vk_clock_gettime(CLOCK_MONOTONIC); - max_clock_period = MAX2(max_clock_period, 1); - break; - -#ifdef CLOCK_MONOTONIC_RAW - case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_KHR: - pTimestamps[d] = begin; - break; -#endif - default: - pTimestamps[d] = 0; - break; - } - } - -#ifdef CLOCK_MONOTONIC_RAW - end = vk_clock_gettime(CLOCK_MONOTONIC_RAW); -#else - end = vk_clock_gettime(CLOCK_MONOTONIC); -#endif - - *pMaxDeviation = vk_time_max_deviation(begin, end, max_clock_period); - - return VK_SUCCESS; -} - /* We need to implement this ourselves so we give the fake ones for vk_common_* * to work when executing actual commands */ static PFN_vkVoidFunction diff --git a/src/kosmickrisp/vulkan/kk_physical_device.c b/src/kosmickrisp/vulkan/kk_physical_device.c index 37defbf0e3a..42a1469fdfe 100644 --- a/src/kosmickrisp/vulkan/kk_physical_device.c +++ b/src/kosmickrisp/vulkan/kk_physical_device.c @@ -122,6 +122,7 @@ kk_get_device_extensions(const struct kk_instance *instance, .EXT_vertex_attribute_divisor = true, /* Optional extensions */ + .KHR_calibrated_timestamps = true, .KHR_shader_maximal_reconvergence = true, .KHR_shader_relaxed_extended_instruction = true, .KHR_shader_subgroup_uniform_control_flow = true, @@ -131,6 +132,7 @@ kk_get_device_extensions(const struct kk_instance *instance, #endif .KHR_workgroup_memory_explicit_layout = true, + .EXT_calibrated_timestamps = true, .EXT_external_memory_metal = true, .EXT_load_store_op_none = true, .EXT_mutable_descriptor_type = true, @@ -1003,31 +1005,6 @@ kk_GetPhysicalDeviceQueueFamilyProperties2( } } -static const VkTimeDomainKHR kk_time_domains[] = { - VK_TIME_DOMAIN_DEVICE_KHR, - VK_TIME_DOMAIN_CLOCK_MONOTONIC_KHR, -#ifdef CLOCK_MONOTONIC_RAW - VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_KHR, -#endif -}; - -VKAPI_ATTR VkResult VKAPI_CALL -kk_GetPhysicalDeviceCalibrateableTimeDomainsKHR(VkPhysicalDevice physicalDevice, - uint32_t *pTimeDomainCount, - VkTimeDomainKHR *pTimeDomains) -{ - VK_OUTARRAY_MAKE_TYPED(VkTimeDomainKHR, out, pTimeDomains, pTimeDomainCount); - - for (int d = 0; d < ARRAY_SIZE(kk_time_domains); d++) { - vk_outarray_append_typed(VkTimeDomainKHR, &out, i) - { - *i = kk_time_domains[d]; - } - } - - return vk_outarray_status(&out); -} - VKAPI_ATTR void VKAPI_CALL kk_GetPhysicalDeviceMultisamplePropertiesEXT( VkPhysicalDevice physicalDevice, VkSampleCountFlagBits samples,