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

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/2617 into main
fuzeofficlal commented 2026-11-25 16:56:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T16:56:55Z.


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).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6609446591 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2617). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T16:56:55Z. --- ## 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`).
oni-swr commented 2026-11-25 18:02:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T17:15:52Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7169247170 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2617#issuecomment-7169247170). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T17:15:52Z. --- **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._
kotekompotek commented 2026-11-25 18:02:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T17:51:41Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7170102095 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2617#issuecomment-7170102095). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T17:51:41Z. --- 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.
Marvisak commented 2026-11-25 23:06:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:17:44Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176182792 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2617#issuecomment-7176182792). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:17:44Z. --- <!-- 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)_
Dukestar69 commented 2026-11-26 06:02:35 +00:00 (Migrated from github.com)

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

Review: APPROVED


Tested locally merged onto origin/main (63bcca4) on Windows 11 x64:

  • Diff review: Assigning sequence numbers when commands leave unsubmitted, switching reads/statuses to BTreeMap<u64, _>, and holding reads behind a held status entry preserves original enqueue ordering for both status fences and first-failure reporting when a queue auto-submits before an explicit Submit.
  • cargo test -p victory-hle dstorage: 18 passed, 0 failed (including a_queue_that_submits_itself_holds_reads_after_held_status and a_queue_that_submits_itself_keeps_enqueue_order_for_first_failure).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6068916086 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2617#pullrequestreview-6068916086). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T05:18:11Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64: - Diff review: Assigning sequence numbers when commands leave `unsubmitted`, switching `reads`/`statuses` to `BTreeMap<u64, _>`, and holding reads behind a held status entry preserves original enqueue ordering for both status fences and first-failure reporting when a queue auto-submits before an explicit `Submit`. - `cargo test -p victory-hle dstorage`: 18 passed, 0 failed (including `a_queue_that_submits_itself_holds_reads_after_held_status` and `a_queue_that_submits_itself_keeps_enqueue_order_for_first_failure`). - `cargo clippy -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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/2617:upstream-pr/2617'
git switch 'upstream-pr/2617'

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/2617'
git switch 'upstream-pr/2617'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2617'
git switch 'upstream-pr/2617'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2617'
git switch 'main'
git merge --squash 'upstream-pr/2617'
git switch 'main'
git merge --ff-only 'upstream-pr/2617'
git switch 'main'
git merge 'upstream-pr/2617'
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!2615
No description provided.