BorderlessMining icon indicating copy to clipboard operation
BorderlessMining copied to clipboard

Tracking issue: GLFW patch for improved fullscreen compatibility

Open comp500 opened this issue 2 years ago • 50 comments

I'm working on a patch to GLFW that will improve borderless fullscreen compatibility using different window flags. I've been looking into the issues with current fullscreen methods Borderless Mining (and similar mods) uses, and I hope that these changes will fix some of the issues people have with the mod currently (including #1 #2 #3 #9).

These patches will only have effect on Windows - if you're experiencing issues on other operating systems, please report them separately.

As I am rather busy currently, I have no timeline or guarantee for these changes to be implemented; but please subscribe to this issue (using the button on the right) for updates and test builds.

comp500 avatar Dec 04 '21 02:12 comp500

The GLFW replacement test 1 build is now available! Get it for Fabric 1.18: borderless-mining-2.0.0-alpha-dev.0d42a0d+1.18.jar.zip (in a zip because GitHub restricts the file type)

Since fullscreen behaviour on Windows is often affected by driver heuristics and multi-monitor quirks, I don't know how all configurations will behave with these changes. Hence, please test this build and let me know your experience! I'm curious to know if any of the following break/occur with your configuration:

  • Overlays (e.g. Xbox Game Bar, NVIDIA Share, Discord, Steam)
  • Input Method Editors (IMEs, e.g. for Chinese input)
  • Screenshots from external applications
  • Excessive tearing (worse than standard fullscreen with VSync)
  • Game minimises when you click in another monitor
  • Taskbar displays on top of the game, when the game is selected
  • Windows cannot be placed on top of the game
  • Framerate forced to VSync/display framerate when VSync is disabled (please check if this does not occur in exclusive fullscreen without VSync first)

If you encounter any issues with these builds, please test to see if you can reproduce the issues with the following changes:

  • If you have multiple graphics processors (especially with hybrid/laptop graphics) change which is used for javaw.exe and check in the F3 screen (https://www.howtogeek.com/351522/how-to-choose-which-gpu-a-game-uses-on-windows-10/)
  • If you use multiple monitors, try changing which monitor you use Minecraft on, and changing the primary monitor
  • Test with other OpenGL games/applications (https://www.pcgamingwiki.com/wiki/List_of_OpenGL_games - though many of these use DirectX on Windows and OpenGL on other OSes)

I ask that you do not distribute this build (and future test builds) in public modpacks; as the changes are experimental and the current build crashes on any OS other than Windows!

Source: https://github.com/comp500/BorderlessMining/commit/0d42a0d51231de4c92be684b4ac626fd9f3f73c3 Source for glfw3.dll: https://github.com/comp500/glfw/commit/08b3a9ee50f6752824826ef240f1d01db2a882ac

(cc: @cpm9 @kosma @NeusFear @ZenoMetal @fortemfiducia @juliand665)

comp500 avatar Dec 18 '21 23:12 comp500

Oh, and one more thing to note: this build completely removes all of the Borderless Mining interface, instead replacing the standard fullscreen option with borderless fullscreen! I may add some of or all the previous features back, depending on what works best for different configurations (but no guarantees).

comp500 avatar Dec 18 '21 23:12 comp500

Tested under the following setup:

  • Win10, GTX 1660S, roughly recent drivers
  • Fabric 1.18.1, heavily modded (including Sodium/Indium/Iris/Continuity)
  • Single monitor but with 125% text scaling
  • Tried Discord and Geforce overlays + Win-Shift-S screenshots at the same time

Found no issues. I wish I could compare to non-patched 1.18.1 so I could look for the tearing a bit harder

I will use my friends as guinea pigs for testing this - private modpack, ca. 10-15 users.

PS. I love the removal of GUI, and just flat out replacing the fullscreen functionality - minimalistic but fully functional (and also I think playing nicely with the Video Settings GUI modifications done by Sodium).

kosma avatar Dec 19 '21 16:12 kosma

Just discovered this mod today, looking for a solution to the curious fact that my FPS drops dramatically with the vanilla true fullscreen enabled.

The current stable release kept my FPS stable in borderless fullscreen mode, but caused significant screen tearing as described in #1. Looks like I stumbled across this mod and the test build at the perfect time!

Relevant specs:

  • Windows 10, build 19043
  • GeForce GTX 1060 6GB, driver version 456.71
  • Java 17.0.1 64bit, 2GB allocated
  • Single ultrawide display (2560x1080)
  • Fabric 1.18, client modded (Sodium, Phosphor, Lithium, Iris, BSL shaders)
  • VSync enabled, render distance 8-12

Things I've noticed:

  • No drop in FPS compared to bordered windowed mode (same as current stable release)
  • Windows screenshot and gamebar overlays work well
  • No excessive tearing (if any at all), as opposed to the current stable release where it is abundant
  • Game does not minimize when taskbar is selected - as expected
  • Taskbar does not display on top of the game, when the game is selected - as expected
  • Windows can be placed on top of the game - as expected

Awesome work! I haven't been able to play in ultrawide fullscreen without sacrificing some visual component (render distance, shaders, etc) in some time, and I'm hyped to longer have to make a choice. :)

Arcensoth avatar Dec 19 '21 20:12 Arcensoth

Did extra testing:

  • MSI Afterburner overlay - works
  • Multi-monitor - works
  • SEUS shaders - works
  • No noticeable performance difference with and without the mod

kosma avatar Dec 20 '21 18:12 kosma

Side note, probably obvious - crashes on macOS because it can't locate the DLL file.

kosma avatar Dec 27 '21 20:12 kosma

I have had no issues previously with borderless mining. Here I will compare fullscreen exclusive and this test of Borderless Mining on 1.18.1.

Relevant specs & info:

  • Windows 10 21H2 (OS Build 19044.1288)
  • NVIDIA GeForce GTX 970 - 497.29 DCH (installed with NVCleanstall)
  • GraalVM Community Edition 17 - 21.3.0 - Java Arguments (some are added by MultiMC)
  • MultiMC development branch - 0.6.14-develop-3122
  • Two monitors - 240hz and 75hz (both 1080p)
  • Fabric 1.18.1 - Mods list
  • V-Sync disabled in-game, render distance 8 and simulation distance 6
  • CapFrameX used to benchmark
  • Windows Game Mode is on
  • Shaders turned off

Benchmarking Results

In each benchmark, I opened a world and walked 25 blocks to the exact same point and then waited for the capture to end in CapFrameX (20 seconds). I did each benchmark fairly and started and stopped at the same place each time. image

Averages (mean)

Fullscreen Exclusive (FSE)
  • Average FPS: 681.5 FPS
  • 1% percentile FPS: 335.366666667 FPS
  • 0.1% percentile FPS: 245.533333333 FPS
  • Score (adding them all up): 1262.4
Borderless Mining (BM)
  • Average FPS: 583.3 FPS
  • 1% percentile FPS: 312.7 FPS
  • 0.1% percentile FPS: 236.966666667 FPS
  • Score (adding them all up): 1132.96666667

Things I've noticed:

  • ShareX screenshot previews work (in the bottom right corner), so overlays work
  • I do not notice any tearing, even if V-Sync is disabled everywhere
  • Game does not minimize when the taskbar or another application is clicked/focused - as expected
  • Taskbar does not display on top of the game, when the game is selected - as expected
  • Windows can be placed on top of the game - as expected

he3als avatar Jan 04 '22 20:01 he3als

Thank you soooo much for producing this version. I've tested this now for several hours without any issues 🥰 My setup is as follows:

RTX 2070 Super (511.23 drivers) Windows 10 Pro 64-bit (21H2 - build 19044.1348) Ryzen 7 5800X Fabric loader (installer version 0.10.2) Minecraft 1.18.1

I have not done any benchmarks, but I've noticed no noticeable slowdown between this mode and regular windowed mode.

SleepyCatten avatar Jan 18 '22 11:01 SleepyCatten

This fixed my tearing issues. My setup:

Minecraft 1.18.1 with sodium, lithium, and etc optimization mods 2 monitors with Minecraft being on the main monitor, no UI scaling GeForce GTX 1060 6GB Intel Core i5-4570 @3.20GHz Windows 10 Pro 64-bit (10.0, build 18362)

Havent noticed any big change in performance. Win+Shift+S captures things fine

Azim avatar Feb 26 '22 09:02 Azim

@Azim That looks like a driver crash in texture uploading (deleted your comment as the game arguments contain your authentication token), not something related to Borderless Mining? I can't seem to replicate the crash on my NVIDIA GPU, it may be a driver issue or a problem with the other mods you're using.

comp500 avatar Mar 06 '22 13:03 comp500

Try re-installing/updating your graphics card drivers.

he3als avatar Mar 06 '22 18:03 he3als

@Azim That looks like a driver crash in texture uploading (deleted your comment as the game arguments contain your authentication token), not something related to Borderless Mining? I can't seem to replicate the crash on my NVIDIA GPU, it may be a driver issue or a problem with the other mods you're using.

just tried updating graphics driver, but confirmed that the game doesnt crash when i remove the Borderless Mining mod upd: even with updated driver it still crashes when mod is installed

Azim avatar Mar 06 '22 18:03 Azim

Does the same crash still occur with only Borderless Mining installed? I'm really not sure what would cause this, it could be a conflict with another mod.

comp500 avatar Mar 06 '22 19:03 comp500

Seems to be conflicting with this one: https://www.curseforge.com/minecraft/mc-mods/distant-horizons/files/3651470

now instead of crash log, it gives me this message: image

Azim avatar Mar 07 '22 10:03 Azim

I tested the experimental version 2.0.0, everything works perfectly for me. But one of my friends (Windows 10) has a problem – OBS can't detect the game window in fullscreen mode during his streams (or simply can't capture the video, I don't know more precisely). It is noteworthy that the old version (1.1.2) did not show this problem.

@comp500, what additional information might you need? I will try to get the log and crash report and send it here.

Felix14-v2 avatar Apr 23 '22 16:04 Felix14-v2

The main thing I need to know is what graphics drivers they're using (Intel/AMD/NVIDIA, hybrid/laptop graphics?); and if it still occurs using Minecraft's fullscreen option? https://github.com/comp500/BorderlessMining/issues/19#issuecomment-997300168 also has a good list of things to test.

comp500 avatar Apr 23 '22 19:04 comp500

what graphics drivers they're using

Nvidia, RTX 2070 if i'm not mistaken. Other things are good (at least, no other problems were noticed). Vanilla's fullscreen was also broken after the graphics driver update, but Borderless Mining 1.1.2 fixes this.

Felix14-v2 avatar Apr 23 '22 19:04 Felix14-v2

I don't think there is anything I can do about that; they could try using a different source (Game Capture or Window Capture?) or a different capture method in Window/Display capture. I'm curious to see if this behaviour is specific to OpenGL applications though, does the same happen with a DirectX (ideally DirectX 11/12) application in Borderless Windowed mode?

comp500 avatar Apr 24 '22 17:04 comp500

I just noticed that it is no longer possible to minimize the game window properly using the keyboard shortcut (Win+D in my case). The window minimizes, but when focusing on any other window, it immediately expands again, sometimes the taskbar disappears: [Demo] After several tests, the game window generally began to behave in an unexpected way: [Demo]

This may be the result of a recent Windows update. If so, I wouldn’t be surprised at all, because there has never been a time that it didn’t break something.

latest.log crash-2022-04-30_01.25.03-client.txt

Tested it without other mods, the result was the same.

Felix14-v2 avatar Apr 29 '22 22:04 Felix14-v2

Tested this mod on an AMD card. AMD drivers have significant issues with Minecraft without this mod for some reason. In exclusive fullscreen screen tearing is absolutely atrocious. VSync fixes this, but then you get random unexplainable FPS drops during gameplay.

With this mod installed, the game runs properly in bordered fullscreen, you can alt tab and use other windows over the game just fine. The FPS drops when using VSync are gone; the game runs consistently smooth when it is on. With VSync off, however, the excessive screen tearing is still there.

Minecraft 1.18.2, RX 580, driver version 22.5.2, Windows 10 64 bit, single monitor.

pajicadvance avatar May 27 '22 00:05 pajicadvance

Any chance of merging this change into the official 1.18.2 version and any subsequent ones (i.e., 1.19 onwards)?

SleepyCatten avatar Jun 05 '22 13:06 SleepyCatten

Apologies for not mentioning it here, but I noticed similar problems to @pajicadvance on an AMD system; however I tested the same exact window flags and coordinates with a DirectX surface and it fixes the issue, so I've been looking into working around it with DirectX-OpenGL interop - sharing the DirectX backbuffer with OpenGL and writing directly to it, then presenting the frame from DirectX. I have some working prototype code, but it needs a decent amount of cleanup and performance testing.

I currently don't have access to an AMD system and am rather busy with other projects, so it may be a few weeks before I can get it finished and into a release, but it would be great to have this issue fixed for all systems. There's also potential for performance improvements with the DXGI swapchain as it gives more control than OpenGL, specifically with waitable objects and triple buffering. I also want to push some of these fixes into something I can upstream to GLFW, though it shouldn't block the mod release.

comp500 avatar Jun 05 '22 21:06 comp500

Apologies for not mentioning it here, but I noticed similar problems to @pajicadvance on an AMD system; however I tested the same exact window flags and coordinates with a DirectX surface and it fixes the issue, so I've been looking into working around it with DirectX-OpenGL interop - sharing the DirectX backbuffer with OpenGL and writing directly to it, then presenting the frame from DirectX. I have some working prototype code, but it needs a decent amount of cleanup and performance testing.

I currently don't have access to an AMD system and am rather busy with other projects, so it may be a few weeks before I can get it finished and into a release, but it would be great to have this issue fixed for all systems. There's also potential for performance improvements with the DXGI swapchain as it gives more control than OpenGL, specifically with waitable objects and triple buffering. I also want to push some of these fixes into something I can upstream to GLFW, though it shouldn't block the mod release.

Thank you 🥰

SleepyCatten avatar Jun 06 '22 09:06 SleepyCatten

The GLFW replacement test 1 build is now available! Get it for Fabric 1.18: borderless-mining-2.0.0-alpha-dev.0d42a0d+1.18.jar.zip (in a zip because GitHub restricts the file type)

Since fullscreen behaviour on Windows is often affected by driver heuristics and multi-monitor quirks, I don't know how all configurations will behave with these changes. Hence, please test this build and let me know your experience! I'm curious to know if any of the following break/occur with your configuration:

  • Overlays (e.g. Xbox Game Bar, NVIDIA Share, Discord, Steam)
  • Input Method Editors (IMEs, e.g. for Chinese input)
  • Screenshots from external applications
  • Excessive tearing (worse than standard fullscreen with VSync)
  • Game minimises when you click in another monitor
  • Taskbar displays on top of the game, when the game is selected
  • Windows cannot be placed on top of the game
  • Framerate forced to VSync/display framerate when VSync is disabled (please check if this does not occur in exclusive fullscreen without VSync first)

If you encounter any issues with these builds, please test to see if you can reproduce the issues with the following changes:

  • If you have multiple graphics processors (especially with hybrid/laptop graphics) change which is used for javaw.exe and check in the F3 screen (https://www.howtogeek.com/351522/how-to-choose-which-gpu-a-game-uses-on-windows-10/)
  • If you use multiple monitors, try changing which monitor you use Minecraft on, and changing the primary monitor
  • Test with other OpenGL games/applications (https://www.pcgamingwiki.com/wiki/List_of_OpenGL_games - though many of these use DirectX on Windows and OpenGL on other OSes)

I ask that you do not distribute this build (and future test builds) in public modpacks; as the changes are experimental and the current build crashes on any OS other than Windows!

Source: 0d42a0d Source for glfw3.dll: comp500/glfw@08b3a9e

(cc: @cpm9 @kosma @NeusFear @ZenoMetal @fortemfiducia @juliand665)

Will a 1.19 version of this build be available once the base mod is updated to 1.19?

TechPro424 avatar Jun 12 '22 13:06 TechPro424

Looks like the 1.19 version is out

TechPro424 avatar Jun 14 '22 14:06 TechPro424

Looks like the 1.19 version is out

Oh, I meant this to be a question to @comp500 as to whether the GLFW patch would be incorporated into the base version after it had been ported to 1.19. Apologies for my lack of clarity there, as I didn't mean to cause confusion.

SleepyCatten avatar Jun 14 '22 14:06 SleepyCatten

Some testing on Windows (NVIDIA)

The GLFW patch for Borderless Mining makes it so that fullscreen exclusive is not used when in-game, which will fix:

  • Overlays
  • Screenshotting
  • Slow alt-tabbing
  • Tearing

However, there will be significantly more input lag and worse performance as everything is passing through DWM, the compositor. With the GLFW patch, no fullscreen optimisations are applied either, as they are mostly exclusive to DirectX.

With regular Borderless Mining, legacy flip (fullscreen exclusive) is used whilst in-game and when you unfocus the game, everything is passed through DWM and it actually switches to a borderless window. This is the reason for the flicker when alt-tabbing.

More info about presentation modes (fullscreen optimisations, exclusive, etc...): https://wiki.special-k.info/SwapChain

How to test which presentation mode is being used

  1. Get PresentMon, I would recommend getting it with Scoop
  2. Open Command Prompt on your second monitor (if you do not have another monitor, record it to an .csv and look that later), run PresentMon with -no_csv
  3. You can now see the presentation mode being used, press Ctrl + C to stop PresentMon. image

he3als avatar Oct 12 '22 21:10 he3als

Note that the DirectX interop technique I mentioned in https://github.com/comp500/BorderlessMining/issues/19#issuecomment-1146883582 (currently still working on it; have made good progress, will release a test build soon) should provide the best of both "fullscreen exclusive" and "windowed" (composited) modes on Windows 10 and newer - where it can use the Independent Flip presentation mode for effectively zero-overhead borderless fullscreen in the best case, and degrades much more gracefully when compositing is required.

This isn't the same as "fullscreen optimisations" per se; that term specifically means where Windows will force DirectX games that use exclusive fullscreen to use a borderless window with a best-effort presentation mode (ideally true immediate Independent Flip). A lot of the terms are muddy, especially for OpenGL where there is no real concept of exclusive fullscreen (but drivers will use heuristics to force bypassing of the compositor - similar effects, but the application has no control over it) and the Windows documentation does not specify how OpenGL framebuffers are composited, or under what circumstances they should be composited or have exclusive access. As far as I know OpenGL on current Windows 10/11 drivers cannot use the enhanced (directflip / independent flip) presentation modes; hence DirectX interop provides significant benefit over any borderless window technique using OpenGL to present the frame.

comp500 avatar Oct 13 '22 02:10 comp500

I've updated the GLFW replacement test to 1.19.2: borderless-mining-2.0.0-alpha.2-dev.b9c3c6c+1.19.2.jar.zip (in a zip because GitHub restricts the file type) Now includes a patch for custom driver-added screen resolutions (see #26 and commit https://github.com/comp500/glfw/commit/2b259010beab6b607d5f957ee4190ab7b45d12d7)

Source: https://github.com/comp500/BorderlessMining/commit/b9c3c6c86da75d3e6fe4e44f77d40b7e0ecfaa41 Source for glfw3.dll: https://github.com/comp500/glfw/commit/2b259010beab6b607d5f957ee4190ab7b45d12d7

comp500 avatar Oct 20 '22 17:10 comp500

GLFW replacement test to 1.19.2

Works fine for me, except for crashes with Better Taskbar installed latest.log crash-2022-10-20_23.51.22-client.txt

Felix14-v2 avatar Oct 20 '22 20:10 Felix14-v2