Repository navigation
d3d12 layer: an Upscale command replayed through AMD's PC upscaler (FFX shim, part 1) - #5139
AwkGrep256 wants to merge 17 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>
Kam471
left a comment
There was a problem hiding this comment.
Built and ran both at 8af9ed0b7 on Windows 11, RTX 5070 Ti, with the local FidelityFX SDK 3.1.6 provider (LEONIDA_FFX_DIR pointing at its signedbin):
d3d12_ffx_upscale_test-> PASS, exit 0:upscale context 1280x720 -> 1920x1080, provider 3.1.6; 30 upscales at 0.41 ms each; 0 non-finite outputs; 880 of 880 square centres within 0.1; an Upscale naming a destroyed context executes the list and skips the command.ffx_vk_dispatch_test-> PASS, exit 0: 30 upscales at 0.35 ms (720p) and 30 at 0.94 ms (1080p -> 4K); 0 non-finite; 880/880 and 1980/1980 centres exact.- Without
LEONIDA_FFX_DIRboth skip with 77 and a message naming the loader DLL, as documented.git diff --checkclean.
The D3D12 Upscale command is now replayed through AMD's PC upscaler through the FFX shim, with the Vulkan backend and replay handoff, and the two tests verify the image result at both scales. No blocking issue.
|
Independent check — build clean; test gated (Windows 11, NVIDIA RTX 5090, driver 617.42, Vulkan SDK 1.4.363.0).
The skip is graceful and correctly scoped — it runs only after the device-side objects initialise, so the wiring compiles and probes fine. AI-assisted (Devin); no game files. |
…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>
…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>
|
Tested The driver offers all three of
With
Under validation, the layer test's time per execute rises to 2.53 ms. Timings are slower than the RX 9070 XT numbers in the doc (0.41 ms to 1080p on RADV). The 9060 XT has half the compute units, so that is expected, and it isn't a like-for-like driver comparison. AMD's DLLs stayed in a scratch folder and are not in this comment or any commit. AI-assisted (Claude Code). Procedural inputs only, no game files. |
|
Thanks @amarovndres, that's the case the doc still listed as not run: RDNA4 on AMD's Windows driver. FSR 4.1.2 passes in both tests, the destroyed-context command is skipped, and there are no sync hazards. Your validation table is useful too. The NVIDIA-named AI-assisted (Claude Code). |
… 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
…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>
…t but not yet submitted Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # runtime/CMakeLists.txt
# Conflicts: # runtime/CMakeLists.txt # runtime/src/vulkan_replay.h
|
Tested
No new failure compared with |
|
Tested |
# Conflicts: # runtime/CMakeLists.txt
# Conflicts: # runtime/shims/d3d12_com.cpp # runtime/src/command_list.h
|
Tested
Not run: other GPUs/vendors, Linux, anything that needs game files. No game files. AI-assisted (Claude Code). |
|
Tested
No game files. AI-assisted (Claude Code). |
Item: the FFX upscale shim (claim: #5032 (comment)), 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: #4999. This branch carries #4999's commits; this PR's own work is the last two commits,
8af9ed0b(the command) and3c05c379(its costs, see Performance).Draft until #4999 is 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: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.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.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