Skip to content

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

Open
BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:gpu/forgotten-reads-before-execute
Open

BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:gpu/forgotten-reads-before-execute

Conversation

@BastienRodz

@BastienRodz BastienRodz commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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

…fore it runs

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 <noreply@google.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Venom2054

Copy link
Copy Markdown

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.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

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.

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

Copy link
Copy Markdown
Owner

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

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: a slot's read in the submission right after its texture is placed or given up is wiped, so the view stays null

5 participants