DirectStorage: workers read a file through a handle each #2904

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

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 23:32 UTC · original
0xkn0wh3r3:hle/dstorage-handle-per-worker → main · +182 −7 · 1 files · 1 commits · open

What

Each DirectStorage worker now reads a file through its own handle instead of the one handle the title's OpenFile made. A worker makes its handle with ReOpenFile the first time it reads that file. If the host refuses, it falls back to the title's handle, logs a warning, and carries on. The handles close with the file object. VICTORY_DSTORAGE_HANDLES=0 reads through the title's handle alone, as before.

Why

The title's handle is opened for synchronous reads, and Windows performs the reads on one such handle one at a time. So the scheduler's workers (one per host core) queued behind each other on every file, however many were free.

Measured with 48 KiB reads at random offsets from 24 threads:

one handle a handle each
title archive, not in the file cache (the fork's RX 7900 XTX machine) 185 MB/s 990 MB/s
2 GiB file in the file cache (this machine, read_bench) 4.2 GB/s 6.6 GB/s

Nothing here depends on the GPU vendor.

Where it comes from

From the avatarmanz/VIctory-7900XTX fork, commit fbc1830. This PR takes only the fork's default handles mode. Left out: its overlapped and unbuffered direct modes, and its xmem lock rework from the same commit.

#234 also targets this serialization, using overlapped reads on one handle, but it bundles that with xmem mapping changes. This PR is only the handle change.

Tested (Windows 11, RTX 5070 Ti)

  • cargo test -p victory-hle: 153 passed, 1 ignored (the benchmark). New test workers_read_a_file_through_handles_of_their_own: six threads read through three handles, and through the title's handle alone, at offsets across a 300,001-byte file and past its end. It checks the bytes and checks that each handle slot a thread used was made.
  • read_bench (ignored): VICTORY_BENCH_FILE=<file> cargo test --release -p victory-hle --lib read_bench -- --ignored --nocapture. The cached-file numbers above come from it.
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.

Not tested

  • Not run with the title on this machine. I couldn't measure the uncached rate here (the benchmark file sat in the file cache), so the 185 → 990 MB/s figure is the fork's.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 23:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2904) `0xkn0wh3r3:hle/dstorage-handle-per-worker` → `main` · +182 −7 · 1 files · 1 commits · open ## What Each DirectStorage worker now reads a file through its own handle instead of the one handle the title's `OpenFile` made. A worker makes its handle with `ReOpenFile` the first time it reads that file. If the host refuses, it falls back to the title's handle, logs a warning, and carries on. The handles close with the file object. `VICTORY_DSTORAGE_HANDLES=0` reads through the title's handle alone, as before. ## Why The title's handle is opened for synchronous reads, and Windows performs the reads on one such handle one at a time. So the scheduler's workers (one per host core) queued behind each other on every file, however many were free. Measured with 48 KiB reads at random offsets from 24 threads: | | one handle | a handle each | |---|---|---| | title archive, not in the file cache (the fork's RX 7900 XTX machine) | 185 MB/s | 990 MB/s | | 2 GiB file in the file cache (this machine, `read_bench`) | 4.2 GB/s | 6.6 GB/s | Nothing here depends on the GPU vendor. ## Where it comes from From the avatarmanz/VIctory-7900XTX fork, commit [`fbc1830`](https://github.com/avatarmanz/VIctory-7900XTX/commit/fbc183085801939cac7b469eb0ce5956d8e0377f). This PR takes only the fork's default `handles` mode. Left out: its `overlapped` and unbuffered `direct` modes, and its xmem lock rework from the same commit. #234 also targets this serialization, using overlapped reads on one handle, but it bundles that with xmem mapping changes. This PR is only the handle change. ## Tested (Windows 11, RTX 5070 Ti) - `cargo test -p victory-hle`: 153 passed, 1 ignored (the benchmark). New test `workers_read_a_file_through_handles_of_their_own`: six threads read through three handles, and through the title's handle alone, at offsets across a 300,001-byte file and past its end. It checks the bytes and checks that each handle slot a thread used was made. - `read_bench` (ignored): `VICTORY_BENCH_FILE=<file> cargo test --release -p victory-hle --lib read_bench -- --ignored --nocapture`. The cached-file numbers above come from it. - `cargo clippy -p victory-hle --all-targets -- -D warnings`: clean. ## Not tested - Not run with the title on this machine. I couldn't measure the uncached rate here (the benchmark file sat in the file cache), so the 185 → 990 MB/s figure is the fork's.
Every worker read a file through the one handle the title's open made.
That handle is opened for synchronous reads, and the host does the reads
of such a handle one after the other, so the workers queued behind each
other on every file. Each worker now reads through a handle of its own,
made from the title's with ReOpenFile when it first reads that file (the
title's handle if the host makes none).

48 KiB reads at random, 24 threads: 185 MB/s through one handle and
990 MB/s through a handle each, from an archive not in the file cache
(the fork's measurement); from the cache on this machine, 4.2 GB/s and
6.6 GB/s (read_bench, ignored, on any file named by VICTORY_BENCH_FILE).
VICTORY_DSTORAGE_HANDLES=0 reads through the title's handle alone, as
before.

From avatarmanz/VIctory-7900XTX fbc1830 (its handles mode; the
overlapped and unbuffered modes and the xmem lock changes are left out).

Co-authored-by: local <local@localhost>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:17:09 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 02:18 UTC · original

Automated triage for the maintainers.

Merge candidate (a recommendation to look, not an approval). In modules/dstorage.rs, each scheduler worker now reads a file through its own handle, made lazily with ReOpenFile from the title's handle (Files::read_at). If reopening fails it falls back to the title's handle, and VICTORY_DSTORAGE_HANDLES=0 restores the old behaviour. Reads are still positional (seek_read), so sharing a handle never depended on a file position; the change only removes the per-handle serialisation, and the PR measured 185 vs 990 MB/s. The test checks that the bytes and end-of-file results match with and without extra handles. CI check passes.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 02:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2904#issuecomment-7180675129) <!-- victory-triage v1 head=487d01e06a3b244f43bd3a8ca7da0d51feb73097 verdict=merge-candidate at=2026-11-26T02:18:28Z --> Automated triage for the maintainers. **Merge candidate** (a recommendation to look, not an approval). In `modules/dstorage.rs`, each scheduler worker now reads a file through its own handle, made lazily with `ReOpenFile` from the title's handle (`Files::read_at`). If reopening fails it falls back to the title's handle, and `VICTORY_DSTORAGE_HANDLES=0` restores the old behaviour. Reads are still positional (`seek_read`), so sharing a handle never depended on a file position; the change only removes the per-handle serialisation, and the PR measured 185 vs 990 MB/s. The test checks that the bytes and end-of-file results match with and without extra handles. CI `check` passes. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 23:35 UTC · original · reviewed

Correct — a synchronous handle serializes reads on the host side, so N workers through one handle queue behind each other; a lazy per-worker handle (OnceLock indexed modulo worker count) removes that contention while keeping the title's handle semantics. The =0 escape hatch is there. LGTM.

**@⁠kotekompotek** on GitHub · 2026-11-25 23:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2904#pullrequestreview-6066484390) · **reviewed** Correct — a synchronous handle serializes reads on the host side, so N workers through one handle queue behind each other; a lazy per-worker handle (OnceLock indexed modulo worker count) removes that contention while keeping the title's handle semantics. The =0 escape hatch is there. LGTM.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 23:43 UTC · original · reviewed

Verified head 487d01e0 cleanly on origin/main (63bcca43) on Windows 11 x64.

Code Review

  • Using ReOpenFile(..., GENERIC_READ, FILE_SHARE_READ, 0) creates distinct kernel FILE_OBJECTs per worker (unlike DuplicateHandle), eliminating synchronous-I/O lock serialization across worker threads while keeping seek_read offsets independent.
  • Handles open lazily via OnceLock, fall back cleanly to first if ReOpenFile fails (or when VICTORY_DSTORAGE_HANDLES=0), and drop cleanly on Instance<File> release.

Local Verification

  • cargo test --locked -p victory-hle: 153/153 unit tests passed (1 ignored read_bench; includes workers_read_a_file_through_handles_of_their_own), plus fidelityfx (1/1) and no_dll_planting (1/1).
  • cargo clippy --locked -p victory-hle --tests -- -D warnings (default and --features diagnostics) & cargo xtask policy (191 files ok): clean.

Looks clean and ready to merge.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 23:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/2904#pullrequestreview-6066557236) · **reviewed** Verified head `487d01e0` cleanly on `origin/main` (`63bcca43`) on Windows 11 x64. ### Code Review - Using `ReOpenFile(..., GENERIC_READ, FILE_SHARE_READ, 0)` creates distinct kernel `FILE_OBJECT`s per worker (unlike `DuplicateHandle`), eliminating synchronous-I/O lock serialization across worker threads while keeping `seek_read` offsets independent. - Handles open lazily via `OnceLock`, fall back cleanly to `first` if `ReOpenFile` fails (or when `VICTORY_DSTORAGE_HANDLES=0`), and drop cleanly on `Instance<File>` release. ### Local Verification - `cargo test --locked -p victory-hle`: **153/153** unit tests passed (1 ignored `read_bench`; includes `workers_read_a_file_through_handles_of_their_own`), plus `fidelityfx` (1/1) and `no_dll_planting` (1/1). - `cargo clippy --locked -p victory-hle --tests -- -D warnings` (default and `--features diagnostics`) & `cargo xtask policy` (`191 files ok`): clean. Looks clean and ready to merge.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 08:13 UTC · original · approved these changes

Verified against origin/main (63bcca4):

  • cargo test -p victory-hle --lib modules::dstorage:: -- --test-threads=1: 17/17 passed (1 ignored bench; including workers_read_a_file_through_handles_of_their_own).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Giving each DirectStorage worker its own file handle avoids contention on shared handles while keeping all existing queue/decompression invariants intact.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 08:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2904#pullrequestreview-6070520954) · **approved these changes** Verified against `origin/main` (`63bcca4`): - `cargo test -p victory-hle --lib modules::dstorage:: -- --test-threads=1`: 17/17 passed (1 ignored bench; including `workers_read_a_file_through_handles_of_their_own`). - `cargo clippy -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Giving each DirectStorage worker its own file handle avoids contention on shared handles while keeping all existing queue/decompression invariants intact. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 18:25 UTC · original

NVIDIA full-suite run, to go with the reports above by Dukestar69, since none of them names a GPU run. Tested exact head 487d01e (on its base 842b0cb).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 11 ignored.
  • The new tests ran and passed: workers_read_a_file_through_handles_of_their_own.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-26 18:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2904#issuecomment-7200447832) NVIDIA full-suite run, to go with the reports above by Dukestar69, since none of them names a GPU run. Tested exact head `487d01e` (on its base `842b0cb`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **867 passed, 0 failed, 11 ignored**. - The new tests ran and passed: `workers_read_a_file_through_handles_of_their_own`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/2904/head:github-bot/gh-2904'
git switch 'github-bot/gh-2904'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2904'
git switch 'github-bot/gh-2904'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2904'
git switch 'github-bot/gh-2904'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2904'
git switch 'main'
git merge --squash 'github-bot/gh-2904'
git switch 'main'
git merge --ff-only 'github-bot/gh-2904'
git switch 'main'
git merge 'github-bot/gh-2904'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2904
No description provided.