comp500 / BorderlessMining

A windowed borderless (fullscreen) mod for 1.15.2 and newer versions of Minecraft
https://www.curseforge.com/minecraft/mc-mods/borderless-mining
MIT License
119 stars 36 forks source link

Tracking issue: GLFW patch for improved fullscreen compatibility #19

Open comp500 opened 2 years ago

comp500 commented 2 years ago

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 commented 2 years ago

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:

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

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 commented 2 years ago

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).

kosma commented 2 years ago

Tested under the following setup:

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).

Arcensoth commented 2 years ago

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:

Things I've noticed:

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. :)

kosma commented 2 years ago

Did extra testing:

kosma commented 2 years ago

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

he3als commented 2 years ago

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:

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)
Borderless Mining (BM)

Things I've noticed:

SleepyCatten commented 2 years ago

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.

Azim commented 2 years ago

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

comp500 commented 2 years ago

@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.

he3als commented 2 years ago

Try re-installing/updating your graphics card drivers.

Azim commented 2 years ago

@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

comp500 commented 2 years ago

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.

Azim commented 2 years ago

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

Felix14-v2 commented 2 years ago

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.

comp500 commented 2 years ago

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.

Felix14-v2 commented 2 years ago

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.

comp500 commented 2 years ago

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?

Felix14-v2 commented 2 years ago

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.

pajicadvance commented 2 years ago

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.

SleepyCatten commented 2 years ago

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

comp500 commented 2 years ago

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.

SleepyCatten commented 2 years ago

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 🥰

TechPro424 commented 2 years ago

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:

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 commented 2 years ago

Looks like the 1.19 version is out

SleepyCatten commented 2 years ago

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.

he3als commented 1 year ago

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:

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

comp500 commented 1 year ago

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 commented 1 year ago

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

Felix14-v2 commented 1 year ago

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

he3als commented 1 year ago

Note that the DirectX interop technique I mentioned in #19 (comment) (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.

Maybe add a little toggle for the DirectX interop as well? Just in case people want to have a fully fullscreen exclusive experience, as fullscreen optimisations may not completely work out for them. However, it's really good, nice work.

Also as a note, I generally referred to the Independent Flip presentation mode as fullscreen optimisations. However, I did not know about it actually being up to the driver/Windows to decide the presentation mode for OpenGL games.

comp500 commented 1 year ago

Compatibility issue should be fixed, I needed to include LWJGL's patches to GLFW (https://github.com/comp500/glfw/commit/942fe81c74c26c527d775137919593ffc24b32b1), get the fix here: borderless-mining-2.0.0-alpha.2-dev.b9c3c6c+1.19.2.jar.zip

Maybe add a little toggle for the DirectX interop as well?

I've made it switchable in game, no restart required :)

Scarlaid commented 1 year ago

Works fine with Better Taskbar but instant crash with PuzzleGUI The lastest.log: latest.log

Crash log:

comp500 commented 1 year ago

I can't really do much about the Puzzle crash, it's trying to use parts of Borderless Mining (the configuration) that aren't present in this version, since I removed all configuration. Easiest fix for now would probably be to change the mod ID in fabric.mod.json to something other than borderlessmining so Puzzle doesn't try to access it.

SleepyCatten commented 1 year ago

Is there a 1.19.3 test version out with the GLFW patch? 💟

Stonley890 commented 1 year ago

Been looking for a solution to full-screen issues and this solves them! Here is a video comparing before and after: https://youtu.be/l-w2_HCctQw

I've tried to figure out why using Minecraft (and some other games) in fullscreen changes the display settings but I couldn't find any answers online describing the same problem. Minecraft works way better than vanilla fullscreen with this patch.

OS: Windows 11 Home Single Language Version: 22H2 Build 22621.963 Display: 1920x1080 Graphics: NVIDIA GeForce RTX 3060

Minecraft: 1.19.2 Mod Loader: Quilt Loader 0.17.7

Jack-Works commented 1 year ago

Tried with Windows 11 22H2 22623.1095, 3840x2160, NVIDIA GeForce RTX3060 Ti, Farbic loader, Iris&Sodium, works good. Tested with PresentMon it is always "Copy with GPU GDI" in the game or out of the game.

Felix14-v2 commented 1 year ago

Is there a 1.19.3 test version out with the GLFW patch?

You can just use 1.19.2 version, it works fine

Except for the flickering when unfocusing Minecraft running with integrated graphics :(

https://user-images.githubusercontent.com/75726196/218817514-cbce676a-4ac1-41d5-aad3-a3c1469bd5dc.mp4 (sorry, OBS can't record Minecraft in fullscreen for some reason)

SleepyCatten commented 1 year ago

Hi @comp500 💟 Has this been merged into the main commit yet by any chance? No worries if not, as I greatly appreciate the work you put into this as it is. I was only thinking that it would be cool to have this patch incorporated into the official latest version, especially for any future 1.20 updates or beyond.

comp500 commented 1 year ago

No, I'm still working on finding a more general solution to the problem that works on non-NVIDIA systems. I can probably integrate this fix for the next release, but it'd have to coexist with the current implementation until the D3D interop system is ready.

SleepyCatten commented 1 year ago

No, I'm still working on finding a more general solution to the problem that works on non-NVIDIA systems. I can probably integrate this fix for the next release, but it'd have to coexist with the current implementation until the D3D interop system is ready.

Thank you so much again for this 💟 I'd be happy to see two release versions (maybe one as stable & one as alpha for Nvidia cards only), but ultimately I'll defer to whatever is best for you 💟

WubTheGame commented 1 year ago

No, I'm still working on finding a more general solution to the problem that works on non-NVIDIA systems. I can probably integrate this fix for the next release, but it'd have to coexist with the current implementation until the D3D interop system is ready.

In case it helps, I'd like to inform you that the 1.18.2 version of this mod (and the test build linked here) does nothing for me while the 1.18 version works fine. I'm on a 7900xt, 3900x, Win10 updated two days ago, three displays with varying resolutions (max is 1440p 144hz, the game's monitor), latest graphics driver, using Quilt 0.18.10 on Minecraft 1.18.2.

That said, I'm wondering if there is/will be any particular reason, technical or practical, to update when there's a new usable version for me? I expect not due to the simple scope of the mod, but just curious.

IdrisQe commented 1 year ago

I'm assuming this is what's causing some of my issues?

When I try to use Printscreen in Windows 10 to take a screenshot, for some reason it always gives me an "outdated" frame - for example I took this one after a few minutes of playing, yet it just shows the world loading screen as if that was when I took the printscreen (it wasn't). image

Edit: It seems whatever gets printscreened is whatever frame was shown when I last alt-tabbed back into the game.

On a similar issue, when using the program ScreenToGif with Borderless Mining, it captures a still image regardless of how much I move my camera while recording.

I might try 2.0.0 alpha in a few and report back based on my findings.

Edit: Yes, it does fix my issues! Though performance seems more stuttery now... Hm... Maybe something to do with the DirectX Interop from what I've been reading here? Admittedly my knowledge of rendering is... near-zero so I may be misunderstanding.

I've made it switchable in game, no restart required :)

Is this in the latest 2.0.0 alpha linked here? I can't seem to find it to try toggling it. Mod Menu integration also isn't working in that version (and the config file doesn't seem to have anything about it anyways)

comp500 commented 1 year ago

The currently released builds don't use the DirectX interop code, so they only work on NVIDIA and can impact performance. When the DirectX interop version is ready, I'll make a separate issue and link it from here - this one is rather cluttered.

Josh65-2201 commented 9 months ago

Has there been any work on this recently?

mse-k commented 8 months ago

Could there be a build for 1.20.2? I was trying to setup an AutoHotkey script and realized this was the issue lol

Enderteck commented 7 months ago

Could this kind of patch be done for the Linux libglfw ?

Right now this mod doesn't work on Wayland with this patched version:

BoyOrigin/glfw-wayland

If someone would tell me how to have both work together that would be nice !

craftercis commented 6 months ago

Hey @comp500. Really nice mod! Im now using a external tool "Borderless Gaming" because the GLFW fix isn't out for 1.20.1 yet. And this fixes my hdr bug within Minecraft. If you have the time, could you please update the fix to 1.20.1?

Edit #1: When I watch a youtube video higher than 720p and open the inventory menu the video is buffering sometimes Edit #2: It works fine for 1.20.1 for some reason lol. But the buffering is still there. I try to make a video from it Edit #3: The stuttering is because of graphics acceleration in the browser. Turned that off and its working fine now. Maybe you can look into that?

Felix14-v2 commented 6 months ago

Im now using a external tool "Borderless Gaming" because the GLFW fix isn't out for 1.20.1 yet. And this fixes my hdr bug within Minecraft. If you have the time, could you please update the fix to 1.20.1?

If you use Sodium, then there's a chance of getting this feature with one of its further updates: https://github.com/CaffeineMC/sodium-fabric/issues/2359

craftercis commented 6 months ago

Im now using a external tool "Borderless Gaming" because the GLFW fix isn't out for 1.20.1 yet. And this fixes my hdr bug within Minecraft. If you have the time, could you please update the fix to 1.20.1?

If you use Sodium, then there's a chance of getting this feature with one of its further updates: CaffeineMC/sodium-fabric#2359

That would be nice. However, The fix comp500 made here works fine for me know on 1.20.1