draw: maintain descriptor copy spans as slots change #304

Manually merged
github merged 1 commit from github-bot/gh-304 into main 2026-12-03 17:20:05 +00:00 AGit
Owner

@⁠tommiehansen on GitHub · 2026-12-03 09:51 UTC · original
tommiehansen:perf/t05-descriptor-copy-spans → main · +168 −12 · 2 files · 1 commits · merged 2026-12-03 17:11 UTC

Problem

After updating the changed and periodically revisited descriptor slots, the heap pass folds the entire retained slot table again to compute each host copy's address span.

Implementation

Index slot intervals by host copy and recompute an extent only after one of its members changes. Preserve the existing changed-slot and periodic discovery path, stale-slot pruning, exact union bounds, copy identity, and first contributing slot order. Preserve the original full fold for A/B testing and fall back if index invariants fail. The index borrows copy identity from live retained slots and does not change resource ownership.

Source Reported result Scope
mandy d367675c Incremental heap-buffer span index Precedent for maintaining spans as slots change.
longroad 87feabed 2.9 → 0.7 ms/frame (−75.9%) Related span-indexing implementation; not this branch's timing.
Upstream #295, RDNA3 Due-slot scan 1.9 ms → 1.5 µs; whole pass 6.5 → 3.0–4.6 ms Different index over the texture queue. FPS remained within run-to-run noise.

Comparison with the existing approach

Operation Original This PR
Extent maintenance Fold retained slots again Recompute affected copy extents
Slot discovery and revisits Existing scan Preserved
Result ordering First contributing slot Preserved
Invariant failure Original fold Falls back to original fold

The retained-slot traversal and ordered output still have costs. The index adds maintenance overhead when slots churn. Longroad's measured reduction establishes a useful precedent, not a predicted xmem speedup.

Why this should be merged

Repeated full extent folding is a specific avoidable CPU cost. The opt-in index is independently reviewable and has a randomized equivalence test plus an original-fold fallback. Measure its incremental CPU cost separately from #295, which addresses a different scan, before claiming any whole-frame improvement.

Validation

An extracted portable differential test compared 8,192 randomized insertions, overwrites and removals against a full fold. Standard and diagnostics Windows-target checks passed on macOS with test targets enabled, using a check-only mimalloc override and pure Rust BLAKE3. Hardware benchmarking was unavailable.

Compare VICTORY_HEAP_SPAN_INDEX=0 and 1 on native Series X RT routes at 1080p on RX 9060 XT 16 GB and 1440p on RX 9070 XT. Record heap preparation time, memory overhead, median and P99 frame time and image parity. Index maintenance can offset the avoided scan if slots churn frequently. The setting is off by default.

**@⁠tommiehansen** on GitHub · 2026-12-03 09:51 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/304) `tommiehansen:perf/t05-descriptor-copy-spans` → `main` · +168 −12 · 2 files · 1 commits · merged 2026-12-03 17:11 UTC ## Problem After updating the changed and periodically revisited descriptor slots, the heap pass folds the entire retained slot table again to compute each host copy's address span. ## Implementation Index slot intervals by host copy and recompute an extent only after one of its members changes. Preserve the existing changed-slot and periodic discovery path, stale-slot pruning, exact union bounds, copy identity, and first contributing slot order. Preserve the original full fold for A/B testing and fall back if index invariants fail. The index borrows copy identity from live retained slots and does not change resource ownership. ## Evidence from related implementations | Source | Reported result | Scope | |---|---|---| | [mandy d367675c](https://github.com/ProjectLeonida/mandy/commit/d367675c705c758f731ae9eb603839a4ebb2283c) | Incremental heap-buffer span index | Precedent for maintaining spans as slots change. | | [longroad 87feabed](https://github.com/Lesloo/longroad/commit/87feabed8efd2c7879181cf007f2d049db961648) | 2.9 → 0.7 ms/frame (**−75.9%**) | Related span-indexing implementation; not this branch's timing. | | [Upstream #295](https://git.gtahub.st/github/lobomfz--VIctory-xmem/pulls/295), RDNA3 | Due-slot scan 1.9 ms → 1.5 µs; whole pass 6.5 → 3.0–4.6 ms | Different index over the texture queue. FPS remained within run-to-run noise. | ## Comparison with the existing approach | Operation | Original | This PR | |---|---|---| | Extent maintenance | Fold retained slots again | Recompute affected copy extents | | Slot discovery and revisits | Existing scan | Preserved | | Result ordering | First contributing slot | Preserved | | Invariant failure | Original fold | Falls back to original fold | The retained-slot traversal and ordered output still have costs. The index adds maintenance overhead when slots churn. Longroad's measured reduction establishes a useful precedent, not a predicted xmem speedup. ## Why this should be merged Repeated full extent folding is a specific avoidable CPU cost. The opt-in index is independently reviewable and has a randomized equivalence test plus an original-fold fallback. Measure its incremental CPU cost separately from #295, which addresses a different scan, before claiming any whole-frame improvement. ## Validation An extracted portable differential test compared 8,192 randomized insertions, overwrites and removals against a full fold. Standard and diagnostics Windows-target checks passed on macOS with test targets enabled, using a check-only mimalloc override and pure Rust BLAKE3. Hardware benchmarking was unavailable. Compare `VICTORY_HEAP_SPAN_INDEX=0` and `1` on native Series X RT routes at 1080p on RX 9060 XT 16 GB and 1440p on RX 9070 XT. Record heap preparation time, memory overhead, median and P99 frame time and image parity. Index maintenance can offset the avoided scan if slots churn frequently. The setting is off by default.
Index slot contributions by host copy and recompute only the extents of copies whose slots changed. Preserve the existing round-robin scan, bounds, resource ownership and first contributing slot order.

Keep the full fold available for comparison and fall back to it if indexed slot state disagrees. A randomized differential test covers insertion, overwrite, removal and shrinking bounds. Hardware timings are unverified.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 09:53:11 +00:00
github manually merged commit 18dbe8a1c8 into main 2026-12-03 17:20:05 +00:00
github-bot changed target branch from main to gh-pr/304/base 2026-12-03 17:20:07 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.