Preserve disjoint shadow refresh ranges #591

Closed
github-bot wants to merge 1 commit from github-bot/gh-591 into main AGit
Owner

@⁠DoubleD17 on GitHub · 2026-11-25 02:44 UTC · original
DoubleD17:fix/disjoint-shadow-refresh-ranges → main · +263 −47 · 1 files · 1 commits · closed without merging

When a submission asks for two disjoint ranges of the same shadow buffer, the previous bounding interval can refresh a dirty page in the gap before any request includes it. Keep the union of overlapping or adjacent ranges and preserve the existing flush points. Adapted from Aydan (aycow) in Marvisak/VIctory#1818, with credit to pablogonz12 for the original reproduction in #185.

A synthetic D3D12 WARP submission and readback on Windows 11 compared base c96b4f2b83 with candidate 0d22b3808d0e5413dd845c771de5d6977cfbdc20. The base copied 192 KiB for two 64 KiB requests. The candidate copied 128 KiB, preserved the gap's previous contents, and copied its 64 KiB on the later request. The overlapping-range and GPU write declaration controls matched the base. The reported refresh volume in fxceless #543 sums requests before batching. Physical GPU and frame-time effects remain unmeasured.

AI-assisted.

**@⁠DoubleD17** on GitHub · 2026-11-25 02:44 UTC · [original](https://github.com/fxceless/victory-fork/pull/591) `DoubleD17:fix/disjoint-shadow-refresh-ranges` → `main` · +263 −47 · 1 files · 1 commits · closed without merging When a submission asks for two disjoint ranges of the same shadow buffer, the previous bounding interval can refresh a dirty page in the gap before any request includes it. Keep the union of overlapping or adjacent ranges and preserve the existing flush points. Adapted from Aydan (aycow) in Marvisak/VIctory#1818, with credit to pablogonz12 for the original reproduction in #185. A synthetic D3D12 WARP submission and readback on Windows 11 compared base c96b4f2b8365bf43d54ab074940923ef8267f4c6 with candidate 0d22b3808d0e5413dd845c771de5d6977cfbdc20. The base copied 192 KiB for two 64 KiB requests. The candidate copied 128 KiB, preserved the gap's previous contents, and copied its 64 KiB on the later request. The overlapping-range and GPU write declaration controls matched the base. The reported refresh volume in fxceless #543 sums requests before batching. Physical GPU and frame-time effects remain unmeasured. AI-assisted.
Keep the union of overlapping and adjacent refresh ranges per shadow. Cover range normalization with CPU unit tests and preserve the WARP readback regression.

Adapted from Aydan (aycow) in Marvisak/VIctory#1818.
Thanks to pablogonz12 for the original reproduction in Marvisak/VIctory#185.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:47:01 +00:00
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-25 22:21 UTC · original

There’s another place where a gap can disappear before a request reaches Batch. State::heap_buffers folds all the directly indexed views of one shadow into min(start)..max(end). On a local build I kept their union through both the heap pass and the submission batch. One first-room pass covered 1,715 MiB of view ranges; bounding the same views would have included another 712 MiB. These are requested spans, before the write watch decides what actually needs copying.

That experimental run lost the device before the timing window, so I don’t have a gameplay timing result or a cause for the loss. The byte counts do show where a caller of this change still requests the gaps.

**@⁠UwUCammie** on GitHub · 2026-11-25 22:21 UTC · [original](https://github.com/fxceless/victory-fork/pull/591#issuecomment-7176264761) There’s another place where a gap can disappear before a request reaches `Batch`. `State::heap_buffers` folds all the directly indexed views of one shadow into `min(start)..max(end)`. On a local build I kept their union through both the heap pass and the submission batch. One first-room pass covered 1,715 MiB of view ranges; bounding the same views would have included another 712 MiB. These are requested spans, before the write watch decides what actually needs copying. That experimental run lost the device before the timing window, so I don’t have a gameplay timing result or a cause for the loss. The byte counts do show where a caller of this change still requests the gaps.
Author
Owner

@⁠Filip722 on GitHub · 2026-11-26 01:53 UTC · original

I tested 494b315c in a local integration based on dc4c0fc with the #256 Wine write path. Runtime was Bazzite 44 and GE-Proton11-14 on an RTX 5060 Laptop GPU (NVIDIA 615.78.08).

Three focused range-union tests passed. The asset-free D3D12 readback fixture passed on the physical RTX with VICTORY_REFRESH_ONCE=0 and =1 in separate processes. The fixture verified the two requested dirty ranges and read the intervening region later, after it was explicitly requested. The integration makes exact ranges opt-in for a later same-binary title comparison. These results cover range and readback correctness.

Codex assisted with the integration and tests.

**@⁠Filip722** on GitHub · 2026-11-26 01:53 UTC · [original](https://github.com/fxceless/victory-fork/pull/591#issuecomment-7180251373) I tested `494b315c` in a local integration based on `dc4c0fc` with the #256 Wine write path. Runtime was Bazzite 44 and GE-Proton11-14 on an RTX 5060 Laptop GPU (NVIDIA 615.78.08). Three focused range-union tests passed. The asset-free D3D12 readback fixture passed on the physical RTX with `VICTORY_REFRESH_ONCE=0` and `=1` in separate processes. The fixture verified the two requested dirty ranges and read the intervening region later, after it was explicitly requested. The integration makes exact ranges opt-in for a later same-binary title comparison. These results cover range and readback correctness. Codex assisted with the integration and tests.
Author
Owner

@⁠Filip722 on GitHub · 2026-11-26 04:29 UTC · original

I followed up the D3D12 readbacks with two Series S opening-cinematic replays on an RTX 5060 Laptop GPU (615.78.08), Bazzite 44 and GE-Proton 11-14. The replays used the same executable containing 494b315c and started with identical isolated state and caches. Only exact refresh differed.

Both rendered the opening cinematic after the FidelityFX fence. From the first to the 105th post-upscale Present, exact off took 523 s (3.81 s median interval), and exact on took 574 s (4.12 s median). The shots and draw counts differed at equal frame ordinals. These samples do not establish a throughput gain or a regression. The exact path's gap counter showed skipped address coverage and does not measure transferred bytes.

OpenAI Codex assisted with the integration and testing.

**@⁠Filip722** on GitHub · 2026-11-26 04:29 UTC · [original](https://github.com/fxceless/victory-fork/pull/591#issuecomment-7182641504) I followed up the D3D12 readbacks with two Series S opening-cinematic replays on an RTX 5060 Laptop GPU (615.78.08), Bazzite 44 and GE-Proton 11-14. The replays used the same executable containing `494b315c` and started with identical isolated state and caches. Only exact refresh differed. Both rendered the opening cinematic after the FidelityFX fence. From the first to the 105th post-upscale Present, exact off took 523 s (3.81 s median interval), and exact on took 574 s (4.12 s median). The shots and draw counts differed at equal frame ordinals. These samples do not establish a throughput gain or a regression. The exact path's gap counter showed skipped address coverage and does not measure transferred bytes. OpenAI Codex assisted with the integration and testing.
github-bot closed this pull request 2026-11-26 11:20:13 +00:00
Author
Owner

@⁠kaayzouee on GitHub · 2026-11-25 02:46 UTC · original · approved these changes

Code review

Reviewed commit 0d22b380. The change is distinct from the existing target-branch implementation. The core range-union algorithm looks correct, and I found no blocking issue in the changed code during static inspection.

What is good

  • RefreshRanges::One preserves the allocation-free common case. A plain Vec for every shadow would be simpler superficially, but would introduce unnecessary allocations on this hot path.
  • Sorting and merging overlapping/adjacent ranges only at flush time is a reasonable trade-off; it avoids repeatedly sorting or shifting elements during recording.
  • Both flush_one() and flush() normalize ranges before updating, preserving the existing GPU-write and title-write barriers.
  • The parallel refresh path still assigns one job per shadow, rather than allowing multiple jobs to update the same shadow concurrently.

The new WARP test is valuable because it checks real readback contents and copied-byte counters, but it is ignored by default and requires diagnostics and an isolated WARP process. The pure RefreshRanges logic can be tested without D3D12 initialization.

Please consider table-driven tests for:

  • Disjoint ranges added in reverse order.
  • Adjacent and overlapping ranges, including nested/duplicate ranges.
  • A bridging range that merges two previously disjoint ranges.
  • Multiple ranges with chained overlaps after promotion from One to Many.
  • Idempotent normalization.

The current dedup_by implementation is correct: Rust passes the later element first and removes that element when the predicate returns true. A short comment documenting that argument order would improve readability, but I would not replace the algorithm with a larger abstraction.

Minor simplifications

  • In Batch::add(), using self.index.entry(key).or_insert_with(...) could avoid a second hash lookup for new shadows, if it remains readable. The current match is also fine.
  • Prefer the named MEM_WRITE_WATCH binding in the WARP test if available in the pinned Windows bindings.
  • The unchanged submission-wide ask_once code still constructs a bounding span per shadow. This is not the same as copying the gap: the write-watch journal records dirty pages separately from Shadow::copy_stale. Nevertheless, the change does not eliminate the potentially broad kernel write-watch query. Treat copied bytes and write-watch overhead as separate metrics.

Verification and verdict

The supplied 192 KiB → 128 KiB synthetic result is useful evidence of the intended behavior. It is not evidence of physical-GPU frame-time improvement, which the PR correctly leaves unmeasured. Testing the WARP case with both VICTORY_ASK_ONCE=0 and the default enabled path would provide additional confidence, as would a multi-shadow wide-refresh test.

Overall, good code quality and appropriately scoped. I would approve the implementation, with the ordinary range-union unit tests as a recommended nonblocking improvement.

Static review only: I inspected the diff and the surrounding batching, shadow-update and write-watch implementations, but did not independently build or run the Windows/WARP tests.


This is an automated message, if you believe this is incorrect, please reply with the relevant technical context or a reproducible counterexample so the finding can be reassessed.

**@⁠kaayzouee** on GitHub · 2026-11-25 02:46 UTC · [original](https://github.com/fxceless/victory-fork/pull/591#pullrequestreview-6051057428) · **approved these changes** ## Code review Reviewed commit `0d22b380`. The change is distinct from the existing target-branch implementation. The core range-union algorithm looks correct, and I found no blocking issue in the changed code during static inspection. ### What is good - `RefreshRanges::One` preserves the allocation-free common case. A plain `Vec` for every shadow would be simpler superficially, but would introduce unnecessary allocations on this hot path. - Sorting and merging overlapping/adjacent ranges only at flush time is a reasonable trade-off; it avoids repeatedly sorting or shifting elements during recording. - Both `flush_one()` and `flush()` normalize ranges before updating, preserving the existing GPU-write and title-write barriers. - The parallel refresh path still assigns one job per shadow, rather than allowing multiple jobs to update the same shadow concurrently. ### Recommended: add ordinary unit tests for the range union The new WARP test is valuable because it checks real readback contents and copied-byte counters, but it is ignored by default and requires diagnostics and an isolated WARP process. The pure `RefreshRanges` logic can be tested without D3D12 initialization. Please consider table-driven tests for: - Disjoint ranges added in reverse order. - Adjacent and overlapping ranges, including nested/duplicate ranges. - A bridging range that merges two previously disjoint ranges. - Multiple ranges with chained overlaps after promotion from `One` to `Many`. - Idempotent normalization. The current `dedup_by` implementation is correct: Rust passes the later element first and removes that element when the predicate returns true. A short comment documenting that argument order would improve readability, but I would not replace the algorithm with a larger abstraction. ### Minor simplifications - In `Batch::add()`, using `self.index.entry(key).or_insert_with(...)` could avoid a second hash lookup for new shadows, if it remains readable. The current match is also fine. - Prefer the named `MEM_WRITE_WATCH` binding in the WARP test if available in the pinned Windows bindings. - The unchanged submission-wide `ask_once` code still constructs a bounding span per shadow. This is not the same as copying the gap: the write-watch journal records dirty pages separately from `Shadow::copy_stale`. Nevertheless, the change does not eliminate the potentially broad kernel write-watch query. Treat copied bytes and write-watch overhead as separate metrics. ### Verification and verdict The supplied 192 KiB → 128 KiB synthetic result is useful evidence of the intended behavior. It is not evidence of physical-GPU frame-time improvement, which the PR correctly leaves unmeasured. Testing the WARP case with both `VICTORY_ASK_ONCE=0` and the default enabled path would provide additional confidence, as would a multi-shadow wide-refresh test. Overall, good code quality and appropriately scoped. I would approve the implementation, with the ordinary range-union unit tests as a recommended nonblocking improvement. Static review only: I inspected the diff and the surrounding batching, shadow-update and write-watch implementations, but did not independently build or run the Windows/WARP tests. --- This is an automated message, if you believe this is incorrect, please reply with the relevant technical context or a reproducible counterexample so the finding can be reassessed.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.