hle/dstorage: return exact DirectStorage HRESULTs and isolate per-worker file handles #4363

Closed
github-bot wants to merge 11 commits from github-bot/gh-4362 into main AGit
Owner

@⁠TheOriginalF on GitHub · 2026-11-30 19:20 UTC · original
TheOriginalF:fix/dstorage-error-codes-and-worker-handles → main · +157 −27 · 1 files · 1 commits · closed without merging

What it changes

Improves DirectStorage error fidelity, option validation, and worker handle isolation in crates/victory-hle/src/modules/dstorage.rs:

  • Returns the 6 exact E_DSTORAGE_* HRESULTs instead of generic error codes.
  • Adds validation/decoding for SWIZZLE_MODE, SOURCE_PHYSICAL_PAGES, and RESERVED_OPTIONS.
  • Isolates OS file handles per worker thread via WORKER_INDEX (integrated with Io::Windows / read_owned_at) to prevent concurrent DirectStorage workers from interfering on shared file handles.
  • Updates assertions and adds 2 unit tests covering exact HRESULTs and per-worker handle isolation.

How it was tested

  • Test system:
    • CPU: AMD Ryzen 9 5950X (Corsair iCUE H150i RGB Pro XT)
    • GPU: Palit GeForce RTX 4090 GameRock OC (SM 6.8)
    • Motherboard: ASUS ROG Strix X570-E Gaming
    • RAM: Corsair Vengeance RGB Pro 32GB (2x16GB @ 3600MHz)
    • PSU: Corsair RM850x (850W)
    • Storage: Corsair MP600 2TB NVMe Gen4 + Seagate Barracuda 2TB HDD
  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): Palit GeForce RTX 4090 GameRock OC (SM 6.8), Series S (--console series-s --execute), no DLSS / no frame generation, default software RT path, cache-pareto
  • Before: baseline.log (84bd61e2, 503.0 s): 119 DirectStorage info events, 0 errors
  • After: all-prs.log (combined branch over 84bd61e2, 430.5 s): 119 DirectStorage info events, 0 errors, clean asset streaming across gameplay and cutscenes — no regressions
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A
  • cargo test passed for the crates it touches: yes (dstorage:: — 39 passed, 0 failed, 10 ignored; cargo clippy — 0 new warnings; xtask policy --staged — ok)

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #3145, #3245, #3553 (touch dstorage.rs for different issues; no overlapping HRESULT/per-worker handle PR found)
**@⁠TheOriginalF** on GitHub · 2026-11-30 19:20 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4362) `TheOriginalF:fix/dstorage-error-codes-and-worker-handles` → `main` · +157 −27 · 1 files · 1 commits · closed without merging ## What it changes Improves DirectStorage error fidelity, option validation, and worker handle isolation in `crates/victory-hle/src/modules/dstorage.rs`: - Returns the 6 exact `E_DSTORAGE_*` HRESULTs instead of generic error codes. - Adds validation/decoding for `SWIZZLE_MODE`, `SOURCE_PHYSICAL_PAGES`, and `RESERVED_OPTIONS`. - Isolates OS file handles per worker thread via `WORKER_INDEX` (integrated with `Io::Windows` / `read_owned_at`) to prevent concurrent DirectStorage workers from interfering on shared file handles. - Updates assertions and adds 2 unit tests covering exact HRESULTs and per-worker handle isolation. ## How it was tested - Test system: - CPU: AMD Ryzen 9 5950X (Corsair iCUE H150i RGB Pro XT) - GPU: Palit GeForce RTX 4090 GameRock OC (SM 6.8) - Motherboard: ASUS ROG Strix X570-E Gaming - RAM: Corsair Vengeance RGB Pro 32GB (2x16GB @ 3600MHz) - PSU: Corsair RM850x (850W) - Storage: Corsair MP600 2TB NVMe Gen4 + Seagate Barracuda 2TB HDD - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): Palit GeForce RTX 4090 GameRock OC (SM 6.8), Series S (`--console series-s --execute`), no DLSS / no frame generation, default software RT path, `cache-pareto` - Before: `baseline.log` (`84bd61e2`, 503.0 s): 119 DirectStorage info events, 0 errors - After: `all-prs.log` (combined branch over `84bd61e2`, 430.5 s): 119 DirectStorage info events, 0 errors, clean asset streaming across gameplay and cutscenes — no regressions - For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A - `cargo test` passed for the crates it touches: yes (`dstorage::` — 39 passed, 0 failed, 10 ignored; `cargo clippy` — 0 new warnings; `xtask policy --staged` — ok) ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #3145, #3245, #3553 (touch `dstorage.rs` for different issues; no overlapping HRESULT/per-worker handle PR found)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 19:22:41 +00:00
Author
Owner

@⁠babuakhil on GitHub · 2026-11-30 19:31 UTC · original

Checked on Windows 11 (Rust 1.98.1, pinned), applied on current main (e1251c31); cherry-picks cleanly. cargo test -p victory-hle --lib dstorage gives 39 passed, 0 failed, 10 ignored, two runs out of two, and Clippy reports nothing in dstorage.rs. Not tested in the game.

A few things I'd look at before this goes in:

1. The per-worker handles already exist on main. this_thread() is only called from Files::read_at, and in a run execute is only called from work(), so the only threads that ever take a number are the dstorage {i} workers. They get 0, 1, 2… in the order they first read, and others has available_parallelism() slots, at least as many as off_the_frames_cores() workers. A throwaway test on plain main (not part of this PR): 8 threads reading one file through Files::open_for_test opened 8 handles, one per thread, with both Io::Handles and Io::Windows (16 slots on this machine). So WORKER_INDEX doesn't change which handle a worker gets in a normal run. It also adds a new way to collide: a non-worker reader (a test, or a future inline path) still numbers itself with this_thread() from 0 and can land on worker i's handle, which main would not do. If there's a case where main's workers did share a handle, it would help to describe it.

2. The six E_DSTORAGE_* values. I couldn't find a public copy of dstorageerr.h to check 0x8924_0007, _000C, _000E, _0031, _0032 and _0035 against (the NuGet package carries it, but I didn't take it apart). Since these are now what the title receives, and the game run in the description had 0 DirectStorage errors, none of these paths ran in the game. Could you add where the values come from? One point is worth checking in particular: the console's GDK header may not use the PC SDK's numbers.

3. Bits 5–20 now say "invalid". main refuses a request with any of bits 5–20 set as E_NOTIMPL ("we don't do this"). With this PR it's E_DSTORAGE_INVALID_SWIZZLE_MODE, which tells the title its request was wrong, although a nonzero swizzle mode may well be valid on the console and only unimplemented here. Bit 23 keeps E_NOTIMPL for exactly that reason, so the two cases end up inconsistent.

4. Overlap with #3387. #3387's note_damaged_archive tests hr != INVALID_DATA, and this PR removes INVALID_DATA (zlib failures become E_DSTORAGE_ZLIB_BAD_HEADER or _BAD_DATA). Whichever lands second will need its check adjusted, or #3387's message will not compile, or will never fire. This PR's new inflate header test is also the same RFC 1950 check as #3387's starts_a_zlib_stream.

**@⁠babuakhil** on GitHub · 2026-11-30 19:31 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4362#issuecomment-7289543997) Checked on Windows 11 (Rust 1.98.1, pinned), applied on current `main` (`e1251c31`); cherry-picks cleanly. `cargo test -p victory-hle --lib dstorage` gives 39 passed, 0 failed, 10 ignored, two runs out of two, and Clippy reports nothing in `dstorage.rs`. Not tested in the game. A few things I'd look at before this goes in: **1. The per-worker handles already exist on `main`.** `this_thread()` is only called from `Files::read_at`, and in a run `execute` is only called from `work()`, so the only threads that ever take a number are the `dstorage {i}` workers. They get 0, 1, 2… in the order they first read, and `others` has `available_parallelism()` slots, at least as many as `off_the_frames_cores()` workers. A throwaway test on plain `main` (not part of this PR): 8 threads reading one file through `Files::open_for_test` opened 8 handles, one per thread, with both `Io::Handles` and `Io::Windows` (16 slots on this machine). So `WORKER_INDEX` doesn't change which handle a worker gets in a normal run. It also adds a new way to collide: a non-worker reader (a test, or a future inline path) still numbers itself with `this_thread()` from 0 and can land on worker `i`'s handle, which `main` would not do. If there's a case where `main`'s workers did share a handle, it would help to describe it. **2. The six `E_DSTORAGE_*` values.** I couldn't find a public copy of `dstorageerr.h` to check `0x8924_0007`, `_000C`, `_000E`, `_0031`, `_0032` and `_0035` against (the NuGet package carries it, but I didn't take it apart). Since these are now what the title receives, and the game run in the description had 0 DirectStorage errors, none of these paths ran in the game. Could you add where the values come from? One point is worth checking in particular: the console's GDK header may not use the PC SDK's numbers. **3. Bits 5–20 now say "invalid".** `main` refuses a request with any of bits 5–20 set as `E_NOTIMPL` ("we don't do this"). With this PR it's `E_DSTORAGE_INVALID_SWIZZLE_MODE`, which tells the title its request was wrong, although a nonzero swizzle mode may well be valid on the console and only unimplemented here. Bit 23 keeps `E_NOTIMPL` for exactly that reason, so the two cases end up inconsistent. **4. Overlap with #3387.** #3387's `note_damaged_archive` tests `hr != INVALID_DATA`, and this PR removes `INVALID_DATA` (zlib failures become `E_DSTORAGE_ZLIB_BAD_HEADER` or `_BAD_DATA`). Whichever lands second will need its check adjusted, or #3387's message will not compile, or will never fire. This PR's new `inflate` header test is also the same RFC 1950 check as #3387's `starts_a_zlib_stream`.
Author
Owner

@⁠TheOriginalF on GitHub · 2026-11-30 21:10 UTC · original

Thanks for the detailed review and for testing this on main, @⁠babuakhil!

Good catches across the board:

  • main's this_thread() already isolates per-worker handles without WORKER_INDEX (and avoids colliding with non-worker threads).
  • Keeping E_NOTIMPL for unimplemented swizzle mode bits 5..=20 is cleaner and more consistent with bit 23.
  • #3387 already handles the RFC 1950 zlib header check and relies on INVALID_DATA.

Closing this PR to keep the queue clean.

**@⁠TheOriginalF** on GitHub · 2026-11-30 21:10 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4362#issuecomment-7292022550) Thanks for the detailed review and for testing this on `main`, @⁠babuakhil! Good catches across the board: - `main`'s `this_thread()` already isolates per-worker handles without `WORKER_INDEX` (and avoids colliding with non-worker threads). - Keeping `E_NOTIMPL` for unimplemented swizzle mode bits `5..=20` is cleaner and more consistent with bit `23`. - #3387 already handles the RFC 1950 zlib header check and relies on `INVALID_DATA`. Closing this PR to keep the queue clean.
github-bot closed this pull request 2026-11-30 21:16:46 +00:00

Pull request closed

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/trustno1-coder--VIctory-NVIDIA!4363
No description provided.