mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
fix: keep FEX's TSO on for Unity games (#1415)
The default FEX preset (Performance + TSO) is fine for Unity. But when the Default profile is switched to a preset that turns TSO off (Performance, Extreme, Extreme-gn, Denuvo), Unity players break. DroidDeck already keeps full TSO for .NET games (`coreclr.dll`) whatever the preset; this gives Unity players the same safety net for TSO. Tested on a Pixel 10 Pro Fold (PowerVR DXT-48-1536), shared preset Performance (TSO off): | Game | Build | TSO off | TSO on | | --- | --- | --- | --- | | Megabonk | Unity 2023.2 IL2CPP, native Linux, "Linux x86 (FEX)" | froze on about half of launches (every thread parked on a futex) | 5 of 5 starts, played run stayed responsive | | Crab Game | Unity IL2CPP, Windows, Proton arm64 | 9 of 10 starts; 1 access violation in `UnityPlayer.dll` (read of a garbage pointer) | 10 of 10 starts | Measured cost of TSO on Megabonk: none (+2% fps with TSO on, within noise). What changes: - `droiddeck-game-env`: `unity_memory_ordering` sets `FEX_TSOENABLED=1` when `UnityPlayer.dll`, `UnityPlayer.so` or `GameAssembly.so` sits next to the executable (or one folder below). A FEX preset chosen for the game still wins (fixes sit between the shared preset and the per-game entry, as for .NET). - `droiddeck-fex`: the FEX tool now applies the environment half of these game-file fixes, so native Linux Unity builds get it too. Launch arguments some fixes add stay Proton-only. - Docs paragraph in `docs/development/game-environment.md`; tests in `test_game_environment.py` and `test_droiddeck_fex.py`. Device check of the change itself: with the session's `droiddeck-game-env` patched, shared TSO off and no per-game entry, Crab Game started with `FEX_TSOENABLED=1`. Related to #1386, but not a fix for its Risk of Rain 2 crash: that game is Unity Mono, which with the default preset already has TSO on; the report points at multiblock instead (as the .NET fix turns off). Both games tested here are IL2CPP, so this PR doesn't change multiblock. #1386's other points (`steam_appid.txt`, `device.txt`) aren't covered. Tests (WSL, on main `16bedf36` with the patch): `test_game_environment` + `test_droiddeck_fex` 119 OK. Full `tools/tests`: 1114 tests, one failure, `test_appimage_run…test_a_failed_program_shows_the_log_it_wrote`, which fails the same way without the patch.
This commit is contained in:
5 files changed
+78
-4
No files matched your search
@@ -672,15 +672,27 @@ def launch(command, env, mode, decide=None):
|
||||
return os.execve(fex["bin"], [fex["bin"], program] + command[1:], guest)
|
||||
|
||||
|
||||
def game_environment(env):
|
||||
def game_environment(env, command):
|
||||
try:
|
||||
game_env = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-game-env"))
|
||||
env = game_env["game_gpu"](env)
|
||||
app = game_env["game_id"](env) or env.get("SteamAppId") or env.get("SteamGameId")
|
||||
if not app:
|
||||
return env
|
||||
with open(GAME_ENVIRONMENT, encoding="utf-8") as source:
|
||||
return game_env["apply_config"](env, json.load(source), str(app))
|
||||
fixes = {}
|
||||
game = game_env["Game"](resolve(command[0], env), command[1:])
|
||||
for check in game_env["FIXES"]:
|
||||
found = check(game)
|
||||
# Environment fixes only: the launch arguments some fixes add were chosen for Windows builds.
|
||||
if found and found[0]:
|
||||
fixes.update(found[0])
|
||||
say(found[2])
|
||||
try:
|
||||
with open(GAME_ENVIRONMENT, encoding="utf-8") as source:
|
||||
config = json.load(source)
|
||||
except FileNotFoundError:
|
||||
config = {"version": 1}
|
||||
return game_env["apply_config"](env, config, str(app), fixes)
|
||||
except FileNotFoundError:
|
||||
return env
|
||||
except Exception as error:
|
||||
@@ -811,7 +823,7 @@ def main(argv):
|
||||
return 0
|
||||
if not command:
|
||||
return 2
|
||||
return launch(command, game_environment(dict(os.environ)), os.environ.get("DROIDDECK_FEX", "auto"))
|
||||
return launch(command, game_environment(dict(os.environ), command), os.environ.get("DROIDDECK_FEX", "auto"))
|
||||
if action == "run":
|
||||
try:
|
||||
mode, decide, command = parse_run(args)
|
||||
|
||||
@@ -87,6 +87,15 @@ def dotnet_memory_ordering(game):
|
||||
return DOTNET_FEX, [], ".NET runtime: FEX with full TSO and without multiblock"
|
||||
|
||||
|
||||
@fix
|
||||
def unity_memory_ordering(game):
|
||||
"""A Unity player under FEX without TSO deadlocks or crashes: Megabonk (Linux, IL2CPP) froze with every
|
||||
thread parked on a futex on about half of all launches, Crab Game (Windows under Proton, IL2CPP) died with
|
||||
an access violation in UnityPlayer.dll. Presets that turn TSO off keep it on for Unity games."""
|
||||
if {"unityplayer.so", "gameassembly.so", "unityplayer.dll"} & game.files:
|
||||
return {"FEX_TSOENABLED": "1"}, [], "Unity: FEX with TSO"
|
||||
|
||||
|
||||
@fix
|
||||
def godot_vulkan(game):
|
||||
if is_godot(game) and not game.has_arg("--rendering-driver"):
|
||||
|
||||
Reference in new issue
Block a user