draw: reuse State allocations across reset, cache target state sync, and stack-allocate RTVs #390

Open
github-bot wants to merge 2 commits from github-bot/gh-390 into main AGit
Owner

@⁠Wiktorxd-1 on GitHub · 2026-11-27 21:50 UTC · original
Wiktorxd-1:perf/reduce-dropped-and-cpu → main · +83 −14 · 1 files · 2 commits · open

What this fixes

On heavy frames, victory_gpu::list::thin spends significant CPU time across worker threads replaying ~26k–40k commands/frame across ~224 command lists/frame:

  • draw::State::reset did *self = State::default(), dropping all Vec and HashMap heap capacities (graphics, compute, targets, target_handles, viewports, scissors, ambient_tables, fresh_tables, root_srv_slots, root_uav_slots) on every list reset.
  • draw::State::prepare_for called ensure_state (resource::host_copy + HostList::states mutex lock) for every bound render target and depth buffer on every consecutive draw, even when targets/depth had not changed since the previous draw.
  • draw::State::set_targets allocated a Vec<D3D12_CPU_DESCRIPTOR_HANDLE> for OMSetRenderTargets on every target change (even though D3D12 has at most 8 RTVs).

I can't give a clean 3D-scene fps delta yet: the local launch test (35s, Series S, DLSS Performance, FG 6x) verified clean startup and rendering (warns=0, crashes.log=False) without loading into a heavy 3D save.

The commits

  1. Reuse draw::State allocations across reset and cache target state sync.
    • State::reset drains self.dynamic via crate::descriptor::release_dynamic (preserving Drop semantics) and .clear()s all Vec/HashMap fields in place instead of reallocating.
    • Added targets_synced: bool and last_depth_state: u32 on State (invalidated in reset, set_targets, and synced) so prepare_for skips redundant ensure_state calls on back-to-back draws to the same targets/depth state (still respecting TESTED_DEPTH read-state transitions).
  2. Stack-allocate RTV descriptor handle array in set_targets.
    • Uses [D3D12_CPU_DESCRIPTOR_HANDLE; 8] on the stack for <= 8 render targets instead of collecting into a Vec.

Tests

  • cargo test --locked -p victory-gpu --lib draw (11 passed; 0 failed; 3 ignored)
  • cargo build --release --locked -p victory (succeeded)
  • Launched target\release\victory.exe via scripts\play-nvidia.ps1 (35s, warns=0, crashes.log=False).

Setup

NVIDIA GeForce RTX 5070, driver 621.14.0, Windows 11 (10.0.26300). Series S profile, DLSS Performance, Frame Generation 6x. My own dump: <game dir>. No game files are attached or quoted.

This change and its testing were done with an AI assistant (Antigravity), and I checked the results on my machine.

**@⁠Wiktorxd-1** on GitHub · 2026-11-27 21:50 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/390) `Wiktorxd-1:perf/reduce-dropped-and-cpu` → `main` · +83 −14 · 1 files · 2 commits · open ## What this fixes On heavy frames, `victory_gpu::list::thin` spends significant CPU time across worker threads replaying ~26k–40k commands/frame across ~224 command lists/frame: - `draw::State::reset` did `*self = State::default()`, dropping all `Vec` and `HashMap` heap capacities (`graphics`, `compute`, `targets`, `target_handles`, `viewports`, `scissors`, `ambient_tables`, `fresh_tables`, `root_srv_slots`, `root_uav_slots`) on every list reset. - `draw::State::prepare_for` called `ensure_state` (`resource::host_copy` + `HostList::states` mutex lock) for every bound render target and depth buffer on every consecutive draw, even when targets/depth had not changed since the previous draw. - `draw::State::set_targets` allocated a `Vec<D3D12_CPU_DESCRIPTOR_HANDLE>` for `OMSetRenderTargets` on every target change (even though D3D12 has at most 8 RTVs). I can't give a clean 3D-scene fps delta yet: the local launch test (`35s`, Series S, DLSS Performance, FG 6x) verified clean startup and rendering (`warns=0`, `crashes.log=False`) without loading into a heavy 3D save. ## The commits 1. **Reuse `draw::State` allocations across `reset` and cache target state sync.** - `State::reset` drains `self.dynamic` via `crate::descriptor::release_dynamic` (preserving `Drop` semantics) and `.clear()`s all `Vec`/`HashMap` fields in place instead of reallocating. - Added `targets_synced: bool` and `last_depth_state: u32` on `State` (invalidated in `reset`, `set_targets`, and `synced`) so `prepare_for` skips redundant `ensure_state` calls on back-to-back draws to the same targets/depth state (still respecting `TESTED_DEPTH` read-state transitions). 2. **Stack-allocate RTV descriptor handle array in `set_targets`.** - Uses `[D3D12_CPU_DESCRIPTOR_HANDLE; 8]` on the stack for `<= 8` render targets instead of collecting into a `Vec`. ## Tests - `cargo test --locked -p victory-gpu --lib draw` (`11 passed; 0 failed; 3 ignored`) - `cargo build --release --locked -p victory` (succeeded) - Launched `target\release\victory.exe` via `scripts\play-nvidia.ps1` (`35s`, `warns=0`, `crashes.log=False`). ## Setup NVIDIA GeForce RTX 5070, driver `621.14.0`, Windows 11 (`10.0.26300`). Series S profile, DLSS Performance, Frame Generation 6x. My own dump: `<game dir>`. No game files are attached or quoted. This change and its testing were done with an AI assistant (Antigravity), and I checked the results on my machine.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 21:52:44 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/390/head:github-bot/gh-390'
git switch 'github-bot/gh-390'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-390'
git switch 'github-bot/gh-390'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-390'
git switch 'github-bot/gh-390'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-390'
git switch 'main'
git merge --squash 'github-bot/gh-390'
git switch 'main'
git merge --ff-only 'github-bot/gh-390'
git switch 'main'
git merge 'github-bot/gh-390'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.