Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new config-only option to prevent exclusive full screen mode #9779

Merged
merged 2 commits into from Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -119,3 +119,5 @@ yaml-cpp.pc

# ssl certificate
cacert.pem

_ReSharper.*/
8 changes: 7 additions & 1 deletion rpcs3/Emu/RSX/VK/vkutils/device.cpp
Expand Up @@ -56,8 +56,9 @@ namespace vk

stencil_export_support = device_extensions.is_supported(VK_EXT_SHADER_STENCIL_EXPORT_EXTENSION_NAME);
conditional_render_support = device_extensions.is_supported(VK_EXT_CONDITIONAL_RENDERING_EXTENSION_NAME);
external_memory_host_support = device_extensions.is_supported(VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME);
external_memory_host_support = device_extensions.is_supported(VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME);
unrestricted_depth_range_support = device_extensions.is_supported(VK_EXT_DEPTH_RANGE_UNRESTRICTED_EXTENSION_NAME);
surface_capabilities_2_support = instance_extensions.is_supported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
}

void physical_device::create(VkInstance context, VkPhysicalDevice pdev, bool allow_extensions)
Expand Down Expand Up @@ -517,6 +518,11 @@ namespace vk
return pgpu->external_memory_host_support;
}

bool render_device::get_surface_capabilities_2_support() const
{
return pgpu->surface_capabilities_2_support;
}

mem_allocator_base* render_device::get_allocator() const
{
return m_allocator.get();
Expand Down
2 changes: 2 additions & 0 deletions rpcs3/Emu/RSX/VK/vkutils/device.h
Expand Up @@ -51,6 +51,7 @@ namespace vk
bool conditional_render_support = false;
bool external_memory_host_support = false;
bool unrestricted_depth_range_support = false;
bool surface_capabilities_2_support = false;

friend class render_device;
private:
Expand Down Expand Up @@ -116,6 +117,7 @@ namespace vk
bool get_conditional_render_support() const;
bool get_unrestricted_depth_range_support() const;
bool get_external_memory_host_support() const;
bool get_surface_capabilities_2_support() const;

mem_allocator_base* get_allocator() const;

Expand Down
5 changes: 5 additions & 0 deletions rpcs3/Emu/RSX/VK/vkutils/instance.hpp
Expand Up @@ -154,6 +154,11 @@ namespace vk
{
extensions.push_back(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME);
}

if (support.is_supported(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME))
{
extensions.push_back(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME);
}
#ifdef _WIN32
extensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
#elif defined(__APPLE__)
Expand Down
58 changes: 56 additions & 2 deletions rpcs3/Emu/RSX/VK/vkutils/swapchain.hpp
Expand Up @@ -586,8 +586,49 @@ namespace vk
VkSwapchainKHR old_swapchain = m_vk_swapchain;
vk::physical_device& gpu = const_cast<vk::physical_device&>(dev.gpu());

VkSurfaceCapabilitiesKHR surface_descriptors = {};
CHECK_RESULT(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu, m_surface, &surface_descriptors));
VkSurfaceCapabilities2KHR pSurfaceCapabilities = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is uncomfortably long now, I'll have to refactor it later. Seems fine otherwise.

pSurfaceCapabilities.sType = VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR;

VkPhysicalDeviceSurfaceInfo2KHR pSurfaceInfo = {};
pSurfaceInfo.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR;
pSurfaceInfo.surface = m_surface;

VkSurfaceCapabilitiesKHR surface_descriptors;
bool init_surface_descriptors = true;
#ifdef _WIN32
bool should_disable_exclusive_full_screen = false;
if (g_cfg.video.vk.force_disable_exclusive_fullscreen_mode && dev.get_surface_capabilities_2_support())
{
HMONITOR hmonitor = MonitorFromWindow(window_handle, MONITOR_DEFAULTTOPRIMARY);
if (hmonitor)
{
VkSurfaceCapabilitiesFullScreenExclusiveEXT full_screen_exclusive_capabilities = {};
VkSurfaceFullScreenExclusiveWin32InfoEXT full_screen_exclusive_win32_info = {};
full_screen_exclusive_capabilities.sType = VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_FULL_SCREEN_EXCLUSIVE_EXT;

pSurfaceCapabilities.pNext = reinterpret_cast<void*>(&full_screen_exclusive_capabilities);

full_screen_exclusive_win32_info.sType = VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_WIN32_INFO_EXT;
full_screen_exclusive_win32_info.hmonitor = hmonitor;

pSurfaceInfo.pNext = reinterpret_cast<void*>(&full_screen_exclusive_win32_info);

CHECK_RESULT(vkGetPhysicalDeviceSurfaceCapabilities2KHR(gpu, &pSurfaceInfo, &pSurfaceCapabilities));

surface_descriptors = pSurfaceCapabilities.surfaceCapabilities;
init_surface_descriptors = false;
should_disable_exclusive_full_screen = !!full_screen_exclusive_capabilities.fullScreenExclusiveSupported;
}
else
rsx_log.warning("Swapchain: failed to get monitor for the window");
}
#endif

if (init_surface_descriptors)
{
surface_descriptors = {};
CHECK_RESULT(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu, m_surface, &surface_descriptors));
}

if (surface_descriptors.maxImageExtent.width < m_width ||
surface_descriptors.maxImageExtent.height < m_height)
Expand Down Expand Up @@ -693,6 +734,19 @@ namespace vk
swap_info.imageExtent.width = std::max(m_width, surface_descriptors.minImageExtent.width);
swap_info.imageExtent.height = std::max(m_height, surface_descriptors.minImageExtent.height);

#ifdef _WIN32
VkSurfaceFullScreenExclusiveInfoEXT full_screen_exclusive_info = {};
if (should_disable_exclusive_full_screen)
{
full_screen_exclusive_info.sType = VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_INFO_EXT;
full_screen_exclusive_info.fullScreenExclusive = VK_FULL_SCREEN_EXCLUSIVE_DISALLOWED_EXT;

swap_info.pNext = reinterpret_cast<void*>(&full_screen_exclusive_info);
}

rsx_log.notice("Swapchain: requesting full screen exclusive mode %d.", static_cast<int>(full_screen_exclusive_info.fullScreenExclusive));
#endif

createSwapchainKHR(dev, &swap_info, nullptr, &m_vk_swapchain);

if (old_swapchain)
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/system_config.h
Expand Up @@ -166,6 +166,7 @@ struct cfg_root : cfg::node
cfg::string adapter{ this, "Adapter" };
cfg::_bool force_fifo{ this, "Force FIFO present mode" };
cfg::_bool force_primitive_restart{ this, "Force primitive restart flag" };
cfg::_bool force_disable_exclusive_fullscreen_mode{this, "Force Disable Exclusive Fullscreen Mode"};

} vk{ this };

Expand Down