ffx: the upscaler's jitter phase count is never 0 (FFX-JITTER-NEVER-ZERO) #3443

Merged
leonida/mandy
MoonEyes merged 3 commits from fix/ffx-jitter-never-zero into main 2026-12-04 11:29:08 +00:00

Pull request successfully merged and closed

Member

Change

The 0xC0000094 (integer division by zero right after the first upscale) is still reported after #3022 (RTX 5070 Ti,
Series S, DLSS performance). Hypothesis (not measured): the title's upscaler refuses the context, the title keeps a null
context, its jitter phase count query answers 0 and it divides by it.

  • A refused creation (error, no context written, or the title's own create not found) now gives the title a stand-in
    context of ours (non-null, result 0). ffxQuery, ffxDestroyContext and ffxConfigure are bound to ours while the
    dispatch is ours, so the stand-in never reaches the title's DLL; our DLSS/stretch upscale still draws.
  • The jitter phase count query (0x10004; render width then display width, from the public ffx_upscale.h) is passed on; if the DLL answers an error or 0, or the context is the stand-in, the count
    is the public FSR 2 formula ceil(8 * (display/render)^2), min 1, max 4096 (720->1080 = 18, 540->1080 = 32,
    1080->1080 = 8). The jitter offset on a stand-in is the public Halton (2,3) sequence.
  • One warning line the first time the fallback serves (widths and reason, no game data).
  • LEONIDA_FFX_SAFE_JITTER=0 gives back the previous behaviour. switches.md regenerated; note in findings.md.

Tests

  • cargo test -p leonida-hle --locked: 284 passed (new: refused/absent create gives a non-null stand-in and safe
    dispatch/configure/destroy; made context kept; phase formula 18/32/8; phases >= 1 for zero and absurd sizes; query
    never answers 0 with a stand-in, a zero, an error or no DLL function; good DLL answers untouched).
  • cargo check -p leonida --tests, python -I tests/test_d3d12_switches.py, scripts/check_no_game_data.py on the touched files.

In-game run

Game gate (scripts/game-gate.ps1) on a test branch that merges four changes over main a558375458: this PR together with the FFX jitter, XMem low window and descriptor-record changes and a periodic preload save. -SeriesS -PrecompileUsed, RTX 4060 8 GB, driver 32.0.16.1088, Windows 11, build with diagnostics. PASS, 314 s in the world, no device loss, median 17.7 fps, VRAM peak 6 390 MB for a 6 776 MB budget. Warning fault_after_stop (access violations in the runtime after the gate stopped the run, clean exit): the same 8 faults appear on a run of another branch, so most likely not from this change (not yet compared with main). cargo test --locked -p leonida-gpu -p leonida on that test branch: 742 + 62 + 5 passed, 0 failed.

On this NVIDIA card the upscaler's context was made normally (no "stand-in context" or "phase count is made here" line), so the fallback this PR adds was not exercised: it needs a card where the 0xC0000094 crash happens today (reports are mostly AMD). Testers with such a card are welcome (docs/game_gate.md).

AI-assisted

Written with Claude Opus 5.5 (Claude Code); reviewed by a separate Claude Opus 5.5 reviewer instance, whose findings (query numbers and widths) are fixed. The query structure layouts are the public ffx_upscale.h ones.

🤖 Generated with Claude Code

## Change The 0xC0000094 (integer division by zero right after the first upscale) is still reported after #3022 (RTX 5070 Ti, Series S, DLSS performance). Hypothesis (not measured): the title's upscaler refuses the context, the title keeps a null context, its jitter phase count query answers 0 and it divides by it. - A refused creation (error, no context written, or the title's own create not found) now gives the title a stand-in context of ours (non-null, result 0). `ffxQuery`, `ffxDestroyContext` and `ffxConfigure` are bound to ours while the dispatch is ours, so the stand-in never reaches the title's DLL; our DLSS/stretch upscale still draws. - The jitter phase count query (0x10004; render width then display width, from the public ffx_upscale.h) is passed on; if the DLL answers an error or 0, or the context is the stand-in, the count is the public FSR 2 formula `ceil(8 * (display/render)^2)`, min 1, max 4096 (720->1080 = 18, 540->1080 = 32, 1080->1080 = 8). The jitter offset on a stand-in is the public Halton (2,3) sequence. - One warning line the first time the fallback serves (widths and reason, no game data). - `LEONIDA_FFX_SAFE_JITTER=0` gives back the previous behaviour. `switches.md` regenerated; note in `findings.md`. ## Tests - `cargo test -p leonida-hle --locked`: 284 passed (new: refused/absent create gives a non-null stand-in and safe dispatch/configure/destroy; made context kept; phase formula 18/32/8; phases >= 1 for zero and absurd sizes; query never answers 0 with a stand-in, a zero, an error or no DLL function; good DLL answers untouched). - `cargo check -p leonida --tests`, `python -I tests/test_d3d12_switches.py`, `scripts/check_no_game_data.py` on the touched files. ## In-game run Game gate (`scripts/game-gate.ps1`) on a test branch that merges four changes over main `a558375458`: this PR together with the FFX jitter, XMem low window and descriptor-record changes and a periodic preload save. `-SeriesS -PrecompileUsed`, RTX 4060 8 GB, driver 32.0.16.1088, Windows 11, build with diagnostics. **PASS, 314 s in the world, no device loss**, median 17.7 fps, VRAM peak 6 390 MB for a 6 776 MB budget. Warning `fault_after_stop` (access violations in the runtime after the gate stopped the run, clean exit): the same 8 faults appear on a run of another branch, so most likely not from this change (not yet compared with main). `cargo test --locked -p leonida-gpu -p leonida` on that test branch: 742 + 62 + 5 passed, 0 failed. On this NVIDIA card the upscaler's context was made normally (no "stand-in context" or "phase count is made here" line), so the fallback this PR adds was not exercised: it needs a card where the 0xC0000094 crash happens today (reports are mostly AMD). Testers with such a card are welcome (docs/game_gate.md). ## AI-assisted Written with Claude Opus 5.5 (Claude Code); reviewed by a separate Claude Opus 5.5 reviewer instance, whose findings (query numbers and widths) are fixed. The query structure layouts are the public `ffx_upscale.h` ones. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A refused or missing upscale context gives the title a stand-in one; the jitter phase count query answers the public FSR 2 formula (min 1) when the DLL answers 0, an error, or the context is the stand-in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Phase count is 0x10004 (render width, then display width), offset 0x10005; 0x10002/0x10003 are never answered for a stand-in. ffxQuery/Destroy/Configure are not bound with LEONIDA_FFX_SAFE_JITTER=0. A partial context of a refused creation is destroyed first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
First-time contributor

Thanks, here are the results.

scripts/game-gate.ps1 run ... -PlayArgs '-SeriesS', 300 s target, default LEONIDA_THIN=1 (6 threads), RX 6800 XT, driver 32.0.21045.29003. Same data folder and caches for both runs, warmed first by a 60 s gate run on main with LEONIDA_THIN=0 (PASS, 29.5 fps median).

Build Result Device loss Mean fps
main 68427be7e FAIL (device_lost, world_not_reached) 306.7 s after the gate's start, about 4.6 s after the first frame line with world draws (808 draws/frame) none: the world was never reached by the gate's count (two frame lines in a row at 500+ draws)
#3443 290bf3dc2 FAIL (device_lost, world_not_reached) 383.3 s after the gate's start, about 2.2 s after the first frame line with world draws (3,294 draws/frame) none, same reason

This is the RDNA 2 LEONIDA_THIN=1 reset from #3264 (0x887A0007, game exit 0x887A0005, device-removed data; none), not the 0xC0000094: no access violation or division by zero in either run. So these runs can't confirm or rule out the fix on this card.

What #3443's code did before the reset: the upscale context was created (render=[1280, 720] upscale=[1920, 1080], amd_fidelityfx_upscaler_xbox.dll refused by the host policy as on main), and four upscale dispatches ran, as on main. Neither of the PR's warnings appears (no stand-in context, no phase count made by the fallback). I can run it again with LEONIDA_THIN=0 to get past world entry, if that helps.

The gate run folders (summary.json, run.json, events.jsonl, memory.csv, leonida.log), with the Windows user and PC names replaced: mandy-gate-main-rx6800xt.zip, mandy-gate-pr3443-rx6800xt.zip.

AI-assisted: log analysis and write-up with Claude Opus 5.5 (High).

Thanks, here are the results. `scripts/game-gate.ps1 run ... -PlayArgs '-SeriesS'`, 300 s target, default `LEONIDA_THIN=1` (6 threads), RX 6800 XT, driver 32.0.21045.29003. Same data folder and caches for both runs, warmed first by a 60 s gate run on main with `LEONIDA_THIN=0` (PASS, 29.5 fps median). | Build | Result | Device loss | Mean fps | |---|---|---|---| | main `68427be7e` | **FAIL** (`device_lost`, `world_not_reached`) | 306.7 s after the gate's start, about 4.6 s after the first frame line with world draws (808 draws/frame) | none: the world was never reached by the gate's count (two frame lines in a row at 500+ draws) | | #3443 `290bf3dc2` | **FAIL** (`device_lost`, `world_not_reached`) | 383.3 s after the gate's start, about 2.2 s after the first frame line with world draws (3,294 draws/frame) | none, same reason | This is the RDNA 2 `LEONIDA_THIN=1` reset from #3264 (`0x887A0007`, game exit `0x887A0005`, `device-removed data; none`), not the `0xC0000094`: no access violation or division by zero in either run. So these runs can't confirm or rule out the fix on this card. What #3443's code did before the reset: the upscale context was created (`render=[1280, 720] upscale=[1920, 1080]`, `amd_fidelityfx_upscaler_xbox.dll` refused by the host policy as on main), and four upscale dispatches ran, as on main. Neither of the PR's warnings appears (no stand-in context, no phase count made by the fallback). I can run it again with `LEONIDA_THIN=0` to get past world entry, if that helps. The gate run folders (`summary.json`, `run.json`, `events.jsonl`, `memory.csv`, `leonida.log`), with the Windows user and PC names replaced: `mandy-gate-main-rx6800xt.zip`, `mandy-gate-pr3443-rx6800xt.zip`. AI-assisted: log analysis and write-up with Claude Opus 5.5 (High).
Author
Member

Merging, with Moon's written OK as maintainer (only two maintainers: the CONTRIBUTING rule against merging one's own PR is waived for this series). Branch updated with main 5e7d6cfcc1 (conflict in run.rs with #3447 resolved: the three FFX bindings kept, then say!). The merged tree (22490c84) is the one tested locally: cargo test --locked -p leonida-gpu -p leonida -p leonida-hle all passed, tests/test_d3d12_switches.py OK. In-game gate in the description (PASS, 314 s, no device loss). AI-assisted (Claude Opus 5.5).

Merging, with Moon's written OK as maintainer (only two maintainers: the CONTRIBUTING rule against merging one's own PR is waived for this series). Branch updated with main `5e7d6cfcc1` (conflict in `run.rs` with #3447 resolved: the three FFX bindings kept, then `say!`). The merged tree (`22490c84`) is the one tested locally: `cargo test --locked -p leonida-gpu -p leonida -p leonida-hle` all passed, `tests/test_d3d12_switches.py` OK. In-game gate in the description (PASS, 314 s, no device loss). AI-assisted (Claude Opus 5.5).
First-time contributor

Thanks @MoonEyes, here are the results.

Same gate recipe as above (-PlayArgs '-SeriesS', 300 s), this time with the LEONIDA_THIN=0 workaround so the runs get past world entry. Same data folder and caches, one run per build.

Build Result Time in the world Device loss Mean fps Median fps p5 fps Frame p95
main 68427be7e PASS 302 s none 19.9 21.5 15.5 64.7 ms
#3443 290bf3dc2 PASS 304 s none 21.6 21.9 17.5 57.2 ms

The mean fps is the gate's frame count divided by the time it covers (the world minus its first 60 s); the other columns are the gate's own. Both runs stopped cleanly on the target, cache saved, no crash, no ERROR line, no missed pipeline wait, video memory under budget the whole time. One run each, played freely rather than on a fixed route, so the fps gap is within what I'd expect from that. The gate's under_2_at_s is 200 s on main and 371 s on #3443 (one second with fewer than 2 frames each; the longest gaps with no frame were 1.4 s and 2.5 s).

No 0xC0000094 and no access violation on either build. But on this card the path #3443 changes is barely used: as on main, the run made one upscale context (1280×720 to 1920×1080) and four upscale dispatches in total, and neither of the PR's warnings appears (no stand-in context, no phase count made by the fallback). So this run shows #3443 does no harm here, but it can't show the fix, since the crash was reported with DLSS on an RTX 5070 Ti.

With the default THIN=1 the device is still lost at world entry with #3443 as on main (my results above, #3264); #3031 avoids it on this card.

Logs: mandy-gate-pr3443-thin0-rx6800xt.zip (Windows user and PC names replaced). The main run's logs are under the #3439 comment.

AI-assisted: log analysis and write-up with Claude Opus 5.5 (High).

Thanks @MoonEyes, here are the results. Same gate recipe as above (`-PlayArgs '-SeriesS'`, 300 s), this time with the `LEONIDA_THIN=0` workaround so the runs get past world entry. Same data folder and caches, one run per build. | Build | Result | Time in the world | Device loss | Mean fps | Median fps | p5 fps | Frame p95 | |---|---|---|---|---|---|---|---| | main `68427be7e` | **PASS** | 302 s | none | 19.9 | 21.5 | 15.5 | 64.7 ms | | #3443 `290bf3dc2` | **PASS** | 304 s | none | 21.6 | 21.9 | 17.5 | 57.2 ms | The mean fps is the gate's frame count divided by the time it covers (the world minus its first 60 s); the other columns are the gate's own. Both runs stopped cleanly on the target, cache saved, no crash, no `ERROR` line, no missed pipeline wait, video memory under budget the whole time. One run each, played freely rather than on a fixed route, so the fps gap is within what I'd expect from that. The gate's `under_2_at_s` is 200 s on main and 371 s on #3443 (one second with fewer than 2 frames each; the longest gaps with no frame were 1.4 s and 2.5 s). No `0xC0000094` and no access violation on either build. But on this card the path #3443 changes is barely used: as on main, the run made one upscale context (1280×720 to 1920×1080) and four upscale dispatches in total, and neither of the PR's warnings appears (no stand-in context, no phase count made by the fallback). So this run shows #3443 does no harm here, but it can't show the fix, since the crash was reported with DLSS on an RTX 5070 Ti. With the default `THIN=1` the device is still lost at world entry with #3443 as on main (my results above, #3264); #3031 avoids it on this card. Logs: `mandy-gate-pr3443-thin0-rx6800xt.zip` (Windows user and PC names replaced). The main run's logs are under [the #3439 comment](https://git.leonida.now/leonida/mandy/pulls/3439#issuecomment-26153). AI-assisted: log analysis and write-up with Claude Opus 5.5 (High).
Sign in to join this conversation.
No description provided.