GPU: refresh and transition ResourceDescriptorHeap views before draws #1543

Closed
n-romanovich wants to merge 3 commits from upstream-pr/1544 into main
n-romanovich commented 2026-11-24 19:01:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by n-romanovich on 2026-11-24T19:01:30Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6589230582 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1544). Originally posted by [n-romanovich](https://github.com/n-romanovich) on 2026-11-24T19:01:30Z. --- ## 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 commented 2026-11-24 21:03:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by n-romanovich on 2026-11-24T20:17:12Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143306821 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1544#issuecomment-7143306821). Originally posted by [n-romanovich](https://github.com/n-romanovich) on 2026-11-24T20:17:12Z. --- 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.
titilyonnais commented 2026-11-24 21:28:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by titilyonnais on 2026-11-24T21:15:07Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144680696 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1544#issuecomment-7144680696). Originally posted by [titilyonnais](https://github.com/titilyonnais) on 2026-11-24T21:15:07Z. --- **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.
aycow commented 2026-11-24 22:02:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-24T21:51:07Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7145472620 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1544#issuecomment-7145472620). Originally posted by [aycow](https://github.com/aycow) on 2026-11-24T21:51:07Z. --- @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 commented 2026-11-24 22:02:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-24T21:58:53Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7145643482 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1544#issuecomment-7145643482). Originally posted by [aycow](https://github.com/aycow) on 2026-11-24T21:58:53Z. --- 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.
upstream-sync closed this pull request 2026-11-25 01:06:49 +00:00
Marvisak commented 2026-11-25 01:08:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:42:16Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148788743 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1544#issuecomment-7148788743). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:42:16Z. --- 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

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