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

Merged
maozhongmao merged 1 commit from upstream-pr/4005 into main 2026-11-30 16:28:30 +00:00
maozhongmao commented 2026-11-30 14:19:13 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by maozhongmao on 2026-11-30T14:19:13Z.


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

  • Searched open pull requests and issues for the same failure. Related
    history: bug-journal 923e38c / #1520 (16 GiB host reaching the 8 GiB
    shared-memory cap in ~95 s, 0x8007000E on a host command list) and the
    VICTORY_TEXTURE_ROOM_PERCENT knob, which the A/B above shows does not
    cover this case. #3994 (send spares under host memory pressure) and #4004
    (frame-log holdback reporting) touch other paths.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5567079696 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4005). Originally posted by [maozhongmao](https://github.com/maozhongmao) on 2026-11-30T14:19:13Z. --- 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 - [x] Searched open pull requests and issues for the same failure. Related history: bug-journal 923e38c / #1520 (16 GiB host reaching the 8 GiB shared-memory cap in ~95 s, `0x8007000E` on a host command list) and the `VICTORY_TEXTURE_ROOM_PERCENT` knob, which the A/B above shows does not cover this case. #3994 (send spares under host memory pressure) and #4004 (frame-log holdback reporting) touch other paths.
maozhongmao commented 2026-11-30 16:04:59 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by maozhongmao on 2026-11-30T16:04:59Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7284084507 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4005#issuecomment-7284084507). Originally posted by [maozhongmao](https://github.com/maozhongmao) on 2026-11-30T16:04:59Z. --- 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 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!4005
No description provided.