Skip to content

Implement PE Loader and FSR 4 Upscaling for Linux - #236

Open
Aeternitae wants to merge 10 commits into
droogie:masterfrom
Aeternitae:FSR4LinuxTest
Open

Aeternitae wants to merge 10 commits into
droogie:masterfrom
Aeternitae:FSR4LinuxTest

Conversation

@Aeternitae

@Aeternitae Aeternitae commented Nov 10, 2026 •

Copy link
Copy Markdown

Apologies in advance if this is a bit messy, it's my first pull request so I'm still learning. This DOES NOT enable frame generation as frame generation was far too buggy when I attempted using it with the PE Loader. This was entirely done by Gemini 3.8 Flash. I don't expect this to be pulled but I'm hoping it at the very least helps get FSR 4 working in bbhost on Linux.

Summary

Enables AMD FidelityFX Super Resolution (FSR 4.1.2) on Linux x86-64 without requiring Wine, Proton, or external runtime wrappers.

Up to now, AMD's FSR 4 in bbhost has been Windows-only because AMD distributes the Vulkan backend solely as precompiled Windows x64 PE DLLs (amd_fidelityfx_loader_vk.dll, amd_fidelityfx_upscaler_vk.dll). On Linux, only DLSS, FSR 3 and TAA was available (via the native libngx_bridge.so and libbbhost_fidelityfx_vk.so), leaving AMD users on Linux without FSR 4 upscaling.

This PR introduces a lightweight, zero-overhead in-process PE32+ loader and Win32/Vulkan MS-ABI bridge (src/host/pe_loader.cpp). It allows upscaler_bridge.dll and the AMD FidelityFX DLLs to run directly within the native Linux bbhost process and communicate with the system's Vulkan ICD (Mesa RADV, AMDVLK, NVIDIA).

Technical Architecture

In-Process PE32+ Loader (src/host/pe_loader.cpp, src/host/pe_loader.h)

Memory Mapping & Relocations: Loads PE32+ DLLs directly using mmap() with proper section permissions (PROT_READ, PROT_WRITE, PROT_EXEC) and applies base relocations (IMAGE_REL_BASED_DIR64).
Win32 Runtime Emulation: Implements clean, self-contained replacements for standard Win32 kernel calls required by the FidelityFX runtime:
Memory: VirtualAlloc, VirtualFree, VirtualProtect, HeapAlloc, HeapFree.
Synchronization: Win32 Events (CreateEventW, SetEvent, ResetEvent, WaitForSingleObject), Critical Sections, SRW Locks, and condition variables.
Timing: QueryPerformanceCounter / QueryPerformanceFrequency mapped directly to Linux CLOCK_MONOTONIC_RAW.
Fibers & TLS: Thread-Local Storage index allocation (FlsAlloc, FlsGetValue, FlsSetValue) and execution of PE TLS callbacks (IMAGE_TLS_DIRECTORY64).
TEB / GS Segment Emulation: Scans and patches MSVC TEB dereferences (mov rax, gs:[0x30], mov r11, gs:[0x10], mov rax, gs:[0x58]) to point to emulated thread data blocks.
Entry Point Execution: Executes DllMain(DLL_PROCESS_ATTACH) and resolves exported symbols via IMAGE_DIRECTORY_ENTRY_EXPORT.

MS-ABI ↔ System V Calling Convention Bridge

Windows x64 binaries use the Microsoft x64 calling convention (RCX, RDX, R8, R9, 32-byte shadow space), while Linux x86-64 uses System V AMD64 (RDI, RSI, RDX, RCX, R8, R9).
Marked bridge callbacks in third_party/upscaler_bridge/upscaler_bridge.h with attribute((ms_abi)) (UB_CALL).
Generated dynamic JIT trampolines (create_ms2sysv_stub) that marshal Vulkan function pointers returned to PE DLLs from MS-ABI to native System V Vulkan driver entry points.

Upscaler Host Integration (src/host/upscaler.cpp, src/host/options.cpp)

Updated upscaler_open() on Linux to discover upscaler_bridge.dll beside the executable or in third_party/upscaler_bridge/bin/ and load it via pe_load_library().
Connected instance and device initialization hooks to wrap Vulkan function resolvers (vkGetInstanceProcAddr / vkGetDeviceProcAddr).
Enabled FSR 4.1.2 in the setup window and in-game Options menu on Linux x86-64.
Full integration with upstream v0.2.32 features.

Build System & Verification (CMakeLists.txt, tests/fsr_hardware_test.cpp)

Added conditional compilation of pe_loader.cpp on Linux + x86_64.
Automated post-build copy of FidelityFX DLLs from third_party/upscaler_bridge/bin/ to the build directory.
Added a standalone hardware verification test (fsr_hardware_test) that creates a real Vulkan device, validates FSR 4 device extensions/features, and records/executes both FSR 4 and FSR 3 compute passes on the GPU.

Hardware Verification

Verified on:

OS: Linux x86-64 (Arch Linux, kernel 6.13)
GPU: AMD Radeon RX 7900 XTX (RADV NAVI31, Vendor 0x1002, Device 0x744c)
Driver: Mesa RADV 26.2.6-arch3.1, Vulkan 1.3.313

@Aeternitae Aeternitae changed the title Implement PE Loader and FSR 4 / FSR 3 Upscaling for Linux Implement PE Loader and FSR 4 Upscaling for Linux Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant