diff --git a/Common/GPU/Vulkan/VulkanContext.cpp b/Common/GPU/Vulkan/VulkanContext.cpp index 9b384731eb..ca83bf9739 100644 --- a/Common/GPU/Vulkan/VulkanContext.cpp +++ b/Common/GPU/Vulkan/VulkanContext.cpp @@ -670,7 +670,9 @@ VkResult VulkanContext::CreateDevice(int physical_device) { } extensionsLookup_.EXT_provoking_vertex = EnableDeviceExtension(VK_EXT_PROVOKING_VERTEX_EXTENSION_NAME, 0); - +#ifdef VK_EXT_full_screen_exclusive + extensionsLookup_.EXT_full_screen_exclusive = EnableDeviceExtension(VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME, 0); +#endif extensionsLookup_.KHR_present_mode_fifo_latest_ready = EnableDeviceExtension(VK_KHR_PRESENT_MODE_FIFO_LATEST_READY_EXTENSION_NAME, 0); if (!extensionsLookup_.KHR_present_mode_fifo_latest_ready) { // Enable the EXT extension instead if available, it's equivalent (was promoted). @@ -1530,6 +1532,19 @@ bool VulkanContext::InitSwapchain(VkPresentModeKHR desiredPresentMode) { swap_chain_info.compositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR; } +#ifdef VK_EXT_full_screen_exclusive + VkSurfaceFullScreenExclusiveInfoEXT fullScreenInfo{ VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_INFO_EXT }; + VkSurfaceFullScreenExclusiveWin32InfoEXT win32ExclusiveInfo{ VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_WIN32_INFO_EXT }; + if (extensionsLookup_.EXT_full_screen_exclusive) { + fullScreenInfo.fullScreenExclusive = fullScreenExclusiveMode_; + if (fullScreenExclusiveMode_ == VK_FULL_SCREEN_EXCLUSIVE_ALLOWED_EXT) { + win32ExclusiveInfo.hmonitor = MonitorFromWindow((HWND)winsysData2_, MONITOR_DEFAULTTONEAREST); + fullScreenInfo.pNext = &win32ExclusiveInfo; + } + swap_chain_info.pNext = &fullScreenInfo; + } +#endif + res = vkCreateSwapchainKHR(device_, &swap_chain_info, NULL, &swapchain_); if (res != VK_SUCCESS) { ERROR_LOG(Log::G3D, "vkCreateSwapchainKHR failed! %s", VulkanResultToString(res)); diff --git a/Common/GPU/Vulkan/VulkanContext.h b/Common/GPU/Vulkan/VulkanContext.h index 6df3e67864..30d5c1053d 100644 --- a/Common/GPU/Vulkan/VulkanContext.h +++ b/Common/GPU/Vulkan/VulkanContext.h @@ -412,6 +412,10 @@ public: return presentMode_; } +#ifdef VK_EXT_full_screen_exclusive + void SetFullScreenExclusiveMode(VkFullScreenExclusiveEXT mode) { fullScreenExclusiveMode_ = mode; } +#endif + std::vector GetAvailablePresentModes() const { return availablePresentModes_; } @@ -530,6 +534,11 @@ private: PhysicalDeviceFeatures deviceFeatures_; +#ifdef VK_EXT_full_screen_exclusive + VkFullScreenExclusiveEXT fullScreenExclusiveMode_ = VK_FULL_SCREEN_EXCLUSIVE_DEFAULT_EXT; +#endif + + VkSurfaceCapabilitiesKHR surfCapabilities_{}; std::vector surfFormats_{}; diff --git a/Common/GPU/Vulkan/VulkanLoader.h b/Common/GPU/Vulkan/VulkanLoader.h index 132e096403..5c571cf48d 100644 --- a/Common/GPU/Vulkan/VulkanLoader.h +++ b/Common/GPU/Vulkan/VulkanLoader.h @@ -272,6 +272,7 @@ struct VulkanExtensions { bool EXT_provoking_vertex; bool KHR_present_mode_fifo_latest_ready; bool EXT_scalar_block_layout; + bool EXT_full_screen_exclusive; // bool EXT_depth_range_unrestricted; // Allows depth outside [0.0, 1.0] in 32-bit float depth buffers. }; diff --git a/Common/GPU/Vulkan/thin3d_vulkan.cpp b/Common/GPU/Vulkan/thin3d_vulkan.cpp index 6278e82043..b5cd55bfd2 100644 --- a/Common/GPU/Vulkan/thin3d_vulkan.cpp +++ b/Common/GPU/Vulkan/thin3d_vulkan.cpp @@ -953,6 +953,7 @@ VKContext::VKContext(VulkanContext *vulkan, bool useRenderThread) // Note that it must also be enabled on the pipelines (which we do). caps_.provokingVertexLast = vulkan->GetDeviceFeatures().enabled.provokingVertex.provokingVertexLast; + caps_.fullScreenExclusiveSupported = vulkan->Extensions().EXT_full_screen_exclusive; // Present mode stuff caps_.presentMaxInterval = 1; caps_.presentInstantModeChange = false; // TODO: Fix this with some work in VulkanContext diff --git a/Common/GPU/thin3d.h b/Common/GPU/thin3d.h index f99673d5cb..b5d8019abf 100644 --- a/Common/GPU/thin3d.h +++ b/Common/GPU/thin3d.h @@ -633,6 +633,7 @@ struct DeviceCaps { bool requiresHalfPixelOffset; bool provokingVertexLast; // GL behavior, what the PSP does bool verySlowShaderCompiler; + bool fullScreenExclusiveSupported; // Old style, for older GL or Direct3D 9. u32 clipPlanesSupported; diff --git a/Core/Config.cpp b/Core/Config.cpp index 8114467109..ce1db82671 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -748,6 +748,7 @@ static const ConfigSetting graphicsSettings[] = { #ifndef MOBILE_DEVICE ConfigSetting("FullScreen", SETTING(g_Config, bFullScreen), false, CfgFlag::DEFAULT), + ConfigSetting("FullScreenExclusive", SETTING(g_Config, bAllowFullScreenExclusive), false, CfgFlag::DEFAULT), ConfigSetting("FullScreenMulti", SETTING(g_Config, bFullScreenMulti), false, CfgFlag::DEFAULT), #endif diff --git a/Core/Config.h b/Core/Config.h index 08648c2d5f..0d5362737f 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -325,6 +325,7 @@ public: int iAppSwitchMode; bool bFullScreen; bool bFullScreenMulti; + bool bAllowFullScreenExclusive; int iInternalResolution; // 0 = Auto (native), 1 = 1x (480x272), 2 = 2x, 3 = 3x, 4 = 4x and so on. int iAnisotropyLevel; // 0 - 5, powers of 2: 0 = 1x = no aniso int iMultiSampleLevel; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index bfae4e00dd..94dcd2a1fe 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -412,10 +412,22 @@ void GameSettingsScreen::CreateGraphicsSettings(UI::ViewGroup *graphicsSettings) fullscreenCheckbox->OnClick.Add([](UI::EventParams &e) { System_ApplyFullscreenState(); }); + if (draw->GetDeviceCaps().fullScreenExclusiveSupported) { + CheckBox* fullscreenExclusive = graphicsSettings->Add(new CheckBox(&g_Config.bAllowFullScreenExclusive, gr->T("Allow exclusive fullscreen"))); + fullscreenExclusive->SetEnabledFunc([] { + return g_Config.bFullScreen && !g_Config.bFullScreenMulti; + }); + fullscreenExclusive->OnClick.Add([this](UI::EventParams &e) { + TriggerRestartOrDo([this]() { + g_Config.bAllowFullScreenExclusive = !g_Config.bAllowFullScreenExclusive; + RecreateViews(); + }); + }); + } if (System_GetPropertyInt(SYSPROP_DISPLAY_COUNT) > 1) { CheckBox *fullscreenMulti = graphicsSettings->Add(new CheckBox(&g_Config.bFullScreenMulti, gr->T("Use all displays"))); fullscreenMulti->SetEnabledFunc([] { - return g_Config.bFullScreen; + return g_Config.bFullScreen && !g_Config.bAllowFullScreenExclusive; }); fullscreenMulti->OnClick.Add([](UI::EventParams &e) { System_ApplyFullscreenState(); diff --git a/Windows/GPU/WindowsVulkanContext.cpp b/Windows/GPU/WindowsVulkanContext.cpp index 243f210345..74485e80db 100644 --- a/Windows/GPU/WindowsVulkanContext.cpp +++ b/Windows/GPU/WindowsVulkanContext.cpp @@ -126,6 +126,13 @@ bool WindowsVulkanContext::Init(HINSTANCE hInst, HWND hWnd, std::string *error_m draw_ = Draw::T3DCreateVulkanContext(vulkan_, useMultiThreading); VkPresentModeKHR presentMode = ConfigPresentModeToVulkan(draw_); + +#ifdef VK_EXT_full_screen_exclusive + vulkan_->SetFullScreenExclusiveMode(g_Config.bFullScreen && g_Config.bAllowFullScreenExclusive + ? VK_FULL_SCREEN_EXCLUSIVE_ALLOWED_EXT + : VK_FULL_SCREEN_EXCLUSIVE_DISALLOWED_EXT); +#endif + if (!vulkan_->InitSwapchain(presentMode)) { *error_message = vulkan_->InitError(); Shutdown(); @@ -169,6 +176,13 @@ void WindowsVulkanContext::Shutdown() { void WindowsVulkanContext::Resize() { draw_->HandleEvent(Draw::Event::LOST_BACKBUFFER, vulkan_->GetBackbufferWidth(), vulkan_->GetBackbufferHeight()); VkPresentModeKHR presentMode = ConfigPresentModeToVulkan(draw_); + +#ifdef VK_EXT_full_screen_exclusive + vulkan_->SetFullScreenExclusiveMode(g_Config.bFullScreen && g_Config.bAllowFullScreenExclusive + ? VK_FULL_SCREEN_EXCLUSIVE_ALLOWED_EXT + : VK_FULL_SCREEN_EXCLUSIVE_DISALLOWED_EXT); +#endif + vulkan_->InitSwapchain(presentMode); draw_->HandleEvent(Draw::Event::GOT_BACKBUFFER, vulkan_->GetBackbufferWidth(), vulkan_->GetBackbufferHeight()); }