GPU: opt-in mip cap (VICTORY_TEXTURE_MAX_DIM), low-RAM pool trimmer (VICTORY_RAM_TRIM_MB), batched descriptor mirror & bind cache #1240

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

@⁠RealAzemed on GitHub · 2026-11-26 01:29 UTC · original
RealAzemed:perf/vram-ram-cap-batched-descriptors-bind-cache → main · +476 −19 · 8 files · 2 commits · open

Summary

Four opt-in / zero-regression memory and CPU optimizations targeting 8 GB VRAM + 16 GB RAM systems and high-draw world scenes (cleanly based on 006c353, independent of #1097, #1117, and #1225):

  1. VICTORY_TEXTURE_MAX_DIM=<pixels> — Opt-in on-demand mip cap (texture.rs, resource.rs)

    • Forces large 2D placed textures (max(width, height) > limit, when VICTORY_LEVELS_ON_DEMAND=1) onto tiles.rs tiled resources and clamps held_levels via capped_first_mip() so top-detail mips above the cap are never allocated on the card.
    • Skips the CPU linear.fill(0) memset on unheld non-packed mip levels (mip < first_tail_mip).
    • Always keeps at least the coarsest level so small or single-mip textures are never dropped. Unit-tested (capped_first_mip_clamps_large_textures_and_keeps_coarsest_level).
  2. VICTORY_RAM_TRIM_MB=<MiB> — Active low-RAM pool trimmer (host.rs, shadow.rs, texture.rs, list.rs)

    • When available_physical_ram() drops below the configured threshold (e.g. VICTORY_RAM_TRIM_MB=2048), runs sweep() every 500 ms and drains hoarded CPU-side pools:
      • shadow::POOL (retained CPU snapshot Vec<u8> buffers),
      • texture::SPARE (pooled upload staging buffers),
      • excess idle host command lists in list::IDLE down to a warm floor of 16.
    • Off by default (unset / 0).
  3. Batched HostHeap::mirror_copied_batch + 8-byte zero-page / zero-slot skip (descriptor/host.rs)

    • In mirror_copied_page: skips untouched all-zero 4 KiB pages in one pass and skips untouched *last == 0 zero slots before calling record_print().
    • Replaces the per-slot for &(index, handle) in &due { self.mirror(index, handle, false); } loop with mirror_copied_batch, acquiring made, textures, placed, buffers, changed, and kept once per changed page instead of once per mirrored slot (~100k–300k fewer mutex lock/unlock cycles per frame on busy world frames). Preserves exact lock order and stale-slot semantics (records_copied_as_bytes_are_made_at_the_next_sync passes).
  4. VICTORY_BIND_CACHE=1 — Opt-in command-list state bind cache (draw.rs, descriptor.rs)

    • Skips redundant OMSetRenderTargets (avoiding Host::rtv/Host::dsv mutex + view creation), IASetPrimitiveTopology, RSSetViewports, RSSetScissorRects, OMSetBlendFactor, OMSetStencilRef, and OMSetDepthBounds when the resolved state matches what is already bound on the host command list.
    • Cleared cleanly in State::reset() and State::replay(). Off by default.

Verification (Ryzen 5 7500F / 16 GB 1-ch DDR5 / RTX 3070 8 GB, Proton Experimental ntsync + vkd3d-proton)

  • Unit tests (cargo test --target x86_64-pc-windows-gnu -p victory-gpu under Proton):
    • texture::title_memory_tests::capped_first_mip_clamps_large_textures_and_keeps_coarsest_level — PASS
    • descriptor::tests::records_copied_as_bytes_are_made_at_the_next_sync — PASS
    • host::batch::ram_idle_ms_scales_with_pressure & vram_idle_ms_scales_with_pressure — PASS
    • 0 new compiler warnings.
  • Live 420-second multi-scene open-world run (VICTORY_TEXTURE_MAX_DIM=1024, VICTORY_RAM_TRIM_MB=2048, VICTORY_BIND_CACHE=1, 0 unhandled exceptions):
    • VRAM saved by VICTORY_TEXTURE_MAX_DIM=1024: 8,096 large textures made (1,391 alive), 88 MB VRAM allocated vs 2,932 MB (2.93 GB) saved (3,020 MB uncapped); 0 uploads starved for VRAM across 143,110 uploads (63.4 GB streamed); total card usage stayed at 5.9–6.3 GiB / 8 GiB across multiple outdoor city/night/sunset scenes.
    • RAM on 16 GB single-channel DDR5: peak RSS 13.5 GB, min available RAM 607 MB, swap max 4.5 GB across the full 420s multi-scene run (previously OOM/thrashing past 15.8 GB RSS + 6.5 GB swap in the opening room).
    • Descriptor sync: 2.2–7.9 ms/frame across 100k–300k looked-at slots with batched page mirroring.
    • Frame rate: 11.9 fps peak (1.40 fps median across 61 in-world lines over 420s on 16 GB RAM).
**@⁠RealAzemed** on GitHub · 2026-11-26 01:29 UTC · [original](https://github.com/fxceless/victory-fork/pull/1240) `RealAzemed:perf/vram-ram-cap-batched-descriptors-bind-cache` → `main` · +476 −19 · 8 files · 2 commits · open ### Summary Four opt-in / zero-regression memory and CPU optimizations targeting **8 GB VRAM + 16 GB RAM** systems and high-draw world scenes (cleanly based on `006c353`, independent of #1097, #1117, and #1225): 1. **`VICTORY_TEXTURE_MAX_DIM=<pixels>` — Opt-in on-demand mip cap (`texture.rs`, `resource.rs`)** - Forces large 2D placed textures (`max(width, height) > limit`, when `VICTORY_LEVELS_ON_DEMAND=1`) onto `tiles.rs` tiled resources and clamps `held_levels` via `capped_first_mip()` so top-detail mips above the cap are never allocated on the card. - Skips the CPU `linear.fill(0)` `memset` on unheld non-packed mip levels (`mip < first_tail_mip`). - Always keeps at least the coarsest level so small or single-mip textures are never dropped. Unit-tested (`capped_first_mip_clamps_large_textures_and_keeps_coarsest_level`). 2. **`VICTORY_RAM_TRIM_MB=<MiB>` — Active low-RAM pool trimmer (`host.rs`, `shadow.rs`, `texture.rs`, `list.rs`)** - When `available_physical_ram()` drops below the configured threshold (e.g. `VICTORY_RAM_TRIM_MB=2048`), runs `sweep()` every 500 ms and drains hoarded CPU-side pools: - `shadow::POOL` (retained CPU snapshot `Vec<u8>` buffers), - `texture::SPARE` (pooled upload staging buffers), - excess idle host command lists in `list::IDLE` down to a warm floor of 16. - Off by default (`unset` / `0`). 3. **Batched `HostHeap::mirror_copied_batch` + 8-byte zero-page / zero-slot skip (`descriptor/host.rs`)** - In `mirror_copied_page`: skips untouched all-zero 4 KiB pages in one pass and skips untouched `*last == 0` zero slots *before* calling `record_print()`. - Replaces the per-slot `for &(index, handle) in &due { self.mirror(index, handle, false); }` loop with `mirror_copied_batch`, acquiring `made`, `textures`, `placed`, `buffers`, `changed`, and `kept` **once per changed page** instead of once per mirrored slot (~100k–300k fewer mutex lock/unlock cycles per frame on busy world frames). Preserves exact lock order and stale-slot semantics (`records_copied_as_bytes_are_made_at_the_next_sync` passes). 4. **`VICTORY_BIND_CACHE=1` — Opt-in command-list state bind cache (`draw.rs`, `descriptor.rs`)** - Skips redundant `OMSetRenderTargets` (avoiding `Host::rtv`/`Host::dsv` mutex + view creation), `IASetPrimitiveTopology`, `RSSetViewports`, `RSSetScissorRects`, `OMSetBlendFactor`, `OMSetStencilRef`, and `OMSetDepthBounds` when the resolved state matches what is already bound on the host command list. - Cleared cleanly in `State::reset()` and `State::replay()`. Off by default. --- ### Verification (Ryzen 5 7500F / 16 GB 1-ch DDR5 / RTX 3070 8 GB, Proton Experimental `ntsync` + `vkd3d-proton`) - **Unit tests (`cargo test --target x86_64-pc-windows-gnu -p victory-gpu` under Proton)**: - `texture::title_memory_tests::capped_first_mip_clamps_large_textures_and_keeps_coarsest_level` — **PASS** - `descriptor::tests::records_copied_as_bytes_are_made_at_the_next_sync` — **PASS** - `host::batch::ram_idle_ms_scales_with_pressure` & `vram_idle_ms_scales_with_pressure` — **PASS** - 0 new compiler warnings. - **Live 420-second multi-scene open-world run (`VICTORY_TEXTURE_MAX_DIM=1024`, `VICTORY_RAM_TRIM_MB=2048`, `VICTORY_BIND_CACHE=1`, `0 unhandled exceptions`)**: - **VRAM saved by `VICTORY_TEXTURE_MAX_DIM=1024`**: `8,096` large textures made (`1,391` alive), **88 MB VRAM allocated vs 2,932 MB (2.93 GB) saved** (`3,020 MB` uncapped); `0` uploads starved for VRAM across 143,110 uploads (`63.4 GB` streamed); total card usage stayed at **5.9–6.3 GiB / 8 GiB** across multiple outdoor city/night/sunset scenes. - **RAM on 16 GB single-channel DDR5**: peak RSS **13.5 GB**, min available RAM **607 MB**, swap max **4.5 GB** across the full 420s multi-scene run (previously OOM/thrashing past 15.8 GB RSS + 6.5 GB swap in the opening room). - **Descriptor sync**: **2.2–7.9 ms/frame** across 100k–300k looked-at slots with batched page mirroring. - **Frame rate**: **11.9 fps peak** (1.40 fps median across 61 in-world lines over 420s on 16 GB RAM).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:00:10 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor/host.rs
  • crates/victory-gpu/src/draw.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1240/head:github-bot/gh-1240'
git switch 'github-bot/gh-1240'

Merge

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