Skip to content

Preserve disjoint shadow refresh ranges - #591

Open
DoubleD17 wants to merge 1 commit into
fxceless:mainfrom
DoubleD17:fix/disjoint-shadow-refresh-ranges
Open

DoubleD17 wants to merge 1 commit into
fxceless:mainfrom
DoubleD17:fix/disjoint-shadow-refresh-ranges

Conversation

@DoubleD17

Copy link
Copy Markdown

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 c96b4f2 with candidate 0d22b38. 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.

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

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.

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

Copy link
Copy Markdown

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.

@Filip722

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants