HLE: hold DirectStorage reads behind held status entries and preserve sequence order #2617

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

@⁠fuzeofficlal on GitHub · 2026-11-25 16:56 UTC · original
fuzeofficlal:fix/hle-dstorage-hold-reads-after-held-status → main · +157 −22 · 1 files · 1 commits · open

Summary

In crates/victory-hle/src/modules/dstorage.rs, Lanes::submit_as(..., explicit = false) (auto-submit when a queue reaches half capacity) holds PAGE_DESTINATION reads and subsequent Command::Status entries in lane.held without assigning them sequence numbers, while allowing plain reads (options & PAGE_DESTINATION == 0) to bypass lane.held and receive earlier self.next_seq values.

That causes two ordering bugs in Lane::flush (self.failures.split_off(&seq)):

  1. Plain reads overtaking a held status fence: for [R1(PAGE_DESTINATION), S1] followed by [R2(plain), S2] (either across two auto-submits or in one batch), R2 bypasses lane.held, receives an earlier seq than S1, and if R2 fails (END_OF_FILE) its error is misattributed to S1, leaving S2 with S_OK.
  2. Inverted first-failure order: even in [R1(PAGE_DESTINATION, fails INVALID_DATA), R2(plain, fails END_OF_FILE), S0] (where R2 intentionally starts early while R1 and S0 wait for Submit), giving R2 a smaller seq than R1 causes S0 to report R2's END_OF_FILE instead of R1's earlier failure INVALID_DATA.

Changes

  • crates/victory-hle/src/modules/dstorage.rs:
    • Assign monotonic seq once in strict enqueue order when commands drain from lane.unsubmitted, storing (u64, Command) in lane.held so explicit Submit() preserves original enqueue sequence numbers.
    • Store Lane::reads and Lane::statuses in BTreeMap<u64, ...> (first_key_value / pop_first in Lanes::start and Lane::flush) so releasing earlier-seq held commands ahead of already-queued plain reads keeps both structures strictly ordered by seq.
    • Track held_status in Lanes::submit_as so plain reads after a held Command::Status stay behind that fence, while plain reads before any held status continue starting early (a_queue_that_submits_itself_holds_reads_into_pages).
    • Add a_queue_that_submits_itself_holds_reads_after_held_status and a_queue_that_submits_itself_keeps_enqueue_order_for_first_failure.

Verification

  • cargo test -p victory-hle --lib modules::dstorage::tests — 18/18 pass (including a_queue_that_submits_itself_holds_reads_into_pages).
  • cargo clippy -p victory-hle --all-targets -- -D warnings — pass (0 warnings).
  • cargo xtask policy — pass (184 files ok).
**@⁠fuzeofficlal** on GitHub · 2026-11-25 16:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/2617) `fuzeofficlal:fix/hle-dstorage-hold-reads-after-held-status` → `main` · +157 −22 · 1 files · 1 commits · open ## Summary In `crates/victory-hle/src/modules/dstorage.rs`, `Lanes::submit_as(..., explicit = false)` (auto-submit when a queue reaches half capacity) holds `PAGE_DESTINATION` reads and subsequent `Command::Status` entries in `lane.held` without assigning them sequence numbers, while allowing plain reads (`options & PAGE_DESTINATION == 0`) to bypass `lane.held` and receive earlier `self.next_seq` values. That causes two ordering bugs in `Lane::flush` (`self.failures.split_off(&seq)`): 1. **Plain reads overtaking a held status fence**: for `[R1(PAGE_DESTINATION), S1]` followed by `[R2(plain), S2]` (either across two auto-submits or in one batch), `R2` bypasses `lane.held`, receives an earlier `seq` than `S1`, and if `R2` fails (`END_OF_FILE`) its error is misattributed to `S1`, leaving `S2` with `S_OK`. 2. **Inverted first-failure order**: even in `[R1(PAGE_DESTINATION, fails INVALID_DATA), R2(plain, fails END_OF_FILE), S0]` (where `R2` intentionally starts early while `R1` and `S0` wait for `Submit`), giving `R2` a smaller `seq` than `R1` causes `S0` to report `R2`'s `END_OF_FILE` instead of `R1`'s earlier failure `INVALID_DATA`. ## Changes - `crates/victory-hle/src/modules/dstorage.rs`: - Assign monotonic `seq` once in strict enqueue order when commands drain from `lane.unsubmitted`, storing `(u64, Command)` in `lane.held` so explicit `Submit()` preserves original enqueue sequence numbers. - Store `Lane::reads` and `Lane::statuses` in `BTreeMap<u64, ...>` (`first_key_value` / `pop_first` in `Lanes::start` and `Lane::flush`) so releasing earlier-`seq` held commands ahead of already-queued plain reads keeps both structures strictly ordered by `seq`. - Track `held_status` in `Lanes::submit_as` so plain reads after a held `Command::Status` stay behind that fence, while plain reads before any held status continue starting early (`a_queue_that_submits_itself_holds_reads_into_pages`). - Add `a_queue_that_submits_itself_holds_reads_after_held_status` and `a_queue_that_submits_itself_keeps_enqueue_order_for_first_failure`. ## Verification - `cargo test -p victory-hle --lib modules::dstorage::tests` — 18/18 pass (including `a_queue_that_submits_itself_holds_reads_into_pages`). - `cargo clippy -p victory-hle --all-targets -- -D warnings` — pass (0 warnings). - `cargo xtask policy` — pass (`184 files ok`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:10:26 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 17:15 UTC · original

CPU verification of 2fe1cdc merged cleanly onto origin/main 13f91ca (detached checkout). CPU only; victory-hle creates no GPU device. Windows 11, cargo -j 4, separate CARGO_TARGET_DIR.

Commands and results:

  • cargo clippy -j 4 -p victory-hle --all-targets: clean.
  • cargo test -j 4 -p victory-hle --lib: 148 passed, 0 failed, 0 ignored. Both new tests pass: a_queue_that_submits_itself_holds_reads_after_held_status and a_queue_that_submits_itself_keeps_enqueue_order_for_first_failure.
  • Negative control: the two new tests on top of origin/main's dstorage.rs both fail (1 passed, 2 failed under the a_queue_that_submits_itself filter).

Review notes: no bug found. Held commands keep their original sequence numbers, and the BTreeMap keyed by sequence slots later releases back in order. A held status now also holds later plain reads, and flush still reports the first failure by enqueue order. No overlap with the other PRs in this batch (this one only touches dstorage.rs).

Not tested: a retail title or real DirectStorage workloads.

Independent review and CPU verification by Claude Code (Claude Sonnet 5.5), an AI. No game files, dumps or retail data were used.

**@⁠oni-swr** on GitHub · 2026-11-25 17:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2617#issuecomment-7169247170) **CPU verification** of `2fe1cdc` merged cleanly onto `origin/main` `13f91ca` (detached checkout). CPU only; `victory-hle` creates no GPU device. Windows 11, `cargo -j 4`, separate `CARGO_TARGET_DIR`. Commands and results: - `cargo clippy -j 4 -p victory-hle --all-targets`: clean. - `cargo test -j 4 -p victory-hle --lib`: **148 passed, 0 failed, 0 ignored**. Both new tests pass: `a_queue_that_submits_itself_holds_reads_after_held_status` and `a_queue_that_submits_itself_keeps_enqueue_order_for_first_failure`. - Negative control: the two new tests on top of `origin/main`'s `dstorage.rs` both fail (1 passed, 2 failed under the `a_queue_that_submits_itself` filter). Review notes: no bug found. Held commands keep their original sequence numbers, and the `BTreeMap` keyed by sequence slots later releases back in order. A held status now also holds later plain reads, and `flush` still reports the first failure by enqueue order. No overlap with the other PRs in this batch (this one only touches `dstorage.rs`). Not tested: a retail title or real DirectStorage workloads. _Independent review and CPU verification by Claude Code (Claude Sonnet 5.5), an AI. No game files, dumps or retail data were used._
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 17:51 UTC · original

Reviewed: keeping sequence numbers on held commands and moving reads/statuses to BTreeMap preserves the original submission order across the hold — and 'reads behind a held status entry wait' closes the reorder where a later read could jump its fence. first_key_value/pop_first keep the take-oldest discipline identical to the VecDeque version. CI green.

**@⁠kotekompotek** on GitHub · 2026-11-25 17:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2617#issuecomment-7170102095) Reviewed: keeping sequence numbers on held commands and moving reads/statuses to `BTreeMap` preserves the original submission order across the hold — and 'reads behind a held status entry wait' closes the reorder where a later read could jump its fence. `first_key_value`/`pop_first` keep the take-oldest discipline identical to the VecDeque version. CI green.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:17 UTC · original

Automated triage for the maintainers.

Recommended for a maintainer's look. In crates/victory-hle/src/modules/dstorage.rs, Lanes::submit_as now gives every command its sequence number when it leaves unsubmitted (held commands keep theirs), and a plain read enqueued behind a held status entry is held too. On main such a read took an earlier sequence number than the held status before it, so Lane::flush could charge its failure to the earlier status entry, which contradicts a status entry covering only the requests enqueued before it. I checked that reads/statuses as BTreeMaps keep the oldest-first behaviour of start and flush, and that the two new tests exercise both orderings. Merges cleanly, CI check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 22:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2617#issuecomment-7176182792) <!-- victory-triage v1 head=2fe1cdc225c71ccad163efaf130eafa4e9cc8bd3 verdict=merge-candidate at=2026-11-25T22:20:30Z --> Automated triage for the maintainers. Recommended for a maintainer's look. In `crates/victory-hle/src/modules/dstorage.rs`, `Lanes::submit_as` now gives every command its sequence number when it leaves `unsubmitted` (held commands keep theirs), and a plain read enqueued behind a held status entry is held too. On `main` such a read took an earlier sequence number than the held status before it, so `Lane::flush` could charge its failure to the earlier status entry, which contradicts a status entry covering only the requests enqueued before it. I checked that `reads`/`statuses` as `BTreeMap`s keep the oldest-first behaviour of `start` and `flush`, and that the two new tests exercise both orderings. Merges cleanly, CI `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
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/2617/head:github-bot/gh-2617'
git switch 'github-bot/gh-2617'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2617'
git switch 'github-bot/gh-2617'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2617'
git switch 'github-bot/gh-2617'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2617'
git switch 'main'
git merge --squash 'github-bot/gh-2617'
git switch 'main'
git merge --ff-only 'github-bot/gh-2617'
git switch 'main'
git merge 'github-bot/gh-2617'
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!2617
No description provided.