@@ -100,6 +100,12 @@ static VkDevice _fifoLatestReadyDevice = VK_NULL_HANDLE;
100100// The game's swapchain, its presents ask the game to recreate it when the present mode override changes
101101static VkSwapchainKHR _gameSwapchain = VK_NULL_HANDLE ;
102102
103+ // Present mode override for the swapchains dxvk/vkd3d-proton create for D3D games under Proton
104+ static VkPhysicalDevice _dxgiPD = VK_NULL_HANDLE ;
105+ static VkSwapchainKHR _dxgiSwapchain = VK_NULL_HANDLE ;
106+ static VkPresentModeKHR _dxgiForcedMode = VK_PRESENT_MODE_MAX_ENUM_KHR ;
107+ static VkPresentModeKHR _dxgiForcedModes[8 ] {};
108+
103109// Set while the FG output handles a swapchain call
104110static thread_local bool _inFGCall = false ;
105111
@@ -810,6 +816,11 @@ static VkResult hkvkCreateDevice(VkPhysicalDevice physicalDevice, const VkDevice
810816 LOG_DEBUG (" _device captured: {0:X}" , (UINT64 ) _device);
811817 MenuOverlayVk::DeviceCreated (_device, &localCreateInfo);
812818 }
819+ else
820+ {
821+ // The D3D device's physical device, for the present mode override of its swapchain
822+ _dxgiPD = physicalDevice;
823+ }
813824 }
814825
815826 ScopedSkipSpoofingGlobal skipSpoofingGlobal {};
@@ -973,6 +984,31 @@ static VkResult hkvkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPres
973984 fg->Present ();
974985 }
975986
987+ // dxvk/vkd3d-proton switch present modes per present (VK_EXT_swapchain_maintenance1), keep the forced one
988+ VkSwapchainPresentModeInfoEXT* dxgiModeInfo = nullptr ;
989+ const VkPresentModeKHR* dxgiModesOld = nullptr ;
990+ if (dxgiBacked && _dxgiForcedMode != VK_PRESENT_MODE_MAX_ENUM_KHR )
991+ {
992+ for (auto next = (VkBaseOutStructure*) localPresentInfo.pNext ; next != nullptr ; next = next->pNext )
993+ {
994+ if (next->sType != VK_STRUCTURE_TYPE_SWAPCHAIN_PRESENT_MODE_INFO_EXT )
995+ continue ;
996+
997+ auto info = (VkSwapchainPresentModeInfoEXT*) next;
998+ if (info->swapchainCount > std::size (_dxgiForcedModes) || info->pPresentModes == nullptr )
999+ break ;
1000+
1001+ for (uint32_t i = 0 ; i < info->swapchainCount ; i++)
1002+ _dxgiForcedModes[i] =
1003+ localPresentInfo.pSwapchains [i] == _dxgiSwapchain ? _dxgiForcedMode : info->pPresentModes [i];
1004+
1005+ dxgiModeInfo = info;
1006+ dxgiModesOld = info->pPresentModes ;
1007+ info->pPresentModes = _dxgiForcedModes;
1008+ break ;
1009+ }
1010+ }
1011+
9761012 // original call
9771013 ScopedVulkanCreatingSC scopedVulkanCreatingSC {};
9781014 VkResult result;
@@ -987,6 +1023,9 @@ static VkResult hkvkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPres
9871023 result = o_QueuePresentKHR (queue, &localPresentInfo);
9881024 }
9891025
1026+ if (dxgiModeInfo != nullptr )
1027+ dxgiModeInfo->pPresentModes = dxgiModesOld;
1028+
9901029 // dxvk/vkd3d-proton's are counted by the DXGI swapchain
9911030 if (!dxgiBacked)
9921031 DeferredRelease::Process ();
@@ -1005,6 +1044,15 @@ static VkResult hkvkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPres
10051044 result = VK_SUBOPTIMAL_KHR ;
10061045 }
10071046
1047+ // Same for dxvk/vkd3d-proton, they recreate their swapchain on suboptimal
1048+ if (State::Instance ().vkPresentModeChanged && result == VK_SUCCESS && dxgiBacked &&
1049+ _dxgiSwapchain != VK_NULL_HANDLE &&
1050+ std::find (localPresentInfo.pSwapchains , localPresentInfo.pSwapchains + localPresentInfo.swapchainCount ,
1051+ _dxgiSwapchain) != localPresentInfo.pSwapchains + localPresentInfo.swapchainCount )
1052+ {
1053+ result = VK_SUBOPTIMAL_KHR ;
1054+ }
1055+
10081056 LOG_FUNC_RESULT (result);
10091057 return result;
10101058}
@@ -1060,19 +1108,28 @@ static VkResult hkvkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateI
10601108 }
10611109 }
10621110
1063- // Present mode override, the FG outputs create their swapchains from this create info too
1064- if (pCreateInfo != nullptr && !State::Instance ().vulkanSkipHooks && !dxgiBacked && _PD != VK_NULL_HANDLE )
1111+ // Present mode override, the FG outputs create their swapchains from this create info too. dxvk/vkd3d-proton's
1112+ // (D3D games under Proton) use the D3D device's physical device
1113+ const VkPhysicalDevice modePD = dxgiBacked ? _dxgiPD : _PD;
1114+ VkSwapchainPresentModesCreateInfoEXT* dxgiModeList = nullptr ;
1115+ uint32_t dxgiModeListCount = 0 ;
1116+ const VkPresentModeKHR* dxgiModeListModes = nullptr ;
1117+ static VkPresentModeKHR dxgiListMode = VK_PRESENT_MODE_FIFO_KHR ;
1118+ if (dxgiBacked)
1119+ _dxgiForcedMode = VK_PRESENT_MODE_MAX_ENUM_KHR ;
1120+
1121+ if (pCreateInfo != nullptr && !State::Instance ().vulkanSkipHooks && modePD != VK_NULL_HANDLE )
10651122 {
10661123 auto & state = State::Instance ();
10671124 state.vkGamePresentMode = pCreateInfo->presentMode ;
10681125
10691126 uint32_t count = 0 ;
10701127 std::vector<VkPresentModeKHR> supported;
10711128
1072- if (vkGetPhysicalDeviceSurfacePresentModesKHR (_PD , pCreateInfo->surface , &count, nullptr ) == VK_SUCCESS )
1129+ if (vkGetPhysicalDeviceSurfacePresentModesKHR (modePD , pCreateInfo->surface , &count, nullptr ) == VK_SUCCESS )
10731130 {
10741131 supported.resize (count);
1075- vkGetPhysicalDeviceSurfacePresentModesKHR (_PD , pCreateInfo->surface , &count, supported.data ());
1132+ vkGetPhysicalDeviceSurfacePresentModesKHR (modePD , pCreateInfo->surface , &count, supported.data ());
10761133 supported.resize (count);
10771134 }
10781135
@@ -1096,7 +1153,7 @@ static VkResult hkvkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateI
10961153 for (auto next = (const VkBaseInStructure*) pCreateInfo->pNext ; next != nullptr ; next = next->pNext )
10971154 gameModeList |= next->sType == VK_STRUCTURE_TYPE_SWAPCHAIN_PRESENT_MODES_CREATE_INFO_EXT ;
10981155
1099- if (const auto & mode = Config::Instance ()->VulkanPresentMode ; mode.has_value () && !gameModeList)
1156+ if (const auto & mode = Config::Instance ()->VulkanPresentMode ; mode.has_value () && ( !gameModeList || dxgiBacked) )
11001157 {
11011158 const auto entry = std::ranges::find (VulkanHooks::PresentModes, (VkPresentModeKHR) mode.value (),
11021159 &VulkanHooks::PresentModeEntry::mode);
@@ -1113,6 +1170,26 @@ static VkResult hkvkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateI
11131170 }
11141171
11151172 localCreateInfo.presentMode = entry->mode ;
1173+
1174+ if (dxgiBacked)
1175+ {
1176+ _dxgiForcedMode = entry->mode ;
1177+
1178+ // dxvk/vkd3d-proton's present mode list becomes the forced mode only, restored after the call
1179+ for (auto next = (VkBaseOutStructure*) pCreateInfo->pNext ; next != nullptr ; next = next->pNext )
1180+ {
1181+ if (next->sType != VK_STRUCTURE_TYPE_SWAPCHAIN_PRESENT_MODES_CREATE_INFO_EXT )
1182+ continue ;
1183+
1184+ dxgiModeList = (VkSwapchainPresentModesCreateInfoEXT*) next;
1185+ dxgiModeListCount = dxgiModeList->presentModeCount ;
1186+ dxgiModeListModes = dxgiModeList->pPresentModes ;
1187+ dxgiListMode = entry->mode ;
1188+ dxgiModeList->presentModeCount = 1 ;
1189+ dxgiModeList->pPresentModes = &dxgiListMode;
1190+ break ;
1191+ }
1192+ }
11161193 }
11171194 else
11181195 {
@@ -1189,6 +1266,19 @@ static VkResult hkvkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateI
11891266 if (result == VK_SUCCESS && lowLatencySwapchain)
11901267 VulkanHooks::SetLowLatencySwapchain (*pSwapchain);
11911268
1269+ if (dxgiModeList != nullptr )
1270+ {
1271+ dxgiModeList->presentModeCount = dxgiModeListCount;
1272+ dxgiModeList->pPresentModes = dxgiModeListModes;
1273+ }
1274+
1275+ if (result == VK_SUCCESS && dxgiBacked && pSwapchain != nullptr && *pSwapchain != VK_NULL_HANDLE &&
1276+ !State::Instance ().vulkanSkipHooks )
1277+ {
1278+ _dxgiSwapchain = *pSwapchain;
1279+ State::Instance ().vkPresentModeChanged = false ;
1280+ }
1281+
11921282 if (result == VK_SUCCESS && device != VK_NULL_HANDLE && pCreateInfo != nullptr && *pSwapchain != VK_NULL_HANDLE &&
11931283 !State::Instance ().vulkanSkipHooks && !dxgiBacked)
11941284 {
0 commit comments