victory-gpu: opt-in parallel texture readback landing (VICTORY_TEXBACK_PARALLEL=1) #268

Open
github-bot wants to merge 1 commit from github-bot/gh-268 into main AGit
Owner

@⁠Vladimir-Human on GitHub · 2026-11-27 13:02 UTC · original
Vladimir-Human:perf/parallel-texback-and-helper-prio → main · +403 −20 · 2 files · 1 commits · open

Summary

Narrowed to isolate strictly the texture readback ticket lifetime behind an opt-in switch VICTORY_TEXBACK_PARALLEL=1 (default off; live VICTORY_AB toggle supported in diagnostics builds).

  • All descriptor slot allocator edits (descriptor.rs, descriptor/host.rs, draw.rs) have been removed for zero overlap with #234.
  • Batched worker resource retirement (VICTORY_BATCH_RETIRE=1) has been split into standalone PR #295 for independent matched-fixture evaluation.
  • VICTORY_CARD_AWAKE=0 and card_steps edits have been dropped from this PR.

Adapted from XaviFortes/VIctory-RDNA commits e4250eb and af65a79.

Changes (2 files: crates/victory-gpu/src/texback.rs, crates/victory-gpu/src/host.rs)

  • Opt-in gating (texback.rs): parallel_enabled() defaults to false and enables parallel readback landing only when VICTORY_TEXBACK_PARALLEL=1 (or VICTORY_AB selects it in diagnostics). When off, land_many executes sequentially in exact submission order.
  • Locking & ticket re-validation (texback.rs): Narrows the TICKETS mutex in texback::land to the final valid re-check and copy_mapped write while preserving the existing MAPPING -> TICKETS lock order (title_memory_reading() held outside TICKETS). Worker threads reuse thread-local Scratch / tiling buffers via land_local.
  • Overlap & dedup planning (texback.rs): plan_land_many skips an earlier readback only when a later still-valid ticket matches the exact (owner, at, end) (so both share identical released/replaced/remapped invalidation predicates and texture subresources). Any overlapping remaining destination ranges fall back to strict sequential submission order.
  • Borrowed flight readbacks (host.rs): read_backs_flight borrows each flight's Deferred::texture_backs in place so ReadbackPool leases stay exclusive until list.reset().

Tests & Verification

Verified with VICTORY_D3D12_DEBUG=1 and --test-threads=1 (0 D3D12 debug errors):

  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default & --features diagnostics): 0 warnings
  • xtask policy --staged (2 files ok) & cargo test -p xtask: 11/11 passed
  • Added 4 unit + real D3D12 HW/WARP tests in texback::tests:
    • parallel_switch_defaults_off_and_accepts_only_one
    • plan_land_many_handles_disjoint_dedup_overlap_and_stale_tickets
    • land_many_preserves_overlap_order_and_disjoint_parallel_on_gpu (tests disjoint parallel landing, same-owner dedup, and both forward [0..256)->[128..384) and reverse [128..384)->[0..256) overlap ordering in both sequential and parallel modes)
    • land_many_blocks_stale_cancelled_superseded_and_remapped_tickets_on_gpu (tests released, replaced, partial remapped, out-of-range remapped, and cancelled later duplicate not suppressing an earlier valid ticket)
  • HW RTX 4070 SUPER: default texback::tests 5/5; --features diagnostics (off & VICTORY_TEXBACK_PARALLEL=1) texback::tests 5/5, host::late_tests 3/3, readback_pool 5/5
  • WARP (VICTORY_D3D12_WARP=1, --features diagnostics, VICTORY_TEXBACK_PARALLEL=1): texback::tests 5/5, host::late_tests 3/3, readback_pool 5/5
**@⁠Vladimir-Human** on GitHub · 2026-11-27 13:02 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/268) `Vladimir-Human:perf/parallel-texback-and-helper-prio` → `main` · +403 −20 · 2 files · 1 commits · open ## Summary Narrowed to isolate strictly the **texture readback ticket lifetime** behind an opt-in switch `VICTORY_TEXBACK_PARALLEL=1` (default **off**; live `VICTORY_AB` toggle supported in `diagnostics` builds). - All descriptor slot allocator edits (`descriptor.rs`, `descriptor/host.rs`, `draw.rs`) have been removed for zero overlap with #234. - Batched worker resource retirement (`VICTORY_BATCH_RETIRE=1`) has been split into standalone PR #295 for independent matched-fixture evaluation. - `VICTORY_CARD_AWAKE=0` and `card_steps` edits have been dropped from this PR. Adapted from `XaviFortes/VIctory-RDNA` commits `e4250eb` and `af65a79`. ## Changes (`2 files: crates/victory-gpu/src/texback.rs`, `crates/victory-gpu/src/host.rs`) - **Opt-in gating (`texback.rs`):** `parallel_enabled()` defaults to `false` and enables parallel readback landing only when `VICTORY_TEXBACK_PARALLEL=1` (or `VICTORY_AB` selects it in `diagnostics`). When off, `land_many` executes sequentially in exact submission order. - **Locking & ticket re-validation (`texback.rs`):** Narrows the `TICKETS` mutex in `texback::land` to the final `valid` re-check and `copy_mapped` write while preserving the existing `MAPPING -> TICKETS` lock order (`title_memory_reading()` held outside `TICKETS`). Worker threads reuse thread-local `Scratch` / tiling buffers via `land_local`. - **Overlap & dedup planning (`texback.rs`):** `plan_land_many` skips an earlier readback only when a later still-valid ticket matches the exact `(owner, at, end)` (so both share identical `released`/`replaced`/`remapped` invalidation predicates and texture subresources). Any overlapping remaining destination ranges fall back to strict sequential submission order. - **Borrowed flight readbacks (`host.rs`):** `read_backs_flight` borrows each flight's `Deferred::texture_backs` in place so `ReadbackPool` leases stay exclusive until `list.reset()`. ## Tests & Verification Verified with `VICTORY_D3D12_DEBUG=1` and `--test-threads=1` (0 D3D12 debug errors): - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default & `--features diagnostics`): **0 warnings** - `xtask policy --staged` (`2 files ok`) & `cargo test -p xtask`: **11/11 passed** - Added 4 unit + real D3D12 HW/WARP tests in `texback::tests`: - `parallel_switch_defaults_off_and_accepts_only_one` - `plan_land_many_handles_disjoint_dedup_overlap_and_stale_tickets` - `land_many_preserves_overlap_order_and_disjoint_parallel_on_gpu` (tests disjoint parallel landing, same-owner dedup, and both forward `[0..256)->[128..384)` and reverse `[128..384)->[0..256)` overlap ordering in both sequential and parallel modes) - `land_many_blocks_stale_cancelled_superseded_and_remapped_tickets_on_gpu` (tests `released`, `replaced`, partial `remapped`, out-of-range `remapped`, and cancelled later duplicate not suppressing an earlier valid ticket) - HW RTX 4070 SUPER: default `texback::tests` **5/5**; `--features diagnostics` (off & `VICTORY_TEXBACK_PARALLEL=1`) `texback::tests` **5/5**, `host::late_tests` **3/3**, `readback_pool` **5/5** - WARP (`VICTORY_D3D12_WARP=1`, `--features diagnostics`, `VICTORY_TEXBACK_PARALLEL=1`): `texback::tests` **5/5**, `host::late_tests` **3/3**, `readback_pool` **5/5**
Combine four low-risk CPU-side D3D12 runtime optimizations (skipping
`VICTORY_HELPER_PRIORITY`, which is already on `main` at `5c803d2`):

1. Parallel `texback::land_many` & borrowed flight readbacks (`texback.rs`, `host.rs`):
   Narrow `TICKETS` lock to the final validity check and copy into title
   memory, skip superseded exact-range duplicates (without letting an
   invalidated later ticket suppress an earlier valid write), borrow
   `texture_backs` across a flight without dropping `TextureReadback`
   leases prematurely, and tile pairwise-disjoint readbacks concurrently
   across `land::each_view` using per-thread `Scratch` buffers/caches.
   Upstream credit: `XaviFortes/VIctory-RDNA` (`e4250eb`, `af65a79`).

2. Batched retired-resource handoff (`host.rs`, `list/thin.rs`):
   Accumulate up to 256 retired `ID3D12Resource`s per list-translation
   worker thread before extending `RETIRED`, flushing at recording end and
   on thread exit via `Drop` (preserving retirement ordering and idempotent
   `retire_in_batches` initialization).
   Upstream credit: `voidopcode/vilocity` (`4315c77`).

3. Packed `DynamicBits` allocator & batched `release_dynamic_many`
   (`descriptor/host.rs`, `descriptor.rs`, `draw.rs`):
   Replace `Vec<bool>` with a 64-bit word bitset skipping 64 occupied
   slots per word, and release dynamic slot ranges in contiguous
   `(heap, id)` batches under one `SHADER_HEAPS` read lock and one heap
   lock while preserving per-heap identity (`id`) isolation.
   Upstream credit: `XaviFortes/VIctory-RDNA` (`13e1f5e`).

4. In-place `card_steps` & NVIDIA `VICTORY_CARD_AWAKE=0`
   (`host/card_steps.rs`, `host.rs`, `host/awake.rs`, `scripts/play.ps1`):
   Allow GPU-side `card_steps` copies/fills on in-place buffers while
   tracking `Taken::copied_ranges` in `Line::written` across `send_late`,
   `execute_own`, and `relay_land` rebuilds via shared helpers so in-flight
   copies to in-place targets remain hazard-tracked; keep
   `VICTORY_CARD_AWAKE=0` explicitly on NVIDIA adapters (and in
   `awake::resolve_mode` `auto` mode).
   Upstream credit: `XaviFortes/VIctory-RDNA` (`5e6fec2`) and
   `voidopcode/vilocity` (`e99bf2f`).

Verified (`VICTORY_D3D12_DEBUG=1`, `--features diagnostics`, `--test-threads=1`):
- `clippy -p victory-gpu --all-targets -- -D warnings` (default & `diagnostics`): 0 warnings
- HW D3D12 suite (texback, retire batch, readback pool, late, card_steps, awake, dynamic/DynamicBits, list::thin): 36/36 passed
- WARP D3D12 suite (same filters, `VICTORY_D3D12_WARP=1`): 36/36 passed
- E2E `card_steps` HW test (`VICTORY_RELAY=2 VICTORY_CARD_STEPS=2`): 1/1 passed
- `xtask policy --staged` (9 files ok) & `cargo test -p xtask` (11/11)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 13:14:39 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 13:09 UTC · original

@⁠Vladimir-Human The readback ticket, resource retirement and descriptor slot allocator are separate lifetimes. I’d compare each change independently with the same fixture. The readback path needs the overlap-order and stale-ticket checks, and the slot changes should be coordinated with #234 so the two reclamation paths don’t overlap.

**@⁠TaynanGT** on GitHub · 2026-11-27 13:09 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/268#issuecomment-7219125079) @⁠Vladimir-Human The readback ticket, resource retirement and descriptor slot allocator are separate lifetimes. I’d compare each change independently with the same fixture. The readback path needs the overlap-order and stale-ticket checks, and the slot changes should be coordinated with #234 so the two reclamation paths don’t overlap.
github-bot changed title from perf(gpu): parallelize texback, batch resource retirement and dynamic slot bitset to victory-gpu: opt-in parallel texture readback landing (VICTORY_TEXBACK_PARALLEL=1) 2026-11-27 14:19:25 +00:00
github-bot force-pushed github-bot/gh-268 from 25bfb037ca to be13f4bfe8 2026-11-27 14:19:26 +00:00 Compare
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-27 14:05 UTC · original

@⁠TaynanGT Thanks for the clear review — #268 has been narrowed to a single lifetime and split cleanly:

  1. Readback ticket lifetime only (VICTORY_TEXBACK_PARALLEL=1, default off): #268 now touches only crates/victory-gpu/src/texback.rs and crates/victory-gpu/src/host.rs, keeping sequential readback landing unchanged by default (VICTORY_AB supported in diagnostics).
  2. Zero overlap with #234: All descriptor slot allocator edits (descriptor.rs, descriptor/host.rs, draw.rs) were removed.
  3. Explicit overlap-order and stale-ticket tests: Added unit and D3D12 HW/WARP tests in crates/victory-gpu/src/texback.rs covering forward/reverse destination overlap order (land_many_preserves_overlap_order_and_disjoint_parallel_on_gpu), disjoint parallel landing, exact (owner, at, end, valid) dedup, and released/replaced/partial remapped/cancelled-duplicate stale-ticket blocking (land_many_blocks_stale_cancelled_superseded_and_remapped_tickets_on_gpu), alongside host::late_tests and readback_pool exclusivity tests (0 D3D12 debug errors on HW and WARP).
  4. Separate retirement PR: Batched worker retire_resource handoff was split into standalone opt-in PR #295 (VICTORY_BATCH_RETIRE=1, default off, with COM refcount lifetime tests until bury()) for independent matched-fixture comparison; VICTORY_CARD_AWAKE=0 and card_steps edits were dropped.
**@⁠Vladimir-Human** on GitHub · 2026-11-27 14:05 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/268#issuecomment-7220333615) @⁠TaynanGT Thanks for the clear review — #268 has been narrowed to a single lifetime and split cleanly: 1. **Readback ticket lifetime only (`VICTORY_TEXBACK_PARALLEL=1`, default off):** #268 now touches only `crates/victory-gpu/src/texback.rs` and `crates/victory-gpu/src/host.rs`, keeping sequential readback landing unchanged by default (`VICTORY_AB` supported in `diagnostics`). 2. **Zero overlap with #234:** All descriptor slot allocator edits (`descriptor.rs`, `descriptor/host.rs`, `draw.rs`) were removed. 3. **Explicit overlap-order and stale-ticket tests:** Added unit and D3D12 HW/WARP tests in `crates/victory-gpu/src/texback.rs` covering forward/reverse destination overlap order (`land_many_preserves_overlap_order_and_disjoint_parallel_on_gpu`), disjoint parallel landing, exact `(owner, at, end, valid)` dedup, and `released`/`replaced`/partial `remapped`/cancelled-duplicate stale-ticket blocking (`land_many_blocks_stale_cancelled_superseded_and_remapped_tickets_on_gpu`), alongside `host::late_tests` and `readback_pool` exclusivity tests (0 D3D12 debug errors on HW and WARP). 4. **Separate retirement PR:** Batched worker `retire_resource` handoff was split into standalone opt-in PR #295 (`VICTORY_BATCH_RETIRE=1`, default off, with COM refcount lifetime tests until `bury()`) for independent matched-fixture comparison; `VICTORY_CARD_AWAKE=0` and `card_steps` edits were dropped.
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 14:25 UTC · original

@⁠Vladimir-Human The split gives us a clean readback test. The overlap-order and remapped-ticket regressions cover the paths I flagged. I’ll compare VICTORY_TEXBACK_PARALLEL on its own. The stamp-ordering case on #295 can stay with retirement.

**@⁠TaynanGT** on GitHub · 2026-11-27 14:25 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/268#issuecomment-7220759235) @⁠Vladimir-Human The split gives us a clean readback test. The overlap-order and remapped-ticket regressions cover the paths I flagged. I’ll compare `VICTORY_TEXBACK_PARALLEL` on its own. The stamp-ordering case on #295 can stay with retirement.
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/268/head:github-bot/gh-268'
git switch 'github-bot/gh-268'

Merge

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