Skip to content

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

Open
KainanP wants to merge 1 commit into
Marvisak:mainfrom
KainanP:perf/list-setters-no-alloc
Open

KainanP wants to merge 1 commit into
Marvisak:mainfrom
KainanP:perf/list-setters-no-alloc

Conversation

@KainanP

@KainanP KainanP commented Nov 26, 2026

Copy link
Copy Markdown

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

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

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 <noreply@anthropic.com>

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@oni-swr

oni-swr commented Nov 26, 2026

Copy link
Copy Markdown

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)

@borosf

borosf commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Independent local verification on Windows 11 x64, Intel Arc B580 12 GB (12 cores), at this PR's head 834a4e1:

cargo test -p victory-gpu --lib --locked --no-fail-fast -- --test-threads=1
cargo clippy -p victory-gpu --all-targets --locked -- -D warnings
cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings

Result: victory-gpu lib: 2 known baseline failures + timing flake (passed on re-run); both new allocation-removal tests passed.

Both clippy runs exit 0 (-D warnings, both feature sets). The B580 baseline failures pristine main also hits are: victory-gpu descriptor::host::tests::dynamic_slots_are_held_until_released + memory::tests::lists_share_a_table_and_copies_keep_their_views (#1744/#1829); victory-shader emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros + emit::valu_tests::fspx_programs_run_with_the_hardwares_dot_products. No PR regressions.

Synthetic tests only; no game data used. Full log kept locally. — borosf

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants