DirectStorage: stage raw reads rejected by Windows #237
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/237"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Belobug/VIctory-Belobug-AMD. Originally posted by loyodea on 2026-11-26T08:01:59Z.
Related to the raw-file-read item in #211. When Windows rejects an uncompressed DirectStorage read with ERROR_INVALID_USER_BUFFER, finish the unread suffix through a reusable host buffer capped at 1 MiB. Refresh the destination write-watch before copying each chunk. Preserve short reads, EOF, other HRESULTs, and successful direct reads.
The current diff in #50 retries the same destination pointer. Our synthetic error injection continues rejecting that pointer and succeeds with the host buffer. The regression uses a real temporary file and simulates the OS error.
Tested
4f62c2ahad 97 passed, the same five memory-mapping failures, and one ignored. The separate HLE integration test and staged asset-policy check passed.Retail DirectStorage behavior remains unverified. Codex contributed the implementation and verification.
Review follow-up for partial-read offsets
Two synthetic tests cover offset overflow after a successful partial read, including a direct read and one that switches to the staging buffer. Both assert
E_INVALIDARG, no callback at a wrapped offset, and preservation of the bytes already read and the unread suffix. A temporarywrapping_addmutation made both tests observe a callback at offset zero. With the checked arithmetic restored, all 18 DirectStorage tests passed on Windows, including an independent rerun. Review threadImported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-26T16:18:50Z.
Review: COMMENTED
AI-assisted review. I inspected the new file-read fallback and its tests statically; I did not run tests or the game. This review suggests a focused offset-overflow boundary case.
Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-26T16:18:50Z.
Code review location:
crates/victory-hle/src/modules/dstorage.rs; line 954AI-assisted review; I did not run tests. Could a unit test cover offset overflow after a successful partial read, such as starting near
u64::MAXand having the callback return bytes that leave a suffix? It should assertE_INVALIDARGand that the next read is never called with a wrapped offset; current tests cover partial reads, EOF, and I/O errors, but not this checked-add boundary.Imported from Belobug/VIctory-Belobug-AMD. Originally posted by loyodea on 2026-11-26T18:53:14Z.
Code review location:
crates/victory-hle/src/modules/dstorage.rs; line 954Thanks for the suggestion. Both read loops check
offset.checked_add(done as u64)before calling the reader. A two-byte partial read atu64::MAX - 1with one byte left would therefore returnE_INVALIDARGbefore the next call. The current tests do not exercise that boundary.Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-26T21:42:41Z.
Tested
7162d28on top of main4f62c2a, natively and without the game: RX 7900 XT, Windows 11 26300, Rust 1.98.1. This follows up on my comment in #211. The new head3a37326only adds the two offset-overflow tests. I have not run those.Which errors does Windows return? I used a local probe test. It flips the last 64 KiB of a pagefile-view destination between read-only and read-write while a synchronous
seek_readruns. I tried buffered and unbuffered reads of 64 KiB, 1 MiB and 16 MiB.This PR stages only on 1784. The race I described in #211 makes the block read-only again before the read starts (the fast path of
guard()ignores the pins). So it gives 998:7162d28still fails with ReadFile 998 (3 of 3 runs). This PR does not touch watch.rs.read_file_into(..., true, seek_read)on a destination whose second block is read-only makes a single call. It returns0x800703e6and does not stage.kernel_will_write, then copy (3 of 3 runs). So staging on 998 as well would cover that case. Fixing the fast path in watch.rs would avoid it.Partial writes before a 1784 failure:
The title's own
ReadFile/fread(files.rs:530, 538) have the same window. This PR does not cover them.Checks:
7162d28fail, so they test the change.Not tested: the game, and the rx9070xt / a-publier branches.
I have the probe tests on a local branch if they are useful.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.