fix,perf(shader,gpu,hle): pin polling loop headers, CUDA preload fence, ambient chroma scrub, and RT-off BVH/dead-pass skips #401

Manually merged
github merged 7 commits from github-bot/gh-401 into gh-pr/401/base 2026-12-03 19:46:57 +00:00 AGit
Owner

@⁠Androtim on GitHub · 2026-12-03 17:20 UTC · original
Androtim:fix/dom-loads-pin-cuda-preload-chroma-bvh-stub → main · +1434 −71 · 15 files · 7 commits · merged 2026-12-03 19:43 UTC

Ports four high-impact GPL-3.0 stability, visual quality, and GPU performance fixes onto main while staying 100% title-neutral and preserving VICTORY_HW_RT=1, VICTORY_BVH_BUILDER=1, VICTORY_RAYS=1, and non-NVIDIA GPU behavior.

Summary of Changes

1. Pin loop headers in srv_memory_regions across polling loops (Critical Hang Fix)

  • Files: crates/victory-shader/src/emit/bitcode/opt.rs, crates/victory-shader/src/emit/mod.rs
  • Upstream: washingtonrbo/ochin-nvidia (d0fe794, GPL-3.0)
  • What changed:
    • Added immediate dominators (idom) and RPO number + dominates() on Tree, and pinned both natural loop headers and irreducible RPO back-edge targets (number[b] <= number[p]) as distinct memory-region origins in srv_memory_regions() before the fast-path !has_writes && !has_loops check.
    • Prevents DOM_LOADS (kept enabled by default) from hoisting/merging SRV loads across spin-wait polling loops — even in shaders without global buffer writes — fixing multi-minute DXGI_ERROR_DEVICE_HUNG timeouts introduced by #396.
    • Updated raw_srv_reuse_across_non_aliasing_writes_and_group_barriers and added polling_loop_backedge_never_merges_srv_load_with_pre_loop_or_across_iterations covering tight self-loops, multi-block loops, and irreducible 2-entry loops.

2. Pre-title VICTORY_CUDA_PRELOAD address-window reservation (Startup Crash Fix + FPS)

  • Files: crates/victory-gpu/src/window.rs, crates/victory-gpu/src/lib.rs, crates/victory-gpu/src/streamline.rs, crates/victory-gpu/src/upload.rs, crates/victory-hle/src/modules/xmem.rs
  • Upstream: SandBar-developer/VIctory-SandBar (0fd6d57, GPL-3.0)
  • What changed:
    • Added window.rs helpers (TITLE [4 GiB, 2^37), allocating(), regions(), free_runs(), title_free(), Fence, fence_title()) and serialized concurrent title-window allocations in upload::allocate_in_window and xmem::XMemVirtualAlloc.
    • When Streamline initializes with DLSS or Frame Generation enabled, preload_cuda() holds free holes in the title window with Fence while calling cuInit(0) (VICTORY_CUDA_PRELOAD, default on unless =0), forcing CUDA reservations above 2^37 before title allocations begin and logging reclaimed/remaining space.
    • Falls back cleanly without touching anything when nvcuda.dll or cuInit is absent or DLSS/FG is inactive, leaving AMD and Intel GPUs 100% unaffected.

3. Specular CLEAN luminance cap, chroma_scrub, and Role::Miss gather reuse

  • Files: crates/victory-gpu/src/ambient.rs
  • Upstream: HUAXIANs/VIctory-RTX (e49340b, GPL-3.0)
  • What changed:
    • Added #define CLEAN (VICTORY_AMBIENT_CLEAN, default on unless =0) capping stand-in reflection found = min(found, 1.5) in reflect_light and bound_light.
    • Added chroma_scrub (VICTORY_AMBIENT_CHROMA_SCRUB, default on unless =0, bumping WORDS to 18) to suppress acid-green and electric-cyan probe spikes alongside magenta/blue-violet garbage, and fixed without_depth() (bound_light) to upload all WORDS root constants including filter and chroma_scrub.
    • Added miss_needs_gather() so Role::Miss reuses already-gathered screen points in Set::Estimate mode instead of re-running a redundant full-screen gather pass.
    • Leaves VICTORY_HW_RT=1 completely untouched. Verified with unit tests plus a WARP D3D12 compute test (reflect_and_bound_clean_cap_and_chroma_scrub_on_gpu).

4. RT-off XboxBvhBuilder.dll build/rehydrate stub & dead RT compute skips

  • Files: crates/victory-hle/src/modules/xboxbvh.rs, apps/victory/src/run.rs, crates/victory-gpu/src/pipeline.rs, crates/victory-gpu/src/draw.rs
  • Upstream: ReZOnGithub/VIctory-lap (4b88ef0, GPL-3.0), HUAXIANs/VIctory-RTX (e49340b / readmet3xt-lab/foxhound #418, GPL-3.0), upsidedownstack/VIctory-Performance (487fc68, GPL-3.0)
  • What changed:
    • Added xboxbvh::Interpose (VICTORY_BVH_STUB, default on unless =0) in run.rs import binding (startup DLLs, main image, and late-loaded DLLs) to stub the 8 GPU BVH build/copy/rehydrate/validate exports of XboxBvhBuilder.dll as no-ops when RT is off, while leaving ctor, dtor, Set64BitMortonCodes, and GetRaytracingAccelerationStructurePrebuildInfo on the title DLL.
    • Added DeadRt classification and skip gates (DeadRt::Resolve for CS_RaytracingResolve via VICTORY_RT_SKIP_RESOLVE; DeadRt::Feeds for CSComputeSkinning, CSGenerateHairVB, CS_ScreenProbes_TraceRays*, and CS_RaytraceVBuffer* without Voxels/Fallback via VICTORY_RT_SKIP_DEAD, default on unless =0) in pipeline.rs (dead_rt_left_out) and draw.rs (State::dispatch, State::execute_indirect).
    • Both mechanisms stay strictly disabled whenever VICTORY_HW_RT=1, VICTORY_RAYS=1, or VICTORY_BVH_BUILDER=1 is active.

Verification

  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-hle --lib xboxbvh:: -> 4 passed; 0 failed
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader --lib bitcode::opt -> 19 passed; 0 failed
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib -- window:: streamline:: ambient:: pipeline::tests:: -> 50 passed; 0 failed; 1 ignored (measurement-only name_scans_time)
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib -- window:: streamline:: ambient:: pipeline:: draw:: -> 97 passed; 0 failed; 2 ignored (prior to fixing Provenance::Title test compilation in victory-hle)
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings -> passed (0 warnings)
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --all-features -- -D warnings -> passed (0 warnings)
  • cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy -> asset policy: 354 files ok
**@⁠Androtim** on GitHub · 2026-12-03 17:20 UTC · [original](https://github.com/Androtim/MiniVI/pull/401) `Androtim:fix/dom-loads-pin-cuda-preload-chroma-bvh-stub` → `main` · +1434 −71 · 15 files · 7 commits · merged 2026-12-03 19:43 UTC Ports four high-impact GPL-3.0 stability, visual quality, and GPU performance fixes onto `main` while staying 100% title-neutral and preserving `VICTORY_HW_RT=1`, `VICTORY_BVH_BUILDER=1`, `VICTORY_RAYS=1`, and non-NVIDIA GPU behavior. ## Summary of Changes ### 1. Pin loop headers in `srv_memory_regions` across polling loops (Critical Hang Fix) - **Files:** `crates/victory-shader/src/emit/bitcode/opt.rs`, `crates/victory-shader/src/emit/mod.rs` - **Upstream:** `washingtonrbo/ochin-nvidia` (`d0fe794`, GPL-3.0) - **What changed:** - Added immediate dominators (`idom`) and RPO `number` + `dominates()` on `Tree`, and pinned both natural loop headers and irreducible RPO back-edge targets (`number[b] <= number[p]`) as distinct memory-region origins in `srv_memory_regions()` **before** the fast-path `!has_writes && !has_loops` check. - Prevents `DOM_LOADS` (kept enabled by default) from hoisting/merging SRV loads across spin-wait polling loops — even in shaders without global buffer writes — fixing multi-minute `DXGI_ERROR_DEVICE_HUNG` timeouts introduced by #396. - Updated `raw_srv_reuse_across_non_aliasing_writes_and_group_barriers` and added `polling_loop_backedge_never_merges_srv_load_with_pre_loop_or_across_iterations` covering tight self-loops, multi-block loops, and irreducible 2-entry loops. ### 2. Pre-title `VICTORY_CUDA_PRELOAD` address-window reservation (Startup Crash Fix + FPS) - **Files:** `crates/victory-gpu/src/window.rs`, `crates/victory-gpu/src/lib.rs`, `crates/victory-gpu/src/streamline.rs`, `crates/victory-gpu/src/upload.rs`, `crates/victory-hle/src/modules/xmem.rs` - **Upstream:** `SandBar-developer/VIctory-SandBar` (`0fd6d57`, GPL-3.0) - **What changed:** - Added `window.rs` helpers (`TITLE` `[4 GiB, 2^37)`, `allocating()`, `regions()`, `free_runs()`, `title_free()`, `Fence`, `fence_title()`) and serialized concurrent title-window allocations in `upload::allocate_in_window` and `xmem::XMemVirtualAlloc`. - When Streamline initializes with DLSS or Frame Generation enabled, `preload_cuda()` holds free holes in the title window with `Fence` while calling `cuInit(0)` (`VICTORY_CUDA_PRELOAD`, default on unless `=0`), forcing CUDA reservations above `2^37` before title allocations begin and logging reclaimed/remaining space. - Falls back cleanly without touching anything when `nvcuda.dll` or `cuInit` is absent or DLSS/FG is inactive, leaving AMD and Intel GPUs 100% unaffected. ### 3. Specular `CLEAN` luminance cap, `chroma_scrub`, and `Role::Miss` gather reuse - **Files:** `crates/victory-gpu/src/ambient.rs` - **Upstream:** `HUAXIANs/VIctory-RTX` (`e49340b`, GPL-3.0) - **What changed:** - Added `#define CLEAN` (`VICTORY_AMBIENT_CLEAN`, default on unless `=0`) capping stand-in reflection `found = min(found, 1.5)` in `reflect_light` and `bound_light`. - Added `chroma_scrub` (`VICTORY_AMBIENT_CHROMA_SCRUB`, default on unless `=0`, bumping `WORDS` to `18`) to suppress acid-green and electric-cyan probe spikes alongside magenta/blue-violet garbage, and fixed `without_depth()` (`bound_light`) to upload all `WORDS` root constants including `filter` and `chroma_scrub`. - Added `miss_needs_gather()` so `Role::Miss` reuses already-gathered screen points in `Set::Estimate` mode instead of re-running a redundant full-screen gather pass. - Leaves `VICTORY_HW_RT=1` completely untouched. Verified with unit tests plus a WARP D3D12 compute test (`reflect_and_bound_clean_cap_and_chroma_scrub_on_gpu`). ### 4. RT-off `XboxBvhBuilder.dll` build/rehydrate stub & dead RT compute skips - **Files:** `crates/victory-hle/src/modules/xboxbvh.rs`, `apps/victory/src/run.rs`, `crates/victory-gpu/src/pipeline.rs`, `crates/victory-gpu/src/draw.rs` - **Upstream:** `ReZOnGithub/VIctory-lap` (`4b88ef0`, GPL-3.0), `HUAXIANs/VIctory-RTX` (`e49340b` / `readmet3xt-lab/foxhound` #418, GPL-3.0), `upsidedownstack/VIctory-Performance` (`487fc68`, GPL-3.0) - **What changed:** - Added `xboxbvh::Interpose` (`VICTORY_BVH_STUB`, default on unless `=0`) in `run.rs` import binding (startup DLLs, main image, and late-loaded DLLs) to stub the 8 GPU BVH build/copy/rehydrate/validate exports of `XboxBvhBuilder.dll` as no-ops when RT is off, while leaving `ctor`, `dtor`, `Set64BitMortonCodes`, and `GetRaytracingAccelerationStructurePrebuildInfo` on the title DLL. - Added `DeadRt` classification and skip gates (`DeadRt::Resolve` for `CS_RaytracingResolve` via `VICTORY_RT_SKIP_RESOLVE`; `DeadRt::Feeds` for `CSComputeSkinning`, `CSGenerateHairVB`, `CS_ScreenProbes_TraceRays*`, and `CS_RaytraceVBuffer*` without `Voxels`/`Fallback` via `VICTORY_RT_SKIP_DEAD`, default on unless `=0`) in `pipeline.rs` (`dead_rt_left_out`) and `draw.rs` (`State::dispatch`, `State::execute_indirect`). - Both mechanisms stay strictly disabled whenever `VICTORY_HW_RT=1`, `VICTORY_RAYS=1`, or `VICTORY_BVH_BUILDER=1` is active. ## Verification - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-hle --lib xboxbvh::` -> `4 passed; 0 failed` - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader --lib bitcode::opt` -> `19 passed; 0 failed` - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib -- window:: streamline:: ambient:: pipeline::tests::` -> `50 passed; 0 failed; 1 ignored` (measurement-only `name_scans_time`) - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib -- window:: streamline:: ambient:: pipeline:: draw::` -> `97 passed; 0 failed; 2 ignored` (prior to fixing `Provenance::Title` test compilation in `victory-hle`) - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings` -> passed (0 warnings) - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --all-features -- -D warnings` -> passed (0 warnings) - `cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy` -> `asset policy: 354 files ok`
Pin natural loop headers (and irreducible RPO back-edge targets) as
distinct memory-region origins inside `srv_memory_regions()`, evaluated
before `!has_writes && !has_loops` so `DOM_LOADS` never hoists or merges
SRV loads across spin-wait polling loops even in shaders without global
buffer writes. Fixes multi-minute `DXGI_ERROR_DEVICE_HUNG` hangs from
#396 while keeping `DOM_LOADS` enabled by default.

Updates `raw_srv_reuse_across_non_aliasing_writes_and_group_barriers`
and adds `polling_loop_backedge_never_merges_srv_load_with_pre_loop_or_across_iterations`
covering tight self-loops, multi-block polling loops, and irreducible
2-entry loops.

Upstream attribution (GPL-3.0):
- Ported from `washingtonrbo/ochin-nvidia` (`d0fe794`, GPL-3.0)
Reserve free holes in the title's low address window `[4 GiB, 2^37)`
around early `nvcuda.dll` `cuInit(0)` (`VICTORY_CUDA_PRELOAD`, default on
when DLSS or frame generation is enabled; `=0` disables) so CUDA's large
address-space reservations land above `2^37` instead of colliding with
early title allocations. Serializes concurrent host/HLE window
allocations via `window::allocating()`.

Falls back cleanly when `nvcuda.dll` or `cuInit` is absent so AMD and
Intel GPUs remain 100% unaffected.

Upstream attribution (GPL-3.0):
- Ported from `SandBar-developer/VIctory-SandBar` (`0fd6d57`, GPL-3.0)
- Add `#define CLEAN` luminance cap (`found = min(found, 1.5)`) in
  `reflect_light` and `bound_light` (`VICTORY_AMBIENT_CLEAN`, default on
  unless `=0`) to keep specular stand-in reflections balanced.
- Add `chroma_scrub` (`VICTORY_AMBIENT_CHROMA_SCRUB`, default on unless
  `=0`, `WORDS = 18`) to drop acid-green and electric-cyan probe spikes
  alongside magenta/blue-violet garbage, and fix `without_depth()`
  (`bound_light`) to upload all `WORDS` root constants including
  `filter` and `chroma_scrub`.
- Reuse already-gathered screen points in `Role::Miss` when running in
  `Set::Estimate` mode (`miss_needs_gather`), avoiding the redundant
  full-screen gather pass.
- Leave `VICTORY_HW_RT=1` completely untouched.
- Add unit tests and WARP D3D12 compute shader verification.

Upstream attribution (GPL-3.0):
- Ported from `HUAXIANs/VIctory-RTX` (`e49340b`, GPL-3.0)
- Add `xboxbvh::Interpose` (`VICTORY_BVH_STUB`, default on unless `=0`)
  to no-op the 8 GPU `XboxBvhBuilder.dll` build, copy, rehydrate, and
  validate exports when ray tracing is off, while leaving `ctor`, `dtor`,
  `Set64BitMortonCodes`, and `GetRaytracingAccelerationStructurePrebuildInfo`
  on the title DLL so prebuild queries keep working.
- Tag and skip dead RT-only compute pipelines in `pipeline.rs` /
  `draw.rs` (`DeadRt::Resolve` for `CS_RaytracingResolve` under
  `VICTORY_RT_SKIP_RESOLVE`, and `DeadRt::Feeds` for `CSComputeSkinning`,
  `CSGenerateHairVB`, `CS_ScreenProbes_TraceRays*`, and
  `CS_RaytraceVBuffer*` without `Voxels`/`Fallback` under
  `VICTORY_RT_SKIP_DEAD`, default on unless `=0`).
- Keep both mechanisms strictly inactive whenever any RT flag
  (`VICTORY_HW_RT=1`, `VICTORY_RAYS=1`, or `VICTORY_BVH_BUILDER=1`) is set.

Upstream attribution (GPL-3.0):
- Ported from `ReZOnGithub/VIctory-lap` (`4b88ef0`, GPL-3.0),
  `HUAXIANs/VIctory-RTX` (`e49340b` / `readmet3xt-lab/foxhound` #418, GPL-3.0),
  and `upsidedownstack/VIctory-Performance` (`487fc68`, GPL-3.0)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 17:27:37 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-12-03 17:35 UTC · original

Triage (101dc008, CI check PASS — run 47161327469):

  • Clean, 100% title-neutral 4-part port (+1,416/-66 across 12 files) with zero opt-in toggles (all new VICTORY_* guards are default-on =0 kill-switches):
    1. Critical #396 hang fix (opt.rs, mod.rs): pins natural loop headers and irreducible RPO back-edge targets in srv_memory_regions() before !has_writes && !has_loops so DOM_LOADS cannot hoist/merge SRV loads across spin-wait polling loops.
    2. VICTORY_CUDA_PRELOAD (window.rs, streamline.rs, upload.rs, xmem.rs): fences title address window [4 GiB, 2^37) during cuInit(0) when DLSS/FG is active; no-op on non-NVIDIA GPUs.
    3. Ambient reflections (ambient.rs): specular CLEAN luminance cap (1.5), chroma_scrub (WORDS = 18, fixed without_depth()), and Role::Miss gather reuse in Set::Estimate.
    4. RT-off BVH stubs & dead compute skips (xboxbvh.rs, run.rs, pipeline.rs, draw.rs): stubs 8 GPU XboxBvhBuilder.dll build/copy/rehydrate/validate exports and skips DeadRt::Resolve / DeadRt::Feeds when RT is completely off.
  • Holding auto-merge for Gate 2 Deep Reasoning Audit (#282) + Gate 3 live GPU verification:
    • Gate 2 focus: (a) srv_memory_regions back-edge pinning soundness, (b) window::Fence VirtualFree cleanup on all exit paths & lock ordering with upload/xmem, (c) ambient.rs WORDS = 18 root-constant binding across all callers + miss_needs_gather lifetime, and (d) confirming DeadRt::Feeds (CSComputeSkinning, CSGenerateHairVB) are strictly RT-only feeds that cannot regress RT-off character skinning or hair rendering.
    • Gate 3 focus: plain---release A/B vs main (21fcafdc) + --features diagnostics visual PNGs (characters, hair, reflections, ambient lighting, 0 hangs/DRED) + quick VICTORY_HW_RT=1 non-regression smoke.
**@⁠Androtim** on GitHub · 2026-12-03 17:35 UTC · [original](https://github.com/Androtim/MiniVI/pull/401#issuecomment-7386762845) Triage (`101dc008`, **CI `check` PASS** — run `47161327469`): - Clean, 100% title-neutral 4-part port (`+1,416/-66` across 12 files) with **zero opt-in toggles** (all new `VICTORY_*` guards are default-on `=0` kill-switches): 1. **Critical `#396` hang fix (`opt.rs`, `mod.rs`):** pins natural loop headers and irreducible RPO back-edge targets in `srv_memory_regions()` before `!has_writes && !has_loops` so `DOM_LOADS` cannot hoist/merge SRV loads across spin-wait polling loops. 2. **`VICTORY_CUDA_PRELOAD` (`window.rs`, `streamline.rs`, `upload.rs`, `xmem.rs`):** fences title address window `[4 GiB, 2^37)` during `cuInit(0)` when DLSS/FG is active; no-op on non-NVIDIA GPUs. 3. **Ambient reflections (`ambient.rs`):** specular `CLEAN` luminance cap (`1.5`), `chroma_scrub` (`WORDS = 18`, fixed `without_depth()`), and `Role::Miss` gather reuse in `Set::Estimate`. 4. **RT-off BVH stubs & dead compute skips (`xboxbvh.rs`, `run.rs`, `pipeline.rs`, `draw.rs`):** stubs 8 GPU `XboxBvhBuilder.dll` build/copy/rehydrate/validate exports and skips `DeadRt::Resolve` / `DeadRt::Feeds` when RT is completely off. - Holding auto-merge for **Gate 2 Deep Reasoning Audit (`#282`)** + **Gate 3 live GPU verification**: - **Gate 2 focus:** (a) `srv_memory_regions` back-edge pinning soundness, (b) `window::Fence` `VirtualFree` cleanup on all exit paths & lock ordering with `upload`/`xmem`, (c) `ambient.rs` `WORDS = 18` root-constant binding across all callers + `miss_needs_gather` lifetime, and (d) confirming `DeadRt::Feeds` (`CSComputeSkinning`, `CSGenerateHairVB`) are strictly RT-only feeds that cannot regress RT-off character skinning or hair rendering. - **Gate 3 focus:** plain-`--release` A/B vs `main` (`21fcafdc`) + `--features diagnostics` visual PNGs (characters, hair, reflections, ambient lighting, 0 hangs/DRED) + quick `VICTORY_HW_RT=1` non-regression smoke.
Author
Owner

@⁠Androtim on GitHub · 2026-12-03 19:32 UTC · original

Marking triage: needs rebase after #402 (158fba11) merged onto main (overlapping ambient.rs). Once rebased cleanly with green CI, ready for Gate 2 + Gate 3 GPU verification.

**@⁠Androtim** on GitHub · 2026-12-03 19:32 UTC · [original](https://github.com/Androtim/MiniVI/pull/401#issuecomment-7389860605) Marking `triage: needs rebase` after `#402` (`158fba11`) merged onto `main` (overlapping `ambient.rs`). Once rebased cleanly with green CI, ready for Gate 2 + Gate 3 GPU verification.
github-bot changed target branch from main to gh-pr/401/base 2026-12-03 19:46:55 +00:00
github manually merged commit dafed46126 into gh-pr/401/base 2026-12-03 19:46:57 +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/Androtim--MiniVI!401
No description provided.