phr00t / FocusEngine

Focus Game Engine. This is Stride/Xenko fast-tracked for Phr00t's Software games. Improvements over the original Focus on Vulkan support, PC platforms, VR, performance & ease. Cherry-picks commits from other forks as needed.
MIT License
97 stars 11 forks source link

Can't resize or change fullscreen mode in Vulkan while running #70

Open phr00t opened 5 years ago

phr00t commented 5 years ago

I tried my best, but I couldn't get stable resizing or fullscreen switching during game run. Tons of system violation access exceptions.

Going to focus on performance and general stability outside of changing display modes during runtime.

I will make it easy to change and set startup resolution settings, though!

phr00t commented 5 years ago

Cleaned up Vulkan system after accepting this "wontfix" fate: https://github.com/phr00t/xenko/commit/512e62a39e1b6bed3361dbbb23e0a9bbbe798f39

phr00t commented 5 years ago

If anyone wants to try and take this up and fix this, be my guest... I just need to focus on a smaller (and more common) subset of Vulkan use cases

phr00t commented 5 years ago

Gave a brain dump on this issue in Discord, pasting here:

https://github.com/phr00t/xenko/blob/master/sources/engine/Xenko.Graphics/Vulkan/SwapChainGraphicsPresenter.Vulkan.cs#L104

that is the line where resizing is suppose to happen if you resize the window, or change fullscreen, the result is OutOfDate and it is suppose to recreate the swap chain currently I have it not present when minimized or alt+tabbing out of fullscreen, so it never gets OutOfDate and doesn't need to recreate swap chains which works pretty well, since you don't need to present anyway in those situations i've tried setting a flag on calls to ResizeBackBuffer to force a CreateSwapChain call when later getting into present (so it always tries recreating the swap chain at that point, to make it easier to control when everything happens) usually a Vulkan "ErrorDeviceLost" ends up happening somewhere down the road after a recreate, which is hard to track down... using game.GraphicsDeviceManager.DeviceCreationFlags |= Debug enables Vulkan validation layers, and will print errors to the Immediate window in visual studio but there are lots of "errors" that cause the app to crash before getting to resizing, although those "errors" don't cause any symptoms when the game is running without validation errors ultimately i gave up, since Unity works fine for devs and gamers not resizing after the game starts, and went to work on other areas of the engine but that is my brain dump in case you decide to take it on

herocrab commented 3 years ago

Was this issue ever fixed? I am seeing something similar with Stride.

phr00t commented 3 years ago

@herocrab this wasn't fixed, but I did implement a very acceptable workaround. Basically, when you resize the window while the game is running, Vulkan reports VK_ERROR_OUT_OF_DATE_KHR when the resize or fullscreen change happens during presentation, which then requires a "swap chain recreation":

https://vulkan-tutorial.com/Drawing_a_triangle/Swap_chain_recreation#page_Suboptimal-or-out-of-date-swap-chain

... this process involves destroying and recreating a bunch of things, and Stride / Xenko just explodes as it wasn't designed for all of this recreation. I worked pretty hard at trying to get the recreation to work, but it was painful and unreliable. Many very popular games get away with asking the player to restart the game when changing resolution and fullscreen modes, so I accepted that limitation and designed a bunch of simple functions around making changes that are applied on restart. This has worked very well with FPS Infinite (hence me labeling this issue "wontfix").

herocrab commented 3 years ago

Thanks for the reply. Are you just hacking a yaml file then for the work around?

phr00t commented 3 years ago

Nothing with YAML, just an easy text file to make it easy for people to manually change outside of the game. The beef of handling this text file to get and set graphics settings starts here:

https://github.com/phr00t/FocusEngine/blob/master/sources/engine/Xenko.Games/GameBase.cs#L452

It needs to do a bunch of checking, because that "Error Out of Date" Vulkan thing can happen in a bunch of scenarios, like requesting a resolution higher than native resolution or if Windows 10 users have display scaling turned on. Some of this checking happens in my SDL Window source files.