coalesce soft-view cursor and word-batch block bitmaps in protect_here #626

Open
RileyW wants to merge 1 commit from RileyW/Darner:pr/guard-scan into Main
First-time contributor

Not yet run in-game on this Darner branch (90 watch unit tests run on this revision; previously verified on RTX 3080 / i7-8700 in a downstream fork).

What it changes

  • The problem on main: read from code (crates/darner-gpu/src/watch.rs:3902, Blocks::insert_all and watch.rs:5050-5085, protect_here).
  1. Inside protect_here's per-block fallback (by_block), in_books(block) linearly scans the entire soft slice on every block (O(B * |soft|)).
  2. Blocks::insert_all inserts one block at a time (one BTreeMap lookup and one SeqCst atomic fetch_or on the mirror Bits per 64 KiB block), and protect_here / protect_aliases_merged also call PROTECTED.set(block) one block at a time.

This change:

  1. Adds Bits::set_all(first, last) (64-bit word-at-a-time atomic fetch_or, matching existing Bits::clear_all) and upgrades Blocks::insert_all, protect_here, and protect_aliases_merged to set/clear block ranges 64 blocks per word.
  2. Adds soft_block_runs(soft, from, to) to build sorted, coalesced block intervals matching exact in_books whole-block coverage semantics, and walks them with a monotonic cursor in by_block (O(B + |soft|)), batching contiguous soft-view runs while keeping exact per-block VirtualProtect, uncommitted_end, absent, and held semantics intact.
  3. Adds unit tests blocks_insert_all_matches_per_block_insert_and_updates_atomic_mirror (including cross-piece boundaries) and soft_block_runs_matches_linear_in_books_on_mixed_and_partial_boundaries (verifying parity with linear in_books across overlapping, unsorted, and partial-block spans).

How it was tested

  • Tested revision: b9dfc99 (based on c8258f9)
  • Commands and results:
    • cargo test -p darner-gpu --lib watch:: --locked -- --test-threads=1 --skip streamed_texture_written_through_an_alias_reaches_a_full_queue (90 passed, 0 failed)
    • cargo clippy --workspace --all-targets --locked -- -D warnings (0 warnings)
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings (0 warnings)
    • cargo xtask policy and cargo xtask policy --staged (ok)
  • Changes a default: yes, for all hosts (purely internal algorithmic/bit-batching speedup with identical per-block protection and bitmap state).
  • A/B result: no in-game Darner A/B table yet (purely identical bit-for-bit behavior; reduces by_block soft lookup from O(B * |soft|) to O(B + |soft|) and bitmap RMWs by up to 64x per contiguous run).
  • Gates run on that revision: both workspace clippy gates, cargo xtask policy, and darner-gpu watch:: tests.
  • Gameplay: not yet re-run in-game on this Darner branch.
  • Hardware dependence: general (CPU watch bookkeeping).
  • Coverage gaps: On Windows 10 22H2, streamed_texture_written_through_an_alias_reaches_a_full_queue aborts (exit code 3) because test binaries without Agility SDK exports see SM 0x65 from system d3d12.dll; all 90 other watch:: tests including both new unit tests passed.

Checklist

  • I ran this change in the game, or say below why it cannot be (CPU watch unit tests run; in-game Darner run pending).
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #565 (watch test isolation), #615 (alias-write notifications in writing/kernel_writing/title_memory_written; separate functions).
  • Replaces or overlaps: none found.
Not yet run in-game on this Darner branch (90 watch unit tests run on this revision; previously verified on RTX 3080 / i7-8700 in a downstream fork). ## What it changes - The problem on main: read from code (crates/darner-gpu/src/watch.rs:3902, Blocks::insert_all and watch.rs:5050-5085, protect_here). 1. Inside protect_here's per-block fallback (by_block), in_books(block) linearly scans the entire soft slice on every block (O(B * |soft|)). 2. Blocks::insert_all inserts one block at a time (one BTreeMap lookup and one SeqCst atomic fetch_or on the mirror Bits per 64 KiB block), and protect_here / protect_aliases_merged also call PROTECTED.set(block) one block at a time. This change: 1. Adds Bits::set_all(first, last) (64-bit word-at-a-time atomic fetch_or, matching existing Bits::clear_all) and upgrades Blocks::insert_all, protect_here, and protect_aliases_merged to set/clear block ranges 64 blocks per word. 2. Adds soft_block_runs(soft, from, to) to build sorted, coalesced block intervals matching exact in_books whole-block coverage semantics, and walks them with a monotonic cursor in by_block (O(B + |soft|)), batching contiguous soft-view runs while keeping exact per-block VirtualProtect, uncommitted_end, absent, and held semantics intact. 3. Adds unit tests blocks_insert_all_matches_per_block_insert_and_updates_atomic_mirror (including cross-piece boundaries) and soft_block_runs_matches_linear_in_books_on_mixed_and_partial_boundaries (verifying parity with linear in_books across overlapping, unsorted, and partial-block spans). ## How it was tested - Tested revision: b9dfc99 (based on c8258f9) - Commands and results: - cargo test -p darner-gpu --lib watch:: --locked -- --test-threads=1 --skip streamed_texture_written_through_an_alias_reaches_a_full_queue (90 passed, 0 failed) - cargo clippy --workspace --all-targets --locked -- -D warnings (0 warnings) - cargo clippy --workspace --all-targets --all-features --locked -- -D warnings (0 warnings) - cargo xtask policy and cargo xtask policy --staged (ok) - Changes a default: yes, for all hosts (purely internal algorithmic/bit-batching speedup with identical per-block protection and bitmap state). - A/B result: no in-game Darner A/B table yet (purely identical bit-for-bit behavior; reduces by_block soft lookup from O(B * |soft|) to O(B + |soft|) and bitmap RMWs by up to 64x per contiguous run). - Gates run on that revision: both workspace clippy gates, cargo xtask policy, and darner-gpu watch:: tests. - Gameplay: not yet re-run in-game on this Darner branch. - Hardware dependence: general (CPU watch bookkeeping). - Coverage gaps: On Windows 10 22H2, streamed_texture_written_through_an_alias_reaches_a_full_queue aborts (exit code 3) because test binaries without Agility SDK exports see SM 0x65 from system d3d12.dll; all 90 other watch:: tests including both new unit tests passed. ## Checklist - [ ] I ran this change in the game, or say below why it cannot be (CPU watch unit tests run; in-game Darner run pending). - [x] This PR contains one change based on main. - [x] The diff follows docs/asset-policy.md. - [x] I recorded this PR dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #565 (watch test isolation), #615 (alias-write notifications in writing/kernel_writing/title_memory_written; separate functions). - Replaces or overlaps: none found.
TrustNo1 changed title from [pr-performance][memory] coalesce soft-view cursor and word-batch block bitmaps in protect_here to coalesce soft-view cursor and word-batch block bitmaps in protect_here 2026-12-06 03:25:58 +00:00
Owner

Test needed — commit b9dfc99d; what to check:

  • The problem on main: read from code (crates/darner-gpu/src/watch.rs:3902, Blocks::insert_all and watch.rs:5050-5085, protect_here).
  1. Inside protect_here's per-block fallback (by_block), in_books(block) linearly scans the entire soft slice on every block (O(B * |soft|)).
  2. Blocks::insert_all inserts one block at a time (one BTreeMap lookup and one SeqCst atomic fetch_or on the mirror Bits per 64 KiB block), and protect_here / protect_aliases_merged also call PROTECTED.set(block) one block at a time.

This change:

  1. Adds Bits::set_all(first, last) (64-bit word-at-a-time atomic fetch_or, matching existing Bits::clear_all) and upgrades Blocks::insert_all, protect_here, and protect_aliases_merged to set/clear block ranges 64 blocks per word.
  2. Adds soft_block_runs(soft, from, to) to build sorted, coalesced block intervals matching exact in_books whole-block coverage semantics, and walks them with a monotonic cursor in by_block (O(B + |soft|)), batching contiguous soft-view runs while keeping exact per-block VirtualProtect, uncommitted_end, absent, and held semantics intact.
  3. Adds unit tests blocks_insert_all_matches_per_block_insert_and_updates_atomic_mirror (including cross-p

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `b9dfc99d`; what to check: - The problem on main: read from code (crates/darner-gpu/src/watch.rs:3902, Blocks::insert_all and watch.rs:5050-5085, protect_here). 1. Inside protect_here's per-block fallback (by_block), in_books(block) linearly scans the entire soft slice on every block (O(B * |soft|)). 2. Blocks::insert_all inserts one block at a time (one BTreeMap lookup and one SeqCst atomic fetch_or on the mirror Bits per 64 KiB block), and protect_here / protect_aliases_merged also call PROTECTED.set(block) one block at a time. This change: 1. Adds Bits::set_all(first, last) (64-bit word-at-a-time atomic fetch_or, matching existing Bits::clear_all) and upgrades Blocks::insert_all, protect_here, and protect_aliases_merged to set/clear block ranges 64 blocks per word. 2. Adds soft_block_runs(soft, from, to) to build sorted, coalesced block intervals matching exact in_books whole-block coverage semantics, and walks them with a monotonic cursor in by_block (O(B + |soft|)), batching contiguous soft-view runs while keeping exact per-block VirtualProtect, uncommitted_end, absent, and held semantics intact. 3. Adds unit tests blocks_insert_all_matches_per_block_insert_and_updates_atomic_mirror (including cross-p Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
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 'pr/guard-scan:RileyW-pr/guard-scan'
git switch 'RileyW-pr/guard-scan'

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.

git switch 'Main'
git merge --no-ff 'RileyW-pr/guard-scan'
git switch 'RileyW-pr/guard-scan'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'RileyW-pr/guard-scan'
git switch 'RileyW-pr/guard-scan'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'RileyW-pr/guard-scan'
git switch 'Main'
git merge --squash 'RileyW-pr/guard-scan'
git switch 'Main'
git merge --ff-only 'RileyW-pr/guard-scan'
git switch 'Main'
git merge 'RileyW-pr/guard-scan'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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
TrustNo1/Darner!626
No description provided.