perf(gpu): VRAM DEFAULT sampled-slot marks with async present readback, WaveIsFirstLane dedup, and shader cache key fix #1425

Merged
adwen-007 merged 1 commit from upstream-pr/1425 into main 2026-11-29 08:16:56 +00:00
adwen-007 commented 2026-11-28 19:40:12 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by adwen-007 on 2026-11-28T19:40:12Z.


Summary

Implements opt-in shader-sampled bindless texture slot tracking (VICTORY_SAMPLED_MARKS=1, off by default, building on the slot-marking concept from #1074) in a way that avoids BAR/PCIe GPU stalls on 8 GB GPUs without full-VRAM Resizable BAR, cuts per-wave shader overhead by 32x, and fixes a shader-cache DXGI_ERROR_DEVICE_HUNG bug when toggling the switch off.

Key changes

  1. Device-local VRAM (D3D12_HEAP_TYPE_DEFAULT) + async present readback (crates/victory-gpu/src/sampled.rs, host.rs)
    • Keeps the 512 KiB SLOT_SAMPLED (u251) bitmask strictly in GPU-local GDDR6 VRAM (host.uav_buffer) instead of a CPU-mapped BAR / shared buffer.
    • Every 30 frames inside Host::present_planes, records a single CopyResource to a permanently mapped cached READBACK buffer followed by a GPU CopyResource clear from a zero UPLOAD buffer, and scans the cached RAM copy once Host::fence_reached confirms completion.
    • Eliminates the ~200–230 ms/frame GPU stalls observed with CPU-mapped BAR / system-RAM mark buffers on RTX 3060 Ti (256 MB BAR).
  2. WaveIsFirstLane() deduplication (crates/victory-shader/src/emit/lower.rs)
    • Tracks (index, per_lane) in heap_indices. For wave-uniform texture handles (!per_lane, the vast majority of bindless texture samples), guards mark_sampled with dx.op.waveIsFirstLane (setting flags::WAVE_OPS), reducing shader ALU and L1/L2 traffic by 32x while preserving per-lane marking for divergent waterfall handles.
  3. Shader cache isolation & self-healing (crates/victory-gpu/src/shader_cache.rs)
    • Hashes VICTORY_SAMPLED_MARKS=1 into shader_cache::build() so shaders translated with root UAV u251 (SLOT_SAMPLED) are never served when VICTORY_SAMPLED_MARKS=0 (otherwise draw leaves u251 unbound and the GPU faults with DXGI_ERROR_DEVICE_HUNG 0x887A0006).
    • Also rejects and re-translates any stale cached HostShader whose root_uavs contains SLOT_SAMPLED when sampled_marks_on() is false.

Testing & Real-Hardware Verification

  • cargo test -p victory-shader a_picked_texture_marks_its_slot_with_sampled_marks — passed (validates DXIL emission with WaveIsFirstLane + WAVE_OPS).
  • cargo test -p victory-gpu sampled::tests — passed.
  • Verified in a continuous 38-minute gameplay session on RTX 3060 Ti (8 GB VRAM, 256 MB BAR) + i7-12700K + Windows 10 (series-x profile):
    • 0 crashes, 0 D3D12 errors, 0 GPU hangs over 38 minutes (413 3D gameplay intervals).
    • Tracked 58,400–59,700 live sampled slots per 30-frame sweep with ~8.5 ms GPU time in active 3D scenes (compared to ~230 ms GPU stalls with CPU-mapped BAR).
    • Identified 16,168 idle bindless textures (~2,349 MB of GDDR6 VRAM) not sampled by any shader within the idle window.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5543891734 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1425). Originally posted by [adwen-007](https://github.com/adwen-007) on 2026-11-28T19:40:12Z. --- ## Summary Implements opt-in shader-sampled bindless texture slot tracking (`VICTORY_SAMPLED_MARKS=1`, off by default, building on the slot-marking concept from #1074) in a way that avoids BAR/PCIe GPU stalls on 8 GB GPUs without full-VRAM Resizable BAR, cuts per-wave shader overhead by 32x, and fixes a shader-cache `DXGI_ERROR_DEVICE_HUNG` bug when toggling the switch off. ### Key changes 1. **Device-local VRAM (`D3D12_HEAP_TYPE_DEFAULT`) + async `present` readback (`crates/victory-gpu/src/sampled.rs`, `host.rs`)** - Keeps the 512 KiB `SLOT_SAMPLED` (`u251`) bitmask strictly in GPU-local GDDR6 VRAM (`host.uav_buffer`) instead of a CPU-mapped BAR / shared buffer. - Every 30 frames inside `Host::present_planes`, records a single `CopyResource` to a permanently mapped cached `READBACK` buffer followed by a GPU `CopyResource` clear from a zero `UPLOAD` buffer, and scans the cached RAM copy once `Host::fence_reached` confirms completion. - Eliminates the ~200–230 ms/frame GPU stalls observed with CPU-mapped BAR / system-RAM mark buffers on RTX 3060 Ti (256 MB BAR). 2. **`WaveIsFirstLane()` deduplication (`crates/victory-shader/src/emit/lower.rs`)** - Tracks `(index, per_lane)` in `heap_indices`. For wave-uniform texture handles (`!per_lane`, the vast majority of bindless texture samples), guards `mark_sampled` with `dx.op.waveIsFirstLane` (setting `flags::WAVE_OPS`), reducing shader ALU and L1/L2 traffic by 32x while preserving per-lane marking for divergent waterfall handles. 3. **Shader cache isolation & self-healing (`crates/victory-gpu/src/shader_cache.rs`)** - Hashes `VICTORY_SAMPLED_MARKS=1` into `shader_cache::build()` so shaders translated with root UAV `u251` (`SLOT_SAMPLED`) are never served when `VICTORY_SAMPLED_MARKS=0` (otherwise `draw` leaves `u251` unbound and the GPU faults with `DXGI_ERROR_DEVICE_HUNG 0x887A0006`). - Also rejects and re-translates any stale cached `HostShader` whose `root_uavs` contains `SLOT_SAMPLED` when `sampled_marks_on()` is false. ## Testing & Real-Hardware Verification - `cargo test -p victory-shader a_picked_texture_marks_its_slot_with_sampled_marks` — passed (validates DXIL emission with `WaveIsFirstLane` + `WAVE_OPS`). - `cargo test -p victory-gpu sampled::tests` — passed. - Verified in a continuous **38-minute gameplay session** on **RTX 3060 Ti (8 GB VRAM, 256 MB BAR) + i7-12700K + Windows 10** (`series-x` profile): - **0 crashes, 0 D3D12 errors, 0 GPU hangs** over 38 minutes (413 3D gameplay intervals). - Tracked **58,400–59,700 live sampled slots** per 30-frame sweep with **~8.5 ms GPU time** in active 3D scenes (compared to ~230 ms GPU stalls with CPU-mapped BAR). - Identified **16,168 idle bindless textures (~2,349 MB of GDDR6 VRAM)** not sampled by any shader within the idle window.
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
trustno1-coder/VIctory-NVIDIA!1425
No description provided.