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

Manually merged
github merged 1 commit from github-bot/gh-1425 into main 2026-11-29 08:22:01 +00:00 AGit
Owner

@⁠adwen-007 on GitHub · 2026-11-28 19:40 UTC · original
adwen-007:perf/sampled-marks-vram-wave → main · +247 −163 · 4 files · 1 commits · merged 2026-11-29 08:16 UTC

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.
**@⁠adwen-007** on GitHub · 2026-11-28 19:40 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1425) `adwen-007:perf/sampled-marks-vram-wave` → `main` · +247 −163 · 4 files · 1 commits · merged 2026-11-29 08:16 UTC ## 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 19:41:58 +00:00
github-bot force-pushed github-bot/gh-1425 from b6f4150b5d to 7d0c28677f 2026-11-28 19:54:55 +00:00 Compare
github manually merged commit 66566be21c into main 2026-11-29 08:22:01 +00:00
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/trustno1-coder--VIctory-NVIDIA!1425
No description provided.