[PR #151] FFX shim: the title's five FidelityFX calls answered by the layer's PC upscaler (part 2) #203

Open
opened 2026-11-26 20:17:07 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/151
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/9883


📝 Commits (10+)

  • c8d136d runtime: AMD's PC FidelityFX upscaler on the layer's Vulkan device (RT-344)
  • e312253 ffx_vk: enable the extensions the upscaler's shaders use; the test fails on validation errors (#4999 review)
  • be631db ffx_vk_dispatch_test: the console's 1080p configuration and a 4K case
  • 8af9ed0 d3d12 layer: an Upscale command replayed through AMD's PC upscaler (FFX shim, part 1)
  • 3c05c37 replay: Upscale images in a PreparedList side table, and one barrier each way
  • 016df7f FFX shim: the title's five FidelityFX calls answered by the layer's PC upscaler (part 2)
  • a2766d2 ffx_vk: the loader's choice depends on GPU and driver, not on architecture alone
  • 37c57c2 Merge branch 'ffx-upscale-shim' into ffx-upscale-shim-2
  • a2fb835 Merge branch 'rt-344-ffx-vk' into ffx-upscale-shim
  • cf8b714 docs: which console mode calls FSR (Rockstar's statement), and LEONIDA_DEVICE_TYPE=6

📊 Changes

18 files changed (+2110 additions, -8 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+68 -0)
📝 runtime/CMakeLists.txt (+33 -0)
📝 runtime/shims/d3d12_com.cpp (+11 -0)
📝 runtime/shims/d3d12_com.h (+5 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+50 -0)
➕ runtime/shims/ffx_shim.cpp (+175 -0)
➕ runtime/shims/ffx_upscale.cpp (+316 -0)
➕ runtime/shims/ffx_upscale.h (+52 -0)
📝 runtime/src/command_list.h (+26 -1)
➕ runtime/src/ffx_vk_backend.cpp (+88 -0)
➕ runtime/src/ffx_vk_backend.h (+89 -0)
📝 runtime/src/vulkan_backend.h (+11 -1)
📝 runtime/src/vulkan_replay.h (+134 -1)
➕ runtime/test/d3d12_ffx_scene.h (+232 -0)
➕ runtime/test/d3d12_ffx_shim_test.cpp (+193 -0)
➕ runtime/test/d3d12_ffx_upscale_test.cpp (+121 -0)
📝 runtime/test/ffx_api_min.h (+43 -5)
➕ runtime/test/ffx_vk_dispatch_test.cpp (+463 -0)

📄 Description

Carried over from old PR 9883 by AwkGrep256 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9883, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
AwkGrep256: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Resubmitted unchanged: this was #5171, closed at the repository's move to the organisation (the members-only switch, 22:25–22:49 UTC) with no review comment; reopening it is refused. Same branch and head (a5112a362), which merges cleanly on main 7e39a81ea. The test reports from other contributors are on #5171.

Item: the FFX upscale shim (claim: https://github.com/ItsNotRexed/Leonida/issues/5032#issuecomment-7095090683), part 2 of 2: the shim table that answers the title's five FidelityFX calls with part 1's layer path.

Depends on: #9882 (part 1, the layer's Upscale command), which depends on #9877 (the backend). This branch carries both; this PR's own work is 016df7f2 and the docs commit after it (plus a merge of the chain's wording fix).

Draft until #9882 and #9877 are ready.

What

  • shims/ffx_shim.cpp serves ffxCreateContext, ffxDestroyContext, ffxConfigure, ffxQuery and ffxDispatch for both package modules that export them:

    • amd_fidelityfx_loader_xbox.dll;
    • amd_fidelityfx_upscaler_xbox.dll.

    dumpbin shows exactly these five on each (docs/d3d12_command_objects.md §3.5). Which module the title calls needs its executable.

  • Registration: the table registers before main, and only with LEONIDA_FFX_PC=1 in the process environment. The shims then own both modules: imports and LoadLibrary/GetProcAddress resolve here, and the package's copies are never mapped. Off, nothing is registered and the title loads the package's DLLs exactly as before; d3d12_ffx_shim_off checks this.

  • In gta6rt: the file is a source of gta6rt itself, in its Vulkan block. In the static library nothing would reference the self-registering object, so the linker would drop it.

The calls:

  • ffxCreateContext: takes the upscale description and the device of the console backend descriptor from the chain. That descriptor is type 0x01000002 with the device at +0x10, measured in docs/d3d12_vulkan.md A.3; the code asserts the offset.
    • The console's version and provider-override descriptors aren't passed on.
    • The backend attaches the SDK 2.4.0 FFX_UPSCALER_VERSION (4.1.2) instead. Without it, AMD's loader reported that the newer API functions are unavailable.
    • The handle the title gets is the rt::ffx_upscale context number.
    • No upscale description is UNKNOWN_DESCTYPE; no backend descriptor or device is ERROR_PARAMETER.
  • ffxDispatch: one leonida::Upscale recorded into the title's list (#9882). Other dispatch types (the reactive-mask generator, …) are UNKNOWN_DESCTYPE, logged once per type.
  • ffxQuery / ffxConfigure: pass through to AMD's loader, with these exceptions:
    • a context-less GET_VERSIONS names the title's D3D12 device, which is replaced by that device's Vulkan handles;
    • other context-less queries get the Vulkan backend chained for the call, and the title's chain is restored;
    • a context-less global-debug configure for effect 0 is sent for the upscaler, because AMD's PC loader answers effect 0 with UNKNOWN_DESCTYPE (measured).
  • ffxDestroyContext: rt::ffx_upscale::destroy (part 1: it waits for idle under the submit lock).
  • Tests:
    • test/d3d12_ffx_scene.h holds the scene both layer tests share; the part 1 test now uses it, which removes about 200 duplicated lines.
    • d3d12_ffx_shim_test calls the five functions as the loader binds them (rt::shims::find on the console names), with the console chain.

When the title calls FSR (added in the last commit)

Rockstar's statement on the console versions, as reported by VideoCardz and Alt Char:

  • Series S: 720p → 1080p with FSR Upscaling 4. That's the one configuration the package's DLL builds (#780).
  • Series X and PS5: 1440p → 4K with Rockstar's own TAA, not FSR.

The runtime reports a Series X by default (XSystemGetDeviceType). So the title would take its TAA path, which needs nothing beyond the translated shaders, and never call FSR.

  • LEONIDA_DEVICE_TYPE=6 reports a Series S, the mode that reaches this shim. That suits weaker GPUs: 720p rendering with PC FSR 4.1 or 3.1.
  • This assumes the title picks its mode from the device type, which only the running title will show.
  • Using FSR in the Series X mode would mean replacing the title's TAA pass, a separate later step that needs the title running. This is in docs/d3d12_vulkan.md A.3.

Performance

  • Off: nothing registered, so there's no change to imports, loading or replay.
  • On, per call:
    • ffxDispatch: a field-by-field copy into a 136-byte Upscale and one record_upscale, O(1). Replay cost is part 1's: one barrier each way, then AMD's dispatch.
    • ffxCreateContext / ffxDestroyContext: rare, at resolution changes.
    • Queries and configures: one registry lookup plus AMD's call. The first context-less call loads AMD's loader once.
  • Logging: the "unsupported type" log takes a mutex only on that error path.

Tested

Built with clang-cl 23.1.5 + xwin and run under Wine 11.22 on CachyOS, Mesa 26.3.1 RADV, FidelityFX SDK 2.4.0 DLLs, through ctest (which sets LEONIDA_FFX_PC per test):

GPU providers offered to the title's device context gets d3d12_ffx_shim d3d12_ffx_shim_off d3d12_ffx_upscale ffx_vk_dispatch
RX 9070 XT 4.1.2, 3.1.6, 2.3.4 FSR 4.1.2 PASS (880/880) PASS PASS PASS
Ryzen 7 9800X3D iGPU 3.1.6, 2.3.4 FSR 3.1.6 PASS (880/880) PASS PASS PASS
  • The test can fail: with ffxDispatch returning OK without recording, the shim test reports 440/880 and FAIL.
  • Without LEONIDA_FFX_DIR, d3d12_ffx_shim and d3d12_ffx_upscale skip (77).
  • Validation: with the host's validation layer beneath Wine and synchronization validation, neither the shim nor the layer reports anything. On the 9070 XT the remaining errors are FSR 4.1.2's own shader errors from #9877; on the iGPU there's only Wine's own 01387.
  • Builds and checks: the full Windows build passes. test_ctest_registration.py, test_cmake_vulkan_missing.py, test_runtime_paths.py and the test_docs_* checks pass.
  • Not run:
    • native Windows (Kam471 ran part 1's tests there);
    • the game's own call sequence, which needs its executable.

No game files. AI-assisted (Claude Code).

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/151 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/9883` --- ### 📝 Commits (10+) - [`c8d136d`](https://github.com/ubiquitarianism/leonida/commit/c8d136d45d5b40bbfeca9a2ecaf9ef744d090110) runtime: AMD's PC FidelityFX upscaler on the layer's Vulkan device (RT-344) - [`e312253`](https://github.com/ubiquitarianism/leonida/commit/e312253b950962d74afa6f8aa35b13b3b40db3a5) ffx_vk: enable the extensions the upscaler's shaders use; the test fails on validation errors (#4999 review) - [`be631db`](https://github.com/ubiquitarianism/leonida/commit/be631db9dc45a8c444fe33b951309fb7ddc2e511) ffx_vk_dispatch_test: the console's 1080p configuration and a 4K case - [`8af9ed0`](https://github.com/ubiquitarianism/leonida/commit/8af9ed0b783a6c9a37812a1168b19bf21e1e4525) d3d12 layer: an Upscale command replayed through AMD's PC upscaler (FFX shim, part 1) - [`3c05c37`](https://github.com/ubiquitarianism/leonida/commit/3c05c3793963c6e9bcf7eb51c3018bade9195ee7) replay: Upscale images in a PreparedList side table, and one barrier each way - [`016df7f`](https://github.com/ubiquitarianism/leonida/commit/016df7f23daf0df26ce0b9a7a6acc0108700d3ee) FFX shim: the title's five FidelityFX calls answered by the layer's PC upscaler (part 2) - [`a2766d2`](https://github.com/ubiquitarianism/leonida/commit/a2766d202e54eca1a66bd5f3b0e796e4937f59fa) ffx_vk: the loader's choice depends on GPU and driver, not on architecture alone - [`37c57c2`](https://github.com/ubiquitarianism/leonida/commit/37c57c21d8e8358166ff83d039cf81ed75141d87) Merge branch 'ffx-upscale-shim' into ffx-upscale-shim-2 - [`a2fb835`](https://github.com/ubiquitarianism/leonida/commit/a2fb8358a57132b0c5083050780f6bf4369480ba) Merge branch 'rt-344-ffx-vk' into ffx-upscale-shim - [`cf8b714`](https://github.com/ubiquitarianism/leonida/commit/cf8b714d0ddc9d0d7b455c933576f49117c415ed) docs: which console mode calls FSR (Rockstar's statement), and LEONIDA_DEVICE_TYPE=6 ### 📊 Changes **18 files changed** (+2110 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+68 -0) 📝 `runtime/CMakeLists.txt` (+33 -0) 📝 `runtime/shims/d3d12_com.cpp` (+11 -0) 📝 `runtime/shims/d3d12_com.h` (+5 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+50 -0) ➕ `runtime/shims/ffx_shim.cpp` (+175 -0) ➕ `runtime/shims/ffx_upscale.cpp` (+316 -0) ➕ `runtime/shims/ffx_upscale.h` (+52 -0) 📝 `runtime/src/command_list.h` (+26 -1) ➕ `runtime/src/ffx_vk_backend.cpp` (+88 -0) ➕ `runtime/src/ffx_vk_backend.h` (+89 -0) 📝 `runtime/src/vulkan_backend.h` (+11 -1) 📝 `runtime/src/vulkan_replay.h` (+134 -1) ➕ `runtime/test/d3d12_ffx_scene.h` (+232 -0) ➕ `runtime/test/d3d12_ffx_shim_test.cpp` (+193 -0) ➕ `runtime/test/d3d12_ffx_upscale_test.cpp` (+121 -0) 📝 `runtime/test/ffx_api_min.h` (+43 -5) ➕ `runtime/test/ffx_vk_dispatch_test.cpp` (+463 -0) </details> ### 📄 Description > Carried over from **old PR 9883** by `AwkGrep256` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9883`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `AwkGrep256`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Resubmitted unchanged: this was `#5171`, closed at the repository's move to the organisation (the members-only switch, 22:25–22:49 UTC) with no review comment; reopening it is refused. Same branch and head (`a5112a362`), which merges cleanly on `main` `7e39a81ea`. The test reports from other contributors are on `#5171`. Item: the FFX upscale shim (claim: https://github.com/ItsNotRexed/Leonida/issues/5032#issuecomment-7095090683), **part 2 of 2: the shim table** that answers the title's five FidelityFX calls with part 1's layer path. Depends on: `#9882` (part 1, the layer's Upscale command), which depends on `#9877` (the backend). This branch carries both; this PR's own work is `016df7f2` and the docs commit after it (plus a merge of the chain's wording fix). **Draft until `#9882` and `#9877` are ready.** ### What - **`shims/ffx_shim.cpp`** serves `ffxCreateContext`, `ffxDestroyContext`, `ffxConfigure`, `ffxQuery` and `ffxDispatch` for both package modules that export them: - `amd_fidelityfx_loader_xbox.dll`; - `amd_fidelityfx_upscaler_xbox.dll`. `dumpbin` shows exactly these five on each (`docs/d3d12_command_objects.md` §3.5). Which module the title calls needs its executable. - **Registration:** the table registers **before `main`, and only with `LEONIDA_FFX_PC=1`** in the process environment. The shims then own both modules: imports and `LoadLibrary`/`GetProcAddress` resolve here, and the package's copies are never mapped. **Off, nothing is registered** and the title loads the package's DLLs exactly as before; `d3d12_ffx_shim_off` checks this. - **In `gta6rt`:** the file is a source of `gta6rt` itself, in its Vulkan block. In the static library nothing would reference the self-registering object, so the linker would drop it. **The calls:** - **`ffxCreateContext`:** takes the upscale description and the device of the console backend descriptor from the chain. That descriptor is type `0x01000002` with the device at `+0x10`, measured in `docs/d3d12_vulkan.md` A.3; the code asserts the offset. - The console's version and provider-override descriptors aren't passed on. - The backend attaches the SDK 2.4.0 `FFX_UPSCALER_VERSION` (4.1.2) instead. Without it, AMD's loader reported that the newer API functions are unavailable. - The handle the title gets is the `rt::ffx_upscale` context number. - No upscale description is `UNKNOWN_DESCTYPE`; no backend descriptor or device is `ERROR_PARAMETER`. - **`ffxDispatch`:** one `leonida::Upscale` recorded into the title's list (`#9882`). Other dispatch types (the reactive-mask generator, …) are `UNKNOWN_DESCTYPE`, logged once per type. - **`ffxQuery` / `ffxConfigure`:** pass through to AMD's loader, with these exceptions: - a context-less `GET_VERSIONS` names the title's D3D12 device, which is replaced by that device's Vulkan handles; - other context-less queries get the Vulkan backend chained for the call, and the title's chain is restored; - a context-less global-debug configure for effect 0 is sent for the upscaler, because AMD's PC loader answers effect 0 with `UNKNOWN_DESCTYPE` (measured). - **`ffxDestroyContext`:** `rt::ffx_upscale::destroy` (part 1: it waits for idle under the submit lock). - **Tests:** - `test/d3d12_ffx_scene.h` holds the scene both layer tests share; the part 1 test now uses it, which removes about 200 duplicated lines. - `d3d12_ffx_shim_test` calls the five functions as the loader binds them (`rt::shims::find` on the console names), with the console chain. ### When the title calls FSR (added in the last commit) Rockstar's statement on the console versions, as reported by [VideoCardz](https://videocardz.com/newz/gta-vi-uses-amd-fsr-4-on-xbox-series-s-renders-at-720p-with-ray-traced-global-illumination) and [Alt Char](https://www.altchar.com/game-news/gta-vi-uses-amds-fsr-4-on-xbox-series-s-but-not-on-series-x-aOvqJ1G7YxhJ): - **Series S:** 720p → 1080p with **FSR Upscaling 4**. That's the one configuration the package's DLL builds (`#780`). - **Series X and PS5:** 1440p → 4K with **Rockstar's own TAA**, not FSR. The runtime reports a **Series X** by default (`XSystemGetDeviceType`). So the title would take its TAA path, which needs nothing beyond the translated shaders, and never call FSR. - **`LEONIDA_DEVICE_TYPE=6`** reports a Series S, the mode that reaches this shim. That suits weaker GPUs: 720p rendering with PC FSR 4.1 or 3.1. - This assumes the title picks its mode from the device type, which only the running title will show. - Using FSR in the Series X mode would mean replacing the title's TAA pass, a separate later step that needs the title running. This is in `docs/d3d12_vulkan.md` A.3. ### Performance - **Off:** nothing registered, so there's no change to imports, loading or replay. - **On, per call:** - `ffxDispatch`: a field-by-field copy into a 136-byte `Upscale` and one `record_upscale`, O(1). Replay cost is part 1's: one barrier each way, then AMD's dispatch. - `ffxCreateContext` / `ffxDestroyContext`: rare, at resolution changes. - Queries and configures: one registry lookup plus AMD's call. The first context-less call loads AMD's loader once. - **Logging:** the "unsupported type" log takes a mutex only on that error path. ### Tested Built with clang-cl 23.1.5 + xwin and run under Wine 11.22 on CachyOS, Mesa 26.3.1 RADV, FidelityFX SDK 2.4.0 DLLs, through `ctest` (which sets `LEONIDA_FFX_PC` per test): | GPU | providers offered to the title's device | context gets | `d3d12_ffx_shim` | `d3d12_ffx_shim_off` | `d3d12_ffx_upscale` | `ffx_vk_dispatch` | |---|---|---|---|---|---|---| | RX 9070 XT | 4.1.2, 3.1.6, 2.3.4 | FSR 4.1.2 | PASS (880/880) | PASS | PASS | PASS | | Ryzen 7 9800X3D iGPU | 3.1.6, 2.3.4 | FSR 3.1.6 | PASS (880/880) | PASS | PASS | PASS | - **The test can fail:** with `ffxDispatch` returning OK without recording, the shim test reports 440/880 and FAIL. - **Without `LEONIDA_FFX_DIR`**, `d3d12_ffx_shim` and `d3d12_ffx_upscale` skip (77). - **Validation:** with the host's validation layer beneath Wine and **synchronization validation**, neither the shim nor the layer reports anything. On the 9070 XT the remaining errors are FSR 4.1.2's own shader errors from `#9877`; on the iGPU there's only Wine's own `01387`. - **Builds and checks:** the full Windows build passes. `test_ctest_registration.py`, `test_cmake_vulkan_missing.py`, `test_runtime_paths.py` and the `test_docs_*` checks pass. - **Not run:** - native Windows (Kam471 ran part 1's tests there); - the game's own call sequence, which needs its executable. No game files. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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
starred/leonida#203
No description provided.