Files: a title's read-only opens go through the host file cache (VICTORY_FILE_CACHE=0: unbuffered, as before) #423

Open
github-bot wants to merge 1 commit from github-bot/gh-423 into main AGit
Owner

@⁠Jesper-Andersson on GitHub · 2026-11-27 02:26 UTC · original
Jesper-Andersson:worktree-file-cache → main · +67 −0 · 1 files · 1 commits · open

Fixes #422.

The title opens its packs read-only with FILE_FLAG_NO_BUFFERING, and files::CreateFileW (crates/victory-hle/src/modules/files.rs:263) passes the flag on to the host unchanged. On Windows the flag keeps every read of those files out of the system file cache, so every launch reads the same bytes from the drive again. On an RTX 2070 SUPER / 32 GB PC with the game on a SATA SSD, letting those opens use the cache cut launch to the title-screen logo from 34-37 s to 21-23 s.

Change

  • files::host_flags (new) is called by CreateFileW and CreateFileA before the host's open. An open whose access is exactly GENERIC_READ and which is not overlapped loses FILE_FLAG_NO_BUFFERING (files::dropped_flags). A buffered handle returns the same bytes for the same aligned reads, and also takes unaligned ones, which an unbuffered handle refuses. An overlapped open keeps the flag: ReadFileScatter needs a handle with both, and a buffered handle may finish an overlapped read inside the call.
  • The rule is the one in Marvisak/VIctory#2427 by imjustprism (commit 79fd6c2, rebased as Marvisak/VIctory#2667), split out of that four-part PR on its own, as its triage asked, with the timing that was missing.
  • Unlike #2427, CreateFileA gets the same rule (it goes to the host's CreateFileW anyway), and the title's unbuffered opens are logged (the first 8, then every 256th), so a log shows whether the switch can change anything.
  • Switch: VICTORY_FILE_CACHE=0 keeps the flag, as before. On by default.

Where it does nothing

  • Opens with any write access, overlapped opens and opens without the flag: unchanged (read_only_opens_lose_no_buffering).
  • CreateFile2 (used by Bink) keeps its flags. They sit in a structure of the caller's.
  • DirectStorage reads: dstorage.rs opens handles of its own, which already go through the cache by default (VICTORY_DSTORAGE_IO=handles).

Measured

RTX 2070 SUPER 8 GB (driver 621.14), Ryzen 7 5800X, 32 GB, Windows 11, game on a SATA SSD (Samsung 870 QVO). Local branch test-perf @ 64c3742 plus this commit (the numbers come from that branch, not from main), diag build, scripts\play.ps1 -NoWarm, Series S, DLSS, intro movies skipped. Four launches one after another, each closed at the title screen. Timed from the first log line to the start of the 2560x1440 logo movie, which comes before the title waits for a key.

Run VICTORY_FILE_CACHE to the logo of which: first movie -> logo
A1 0 (as before) 36.8 s 27.9 s
A2 0 (as before) 34.3 s 25.3 s
B1 1 22.8 s 14.7 s
B2 1 21.1 s 15.5 s

The log showed the title opening 8 files unbuffered, all access=0x80000000, flags=0x20000000, none overlapped. Each run logged the same 8 refused compute pipelines this card always has (#70), and nothing new. B1, the first launch with the cache on, was already as fast as B2. Frame times in game are not what this changes, and they were not compared.

Checks

  • cargo test -p victory-hle --locked: 160 passed, 2 ignored (new: modules::files::tests::read_only_opens_lose_no_buffering)
  • cargo test -p victory-hle --all-features --locked -- --test-threads=1: 160 passed, 2 ignored
  • cargo clippy --workspace --all-targets --locked -- -D warnings: fails on errors already on main (014d52d), none in changed code: 4 transmute used without annotations in crates/victory-loader/src/descriptor_sites.rs, and in victory-gpu (list.rs totals unused, host/panel.rs, host/place.rs, watch.rs, and with --all-features also texture.rs, host/rtstamps.rs). cargo clippy -p victory-hle --all-targets [--all-features]: no warnings in victory-hle
  • cargo xtask policy: 272 files ok
  • In game: launched to the title screen 4 times, as above. Not played into the world.

Not checked

  • A hard drive, and a cold launch after a reboot (here, the file cache only held what earlier runs had read).
  • Loading into the world, AMD.
  • Linux/Proton: probably no change. UwUCammie checked Wine 11.22 (UwUCammie/victory-amd@e036355b): FILE_FLAG_NO_BUFFERING doesn't reach the host as O_DIRECT, so both kinds of open already read through Linux's page cache.
  • The most useful check: the same A/B on a hard drive, where an unbuffered read costs the most.
  • Marvisak/VIctory#2427 and #2667 (the original, bundled with a pool for small buffers and two DirectStorage changes). This PR is only its files.rs part.
  • No upstream PR touches these opens. #258 changes files.rs, but only how .. is resolved in paths.

This change was made with AI assistance (Claude Code).

**@⁠Jesper-Andersson** on GitHub · 2026-11-27 02:26 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/423) `Jesper-Andersson:worktree-file-cache` → `main` · +67 −0 · 1 files · 1 commits · open Fixes #422. The title opens its packs read-only with `FILE_FLAG_NO_BUFFERING`, and `files::CreateFileW` (`crates/victory-hle/src/modules/files.rs:263`) passes the flag on to the host unchanged. On Windows the flag keeps every read of those files out of the system file cache, so every launch reads the same bytes from the drive again. On an RTX 2070 SUPER / 32 GB PC with the game on a SATA SSD, letting those opens use the cache cut launch to the title-screen logo from 34-37 s to 21-23 s. ## Change - `files::host_flags` (new) is called by `CreateFileW` and `CreateFileA` before the host's open. An open whose access is exactly `GENERIC_READ` and which is not overlapped loses `FILE_FLAG_NO_BUFFERING` (`files::dropped_flags`). A buffered handle returns the same bytes for the same aligned reads, and also takes unaligned ones, which an unbuffered handle refuses. An overlapped open keeps the flag: `ReadFileScatter` needs a handle with both, and a buffered handle may finish an overlapped read inside the call. - The rule is the one in Marvisak/VIctory#2427 by imjustprism (commit 79fd6c2, rebased as Marvisak/VIctory#2667), split out of that four-part PR on its own, as its triage asked, with the timing that was missing. - Unlike #2427, `CreateFileA` gets the same rule (it goes to the host's `CreateFileW` anyway), and the title's unbuffered opens are logged (the first 8, then every 256th), so a log shows whether the switch can change anything. - Switch: `VICTORY_FILE_CACHE=0` keeps the flag, as before. On by default. ## Where it does nothing - Opens with any write access, overlapped opens and opens without the flag: unchanged (`read_only_opens_lose_no_buffering`). - `CreateFile2` (used by Bink) keeps its flags. They sit in a structure of the caller's. - DirectStorage reads: `dstorage.rs` opens handles of its own, which already go through the cache by default (`VICTORY_DSTORAGE_IO=handles`). ## Measured RTX 2070 SUPER 8 GB (driver 621.14), Ryzen 7 5800X, 32 GB, Windows 11, game on a SATA SSD (Samsung 870 QVO). Local branch `test-perf` @ 64c3742 plus this commit (the numbers come from that branch, not from `main`), diag build, `scripts\play.ps1 -NoWarm`, Series S, DLSS, intro movies skipped. Four launches one after another, each closed at the title screen. Timed from the first log line to the start of the 2560x1440 logo movie, which comes before the title waits for a key. | Run | `VICTORY_FILE_CACHE` | to the logo | of which: first movie -> logo | |---|---|---|---| | A1 | 0 (as before) | 36.8 s | 27.9 s | | A2 | 0 (as before) | 34.3 s | 25.3 s | | B1 | 1 | 22.8 s | 14.7 s | | B2 | 1 | 21.1 s | 15.5 s | The log showed the title opening 8 files unbuffered, all `access=0x80000000`, `flags=0x20000000`, none overlapped. Each run logged the same 8 refused compute pipelines this card always has (#70), and nothing new. B1, the first launch with the cache on, was already as fast as B2. Frame times in game are not what this changes, and they were not compared. ## Checks - `cargo test -p victory-hle --locked`: 160 passed, 2 ignored (new: `modules::files::tests::read_only_opens_lose_no_buffering`) - `cargo test -p victory-hle --all-features --locked -- --test-threads=1`: 160 passed, 2 ignored - `cargo clippy --workspace --all-targets --locked -- -D warnings`: fails on errors already on `main` (014d52d), none in changed code: 4 `transmute used without annotations` in `crates/victory-loader/src/descriptor_sites.rs`, and in `victory-gpu` (`list.rs` `totals` unused, `host/panel.rs`, `host/place.rs`, `watch.rs`, and with `--all-features` also `texture.rs`, `host/rtstamps.rs`). `cargo clippy -p victory-hle --all-targets [--all-features]`: no warnings in `victory-hle` - `cargo xtask policy`: 272 files ok - In game: launched to the title screen 4 times, as above. Not played into the world. ## Not checked - A hard drive, and a cold launch after a reboot (here, the file cache only held what earlier runs had read). - Loading into the world, AMD. - Linux/Proton: probably no change. UwUCammie checked Wine 11.22 (UwUCammie/victory-amd@e036355b): `FILE_FLAG_NO_BUFFERING` doesn't reach the host as `O_DIRECT`, so both kinds of open already read through Linux's page cache. - The most useful check: the same A/B on a hard drive, where an unbuffered read costs the most. ## Related - Marvisak/VIctory#2427 and #2667 (the original, bundled with a pool for small buffers and two DirectStorage changes). This PR is only its `files.rs` part. - No upstream PR touches these opens. #258 changes `files.rs`, but only how `..` is resolved in paths. This change was made with AI assistance (Claude Code).
After Marvisak/VIctory#2427 by imjustprism (79fd6c2), its files.rs part only: CreateFileW and
CreateFileA opens with access exactly GENERIC_READ and not overlapped lose FILE_FLAG_NO_BUFFERING,
so the title's packs are read through the system file cache. The title's unbuffered opens are
logged (first 8, every 256th) so a run with the switch off says whether it can change anything.
RTX 2070 SUPER, 32 GB, SATA SSD: launch to the title-screen logo 34-37 s -> 21-23 s.

Fixes #422.

This change was made with AI assistance (Claude Code).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 02:29:43 +00:00
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-27 02:55 UTC · original

I checked the host I/O path on Wine 11.22. Two generated files returned the same bytes from aligned 4 KiB reads. FileModeInformation distinguished the ordinary and FILE_FLAG_NO_BUFFERING opens (0x20 and 0x28). Their Linux file descriptors had identical open flags, and neither used O_DIRECT on this setup. So the Windows title-logo result may not carry over to this Wine path. Probe and result

**@⁠UwUCammie** on GitHub · 2026-11-27 02:55 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/423#issuecomment-7208548150) I checked the host I/O path on Wine 11.22. Two generated files returned the same bytes from aligned 4 KiB reads. `FileModeInformation` distinguished the ordinary and `FILE_FLAG_NO_BUFFERING` opens (`0x20` and `0x28`). Their Linux file descriptors had identical open flags, and neither used `O_DIRECT` on this setup. So the Windows title-logo result may not carry over to this Wine path. [Probe and result](https://github.com/UwUCammie/victory-amd/commit/e036355b)
Author
Owner

@⁠Erick-Franco on GitHub · 2026-11-27 03:07 UTC · original · approved these changes

**@⁠Erick-Franco** on GitHub · 2026-11-27 03:07 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/423#pullrequestreview-6082946546) · **approved these changes**
Author
Owner

@⁠Jesper-Andersson on GitHub · 2026-11-27 03:29 UTC · original

Thanks for checking. That fits: under Wine both opens already go through Linux's page cache, so the switch should neither help nor hurt there, and the gain is Windows-only. I've put that in the PR's "Not checked" section: on Wine/Proton, NO_BUFFERING doesn't reach the host as O_DIRECT (your e036355b), so expect no change.

This comment was written with AI assistance (Claude Code).

**@⁠Jesper-Andersson** on GitHub · 2026-11-27 03:29 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/423#issuecomment-7209033051) Thanks for checking. That fits: under Wine both opens already go through Linux's page cache, so the switch should neither help nor hurt there, and the gain is Windows-only. I've put that in the PR's "Not checked" section: on Wine/Proton, `NO_BUFFERING` doesn't reach the host as `O_DIRECT` (your e036355b), so expect no change. This comment was written with AI assistance (Claude Code).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/423/head:github-bot/gh-423'
git switch 'github-bot/gh-423'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-423'
git switch 'github-bot/gh-423'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-423'
git switch 'github-bot/gh-423'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-423'
git switch 'main'
git merge --squash 'github-bot/gh-423'
git switch 'main'
git merge --ff-only 'github-bot/gh-423'
git switch 'main'
git merge 'github-bot/gh-423'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.