diff options
| author | mariuslozo-boop <254631011+mariuslozo-boop@users.noreply.github.com> | 2026-11-23 06:37:38 +0100 |
|---|---|---|
| committer | mariuslozo-boop <254631011+mariuslozo-boop@users.noreply.github.com> | 2026-11-23 06:37:38 +0100 |
| commit | 28ea6b971ba229e8caeb7bf4a50f263224b448fb (patch) | |
| tree | 83612b5f78671113bdf91c82d8a4df8e94288f44 /runtime/src/vulkan_present.h | |
| parent | 9366e54f9744bbcd7df428c602ce1e775a9b9001 (diff) | |
| parent | 98fa503f8a19c3ed65df1f4f2f0e4571aa42c4f7 (diff) | |
Merge remote-tracking branch 'origin/main' into rt/exe-tls-slot0
# Conflicts:
# runtime/src/main.cpp
Diffstat (limited to 'runtime/src/vulkan_present.h')
| -rw-r--r-- | runtime/src/vulkan_present.h | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/runtime/src/vulkan_present.h b/runtime/src/vulkan_present.h index fc6d1699e..a29cce3fa 100644 --- a/runtime/src/vulkan_present.h +++ b/runtime/src/vulkan_present.h | |||
| @@ -166,8 +166,10 @@ public: | |||
| 166 | { | 166 | { |
| 167 | std::lock_guard lock(context_.submit_mutex()); | 167 | std::lock_guard lock(context_.submit_mutex()); |
| 168 | vk.vkQueueWaitIdle(queue_); | 168 | vk.vkQueueWaitIdle(queue_); |
| 169 | // A WSI layer may perform a device-wide idle while destroying the swapchain. | ||
| 170 | // Keep that implicit idle serialized with submits from every context queue. | ||
| 171 | release(swapchain_); | ||
| 169 | } | 172 | } |
| 170 | release(swapchain_); | ||
| 171 | swapchain_ = VK_NULL_HANDLE; | 173 | swapchain_ = VK_NULL_HANDLE; |
| 172 | release_capture(); | 174 | release_capture(); |
| 173 | composer_.reset(); | 175 | composer_.reset(); |
| @@ -299,7 +301,9 @@ public: | |||
| 299 | } | 301 | } |
| 300 | 302 | ||
| 301 | // The last presented frame as the swapchain stores it (4 bytes a texel, rows tightly packed, format() order). | 303 | // The last presented frame as the swapchain stores it (4 bytes a texel, rows tightly packed, format() order). |
| 302 | // Waits for the frame to finish. False if no captured frame is available or the wait fails. | 304 | // Waits for the frame to finish. False when nothing was presented since enable_capture(), after a present |
| 305 | // that was skipped because the window is minimised (it returned VK_SUCCESS but showed nothing), until the next | ||
| 306 | // frame that is shown (the frame before it is not what the window was last asked to show), or when the wait fails. | ||
| 303 | bool read_back(std::vector<std::uint8_t>& pixels, VkExtent2D* extent, VkFormat* format) { | 307 | bool read_back(std::vector<std::uint8_t>& pixels, VkExtent2D* extent, VkFormat* format) { |
| 304 | if (!capture_ || !capture_ptr_ || !captured_) return false; | 308 | if (!capture_ || !capture_ptr_ || !captured_) return false; |
| 305 | const Frame& frame = frames_[(frame_index_ + frames_.size() - 1) % frames_.size()]; | 309 | const Frame& frame = frames_[(frame_index_ + frames_.size() - 1) % frames_.size()]; |
| @@ -331,6 +335,7 @@ public: | |||
| 331 | } | 335 | } |
| 332 | if (!swapchain_) { // minimised: try again next frame | 336 | if (!swapchain_) { // minimised: try again next frame |
| 333 | stale_ = true; | 337 | stale_ = true; |
| 338 | captured_ = false; // nothing was shown: read_back() must not hand out the frame before | ||
| 334 | return VK_SUCCESS; | 339 | return VK_SUCCESS; |
| 335 | } | 340 | } |
| 336 | if (binding && !presentable(source)) return VK_ERROR_UNKNOWN; // checked before an image is acquired for it | 341 | if (binding && !presentable(source)) return VK_ERROR_UNKNOWN; // checked before an image is acquired for it |
| @@ -347,7 +352,10 @@ public: | |||
| 347 | VkResult acquired = acquire(frame.acquired, &image); | 352 | VkResult acquired = acquire(frame.acquired, &image); |
| 348 | if (acquired == VK_ERROR_OUT_OF_DATE_KHR) { | 353 | if (acquired == VK_ERROR_OUT_OF_DATE_KHR) { |
| 349 | if (!recreate(vsync, swapchain_srgb_, swapchain_hdr_req_)) return acquired; | 354 | if (!recreate(vsync, swapchain_srgb_, swapchain_hdr_req_)) return acquired; |
| 350 | if (!swapchain_) return VK_SUCCESS; | 355 | if (!swapchain_) { // minimised since the last present: skipped, as above |
| 356 | captured_ = false; | ||
| 357 | return VK_SUCCESS; | ||
| 358 | } | ||
| 351 | acquired = acquire(frame.acquired, &image); | 359 | acquired = acquire(frame.acquired, &image); |
| 352 | } | 360 | } |
| 353 | if (acquired != VK_SUCCESS && acquired != VK_SUBOPTIMAL_KHR) return acquired; // nothing was acquired | 361 | if (acquired != VK_SUCCESS && acquired != VK_SUBOPTIMAL_KHR) return acquired; // nothing was acquired |
| @@ -873,7 +881,10 @@ private: | |||
| 873 | } | 881 | } |
| 874 | } | 882 | } |
| 875 | if (extent.width == 0 || extent.height == 0) { | 883 | if (extent.width == 0 || extent.height == 0) { |
| 876 | release(swapchain_); | 884 | { |
| 885 | std::lock_guard lock(context_.submit_mutex()); | ||
| 886 | release(swapchain_); | ||
| 887 | } | ||
| 877 | swapchain_ = VK_NULL_HANDLE; | 888 | swapchain_ = VK_NULL_HANDLE; |
| 878 | vsync_ = vsync; | 889 | vsync_ = vsync; |
| 879 | swapchain_srgb_ = srgb; | 890 | swapchain_srgb_ = srgb; |
| @@ -985,13 +996,18 @@ private: | |||
| 985 | info.oldSwapchain = old; | 996 | info.oldSwapchain = old; |
| 986 | VkSwapchainKHR fresh = VK_NULL_HANDLE; | 997 | VkSwapchainKHR fresh = VK_NULL_HANDLE; |
| 987 | const VkResult created = vkCreateSwapchainKHR_(device, &info, nullptr, &fresh); | 998 | const VkResult created = vkCreateSwapchainKHR_(device, &info, nullptr, &fresh); |
| 988 | release(old); // retired by the creation attempt, whether or not it succeeded | 999 | { |
| 1000 | std::lock_guard lock(context_.submit_mutex()); | ||
| 1001 | release(old); // retired by the creation attempt, whether or not it succeeded | ||
| 1002 | } | ||
| 989 | if (created != VK_SUCCESS) return false; | 1003 | if (created != VK_SUCCESS) return false; |
| 990 | 1004 | ||
| 991 | std::vector<VkImage> images; | 1005 | std::vector<VkImage> images; |
| 992 | std::vector<VkSemaphore> ready; | 1006 | std::vector<VkSemaphore> ready; |
| 993 | const auto discard = [&] { | 1007 | const auto discard = [&] { |
| 994 | for (VkSemaphore semaphore : ready) vk.vkDestroySemaphore(device, semaphore, nullptr); | 1008 | for (VkSemaphore semaphore : ready) vk.vkDestroySemaphore(device, semaphore, nullptr); |
| 1009 | // The WSI implementation may block on the device here too. | ||
| 1010 | std::lock_guard lock(context_.submit_mutex()); | ||
| 995 | vkDestroySwapchainKHR_(device, fresh, nullptr); | 1011 | vkDestroySwapchainKHR_(device, fresh, nullptr); |
| 996 | return false; | 1012 | return false; |
| 997 | }; | 1013 | }; |