GPU: retry a fallback descriptor heap that could not be created #4807

Open
github-bot wants to merge 16 commits from github-bot/gh-4806 into main AGit
Owner

@⁠Jineggegg on GitHub · 2026-12-01 09:33 UTC · original
Jineggegg:fallback-heap-retry → main · +134 −77 · 2 files · 16 commits · open

Based on main at e1251c31; one commit.

Problem

Sometimes the title binds no view heap or no sampler heap, but the draw uses a root signature with CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED or SAMPLER_HEAP_DIRECTLY_INDEXED. The host then binds a 1-descriptor fallback heap (Host::fallback_view_heap, Host::fallback_sampler_heap).

Both heaps are cached as OnceLock<Option<ID3D12DescriptorHeap>>. If the first CreateDescriptorHeap fails (memory pressure, or a transient driver refusal), None stays cached for the rest of the run. From then on, every list that needs the fallback sets the root signature without both heaps bound. That is debug-layer error 1419, and on NVIDIA it removes the device.

The draw path also marks its heaps as set when one of the two is missing (draw.rs, host_heaps_set). So it does not try again until the title's heaps change.

Reproduction

This is a resource-exhaustion path, so a normal run does not hit it on demand. To force it:

  1. Make the first fallback heap creation fail. For example, return an error from the closure in fallback_view_heap on its first call, or run with VRAM nearly exhausted by another process.
  2. Run a scene where a pass binds no view heap but its root signature indexes the heap directly. Turn the D3D12 debug layer on.
  3. Before this change: error 1419 on every such draw for the rest of the run, and the device is removed on NVIDIA. After: only the draws before the next successful creation are affected; binding then returns to normal.

Change

  • New helper made_once(cell, make). It keeps a value in a OnceLock<T> only if make produced one.
    • A failure leaves the cell empty, so the next caller tries again.
    • If several callers race, all of them get the value published first. The extra heaps are dropped.
    • A caller that fails while another thread publishes gets the published heap.
  • fallback_view and fallback_sampler become OnceLock<ID3D12DescriptorHeap> and use made_once. The heap creation code is unchanged.
  • In draw.rs (heap binding before the root signature), host_heaps_set is set only when both heaps were bound. While a fallback is missing, the next draw or dispatch tries again.

Once the heap exists, nothing changes: the fast path is a single OnceLock::get, as before. In a normal run both heaps are always bound (the title's or the fallback), so host_heaps_set behaves as before.

Tests

New unit tests, no GPU needed (host::made_once_tests):

  • a_failure_is_tried_again_and_a_success_is_kept: failures are not cached, the first success is kept, and nothing is made after it.
  • racing_callers_all_get_the_value_published_first: a caller that fails while another publishes gets the published value; 8 racing threads (half of them failing) all see one value.

Results on Windows (toolchain pinned in rust-toolchain.toml, Rust 1.98.1; RTX 5090, driver 621.14):

  • Clippy. main (e1251c31) does not pass -D warnings at the moment: 4 warnings without --all-features (field loop_caps is never read in crates/victory-shader/src/emit/lower.rs; manual implementation of .is_multiple_of() in crates/victory-gpu/src/host.rs; match can be simplified with .unwrap_or_default() in crates/victory-hle/src/modules/xmem.rs; method ranged is never used in crates/victory-gpu/src/shadow.rs) and 5 with it (also function mb is never used in crates/victory-gpu/src/copystat.rs). Both CI configurations were therefore run without -D and compared with main's diagnostics. This branch adds none, in either configuration.
  • cargo test --workspace --locked --no-fail-fast on the GPU: 2522 passed, 6 failed, 96 ignored (main: 2520 passed, 5 failed, 96 ignored). The failures main has itself (list::thin::tests::bindings_record_no_work, shader_cache::tests::every_switch_of_the_translator_is_in_the_key, emit::bitcode::opt::tests::hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity, policy::tests::repository_passes_policy), and host::card_steps::tests::shared_scratch_eliminates_flight_settle_end_to_end. That one is intermittent on main too: running the victory-gpu lib tests of main, this branch and two other branches in turn in one GPU window, it failed in 1 of 22 runs on main and 0 of 22 on this branch. The test expects each round's first submission (a few milliseconds of GPU copies) to be still in flight when the second is submitted; in the failing round the second submission took 110 µs because the first had already finished. This change does not touch that path. So no new failure. Failing on main but passing here: victory_hle::modules::xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it. Unit tests that need no device, cargo test -p victory-gpu --lib: host::made_once_tests: 2 passed, 0 failed.

Performance

Nothing to measure on the normal path: once a fallback heap exists, the only cost is the same OnceLock::get as before, and the draw path binds the same heaps. The change only matters after a failed creation. It is a correctness fix for an edge case, not a speed change.

Risk

  • Low. A device that fails the allocation every time now tries again on each draw that needs the heap. That costs one failed CreateDescriptorHeap and one redundant SetDescriptorHeaps per such draw, only while creation keeps failing.
  • Callers that race can briefly create two 1-descriptor heaps; one of them is dropped.

Attribution

Ported from the author's own fork, where the same fix was made for its empty view heap. No third-party code.

AI assistance: the change, its tests and this description were prepared with an AI coding assistant (Claude Code) and checked by the results above.

🤖 Generated with Claude Code

**@⁠Jineggegg** on GitHub · 2026-12-01 09:33 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4806) `Jineggegg:fallback-heap-retry` → `main` · +134 −77 · 2 files · 16 commits · open Based on `main` at `e1251c31`; one commit. ## Problem Sometimes the title binds no view heap or no sampler heap, but the draw uses a root signature with `CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED` or `SAMPLER_HEAP_DIRECTLY_INDEXED`. The host then binds a 1-descriptor fallback heap (`Host::fallback_view_heap`, `Host::fallback_sampler_heap`). Both heaps are cached as `OnceLock<Option<ID3D12DescriptorHeap>>`. If the first `CreateDescriptorHeap` fails (memory pressure, or a transient driver refusal), `None` stays cached for the rest of the run. From then on, every list that needs the fallback sets the root signature without both heaps bound. That is debug-layer error 1419, and on NVIDIA it removes the device. The draw path also marks its heaps as set when one of the two is missing (`draw.rs`, `host_heaps_set`). So it does not try again until the title's heaps change. ## Reproduction This is a resource-exhaustion path, so a normal run does not hit it on demand. To force it: 1. Make the first fallback heap creation fail. For example, return an error from the closure in `fallback_view_heap` on its first call, or run with VRAM nearly exhausted by another process. 2. Run a scene where a pass binds no view heap but its root signature indexes the heap directly. Turn the D3D12 debug layer on. 3. Before this change: error 1419 on every such draw for the rest of the run, and the device is removed on NVIDIA. After: only the draws before the next successful creation are affected; binding then returns to normal. ## Change - New helper `made_once(cell, make)`. It keeps a value in a `OnceLock<T>` only if `make` produced one. - A failure leaves the cell empty, so the next caller tries again. - If several callers race, all of them get the value published first. The extra heaps are dropped. - A caller that fails while another thread publishes gets the published heap. - `fallback_view` and `fallback_sampler` become `OnceLock<ID3D12DescriptorHeap>` and use `made_once`. The heap creation code is unchanged. - In `draw.rs` (heap binding before the root signature), `host_heaps_set` is set only when both heaps were bound. While a fallback is missing, the next draw or dispatch tries again. Once the heap exists, nothing changes: the fast path is a single `OnceLock::get`, as before. In a normal run both heaps are always bound (the title's or the fallback), so `host_heaps_set` behaves as before. ## Tests New unit tests, no GPU needed (`host::made_once_tests`): - `a_failure_is_tried_again_and_a_success_is_kept`: failures are not cached, the first success is kept, and nothing is made after it. - `racing_callers_all_get_the_value_published_first`: a caller that fails while another publishes gets the published value; 8 racing threads (half of them failing) all see one value. Results on Windows (toolchain pinned in `rust-toolchain.toml`, Rust 1.98.1; RTX 5090, driver 621.14): - Clippy. `main` (`e1251c31`) does not pass `-D warnings` at the moment: 4 warnings without `--all-features` (field `loop_caps` is never read in `crates/victory-shader/src/emit/lower.rs`; manual implementation of `.is_multiple_of()` in `crates/victory-gpu/src/host.rs`; match can be simplified with `.unwrap_or_default()` in `crates/victory-hle/src/modules/xmem.rs`; method `ranged` is never used in `crates/victory-gpu/src/shadow.rs`) and 5 with it (also function `mb` is never used in `crates/victory-gpu/src/copystat.rs`). Both CI configurations were therefore run without `-D` and compared with `main`'s diagnostics. This branch adds none, in either configuration. - `cargo test --workspace --locked --no-fail-fast` on the GPU: 2522 passed, 6 failed, 96 ignored (`main`: 2520 passed, 5 failed, 96 ignored). The failures `main` has itself (`list::thin::tests::bindings_record_no_work`, `shader_cache::tests::every_switch_of_the_translator_is_in_the_key`, `emit::bitcode::opt::tests::hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity`, `policy::tests::repository_passes_policy`), and `host::card_steps::tests::shared_scratch_eliminates_flight_settle_end_to_end`. That one is intermittent on `main` too: running the `victory-gpu` lib tests of `main`, this branch and two other branches in turn in one GPU window, it failed in 1 of 22 runs on `main` and 0 of 22 on this branch. The test expects each round's first submission (a few milliseconds of GPU copies) to be still in flight when the second is submitted; in the failing round the second submission took 110 µs because the first had already finished. This change does not touch that path. So no new failure. Failing on `main` but passing here: `victory_hle::modules::xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it`. Unit tests that need no device, `cargo test -p victory-gpu --lib`: `host::made_once_tests`: 2 passed, 0 failed. ## Performance Nothing to measure on the normal path: once a fallback heap exists, the only cost is the same `OnceLock::get` as before, and the draw path binds the same heaps. The change only matters after a failed creation. It is a correctness fix for an edge case, not a speed change. ## Risk - Low. A device that fails the allocation every time now tries again on each draw that needs the heap. That costs one failed `CreateDescriptorHeap` and one redundant `SetDescriptorHeaps` per such draw, only while creation keeps failing. - Callers that race can briefly create two 1-descriptor heaps; one of them is dropped. ## Attribution Ported from the author's own fork, where the same fix was made for its empty view heap. No third-party code. AI assistance: the change, its tests and this description were prepared with an AI coding assistant (Claude Code) and checked by the results above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`slots_showing` took the slot's `Made` key with `?`, but `Made` has keys
for the title's `count` slots only while `kept` also has the dynamic
ones: a host texture shown by a dynamic slot was no longer reported, so
it was no longer blocked and could be chosen (freeing nothing, as the
dynamic slot holds a reference, while the title made a second copy).
Those slots are reported again with key 0, as before the key was carried;
they are never put back to waiting, only counted as blocking. Test:
`a_dynamic_slot_showing_a_texture_still_blocks_its_eviction`.

`SLOT_LOOKING` is now cleared by a drop guard, so a look that panics does
not stop every later look.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit b23c0c4038)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The 1-descriptor fallback view and sampler heaps, bound for a
directly-indexed root signature when the title binds none, were
`OnceLock<Option<_>>`: one failed CreateDescriptorHeap (memory pressure,
a transient driver refusal) was kept for the rest of the run, and every
later list using such a root signature went without the heap (the debug
layer's 1419; removes the device on NVIDIA).

Only a heap made is kept now (`made_once`): a failure leaves the cell
empty and the next list that needs the heap tries again; callers racing
to make one all get the one published first. The draw path no longer
marks its heaps set while one of the two is missing, so the next draw
or dispatch tries again instead of waiting for the title's heaps to
change.

Tests: `made_once` keeps failures out and the first success in, also
with racing callers (no GPU needed).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 09:39:51 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-12-01 09:54 UTC · original

I cherry-picked 5156288 onto current main 5fabb46 as 8aa89eb. The Git author and patch ID match, and the unrelated release history drops out of the comparison.

One gap remains after the retry change. The draw path still reaches the root signature on the first missing-heap call. Victory's root signatures set both directly indexed heap flags, and D3D12 requires those heaps to be bound before the root signature. DirectX Shader Model 6.6 specification

Proposed follow-up commit returns from State::bind before recording a root signature while either heap is missing. The calling draw and dispatch paths already honor that result. The next call tries the fallback again.

A native Rust fixture using the exact binding blocks checked a missing view heap, a missing sampler heap and both missing. In all three cases the author head proceeded to the root signature. The patch skipped the recording step and, on retry, bound both heaps before the root signature. The fixture mocks D3D12 calls. cargo check --locked -p victory-gpu --jobs 2 and the staged policy check for the follow-up passed.

Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the follow-up into another commit.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-12-01 09:54 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4806#issuecomment-7307373012) I cherry-picked `5156288` onto current `main` `5fabb46` as `8aa89eb`. The Git author and patch ID match, and the unrelated release history drops out of the comparison. One gap remains after the retry change. The draw path still reaches the root signature on the first missing-heap call. Victory's root signatures set both directly indexed heap flags, and D3D12 requires those heaps to be bound before the root signature. [DirectX Shader Model 6.6 specification](https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_DynamicResources.html#setdescriptorheaps-and-setrootsignature) [Proposed follow-up commit](https://github.com/andrewpozdnakov7-jpg/VIctory-NVIDIA/commit/a1e50eb673ff3b7388859bbccfc021c0c934b260) returns from `State::bind` before recording a root signature while either heap is missing. The calling draw and dispatch paths already honor that result. The next call tries the fallback again. A native Rust fixture using the exact binding blocks checked a missing view heap, a missing sampler heap and both missing. In all three cases the author head proceeded to the root signature. The patch skipped the recording step and, on retry, bound both heaps before the root signature. The fixture mocks D3D12 calls. `cargo check --locked -p victory-gpu --jobs 2` and the staged policy check for the follow-up passed. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the follow-up into another commit.
main was rewritten after this branch was made: e1251c31 and the 13 commits
before it are no longer on main, so GitHub showed the branch as conflicting
(in host/menu.rs and modules/xmem.rs, which this branch does not change).
This merge takes main as it is now and keeps only this branch's change,
which applies to it without conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠Jineggegg on GitHub · 2026-12-01 11:19 UTC · original

Thanks for checking this against current main and for the follow-up. It's right: Victory's root signatures set both directly indexed heap flags, so binding the root signature with a heap missing was wrong.

I've taken your commit as it was, with you as the Git author (4572d52a, on top of a merge of main 5fabb46e into this branch). It applied cleanly. State::bind's three callers already skip the draw or dispatch when it returns false, and the two tests that assert it succeeds set both heaps first.

Checked on Windows (Rust 1.98.1, RTX 5090):

  • Both Clippy configurations (with and without --all-features) report the same 5 warnings as main 5fabb46e, and nothing else. CI's -D warnings stops on those 5 on main too.
  • cargo test --workspace --locked: 2489 passed, 1 failed, 96 ignored. The failure is modules::xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it, which also fails on main. Nothing new.
**@⁠Jineggegg** on GitHub · 2026-12-01 11:19 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4806#issuecomment-7309489899) Thanks for checking this against current `main` and for the follow-up. It's right: Victory's root signatures set both directly indexed heap flags, so binding the root signature with a heap missing was wrong. I've taken your commit as it was, with you as the Git author (`4572d52a`, on top of a merge of `main` `5fabb46e` into this branch). It applied cleanly. `State::bind`'s three callers already skip the draw or dispatch when it returns false, and the two tests that assert it succeeds set both heaps first. Checked on Windows (Rust 1.98.1, RTX 5090): - Both Clippy configurations (with and without `--all-features`) report the same 5 warnings as `main` `5fabb46e`, and nothing else. CI's `-D warnings` stops on those 5 on `main` too. - `cargo test --workspace --locked`: 2489 passed, 1 failed, 96 ignored. The failure is `modules::xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it`, which also fails on `main`. Nothing new.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/4807/head:github-bot/gh-4806'
git switch 'github-bot/gh-4806'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-4806'
git switch 'github-bot/gh-4806'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-4806'
git switch 'github-bot/gh-4806'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-4806'
git switch 'main'
git merge --squash 'github-bot/gh-4806'
git switch 'main'
git merge --ff-only 'github-bot/gh-4806'
git switch 'main'
git merge 'github-bot/gh-4806'
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/trustno1-coder--VIctory-NVIDIA!4807
No description provided.