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

Open
Vladimir-Human wants to merge 1 commit from upstream-pr/184 into stable-amd
Vladimir-Human commented 2026-11-28 18:24:51 +00:00 (Migrated from github.com)

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


Clean port of #57 (part 2/4 of #51) onto origin/stable-amd (75022ba, Cargo.lock untouched).

Supersedes #57.

Verification (clean port on 75022ba)

  • cargo check --workspace --tests --locked — passed
  • cargo check -p victory-gpu --tests --locked --features diagnostics — passed
  • cargo test --locked -p victory-gpu --lib shadow — 42 passed, 0 failed, 2 ignored
<!-- greyfinch-sync:PastiiJay/klbf-lab:issue:5543284014 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/184). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-28T18:24:51Z. --- Clean port of #57 (part 2/4 of #51) onto origin/stable-amd (75022ba, Cargo.lock untouched). Supersedes #57. ### Verification (clean port on 75022ba) - cargo check --workspace --tests --locked — passed - cargo check -p victory-gpu --tests --locked --features diagnostics — passed - cargo test --locked -p victory-gpu --lib shadow — 42 passed, 0 failed, 2 ignored
HandshakeHackin commented 2026-11-28 19:20:29 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-28T19:20:29Z.


I carried the untouched-tail check requested in #57 onto this head. The retained copy, the title buffer and the GPU input each get a different byte pattern in the prefix, clean page and unused suffix. Dirty pages 62, 64 and 65 cross the bitmap’s 64-page boundary. The test compares both complete destination buffers with the scalar reference at seven tail lengths (1, 31, 32, 33, 63, 64 and 65 bytes).

On a Windows runner with AVX2 required, all five active tests in the module passed. In a separate negative control I widened the last merge by one byte. The new test failed at byte 196,609, exactly the first untouched byte for the one-byte tail. Test-only commit · Windows run and negative control.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7244471131 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/184#issuecomment-7244471131). Originally posted by [HandshakeHackin](https://github.com/HandshakeHackin) on 2026-11-28T19:20:29Z. --- I carried the [untouched-tail check requested in #57](https://github.com/PastiiJay/klbf-lab/pull/57) onto this head. The retained copy, the title buffer and the GPU input each get a different byte pattern in the prefix, clean page and unused suffix. Dirty pages 62, 64 and 65 cross the bitmap’s 64-page boundary. The test compares both complete destination buffers with the scalar reference at seven tail lengths (1, 31, 32, 33, 63, 64 and 65 bytes). On a Windows runner with AVX2 required, all five active tests in the module passed. In a separate negative control I widened the last merge by one byte. The new test failed at byte **196,609**, exactly the first untouched byte for the one-byte tail. [Test-only commit](https://github.com/HandshakeHackin/klbf-lab/commit/d28b66b9ee62e4c65c0f0b8e66b152c4ba9dab23) · [Windows run and negative control](https://github.com/HandshakeHackin/klbf-lab/actions/runs/46180224291/job/141087876740).
Habluer commented 2026-11-29 01:09:16 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Habluer on 2026-11-29T01:09:16Z.


Tried this on a Ryzen 5 8500G (6C/12T) + RX 6750 XT, on top of v26.11.6 with PR #26, VICTORY_ABSENT_CACHE=1, Port 2 and LEAN_MATH=247, scene bm-v1.

This PR replaces PR #26's mask_runs with merge_back_piece in shadow.rs, so I had to apply it on top of PR #26 before building.

Result: 11.6–12.9 FPS, copying back 19.0–21.1 ms, vs. ~13–15 FPS / 17.7–19.7 ms on my baseline. But this run had 37–56 pipelines being made throughout (the control had 0), so I don't think it says anything about the AVX2 path. Treat it as inconclusive, not a regression.

If it's useful I can rerun it with a fully warm cache.

Full breakdown of the setup and measurements: #219

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7248596052 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/184#issuecomment-7248596052). Originally posted by [Habluer](https://github.com/Habluer) on 2026-11-29T01:09:16Z. --- Tried this on a Ryzen 5 8500G (6C/12T) + RX 6750 XT, on top of v26.11.6 with PR #26, `VICTORY_ABSENT_CACHE=1`, Port 2 and `LEAN_MATH=247`, scene `bm-v1`. This PR replaces PR #26's `mask_runs` with `merge_back_piece` in `shadow.rs`, so I had to apply it on top of PR #26 before building. Result: 11.6–12.9 FPS, `copying back` 19.0–21.1 ms, vs. ~13–15 FPS / 17.7–19.7 ms on my baseline. But this run had 37–56 pipelines being made throughout (the control had 0), so I don't think it says anything about the AVX2 path. Treat it as inconclusive, not a regression. If it's useful I can rerun it with a fully warm cache. Full breakdown of the setup and measurements: #219
PastiiJay commented 2026-11-29 08:25:17 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-29T08:25:17Z.


appreciated, and good call saying right away the run isn't clean. yes, a rerun would help: same build with and without the PR, fully warm cache, so both stay at 0 pipelines being made. the two copying back lines from steady blocks are enough

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7253093710 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/184#issuecomment-7253093710). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-29T08:25:17Z. --- appreciated, and good call saying right away the run isn't clean. yes, a rerun would help: same build with and without the PR, fully warm cache, so both stay at 0 pipelines being made. the two copying back lines from steady blocks are enough
Habluer commented 2026-11-29 17:34:28 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Habluer on 2026-11-29T17:34:28Z.


@PastiiJay here is the clean rerun: same warm cache, same profile and same save, one run per arm. Arm A is my current baseline build, arm B is the same build plus this PR (#184).

  • Cache: shaders=25717 | early=3797 | warm=8073 in both arms.
  • Executables: baseline SHA-256 1E35E7DCAEF9E81C59296626242F19810A4881495B90B213B2BA2EAABE7BD5B1; with the PR 5501551209C3906C61E00BBD581A3695801C25C7CE8A9EC3A8A78D5AE2FCA66F.
  • Pipelines being made: the first world block had some in progress (34 in A, 3 in B). Every block after it reads 0 being made: 13 blocks in A, 14 in B.
  • Input: scripted AUTO_INPUT ran in both arms with no cancellation logged. The save hash was identical before and after each run.

Two copying back lines from steady blocks (0 being made in both):

# A, baseline (14:55:08Z)
5.3 fps, 187.9 ms/frame (52.6 preparing: copies 23.4 ms 111.3 MB, textures 1.4 ms 28.3 MB; 11.6 on the GPU; 16.7 copying back 24.8 MB), 3365 draws/frame, dropped 2024 without a host pipeline (0 being made)

# B, with PR #184 (14:58:30Z)
7.7 fps, 130.0 ms/frame (65.3 preparing: copies 23.1 ms 135.9 MB, textures 5.0 ms 66.9 MB; 6.9 on the GPU; 18.8 copying back 24.8 MB), 3443 draws/frame, dropped 2573 without a host pipeline (0 being made)

Over all the steady blocks with 0 being made, copying back was:

A, baseline B, with PR #184
Blocks 13 14
Range 13.1–24.6 ms 16.1–24.6 ms
Median 16.7 ms 19.7 ms

In this run the PR did not lower copying back on my machine. The median was about 3 ms higher with it. Caveats: one run per arm, A then B, no repeat and no reversed order. The draw counts per block also differ a lot (from about 1.1k to about 5.2k per frame), so I am not reading the absolute fps between the arms. I would not call this a regression either, only a result with no gain in copying back.

Ryzen 5 8500G + RX 6750 XT, 32 GB RAM, Windows 11, BM-v1.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7259797768 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/184#issuecomment-7259797768). Originally posted by [Habluer](https://github.com/Habluer) on 2026-11-29T17:34:28Z. --- @PastiiJay here is the clean rerun: same warm cache, same profile and same save, one run per arm. Arm A is my current baseline build, arm B is the same build plus this PR (#184). - **Cache:** `shaders=25717 | early=3797 | warm=8073` in both arms. - **Executables:** baseline SHA-256 `1E35E7DCAEF9E81C59296626242F19810A4881495B90B213B2BA2EAABE7BD5B1`; with the PR `5501551209C3906C61E00BBD581A3695801C25C7CE8A9EC3A8A78D5AE2FCA66F`. - **Pipelines being made:** the first world block had some in progress (34 in A, 3 in B). Every block after it reads `0 being made`: 13 blocks in A, 14 in B. - **Input:** scripted `AUTO_INPUT` ran in both arms with no cancellation logged. The save hash was identical before and after each run. Two `copying back` lines from steady blocks (`0 being made` in both): ```text # A, baseline (14:55:08Z) 5.3 fps, 187.9 ms/frame (52.6 preparing: copies 23.4 ms 111.3 MB, textures 1.4 ms 28.3 MB; 11.6 on the GPU; 16.7 copying back 24.8 MB), 3365 draws/frame, dropped 2024 without a host pipeline (0 being made) # B, with PR #184 (14:58:30Z) 7.7 fps, 130.0 ms/frame (65.3 preparing: copies 23.1 ms 135.9 MB, textures 5.0 ms 66.9 MB; 6.9 on the GPU; 18.8 copying back 24.8 MB), 3443 draws/frame, dropped 2573 without a host pipeline (0 being made) ``` Over all the steady blocks with `0 being made`, copying back was: | | A, baseline | B, with PR #184 | |--------|--------------|-----------------| | Blocks | 13 | 14 | | Range | 13.1–24.6 ms | 16.1–24.6 ms | | Median | 16.7 ms | 19.7 ms | In this run the PR did not lower copying back on my machine. The median was about 3 ms higher with it. Caveats: one run per arm, A then B, no repeat and no reversed order. The draw counts per block also differ a lot (from about 1.1k to about 5.2k per frame), so I am not reading the absolute fps between the arms. I would not call this a regression either, only a result with no gain in copying back. Ryzen 5 8500G + RX 6750 XT, 32 GB RAM, Windows 11, BM-v1.
PastiiJay commented 2026-11-29 17:38:08 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-29T17:38:08Z.


thanks @Habluer for the clean A/B, same cache and save in both arms is exactly what makes it readable. passed on.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7259845239 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/184#issuecomment-7259845239). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-29T17:38:08Z. --- thanks @Habluer for the clean A/B, same cache and save in both arms is exactly what makes it readable. passed on.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/184:upstream-pr/184'
git switch 'upstream-pr/184'

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 'stable-amd'
git merge --no-ff 'upstream-pr/184'
git switch 'upstream-pr/184'
git rebase 'stable-amd'
git switch 'stable-amd'
git merge --ff-only 'upstream-pr/184'
git switch 'upstream-pr/184'
git rebase 'stable-amd'
git switch 'stable-amd'
git merge --no-ff 'upstream-pr/184'
git switch 'stable-amd'
git merge --squash 'upstream-pr/184'
git switch 'stable-amd'
git merge --ff-only 'upstream-pr/184'
git switch 'stable-amd'
git merge 'upstream-pr/184'
git push origin 'stable-amd'
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!184
No description provided.