Skip to content

GPU: walk only dirty gaps when refreshing guarded views - #181

Merged
pablogonz12 merged 2 commits into
mainfrom
int/fork-979
Nov 25, 2026
Merged

pablogonz12 merged 2 commits into
mainfrom
int/fork-979

Conversation

@pablogonz12

@pablogonz12 pablogonz12 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

What

Repeated checks of clean view heaps in crates/victory-gpu/src/watch.rs collect one entry per 64 KiB block while holding the guard mutex, then scan that vector to find the few dirty gaps. This keeps the same clean blocks as contiguous half-open runs (CleanBlocks: a BTreeMap of from..to), so the fully clean range is one lookup and the mixed range visits only its dirty gaps. Mapping queries, alias protection and dirty notifications are unchanged.

  • CleanBlocks::insert/remove/uncovered with the interval arithmetic the guard loop needs.
  • guards().clean becomes CleanBlocks; protect, open, title_memory_remapped and the write-watch path call the run operations.
  • New test watch::tests::clean_runs_match_per_block_tracking: every interval from..to over 36 blocks, for a sequence of inserts and removes, equals the old per-block BTreeSet reference.

Credit

fxceless/victory-fork PR #979 by gmanka, GPL-3.0. Cherry-picked with -x, author kept. Conflicts: this tree keeps its own mapped block set (the fork's aliased/viewed sets are not here), so the clean set alone was rebased onto it. CREDITS.md line added.

Gates

  • cargo xwin clippy --target x86_64-pc-windows-msvc --workspace --all-targets -- -D warnings: clean.
  • victory-gpu tests under Wine (GE-Proton11-14, VICTORY_TEST_ADAPTER=hw, native dxgi): 197 passed; 0 failed; 2 ignored (both ignored are pre-existing: clean_copies_bench and the handle-opened section test). clean_runs_match_per_block_tracking ok.
  • cargo xtask policy: 244 files ok; git grep -iE "gta ?(vi|6)|grand theft|rockstar" empty.

Off switch

None: same set of blocks, same notification order and same results, only fewer entries allocated and scanned. No env switch, no new behaviour to turn off.

Not tested in a game run.

Summary by CodeRabbit

  • Refactor
    • Improved internal tracking of clean ranges used when guarding protected blocks. Adjacent ranges and gaps are handled consistently, and removing a block updates the affected range. Existing guarding behavior is preserved; this update does not introduce visible changes to the app.

Repeated checks of clean view heaps collect one entry per 64 KiB block
while holding the guard mutex. If most blocks are clean, that allocates
and scans thousands of entries to find just a few dirty gaps.

Track the same clean blocks as contiguous half-open runs. The fully
clean path needs a single lookup and the mixed path visits only dirty
gaps. Keep the existing mapping queries, alias protection, and dirty
notifications. Compare the interval operations with the old per-block
representation and retain the existing guard and mapping tests.

Based-on: fxceless/victory-fork#824
Tested-on: RX 6800, Fedora Linux 45, Wine (14 guard and mapping tests)
Assisted-by: gpt-6.2 sol xhigh
(cherry picked from commit ac6e475108f0e82ed6efb657e4f0b7552c0275f7)
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Clean block interval tracking

Layer / File(s) Summary
Clean block interval operations
crates/victory-gpu/src/watch.rs, CREDITS.md
CleanBlocks merges inserted runs, splits runs when removing a block, and returns uncovered gaps. CREDITS.md credits the related interval-tracking design.
Guard updates and validation
crates/victory-gpu/src/watch.rs
guard scans uncovered intervals. Protection, opening, and remapping paths update the interval map. A test compares interval gaps with per-block tracking.

Possibly related PRs

  • pablogonz12/Scarlight#174: This PR changes the guard block representation in the same file and updates overlapping guard paths.
  • pablogonz12/Scarlight#100: This PR adds checks and remapping behavior for known blocks whose state representation changes here.

Suggested reviewers: fxceless, brainbudt

Change: Refactor

Merge Risk: Minimal · up to 078f4

This change replaces per-block clean tracking with interval tracking in the guarded-memory watcher, keeping behavior unchanged. No concrete issues were identified, and the author reports clean lint and passing tests. It was not exercised in a game run.

Architecture risk: Low · up to 078f4

The change affects 2 systems.

Changed systems: crates, CREDITS.md

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — crates (service) was modified; 1 changed file maps to changed impact.
  • observed — CREDITS.md (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in crates/victory-gpu/src/watch.rs: Guards.clean changes from BTreeSet<usize> to CleanBlocks, which stores clean blocks as intervals.
  • observed — Modified behavior in crates/victory-gpu/src/watch.rs: Adds interval operations for clean blocks: insert merges overlapping or touching runs, remove deletes a block while preserving either side as runs, and uncovered returns gaps in a requested range. Guards initializes the new interval map instead of an empty set.
  • observed — Modified behavior in crates/victory-gpu/src/watch.rs: guard now gets the uncovered intervals and scans only those blocks, rather than collecting clean blocks and iterating through every block in the range. It still reports open blocks as written, records already-protected blocks as clean, and protects remaining open runs.
  • observed — Modified behavior in crates/victory-gpu/src/watch.rs: protect records the protected range in clean with an interval insertion instead of extending a set with individual blocks.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 1
  • Waived: $0.25 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a4642f0e-754d-46ba-9fdb-661a90df3636
Commits

Reviewing files that changed from the base of the PR and between 58ae463 and 078f471.

Files selected for processing: 1

  • CREDITS.md

Limit details: You’ve used all 10 included reviews currently available.

@pablogonz12
pablogonz12 merged commit 8ebfe76 into main Nov 25, 2026
4 checks passed
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.

2 participants