GPU: route upload buffers to GPU_UPLOAD VRAM under budget and move indirect arguments to DEFAULT #3228

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

@⁠0xKaji on GitHub · 2026-11-26 13:47 UTC · original
0xKaji:perf/upload-buffers-vram → main · +212 −17 · 3 files · 1 commits · open

Summary

Routes CPU-write-only / GPU-read-only upload buffers (Host::upload_buffer: texture staging chunks/buffers, command-list scratch, descriptor strides/marks/addresses, title-memory page tables) to D3D12_HEAP_TYPE_GPU_UPLOAD (VRAM via Resizable BAR) while local VRAM stays below 80% of its DXGI budget, and moves GPU-only indirect argument buffers (HostList::arguments) to D3D12_HEAP_TYPE_DEFAULT.

Changes

  • ReBAR GPU_UPLOAD routing (host.rs): Checks D3D12_FEATURE_D3D12_OPTIONS16.GPUUploadHeapSupported once at device creation and routes Host::upload_buffer to D3D12_HEAP_TYPE_GPU_UPLOAD (D3D12_RESOURCE_STATE_COMMON) when local VRAM usage + allocation fits within 80% of DXGI local budget (refreshed every 250 ms or on >= 4 MiB allocations), falling back cleanly to D3D12_HEAP_TYPE_UPLOAD in system RAM. Toggleable via VICTORY_UPLOAD_VRAM=0.
  • GPU-only indirect arguments (host.rs, indirect.rs): Allocates HostList::arguments via Host::default_uav_buffer (D3D12_HEAP_TYPE_DEFAULT + ALLOW_UNORDERED_ACCESS) instead of CPU-mapped shared_buffer; updates indirect.rs tests to read back via a READBACK buffer.
  • Idle pool cleanup (host.rs, list.rs): Adds HostList::release_idle_buffers() called from list::recycle() so command lists parked in SPARE drop oversized arguments and trim scratch chunks.

Measured A/B (Linux Wine 11.22 + vkd3d-proton, RTX 3060 8 GiB ReBAR, 16 GiB RAM, Series S + #2112)

  • VICTORY_UPLOAD_VRAM=0 → VICTORY_UPLOAD_VRAM=1:
    • GPU system memory: 4,180 MB → 3,697 MB (-483 MB)
    • Process commit: 3,337 MB → 3,046 MB (-291 MB)
    • Working set / Peak RSS: 14,510 MB / 13,959 MiB → 13,357 MB / 12,847 MiB (-1,112 MiB RSS)
    • Upload allocation split: 0 MB VRAM / 177 MB RAM → 59 MB VRAM / 0 MB RAM
    • Median GPU frame time: 6.0 ms → 4.9 ms, median FPS: 28.9 → 30.0 (no regression).

Verification

  • cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings
  • cargo xwin clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-msvc -- -D warnings
  • cargo test -p xtask --locked (6/6 passed)
  • Wine unit tests: upload_vram_fits_checks_80_percent_headroom, list_scratch_grows_to_fit_and_reuses_fenced_chunks (2/2 passed)
  • Complementary to #3102, #2993, and #2875, which move shared_buffer shadow copies of title memory to VRAM; this PR targets upload_buffer and HostList::arguments instead.
  • Minor neighbor overlap with #2972 on HostList::scratch trimming (release_idle_buffers here only runs when a list is parked in SPARE, and does not alter HostList::reset or Scratch).
**@⁠0xKaji** on GitHub · 2026-11-26 13:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/3228) `0xKaji:perf/upload-buffers-vram` → `main` · +212 −17 · 3 files · 1 commits · open ## Summary Routes CPU-write-only / GPU-read-only upload buffers (`Host::upload_buffer`: texture staging chunks/buffers, command-list scratch, descriptor `strides`/`marks`/`addresses`, title-memory page tables) to `D3D12_HEAP_TYPE_GPU_UPLOAD` (VRAM via Resizable BAR) while local VRAM stays below 80% of its DXGI budget, and moves GPU-only indirect argument buffers (`HostList::arguments`) to `D3D12_HEAP_TYPE_DEFAULT`. ## Changes - **ReBAR `GPU_UPLOAD` routing (`host.rs`):** Checks `D3D12_FEATURE_D3D12_OPTIONS16.GPUUploadHeapSupported` once at device creation and routes `Host::upload_buffer` to `D3D12_HEAP_TYPE_GPU_UPLOAD` (`D3D12_RESOURCE_STATE_COMMON`) when local VRAM usage + allocation fits within 80% of DXGI local budget (refreshed every 250 ms or on >= 4 MiB allocations), falling back cleanly to `D3D12_HEAP_TYPE_UPLOAD` in system RAM. Toggleable via `VICTORY_UPLOAD_VRAM=0`. - **GPU-only indirect arguments (`host.rs`, `indirect.rs`):** Allocates `HostList::arguments` via `Host::default_uav_buffer` (`D3D12_HEAP_TYPE_DEFAULT` + `ALLOW_UNORDERED_ACCESS`) instead of CPU-mapped `shared_buffer`; updates `indirect.rs` tests to read back via a `READBACK` buffer. - **Idle pool cleanup (`host.rs`, `list.rs`):** Adds `HostList::release_idle_buffers()` called from `list::recycle()` so command lists parked in `SPARE` drop oversized `arguments` and trim `scratch` chunks. ## Measured A/B (Linux Wine 11.22 + vkd3d-proton, RTX 3060 8 GiB ReBAR, 16 GiB RAM, Series S + #2112) - `VICTORY_UPLOAD_VRAM=0` → `VICTORY_UPLOAD_VRAM=1`: - GPU system memory: `4,180 MB` → `3,697 MB` (**-483 MB**) - Process commit: `3,337 MB` → `3,046 MB` (**-291 MB**) - Working set / Peak RSS: `14,510 MB` / `13,959 MiB` → `13,357 MB` / `12,847 MiB` (**-1,112 MiB** RSS) - Upload allocation split: `0 MB VRAM / 177 MB RAM` → `59 MB VRAM / 0 MB RAM` - Median GPU frame time: `6.0 ms` → `4.9 ms`, median FPS: `28.9` → `30.0` (no regression). ## Verification - `cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings` - `cargo xwin clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-msvc -- -D warnings` - `cargo test -p xtask --locked` (6/6 passed) - Wine unit tests: `upload_vram_fits_checks_80_percent_headroom`, `list_scratch_grows_to_fit_and_reuses_fenced_chunks` (2/2 passed) ## Partial Overlaps / Related PRs - Complementary to `#3102`, `#2993`, and `#2875`, which move `shared_buffer` shadow copies of title memory to VRAM; this PR targets `upload_buffer` and `HostList::arguments` instead. - Minor neighbor overlap with `#2972` on `HostList::scratch` trimming (`release_idle_buffers` here only runs when a list is parked in `SPARE`, and does not alter `HostList::reset` or `Scratch`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:47:26 +00:00
Author
Owner

@⁠potatoe0100 on GitHub · 2026-11-26 14:03 UTC · original

Tested ef8d719 merged onto main 63bcca4 on an RTX 4060 8 GB (Ada, PCIe 4.0 x8, driver 621.14, Windows 11 Pro 26300, Resizable BAR on). No game files, so synthetic tests only.

Tests: cargo test -p victory-gpu -p victory-shader --lib --locked -- --test-threads=1 (skipping heap_direct_texture_reads_mark_their_heap_index, #2571). Same result as main on this card: the new upload_vram_fits_checks_80_percent_headroom, list_scratch_grows_to_fit_and_reuses_fenced_chunks and all indirect::tests pass. The only failures are the 5 known capped-heap ones (#1835), which fail on main too. OPTIONS16.GPUUploadHeapSupported is true here, so the GPU_UPLOAD path really ran.

Costs measured on this card (a throwaway --release probe, not part of the PR):

per buffer / rate
DEFAULT 64 KiB create + release (default_uav_buffer) 0.25 ms
UPLOAD 64 KiB create + map + release 0.18 ms
GPU_UPLOAD 64 KiB create + map + release 0.31 ms
CPU write, 64 MiB memcpy into UPLOAD 55.9 GB/s
CPU write, 64 MiB memcpy into GPU_UPLOAD 10.4 GB/s

Two things this suggests, for whoever reviews:

  1. release_idle_buffers() runs on every list::recycle(). It drops the indirect arguments buffer and trims scratch to at most one chunk. list.rs notes the title resets up to 21 lists a frame, so a recycled list that does indirect work makes a new DEFAULT buffer each time (about 0.25 ms here). A list that needs a few MiB of scratch also regrows it 64 KiB → 4 MiB, about 7 allocations. Before this PR both were kept across reuse. Would it be enough to trim only lists that have sat in SPARE for a while, or only when the buffer is well above what was used?
  2. Writes from the CPU into GPU_UPLOAD go over PCIe, so they run about 5x slower than into system memory on this x8 card. That cost now lands on the recording thread for texture staging chunks and list.upload copies. That's fine when the GPU copy saved is the bottleneck, but on a card with a narrow link it may move time into "preparing", which is already the largest part of a frame in the forks' measurements. A per-caller choice (VRAM for small, often-rewritten tables; system memory for large staging writes) might be worth measuring.

AI-assisted (Claude)

**@⁠potatoe0100** on GitHub · 2026-11-26 14:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/3228#issuecomment-7194216680) Tested `ef8d719` merged onto `main` `63bcca4` on an **RTX 4060 8 GB** (Ada, PCIe 4.0 x8, driver 621.14, Windows 11 Pro 26300, Resizable BAR on). No game files, so synthetic tests only. **Tests:** `cargo test -p victory-gpu -p victory-shader --lib --locked -- --test-threads=1` (skipping `heap_direct_texture_reads_mark_their_heap_index`, #2571). Same result as `main` on this card: the new `upload_vram_fits_checks_80_percent_headroom`, `list_scratch_grows_to_fit_and_reuses_fenced_chunks` and all `indirect::tests` pass. The only failures are the 5 known capped-heap ones (#1835), which fail on `main` too. `OPTIONS16.GPUUploadHeapSupported` is true here, so the GPU_UPLOAD path really ran. **Costs measured on this card** (a throwaway `--release` probe, not part of the PR): | | per buffer / rate | |---|---| | DEFAULT 64 KiB create + release (`default_uav_buffer`) | 0.25 ms | | UPLOAD 64 KiB create + map + release | 0.18 ms | | GPU_UPLOAD 64 KiB create + map + release | 0.31 ms | | CPU write, 64 MiB memcpy into UPLOAD | 55.9 GB/s | | CPU write, 64 MiB memcpy into GPU_UPLOAD | 10.4 GB/s | Two things this suggests, for whoever reviews: 1. `release_idle_buffers()` runs on every `list::recycle()`. It drops the indirect `arguments` buffer and trims scratch to at most one chunk. `list.rs` notes the title resets up to 21 lists a frame, so a recycled list that does indirect work makes a new DEFAULT buffer each time (about 0.25 ms here). A list that needs a few MiB of scratch also regrows it 64 KiB → 4 MiB, about 7 allocations. Before this PR both were kept across reuse. Would it be enough to trim only lists that have sat in `SPARE` for a while, or only when the buffer is well above what was used? 2. Writes from the CPU into GPU_UPLOAD go over PCIe, so they run about 5x slower than into system memory on this x8 card. That cost now lands on the recording thread for texture staging chunks and `list.upload` copies. That's fine when the GPU copy saved is the bottleneck, but on a card with a narrow link it may move time into "preparing", which is already the largest part of a frame in the forks' measurements. A per-caller choice (VRAM for small, often-rewritten tables; system memory for large staging writes) might be worth measuring. AI-assisted (Claude)
Author
Owner

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

Verified on RTX 5090 (Resizable BAR / GPU_UPLOAD capable) against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib host::tests -- --test-threads=1 --skip dynamic_slots_are_held_until_released: passed.
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed; indirect::: 6/6 passed; shadow::: 10/10 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly routes upload buffers to GPU_UPLOAD VRAM within budget and moves indirect arguments accordingly.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 14:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/3228#pullrequestreview-6075544800) · **approved these changes** Verified on RTX 5090 (Resizable BAR / `GPU_UPLOAD` capable) against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib host::tests -- --test-threads=1 --skip dynamic_slots_are_held_until_released`: passed. - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 20/20 passed; `indirect::`: 6/6 passed; `shadow::`: 10/10 passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly routes upload buffers to `GPU_UPLOAD` VRAM within budget and moves indirect arguments accordingly. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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/3228/head:github-bot/gh-3228'
git switch 'github-bot/gh-3228'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3228'
git switch 'github-bot/gh-3228'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3228'
git switch 'github-bot/gh-3228'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3228'
git switch 'main'
git merge --squash 'github-bot/gh-3228'
git switch 'main'
git merge --ff-only 'github-bot/gh-3228'
git switch 'main'
git merge 'github-bot/gh-3228'
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!3228
No description provided.