d3d12 ffx: AMD FSR 4 upscaler through AMD's PC DLL on RDNA 2-4 (D3D12-FSR4-PC-UPSCALER) #3404

Code

Clone this repository

Checkout

From your project repository, check out a new branch and test the changes.

git fetch -u origin "+refs/pull/3404/head:oreofr/fsr4-pc-upscaler"
git switch "oreofr/fsr4-pc-upscaler"
Open
leonida/mandy
OreoFR wants to merge 1 commit from oreofr/fsr4-pc-upscaler into main AGit

This pull request has changes conflicting with the target branch.

Merge manually to resolve the conflicts.

Conversation
Reviewers 0 approvals
  • No reviewers
Details

This pull request has changes conflicting with the target branch.

Merge manually to resolve the conflicts.

  • d3d12/apps/leonida/src/run.rs
  • d3d12/crates/leonida-gpu/src/list.rs
  • d3d12/crates/leonida-hle/src/modules/ffx.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3404/head:oreofr/fsr4-pc-upscaler'
git switch 'oreofr/fsr4-pc-upscaler'
Member

Item: D3D12-FSR4-PC-UPSCALER (claimed in #3312).

What and why

On AMD cards the title's Series S upscale (ffxDispatch) is a plain stretch today (leonida-hle/src/modules/ffx.rs), with no temporal reconstruction. This adds AMD's own PC FSR 4 for it: LEONIDA_UPSCALE=fsr4 makes leonida_gpu::list::upscale_now record AMD's signed amd_fidelityfx_upscaler_dx12.dll (FidelityFX SDK v2.4.0) on the host list, in the same place DLSS is recorded, from the title's colour, depth, motion vectors, exposure, jitter, near/far and field of view (the title's upscale already speaks the same public API, ffx_upscale.h).

  • New d3d12/crates/leonida-gpu/src/fsr4.rs: loads the DLL (Authenticode checked first, its own folder + System32 only), lists the providers the DLL offers for the device and picks the newest FSR 4.x (FP8 on RDNA 4, INT8 "4.1.2" on RDNA 2/3/3.5), else the newest FSR 3.1.x (pick_provider); one context per (colour size, output size, flags), made with the flags the title gave its own context (note_upscale_create_flags from ffx.rs's create, debug bits dropped; LEONIDA_FSR4_FLAGS overrides for A/B). A replaced context is destroyed 16 upscales later, not while lists may still use it.
  • list.rs: Upscale carries fsr4 and the camera FOV (in word 10, so thin mode carries them too); FSR 4 is tried first, then DLSS, then the stretch.
  • apps/leonida/src/run.rs: LEONIDA_UPSCALE=fsr4 takes the dispatch like stretch|dlss.
  • fsr.rs: only visibility (pub(crate)) of the shared FidelityFX structures, dir() and verify_signature(); no behaviour change.
  • scripts/play-nvidia.ps1: -More @{LEONIDA_UPSCALE='fsr4'} sets LEONIDA_FIDELITYFX_DIR and says when the DLL is missing; Series X treats fsr4 like dlss|stretch.

Switch and default

Off by default. On only with LEONIDA_UPSCALE=fsr4, and only on an AMD adapter (vendor 0x1002, from the host device's adapter): on any other vendor, or an unknown one, the DLL is not even looked for (gated, test a_card_that_is_not_amds_falls_back_without_loading). Not auto-enabled on RDNA 2-4: nothing has run in game yet. The card-name check (fsr4_card, RX 6xxx/7xxx/9xxx, 6x0M/7x0M/8x0M, 80x0S) is only logged.

NVIDIA unchanged: without LEONIDA_UPSCALE=fsr4 the new branch is never entered (if up.fsr4), dlss and stretch take the same paths as before; with it on NVIDIA, the vendor gate refuses before loading anything and the upscale is the stretch.

Fallback, and the 0xC0000094 report

Missing DLL, bad signature, no provider, refused context: one FSR 4: ... stays a stretch line in the log, never retried, and the upscale is the stretch (record returns false). A refused dispatch: that upscale is a stretch (logged once). Nothing here returns an error to the title or leaves it without its own context.

On MoonEyes' 0xC0000094 on AMD: the title divides by its upscaler's jitter phase count when its own (console) context was refused (ffx.rs create, title+0x28f03e8). Our PC context is separate and the title never sees it, so its refusal cannot cause that crash. With LEONIDA_UPSCALE=fsr4 the existing ffx::create stand-in is bound (as for stretch|dlss), so the title's own context is made at its shipped sizes. Whether MoonEyes' crash is that one (e.g. a run with LEONIDA_UPSCALE unset, where the stand-in is not bound) needs his log; this PR does not claim to fix it.

What is fetched

scripts/get-amd-fidelityfx.ps1 -Upscaler (also Get-AMD-FidelityFX.cmd -Upscaler) adds, from AMD's own repository at the pinned tag:

  • URL: https://raw.githubusercontent.com/GPUOpen-LibrariesAndSDKs/FidelityFX-SDK/v2.4.0/Kits/FidelityFX/signedbin/amd_fidelityfx_upscaler_dx12.dll
  • Size 57664272, git blob 6d01d9f52c412fc336350f04e948eb1bee196a38 (from the v2.4.0 tree, GitHub API), SHA-256 AAD4FCCCCB29084A655F9A4F9F613BD22C8C03FB4A0F8840148CC6543B4CCACE (computed on a copy downloaded once from that URL, outside the repository; it matches Darner's pin), Authenticode valid, signer "Advanced Micro Devices".

Without -Upscaler the script fetches the same two FSR 3 DLLs as before (the launcher's button is unchanged). No AMD file is in this PR.

Credit

After Darner (TrustNo1/Darner, GPL-3.0-or-later) commit 5345be7 by ggwp (crates/darner-hle/src/modules/fidelityfx/pc.rs, apps/darner/src/play.rs amd_fsr4_card, scripts/get-amd-fsr.ps1), itself adapted from Marvisak/VIctory PR #2751. Darner serves the title's FidelityFX contexts with the PC DLL; here the PC context is ours and sits where DLSS is recorded.

Tests (RTX 4070 Laptop, NVIDIA; Windows 11)

  • cargo test -p leonida-gpu -p leonida-hle -p leonida --locked: all pass (leonida-gpu 737 passed / 59 ignored, leonida-hle 259 passed / 2 ignored, the rest OK). New in fsr4.rs: structure layouts against SDK v2.4.0's headers, provider picking, AMD-only gate, card names, creation flags, missing DLL and unsigned DLL refused; list.rs words round-trip with fsr4 and FOV.
  • cargo clippy -p leonida-gpu -p leonida-hle -p leonida --all-targets --locked: no warnings.
  • cargo build --profile diag -p leonida: links, no warnings.
  • python -I tests/test_leonida_launcher.py (240 OK, the fetcher's pins, -Upscaler with a fake DLL keeps nothing), python -I tests/test_d3d12_switches.py (d3d12/docs/switches.md regenerated: LEONIDA_FSR4_FLAGS, LEONIDA_UPSCALE), python -I tests/test_docs_links.py, python -I scripts/check_no_game_data.py on the changed files: OK.

Needs an AMD RDNA 2/3/4 tester; not run in game. Steps are in d3d12/README.md, "FSR 4 on AMD cards (experimental)": Get-AMD-FidelityFX.cmd -Upscaler, then scripts\play-nvidia.ps1 -Log -More @{LEONIDA_UPSCALE='fsr4'} on Series S, and the FSR 4: lines of the log, fps with and without, and screenshots on this PR.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

Item: **D3D12-FSR4-PC-UPSCALER** (claimed in #3312). ## What and why On AMD cards the title's Series S upscale (`ffxDispatch`) is a plain stretch today (`leonida-hle/src/modules/ffx.rs`), with no temporal reconstruction. This adds AMD's own PC FSR 4 for it: `LEONIDA_UPSCALE=fsr4` makes `leonida_gpu::list::upscale_now` record AMD's signed `amd_fidelityfx_upscaler_dx12.dll` (FidelityFX SDK v2.4.0) on the host list, in the same place DLSS is recorded, from the title's colour, depth, motion vectors, exposure, jitter, near/far and field of view (the title's upscale already speaks the same public API, `ffx_upscale.h`). - New `d3d12/crates/leonida-gpu/src/fsr4.rs`: loads the DLL (Authenticode checked first, its own folder + System32 only), lists the providers the DLL offers for the device and picks the newest FSR 4.x (FP8 on RDNA 4, INT8 "4.1.2" on RDNA 2/3/3.5), else the newest FSR 3.1.x (`pick_provider`); one context per (colour size, output size, flags), made with the flags the title gave its own context (`note_upscale_create_flags` from `ffx.rs`'s create, debug bits dropped; `LEONIDA_FSR4_FLAGS` overrides for A/B). A replaced context is destroyed 16 upscales later, not while lists may still use it. - `list.rs`: `Upscale` carries `fsr4` and the camera FOV (in word 10, so thin mode carries them too); FSR 4 is tried first, then DLSS, then the stretch. - `apps/leonida/src/run.rs`: `LEONIDA_UPSCALE=fsr4` takes the dispatch like `stretch|dlss`. - `fsr.rs`: only visibility (`pub(crate)`) of the shared FidelityFX structures, `dir()` and `verify_signature()`; no behaviour change. - `scripts/play-nvidia.ps1`: `-More @{LEONIDA_UPSCALE='fsr4'}` sets `LEONIDA_FIDELITYFX_DIR` and says when the DLL is missing; Series X treats `fsr4` like `dlss|stretch`. ## Switch and default **Off by default.** On only with `LEONIDA_UPSCALE=fsr4`, and **only on an AMD adapter** (vendor 0x1002, from the host device's adapter): on any other vendor, or an unknown one, the DLL is not even looked for (`gated`, test `a_card_that_is_not_amds_falls_back_without_loading`). Not auto-enabled on RDNA 2-4: nothing has run in game yet. The card-name check (`fsr4_card`, RX 6xxx/7xxx/9xxx, 6x0M/7x0M/8x0M, 80x0S) is only logged. **NVIDIA unchanged:** without `LEONIDA_UPSCALE=fsr4` the new branch is never entered (`if up.fsr4`), `dlss` and `stretch` take the same paths as before; with it on NVIDIA, the vendor gate refuses before loading anything and the upscale is the stretch. ## Fallback, and the 0xC0000094 report Missing DLL, bad signature, no provider, refused context: one `FSR 4: ... stays a stretch` line in the log, never retried, and the upscale is the stretch (`record` returns false). A refused dispatch: that upscale is a stretch (logged once). Nothing here returns an error to the title or leaves it without its own context. On MoonEyes' 0xC0000094 on AMD: the title divides by its upscaler's jitter phase count when its own (console) context was refused (`ffx.rs` `create`, title+0x28f03e8). Our PC context is separate and the title never sees it, so its refusal cannot cause that crash. With `LEONIDA_UPSCALE=fsr4` the existing `ffx::create` stand-in is bound (as for `stretch|dlss`), so the title's own context is made at its shipped sizes. Whether MoonEyes' crash is that one (e.g. a run with `LEONIDA_UPSCALE` unset, where the stand-in is not bound) needs his log; this PR does not claim to fix it. ## What is fetched `scripts/get-amd-fidelityfx.ps1 -Upscaler` (also `Get-AMD-FidelityFX.cmd -Upscaler`) adds, from AMD's own repository at the pinned tag: - URL: `https://raw.githubusercontent.com/GPUOpen-LibrariesAndSDKs/FidelityFX-SDK/v2.4.0/Kits/FidelityFX/signedbin/amd_fidelityfx_upscaler_dx12.dll` - Size 57664272, git blob `6d01d9f52c412fc336350f04e948eb1bee196a38` (from the v2.4.0 tree, GitHub API), SHA-256 `AAD4FCCCCB29084A655F9A4F9F613BD22C8C03FB4A0F8840148CC6543B4CCACE` (computed on a copy downloaded once from that URL, outside the repository; it matches Darner's pin), Authenticode valid, signer "Advanced Micro Devices". Without `-Upscaler` the script fetches the same two FSR 3 DLLs as before (the launcher's button is unchanged). No AMD file is in this PR. ## Credit After Darner (TrustNo1/Darner, GPL-3.0-or-later) commit 5345be7 by ggwp (`crates/darner-hle/src/modules/fidelityfx/pc.rs`, `apps/darner/src/play.rs` `amd_fsr4_card`, `scripts/get-amd-fsr.ps1`), itself adapted from Marvisak/VIctory PR #2751. Darner serves the title's FidelityFX contexts with the PC DLL; here the PC context is ours and sits where DLSS is recorded. ## Tests (RTX 4070 Laptop, NVIDIA; Windows 11) - `cargo test -p leonida-gpu -p leonida-hle -p leonida --locked`: all pass (leonida-gpu 737 passed / 59 ignored, leonida-hle 259 passed / 2 ignored, the rest OK). New in `fsr4.rs`: structure layouts against SDK v2.4.0's headers, provider picking, AMD-only gate, card names, creation flags, missing DLL and unsigned DLL refused; `list.rs` words round-trip with `fsr4` and FOV. - `cargo clippy -p leonida-gpu -p leonida-hle -p leonida --all-targets --locked`: no warnings. - `cargo build --profile diag -p leonida`: links, no warnings. - `python -I tests/test_leonida_launcher.py` (240 OK, the fetcher's pins, `-Upscaler` with a fake DLL keeps nothing), `python -I tests/test_d3d12_switches.py` (`d3d12/docs/switches.md` regenerated: `LEONIDA_FSR4_FLAGS`, `LEONIDA_UPSCALE`), `python -I tests/test_docs_links.py`, `python -I scripts/check_no_game_data.py` on the changed files: OK. **Needs an AMD RDNA 2/3/4 tester; not run in game.** Steps are in `d3d12/README.md`, "FSR 4 on AMD cards (experimental)": `Get-AMD-FidelityFX.cmd -Upscaler`, then `scripts\play-nvidia.ps1 -Log -More @{LEONIDA_UPSCALE='fsr4'}` on Series S, and the `FSR 4:` lines of the log, fps with and without, and screenshots on this PR. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
LEONIDA_UPSCALE=fsr4 (off by default) records AMD's signed
amd_fidelityfx_upscaler_dx12.dll (FidelityFX SDK v2.4.0) for the title's
upscale, where DLSS is recorded, on AMD adapters only (vendor 0x1002; on
any other the DLL is not loaded). The newest FSR 4.x provider the DLL
offers is picked, else FSR 3.1.x. A missing DLL, bad signature, missing
provider or refused context logs one line and leaves the stretch.

scripts/get-amd-fidelityfx.ps1 -Upscaler fetches the DLL from AMD's
GitHub at v2.4.0, pinned by size, git blob, SHA-256 and AMD's signature.

After Darner (TrustNo1/Darner, GPL-3.0-or-later) commit 5345be7 by ggwp,
itself adapted from Marvisak/VIctory PR #2751.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Member

Conflict with #3378 (fitted on beta)

This PR conflicts in code with #3378 (d72ecd346) in d3d12/crates/leonida-gpu/src/list.rs and d3d12/crates/leonida-hle/src/modules/ffx.rs: both add a field to Upscale and both take bit 2 of w[10] in the recorded words (#3378: mv_jittered, this PR: fsr4), and they collide in dispatch and create.

How it was fitted on beta (merge ab504936d, beta head 0d70cf038):

  • w[10]: bit 0 reset, bit 1 DLSS, bit 2 mv_jittered (#3378, unchanged), bit 3 fsr4 (moved from bit 2), fov in bits 32-63 (unchanged). to_words/from_words and an_upscale_keeps_its_numbers_through_its_words updated; the test now also checks that turning one of dlss/mv_jittered/fsr4 off leaves the other two and the fov as they were.
  • ffx.rs: dispatch fills mv_jittered, fsr4 and fov; create calls #3378's note_context_flags, which now also calls leonida_gpu::list::note_upscale_create_flags, so FSR 4's context gets the title's flags at both points #3378 reads them (before and after the title's own create). INPUT_FLAGS (0x17f) keeps bit 2 (FFX_UPSCALE_ENABLE_MOTION_VECTORS_JITTER_CANCELLATION), so FSR 4 follows the title's jitter flag the same way DLSS/FG do.
  • docs/switches.md regenerated.

Checks on beta: cargo build --locked --profile diag -p leonida --features diagnostics,dlss,mimalloc OK; cargo test of the upscale-words test, fsr4::, fg::, dlss:: (with --features dlss) and leonida-hle modules::ffx OK. Not run in game (no AMD card here).

Whichever of #3404 / #3378 merges into main second needs the same fit (separate bits, one notes-flags path).

AI-assisted (Claude Code).

**Conflict with #3378 (fitted on `beta`)** This PR conflicts in code with #3378 (`d72ecd346`) in `d3d12/crates/leonida-gpu/src/list.rs` and `d3d12/crates/leonida-hle/src/modules/ffx.rs`: both add a field to `Upscale` and both take **bit 2 of `w[10]`** in the recorded words (#3378: `mv_jittered`, this PR: `fsr4`), and they collide in `dispatch` and `create`. How it was fitted on `beta` (merge `ab504936d`, beta head `0d70cf038`): - `w[10]`: bit 0 reset, bit 1 DLSS, bit 2 `mv_jittered` (#3378, unchanged), **bit 3 `fsr4`** (moved from bit 2), `fov` in bits 32-63 (unchanged). `to_words`/`from_words` and `an_upscale_keeps_its_numbers_through_its_words` updated; the test now also checks that turning one of dlss/mv_jittered/fsr4 off leaves the other two and the fov as they were. - `ffx.rs`: `dispatch` fills `mv_jittered`, `fsr4` and `fov`; `create` calls #3378's `note_context_flags`, which now also calls `leonida_gpu::list::note_upscale_create_flags`, so FSR 4's context gets the title's flags at both points #3378 reads them (before and after the title's own create). `INPUT_FLAGS` (0x17f) keeps bit 2 (`FFX_UPSCALE_ENABLE_MOTION_VECTORS_JITTER_CANCELLATION`), so FSR 4 follows the title's jitter flag the same way DLSS/FG do. - `docs/switches.md` regenerated. Checks on beta: `cargo build --locked --profile diag -p leonida --features diagnostics,dlss,mimalloc` OK; `cargo test` of the upscale-words test, `fsr4::`, `fg::`, `dlss::` (with `--features dlss`) and `leonida-hle` `modules::ffx` OK. Not run in game (no AMD card here). Whichever of #3404 / #3378 merges into `main` second needs the same fit (separate bits, one notes-flags path). AI-assisted (Claude Code).
Sign in to join this conversation.
No description provided.