Files
ThreadPilot/ViewModels/SystemTweaksViewModel.GameBoost.cs
T
PrimeBuild-pc f8d6f19dba feat: Game Boost, CPU Sets for the game and selected background apps
While a detected game runs, Game Boost sets process default CPU Sets from
the CPU topology: on AMD X3D with one larger L3 the game goes to the V-Cache
CCD, on Intel hybrid CPUs to the P-cores, and selected background apps
(browsers, sync clients, updaters, launchers) to the other cores. On dual-CCD
parts with equal L3 only the background moves, unless Isolation mode also
keeps the game on CCD0. Single-L3 and unreadable topologies are left to
Windows. Above Normal priority for the game is optional; never High.

Each change is written to a journal before it is made and undone when the
game exits, Game Boost is turned off or ThreadPilot closes, and on the next
start after a crash. Only values still exactly as Game Boost set them are
restored, never one a user rule or a manual change has taken over since.
Persistent rules and Game Boost share one apply gate, and a rule always
wins over Game Boost for the setting it covers.

The switch, mode and lists are on the Tweaks page, off by default, and take
effect without a restart.
2026-10-15 16:17:41 +02:00

184 lines
7.4 KiB
C#

namespace ThreadPilot.ViewModels
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ThreadPilot.Models;
using ThreadPilot.Services;
/// <summary>
/// Game Boost card on the Tweaks page. Every switch saves at once; the session service reacts to the
/// settings change, so turning it off restores the running game without a restart.
/// </summary>
public partial class SystemTweaksViewModel
{
private readonly IApplicationSettingsService? settingsService;
private readonly IGameSessionService? gameSessionService;
private bool isLoadingGameBoost;
[ObservableProperty]
private bool isGameBoostAvailable;
[ObservableProperty]
private bool gameBoostEnabled;
[ObservableProperty]
private bool gameBoostAutomatic = true;
[ObservableProperty]
private bool gameBoostIsolation;
[ObservableProperty]
private bool gameBoostAboveNormal;
[ObservableProperty]
private string gameBoostDecisionText = string.Empty;
[ObservableProperty]
private string gameBoostManualGamesText = string.Empty;
[ObservableProperty]
private string gameBoostExcludedGamesText = string.Empty;
[ObservableProperty]
private string gameBoostBackgroundText = string.Empty;
internal async Task LoadGameBoostAsync()
{
if (this.settingsService == null || this.gameSessionService == null)
{
return;
}
var settings = this.settingsService.Settings;
await InvokeOnUiAsync(() =>
{
this.isLoadingGameBoost = true;
try
{
this.IsGameBoostAvailable = true;
this.GameBoostEnabled = settings.GameBoostEnabled;
this.GameBoostIsolation = settings.GameBoostMode == GameBoostMode.Isolation;
this.GameBoostAutomatic = !this.GameBoostIsolation;
this.GameBoostAboveNormal = settings.GameBoostAboveNormalPriority;
this.GameBoostManualGamesText = string.Join(Environment.NewLine, settings.GameBoostManualGames);
this.GameBoostExcludedGamesText = string.Join(Environment.NewLine, settings.GameBoostExcludedGames);
this.GameBoostBackgroundText = string.Join(Environment.NewLine, settings.GameBoostBackgroundProcesses);
}
finally
{
this.isLoadingGameBoost = false;
}
});
await this.RefreshGameBoostDecisionTextAsync();
}
[RelayCommand]
private Task SaveGameBoostListsAsync() => this.SaveGameBoostAsync();
partial void OnGameBoostEnabledChanged(bool value) => this.QueueGameBoostSave();
partial void OnGameBoostAboveNormalChanged(bool value) => this.QueueGameBoostSave();
partial void OnGameBoostIsolationChanged(bool value)
{
if (this.GameBoostAutomatic == value)
{
this.GameBoostAutomatic = !value;
}
this.QueueGameBoostSave();
}
partial void OnGameBoostAutomaticChanged(bool value)
{
if (this.GameBoostIsolation == value)
{
this.GameBoostIsolation = !value;
}
}
private void QueueGameBoostSave()
{
if (!this.isLoadingGameBoost)
{
TaskSafety.FireAndForget(
this.SaveGameBoostAsync(),
ex => this.SetError(this.Localize("GameBoost_SaveFailed", "Could not save Game Boost settings"), ex));
}
}
private async Task SaveGameBoostAsync()
{
if (this.settingsService == null)
{
return;
}
var updated = (ApplicationSettingsModel)this.settingsService.Settings.Clone();
updated.GameBoostEnabled = this.GameBoostEnabled;
updated.GameBoostMode = this.GameBoostIsolation ? GameBoostMode.Isolation : GameBoostMode.Automatic;
updated.GameBoostAboveNormalPriority = this.GameBoostAboveNormal;
updated.GameBoostManualGames = SplitLines(this.GameBoostManualGamesText);
updated.GameBoostExcludedGames = SplitLines(this.GameBoostExcludedGamesText);
updated.GameBoostBackgroundProcesses = SplitLines(this.GameBoostBackgroundText);
await this.settingsService.UpdateSettingsAsync(updated);
await this.LogUserActionAsync(
"GameBoostSettingsChanged",
$"Game Boost {(updated.GameBoostEnabled ? "on" : "off")}, {updated.GameBoostMode}",
"GameBoost");
await this.RefreshGameBoostDecisionTextAsync();
}
private async Task RefreshGameBoostDecisionTextAsync()
{
if (this.gameSessionService == null)
{
return;
}
var decision = await this.gameSessionService.GetDecisionAsync();
var game = decision.GameSelection?.GlobalLogicalProcessorIndexes.Count ?? 0;
var background = decision.BackgroundSelection?.GlobalLogicalProcessorIndexes.Count ?? 0;
var text = decision.Kind switch
{
GameBoostTopologyKind.AmdAsymmetricCache => this.Localize(
"GameBoost_Decision_AmdVCache",
"Game on the CCD with 3D V-Cache ({0} CPUs), selected background apps on the other CCD ({1} CPUs).",
game,
background),
GameBoostTopologyKind.AmdSymmetricMultiL3 when decision.GameSelection != null => this.Localize(
"GameBoost_Decision_AmdCcd0",
"Game on CCD0 ({0} CPUs), background apps on the other CCD ({1} CPUs).",
game,
background),
GameBoostTopologyKind.AmdSymmetricMultiL3 => this.Localize(
"GameBoost_Decision_AmdBackgroundOnly",
"Windows places the game; selected background apps move off CCD0 ({0} CPUs). Isolation also keeps the game on CCD0.",
background),
GameBoostTopologyKind.IntelHybrid => this.Localize(
"GameBoost_Decision_IntelHybrid",
"Game on the P-cores ({0} CPUs), selected background apps on the E-cores ({1} CPUs).",
game,
background),
_ => this.Localize(
"GameBoost_Decision_Unsupported",
"On this CPU Windows decides the cores; Game Boost only applies the optional priority."),
};
await InvokeOnUiAsync(() => this.GameBoostDecisionText = text);
}
private static List<string> SplitLines(string text) =>
(text ?? string.Empty)
.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
}
}