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

Open
kotekompotek wants to merge 1 commit from upstream-pr/3198 into main
kotekompotek commented 2026-11-26 12:06:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T12:06:14Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6626286279 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3198). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T12:06:14Z. --- 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.
AurumCarlos commented 2026-11-26 13:04:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T12:16:15Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6073971763 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3198#pullrequestreview-6073971763). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-26T12:16:15Z. **Review:** COMMENTED --- 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.
Dukestar69 commented 2026-11-26 14:01:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T13:08:26Z.

Review: APPROVED


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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6074664913 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3198#pullrequestreview-6074664913). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T13:08:26Z. **Review:** APPROVED --- 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).
oni-swr commented 2026-11-26 15:02:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T14:43:50Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7195238934 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3198#issuecomment-7195238934). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T14:43:50Z. --- **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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3198:upstream-pr/3198'
git switch 'upstream-pr/3198'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3198'
git switch 'upstream-pr/3198'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3198'
git switch 'upstream-pr/3198'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3198'
git switch 'main'
git merge --squash 'upstream-pr/3198'
git switch 'main'
git merge --ff-only 'upstream-pr/3198'
git switch 'main'
git merge 'upstream-pr/3198'
git push origin 'main'
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
Marvisak/VIctory!3196
No description provided.