diff options
| author | totonii <totonicontato@gmail.com> | 2026-11-22 08:18:25 -0300 |
|---|---|---|
| committer | totonii <totonicontato@gmail.com> | 2026-11-22 08:18:25 -0300 |
| commit | 1e5d0dbeb9f78c7577b119374cc385c7c64cef8f (patch) | |
| tree | a1e9844b91b7feced6d2a3f9a085485f4dcfdfb6 /runtime/shims/dxgi_com.cpp | |
| parent | a6daa4cffffa5a77fbda1aa80185d980d6bbdee7 (diff) | |
fix(dxgi): probe VK_PRESENT_MODE_IMMEDIATE_KHR for DXGI_FEATURE_PRESENT_ALLOW_TEARING
Diffstat (limited to 'runtime/shims/dxgi_com.cpp')
| -rw-r--r-- | runtime/shims/dxgi_com.cpp | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/runtime/shims/dxgi_com.cpp b/runtime/shims/dxgi_com.cpp index e61b7d392..3c8102b99 100644 --- a/runtime/shims/dxgi_com.cpp +++ b/runtime/shims/dxgi_com.cpp | |||
| @@ -777,15 +777,50 @@ public: | |||
| 777 | if (!data) return E_INVALIDARG; | 777 | if (!data) return E_INVALIDARG; |
| 778 | if (feature == DXGI_FEATURE_PRESENT_ALLOW_TEARING) { | 778 | if (feature == DXGI_FEATURE_PRESENT_ALLOW_TEARING) { |
| 779 | if (size != sizeof(BOOL)) return E_INVALIDARG; | 779 | if (size != sizeof(BOOL)) return E_INVALIDARG; |
| 780 | const auto present_modes = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfacePresentModesKHR>( | 780 | std::call_once(tearing_once_, [this] { tearing_supported_ = probe_immediate_present_mode(); }); |
| 781 | gipa_ ? gipa_(instance_, "vkGetPhysicalDeviceSurfacePresentModesKHR") : nullptr); | 781 | *static_cast<BOOL*>(data) = tearing_supported_ ? TRUE : FALSE; |
| 782 | *static_cast<BOOL*>(data) = present_modes ? TRUE : FALSE; | ||
| 783 | return S_OK; | 782 | return S_OK; |
| 784 | } | 783 | } |
| 785 | return E_INVALIDARG; | 784 | return E_INVALIDARG; |
| 786 | } | 785 | } |
| 787 | 786 | ||
| 788 | private: | 787 | private: |
| 788 | bool probe_immediate_present_mode() const { | ||
| 789 | if (!gipa_ || !instance_ || !physical_) return false; | ||
| 790 | const auto create_surface = | ||
| 791 | reinterpret_cast<PFN_vkCreateWin32SurfaceKHR>(gipa_(instance_, "vkCreateWin32SurfaceKHR")); | ||
| 792 | const auto destroy_surface = | ||
| 793 | reinterpret_cast<PFN_vkDestroySurfaceKHR>(gipa_(instance_, "vkDestroySurfaceKHR")); | ||
| 794 | const auto present_modes = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfacePresentModesKHR>( | ||
| 795 | gipa_(instance_, "vkGetPhysicalDeviceSurfacePresentModesKHR")); | ||
| 796 | if (!create_surface || !destroy_surface || !present_modes) return false; | ||
| 797 | const HINSTANCE hinst = GetModuleHandleW(nullptr); | ||
| 798 | HWND probe_hwnd = CreateWindowExW(0, L"STATIC", L"", WS_POPUP, 0, 0, 1, 1, nullptr, nullptr, hinst, nullptr); | ||
| 799 | if (!probe_hwnd) return false; | ||
| 800 | VkWin32SurfaceCreateInfoKHR sci{VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR}; | ||
| 801 | sci.hinstance = hinst; | ||
| 802 | sci.hwnd = probe_hwnd; | ||
| 803 | VkSurfaceKHR surf = VK_NULL_HANDLE; | ||
| 804 | bool has_immediate = false; | ||
| 805 | if (create_surface(instance_, &sci, nullptr, &surf) == VK_SUCCESS && surf) { | ||
| 806 | std::uint32_t count = 0; | ||
| 807 | if (present_modes(physical_, surf, &count, nullptr) == VK_SUCCESS && count > 0) { | ||
| 808 | std::vector<VkPresentModeKHR> modes(count); | ||
| 809 | if (present_modes(physical_, surf, &count, modes.data()) == VK_SUCCESS) { | ||
| 810 | for (VkPresentModeKHR m : modes) { | ||
| 811 | if (m == VK_PRESENT_MODE_IMMEDIATE_KHR) { | ||
| 812 | has_immediate = true; | ||
| 813 | break; | ||
| 814 | } | ||
| 815 | } | ||
| 816 | } | ||
| 817 | } | ||
| 818 | destroy_surface(instance_, surf, nullptr); | ||
| 819 | } | ||
| 820 | DestroyWindow(probe_hwnd); | ||
| 821 | return has_immediate; | ||
| 822 | } | ||
| 823 | |||
| 789 | std::atomic<ULONG> refs_{1}; | 824 | std::atomic<ULONG> refs_{1}; |
| 790 | leonida::VulkanContext& context_; | 825 | leonida::VulkanContext& context_; |
| 791 | PFN_vkGetInstanceProcAddr gipa_; | 826 | PFN_vkGetInstanceProcAddr gipa_; |
| @@ -795,6 +830,8 @@ private: | |||
| 795 | VkQueue queue_; | 830 | VkQueue queue_; |
| 796 | std::uint32_t queue_family_; | 831 | std::uint32_t queue_family_; |
| 797 | HWND assoc_hwnd_ = nullptr; | 832 | HWND assoc_hwnd_ = nullptr; |
| 833 | mutable std::once_flag tearing_once_; | ||
| 834 | bool tearing_supported_ = false; | ||
| 798 | }; | 835 | }; |
| 799 | 836 | ||
| 800 | } // namespace | 837 | } // namespace |