Retail title on NVIDIA: root-cause fixes log (each with its cause, evidence and code) #2952

Open
opened 2026-11-27 03:58:02 +00:00 by github-bot · 9 comments
Owner

@⁠claudetools-gh on GitHub · 2026-11-27 03:56 UTC · original

A running log of fixes for the retail title where the root cause is shown, the fix is on by default (not behind an env switch), and the result was measured in the world on our machine. Each entry is its own comment below, with the cause, the evidence, the fix (code in the comment when it is ours and small) and what was ruled out. This issue gets updated as entries land.

The goal is that others can take a fix as it is, instead of collecting switches. Workarounds that only hide a symptom (refusing programs, budgets that drop work, barriers added "because it stops hanging") do not go here. If you have an entry of that kind, or a correction to one of ours, please add it in the same format.

Machine: RTX 5070 Ti 16 GB (driver 621.01), Ryzen 7 9700X, 62 GB RAM, Windows 11 26300, render 2560x1440. Tree: nvidia-dev-based lab tree (MacieGx's lab plus our changes).

# Fix Area Effect measured here
1 Loading-art flicker: write guards for cold blocks title_textures.rs 96 flashes in 50 s → 0 in 85 s
2 Direct DXIL division: overflowed quotient gives ±Inf, v_div_fmas_f32 scales by VCC dxil/prelude.rs, dxil/lower_valu.rs GPU tests in both backends; no visual change in the cell
3 Preparation builds a split program's whole form first shaders.rs 0 chained dispatches in every world run
4 Single-record clamp without the 1,024-thread scan indirect_clamp.hlsl/.rs 137 → 135 ms a frame, byte-identical output
5 Map of GPU-written memory waits only for the copy backs it overlaps sparse.rs 5.2 → 7.3 fps (195 → 137 ms; corrected numbers)
6 Pipeline caches replaced a pipeline lists still used (world-entry hang); two-pass draws recorded in batches, on by default bind.rs hang gone with the race still happening; 135 → 103–109 ms a frame

AI-assisted.

**@⁠claudetools-gh** on GitHub · 2026-11-27 03:56 UTC · [original](https://github.com/xcl-dev/xcl/issues/2952) A running log of fixes for the retail title where the **root cause is shown**, the fix is **on by default** (not behind an env switch), and the result was **measured in the world** on our machine. Each entry is its own comment below, with the cause, the evidence, the fix (code in the comment when it is ours and small) and what was ruled out. This issue gets updated as entries land. The goal is that others can take a fix as it is, instead of collecting switches. Workarounds that only hide a symptom (refusing programs, budgets that drop work, barriers added "because it stops hanging") do not go here. If you have an entry of that kind, or a correction to one of ours, please add it in the same format. **Machine:** RTX 5070 Ti 16 GB (driver 621.01), Ryzen 7 9700X, 62 GB RAM, Windows 11 26300, render 2560x1440. **Tree:** `nvidia-dev`-based lab tree (MacieGx's lab plus our changes). | # | Fix | Area | Effect measured here | |---|---|---|---| | [1](https://git.gtahub.st/github/xcl-dev--xcl/issues/2952) | Loading-art flicker: write guards for cold blocks | `title_textures.rs` | 96 flashes in 50 s → 0 in 85 s | | [2](https://git.gtahub.st/github/xcl-dev--xcl/issues/2952) | Direct DXIL division: overflowed quotient gives ±Inf, `v_div_fmas_f32` scales by VCC | `dxil/prelude.rs`, `dxil/lower_valu.rs` | GPU tests in both backends; no visual change in the cell | | [3](https://git.gtahub.st/github/xcl-dev--xcl/issues/505) | Preparation builds a split program's whole form first | `shaders.rs` | 0 chained dispatches in every world run | | [4](https://git.gtahub.st/github/xcl-dev--xcl/issues/2952) | Single-record clamp without the 1,024-thread scan | `indirect_clamp.hlsl/.rs` | 137 → 135 ms a frame, byte-identical output | | [5](https://git.gtahub.st/github/xcl-dev--xcl/issues/505) | `Map` of GPU-written memory waits only for the copy backs it overlaps | `sparse.rs` | 5.2 → 7.3 fps (195 → 137 ms; [corrected numbers](https://git.gtahub.st/github/xcl-dev--xcl/issues/505)) | | [6](https://git.gtahub.st/github/xcl-dev--xcl/issues/2952) | Pipeline caches replaced a pipeline lists still used (world-entry hang); two-pass draws recorded in batches, on by default | `bind.rs` | hang gone with the race still happening; 135 → 103–109 ms a frame | AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:58:02 +00:00
Author
Owner

@⁠claudetools-gh on GitHub · 2026-11-27 03:56 UTC · original

1. Loading-art flicker: the first write to a cold block reaches the GPU unseen

Symptom. On the loading art, single frames of black or of the background without the character layer, in a cycle of about 216 frames (96 flashes in 50 s here). Reported also on an RTX 4080 (#2572) and an RTX 3090 (#2917).

Cause. 7c18bc41 (on nvidia-dev, not on main) makes each look for CPU writes before a submit take only the 2 MiB blocks written in the last hot_for (1,500 ms), while a background walk finds writes to the other blocks later. A block that has gone cold and gets written just before a submit is uploaded late: the GPU reads the stale copy for that frame. Evidence: XCL_WATCH_HOT=0 gives 0 flashes in 85 s, and XCL_WATCH_HOT_MS=10000 also removes them, at a cost in fps.

Fix (ours, default on): write guards on cold blocks. A block that leaves the hot set is set PAGE_READONLY by a guard thread. The next look reads its write-watch bits one last time, then leaves it alone. The first write to it faults into a lock-free vectored handler, which makes the block writable again, puts it back in the hot set and lets the write retry. So the looks stay as cheap as with 7c18bc41, and no first write is missed.

XCL's own writers have to open the blocks first: ReadFile (including OVERLAPPED), DirectStorage, physical-page copies and CLZERO emulation. The VirtualProtect/Alloc/Free/Query hooks and cpu_writes know about the guards too, and the title's protect/commit/free calls pin the blocks across the call. About 1,500 lines over 13 files, so we describe it rather than paste it. Ask if you want a part of it.

Measured: 0 flashes in 85 s and 0 leaks (no block left writable without being hot), with no fps cost against hot looks. The simpler alternative, if you don't need the hot-look speed, is MacieGx's 240037e7, which turns hot looks off by default.

AI-assisted.

**@⁠claudetools-gh** on GitHub · 2026-11-27 03:56 UTC · [original](https://github.com/xcl-dev/xcl/issues/2952#issuecomment-7209397166) ### 1. Loading-art flicker: the first write to a cold block reaches the GPU unseen **Symptom.** On the loading art, single frames of black or of the background without the character layer, in a cycle of about 216 frames (96 flashes in 50 s here). Reported also on an RTX 4080 (#2572) and an RTX 3090 (#2917). **Cause.** `7c18bc41` (on `nvidia-dev`, not on `main`) makes each look for CPU writes before a submit take only the 2 MiB blocks written in the last `hot_for` (1,500 ms), while a background walk finds writes to the other blocks later. A block that has gone cold and gets written just before a submit is uploaded late: the GPU reads the stale copy for that frame. Evidence: `XCL_WATCH_HOT=0` gives 0 flashes in 85 s, and `XCL_WATCH_HOT_MS=10000` also removes them, at a cost in fps. **Fix (ours, default on): write guards on cold blocks.** A block that leaves the hot set is set `PAGE_READONLY` by a guard thread. The next look reads its write-watch bits one last time, then leaves it alone. The first write to it faults into a lock-free vectored handler, which makes the block writable again, puts it back in the hot set and lets the write retry. So the looks stay as cheap as with `7c18bc41`, and no first write is missed. XCL's own writers have to open the blocks first: `ReadFile` (including OVERLAPPED), DirectStorage, physical-page copies and CLZERO emulation. The `VirtualProtect`/`Alloc`/`Free`/`Query` hooks and `cpu_writes` know about the guards too, and the title's protect/commit/free calls pin the blocks across the call. About 1,500 lines over 13 files, so we describe it rather than paste it. Ask if you want a part of it. **Measured:** 0 flashes in 85 s and 0 leaks (no block left writable without being hot), with no fps cost against hot looks. The simpler alternative, if you don't need the hot-look speed, is MacieGx's `240037e7`, which turns hot looks off by default. AI-assisted.
Author
Owner

@⁠claudetools-gh on GitHub · 2026-11-27 03:56 UTC · original · edited 2026-11-27 07:31 UTC

Correction (2026-11-27): the v_div_fmas_f32 part below follows #1144 in scaling by a fixed 2^32 when VCC is set. As @⁠KDenKC showed (#1144), AMD hardware tests (tinygrad, MIT) expect 2^64·fma when exponent(S2) > 127 and 2^-64·fma otherwise: the factor that undoes v_div_scale_f32's ±64. Here it has no effect today, because our v_div_scale_f32 never sets VCC. We are fixing it to the ±64 rule, with tinygrad's two vectors as tests, and will update this entry. The div_fixup part stands.

2. Direct DXIL division: an overflowed quotient became NaN

Cause. The direct translator's v_div_scale_f32 returns its source unscaled and clears VCC, so the f32 division sequence (rcp, Newton fmas, v_div_fmas, v_div_fixup) can overflow where the hardware's scaled sequence never does. q = n·rcp(d) becomes Inf, the next fma(-d, q, n) gives -Inf, and the step after that gives NaN. div_fixup then returned that NaN for finite operands. #1144 fixed div_fixup and v_div_fmas_f32 in the HLSL path only; with XCL_DIRECT_DXIL=1 the bug stayed. A NaN in HDR shows as black and spreads through bloom, so we checked it.

Fix. #1144's rules, ported to dxil/prelude.rs (div_fixup). Each select wins over the ones before it:

pub fn div_fixup(&mut self, q: Value, d: Value, n: Value) -> Value {
    let (qu, du, nu) = (self.bits(q), self.bits(d), self.bits(n));
    let abs = self.c(0x7FFF_FFFF);
    let (qa, da, na) = (self.and(qu, abs), self.and(du, abs), self.and(nu, abs));
    let x = self.xor(du, nu);
    let top = self.c(0x8000_0000);
    let sign = self.and(x, top);
    let inf = self.c(0x7F80_0000);
    let zero = self.c(0);
    let quiet = self.c(0x0040_0000);
    let signed_inf = self.or(sign, inf);
    let mut r = self.or(sign, qa);
    let q_nan = self.cmp(Pred::UGt, qa, inf);
    r = self.sel(q_nan, signed_inf, r); // overflowed quotient: ±Inf
    let ff = self.c(0xFF);
    let nsh = self.lshrc(nu, 23);
    let en = self.and(nsh, ff);
    let dsh = self.lshrc(du, 23);
    let ed = self.and(dsh, ff);
    let k150 = self.c(150);
    let en150 = self.add(en, k150);
    let under = self.cmp(Pred::ULt, en150, ed);
    r = self.sel(under, sign, r); // exponent gap under -150: ±0
    let d_inf = self.cmp(Pred::Eq, da, inf);
    let n_zero = self.cmp(Pred::Eq, na, zero);
    let to_zero = self.lor(d_inf, n_zero);
    r = self.sel(to_zero, sign, r); // x/Inf, 0/x
    let d_zero = self.cmp(Pred::Eq, da, zero);
    let n_inf = self.cmp(Pred::Eq, na, inf);
    let to_inf = self.lor(d_zero, n_inf);
    r = self.sel(to_inf, signed_inf, r); // x/0, Inf/x
    let zz = self.land(d_zero, n_zero);
    let ii = self.land(d_inf, n_inf);
    let invalid = self.lor(zz, ii);
    let nan = self.c(0xFFC0_0000);
    r = self.sel(invalid, nan, r); // 0/0, Inf/Inf
    let d_nan = self.cmp(Pred::UGt, da, inf);
    let dq = self.or(du, quiet);
    r = self.sel(d_nan, dq, r);
    let n_nan = self.cmp(Pred::UGt, na, inf);
    let nq = self.or(nu, quiet);
    r = self.sel(n_nan, nq, r); // NaN operands, the numerator's first
    self.f(r)
}

In dxil/lower_valu.rs, both forms of v_div_fmas_f32 (the plain one and the rounding-mode one) now read VCC (u.get(3), Src::Pair) and select ldexp_f(r, 32) for lanes where it is set, as the HLSL path does since #1144.

Tested: #1144's gpu_div_fixup_f32_special_cases_and_sign and gpu_div_fmas_f32_scales_by_vcc pass with and without XCL_DIRECT_DXIL=1 (3/3 in each). The VCC test failed on the direct path before the change.

Not a fix for our dark cell. The black window stayed the same. A follow-up for quotients that come out as 0 or Inf from an unscaled reciprocal will be its own entry once it is measured in the world.

AI-assisted.

**@⁠claudetools-gh** on GitHub · 2026-11-27 03:56 UTC · [original](https://github.com/xcl-dev/xcl/issues/2952#issuecomment-7209397473) · edited 2026-11-27 07:31 UTC > **Correction (2026-11-27):** the `v_div_fmas_f32` part below follows #1144 in scaling by a fixed `2^32` when VCC is set. As @⁠KDenKC showed (https://git.gtahub.st/github/xcl-dev--xcl/pulls/1144), AMD hardware tests (tinygrad, MIT) expect `2^64·fma` when `exponent(S2) > 127` and `2^-64·fma` otherwise: the factor that undoes `v_div_scale_f32`'s `±64`. Here it has no effect today, because our `v_div_scale_f32` never sets VCC. We are fixing it to the ±64 rule, with tinygrad's two vectors as tests, and will update this entry. The `div_fixup` part stands. ### 2. Direct DXIL division: an overflowed quotient became NaN **Cause.** The direct translator's `v_div_scale_f32` returns its source unscaled and clears VCC, so the f32 division sequence (`rcp`, Newton fmas, `v_div_fmas`, `v_div_fixup`) can overflow where the hardware's scaled sequence never does. `q = n·rcp(d)` becomes Inf, the next `fma(-d, q, n)` gives -Inf, and the step after that gives NaN. `div_fixup` then returned that NaN for finite operands. #1144 fixed `div_fixup` and `v_div_fmas_f32` in the HLSL path only; with `XCL_DIRECT_DXIL=1` the bug stayed. A NaN in HDR shows as black and spreads through bloom, so we checked it. **Fix.** #1144's rules, ported to `dxil/prelude.rs` (`div_fixup`). Each select wins over the ones before it: ```rust pub fn div_fixup(&mut self, q: Value, d: Value, n: Value) -> Value { let (qu, du, nu) = (self.bits(q), self.bits(d), self.bits(n)); let abs = self.c(0x7FFF_FFFF); let (qa, da, na) = (self.and(qu, abs), self.and(du, abs), self.and(nu, abs)); let x = self.xor(du, nu); let top = self.c(0x8000_0000); let sign = self.and(x, top); let inf = self.c(0x7F80_0000); let zero = self.c(0); let quiet = self.c(0x0040_0000); let signed_inf = self.or(sign, inf); let mut r = self.or(sign, qa); let q_nan = self.cmp(Pred::UGt, qa, inf); r = self.sel(q_nan, signed_inf, r); // overflowed quotient: ±Inf let ff = self.c(0xFF); let nsh = self.lshrc(nu, 23); let en = self.and(nsh, ff); let dsh = self.lshrc(du, 23); let ed = self.and(dsh, ff); let k150 = self.c(150); let en150 = self.add(en, k150); let under = self.cmp(Pred::ULt, en150, ed); r = self.sel(under, sign, r); // exponent gap under -150: ±0 let d_inf = self.cmp(Pred::Eq, da, inf); let n_zero = self.cmp(Pred::Eq, na, zero); let to_zero = self.lor(d_inf, n_zero); r = self.sel(to_zero, sign, r); // x/Inf, 0/x let d_zero = self.cmp(Pred::Eq, da, zero); let n_inf = self.cmp(Pred::Eq, na, inf); let to_inf = self.lor(d_zero, n_inf); r = self.sel(to_inf, signed_inf, r); // x/0, Inf/x let zz = self.land(d_zero, n_zero); let ii = self.land(d_inf, n_inf); let invalid = self.lor(zz, ii); let nan = self.c(0xFFC0_0000); r = self.sel(invalid, nan, r); // 0/0, Inf/Inf let d_nan = self.cmp(Pred::UGt, da, inf); let dq = self.or(du, quiet); r = self.sel(d_nan, dq, r); let n_nan = self.cmp(Pred::UGt, na, inf); let nq = self.or(nu, quiet); r = self.sel(n_nan, nq, r); // NaN operands, the numerator's first self.f(r) } ``` In `dxil/lower_valu.rs`, both forms of `v_div_fmas_f32` (the plain one and the rounding-mode one) now read VCC (`u.get(3)`, `Src::Pair`) and select `ldexp_f(r, 32)` for lanes where it is set, as the HLSL path does since #1144. **Tested:** #1144's `gpu_div_fixup_f32_special_cases_and_sign` and `gpu_div_fmas_f32_scales_by_vcc` pass with and without `XCL_DIRECT_DXIL=1` (3/3 in each). The VCC test failed on the direct path before the change. **Not a fix for our dark cell.** The black window stayed the same. A follow-up for quotients that come out as 0 or Inf from an unscaled reciprocal will be its own entry once it is measured in the world. AI-assisted.
Author
Owner

@⁠claudetools-gh on GitHub · 2026-11-27 03:56 UTC · original

4. Single-record clamp: no 1,024-thread scan for one 12-byte record

Cause. Each two-pass mesh draw of this title (~3,700 a frame, all single-record ExecuteIndirect(DispatchMesh) with no count buffer) bounds its record with indirect_clamp.hlsl's main: one group of 1,024 threads, a prefix scan and about 23 group syncs, all for one record.

Fix. A second entry point in indirect_clamp.hlsl, chosen in bound_within when max == 1 && count_buf == 0. Its output is exactly what main gives for that case: the inclusive sum of a single record is its own work.

[numthreads(1, 1, 1)]
void single_record() {
    for (uint k = 0; k < stride; k += 4)
        bounded.Store(k, source.Load(source_at + k));
    uint3 a = source.Load3(source_at + action_at);
    uint work = clamp_args(a);
    if (work > budget) {
        if ((kind & 0xFF) <= 1)
            a.y = 0;
        else
            a = uint3(0, 0, 0);
    }
    bounded.Store3(action_at, a);
}

The pipeline is made on first use from the same root signature, and falls back to main if it fails.

Tested: a GPU test runs both entry points over 8 cases and compares every output byte: a normal record, garbage (0xFFFFFFFF), zero, over budget, exactly at budget, fold, and draws with fields outside the action.

Measured: in the world, frames 3000–3600 take 134–135 ms against 137 ms. It is small, but it holds across runs.

AI-assisted.

**@⁠claudetools-gh** on GitHub · 2026-11-27 03:56 UTC · [original](https://github.com/xcl-dev/xcl/issues/2952#issuecomment-7209397779) ### 4. Single-record clamp: no 1,024-thread scan for one 12-byte record **Cause.** Each two-pass mesh draw of this title (~3,700 a frame, all single-record `ExecuteIndirect(DispatchMesh)` with no count buffer) bounds its record with `indirect_clamp.hlsl`'s `main`: one group of 1,024 threads, a prefix scan and about 23 group syncs, all for one record. **Fix.** A second entry point in `indirect_clamp.hlsl`, chosen in `bound_within` when `max == 1 && count_buf == 0`. Its output is exactly what `main` gives for that case: the inclusive sum of a single record is its own work. ```hlsl [numthreads(1, 1, 1)] void single_record() { for (uint k = 0; k < stride; k += 4) bounded.Store(k, source.Load(source_at + k)); uint3 a = source.Load3(source_at + action_at); uint work = clamp_args(a); if (work > budget) { if ((kind & 0xFF) <= 1) a.y = 0; else a = uint3(0, 0, 0); } bounded.Store3(action_at, a); } ``` The pipeline is made on first use from the same root signature, and falls back to `main` if it fails. **Tested:** a GPU test runs both entry points over 8 cases and compares every output byte: a normal record, garbage (`0xFFFFFFFF`), zero, over budget, exactly at budget, fold, and draws with fields outside the action. **Measured:** in the world, frames 3000–3600 take 134–135 ms against 137 ms. It is small, but it holds across runs. AI-assisted.
Author
Owner

@⁠SergeAx on GitHub · 2026-11-27 06:24 UTC · original

Item 1 confirmed on an RTX 5080 16 GB (driver 621.14, Windows 10 22H2): nvidia-dev ecc0bb57 + #2929 + #1435, release, warm caches.

  • With the defaults, the loading art shows single black frames, in the same pattern every run.
  • XCL_WATCH_HOT=0 alone removes them. The run before it, with XCL_WATCH_HOT=0 and two other changes, had none either.
  • These did not remove them, one run each: XCL_PAGE_MAPPINGS=0, XCL_DISPATCH_LOOP_BUDGET=0, XCL_DS_KNOWN_WRITES=0, and title texture uploads back on XCL's own queue (a local switch that makes title_queue_for return None, as before 124ccfb1).
  • A bisect of nvidia-dev against main b49be18 (good) found them already at 41303e41 (24 November 23:54), which contains 7c18bc41.

The black frames were judged by eye, watching the loading screen in each run.

AI use: Claude Code (Claude Opus 5.5) built the trees, ran the title, set up the bisect and wrote this; the user watched the screen.

**@⁠SergeAx** on GitHub · 2026-11-27 06:24 UTC · [original](https://github.com/xcl-dev/xcl/issues/2952#issuecomment-7211503717) Item 1 confirmed on an RTX 5080 16 GB (driver 621.14, Windows 10 22H2): `nvidia-dev` `ecc0bb57` + #2929 + #1435, release, warm caches. - With the defaults, the loading art shows single black frames, in the same pattern every run. - `XCL_WATCH_HOT=0` alone removes them. The run before it, with `XCL_WATCH_HOT=0` and two other changes, had none either. - These did not remove them, one run each: `XCL_PAGE_MAPPINGS=0`, `XCL_DISPATCH_LOOP_BUDGET=0`, `XCL_DS_KNOWN_WRITES=0`, and title texture uploads back on XCL's own queue (a local switch that makes `title_queue_for` return `None`, as before `124ccfb1`). - A bisect of `nvidia-dev` against `main` `b49be18` (good) found them already at `41303e41` (24 November 23:54), which contains `7c18bc41`. The black frames were judged by eye, watching the loading screen in each run. AI use: Claude Code (Claude Opus 5.5) built the trees, ran the title, set up the bisect and wrote this; the user watched the screen.
Author
Owner

@⁠KDenKC on GitHub · 2026-11-27 06:30 UTC · original · edited 2026-11-27 06:50 UTC

On entry 2 (direct-DXIL division), after reading the lowering at main c2ee10e4 and nvidia-dev a5e2d851: the cause is on both pins. gpu/dxil/lower_valu.rs:1015-1022 passes v_div_scale_f32's selected input through and clears the lane mask, and :630-636 / :1117-1120 emit v_div_fmas_f32 with no VCC post-scale.

Your div_fixup change fixes the special-value result bits, but DIV_SCALE stays unscaled, so the sequence still overflows before fixup sees it. Two inputs where the result still differs from hardware (static; no GPU probe yet):

  • n = d = 2^-130, with f32 denormals preserved. The true quotient is 1. Unscaled, rcp(2^-130) = 2^130 overflows to +inf, then fma(-d, inf, 1) = -inf and fma(-inf, inf, inf) = NaN. The patched fixup maps that NaN to +inf. Hardware prescales because the denominator is subnormal and never produces that NaN.
  • DIV_FMAS with VCC set: scaling the already-rounded FMA isn't the same as scaling inside the fused operation. For 2^-126 * 2^-30 + 0, the f32 intermediate 2^-156 rounds to zero even with denormals kept, so scaling it afterwards stays 0, while the fused, scaled result is 2^-124 (prelude.rs:156-173's ldexp_f keeps the zero).

So a complete fix needs DIV_SCALE's prescale and its VCC output, and a post-scale inside the FMA. Related: #1144 (eac652c3) is HLSL-only. Its direct-DXIL follow-up was posted inline there (#1144) but isn't in the head. Raw-bit outputs from an AMD hardware probe for all three opcodes would make a fixture for either path; we can run the same fixture through direct DXIL on an RTX 5090, both f32 denorm modes.

On entry 1: on main this is covered by #2934 (c230aa1b, opt-in watch trap: fault recovery, I/O pins, final look). The cold-block gap itself comes from 7c18bc41, which only nvidia-dev has.

AI use: Codex (GPT-6.2-Sol) reviewed the code and worked out the cases; Claude Code (Claude Opus 5.5) checked the arithmetic and wrote this comment.

Update: the ldexp_f(r, 32) in the entry-2 patch (and in #1144) is likely the wrong factor for the hardware: tinygrad's AMD hardware tests expect 2^64 or 2^-64 by exponent(S2) > 127. Details on #1144: #1144

**@⁠KDenKC** on GitHub · 2026-11-27 06:30 UTC · [original](https://github.com/xcl-dev/xcl/issues/2952#issuecomment-7211584196) · edited 2026-11-27 06:50 UTC On entry 2 (direct-DXIL division), after reading the lowering at `main` `c2ee10e4` and `nvidia-dev` `a5e2d851`: the cause is on both pins. `gpu/dxil/lower_valu.rs:1015-1022` passes `v_div_scale_f32`'s selected input through and clears the lane mask, and `:630-636` / `:1117-1120` emit `v_div_fmas_f32` with no VCC post-scale. Your `div_fixup` change fixes the special-value result bits, but `DIV_SCALE` stays unscaled, so the sequence still overflows before fixup sees it. Two inputs where the result still differs from hardware (static; no GPU probe yet): - `n = d = 2^-130`, with f32 denormals preserved. The true quotient is `1`. Unscaled, `rcp(2^-130) = 2^130` overflows to `+inf`, then `fma(-d, inf, 1) = -inf` and `fma(-inf, inf, inf) = NaN`. The patched fixup maps that NaN to `+inf`. Hardware prescales because the denominator is subnormal and never produces that NaN. - `DIV_FMAS` with VCC set: scaling the already-rounded FMA isn't the same as scaling inside the fused operation. For `2^-126 * 2^-30 + 0`, the f32 intermediate `2^-156` rounds to zero even with denormals kept, so scaling it afterwards stays `0`, while the fused, scaled result is `2^-124` (`prelude.rs:156-173`'s `ldexp_f` keeps the zero). So a complete fix needs `DIV_SCALE`'s prescale and its VCC output, and a post-scale inside the FMA. Related: #1144 (`eac652c3`) is HLSL-only. Its direct-DXIL follow-up was posted inline there (https://git.gtahub.st/github/xcl-dev--xcl/pulls/1144) but isn't in the head. Raw-bit outputs from an AMD hardware probe for all three opcodes would make a fixture for either path; we can run the same fixture through direct DXIL on an RTX 5090, both f32 denorm modes. On entry 1: on main this is covered by #2934 (`c230aa1b`, opt-in watch trap: fault recovery, I/O pins, final look). The cold-block gap itself comes from `7c18bc41`, which only `nvidia-dev` has. AI use: Codex (GPT-6.2-Sol) reviewed the code and worked out the cases; Claude Code (Claude Opus 5.5) checked the arithmetic and wrote this comment. **Update:** the `ldexp_f(r, 32)` in the entry-2 patch (and in #1144) is likely the wrong factor for the hardware: tinygrad's AMD hardware tests expect `2^64` or `2^-64` by `exponent(S2) > 127`. Details on #1144: https://git.gtahub.st/github/xcl-dev--xcl/pulls/1144
Author
Owner

@⁠claudetools-gh on GitHub · 2026-11-27 08:53 UTC · original

6. Pipeline caches replaced a pipeline that lists were still using: GPU hang at world entry (and two-pass batching)

Symptom. At world entry, 0x887a0006 (DEVICE_HUNG) a few seconds after the first frames that used a compute pipeline from one of XCL's internal per-device caches. It depended on timing: some runs hung and others didn't, on the same build.

Cause. Several of XCL's helper pipelines are cached per device with a check-then-insert:

if let Some(pair) = CACHE.lock().unwrap().as_ref().and_then(|m| m.get(&key).cloned()) { return Ok(pair); }
// ... build rs + pso ...
CACHE.lock().unwrap().get_or_insert_with(HashMap::new).insert(key, (rs.clone(), pso.clone()));

The failing sequence:

  1. Two threads find the cache empty at the same time, and each builds its own pipeline.
  2. Each records its lists with the pipeline it built.
  3. The second insert replaces the first thread's pipeline. The cache held the only lasting reference, and D3D12 does not keep a pipeline alive for the command lists that use it.
  4. When those lists run, they execute with a freed pipeline, and the GPU hangs.

It only happens when the first uses come from several threads within the same millisecond, which is what a title's world entry does.

Evidence.

  • This showed up with our two-pass batching (below), whose packing pipeline had the same cache. Every run whose first batches were recorded on 3–5 threads at once hung; every run where they started on one thread survived. That held for 4 runs out of 4 on each side, including one run with an extra barrier that we had wrongly taken for a fix.
  • A GPU test that builds the pipeline on 8 threads at once against a fresh device got 5 different pipelines, while the cache kept only 1. With the fix, all 8 get the same one.
  • In the game, after the fix, the race still happens ("made on threads at once" is logged twice at world entry), and nothing hangs. We checked 3 runs.

Fix. The first pipeline put in the cache wins, and every thread uses that one. A pipeline built at the same moment on another thread is dropped before any list records with it.

fn cached_or<K: std::hash::Hash + Eq, V: Clone>(cache: &Mutex<Option<HashMap<K, V>>>, key: K, made: V) -> V {
    cache.lock().unwrap().get_or_insert_with(HashMap::new).entry(key).or_insert(made).clone()
}
// ... build rs + pso ...
Ok(cached_or(&CACHE, key, (rs, pso)))

Upstream. nvidia-dev (eae01502 and later) has the same pattern in scale_indirect_pipeline (bind.rs, the insert(key, (rs.clone(), pso.clone())) after building the scale PSO). It is used by two-pass ExecuteIndirects of more than one record, whose first uses at world entry also come from several threads. We have not measured whether it causes any of the world-entry hangs reported here, but it is a use-after-free of a pipeline whenever it races, and the fix is two lines.

What it unlocked here: two-pass mesh draws recorded in batches, on by default. The title issues ~3,700 single-record ExecuteIndirect(DispatchMesh) calls a frame. Each one becomes a clamp, a compute pass and a mesh pass, with full drains in between. We now defer up to 32 such calls per list and record them together:

  • each call's record is bounded;
  • a packing compute pass lays the calls' records out in the list's record buffer, by the size they actually need on the GPU;
  • all the compute passes run, then one UAV barrier, then all the mesh passes in the original order, each with its own PSO, stencil ref and blend factor;
  • calls that don't fit spill into later rounds, gated by predication, and a call too big for one round is split by group ranges (a group base in the io block, added by both translators).

The batch is recorded before any other list call that could change what it draws (a per-slot hook). Calls whose console program writes memory other than its records are recorded as a batch of one. In this cell view, 5.2 M calls went into 290 k batches (~18 a batch).

same cell view, frames 3000–3900 ms a frame
before batching 135
batching, warm cache (2 runs) 103–109

Not yet 0: 0.06 % of the calls (~3,300 in 5 min) are still left without room in a batch's rounds, plus a few cut at the last round (one call at the clamp's 2^22-group cap). The fix in progress sizes the rounds by the list's buffer and caps the largest call first. Single-record calls split into 4 mesh groups still take the old per-call path.

AI-assisted.

**@⁠claudetools-gh** on GitHub · 2026-11-27 08:53 UTC · [original](https://github.com/xcl-dev/xcl/issues/2952#issuecomment-7214036990) ### 6. Pipeline caches replaced a pipeline that lists were still using: GPU hang at world entry (and two-pass batching) **Symptom.** At world entry, 0x887a0006 (DEVICE_HUNG) a few seconds after the first frames that used a compute pipeline from one of XCL's internal per-device caches. It depended on timing: some runs hung and others didn't, on the same build. **Cause.** Several of XCL's helper pipelines are cached per device with a check-then-insert: ```rust if let Some(pair) = CACHE.lock().unwrap().as_ref().and_then(|m| m.get(&key).cloned()) { return Ok(pair); } // ... build rs + pso ... CACHE.lock().unwrap().get_or_insert_with(HashMap::new).insert(key, (rs.clone(), pso.clone())); ``` The failing sequence: 1. Two threads find the cache empty at the same time, and each builds its own pipeline. 2. Each records its lists with the pipeline it built. 3. The second `insert` replaces the first thread's pipeline. The cache held the only lasting reference, and D3D12 does not keep a pipeline alive for the command lists that use it. 4. When those lists run, they execute with a freed pipeline, and the GPU hangs. It only happens when the first uses come from several threads within the same millisecond, which is what a title's world entry does. **Evidence.** - This showed up with our two-pass batching (below), whose packing pipeline had the same cache. Every run whose first batches were recorded on 3–5 threads at once hung; every run where they started on one thread survived. That held for 4 runs out of 4 on each side, including one run with an extra barrier that we had wrongly taken for a fix. - A GPU test that builds the pipeline on 8 threads at once against a fresh device got 5 different pipelines, while the cache kept only 1. With the fix, all 8 get the same one. - In the game, after the fix, the race still happens ("made on threads at once" is logged twice at world entry), and nothing hangs. We checked 3 runs. **Fix.** The first pipeline put in the cache wins, and every thread uses that one. A pipeline built at the same moment on another thread is dropped before any list records with it. ```rust fn cached_or<K: std::hash::Hash + Eq, V: Clone>(cache: &Mutex<Option<HashMap<K, V>>>, key: K, made: V) -> V { cache.lock().unwrap().get_or_insert_with(HashMap::new).entry(key).or_insert(made).clone() } // ... build rs + pso ... Ok(cached_or(&CACHE, key, (rs, pso))) ``` **Upstream.** `nvidia-dev` (`eae01502` and later) has the same pattern in `scale_indirect_pipeline` (`bind.rs`, the `insert(key, (rs.clone(), pso.clone()))` after building the scale PSO). It is used by two-pass ExecuteIndirects of more than one record, whose first uses at world entry also come from several threads. We have not measured whether it causes any of the world-entry hangs reported here, but it is a use-after-free of a pipeline whenever it races, and the fix is two lines. **What it unlocked here: two-pass mesh draws recorded in batches, on by default.** The title issues ~3,700 single-record `ExecuteIndirect(DispatchMesh)` calls a frame. Each one becomes a clamp, a compute pass and a mesh pass, with full drains in between. We now defer up to 32 such calls per list and record them together: - each call's record is bounded; - a packing compute pass lays the calls' records out in the list's record buffer, by the size they actually need on the GPU; - all the compute passes run, then one UAV barrier, then all the mesh passes in the original order, each with its own PSO, stencil ref and blend factor; - calls that don't fit spill into later rounds, gated by predication, and a call too big for one round is split by group ranges (a group base in the io block, added by both translators). The batch is recorded before any other list call that could change what it draws (a per-slot hook). Calls whose console program writes memory other than its records are recorded as a batch of one. In this cell view, 5.2 M calls went into 290 k batches (~18 a batch). | same cell view, frames 3000–3900 | ms a frame | |---|---| | before batching | 135 | | batching, warm cache (2 runs) | **103–109** | **Not yet 0:** 0.06 % of the calls (~3,300 in 5 min) are still left without room in a batch's rounds, plus a few cut at the last round (one call at the clamp's 2^22-group cap). The fix in progress sizes the rounds by the list's buffer and caps the largest call first. Single-record calls split into 4 mesh groups still take the old per-call path. AI-assisted.
Author
Owner

@⁠KDenKC on GitHub · 2026-11-27 09:14 UTC · original

On entry 6: we went through every pipeline and root-signature cache in crates/xcl/src at main 623d02e4 and nvidia-dev 3f39671d (13 caches). scale_indirect_pipeline is the only one with the race, and it's on nvidia-dev only. main has no copy of it.

  • bind.rs ~1835-1853 at 3f39671d builds rs and pso outside CACHE's lock, then calls insert(key, (rs.clone(), pso.clone())), so a second racing build replaces the first.
  • The caller, prepare_scaled_args, keeps only raw pointers: Rewrite { rs: rs.as_raw() as usize, pso: pso.as_raw() as usize, .. }, under the comment "the pair is the device's for good: scale_indirect_pipeline keeps it". Its own rs/pso handles drop at return. So once the replacement drops the first pair, any list recorded with that Rewrite points at a freed PSO and root signature. Your entry(key).or_insert(made) makes the comment true.
  • The other caches are safe against this:
    • Several build under their lock or a OnceLock: dispatch-chain whole forms, the clamp, the compositor, the shader Pipelines signatures, the indirect guard, scatter, and ABI_RS_SAMPLERS.
    • ABI_RS keeps the first one with compare_exchange.
    • DEPTH_BIAS_PSOS re-checks under the lock.
    • The stand-in cache stores Weak, while each shell keeps its own Arc.
    • The two-pass and chain maps key by fresh COM pointers.

Not measured: how often the race fires at world entry, or whether it accounts for any of the reported world-entry hangs on nvidia-dev.

AI use: Gemini (Antigravity) went through the caches; Claude Code (Claude Opus 5.5) checked the vulnerable site and its caller and wrote this comment.

**@⁠KDenKC** on GitHub · 2026-11-27 09:14 UTC · [original](https://github.com/xcl-dev/xcl/issues/2952#issuecomment-7214440521) On entry 6: we went through every pipeline and root-signature cache in `crates/xcl/src` at `main` `623d02e4` and `nvidia-dev` `3f39671d` (13 caches). `scale_indirect_pipeline` is the only one with the race, and it's on `nvidia-dev` only. `main` has no copy of it. - `bind.rs` ~1835-1853 at `3f39671d` builds `rs` and `pso` outside `CACHE`'s lock, then calls `insert(key, (rs.clone(), pso.clone()))`, so a second racing build replaces the first. - The caller, `prepare_scaled_args`, keeps only raw pointers: `Rewrite { rs: rs.as_raw() as usize, pso: pso.as_raw() as usize, .. }`, under the comment "the pair is the device's for good: `scale_indirect_pipeline` keeps it". Its own `rs`/`pso` handles drop at return. So once the replacement drops the first pair, any list recorded with that `Rewrite` points at a freed PSO and root signature. Your `entry(key).or_insert(made)` makes the comment true. - The other caches are safe against this: - Several build under their lock or a `OnceLock`: dispatch-chain whole forms, the clamp, the compositor, the shader `Pipelines` signatures, the indirect guard, scatter, and `ABI_RS_SAMPLERS`. - `ABI_RS` keeps the first one with `compare_exchange`. - `DEPTH_BIAS_PSOS` re-checks under the lock. - The stand-in cache stores `Weak`, while each shell keeps its own `Arc`. - The two-pass and chain maps key by fresh COM pointers. Not measured: how often the race fires at world entry, or whether it accounts for any of the reported world-entry hangs on `nvidia-dev`. AI use: Gemini (Antigravity) went through the caches; Claude Code (Claude Opus 5.5) checked the vulnerable site and its caller and wrote this comment.
Author
Owner

@⁠claudetools-gh on GitHub · 2026-11-27 09:46 UTC · original

@⁠KDenKC thank you, that is a careful review. On each point:

  • Entry 6: good to have the full sweep. One vulnerable site, nvidia-dev only, with the caller keeping raw pointers, makes it a clear two-line fix there.

  • Entry 2: agreed, the first patch only fixed div_fixup's special values. Since then, on our tree:

    • v_div_scale_f32 returns NaN with flag 0 when n or d is ±0, as in the ISA. A pair of non-zero subnormals is prescaled by 2^64 in both passes with the flag kept at 0, since the factor cancels in the quotient. That covers your n = d = 2^-130 case: both become normal and the quotient is 1.
    • v_div_fmas_f32 with VCC uses tinygrad's rule: 2^64 when exponent(S2) > 127, else 2^-64.
    • div_fixup's last resort, when q comes out 0, NaN or Inf for finite non-zero operands, divides normalised magnitudes and puts the exponent and sign back.

    GPU tests run in both backends, with and without XCL_DIRECT_DXIL=1. Your second case stays open: we still scale after the rounded FMA, not inside it, so 2^-126 * 2^-30 + 0 still gives 0. A hardware fixture for the three opcodes would settle the rest. If you have one, we'll run it through our direct-DXIL path on an RTX 5070 Ti and post the bits. Entry 2 gets updated once this has been measured in the game.

  • Entry 1: noted. On main it is the opt-in watch trap of #2934. The gap itself is nvidia-dev's 7c18bc41.

AI-assisted.

**@⁠claudetools-gh** on GitHub · 2026-11-27 09:46 UTC · [original](https://github.com/xcl-dev/xcl/issues/2952#issuecomment-7215083698) @⁠KDenKC thank you, that is a careful review. On each point: - **Entry 6:** good to have the full sweep. One vulnerable site, `nvidia-dev` only, with the caller keeping raw pointers, makes it a clear two-line fix there. - **Entry 2:** agreed, the first patch only fixed `div_fixup`'s special values. Since then, on our tree: - `v_div_scale_f32` returns NaN with flag 0 when `n` or `d` is ±0, as in the ISA. A pair of non-zero subnormals is prescaled by `2^64` in both passes with the flag kept at 0, since the factor cancels in the quotient. That covers your `n = d = 2^-130` case: both become normal and the quotient is 1. - `v_div_fmas_f32` with VCC uses tinygrad's rule: `2^64` when `exponent(S2) > 127`, else `2^-64`. - `div_fixup`'s last resort, when `q` comes out 0, NaN or Inf for finite non-zero operands, divides normalised magnitudes and puts the exponent and sign back. GPU tests run in both backends, with and without `XCL_DIRECT_DXIL=1`. Your second case stays open: we still scale after the rounded FMA, not inside it, so `2^-126 * 2^-30 + 0` still gives 0. A hardware fixture for the three opcodes would settle the rest. If you have one, we'll run it through our direct-DXIL path on an RTX 5070 Ti and post the bits. Entry 2 gets updated once this has been measured in the game. - **Entry 1:** noted. On `main` it is the opt-in watch trap of #2934. The gap itself is `nvidia-dev`'s `7c18bc41`. AI-assisted.
Author
Owner

@⁠KDenKC on GitHub · 2026-11-27 10:08 UTC · original

@⁠claudetools-gh thanks. On the fused case: our local direct-DXIL version applies the ±64 scale before the single rounding of v_div_fmas_f32, rather than scaling the rounded FMA. Its raw-bit GPU test with S0 = 2^-126, S1 = 2^-30, S2 = 0, VCC set, expects 2^-124. It passes on an RTX 5090 (split wave64) and on an AMD RDNA2 iGPU (native wave64), and fails on main. The other fixtures pass the same way: n = d = 2^-130, 0/0, the full LLVM fdiv.f32 sequence against the host's IEEE quotient. We don't have AMD hardware vectors beyond tinygrad's tests. It isn't public yet. Once it's posted, the fixture values are in its tests for your RTX 5070 Ti run.

AI use: Claude Code (Claude Opus 5.5).

**@⁠KDenKC** on GitHub · 2026-11-27 10:08 UTC · [original](https://github.com/xcl-dev/xcl/issues/2952#issuecomment-7215528237) @⁠claudetools-gh thanks. On the fused case: our local direct-DXIL version applies the `±64` scale before the single rounding of `v_div_fmas_f32`, rather than scaling the rounded FMA. Its raw-bit GPU test with `S0 = 2^-126, S1 = 2^-30, S2 = 0`, VCC set, expects `2^-124`. It passes on an RTX 5090 (split wave64) and on an AMD RDNA2 iGPU (native wave64), and fails on `main`. The other fixtures pass the same way: `n = d = 2^-130`, `0/0`, the full LLVM `fdiv.f32` sequence against the host's IEEE quotient. We don't have AMD hardware vectors beyond tinygrad's tests. It isn't public yet. Once it's posted, the fixture values are in its tests for your RTX 5070 Ti run. AI use: Claude Code (Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.