Skip to content

GPU: read watched texture memory through a shared scratch buffer - #495

Closed
ghost wants to merge 1 commit into
mainfrom
unknown repository
Closed

ghost wants to merge 1 commit into
mainfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Nov 24, 2026

Copy link
Copy Markdown

Every texture the title samples through a watched pool stays in STAGING for the rest of the run, and each one kept a Vec the size of its title memory (Last::read). That buffer is only needed while the texture is detiled, so on a long world run it adds gigabytes of commit on top of the title's own, and when Windows runs out of commit a failed allocation aborts the process: no crashes.log entry, only memory allocation of N bytes failed.

What I saw

RTX 3070 Ti, 31 GB RAM, the world loaded (black, minimap only), diagnostics build with the host debug layer. Two aborts, in different places and at different sizes:

memory allocation of 7372800 bytes failed     (during D3D12 submissions)
memory allocation of 12582912 bytes failed    (during shader translation)

System commit was about 52 GB of a 48 to 54 GB limit for the whole run (a growing pagefile), with the process at about 21 GB private. Neither abort left anything in crashes.log.

Fix

The buffer is one per thread (READ), reused for every texture, and reserved with try_reserve_exact. If the reservation fails the upload is skipped with a one-time warning, and the texture still asks to be detiled next time (asked is only updated after the reservation succeeds). No behaviour change otherwise.

Verified

cargo test -p victory-gpu --lib    43 passed, 0 failed, 1 ignored
rustfmt --check texture.rs         clean
cargo clippy -p victory-gpu        nothing new in texture.rs
cargo xtask policy --staged        ok (commit hook)

On the machine above, with this change the abort did not come back over several later runs (one of 20+ minutes with the process flat at about 21 to 22 GB private). I also raised the pagefile to 32 GB at the same time, so I cannot separate the two effects from those runs. I did not test the try_reserve_exact failure branch under real memory pressure.

Not in this PR

The STAGING map itself is still never cleared, so the upload buffers stay for the run. That is a separate question and I left it alone.

🤖 Generated with Claude Code

Every texture ever sampled stays in STAGING, and each one kept a Vec the
size of its title memory (Last::read) for the rest of the run, though it is
only needed while the texture is detiled. On a long world run that adds up
to gigabytes on top of the title's own commit, and when the host runs out of
commit a failed allocation aborts the process: no crashes.log entry, no
message beyond "memory allocation of N bytes failed".

The buffer is now one per thread (READ), reused for every texture, and it is
reserved with try_reserve_exact: if that fails the upload is skipped with a
one-time warning, and the texture still asks to be detiled next time.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ghost

ghost commented Nov 24, 2026

Copy link
Copy Markdown
Author

Closing as a duplicate of #215, which makes the same change in texture.rs (one thread-local read buffer in place of Last::read), was opened first, and has tests and a measurement. I should have searched for existing PRs before opening this one. If you were including #495 in a test stack, please use #215 instead. The one difference, a try_reserve_exact fallback so a failed allocation skips the upload instead of aborting the process, is described in a comment on #215.

@ghost ghost closed this Nov 24, 2026
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 27, 2026
…lent playback endpoint

Ported from pragyaangaur/VIctory-macOS (GPL-3.0): Marvisak#495 (c37dc6eac6) and
the audio half of Marvisak#405 (3587d54480).

DirectStorage (Marvisak#495, adapted to our scheduler):
- A queue that submits itself still holds reads into physical pages for
  the title's Submit, but no longer forever: a "dstorage hold" thread
  starts them once they have waited VICTORY_DSTORAGE_HOLD_MS (2000 by
  default, also when empty or not a number; 0 holds nothing). Their page
  lists are read as they are then, with the existing late-list re-reads.
- A title polling a pending status entry for as long (the same
  VICTORY_DSTORAGE_HOLD_MS) while reads are held starts them too, but
  only queues held since before it began to poll, or held for the hold
  and behind the polled entry: a queue held meanwhile may still have its
  page table being written. The poll path takes the scheduler lock with
  try_lock and never starts workers.
- Such a late start starts only what was held, in order; commands
  enqueued since wait for a Submit as before.
- Unlike upstream, the workers are woken after either release (upstream
  left released reads waiting for an unrelated notify), the poll clock
  restarts after a 250 ms pause, and the release logs are rate-limited.
  Upstream's own stuck-queue watchdog is left out: the periodic
  VICTORY_DSTORAGE_SUMMARY line already shows held/oldest. The catch_unwind
  guard, the summary and release_ref are kept as they were.

Audio (Marvisak#405):
- audio::silent serves CoCreateInstance (ole32 and api-ms-win-core-com-l1-*).
  An MMDeviceEnumerator whose host has no active render endpoint, or any
  with VICTORY_SILENT_AUDIO=1, is wrapped: render flow shows one silent
  device whose ISpatialAudioClient takes 48 kHz float objects and signals
  the title's event every 10 ms; capture and everything else go to the host.
- Over upstream: the activation PROPVARIANT must be a VT_BLOB with data
  before its blob is read, the stream signals its own duplicate of the
  title's event (closed after the clock's thread ends; activation fails
  with E_HANDLE if it is not a handle), so a title closing its handle
  first never has another object signalled, a failed clock-thread spawn
  is logged, and the tests free GetId's string.
- windows gains Win32_UI_Shell_PropertiesSystem (a feature: Cargo.lock is
  unchanged) and windows-core is no longer optional (already locked).

Tests: hold expiry, a late Submit after the hold, poll release with
pause reset, a queue held just before the poll's end left held while
an older one starts, the polled entry's queue, a late start leaving
newer commands, the poll wait following the hold (up to u64::MAX ms),
zero hold, HOLD_MS parsing, and an end-to-end page read that is never
submitted; for audio, routing, the blob parsing and refusals, client to
stream activation with ticks, ticks after the title closes its event, a
non-handle event, and the device id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants