|
1 | 1 | /* |
2 | | - * Copyright 2019-2023 Diligent Graphics LLC |
| 2 | + * Copyright 2019-2024 Diligent Graphics LLC |
3 | 3 | * Copyright 2015-2019 Egor Yusov |
4 | 4 | * |
5 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
@@ -89,23 +89,14 @@ void SwapChainVkImpl::CreateSurface() |
89 | 89 |
|
90 | 90 | err = vkCreateAndroidSurfaceKHR(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, NULL, &m_VkSurface); |
91 | 91 | } |
92 | | -#elif defined(VK_USE_PLATFORM_IOS_MVK) |
93 | | - if (m_Window.pCALayer != nullptr) |
| 92 | +#elif defined(VK_USE_PLATFORM_METAL_EXT) |
| 93 | + if (void* pLayer = m_Window.GetLayer()) |
94 | 94 | { |
95 | | - VkIOSSurfaceCreateInfoMVK surfaceCreateInfo{}; |
96 | | - surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK; |
97 | | - surfaceCreateInfo.pView = m_Window.pCALayer; |
| 95 | + VkMetalSurfaceCreateInfoEXT surfaceCreateInfo{}; |
| 96 | + surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT; |
| 97 | + surfaceCreateInfo.pLayer = pLayer; |
98 | 98 |
|
99 | | - err = vkCreateIOSSurfaceMVK(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, nullptr, &m_VkSurface); |
100 | | - } |
101 | | -#elif defined(VK_USE_PLATFORM_MACOS_MVK) |
102 | | - if (m_Window.pNSView != nullptr) |
103 | | - { |
104 | | - VkMacOSSurfaceCreateInfoMVK surfaceCreateInfo{}; |
105 | | - surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK; |
106 | | - surfaceCreateInfo.pView = m_Window.pNSView; |
107 | | - |
108 | | - err = vkCreateMacOSSurfaceMVK(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, NULL, &m_VkSurface); |
| 99 | + err = vkCreateMetalSurfaceEXT(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, NULL, &m_VkSurface); |
109 | 100 | } |
110 | 101 | #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) |
111 | 102 | if (m_Window.pDisplay != nullptr) |
@@ -765,6 +756,17 @@ void SwapChainVkImpl::Present(Uint32 SyncInterval) |
765 | 756 | m_SemaphoreIndex = m_SwapChainDesc.BufferCount - 1; // To start with 0 index when acquire next image |
766 | 757 |
|
767 | 758 | res = AcquireNextImage(pImmediateCtxVk); |
| 759 | + |
| 760 | +#if PLATFORM_APPLE |
| 761 | + // For some reason, on MoltenVk we may get VK_SUBOPTIMAL_KHR first time we |
| 762 | + // acquire the image after the swap chain has been recreated. |
| 763 | + // Recreating it yet again seems to fix the problem. |
| 764 | + if (res == VK_SUBOPTIMAL_KHR) |
| 765 | + { |
| 766 | + RecreateVulkanSwapchain(pImmediateCtxVk); |
| 767 | + res = AcquireNextImage(pImmediateCtxVk); |
| 768 | + } |
| 769 | +#endif |
768 | 770 | } |
769 | 771 | DEV_CHECK_ERR(res == VK_SUCCESS, "Failed to acquire next swap chain image"); |
770 | 772 | } |
|
0 commit comments