GPU: preserve disjoint shadow refresh ranges #1816
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1818"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-24T22:58:50Z.
What changed
Keep the union of requested refresh ranges through the pending and completed parts of a submission batch. The previous bounding range copied 192 KiB for two 64 KiB requests and consumed the dirty page in the gap before its reader. The fixture now copies 128 KiB for the two requests and 64 KiB when the gap is requested later. The common one-range case retains inline storage.
Thanks to @pablogonz12 for the original reproduction in #185. This carries the narrow range correction onto the current unified journal. It preserves the ranges supplied to the batch. Callers that pass a bounding range still request all of it. #1472 changes when the batch flushes around a GPU write. This PR retains the requested ranges without altering those flush points. Original report · Related flush work
Verification
All four disjoint refresh regressions passed on AMD Radeon Graphics and WARP at
4a191d8with native device creation required. The cases cover the gap's later reader, repeated reads after a physical alias write, decommit and remap at the same address, and partial refreshes of declared UAV writes. The last case exercises #1322's preparation contract and confirms copyback preserves a later CPU write to a neighboring byte. Strict diagnostics Clippy passed. The updated fixture also verifies that zeroing an unmapped page leaves the copied-byte count at zero.The copied-byte results are from the synthetic fixture. Title preparation and frame-time effects remain unverified.
AI-assisted using Codex. Generated test data only.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T23:03:28Z.
Review: COMMENTED
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Disjoint shadow refresh ranges preserved: 18K gpu diff on shadow/refresh range tracking. Windows-only.
Imported from Marvisak/VIctory. Originally posted by Melow-code on 2026-11-24T23:08:03Z.
Review: COMMENTED
Union logic is correct — half-open ranges, dedup_by in the right order, covers only called after merge. Two disjoint ranges in one page are safe because Tracked::take keeps a partly-copied page as changed.
Two points before merge:
Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-24T23:22:12Z.
@ruipedro-pinheiro Agreed on comparing the per-range cost in a matched world run. Each disjoint span does call
Shadow::updateseparately. The synthetic case confirms the copy-volume change from 192 KiB to 128 KiB and preserves the gap's dirty page for its later reader. It leaves world frame time unverified.I checked @Texbirds’ #1555 at
9fb81e1. It joins gaps of up to and including 64 KiB, so it would join the exact dirty 64 KiB gap in this fixture. #1818 merges touching ranges and leaves that gap for its reader. These are alternative policies in the same batch code. I agree that we should pick one after comparing both.@pablogonz12 If an authorized world run is available, could you compare
70564ae, #1818 at24a7d70, and #1555 at9fb81e1as separate warm-cache builds? Please hold the rest of the stack, adapter, scene, inputs and frame window fixed. Aggregate frame time, preparation and batch-flush time, bytes copied and watch queries from the diagnostics frame lines would show whether the saved copies outweigh the extra calls. Draw and submission counts help check that the windows match. Review · #1555AI-assisted using Codex.
Imported from Marvisak/VIctory. Originally posted by pablogonz12 on 2026-11-24T23:31:49Z.
Noted. A matched warm-cache world A/B of
70564ae, #1818 at24a7d70and #1555 at9fb81e1, as three separate builds, is on our list for the next free GPU slot; I will post the frame numbers here once it has run. Not tested yet, so no numbers today.Imported from Marvisak/VIctory. Originally posted by Melow-code on 2026-11-25T01:03:48Z.
Thanks — a matched warm-cache world A/B of main, #1818 and #1555 is exactly what the per-range question needs, and the synthetic case already shows the copy-volume change going the right way. I will read the frame numbers when they land. (Reply written with DeepSeek V4 Pro, OpenCode.)
Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-25T01:26:43Z.
Updated this branch to
ccfb029at254a67f. The disjoint-refresh implementation is unchanged by the follow-up. The regression now matches #1322: a declared UAV range refreshes CPU-written bytes before execution and updates its copyback snapshot. In the fixture, both requested spans refresh and the gap stays untouched. After the GPU changes one byte, copyback preserves a later CPU write to its neighbor.All four disjoint tests passed with a required device on the default AMD adapter and WARP. The matched warm-cache comparison of main, #1818, and #1555 remains the evidence needed for the per-range performance question. The original comparison heads are still valid to reproduce the originally queued test.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T06:30:39Z.
Automated triage for the maintainers.
Needs work (kept). The new head only merges current
main(f3578e3) into the branch. The PR's own diff tocrates/victory-gpu/src/host.rs(Batch,RefreshRanges) andwatch.rsis identical to the one reviewed last time, and it merges cleanly.The open points from the last review are still open:
main'sBatchmodel ("what the title's threads write meanwhile is for later submissions"), the bounding range is not a correctness bug. The change is about copy volume, paid for with oneShadow::updateper disjoint span.main, this PR and #1555 on the same current baseline is still pending, and a maintainer needs those numbers to pick one.CI: passing (
check).Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Melow-code on 2026-11-25T11:54:08Z.
Review: COMMENTED
I read the union logic against
Shadow::updateandTracked::takeon main (70564ae). I found no correctness bug.RefreshRanges::addandmergetreat the ranges as half-open. They join ranges that touch and keep ranges with a gap apart.dedup_byclosure gets the later element first, soprevious.1 = max(...)extends the kept range.coversneeds sorted, disjoint ranges. Every path that writescurrentcallsmergefirst, so this holds.debug_assert!on that order incoverswould protect later callers.Tracked::takekeeps a page that it copies only in part as changed. So the second range still copies its bytes.Two points to check before merge:
updatecall, and each call takes thependingandchangedlocks and the guards. One copy with many small disjoint requests now makes many calls in place of one. A frame-time number from a world scene would show if this matters.The
CloseHandlein thetwin_viewstest helper is correct. The views keep the section alive.Imported from Marvisak/VIctory. Originally posted by Melow-code on 2026-11-25T11:54:35Z.
Review: COMMENTED
I read the union logic against
Shadow::updateandTracked::takeon main (70564ae). I found no correctness bug.RefreshRanges::addandmergetreat the ranges as half-open. They join ranges that touch and keep ranges with a gap apart.dedup_byclosure gets the later element first, soprevious.1 = max(...)extends the kept range.coversneeds sorted, disjoint ranges. Every path that writescurrentcallsmergefirst, so this holds.debug_assert!on that order incoverswould protect later callers.Tracked::takekeeps a page that it copies only in part as changed. So the second range still copies its bytes.Two points to check before merge:
updatecall, and each call takes thependingandchangedlocks and the guards. One copy with many small disjoint requests now makes many calls in place of one. A frame-time number from a world scene would show if this matters.The
CloseHandlein thetwin_viewstest helper is correct. The views keep the section alive.Imported from Marvisak/VIctory. Originally posted by Melow-code on 2026-11-25T11:54:44Z.
Review: COMMENTED
I read the union logic against
Shadow::updateandTracked::takeon main (70564ae). I found no correctness bug.RefreshRanges::addandmergetreat the ranges as half-open. They join ranges that touch and keep ranges with a gap apart.dedup_byclosure gets the later element first, soprevious.1 = max(...)extends the kept range.coversneeds sorted, disjoint ranges. Every path that writescurrentcallsmergefirst, so this holds.debug_assert!on that order incoverswould protect later callers.Tracked::takekeeps a page that it copies only in part as changed. So the second range still copies its bytes.Two points to check before merge:
updatecall, and each call takes thependingandchangedlocks and the guards. One copy with many small disjoint requests now makes many calls in place of one. A frame-time number from a world scene would show if this matters.The
CloseHandlein thetwin_viewstest helper is correct. The views keep the section alive.Imported from Marvisak/VIctory. Originally posted by shortselow-byte on 2026-11-25T13:35:55Z.
Merged onto current
main(940d32f), this no longer compiles its tests, although GitHub shows it as mergeable. The branch is based onccfb029, one commit beforecd94d35("GPU: shaders mark the pages they write through views"), which gaveShadow::writinga third parameter:So
cargo test -p victory-gpu(and clippy--all-targets) would fail onmainafter the merge. Checked locally on Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT, in an isolated target directory:copy.writing(busy, 4, false),disjoint_partial_refreshes_update_declared_write_snapshotspasses;true, it fails athost.rs:3250.So a rebase with
falsethere looks like all it needs. I only ran that one test with the fix, not the whole workspace.Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-25T13:38:27Z.
Thanks for the implementation and regression coverage. As the author of #1555, I think minimizing copied bytes and minimizing preparation time are two different objectives.
The 64 KiB coalescing threshold in #1555 intentionally reduces
Shadow::update()calls, lock acquisitions and change-tracking overhead. In the three-page regression, assuming no intervening writes or invalidations, both approaches ultimately copy 192 KiB, but #1555 requires one update call instead of three.The findings in #2134 and #2136 further support investigating this overhead independently of copy volume.
Given the recently reported compilation issue against main (
940d32f) and the GPU write-tracking changes incd94d35, both PRs should be validated and benchmarked against the same updated baseline.I also see potential in combining #1818's exact range tracking with #1555's batching strategy through shared locking.
Ultimately, correctness, preparation time and actual frame time should determine which approach lands. Neither approach has demonstrated superior real-world performance yet.
Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-25T16:58:41Z.
@shortselow-byte Thanks for isolating the compile error and checking both values of the new parameter. The merge at
4a191d8usesmarked=falsefor the declared-write fixture and preserves main's clean-shadow shortcut. All four disjoint tests passed on default hardware and WARP, including unmapped-page zeroing and preservation of the neighboring CPU byte.@Texbirds The current control measures copy volume at the first read. If the gap is eventually read with no intervening changes, both approaches can ultimately move the same number of bytes and the lock and query costs can decide the result. The matched title comparison on the same current-main baseline is still pending. This update makes no title frame-time claim.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.