gpu/shadow: O(dirty) CopiedPages bitmask, lock-free mirrors & AVX2 merge/diff (2/4 of #51) #57

Closed
Vladimir-Human wants to merge 87 commits from upstream-pr/57 into main
Vladimir-Human commented 2026-11-26 00:39:55 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-26T00:39:55Z.


Split 2/4 of #51 cleanly on top of beta (independent of #56, Part 3 ReBAR, and Part 4 Lazy Copy-Back).

Summary of Changes (crates/victory-gpu/src/shadow.rs)

  • O(dirty) CopiedPages bitmask + SmallRuns inline coalescer: pairs per-page copied stamps with a 64-page-per-word uncopied_bits bitmask and inline 8-entry SmallRuns so Shadow::copy_stale skips clean spans 64 pages at a time, plans coalesced copy runs under self.copied, and releases the mutex before issuing memory copies.
  • Lock-free fast-path mirrors: adds Shadow::has_pending (AtomicBool) and Card::{has_dirty, has_sent} (AtomicBools with Release/Acquire ordering in card_dirty and card_merge_relay) to avoid mutex traffic on read-only windows and clean carded copies.
  • AVX2 merge/diff kernels with scalar fallbacks: adds has_avx2() runtime dispatch for first_difference, last_difference, changed_runs, merge_piece, merge_sync_card, and merge_back_piece, eliminating back_piece's per-piece mask allocation.
  • Lock-free WideDone worker completion, panic propagation, and TLS scratch reuse: moves copy_wide and Shadow::differing onto the kept worker pool with WideDone, adaptive WIDE_MIN_SPLIT batching, nested IN_WIDE reentrancy guard, and SCRATCH_TITLE / parts+rest buffer reuse.
  • Unit tests & opt-in microbenchmark: copied_and_simd_tests::{plan_stale_matches_oracle_across_boundaries_and_partial_init, simd_diff_and_merge_helpers_match_scalar_oracles, nested_wide_runs_without_deadlock, wide_propagates_worker_panic_without_deadlocking_pool} and #[ignore] bench_copied_and_simd.

Verification (VICTORY_D3D12_DEBUG=1)

  • cargo test -p victory-gpu -> passed
  • cargo test -p victory-gpu --all-features -> passed
  • cargo run -p xtask -- policy --staged -> asset policy: 1 files ok (shadow.rs = 222,729 B)

Related: #51, #56

<!-- greyfinch-sync:PastiiJay/klbf-lab:issue:5501758850 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-26T00:39:55Z. --- Split 2/4 of #51 cleanly on top of `beta` (independent of #56, Part 3 ReBAR, and Part 4 Lazy Copy-Back). ### Summary of Changes (`crates/victory-gpu/src/shadow.rs`) - **O(dirty) `CopiedPages` bitmask + `SmallRuns` inline coalescer**: pairs per-page copied stamps with a 64-page-per-word `uncopied_bits` bitmask and inline 8-entry `SmallRuns` so `Shadow::copy_stale` skips clean spans 64 pages at a time, plans coalesced copy runs under `self.copied`, and releases the mutex before issuing memory copies. - **Lock-free fast-path mirrors**: adds `Shadow::has_pending` (`AtomicBool`) and `Card::{has_dirty, has_sent}` (`AtomicBool`s with Release/Acquire ordering in `card_dirty` and `card_merge_relay`) to avoid mutex traffic on read-only windows and clean carded copies. - **AVX2 merge/diff kernels with scalar fallbacks**: adds `has_avx2()` runtime dispatch for `first_difference`, `last_difference`, `changed_runs`, `merge_piece`, `merge_sync_card`, and `merge_back_piece`, eliminating `back_piece`'s per-piece `mask` allocation. - **Lock-free `WideDone` worker completion, panic propagation, and TLS scratch reuse**: moves `copy_wide` and `Shadow::differing` onto the kept worker pool with `WideDone`, adaptive `WIDE_MIN_SPLIT` batching, nested `IN_WIDE` reentrancy guard, and `SCRATCH_TITLE` / `parts`+`rest` buffer reuse. - **Unit tests & opt-in microbenchmark**: `copied_and_simd_tests::{plan_stale_matches_oracle_across_boundaries_and_partial_init, simd_diff_and_merge_helpers_match_scalar_oracles, nested_wide_runs_without_deadlock, wide_propagates_worker_panic_without_deadlocking_pool}` and `#[ignore] bench_copied_and_simd`. ### Verification (`VICTORY_D3D12_DEBUG=1`) - `cargo test -p victory-gpu` -> passed - `cargo test -p victory-gpu --all-features` -> passed - `cargo run -p xtask -- policy --staged` -> `asset policy: 1 files ok` (`shadow.rs` = 222,729 B) Related: #51, #56
HandshakeHackin commented 2026-11-26 02:53:02 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-26T02:53:02Z.


I tested ea3f336 on a Windows x64 runner that confirmed AVX2 was available. Across 22,380 placements of a changed byte range (including empty spans) in 31–97 byte buffers, the first/last differences and exact changed runs matched the expected values. With CPU edits at bytes 30, 31, 32, 63 and 64 where present, the copy-back merge also preserved those edits, returned the expected disjoint ranges, and left the host and title buffers byte-identical to the oracle. This exercises all-changed 32-byte blocks, ends of vectors and scalar tails using synthetic bytes. Test and log

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7181202783 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7181202783). Originally posted by [HandshakeHackin](https://github.com/HandshakeHackin) on 2026-11-26T02:53:02Z. --- I tested `ea3f336` on a Windows x64 runner that confirmed AVX2 was available. Across 22,380 placements of a changed byte range (including empty spans) in 31–97 byte buffers, the first/last differences and exact changed runs matched the expected values. With CPU edits at bytes 30, 31, 32, 63 and 64 where present, the copy-back merge also preserved those edits, returned the expected disjoint ranges, and left the host and title buffers byte-identical to the oracle. This exercises all-changed 32-byte blocks, ends of vectors and scalar tails using synthetic bytes. [Test and log](https://github.com/HandshakeHackin/klbf-lab/actions/runs/45744902455/job/139658477513)
PastiiJay commented 2026-11-26 10:42:14 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-26T10:42:14Z.


Thanks for the 22k-placement check against the oracle, that's thorough. We'll test the AVX2 path in game.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7189720479 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7189720479). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-26T10:42:14Z. --- Thanks for the 22k-placement check against the oracle, that's thorough. We'll test the AVX2 path in game.
Proudnoob4 commented 2026-11-26 14:39:27 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Proudnoob4 on 2026-11-26T14:39:27Z.


Live in-game GTA 6 runtime oracle audit + 10-minute benchmark (0 mismatches, -65% noting the runs, -82% finding the pages)

We ported this full shadow/watch optimization stack (O(dirty) TOUCHED_CARDS, 64-page-per-word CopiedPages bitmask, lock-free has_pending, direct merge_under_writes, FOUND_LOOSE thread-local cache, in-place joined(), and AVX2 first_difference / last_difference / merge_piece / merge_sync_card / changed_runs) into our RTX 4080 / i5-13600K (Windows 10) GTA 6 Series S build and verified it both for live correctness and steady-state performance:

  1. 10-minute live GTA 6 runtime oracle audit (31,249 log lines, real gameplay frames):

    • Instrumented all 7 fast paths (AVX2 first_difference/last_difference/changed_runs/merge_piece/merge_sync_card, TOUCHED_CARDS dirty scan, CopiedPages bitmask, FOUND_LOOSE cache, and in-place joined()) to compare against the scalar / stock reference on live frames.
    • Result: 0 mismatches (ERROR=0) across the entire 10-minute live run.
  2. 10-minute release benchmark (RTX 4080 16 GB, i5-13600K, Win10, render_scale=0.6667, VICTORY_CARD_BUFFERS_MIN_KB=64, VICTORY_FETCH_CHECK=1, VICTORY_SKIP_WC_MIN_KB=1024, RT skipped):

    • VICTORY_LATE_WAIT=2 (212 pages looked at, 77,290 changed runs, 2.38 MB):
      • finding the pages: ~0.28 ms -> 0.05 ms (-82%)
      • noting the runs: ~3.7 ms -> 1.28 ms (-65%)
      • comparing pages: 1.93 ms wall (1.65 ms reading + 6.71 ms comparing/putting in across worker threads)
    • End-to-end settled performance (n=104, tail-40 n=40):
      • 32.00 fps median (31.50 p10, 32.60 p90, 32.70 tail-40 max, 33.20 overall max; 0 tail frames >55 ms)
      • 4,505 draws/frame, 317 pieces landed/frame (4.5 MB dirty 4 KiB pages, 0.84 MB dwords)
      • Visual verification (t=140..600s): 0/230 black frames, 120/120 clean consecutive burst frames (4 fps contact sheets at t=420–435s and t=520–535s).

The AVX2 paths and O(dirty) bookkeeping held up 100% clean in real GTA 6 gameplay!

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7195133760 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7195133760). Originally posted by [Proudnoob4](https://github.com/Proudnoob4) on 2026-11-26T14:39:27Z. --- ### Live in-game GTA 6 runtime oracle audit + 10-minute benchmark (`0` mismatches, `-65%` `noting the runs`, `-82%` `finding the pages`) We ported this full shadow/watch optimization stack (`O(dirty)` `TOUCHED_CARDS`, 64-page-per-word `CopiedPages` bitmask, lock-free `has_pending`, direct `merge_under_writes`, `FOUND_LOOSE` thread-local cache, in-place `joined()`, and AVX2 `first_difference` / `last_difference` / `merge_piece` / `merge_sync_card` / `changed_runs`) into our RTX 4080 / i5-13600K (Windows 10) GTA 6 Series S build and verified it both for live correctness and steady-state performance: 1. **10-minute live GTA 6 runtime oracle audit (`31,249` log lines, real gameplay frames):** - Instrumented all 7 fast paths (AVX2 `first_difference`/`last_difference`/`changed_runs`/`merge_piece`/`merge_sync_card`, `TOUCHED_CARDS` dirty scan, `CopiedPages` bitmask, `FOUND_LOOSE` cache, and in-place `joined()`) to compare against the scalar / stock reference on live frames. - **Result: `0` mismatches (`ERROR=0`) across the entire 10-minute live run.** 2. **10-minute release benchmark (RTX 4080 16 GB, i5-13600K, Win10, `render_scale=0.6667`, `VICTORY_CARD_BUFFERS_MIN_KB=64`, `VICTORY_FETCH_CHECK=1`, `VICTORY_SKIP_WC_MIN_KB=1024`, RT skipped):** - **`VICTORY_LATE_WAIT=2` (`212` pages looked at, `77,290` changed runs, `2.38 MB`):** - `finding the pages`: **`~0.28 ms -> 0.05 ms` (-82%)** - `noting the runs`: **`~3.7 ms -> 1.28 ms` (-65%)** - `comparing pages`: **`1.93 ms`** wall (`1.65 ms` reading + `6.71 ms` comparing/putting in across worker threads) - **End-to-end settled performance (`n=104`, tail-40 `n=40`):** - **`32.00 fps` median** (`31.50` p10, `32.60` p90, `32.70` tail-40 max, `33.20` overall max; `0` tail frames `>55 ms`) - **`4,505` draws/frame**, `317` pieces landed/frame (`4.5 MB` dirty 4 KiB pages, `0.84 MB` dwords) - **Visual verification (`t=140..600s`):** `0/230` black frames, `120/120` clean consecutive burst frames (`4 fps` contact sheets at `t=420–435s` and `t=520–535s`). The AVX2 paths and `O(dirty)` bookkeeping held up 100% clean in real GTA 6 gameplay!
PastiiJay commented 2026-11-26 14:49:11 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-26T14:49:11Z.


Thanks @Proudnoob4, a 10-minute live oracle with zero mismatches is the strongest check this one has had, and the drop in page-finding time is a nice bonus. If you have the setup ready, the same oracle-plus-benchmark on #59 (lazy copy-back) would be the most useful next run, since it touches the same shadow path.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7195375503 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7195375503). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-26T14:49:11Z. --- Thanks @Proudnoob4, a 10-minute live oracle with zero mismatches is the strongest check this one has had, and the drop in page-finding time is a nice bonus. If you have the setup ready, the same oracle-plus-benchmark on #59 (lazy copy-back) would be the most useful next run, since it touches the same shadow path.
Proudnoob4 commented 2026-11-26 14:58:58 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Proudnoob4 on 2026-11-26T14:58:58Z.


@PastiiJay Sounds like a plan! We're running a 10-minute verification pass on our current batch (fxceless#1184 + #1274 + #1276) right now, and right after that we'll port #59 (VICTORY_LAZY_COPYBACK=1) onto our tree, run the live GTA 6 coherence/oracle + 10-minute benchmark on RTX 4080 / i5-13600K (Win10), and post the full measured results and visual check on #59.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7195610617 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7195610617). Originally posted by [Proudnoob4](https://github.com/Proudnoob4) on 2026-11-26T14:58:58Z. --- @PastiiJay Sounds like a plan! We're running a 10-minute verification pass on our current batch (`fxceless#1184` + `#1274` + `#1276`) right now, and right after that we'll port `#59` (`VICTORY_LAZY_COPYBACK=1`) onto our tree, run the live GTA 6 coherence/oracle + 10-minute benchmark on RTX 4080 / i5-13600K (Win10), and post the full measured results and visual check on `#59`.
PastiiJay commented 2026-11-26 15:18:56 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-26T15:18:56Z.


Sounds good, thanks. We will watch #59 for the results; a visual check of the same scenes with and without VICTORY_LAZY_COPYBACK=1 would be the part we care about most.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7196091611 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7196091611). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-26T15:18:56Z. --- Sounds good, thanks. We will watch #59 for the results; a visual check of the same scenes with and without `VICTORY_LAZY_COPYBACK=1` would be the part we care about most.
Vladimir-Human commented 2026-11-27 08:33:27 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-27T08:33:27Z.


Backported the concurrency hardening identified by @efsebayern and @TaynanGT (TaynanGT/Vice-Tay#192, c289a95) in 7399812:

  • Hold self.copied across copies in Shadow::copy_stale: keeps the copied mutex locked from plan_stale through self.copy(...) so concurrent refreshes cannot observe stamped at == now pages before their bytes land or race on writing self.data.
  • Skip clean copies in card_dirty: returns early when !c.has_dirty instead of locking and pruning c.sent on clean copies.

Verified locally on Windows (VICTORY_D3D12_DEBUG=1):

  • cargo clippy -p victory-gpu --all-targets & --features diagnostics: 0 warnings in crates/victory-gpu/src/shadow.rs (only pre-existing upstream warnings in untouched files)
  • cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 32 passed; 0 failed; 1 ignored
  • cargo test -p victory-gpu --features diagnostics --lib shadow:: -- --test-threads=1: 32 passed; 0 failed; 1 ignored
<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7213664883 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7213664883). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-27T08:33:27Z. --- Backported the concurrency hardening identified by `@efsebayern` and `@TaynanGT` ([TaynanGT/Vice-Tay#192](https://github.com/TaynanGT/Vice-Tay/pull/192), `c289a95`) in `7399812`: - **Hold `self.copied` across copies in `Shadow::copy_stale`:** keeps the `copied` mutex locked from `plan_stale` through `self.copy(...)` so concurrent refreshes cannot observe stamped `at == now` pages before their bytes land or race on writing `self.data`. - **Skip clean copies in `card_dirty`:** returns early when `!c.has_dirty` instead of locking and pruning `c.sent` on clean copies. Verified locally on Windows (`VICTORY_D3D12_DEBUG=1`): - `cargo clippy -p victory-gpu --all-targets` & `--features diagnostics`: 0 warnings in `crates/victory-gpu/src/shadow.rs` (only pre-existing upstream warnings in untouched files) - `cargo test -p victory-gpu --lib shadow:: -- --test-threads=1`: `32 passed; 0 failed; 1 ignored` - `cargo test -p victory-gpu --features diagnostics --lib shadow:: -- --test-threads=1`: `32 passed; 0 failed; 1 ignored`
PastiiJay commented 2026-11-27 09:52:38 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T09:52:38Z.


Thanks @Vladimir-Human, and credit to @efsebayern and @TaynanGT for the hardening. We'll review it with the next beta batch. Could you rebase on the current head if it no longer merges cleanly by then?

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7215202038 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7215202038). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-27T09:52:38Z. --- Thanks @Vladimir-Human, and credit to @efsebayern and @TaynanGT for the hardening. We'll review it with the next beta batch. Could you rebase on the current head if it no longer merges cleanly by then?
TaynanGT commented 2026-11-27 09:58:21 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T09:58:21Z.


@PastiiJay 7399812 also merges cleanly against beta at 6cce57e. It keeps the CopiedPages lock through the actual copy, matching the guard that landed in Vice-Tay #192. That is the part to keep together if the next beta head needs a rebase.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7215320770 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7215320770). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T09:58:21Z. --- @PastiiJay `7399812` also merges cleanly against `beta` at `6cce57e`. It keeps the `CopiedPages` lock through the actual copy, matching the guard that landed in Vice-Tay #192. That is the part to keep together if the next beta head needs a rebase.
Vladimir-Human commented 2026-11-27 10:44:17 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-27T10:44:17Z.


Thanks @PastiiJay and @TaynanGT! Confirmed 7399812 merges cleanly against current beta (6cce57e), and I will rebase promptly (keeping the CopiedPages lock scope across self.copy(...) intact) whenever the next beta batch lands.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7216244926 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7216244926). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-27T10:44:17Z. --- Thanks @PastiiJay and @TaynanGT! Confirmed `7399812` merges cleanly against current `beta` (`6cce57e`), and I will rebase promptly (keeping the `CopiedPages` lock scope across `self.copy(...)` intact) whenever the next beta batch lands.
PastiiJay commented 2026-11-27 10:50:24 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T10:50:24Z.


Thanks @Vladimir-Human for the lock-scope note on CopiedPages, that's exactly the part we're checking. Could you say which tests you ran around self.copy(...) on your side?

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7216366761 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7216366761). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-27T10:50:24Z. --- Thanks @Vladimir-Human for the lock-scope note on `CopiedPages`, that's exactly the part we're checking. Could you say which tests you ran around `self.copy(...)` on your side?
TaynanGT commented 2026-11-27 10:51:41 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T10:51:41Z.


@Vladimir-Human The AVX2 comparison against the scalar result is a useful regression to carry with the copy lock when the rebase is needed. That keeps the buffer-content check tied to the new head.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7216392908 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7216392908). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T10:51:41Z. --- @Vladimir-Human The AVX2 comparison against the scalar result is a useful regression to carry with the copy lock when the rebase is needed. That keeps the buffer-content check tied to the new head.
PastiiJay commented 2026-11-27 10:52:04 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T10:52:04Z.


We'll take them onto the AMD line one at a time with an A/B bench. Thanks, the tests you added make that much easier.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7216400944 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7216400944). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-27T10:52:04Z. --- We'll take them onto the AMD line one at a time with an A/B bench. Thanks, the tests you added make that much easier.
TaynanGT commented 2026-11-27 10:58:58 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T10:58:58Z.


@PastiiJay The scalar fixture covers both the AVX2 tails and CPU edits that occur before copy-back. It can travel with that piece of the AMD port, then the scene comparison can focus on timing.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7216538929 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7216538929). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T10:58:58Z. --- @PastiiJay The scalar fixture covers both the AVX2 tails and CPU edits that occur before copy-back. It can travel with that piece of the AMD port, then the scene comparison can focus on timing.
PastiiJay commented 2026-11-27 11:11:35 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T11:11:35Z.


checked it against our AMD line: our copy_stale already holds copied for the whole copy and card_dirty has no dirty/sent split, so that race isn't there. thanks for pointing at it, it was worth the check.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7216788216 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7216788216). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-27T11:11:35Z. --- checked it against our AMD line: our copy_stale already holds `copied` for the whole copy and card_dirty has no dirty/sent split, so that race isn't there. thanks for pointing at it, it was worth the check.
TaynanGT commented 2026-11-27 11:16:51 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T11:16:51Z.


@PastiiJay The AMD branch already has the copy serialization that change was meant to protect. The scalar oracle can therefore check the AVX2 port against your current implementation.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7216890544 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7216890544). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T11:16:51Z. --- @PastiiJay The AMD branch already has the copy serialization that change was meant to protect. The scalar oracle can therefore check the AVX2 port against your current implementation.
PastiiJay commented 2026-11-27 14:04:24 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T14:04:24Z.


Thanks @TaynanGT, good to know the scalar oracle can check the AVX2 port against what's already on the AMD branch. We'll use it as the reference when we port this.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7220298759 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7220298759). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-27T14:04:24Z. --- Thanks @TaynanGT, good to know the scalar oracle can check the AVX2 port against what's already on the AMD branch. We'll use it as the reference when we port this.
TaynanGT commented 2026-11-27 14:25:12 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T14:25:12Z.


@PastiiJay For the AVX2 port, run the scalar and vector paths over the same dirty-page map and compare both the merged bytes and the untouched tail. That’ll catch a boundary difference even if the whole-page cases pass.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7220759230 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7220759230). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T14:25:12Z. --- @PastiiJay For the AVX2 port, run the scalar and vector paths over the same dirty-page map and compare both the merged bytes and the untouched tail. That’ll catch a boundary difference even if the whole-page cases pass.
PastiiJay commented 2026-11-27 14:27:02 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T14:27:02Z.


Good tip, comparing the untouched tail too. We'll add that check when we port it.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7220797588 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7220797588). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-27T14:27:02Z. --- Good tip, comparing the untouched tail too. We'll add that check when we port it.
HandshakeHackin commented 2026-11-27 14:38:11 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-27T14:38:11Z.


I added the sparse-page case @TaynanGT suggested as a test-only commit on 7399812. It marks pages 0, 2 and 3 dirty, starts seven bytes into page 0, and stops 31, 32 or 33 bytes into page 3. It compares the full merged buffers against the scalar implementation and separately checks the prefix, clean page and unused suffix against their original bytes.

The regression passed on a Windows x64 runner with AVX2. Deliberately dropping the scalar remainder in the AVX2 merge made the new test fail. Windows run, including the negative control

Following the suffix suggestion below, the updated test fills the suffix with a distinct byte in each input. The complete destination still matched the scalar result. Extending just the final merge range by one byte made the test fail, as did dropping the scalar remainder. Both negative controls on AVX2

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7221033555 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7221033555). Originally posted by [HandshakeHackin](https://github.com/HandshakeHackin) on 2026-11-27T14:38:11Z. --- I added the sparse-page case @TaynanGT suggested as a [test-only commit on `7399812`](https://github.com/HandshakeHackin/klbf-lab/commit/a6a5968e08df89a264c41963eaf3fa912e320ea2). It marks pages 0, 2 and 3 dirty, starts seven bytes into page 0, and stops 31, 32 or 33 bytes into page 3. It compares the full merged buffers against the scalar implementation and separately checks the prefix, clean page and unused suffix against their original bytes. The regression passed on a Windows x64 runner with AVX2. Deliberately dropping the scalar remainder in the AVX2 merge made the new test fail. [Windows run, including the negative control](https://github.com/HandshakeHackin/klbf-lab/actions/runs/46016921702/job/140566297605) Following the suffix suggestion below, the [updated test](https://github.com/HandshakeHackin/klbf-lab/commit/cf7f73aafe0ad41c3796f08f051f08ed4698ba04) fills the suffix with a distinct byte in each input. The complete destination still matched the scalar result. Extending just the final merge range by one byte made the test fail, as did dropping the scalar remainder. [Both negative controls on AVX2](https://github.com/HandshakeHackin/klbf-lab/actions/runs/46019499200/job/140575144240)
TaynanGT commented 2026-11-27 14:38:58 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T14:38:58Z.


@PastiiJay Give the unchanged suffix a different sentinel in each input, then compare the entire destination. That makes it easy to spot a vector write that crosses the dirty range.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7221049481 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7221049481). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T14:38:58Z. --- @PastiiJay Give the unchanged suffix a different sentinel in each input, then compare the entire destination. That makes it easy to spot a vector write that crosses the dirty range.
Vladimir-Human commented 2026-11-28 18:24:53 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-28T18:24:53Z.


Superseded by https://github.com/PastiiJay/klbf-lab/pull/184 cleanly ported onto origin/stable-amd (75022ba).

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7243771870 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7243771870). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-28T18:24:53Z. --- Superseded by https://github.com/PastiiJay/klbf-lab/pull/184 cleanly ported onto `origin/stable-amd` (`75022ba`).
TaynanGT commented 2026-11-29 11:25:40 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-29T11:25:40Z.


Thanks for carrying the AVX2 work forward to #184. The sparse-page and unaligned-tail negative controls from HandshakeHackin are particularly valuable for checking the port without relying on performance results alone.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7255104492 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/57#issuecomment-7255104492). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-29T11:25:40Z. --- Thanks for carrying the AVX2 work forward to #184. The sparse-page and unaligned-tail negative controls from HandshakeHackin are particularly valuable for checking the port without relying on performance results alone.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
PastiiJay/klbf-lab!57
No description provided.