perf(gpu): O(1) lock-free shadow::card_patches() via PATCHED_CARDS #11

Closed
github-bot wants to merge 1 commit from gh-pr/11/head into gh-pr/11/base
Owner

@⁠justadudeinbulgaria on GitHub · 2026-11-29 21:13 UTC · original
justadudeinbulgaria:pr/o1-card-patches → main · +133 −9 · 1 files · 1 commits · closed without merging

Problem

shadow::card_patches(sent_as) locked CARDED and linearly iterated every card-backed shadow copy (~3,700+ buffers) on every submission, taking both c.dirty and c.patch mutexes on each copy even when zero or only a handful of buffers received masked patches.

Solution

Mirrors the existing TOUCHED fast-path design in crates/victory-gpu/src/shadow.rs:

  • Adds Card::patched: AtomicBool, a leaf-lock PATCHED_CARDS list, a lock-free PATCHED_PENDING: AtomicUsize counter, and a PATCHED_ALL fallback for pre-join unit tests.
  • Submissions with no pending patches return immediately in O(1) without locking any mutex; non-empty submissions drain only actually-patched copies and sort deterministically by shadow.start.

Verification

  • cargo xtask policy --staged: passed (1 files ok).
  • Added and ran shadow::touched_tests::the_list_of_patched_copies_gives_what_the_look_at_every_copy_gives (--ignored --exact) verifying exact parity between the PATCHED_CARDS path and a full CARDED scan.
  • Live-verified in gameplay on RTX 2060 SUPER 8 GB + i5-10600K with zero visual regressions.
**@⁠justadudeinbulgaria** on GitHub · 2026-11-29 21:13 UTC · [original](https://github.com/ToLIManl/VIctory-Hydra/pull/11) `justadudeinbulgaria:pr/o1-card-patches` → `main` · +133 −9 · 1 files · 1 commits · closed without merging ## Problem shadow::card_patches(sent_as) locked CARDED and linearly iterated every card-backed shadow copy (~3,700+ buffers) on every submission, taking both c.dirty and c.patch mutexes on each copy even when zero or only a handful of buffers received masked patches. ## Solution Mirrors the existing TOUCHED fast-path design in crates/victory-gpu/src/shadow.rs: - Adds Card::patched: AtomicBool, a leaf-lock PATCHED_CARDS list, a lock-free PATCHED_PENDING: AtomicUsize counter, and a PATCHED_ALL fallback for pre-join unit tests. - Submissions with no pending patches return immediately in O(1) without locking any mutex; non-empty submissions drain only actually-patched copies and sort deterministically by shadow.start. ## Verification - cargo xtask policy --staged: passed (1 files ok). - Added and ran shadow::touched_tests::the_list_of_patched_copies_gives_what_the_look_at_every_copy_gives (--ignored --exact) verifying exact parity between the PATCHED_CARDS path and a full CARDED scan. - Live-verified in gameplay on RTX 2060 SUPER 8 GB + i5-10600K with zero visual regressions.
Track card-backed shadow copies that received masked patches via Card::patched (AtomicBool), a leaf-lock PATCHED_CARDS list, and a lock-free PATCHED_PENDING counter, matching the existing TOUCHED design.

Previously card_patches() locked CARDED and linearly scanned every card-backed shadow copy (~3,700+ buffers) on every submission, acquiring dirty and patch locks on each buffer even when none or only a handful were patched. With PATCHED_CARDS, empty submissions return immediately in O(1) without taking any mutex, and non-empty submissions only visit actually-patched copies (sorted deterministically by shadow.start).

Includes a unit test verifying exact parity between the PATCHED_CARDS fast path and a full CARDED scan.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 17:08:37 +00:00
github-bot closed this pull request 2026-12-02 17:08:38 +00:00
Author
Owner

@⁠ToLIManl on GitHub · 2026-11-30 23:55 UTC · original

Ported cleanly onto \main\ in commit \869198.

Because the PR branch predated the clean-room history rewrite (\ b745f28), the isolated \PATCHED_CARDS\ / lock-free \shadow::card_patches()\ optimization was ported cleanly with \Co-authored-by\ attribution and verified with \ ictory-gpu\ release tests (\shadow::\ \39 passed, plus exact ignored equivalence test \1 passed) and a live RTX 3060 benchmark.

**@⁠ToLIManl** on GitHub · 2026-11-30 23:55 UTC · [original](https://github.com/ToLIManl/VIctory-Hydra/pull/11#issuecomment-7295691946) Ported cleanly onto \main\ in commit \869198\. Because the PR branch predated the clean-room history rewrite (\ b745f28\), the isolated \PATCHED_CARDS\ / lock-free \shadow::card_patches()\ optimization was ported cleanly with \Co-authored-by\ attribution and verified with \ ictory-gpu\ release tests (\shadow::\ \39 passed\, plus exact ignored equivalence test \1 passed\) and a live RTX 3060 benchmark.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.