ReadFile: VICTORY_READ_BOUNCE, large reads through a buffer of ours (start-up int3: shader database read with runs of zeros) #368

Merged
afutuga merged 1 commit from upstream-pr/368 into main 2026-11-29 08:16:59 +00:00
afutuga commented 2026-11-27 21:31:58 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by afutuga on 2026-11-27T21:31:58Z.


PC: Windows 10 22H2 (19045), RTX 4060 Ti 16 GB, Ryzen 7 5700X (8 cores, 16 threads), 32 GB.
Built from source, release profile. This PR now holds one commit, which merges cleanly into
current main (the earlier DirectStorage-workers commits are gone: main has its own
VICTORY_DSTORAGE_WORKERS now, and they were not the cause).

The problem

In streaks of hours, every start ended about 2 seconds in with the title's own breakpoint:

VIctory: unhandled exception 0x80000003 at victory-image-...dll+0x22106e0

(+0x22106e0 is int3; ret, reached from an assert-not-null at +0x2a34d0.)

What it was

  • The stop is in the shader-database loader (+0x2499630, SGD5 files): it reads a 0x90 header
    and a size from its stream, allocates the size, and asserts the pointer. The size was 0.
  • Reading the loader's stream at the stop: a 271 MiB database in one buffer (at 0x520000000),
    valid at its start and end, but a run of zeros (512 KiB or 1 MiB, 64 KiB aligned) where it was
    reading.
  • That buffer is filled by +0x313fc0 → the file device's ReadBulk → one ReadFile of
    271,044,608 bytes, straight into pages the title mapped just before with
    XMemMapPhysicalPagesScatter (same thread, the mapping call returned first).
  • Checked right after that ReadFile returned TRUE with every byte read: 3-9 runs of 64 KiB
    blocks of zeros already there. The views were MEM_COMMIT, PAGE_READWRITE, MEM_MAPPED, the
    same as their neighbours with bytes; no pages were uncommitted before the read; no mapping call
    touched the range during it; reading the file again at that offset gives the bytes.

So the kernel's write into those mapped physical pages does not land, now and then, while the
call reports success. I did not find why; whatever it is, a user-mode copy does not lose them.

This change

VICTORY_READ_BOUNCE=1: a title ReadFile of 64 KiB or more reads into a buffer of ours,
8 MiB at a time, and copies it into the title's memory from user mode (as fread already does
for the guards). An asynchronous handle's read is waited for, so the call stays synchronous, as
the title's are. Off by default.

Results in the same hours: with it, no run of zeros after the read and 8 starts of 8 (3 in a
diagnostics build, 5 in release); without it, the stop as before (two control starts: one stopped).
The extra copy costs a few tens of ms for the 271 MiB file. It may be worth having on by default
once someone else confirms it.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5533343805 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/368). Originally posted by [afutuga](https://github.com/afutuga) on 2026-11-27T21:31:58Z. --- **PC:** Windows 10 22H2 (19045), RTX 4060 Ti 16 GB, Ryzen 7 5700X (8 cores, 16 threads), 32 GB. Built from source, release profile. This PR now holds one commit, which merges cleanly into current `main` (the earlier DirectStorage-workers commits are gone: `main` has its own `VICTORY_DSTORAGE_WORKERS` now, and they were not the cause). ## The problem In streaks of hours, every start ended about 2 seconds in with the title's own breakpoint: VIctory: unhandled exception 0x80000003 at victory-image-...dll+0x22106e0 (`+0x22106e0` is `int3; ret`, reached from an assert-not-null at `+0x2a34d0`.) ## What it was - The stop is in the shader-database loader (`+0x2499630`, `SGD5` files): it reads a 0x90 header and a size from its stream, allocates the size, and asserts the pointer. The size was 0. - Reading the loader's stream at the stop: a 271 MiB database in one buffer (at `0x520000000`), valid at its start and end, but a run of zeros (512 KiB or 1 MiB, 64 KiB aligned) where it was reading. - That buffer is filled by `+0x313fc0` → the file device's `ReadBulk` → one `ReadFile` of 271,044,608 bytes, straight into pages the title mapped just before with `XMemMapPhysicalPagesScatter` (same thread, the mapping call returned first). - Checked right after that `ReadFile` returned TRUE with every byte read: 3-9 runs of 64 KiB blocks of zeros already there. The views were `MEM_COMMIT`, `PAGE_READWRITE`, `MEM_MAPPED`, the same as their neighbours with bytes; no pages were uncommitted before the read; no mapping call touched the range during it; reading the file again at that offset gives the bytes. So the kernel's write into those mapped physical pages does not land, now and then, while the call reports success. I did not find why; whatever it is, a user-mode copy does not lose them. ## This change `VICTORY_READ_BOUNCE=1`: a title `ReadFile` of 64 KiB or more reads into a buffer of ours, 8 MiB at a time, and copies it into the title's memory from user mode (as `fread` already does for the guards). An asynchronous handle's read is waited for, so the call stays synchronous, as the title's are. Off by default. Results in the same hours: with it, no run of zeros after the read and 8 starts of 8 (3 in a diagnostics build, 5 in release); without it, the stop as before (two control starts: one stopped). The extra copy costs a few tens of ms for the 271 MiB file. It may be worth having on by default once someone else confirms it.
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
trustno1-coder/VIctory-NVIDIA!368
No description provided.