GPU: preserve disjoint shadow refresh ranges #1818

Open
github-bot wants to merge 6 commits from github-bot/gh-1818 into main AGit
Owner

@⁠aycow on GitHub · 2026-11-24 22:58 UTC · original
aycow:fix/disjoint-shadow-refresh-current → main · +320 −31 · 2 files · 6 commits · open

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 4a191d8 with 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.

$env:VICTORY_TEST_SHADOW_DISJOINT_REQUIRE_GPU = '1'
cargo test -p victory-gpu --features diagnostics --locked --lib disjoint -- --nocapture --test-threads=1
$env:VICTORY_D3D12_WARP = '1'
cargo test -p victory-gpu --features diagnostics --locked --lib disjoint -- --nocapture --test-threads=1

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.

**@⁠aycow** on GitHub · 2026-11-24 22:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/1818) `aycow:fix/disjoint-shadow-refresh-current` → `main` · +320 −31 · 2 files · 6 commits · open ## 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](https://git.gtahub.st/github/Marvisak--VIctory/pulls/185) · [Related flush work](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1472) ## Verification All four disjoint refresh regressions passed on AMD Radeon Graphics and WARP at `4a191d8` with 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. ```powershell $env:VICTORY_TEST_SHADOW_DISJOINT_REQUIRE_GPU = '1' cargo test -p victory-gpu --features diagnostics --locked --lib disjoint -- --nocapture --test-threads=1 $env:VICTORY_D3D12_WARP = '1' cargo test -p victory-gpu --features diagnostics --locked --lib disjoint -- --nocapture --test-threads=1 ``` 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.
Keep the requested union through pending and completed preparation. Leave dirty gaps for later readers and retain one inline range for the common case.

Reproduces the copy amplification reported by pablogonz12 on Marvisak/VIctory#185 (https://github.com/Marvisak/VIctory/pull/185#issuecomment-7138450289) and carries forward the range behavior from 20ff80e on the current unified journal.
Exercise independent shadow observers, concurrent alias writes over three submissions, a same-address decommit and recommit, and a pending GPU-written dword next to partial CPU refreshes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:45:36 +00:00
Author
Owner

@⁠aycow on GitHub · 2026-11-24 23:22 UTC · original

@⁠ruipedro-pinheiro Agreed on comparing the per-range cost in a matched world run. Each disjoint span does call Shadow::update separately. 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 at 24a7d70, and #1555 at 9fb81e1 as 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 · #1555

AI-assisted using Codex.

**@⁠aycow** on GitHub · 2026-11-24 23:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/1818#issuecomment-7147321169) @⁠ruipedro-pinheiro Agreed on comparing the per-range cost in a matched world run. Each disjoint span does call `Shadow::update` separately. 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 at `24a7d70`, and #1555 at `9fb81e1` as 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](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1818) · [#1555](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1555) AI-assisted using Codex.
Author
Owner

@⁠pablogonz12 on GitHub · 2026-11-24 23:31 UTC · original

Noted. A matched warm-cache world A/B of 70564ae, #1818 at 24a7d70 and #1555 at 9fb81e1, 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.

**@⁠pablogonz12** on GitHub · 2026-11-24 23:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/1818#issuecomment-7147503335) Noted. A matched warm-cache world A/B of `70564ae`, #1818 at `24a7d70` and #1555 at `9fb81e1`, 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.
Author
Owner

@⁠Melow-code on GitHub · 2026-11-25 01:03 UTC · original

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

**@⁠Melow-code** on GitHub · 2026-11-25 01:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/1818#issuecomment-7149167348) 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.)
Author
Owner

@⁠aycow on GitHub · 2026-11-25 01:26 UTC · original

Updated this branch to ccfb029 at 254a67f. 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.

**@⁠aycow** on GitHub · 2026-11-25 01:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/1818#issuecomment-7149553069) Updated this branch to `ccfb029` at `254a67f`. 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 06:30 UTC · original · edited 2026-11-26 01:24 UTC

Automated triage for the maintainers.

Needs work (kept). The new head only merges current main (f3578e3) into the branch. The PR's own diff to crates/victory-gpu/src/host.rs (Batch, RefreshRanges) and watch.rs is identical to the one reviewed last time, and it merges cleanly.

The open points from the last review are still open:

  • Framing. Under main's Batch model ("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 one Shadow::update per disjoint span.
  • Policy. #1555 does the opposite (it coalesces gaps up to 64 KiB). The matched warm-cache world comparison of main, this PR and #1555 on the same current baseline is still pending, and a maintainer needs those numbers to pick one.
  • Tests. About 230 lines of tests for a ~60-line change. Once a policy is chosen, keeping the gap-reader and declared-write cases would do.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 06:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1818#issuecomment-7154864715) · edited 2026-11-26 01:24 UTC <!-- victory-triage v1 head=68f6115ea5d803d9fd85c5786d36e8fa27581962 verdict=needs-work at=2026-11-26T01:24:00Z --> Automated triage for the maintainers. **Needs work (kept).** The new head only merges current `main` (`f3578e3`) into the branch. The PR's own diff to `crates/victory-gpu/src/host.rs` (`Batch`, `RefreshRanges`) and `watch.rs` is identical to the one reviewed last time, and it merges cleanly. The open points from the last review are still open: - **Framing.** Under `main`'s `Batch` model ("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 one `Shadow::update` per disjoint span. - **Policy.** #1555 does the opposite (it coalesces gaps up to 64 KiB). The matched warm-cache world comparison of `main`, this PR and #1555 on the same current baseline is still pending, and a maintainer needs those numbers to pick one. - **Tests.** About 230 lines of tests for a ~60-line change. Once a policy is chosen, keeping the gap-reader and declared-write cases would do. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠shortselow-byte on GitHub · 2026-11-25 13:35 UTC · original

Merged onto current main (940d32f), this no longer compiles its tests, although GitHub shows it as mergeable. The branch is based on ccfb029, one commit before cd94d35 ("GPU: shaders mark the pages they write through views"), which gave Shadow::writing a third parameter:

error[E0061]: this method takes 3 arguments but 2 arguments were supplied
    --> crates\victory-gpu\src\host.rs:3223:14
     |
3223 |         copy.writing(busy, 4);
     |              ^^^^^^^--------- argument #3 of type `bool` is missing
note: method defined here
    --> crates\victory-gpu\src\shadow.rs:274:19
     |
 274 |     pub(crate) fn writing(&self, address: usize, len: usize, marked: bool) {

So cargo test -p victory-gpu (and clippy --all-targets) would fail on main after the merge. Checked locally on Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT, in an isolated target directory:

  • with copy.writing(busy, 4, false), disjoint_partial_refreshes_update_declared_write_snapshots passes;
  • with true, it fails at host.rs:3250.

So a rebase with false there looks like all it needs. I only ran that one test with the fix, not the whole workspace.

**@⁠shortselow-byte** on GitHub · 2026-11-25 13:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/1818#issuecomment-7164010658) **Merged onto current `main` (`940d32f`), this no longer compiles its tests**, although GitHub shows it as mergeable. The branch is based on `ccfb029`, one commit before `cd94d35` ("GPU: shaders mark the pages they write through views"), which gave `Shadow::writing` a third parameter: ``` error[E0061]: this method takes 3 arguments but 2 arguments were supplied --> crates\victory-gpu\src\host.rs:3223:14 | 3223 | copy.writing(busy, 4); | ^^^^^^^--------- argument #3 of type `bool` is missing note: method defined here --> crates\victory-gpu\src\shadow.rs:274:19 | 274 | pub(crate) fn writing(&self, address: usize, len: usize, marked: bool) { ``` So `cargo test -p victory-gpu` (and clippy `--all-targets`) would fail on `main` after the merge. Checked locally on Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT, in an isolated target directory: - with `copy.writing(busy, 4, false)`, `disjoint_partial_refreshes_update_declared_write_snapshots` passes; - with `true`, it fails at `host.rs:3250`. So a rebase with `false` there looks like all it needs. I only ran that one test with the fix, not the whole workspace.
Author
Owner

@⁠Texbirds on GitHub · 2026-11-25 13:38 UTC · original

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 in cd94d35, 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.

**@⁠Texbirds** on GitHub · 2026-11-25 13:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/1818#issuecomment-7164073457) 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 in `cd94d35`, 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.
Author
Owner

@⁠aycow on GitHub · 2026-11-25 16:58 UTC · original

@⁠shortselow-byte Thanks for isolating the compile error and checking both values of the new parameter. The merge at 4a191d8 uses marked=false for 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.

**@⁠aycow** on GitHub · 2026-11-25 16:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/1818#issuecomment-7168816755) @⁠shortselow-byte Thanks for isolating the compile error and checking both values of the new parameter. The merge at `4a191d8` uses `marked=false` for 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1818/head:github-bot/gh-1818'
git switch 'github-bot/gh-1818'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1818'
git switch 'github-bot/gh-1818'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1818'
git switch 'github-bot/gh-1818'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1818'
git switch 'main'
git merge --squash 'github-bot/gh-1818'
git switch 'main'
git merge --ff-only 'github-bot/gh-1818'
git switch 'main'
git merge 'github-bot/gh-1818'
git push origin 'main'
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!1818
No description provided.