perf(vk): cut AMD FSR 4 INT8 Lite dispatch time 27-33% (+5-11% FPS, +32% 1% low at 33% scale) on AMD LLPC GPUs via direct unroll and selective Wave64 #2495

Open
Jer9 wants to merge 5 commits from Jer9/Longshot:perf/vk-fsr4-int8-lite-llpc-tune into main
Contributor

Summary

On AMD Windows LLPC GPUs (RDNA 3 / 3.5 / 4) running AMD FSR 4.1.2's INT8 Lite model — including integrated GPUs like the Radeon 860M where INT8 Lite stands in (g_standin), Strix Point APUs where INT8 Lite is native, and AMD GPUs where the player forces Lite via the menu or RX_VK_FSR4_MODEL=lite — FSR 4 shader tuning did not accelerate INT8 Lite on main or on open PR #1999 alone:

  1. make_context() suppressed tuning (suppress = true) whenever INT8 Lite stood in or was forced (lite && native_model() != MODEL_LITE), leaving all passes on stock AMD's shaders.
  2. Even when tuning was enabled, copying Function-scope constant weight arrays into a writable storage-buffer tail (arrays_to_buffer) regressed by +1.4–2.4 ms on AMD's Windows LLPC compiler, and INT8 Lite's smaller scratch buffer (<= 64 MiB) skipped Big buffer creation anyway so kind & 2 was never set to feed the unroller.
  3. On AMD LLPC, forcing INT8 Lite's rolled pass2 to Wave64 regressed (+335 us), whereas running postpass at Wave64 (fsr4_postpass_wave64) helped and unrolling pass2 at Wave32 + postpass at Wave64 delivered the fastest schedule.
  4. fsr4_compact_builds was limited to AMD's older RDNA 1/2 proprietary compiler (at 1 GiB headroom), leaving LLPC systems at an 8 GiB commit-headroom requirement even though compact folded passes (<= 60k words) peak under 60 MB of compile RAM.

Stack / Dependency Note: This branch builds on open PR #1999 by @madebyjordan (cherry-picking 09345da7 and 64318392 with original authorship preserved as e3a1aa49 and e0aa6e05), which introduces the expanded constant-folding SPIR-V unroller (spirv_unroll.h) and postpass unrolling. On top of #1999, this PR:

  • Splits compiler-specific FSR 4 tuning policy in gpu/vk/device_policy.h:
    • fsr4_arrays_to_buffer: on for AMD's older Windows proprietary shader compiler (RDNA 1/2, preserving #1999's RX 6700 XT behavior verbatim), off on AMD Windows LLPC (RDNA 3/3.5/4) and Linux RADV.
    • fsr4_postpass_wave64: on for AMD Windows LLPC, off on RDNA 1/2 proprietary and Linux RADV.
    • fsr4_compact_builds: on for both AMD Windows compilers (RDNA 1/2 proprietary and RDNA 3/3.5/4 LLPC), lowering kCompactHeadroom for compact folded passes (<= 60k words) to 256 MiB while keeping 8 GiB everywhere else.
    • Non-AMD GPUs (NVIDIA, Intel) keep fsr4_tune = false and remain completely untouched.
  • Adds direct unrolling without a storage-buffer tail (gpu/vk/fsr4_tune.h, gpu/vk/vk_fsr4.cpp):
    • fsr4_tune::has_const_arrays() detects eligible Function-scope constant uint weight arrays without requiring a writable storage-buffer tail (kind & 4), allowing spirv_unroll.h to fold constant tables directly into immediates from AMD's original SPIR-V.
    • fsr4_tune::wants_wave64(entry, postpass_wave64, lite) runs postpass at 64 lanes on LLPC and keeps INT8 Lite's pass2 at 32 lanes.
    • make_context() lifts tuning suppression for AMD INT8 Lite (stand-in, forced, and native) while still honoring RX_VK_FSR4_TUNE=0 and non-AMD fsr4_tune=false.
    • tune::begin_context() clears stale cur before context creation (and on Lite-refused fallback retry) so an Auto -> Lite model switch on RDNA 1/2 (fsr4_arrays_to_buffer=1) never rewrites Lite's shaders against an older live Auto context's > 64 MiB Big buffer while temporal_later drains.
    • create_compute_pipelines() keeps the non-4.1.2 legacy unroller (expanded_unroll == false) strictly layer-only (is_layer_pass(entry)) even when postpass_wave64 sets kind & 1 on postpass.

What a player notices:

  • On AMD RDNA 3 / 3.5 integrated GPUs using FSR 4 INT8 Lite (such as Radeon 860M), FSR 4 upscaling runs 27–33% faster (-1.06 to -2.25 ms per frame), lifting gameplay frame rates by +5.0% to +11.3% (and +32.4% 1% lows at 33% render scale) with visually indistinguishable output and zero extra VRAM usage.
  • On systems with tight free commit memory, compact folded FSR 4 passes (<= 60k words, < 60 MB compile RAM) now unroll with 256 MiB spare commit headroom instead of staying rolled below 8 GiB, and save into cache/longshot_fsr4_pipelines.bin (~231 KiB) across game updates.

Helps:

  • Players on AMD RDNA 3 / 3.5 / 4 Windows LLPC GPUs running AMD FSR 4.1.2 INT8 Lite (stand-in, native, or forced) or other FSR 4 models benefiting from tail-free direct unrolling, Wave64 postpass, and 256 MiB compact headroom.
  • Players on AMD RDNA 1/2 Windows GPUs using forced INT8 Lite or running with < 1 GiB free commit memory.

No measurable impact:

  • NVIDIA and Intel GPUs (fsr4_tune = false, hooks never installed).
  • Players not using AMD FSR 4, or running with RX_VK_FSR4_TUNE=0 (clean fallback to stock AMD's shaders).
  • RDNA 1/2 proprietary Windows Auto (Navi 2 INT8) keeps identical fsr4_arrays_to_buffer=1, fsr4_postpass_wave64=0, and expanded-unroller behavior vs #1999.

Builds on #1999 (credit: @madebyjordan).

Files to read first:

  • gpu/vk/device_policy.h: fsr4_arrays_to_buffer, fsr4_postpass_wave64, and fsr4_compact_builds policy rules and vk: policy: logging.
  • gpu/vk/fsr4_tune.h: wants_wave64(entry, postpass_wave64, lite) and has_const_arrays().
  • gpu/vk/vk_fsr4.cpp: direct-unroll candidate marking (kind & 4), tune::begin_context(), per-pipeline orig_lanes[i], legacy layer-only guard, kCompactHeadroom = 256 MiB, and make_context() suppression lift.
  • docs/dev/reference/upscalers.md: updated compiler policy and INT8 Lite stand-in tuning documentation.
  • tests/test_device_policy.py, tests/test_fsr4_bind_dispatch.py, tests/test_fsr4_tune.py: game-free coverage for all policy matrices, direct unroll, selective Wave64, 256 MiB headroom boundary, Auto -> Lite begin_context() isolation, and !expanded_unroll postpass guard.

Testing

Tested:

  • Hardware & environment: Windows 11 (build 26200), AMD Ryzen AI 7 350 (znver5, 8C/16T), AMD Radeon(TM) 860M Graphics (8 CUs, RDNA 3.5 iGPU, 1002:1114, 6 GB VGM / 12,212 MB allowed VRAM), Adrenalin 26.10.1 (LLPC), FSR SDK 2.4 (amd_fidelityfx_upscaler_vk.dll 4.1.2.4555, SHA-256 verified), INT8 Lite stand-in (RX_VK_FSR4=1), FG Off, Uncapped, VSync Off, RX_VK_PRECOMPILE=1, RX_VK_PASS_TIMING=1.
  • In-game interleaved release-speed A/B (29 total runs, 0 VK_ERROR_DEVICE_LOST, 0 crashes, 0 dispatch failures):
    • Market (market-entrance, 1680x1048, 67% render scale, 3 interleaved rounds): fsr4 ffxDispatch 6.743 -> 4.492 ms (-2.251 ms / -33.4%), GPU in all 23.93 -> 20.14 ms (-15.8%), Mean FPS 32.54 -> 36.21 (+11.3%).
    • Market (market-entrance, 1680x1048, 33% render scale, 2 interleaved rounds): fsr4 ffxDispatch 6.523 -> 4.737 ms (-1.786 ms / -27.4%), GPU in all 19.55 -> 17.71 ms (-9.4%), Mean FPS 37.31 -> 41.48 (+11.1%), 1% low 19.00 -> 25.17 (+32.4%).
    • Hyrule Field (castle-gate, 1680x1048, 67% render scale, 2 interleaved rounds): fsr4 ffxDispatch 6.397 -> 4.399 ms (-1.998 ms / -31.2%), GPU in all 23.77 -> 22.35 ms (-6.0%), Mean FPS 33.52 -> 35.81 (+6.8%).
    • Market (market-entrance, 1280x720, 67% render scale, 2 interleaved rounds): fsr4 ffxDispatch 3.609 -> 2.545 ms (-1.064 ms / -29.5%), GPU in all 18.81 -> 16.96 ms (-9.8%), Mean FPS 41.30 -> 43.38 (+5.0%).
    • Every tuned run logged passes unrolled by the expanded unroller (direct, no buffer tail); a compact build wants 256 MiB of memory to spare, model: Lite (...), tuned, 64 lanes wide (1 so far), and unrolled=2 (postpass 17799 -> 42598 words, pass2 21112 -> 44759 words; pass1 cleanly left rolled).
  • Control & safety probes:
    • #1999-only (e0aa6e05, Market 1680x1048, 67% render scale): stayed on AMD's shaders (0 unrolled, 6.613 ms vs stock 6.695 ms).
    • Kill-switch (RX_VK_FSR4_TUNE=0): clean fallback to AMD's shaders (0 unrolled, 6.862 ms, 32.70 FPS — stock parity).
    • Cold compile & RAM: 0.49–0.92 s rebuilding cache/longshot_fsr4_pipelines.bin (236,868 B / 231.3 KiB, RX_VK_PCACHE_LOAD=0 skips read/save cleanly), 1.78 s on empty AMD\VkCache, +57.8 MiB Private RAM / +85.2 MiB WS during build_unrolled (overall peak 14,828 MiB < stock 15,489 MiB).
    • Lossless visual diff (1680x1048, 67% render scale, Market static spawn, RX_VK_SHOT_MENU=0, direct PNG inspection): 0 artifacts, NaNs, or color shift; median abs RGB delta 0.00 / 255 (42.26% exact 0, 84.61% <= 1 LSB, 89.73% <= 2 LSB), MAE 1.37 / 255 (0.54%), PSNR 32.79 dB, per-channel mean drift <= 0.05 / 255.
  • Game-free checks:
    • New/updated tests failed before the implementation on #1999 (e0aa6e05) and pass at f8253663 under both clang++ and g++: tests/test_device_policy.py (25 PCs / 77 fields), tests/test_fsr4_bind_dispatch.py (including direct unroll, 256 MiB boundary, Auto -> Lite begin_context(), and !expanded_unroll + postpass_wave64 guard), tests/test_fsr4_own_cache.py, tests/test_fsr4_prepare_model.py, tests/test_fsr4_models.py, tests/test_doc_anchors.py, tests/test_switch_table.py, and tests/test_fsr4_tune.py (run with both clang++ and g++ for C++ compile, has_const_arrays, selective wants_wave64, SPIR-V VM parity, and source_problems()).
    • scripts/check_third_party.py: 17 parts as their notes say.
    • Full python -I -B tests/run_all.py --strict --jobs 12 (canonical path, Windows): 901 passed, 28 failed, 50 skipped (340 s), with 0 regressions introduced by this PR: 27/28 failures reproduce identically on clean forge/main (test_amd_subgroup_profiles, test_auto_handheld, test_crash_dialog, test_crt_options, test_dev_ab, test_dev_build, test_dev_migrate, test_dev_packs, test_flat_map, test_game_menu_mouse_buttons, test_input_movie, test_linux_preflight, test_menu_text_field, test_pads_after_menu, test_perf_report, test_pipeline_share, test_portable_builder_home, test_portable_builder_startup, test_rdna2_mesh_only, test_readback_timeout_source, test_rumble_menu, test_sampler_admission, test_sdiv_overflow, test_shader_profile_caps, test_target_image_reuse, test_vibration_menu, test_vram_compact), and the 28th (test_fsr4_tune.py) fails Windows --strict only for not found: spirv_val (upstream #1999 commit e3a1aa49 removed the Windows RUN_ALL_SKIP; Linux CI runs test_fsr4_tune.py with spirv-val).

How to test:

  1. On an AMD Windows LLPC GPU (e.g. Radeon 860M / 880M / 890M, RX 7000, or RX 9000) with FSR SDK 2.4 (amd_fidelityfx_loader_vk.dll + amd_fidelityfx_upscaler_vk.dll 4.1.2) beside the binary, set RX_VK_FSR4=1 and RX_VK_PASS_TIMING=1 (and RX_VK_FSR4_MODEL=lite if the GPU defaults to Auto FP8/INT8 Full).
  2. Load market-entrance at 1680x1048, 67% render scale, walk straight forward ~5 s (0:LUP/5000) to the central fountain before panning, and confirm longshot_log.txt logs passes unrolled by the expanded unroller (direct, no buffer tail); a compact build wants 256 MiB of memory to spare, model: Lite (...), tuned, tuned fsr4_model_v07_fp8_no_scale_postpass: its loops unrolled, and tuned fsr4_model_v07_fp8_no_scale_pass2: its loops unrolled.
  3. Compare fsr4 ffxDispatch (AMD's passes) and Mean FPS against RX_VK_FSR4_TUNE=0 (or main), verifying ~27–33% lower FSR 4 dispatch time and clean fallback to AMD's shaders when RX_VK_FSR4_TUNE=0.

Still to test:

  • Tier 1 AMD RDNA 1/2 Windows proprietary compiler (e.g. RX 6700 XT / RX 6600): verify fsr4_arrays_to_buffer=1, fsr4_postpass_wave64=0, fsr4_compact_builds=1 preserve #1999 Auto performance and cleanly survive live Insert menu Auto -> Lite switching without artifacts or device loss (@Beanstalk test, or by hand)
  • Tier 1 AMD RDNA 3/4 Windows LLPC discrete GPUs (RX 7900 XTX INT8 Full, RX 9070 XT FP8 & forced INT8 Lite): verify fsr4_arrays_to_buffer=0, fsr4_postpass_wave64=1, fsr4_compact_builds=1 speed, cold compile time, and visual parity (@Beanstalk test)
  • Tier 2 AMD Strix Point / Strix Halo Windows LLPC APUs (Radeon 880M/890M native INT8 Lite, Radeon 8060S INT8 Full): verify fsr4 ffxDispatch speedup and visual parity (@Beanstalk test)
  • Tier 1 Linux AMD RADV (RX 6700 XT / RX 7900 XTX / RX 9070 XT / Steam Deck with amd_fidelityfx_upscaler_vk.so): verify fsr4_arrays_to_buffer=0, fsr4_postpass_wave64=0, fsr4_compact_builds=0 (8 GiB) and Linux CI tests/test_fsr4_tune.py with spirv-val (@Beanstalk test)
  • Tier 1 Non-AMD GPUs (NVIDIA RTX / Intel Arc with FSR 4 stand-in): verify fsr4_tune=0 remains untouched (AMD's shaders) (@Beanstalk test)

Measurements

Verdict: Cuts AMD FSR 4.1.2 INT8 Lite fsr4 ffxDispatch GPU time by -27.4% to -33.4% (-1.064 to -2.251 ms), cuts total GPU frame time in all by -6.0% to -15.8%, lifts Mean FPS by +5.0% to +11.3% across all 4 tested scenes/resolutions with zero round overlap, and lifts 1% low FPS by +32.4% at 33% render scale (1680x1048) on AMD Radeon 860M (Adrenalin 26.10.1 LLPC). Cold unroll build stays well below limits (0.49–0.92 s with warm driver cache / 1.78 s empty AMD\VkCache, +57.8 MiB Private RAM during build_unrolled, 231.3 KiB cache file), visual output is lossless-parity (84.61% of pixels <= 1 LSB, 0 artifacts), and RX_VK_FSR4_TUNE=0 cleanly restores stock parity.

Setup: Windows 11 (build 26200), AMD Ryzen AI 7 350, AMD Radeon(TM) 860M Graphics (8 CUs, RDNA 3.5 iGPU, 6 GB VGM), Adrenalin 26.10.1 (LLPC), FSR SDK 2.4 (FSR 4.1.2 INT8 Lite via RX_VK_FSR4=1), FG Off, Uncapped, VSync Off, RX_VK_PRECOMPILE=1, RX_VK_PASS_TIMING=1, >= 12.5 s post-load settle, scripted 15 s drive (0:LUP/5000, 0:RRIGHT/5000, 0:RLEFT/5000), strictly interleaved rounds (Before -> After), medians reported. (The stock main binary was built at 8aa5ab87; the sole intervening commit to current merge-base ef280956 is #2429, which edits only .forgejo/ CI workflows, CI docs, and scripts/ci_secret.sh with zero gpu//host//nx2/ changes. The PR binary was built at bd27181b; follow-up commit f8253663 only adds tune::begin_context() for RDNA 1/2 Auto -> Lite switches, the non-4.1.2 legacy unroller postpass guard, and has_const_arrays() malformed-SPIR-V bounds checks, leaving the measured AMD LLPC FSR 4.1.2 path behaviorally identical.)

Where it makes a difference (interleaved medians on AMD Radeon 860M LLPC, FSR 4.1.2 INT8 Lite):

Metric Before: main @ 8aa5ab87 After: this PR @ f8253663 Delta
Market (market-entrance), 1680x1048, 67% render scale (1120x699 -> 1680x1048, 3 rounds):
fsr4 ffxDispatch GPU time 6.743 ms 4.492 ms -2.251 ms (-33.4%)
GPU in all frame time 23.93 ms 20.14 ms -3.79 ms (-15.8%)
Mean FPS 32.54 36.21 +3.67 (+11.3%)
Market (market-entrance), 1680x1048, 33% render scale (560x350 -> 1680x1048, 2 rounds):
fsr4 ffxDispatch GPU time 6.523 ms 4.737 ms -1.786 ms (-27.4%)
GPU in all frame time 19.55 ms 17.71 ms -1.84 ms (-9.4%)
Mean FPS 37.31 41.48 +4.16 (+11.1%)
1% low FPS 19.00 25.17 +6.17 (+32.4%)
Hyrule Field (castle-gate), 1680x1048, 67% render scale (1120x699 -> 1680x1048, 2 rounds):
fsr4 ffxDispatch GPU time 6.397 ms 4.399 ms -1.998 ms (-31.2%)
GPU in all frame time 23.77 ms 22.35 ms -1.42 ms (-6.0%)
Mean FPS 33.52 35.81 +2.30 (+6.8%)
Market (market-entrance), 1280x720, 67% render scale (854x480 -> 1280x720, 2 rounds):
fsr4 ffxDispatch GPU time 3.609 ms 2.545 ms -1.064 ms (-29.5%)
GPU in all frame time 18.81 ms 16.96 ms -1.84 ms (-9.8%)
Mean FPS 41.30 43.38 +2.08 (+5.0%)

(Per-round fsr4 ffxDispatch ms — zero overlap in any condition: Market 1680x1048 67% Stock 6.792, 6.671, 6.743 vs PR 4.546, 4.492, 4.457; Market 1680x1048 33% Stock 6.454, 6.592 vs PR 4.738, 4.736; Hyrule 1680x1048 67% Stock 6.392, 6.402 vs PR 4.336, 4.462; Market 1280x720 67% Stock 3.596, 3.622 vs PR 2.514, 2.577.)

Where it does NOT make a difference (within run-to-run variance) & control checks:

Metric Before: main @ 8aa5ab87 After: this PR @ f8253663 Delta
Market 1680x1048, 67% render scale — 1% low FPS 18.54 19.05 +0.51 (+2.8%)
Market 1680x1048, 67% render scale — VRAM usage 3,578 MB 3,546 MB -32 MB
Market 1280x720, 67% render scale — 1% low FPS 22.41 22.60 +0.20 (+0.9%)
Market 1280x720, 67% render scale — VRAM usage 3,311 MB 3,263 MB -48 MB
Market 1680x1048, 33% render scale — VRAM usage 3,498 MB 3,386 MB -112 MB
Hyrule Field 1680x1048, 67% render scale — VRAM usage 2,998 MB 3,062 MB +64 MB
Hyrule Field 1680x1048, 67% render scale — 1% low FPS* 22.66 18.12 -4.54 (-20.0%)*
#1999-only (e0aa6e05, 0 unrolled, Market 1680x1048, 67% render scale) — fsr4 ffxDispatch 6.695 ms 6.613 ms (#1999-only) -0.082 ms (-1.2%)
Kill-switch (RX_VK_FSR4_TUNE=0, Market 1680x1048, 67% render scale) — fsr4 ffxDispatch 6.743 ms 6.862 ms (TUNE=0) +0.119 ms (+1.8%)

*Hyrule Field R1 1% low was at parity (22.81 vs 22.33); R2 13.43 was caused by an unrelated ASTC streaming burst (astc_flush_ms=31.8 ms, uploads=28, pipe_waits=0) from walking slightly farther during 0:LUP/5000 at higher FPS.

Secondary costs (cold compile, cache size, RAM, visual parity):

  • Cold unroll build (pass2 21112 -> 44759 words + postpass 17799 -> 42598 words): 0.49–0.92 s rebuilding cache/longshot_fsr4_pipelines.bin with a warm AMD driver cache (0.92 s under RX_VK_PCACHE_LOAD=0 which skips read/save cleanly); 1.78 s on an empty AMD\VkCache on the same Radeon 860M (0.97 s pass2 + 0.81 s postpass).
  • Cache size & compile RAM: cache/longshot_fsr4_pipelines.bin = 236,868 B (231.3 KiB). Process memory delta across build_unrolled = +57.8 MiB Private / +85.2 MiB WS; overall peak Private 14,828 MiB stayed below stock 15,489 MiB.
  • Visual diff (lossless PNG, Market static spawn 1680x1048 67% render scale, RX_VK_SHOT_MENU=0): 0 artifacts/NaNs/color shift; median abs RGB delta 0.00 / 255 (42.26% bit-exact 0, 84.61% <= 1 LSB, 89.73% <= 2 LSB), MAE 1.37 / 255 (0.54%), PSNR 32.79 dB, channel means [67.39, 51.75, 55.78] vs [67.43, 51.80, 55.79] (<= 0.05 drift; max 176 on wind-animated bunting/Navi across the frame-timestamp offset).

Verbatim longshot_log.txt excerpt (Market 1680x1048, 67% render scale, this PR):

[hos host] vk: policy: can and measured: mirrors=0 import_chunk=16 MB ub_snapshot=0 split_ub_flush=1 native_float_add=1(seen on AMD 0x8001a0) warp64=1 batch_submits=0 mma_unroll_try=0 global_table_loop=0 occ_copy=0 intel_side_by_side_auto=0 fsr4_tune=1 fsr4_arrays_to_buffer=0 fsr4_postpass_wave64=1 fsr4_compact_builds=1 gpu_clock_peak=0 readback_late_newest=0 acquire_ahead=1 pcache_small_pc=0 bc_small_runs=1
[hos host] vk: AMD FSR 4: passes unrolled by the expanded unroller (direct, no buffer tail); a compact build wants 256 MiB of memory to spare
[hos host] vk: AMD FSR 4: model: Lite (INT8, standing in: AMD lists no FSR 4 model for this GPU), tuned
[hos host] vk: AMD FSR 4: the unrolled layers' pipeline cache: read
[hos host] vk: AMD FSR 4: tuned: its network's layers run 64 lanes wide (1 so far)
[hos host] vk: AMD FSR 4: fsr4_model_v07_fp8_no_scale_pass1 left rolled (2 loops kept: unrolled whole it would pass 120000 words, or they cannot be)
[hos host] vk: AMD FSR 4: tuned fsr4_model_v07_fp8_no_scale_postpass: its loops unrolled (17799 -> 42598 words), bound in its place from now (0.24 s from the caches)
[hos host] vk: AMD FSR 4: tuned fsr4_model_v07_fp8_no_scale_pass2: its loops unrolled (21112 -> 44759 words), bound in its place from now (0.40 s from the caches)
[hos Presentation Thread] vk:   20.14 ms a frame in all (recordings' command buffers + upload command buffers; the present's blit to the window is not timed; the 'GPU time' line of an unprofiled run counts the first kind only)
[hos Presentation Thread] vk:   m   4.538 ms     1.0 x   4545.8 us       1.0 items    0.00 MB  fsr4 ffxDispatch (AMD's passes)

Risks

  • Escape hatch: Setting RX_VK_FSR4_TUNE=0 in longshot_env.txt disables all FSR 4 tuning hooks completely (AMD's shaders), verified to restore stock parity. Reverting the commit cleanly restores #1999 behavior.
  • Untested Tier 1 AMD models & drivers (pre-merge gate): fsr4_arrays_to_buffer=0, fsr4_postpass_wave64=1, and fsr4_compact_builds=1 apply to all AMD Windows LLPC GPUs (RDNA 3/3.5/4), including discrete RX 7000 (INT8 Full) and RX 9000 (FP8 / forced INT8 Lite), and Linux RADV now skips arrays_to_buffer (fsr4_arrays_to_buffer=0, keeping 8 GiB headroom). Cooperative-matrix/subgroup shaders remain protected by !lane_dep on both Wave64 and direct unroll, and Still to test lists Test Farm runs on RX 6700 XT, RX 7000/9000 LLPC, Strix Point/Halo, Linux RADV, and non-AMD GPUs before merge.
  • RDNA 1/2 Auto -> Lite switching: tune::begin_context() clears cur = 0 before each context creation (leaving existing bigs intact for in-flight dispatches) so forced Lite's <= 64 MiB scratch buffer never attaches to an older live Auto context's Big tail.
  • Pipeline cache & cold compile: Unrolled pipelines are stored in cache/longshot_fsr4_pipelines.bin (~231 KiB, independent of the translator's cache, validated by GPU/driver UUID and keyed by Vulkan driver state including SPIR-V bytecode and requiredSubgroupSize). First-time cold unroll on empty driver cache takes ~1.8 s on Radeon 860M and peaks at +57.8 MiB Private RAM (256 MiB commit headroom gate); RX_VK_PCACHE_LOAD=0 skips reading and saving the file. No saves, longshot_options.ini, or renderer ABI (MKWVK_API_VERSION) are changed.
  • Merge order: Stacked on open PR #1999 (@madebyjordan); merge after #1999 (or rebase once #1999 lands).

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
<!-- Suggested PR title: perf(vk): cut AMD FSR 4 INT8 Lite dispatch time 27-33% (+5-11% FPS, +32% 1% low at 33% scale) on AMD LLPC GPUs via direct unroll and selective Wave64 --> ## Summary On AMD Windows LLPC GPUs (RDNA 3 / 3.5 / 4) running AMD FSR 4.1.2's **INT8 Lite** model — including integrated GPUs like the Radeon 860M where INT8 Lite stands in (`g_standin`), Strix Point APUs where INT8 Lite is native, and AMD GPUs where the player forces Lite via the menu or `RX_VK_FSR4_MODEL=lite` — FSR 4 shader tuning did not accelerate INT8 Lite on `main` or on open PR #1999 alone: 1. `make_context()` suppressed tuning (`suppress = true`) whenever INT8 Lite stood in or was forced (`lite && native_model() != MODEL_LITE`), leaving all passes on stock `AMD's shaders`. 2. Even when tuning was enabled, copying Function-scope constant weight arrays into a writable storage-buffer tail (`arrays_to_buffer`) regressed by `+1.4–2.4 ms` on AMD's Windows LLPC compiler, and INT8 Lite's smaller scratch buffer (`<= 64 MiB`) skipped `Big` buffer creation anyway so `kind & 2` was never set to feed the unroller. 3. On AMD LLPC, forcing INT8 Lite's rolled `pass2` to Wave64 regressed (`+335 us`), whereas running `postpass` at Wave64 (`fsr4_postpass_wave64`) helped and unrolling `pass2` at Wave32 + `postpass` at Wave64 delivered the fastest schedule. 4. `fsr4_compact_builds` was limited to AMD's older RDNA 1/2 proprietary compiler (at `1 GiB` headroom), leaving LLPC systems at an `8 GiB` commit-headroom requirement even though compact folded passes (`<= 60k` words) peak under `60 MB` of compile RAM. **Stack / Dependency Note:** This branch builds on open PR #1999 by `@madebyjordan` (cherry-picking `09345da7` and `64318392` with original authorship preserved as `e3a1aa49` and `e0aa6e05`), which introduces the expanded constant-folding SPIR-V unroller (`spirv_unroll.h`) and postpass unrolling. On top of #1999, this PR: - **Splits compiler-specific FSR 4 tuning policy in `gpu/vk/device_policy.h`:** - `fsr4_arrays_to_buffer`: on for AMD's older Windows proprietary shader compiler (RDNA 1/2, preserving #1999's RX 6700 XT behavior verbatim), off on AMD Windows LLPC (RDNA 3/3.5/4) and Linux RADV. - `fsr4_postpass_wave64`: on for AMD Windows LLPC, off on RDNA 1/2 proprietary and Linux RADV. - `fsr4_compact_builds`: on for both AMD Windows compilers (RDNA 1/2 proprietary and RDNA 3/3.5/4 LLPC), lowering `kCompactHeadroom` for compact folded passes (`<= 60k` words) to `256 MiB` while keeping `8 GiB` everywhere else. - Non-AMD GPUs (`NVIDIA`, `Intel`) keep `fsr4_tune = false` and remain completely untouched. - **Adds direct unrolling without a storage-buffer tail (`gpu/vk/fsr4_tune.h`, `gpu/vk/vk_fsr4.cpp`):** - `fsr4_tune::has_const_arrays()` detects eligible Function-scope constant `uint` weight arrays without requiring a writable storage-buffer tail (`kind & 4`), allowing `spirv_unroll.h` to fold constant tables directly into immediates from AMD's original SPIR-V. - `fsr4_tune::wants_wave64(entry, postpass_wave64, lite)` runs `postpass` at 64 lanes on LLPC and keeps INT8 Lite's `pass2` at 32 lanes. - `make_context()` lifts tuning suppression for AMD INT8 Lite (stand-in, forced, and native) while still honoring `RX_VK_FSR4_TUNE=0` and non-AMD `fsr4_tune=false`. - `tune::begin_context()` clears stale `cur` before context creation (and on Lite-refused fallback retry) so an `Auto -> Lite` model switch on RDNA 1/2 (`fsr4_arrays_to_buffer=1`) never rewrites Lite's shaders against an older live Auto context's `> 64 MiB` `Big` buffer while `temporal_later` drains. - `create_compute_pipelines()` keeps the non-4.1.2 legacy unroller (`expanded_unroll == false`) strictly layer-only (`is_layer_pass(entry)`) even when `postpass_wave64` sets `kind & 1` on `postpass`. **What a player notices:** - On AMD RDNA 3 / 3.5 integrated GPUs using FSR 4 INT8 Lite (such as Radeon 860M), FSR 4 upscaling runs **27–33% faster** (`-1.06` to `-2.25 ms` per frame), lifting gameplay frame rates by **+5.0% to +11.3%** (and **+32.4% 1% lows** at `33% render scale`) with visually indistinguishable output and zero extra VRAM usage. - On systems with tight free commit memory, compact folded FSR 4 passes (`<= 60k` words, `< 60 MB` compile RAM) now unroll with `256 MiB` spare commit headroom instead of staying rolled below `8 GiB`, and save into `cache/longshot_fsr4_pipelines.bin` (`~231 KiB`) across game updates. **Helps:** - Players on AMD RDNA 3 / 3.5 / 4 Windows LLPC GPUs running AMD FSR 4.1.2 INT8 Lite (stand-in, native, or forced) or other FSR 4 models benefiting from tail-free direct unrolling, Wave64 postpass, and `256 MiB` compact headroom. - Players on AMD RDNA 1/2 Windows GPUs using forced INT8 Lite or running with `< 1 GiB` free commit memory. **No measurable impact:** - NVIDIA and Intel GPUs (`fsr4_tune = false`, hooks never installed). - Players not using AMD FSR 4, or running with `RX_VK_FSR4_TUNE=0` (clean fallback to stock `AMD's shaders`). - RDNA 1/2 proprietary Windows `Auto` (Navi 2 INT8) keeps identical `fsr4_arrays_to_buffer=1`, `fsr4_postpass_wave64=0`, and expanded-unroller behavior vs #1999. Builds on #1999 (credit: `@madebyjordan`). Files to read first: - `gpu/vk/device_policy.h`: `fsr4_arrays_to_buffer`, `fsr4_postpass_wave64`, and `fsr4_compact_builds` policy rules and `vk: policy:` logging. - `gpu/vk/fsr4_tune.h`: `wants_wave64(entry, postpass_wave64, lite)` and `has_const_arrays()`. - `gpu/vk/vk_fsr4.cpp`: direct-unroll candidate marking (`kind & 4`), `tune::begin_context()`, per-pipeline `orig_lanes[i]`, legacy layer-only guard, `kCompactHeadroom = 256 MiB`, and `make_context()` suppression lift. - `docs/dev/reference/upscalers.md`: updated compiler policy and INT8 Lite stand-in tuning documentation. - `tests/test_device_policy.py`, `tests/test_fsr4_bind_dispatch.py`, `tests/test_fsr4_tune.py`: game-free coverage for all policy matrices, direct unroll, selective Wave64, `256 MiB` headroom boundary, `Auto -> Lite` `begin_context()` isolation, and `!expanded_unroll` postpass guard. ## Testing **Tested:** - **Hardware & environment:** Windows 11 (build 26200), AMD Ryzen AI 7 350 (`znver5`, 8C/16T), AMD Radeon(TM) 860M Graphics (8 CUs, RDNA 3.5 iGPU, `1002:1114`, 6 GB VGM / 12,212 MB allowed VRAM), Adrenalin 26.10.1 (`LLPC`), FSR SDK 2.4 (`amd_fidelityfx_upscaler_vk.dll` 4.1.2.4555, SHA-256 verified), INT8 Lite stand-in (`RX_VK_FSR4=1`), FG Off, Uncapped, VSync Off, `RX_VK_PRECOMPILE=1`, `RX_VK_PASS_TIMING=1`. - **In-game interleaved release-speed A/B (`29` total runs, `0` `VK_ERROR_DEVICE_LOST`, `0` crashes, `0` dispatch failures):** - Market (`market-entrance`, `1680x1048`, `67% render scale`, 3 interleaved rounds): `fsr4 ffxDispatch` `6.743 -> 4.492 ms` (`-2.251 ms` / `-33.4%`), GPU `in all` `23.93 -> 20.14 ms` (`-15.8%`), Mean FPS `32.54 -> 36.21` (`+11.3%`). - Market (`market-entrance`, `1680x1048`, `33% render scale`, 2 interleaved rounds): `fsr4 ffxDispatch` `6.523 -> 4.737 ms` (`-1.786 ms` / `-27.4%`), GPU `in all` `19.55 -> 17.71 ms` (`-9.4%`), Mean FPS `37.31 -> 41.48` (`+11.1%`), 1% low `19.00 -> 25.17` (`+32.4%`). - Hyrule Field (`castle-gate`, `1680x1048`, `67% render scale`, 2 interleaved rounds): `fsr4 ffxDispatch` `6.397 -> 4.399 ms` (`-1.998 ms` / `-31.2%`), GPU `in all` `23.77 -> 22.35 ms` (`-6.0%`), Mean FPS `33.52 -> 35.81` (`+6.8%`). - Market (`market-entrance`, `1280x720`, `67% render scale`, 2 interleaved rounds): `fsr4 ffxDispatch` `3.609 -> 2.545 ms` (`-1.064 ms` / `-29.5%`), GPU `in all` `18.81 -> 16.96 ms` (`-9.8%`), Mean FPS `41.30 -> 43.38` (`+5.0%`). - Every tuned run logged `passes unrolled by the expanded unroller (direct, no buffer tail); a compact build wants 256 MiB of memory to spare`, `model: Lite (...), tuned`, `64 lanes wide (1 so far)`, and `unrolled=2` (`postpass` `17799 -> 42598 words`, `pass2` `21112 -> 44759 words`; `pass1` cleanly `left rolled`). - **Control & safety probes:** - `#1999`-only (`e0aa6e05`, Market `1680x1048`, `67% render scale`): stayed on `AMD's shaders` (`0` unrolled, `6.613 ms` vs stock `6.695 ms`). - Kill-switch (`RX_VK_FSR4_TUNE=0`): clean fallback to `AMD's shaders` (`0` unrolled, `6.862 ms`, `32.70 FPS` — stock parity). - Cold compile & RAM: `0.49–0.92 s` rebuilding `cache/longshot_fsr4_pipelines.bin` (`236,868 B` / `231.3 KiB`, `RX_VK_PCACHE_LOAD=0` skips read/save cleanly), `1.78 s` on empty `AMD\VkCache`, `+57.8 MiB` Private RAM / `+85.2 MiB` WS during `build_unrolled` (overall peak `14,828 MiB` < stock `15,489 MiB`). - Lossless visual diff (`1680x1048`, `67% render scale`, Market static spawn, `RX_VK_SHOT_MENU=0`, direct PNG inspection): `0` artifacts, NaNs, or color shift; median abs RGB delta `0.00 / 255` (`42.26%` exact `0`, `84.61%` `<= 1` LSB, `89.73%` `<= 2` LSB), MAE `1.37 / 255` (`0.54%`), PSNR `32.79 dB`, per-channel mean drift `<= 0.05 / 255`. - **Game-free checks:** - New/updated tests failed before the implementation on #1999 (`e0aa6e05`) and pass at `f8253663` under both `clang++` and `g++`: `tests/test_device_policy.py` (25 PCs / 77 fields), `tests/test_fsr4_bind_dispatch.py` (including direct unroll, `256 MiB` boundary, `Auto -> Lite` `begin_context()`, and `!expanded_unroll` + `postpass_wave64` guard), `tests/test_fsr4_own_cache.py`, `tests/test_fsr4_prepare_model.py`, `tests/test_fsr4_models.py`, `tests/test_doc_anchors.py`, `tests/test_switch_table.py`, and `tests/test_fsr4_tune.py` (run with both `clang++` and `g++` for C++ compile, `has_const_arrays`, selective `wants_wave64`, SPIR-V VM parity, and `source_problems()`). - `scripts/check_third_party.py`: `17 parts as their notes say`. - Full `python -I -B tests/run_all.py --strict --jobs 12` (canonical path, Windows): **901 passed, 28 failed, 50 skipped** (`340 s`), with `0` regressions introduced by this PR: 27/28 failures reproduce identically on clean `forge/main` (`test_amd_subgroup_profiles`, `test_auto_handheld`, `test_crash_dialog`, `test_crt_options`, `test_dev_ab`, `test_dev_build`, `test_dev_migrate`, `test_dev_packs`, `test_flat_map`, `test_game_menu_mouse_buttons`, `test_input_movie`, `test_linux_preflight`, `test_menu_text_field`, `test_pads_after_menu`, `test_perf_report`, `test_pipeline_share`, `test_portable_builder_home`, `test_portable_builder_startup`, `test_rdna2_mesh_only`, `test_readback_timeout_source`, `test_rumble_menu`, `test_sampler_admission`, `test_sdiv_overflow`, `test_shader_profile_caps`, `test_target_image_reuse`, `test_vibration_menu`, `test_vram_compact`), and the 28th (`test_fsr4_tune.py`) fails Windows `--strict` only for `not found: spirv_val` (upstream #1999 commit `e3a1aa49` removed the Windows `RUN_ALL_SKIP`; Linux CI runs `test_fsr4_tune.py` with `spirv-val`). **How to test:** 1. On an AMD Windows LLPC GPU (e.g. Radeon 860M / 880M / 890M, RX 7000, or RX 9000) with FSR SDK 2.4 (`amd_fidelityfx_loader_vk.dll` + `amd_fidelityfx_upscaler_vk.dll` 4.1.2) beside the binary, set `RX_VK_FSR4=1` and `RX_VK_PASS_TIMING=1` (and `RX_VK_FSR4_MODEL=lite` if the GPU defaults to Auto FP8/INT8 Full). 2. Load `market-entrance` at `1680x1048`, `67% render scale`, walk straight forward ~5 s (`0:LUP/5000`) to the central fountain before panning, and confirm `longshot_log.txt` logs `passes unrolled by the expanded unroller (direct, no buffer tail); a compact build wants 256 MiB of memory to spare`, `model: Lite (...), tuned`, `tuned fsr4_model_v07_fp8_no_scale_postpass: its loops unrolled`, and `tuned fsr4_model_v07_fp8_no_scale_pass2: its loops unrolled`. 3. Compare `fsr4 ffxDispatch (AMD's passes)` and Mean FPS against `RX_VK_FSR4_TUNE=0` (or `main`), verifying ~27–33% lower FSR 4 dispatch time and clean fallback to `AMD's shaders` when `RX_VK_FSR4_TUNE=0`. **Still to test:** - Tier 1 AMD RDNA 1/2 Windows proprietary compiler (e.g. RX 6700 XT / RX 6600): verify `fsr4_arrays_to_buffer=1`, `fsr4_postpass_wave64=0`, `fsr4_compact_builds=1` preserve #1999 Auto performance and cleanly survive live Insert menu `Auto -> Lite` switching without artifacts or device loss (@Beanstalk test, or by hand) - Tier 1 AMD RDNA 3/4 Windows LLPC discrete GPUs (RX 7900 XTX INT8 Full, RX 9070 XT FP8 & forced INT8 Lite): verify `fsr4_arrays_to_buffer=0`, `fsr4_postpass_wave64=1`, `fsr4_compact_builds=1` speed, cold compile time, and visual parity (@Beanstalk test) - Tier 2 AMD Strix Point / Strix Halo Windows LLPC APUs (Radeon 880M/890M native INT8 Lite, Radeon 8060S INT8 Full): verify `fsr4 ffxDispatch` speedup and visual parity (@Beanstalk test) - Tier 1 Linux AMD RADV (RX 6700 XT / RX 7900 XTX / RX 9070 XT / Steam Deck with `amd_fidelityfx_upscaler_vk.so`): verify `fsr4_arrays_to_buffer=0`, `fsr4_postpass_wave64=0`, `fsr4_compact_builds=0` (`8 GiB`) and Linux CI `tests/test_fsr4_tune.py` with `spirv-val` (@Beanstalk test) - Tier 1 Non-AMD GPUs (NVIDIA RTX / Intel Arc with FSR 4 stand-in): verify `fsr4_tune=0` remains untouched (`AMD's shaders`) (@Beanstalk test) ## Measurements **Verdict:** Cuts AMD FSR 4.1.2 INT8 Lite `fsr4 ffxDispatch` GPU time by **-27.4% to -33.4%** (`-1.064` to `-2.251 ms`), cuts total GPU frame time `in all` by **-6.0% to -15.8%**, lifts Mean FPS by **+5.0% to +11.3%** across all 4 tested scenes/resolutions with zero round overlap, and lifts 1% low FPS by **+32.4%** at `33% render scale` (`1680x1048`) on AMD Radeon 860M (Adrenalin 26.10.1 LLPC). Cold unroll build stays well below limits (`0.49–0.92 s` with warm driver cache / `1.78 s` empty `AMD\VkCache`, `+57.8 MiB` Private RAM during `build_unrolled`, `231.3 KiB` cache file), visual output is lossless-parity (`84.61%` of pixels `<= 1` LSB, `0` artifacts), and `RX_VK_FSR4_TUNE=0` cleanly restores stock parity. Setup: Windows 11 (build 26200), AMD Ryzen AI 7 350, AMD Radeon(TM) 860M Graphics (8 CUs, RDNA 3.5 iGPU, 6 GB VGM), Adrenalin 26.10.1 (`LLPC`), FSR SDK 2.4 (FSR 4.1.2 INT8 Lite via `RX_VK_FSR4=1`), FG Off, Uncapped, VSync Off, `RX_VK_PRECOMPILE=1`, `RX_VK_PASS_TIMING=1`, `>= 12.5 s` post-load settle, scripted 15 s drive (`0:LUP/5000`, `0:RRIGHT/5000`, `0:RLEFT/5000`), strictly interleaved rounds (`Before -> After`), medians reported. *(The stock `main` binary was built at `8aa5ab87`; the sole intervening commit to current merge-base `ef280956` is #2429, which edits only `.forgejo/` CI workflows, CI docs, and `scripts/ci_secret.sh` with zero `gpu/`/`host/`/`nx2/` changes. The PR binary was built at `bd27181b`; follow-up commit `f8253663` only adds `tune::begin_context()` for RDNA 1/2 `Auto -> Lite` switches, the non-4.1.2 legacy unroller postpass guard, and `has_const_arrays()` malformed-SPIR-V bounds checks, leaving the measured AMD LLPC FSR 4.1.2 path behaviorally identical.)* **Where it makes a difference (interleaved medians on AMD Radeon 860M LLPC, FSR 4.1.2 INT8 Lite):** | Metric | Before: main @ 8aa5ab87 | After: this PR @ f8253663 | Delta | |---|---:|---:|---:| | **Market (`market-entrance`), `1680x1048`, `67% render scale` (`1120x699 -> 1680x1048`, 3 rounds):** | | | | | `fsr4 ffxDispatch` GPU time | 6.743 ms | 4.492 ms | -2.251 ms (-33.4%) | | GPU `in all` frame time | 23.93 ms | 20.14 ms | -3.79 ms (-15.8%) | | Mean FPS | 32.54 | 36.21 | +3.67 (+11.3%) | | **Market (`market-entrance`), `1680x1048`, `33% render scale` (`560x350 -> 1680x1048`, 2 rounds):** | | | | | `fsr4 ffxDispatch` GPU time | 6.523 ms | 4.737 ms | -1.786 ms (-27.4%) | | GPU `in all` frame time | 19.55 ms | 17.71 ms | -1.84 ms (-9.4%) | | Mean FPS | 37.31 | 41.48 | +4.16 (+11.1%) | | 1% low FPS | 19.00 | 25.17 | +6.17 (+32.4%) | | **Hyrule Field (`castle-gate`), `1680x1048`, `67% render scale` (`1120x699 -> 1680x1048`, 2 rounds):** | | | | | `fsr4 ffxDispatch` GPU time | 6.397 ms | 4.399 ms | -1.998 ms (-31.2%) | | GPU `in all` frame time | 23.77 ms | 22.35 ms | -1.42 ms (-6.0%) | | Mean FPS | 33.52 | 35.81 | +2.30 (+6.8%) | | **Market (`market-entrance`), `1280x720`, `67% render scale` (`854x480 -> 1280x720`, 2 rounds):** | | | | | `fsr4 ffxDispatch` GPU time | 3.609 ms | 2.545 ms | -1.064 ms (-29.5%) | | GPU `in all` frame time | 18.81 ms | 16.96 ms | -1.84 ms (-9.8%) | | Mean FPS | 41.30 | 43.38 | +2.08 (+5.0%) | *(Per-round `fsr4 ffxDispatch` ms — zero overlap in any condition: Market `1680x1048` 67% Stock `6.792, 6.671, 6.743` vs PR `4.546, 4.492, 4.457`; Market `1680x1048` 33% Stock `6.454, 6.592` vs PR `4.738, 4.736`; Hyrule `1680x1048` 67% Stock `6.392, 6.402` vs PR `4.336, 4.462`; Market `1280x720` 67% Stock `3.596, 3.622` vs PR `2.514, 2.577`.)* **Where it does NOT make a difference (within run-to-run variance) & control checks:** | Metric | Before: main @ 8aa5ab87 | After: this PR @ f8253663 | Delta | |---|---:|---:|---:| | Market `1680x1048`, `67% render scale` — 1% low FPS | 18.54 | 19.05 | +0.51 (+2.8%) | | Market `1680x1048`, `67% render scale` — VRAM usage | 3,578 MB | 3,546 MB | -32 MB | | Market `1280x720`, `67% render scale` — 1% low FPS | 22.41 | 22.60 | +0.20 (+0.9%) | | Market `1280x720`, `67% render scale` — VRAM usage | 3,311 MB | 3,263 MB | -48 MB | | Market `1680x1048`, `33% render scale` — VRAM usage | 3,498 MB | 3,386 MB | -112 MB | | Hyrule Field `1680x1048`, `67% render scale` — VRAM usage | 2,998 MB | 3,062 MB | +64 MB | | Hyrule Field `1680x1048`, `67% render scale` — 1% low FPS* | 22.66 | 18.12 | -4.54 (-20.0%)* | | `#1999`-only (`e0aa6e05`, `0` unrolled, Market `1680x1048`, `67% render scale`) — `fsr4 ffxDispatch` | 6.695 ms | 6.613 ms (`#1999`-only) | -0.082 ms (-1.2%) | | Kill-switch (`RX_VK_FSR4_TUNE=0`, Market `1680x1048`, `67% render scale`) — `fsr4 ffxDispatch` | 6.743 ms | 6.862 ms (`TUNE=0`) | +0.119 ms (+1.8%) | *\*Hyrule Field R1 1% low was at parity (`22.81` vs `22.33`); R2 `13.43` was caused by an unrelated ASTC streaming burst (`astc_flush_ms=31.8 ms`, `uploads=28`, `pipe_waits=0`) from walking slightly farther during `0:LUP/5000` at higher FPS.* **Secondary costs (cold compile, cache size, RAM, visual parity):** - **Cold unroll build (`pass2` `21112 -> 44759` words + `postpass` `17799 -> 42598` words):** `0.49–0.92 s` rebuilding `cache/longshot_fsr4_pipelines.bin` with a warm AMD driver cache (`0.92 s` under `RX_VK_PCACHE_LOAD=0` which skips read/save cleanly); `1.78 s` on an empty `AMD\VkCache` on the same Radeon 860M (`0.97 s pass2 + 0.81 s postpass`). - **Cache size & compile RAM:** `cache/longshot_fsr4_pipelines.bin` = `236,868 B` (`231.3 KiB`). Process memory delta across `build_unrolled` = `+57.8 MiB` Private / `+85.2 MiB` WS; overall peak Private `14,828 MiB` stayed below stock `15,489 MiB`. - **Visual diff (lossless PNG, Market static spawn `1680x1048` `67% render scale`, `RX_VK_SHOT_MENU=0`):** `0` artifacts/NaNs/color shift; median abs RGB delta `0.00 / 255` (`42.26%` bit-exact `0`, `84.61%` `<= 1` LSB, `89.73%` `<= 2` LSB), MAE `1.37 / 255` (`0.54%`), PSNR `32.79 dB`, channel means `[67.39, 51.75, 55.78]` vs `[67.43, 51.80, 55.79]` (`<= 0.05` drift; max `176` on wind-animated bunting/Navi across the frame-timestamp offset). **Verbatim `longshot_log.txt` excerpt (Market `1680x1048`, `67% render scale`, this PR):** ```text [hos host] vk: policy: can and measured: mirrors=0 import_chunk=16 MB ub_snapshot=0 split_ub_flush=1 native_float_add=1(seen on AMD 0x8001a0) warp64=1 batch_submits=0 mma_unroll_try=0 global_table_loop=0 occ_copy=0 intel_side_by_side_auto=0 fsr4_tune=1 fsr4_arrays_to_buffer=0 fsr4_postpass_wave64=1 fsr4_compact_builds=1 gpu_clock_peak=0 readback_late_newest=0 acquire_ahead=1 pcache_small_pc=0 bc_small_runs=1 [hos host] vk: AMD FSR 4: passes unrolled by the expanded unroller (direct, no buffer tail); a compact build wants 256 MiB of memory to spare [hos host] vk: AMD FSR 4: model: Lite (INT8, standing in: AMD lists no FSR 4 model for this GPU), tuned [hos host] vk: AMD FSR 4: the unrolled layers' pipeline cache: read [hos host] vk: AMD FSR 4: tuned: its network's layers run 64 lanes wide (1 so far) [hos host] vk: AMD FSR 4: fsr4_model_v07_fp8_no_scale_pass1 left rolled (2 loops kept: unrolled whole it would pass 120000 words, or they cannot be) [hos host] vk: AMD FSR 4: tuned fsr4_model_v07_fp8_no_scale_postpass: its loops unrolled (17799 -> 42598 words), bound in its place from now (0.24 s from the caches) [hos host] vk: AMD FSR 4: tuned fsr4_model_v07_fp8_no_scale_pass2: its loops unrolled (21112 -> 44759 words), bound in its place from now (0.40 s from the caches) [hos Presentation Thread] vk: 20.14 ms a frame in all (recordings' command buffers + upload command buffers; the present's blit to the window is not timed; the 'GPU time' line of an unprofiled run counts the first kind only) [hos Presentation Thread] vk: m 4.538 ms 1.0 x 4545.8 us 1.0 items 0.00 MB fsr4 ffxDispatch (AMD's passes) ``` ## Risks - **Escape hatch:** Setting `RX_VK_FSR4_TUNE=0` in `longshot_env.txt` disables all FSR 4 tuning hooks completely (`AMD's shaders`), verified to restore stock parity. Reverting the commit cleanly restores #1999 behavior. - **Untested Tier 1 AMD models & drivers (pre-merge gate):** `fsr4_arrays_to_buffer=0`, `fsr4_postpass_wave64=1`, and `fsr4_compact_builds=1` apply to all AMD Windows LLPC GPUs (RDNA 3/3.5/4), including discrete RX 7000 (`INT8 Full`) and RX 9000 (`FP8` / forced `INT8 Lite`), and Linux RADV now skips `arrays_to_buffer` (`fsr4_arrays_to_buffer=0`, keeping `8 GiB` headroom). Cooperative-matrix/subgroup shaders remain protected by `!lane_dep` on both Wave64 and direct unroll, and `Still to test` lists Test Farm runs on RX 6700 XT, RX 7000/9000 LLPC, Strix Point/Halo, Linux RADV, and non-AMD GPUs before merge. - **RDNA 1/2 `Auto -> Lite` switching:** `tune::begin_context()` clears `cur = 0` before each context creation (leaving existing `bigs` intact for in-flight dispatches) so forced Lite's `<= 64 MiB` scratch buffer never attaches to an older live Auto context's `Big` tail. - **Pipeline cache & cold compile:** Unrolled pipelines are stored in `cache/longshot_fsr4_pipelines.bin` (`~231 KiB`, independent of the translator's cache, validated by GPU/driver UUID and keyed by Vulkan driver state including SPIR-V bytecode and `requiredSubgroupSize`). First-time cold unroll on empty driver cache takes `~1.8 s` on Radeon 860M and peaks at `+57.8 MiB` Private RAM (`256 MiB` commit headroom gate); `RX_VK_PCACHE_LOAD=0` skips reading and saving the file. No saves, `longshot_options.ini`, or renderer ABI (`MKWVK_API_VERSION`) are changed. - **Merge order:** Stacked on open PR #1999 (`@madebyjordan`); merge after #1999 (or rebase once #1999 lands). ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold.
Assisted-by: Gemini (Antigravity)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 09345da7f8)

# Conflicts:
#	gpu/vk/vk_fsr4.cpp
Found by a cold read of spirv_unroll.h; none is reachable with FSR 4.1.2's shaders, the only set the expanded unroller
takes. Each has a synthetic case in tests/test_fsr4_tune.py that fails without its line:

- R7: a header phi fed by the loop's own test was cloned with the test's id, which no copy defines.
- R8: the counter became a constant index in every body copy with no bounds check, `if (i < 2) x = arr[i]` over four
  trips leaving arr[2] and arr[3] in branches never taken.
- R10: a loop refused after its constants were made gave their ids back but left them in the constant table, so the
  next loop was handed an id no instruction defines.
- R9: DCE removed a constant composite read by no instruction though decorated (BuiltIn WorkgroupSize).

The worker_fn comment said device_proc writes the real_* pointers; it never does.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
(cherry picked from commit 64318392b3)
Assisted-by: Antigravity
Assisted-by: Antigravity
fix(vk): clear stale FSR 4 Big buffer gen on model switch and keep legacy unroller layer-only
Some checks are pending
Website / Website on Cloudflare (pull_request_target) Has been skipped
Website / Website builds (pull_request_target) Has been skipped
Website / Website preview, build (pull_request_target) Has been skipped
Website / Website preview, upload (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
Website / Website builds (pull_request) Blocked by required conditions
Website / Website preview, build (pull_request) Blocked by required conditions
Website / Website preview, upload (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 6s
beanstalk/approval waiting for a BigBean's 👍 on the request
f8253663dd
Assisted-by: Antigravity
Author
Contributor

Tested in game: Windows 11 AMD Radeon 860M (Adrenalin 26.10.1 LLPC), 29 interleaved runs across Market/Hyrule 1680x1048 and 1280x720 (67%/33%), -27.4% to -33.4% ffxDispatch, +5.0% to +11.3% FPS, 0 DEVICE_LOST, lossless visual match

Tested in game: Windows 11 AMD Radeon 860M (Adrenalin 26.10.1 LLPC), 29 interleaved runs across Market/Hyrule 1680x1048 and 1280x720 (67%/33%), -27.4% to -33.4% ffxDispatch, +5.0% to +11.3% FPS, 0 DEVICE_LOST, lossless visual match
Author
Contributor

@Beanstalk Please run these hardware verification checks on this PR head:

  • AMD RDNA 1/2 Windows proprietary (RX 6700 XT / RX 6600): FSR 4 Auto (Navi 2 INT8) and live Insert menu Auto -> Lite model switch (fsr4_arrays_to_buffer=1, fsr4_postpass_wave64=0, fsr4_compact_builds=1)
  • AMD RDNA 3/4 Windows LLPC discrete (RX 7900 XTX INT8 Full, RX 9070 XT FP8 & forced INT8 Lite): fsr4 ffxDispatch, cold compile time, and visual parity (fsr4_arrays_to_buffer=0, fsr4_postpass_wave64=1, fsr4_compact_builds=1)
  • AMD Strix Point / Strix Halo Windows LLPC APUs (Radeon 880M/890M native INT8 Lite, Radeon 8060S INT8 Full): fsr4 ffxDispatch speedup & visual parity
  • Linux AMD RADV (RX 6700 XT, RX 7900 XTX, RX 9070 XT, or Steam Deck): verify fsr4_arrays_to_buffer=0, fsr4_postpass_wave64=0, fsr4_compact_builds=0 and tests/test_fsr4_tune.py with spirv-val
  • Non-AMD GPU (NVIDIA RTX or Intel Arc with FSR 4 stand-in): verify fsr4_tune=0 remains untouched (AMD's shaders)
@Beanstalk Please run these hardware verification checks on this PR head: - AMD RDNA 1/2 Windows proprietary (`RX 6700 XT` / `RX 6600`): FSR 4 `Auto` (`Navi 2 INT8`) and live Insert menu `Auto -> Lite` model switch (`fsr4_arrays_to_buffer=1`, `fsr4_postpass_wave64=0`, `fsr4_compact_builds=1`) - AMD RDNA 3/4 Windows LLPC discrete (`RX 7900 XTX` `INT8 Full`, `RX 9070 XT` `FP8` & forced `INT8 Lite`): `fsr4 ffxDispatch`, cold compile time, and visual parity (`fsr4_arrays_to_buffer=0`, `fsr4_postpass_wave64=1`, `fsr4_compact_builds=1`) - AMD Strix Point / Strix Halo Windows LLPC APUs (`Radeon 880M/890M` native `INT8 Lite`, `Radeon 8060S` `INT8 Full`): `fsr4 ffxDispatch` speedup & visual parity - Linux AMD RADV (`RX 6700 XT`, `RX 7900 XTX`, `RX 9070 XT`, or `Steam Deck`): verify `fsr4_arrays_to_buffer=0`, `fsr4_postpass_wave64=0`, `fsr4_compact_builds=0` and `tests/test_fsr4_tune.py` with `spirv-val` - Non-AMD GPU (`NVIDIA RTX` or `Intel Arc` with FSR 4 stand-in): verify `fsr4_tune=0` remains untouched (`AMD's shaders`)
Member

@Jer9 only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@Jer9 only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Some checks are pending
Website / Website on Cloudflare (pull_request_target) Has been skipped
Website / Website builds (pull_request_target) Has been skipped
Website / Website preview, build (pull_request_target) Has been skipped
Website / Website preview, upload (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
Website / Website builds (pull_request) Blocked by required conditions
Website / Website preview, build (pull_request) Blocked by required conditions
Website / Website preview, upload (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 6s
beanstalk/approval waiting for a BigBean's 👍 on the request
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/vk-fsr4-int8-lite-llpc-tune:Jer9-perf/vk-fsr4-int8-lite-llpc-tune'
git switch 'Jer9-perf/vk-fsr4-int8-lite-llpc-tune'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2495
No description provided.