Add opt-in Follow Steam FEX preset

This commit is contained in:
Kurt Himebauch committed 2026-12-05 18:17:43 -05:00
1 parent 1596e2966d
commit ae354a25a6
12 files changed
+150 -12

No files matched your search

@@ -3,6 +3,9 @@ package com.droiddeck.launcher.core
import com.droiddeck.launcher.R
object FexPreset {
const val FOLLOW_STEAM = "FOLLOW_STEAM"
const val FOLLOW_STEAM_FALLBACK = "PERFORMANCE_TSO"
class Preset(val id: String, val label: Int, val detail: Int, val env: List<String>)
private fun tso(main: Int, vector: Int, memcpy: Int, halfBarrier: Int) = listOf(
@@ -11,6 +14,7 @@ object FexPreset {
val all: List<Preset> = listOf(
Preset("", R.string.fex_default_label, R.string.fex_default_detail, emptyList()),
Preset(FOLLOW_STEAM, R.string.fex_follow_steam_label, R.string.fex_follow_steam_detail, emptyList()),
Preset("STABILITY", R.string.fex_stability_label, R.string.fex_stability_detail, tso(1, 1, 1, 1) + listOf("FEX_X87REDUCEDPRECISION=0", "FEX_MULTIBLOCK=0")),
Preset("COMPATIBILITY", R.string.fex_compatibility_label, R.string.fex_compatibility_detail, tso(1, 1, 1, 1) + listOf("FEX_X87REDUCEDPRECISION=0", "FEX_MULTIBLOCK=1")),
Preset("INTERMEDIATE", R.string.fex_intermediate_label, R.string.fex_intermediate_detail, tso(1, 0, 0, 1) + listOf("FEX_X87REDUCEDPRECISION=1", "FEX_MULTIBLOCK=1")),
@@ -26,6 +30,8 @@ object FexPreset {
tso(0, 0, 0, 0) + listOf("FEX_X87REDUCEDPRECISION=1", "FEX_MULTIBLOCK=1", "FEX_SMCCHECKS=full", "FEX_HIDEHYPERVISORBIT=1")),
)
val forGame = all.filterNot { it.id == FOLLOW_STEAM }
fun byId(id: String): Preset = all.firstOrNull { it.id == id } ?: all[0]
fun env(id: String): List<String> = byId(id).env
@@ -61,7 +61,8 @@ object GameEnvironment {
}
fun effective(config: Config, preset: String, scope: String, forceSsbs: Boolean = false): Map<String, String?> =
defaults(preset, forceSsbs) + config.shared + if (scope.isEmpty()) emptyMap() else knownGames[scope].orEmpty() + config.games[scope].orEmpty()
defaults(if (preset == FexPreset.FOLLOW_STEAM) FexPreset.FOLLOW_STEAM_FALLBACK else preset, forceSsbs) +
config.shared + if (scope.isEmpty()) emptyMap() else knownGames[scope].orEmpty() + config.games[scope].orEmpty()
/**
* What some Steam games need here whatever the shared settings say; the game's own settings still win.
@@ -89,7 +90,7 @@ object GameEnvironment {
require(scope.isNotEmpty() && validScope(scope))
val entries = config.games[scope].orEmpty()
if (FexPreset.environmentKeys.none(entries::containsKey)) return null
return FexPreset.all.firstOrNull { preset ->
return FexPreset.forGame.firstOrNull { preset ->
val expected = presetFor(scope, preset.id)
FexPreset.environmentKeys.all { key -> entries.containsKey(key) && entries[key] == expected[key] }
}?.id ?: CUSTOM_FEX_PRESET
@@ -97,7 +98,7 @@ object GameEnvironment {
fun withGameFexPreset(config: Config, scope: String, preset: String?): Config {
require(scope.isNotEmpty() && validScope(scope))
require(preset == null || FexPreset.all.any { it.id == preset })
require(preset == null || FexPreset.forGame.any { it.id == preset })
val entries = config.entries(scope).filterKeys { it !in FexPreset.environmentKeys }.toMutableMap()
if (preset != null) {
val values = presetFor(scope, preset)
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.session
import android.content.Context
import android.util.AtomicFile
import android.util.Log
import com.droiddeck.launcher.core.FexPreset
import com.droiddeck.launcher.core.GameEnvironment
import com.droiddeck.launcher.core.TextureFiltering
import com.droiddeck.launcher.runtime.LinuxRuntime
@@ -114,8 +115,13 @@ object GameEnvironmentStore {
) {
publishGameCores(context)
val stored = config ?: read(context)
val resolved = GameEnvironment.withKnownGames(stored).copy(shared = GameEnvironment.defaults(SessionPrefs.fexPreset(context), SessionPrefs.forceSsbs(context)) + stored.shared)
val preset = SessionPrefs.fexPreset(context)
val resolved = GameEnvironment.withKnownGames(stored).copy(shared = GameEnvironment.defaults(preset, SessionPrefs.forceSsbs(context)) + stored.shared)
val json = encode(resolved)
// Keep preset values separate from raw shared overrides so the guest can replace only defaults.
if (preset == FexPreset.FOLLOW_STEAM) {
json.put("followSteamFex", JSONObject(FexPreset.environment(FexPreset.FOLLOW_STEAM_FALLBACK)))
}
val dxvk = TextureFiltering.dxvkOptions(
SessionPrefs.textureAnisotropy(context), SessionPrefs.textureLodBias(context),
TextureFiltering.autoLodBias(SessionState.upscaleRatio),
@@ -1381,7 +1381,8 @@ internal fun FexPresetChip(
focusRequester = first,
) { onPick(null); onDismiss() }
}
FexPreset.all.forEachIndexed { index, option ->
val options = if (allowInheritance) FexPreset.forGame else FexPreset.all
options.forEachIndexed { index, option ->
MenuItem(
stringResource(option.label),
checked = !inherited && option.id == preset,
@@ -1228,7 +1228,7 @@ internal fun GameSettingsMenus(host: MenuHost, game: com.droiddeck.launcher.fron
if (fex == com.droiddeck.launcher.core.GameEnvironment.CUSTOM_FEX_PRESET) {
MenuItem(custom, checked = true, enabled = false) {}
}
com.droiddeck.launcher.core.FexPreset.all.forEach { option ->
com.droiddeck.launcher.core.FexPreset.forGame.forEach { option ->
MenuItem(stringResource(option.label), checked = fex == option.id, enabled = ready, detail = stringResource(option.detail)) {
host.open = key
save { com.droiddeck.launcher.session.GameEnvironmentStore.setGameFexPreset(it, scope, option.id) }
+2
View File
@@ -143,6 +143,8 @@
<string name="game_settings_title">Games</string>
<string name="fex_default_label">Stock FEX</string>
<string name="fex_default_detail">No FEX tuning applied.</string>
<string name="fex_follow_steam_label">Follow Steam</string>
<string name="fex_follow_steam_detail">Use Steam’s available FEX hints for Proton games. Otherwise use Performance + TSO. Per-game settings still win.</string>
<string name="fex_stability_label">Stability</string>
<string name="fex_stability_detail">Safest, slowest settings.</string>
<string name="fex_compatibility_label">Compatibility</string>
@@ -4,6 +4,17 @@ import org.junit.Assert.*
import org.junit.Test
class GameEnvironmentTest {
@Test
fun followSteamIsGlobalOnlyAndKeepsThePerformanceTsoFallbackAndGameOverrides() {
val preset = FexPreset.FOLLOW_STEAM
val config = GameEnvironment.withGameFexPreset(GameEnvironment.Config(), "42", "PERFORMANCE")
assertTrue(FexPreset.all.any { it.id == preset })
assertFalse(FexPreset.forGame.any { it.id == preset })
assertFalse(GameEnvironment.defaults(preset).containsKey("FEX_TSOENABLED"))
assertEquals(GameEnvironment.effective(config, "PERFORMANCE_TSO", "43"), GameEnvironment.effective(config, preset, "43"))
assertEquals("0", GameEnvironment.effective(config, preset, "42")["FEX_TSOENABLED"])
}
@Test fun defaultsDetectGraphicsCapabilitiesAndKeepCaching() {
val values = GameEnvironment.defaults("")
assertEquals("false", values["MESA_SHADER_CACHE_DISABLE"])
@@ -803,8 +803,9 @@ def game_environment(env, command, proton=None):
config = json.load(source)
except FileNotFoundError:
config = {"version": 1}
env = game_env["apply_config"](env, config, str(app), fixes)
if proton and len(proton) > 2 and proton[1] == "waitforexitandrun":
steam_proton = bool(proton and len(proton) > 2 and proton[1] == "waitforexitandrun")
env = game_env["apply_config"](env, config, str(app), fixes, steam_proton=steam_proton)
if steam_proton:
logged = game_env["apply_game_debug_logs"](env, config)
if logged is not env:
say("game debug logs enabled for this launch")
@@ -812,11 +812,45 @@ def game_images(env):
return True
def apply_config(env, config, app_id, fixes=None):
STEAM_FEX_HINTS = {
"FEX_TSOENABLED": ("STEAM_FEX_TSOENABLED", "TSOEnabled"),
"FEX_MULTIBLOCK": ("STEAM_FEX_MULTIBLOCK", "Multiblock"),
}
def follow_steam_fex(env, fallback, app_id, steam_proton):
if not isinstance(fallback, dict):
raise ValueError("invalid Follow Steam FEX fallback")
runtime_id = app_number(env.get("SteamAppId") or env.get("STEAM_COMPAT_APP_ID"))
if not steam_proton or env.get("DROIDDECK_DIRECT_PROTON") == "1" or runtime_id != app_id \
or runtime_id is None or int(runtime_id) >= 2**31:
return fallback
# A caller-supplied FEX config takes the place of Proton's generated one. Do not
# mask it with DroidDeck defaults; explicit DroidDeck overrides are applied later.
config = env.get("FEX_APP_CONFIG")
if config and os.path.isfile(config):
return {}
result = fallback.copy()
override = env.get("STEAM_COMPAT_FEX_CONFIG", "")
# Use the actual launch variables, not the numeric Steam Frame metadata enums.
# Valve's nonempty override is a bitset: absent flags mean off. Ignore an
# unknown/malformed payload rather than treating it as an all-off override.
names = "|".join(name for _, name in STEAM_FEX_HINTS.values())
flags = dict(re.findall(rf"(?<![\w])({names}):([01])(?![\w])", override))
for target, (hint, option) in STEAM_FEX_HINTS.items():
value = flags.get(option, "0") if flags else env.get(hint)
if value in ("0", "1"):
result[target] = value
return result
def apply_config(env, config, app_id, fixes=None, *, steam_proton=False):
if config.get("version") != 1:
raise ValueError("unsupported environment configuration")
result = env.copy()
entries = split_game_gpu(config.get("shared", {}))
fallback = config.get("followSteamFex")
entries = follow_steam_fex(env, fallback, app_id, steam_proton) if fallback is not None else {}
entries = dict(entries, **split_game_gpu(config.get("shared", {})))
for name, value in (fixes or {}).items():
if name == "WINEDLLOVERRIDES" and entries.get(name, env.get(name)):
value = entries.get(name, env.get(name)) + ";" + value
@@ -1745,7 +1779,7 @@ def main():
launch_config_valid = False
if launch_config_valid:
try:
effective_env = apply_config(env, launch_config, app_id)
effective_env = apply_config(env, launch_config, app_id, steam_proton=True)
except (OSError, ValueError, TypeError, AttributeError):
launch_config_valid = False
if not launch_config_valid:
@@ -1816,7 +1850,7 @@ def main():
if launch_config_valid:
if "vblank_mode" in config.get("shared", {}):
fixes.pop("vblank_mode", None)
env = apply_config(env, launch_config, app_id, fixes)
env = apply_config(env, launch_config, app_id, fixes, steam_proton=True)
note = keyboard_helper_off(env)
if note:
print("droiddeck-game-env: " + note, file=sys.stderr)
@@ -524,6 +524,8 @@ def main(argv):
os.makedirs(target.compatdata, exist_ok=True)
env = environment(os.environ, target, folder, root, window, game_id)
env.update(extra)
# The launcher synthesizes Steam IDs for direct runs: those are not client hints.
env["DROIDDECK_DIRECT_PROTON"] = "1"
if app is None and verb == VERB:
env["DROIDDECK_DESKTOP_PROGRAM"] = program
say("%s with %s (%s), %s prefix %s%s" % (program, name, why, target.kind, target.compatdata,
+15
View File
@@ -28,6 +28,21 @@ def elf(machine, data=1, size=64):
return bytes(head)
class FollowSteamFexDispatchTest(unittest.TestCase):
def test_arm_proton_route_resolves_steam_hints_on_the_game_not_the_client(self):
with tempfile.TemporaryDirectory() as tmp:
config = Path(tmp) / "game-environment.json"
config.write_text(json.dumps({"version": 1, "followSteamFex": {"FEX_TSOENABLED": "1"}}))
env = {"SteamAppId": "42", "STEAM_COMPAT_DATA_PATH": "/compatdata/42", "STEAM_FEX_TSOENABLED": "0"}
with mock.patch.dict(G, {"BIN_DIR": str(BIN), "GAME_ENVIRONMENT": str(config)}):
game = FEX["game_environment"](env, ["/tmp/game.exe"],
["/tmp/proton", "waitforexitandrun", "/tmp/game.exe"])
native = FEX["game_environment"](env, ["/tmp/native-game"])
self.assertEqual(game["FEX_TSOENABLED"], "0")
self.assertEqual(native["FEX_TSOENABLED"], "1")
self.assertNotIn("FEX_TSOENABLED", env)
class FexTestCase(unittest.TestCase):
def setUp(self):
self.tmp = Path(tempfile.mkdtemp())
+59
View File
@@ -24,6 +24,65 @@ STATE = tempfile.TemporaryDirectory()
COMPAT["main"].__globals__["COMPAT_DIR"] = STATE.name
class FollowSteamFexTest(unittest.TestCase):
fallback = {"FEX_TSOENABLED": "1", "FEX_MULTIBLOCK": "1", "FEX_X87REDUCEDPRECISION": "1"}
steam = {"SteamAppId": "42", "STEAM_FEX_TSOENABLED": "0", "STEAM_FEX_MULTIBLOCK": "0"}
def options(self, env=None, config=None, fixes=None, app_id="42", steam_proton=True):
result = MODULE["apply_config"](env or {}, {"version": 1, "followSteamFex": self.fallback, **(config or {})},
app_id, fixes, steam_proton=steam_proton)
return {key: value for key, value in result.items() if key.startswith("FEX_")}
def test_defaults_apply_only_valid_per_flag_hints_for_matching_steam_games(self):
self.assertEqual(self.options(self.steam), dict(self.fallback, FEX_TSOENABLED="0", FEX_MULTIBLOCK="0"))
self.assertEqual(self.options({**self.steam, "STEAM_FEX_MULTIBLOCK": "unknown"}),
dict(self.fallback, FEX_TSOENABLED="0"))
self.assertEqual(self.options({"SteamAppId": "42", "STEAM_FEX_TSOENABLED": "2"}), self.fallback)
def test_non_steam_and_mismatched_app_ids_use_fallback(self):
self.assertEqual(self.options(self.steam, steam_proton=False), self.fallback)
self.assertEqual(self.options(self.steam, app_id="99"), self.fallback)
self.assertEqual(self.options({**self.steam, "DROIDDECK_DIRECT_PROTON": "1"}), self.fallback)
self.assertEqual(self.options({**self.steam, "SteamAppId": "2147483648"}, app_id="2147483648"), self.fallback)
def test_steam_local_override_precedes_hints_without_mistaking_unknown_flags_for_off(self):
local = {**self.steam, "STEAM_FEX_MULTIBLOCK": "1", "STEAM_COMPAT_FEX_CONFIG": "TSOEnabled:1"}
self.assertEqual(self.options(local), dict(self.fallback, FEX_MULTIBLOCK="0"))
self.assertEqual(self.options({**local, "STEAM_COMPAT_FEX_CONFIG": "Unknown:1"}),
dict(self.fallback, FEX_TSOENABLED="0"))
def test_dd_manual_settings_and_known_fixes_keep_their_precedence(self):
config = {"shared": {"FEX_TSOENABLED": "1"}, "games": {"42": {"FEX_MULTIBLOCK": None}}}
result = self.options(self.steam, config, {"FEX_X87REDUCEDPRECISION": "0"})
self.assertEqual(result, {"FEX_TSOENABLED": "1", "FEX_X87REDUCEDPRECISION": "0"})
def test_an_existing_fex_app_config_is_not_replaced_or_masked_by_the_fallback(self):
with tempfile.TemporaryDirectory() as tmp:
fex_config = Path(tmp) / "fex.json"
fex_config.write_text('{"Config":{"TSOEnabled":"0"}}')
result = self.options({**self.steam, "FEX_APP_CONFIG": str(fex_config)}, fixes={"FEX_MULTIBLOCK": "1"})
self.assertEqual(result, {"FEX_APP_CONFIG": str(fex_config), "FEX_MULTIBLOCK": "1"})
self.assertEqual(json.loads(fex_config.read_text()), {"Config": {"TSOEnabled": "0"}})
def test_real_game_wrapper_delivers_steam_values_only_for_the_proton_game_verb(self):
with tempfile.TemporaryDirectory() as tmp:
home = Path(tmp)
config = home / ".config/droiddeck/game-environment.json"
config.parent.mkdir(parents=True)
config.write_text(json.dumps({"version": 1, "followSteamFex": self.fallback}))
probe = home / "proton"
probe.write_text("#!" + sys.executable + "\nimport os\nprint(os.getenv('FEX_TSOENABLED', 'unset'))\n")
probe.chmod(0o755)
env = {**os.environ, **self.steam, "HOME": tmp, "DROIDDECK_FASTEST_CORES": "0",
"STEAM_COMPAT_DATA_PATH": str(home / "compatdata/42")}
env.pop("FEX_TSOENABLED", None)
for verb, direct, expected in (("waitforexitandrun", "0", "0"), ("waitforexitandrun", "1", "1"), ("run", "0", "unset")):
with self.subTest(verb=verb, direct=direct):
output = subprocess.check_output([sys.executable, str(BIN / "droiddeck-game-env"), str(probe), verb, "game.exe"],
env={**env, "DROIDDECK_DIRECT_PROTON": direct}, text=True)
self.assertEqual(output.strip(), expected)
class ProducerAcquireGameEnvironmentTest(unittest.TestCase):
def test_prefixed_opt_in_enters_only_the_game_environment(self):
key = "DROIDDECK_GAME_FRAME_ACQUIRE"