feat: introduce hardware performance profiles #266
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/readmet3xt-lab--foxhound!266
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-266"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Cleovage on GitHub · 2026-12-01 05:33 UTC · original
Cleovage:main→main· +2470 −192 · 25 files · 67 commits · closed without mergingSummary
This PR introduces a universal hardware-adaptive performance tuning engine (
VICTORY_PERF_PROFILE) along with phased performance upgrades acrossvictory-core,victory-gpu,victory-formats,victory-hle,victory-shader,apps/victory,scripts/play-foxhound.ps1, andlauncher/Launcher.cs.Proven, bit-exact optimizations are enabled by default, while aggressive/experimental paths remain opt-in via individual
VICTORY_*environment switches or themax-fpsprofile.What Changed
1. Universal Hardware-Adaptive Tuning & Customization
PerfProfile,HardwareSpec, andPerfTuningincrates/victory-core/src/perf.rs(auto,balanced,low-vram,high-vram,amd-rdna,nvidia-rtx,max-fps,safe).crates/victory-gpu/src/perf.rs.victory.example.toml,victory config,scripts/play-foxhound.ps1, andlauncher/Launcher.cs(strictly C# 5 compatible).2. Phase 1 — CPU Submission, Guard Sharding & Dirty Tracking (
victory-gpu)GUARD_EPOCHS) and lock-free two-level atomic write-watch journal (ATOMIC_JOURNAL) inperf.rsandwatch.rs.GetWriteWatchrange coalescing (VICTORY_WATCH_COALESCE_KB).shadow::wide()plus configurable spin-wait (VICTORY_WIDE_SPIN_US).host.rsand a single-pass AVX2 fused diff-copy kernel (fused_diff_copy_dwords).VICTORY_HOT_RING_PROMOTE=1).3. Phase 2 — VRAM Pool Packing & Residency (
victory-gpu)VICTORY_POOL_PACK=1) and added segregated Small/Medium/Large VRAM pools (16 / 32 / 32–64 MiB,VICTORY_POOL_SEGREGATED=1) inpool.rs.VICTORY_ALLOCATOR_TRIM_S).VICTORY_VRAM_HEADROOM_MB) and heat-sorted PC-to-VRAM texture promotion (PC_TEXTURE_HEAT) inresidency.rsandresource.rs.4. Phase 3 — BCPack Decompression & Hybrid-CPU DirectStorage (
victory-formats,victory-hle)VICTORY_BCPACK_FAST=1) with bounded thread-local scratch buffer reuse (SCRATCH_RECORDS) and a decoupledsplit_lanes()helper inbcpack.rs, plus bit-exact parity unit tests against the reference decoder.keep_on_slow_cores,VICTORY_DSTORAGE_PIN_ECORES=1) and adaptive decompression yield pacing (VICTORY_DSTORAGE_YIELD_MS) incores.rsanddstorage.rs.5. Phase 4 — GPU Execution & Shader Optimizer (
victory-gpu,victory-shader)VICTORY_SEND_REBAR_FAST=1) inhost/send.rs.ComputeQueueandstrip_pixel_read_state(),VICTORY_ASYNC_QUEUE=1) inhost/two_queues.rsand wiredVICTORY_PLACED_READSthroughperf::tuning()inhost/card_steps.rs.HashMaps incrates/victory-shader/src/emit/bitcode/opt.rswith a deterministic zero-dependencyFastHasher.VICTORY_SHADER_OPT=autoand cache-key-isolatedVICTORY_SHADER_FAST_MATH=1incrates/victory-shader/src/emit/mod.rs.docs/performance-upgrades.md.Requested Verification Checklist (Please Run on Windows)
cargo check --workspace --all-targetscargo test --workspace(especiallyvictory-core::perf,victory-formats::bcpack,victory-gpu::perf,victory-gpu::pool,victory-gpu::host::two_queues)cargo clippy --workspace --all-targetslauncher/Launcher.cswith.NET Framework csc.exe(C# 5)auto/balanced,low-vram, andmax-fpsprofiles (and verifysafeprofile restores baseline behavior)@copilot-pull-request-reviewer[bot] on GitHub · 2026-12-01 05:33 UTC · original · reviewed
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
@copilot-pull-request-reviewer[bot] on GitHub · 2026-12-01 05:34 UTC · original · reviewed
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
@ -94,0 +105,4 @@let perf_profile = env("VICTORY_PERF_PROFILE").and_then(|v| v.to_str().and_then(crate::perf::PerfProfile::parse)).or_else(|| perf.profile.as_deref().and_then(crate::perf::PerfProfile::parse)).unwrap_or_default();@Copilot on GitHub · 2026-12-01 05:42 UTC · original
The TOML profile is parsed into
Config, but the runtime tuning singleton is still created exclusively fromPerfTuning::from_env;run()loadscfgwithout propagatingcfg.perf_profile(the only consumer here isshow_config). As a result,[performance].profile = 'safe'/'max-fps'has no effect when launching throughvictory, despite the documented configuration path. Initialize the GPU tuning from the loaded profile or otherwise make the config value part of the runtime profile resolution.@ -0,0 +271,4 @@PerfProfile::LowVram => {t.pool_segregated = true;t.pool_pack = true;t.texture_block_mb = 16;@Copilot on GitHub · 2026-12-01 05:42 UTC · original
The low-VRAM preset resolves the large texture block to 16 MiB, but this PR documents and exposes that preset as using 32 MiB blocks (
docs/performance-upgrades.md:25andlauncher/Launcher.cs:495). Selectinglow-vramtherefore does not apply the advertised profile. Either use the documented 32 MiB value here or update all of those user-facing descriptions to the intended 16 MiB behavior.@ -26,0 +32,4 @@fn fast_lanes_on() -> bool {static ON: OnceLock<bool> = OnceLock::new();*ON.get_or_init(|| std::env::var_os("VICTORY_BCPACK_FAST").is_none_or(|v| v != "0"))}@Copilot on GitHub · 2026-12-01 05:42 UTC · original
fast_lanes_on()reads onlyVICTORY_BCPACK_FAST, so it never consumes the resolvedPerfTuning::bcpack_fastvalue. In particular, selecting thesafeprofile leaves the fast decoder enabled unless a separate environment override is supplied, and the profile engine cannot control this switch as advertised. Route this decision through the profile resolution (while preserving an explicit override).@ -273,2 +285,3 @@"async compute queue planning and compute-queue infrastructure enabled (VICTORY_ASYNC_QUEUE=1)");truereturn true;@Copilot on GitHub · 2026-12-01 05:42 UTC · original
active()only changes the planning/logging branch inon().ComputeQueue::create,signal, andwait_forhave no production callers (the type is explicitlyallow(dead_code)), soVICTORY_ASYNC_QUEUE=1and themax-fpsprofile do not create or submit work to a compute queue; they continue using the existing direct-queue path. Either wire the queue into submission or keep this switch as plan-only instead of advertising it as enabled infrastructure.@ -0,0 +500,4 @@base_offset: usize,out_pairs: &mut Vec<(u32, u32)>,) -> usize {let len = src.len().min(staging.len()) & !3;@Copilot on GitHub · 2026-12-01 05:42 UTC · original
fused_diff_copy_dwordsis only referenced by its unit test; no production refresh path calls it, and the new host changes still use the existing refresh worker logic. Thusfused_diff_copyis reported as enabled by the profile, but the AVX2 fused diff/copy kernel never affects frame submissions. Integrate it into the dirty-copy path or remove it from the advertised tuning profile until it is wired.@ -2547,0 +2545,4 @@list.sort_unstable_by(|&a, &b| {crate::perf::PC_TEXTURE_HEAT.score(b).cmp(&crate::perf::PC_TEXTURE_HEAT.score(a))@Copilot on GitHub · 2026-12-01 05:42 UTC · original
The promotion sort reads
PC_TEXTURE_HEAT.score, butPcTextureHeat::touchhas no callers anywhere in the repository. All candidates therefore retain a zero score (or the same stale bucket score), so this path does not promote actively sampled textures first as documented. Record heat at the texture-sampling/descriptor path before relying on this ordering.@copilot-pull-request-reviewer[bot] on GitHub · 2026-12-01 05:42 UTC · original · reviewed
🟡 Changes recommended
Multiple moderate issues remain where documented performance profiles and switches are not propagated into or wired through the runtime paths that use them.
9 open issues
Review effort: Lite
@ -2106,0 +2109,4 @@let tuning = crate::perf::tuning();if tuning.guard_shards {crate::perf::GUARD_EPOCHS.bump(block);}@Copilot on GitHub · 2026-12-01 05:42 UTC · original
This only increments the new epoch table; no production path calls
GUARD_EPOCHS::lock_rangeor reads its epochs, while the actual guard state is still serialized by the globalGUARDSmutex inguards(). Therefore enablingguard_shardsdoes not shard guard operations or remove the contention described by this profile.@ -306,0 +313,4 @@}} else {parse_shader_opt(raw.as_deref())}@Copilot on GitHub · 2026-12-01 05:42 UTC · original
The profile resolver stores
shader_opt, but this function still resolves solely fromVICTORY_SHADER_OPT; settingVICTORY_PERF_PROFILE=auto,nvidia-rtx, orsafenever reaches this branch. The profile's advertised hardware-adaptive shader mode is therefore ignored unless a separate shader switch is set. Use the resolved profile setting here, with the explicit shader environment variable remaining the higher-priority override.@ -306,0 +322,4 @@/// never collide with exact shader cache entries.pub fn fast_math() -> bool {static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();*ON.get_or_init(|| std::env::var_os("VICTORY_SHADER_FAST_MATH").is_some_and(|v| v == "1"))@Copilot on GitHub · 2026-12-01 05:42 UTC · original
The new fast-math switch is only read here and included in
translation_fingerprint; there are no lowering/optimization call sites that consultfast_math(). ConsequentlyVICTORY_SHADER_FAST_MATH=1changes cache identity but produces the same shader as the exact path, so the documented fast-math optimization is not actually enabled.@bannnned on GitHub · 2026-12-01 07:24 UTC · original · reviewed
I tested
89e5266on Windows x64 with Rust 1.98.1 and MSVC. I left the build and CI failures inline, along with a reproducible write-watch regression under the default settings. The write-watch regression test passes on the base commit and with coalescing disabled. The C# launcher build and the BCPack parity tests passed.@ -194,2 +192,2 @@}ahead.truncate(out + 1);let gap_pages = crate::perf::tuning().watch_coalesce_kb / (PAGE >> 10);crate::perf::coalesce_watch_ranges(ahead, gap_pages);@bannnned on GitHub · 2026-12-01 07:24 UTC · original
[P1] Keep journal coverage limited to queried pages.
merge_aheadruns on ranges that have already been queried. Bridging a gap here makesahead_containstreat that gap as queried, sowrites()skipsGetWriteWatchfor it. I reproduced this on Windows with three write-watched pages. After querying the two outer pages separately throughask_rest, a write to the middle page was missing fromwrites(). The same test passed on the base commit and withVICTORY_WATCH_COALESCE_KB=0. Please keep exact coverage in the journal and bridge gaps only when the actual kernel query covers them.@ -12,6 +12,7 @@ blake3.workspace = truezlib-rs.workspace = truetracing.workspace = trueanyhow.workspace = truevictory-core.workspace = true@bannnned on GitHub · 2026-12-01 07:24 UTC · original
[P1] Update
Cargo.lockfor the new dependency. CI and the Windows package build use--locked. On a fresh checkout of this head,cargo check --locked --workspace --all-targetsfails before compilation because thevictory-gpuentry inCargo.lockis missingvictory-core.@ -2547,0 +2544,4 @@// Promote hottest actively sampled PC textures back into VRAM first.list.sort_unstable_by(|&a, &b| {crate::perf::PC_TEXTURE_HEAT.score(b)@bannnned on GitHub · 2026-12-01 07:24 UTC · original
[P1] Use the same ID type at both
scorecall sites. After refreshing the lockfile locally, Windows x64 MSVC reportedE0308on both calls. The promotion list storesusizeIDs andPcTextureHeat::scoreacceptsu64. Please align the types at the API boundary or convert both IDs explicitly.@ -0,0 +707,4 @@#[test]fn atomic_journal_tracks_epochs_lock_free() {let j = AtomicJournal::new();@bannnned on GitHub · 2026-12-01 07:24 UTC · original
[P1] Keep the journal table off the test thread's stack.
AtomicJournal::new()constructs a 4 MiB pointer table in this test's local variable. With the default test settings on Windows, this aborts the test executable withSTATUS_STACK_OVERFLOW(0xc00000fd). All sixperftests passed withRUST_MIN_STACK=16777216as a control. A test-localstatictable would follow the existingLandedtest's approach.@ -0,0 +484,4 @@/// immediately instead of tail-stalling the worker pool.pub fn sort_lpt_refreshes<T>(items: &mut [(T, usize, usize)]) {if items.len() >= 4 && tuning().wide_lpt_schedule {items.sort_unstable_by(|a, b| b.2.saturating_sub(b.1).cmp(&a.2.saturating_sub(a.1)));@bannnned on GitHub · 2026-12-01 07:24 UTC · original
Fix the warnings that fail CI. After fixing the lockfile and the
scoreargument types locally, both CI variants of Clippy still failed with-D warnings. This sort triggersclippy::unnecessary_sort_byand can usesort_unstable_by_keywithReverse. The newstrip_pixel_read_statealso triggersdead_codein the library build.@ -152,0 +164,4 @@let fit = spare.iter().enumerate().filter(|(_, m)| m.size >= size && m.on_bar == want_bar)@bannnned on GitHub · 2026-12-01 07:24 UTC · original
[P2] Reuse upload buffers when ReBAR is unavailable. The pool lookup filters on
want_barbefore checkingGPUUploadHeapSupported. If ReBAR is disabled or card allocation fails, the fallback buffer comes back withon_bar=falseand the next BAR-requested submission excludes it again. That creates fresh buffers even when an existing system-memory upload buffer fits. Please derive the preferred pool from the device capability and allow the ordinary pool on the allocation fallback path.@ -0,0 +112,4 @@let end = desc.Description.iter().position(|&c| c == 0).unwrap_or(desc.Description.len());let name = String::from_utf16_lossy(&desc.Description[..end]);let vendor = GpuVendor::from_pci_id(desc.VendorId);if best.as_ref().is_none_or(|(b, ..)| vram_mb > *b) {@bannnned on GitHub · 2026-12-01 07:24 UTC · original
[P2] Resolve the profile for the adapter the game actually uses. This probe always selects the adapter with the most dedicated memory. The existing D3D12 adapter picker honors
VICTORY_ADAPTER, so explicitly selecting a smaller card can apply another card's VRAM thresholds.victory configalso resolves fromHardwareSpec::default()and can report a differentautoresult. Please use the same adapter selection and resolved settings for both the runtime and the diagnostic output.@readmet3xt-lab on GitHub · 2026-12-01 10:50 UTC · original
Thanks for the write-up. This cannot go in as it is, for three reasons:
victory-gpugains a dependency onvictory-core, butCargo.lockis not updated, so everycargo ... --lockedstep stops at once ("cannot update the lock file ... because --locked was passed").What would be welcome: one change per pull request, each building with
--lockedand passingcargo clippy --workspace --all-targets --locked -- -D warnings(with and without--all-features) andcargo test --workspace --locked, with defaults unchanged unless a measurement in the game says otherwise. The fullest-block packing overlaps #276, which is being tested now. The profile selector alone (no default changes) would be a good first one.@hexgeon1 on GitHub · 2026-12-01 10:58 UTC · original
Hot rings (
VICTORY_HOT_RING_PROMOTE) multiply buffer uploads by ~15x and drop gameplay to 3-4 fpsTested on an RTX 3090 (24 GB), Ryzen 7 5700X, Windows 10 22H2, with this PR merged onto
main(297f58a) together with the other open PRs up to #277. Same place in the game for every run, Series X profile, 1440p, DLSS off.hot_ringhost copies in the card's memory)The profile makes no difference; turning Experimental speedups on does. The extra time on the submitting thread is almost all buffer refreshes and copies in the card's memory, while the GPU sits idle.
Then hot rings alone were forced off (
hot_ring=0whatever the profile or launcher asks), every other switch left as it was:hot_ringSo hot rings account for the whole slowdown. With them off, the other experimental switches bring no gain here; the submitting thread is 10-30 ms slower with them than with Experimental speedups off.
Cause, from the code:
Guards::rests()returns true for a promoted block, soprotect()skips it and it stays unguarded. An unguarded block is never known to be clean, so it is sent up whole at every asking (~45 flushes a frame here). It is the failure the comment aboveprotect()already describes for unguarded views ("copied again at every asking ... 2.4 to 3.4 GB of copies a frame, 2 fps").is_hot()demotes afterHOT_DEMOTE_QUIET_FRAMES(60) frames without a write fault, but an open block cannot fault. A busy ring is demoted, guarded, faults, and is promoted again 3 frames later, so it is unguarded ~95 % of the time.What it saves is a few dozen faults and re-guards a frame; what it costs is hundreds of MB of uploads. To pay off, an open block would need another way to tell what changed (a write watch, say) instead of being treated as written.
Also in this PR, found while building it on Windows:
resource.rs:PC_TEXTURE_HEAT.score(b)passes the list'susizewherescore()takesu64, sovictory-gpudoes not compile on Windows (E0308). Nothing callsPC_TEXTURE_HEAT.touch(), so every score is 0 and the sort is a no-op.Cargo.locklacks the newvictory-gpu->victory-coredependency, socargo build --locked(asbuild-launcher.ps1 -Packageruns it) fails.perf::tests::atomic_journal_tracks_epochs_lock_freeoverflows the test thread's stack:AtomicJournalis 2^19 pointers (4 MiB) built on the stack.merge_aheadnow joins asked ranges acrossVICTORY_WATCH_COALESCE_KBgaps, so pages in the gaps count as asked although the write watch was never asked about them.The launcher's "Hot rings + placed reads (lower CPU stalls)" choice is the one that turns this on.
@Fernando-Laydner on GitHub · 2026-12-01 21:30 UTC · original · edited 2026-12-01 21:34 UTC
We tested a related write-watch change on an RTX 4050 Laptop (6 GB VRAM), i7-13620H, 32 GB RAM, Windows 11. At
89e5266e7, this PR applieswatch_coalesce_kbinmerge_ahead. The loop inask_aheadthat groups ranges for Windows queries still uses an 8 MiBAHEAD_GAP.On our fork, we tried a smaller gap only for submission-wide queries from
ask_once. Standalone queries kept the 8 MiB gap. A regression test wrote to a page inside a skipped gap and verified that a later individual query still detected the write.Median write-watch time fell from 6.1 to 4.5 ms/frame at 512 KiB. These were single runs on our custom fork in the Series S prologue, DLSS Performance, frame generation off. An independent repeat on upstream would help determine whether this is worth exposing as an option.
For the Full-log comparison, we aligned runs on the prologue loading transition, skipped five seconds, and kept complete reporting intervals from the next 45 seconds. That gave about 44 seconds of gameplay per run. We calculated base FPS as total frames divided by elapsed time.
For a repeat, I'd run 8 MiB / 512 KiB / 8 MiB on one binary with the same save, cache warm-up and logging cadence. Two additional counters would help explain the result: the number of Windows write-watch queries and the total bytes those queries span. Together with write-watch time and long-frame counts, they would show whether scanning fewer unused pages offsets the cost of extra calls.
Buffer budget on a 6 GB GPU. A fixed 512 MiB buffer ceiling produced 8.41 base FPS, with 15.9% of frames over 150 ms. On automatic, the effective ceiling was 927 MiB: 11.48 FPS and 3.8% over 150 ms. A second 512 MiB run reached 6.91 FPS. External memory sampling differed between runs, so the exact effect size is uncertain. Before setting a fixed ceiling for 6 GB adapters, we'd benchmark it against the automatic budget and log the effective ceiling in both runs.
Why compare frame delivery as well as CPU preparation time. In a separate write-watch experiment, querying only uncovered ranges reduced median preparation time from 56.5 to 51.5 ms/frame. Yet base FPS fell from 13.02 to 12.42 and presents over 200 ms rose from 3 to 11. Looking only at median preparation time would have ranked those runs in the opposite order.
For the Full-log comparison, we aligned runs on the loading pause before the prologue, skipped five seconds, and kept complete reporting intervals within the next 45 seconds. We calculated base FPS as total frames divided by elapsed time. Reporting that alongside the percentage of frames over 150 ms, the count over 200 ms, and median write-watch and preparation times would make low-VRAM results easier to compare across machines.
Pull request closed