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

Workaround for Linux shaders breakage #587

Merged
merged 8 commits into from
Sep 17, 2024

Conversation

Rainyan
Copy link
Collaborator

@Rainyan Rainyan commented Sep 14, 2024

Description

This is a hack around the vision mode shaders sporadically breaking on Linux builds.

It seems that for whatever reason, the shader state cached at the glshaders.cfg file somehow leads to the corruption upon successive runs of the game, and write-protecting the file offers a simple way to avoid that breakage.

Ideally, we should figure out what's really going wrong here at the shader system and/or precaching level, but this should suffice for avoiding the bug.

I opted to implement this as a CMakeLists step rather than submit the glshaders file itself, because to my understanding git does not version control the "read-only" file permissions required to keep the game from modifying the file.

edit: The hack is now done at runtime, because doing it in the CMake scripts won't carry over to users as pointed out by nullsystem, and we can't version control the file, because the filesystem specific metadata required for the read-only state won't carry over, and the concept of file permission flags is not universally available on all filesystems.

For more discussion, see: #438 (comment)

Steps to repro the bug

  • Use Linux
  • Build the game from master (or test with a recent release)
  • Launch the game
  • Check whether visions modes are broken for any of the 3 classes
  • If they're not broken, close the game, relaunch it, and check again
  • If you have the bug, you should be seeing shader corruption within a few tries

Steps to test this patch

  • The aforementioned corruption no longer occurs

Toolchain

  • Linux GCC Distro Native [Mint 21.3 Cinnamon + (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0]
  • cmake version 3.30.3

Linked Issues

@nullsystem
Copy link
Collaborator

nullsystem commented Sep 15, 2024

My main concern is for those downloading and installing the builds. Checking the GitHub artifact, the resources.zip is generated via Windows so it didn't apply here and neither the libraries zip includes this, so it seems to me those will not get the read-only glshaders.cfg.

@Rainyan
Copy link
Collaborator Author

Rainyan commented Sep 15, 2024

My main concern is for those downloading and installing the builds. Checking the GitHub artifact, the resources.zip is generated via Windows so it didn't apply here and neither the libraries zip includes this, so it seems to me those will not get the read-only glshaders.cfg.

Right, and the chmod permissions are stored on the filesystem, so generating the file in the CI is a dead end... I guess I'll have to see if this can be monkey patched at runtime after all.

Fix NeotokyoRebuild#438

This is a hack around the vision mode shaders sporadically breaking on
Linux builds.

It seems that for whatever reason, the shader state cached at the
glshaders file somehow leads to the corruption upon successive runs of
the game, and write-protecting the file offers a simple way to avoid
that breakage.

Ideally, we should figure out  what's really going wrong here at the
shader system and/or precaching level, but this should suffice for
avoiding the bug.

We're doing this at runtime because we can't version control the
filesystem specific file metadata required for the read-only state.

For more discussion, see:
* NeotokyoRebuild#587
* NeotokyoRebuild#438 (comment)
Use ARRAYSIZE to catch incorrect input types
@Rainyan
Copy link
Collaborator Author

Rainyan commented Sep 15, 2024

@nullsystem I've moved the patch to the client dll initialization, could you test if it's still working correctly for you?

@xedmain
Copy link
Contributor

xedmain commented Sep 16, 2024

what should happen is that glshaders.cfg gets set to read-only when I run NT;RE, right? I can test right now

@nullsystem
Copy link
Collaborator

@Rainyan Looks like it works for me and manages to stub out that file with empty glshadercachev002.

@xedmain
Copy link
Contributor

xedmain commented Sep 16, 2024

installed resources and linux release from the artifacts, ran the game twice and checked visions both times:
vision modes all work
the glshaders.cfg file is 21 bytes, set to read only

I wonder what will happen if NT;RE is installed on wacky filesystems like NTFS, FAT32/exFAT that have different types of permissions, as well what will happen if the current user can't modify permissions

@xedmain
Copy link
Contributor

xedmain commented Sep 16, 2024

nevermind, I see in the code that it just errors out

@Rainyan

This comment was marked as outdated.

@Rainyan Rainyan marked this pull request as ready for review September 16, 2024 04:36
Turn off the cvar for glshaders.cfg file generation on exit by default.

Also remove the file, if it exists on launch. This will be too late to
take effect for runs of the game where the file already exists, but
should fix it for future runs.

This also removes the dependency on filesystem specific read permission
flags for the fix.
@Rainyan
Copy link
Collaborator Author

Rainyan commented Sep 16, 2024

I found the cvar mat_autosave_glshaders which is used by the shaderapidx9 library. It seems that toggling it off prevents the game from generating the problematic glshaders.cfg file altogether.

I made changes such that we toggle the autosave off via cvar, and then delete the file if it already existed. Since we're too late intervene at client load, it'll still be bugged for a run where the buggy file existed, but this should fix it for any future runs. And players first-time launching the game should never run into the problem, as the cvar change should prevent the file from being generated in the first place.

This also removes the chmod filesystem permission flags fiddling, since it wasn't compatible across all the possible kinds of filesystems, as pointed out by @xedmain.

@Rainyan Rainyan removed the request for review from xedmain September 17, 2024 09:54
@Rainyan Rainyan merged commit e218a48 into NeotokyoRebuild:master Sep 17, 2024
6 checks passed
@Rainyan Rainyan deleted the bug/glshaders branch September 17, 2024 10:15
@nullsystem nullsystem added this to the v8.1-prealpha milestone Sep 18, 2024
@Rainyan Rainyan mentioned this pull request Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Vision modes are sometimes broken on linux
4 participants