GPU: a placed texture without a host texture gives back its slot #3198

Open
github-bot wants to merge 1 commit from github-bot/gh-3198 into main AGit
Owner

@⁠kotekompotek on GitHub · 2026-11-26 12:06 UTC · original
kotekompotek:gpu/placed-texture-gives-back-its-slot → main · +36 −1 · 1 files · 1 commits · open

Fixes VIC-BT-027 from the audit list in #1242.

HostList-side texture lookup: texture_at inserts the freshly made resource into PLACED_TEXTURES before the host texture is known to exist. When CreateCommittedResource fails (or there is no host), the entry stays — and current() answers a cached resource whose host() is None (Some(None) passes the (_, Some(_)) key check and returns true), so every later texture_at for that slot returns the host-less resource forever. The slot is poisoned by its first failed lookup.

The fix gives the slot back: if resource(out).host() came back None, the map entry is removed (guarded against a racing inserter) so a later ask can try again.

Regression test a_placed_texture_without_a_host_texture_is_not_kept: a width-0 texture desc whose host texture cannot be made returns None and leaves no PLACED_TEXTURES entry, while a good desc still caches.

cargo clippy -p victory-gpu --all-targets clean on the pinned toolchain; the new test passes.

**@⁠kotekompotek** on GitHub · 2026-11-26 12:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/3198) `kotekompotek:gpu/placed-texture-gives-back-its-slot` → `main` · +36 −1 · 1 files · 1 commits · open Fixes VIC-BT-027 from the audit list in #1242. `HostList`-side texture lookup: `texture_at` inserts the freshly made resource into `PLACED_TEXTURES` before the host texture is known to exist. When `CreateCommittedResource` fails (or there is no host), the entry stays — and `current()` answers a cached resource whose `host()` is `None` (`Some(None)` passes the `(_, Some(_))` key check and returns `true`), so every later `texture_at` for that slot returns the host-less resource forever. The slot is poisoned by its first failed lookup. The fix gives the slot back: if `resource(out).host()` came back `None`, the map entry is removed (guarded against a racing inserter) so a later ask can try again. Regression test `a_placed_texture_without_a_host_texture_is_not_kept`: a width-0 texture desc whose host texture cannot be made returns `None` and leaves no `PLACED_TEXTURES` entry, while a good desc still caches. `cargo clippy -p victory-gpu --all-targets` clean on the pinned toolchain; the new test passes.
texture_at put its resource into the map before the host texture was
known to exist, and current() answers a cached resource whose host
texture never was — so a slot that failed once answered every later
ask with nothing.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:07:55 +00:00
Author
Owner

@⁠AurumCarlos on GitHub · 2026-11-26 12:16 UTC · original · reviewed

The diagnosis is right: Resource::host() stores a failed shared_texture as Some(None), current() returns true for it, and the slot then answers that host-less resource for good. The removal is keyed correctly too (desc is the normalised copy with words 1 and 13 zeroed), and the == Some(&(out as usize)) check avoids removing a racing inserter's entry.

One concern about what happens on the next ask, though:

Each retry leaks a resource and adds to PLACED_BYTES again. When the slot is given back, out is only removed from the map. It is never released, and the placed_size added to PLACED_BYTES just before is never subtracted. So the next texture_at for the same address and description runs create_at_address again (a new Resource, refcount 1), shared_texture again (a new CreateCommittedResource attempt), and fetch_add again.

For a failure that is transient (memory pressure), that's the point of the change. But for one that is deterministic, like the width-0 description in the test, the host texture can never be made. texture_at runs for the slots a submission's shaders read, so that becomes one leaked Resource, one failed host creation and one more PLACED_BYTES increment per draw that reads the slot, for the rest of the session. Before this change it cost one resource, once. PLACED_BYTES is only used in the host.rs stats line, so that part is cosmetic, but the leak and the repeated D3D12 calls on the draw path are not.

Some options:

  • Release out and subtract its placed_size when the slot is given back. Note that another thread may have picked out up from the map between drop(map) and the removal (the current() check passes for it until the host texture is stored), so releasing it there is only safe if every caller holds its own reference.
  • Or keep the failure cached, but let it expire. For example, keep a negative entry keyed by (address, desc) that is retried only after the memory key's host texture changes, or after N frames, so a description that can never succeed doesn't retry on every draw.

In both cases, a test that calls texture_at(address, &bad) twice and checks that nothing grows (PLACED_BYTES, or the count of live resources) would pin down the behaviour you choose.

A smaller point: the test returns early without a host, so on CI runners with no adapter it checks nothing. It might be worth noting that in the PR description next to the clippy/test line, so readers know which machine actually ran it.

**@⁠AurumCarlos** on GitHub · 2026-11-26 12:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/3198#pullrequestreview-6073971763) · **reviewed** The diagnosis is right: `Resource::host()` stores a failed `shared_texture` as `Some(None)`, `current()` returns `true` for it, and the slot then answers that host-less resource for good. The removal is keyed correctly too (`desc` is the normalised copy with words 1 and 13 zeroed), and the `== Some(&(out as usize))` check avoids removing a racing inserter's entry. One concern about what happens on the next ask, though: **Each retry leaks a resource and adds to `PLACED_BYTES` again.** When the slot is given back, `out` is only removed from the map. It is never released, and the `placed_size` added to `PLACED_BYTES` just before is never subtracted. So the next `texture_at` for the same address and description runs `create_at_address` again (a new `Resource`, refcount 1), `shared_texture` again (a new `CreateCommittedResource` attempt), and `fetch_add` again. For a failure that is transient (memory pressure), that's the point of the change. But for one that is deterministic, like the width-0 description in the test, the host texture can never be made. `texture_at` runs for the slots a submission's shaders read, so that becomes one leaked `Resource`, one failed host creation and one more `PLACED_BYTES` increment per draw that reads the slot, for the rest of the session. Before this change it cost one resource, once. `PLACED_BYTES` is only used in the `host.rs` stats line, so that part is cosmetic, but the leak and the repeated D3D12 calls on the draw path are not. Some options: - Release `out` and subtract its `placed_size` when the slot is given back. Note that another thread may have picked `out` up from the map between `drop(map)` and the removal (the `current()` check passes for it until the host texture is stored), so releasing it there is only safe if every caller holds its own reference. - Or keep the failure cached, but let it expire. For example, keep a negative entry keyed by `(address, desc)` that is retried only after the memory key's host texture changes, or after N frames, so a description that can never succeed doesn't retry on every draw. In both cases, a test that calls `texture_at(address, &bad)` twice and checks that nothing grows (`PLACED_BYTES`, or the count of live resources) would pin down the behaviour you choose. A smaller point: the test returns early without a host, so on CI runners with no adapter it checks nothing. It might be worth noting that in the PR description next to the clippy/test line, so readers know which machine actually ran it.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 13:08 UTC · original · approved these changes

Verified on RTX 5090 against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib resource:: -- --test-threads=1: passed.
  • cargo test -p victory-gpu --lib descriptor::host:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released: 14/14 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly releases the slot when a placed texture has no host texture.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 13:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/3198#pullrequestreview-6074664913) · **approved these changes** Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib resource:: -- --test-threads=1`: passed. - `cargo test -p victory-gpu --lib descriptor::host:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released`: 14/14 passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly releases the slot when a placed texture has no host texture. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 14:43 UTC · original

WARP verification of head a867f4fc (base = current main 63bcca4).

Setup: Windows 11, VICTORY_WARP=1 + VICTORY_D3D12_WARP=1, --features diagnostics (software adapter only, no physical GPU), Windows SDK dxil.dll, synthetic tests only.

  • cargo test -p victory-gpu --lib: 247 passed, 0 failed, 1 ignored
  • New test resource::tests::a_placed_texture_without_a_host_texture_is_not_kept: pass
  • Control (main + only this PR's test, no fix): fails (the failed texture is not kept)

Verified with Claude Code (Claude Sonnet 5.5).

**@⁠oni-swr** on GitHub · 2026-11-26 14:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/3198#issuecomment-7195238934) **WARP verification** of head `a867f4fc` (base = current main `63bcca4`). Setup: Windows 11, `VICTORY_WARP=1` + `VICTORY_D3D12_WARP=1`, `--features diagnostics` (software adapter only, no physical GPU), Windows SDK `dxil.dll`, synthetic tests only. - `cargo test -p victory-gpu --lib`: **247 passed, 0 failed, 1 ignored** - New test `resource::tests::a_placed_texture_without_a_host_texture_is_not_kept`: **pass** - Control (main + only this PR's test, no fix): **fails** (`the failed texture is not kept`) Verified with Claude Code (Claude Sonnet 5.5).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3198/head:github-bot/gh-3198'
git switch 'github-bot/gh-3198'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3198'
git switch 'github-bot/gh-3198'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3198'
git switch 'github-bot/gh-3198'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3198'
git switch 'main'
git merge --squash 'github-bot/gh-3198'
git switch 'main'
git merge --ff-only 'github-bot/gh-3198'
git switch 'main'
git merge 'github-bot/gh-3198'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3198
No description provided.