perf(gpu): check clean guard ranges one bitmap word at a time #381

Open
github-bot wants to merge 5 commits from github-bot/gh-381 into main AGit
Owner

@⁠tommiehansen on GitHub · 2026-12-03 21:45 UTC · original
tommiehansen:codex/watch-clean-bitmap → main · +46 −2 · 1 files · 5 commits · open

Follow-up — clean-range benchmark coverage restored

Standard comparison at b581f7e vs f66910f (four ABBA blocks, Linux CPU-only):

Workload Base (ms) Candidate (ms) Paired time change Equivalence
Clean ranges 0.070 0.005 −93.29% Identical
Mixed ranges 0.070 0.004 −94.80% Identical

The adapter now recognizes the production covers_or_empty predicate. The comparison completed successfully, but the separate coverage assertion failed because it used the unqualified workload name; this is a harness-check failure, not a production correctness failure. Follow-up audit corrects the identifier and additionally verifies implementation identity and correctness digests. These are synthetic bitmap predicate timings, not frame-time savings.


Standard benchmark — 2026-12-05

CPU-only Standard audit · b581f7e vs f66910f.

Workload Baseline (ms) Candidate (ms) Result
Clean watch ranges 0.084 — Candidate unsupported
Mixed watch ranges 0.085 — Candidate unsupported
Asking ranges 0.017 0.017 No significant difference

The job passed, but the relevant optimized clean/mixed range workloads were not measured on the candidate. No new performance claim; harness coverage must be fixed.


What this does

check clean guard ranges one bitmap word at a time.

Checks

  • N/A: equivalent clean-range predicate optimization; boundary oracle matched both measured revisions.
  • N/A: no new or changed switch.
  • No unrelated cleanup: Single watch predicate subject.
  • A test must exercise the change: Boundary oracle deliberately passes both implementations; need performance/work-count sensitivity test on current head.
  • Queue checked on 2026-12-04: #312 scopes separate write-watch queries; #513 changes watch lock contention. Review integration.
  • Run cargo xtask policy on the final revision; no new game assets or build output intended.

Verified

Existing measurements and commands are retained below at their original revisions. No fresh compile, policy or hardware test is claimed by this metadata review.

Cost

Synthetic predicate −94.89% to −95.94%, with drift; no live guard/FPS timing.


Detailed implementation and historical validation

Problem

The write-watch guard checks whether a view range is already clean before taking the more expensive path. The current predicate walks every set bit to count it. Upstream documents workloads with about 150,000 view blocks queried in a frame, nearly all clean.

Change and correctness

Reuse the existing masked bitmap-word scan, with the same sequentially consistent word loads as the set-bit iterator. A covered word needs one comparison, and a missing bit can send the request to the existing slow path immediately. The scan preserves partial-word masks, missing-piece behavior and the empty-range result. The shared guard lock and subsequent BESIDE check remain in their original order. No shader, mapping, reset, protection or queue behavior is changed. The implementation is derived from the existing in-tree bitmap and guard code.

Validation

Apple M5, macOS ARM64, Bench Suite Standard, four paired A/B/B/A blocks. Each timed sample checks 64 ranges of 2,784 blocks. The fixture extracts the corresponding production bitmap and the predicate called by guard from each revision.

CPU predicate 45591b0 19f71f9 Paired change (95% CI)
All ranges clean 64.833 µs 3.000 µs −94.89% (−96.44% to −92.66%)
One quarter of ranges contain a missing bit 64.251 µs 2.375 µs −95.94% (−97.45% to −93.53%)

Both result digests matched. The exhaustive local boundary oracle passed for both revisions, including empty ranges, missing bits and word and bitmap-piece boundaries. The production snapshots compiled the relevant portable code. Asset policy and Git whitespace checks passed. Candidate microseconds had high relative variance, and clean baseline drift was +5.5%.

./tools/benchmark-suite/run compare 45591b0f6daf6f5d2a738307d72713428c958633 19f71f969f227fb2505797a9109b0642ba47d6f5 \
  --cpu-only --suite sync --profile standard --blocks 4 \
  --out local/benchmarks/phase7-watch-clean-bitmap

The two workloads are provided by Benchmark Suite PR #322. They time the clean-range predicate and exclude the rest of guard, lock contention and Windows write-watch calls. Hardware benchmarking was unavailable. Please test matched RT-enabled native routes on RX 9060 XT 16 GB at 1080p and RX 9070 XT at 1440p, with frame generation off, and compare guard CPU time, copy correctness and P99. No gameplay FPS change is inferred.

The benchmark workload is committed at 7d2ad97 in PR #322. Upstream 1152b9c still has the benchmarked baseline watch.rs, and GitHub reports a clean merge against that revision.

Follow-up review fixes (2026-12-04)

Head: 4634589b6be95cc5f67336663f64109042a13170.

Name the empty-range semantics explicitly (covers_or_empty). Added clean_range_word_scan_matches_set_bit_count, comparing against the original set-bit count across word and piece boundaries, absent pieces, holes and empty ranges.

Pinned CI audit started for this revision. Final-head compilation, tests and policy results are pending; historical measurements have not been relabelled.

Queue refresh — 2026-12-05

Merged upstream main b581f7e0a8086158953a64068ba29305d5450d68 into the existing branch without rewriting history. New head: f66910f888999fc362a73b11fa7df368783eb535. Live before/after watch tally still needed.

Fresh pinned CI audit is the verification record for this revision; previous tests apply to the previously stated heads. #528 remains a separate policy prerequisite, not a runtime dependency. No new gameplay or GPU timing claim.

**@⁠tommiehansen** on GitHub · 2026-12-03 21:45 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/381) `tommiehansen:codex/watch-clean-bitmap` → `main` · +46 −2 · 1 files · 5 commits · open ## Follow-up — clean-range benchmark coverage restored [Standard comparison](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47507523617/job/145635097937) at `b581f7e` vs `f66910f` (four ABBA blocks, Linux CPU-only): | Workload | Base (ms) | Candidate (ms) | Paired time change | Equivalence | |---|---:|---:|---:|---| | Clean ranges | 0.070 | 0.005 | **−93.29%** | Identical | | Mixed ranges | 0.070 | 0.004 | **−94.80%** | Identical | The adapter now recognizes the production `covers_or_empty` predicate. The comparison completed successfully, but the separate coverage assertion failed because it used the unqualified workload name; this is a harness-check failure, not a production correctness failure. Follow-up audit corrects the identifier and additionally verifies implementation identity and correctness digests. These are synthetic bitmap predicate timings, not frame-time savings. --- ## Standard benchmark — 2026-12-05 [CPU-only Standard audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47503640056/job/145622974695) · `b581f7e` vs `f66910f`. | Workload | Baseline (ms) | Candidate (ms) | Result | |---|---:|---:|---| | Clean watch ranges | 0.084 | — | Candidate unsupported | | Mixed watch ranges | 0.085 | — | Candidate unsupported | | Asking ranges | 0.017 | 0.017 | No significant difference | The job passed, but the relevant optimized clean/mixed range workloads were not measured on the candidate. No new performance claim; harness coverage must be fixed. --- ## What this does check clean guard ranges one bitmap word at a time. ## Checks - N/A: equivalent clean-range predicate optimization; boundary oracle matched both measured revisions. - N/A: no new or changed switch. - [x] No unrelated cleanup: Single watch predicate subject. - [ ] A test must exercise the change: Boundary oracle deliberately passes both implementations; need performance/work-count sensitivity test on current head. - [x] Queue checked on 2026-12-04: #312 scopes separate write-watch queries; #513 changes watch lock contention. Review integration. - [ ] Run `cargo xtask policy` on the final revision; no new game assets or build output intended. ## Verified Existing measurements and commands are retained below at their original revisions. No fresh compile, policy or hardware test is claimed by this metadata review. ## Cost Synthetic predicate −94.89% to −95.94%, with drift; no live guard/FPS timing. --- ## Detailed implementation and historical validation ## Problem The write-watch guard checks whether a view range is already clean before taking the more expensive path. The current predicate walks every set bit to count it. Upstream documents workloads with about 150,000 view blocks queried in a frame, nearly all clean. ## Change and correctness Reuse the existing masked bitmap-word scan, with the same sequentially consistent word loads as the set-bit iterator. A covered word needs one comparison, and a missing bit can send the request to the existing slow path immediately. The scan preserves partial-word masks, missing-piece behavior and the empty-range result. The shared guard lock and subsequent `BESIDE` check remain in their original order. No shader, mapping, reset, protection or queue behavior is changed. The implementation is derived from the existing in-tree bitmap and guard code. ## Validation Apple M5, macOS ARM64, Bench Suite Standard, four paired A/B/B/A blocks. Each timed sample checks 64 ranges of 2,784 blocks. The fixture extracts the corresponding production bitmap and the predicate called by `guard` from each revision. | CPU predicate | `45591b0` | `19f71f9` | Paired change (95% CI) | |---|---:|---:|---:| | All ranges clean | 64.833 µs | 3.000 µs | −94.89% (−96.44% to −92.66%) | | One quarter of ranges contain a missing bit | 64.251 µs | 2.375 µs | −95.94% (−97.45% to −93.53%) | Both result digests matched. The exhaustive local boundary oracle passed for both revisions, including empty ranges, missing bits and word and bitmap-piece boundaries. The production snapshots compiled the relevant portable code. Asset policy and Git whitespace checks passed. Candidate microseconds had high relative variance, and clean baseline drift was +5.5%. ```sh ./tools/benchmark-suite/run compare 45591b0f6daf6f5d2a738307d72713428c958633 19f71f969f227fb2505797a9109b0642ba47d6f5 \ --cpu-only --suite sync --profile standard --blocks 4 \ --out local/benchmarks/phase7-watch-clean-bitmap ``` The two workloads are provided by Benchmark Suite PR #322. They time the clean-range predicate and exclude the rest of `guard`, lock contention and Windows write-watch calls. Hardware benchmarking was unavailable. Please test matched RT-enabled native routes on RX 9060 XT 16 GB at 1080p and RX 9070 XT at 1440p, with frame generation off, and compare guard CPU time, copy correctness and P99. No gameplay FPS change is inferred. The benchmark workload is committed at [`7d2ad97`](https://github.com/tommiehansen/VIctory-xmem/commit/7d2ad97) in PR #322. Upstream `1152b9c` still has the benchmarked baseline `watch.rs`, and GitHub reports a clean merge against that revision. ### Follow-up review fixes (2026-12-04) Head: `4634589b6be95cc5f67336663f64109042a13170`. Name the empty-range semantics explicitly (`covers_or_empty`). Added `clean_range_word_scan_matches_set_bit_count`, comparing against the original set-bit count across word and piece boundaries, absent pieces, holes and empty ranges. Pinned [CI audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47438443784) started for this revision. Final-head compilation, tests and policy results are pending; historical measurements have not been relabelled. ### Queue refresh — 2026-12-05 Merged upstream main `b581f7e0a8086158953a64068ba29305d5450d68` into the existing branch without rewriting history. New head: `f66910f888999fc362a73b11fa7df368783eb535`. Live before/after watch tally still needed. [Fresh pinned CI audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47466412636) is the verification record for this revision; previous tests apply to the previously stated heads. #528 remains a separate policy prerequisite, not a runtime dependency. No new gameplay or GPU timing claim.
The guard fast path consumed every set bit before deciding whether a range was entirely clean. Compare masked bitmap words directly and return on the first missing bit. Retain the same sequentially consistent loads, empty-range behavior, separate BESIDE check, and shared guard lock.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 21:46:29 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-03 22:19 UTC · original

Tested on native Windows 11 (MSVC), with the PR applied on top of 0b652f8 and also on its own branch.

Equivalence. I added a local-only test (not part of this PR) that compares g.clean.range(first..last).count() == last - first from main against covers(first, last) on the same Blocks, over every [first, last) pair (empty ranges included) in each window:

  • 4 words (256 blocks) at two offsets: all set, all clear, every single-hole and single-bit pattern, plus 2000 random ones (dense, sparse, half and contiguous runs)
  • every one of the 65536 patterns of a 16-bit window across a word boundary, with all ranges inside 32 blocks around it
  • across a 4 GiB piece boundary, with the next piece allocated and with it missing
  • the last words of the bitmap, with ranges running past the end (where main clamps)

253,188,480 cases, 0 mismatches (94.8M of them clean). To check the harness itself, I made the end mask drop the last bit when a range ends on a word boundary, and it caught that right away (f=0 l=64 and others), so it does look at the edges.

Tests, PR on 0b652f8, cargo test -p victory-gpu --lib -- --test-threads=4 --skip descriptor::tests::views_die_with_their_resource: 338 passed / 5 failed / 23 ignored, twice. That's the same as main. The 4 indirect/pipeline failures also fail on main here. watch::tests::the_rest_of_the_one_asking_has_a_number_of_its_own is flaky in the full watch run on both (main failed 2 of 4 runs, PR 3 of 5) and passes every time when run alone on both. The other watch:: tests pass in debug and release.

Clippy with --all-targets: no new warnings compared to main. A small nit: rustfmt with the repo config wants to wrap the all_ordered signature and the covers body.

Rough timing in release (not the bench suite), 64 ranges of 2,784 blocks over a 150k-block clean set: old 66.0 us, new 2.75 us (about 24x). With a hole in some ranges: 66.7 us vs 2.06 us. That's the same order as your numbers.

Looks right to me.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-03 22:19 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/381#issuecomment-7394050163) Tested on native Windows 11 (MSVC), with the PR applied on top of 0b652f8 and also on its own branch. Equivalence. I added a local-only test (not part of this PR) that compares `g.clean.range(first..last).count() == last - first` from main against `covers(first, last)` on the same `Blocks`, over every `[first, last)` pair (empty ranges included) in each window: - 4 words (256 blocks) at two offsets: all set, all clear, every single-hole and single-bit pattern, plus 2000 random ones (dense, sparse, half and contiguous runs) - every one of the 65536 patterns of a 16-bit window across a word boundary, with all ranges inside 32 blocks around it - across a 4 GiB piece boundary, with the next piece allocated and with it missing - the last words of the bitmap, with ranges running past the end (where main clamps) 253,188,480 cases, 0 mismatches (94.8M of them clean). To check the harness itself, I made the end mask drop the last bit when a range ends on a word boundary, and it caught that right away (f=0 l=64 and others), so it does look at the edges. Tests, PR on 0b652f8, `cargo test -p victory-gpu --lib -- --test-threads=4 --skip descriptor::tests::views_die_with_their_resource`: 338 passed / 5 failed / 23 ignored, twice. That's the same as main. The 4 indirect/pipeline failures also fail on main here. `watch::tests::the_rest_of_the_one_asking_has_a_number_of_its_own` is flaky in the full watch run on both (main failed 2 of 4 runs, PR 3 of 5) and passes every time when run alone on both. The other watch:: tests pass in debug and release. Clippy with `--all-targets`: no new warnings compared to main. A small nit: rustfmt with the repo config wants to wrap the `all_ordered` signature and the `covers` body. Rough timing in release (not the bench suite), 64 ranges of 2,784 blocks over a 150k-block clean set: old 66.0 us, new 2.75 us (about 24x). With a hole in some ranges: 66.7 us vs 2.06 us. That's the same order as your numbers. Looks right to me. AI-assisted: yes
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-04 00:05 UTC · original

Thanks @⁠Kal0s-design for verifying watch.rs across the 253M-case differential check and catching the formatting nits. Fixed rustfmt formatting on all_ordered and covers (formatting-only change; rustfmt --edition 2024 --check and Windows x86_64-pc-windows-msvc victory-gpu --all-targets check pass).

**@⁠tommiehansen** on GitHub · 2026-12-04 00:05 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/381#issuecomment-7396354496) Thanks @⁠Kal0s-design for verifying `watch.rs` across the 253M-case differential check and catching the formatting nits. Fixed `rustfmt` formatting on `all_ordered` and `covers` (formatting-only change; `rustfmt --edition 2024 --check` and Windows `x86_64-pc-windows-msvc` `victory-gpu --all-targets` check pass).
Author
Owner

@⁠Luxuride on GitHub · 2026-12-04 12:03 UTC · original

Safe as written and a real micro-win — the swap is semantically identical (watch.rs:1487-1489 skips the missing piece and count() cannot reach last - first, and the BESIDE check is untouched) — but three small things:

  • No number, in a file that already keeps numbers. watch.rs:2102-2106 says a frame asks about "some 10 GB of view memory, 150,000 blocks, nearly all clean", and the tally at watch.rs:2127 counts exactly the "no question to Windows" cases. One before/after line of that counter sells the change by itself.
  • Two orderings now describe the same predicate: all() uses Acquire (watch.rs:1474) while covers asks for SeqCst (watch.rs:1866) to match Bits::range (watch.rs:1390). Keep the SeqCst — it is the same word order the range iterator had — but comment why, or the next reader will "fix" it back.
  • covers returns true for an empty range (watch.rs:1862) while the all() it wraps returns false (watch.rs:1497). Correct at this call site, but name it (covers_or_empty) or assert first < last, because it will bite the next caller.

Fold the rustfmt commit into the first one before merging.

**@⁠Luxuride** on GitHub · 2026-12-04 12:03 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/381#issuecomment-7410925778) Safe as written and a real micro-win — the swap is semantically identical (`watch.rs:1487-1489` skips the missing piece and `count()` cannot reach `last - first`, and the `BESIDE` check is untouched) — but three small things: - No number, in a file that already keeps numbers. `watch.rs:2102-2106` says a frame asks about "some 10 GB of view memory, 150,000 blocks, nearly all clean", and the tally at `watch.rs:2127` counts exactly the "no question to Windows" cases. One before/after line of that counter sells the change by itself. - Two orderings now describe the same predicate: `all()` uses `Acquire` (`watch.rs:1474`) while `covers` asks for `SeqCst` (`watch.rs:1866`) to match `Bits::range` (`watch.rs:1390`). Keep the `SeqCst` — it is the same word order the range iterator had — but comment why, or the next reader will "fix" it back. - `covers` returns `true` for an empty range (`watch.rs:1862`) while the `all()` it wraps returns `false` (`watch.rs:1497`). Correct at this call site, but name it (`covers_or_empty`) or assert `first < last`, because it will bite the next caller. Fold the rustfmt commit into the first one before merging.
github-bot changed title from watch: check clean guard ranges one bitmap word at a time to perf(gpu): check clean guard ranges one bitmap word at a time 2026-12-04 22:20:00 +00:00
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-05 10:19 UTC · original

Thanks for the bitmap review. f66910f uses covers_or_empty and documents the SeqCst ordering. The restored clean/mixed benchmark coverage now passes CI with matching digests and verified production predicates. The preceding Standard comparison measured 93.29%/94.80% lower predicate time; not per-frame savings.

**@⁠tommiehansen** on GitHub · 2026-12-05 10:19 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/381#issuecomment-7436367741) Thanks for the bitmap review. [f66910f](https://github.com/tommiehansen/VIctory-xmem/commit/f66910f888999fc362a73b11fa7df368783eb535) uses covers_or_empty and documents the SeqCst ordering. The restored clean/mixed benchmark coverage now passes [CI with matching digests and verified production predicates](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47508151165). The preceding Standard comparison measured 93.29%/94.80% lower predicate time; not per-frame savings.
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/381/head:github-bot/gh-381'
git switch 'github-bot/gh-381'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-381'
git switch 'github-bot/gh-381'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-381'
git switch 'github-bot/gh-381'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-381'
git switch 'main'
git merge --squash 'github-bot/gh-381'
git switch 'main'
git merge --ff-only 'github-bot/gh-381'
git switch 'main'
git merge 'github-bot/gh-381'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.