diff options
| author | quartz-heron-58 <245169279+quartz-heron-58@users.noreply.github.com> | 2026-11-25 00:42:48 +0800 |
|---|---|---|
| committer | quartz-heron-58 <245169279+quartz-heron-58@users.noreply.github.com> | 2026-11-25 00:42:48 +0800 |
| commit | da74b96810eba31eb15d1cfd576fe4c69f159912 (patch) | |
| tree | 421a3c01b4205212d28a02e5ebb812d1b2d22d01 /runtime/src/vulkan_backend.h | |
| parent | 5c1f77e1d4bafb3cba8c3e2037de28cb376f633e (diff) | |
vulkan: print the driver's fault report when the device is lost (RT-DEVICE-FAULT-INFO)
Where the device has VK_EXT_device_fault, enable it and, the first time the
device is lost, query vkGetDeviceFaultInfoEXT and print the description, the
address faults and the vendor faults after the "device was lost" line.
Nothing is printed and nothing changes without the extension.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/vulkan_backend.h')
| -rw-r--r-- | runtime/src/vulkan_backend.h | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h index dcf89476c..7f0723483 100644 --- a/runtime/src/vulkan_backend.h +++ b/runtime/src/vulkan_backend.h | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | #include "statistics_sum_spirv.h" | 17 | #include "statistics_sum_spirv.h" |
| 18 | #include "vulkan13_features.h" | 18 | #include "vulkan13_features.h" |
| 19 | #include "vulkan_depth24.h" | 19 | #include "vulkan_depth24.h" |
| 20 | #include "vulkan_device_fault.h" | ||
| 20 | #include "vulkan_indirect_dispatch_count.h" | 21 | #include "vulkan_indirect_dispatch_count.h" |
| 21 | #include "vulkan_scratch.h" | 22 | #include "vulkan_scratch.h" |
| 22 | #include "vulkan_replay.h" | 23 | #include "vulkan_replay.h" |
| @@ -107,7 +108,7 @@ struct VulkanDeviceFunctions { | |||
| 107 | X(vkCreatePipelineCache) X(vkDestroyPipelineCache) \ | 108 | X(vkCreatePipelineCache) X(vkDestroyPipelineCache) \ |
| 108 | X(vkCreateEvent) X(vkDestroyEvent) X(vkResetEvent) X(vkCmdSetEvent) X(vkCmdWaitEvents) X(vkCmdDrawMeshTasksEXT) \ | 109 | X(vkCreateEvent) X(vkDestroyEvent) X(vkResetEvent) X(vkCmdSetEvent) X(vkCmdWaitEvents) X(vkCmdDrawMeshTasksEXT) \ |
| 109 | X(vkCreateRenderPass2) X(vkDestroyRenderPass) X(vkCreateFramebuffer) X(vkDestroyFramebuffer) \ | 110 | X(vkCreateRenderPass2) X(vkDestroyRenderPass) X(vkCreateFramebuffer) X(vkDestroyFramebuffer) \ |
| 110 | X(vkCmdBeginRenderPass) X(vkCmdEndRenderPass) | 111 | X(vkCmdBeginRenderPass) X(vkCmdEndRenderPass) X(vkGetDeviceFaultInfoEXT) |
| 111 | #define LEONIDA_VK_MEMBER(name) PFN_##name name = nullptr; | 112 | #define LEONIDA_VK_MEMBER(name) PFN_##name name = nullptr; |
| 112 | LEONIDA_VK_DEVICE_FUNCTIONS(LEONIDA_VK_MEMBER) | 113 | LEONIDA_VK_DEVICE_FUNCTIONS(LEONIDA_VK_MEMBER) |
| 113 | #undef LEONIDA_VK_MEMBER | 114 | #undef LEONIDA_VK_MEMBER |
| @@ -565,6 +566,22 @@ inline bool set_device_lost(std::atomic<bool>& flag, const char* where) noexcept | |||
| 565 | return true; | 566 | return true; |
| 566 | } | 567 | } |
| 567 | 568 | ||
| 569 | // What the driver says about the loss, printed after the line above by the caller whose set_device_lost returned true, | ||
| 570 | // so once per device. Only where VK_EXT_device_fault is enabled: the entry point is null otherwise and nothing is | ||
| 571 | // printed (src/vulkan_device_fault.h). device_fault_reports counts the reports printed in this process (for tests). | ||
| 572 | inline std::atomic<unsigned> device_fault_reports{0}; | ||
| 573 | inline void report_device_fault(const VulkanDeviceFunctions& vk, VkDevice device) noexcept { | ||
| 574 | if (!vk.vkGetDeviceFaultInfoEXT || !device) return; | ||
| 575 | try { | ||
| 576 | const auto lines = device_fault_lines([&](VkDeviceFaultCountsEXT* counts, VkDeviceFaultInfoEXT* info) { | ||
| 577 | return vk.vkGetDeviceFaultInfoEXT(device, counts, info); | ||
| 578 | }); | ||
| 579 | for (const std::string& line : lines) std::fprintf(stderr, "[rt] vulkan: %s\n", line.c_str()); | ||
| 580 | device_fault_reports.fetch_add(1, std::memory_order_relaxed); | ||
| 581 | } catch (...) { // out of memory while the device is going down: the loss itself is already said | ||
| 582 | } | ||
| 583 | } | ||
| 584 | |||
| 568 | // Centralized single-thread fence dispatcher using Vulkan 1.2 vkWaitSemaphores(VK_SEMAPHORE_WAIT_ANY_BIT). | 585 | // Centralized single-thread fence dispatcher using Vulkan 1.2 vkWaitSemaphores(VK_SEMAPHORE_WAIT_ANY_BIT). |
| 569 | // Eliminates per-fence OS threads and 10ms polling: a synthetic timeline semaphore (wakeup_sem_) at index 0 | 586 | // Eliminates per-fence OS threads and 10ms polling: a synthetic timeline semaphore (wakeup_sem_) at index 0 |
| 570 | // wakes vkWaitSemaphores immediately whenever a new wait, a released fence, or shutdown arrives while waiting_ == true. | 587 | // wakes vkWaitSemaphores immediately whenever a new wait, a released fence, or shutdown arrives while waiting_ == true. |
| @@ -837,7 +854,9 @@ private: | |||
| 837 | epoch_cv_.notify_all(); | 854 | epoch_cv_.notify_all(); |
| 838 | 855 | ||
| 839 | if (res == VK_ERROR_DEVICE_LOST || device_lost_.load(std::memory_order_acquire)) { | 856 | if (res == VK_ERROR_DEVICE_LOST || device_lost_.load(std::memory_order_acquire)) { |
| 840 | set_device_lost(device_lost_, "vkWaitSemaphores in the fence dispatcher returned VK_ERROR_DEVICE_LOST"); | 857 | if (set_device_lost(device_lost_, |
| 858 | "vkWaitSemaphores in the fence dispatcher returned VK_ERROR_DEVICE_LOST")) | ||
| 859 | report_device_fault(vk_, device_); | ||
| 841 | std::vector<Entry> drained = std::move(pending_); | 860 | std::vector<Entry> drained = std::move(pending_); |
| 842 | pending_.clear(); | 861 | pending_.clear(); |
| 843 | dispatch_outside_lock(lock, drained, signal_event_); | 862 | dispatch_outside_lock(lock, drained, signal_event_); |
| @@ -867,8 +886,9 @@ private: | |||
| 867 | pending_.resize(write); | 886 | pending_.resize(write); |
| 868 | for (Entry& e : pending_) ready.push_back(std::move(e)); | 887 | for (Entry& e : pending_) ready.push_back(std::move(e)); |
| 869 | pending_.clear(); | 888 | pending_.clear(); |
| 870 | set_device_lost(device_lost_, | 889 | if (set_device_lost(device_lost_, |
| 871 | "vkGetSemaphoreCounterValue in the fence dispatcher returned VK_ERROR_DEVICE_LOST"); | 890 | "vkGetSemaphoreCounterValue in the fence dispatcher returned VK_ERROR_DEVICE_LOST")) |
| 891 | report_device_fault(vk_, device_); | ||
| 872 | dispatch_outside_lock(lock, ready, signal_event_); | 892 | dispatch_outside_lock(lock, ready, signal_event_); |
| 873 | return; | 893 | return; |
| 874 | } | 894 | } |
| @@ -1556,7 +1576,7 @@ public: | |||
| 1556 | std::mutex& submit_mutex() { return submit_mutex_; } | 1576 | std::mutex& submit_mutex() { return submit_mutex_; } |
| 1557 | 1577 | ||
| 1558 | void mark_device_lost(const char* where = "a Vulkan call returned VK_ERROR_DEVICE_LOST") noexcept { | 1578 | void mark_device_lost(const char* where = "a Vulkan call returned VK_ERROR_DEVICE_LOST") noexcept { |
| 1559 | set_device_lost(device_lost_, where); | 1579 | if (set_device_lost(device_lost_, where)) report_device_fault(vk, device_); |
| 1560 | if (fence_dispatcher_) { | 1580 | if (fence_dispatcher_) { |
| 1561 | try { | 1581 | try { |
| 1562 | fence_dispatcher_->notify_device_lost(); | 1582 | fence_dispatcher_->notify_device_lost(); |