diff options
| author | SHAURYASANYAL3 <shauryasanya.21jun@gmail.com> | 2026-11-22 18:52:42 +0530 |
|---|---|---|
| committer | SHAURYASANYAL3 <shauryasanya.21jun@gmail.com> | 2026-11-22 18:59:51 +0530 |
| commit | 1f71839aa34a57bb2fc6bed5dbcd6f5a93d7f541 (patch) | |
| tree | 8b9fdd898a5166b2884a3284e99c7d15b6078669 /runtime/src | |
| parent | a0acd33d77babe67a28e398b2936a9f735a50f5d (diff) | |
runtime: fallback and clamp swapchain extent when surface reports undefined extent (D3D-165)
Diffstat (limited to 'runtime/src')
| -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 b862ae6a3..63438324c 100644 --- a/runtime/src/vulkan_present.h +++ b/runtime/src/vulkan_present.h | |||
| @@ -74,9 +74,10 @@ class VulkanPresenter { | |||
| 74 | public: | 74 | public: |
| 75 | VulkanPresenter(VulkanContext& context, PFN_vkGetInstanceProcAddr get_instance, VkInstance instance, | 75 | VulkanPresenter(VulkanContext& context, PFN_vkGetInstanceProcAddr get_instance, VkInstance instance, |
| 76 | VkPhysicalDevice physical, VkQueue queue, std::uint32_t family, VkSurfaceKHR surface, | 76 | VkPhysicalDevice physical, VkQueue queue, std::uint32_t family, VkSurfaceKHR surface, |
| 77 | bool swapchain_maintenance1 = false) | 77 | bool swapchain_maintenance1 = false, |
| 78 | std::function<VkExtent2D()> extent_fn = nullptr) | ||
| 78 | : context_(context), instance_(instance), physical_(physical), queue_(queue), surface_(surface), | 79 | : context_(context), instance_(instance), physical_(physical), queue_(queue), surface_(surface), |
| 79 | maintenance1_(swapchain_maintenance1) { | 80 | maintenance1_(swapchain_maintenance1), extent_fn_(std::move(extent_fn)) { |
| 80 | #define LEONIDA_INSTANCE_FN(name) name##_ = reinterpret_cast<PFN_##name>(get_instance(instance, #name)); | 81 | #define LEONIDA_INSTANCE_FN(name) name##_ = reinterpret_cast<PFN_##name>(get_instance(instance, #name)); |
| 81 | LEONIDA_INSTANCE_FN(vkGetPhysicalDeviceSurfaceSupportKHR) | 82 | LEONIDA_INSTANCE_FN(vkGetPhysicalDeviceSurfaceSupportKHR) |
| 82 | LEONIDA_INSTANCE_FN(vkGetPhysicalDeviceSurfaceCapabilitiesKHR) | 83 | LEONIDA_INSTANCE_FN(vkGetPhysicalDeviceSurfaceCapabilitiesKHR) |
| @@ -568,7 +569,21 @@ private: | |||
| 568 | tear_mode_ = VK_PRESENT_MODE_MAX_ENUM_KHR; | 569 | tear_mode_ = VK_PRESENT_MODE_MAX_ENUM_KHR; |
| 569 | VkSurfaceCapabilitiesKHR caps{}; | 570 | VkSurfaceCapabilitiesKHR caps{}; |
| 570 | if (vkGetPhysicalDeviceSurfaceCapabilitiesKHR_(physical_, surface_, &caps) != VK_SUCCESS) return false; | 571 | if (vkGetPhysicalDeviceSurfaceCapabilitiesKHR_(physical_, surface_, &caps) != VK_SUCCESS) return false; |
| 571 | if (caps.currentExtent.width == 0 || caps.currentExtent.height == 0) { | 572 | VkExtent2D extent = caps.currentExtent; |
| 573 | // When the platform leaves the swapchain extent to the application (0xFFFFFFFF, as on Intel UHD / Win32 WSI), | ||
| 574 | // query the window client area or fall back to the last known extent, and clamp to the surface bounds (D3D-165). | ||
| 575 | if (extent.width == 0xFFFFFFFF || extent.height == 0xFFFFFFFF) { | ||
| 576 | if (extent_fn_) extent = extent_fn_(); | ||
| 577 | // ponytail: if no window extent function was supplied, fall back to last extent_ or minImageExtent | ||
| 578 | if (extent.width == 0xFFFFFFFF || extent.height == 0xFFFFFFFF || (extent.width == 0 && extent.height == 0)) { | ||
| 579 | extent = extent_.width && extent_.height ? extent_ : caps.minImageExtent; | ||
| 580 | } | ||
| 581 | if (extent.width && extent.height) { | ||
| 582 | extent.width = std::clamp(extent.width, caps.minImageExtent.width, caps.maxImageExtent.width); | ||
| 583 | extent.height = std::clamp(extent.height, caps.minImageExtent.height, caps.maxImageExtent.height); | ||
| 584 | } | ||
| 585 | } | ||
| 586 | if (extent.width == 0 || extent.height == 0) { | ||
| 572 | release(swapchain_); | 587 | release(swapchain_); |
| 573 | swapchain_ = VK_NULL_HANDLE; | 588 | swapchain_ = VK_NULL_HANDLE; |
| 574 | vsync_ = vsync; | 589 | vsync_ = vsync; |
| @@ -632,7 +647,7 @@ private: | |||
| 632 | if (caps.maxImageCount) info.minImageCount = std::min(info.minImageCount, caps.maxImageCount); | 647 | if (caps.maxImageCount) info.minImageCount = std::min(info.minImageCount, caps.maxImageCount); |
| 633 | info.imageFormat = chosen.format; | 648 | info.imageFormat = chosen.format; |
| 634 | info.imageColorSpace = chosen.colorSpace; | 649 | info.imageColorSpace = chosen.colorSpace; |
| 635 | info.imageExtent = caps.currentExtent; | 650 | info.imageExtent = extent; |
| 636 | info.imageArrayLayers = 1; | 651 | info.imageArrayLayers = 1; |
| 637 | info.imageUsage = usage; | 652 | info.imageUsage = usage; |
| 638 | info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; | 653 | info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| @@ -686,7 +701,7 @@ private: | |||
| 686 | images_ = std::move(images); | 701 | images_ = std::move(images); |
| 687 | ready_ = std::move(ready); | 702 | ready_ = std::move(ready); |
| 688 | format_ = chosen.format; | 703 | format_ = chosen.format; |
| 689 | extent_ = caps.currentExtent; | 704 | extent_ = extent; |
| 690 | if (capture_) { | 705 | if (capture_) { |
| 691 | // A capture that cannot be made fails the recreation with the swapchain in place and stale_ still set. | 706 | // A capture that cannot be made fails the recreation with the swapchain in place and stale_ still set. |
| 692 | const bool four_bytes = format_ == VK_FORMAT_B8G8R8A8_UNORM || format_ == VK_FORMAT_R8G8B8A8_UNORM || | 707 | const bool four_bytes = format_ == VK_FORMAT_B8G8R8A8_UNORM || format_ == VK_FORMAT_R8G8B8A8_UNORM || |
| @@ -785,6 +800,7 @@ private: | |||
| 785 | bool ok_ = false; | 800 | bool ok_ = false; |
| 786 | bool swapchain_srgb_ = false; // the swapchain format follows the source being presented (set once it exists) | 801 | bool swapchain_srgb_ = false; // the swapchain format follows the source being presented (set once it exists) |
| 787 | std::function<bool()> abort_; | 802 | std::function<bool()> abort_; |
| 803 | std::function<VkExtent2D()> extent_fn_; | ||
| 788 | std::map<VkFormat, VkFormatFeatureFlags> features_; | 804 | std::map<VkFormat, VkFormatFeatureFlags> features_; |
| 789 | bool warned_srgb_ = false; | 805 | bool warned_srgb_ = false; |
| 790 | bool capture_ = false; | 806 | bool capture_ = false; |