Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# Local configuration (contains paths to YOUR files)
/victory.toml
/.env

# Places people tend to drop data into. Keep data outside the repo instead.
/game/
Expand Down
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,69 @@ title's window has focus:
| F / H | stick clicks |
| Esc, Tab | Menu, View |

## Performance presets (.env)

The PowerShell launcher applies a named preset before starting VIctory.
These experimental switches require the corresponding performance backports
(PR #1 and #2); older builds simply do not consume the new variables.

| Profile | Window grid | Idle scratch budget | Buffered title reads | Soft VRAM target |
|---------|-------------|---------------------|----------------------|------------------|
| default | 4096 KiB | 0 MiB | off | automatic |
| low | 1024 KiB | 0 MiB | off | automatic |
| high | 1024 KiB | 256 MiB | on | automatic |
| 8gb | 1024 KiB | 0 MiB | off | 5120 MiB |
| 12gb | 1024 KiB | 128 MiB | off | 7680 MiB |
| 16gb | 1024 KiB | 256 MiB | off | 10240 MiB |

The hardware profiles are for **dedicated VRAM**, not system RAM. Inspired
by [VItoriaBr's 8 GB / 16 GB presets](https://github.com/uiliannn/VItoriaBr#english).
The 12 GB target is an interpolation, not a measured setting.
`VICTORY_VRAM_TARGET_MB` sets a soft local-memory eviction threshold in
MiB (0 = automatic). It limits the existing DXGI budget threshold, never
raises it. Only eligible title-fed textures can be evicted, so this is
not a hard VRAM cap or a separate texture-only budget. More aggressive
eviction can cause texture churn. The fork's separate card-buffer budget,
async submission and internal-resolution controls are not implemented here.

From the repository root, after building the release executable:

```powershell
.\scripts\launch.ps1 -Preset default -VictoryArgs @('run', 'D:\game\title.exe', '--execute')
.\scripts\launch.ps1 -Preset low -VictoryArgs @('run', 'D:\game\title.exe', '--execute')
.\scripts\launch.ps1 -Preset high -VictoryArgs @('run', 'D:\game\title.exe', '--execute')
.\scripts\launch.ps1 -Preset 8gb -VictoryArgs @('run', 'D:\game\title.exe', '--execute')
.\scripts\launch.ps1 -Preset 12gb -ShowSettings
.\scripts\launch.ps1 -Preset 16gb -ShowSettings
```

Use `-VictoryExe 'C:\vt\release\victory.exe'` for a custom build path.
The launcher accepts any VIctory command via `-VictoryArgs`, so the same
profile can be used when prebuilding shaders or pipelines.

The tracked profiles are in `presets/*.env`. To override a setting locally,
create a git-ignored `.env` in the repository root, for example:

```dotenv
# Only the settings you want to override
VICTORY_SCRATCH_SPARE_MB=128
```

Precedence for the four managed variables: local `.env` > selected preset
> inherited environment. All other environment variables are left alone.
The launcher accepts plain KEY=VALUE lines, blank lines and whole-line
comments. It validates the four numeric settings, rejects unknown names
and duplicate entries, and does not execute file contents. The parent
PowerShell environment is restored when VIctory exits.

These are memory/performance profiles, not graphics-quality presets.
Smaller windows may increase overlapping copies; the spare budget is not a
total memory limit. Buffered reads can change I/O behavior. Test one switch
at a time, and compare frame times, memory use and rendering. No FPS gain
is guaranteed. The existing `victory.toml` remains the configuration for
game, cache and data paths. Debug and rendering-correctness switches are
not changed by the presets.

## Commands

```
Expand Down
39 changes: 38 additions & 1 deletion crates/victory-gpu/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,33 @@ fn evictable(t: &HostTexture) -> bool {
t.key.is_some() && crate::texture::title_written(&t.texture) && !t.host_written.load(std::sync::atomic::Ordering::Relaxed)
}

/// Optional soft ceiling for local GPU memory pressure (MiB). Zero or an
/// invalid value leaves DXGI's dynamic budget as the only limit.
#[cfg(windows)]
fn vram_target() -> Option<u64> {
static TARGET: std::sync::OnceLock<Option<u64>> = std::sync::OnceLock::new();
*TARGET.get_or_init(|| {
let target = std::env::var("VICTORY_VRAM_TARGET_MB").ok()
.and_then(|v| v.trim().parse::<u64>().ok())
.filter(|&v| (1024..=65536).contains(&v));
if let Some(mib) = target {
tracing::info!(mib, "soft local GPU memory target enabled");
}
target
})
}

/// The host reports decimal MB. An optional MiB ceiling lowers the existing
/// eviction threshold, but never raises it above the driver's current budget.
/// Keep the existing hysteresis ratio and eviction eligibility.
#[cfg(windows)]
fn eviction_excess(used: f64, budget: f64, target_mib: Option<u64>) -> u64 {
let high = BUDGET_HIGH * budget;
let high = target_mib.map_or(high, |mib| high.min(mib as f64 * 1_048_576.0 / 1e6));
let low = if target_mib.is_some() { high * (BUDGET_LOW / BUDGET_HIGH) } else { BUDGET_LOW * budget };
if used > high { ((used - low) * 1e6) as u64 } else { 0 }
}

/// Once per presented frame, before a submission (`Host::execute`, one at a
/// time, the last one has run): gives up host textures fed from title memory
/// that the title has not used for [`IDLE_MS`], and past [`BUDGET_HIGH`] of
Expand All @@ -1597,7 +1624,7 @@ pub(crate) fn evict_unused() {
// Free space in the heaps of textures takes the card's memory but
// is not in use: new textures go there first.
let used = used - crate::placement::free_bytes() as f64 / 1e6;
if used > BUDGET_HIGH * budget { ((used - BUDGET_LOW * budget) * 1e6) as u64 } else { 0 }
eviction_excess(used, budget, vram_target())
});
evict(frame, now_ms(), over);
}
Expand Down Expand Up @@ -2491,6 +2518,16 @@ mod tests {
assert!(choose(&[early], frame, now, 0).is_empty(), "too few frames ago");
}

#[test]
fn vram_target_only_lowers_the_dynamic_eviction_threshold() {
assert_eq!(eviction_excess(899.0, 1000.0, None), 0);
assert_eq!(eviction_excess(950.0, 1000.0, None), 100_000_000);
assert_eq!(eviction_excess(950.0, 1000.0, Some(5120)), 100_000_000);
assert_eq!(eviction_excess(5300.0, 10000.0, Some(5120)), 0);
assert!(eviction_excess(5500.0, 10000.0, Some(5120)) > 0);
assert_eq!(eviction_excess(5500.0, 10000.0, None), 0);
}

/// Title textures of one memory share a key in any format of the same
/// element; another address, shape, element size or a depth texture is
/// another memory. The library's own layout pick resolves as spelled.
Expand Down
5 changes: 5 additions & 0 deletions presets/12gb.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 12 GiB dedicated VRAM; experimental
VICTORY_WINDOW_KB=1024
VICTORY_SCRATCH_SPARE_MB=128
VICTORY_BUFFERED_TITLE_READS=0
VICTORY_VRAM_TARGET_MB=7680
5 changes: 5 additions & 0 deletions presets/16gb.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 16 GiB dedicated VRAM; experimental
VICTORY_WINDOW_KB=1024
VICTORY_SCRATCH_SPARE_MB=256
VICTORY_BUFFERED_TITLE_READS=0
VICTORY_VRAM_TARGET_MB=10240
5 changes: 5 additions & 0 deletions presets/8gb.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 8 GiB dedicated VRAM; experimental
VICTORY_WINDOW_KB=1024
VICTORY_SCRATCH_SPARE_MB=0
VICTORY_BUFFERED_TITLE_READS=0
VICTORY_VRAM_TARGET_MB=5120
5 changes: 5 additions & 0 deletions presets/default.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Original memory behavior
VICTORY_WINDOW_KB=4096
VICTORY_SCRATCH_SPARE_MB=0
VICTORY_BUFFERED_TITLE_READS=0
VICTORY_VRAM_TARGET_MB=0
5 changes: 5 additions & 0 deletions presets/high.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Experimental performance tuning; may use more memory
VICTORY_WINDOW_KB=1024
VICTORY_SCRATCH_SPARE_MB=256
VICTORY_BUFFERED_TITLE_READS=1
VICTORY_VRAM_TARGET_MB=0
5 changes: 5 additions & 0 deletions presets/low.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Experimental lower-memory tuning
VICTORY_WINDOW_KB=1024
VICTORY_SCRATCH_SPARE_MB=0
VICTORY_BUFFERED_TITLE_READS=0
VICTORY_VRAM_TARGET_MB=0
119 changes: 119 additions & 0 deletions scripts/launch.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Apply authored numeric performance settings without evaluating .env text.
[CmdletBinding()]
param(
[ValidateSet('default', 'low', 'high', '8gb', '12gb', '16gb')]
[string]$Preset = 'default',
[string]$VictoryExe,
[string[]]$VictoryArgs,
[switch]$ShowSettings
)

$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $PSScriptRoot
if (-not $VictoryExe) {
$VictoryExe = Join-Path $root 'target\release\victory.exe'
}

$names = @(
'VICTORY_WINDOW_KB',
'VICTORY_SCRATCH_SPARE_MB',
'VICTORY_BUFFERED_TITLE_READS',
'VICTORY_VRAM_TARGET_MB'
)

function Read-PerformanceEnv([string]$Path) {
$settings = @{}
$lineNumber = 0
foreach ($line in Get-Content -LiteralPath $Path -Encoding UTF8) {
$lineNumber++
$line = $line.Trim()
if (-not $line -or $line.StartsWith('#')) { continue }
if ($line -cnotmatch '^(VICTORY_[A-Z0-9_]+)\s*=\s*([0-9]+)$') {
throw "Invalid numeric setting at $($Path):$lineNumber"
}
$name = $Matches[1]
$value = $Matches[2]
if ($names -cnotcontains $name) {
throw "Unknown performance setting $name at $($Path):$lineNumber"
}
if ($settings.ContainsKey($name)) {
throw "Duplicate performance setting $name at $($Path):$lineNumber"
}
switch ($name) {
'VICTORY_WINDOW_KB' {
if (@('64','128','256','512','1024','2048','4096') -cnotcontains $value) {
throw "$name must be a power of two from 64 through 4096"
}
}
'VICTORY_SCRATCH_SPARE_MB' {
$mb = 0
if (-not [int]::TryParse($value, [ref]$mb) -or $mb -gt 512) {
throw "$name must be between 0 and 512"
}
$value = $mb.ToString()
}
'VICTORY_VRAM_TARGET_MB' {
$mb = 0
if (-not [int]::TryParse($value, [ref]$mb) -or ($mb -ne 0 -and ($mb -lt 1024 -or $mb -gt 65536))) {
throw "$name must be 0 (automatic) or between 1024 and 65536"
}
$value = $mb.ToString()
}
'VICTORY_BUFFERED_TITLE_READS' {
if (@('0','1') -cnotcontains $value) {
throw "$name must be 0 or 1"
}
}
}
$settings[$name] = $value
}
return $settings
}

$profilePath = Join-Path $root ('presets\' + $Preset.ToLowerInvariant() + '.env')
$settings = Read-PerformanceEnv $profilePath
foreach ($name in $names) {
if (-not $settings.ContainsKey($name)) {
throw "Incomplete preset: $name is missing from $profilePath"
}
}
$localPath = Join-Path $root '.env'
if (Test-Path -LiteralPath $localPath -PathType Leaf) {
$local = Read-PerformanceEnv $localPath
foreach ($name in $local.Keys) {
$settings[$name] = $local[$name]
}
}

Write-Host "VIctory performance preset: $Preset"
foreach ($name in $names) {
Write-Host "$name=$($settings[$name])"
}
if ($ShowSettings) { return }

if (-not $VictoryArgs -or $VictoryArgs.Count -eq 0) {
throw 'Specify -VictoryArgs, e.g. @("run", "D:\game\title.exe", "--execute")'
}
$exe = (Get-Item -LiteralPath $VictoryExe).FullName
if (-not (Test-Path -LiteralPath $exe -PathType Leaf)) {
throw "VIctory executable not found: $exe"
}

# Save and restore only the managed variables, including absent values.
$previous = @{}
foreach ($name in $names) {
$previous[$name] = [Environment]::GetEnvironmentVariable($name, 'Process')
}
try {
foreach ($name in $names) {
[Environment]::SetEnvironmentVariable($name, $settings[$name], 'Process')
}
& $exe @VictoryArgs
$code = $LASTEXITCODE
}
finally {
foreach ($name in $names) {
[Environment]::SetEnvironmentVariable($name, $previous[$name], 'Process')
}
}
exit $code
15 changes: 14 additions & 1 deletion xtask/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ pub fn check(path: &str, content: &[u8]) -> Vec<String> {
let mut problems = Vec::new();
let name = path.rsplit('/').next().unwrap_or(path);
let ext = name.rsplit_once('.').map(|(_, e)| e.to_ascii_lowercase());
let allowed = ALLOWED_NAMES.contains(&name)
// Only the checked-in, authored numeric presets are allowed, not
// arbitrary local .env files (which may contain private configuration).
let preset = matches!(path, "presets/default.env" | "presets/low.env" | "presets/high.env" | "presets/8gb.env" | "presets/12gb.env" | "presets/16gb.env");
let allowed = preset || ALLOWED_NAMES.contains(&name)
|| ext
.as_deref()
.is_some_and(|e| ALLOWED_EXTENSIONS.contains(&e));
Expand Down Expand Up @@ -230,6 +233,16 @@ mod tests {
super::run(&crate::workspace_root(), false).unwrap();
}

#[test]
fn only_named_env_presets_are_allowed() {
for path in ["presets/default.env", "presets/low.env", "presets/high.env", "presets/8gb.env", "presets/12gb.env", "presets/16gb.env"] {
assert!(check(path, b"VICTORY_WINDOW_KB=1024\n").is_empty());
assert!(!check(path, b"\0").is_empty());
}
assert!(!check(".env", b"VICTORY_WINDOW_KB=1024\n").is_empty());
assert!(!check("presets/local.env", b"KEY=secret\n").is_empty());
}

#[test]
fn accepts_source() {
assert!(check("crates/x/src/lib.rs", b"fn main() {}\n").is_empty());
Expand Down