GPU: viewports, scissors and barriers set without an allocation per call #3297
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3297
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3297"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@KainanP on GitHub · 2026-11-26 16:21 UTC · original
KainanP:perf/list-setters-no-alloc→main· +171 −7 · 2 files · 1 commits · openRemoves the per-call allocations in three list setters that #2586's per-call table (comment 7195391455) pointed at.
Change
Only
crates/victory-gpuchanges.draw.rs:RSSetViewportsandRSSetScissorRectskeep what they set for the list's next segment (Fixed, replayed byState::cut). They used to keep it in a newVecper call (to_vec()). Now they refill theVecthe list already has (keep), so only a list's first call allocates. The host call gets the title's slice as before.list.rs:ResourceBarrierbuilt its host barriers in a newVecper 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 aVecas 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.63bcca4RSSetViewports, 1 (0xa8)RSSetScissorRects, 1 (0xb0)ResourceBarrier, 1 texture transition (0xd0)ResourceBarrier, 1 buffer UAV (0xd0)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, andState::cutreplays them.cargo test -p victory-gpu --release --lib, with the same failures as on main63bcca4:dynamic_slots_are_held_until_releasedandlists_share_a_table_and_copies_keep_their_views.memory_tests::heap_direct_texture_reads_mark_their_heap_indexwas skipped because it access-violates on main here.a_texture_written_in_one_format_reads_in_another_through_a_placed_view, which also fails on main.--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, andcargo xtask policy.Unrelated to this PR:
shadow::tests::partial_refresh_under_marked_range_updates_saved_bytessometimes fails in the parallel run on main63bcca4too (2 of 30 runs on RTX).Overlaps
keep(&mut self.fixed.viewports, viewports). #3176's scissorVecholds the normalized rects. ThatVeccould be the one kept, or its rects could be written into the keptVecwithkeep.barrieraround aVecit 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.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
@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):
Fixed::{viewports, scissors}backing vectors viakeep()and using an inline 8-slot stack buffer (spilling toVecfor>= 8barriers, preserving room for the trailingUAV_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 (includingkept_viewports_and_scissors_are_the_last_set).cargo test -p victory-gpu --lib list:: -- --test-threads=1(RTX 5090): 5 passed, 0 failed (includingbarriers_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 on GitHub · 2026-11-26 18:24 UTC · original
WARP verification of #3297 (synthetic tests only, no game files, no physical GPU).
Commits
834a4e1f73f93d1e9b5d1ed56bd818b61b3e37c563bcca43c6a00a758510398fa43096ce7e4f7df0Environment
d3d10warp.dll10.0.26100.9818,dxil.dll1.8.2502.11 (Windows SDK 10.0.26100.0 x64)VICTORY_WARP=1,VICTORY_D3D12_WARP=1,--features diagnostics, whichVICTORY_D3D12_WARPneeds to take effect invictory-gpu.New tests, head vs control
Control =
63bcca43with only the PR's two tests applied.draw::tests::kept_viewports_and_scissors_are_the_last_setlist::tests::barriers_beyond_the_stack_room_all_reach_the_listBoth 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 --lib63bcca43--test-threads=1The 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
xtask policy.AI use: Claude Code (Claude Sonnet 5.5)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.