gpu: optimize single-record indirect argument clamp #3913

Open
Tigoniukas wants to merge 1 commit from upstream-pr/3913 into main
Tigoniukas commented 2026-11-30 20:35:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Tigoniukas on 2026-11-30T20:35:40Z.


Summary

This PR optimizes the single-record indirect argument clamp path in the D3D12 GPU backend.

When records == 1, only lane 0 needs to process the argument and update the remaining budget. The new fast path avoids unnecessary group synchronization while preserving the existing tiled implementation for multiple records.

Changes

  • Add a dedicated fast path for single-record indirect argument clamping.
  • Avoid GroupMemoryBarrierWithGroupSync operations in this case.
  • Preserve the existing multi-record path.
  • Add a regression test covering single-record budget handling.

Validation

  • cargo test --workspace --locked — passed.
  • cargo clippy --workspace --all-targets — passed.
  • git diff --check — passed.

Performance measurements

Tested on:

  • GPU: AMD Radeon RX 7600
  • CPU: AMD Ryzen 5 7500F
  • API: Direct3D 12
  • Workload: Synthetic indirect compute-dispatch benchmark, 512 calls per pass
Version Steady-state GPU time per call
Original ~9.01 µs
Optimized ~6.53 µs

Observed reduction in GPU execution time: approximately 27.6%.

The result was reproduced across repeated A/B benchmark runs.

Limitations: These measurements represent a synthetic GPU workload, not actual game performance. No in-game FPS improvement is claimed. CPU command-recording time did not show a consistent improvement.

Scope

This is a small, isolated optimization of the existing indirect argument clamp shader. Further reductions in dispatch and resource-barrier overhead are outside the scope of this PR.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5573295964 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3913). Originally posted by [Tigoniukas](https://github.com/Tigoniukas) on 2026-11-30T20:35:40Z. --- ## Summary This PR optimizes the single-record indirect argument clamp path in the D3D12 GPU backend. When `records == 1`, only lane 0 needs to process the argument and update the remaining budget. The new fast path avoids unnecessary group synchronization while preserving the existing tiled implementation for multiple records. ## Changes - Add a dedicated fast path for single-record indirect argument clamping. - Avoid `GroupMemoryBarrierWithGroupSync` operations in this case. - Preserve the existing multi-record path. - Add a regression test covering single-record budget handling. ## Validation - `cargo test --workspace --locked` — passed. - `cargo clippy --workspace --all-targets` — passed. - `git diff --check` — passed. ## Performance measurements Tested on: - GPU: AMD Radeon RX 7600 - CPU: AMD Ryzen 5 7500F - API: Direct3D 12 - Workload: Synthetic indirect compute-dispatch benchmark, 512 calls per pass | Version | Steady-state GPU time per call | |---|---:| | Original | ~9.01 µs | | Optimized | ~6.53 µs | **Observed reduction in GPU execution time: approximately 27.6%.** The result was reproduced across repeated A/B benchmark runs. **Limitations:** These measurements represent a synthetic GPU workload, not actual game performance. No in-game FPS improvement is claimed. CPU command-recording time did not show a consistent improvement. ## Scope This is a small, isolated optimization of the existing indirect argument clamp shader. Further reductions in dispatch and resource-barrier overhead are outside the scope of this PR.
passerbyyhx commented 2026-12-01 12:30:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-12-01T12:30:25Z.


Compared 661dbc6d with parent 63bcca43 on an RTX 4090 Laptop GPU and WARP. With 1, 2 and 64 records, draw, indexed draw, compute and mesh all produced the expected argument words and remaining budget on both revisions. The input buffer stayed intact. When one record exhausted the budget exactly, the next record had zero work.

On the 4090, eight fresh processes in ABBA BAAB order timed batches of 512 calls using GPU timestamps. For one record the process medians were 3.475 µs/call on the parent and 3.187 on the PR. The four paired changes were −21.4%, −22.7%, +5.9% and +20.0%, so these runs did not establish a consistent speedup. For 2 and 64 records the medians were 3.851 → 4.103 and 10.543 → 10.575 µs/call.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7311228701 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3913#issuecomment-7311228701). Originally posted by [passerbyyhx](https://github.com/passerbyyhx) on 2026-12-01T12:30:25Z. --- Compared `661dbc6d` with parent `63bcca43` on an RTX 4090 Laptop GPU and WARP. With 1, 2 and 64 records, draw, indexed draw, compute and mesh all produced the expected argument words and remaining budget on both revisions. The input buffer stayed intact. When one record exhausted the budget exactly, the next record had zero work. On the 4090, eight fresh processes in ABBA BAAB order timed batches of 512 calls using GPU timestamps. For one record the process medians were 3.475 µs/call on the parent and 3.187 on the PR. The four paired changes were −21.4%, −22.7%, +5.9% and +20.0%, so these runs did not establish a consistent speedup. For 2 and 64 records the medians were 3.851 → 4.103 and 10.543 → 10.575 µs/call.
cloph-dsp commented 2026-12-01 13:32:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-12-01T13:32:51Z.


Verification (independent, AI-assisted: Hy4 flash). Windows, Rust 1.100.0 (Scoop rust-msvc), MSVC, commit-scoped shallow worktree.

Base 63bcca43c6a00a758510398fa43096ce7e4f7df0, head 661dbc6d106aab794217997e9ad431354347ce1c. git diff --numstat → crates/victory-gpu/src/indirect.rs 34/0.

The test is new on the base — git grep -F one_record_clamps_and_spends_the_budget 63bcca43 -- . finds nothing, exit 1.

git diff --check "63bcca43..661dbc6d" → no output, exit 0.

$env:CARGO_TARGET_DIR='D:\Victory-Contrib\target-3913'
cargo test --locked -p victory-gpu --lib -- indirect::tests::one_record_clamps_and_spends_the_budget --exact --test-threads=1 --quiet

Result: running 1 test, test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 232 filtered out; finished in 0.50s.

The test works on plain indirect argument buffers, no device opened; GPU/driver N/A. No game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7312796781 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3913#issuecomment-7312796781). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-12-01T13:32:51Z. --- Verification (independent, AI-assisted: Hy4 flash). Windows, Rust 1.100.0 (Scoop rust-msvc), MSVC, commit-scoped shallow worktree. Base `63bcca43c6a00a758510398fa43096ce7e4f7df0`, head `661dbc6d106aab794217997e9ad431354347ce1c`. `git diff --numstat` → crates/victory-gpu/src/indirect.rs 34/0. The test is new on the base — `git grep -F one_record_clamps_and_spends_the_budget 63bcca43 -- .` finds nothing, exit 1. `git diff --check "63bcca43..661dbc6d"` → no output, exit 0. ``` $env:CARGO_TARGET_DIR='D:\Victory-Contrib\target-3913' cargo test --locked -p victory-gpu --lib -- indirect::tests::one_record_clamps_and_spends_the_budget --exact --test-threads=1 --quiet ``` Result: `running 1 test`, `test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 232 filtered out; finished in 0.50s`. The test works on plain indirect argument buffers, no device opened; GPU/driver N/A. No game data.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3913:upstream-pr/3913'
git switch 'upstream-pr/3913'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3913'
git switch 'upstream-pr/3913'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3913'
git switch 'upstream-pr/3913'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3913'
git switch 'main'
git merge --squash 'upstream-pr/3913'
git switch 'main'
git merge --ff-only 'upstream-pr/3913'
git switch 'main'
git merge 'upstream-pr/3913'
git push origin 'main'
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
Marvisak/VIctory!3913
No description provided.