Skip to content

host: keep 512 MB of the card's budget free of texture copies - #4005

Open
maozhongmao wants to merge 1 commit into
trustno1-coder:mainfrom
maozhongmao:texture-keep-free-reserve
Open

maozhongmao wants to merge 1 commit into
trustno1-coder:mainfrom
maozhongmao:texture-keep-free-reserve

Conversation

@maozhongmao

@maozhongmao maozhongmao commented Nov 30, 2026 •

Copy link
Copy Markdown

Fixes #

Summary

On an 8 GiB card the run still ends with the driver refusing a command list
(0x8007000E) or removing the device (0x887A0007) while the card's own
memory is over its budget. The texture room line does not prevent that,
because render targets, buffer copies and scratch are made with no room test
of their own; only the host texture copies are weighed against a line, and
they can be pushed over it by everything else.

This adds VICTORY_TEXTURE_KEEP_FREE_MB (512 MB by default; 0 restores the
old behaviour): that many bytes of the card's budget are kept free of host
texture copies. The cap is recomputed from the DXGI budget, the current use
and the bytes that are not host copies, so it follows the scene instead of
being a fixed number; and the once-a-second sweep takes idle copies down to
the same line, so the reserve comes back after a scene grew past it. An
explicit VICTORY_TEXTURE_BUDGET_MB is now checked before the normal room
line as well.

What it changes, by function

crates/victory-gpu/src/resource.rs

  • keep_free_bytes(): the reserve, from VICTORY_TEXTURE_KEEP_FREE_MB
    (default 512 MB; clamped to 8192 MB; 0 = off).

  • dynamic_texture_cap(memory): the bytes host copies may hold:

    cap = budget - keep_free - (DXGI CurrentUsage - host texture bytes)
    

    The bracket is what the title holds on the card that is not a host copy of
    a texture: render targets (aliased or committed), the buffers of
    VICTORY_CARD_BUFFERS_MB, scratch, staging. Those are the bytes that used
    to take the card past its budget unnoticed.

  • room_for_first_upload(): checks dynamic_texture_cap() before the
    ordinary room line, and counts a refusal in FirstUpload::ExplicitBudget
    so the existing per-reason counters stay meaningful. The check is on
    HOST_TEXTURES[1] (every host texture alive), not on KINDS[1] (only the
    copies the title fills), which is what the memory line reports.

  • an explicit VICTORY_TEXTURE_BUDGET_MB is now also checked before the
    room line: before this it was only consulted once the card had no room
    anyway, so a card with room took textures past it (0 ExplicitBudget
    refusals in a full run with 4096 set).

  • let_go_idle(): the sweep's soft budget is now
    soft_budget().or_else(dynamic_texture_cap), so idle copies are taken down
    to the same line (idle 5 s when over it), not only down to a fixed
    VICTORY_TEXTURE_SOFT_MB.

  • breakdown() and the memory now line: VICTORY_CARD_BREAKDOWN=1
    appends the host-texture count and bytes, the aliased-target bytes and the
    free texture blocks to the once-a-second line. Every number in this PR came
    from it.

Reproduction

  • RTX 4060 Ti 8 GiB (driver 610.88), 16 GiB RAM, Windows 10 22H2,
    D3D12 Agility 1.618 beside victory.exe.
  • Series S profile, 1920x1080, no DLSS, no frame generation, no ray tracing.
VICTORY_GAME_DIR=<dump>
VICTORY_CARD_BUFFERS_MB=768
VICTORY_TEXTURE_ROOM_PERCENT=80
VICTORY_LOG=info
victory.exe run <dump>\game_scarlett_master.exe --console series-s --execute

Walk around the city and enter a fight; the crash comes after a few minutes.

What the log showed

Before (room line at 80 %, no reserve):

memory now: committed 22817 MB, the card's own 7845 MB in use of a
budget of 7092 MB, the PC's shared with the card 6861 MB in use;
host textures 34607 (5807 MB), aliased targets 0 MB, free texture blocks 325 MB
VIctory: host GPU failure: host GPU device removed ... (0x887A0007)

and, earlier in the same configuration, the command-list variant:

a host command list did not reset (0x8007000E); available RAM 704 MiB,
available commit 4741 MiB; DXGI usage/budget: local 7416/7141 MiB,
non-local 7181/7405 MiB

After (reserve 512 MB):

memory now: committed 21102 MB, the card's own 6446 MB in use of a
budget of 7060 MB, the PC's shared with the card 6582 MB in use;
host textures 28087 (4323 MB), aliased targets 0 MB, free texture blocks 368 MB

The card's own use then stays at 6.4-6.9 GiB of a 7.0-7.2 GiB budget (about
500-600 MiB free) across the sessions tested, with the world fully rendered,
and the run no longer ends.

A/B

Configuration Card's own / budget Host textures Result
VICTORY_TEXTURE_ROOM_PERCENT=80 only 7845 / 7092 MiB 5807 MiB device removed (0x887A0007)
no switches (default line, ~90 %) 8179 / 7135 MiB 5118 MiB a host command list did not reset (0x8007000E)
VICTORY_TEXTURE_KEEP_FREE_MB=512 6446-6900 / 7060-7181 MiB 4323 MiB no crash

Risks and limits

  • The reserve is off (0) by default on cards where nothing else changed:
    behaviour is exactly as before.
  • When the cap is reached, a first upload is refused and that slot draws
    black until copies are let go; with 512 MB on this card that did not show
    in play. A lower reserve (e.g. 1024 or 1536) trades texture churn for
    headroom, a higher one goes back towards the old failure.
  • The cap uses CurrentUsage from DXGI, which includes the driver's own
    allocations as well as ours; on cards whose budget moves under us
    (the log records moves of 256 MB and more) the cap moves with it.
  • Tested on one 8 GiB card and 16 GiB host; behaviour on larger cards is
    expected to be the same below their budget, but is untested here.

Tests

  • cargo test -p victory-gpu: the suite passes except
    ambient::tests::the_passes_build, which aborts the test process (exit 3)
    on this machine before any of this change runs; it is an ambient shader
    test and touches none of the code here.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings fails only in
    victory-shader (while_immutable_condition, 3 sites), which this
    branch does not touch.

Checked for overlap

A card that runs out of its budget mid-frame has the driver refuse a command list or remove the device (0x8007000E / 0x887A0007). With VICTORY_TEXTURE_ROOM_PERCENT=80 alone, an 8 GiB card still ended at DXGI local 7845/7092 MiB (host texture copies 5807 MiB): render targets, buffer copies and scratch are made with no room test of their own.

VICTORY_TEXTURE_KEEP_FREE_MB (512 MB by default, 0: off as before) keeps that much of the budget free: a first upload is admitted only while the host copies fit what the budget leaves after the other card bytes and the reserve, and the idle sweep takes idle copies down to the same line. An explicit VICTORY_TEXTURE_BUDGET_MB is now checked before the normal room line. VICTORY_CARD_BREAKDOWN=1 adds the host-texture, aliased-target and free-block breakdown to the memory line.
@github-actions github-actions Bot added the pr-fix Pull request: fixes a bug label Nov 30, 2026
@github-actions github-actions Bot changed the title [pr-fix] host: keep 512 MB of the card's budget free of texture copies host: keep 512 MB of the card's budget free of texture copies Nov 30, 2026
@maozhongmao

Copy link
Copy Markdown
Author

Update after v2026.11.30.01: on the machine this was reported from (16 GiB host, 8 GiB card) the release's play path already keeps the run stable - memory stays around 12 GB and it no longer ends. So this change is no longer the only way past the failure; what it still covers is the plain victory.exe run ... path and setups that do not start through the launcher's defaults, where the same 0x8007000E / 0x887A0007 remains reachable.

The A/B numbers above were taken before that release. Whether this belongs in the tree is up to you; I can re-run the numbers against c71899d if that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-fix Pull request: fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant