Skip to content

GPU: refresh placed buffer tables after backing registration - #2158

Closed
andrewpozdnakov7-jpg wants to merge 5 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:fix/850-refresh-placed-buffer
Closed

andrewpozdnakov7-jpg wants to merge 5 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:fix/850-refresh-placed-buffer

Conversation

@andrewpozdnakov7-jpg

@andrewpozdnakov7-jpg andrewpozdnakov7-jpg commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Refs #850

A placed buffer SRV can already be mirrored against a loose shadow when the title registers a buffer for the same range. VIctory then refreshes the registered buffer, but the table still points at the loose shadow.

When the backing changes while an older recorded segment holds the heap, the next dispatch uses a temporary table keyed by the current backing. Once all recorded segments release the heap, its next bind refreshes the persistent slot.

Submission and reset

Current main keeps a queue-owned reference to each submitted host segment and gives a reset title list a fresh segment when the old one is held. The descriptor-heap lease lives in the old segment, with its recorded commands. Submission confirms the fence value before copy-back. A failed wait registration falls back to polling the completed value. Signal failure or device removal stops the submission before copy-back. D3D12 fence wait

Verification

The same synthetic Windows/WARP dispatch and texture readback on da82e444ec46a162ca779c82d4cf191a69182971 still gave 0 from the existing placed descriptor after buffer registration. At 4803f2b3d38fcbeb446cc2420cabc1f4b854fc8f, based on 67e8ae1401df112248aed36d0024483181b718b7, a new dispatch reads 1.25 through a temporary table while older segments retain the heap. The persistent slot then reads 1.25 after they retire, matching the fresh-descriptor control. The intervening upstream commit changes the shader test harness.

The queued-reset test keeps the old segment's lease until that segment executes and is recycled. The failed-wait test confirms actual completion before returning. Full GPU suite on WARP passed with 201 passed and 1 ignored under both D3D12 debug flag settings. Strict GPU Clippy passed with default and all features, and the asset policy passed.

The placed-buffer readback is confirmed. The relationship to the cutscene symptom in #850 and the frame-time cost of the per-draw check remain open. Previous verified head

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --features diagnostics --lib placed_buffer_tests — passed on RTX 5090
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (184 files ok)

Clean refresh of placed buffer tables after backing registration with end-to-end GPU test coverage. Looks good.

AI-assisted (Gemini 4 Neon).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Placed buffer tables refreshed after backing registration — table-refresh ordering fix; relates to #2120/#2130's buffer copy placement.

RecompLive added a commit to RecompLive/victory-fork that referenced this pull request Nov 25, 2026
A descriptor table is made afresh only when its slot reaches past the host heap. A placed buffer view keeps the same slot, but its backing copy changes once the title registers a resource at that address. Draws that reuse that table then read through the stale loose shadow, so the synthetic read-and-store shader writes zeros.

The table-fresh path now also checks the slot when it holds a placed buffer view: if the copy the view would use now differs from the kept slot, the table is made afresh. The table key hashes the copy buffer too, so two tables with one record but different backing are distinct.

From Marvisak/VIctory#2158 (GPL-3.0-or-later, by andrewpozdnakov7-jpg). Cherry-picked from 1bccc4f. Here, hand_out takes the title bytecode pointers as an extra argument, so the test passes &[]; it skips on this PC, where the runtime reports no SM 6.6 device.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate, with two points for the maintainer to weigh.

What it fixes. A placed-buffer view mirrored against a loose shadow kept that copy after the title registered a buffer over the same range. HostHeap (descriptor/host.rs) now tracks placed-buffer slots and refreshes them in lease_for_list once no recorded segment holds the heap. shadow::register/unregister bump the new binding generation. Until the refresh, State (draw.rs) gives an affected table fresh slots and keys the fresh-table cache by the backing buffer.

What I checked.

  • The lease lives in Deferred::view_heaps, so main's HostList::reset (*self.deferred() = Deferred::default()) and segment recycling release it. A heap is rewritten only when no segment can still execute.
  • The new synthetic WARP dispatch test reads 0 on main and 1.25 with the fix.
  • CI check passes on this head, and the branch merges cleanly into current main.

Points to weigh:


Generated by Claude Code

Keep the old persistent descriptor while a recorded list can execute with its heap. Refresh only the placed buffer slots when an idle heap binds again after a buffer registration change.
The loose shadow outlives the draw test. Give it a mapped window for later memory submissions in the same process.
@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

Thanks for the review. f325f85 refreshes the persistent placed-buffer slots when the first command list binds the idle heap after a buffer registration change. Earlier recorded lists keep the binding until reset or release, including a closed list that has yet to be submitted. Table arrays and bindless shaders can index beyond the explicitly named table entries, so this tracks the lifetime of the bound heap. A heap that stays continuously referenced still uses the temporary table for an affected draw until the heap becomes idle.

The draw-time backing check now skips heaps with no placed buffers. On the remaining heaps, it checks the tracked placed slot set before decoding a view or looking up a shadow. Fresh tables retain backing identity in their cache key, including tables beyond the native heap limit.

The same Windows/WARP test records a VIctory dispatch and reads the resulting texel. On main 940d32f, the existing slot read 0 after registration. On the previous PR head 1bccc4f, it read 1.25 through a temporary table even after the old lists retired. At f346d1d, it reads 1.25 through a temporary table while the older list can run, then reads 1.25 through the refreshed permanent slot.

The test now lives under draw and uses writable pool memory. Its source keeps a complete loose-shadow window mapped for later tests. The full GPU suite passed on WARP with 147 passed and 2 ignored, including a run with the D3D12 debug layer enabled. Strict GPU Clippy in both configurations and the staged asset policy passed. The link to the cutscene in #850 remains open.

If these changes are folded into another author's commit, please preserve attribution with this trailer:

Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com

Serialize reset with the submission of the same list and retain title list objects for the call. Confirm the fence before copy-back and reuse, even when the blocking wait fails.
@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

I checked the remaining reset and fence question on f346d1d. Host::execute serialized submissions, while HostList::reset could independently clear Deferred and reset the host allocator. The fence path also logged a failed wait and continued. Direct3D permits resetting the command list during execution, while VIctory reuses its paired allocator and must wait for that allocator safely. D3D12 allocator reset

1676f3d makes Host::execute hold the submitted lists' guards from preparation through confirmed fence completion and copy-back. HostList::reset takes the same guard before clearing its lease or reusing the allocator. The guest queue also retains each title list object through the call, so a concurrent Release of the caller's reference leaves the submission's reference alive.

After the queue signals, the synchronous wait is followed by a check of GetCompletedValue. A failed wait falls back to polling the fence while the list guards remain held. A failed signal or removed device follows the host failure path before copy-back. D3D12 fence completion

On Windows/WARP, a queued test fence held a native submission pending. The concurrent reset waited, the heap lease was live while it waited, and reset released it after the fence. The injected wait error also waited for the native fence. The guest Release check kept one submission reference. All three checks fail in a control build with their respective safeguards disabled. The existing readback test still reads 1.25 through a temporary table while older lists can execute and 1.25 through the permanent slot after retirement. Four focused tests passed. The full GPU suite passed with 150 passed and 2 ignored, both with and without the debug layer. The reset and wait checks passed 12 of 12 repeats. Both strict GPU Clippy modes and staged asset policy passed.

If this work is folded into another author's commit, please preserve attribution with this trailer:

Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

I updated this branch to current main 67e8ae1401df112248aed36d0024483181b718b7, preserving 1676f3d in its history. The old test still read 0 on da82e44. The updated head reads 1.25 from a temporary table while an older segment keeps the heap, then reads 1.25 from the persistent slot after retirement. Updated commit

The queue on current main owns the recorded host segments across title-list reset. I kept the lease with that segment and checked that it survives reset until the old segment runs and is recycled. The injected fence-wait failure still waits for the actual completed value. Full WARP GPU suite 201 passed and 1 ignored in both D3D12 debug flag settings. Strict GPU Clippy and asset policy passed. I updated the description to reflect these paths.

Please preserve Git authorship if carrying the fix or test into another branch. If folding it into another commit, please include the trailer below.

Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com

@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing because nothing shows the stale copy occurs in the title, and the mechanism is large with no measured cost: a lease per view heap per list, temporary fresh tables on hosts that make none today, a mutex and a set lookup per used table entry on every draw, and an idle-heap refresh that walks every placed-buffer slot whenever a title buffer was registered or released, which the title does every frame. The Host::execute rework is unrelated to placed buffers and changes the core submission path. If the bug is shown in the title, a smaller fix fits main: let mirror()/sync_slots make a placed-buffer slot again when its kept buffer is no longer the one view_copy(view) returns. The fence change can be its own PR.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

Thanks for suggesting the standalone fence change. #2899 carries that change and the WARP regression at fde6a92 on 842b0cb76f8f5fa9289bd779783c51ec24d75302.

The same test returned while the queue was still gated, with fence value 0 on main. In all six paired runs the patch waited until the queue reached 1. The full suite passed under both D3D12 debug settings and with GPU timing enabled.

Please preserve the Git author if cherry-picking the fix or test. If folded into another commit, please include Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com>.

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.

4 participants