diff options
| author | CLHelper <359823989+CLHelper@users.noreply.github.com> | 2026-11-24 16:09:38 +0000 |
|---|---|---|
| committer | CLHelper <359823989+CLHelper@users.noreply.github.com> | 2026-11-24 16:09:38 +0000 |
| commit | 5c1f77e1d4bafb3cba8c3e2037de28cb376f633e (patch) | |
| tree | 79176ca66d552c48ec478d20f8f82ec49c82d9be /runtime/src/vulkan_backend.h | |
| parent | a28927849adb4e40dfdec8c32fb6758dcd205a37 (diff) | |
vulkan: say once when the device is lost (RT-DEVICE-LOST-LOG)
VulkanContext::mark_device_lost() and the fence dispatcher's two VK_ERROR_DEVICE_LOST paths only set the device's lost
flag. From then on every fence reads UINT64_MAX and device calls return DXGI_ERROR_DEVICE_REMOVED, so a title takes its
own device-removed path (on the retail boot an int3 at game_scarlett_master.exe+0x2474606, reached from its frame wait
reading a fence's completed value as ~0), and nothing in the log said the device had gone first.
set_device_lost() sets the flag with an exchange and, the first time for a device, prints one stderr line saying where
the loss was seen. mark_device_lost() takes that place as an optional argument; the dispatcher passes its own two.
device_lost_reports counts the lines for tests.
Tests: vk_fence_dispatcher_sync_test cases 3 and 4 check one line per device, from mark_device_lost() and from the
dispatcher's vkGetSemaphoreCounterValue path, and none from a later call on the same device.
AI-assisted.
Diffstat (limited to 'runtime/src/vulkan_backend.h')
| -rw-r--r-- | runtime/src/vulkan_backend.h | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h index f90dd6a3f..dcf89476c 100644 --- a/runtime/src/vulkan_backend.h +++ b/runtime/src/vulkan_backend.h | |||
| @@ -549,6 +549,22 @@ private: | |||
| 549 | void* bindless_release_user_ = nullptr; | 549 | void* bindless_release_user_ = nullptr; |
| 550 | }; | 550 | }; |
| 551 | 551 | ||
| 552 | // Sets a device's lost flag and says so once, on stderr, at the moment it is first seen. From then on every fence of | ||
| 553 | // the device reads UINT64_MAX and device calls return DXGI_ERROR_DEVICE_REMOVED, so a title takes its own | ||
| 554 | // device-removed path (on the retail boot an int3 at game_scarlett_master.exe+0x2474606, reached from its frame wait | ||
| 555 | // reading a fence's completed value as ~0); without this line that later stop is the first sign of the loss. | ||
| 556 | // True when this call set the flag. device_lost_reports counts the lines said in this process (for tests). | ||
| 557 | inline std::atomic<unsigned> device_lost_reports{0}; | ||
| 558 | inline bool set_device_lost(std::atomic<bool>& flag, const char* where) noexcept { | ||
| 559 | if (flag.exchange(true, std::memory_order_acq_rel)) return false; | ||
| 560 | device_lost_reports.fetch_add(1, std::memory_order_relaxed); | ||
| 561 | std::fprintf(stderr, | ||
| 562 | "[rt] vulkan: the device was lost (%s); its fences now read UINT64_MAX and device calls return " | ||
| 563 | "DXGI_ERROR_DEVICE_REMOVED\n", | ||
| 564 | where); | ||
| 565 | return true; | ||
| 566 | } | ||
| 567 | |||
| 552 | // Centralized single-thread fence dispatcher using Vulkan 1.2 vkWaitSemaphores(VK_SEMAPHORE_WAIT_ANY_BIT). | 568 | // Centralized single-thread fence dispatcher using Vulkan 1.2 vkWaitSemaphores(VK_SEMAPHORE_WAIT_ANY_BIT). |
| 553 | // Eliminates per-fence OS threads and 10ms polling: a synthetic timeline semaphore (wakeup_sem_) at index 0 | 569 | // Eliminates per-fence OS threads and 10ms polling: a synthetic timeline semaphore (wakeup_sem_) at index 0 |
| 554 | // wakes vkWaitSemaphores immediately whenever a new wait, a released fence, or shutdown arrives while waiting_ == true. | 570 | // wakes vkWaitSemaphores immediately whenever a new wait, a released fence, or shutdown arrives while waiting_ == true. |
| @@ -821,7 +837,7 @@ private: | |||
| 821 | epoch_cv_.notify_all(); | 837 | epoch_cv_.notify_all(); |
| 822 | 838 | ||
| 823 | if (res == VK_ERROR_DEVICE_LOST || device_lost_.load(std::memory_order_acquire)) { | 839 | if (res == VK_ERROR_DEVICE_LOST || device_lost_.load(std::memory_order_acquire)) { |
| 824 | device_lost_.store(true, std::memory_order_release); | 840 | set_device_lost(device_lost_, "vkWaitSemaphores in the fence dispatcher returned VK_ERROR_DEVICE_LOST"); |
| 825 | std::vector<Entry> drained = std::move(pending_); | 841 | std::vector<Entry> drained = std::move(pending_); |
| 826 | pending_.clear(); | 842 | pending_.clear(); |
| 827 | dispatch_outside_lock(lock, drained, signal_event_); | 843 | dispatch_outside_lock(lock, drained, signal_event_); |
| @@ -851,7 +867,8 @@ private: | |||
| 851 | pending_.resize(write); | 867 | pending_.resize(write); |
| 852 | for (Entry& e : pending_) ready.push_back(std::move(e)); | 868 | for (Entry& e : pending_) ready.push_back(std::move(e)); |
| 853 | pending_.clear(); | 869 | pending_.clear(); |
| 854 | device_lost_.store(true, std::memory_order_release); | 870 | set_device_lost(device_lost_, |
| 871 | "vkGetSemaphoreCounterValue in the fence dispatcher returned VK_ERROR_DEVICE_LOST"); | ||
| 855 | dispatch_outside_lock(lock, ready, signal_event_); | 872 | dispatch_outside_lock(lock, ready, signal_event_); |
| 856 | return; | 873 | return; |
| 857 | } | 874 | } |
| @@ -1538,8 +1555,8 @@ public: | |||
| 1538 | // Vulkan requires external synchronisation of a VkQueue; every D3D12 queue of the device may share one. | 1555 | // Vulkan requires external synchronisation of a VkQueue; every D3D12 queue of the device may share one. |
| 1539 | std::mutex& submit_mutex() { return submit_mutex_; } | 1556 | std::mutex& submit_mutex() { return submit_mutex_; } |
| 1540 | 1557 | ||
| 1541 | void mark_device_lost() noexcept { | 1558 | void mark_device_lost(const char* where = "a Vulkan call returned VK_ERROR_DEVICE_LOST") noexcept { |
| 1542 | device_lost_.store(true, std::memory_order_release); | 1559 | set_device_lost(device_lost_, where); |
| 1543 | if (fence_dispatcher_) { | 1560 | if (fence_dispatcher_) { |
| 1544 | try { | 1561 | try { |
| 1545 | fence_dispatcher_->notify_device_lost(); | 1562 | fence_dispatcher_->notify_device_lost(); |