Skip to content

perf(gpu): avoid temporary allocations in single-range descriptor copies - #1616

Open
Damokles2 wants to merge 1 commit into
trustno1-coder:mainfrom
Damokles2:perf-descriptor-copy-single-range
Open

Damokles2 wants to merge 1 commit into
trustno1-coder:mainfrom
Damokles2:perf-descriptor-copy-single-range

Conversation

@Damokles2

Copy link
Copy Markdown
Contributor

Closes #1572.

What it changes

CopyDescriptors builds two temporary range vectors even when both sides have exactly one range. The source-first fast path keeps the existing kind and null-start checks, snapshots source metadata before destination metadata, and calls the unchanged copy_simple with the smaller count when it is nonzero. Null optional size arrays still mean one descriptor per range. The general multi-range loop, overlap-aware copying, and write-before-mirror ordering are preserved.

How it was tested

Hosted Windows with Rust 1.98.1 on the MSVC target. The D3D12 smoke used the WARP software adapter and synthetic sampler descriptors. The test suite used no game assets.

  • All 12,233 differential cases matched complete buffers, untouched entries, metadata-alias behavior, and ordered copy and mirror calls.
  • Locked workspace compilation passed on both revisions. All 98 asset-independent CPU tests passed on each, with 3 ignored and 13 filtered.
  • Both committed Windows regression tests passed: single_range_dispatch_preserves_complete_descriptor_bytes and general_path_snapshots_metadata_before_overwriting_it. They cover all four heap kinds, overlapping buffers, null optional sizes, unequal and zero counts, and metadata snapshot ordering.
  • The WARP test passed. It verified real sampler heap lookup and mirroring, including a three-slot copy, an untouched neighbor, and clearing one slot.
  • All 18 eligible synthetic workloads eliminated two allocator calls and 32 cumulative requested bytes. General-path allocation counts and requested bytes were unchanged.

Synthetic performance and trade-off

Representative hosted production medians from the candidate runner:

Workload Original Production
Default single-range preparation 83.493 ns 5.254 ns
Default single-range full copy 87.260 ns 7.100 ns
256-descriptor full copy 121.063 ns 43.280 ns

The latest hosted production comparison also measured these general-path slowdowns. The values are paired median deltas across two passes of 41 alternating pairs.

Full-copy control Measured overhead
1 source × 4 destination ranges +2.032 to +2.214 ns
4 source × 1 destination range +3.273 to +3.633 ns
2 × 2 ranges +3.938 to +4.462 ns
4 × 4 ranges +3.453 to +4.530 ns
Zero ranges on both sides +0.308 ns in both passes

These costs exceeded the same-runner original-versus-original noise for the corresponding controls. The earlier hosted refinement and local production measurements showed smaller overhead. The magnitude varies across builds and environments, and these measurements leave its cause unisolated. The real workload distribution and complete live heap and mirroring latency remain unknown. The evidence supports a synthetic single-range benefit and a measured general-path cost for review.

Hosted validation

Both workflows finished red on identical pre-existing failures in strict affected-crate and workspace Clippy, workspace formatting (4,338 hunks), and the asset-policy size limit for the unchanged crates/victory-shader/src/emit/lower.rs. Compilation, CPU tests, focused Windows tests, WARP, differential checks, and benchmark steps succeeded individually.

Checked for overlap

AI-assisted with OpenAI Codex.

@github-actions github-actions Bot added pr-performance Pull request: makes it faster or use less memory rendering Missing, black, flickering or corrupted graphics labels Nov 28, 2026
@github-actions github-actions Bot changed the title [pr-performance][rendering] perf(gpu): avoid temporary allocations in single-range descriptor copies perf(gpu): avoid temporary allocations in single-range descriptor copies Nov 28, 2026
@upipibi

upipibi commented Nov 29, 2026

Copy link
Copy Markdown

Test report for #1616 (head 59dd62e), merged --no-ff onto main 568c5e5. This PR is based on an older main;
the merge was clean. Synthetic tests only: no title run, no game files.

Setup: RTX 3070, driver 616.56, Windows 11 (10.0.26100), rustc 1.98.1. Every run logged the GPU and driver from
nvidia-smi before it started.

Both new tests pass, 3/3 runs:

  • descriptor::tests::single_range_dispatch_preserves_complete_descriptor_bytes;
  • descriptor::tests::general_path_snapshots_metadata_before_overwriting_it.

Both are CPU-only. They call copy on plain arrays with a null device, so no D3D12 device is used. I also ran them
three times with VICTORY_D3D12_WARP=1 --features diagnostics; they pass the same. The WARP sampler-heap test the
description mentions is not in the diff, so it is not covered here.

Negative controls

  • A, main's copy with only the two tests added: both pass. That fits a speed-up that keeps the behaviour the
    same: the tests guard what main already does.
  • B, the new single-range fast path copying the source count without limiting it to the destination's
    (left instead of left.min(room)): single_range_dispatch_preserves_complete_descriptor_bytes fails, at
    the case kind 0, source size 3, destination size null (one descriptor), destination 1. Two descriptors past the
    destination's one are overwritten. general_path_snapshots_metadata_before_overwriting_it still passes; it uses
    two ranges, so it never reaches the fast path. So the single-range test does catch a fast path that ignores the
    destination's size.

cargo test -p victory-gpu --lib --locked

Run PR Main 568c5e5
default 591 passed, 0 failed, 44 ignored 589 passed, 0 failed, 44 ignored
--features diagnostics 645 passed, 0 failed, 44 ignored 643 passed, 0 failed, 44 ignored

The two extra tests are the PR's own. I did not measure the timings in the description.

Not tested: the effect in a title.

Tested with the help of Claude Code (Claude Opus 5.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request: makes it faster or use less memory rendering Missing, black, flickering or corrupted graphics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid temporary range allocations in single-range descriptor copies

2 participants