GPU: viewports, scissors and barriers set without an allocation per call #3297

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

@⁠KainanP on GitHub · 2026-11-26 16:21 UTC · original
KainanP:perf/list-setters-no-alloc → main · +171 −7 · 2 files · 1 commits · open

Removes the per-call allocations in three list setters that #2586's per-call table (comment 7195391455) pointed at.

Change

Only crates/victory-gpu changes.

  • draw.rs: RSSetViewports and RSSetScissorRects keep what they set for the list's next segment (Fixed, replayed by State::cut). They used to keep it in a new Vec per call (to_vec()). Now they refill the Vec the list already has (keep), so only a list's first call allocates. The host call gets the title's slice as before.
  • list.rs: ResourceBarrier built its host barriers in a new Vec per call. Up to seven title barriers, plus the buffer UAV barrier that may follow them, now go into a stack array. More than seven go into a Vec as before.

The host calls, their arguments and their order are the same as before.

Measured

The list bench from KainanP/VIctory@perf/list-call-bench (pipeline::list_bench, #[ignore], cargo test -p victory-gpu --release list_bench -- --ignored --nocapture). Each row is the best of 5 × 20,000 calls. Both builds ran 7 times interleaved, and the table gives the median. RTX 4060 Laptop GPU, Core i7-14650HX, Windows 11, release. Four unrelated Python jobs were using the CPU throughout, which is why the builds were interleaved.

ns a call main 63bcca4 this PR
RSSetViewports, 1 (0xa8) 50 [47–55] 23 [22–25]
RSSetScissorRects, 1 (0xb0) 56 [54–58] 28 [27–30]
ResourceBarrier, 1 texture transition (0xd0) 312 [299–401] 262 [253–284]
ResourceBarrier, 1 buffer UAV (0xd0) 191 [184–263] 145 [137–154]

A second set of 7 runs in the opposite order gave 48→22, 54→28, 304→264 and 189→143. The draw, dispatch and indirect rows don't go through this code. Across the two sets they moved by 1–3% in both directions, within the run-to-run spread.

Not measured: a game frame. The gain is about 25–50 ns per call. How much that adds up to per frame depends on how many viewport, scissor and barrier calls a frame makes, and I don't have that count from a game run.

Tests

New tests (synthetic, no game data):

  • list::tests::barriers_beyond_the_stack_room_all_reach_the_list: 3, 7, 8 and 21 barriers per call, texture transitions mixed with buffer UAV barriers, sent through the title's method. After each call, every texture's tracked state is the last one asked for. Then the list runs. With the loop cut to the first seven barriers, the test fails at 8.
  • draw::tests::kept_viewports_and_scissors_are_the_last_set: the kept viewports and scissors are the last ones set, whatever the earlier counts were, and State::cut replays them.

cargo test -p victory-gpu --release --lib, with the same failures as on main 63bcca4:

  • RTX 4060: 231 passed, 2 failed. The failures are the known NVIDIA heap pair, dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views. memory_tests::heap_direct_texture_reads_mark_their_heap_index was skipped because it access-violates on main here.
  • Intel UHD (a78b), selected with a local adapter hook that isn't in this PR: 230 passed, 3 failed. Those are the same pair plus a_texture_written_in_one_format_reads_in_another_through_a_placed_view, which also fails on main.
  • WARP (--features diagnostics, VICTORY_D3D12_WARP=1, --test-threads=1): 248 passed, 0 failed.

Also passing: cargo clippy -p victory-gpu --all-targets -- -D warnings, with and without --all-features, and cargo xtask policy.

Unrelated to this PR: shadow::tests::partial_refresh_under_marked_range_updates_saved_bytes sometimes fails in the parallel run on main 63bcca4 too (2 of 30 runs on RTX).

Overlaps

  • #3176 (viewport/scissor count clamp and inverted rects) edits the same two setters. After both, the clamped slice should go through keep(&mut self.fixed.viewports, viewports). #3176's scissor Vec holds the normalized rects. That Vec could be the one kept, or its rects could be written into the kept Vec with keep.
  • #3129 (coalesce duplicate transitions) rewrites the same part of barrier around a Vec it edits in place (push_host_barrier / emit_barriers). If #3129 is merged first, the barrier half of this PR should be dropped in favour of #3129's version. The viewport and scissor half doesn't touch #3129's code.
  • No textual conflicts with #2472, #3197, #3258, #3274, #3275 or #2848.

AI use: Claude Code (Claude Opus 5.5) wrote the change and the tests, ran the measurements and drafted this description.

🤖 Generated with Claude Code

**@⁠KainanP** on GitHub · 2026-11-26 16:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/3297) `KainanP:perf/list-setters-no-alloc` → `main` · +171 −7 · 2 files · 1 commits · open Removes the per-call allocations in three list setters that #2586's per-call table (comment 7195391455) pointed at. ## Change Only `crates/victory-gpu` changes. - `draw.rs`: `RSSetViewports` and `RSSetScissorRects` keep what they set for the list's next segment (`Fixed`, replayed by `State::cut`). They used to keep it in a new `Vec` per call (`to_vec()`). Now they refill the `Vec` the list already has (`keep`), so only a list's first call allocates. The host call gets the title's slice as before. - `list.rs`: `ResourceBarrier` built its host barriers in a new `Vec` per call. Up to seven title barriers, plus the buffer UAV barrier that may follow them, now go into a stack array. More than seven go into a `Vec` as before. The host calls, their arguments and their order are the same as before. ## Measured The list bench from [KainanP/VIctory@perf/list-call-bench](https://github.com/KainanP/VIctory/tree/perf/list-call-bench) (`pipeline::list_bench`, `#[ignore]`, `cargo test -p victory-gpu --release list_bench -- --ignored --nocapture`). Each row is the best of 5 × 20,000 calls. Both builds ran 7 times interleaved, and the table gives the median. RTX 4060 Laptop GPU, Core i7-14650HX, Windows 11, release. Four unrelated Python jobs were using the CPU throughout, which is why the builds were interleaved. | ns a call | main 63bcca4 | this PR | |---|---:|---:| | `RSSetViewports`, 1 (0xa8) | 50 [47–55] | **23** [22–25] | | `RSSetScissorRects`, 1 (0xb0) | 56 [54–58] | **28** [27–30] | | `ResourceBarrier`, 1 texture transition (0xd0) | 312 [299–401] | **262** [253–284] | | `ResourceBarrier`, 1 buffer UAV (0xd0) | 191 [184–263] | **145** [137–154] | A second set of 7 runs in the opposite order gave 48→22, 54→28, 304→264 and 189→143. The draw, dispatch and indirect rows don't go through this code. Across the two sets they moved by 1–3% in both directions, within the run-to-run spread. **Not measured:** a game frame. The gain is about 25–50 ns per call. How much that adds up to per frame depends on how many viewport, scissor and barrier calls a frame makes, and I don't have that count from a game run. ## Tests New tests (synthetic, no game data): - `list::tests::barriers_beyond_the_stack_room_all_reach_the_list`: 3, 7, 8 and 21 barriers per call, texture transitions mixed with buffer UAV barriers, sent through the title's method. After each call, every texture's tracked state is the last one asked for. Then the list runs. With the loop cut to the first seven barriers, the test fails at 8. - `draw::tests::kept_viewports_and_scissors_are_the_last_set`: the kept viewports and scissors are the last ones set, whatever the earlier counts were, and `State::cut` replays them. `cargo test -p victory-gpu --release --lib`, with the same failures as on main 63bcca4: - RTX 4060: 231 passed, 2 failed. The failures are the known NVIDIA heap pair, `dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`. `memory_tests::heap_direct_texture_reads_mark_their_heap_index` was skipped because it access-violates on main here. - Intel UHD (a78b), selected with a local adapter hook that isn't in this PR: 230 passed, 3 failed. Those are the same pair plus `a_texture_written_in_one_format_reads_in_another_through_a_placed_view`, which also fails on main. - WARP (`--features diagnostics`, `VICTORY_D3D12_WARP=1`, `--test-threads=1`): 248 passed, 0 failed. Also passing: `cargo clippy -p victory-gpu --all-targets -- -D warnings`, with and without `--all-features`, and `cargo xtask policy`. Unrelated to this PR: `shadow::tests::partial_refresh_under_marked_range_updates_saved_bytes` sometimes fails in the parallel run on main 63bcca4 too (2 of 30 runs on RTX). ## Overlaps - #3176 (viewport/scissor count clamp and inverted rects) edits the same two setters. After both, the clamped slice should go through `keep(&mut self.fixed.viewports, viewports)`. #3176's scissor `Vec` holds the normalized rects. That `Vec` could be the one kept, or its rects could be written into the kept `Vec` with `keep`. - #3129 (coalesce duplicate transitions) rewrites the same part of `barrier` around a `Vec` it edits in place (`push_host_barrier` / `emit_barriers`). If #3129 is merged first, the barrier half of this PR should be dropped in favour of #3129's version. The viewport and scissor half doesn't touch #3129's code. - No textual conflicts with #2472, #3197, #3258, #3274, #3275 or #2848. _AI use: Claude Code (Claude Opus 5.5) wrote the change and the tests, ran the measurements and drafted this description._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
RSSetViewports and RSSetScissorRects kept what they set (for the list's
next segment) in a new Vec per call; they now refill the one the list
already has. ResourceBarrier built its host barriers in a Vec per call;
up to seven title barriers (and the buffer UAV barrier added after them)
now go through a stack array, more than that through a Vec as before.
Same host calls, same arguments, same order.

Measured with the list bench (perf/list-call-bench, RTX 4060 Laptop,
median of 7 interleaved runs, ns a call): RSSetViewports 50 -> 23,
RSSetScissorRects 56 -> 28, ResourceBarrier one texture transition
312 -> 262, one buffer UAV 191 -> 145.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 16:22:02 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 16:51 UTC · original · approved these changes

Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):

  • Reusing Fixed::{viewports, scissors} backing vectors via keep() and using an inline 8-slot stack buffer (spilling to Vec for >= 8 barriers, preserving room for the trailing UAV_BARRIER) cleanly removes per-call heap allocations on hot command-list recording paths.
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1 (RTX 5090): 21 passed, 0 failed (including kept_viewports_and_scissors_are_the_last_set).
  • cargo test -p victory-gpu --lib list:: -- --test-threads=1 (RTX 5090): 5 passed, 0 failed (including barriers_beyond_the_stack_room_all_reach_the_list).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 16:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/3297#pullrequestreview-6077857571) · **approved these changes** Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090): - Reusing `Fixed::{viewports, scissors}` backing vectors via `keep()` and using an inline 8-slot stack buffer (spilling to `Vec` for `>= 8` barriers, preserving room for the trailing `UAV_BARRIER`) cleanly removes per-call heap allocations on hot command-list recording paths. - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1` (RTX 5090): 21 passed, 0 failed (including `kept_viewports_and_scissors_are_the_last_set`). - `cargo test -p victory-gpu --lib list:: -- --test-threads=1` (RTX 5090): 5 passed, 0 failed (including `barriers_beyond_the_stack_room_all_reach_the_list`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 18:24 UTC · original

WARP verification of #3297 (synthetic tests only, no game files, no physical GPU).

Commits

  • Head: 834a4e1f73f93d1e9b5d1ed56bd818b61b3e37c5
  • Base / main control: 63bcca43c6a00a758510398fa43096ce7e4f7df0

Environment

  • Windows 11 10.0.26200, rustc/cargo 1.98.1
  • WARP d3d10warp.dll 10.0.26100.9818, dxil.dll 1.8.2502.11 (Windows SDK 10.0.26100.0 x64)
  • VICTORY_WARP=1, VICTORY_D3D12_WARP=1, --features diagnostics, which VICTORY_D3D12_WARP needs to take effect in victory-gpu.

New tests, head vs control
Control = 63bcca43 with only the PR's two tests applied.

test head control
draw::tests::kept_viewports_and_scissors_are_the_last_set ok ok
list::tests::barriers_beyond_the_stack_room_all_reach_the_list ok ok

Both tests pass on main too. This PR is a no-behaviour-change refactor, and these tests guard the behaviour, so they are not expected to fail before the fix. Both return early if no host GPU exists, and I did not independently confirm the WARP host path was taken. I did not run the perf bench, so I can't speak to the nanosecond figures.

Full cargo test -p victory-gpu --features diagnostics --lib

run head main 63bcca43
--test-threads=1 247 passed, 1 failed, 1 ignored (249 total) 245 passed, 1 failed, 1 ignored (247 total)
parallel 247 passed, 1 failed, 1 ignored 245 passed, 1 failed, 1 ignored

The one failure is frame::tests::waits_end_on_ticks_and_count_frames. It fails the same way on unmodified main in both modes, so it is not a regression from this PR.

Not tested

  • Any physical GPU: WARP software adapter only. The RTX/Intel runs in the PR description are not reproduced here.
  • No game files or game frames.
  • I did not run clippy or xtask policy.

AI use: Claude Code (Claude Sonnet 5.5)

**@⁠oni-swr** on GitHub · 2026-11-26 18:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3297#issuecomment-7200428380) WARP verification of #3297 (synthetic tests only, no game files, no physical GPU). **Commits** - Head: `834a4e1f73f93d1e9b5d1ed56bd818b61b3e37c5` - Base / main control: `63bcca43c6a00a758510398fa43096ce7e4f7df0` **Environment** - Windows 11 10.0.26200, rustc/cargo 1.98.1 - WARP `d3d10warp.dll` 10.0.26100.9818, `dxil.dll` 1.8.2502.11 (Windows SDK 10.0.26100.0 x64) - `VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`, `--features diagnostics`, which `VICTORY_D3D12_WARP` needs to take effect in `victory-gpu`. **New tests, head vs control** Control = `63bcca43` with only the PR's two tests applied. | test | head | control | |---|---|---| | `draw::tests::kept_viewports_and_scissors_are_the_last_set` | ok | ok | | `list::tests::barriers_beyond_the_stack_room_all_reach_the_list` | ok | ok | Both tests pass on main too. This PR is a no-behaviour-change refactor, and these tests guard the behaviour, so they are not expected to fail before the fix. Both return early if no host GPU exists, and I did not independently confirm the WARP host path was taken. I did not run the perf bench, so I can't speak to the nanosecond figures. **Full `cargo test -p victory-gpu --features diagnostics --lib`** | run | head | main `63bcca43` | |---|---|---| | `--test-threads=1` | 247 passed, 1 failed, 1 ignored (249 total) | 245 passed, 1 failed, 1 ignored (247 total) | | parallel | 247 passed, 1 failed, 1 ignored | 245 passed, 1 failed, 1 ignored | The one failure is `frame::tests::waits_end_on_ticks_and_count_frames`. It fails the same way on unmodified main in both modes, so it is not a regression from this PR. **Not tested** - Any physical GPU: WARP software adapter only. The RTX/Intel runs in the PR description are not reproduced here. - No game files or game frames. - I did not run clippy or `xtask policy`. AI use: Claude Code (Claude Sonnet 5.5)
This pull request can be merged automatically.
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/3297/head:github-bot/gh-3297'
git switch 'github-bot/gh-3297'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3297'
git switch 'github-bot/gh-3297'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3297'
git switch 'github-bot/gh-3297'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3297'
git switch 'main'
git merge --squash 'github-bot/gh-3297'
git switch 'main'
git merge --ff-only 'github-bot/gh-3297'
git switch 'main'
git merge 'github-bot/gh-3297'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3297
No description provided.