fix(gpu): a parallel compare's first cut saturates at its span's start #241

Closed
github-bot wants to merge 1 commit from github-bot/gh-241 into main AGit
Owner

@⁠mutlusinan on GitHub · 2026-11-27 20:03 UTC · original
mutlusinan:fix/shadow-scan-cut → main · +29 −2 · 1 files · 1 commits · closed without merging

Problem

The per-thread cut in the parallel compare was

(at - (start + at) % PIECE).max(from)

When the compared span does not begin on a PIECE boundary, (start + at) % PIECE can exceed at's offset into the span, so the subtraction runs below from and wraps in a release build. The first thread then scans an empty (or enormous) range: differences in the first piece are never found, and those bytes are never copied back into title memory.

Fix

fn scan_boundary(start: usize, from: usize, at: usize) -> usize {
    at.saturating_sub((start + at) % PIECE).max(from)
}

The cut now saturates at the span's start. The new unit test walks unaligned starts (0, 1, 31, PIECE-1), several from offsets and three cuts, and asserts the cuts stay strictly ordered and (except the first and last) land on piece boundaries.

Verification

  • cargo check -p victory-gpu --target x86_64-pc-windows-msvc --locked — clean.
  • The new test is a pure unit test, but victory-gpu needs Windows to build, so it was not executed here.

From kelvaroq native/patches/0009-shadow-compare.patch (GPL-3.0-or-later); the same fix as fxceless/victory-fork 81d54b0 (fork PR #1407).

**@⁠mutlusinan** on GitHub · 2026-11-27 20:03 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/241) `mutlusinan:fix/shadow-scan-cut` → `main` · +29 −2 · 1 files · 1 commits · closed without merging ### Problem The per-thread cut in the parallel compare was ```rust (at - (start + at) % PIECE).max(from) ``` When the compared span does not begin on a `PIECE` boundary, `(start + at) % PIECE` can exceed `at`'s offset into the span, so the subtraction runs below `from` and wraps in a release build. The first thread then scans an empty (or enormous) range: differences in the first piece are never found, and those bytes are never copied back into title memory. ### Fix ```rust fn scan_boundary(start: usize, from: usize, at: usize) -> usize { at.saturating_sub((start + at) % PIECE).max(from) } ``` The cut now saturates at the span's start. The new unit test walks unaligned starts (`0, 1, 31, PIECE-1`), several `from` offsets and three cuts, and asserts the cuts stay strictly ordered and (except the first and last) land on piece boundaries. ### Verification - `cargo check -p victory-gpu --target x86_64-pc-windows-msvc --locked` — clean. - The new test is a pure unit test, but `victory-gpu` needs Windows to build, so it was not executed here. From kelvaroq `native/patches/0009-shadow-compare.patch` (GPL-3.0-or-later); the same fix as fxceless/victory-fork `81d54b0` (fork PR #1407).
The per-thread cut was `at - (start + at) % PIECE`. When the span does not
begin on a piece boundary the subtraction runs below the span's start and
wraps in a release build; the first thread then scanned nothing (or a huge
range), so differences in the first piece were never found and those bytes
were never copied back into title memory.

`scan_boundary` subtracts the offset into the piece from the span and
saturates at `from`; the test walks unaligned starts and asserts the cuts
stay ordered and on piece boundaries.

From kelvaroq native/patches/0009-shadow-compare.patch (GPL-3.0-or-later);
the same fix as fxceless/victory-fork 81d54b0 (fork pull request #1407).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 20:04:18 +00:00
Author
Owner

@⁠mutlusinan on GitHub · 2026-11-27 20:21 UTC · original

Risk assessment (porting review)

  • Pure integer arithmetic; the cut saturates at the span's start instead of wrapping below it. An early cut can collapse to from, producing an empty range for one thread; scanning an empty range is a no-op and the new test asserts the cut sequence stays strictly ordered and on piece boundaries for unaligned starts.
  • No change to which bytes are compared, only where the cuts land.
  • The unit test is pure, but victory-gpu only builds on Windows, so it was not executed here.
  • Compatibility: merges cleanly and type-checks against main at e69e39c.
**@⁠mutlusinan** on GitHub · 2026-11-27 20:21 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/241#issuecomment-7227422263) ### Risk assessment (porting review) - Pure integer arithmetic; the cut saturates at the span's start instead of wrapping below it. An early cut can collapse to `from`, producing an empty range for one thread; scanning an empty range is a no-op and the new test asserts the cut sequence stays strictly ordered and on piece boundaries for unaligned starts. - No change to which bytes are compared, only where the cuts land. - The unit test is pure, but `victory-gpu` only builds on Windows, so it was not executed here. - **Compatibility:** merges cleanly and type-checks against `main` at `e69e39c`.
Author
Owner

@⁠1tsethan on GitHub · 2026-11-27 23:00 UTC · original

Independent Windows validation of PR #241.

Tested commit: 30279c13dd81686d8a8cce7d329c10098fe043bd.

cargo test --locked -p victory-gpu unaligned_parallel_scan -- --nocapture --test-threads=1

Exit: 0.

  • test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 455 filtered out; finished in 0.00s

Independent verification with OpenAI Codex assistance. Windows 11 Pro build 26200; Rust 1.98.1 MSVC; Windows SDK libraries from Microsoft.Windows.SDK.CPP.x64 10.0.28000.2957. Test harness used an RTX 3070 Ti / AMD integrated-GPU host; adapter identity was not captured for every test. These are focused checks on the stated PR commit, not gameplay, FPS, or a merged-main integration result.

**@⁠1tsethan** on GitHub · 2026-11-27 23:00 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/241#issuecomment-7229792021) Independent Windows validation of PR #241. Tested commit: `30279c13dd81686d8a8cce7d329c10098fe043bd`. `cargo test --locked -p victory-gpu unaligned_parallel_scan -- --nocapture --test-threads=1` Exit: **0**. - test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 455 filtered out; finished in 0.00s Independent verification with OpenAI Codex assistance. Windows 11 Pro build 26200; Rust 1.98.1 MSVC; Windows SDK libraries from Microsoft.Windows.SDK.CPP.x64 10.0.28000.2957. Test harness used an RTX 3070 Ti / AMD integrated-GPU host; adapter identity was not captured for every test. These are focused checks on the stated PR commit, not gameplay, FPS, or a merged-main integration result. <!-- victory-native-validation-20261128 -->
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-28 00:57 UTC · original

Independent local verification (Windows, Rust 1.100.0/MSVC, no game data):

  • PR #241 at head 30279c13dd81686d8a8cce7d329c10098fe043bd, merge base 0cef07e9d766df48f0e95f13ce3bbbe2290fe9d3.
  • cargo test --locked -p victory-gpu --lib shadow::difference_tests::unaligned_parallel_scan_covers_the_first_piece -- --exact --test-threads=1 --quiet → 1 passed, 0 failed, 455 filtered, exit 0.
  • git grep -F for the test name on the merge base returned no hits (test is new on this PR); git diff --check 0cef07e9 HEAD clean (1 file, +29/-2).
  • Used a per-worktree CARGO_TARGET_DIR with CARGO_BUILD_JOBS=2.
  • Only the named synthetic CPU test was replayed; full workspace suite and clippy were not run locally (no clippy component on this toolchain). The crate builds with pre-existing warnings.
  • GPU/driver: N/A (CPU-only shadow bookkeeping test). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

**@⁠cloph-dsp** on GitHub · 2026-11-28 00:57 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/241#issuecomment-7231318914) Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #241 at head `30279c13dd81686d8a8cce7d329c10098fe043bd`, merge base `0cef07e9d766df48f0e95f13ce3bbbe2290fe9d3`. - `cargo test --locked -p victory-gpu --lib shadow::difference_tests::unaligned_parallel_scan_covers_the_first_piece -- --exact --test-threads=1 --quiet` → 1 passed, 0 failed, 455 filtered, exit 0. - `git grep -F` for the test name on the merge base returned no hits (test is new on this PR); `git diff --check 0cef07e9 HEAD` clean (1 file, +29/-2). - Used a per-worktree `CARGO_TARGET_DIR` with `CARGO_BUILD_JOBS=2`. - Only the named synthetic CPU test was replayed; full workspace suite and clippy were not run locally (no clippy component on this toolchain). The crate builds with pre-existing warnings. - GPU/driver: N/A (CPU-only shadow bookkeeping test). No game data, assets, extracted shaders, DRM or decrypt involved. AI-assisted (Hy4 flash).
github-bot closed this pull request 2026-11-28 02:54:27 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-11-28 02:49 UTC · original

Merged into main (8fc2254) and shipped in v2026.11.27.10. The commit keeps you as its author, so it counts toward the contributors list. GitHub shows this as closed rather than merged only because the commits were applied on top of the newest main (new commit IDs). Thank you!

**@⁠trustno1-coder** on GitHub · 2026-11-28 02:49 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/241#issuecomment-7232616897) Merged into main (8fc2254) and shipped in [v2026.11.27.10](https://github.com/trustno1-coder/VIctory-NVIDIA/releases/tag/v2026.11.27.10). The commit keeps you as its author, so it counts toward the contributors list. GitHub shows this as closed rather than merged only because the commits were applied on top of the newest main (new commit IDs). Thank you!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!241
No description provided.