Add ZeroFG and optional ZeroPacer (#3552)

Add ZeroFG as a frame generation engine with its opt-in pacer. Keep frame generation in the dedicated session tab and keep manual DLL import removed.
This commit is contained in:
LunaDL authored and GitHub committed 2026-12-03 22:29:39 -05:00
1 parent 34b78e2e42
commit a6ffbe7d81
26 files changed
+1348 -111

No files matched your search

@@ -10,11 +10,13 @@ object FrameGen {
const val ENGINE_DDFG = "ddfg"
private const val LEGACY_ENGINE_WINFG = "winfg"
const val ENGINE_LSFG = "lsfg"
const val ENGINE_ZEROFG = "zerofg"
private const val DDFG_PERF_PRESET = 2
private const val DDFG_MODEL = 4
private const val FLOW_SCALE_DDFG = 0.60f
private const val FLOW_SCALE_LSFG = 0.80f
private const val FLOW_SCALE_ZEROFG = 1.0f
val ADAPTIVE_TARGETS = listOf(120, 90, 60)
@@ -69,6 +71,14 @@ object FrameGen {
.putString("engine", mode.engine).putInt("multiplier", mode.multiplier).putInt("target", mode.target).apply()
}
fun pacerEnabled(context: Context): Boolean =
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getBoolean("pacer", false)
fun setPacer(context: Context, enabled: Boolean) {
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().putBoolean("pacer", enabled).apply()
WaylandCompositor.nativeSetFrameGenPacer(enabled)
}
fun clearGlobal(context: Context) {
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit()
.remove("engine").remove("multiplier").remove("target").apply()
@@ -80,6 +90,7 @@ object FrameGen {
mode.engine == ENGINE_DDFG -> context.getString(R.string.frame_gen_ddfg, mode.multiplier)
mode.engine == ENGINE_LSFG && mode.target > 0 -> context.getString(R.string.frame_gen_lsfg_adaptive, mode.target)
mode.engine == ENGINE_LSFG -> context.getString(R.string.frame_gen_lsfg, mode.multiplier)
mode.engine == ENGINE_ZEROFG -> context.getString(R.string.frame_gen_zerofg, mode.multiplier)
else -> context.getString(R.string.frame_gen_off)
}
@@ -104,6 +115,7 @@ object FrameGen {
fun applyPrepared(context: Context, prepared: PreparedApply, refreshHz: Float): String? {
val mode = prepared.mode
WaylandCompositor.nativeSetFrameGenPacer(pacerEnabled(context))
when (mode.engine) {
ENGINE_LSFG -> {
val status = prepared.lsfgStatus ?: LsfgNative.STATUS_NOT_INSTALLED
@@ -127,6 +139,11 @@ object FrameGen {
WaylandCompositor.nativeSetFrameGenTuning(FLOW_SCALE_DDFG, refreshHz)
WaylandCompositor.nativeSetFrameGenArmed(true, mode.multiplier, 0)
}
ENGINE_ZEROFG -> {
WaylandCompositor.nativeSetFrameGenEngine(WaylandCompositor.FG_ENGINE_ZEROFG)
WaylandCompositor.nativeSetFrameGenTuning(FLOW_SCALE_ZEROFG, refreshHz)
WaylandCompositor.nativeSetFrameGenArmed(true, mode.multiplier, 0)
}
else -> WaylandCompositor.nativeSetFrameGenArmed(false, 0, 0)
}
Log.i(TAG, "frame generation: $mode at ${refreshHz}Hz")
@@ -11,6 +11,10 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
@@ -29,18 +33,22 @@ internal fun FrameGenMenu(
onResetGame: () -> Unit = {},
focusModifier: Modifier = Modifier,
legacyButtons: Boolean = false,
listLayout: Boolean = false,
) {
val need = stringResource(R.string.lsfg_needs_steam)
val selectedEngine = mode.engine.takeIf { it != FrameGen.ENGINE_OFF }
val offLabel = FrameGen.label(LocalContext.current, FrameGen.Mode.OFF)
val colors = MaterialTheme.colorScheme
val engines = listOf(FrameGen.ENGINE_LSFG to "LSFG", FrameGen.ENGINE_DDFG to "DDFG")
val context = LocalContext.current
var pacerEnabled by remember { mutableStateOf(FrameGen.pacerEnabled(context)) }
val engines = listOf(FrameGen.ENGINE_LSFG to "LSFG", FrameGen.ENGINE_DDFG to "DDFG", FrameGen.ENGINE_ZEROFG to "ZeroFG")
if (legacyButtons) {
val context = LocalContext.current
val options = buildList {
add(FrameGen.Mode.OFF.copy(multiplier = mode.multiplier))
(2..4).forEach { add(FrameGen.Mode(FrameGen.ENGINE_DDFG, it)) }
(2..4).forEach { add(FrameGen.Mode(FrameGen.ENGINE_ZEROFG, it)) }
(2..4).forEach { add(FrameGen.Mode(FrameGen.ENGINE_LSFG, it)) }
FrameGen.ADAPTIVE_TARGETS.forEach { add(FrameGen.Mode(FrameGen.ENGINE_LSFG, target = it)) }
}
@@ -99,48 +107,85 @@ internal fun FrameGenMenu(
),
) { Text(offLabel) }
Row(Modifier.fillMaxWidth().padding(top = 8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
val focusIndex = engines.indexOfFirst { (engine, _) ->
selectedEngine == engine || engine != FrameGen.ENGINE_LSFG || lossless.ready
if (listLayout) {
Column(Modifier.fillMaxWidth().padding(top = 8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
engines.forEach { (engine, label) ->
val selected = selectedEngine == engine
val enabled = selected || engine != FrameGen.ENGINE_LSFG || lossless.ready
val pick = {
onPick(if (selected) FrameGen.Mode.OFF.copy(multiplier = mode.multiplier) else FrameGen.Mode(engine, mode.multiplier.coerceIn(2, 4)))
}
OutlinedButton(
onClick = pick,
enabled = enabled,
modifier = Modifier.fillMaxWidth().controllerConfirm(enabled = enabled, onClick = pick),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (selected) colors.primary.copy(alpha = 0.16f) else colors.surface,
contentColor = if (selected) colors.primary else colors.onSurface,
),
) { Text(label) }
}
}
engines.forEachIndexed { index, (engine, label) ->
val selected = selectedEngine == engine
val enabled = selected || engine != FrameGen.ENGINE_LSFG || lossless.ready
val pick = {
onPick(if (selected) FrameGen.Mode.OFF.copy(multiplier = mode.multiplier) else FrameGen.Mode(engine, mode.multiplier.coerceIn(2, 4)))
} else {
Row(Modifier.fillMaxWidth().padding(top = 8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
val focusIndex = engines.indexOfFirst { (engine, _) ->
selectedEngine == engine || engine != FrameGen.ENGINE_LSFG || lossless.ready
}
engines.forEachIndexed { index, (engine, label) ->
val selected = selectedEngine == engine
val enabled = selected || engine != FrameGen.ENGINE_LSFG || lossless.ready
val pick = {
onPick(if (selected) FrameGen.Mode.OFF.copy(multiplier = mode.multiplier) else FrameGen.Mode(engine, mode.multiplier.coerceIn(2, 4)))
}
OutlinedButton(
onClick = pick,
enabled = enabled,
modifier = (if (index == focusIndex) focusModifier else Modifier)
.weight(1f).controllerConfirm(enabled = enabled, onClick = pick),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (selected) colors.primary.copy(alpha = 0.16f) else colors.surface,
contentColor = if (selected) colors.primary else colors.onSurface,
),
) { Text(label) }
}
OutlinedButton(
onClick = pick,
enabled = enabled,
modifier = (if (index == focusIndex) focusModifier else Modifier)
.weight(1f).controllerConfirm(enabled = enabled, onClick = pick),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (selected) colors.primary.copy(alpha = 0.16f) else colors.surface,
contentColor = if (selected) colors.primary else colors.onSurface,
),
) { Text(label) }
}
}
if (selectedEngine != null) {
val multiplierEnabled = mode.engine != FrameGen.ENGINE_LSFG || lossless.ready
val multiplierEnabled = mode.engine != FrameGen.ENGINE_LSFG || lossless.ready
if (listLayout) {
Column(
Modifier.fillMaxWidth().padding(top = 8.dp),
verticalArrangement = Arrangement.spacedBy(6.dp),
) {
(2..4).forEach { multiplier ->
val selected = mode.multiplier == multiplier && mode.target == 0
val pickMultiplier = { onPick(mode.copy(multiplier = multiplier, target = 0)) }
OutlinedButton(
onClick = pickMultiplier,
enabled = multiplierEnabled,
modifier = Modifier.fillMaxWidth().controllerConfirm(enabled = multiplierEnabled, onClick = pickMultiplier),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (selected) colors.secondary.copy(alpha = 0.18f) else colors.surface,
contentColor = if (selected) colors.secondary else colors.onSurface,
),
) { Text("${multiplier}×") }
}
}
} else {
Row(
Modifier.fillMaxWidth().padding(top = 8.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
(2..4).forEach { multiplier ->
val selected = mode.multiplier == multiplier && mode.target == 0
val pickMultiplier = {
onPick(mode.copy(multiplier = multiplier, target = 0))
}
val pickMultiplier = { onPick(mode.copy(multiplier = multiplier, target = 0)) }
OutlinedButton(
onClick = pickMultiplier,
enabled = multiplierEnabled,
modifier = Modifier.weight(1f).controllerConfirm(
enabled = multiplierEnabled,
onClick = pickMultiplier,
),
modifier = Modifier.weight(1f).controllerConfirm(enabled = multiplierEnabled, onClick = pickMultiplier),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (selected) colors.secondary.copy(alpha = 0.18f) else colors.surface,
@@ -151,6 +196,25 @@ internal fun FrameGenMenu(
}
}
val togglePacer = {
val enabled = !pacerEnabled
FrameGen.setPacer(context, enabled)
pacerEnabled = enabled
}
OutlinedButton(
onClick = togglePacer,
modifier = Modifier.fillMaxWidth().padding(top = 8.dp)
.controllerConfirm(onClick = togglePacer),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
colors = ButtonDefaults.outlinedButtonColors(
containerColor = if (pacerEnabled) colors.primary.copy(alpha = 0.16f) else colors.surface,
contentColor = if (pacerEnabled) colors.primary else colors.onSurface,
),
) {
Text("ZeroPacer" + if (pacerEnabled) " ✓" else "")
}
if (selectedEngine == FrameGen.ENGINE_LSFG) {
Row(
Modifier.fillMaxWidth().padding(top = 8.dp),
@@ -196,6 +260,5 @@ internal fun FrameGenMenu(
Text(stringResource(R.string.comp_game_use_general) + if (hasGameOverride) "" else " ✓")
}
}
}
}
@@ -482,6 +482,13 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
}
}
LaunchedEffect(page) { host.open = null; appToChooseDisplay = null; managing = false }
LaunchedEffect(host.open) {
if (host.open == "frame-generation") repeat(24) {
androidx.compose.runtime.withFrameNanos { }
focus.request("frame-generation")
if (focus.focused == "frame-generation") return@LaunchedEffect
}
}
LaunchedEffect(a.selectedGameProfileId) {
if (host.open == "fex") host.open = null
}
@@ -910,24 +917,31 @@ private fun DrawerPerformancePage(host: MenuHost, a: DrawerActions, track: (Stri
@Composable
private fun DrawerFrameGenPage(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) {
private fun DrawerFrameGenSettings(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) {
val fgLabel = FrameGen.label(LocalContext.current, a.frameGen)
val scope = if (a.frameGenTargetGameId != null)
"${stringResource(R.string.frame_gen_scope_game)} · ${a.frameGenTargetGameName ?: "ID ${a.frameGenTargetGameId}"}"
else stringResource(R.string.frame_gen_scope_global)
SettingsGroup(stringResource(R.string.frame_gen_title), compact = true, key = "frame-generation", detail = summary(fgLabel, scope)) {
SettingsRow(stringResource(R.string.frame_gen_title), scope, stacked = true, tightControlSpacing = true) {
FrameGenMenu(
a.frameGen, a.lossless, a.onFrameGenPick,
gameProfileId = a.frameGenTargetGameId,
hasGameOverride = a.hasGameOverride,
onResetGame = a.onFrameGenReset,
)
}
FrameGenMenu(
mode = a.frameGen,
lossless = a.lossless,
onPick = a.onFrameGenPick,
gameProfileId = a.frameGenTargetGameId,
hasGameOverride = a.hasGameOverride,
onResetGame = a.onFrameGenReset,
focusModifier = track("frame-generation"),
)
}
}
@Composable
private fun DrawerFrameGenPage(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) {
DrawerFrameGenSettings(host, a, track)
}
@Composable
private fun DrawerDisplayPage(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) {
@@ -460,12 +460,14 @@ public final class WaylandCompositor {
public static final int SCENE_BUTTON = 3, SCENE_WHEEL = 4, SCENE_POINTER_DELTA = 6, SCENE_AXIS = 11, SCENE_AXIS_FINGER = 12;
public static final int WHEEL_STEP_UNITS = 120, POINTER_DELTA_SCALE = 256;
public static final int FG_ENGINE_LSFG = 0, FG_ENGINE_DDFG = 1;
public static final int FG_ENGINE_LSFG = 0, FG_ENGINE_DDFG = 1, FG_ENGINE_ZEROFG = 2;
public static native void nativeSetFrameGenEngine(int kind);
public static native void nativeSetFrameGenArmed(boolean armed, int multiplier, int targetFps);
public static native void nativeSetFrameGenPacer(boolean on);
public static native void nativeSetLsfgCachePath(String path);
public static native void nativeSetFrameGenTuning(float flowScale, float refreshHz);