Skip to content
Merged
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
3 changes: 2 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ It is a fork of [fxceless/victory-gta6](https://github.com/fxceless/victory-gta6
| `scripts/rename-from-upstream.ps1` | renames code taken from upstream (`victory` to `leonida`) |
| `run-gta6.ps1` | builds and starts the game with the frame-rate switches for this PC's graphics card |
| `measure-gta6.ps1`, `start-measure.cmd` | the same with the diagnostics build and logs; a double-click start for testers |
| `gpu-profiles.json`, `scripts/leonida-settings.ps1` | the run scripts' switches by graphics card, and the loader that applies them |
| `gpu-profiles.json`, `leonida-core::graphics` | measured profiles embedded in the executable, and native settings resolution |
| `scripts/leonida-settings.ps1` | launcher queries and reports for the native graphics settings |
| `scripts/measure-run.ps1`, `scripts/make-view.ps1` | one unattended diagnostics run with frame shots and a summary of its figures; small JPEG copies of shots |
| `docs/` | architecture, asset policy, ray tracing, the fork's measurement log |
| `.claude/skills/` | agent skills, copied in `.agents/skills/` for other agents; [AGENTS.md](AGENTS.md) lists them. Edit both copies |
Expand Down
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ clap = { version = "4.6.9", features = ["derive"] }
tracing = "0.1.44"
tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
serde = { version = "1.0.229", features = ["derive"] }
serde_json = "1.0"
toml = "1.2.2"
object = { version = "0.41.0", default-features = false, features = ["read_core", "pe", "coff", "archive", "std"] }
windows-sys = "0.61.2"
Expand Down
47 changes: 39 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ It is a fork of [victory-gta6](https://github.com/fxceless/victory-gta6), itself
**Made for everyone's PC, not just ours.** Many projects like this are tuned on the developer's own machine and
nowhere else. Leonida Legacy aims to run as well as it can on your hardware, and to be usable by people who can't
code and don't have an AI assistant to help them. The run scripts pick their settings for your graphics card
code and don't have an AI assistant to help them. The program picks its settings for your graphics card
(`gpu-profiles.json`), so a change that helps one card is not forced on everyone. If it runs badly on your PC, tell us
your CPU, GPU, driver version and frame rate (see [Contact](#contact)); that is how new cards get a profile.

## Status

**Not playable yet: 2 to 4 frames per second by default, and shadowed areas are black.** Tested on Windows 11 Pro,
**Not playable yet: frame rates are low, and shadowed areas are black.** Tested on Windows 11 Pro,
AMD Ryzen 7 7800X3D, NVIDIA RTX 3080 12 GB, 32 GB RAM, Series X profile. The world frame rates below were measured
by victory-gta6 on an RTX 4070 and have not been measured again on this machine yet.

Expand All @@ -62,7 +62,7 @@ by victory-gta6 on an RTX 4070 and have not been measured again on this machine
| Saves | the game autosaves a checkpoint and loads it again |
| First gameplay scene | renders characters, textures, sky and the sunlit exterior; HUD, pause menu and pad input work |
| Light in shadow | missing: ray-traced bounce light and shadows don't run yet, so anything out of direct sun is black |
| Frame rate in the world | 2-4 fps by default; about 10 fps in the first rooms with the newer switches, all off by default |
| Frame rate in the world | Earlier measurements: 2-4 fps without the newer switches, about 10 fps in the first rooms with them; the measured base profile now applies to direct launches too |

Known problems:

Expand Down Expand Up @@ -91,17 +91,47 @@ The first run asks for the folder of your copy of the game (the one with `Micros
`leonida.toml`, which git ignores. `leonida config` shows what is set, and `leonida.example.toml` lists the other
settings.

`run-gta6.ps1` does the build and the run in one step, with the frame-rate switches measured for your graphics card
(`gpu-profiles.json`; they are off by default in the program). It asks for the game folder too, and whether to
remember it:
`run-gta6.ps1` does the build and the run in one step. The program itself selects the frame-rate settings from
`gpu-profiles.json`, including when launched directly through Wine. It asks for the game folder too, and whether
to remember it:

```powershell
powershell -ExecutionPolicy Bypass -File .\run-gta6.ps1
```

`measure-gta6.ps1` does the same with the diagnostics build, the frame log and the card meter on, and saves
everything the game prints to `%LOCALAPPDATA%\leonida\logs`. `-SpeedSwitches off` runs it without the frame-rate
switches, for a comparison in the same place.
switches or your graphics overrides, for a comparison in the same place.

### Graphics settings

The measured base profile is automatic. Experimental profiles such as `card-windows` remain opt-in.
To change a setting, add a `[graphics]` section to your `leonida.toml`; the example file lists every option:

```toml
[graphics]
async_submit = false
queue2 = 0
```

Only the options you write change. To disable automatic profiles, use `profiles = ["none"]` (or `profiles = []`)
in that section. Other settings you explicitly write still apply. To choose profiles yourself, use a list such
as `profiles = ["base", "my-test"]`; named profiles include the base settings and apply in catalog order.

Environment overrides take precedence over TOML settings, which take precedence over profiles. For example,
an explicit `LEONIDA_QUEUE2=0` still wins. `LEONIDA_PROFILE` overrides the profile list, except the existing
diagnostics value `1`, which enables the CPU sampler and leaves graphics selection to the config. Run
`leonida config --graphics` to see the selected adapter, profiles, effective values and their sources as JSON;
it needs no game files. The scripts use this same result and leave your environment overrides intact.

The standard catalog is built into the executable. Put local profiles in `gpu-profiles.local.json` beside
your selected config file (the current folder when no config exists). They apply after the built-in catalog.
Profiles match the adapter used by Direct3D, including Wine's reported adapter identity. If discovery fails,
only profiles without card-specific conditions match. A local profile can cancel an earlier profile value
with `null`, but cannot override an explicit TOML or environment value. Game/cache/data paths, logging, RenderDoc startup
and WARP selection remain separate from graphics profiles.
GPU name patterns support case-insensitive `*`, `?`, `[abc]` and `[a-z]`; malformed patterns and unsupported
backtick escapes or negated character classes report an error. Unknown profile names also report an error.

### Testing for the project, with no programming experience

Expand Down Expand Up @@ -146,7 +176,8 @@ An experimental optimization reduces GPU work before individual indirect draws.
RTX 5090 benchmark by 19.4%; gameplay and other cards are unmeasured, so it stays off by default.
[The measurements and limits are here](docs/fork-notes.md#newest-2026-11-26).

To compare it using your configured game, create `gpu-profiles.local.json` with the following content. If
To compare it using your configured game, create `gpu-profiles.local.json` beside your selected config file
(normally in the checkout) with the following content. If
the file already exists, add only this profile object to its existing `profiles` array:

```json
Expand Down
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ The goal: a console-like experience on PC. The game starts straight into play, h
|----|------|-------|-------|
| U-1 | One step from download to playing: build, warm the cache (P-7) and run, with no terminal knowledge needed. | `run-gta6.ps1` | - |
| U-2 | Fullscreen and borderless window, and a choice of output resolution. | `leonida-gpu` | GPU |
| U-3 | The frame-rate switches as settings in `leonida.toml` instead of environment variables, with the tested ones on by default. Since #24 the run scripts pick them by graphics card from `gpu-profiles.json`; this item moves that choice into the program itself. | `leonida-core` (config) | - |
| U-4 | Pad first: after launch, the game is playable without touching the keyboard. | `leonida-hle` (input) | game |

## Code health
Expand Down
4 changes: 4 additions & 0 deletions apps/leonida/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ memchr.workspace = true
clap.workspace = true
walkdir.workspace = true

[dev-dependencies]
serde_json.workspace = true
tempfile.workspace = true

[features]
# Debug-level logs and the debugging switches (frame capture, stack dumps,
# the host debug layer, scripted keys). Off in a plain release build.
Expand Down
126 changes: 126 additions & 0 deletions apps/leonida/src/graphics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//! Resolve graphics settings before the runtime caches any switches.
use anyhow::Result;
use leonida_core::Config;
use leonida_core::graphics::{Adapter, Plan};

pub fn plan(config: &Config) -> Result<Plan> {
let environment = leonida_core::graphics::snapshot_environment()?;
let gpu = match leonida_hle::modules::d3d12x::graphics_adapter() {
Ok(adapter) => Some(Adapter {
name: adapter.name,
vendor: match adapter.vendor_id {
0x10de => "nvidia",
0x1002 => "amd",
0x8086 => "intel",
_ => "other",
}
.into(),
vram_mb: adapter.vram_mb,
}),
Err(error) => {
eprintln!("graphics adapter unavailable ({error}); matching only general profiles");
None
}
};
config.graphics_plan(gpu, &environment)
}

/// The executable calls this before loading a title or creating a translation
/// host. Existing GPU consumers keep reading their switches in one place.
#[cfg(windows)]
pub fn initialize(config: &Config) -> Result<()> {
let plan = plan(config)?;
apply(&plan);
let profiles = if plan.profiles.is_empty() {
"none".to_owned()
} else {
plan.profiles.join(", ")
};
eprintln!(
"graphics card: {}; profiles: {profiles}",
plan.gpu.as_ref().map_or("unknown", |gpu| gpu.name.as_str())
);
Ok(())
}

#[cfg(windows)]
fn apply(plan: &Plan) {
for (key, value) in &plan.settings {
// Explicit environment values already have precedence in the plan.
// Leave them alone, including empty values used to disable a switch.
if plan
.sources
.get(key)
.is_some_and(|source| source == "environment")
{
continue;
}
// SAFETY: environment updates are thread-safe on Windows. This bridge
// is Windows-only and runs before the GPU's workers and OnceLocks; the
// resolver rejects NULs and invalid variable names before this point.
unsafe { std::env::set_var(key, value) };
}
}

#[cfg(not(windows))]
pub fn initialize(config: &Config) -> Result<()> {
// The native Linux frontend can inspect files but cannot run the Windows
// GPU backend. Validate its settings without mutating a Unix environment.
let _ = plan(config)?;
Ok(())
}

#[cfg(all(test, windows))]
mod tests {
use super::*;
use std::process::Command;

#[test]
fn startup_applies_settings_without_replacing_explicit_values() {
const CHILD: &str = "LEONIDA_GRAPHICS_TEST_CHILD";
if std::env::var_os(CHILD).is_some() {
let config = Config::load().unwrap();
initialize(&config).unwrap();
assert_eq!(std::env::var("LEONIDA_ASYNC_SUBMIT").unwrap(), "0");
assert_eq!(std::env::var("LEONIDA_QUEUE2").unwrap(), "2");
assert_eq!(std::env::var("LEONIDA_INDIRECT_GATHER").unwrap(), "1");
assert_eq!(std::env::var("LEONIDA_JOIN_PARTS").unwrap(), "");
assert!(std::env::var_os("LEONIDA_CARD_WINDOWS_MB").is_none());
eprintln!("graphics startup: config, profile and explicit overrides applied");
return;
}

let dir = tempfile::tempdir().unwrap();
let config = dir.path().join("settings.toml");
std::fs::write(&config, "[graphics]\nasync_submit = false\nqueue2 = 3\n").unwrap();
let mut child = Command::new(std::env::current_exe().unwrap());
for (key, _) in std::env::vars_os() {
if key
.to_string_lossy()
.to_ascii_uppercase()
.starts_with("LEONIDA_")
{
child.env_remove(key);
}
}
let output = child
.args([
"--exact",
"graphics::tests::startup_applies_settings_without_replacing_explicit_values",
"--nocapture",
])
.env(CHILD, "1")
.env("LEONIDA_CONFIG", config)
.env("LEONIDA_QUEUE2", "2")
.env("LEONIDA_JOIN_PARTS", "")
.current_dir(dir.path())
.output()
.unwrap();
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(output.status.success(), "{stderr}");
assert!(
stderr.contains("graphics startup: config, profile and explicit overrides applied")
);
}
}
12 changes: 11 additions & 1 deletion apps/leonida/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! the user's cache directory (outside the repository).

mod census;
mod graphics;
mod inspect;
mod run;
mod shader;
Expand Down Expand Up @@ -120,6 +121,9 @@ enum Command {
/// First save this folder as the game folder in leonida.toml.
#[arg(long)]
game_dir: Option<PathBuf>,
/// Print the effective graphics settings as JSON, without running a title.
#[arg(long, conflicts_with = "game_dir")]
graphics: bool,
},
}

Expand Down Expand Up @@ -168,6 +172,7 @@ fn main() -> Result<()> {
jobs,
warm,
} => {
graphics::initialize(&leonida_core::Config::load()?)?;
// The warm-up keys its translations on the same host facts a run
// gets from the device; the switches below still override them.
if warm.is_some() && !leonida_hle::modules::d3d12x::probe_translation_host() {
Expand Down Expand Up @@ -200,7 +205,12 @@ fn main() -> Result<()> {
};
run::run(&exe, unimplemented, strict, execute, console)
}
Command::Config { game_dir } => {
Command::Config { game_dir, graphics } => {
if graphics {
let plan = graphics::plan(&leonida_core::Config::load()?)?;
println!("{}", plan.to_json()?);
return Ok(());
}
if let Some(dir) = game_dir {
check_game_dir(&dir)?;
let saved = leonida_core::Config::save_game_dir(&dir)?;
Expand Down
1 change: 1 addition & 0 deletions apps/leonida/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn run_title(
// A title that relaunched itself: the old process must be gone first.
leonida_hle::modules::lifecycle::wait_for_previous();
let cfg = leonida_core::Config::load()?;
crate::graphics::initialize(&cfg)?;
let original = std::fs::read(exe).with_context(|| format!("reading {}", exe.display()))?;
let prepared = leonida_loader::prepare(&original)?;
let hash = prepared.original_hash.to_hex();
Expand Down
Loading