perf(gpu,shader,pipeline): 8GB VRAM residency guard, hybrid core pinning, lock-free queues, and Pass 2 submit/descriptor/shader optimizations #41

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

@⁠xonix97 on GitHub · 2026-12-03 15:28 UTC · original
xonix97:perf/rtx5060-14650hx-8gb-vram → main · +1143 −239 · 14 files · 1 commits · open

Summary

Two optimization passes targeting 8 GB VRAM GPUs (e.g. RTX 5060 Laptop GPU, NVIDIA Blackwell) and hybrid P/E-core CPUs (e.g. Intel Core i7-14650HX, 16 GB RAM):

Pass 1: 8 GB VRAM Residency, Hybrid Threading, Barriers & Lock-Free Command Queues

  • 8 GB VRAM Budget & Demotion (crates/victory-gpu/src/residency.rs, resource.rs, host.rs, shadow.rs):
    • Added DXGI local VRAM budget tracking (DEFAULT_VRAM_SOFT_CAP_BYTES = 6963 MiB, override via VICTORY_VRAM_SOFT_CAP_MB), pressure tiers, dynamic mip clamping (effective_edge_max()), and L0 write-combined D3D12_HEAP_TYPE_CUSTOM demotion for textures (host_texture_as()) and >= 64 KiB UAV buffers (uav_buffer_now()) when over the soft cap on 8 GB GPUs.
    • Capped Resizable BAR write-combined shadow mapping (window_mapped_most() / window_mapped_for()) on small-BAR / 16 GB RAM 8 GB GPUs to prevent PCIe thrashing.
  • Hybrid P/E-Core Thread Placement (crates/victory-gpu/src/cores.rs):
    • Detected hybrid efficiency sets (hybrid_efficiency_sets(), slow_of()) and pinned background shader compiles / non-frame work to E-cores (keep_off_the_frames_cores(), keep_runtime_compiles_off_the_frames_cores()) while keeping frame-critical work on fast P-cores.
  • Background PSO Library Saving (crates/victory-gpu/src/pipeline/make.rs):
    • Enabled a default 30 s periodic PSO library save timer when VICTORY_LIBRARY_SAVE_TIMER_S is unset.
  • NVIDIA Blackwell Enhanced/Narrow Barriers (crates/victory-gpu/src/host/place.rs):
    • Defaulted narrow_mask() to NARROW_ALL on discrete NVIDIA adapters supporting Enhanced Barriers unless overridden via VICTORY_NARROW_BARRIERS.
  • Lock-Free Thin Command Queues (crates/victory-gpu/src/list/thin.rs):
    • Replaced global READY/WORDS mutexes with bounded lock-free MPMC rings (LockFreeRing, READY_RING, WORDS_RING), thread-local LOCAL_WORDS word chunk pooling, and scaled default_thin_threads().

Pass 2: Submission Lock Split, Descriptor Batching, Shader Cache/Bitcode & PCIe Writeback Tuning

  • Reduced Host::submit Critical Section & Default Async Relay (crates/victory-gpu/src/host.rs):
    • Moved heap marking (heaps_mark, first_heaps), write-watch range collection (Batch::collect_watch_ranges), async ask_first, and command-list vector preallocation outside self.submitted.lock().
    • Enabled VICTORY_SUBMIT_SPLIT and VICTORY_RELAY_COPY by default at runtime (!= "0" opt-out; disabled under cfg!(test)).
  • Direct Dynamic Descriptor Writes & Batched Table Copies (crates/victory-gpu/src/descriptor/host.rs, draw.rs):
    • Bypassed thread-local descriptor staging + CopyDescriptorsSimple(1) for exclusively-owned dynamic slots (is_dynamic_slot), writing directly in place.
    • Added DynamicCopyBatch (HostHeap::make_listed_into + CopyDescriptors flush in draw.rs::tables()) using a thread-local scratch buffer to batch cached dynamic table copies across a draw into a single COM call.
  • LRU Shader Cache, Zero-Alloc Cache Keying & Bitcode Scratch Buffers (crates/victory-pipeline/src/cache.rs, crates/victory-gpu/src/shader_cache.rs, crates/victory-shader/src/emit/bitcode.rs, crates/victory-shader/src/gfx10/mod.rs):
    • Added streaming CacheKey::from_parts to eliminate container-sized Vec concatenation on every shader cache lookup.
    • Upgraded shader_cache::MEMORY_CACHE to a lock-free-read LRU cache (AtomicU64 access stamps, VICTORY_SHADER_MEM_CACHE default 8192) evicting the least-recently-used entry when full (cached loads already skip DXIL validation).
    • Reused one scratch Vec<u64> (fill_chars) across Module::emit blocks in bitcode.rs and pre-reserved pending capacity in gfx10::decode.
  • PCIe Copy-Back Cutoff (crates/victory-gpu/src/shadow.rs):
    • Enabled wc_no_back by default at runtime (VICTORY_WC_NO_BACK != "0") with a 1024 KiB minimum size cutoff (VICTORY_WC_NO_BACK_MIN_KB, 0 under cfg!(test)) so large WC buffers stay on-card while small CPU-readback results (< 1 MiB) still copy back accurately.

Verification

  • cargo clippy --workspace --lib --locked: compiles cleanly with 0 new warnings in modified files.
  • cargo xtask policy --staged: asset policy: 14 files ok.
  • cargo build --release --locked -p victory: succeeded (target/release/victory.exe).
  • Targeted unit tests passed after final edits: residency::tests, cores::tests, pipeline::make::tests, shader_cache::tests (12 passed), descriptor::host::tests (72 passed, 1 ignored), draw::tests (9 passed), host::tests (91 passed, 2 ignored), shadow::wc_no_back_tests (1 passed), texback::tests (4 passed), watch::many_askers_tests (11 passed), victory-pipeline (13 passed), victory (81 + 1 + 2 passed), victory-core (24 passed), victory-game (43 passed), victory-loader (86 + 2 + 2 passed), victory-pe (36 passed).
  • Pre-existing upstream test issues on base commit 60d36c7 (untouched crates/tests): victory-shader --lib --tests fails to compile (missing field code_table), victory-formats bcpack::tests::oracle_parity_* (3 failed), victory-hle gameinput/xmem (6 failed), xtask repo-wide asset policy (5 pre-existing files), and victory-gpu shadow::landing_tests::what_a_landing_wrote_is_not_sent_up_again.
**@⁠xonix97** on GitHub · 2026-12-03 15:28 UTC · [original](https://github.com/ToLIManl/VIctory-Hydra/pull/41) `xonix97:perf/rtx5060-14650hx-8gb-vram` → `main` · +1143 −239 · 14 files · 1 commits · open ## Summary Two optimization passes targeting 8 GB VRAM GPUs (e.g. RTX 5060 Laptop GPU, NVIDIA Blackwell) and hybrid P/E-core CPUs (e.g. Intel Core i7-14650HX, 16 GB RAM): ### Pass 1: 8 GB VRAM Residency, Hybrid Threading, Barriers & Lock-Free Command Queues - **8 GB VRAM Budget & Demotion (`crates/victory-gpu/src/residency.rs`, `resource.rs`, `host.rs`, `shadow.rs`)**: - Added DXGI local VRAM budget tracking (`DEFAULT_VRAM_SOFT_CAP_BYTES = 6963 MiB`, override via `VICTORY_VRAM_SOFT_CAP_MB`), pressure tiers, dynamic mip clamping (`effective_edge_max()`), and L0 write-combined `D3D12_HEAP_TYPE_CUSTOM` demotion for textures (`host_texture_as()`) and >= 64 KiB UAV buffers (`uav_buffer_now()`) when over the soft cap on 8 GB GPUs. - Capped Resizable BAR write-combined shadow mapping (`window_mapped_most()` / `window_mapped_for()`) on small-BAR / 16 GB RAM 8 GB GPUs to prevent PCIe thrashing. - **Hybrid P/E-Core Thread Placement (`crates/victory-gpu/src/cores.rs`)**: - Detected hybrid efficiency sets (`hybrid_efficiency_sets()`, `slow_of()`) and pinned background shader compiles / non-frame work to E-cores (`keep_off_the_frames_cores()`, `keep_runtime_compiles_off_the_frames_cores()`) while keeping frame-critical work on fast P-cores. - **Background PSO Library Saving (`crates/victory-gpu/src/pipeline/make.rs`)**: - Enabled a default `30 s` periodic PSO library save timer when `VICTORY_LIBRARY_SAVE_TIMER_S` is unset. - **NVIDIA Blackwell Enhanced/Narrow Barriers (`crates/victory-gpu/src/host/place.rs`)**: - Defaulted `narrow_mask()` to `NARROW_ALL` on discrete NVIDIA adapters supporting Enhanced Barriers unless overridden via `VICTORY_NARROW_BARRIERS`. - **Lock-Free Thin Command Queues (`crates/victory-gpu/src/list/thin.rs`)**: - Replaced global `READY`/`WORDS` mutexes with bounded lock-free MPMC rings (`LockFreeRing`, `READY_RING`, `WORDS_RING`), thread-local `LOCAL_WORDS` word chunk pooling, and scaled `default_thin_threads()`. ### Pass 2: Submission Lock Split, Descriptor Batching, Shader Cache/Bitcode & PCIe Writeback Tuning - **Reduced `Host::submit` Critical Section & Default Async Relay (`crates/victory-gpu/src/host.rs`)**: - Moved heap marking (`heaps_mark`, `first_heaps`), write-watch range collection (`Batch::collect_watch_ranges`), async `ask_first`, and command-list vector preallocation outside `self.submitted.lock()`. - Enabled `VICTORY_SUBMIT_SPLIT` and `VICTORY_RELAY_COPY` by default at runtime (`!= "0"` opt-out; disabled under `cfg!(test)`). - **Direct Dynamic Descriptor Writes & Batched Table Copies (`crates/victory-gpu/src/descriptor/host.rs`, `draw.rs`)**: - Bypassed thread-local descriptor staging + `CopyDescriptorsSimple(1)` for exclusively-owned dynamic slots (`is_dynamic_slot`), writing directly in place. - Added `DynamicCopyBatch` (`HostHeap::make_listed_into` + `CopyDescriptors` flush in `draw.rs::tables()`) using a thread-local scratch buffer to batch cached dynamic table copies across a draw into a single COM call. - **LRU Shader Cache, Zero-Alloc Cache Keying & Bitcode Scratch Buffers (`crates/victory-pipeline/src/cache.rs`, `crates/victory-gpu/src/shader_cache.rs`, `crates/victory-shader/src/emit/bitcode.rs`, `crates/victory-shader/src/gfx10/mod.rs`)**: - Added streaming `CacheKey::from_parts` to eliminate container-sized `Vec` concatenation on every shader cache lookup. - Upgraded `shader_cache::MEMORY_CACHE` to a lock-free-read LRU cache (`AtomicU64` access stamps, `VICTORY_SHADER_MEM_CACHE` default `8192`) evicting the least-recently-used entry when full (cached loads already skip DXIL validation). - Reused one scratch `Vec<u64>` (`fill_chars`) across `Module::emit` blocks in `bitcode.rs` and pre-reserved `pending` capacity in `gfx10::decode`. - **PCIe Copy-Back Cutoff (`crates/victory-gpu/src/shadow.rs`)**: - Enabled `wc_no_back` by default at runtime (`VICTORY_WC_NO_BACK != "0"`) with a `1024 KiB` minimum size cutoff (`VICTORY_WC_NO_BACK_MIN_KB`, `0` under `cfg!(test)`) so large WC buffers stay on-card while small CPU-readback results (< 1 MiB) still copy back accurately. ## Verification - `cargo clippy --workspace --lib --locked`: compiles cleanly with 0 new warnings in modified files. - `cargo xtask policy --staged`: `asset policy: 14 files ok`. - `cargo build --release --locked -p victory`: succeeded (`target/release/victory.exe`). - Targeted unit tests passed after final edits: `residency::tests`, `cores::tests`, `pipeline::make::tests`, `shader_cache::tests` (`12 passed`), `descriptor::host::tests` (`72 passed, 1 ignored`), `draw::tests` (`9 passed`), `host::tests` (`91 passed, 2 ignored`), `shadow::wc_no_back_tests` (`1 passed`), `texback::tests` (`4 passed`), `watch::many_askers_tests` (`11 passed`), `victory-pipeline` (`13 passed`), `victory` (`81 + 1 + 2 passed`), `victory-core` (`24 passed`), `victory-game` (`43 passed`), `victory-loader` (`86 + 2 + 2 passed`), `victory-pe` (`36 passed`). - Pre-existing upstream test issues on base commit `60d36c7` (untouched crates/tests): `victory-shader --lib --tests` fails to compile (`missing field code_table`), `victory-formats` `bcpack::tests::oracle_parity_*` (3 failed), `victory-hle` `gameinput`/`xmem` (6 failed), `xtask` repo-wide asset policy (5 pre-existing files), and `victory-gpu` `shadow::landing_tests::what_a_landing_wrote_is_not_sent_up_again`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 15:31:34 +00:00
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/41/head:github-bot/gh-41'
git switch 'github-bot/gh-41'

Merge

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