upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/vulkan_present.h
diff options
context:
space:
mode:
authorInstru Control <122008638+hosienzade45@users.noreply.github.com>2026-11-22 15:42:57 +0330
committerGitHub <noreply@github.com>2026-11-22 15:42:57 +0330
commitb367783da59adfa32f05fee9f0016f3a389d8537 (patch)
treea903eb40560c4676af64d0f70537b47f6a220fa5 /runtime/src/vulkan_present.h
parentbb2e18421dac527374eb837c88b5063c5d96f81f (diff)
Keep the Vulkan swapchain alive until preflight succeeds
Diffstat (limited to 'runtime/src/vulkan_present.h')
-rw-r--r--runtime/src/vulkan_present.h40
1 files changed, 20 insertions, 20 deletions
diff --git a/runtime/src/vulkan_present.h b/runtime/src/vulkan_present.h
index 98a8d93c9..4bd7cb280 100644
--- a/runtime/src/vulkan_present.h
+++ b/runtime/src/vulkan_present.h
@@ -509,9 +509,8 @@ private:
509 } 509 }
510 510
511 // (Re)creates the swapchain for the surface's current size. A zero-sized surface (minimised) leaves no 511 // (Re)creates the swapchain for the surface's current size. A zero-sized surface (minimised) leaves no
512 // swapchain and is retried on the next present. Nothing is published until every piece exists: on any failure 512 // swapchain and is retried on the next present. Keep the old swapchain until the surface queries succeed and
513 // the presenter is left with no swapchain and stale_ set, so the next present tries again, and no image is ever 513 // the replacement can be attempted. An incomplete replacement stays stale so the next present tries again.
514 // acquired without its per-image semaphore.
515 bool recreate(bool vsync, bool srgb) { 514 bool recreate(bool vsync, bool srgb) {
516 auto& vk = context_.vk; 515 auto& vk = context_.vk;
517 const VkDevice device = context_.device(); 516 const VkDevice device = context_.device();
@@ -522,25 +521,25 @@ private:
522 stale_ = true; // until this succeeds 521 stale_ = true; // until this succeeds
523 VkSurfaceCapabilitiesKHR caps{}; 522 VkSurfaceCapabilitiesKHR caps{};
524 if (vkGetPhysicalDeviceSurfaceCapabilitiesKHR_(physical_, surface_, &caps) != VK_SUCCESS) return false; 523 if (vkGetPhysicalDeviceSurfaceCapabilitiesKHR_(physical_, surface_, &caps) != VK_SUCCESS) return false;
525 VkSwapchainKHR old = swapchain_;
526 swapchain_ = VK_NULL_HANDLE;
527 if (caps.currentExtent.width == 0 || caps.currentExtent.height == 0) { 524 if (caps.currentExtent.width == 0 || caps.currentExtent.height == 0) {
528 release(old); 525 release(swapchain_);
526 swapchain_ = VK_NULL_HANDLE;
529 vsync_ = vsync; 527 vsync_ = vsync;
530 swapchain_srgb_ = srgb; 528 swapchain_srgb_ = srgb;
531 stale_ = false; 529 stale_ = false;
532 return true; 530 return true;
533 } 531 }
534 if (!(caps.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) { 532 VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
535 release(old); 533 if (capture_) usage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
536 return false; 534 if ((caps.supportedUsageFlags & usage) != usage) return false;
537 }
538 535
539 std::uint32_t count = 0; 536 std::uint32_t count = 0;
540 vkGetPhysicalDeviceSurfaceFormatsKHR_(physical_, surface_, &count, nullptr); 537 if (vkGetPhysicalDeviceSurfaceFormatsKHR_(physical_, surface_, &count, nullptr) != VK_SUCCESS || !count)
538 return false;
541 std::vector<VkSurfaceFormatKHR> formats(count); 539 std::vector<VkSurfaceFormatKHR> formats(count);
542 vkGetPhysicalDeviceSurfaceFormatsKHR_(physical_, surface_, &count, formats.data()); 540 if (vkGetPhysicalDeviceSurfaceFormatsKHR_(physical_, surface_, &count, formats.data()) != VK_SUCCESS || !count)
543 if (formats.empty()) return false; 541 return false;
542 formats.resize(count);
544 // An sRGB source wants an sRGB swapchain (the blit decodes and encodes, which cancel); any other source 543 // An sRGB source wants an sRGB swapchain (the blit decodes and encodes, which cancel); any other source
545 // wants UNORM (the bytes go through as they are). BGRA before RGBA, as the surface lists them. 544 // wants UNORM (the bytes go through as they are). BGRA before RGBA, as the surface lists them.
546 VkSurfaceFormatKHR chosen = formats[0]; 545 VkSurfaceFormatKHR chosen = formats[0];
@@ -565,9 +564,12 @@ private:
565 break; 564 break;
566 } 565 }
567 } 566 }
568 vkGetPhysicalDeviceSurfacePresentModesKHR_(physical_, surface_, &count, nullptr); 567 if (vkGetPhysicalDeviceSurfacePresentModesKHR_(physical_, surface_, &count, nullptr) != VK_SUCCESS || !count)
568 return false;
569 std::vector<VkPresentModeKHR> modes(count); 569 std::vector<VkPresentModeKHR> modes(count);
570 vkGetPhysicalDeviceSurfacePresentModesKHR_(physical_, surface_, &count, modes.data()); 570 if (vkGetPhysicalDeviceSurfacePresentModesKHR_(physical_, surface_, &count, modes.data()) != VK_SUCCESS || !count)
571 return false;
572 modes.resize(count);
571 VkPresentModeKHR mode = VK_PRESENT_MODE_FIFO_KHR; // always available 573 VkPresentModeKHR mode = VK_PRESENT_MODE_FIFO_KHR; // always available
572 if (!vsync) { 574 if (!vsync) {
573 for (const VkPresentModeKHR wanted : {VK_PRESENT_MODE_MAILBOX_KHR, VK_PRESENT_MODE_IMMEDIATE_KHR}) 575 for (const VkPresentModeKHR wanted : {VK_PRESENT_MODE_MAILBOX_KHR, VK_PRESENT_MODE_IMMEDIATE_KHR})
@@ -585,17 +587,15 @@ private:
585 info.imageColorSpace = chosen.colorSpace; 587 info.imageColorSpace = chosen.colorSpace;
586 info.imageExtent = caps.currentExtent; 588 info.imageExtent = caps.currentExtent;
587 info.imageArrayLayers = 1; 589 info.imageArrayLayers = 1;
588 info.imageUsage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; 590 info.imageUsage = usage;
589 if (capture_) {
590 if (!(caps.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT)) return false;
591 info.imageUsage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
592 }
593 info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; 591 info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
594 info.preTransform = caps.currentTransform; 592 info.preTransform = caps.currentTransform;
595 info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; 593 info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
596 if (!(caps.supportedCompositeAlpha & info.compositeAlpha)) info.compositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR; 594 if (!(caps.supportedCompositeAlpha & info.compositeAlpha)) info.compositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR;
597 info.presentMode = mode; 595 info.presentMode = mode;
598 info.clipped = VK_TRUE; 596 info.clipped = VK_TRUE;
597 const VkSwapchainKHR old = swapchain_;
598 swapchain_ = VK_NULL_HANDLE;
599 info.oldSwapchain = old; 599 info.oldSwapchain = old;
600 VkSwapchainKHR fresh = VK_NULL_HANDLE; 600 VkSwapchainKHR fresh = VK_NULL_HANDLE;
601 const VkResult created = vkCreateSwapchainKHR_(device, &info, nullptr, &fresh); 601 const VkResult created = vkCreateSwapchainKHR_(device, &info, nullptr, &fresh);