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
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2495
Loading…
Reference in a new issue
No description provided.
Delete branch "Jer9/Longshot:perf/vk-fsr4-int8-lite-llpc-tune"
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?
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 orRX_VK_FSR4_MODEL=lite— FSR 4 shader tuning did not accelerate INT8 Lite onmainor on open PR #1999 alone:make_context()suppressed tuning (suppress = true) whenever INT8 Lite stood in or was forced (lite && native_model() != MODEL_LITE), leaving all passes on stockAMD's shaders.arrays_to_buffer) regressed by+1.4–2.4 mson AMD's Windows LLPC compiler, and INT8 Lite's smaller scratch buffer (<= 64 MiB) skippedBigbuffer creation anyway sokind & 2was never set to feed the unroller.pass2to Wave64 regressed (+335 us), whereas runningpostpassat Wave64 (fsr4_postpass_wave64) helped and unrollingpass2at Wave32 +postpassat Wave64 delivered the fastest schedule.fsr4_compact_buildswas limited to AMD's older RDNA 1/2 proprietary compiler (at1 GiBheadroom), leaving LLPC systems at an8 GiBcommit-headroom requirement even though compact folded passes (<= 60kwords) peak under60 MBof compile RAM.Stack / Dependency Note: This branch builds on open PR #1999 by
@madebyjordan(cherry-picking09345da7and64318392with original authorship preserved ase3a1aa49ande0aa6e05), which introduces the expanded constant-folding SPIR-V unroller (spirv_unroll.h) and postpass unrolling. On top of #1999, this PR: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), loweringkCompactHeadroomfor compact folded passes (<= 60kwords) to256 MiBwhile keeping8 GiBeverywhere else.NVIDIA,Intel) keepfsr4_tune = falseand remain completely untouched.gpu/vk/fsr4_tune.h,gpu/vk/vk_fsr4.cpp):fsr4_tune::has_const_arrays()detects eligible Function-scope constantuintweight arrays without requiring a writable storage-buffer tail (kind & 4), allowingspirv_unroll.hto fold constant tables directly into immediates from AMD's original SPIR-V.fsr4_tune::wants_wave64(entry, postpass_wave64, lite)runspostpassat 64 lanes on LLPC and keeps INT8 Lite'spass2at 32 lanes.make_context()lifts tuning suppression for AMD INT8 Lite (stand-in, forced, and native) while still honoringRX_VK_FSR4_TUNE=0and non-AMDfsr4_tune=false.tune::begin_context()clears stalecurbefore context creation (and on Lite-refused fallback retry) so anAuto -> Litemodel switch on RDNA 1/2 (fsr4_arrays_to_buffer=1) never rewrites Lite's shaders against an older live Auto context's> 64 MiBBigbuffer whiletemporal_laterdrains.create_compute_pipelines()keeps the non-4.1.2 legacy unroller (expanded_unroll == false) strictly layer-only (is_layer_pass(entry)) even whenpostpass_wave64setskind & 1onpostpass.What a player notices:
-1.06to-2.25 msper frame), lifting gameplay frame rates by +5.0% to +11.3% (and +32.4% 1% lows at33% render scale) with visually indistinguishable output and zero extra VRAM usage.<= 60kwords,< 60 MBcompile RAM) now unroll with256 MiBspare commit headroom instead of staying rolled below8 GiB, and save intocache/longshot_fsr4_pipelines.bin(~231 KiB) across game updates.Helps:
256 MiBcompact headroom.< 1 GiBfree commit memory.No measurable impact:
fsr4_tune = false, hooks never installed).RX_VK_FSR4_TUNE=0(clean fallback to stockAMD's shaders).Auto(Navi 2 INT8) keeps identicalfsr4_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, andfsr4_compact_buildspolicy rules andvk: policy:logging.gpu/vk/fsr4_tune.h:wants_wave64(entry, postpass_wave64, lite)andhas_const_arrays().gpu/vk/vk_fsr4.cpp: direct-unroll candidate marking (kind & 4),tune::begin_context(), per-pipelineorig_lanes[i], legacy layer-only guard,kCompactHeadroom = 256 MiB, andmake_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 MiBheadroom boundary,Auto -> Litebegin_context()isolation, and!expanded_unrollpostpass guard.Testing
Tested:
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.dll4.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.29total runs,0VK_ERROR_DEVICE_LOST,0crashes,0dispatch failures):market-entrance,1680x1048,67% render scale, 3 interleaved rounds):fsr4 ffxDispatch6.743 -> 4.492 ms(-2.251 ms/-33.4%), GPUin all23.93 -> 20.14 ms(-15.8%), Mean FPS32.54 -> 36.21(+11.3%).market-entrance,1680x1048,33% render scale, 2 interleaved rounds):fsr4 ffxDispatch6.523 -> 4.737 ms(-1.786 ms/-27.4%), GPUin all19.55 -> 17.71 ms(-9.4%), Mean FPS37.31 -> 41.48(+11.1%), 1% low19.00 -> 25.17(+32.4%).castle-gate,1680x1048,67% render scale, 2 interleaved rounds):fsr4 ffxDispatch6.397 -> 4.399 ms(-1.998 ms/-31.2%), GPUin all23.77 -> 22.35 ms(-6.0%), Mean FPS33.52 -> 35.81(+6.8%).market-entrance,1280x720,67% render scale, 2 interleaved rounds):fsr4 ffxDispatch3.609 -> 2.545 ms(-1.064 ms/-29.5%), GPUin all18.81 -> 16.96 ms(-9.8%), Mean FPS41.30 -> 43.38(+5.0%).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), andunrolled=2(postpass17799 -> 42598 words,pass221112 -> 44759 words;pass1cleanlyleft rolled).#1999-only (e0aa6e05, Market1680x1048,67% render scale): stayed onAMD's shaders(0unrolled,6.613 msvs stock6.695 ms).RX_VK_FSR4_TUNE=0): clean fallback toAMD's shaders(0unrolled,6.862 ms,32.70 FPS— stock parity).0.49–0.92 srebuildingcache/longshot_fsr4_pipelines.bin(236,868 B/231.3 KiB,RX_VK_PCACHE_LOAD=0skips read/save cleanly),1.78 son emptyAMD\VkCache,+57.8 MiBPrivate RAM /+85.2 MiBWS duringbuild_unrolled(overall peak14,828 MiB< stock15,489 MiB).1680x1048,67% render scale, Market static spawn,RX_VK_SHOT_MENU=0, direct PNG inspection):0artifacts, NaNs, or color shift; median abs RGB delta0.00 / 255(42.26%exact0,84.61%<= 1LSB,89.73%<= 2LSB), MAE1.37 / 255(0.54%), PSNR32.79 dB, per-channel mean drift<= 0.05 / 255.e0aa6e05) and pass atf8253663under bothclang++andg++:tests/test_device_policy.py(25 PCs / 77 fields),tests/test_fsr4_bind_dispatch.py(including direct unroll,256 MiBboundary,Auto -> Litebegin_context(), and!expanded_unroll+postpass_wave64guard),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, andtests/test_fsr4_tune.py(run with bothclang++andg++for C++ compile,has_const_arrays, selectivewants_wave64, SPIR-V VM parity, andsource_problems()).scripts/check_third_party.py:17 parts as their notes say.python -I -B tests/run_all.py --strict --jobs 12(canonical path, Windows): 901 passed, 28 failed, 50 skipped (340 s), with0regressions introduced by this PR: 27/28 failures reproduce identically on cleanforge/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--strictonly fornot found: spirv_val(upstream #1999 commite3a1aa49removed the WindowsRUN_ALL_SKIP; Linux CI runstest_fsr4_tune.pywithspirv-val).How to test:
amd_fidelityfx_loader_vk.dll+amd_fidelityfx_upscaler_vk.dll4.1.2) beside the binary, setRX_VK_FSR4=1andRX_VK_PASS_TIMING=1(andRX_VK_FSR4_MODEL=liteif the GPU defaults to Auto FP8/INT8 Full).market-entranceat1680x1048,67% render scale, walk straight forward ~5 s (0:LUP/5000) to the central fountain before panning, and confirmlongshot_log.txtlogspasses 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, andtuned fsr4_model_v07_fp8_no_scale_pass2: its loops unrolled.fsr4 ffxDispatch (AMD's passes)and Mean FPS againstRX_VK_FSR4_TUNE=0(ormain), verifying ~27–33% lower FSR 4 dispatch time and clean fallback toAMD's shaderswhenRX_VK_FSR4_TUNE=0.Still to test:
fsr4_arrays_to_buffer=1,fsr4_postpass_wave64=0,fsr4_compact_builds=1preserve #1999 Auto performance and cleanly survive live Insert menuAuto -> Liteswitching without artifacts or device loss (@Beanstalk test, or by hand)fsr4_arrays_to_buffer=0,fsr4_postpass_wave64=1,fsr4_compact_builds=1speed, cold compile time, and visual parity (@Beanstalk test)fsr4 ffxDispatchspeedup and visual parity (@Beanstalk test)amd_fidelityfx_upscaler_vk.so): verifyfsr4_arrays_to_buffer=0,fsr4_postpass_wave64=0,fsr4_compact_builds=0(8 GiB) and Linux CItests/test_fsr4_tune.pywithspirv-val(@Beanstalk test)fsr4_tune=0remains untouched (AMD's shaders) (@Beanstalk test)Measurements
Verdict: Cuts AMD FSR 4.1.2 INT8 Lite
fsr4 ffxDispatchGPU time by -27.4% to -33.4% (-1.064to-2.251 ms), cuts total GPU frame timein allby -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% at33% render scale(1680x1048) on AMD Radeon 860M (Adrenalin 26.10.1 LLPC). Cold unroll build stays well below limits (0.49–0.92 swith warm driver cache /1.78 semptyAMD\VkCache,+57.8 MiBPrivate RAM duringbuild_unrolled,231.3 KiBcache file), visual output is lossless-parity (84.61%of pixels<= 1LSB,0artifacts), andRX_VK_FSR4_TUNE=0cleanly 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 viaRX_VK_FSR4=1), FG Off, Uncapped, VSync Off,RX_VK_PRECOMPILE=1,RX_VK_PASS_TIMING=1,>= 12.5 spost-load settle, scripted 15 s drive (0:LUP/5000,0:RRIGHT/5000,0:RLEFT/5000), strictly interleaved rounds (Before -> After), medians reported. (The stockmainbinary was built at8aa5ab87; the sole intervening commit to current merge-baseef280956is #2429, which edits only.forgejo/CI workflows, CI docs, andscripts/ci_secret.shwith zerogpu//host//nx2/changes. The PR binary was built atbd27181b; follow-up commitf8253663only addstune::begin_context()for RDNA 1/2Auto -> Liteswitches, the non-4.1.2 legacy unroller postpass guard, andhas_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):
8aa5ab87f8253663market-entrance),1680x1048,67% render scale(1120x699 -> 1680x1048, 3 rounds):fsr4 ffxDispatchGPU timein allframe timemarket-entrance),1680x1048,33% render scale(560x350 -> 1680x1048, 2 rounds):fsr4 ffxDispatchGPU timein allframe timecastle-gate),1680x1048,67% render scale(1120x699 -> 1680x1048, 2 rounds):fsr4 ffxDispatchGPU timein allframe timemarket-entrance),1280x720,67% render scale(854x480 -> 1280x720, 2 rounds):fsr4 ffxDispatchGPU timein allframe time(Per-round
fsr4 ffxDispatchms — zero overlap in any condition: Market1680x104867% Stock6.792, 6.671, 6.743vs PR4.546, 4.492, 4.457; Market1680x104833% Stock6.454, 6.592vs PR4.738, 4.736; Hyrule1680x104867% Stock6.392, 6.402vs PR4.336, 4.462; Market1280x72067% Stock3.596, 3.622vs PR2.514, 2.577.)Where it does NOT make a difference (within run-to-run variance) & control checks:
8aa5ab87f82536631680x1048,67% render scale— 1% low FPS1680x1048,67% render scale— VRAM usage1280x720,67% render scale— 1% low FPS1280x720,67% render scale— VRAM usage1680x1048,33% render scale— VRAM usage1680x1048,67% render scale— VRAM usage1680x1048,67% render scale— 1% low FPS*#1999-only (e0aa6e05,0unrolled, Market1680x1048,67% render scale) —fsr4 ffxDispatch#1999-only)RX_VK_FSR4_TUNE=0, Market1680x1048,67% render scale) —fsr4 ffxDispatchTUNE=0)*Hyrule Field R1 1% low was at parity (
22.81vs22.33); R213.43was caused by an unrelated ASTC streaming burst (astc_flush_ms=31.8 ms,uploads=28,pipe_waits=0) from walking slightly farther during0:LUP/5000at higher FPS.Secondary costs (cold compile, cache size, RAM, visual parity):
pass221112 -> 44759words +postpass17799 -> 42598words):0.49–0.92 srebuildingcache/longshot_fsr4_pipelines.binwith a warm AMD driver cache (0.92 sunderRX_VK_PCACHE_LOAD=0which skips read/save cleanly);1.78 son an emptyAMD\VkCacheon the same Radeon 860M (0.97 s pass2 + 0.81 s postpass).cache/longshot_fsr4_pipelines.bin=236,868 B(231.3 KiB). Process memory delta acrossbuild_unrolled=+57.8 MiBPrivate /+85.2 MiBWS; overall peak Private14,828 MiBstayed below stock15,489 MiB.1680x104867% render scale,RX_VK_SHOT_MENU=0):0artifacts/NaNs/color shift; median abs RGB delta0.00 / 255(42.26%bit-exact0,84.61%<= 1LSB,89.73%<= 2LSB), MAE1.37 / 255(0.54%), PSNR32.79 dB, channel means[67.39, 51.75, 55.78]vs[67.43, 51.80, 55.79](<= 0.05drift; max176on wind-animated bunting/Navi across the frame-timestamp offset).Verbatim
longshot_log.txtexcerpt (Market1680x1048,67% render scale, this PR):Risks
RX_VK_FSR4_TUNE=0inlongshot_env.txtdisables all FSR 4 tuning hooks completely (AMD's shaders), verified to restore stock parity. Reverting the commit cleanly restores #1999 behavior.fsr4_arrays_to_buffer=0,fsr4_postpass_wave64=1, andfsr4_compact_builds=1apply to all AMD Windows LLPC GPUs (RDNA 3/3.5/4), including discrete RX 7000 (INT8 Full) and RX 9000 (FP8/ forcedINT8 Lite), and Linux RADV now skipsarrays_to_buffer(fsr4_arrays_to_buffer=0, keeping8 GiBheadroom). Cooperative-matrix/subgroup shaders remain protected by!lane_depon both Wave64 and direct unroll, andStill to testlists Test Farm runs on RX 6700 XT, RX 7000/9000 LLPC, Strix Point/Halo, Linux RADV, and non-AMD GPUs before merge.Auto -> Liteswitching:tune::begin_context()clearscur = 0before each context creation (leaving existingbigsintact for in-flight dispatches) so forced Lite's<= 64 MiBscratch buffer never attaches to an older live Auto context'sBigtail.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 andrequiredSubgroupSize). First-time cold unroll on empty driver cache takes~1.8 son Radeon 860M and peaks at+57.8 MiBPrivate RAM (256 MiBcommit headroom gate);RX_VK_PCACHE_LOAD=0skips reading and saving the file. No saves,longshot_options.ini, or renderer ABI (MKWVK_API_VERSION) are changed.@madebyjordan); merge after #1999 (or rebase once #1999 lands).Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.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
@Beanstalk Please run these hardware verification checks on this PR head:
RX 6700 XT/RX 6600): FSR 4Auto(Navi 2 INT8) and live Insert menuAuto -> Litemodel switch (fsr4_arrays_to_buffer=1,fsr4_postpass_wave64=0,fsr4_compact_builds=1)RX 7900 XTXINT8 Full,RX 9070 XTFP8& forcedINT8 Lite):fsr4 ffxDispatch, cold compile time, and visual parity (fsr4_arrays_to_buffer=0,fsr4_postpass_wave64=1,fsr4_compact_builds=1)Radeon 880M/890MnativeINT8 Lite,Radeon 8060SINT8 Full):fsr4 ffxDispatchspeedup & visual parityRX 6700 XT,RX 7900 XTX,RX 9070 XT, orSteam Deck): verifyfsr4_arrays_to_buffer=0,fsr4_postpass_wave64=0,fsr4_compact_builds=0andtests/test_fsr4_tune.pywithspirv-valNVIDIA RTXorIntel Arcwith FSR 4 stand-in): verifyfsr4_tune=0remains untouched (AMD's shaders)@Jer9 only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.