Skip to content

GPU: giving up a texture leaves the dynamic slots of recorded lists alone - #2598

Open
BastienRodz wants to merge 2 commits into
Marvisak:mainfrom
BastienRodz:gpu/evict-keeps-live-dynamic-slots-pr
Open

BastienRodz wants to merge 2 commits into
Marvisak:mainfrom
BastienRodz:gpu/evict-keeps-live-dynamic-slots-pr

Conversation

@BastienRodz

Copy link
Copy Markdown
Contributor

What's wrong

HostHeap::evict (69d1e8e, which scans kept since ed25c0e) nulled every slot viewing a given-up texture. That included the dynamic slots of lists recorded but not yet reset: a list's descriptor tables for its draws, released only at reset and not made again before the list runs. Such a list's draws then read a null 2D view, and the slot no longer held the texture. resource.rs says lists recorded before an eviction keep what they use until they are reset.

What the fix does

In HostHeap::evict:

  • skip dynamic slots (index >= count) still taken in next, i.e. held by a list not yet reset;
  • keep nulling title slots and dynamic slots already released;
  • take made and next before scanning kept and hold them across the clearing, so a slot taken or rewritten meanwhile is not nulled. The order is made, then next, then kept (taken by keep), and no path holds kept while taking either of the other two.

Tests

New descriptor::host::tests::live_dynamic_slots_keep_a_texture_given_up: a placed texture viewed from a title slot, from a dynamic slot still held, and from a dynamic slot already released. When the texture is given up, the held dynamic slot must keep its view and texture, while the other two are nulled.

Results:

  • On main (67e8ae1) it fails: a live dynamic slot keeps its view.
  • With the fix it passes, and so do resource::tests (17) and descriptor::host::tests (13). The exception is dynamic_slots_are_held_until_released, which fails on main too under vkd3d-proton because of its heap cap. Run under Wine 10 with vkd3d-proton 3.1 on llvmpipe; without a host device the test returns early.
  • windows-latest run on the fork: https://github.com/BastienRodz/VIctory/actions/runs/45654306765

Not tested

No title run, and no AMD/NVIDIA GPU. How often a texture viewed from a held list's table is given up is not measured. It needs either a texture idle for longer than the eviction delay while a list recorded earlier still runs, or the budget pass reaching textures that recorded lists use.

Fixes #2597

AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed and verified it). No game data used.

🤖 Generated with Claude Code

…lone

Since 69d1e8e, giving up a host texture (idle, or past the card's
budget) nulls every heap slot viewing it (HostHeap::evict). Since
ed25c0e it finds them by scanning `kept`, which covers the dynamic slots
too: the descriptor tables lists build for their draws. A recorded list
not yet reset still uses those (the dynamic slots it took are not
released until then), and its table is not made again before it runs,
so its draws read a null 2D view, and the slot no longer held the
texture. resource.rs: "Lists recorded before hold it until they are
reset, so no GPU work reads it freed".

evict now leaves dynamic slots a list still holds (taken in `next`), and
holds `made` and `next` across the scan and the clearing.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@fyernald fyernald left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on an RTX 3080 (617.42), Windows 10 (19045), main 67e8ae1: cargo test -p victory-gpu --lib --locked -- --test-threads=1 gives 193 passed, 3 failed. live_dynamic_slots_keep_a_texture_given_up passes. The 3 failures also fail on main here: the two heap-cap tests (FIND-9) and the Windows 10 castable test (#1999).

I checked the lock order, since evict now holds next too. Every function in descriptor/host.rs that holds more than one of these locks takes made before kept (mirror, describe_slot, unmade_placed). dynamic and release hold next alone and call nothing that locks. So made → next → kept here can't deadlock with them.

One question, not a blocker: a texture given up while a recorded list holds its dynamic slot stays referenced from kept after the list resets. release only clears the taken bit, so the reference goes when the slot is next written by make_at, not at the reset. If evictions are about freeing video memory under pressure, that texture lives until the dynamic cursor comes back round. That's probably fine given how fast the dynamic range cycles, but worth a line in the comment.

Until the slot is next made, not until its list is reset (review by
fyernald).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BastienRodz

Copy link
Copy Markdown
Contributor Author

Thanks @fyernald, the lock-order check is appreciated. On your question: yes, a held dynamic slot keeps the given-up texture until the slot is next made, not until its list resets, since release only clears the taken bit. Dropping the reference at reset would mean release taking kept too, so I'd rather leave it and say so. 1c356e5 adds that line to the comment in evict.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

Verification of 1c356e5

Environment: Windows 11, D3D12 on the WARP software adapter only (VICTORY_D3D12_WARP=1, cargo ... --features diagnostics, which is what compiles that switch in; VICTORY_DXIL set to the Windows SDK dxil.dll). No physical GPU device was created. Not run on real GPU hardware.

  • Mergeable: git merge-tree against origin/main (67e8ae1) is clean.
  • cargo test -p victory-gpu --features diagnostics --lib live_dynamic_slots_keep_a_texture_given_up: 1 passed. I confirmed it runs on a real WARP device and is not skipped by the host() early return (checked on the earlier head ed0fa73).
  • Baseline-red: with the new evict slot filter disabled and the test kept, it fails at a live dynamic slot keeps its view. The test does catch GPU: giving up a texture nulls the dynamic descriptor slots of lists recorded before #2597.
  • Full cargo test -p victory-gpu --features diagnostics --lib at this head, two runs: 199 passed, 0 failed, 1 ignored.
  • cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings: clean.

Independent verification by Claude Code (Claude Sonnet 5.5), an AI assistant, run for oni-swr. No game files, dumps, or shader names were used.

@Machad3x

Copy link
Copy Markdown

Setup: RTX 3080 Ti (driver 621.24), Windows 11, a local stack of open PRs merged with main 67e8ae1.

Applied cleanly on that stack, together with #2601, #2576, #2611, #2626. One 10-minute game run reached gameplay with no device removal. These five PRs were not tested one by one, so nothing in that run is attributed to this PR alone.

Written with Claude Code; tested locally.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

In crates/victory-gpu/src/descriptor/host.rs, HostHeap::evict now skips dynamic slots (index >= count) that are still marked taken in next, so a recorded list that is not yet reset keeps the view and texture it uses when that texture is given up. Title slots and released dynamic slots are still nulled. I checked the index math (kept has count + dynamic entries and next.1 has dynamic, so taken.1[d] stays in bounds) and the lock order: made, then next, then kept. mirror takes made then kept, and dynamic/release take only next, so I found no inversion. One thing to weigh: made is now held during the full kept scan. Before, it was taken only after the scan, so title threads waiting on made may block a little longer while an eviction pass runs. The new test live_dynamic_slots_keep_a_texture_given_up covers held, released and title slots. CI: passing (check). This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GPU: giving up a texture nulls the dynamic descriptor slots of lists recorded before

5 participants