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

Merged
Damokles2 merged 1 commit from upstream-pr/1616 into main 2026-11-29 08:16:55 +00:00
Damokles2 commented 2026-11-28 22:24:54 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Damokles2 on 2026-11-28T22:24:54Z.


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

  • I searched the open PRs and the triage issue for the same change and affected file. Related NVIDIA work includes #801 and #1298. Original VIctory #1382 changes mirroring inside copy_simple. The range collection change here is independent.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5545167294 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1616). Originally posted by [Damokles2](https://github.com/Damokles2) on 2026-11-28T22:24:54Z. --- 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 - Baseline source `d4b5d51702db615bd0aec74a35b042f60ba4cf62`. [Baseline workflow](https://github.com/Damokles2/VIctory-NVIDIA/actions/runs/46194890207) - Production source `59dd62e7d7507457a5c0e6c89b1c2acfcc3420c6`. [Candidate workflow](https://github.com/Damokles2/VIctory-NVIDIA/actions/runs/46194890234) 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 - [x] I searched the open PRs and the triage issue for the same change and affected file. Related NVIDIA work includes #801 and #1298. Original VIctory #1382 changes mirroring inside `copy_simple`. The range collection change here is independent. AI-assisted with OpenAI Codex.
upipibi commented 2026-11-29 03:18:23 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by upipibi on 2026-11-29T03:18:23Z.


Test report for #1616 (head 59dd62e7), merged --no-ff onto main 568c5e5d. 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 568c5e5d
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).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7249967382 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1616#issuecomment-7249967382). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-29T03:18:23Z. --- Test report for #1616 (head 59dd62e7), merged `--no-ff` onto main 568c5e5d. 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 568c5e5d | |---|---|---| | 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 in to join this conversation.
No reviewers
No labels
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.

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