DirectStorage: stage raw reads rejected by Windows #237
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!237
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@loyodea on GitHub · 2026-11-26 08:01 UTC · original
loyodea:victory-dstorage-read-compat→main· +203 −10 · 1 files · 2 commits · openRelated 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 thread@gut0to on GitHub · 2026-11-26 16:18 UTC · original · reviewed
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.
@ -951,0 +951,4 @@) -> Result<(), HRESULT> {let mut done = 0;while done < out.len() {let at = offset.checked_add(done as u64).ok_or(E_INVALIDARG)?;@gut0to on GitHub · 2026-11-26 16:18 UTC · original
AI-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.@ -951,0 +951,4 @@) -> Result<(), HRESULT> {let mut done = 0;while done < out.len() {let at = offset.checked_add(done as u64).ok_or(E_INVALIDARG)?;@loyodea on GitHub · 2026-11-26 18:53 UTC · original
Thanks 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.@adrianmjim on GitHub · 2026-11-26 21:42 UTC · original
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.