Repository navigation
FFX shim: the title's five FidelityFX calls answered by the layer's PC upscaler (part 2) - #5171
AwkGrep256 wants to merge 26 commits into
Conversation
…T-344) The AMD counterpart of ItsNotRexed#4801's DLSS backend. The game calls the five FFX functions of the package's amd_fidelityfx_upscaler_xbox.dll, whose 29 INT8 programs would otherwise be translated and which only builds a 1080p Quality table. AMD's public FidelityFX SDK 2.4.0 ships a signed Vulkan loader (amd_fidelityfx_loader_vk.dll) at feature parity with DX12, so the same calls can be answered on the layer's own VkDevice with no D3D12 device. The loader picks the newest upscaler the GPU has. - src/ffx_vk_backend.{h,cpp}: load the loader from LEONIDA_FFX_DIR or next to the program, create the upscale context with the Vulkan backend descriptor in place of the console one, report the provider, pass dispatches through (VkImage resources, a VkCommandBuffer). - test/ffx_api_min.h: the Vulkan backend descriptor and the provider-version query, from the SDK's MIT headers. - test/ffx_vk_dispatch_test.cpp: 30 upscales of a procedural checkerboard (no game data) with the game's context flags; every output value finite and every square right. Skips (77) without a GPU or the DLL. - docs/d3d12_vulkan.md A.3: what was measured. Under Wine 11.22 on RADV (Mesa 26.3.1), no device extensions: RX 9070 XT gets FSR 4.1.2 (0.64 ms per 1280x720 -> 2560x1440 upscale), the 9800X3D iGPU FSR 3.1.6 (15.7 ms); both pass. Not run on Windows yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ils on validation errors (ItsNotRexed#4999 review) whattheflop's Windows run (AMD driver 32.0.21030.2001, Ryzen 7 9800X3D iGPU) under Khronos validation found FSR 3.1.6's shader modules using compute-shader derivatives the fixture device had not enabled (pCode-08740/08742). The same shows under RADV, and FSR 4.1.2 on the RX 9070 XT also uses 8-bit floats and cooperative matrices. - ffx_vk_backend.h: wanted_device_extensions, the three AMD's own sample device enables where present (VK_KHR_compute_shader_derivatives, VK_KHR_cooperative_matrix, VK_EXT_shader_float8). - ffx_vk_dispatch_test: enables those the device has with all their features; LEONIDA_VK_VALIDATION=1 runs under VK_LAYER_KHRONOS_validation and fails on any validation error except the five known_provider_error names by VUID and text, which are in AMD's FSR 4.1.2 shaders (SPV_NV_cooperative_matrix2, which RADV does not offer on RDNA4; two spirv-val rejections; 3-component writes to RGBA16F storage images). Fails if the layer is missing. - docs/d3d12_vulkan.md A.3: corrects "no device extensions" and lists them. With the extensions, the iGPU (FSR 3.1.6) is clean under the host validation layer; the 9070 XT (FSR 4.1.2) reports only the five provider errors. Applied to the earlier logs, the rules count the iGPU's derivatives errors, so that run would now fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test ran one 1280x720 -> 2560x1440 case. It now runs two, each on its own context: 1280x720 -> 1920x1080, the one configuration the console's DLL builds (docs/d3d12_vulkan.md A.3), and 1920x1080 -> 3840x2160. Under Wine on RADV: RX 9070 XT (FSR 4.1.2) 0.41 ms and 1.22 ms per upscale, 9800X3D iGPU (FSR 3.1.6) 10.1 ms and 35.3 ms; both pass, and both cases fail with the dispatch removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…FX shim, part 1) The layer side of the FFX upscale shim behind ItsNotRexed#4999 (RT-344): what the shim will record for the game's ffxDispatch, and how replay runs it. Off unless LEONIDA_FFX_PC=1; with it off the device and replay behave as before. - command_list.h: leonida::Upscale (FfxDispatchDescUpscale's fields, images as resource ids), recorded by CommandList::upscale. - vulkan_replay.h: two hooks (upscale_ready, upscale). Prepare resolves the images and skips a command whose context is gone; emit moves the inputs to the NON_PIXEL_SHADER_RESOURCE layout and the output to the UAV layout through the layout tracker, records the upscale and moves each back. - vulkan_backend.h: an Upscale counts as shader work; set_upscaler() sets the hooks once, before the device is handed out. - shims/ffx_upscale.{h,cpp}: the contexts on a device (create, destroy, provider), the hooks, and the FfxApiSurfaceFormat of each VkFormat. destroy() and device teardown wait for idle under the submit lock first. - d3d12_vulkan_device.cpp: with the switch on, enables the upscaler's extensions and the core features its shaders declare (found under the validation layer: 16-bit storage, variable pointers, int8, float16, the Vulkan memory model with device scope), each where the GPU has it. - d3d12_com: rt::d3d12::record_upscale (not in bundles or copy lists). - ffx_vk_backend: getenv_s, as the layer reads its variables. - test/d3d12_ffx_upscale_test: end to end through the layer's own objects. Under Wine on RADV: RX 9070 XT FSR 4.1.2 0.49 ms, iGPU FSR 3.1.6 10.1 ms per 720p -> 1080p execute; 880/880 squares; a destroyed context is skipped; the test fails with the upscale call removed. Validation with sync validation: nothing from the layer (iGPU silent; on the 9070 XT only FSR 4.1.2's own shader errors). Full Linux and Windows builds; Linux ctest 48/50 (2 skipped); the d3d12_* tests under Wine fail the same 6 as main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…each way Two costs of the Upscale command, measured: - Prepared carried a std::vector for the Upscale images, 24 bytes on every command of every list, upscaler on or off (944 -> 968 bytes). The images now live in PreparedList::upscale_images, kept between executions like draws, and an Upscale names its first through Prepared::draw: Prepared is 944 bytes again. replay_cpu_bench's frame (37,888 commands): ~4,620 -> ~4,540 us, about 0.9 MB less touched per execute. - Emit issued one vkCmdPipelineBarrier per image piece, up to 14 per upscale. It now collects them (and one memory barrier for pieces already in place) into one barrier before the upscale and one after, with restrict_to_queue and layout_range as detail::image_barrier applies them; fixed-size storage, no heap allocation. Same results: d3d12_ffx_upscale_test PASS on the RX 9070 XT (FSR 4.1.2, 0.49 ms) and the iGPU (FSR 3.1.6); validation with sync validation reports nothing from the layer and no hazard; replay and command-list unit tests pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…C upscaler (part 2) shims/ffx_shim.cpp serves ffxCreateContext, ffxDestroyContext, ffxConfigure, ffxQuery and ffxDispatch for amd_fidelityfx_loader_xbox.dll and amd_fidelityfx_upscaler_xbox.dll, the two package modules that export them (which one the title calls needs its executable). The table registers before main and only with LEONIDA_FFX_PC=1; off, nothing is registered and the title loads the package's DLLs as before. It is a source of gta6rt itself: in the static library nothing would reference it and the linker would drop it. - create: the upscale description and the device of the console backend descriptor (0x01000002, device at +0x10) from the chain; the console's version and override descriptors are not passed on. The handle is the rt::ffx_upscale context number. - dispatch: one leonida::Upscale into the title's list (record_upscale). - query/configure: through AMD's loader (rt::ffx_upscale::query, configure); a context-less GET_VERSIONS gets the device's Vulkan handles, other context-less queries the Vulkan backend chained for the call; a global debug configure for effect 0 goes to the upscaler (AMD's PC loader answers effect 0 with UNKNOWN_DESCTYPE, measured). - Other description types: FFX_API_RETURN_ERROR_UNKNOWN_DESCTYPE, logged once. - ffx_vk_backend: query/configure pass-through, and the SDK 2.4.0 FFX_UPSCALER_VERSION (4.1.2) descriptor on create, without which the loader reports the newer API functions unavailable. - test/d3d12_ffx_scene.h: the scene both layer tests share (the part 1 test now uses it). test/d3d12_ffx_shim_test: the functions as the loader binds them, on (LEONIDA_FFX_PC=1) and off (--expect-off, nothing registered or owned). Under Wine on RADV: RX 9070 XT offered 4.1.2/3.1.6/2.3.4, context FSR 4.1.2, 30 dispatches 880/880; iGPU FSR 3.1.6, 880/880; off test passes; the test fails with the dispatch not recorded. Validation with sync validation: nothing from the layer or the shim. Full Windows build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kam471
left a comment
There was a problem hiding this comment.
Built and ran at 016df7f23 on Windows 11, RTX 5070 Ti, with the local FidelityFX SDK 3.1.6 provider (LEONIDA_FFX_DIR):
ctest -R 'ffx'-> 4/4 passed:ffx_vk_dispatch,d3d12_ffx_upscale,d3d12_ffx_shim,d3d12_ffx_shim_off.d3d12_ffx_shim_testruns the title's five console calls through the shim (create/destroy/configure/query/dispatch, the 4.1.1 version descriptor, the Xbox backend descriptor) and the upscale checks are the usual 880/880 and 1980/1980 centres with 0 non-finite.- The
--expect-offcase confirms nothing is registered and the package DLLs are not owned whenLEONIDA_FFX_PC=0. git diff --checkclean.
The FFX shim part 2 answers the title's five FidelityFX calls through the layer's PC upscaler, and the off switch is tested both ways. No blocking issue.
…cture alone RSK2707X's native Windows run on an RX 7600 (RDNA3, AMD 26.11.2) got FSR 4.1.2, where the comments said FSR 4.1 only on RDNA4 and RDNA2 discrete. The comments and docs/d3d12_vulkan.md A.3 now state what was measured: 4.1.2 on RDNA4 under RADV and on RDNA3 under AMD's Windows driver, 3.1.6 on an RDNA2 iGPU and on NVIDIA (RTX 3080 Ti, 4080, 5070 Ti), with the reviewers' Windows results. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…A_DEVICE_TYPE=6 Rockstar's statement on the console versions (VideoCardz, Alt Char, November 2026): the Series S renders at 720p and upscales to 1080p with FSR Upscaling 4, the package DLL's one configuration; the Series X and PS5 render at 1440p and reach 4K with Rockstar's own TAA. The runtime reports a Series X by default, so the shim is reached in the Series S mode (LEONIDA_DEVICE_TYPE=6), assuming the title picks its mode from the device type. Using FSR in the Series X mode would mean replacing the title's TAA pass, which needs the title running. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the shader errors there too amarovndres ran both tests on an RX 9060 XT with AMD 26.10.1: FSR 4.1.2, every square right, and under validation only the five known_provider_error entries, as under RADV and on the RX 7600. The A.3 note that RDNA4 on Windows was not run is replaced by that result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # docs/d3d12_vulkan.md
|
status: an automated review (Claude Code ultrareview) of this chain found issues. I'm fixing them now, so please hold off merging #4999 / #5139 / #5171 until I push. The important one: Also being fixed:
A rare race between |
…s DLL search path Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # runtime/src/ffx_vk_backend.cpp
…ons without VK_KHR_shader_fma headers, move a misplaced comment Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… code the Vulkan device in every device-carrying query The shim looked for 0x02000002, which the console DLL refuses, so the title's context would never be created; the test made the same mistake. Its id is now written out separately in the test, with a BACKEND_ID_XBOX control. GPU_MEMORY_USAGE_V2 (device at +0x10) and GET_VERSIONS with a context now get the layer's VkDeviceContext for the call, the title's device put back after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t but not yet submitted Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Fixed and pushed. The shim now uses the measured console backend ID (0x01000002 from the docs), and the test catches the old wrong one. Device-carrying queries (GPU memory usage, versions) get the right Vulkan device, the barrier batching keeps its sync info past 14 barriers, the FFX extensions no longer depend on the FMA |
# Conflicts: # runtime/CMakeLists.txt
# Conflicts: # runtime/CMakeLists.txt # runtime/src/vulkan_replay.h
# Conflicts: # runtime/CMakeLists.txt
|
Tested 9646184 on NVIDIA GeForce RTX 4080, driver 617.42: d3d12_ffx_shim_test --expect-off with LEONIDA_FFX_PC unset exits 0 and prints "PASS: with LEONIDA_FFX_PC off nothing is registered and the package's FFX DLLs are not owned". d3d12_ffx_upscale_test builds but was not run, and the enabled path (LEONIDA_FFX_PC=1) was not run because it needs the FidelityFX SDK DLLs, which are not on this machine. AI-assisted. |
|
Note on the red AI-assisted. |
|
Tested 9646184 merged with main 28f8653 on Linux/Python 3.12.16: concern. The merge with main conflicts in runtime/CMakeLists.txt, runtime/shims/d3d12_com.cpp and runtime/src/command_list.h, so the branch needs a rebase. No tests were run (the changes are native C++ and GPU tests, not run on Linux). |
# Conflicts: # runtime/CMakeLists.txt
# Conflicts: # runtime/shims/d3d12_com.cpp # runtime/src/command_list.h
Item: the FFX upscale shim (claim: #5032 (comment)), part 2 of 2: the shim table that answers the title's five FidelityFX calls with part 1's layer path.
Depends on: #5139 (part 1, the layer's Upscale command), which depends on #4999 (the backend). This branch carries both; this PR's own work is
016df7f2and the docs commit after it (plus a merge of the chain's wording fix).Draft until #5139 and #4999 are ready.
What
shims/ffx_shim.cppservesffxCreateContext,ffxDestroyContext,ffxConfigure,ffxQueryandffxDispatchfor both package modules that export them:amd_fidelityfx_loader_xbox.dll;amd_fidelityfx_upscaler_xbox.dll.dumpbinshows 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 withLEONIDA_FFX_PC=1in the process environment. The shims then own both modules: imports andLoadLibrary/GetProcAddressresolve 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_offchecks this.In
gta6rt: the file is a source ofgta6rtitself, 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 type0x01000002with the device at+0x10, measured indocs/d3d12_vulkan.mdA.3; the code asserts the offset.FFX_UPSCALER_VERSION(4.1.2) instead. Without it, AMD's loader reported that the newer API functions are unavailable.rt::ffx_upscalecontext number.UNKNOWN_DESCTYPE; no backend descriptor or device isERROR_PARAMETER.ffxDispatch: oneleonida::Upscalerecorded into the title's list (d3d12 layer: an Upscale command replayed through AMD's PC upscaler (FFX shim, part 1) #5139). Other dispatch types (the reactive-mask generator, …) areUNKNOWN_DESCTYPE, logged once per type.ffxQuery/ffxConfigure: pass through to AMD's loader, with these exceptions:GET_VERSIONSnames the title's D3D12 device, which is replaced by that device's Vulkan handles;UNKNOWN_DESCTYPE(measured).ffxDestroyContext:rt::ffx_upscale::destroy(part 1: it waits for idle under the submit lock).test/d3d12_ffx_scene.hholds the scene both layer tests share; the part 1 test now uses it, which removes about 200 duplicated lines.d3d12_ffx_shim_testcalls the five functions as the loader binds them (rt::shims::findon 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:
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=6reports a Series S, the mode that reaches this shim. That suits weaker GPUs: 720p rendering with PC FSR 4.1 or 3.1.docs/d3d12_vulkan.mdA.3.Performance
ffxDispatch: a field-by-field copy into a 136-byteUpscaleand onerecord_upscale, O(1). Replay cost is part 1's: one barrier each way, then AMD's dispatch.ffxCreateContext/ffxDestroyContext: rare, at resolution changes.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 setsLEONIDA_FFX_PCper test):d3d12_ffx_shimd3d12_ffx_shim_offd3d12_ffx_upscaleffx_vk_dispatchffxDispatchreturning OK without recording, the shim test reports 440/880 and FAIL.LEONIDA_FFX_DIR,d3d12_ffx_shimandd3d12_ffx_upscaleskip (77).01387.test_ctest_registration.py,test_cmake_vulkan_missing.py,test_runtime_paths.pyand thetest_docs_*checks pass.No game files. AI-assisted (Claude Code).
🤖 Generated with Claude Code