feat(vk): AMD CAS as a Sharpening method #1979
Open
FIocker wants to merge 2 commits from
FIocker/super-build/amd-cas into main
pull from: FIocker/super-build/amd-cas
merge into: MagicBeanDev:main
MagicBeanDev:main
MagicBeanDev:github/pr/2893
MagicBeanDev:github/pr/2890
MagicBeanDev:github/pr/2887
MagicBeanDev:github/pr/2878
MagicBeanDev:github/pr/2875
MagicBeanDev:github/pr/2874
MagicBeanDev:github/pr/2873
MagicBeanDev:github/pr/2871
MagicBeanDev:github/pr/2756
MagicBeanDev:github/pr/2897
MagicBeanDev:github/pr/2896
MagicBeanDev:github/pr/2718
MagicBeanDev:github/pr/2842
MagicBeanDev:github/pr/2691
MagicBeanDev:github/pr/2895
MagicBeanDev:github/pr/2743
MagicBeanDev:github/pr/2765
MagicBeanDev:github/pr/2708
MagicBeanDev:github/pr/2732
MagicBeanDev:github/pr/2755
MagicBeanDev:github/pr/2817
MagicBeanDev:github/pr/2876
MagicBeanDev:release-please--branches--main
MagicBeanDev:release-please--branches--main--release-notes
MagicBeanDev:github/pr/2778
MagicBeanDev:github/pr/2888
MagicBeanDev:github/pr/2866
MagicBeanDev:github/pr/2877
MagicBeanDev:github/pr/2800
MagicBeanDev:github/pr/2829
MagicBeanDev:github/pr/2850
MagicBeanDev:github/pr/2889
MagicBeanDev:github/pr/2882
MagicBeanDev:github/pr/2860
MagicBeanDev:github/pr/2849
MagicBeanDev:github/pr/2886
MagicBeanDev:github/pr/2794
MagicBeanDev:github/pr/2840
MagicBeanDev:github/pr/2830
MagicBeanDev:github/pr/2834
MagicBeanDev:github/pr/2719
MagicBeanDev:github/pr/2742
MagicBeanDev:github/pr/2741
MagicBeanDev:github/pr/2820
MagicBeanDev:github/pr/2771
MagicBeanDev:github/pr/2859
MagicBeanDev:github/pr/2858
MagicBeanDev:github/pr/2823
MagicBeanDev:github/pr/2757
MagicBeanDev:github/pr/2769
MagicBeanDev:github/pr/2844
MagicBeanDev:github/pr/2843
MagicBeanDev:github/pr/2673
MagicBeanDev:github/pr/2855
MagicBeanDev:github/pr/2739
MagicBeanDev:github/pr/2807
MagicBeanDev:github/pr/2851
MagicBeanDev:github/pr/2789
MagicBeanDev:github/pr/2814
MagicBeanDev:github/pr/2818
MagicBeanDev:github/pr/2774
MagicBeanDev:github/pr/2772
MagicBeanDev:github/pr/2750
MagicBeanDev:github/pr/2786
MagicBeanDev:github/pr/2785
MagicBeanDev:github/pr/2782
MagicBeanDev:github/pr/2779
MagicBeanDev:github/pr/2775
MagicBeanDev:github/pr/2706
MagicBeanDev:github/pr/2766
MagicBeanDev:github/pr/2747
MagicBeanDev:github/pr/2759
MagicBeanDev:github/pr/2745
MagicBeanDev:github/pr/2740
MagicBeanDev:github/pr/2733
MagicBeanDev:github/pr/2725
MagicBeanDev:github/pr/2727
MagicBeanDev:github/pr/2728
MagicBeanDev:github/pr/2729
MagicBeanDev:github/pr/2721
MagicBeanDev:github/pr/2722
MagicBeanDev:github/pr/2715
MagicBeanDev:github/pr/2714
MagicBeanDev:github/pr/2707
MagicBeanDev:github/pr/2703
MagicBeanDev:github/pr/2705
MagicBeanDev:github/pr/2697
MagicBeanDev:github/pr/2679
MagicBeanDev:github/pr/2676
MagicBeanDev:github/pr/2669
MagicBeanDev:docs/what-hookshot-connects-to
MagicBeanDev:fix/hdr-encode-test
MagicBeanDev:fix/main-tests
MagicBeanDev:fix/play-cache-files
MagicBeanDev:perf/game-barrier-order
MagicBeanDev:feat/heap-lazy
MagicBeanDev:feat/texture-detail
MagicBeanDev:perf/astc-opaque-bc1
MagicBeanDev:fix/fs-dir-lock
MagicBeanDev:fix/framegen-native-kept
MagicBeanDev:fix/update-no-downgrade
MagicBeanDev:port/k10-gcn-f16-mirrors
MagicBeanDev:fix/framegen-mult-cap
MagicBeanDev:chore/release-as-2.1.1
MagicBeanDev:perf/pcache-load-switch
MagicBeanDev:fix/prepare-progress-log
MagicBeanDev:fix/update-closes-stale-game
MagicBeanDev:fix/hdr-scaled-sampled
MagicBeanDev:perf/first-start-preset
MagicBeanDev:perf/zero-upload
MagicBeanDev:fix/vcore-escape-2s
MagicBeanDev:test/fake-gh-atomic
MagicBeanDev:perf/batch-idle-flush
MagicBeanDev:test/finish-stub-a
MagicBeanDev:chore/record-2.1.0
MagicBeanDev:fix/main-red-tests
MagicBeanDev:fix/test-display-startup-driver-cache
MagicBeanDev:feat/mesh-shader-mode
MagicBeanDev:fix/menu-probes-at-startup
MagicBeanDev:fix/fps-counter-classic
MagicBeanDev:fix/test-log-batch-flake
MagicBeanDev:fix/narrow-screen-hud
MagicBeanDev:ci/prereleases
MagicBeanDev:release/v2.0.15
MagicBeanDev:hotfix/v2.0.15
MagicBeanDev:fix/present-ahead-replay
MagicBeanDev:release/v2.0.13
MagicBeanDev:fix/bracket-paths-2013
MagicBeanDev:fix/hdr-overlays-2013
MagicBeanDev:fix/fps-counter-scale-2013
MagicBeanDev:fix/stick-seen-at-rest
MagicBeanDev:hotfix/menu-fits-screen
MagicBeanDev:fix/f1-always-opens-menu
MagicBeanDev:fix/ini-keep-lines
MagicBeanDev:claude/cranky-pike-7cf247
MagicBeanDev:perf/texture-answer-flat
MagicBeanDev:fix/stamp-test-modules
MagicBeanDev:fix/appimage-fonts
MagicBeanDev:fix/display-awake
MagicBeanDev:release/v2.0.12
MagicBeanDev:fix/discord-windows
MagicBeanDev:rc/v2.0.12-tests
MagicBeanDev:fix/dlss-keep-feature
MagicBeanDev:rc/v2.0.12
MagicBeanDev:button-icons
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
autorelease: pending
autorelease: tagged
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
github_actions
Pull requests that update GitHub Actions code
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
question
Further information is requested
testing wanted
wontfix
This will not be worked on
No labels
accessibility
autorelease: pending
autorelease: tagged
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
testing wanted
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
2 participants
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/Hookshot!1979
Loading…
Reference in a new issue
No description provided.
Delete branch "FIocker/super-build/amd-cas"
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?
This adds a Sharpening method row under Sharpness in the Graphics tab. It offers Gentle (today's sharpen) or AMD CAS, is saved as
sharpening_method, and is left out of the Quality preset. It's a standalone PR onmain(rebuilt on51da0464).Why
Temporal upscalers soften the picture. DLSS, DLAA and FSR rebuild each frame from jittered samples, and the result is noticeably softer than a native render, especially textures, foliage and distant detail. The window pass's current sharpen is RCAS-like and never goes past the light and dark around a pixel. That keeps it free of halos, but it also means it barely recovers detail an upscaler has smoothed over.
AMD's Contrast Adaptive Sharpening suits this job. It is designed to sharpen most where the picture is soft and least where edges already have contrast. That brings back the texture detail DLSS and FSR blur without overshooting edges that are already crisp. It's the sharpener many games pair with their upscalers for exactly this reason.
How
shaders/fg_scale.comp: addscas(), AMD FidelityFX CAS (MIT,ffx_cas.h), using its filter without scaling.main()uses it whenpc.method == 1; otherwise the existingsharpen()runs unchanged.int methodat the end and grow from 20 to 24 bytes, for both offg_scale.comp's pipelines: the plain one and theFG_SCALE_PQone for native HDR (#1942/#2342).vk_framegen.cppmakes both with 24, andtests/upscale_independent_test.cppchecks both.fg_scale_comp_spv.handfg_scale_pq_comp_spv.h, are regenerated withtests/test_fg_scale_sharpen.py --write(glslang 11.12.0). That's the script that writes the pair;scripts/host_shaders.pycovers onlygpu/vk/host_shaders/.opts.sharpen_method, the row, andtx_sharpen_method. Gentle is the default, so nothing changes until someone picks AMD CAS.third_party/fidelityfx-sdk/LICENSE.txt.Testing
tests/run_all.py, the whole suite, locally (clang targeting MSVC, the CPM Vulkan headers, glslang 11.12): 433 passed. The 24 failures are exactly the ones main at51da0464has on the same machine, all down to the local toolchain.test_fg_scale_sharpen.py(cas()included) andtest_upscale_independent.py(the method, on both pipelines) pass.🤖 Generated with Claude Code
Thanks, this is a small, clean change. The description matches the diff: of the −477 lines, 469 are the regenerated SPIR-V header, and the rest are one-line replacements (push size 20→24, the pc struct, the test stub). No features are dropped and nothing else is rewritten.
What I checked:
cas()matches ffx_cas.h's no-scaling path: soft min/max over the cross plus the 3×3,amp = sqrt(saturate(min(mn, 2 − mx) / mx)),peak = −1/lerp(8, 5, sharpness), the cross-shaped lobe normalised by1 + 4w, then saturate. Themax(mx, 1/1024)guard stands in for the barercpand avoids a divide by zero on black. The neighbour spacing and edge handling are the same as the existing sharpen (one picture pixel, clamp-to-edge sampler).dst), and the HDR10 pass encodes after it fromframegen_scaled_view()(vk_replay.cpp present). So the 0..1 assumptions in2 − mxand the final clamp hold. Like the Gentle path, it sharpens the encoded values, not linear light, which is also how most CAS integrations use it.methodat offset 20 and the block is 24 bytes. That matchesinit_scale, the C++ struct (both dispatches, side 3 and the main one, pushsizeof pc) and the test stub.spirv-valpasses, and the disassembly differs only in the order of threeOpDecoratelines. So the header is this shader.test_fg_scale_sharpen.pywill pass without comparing bytes because of the version mismatch. Nit: regenerating with 16.6.0 would keep main's header on one glslang.HOS_OPT_*id, so no collision with main or the open PRs. The value is saved by name assharpening_method, it ispreset_exemptas described, and it takes no restart. I checked the tests that cut the row table or functions out of vk_menu.cpp (test_upscaler_rows,test_menu_restart_slots,test_framegen_preset, theRow rows[]cutters): none depends on the row after Sharpness, so I don't expect breaks.Still open:
cas()is a direct port of AMD's filter, so please add AMD's copyright line and point to the MIT text.third_party/fidelityfx-sdk/LICENSE.txtalready has it in the tree.action_required(they wait for a maintainer to approve the run). The description says the C++ fixtures were left to CI, so for now nothing has compiledupscale_independent_test.cppor the shader tests on this branch. This port onto main also hasn't been played. A run in the game with AMD CAS at a couple of Sharpness values, plus a before/after screenshot (CONTRIBUTING asks for screenshots when a change shows on screen), would settle it.test_fg_scale_sharpen.pycheckssharpen()'s properties as compiled C++ (unchanged at 0, within 0..1, no halos past the neighbours), but nothing coverscas(). The same harness could check that a flat neighbourhood is unchanged and the output stays in 0..1.upscale_independent_testcould also check thatpc.methodfollowsopts.sharpen_method.int fx; float strength; float time). Whichever lands second has to move its members and regenerate the header. #1942 adds a PQ variant of this shader, sofg_scale_pq_comp_spv.hwould need regenerating too.@ -59,6 +60,26 @@ vec3 sharpen(vec3 c, vec3 n, vec3 s, vec3 w, vec3 e, float amount) {// (and no further than the lightest and darkest pixel around it: an edge gets steeper, no halo beside it)Please keep AMD's notice with the port, e.g.
// Copyright (c) 2019-2020 Advanced Micro Devices, Inc. MIT licence: third_party/fidelityfx-sdk/LICENSE.txt(or the full permission text). Crediting ffx_cas.h is good, but MIT asks for the copyright line itself to go with substantial portions.Nit, UX: the pass only runs at
pc.sharp > 0, and CAS's sharpness 0 is already a full −1/8 lobe (kernel centre 2, sides −0.25 whereampis 1). So the slider's first step (0 → 10%) goes from none straight to near CAS's floor, while Gentle starts from nothing. AMD's mapping is fine. A hint line for the row could say that the first step is already noticeable, or you could fade the lobe in over the first step.Thanks for the careful review. The branch is rebased on main (
d7a73062), and these are addressed in7856f59b:cas():Copyright (C) 2024 Advanced Micro Devices, Inc. (FidelityFX SDK 1.1.4), the year in the SDK'sffx_cas.hI ported from, plus a pointer to the MIT text inthird_party/fidelityfx-sdk/LICENSE.txt.w *= clamp(amount * 10, 0, 1)), so CAS starts from nothing like Gentle does; from 10% on it's AMD's mapping. The comment says this part isn't AMD's.test_fg_scale_sharpen.pynow compilescas()too and checks: the picture unchanged at 0; finite and inside 0..1 over 200k random neighbourhoods at every setting; flat black, grey and white unchanged at full strength; a blurred edge steeper as the setting rises.upscale_independent_testchecks the pushedmethodis 1 for AMD CAS and 0 for Gentle.test_upscaler_rowsandtest_menu_restart_slotslocally (clang targeting MSVC); all pass.--write.Heads-up: this conflicts with main now. Could you rebase onto main and resolve the conflicts? Thanks!
The review points are all addressed in
7856f59b(AMD's notice, the fade-in, thecas()andmethodtests). What's left is mechanical, but it needs doing before this can go in.It conflicts with main in
gpu/vk/shaders/fg_scale_comp_spv.h,gpu/vk/vk_menu.cppandtests/upscale_independent_test.cpp. Since #1942/#2342,fg_scale.compis also compiled withFG_SCALE_PQintofg_scale_pq_comp_spv.h, which writes RGB10A2 for native HDR. Addingint methodto the push block means both headers have to be regenerated withscripts/host_shaders.py, not just the one in this branch. Otherwise the PQ pipeline is left with a 20-byte block while the C++ pushes 24. On the PQ path CAS works on PQ codes, which stay within 0..1, so the clamp still holds, but please say in the description what you saw with HDR on.The PR title also fails the Conventional Commit check: something like
feat(vk): AMD CAS as a Sharpening methodwould pass. The in-game run and the before/after screenshots are still to come.AMD CAS sharpening: unsoften DLSS / FSR upscaled picturesto feat(vk): AMD CAS as a Sharpening methodRebuilt on main at
51da0464(81e31ce7):vk_framegen.cppmade theFG_SCALE_PQpipeline with 20 bytes. Both pipelines are now made with 24, and both headers are regenerated. One correction: the pair comes fromtests/test_fg_scale_sharpen.py --write, sincescripts/host_shaders.pyonly buildsgpu/vk/host_shaders/.upscale_independent_testnow checks the 24-byte block on both pipelines. The whole localrun_all.pymatches main at51da0464: 433 passed, and the 24 failures are main's own on this machine.Everything from my last review is fixed. Both
FG_SCALEpipelines are now made with a 24-byte push block (vk_framegen.cpp:263and:576), both headers are regenerated,upscale_independent_testchecks 24 on both, and the title passes. You were right that the pair comes fromtests/test_fg_scale_sharpen.py --write. I had pointed you at the wrong script.I merged it into current main.
test_fg_scale_sharpen,test_upscale_independent,test_framegen_resources,test_upscaler_rows,test_menu_restart_slots,test_menu_i18nandtest_framegen_presetall pass.Still open:
tests/test_readme_menu_rows.py, which needs a readme option-table line for every menu row. With both merged, it fails on "Sharpening method". Please add a line after Sharpness, for example| | Sharpening method | Gentle, AMD CAS | Gentle |.