GPU: read marks of slots forgotten before a submission are cleared before it runs #2576

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

@⁠BastienRodz on GitHub · 2026-11-25 16:08 UTC · original
BastienRodz:gpu/forgotten-reads-before-execute → main · +96 −14 · 2 files · 1 commits · open

What's wrong

HostHeap::mirror (a placed texture view left null until read) and HostHeap::evict (a texture given up) call shadow::forget_read(slot) so the slot's next read marks it again. Both run before the submission executes, inside sync_heaps and evict_unused in Host::execute. The forgotten marks were cleared only inside take_reads, after the submission. That wiped the mark a shader of that very submission had just set, so the slot was not made until a later submission read it again: at least one more frame with a null view, or forever if it was read only once. The behaviour comes from 52d14b1, and since 69d1e8e it also follows every eviction.

What the fix does

  • shadow::clear_forgotten_reads() clears the marks (bitmaps and seen) of slots forgotten since the last submission. Host::execute calls it just before ExecuteCommandLists, after evict_unused and sync_heaps.
  • take_reads still clears slots forgotten while the submission ran, such as a title thread rewriting a slot meanwhile.
  • The bitmap slices and the clearing are shared by both functions through read_marks and clear_forgotten. The marks are unchanged otherwise.

Tests

New host::tests::forgotten_slot_read_in_the_next_submission_is_made:

  • a placed texture view is written into a heap slot (left null);
  • a submission sets the slot's read mark on the GPU, like a shader reading it, and the view must be made after it;
  • the texture is then given up, and the next submission's read must make it again.

Results:

  • On main (67e8ae1) it fails: made after its first read.
  • With the fix it passes, as do host::tests, shadow::tests (8) and descriptor::host::tests. The exception is dynamic_slots_are_held_until_released, which also fails on main under vkd3d-proton (its heap cap is below HEAP_VIEWS). 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 (success): https://github.com/BastienRodz/VIctory/actions/runs/45651336090

Not tested

No title run, and no AMD/NVIDIA GPU. How many slots a frame loses this way is not measured.

Fixes #2574

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

🤖 Generated with Claude Code

**@⁠BastienRodz** on GitHub · 2026-11-25 16:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2576) `BastienRodz:gpu/forgotten-reads-before-execute` → `main` · +96 −14 · 2 files · 1 commits · open ### What's wrong `HostHeap::mirror` (a placed texture view left null until read) and `HostHeap::evict` (a texture given up) call `shadow::forget_read(slot)` so the slot's next read marks it again. Both run before the submission executes, inside `sync_heaps` and `evict_unused` in `Host::execute`. The forgotten marks were cleared only inside `take_reads`, after the submission. That wiped the mark a shader of that very submission had just set, so the slot was not made until a later submission read it again: at least one more frame with a null view, or forever if it was read only once. The behaviour comes from 52d14b1, and since 69d1e8e it also follows every eviction. ### What the fix does - `shadow::clear_forgotten_reads()` clears the marks (bitmaps and `seen`) of slots forgotten since the last submission. `Host::execute` calls it just before `ExecuteCommandLists`, after `evict_unused` and `sync_heaps`. - `take_reads` still clears slots forgotten while the submission ran, such as a title thread rewriting a slot meanwhile. - The bitmap slices and the clearing are shared by both functions through `read_marks` and `clear_forgotten`. The marks are unchanged otherwise. ### Tests New `host::tests::forgotten_slot_read_in_the_next_submission_is_made`: - a placed texture view is written into a heap slot (left null); - a submission sets the slot's read mark on the GPU, like a shader reading it, and the view must be made after it; - the texture is then given up, and the next submission's read must make it again. Results: - On `main` (67e8ae1) it fails: `made after its first read`. - With the fix it passes, as do `host::tests`, `shadow::tests` (8) and `descriptor::host::tests`. The exception is `dynamic_slots_are_held_until_released`, which also fails on `main` under vkd3d-proton (its heap cap is below `HEAP_VIEWS`). 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 (success): https://github.com/BastienRodz/VIctory/actions/runs/45651336090 ### Not tested No title run, and no AMD/NVIDIA GPU. How many slots a frame loses this way is not measured. Fixes #2574 AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed, simplified and verified it). No game data used. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Since 52d14b1 a heap slot whose texture view is left null (a placed
texture written into the heap, or one given up since 69d1e8e) is
forgotten (forget_read) so that its next read marks it again and
take_reads, after the submission, has its view made. Both happen before
the submission runs (sync_heaps, evict_unused), but the forgotten marks
were only cleared inside take_reads, after it ran: the mark a shader of
that very submission had just set was wiped with them. The slot was made
only after a later submission read it again (another frame of a null
view), or never if nothing read it again.

The marks of slots forgotten since the last submission are now cleared
just before the next one runs (clear_forgotten_reads); take_reads still
clears those forgotten while it ran.

Co-Authored-By: Gemini 4 Neon <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:09:37 +00:00
Author
Owner

@⁠Venom2054 on GitHub · 2026-11-25 16:20 UTC · original

Tested 67e8ae1 (parent) and c040ff1 on native Windows 11 with an RTX 5070 Ti (NVIDIA 621.01) and D3D12 WARP. I ran forgotten_slot_read_in_the_next_submission_is_made in a fresh process for each adapter and each of the two read bitmaps, with a required D3D12 device and a check of its DXGI adapter name.

Adapter Parent With this PR
RTX 5070 Ti Both fail at made after its first read Both pass, including the first read after eviction
WARP Both fail at the same assertion Both pass, including the first read after eviction

I also counted slot indices forgotten immediately before a submission and returned by take_reads() after that same submission. The counter saw one matching slot at each of the two expected points in the fixture. In one prologue run on the RTX, 0 of 514 submissions with forgotten slots had a match. That run used the PR plus the typed-UAV format change from #1926 (93c4e181) and counters. The device reported DXGI_ERROR_DEVICE_HUNG at 79.6 s, before the first world frame. This confirms the fix on native D3D12; its effect on visible textures in the world is still open.

Tested with OpenAI Codex assistance.

**@⁠Venom2054** on GitHub · 2026-11-25 16:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2576#issuecomment-7167795881) Tested `67e8ae1` (parent) and `c040ff1` on native Windows 11 with an RTX 5070 Ti (NVIDIA 621.01) and D3D12 WARP. I ran `forgotten_slot_read_in_the_next_submission_is_made` in a fresh process for each adapter and each of the two read bitmaps, with a required D3D12 device and a check of its DXGI adapter name. | Adapter | Parent | With this PR | | --- | --- | --- | | RTX 5070 Ti | Both fail at `made after its first read` | Both pass, including the first read after eviction | | WARP | Both fail at the same assertion | Both pass, including the first read after eviction | I also counted slot indices forgotten immediately before a submission and returned by `take_reads()` after that same submission. The counter saw one matching slot at each of the two expected points in the fixture. In one prologue run on the RTX, **0 of 514 submissions with forgotten slots** had a match. That run used the PR plus the typed-UAV format change from #1926 (`93c4e181`) and counters. The device reported `DXGI_ERROR_DEVICE_HUNG` at 79.6 s, before the first world frame. This confirms the fix on native D3D12; its effect on visible textures in the world is still open. Tested with OpenAI Codex assistance.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 16:33 UTC · original

oni-swr verification — head c040ff1e378aaa9d31a0b075fe1d5be1c8a764f2, origin/main 67e8ae1401df112248aed36d0024483181b718b7

Environment: Windows 11 Pro (26200), rustc 1.98.1, WARP only (VICTORY_D3D12_WARP=1 with --features diagnostics, which is what makes the host device the software adapter; Windows SDK 10.0.26100.0 dxil.dll on PATH). No hardware GPU use in the reported runs, no game files, no retail data. Merge check: git merge-tree --write-tree origin/main <head> is clean.

Commands / results

  • cargo test --locked -p victory-gpu --features diagnostics --lib -- forgotten_slot host::tests shadow::tests: 35 passed, 0 failed, 0 ignored (includes the new host::tests::forgotten_slot_read_in_the_next_submission_is_made; it needs a host device, which on this setup is WARP, so it did not return early)
  • cargo test --locked -p victory-gpu --features diagnostics --lib: 4 repeated runs 199 passed / 0 failed / 1 ignored; --test-threads=1: 199 / 0 / 1. One earlier run failed only memory::tests::a_submission_that_missed_leaves_the_copies_at_once, the unrelated WARP flake I also measured on origin/main (9/60 runs); it passes alone.
  • Regression check: the PR's tests and shadow.rs on origin/main with only the clear_forgotten_reads() call in Host::execute removed: the new test fails (made after its first read, host.rs:476); with the call it passes.

Review: the logic matches #2574: forgotten marks (from mirror / evict before ExecuteCommandLists) are cleared right before the submission, so the submission's own reads survive for take_reads; take_reads still clears slots forgotten while it ran. Extracting read_marks/clear_forgotten keeps both paths identical. Ordering is right (after evict_unused and sync_heaps). One observation, not a defect: clear_forgotten_reads returns early when no bitmap is mapped, leaving the forgotten list for later, as take_reads already did. I found no defects.

Overlap: #2574 is the issue this fixes; no other open PR addresses it. #2472, #2545, #2540, #2474, #2559 and #2573 also touch host.rs and merge with this branch cleanly (merge-tree).

AI disclosure: this review and verification were done by Claude Code (Claude Sonnet 5.5), not a human reviewer. Comment-only; no code changed.

**@⁠oni-swr** on GitHub · 2026-11-25 16:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2576#issuecomment-7168182244) **oni-swr verification** — head `c040ff1e378aaa9d31a0b075fe1d5be1c8a764f2`, `origin/main` `67e8ae1401df112248aed36d0024483181b718b7` **Environment:** Windows 11 Pro (26200), rustc 1.98.1, **WARP only** (`VICTORY_D3D12_WARP=1` with `--features diagnostics`, which is what makes the host device the software adapter; Windows SDK 10.0.26100.0 `dxil.dll` on PATH). No hardware GPU use in the reported runs, no game files, no retail data. Merge check: `git merge-tree --write-tree origin/main <head>` is clean. **Commands / results** - `cargo test --locked -p victory-gpu --features diagnostics --lib -- forgotten_slot host::tests shadow::tests`: 35 passed, 0 failed, 0 ignored (includes the new `host::tests::forgotten_slot_read_in_the_next_submission_is_made`; it needs a host device, which on this setup is WARP, so it did not return early) - `cargo test --locked -p victory-gpu --features diagnostics --lib`: 4 repeated runs 199 passed / 0 failed / 1 ignored; `--test-threads=1`: 199 / 0 / 1. One earlier run failed only `memory::tests::a_submission_that_missed_leaves_the_copies_at_once`, the unrelated WARP flake I also measured on `origin/main` (9/60 runs); it passes alone. - Regression check: the PR's tests and `shadow.rs` on `origin/main` with only the `clear_forgotten_reads()` call in `Host::execute` removed: the new test **fails** (`made after its first read`, `host.rs:476`); with the call it passes. **Review:** the logic matches #2574: forgotten marks (from `mirror` / `evict` before `ExecuteCommandLists`) are cleared right before the submission, so the submission's own reads survive for `take_reads`; `take_reads` still clears slots forgotten while it ran. Extracting `read_marks`/`clear_forgotten` keeps both paths identical. Ordering is right (after `evict_unused` and `sync_heaps`). One observation, not a defect: `clear_forgotten_reads` returns early when no bitmap is mapped, leaving the forgotten list for later, as `take_reads` already did. I found no defects. **Overlap:** #2574 is the issue this fixes; no other open PR addresses it. #2472, #2545, #2540, #2474, #2559 and #2573 also touch `host.rs` and merge with this branch cleanly (`merge-tree`). AI disclosure: this review and verification were done by Claude Code (Claude Sonnet 5.5), not a human reviewer. Comment-only; no code changed.
Author
Owner

@⁠Machad3x on GitHub · 2026-11-25 18:26 UTC · original

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, #2598, #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.

**@⁠Machad3x** on GitHub · 2026-11-25 18:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2576#issuecomment-7170913542) 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, #2598, #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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:17 UTC · original

Automated triage for the maintainers.

Merge candidate. This fixes #2574. Read marks of slots forgotten by HostHeap::mirror/evict during evict_unused and sync_heaps were cleared only in take_reads, after the submission, which wiped the mark the same submission had just set. The new shadow::clear_forgotten_reads clears them in Host::execute after both calls and before ExecuteCommandLists. take_reads keeps clearing slots forgotten while the submission ran. The read_marks/clear_forgotten split keeps the bitmap handling the same for both paths. The existing take_reads test still holds by my reading, and the new host test reproduces the lost read.

CI: check passing. Merges cleanly into current main. A recommendation to look at it, not an approval.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 22:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2576#issuecomment-7176169490) <!-- victory-triage v1 head=c040ff1e378aaa9d31a0b075fe1d5be1c8a764f2 verdict=merge-candidate at=2026-11-25T22:16:58Z --> Automated triage for the maintainers. **Merge candidate.** This fixes #2574. Read marks of slots forgotten by `HostHeap::mirror`/`evict` during `evict_unused` and `sync_heaps` were cleared only in `take_reads`, after the submission, which wiped the mark the same submission had just set. The new `shadow::clear_forgotten_reads` clears them in `Host::execute` after both calls and before `ExecuteCommandLists`. `take_reads` keeps clearing slots forgotten while the submission ran. The `read_marks`/`clear_forgotten` split keeps the bitmap handling the same for both paths. The existing `take_reads` test still holds by my reading, and the new host test reproduces the lost read. CI: `check` passing. Merges cleanly into current `main`. A recommendation to look at it, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
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/2576/head:github-bot/gh-2576'
git switch 'github-bot/gh-2576'

Merge

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