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

Open
0xkn0wh3r3 wants to merge 1 commit from upstream-pr/2904 into main
0xkn0wh3r3 commented 2026-11-25 23:32:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T23:32:51Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6615951930 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2904). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T23:32:51Z. --- ## 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.
kotekompotek commented 2026-11-25 23:35:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T23:35:40Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066484390 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2904#pullrequestreview-6066484390). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T23:35:40Z. **Review:** COMMENTED --- 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.
fuzeofficlal commented 2026-11-25 23:43:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:43:19Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066557236 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2904#pullrequestreview-6066557236). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T23:43:19Z. **Review:** COMMENTED --- 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.
Marvisak commented 2026-11-26 03:05:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T02:18:34Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7180675129 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2904#issuecomment-7180675129). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T02:18:34Z. --- <!-- 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)_
Dukestar69 commented 2026-11-26 08:13:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T08:13:46Z.

Review: APPROVED


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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6070520954 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2904#pullrequestreview-6070520954). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T08:13:46Z. **Review:** APPROVED --- 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).
futurepro62 commented 2026-11-26 18:25:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T18:25:31Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7200447832 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2904#issuecomment-7200447832). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T18:25:31Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2904:upstream-pr/2904'
git switch 'upstream-pr/2904'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2904'
git switch 'upstream-pr/2904'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2904'
git switch 'upstream-pr/2904'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2904'
git switch 'main'
git merge --squash 'upstream-pr/2904'
git switch 'main'
git merge --ff-only 'upstream-pr/2904'
git switch 'main'
git merge 'upstream-pr/2904'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2902
No description provided.