mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 22:30:53 +01:00
[PR #150] d3d12 layer: an Upscale command replayed through AMD's PC upscaler (FFX shim, part 1) #202
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#202
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/150
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:old-pr/9882📝 Commits (10+)
c8d136druntime: AMD's PC FidelityFX upscaler on the layer's Vulkan device (RT-344)e312253ffx_vk: enable the extensions the upscaler's shaders use; the test fails on validation errors (#4999 review)be631dbffx_vk_dispatch_test: the console's 1080p configuration and a 4K case8af9ed0d3d12 layer: an Upscale command replayed through AMD's PC upscaler (FFX shim, part 1)3c05c37replay: Upscale images in a PreparedList side table, and one barrier each waya2766d2ffx_vk: the loader's choice depends on GPU and driver, not on architecture alonea2fb835Merge branch 'rt-344-ffx-vk' into ffx-upscale-shim8abab27docs: FSR 4.1.2 on RDNA4 under AMD's Windows driver (RX 9060 XT), and the shader errors there too3e06827Merge branch 'rt-344-ffx-vk' into ffx-upscale-shimc1e976affx_vk: load the provider by full path instead of changing the process DLL search path📊 Changes
15 files changed (+1533 additions, -8 deletions)
View changed files
📝
docs/d3d12_vulkan.md(+45 -0)📝
runtime/CMakeLists.txt(+20 -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_upscale.cpp(+235 -0)➕
runtime/shims/ffx_upscale.h(+44 -0)📝
runtime/src/command_list.h(+26 -1)➕
runtime/src/ffx_vk_backend.cpp(+73 -0)➕
runtime/src/ffx_vk_backend.h(+84 -0)📝
runtime/src/vulkan_backend.h(+11 -1)📝
runtime/src/vulkan_replay.h(+134 -1)➕
runtime/test/d3d12_ffx_upscale_test.cpp(+307 -0)📝
runtime/test/ffx_api_min.h(+25 -5)➕
runtime/test/ffx_vk_dispatch_test.cpp(+463 -0)📄 Description
Original description (mentions and
#Nreferences are disabled; the numbers refer to the old repository):Resubmitted unchanged: this was
#5139, 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 (c75c03a98), which merges cleanly onmain7e39a81ea. The test reports from other contributors are on#5139.Item: the FFX upscale shim (claim: https://github.com/ItsNotRexed/Leonida/issues/5032#issuecomment-7095090683), part 1 of 2: the layer side. Part 2 is the shim table that answers the game's five
ffx*calls; it calls into this.Depends on:
#9877. This branch carries#9877's commits; this PR's own work is the last two commits,8af9ed0b(the command) and3c05c379(its costs, see Performance).Draft until
#9877is ready.What
The game's
ffxDispatchbecomes one recorded command in its D3D12 command list.ExecuteCommandListsreplays it through AMD's PC upscaler on the layer's ownVkDevice. This follows the shape of the existingxdxr_recordreplay hook.It is off unless
LEONIDA_FFX_PC=1. With it off, the device and replay behave as before; nothing new runs.command_list.h:leonida::UpscaleholdsFfxDispatchDescUpscale's fields, with the images as resource ids.CommandList::upscalerecords it and checks the required images and sizes.vulkan_replay.h: two hooks,upscale_readyandupscale.detail::round_tripuses. It records the upscale, then moves every image back.vulkan_backend.h: an Upscale counts as shader work.set_upscaler()sets the hooks once, before the device is handed out, because replay reads them without a lock.shims/ffx_upscale.{h,cpp}: the upscale contexts of a device (create,destroy,provider), the hooks, and the FfxApiSurfaceFormat for each VkFormat.d3d12_vulkan_device.cpp, only when the switch is on:#9877's wanted extensions, and the core features the upscaler's shaders declare, each where the GPU has it;d3d12_com:rt::d3d12::record_upscale, which refuses bundles and copy lists.ffx_vk_backend:getenv_s, the way the layer reads its variables (getenvwarned under/W4).Performance
With the upscaler off, which is the default:
Commandstays 296 bytes, becauseUpscale(136 bytes) is smaller thanDraw(288). A replay entry (detail::Prepared) stays 944 bytes.runs_shaders. That's O(1) per command.replay_cpu_bench's frame (37,888 commands, layer only) takes about 4,540 µs, the same asmainwithin noise.3c05c379fixed:8af9ed0bput astd::vectorin everyPrepared(944 → 968 bytes, about 0.9 MB more touched per execute of that frame). The images now live in aPreparedListside table, kept between executions likedraws. That brought the frame back from about 4,620 µs.With it on, per Upscale command:
std::mapover the contexts, of which there is normally one.vkCmdPipelineBarrierbefore the upscale and one after, from fixed-size storage with no heap allocation (8af9ed0bissued up to 14);ffxDispatch.#9877's test), on an RX 9070 XT.Rare costs:
destroy()and device teardown wait for the device to go idle. That only happens on a resolution change or at exit.Stability
destroy()and device teardown wait for the device under the submit lock before freeing a context. That's the pattern the bindless set uses, and it's needed because aVkQueueneeds external synchronization. It costs a stall on a resolution change, never per frame.Validation
Run with the host's
VK_LAYER_KHRONOS_validationbeneath Wine, with synchronization validation on and no duplicate limit.storageBuffer16BitAccess(RuntimeSpirv-storageBuffer16BitAccess-11161);variablePointersStorageBufferandvariablePointers;shaderInt8andshaderFloat16;vulkanMemoryModelandvulkanMemoryModelDeviceScope(RuntimeSpirv-vulkanMemoryModel-06265).These are now enabled when the switch is on.
vkCreateDevice-…-01387.#9877(SPV_NV_cooperative_matrix2, which RADV doesn't offer; two spirv-val rejections; 3-component writes).rw_recurrent_0on FSR 4,rw_accumulation,rw_spd_mip*and others on FSR 3.1.Reviews
8af9ed0b, native Windows 11, RTX 5070 Ti. Bothd3d12_ffx_upscale_testandffx_vk_dispatch_testPASS: FSR 3.1.6, 880/880 (1980/1980 at 4K), 0.41 ms through the layer. The destroyed-context case was skipped, both tests skip with 77 without the DLL, and "no blocking issue". (3c05c379came after this run; it changes only how replay stores and batches, and gives the same results below.)Tested
Built with clang-cl 23.1.5 + xwin, run under Wine 11.22 on CachyOS, Mesa 26.3.1 RADV, FidelityFX SDK 2.4.0 DLLs.
d3d12_ffx_upscale_test(new) goes end to end through the layer's own D3D12 objects. Its inputs:It records the step with
record_upscale30 times, then reads the output back:At
3c05c379:ctest: 48 of 50 pass, the other 2 skip (corpus, validation layer); that includes the 10 replay and command-list unit tests.d3d12_*tests under Wine, upscaler off: 62 of 68 pass. The same 6 fail when built frommain(fence_timing,indirect_dispatch_count,private_data,subresource_copy,heap_properties,residency).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.