Files
DroidDeck/tools/upscale/layer
The412Banner 7aa54ab9c7 upscale: hide VK_EXT_descriptor_buffer from games so Full FSR 4.1 shows the picture
Root cause of the black Full FSR 4.1 frame in D3D12 games on Turnip: vkd3d-proton uses its own
descriptor buffers in the command buffers the upscaler records into. Measured on the Red Magic 12
Pro (Adreno 850) with the XeSS DX12 sample: Full black in 9/9 shots, and still black with the direct
output write off and with the exposure pass off; with VKD3D_DISABLE_EXTENSIONS=VK_EXT_descriptor_buffer
the picture is there (5/6 shots coloured, the sixth caught the triangle off screen, as with the other
engines), with the direct write on.

The layer now hides the extension from the game (vkd3d then uses its classic descriptors) and still
enables it for itself; DROIDDECK_UPSCALE_APP_DESCRIPTOR_BUFFER=1 shows it again. The Lite fallback
now triggers only when the game enabled descriptor buffers anyway (Turnip), not for every D3D12
frame. The FULL_DIRECT_OUT / FULL_AUTO_EXPOSURE test switches are removed.
2026-12-04 20:43:28 -05:00
..

VK_LAYER_DROIDDECK_upscale

A Vulkan layer that runs the upscaler calls of Windows games (FSR 4 / FSR 3 / FSR 2 through FidelityFX, DLSS through NGX, XeSS) on the device: on the Adreno GPU, or on the Snapdragon Hexagon NPU through Qualcomm QNN. The Windows side is a set of bridge DLLs (amd_fidelityfx_*.dll, nvngx.dll, libxess.dll, ...). They talk to this layer through two Vulkan buffers with magic sizes and a vkCmdUpdateBuffer doorbell (fsr4_seam_proto.h). That protocol, its buffer sizes, magic values and backend IDs are unchanged from upstream, so the upstream bridge DLLs work against this layer.

Layer name VK_LAYER_DROIDDECK_upscale, library libVkLayer_droiddeck_upscale.so, implicit layer. The manifest template VK_LAYER_DROIDDECK_upscale.json turns it on with DROIDDECK_UPSCALE=1 and off with DROIDDECK_UPSCALE_DISABLE=1.

Origin, credits, licence

GPL-3.0, like DroidDeck. Ported from app/src/main/cpp/fsr4npu/ of michaelisomer-cyber/Winlator-NeuralScale at commit a0ab6b0f770e1a6786b4e68def46b4edb8baafd0, updated to 71c140d9e5586f659251c3ebc602f2d21923655c (upstream r5: full FSR 4.1 on the NPU, ghosting fix, S8/U8 Lite graphs, SGSR 2, D3D11 DLSS) (GPL-3.0). From r5 DroidDeck leaves out upstream's root-only parts (performance/thermal manager, GPU clock floor, bypass charging) and keeps its own NPU detection (DROIDDECK_UPSCALE_NPU, set by the app for any HTP generation it finds, including the phone's own QNN libraries) and Intel's XeSS 3. That project is a fork of StevenMXZ/Winlator-Ludashi. The first commit that adds this folder holds the upstream files unchanged; the DroidDeck changes are in the commits after it.

Work this code builds on, as credited upstream:

Files

File What
fsr4_layer.c Loader interface, device/extension/feature injection, GPU/DLSS spoof, seam mailbox + doorbell, ctrl and status files
fsr4_pipeline.c/.h Backend dispatch and fallbacks, FSR 4.1.1 Full NPU (external pack) path
fsr4_builtin.c/.h FSR 4.0.2 INT8 on the NPU; no longer dispatched since r5 (full FSR 4.1 runs on the NPU instead)
fsr412_lite.c/.h FSR 4.1.2 Lite INT8, GPU DP4a or NPU
fsr411_full_gpu.c/.h FSR 4.1.1 Full INT8 on the GPU
fsr3_gpu.c/.h FSR 3.1 on the GPU, also the fallback for every other backend
sgsr2_gpu.c/.h Snapdragon Game Super Resolution 2 on the GPU (sgsr2_*.spv)
fsr4_qnn.c/.h QNN/FastRPC/AHardwareBuffer runtime; stubs only in glibc builds
fsr4_seam_proto.h Shared protocol with the Windows bridge DLLs (do not change)
fsr_gpu_timer.h GPU timestamp helper for the status file
dd_upscale_compat.h DroidDeck env lookup and logging (logcat, or stderr in glibc builds)
shaders/*.comp GLSL source of fsr3_*.spv, fsr4_builtin_*.spv, fsr412_lite/lite_npu_{pack,unpack}.spv
scripts/pack_*.py Build fsr4_v07_i8.wpack and fsr412_lite/fsr412_lite_i8.wpack from the AMD weights
CMakeLists.txt APK build (bionic), added from app/src/main/cpp/CMakeLists.txt
build-glibc.sh PRoot guest build (glibc), called by tools/components/recipes/runtime.sh

Builds

  • APK (bionic, arm64-v8a, minSdk 26): Gradle's NDK build makes libVkLayer_droiddeck_upscale.so through add_subdirectory(../../../../tools/upscale/layer upscale_layer). Links android log dl m, -Wl,-z,max-page-size=16384 -Wl,-Bsymbolic. The manifest's relative library_path is meant to be rewritten to the absolute path by the app.
  • PRoot guest (glibc): tools/upscale/layer/build-glibc.sh OUT (CC, default aarch64-linux-gnu-gcc; Vulkan headers from VK_INCLUDE or the NDK). Built with -DDD_UPSCALE_NO_ANDROID: no AHardwareBuffer, FastRPC, QNN or liblog (logs go to stderr). Every NPU init fails with npu_unavailable and the backends take their GPU fallbacks. OUT gets the library and a manifest with library_path /usr/local/lib/droiddeck-upscale-layer/libVkLayer_droiddeck_upscale.so (override with DD_UPSCALE_GUEST_LIB). The runtime recipe installs both into app/src/main/assets/linuxfs/usr/local/lib/droiddeck-upscale-layer/.
  • -Bsymbolic is needed in both builds: the layer exports vkGetInstanceProcAddr, and a libvulkan already in the global symbol scope would otherwise win the lookup (the loader then fails with Failed to find 'vkCreateInstance').

Environment

Each key is read as DROIDDECK_UPSCALE_<KEY> first, then WINLATOR_FSR4_<KEY> (dd_upscale_compat.h). Empty values count as unset.

Key Read at Meaning
DIR (then DM_FSR4_DIR) fsr4_pipeline.c:566, :826 Data dir (layout below). Unset: no backend can load its files, frames get a plain blit. No built-in fallback path
POWER fsr4_pipeline.c:575, :830 HTP power vote: burst, turbo (default), balanced/nom, low
BACKEND, then ENGINE fsr4_layer.c:458 Start backend (names under ctrl file). Unset: Auto
APP_DESCRIPTOR_BUFFER fsr4_layer.c hide_app_descriptor_buffer 1 = let the game see VK_EXT_descriptor_buffer. Default: hidden from the game (the layer still uses it), because vkd3d-proton's own descriptor buffers make FSR 4.1.1 Full write a black frame on Turnip
FULL_ON_TURNIP fsr4_pipeline.c full_black_here 1 = run FSR 4.1.1 Full on Turnip even when the game enabled descriptor buffers itself. Default: Lite stands in then
NPU_SYNC fsr4_layer.c:462 1 = GPU waits for the NPU each frame. Anything else = async (default). sync/true also mean sync
SHARPNESS fsr4_layer.c:464 RCAS 0.0-1.0, default 0.55
PRESET fsr4_pipeline.c:1239 ultraperf or performance forces the preset; else from the game's quality mode / ratio
CTRL_FILE fsr4_layer.c:472 Live control file, format below
STATUS_FILE fsr4_layer.c:526 Live status file, format below
NATIVELIB_DIR fsr4_qnn.c:311 Folder with the Qualcomm host libraries (see NPU setup)
HTP_ARCH fsr4_qnn.c:237 Optional override of the HTP arch (v79, v81) used for the cache folder
SPOOF_DLSS fsr4_layer.c:557, :583 1 = expose VK_NVX_binary_import / VK_NVX_image_view_handle (stub functions) and report an RTX 2060 vendorID/deviceID/name
GPU_SPOOF fsr4_layer.c:570 Words split by , + ; or blanks: rtx / rdna4 pick the reported GPU; 1 also rewrites driverID/driverName/driverInfo; off/none/0 keep the real GPU even with SPOOF_DLSS=1
VRAM_OVERRIDE fsr4_layer.c:757 1 = report VRAM_MB as the size of every device-local heap (and its budget). Off otherwise
VRAM_MB (then WRAPPER_VMEM_MAX_SIZE) fsr4_layer.c:759 Heap size in MB for VRAM_OVERRIDE=1, 512-65536
RDR2_PATCH fsr4_layer.c:235 1 = patch RDR2.exe's DLSS vendor checks in memory. Off otherwise (Arxan crashes after loading with it)
LOG fsr4_qnn.c:145, fsr4_pipeline.c:443 2 = verbose QNN log and every NPU dispatch logged
JX, JY, MX, MY fsr4_pipeline.c:1387-1390 Debug: jitter and motion-vector scale multipliers for the external FSR 4.1.1 NPU pack, default 1

Not prefixed: ADSP_LIBRARY_PATH (read and, if <DIR>/adsp is missing from it, prepended by the layer, fsr4_qnn.c:262), LD_LIBRARY_PATH (searched for QNN libraries, fsr4_qnn.c:303). Upstream's WINLATOR_FSR4_DISABLE_LAYER only lived in its manifest; the C code never read it. Here the loader switch is DROIDDECK_UPSCALE_DISABLE=1.

Spoof examples: SPOOF_DLSS=1 gives RTX 2060 IDs with the real driverID; add GPU_SPOOF=1 for VK_DRIVER_ID_NVIDIA_PROPRIETARY too. GPU_SPOOF=rdna4 gives Radeon RX 9070 XT IDs, GPU_SPOOF=rdna4,1 adds the AMD driverID. Upstream rewrote the driverID whenever GPU_SPOOF was rtx or rdna4; here that needs the 1 word.

Ctrl file (read)

read_live_ctrl, fsr4_layer.c:454-505. Re-read at most every 200 ms, when a doorbell arrives and at vkCreateDevice. One key=value per line; keys missing from the file keep their last value (first the env values):

enabled=1          # 0, off..., false... = bypass (plain blit); anything else = on
backend=fsr4_1_lite_gpu
engine=fsr4_1_lite_gpu   # same as backend=, upstream writes both
npu_sync=async     # 1, sync..., true... = sync; anything else = async
sharpness=0.55     # clamped to 0..1

Backend names, matched by prefix (parse_backend_str in fsr4_layer.c): xess/xess3 = XeSS 3 DP4a (1, runs in the bridge), fsr4_0_npu/fsr4_npu = FSR 4.1 Full NPU (4; FSR 4.0.2 is gone since r5), sgsr2/snapdragon/gsr2 = SGSR 2 (7), fsr4_1_full_npu/412_full_npu (4), fsr4_1_full_gpu/412_full_gpu (6), fsr4_1_lite_gpu/412_lite_gpu (5), fsr4_1_lite_npu/412_lite_npu/fsr4/npu (3), fsr3/gpu = FSR 3.1 GPU (0), auto or anything else = Auto (8). If the first line has none of these keys, it is a bare flag: containing 0, off or false turns the upscaler off, anything else on.

Status file (written)

write_live_status, fsr4_layer.c:507-553. Written to <STATUS_FILE>.tmp, then renamed over STATUS_FILE. At most every 250 ms unless enabled/backend/sync/NPU use/quality/render width changed; always at vkCreateDevice. Exactly these lines in this order:

layer=1
driver=<real GPU name>
ahb=<pending|gpu_only|zc|staging|zc_avail|staging_avail|zc_pending|zc_failed>
npu_state=<standby|ready|compiling|failed|cached|ready_to_compile|no_pack|fsr3_gpu|xess3_dp4a|fsr412_lite_gpu|fsr411_full_gpu|...>
rdr2_patch=<none|partial|ok>
engine=<fsr3|fsr4>
backend=<fsr3_gpu|xess3_gpu|sgsr2_gpu|fsr4_1_lite_npu|fsr4_1_full_npu|fsr4_1_lite_gpu|fsr4_1_full_gpu|auto>
backend_tag=<what really ran, e.g. FSR4.1-Lite-GPU (NPU fallback)>
npu_sync=<sync|async>
sharpness=<%.2f>
enabled=<0|1>
active=<0|1>
npu=<0|1>
api=<None|FSR 4 (Vulkan)|FSR 4 (DX12)|DLSS (Vulkan)|DLSS (DX12)|XeSS (Vulkan)|XeSS (DX12)|FSR 3 (...)|FSR 2 (...)>
quality=<Native AA (DLAA)|Ultra Quality|Quality|Balanced|Performance|Ultra Performance|Auto>
render=<w>x<h>
output=<w>x<h>
preset=<perf|ultraperf>
gpu_us=<u32>
htp_us=<u32>
dispatches=<u64>
reason=<ok|standby|bypass_off|ok_fsr3_gpu|missing_fsr3_shaders|npu_unavailable|...>
ts_ms=<CLOCK_REALTIME ms>

Data dir (DROIDDECK_UPSCALE_DIR)

Same tree as upstream's app/src/main/assets/fsr4/. None of it is in this repo; it is installed at run time. Paths the layer opens, relative to the dir:

Path Used by Built here?
fsr3_prepare.spv, fsr3_accumulate.spv, fsr3_rcas.spv FSR 3.1 GPU (fsr3_gpu.c:343, :385) Source in shaders/. Upstream's files look like glslc -O --target-env=vulkan1.1 output (Shaderc, SPIR-V 1.3); a local build of that is close in size, not byte-identical. Not built by the layer builds
fsr4_builtin_pre.spv, fsr4_builtin_post_a.spv, fsr4_builtin_post_b.spv FSR 4.0.2 NPU (fsr4_builtin.c:560, :609) Source in shaders/
fsr4_v07_i8.wpack FSR 4.0.2 NPU graph (fsr4_qnn.c:1583) scripts/pack_fsr4_weights.py, needs fsr4-hexagon and AMD weights
fsr412_lite/0000.spv ... 0010.spv, 0013.spv, weights.bin FSR 4.1.2 Lite (fsr412_lite.c:410, :688) No: precompiled AMD FidelityFX SDK passes (per upstream)
fsr412_lite/lite_npu_pack.spv, lite_npu_unpack.spv Lite NPU (fsr412_lite.c:618) Source in shaders/
fsr412_lite/fsr412_lite_i8.wpack Lite NPU graph (fsr412_lite.c:456) scripts/pack_fsr412_lite_weights.py, needs vela + weights.bin
fsr411_full/{quality,performance}/pass-00.spv ... pass-27.spv, initializers.bin FSR 4.1.1 Full GPU (fsr411_full_gpu.c:328, :346) No: precompiled AMD FidelityFX SDK passes (per upstream)
fsr411_full/performance/fsr411_full_zc_{s8,i8}.wpack FSR 4.1.1 Full NPU graph, S8 first then U8 (r5) No (upstream scripts/pack_fsr411_full_npu.py)
fsr412_lite/fsr412_lite_zc_{s8,i8}.wpack FSR 4.1.2 Lite NPU graph, S8 first then U8 (r5) No (upstream scripts/build_fsr412_lite_tiers.py)
sgsr2_convert.spv, sgsr2_activate.spv, sgsr2_upscale.spv SGSR 2 (sgsr2_gpu.c) Source in shaders/
adsp/libQnnHtpV79Skel.so, adsp/libQnnHtpV81Skel.so NPU side, loaded by FastRPC through ADSP_LIBRARY_PATH; also probed for the arch (fsr4_qnn.c:224) No: Qualcomm QNN
<arch>/fsr4_v07_i8_cache.bin, <arch>/fsr412_lite_i8_cache.bin Compiled NPU graphs, written by the layer on first use Made on the device
1080/{performance,ultraperf}/pass-00.spv, pass-01-npu.spv, pass-28.spv, initializers.bin, v81/nf4_k1h.bin, v81/nf4up_k1h.bin Optional external FSR 4.1.1 Full NPU pack (fsr4_pipeline.c:460-478, fsr4_qnn.c:1018); v81 only No
jni/arm64-v8a/<lib>, <lib> First two places searched for QNN host libraries No

<arch> is v79 or v81: HTP_ARCH if set, else the SoC (ro.soc.model / ro.vendor.qti.soc_model starting with SM8750 = v79, SM8850 = v81, or ro.vendor.qti.soc_name / ro.board.platform sun = v79, canoe = v81), else the libQnnHtpV<NN>Stub.so mapped in the process, else the only skel present in adsp/, else htp (fsr4_qnn.c:176-250). Upstream always used v81/.

NPU setup (Android build only)

  • Host libraries: libQnnSystem.so, libQnnHtp.so, libQnnHtpV79Stub.so, libQnnHtpV81Stub.so, libQnnHtpPrepare.so (on-device graph compile). Searched in this order (fsr4_qnn.c:303): <DIR>/jni/arm64-v8a/, <DIR>/, <NATIVELIB_DIR>/, each LD_LIBRARY_PATH entry, then the bare name (Android sphal namespace first, then the default one).
  • libQnnHtp.so opens the arch stub by name itself. The layer loads libQnnHtpV<arch>Stub.so (both stubs when the arch is unknown) from the same search list first (fsr4_qnn.c:364), so NATIVELIB_DIR alone is enough; LD_LIBRARY_PATH does not have to name the folder.
  • ADSP_LIBRARY_PATH must list <DIR>/adsp (the skels), ;-separated, e.g. <DIR>/adsp;/vendor/dsp/cdsp;/vendor/lib/rfsa/adsp;/system/lib/rfsa/adsp. The layer prepends <DIR>/adsp itself when it is missing.
  • libcdsprpc.so comes from the vendor partition.

DroidDeck changes from upstream

  • Layer name, library name, log tags, manifest (implicit, DROIDDECK_UPSCALE / DROIDDECK_UPSCALE_DISABLE).
  • DROIDDECK_UPSCALE_<KEY> env with WINLATOR_FSR4_<KEY> fallback.
  • No hardcoded /data/user/0/com.winlator.cmod/files/fsr4 fallback; no data dir means GPU blit.
  • Compiled NPU graph caches in <DIR>/<arch>/ instead of <DIR>/v81/.
  • driverID/driverName/driverInfo rewrite only with GPU_SPOOF word 1; SPOOF_DLSS=1 alone reports RTX vendor/device IDs.
  • Arch stub preloaded from the library search list (NATIVELIB_DIR works without LD_LIBRARY_PATH).
  • glibc build (DD_UPSCALE_NO_ANDROID) with QNN stubs and stderr logging.
  • -Bsymbolic link flag; pack scripts take their paths as arguments instead of the author's Windows paths.