GPU: refresh and transition ResourceDescriptorHeap views before draws #1544

Closed
github-bot wants to merge 3 commits from gh-pr/1544/head into gh-pr/1544/base
Owner

@⁠n-romanovich on GitHub · 2026-11-24 19:01 UTC · original
n-romanovich:fix/bindless-resource-refresh → main · +182 −1 · 3 files · 3 commits · closed without merging

Summary

Fixes Issue #754.

Brings resources accessed through ResourceDescriptorHeap[] (RootType::ResourceHeap and dynamic bindless indexing) up to date before draws and dispatches:

  • crates/victory-gpu/src/descriptor/host.rs: track written title view slots (live_slots) and a monotonic generation counter (bumped on view writes, updates, and slot invalidations).
  • crates/victory-gpu/src/descriptor.rs: expose forgotten_epoch() bumped in forget() so stale/released resources are invalidated immediately.
  • crates/victory-gpu/src/draw.rs:
    • Handle explicit RootType::ResourceHeap entries via State::heap_entry.
    • Add State::refresh_heap to mirror deferred buffer views, refresh shadow buffers, upload title-written textures, and transition SRVs to SHADER_RESOURCE (skipping active render/depth targets), cached per (host_heap_ptr, generation, forgotten_epoch) per command list.
  • Added unit test shader_visible_heap_tracks_live_slots_and_generation.

Testing

Tested on Windows 11, NVIDIA GeForce RTX 5060 Ti:

  • cargo clippy --workspace --all-targets --locked -- -D warnings (pass)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings (pass)
  • cargo test -p victory-gpu --locked (51 passed, 0 failed, 1 ignored)

AI-assisted: implemented and reviewed with AI assistance.

**@⁠n-romanovich** on GitHub · 2026-11-24 19:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1544) `n-romanovich:fix/bindless-resource-refresh` → `main` · +182 −1 · 3 files · 3 commits · closed without merging ## Summary Fixes Issue #754. Brings resources accessed through `ResourceDescriptorHeap[]` (`RootType::ResourceHeap` and dynamic bindless indexing) up to date before draws and dispatches: - `crates/victory-gpu/src/descriptor/host.rs`: track written title view slots (`live_slots`) and a monotonic `generation` counter (bumped on view writes, updates, and slot invalidations). - `crates/victory-gpu/src/descriptor.rs`: expose `forgotten_epoch()` bumped in `forget()` so stale/released resources are invalidated immediately. - `crates/victory-gpu/src/draw.rs`: - Handle explicit `RootType::ResourceHeap` entries via `State::heap_entry`. - Add `State::refresh_heap` to mirror deferred buffer views, refresh shadow buffers, upload title-written textures, and transition SRVs to `SHADER_RESOURCE` (skipping active render/depth targets), cached per `(host_heap_ptr, generation, forgotten_epoch)` per command list. - Added unit test `shader_visible_heap_tracks_live_slots_and_generation`. ## Testing Tested on Windows 11, NVIDIA GeForce RTX 5060 Ti: - `cargo clippy --workspace --all-targets --locked -- -D warnings` (pass) - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` (pass) - `cargo test -p victory-gpu --locked` (51 passed, 0 failed, 1 ignored) AI-assisted: implemented and reviewed with AI assistance.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:35:45 +00:00
github-bot closed this pull request 2026-11-26 04:35:45 +00:00
Author
Owner

@⁠n-romanovich on GitHub · 2026-11-24 20:17 UTC · original

Updated in 78fd990:

Gated refresh_heap() on pipelines that actually use RootType::ResourceHeap so non-bindless UI/2D draws avoid unnecessary heap sweeps and stay at 30 fps.
Removed the unconditional shadow.gpu_writes() call inside refresh_heap() (explicit UAV entries are still handled via heap_entry()), eliminating redundant readback overhead.

**@⁠n-romanovich** on GitHub · 2026-11-24 20:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/1544#issuecomment-7143306821) Updated in 78fd990: Gated refresh_heap() on pipelines that actually use RootType::ResourceHeap so non-bindless UI/2D draws avoid unnecessary heap sweeps and stay at 30 fps. Removed the unconditional shadow.gpu_writes() call inside refresh_heap() (explicit UAV entries are still handled via heap_entry()), eliminating redundant readback overhead.
Author
Owner

@⁠titilyonnais on GitHub · 2026-11-24 21:15 UTC · original

Tested on AMD (RX 9070 XT): the world lasted longer, then a page fault inside freed textures

Setup: Windows 11 (build 26300), AMD RX 9070 XT (driver 32.0.32029.2010), retail dump 1.0.2.1. main at ffe310e, with and without this PR merged on top (no conflicts), both built with cargo build --profile diag -p victory --features diagnostics. cargo test -p victory-gpu passes with the PR (51 passed, 1 ignored). Both runs used VICTORY_D3D12_DEBUG=1 VICTORY_D3D12_DRED=1 VICTORY_GPU_TIMING=1 and the same shader cache, up to the intro mission in the world.

main main + #1544
Time in the world (from host frame 1,600 to the device removal) 77 s 223 s
Last host frame 1,679 1,774
Frame time at the end 1.8–2.7 s 1.7–1.8 s
Slow host submissions (longest) 24 (878 ms) 73 (1,029 ms)
How it ended page fault page fault

The two faults are not the same:

  • main: page fault at 0x45f4ee000, just past the end of a title memory copy (0xcaec00000+0x400000 at host 0x45f000000, offset 0x4ee000), and the report also has view heap 0x102800000+0x2e00000: 0x359eee000 past its end.
  • With this PR: page fault at 0x5dcbe6000; inside freed ["texture 1024x1024 f98 flags 0x0 (type 34)", "texture 2048x2048 f98 flags 0x0 (type 34)"]. The commands in flight are mesh draws (8b07450f04377f14, 264ae8d58e78b62d, 633c1f8872ed8c6d), whose tables all name placed SRVs.

So with the PR, the title lasts about three times longer in the world on this card, with no frame-time cost, and the fault moves to freed placed textures. I have not looked into which draw reads those textures or why.

Caveats: one run of each, and the world's streaming differs from run to run, so the 77 s vs 223 s needs more runs before it means much. I also did not check how often refresh_heap actually ran (it only runs for pipelines with a ResourceHeap entry). I can do more runs if that helps.

**@⁠titilyonnais** on GitHub · 2026-11-24 21:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/1544#issuecomment-7144680696) **Tested on AMD (RX 9070 XT): the world lasted longer, then a page fault inside freed textures** Setup: Windows 11 (build 26300), AMD RX 9070 XT (driver 32.0.32029.2010), retail dump 1.0.2.1. `main` at ffe310e, with and without this PR merged on top (no conflicts), both built with `cargo build --profile diag -p victory --features diagnostics`. `cargo test -p victory-gpu` passes with the PR (51 passed, 1 ignored). Both runs used `VICTORY_D3D12_DEBUG=1 VICTORY_D3D12_DRED=1 VICTORY_GPU_TIMING=1` and the same shader cache, up to the intro mission in the world. | | `main` | `main` + #1544 | |---|---|---| | Time in the world (from host frame 1,600 to the device removal) | 77 s | 223 s | | Last host frame | 1,679 | 1,774 | | Frame time at the end | 1.8–2.7 s | 1.7–1.8 s | | Slow host submissions (longest) | 24 (878 ms) | 73 (1,029 ms) | | How it ended | page fault | page fault | The two faults are not the same: - `main`: `page fault at 0x45f4ee000`, just past the end of a title memory copy (`0xcaec00000+0x400000 at host 0x45f000000, offset 0x4ee000`), and the report also has `view heap 0x102800000+0x2e00000: 0x359eee000 past its end`. - With this PR: `page fault at 0x5dcbe6000; inside freed ["texture 1024x1024 f98 flags 0x0 (type 34)", "texture 2048x2048 f98 flags 0x0 (type 34)"]`. The commands in flight are mesh draws (`8b07450f04377f14`, `264ae8d58e78b62d`, `633c1f8872ed8c6d`), whose tables all name placed SRVs. So with the PR, the title lasts about three times longer in the world on this card, with no frame-time cost, and the fault moves to freed placed textures. I have not looked into which draw reads those textures or why. Caveats: one run of each, and the world's streaming differs from run to run, so the 77 s vs 223 s needs more runs before it means much. I also did not check how often `refresh_heap` actually ran (it only runs for pipelines with a `ResourceHeap` entry). I can do more runs if that helps.
Author
Owner

@⁠aycow on GitHub · 2026-11-24 21:51 UTC · original

@⁠n-romanovich The same zero-instance mechanism reported in #71 has relevant changes on main 70564ae, notably c75fdba, 4051149 and bacb06a. We are building an independent synthetic control around a GPU-produced descriptor index, a known nonzero instance record and visibility/indirect argument readback. Have you seen a valid, still-null bindless buffer on this exact main, or a reproducible descriptor-lifetime or refresh gap that #1544 still fixes? An aggregate control could distinguish intentionally refused empty or out-of-bounds views from a valid view left null. We will keep the fixture separate from your implementation.

AI-assisted using Codex.

**@⁠aycow** on GitHub · 2026-11-24 21:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/1544#issuecomment-7145472620) @⁠n-romanovich The same zero-instance mechanism reported in #71 has relevant changes on main 70564ae, notably c75fdba, 4051149 and bacb06a. We are building an independent synthetic control around a GPU-produced descriptor index, a known nonzero instance record and visibility/indirect argument readback. Have you seen a valid, still-null bindless buffer on this exact main, or a reproducible descriptor-lifetime or refresh gap that #1544 still fixes? An aggregate control could distinguish intentionally refused empty or out-of-bounds views from a valid view left null. We will keep the fixture separate from your implementation. AI-assisted using Codex.
Author
Owner

@⁠aycow on GitHub · 2026-11-24 21:58 UTC · original

The independent synthetic control now passes on exact 70564ae plus tests on AMD and WARP with full GPU-based validation. A GPU-written index selected live or native-null slots for the same title buffer. The live path read the expected nonzero position, wrote visibility and args (1,1,1), and changed a sentinel via native ExecuteIndirect. The null control read zero, wrote (0,1,1), and left the sentinel intact. A later live read saw the updated record.

This gives us a reference for the current-main title comparison. Aggregate live/null counts, whether a null was refused as empty or out of bounds, the matching nonzero read/visibility counts, indirect groups, and the outcome at presentation would distinguish the remaining cases. The fixture does not exercise concurrent heap replacement, eager loading pressure, or title rendering.

AI-assisted using Codex.

**@⁠aycow** on GitHub · 2026-11-24 21:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/1544#issuecomment-7145643482) The [independent synthetic control](https://github.com/aycow/VIctory/commit/270c76666b50086bda28473e20b448fd90f6f88b) now passes on exact 70564ae plus tests on AMD and WARP with full GPU-based validation. A GPU-written index selected live or native-null slots for the same title buffer. The live path read the expected nonzero position, wrote visibility and args (1,1,1), and changed a sentinel via native ExecuteIndirect. The null control read zero, wrote (0,1,1), and left the sentinel intact. A later live read saw the updated record. This gives us a reference for the current-main title comparison. Aggregate live/null counts, whether a null was refused as empty or out of bounds, the matching nonzero read/visibility counts, indirect groups, and the outcome at presentation would distinguish the remaining cases. The fixture does not exercise concurrent heap replacement, eager loading pressure, or title rendering. AI-assisted using Codex.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:42 UTC · original

Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

the new head is the same change rebased; main brings heap-indexed views up to date per submission (bindless.rs, Step::Heap in Host::execute), while this walks every live heap slot per draw.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/1544#issuecomment-7148788743) Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. the new head is the same change rebased; main brings heap-indexed views up to date per submission (bindless.rs, Step::Heap in Host::execute), while this walks every live heap slot per draw. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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!1544
No description provided.