feat(vk): shadow resolution option #1892
Open
FIocker wants to merge 4 commits from
FIocker/super-build/shadow-resolution into main
pull from: FIocker/super-build/shadow-resolution
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!1892
Loading…
Reference in a new issue
No description provided.
Delete branch "FIocker/super-build/shadow-resolution"
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 Shadow resolution row to the Graphics tab: Game, 1.5x, 2x, 3x or 4x. It is saved as
shadow_resolution, applies after a restart, and sits under Detail, outside the Quality preset. The default is Game, so nobody's picture changes until they opt in. It's a standalone PR onmain(rebuilt on51da0464).Why
OoT's shadow maps are fairly coarse on a big monitor. The characters' maps are 768 px or smaller. The sun's three cascades are only 1600 × 1600 (D16, docked), and each farther cascade spreads those pixels over more ground. Shadows lose detail with distance, and edges show stair steps and shimmer.
How
Everything happens in the renderer; the game isn't patched.
gpu/vk/shadow_res.h, pure, no Vulkan): the predicate, the side and the edge rounding, used bycreate,scissor_rectandvk_xfer.cpp.vk_texture.cpp,create): textures that look like shadow maps get a largerVkImage. That means square depth textures, 2D or 2D array, one level, single sample, 256 to 4096 px and a multiple of 32. The multiple of 32 leaves out the odd sizes that follow dynamic resolution. Each side is capped at 8192 px and each image at 1 GB.Texture::rsstores the scale, and the VRAM budget counts the larger image. VRAM compaction (RX_VK_COMPACT=1) rebuilds a moved image at its image size, so a scaled map stays scaled.widthandheightstay at the game's size, so uploads, buffer copies and read-backs still address the game's texels, inside the image.vk_draw.cpp):targets()sizes a depth-only pass over such a texture to its image and setsTargets::scale. The game's viewport, scissor and clear rectangles are multiplied by that scale. The draw's scissor and both clears usescissor_rect, which rounds each edge to the nearest texel (shadow_res::edge), so rectangles that meet still meet. At Game it gives the same rectangles as before.vk_xfer.cpp):copy_b2t). OoT never copies its shadow maps to buffers, but this is why the option is shaped around how OoT uses its maps, not a general texture scale.A depth texture that qualifies but is drawn alongside colour targets isn't a shadow map. That pass keeps the game's size, and the texture's size and format go on a refusal list (
shadow_res_refuse), so the texture is made at the game's size when the game makes it again. The texture already made keeps its larger image, so anything sampling that depth would read the wrong region until then. It's a logged limitation: OoT's shadow passes are depth-only, and it hasn't happened.Cost
The cascades take about 15 MB at the game's size, 61 MB at 2x (3200² × 3) and 246 MB at 4x (6400² × 3). The characters' maps cost little at any setting.
Testing
vk_draw.cpp,vk_texture.cpp,vk_xfer.cppandvk_menu.cppcompile with clang usingnx2/build.py's renderer flags. The full game builds with MSVC as part of the combined build, which has the same change. llvm-mingw and Linux need CI.tests/run_all.py, the whole suite, locally (clang targeting MSVC, the CPM Vulkan headers, glslang 11.12): 433 passed. The failures are exactly the ones main at51da0464has on the same machine, all down to the local toolchain. Of these:tests/test_shadow_resolution.pychecks the predicate on OoT's sizes and the odd ones, and the 8192 and 1 GB caps. It also checks that every qualifying size at every factor maps the game's whole extent onto the whole image, and that edges stay in order and shared, so rectangles that meet still meet (1.5x included).test_preset_exempt,test_menu_restart_slotsandtest_native_astc_texture_countpass too.🤖 Generated with Claude Code
Thanks, this is a nice, self-contained way to do it:
width/heightstay the game's and only the image and the passes over it grow, so uploads, copies and sampling mostly don't need to know. I went throughtargets(), the viewport/scissor/clear scaling, the bias checks,copy_t2t/clear_tex, and the image/budget sizing. AtGame(factor 1)scissor_rectgives the same rectangles as the old dynamic-state scissor andclear_rect, so the refactor shouldn't change anything when the option is off.Blockers:
vk_menu.cppandvk_menu.hconflict with the new Anisotropic filtering row andopts.anisotropy. Both are trivial to fix (keep both). The other four files merge cleanly. Because of the conflict, no CI has run on this PR, so nothing has built it with llvm-mingw or on Linux yet (the description only mentions MSVC, which the project doesn't ship with). Please rebase so the checks run. After the merge there are 12 restart rows againstkMax = 16, sotest_menu_restart_slotsstill passes.Worth fixing (inline):
gwline.RX_VK_COMPACT=1, off by default) rebuilds images att->width/t->height. It would shrink a scaled shadow map back to the game's size whilersstays above 1. Details on theci.extentline.Smaller things:
targets()(depth drawn with colour) keeps its larger image until the game makes it again. If something samples that depth, it reads the wrong region, because only the game-sized top-left corner was drawn. That's fine as a logged limitation for OoT, whose shadow passes are depth-only. Maybe say so in the comment, since the refusal only applies to the next texture made.clear_rectis now just a forwarder toscissor_rect. Its two callers could callscissor_rectdirectly.Gameand at 1.5x would be good, since 1.5x gives non-integer edges (768 -> 1152) and is the setting most likely to show seams from the rounding. A source test for the qualifying predicate and thescissor_rectrounding (two rectangles that meet still meet) would also fit the repo's style.No other reviews or comments on the PR yet. Once it's rebased and CI is green, I'd be happy to look again.
The constant bias checks use the game's size now, good. But the game's own slope-scaled bias (
d.bias[2] = s.poly_offset[0]a few lines up) is in units of the depth slope per pixel. At scale k, each pixel covers 1/k as much ground, so the slope term drops by k. At 4x the cascades get a quarter of the slope bias the game asked for, which is the usual way acne comes back at higher shadow resolutions. Something likeif (at.scale != 1.0f) d.bias[2] *= at.scale;(for depth-only passes) would keep the game's bias. It didn't show on your RTX run, but it's cheap to keep equal, and other GPUs' rasterizers differ.Nit:
clear_rectonly forwards now. The two callers could callscissor_rectdirectly.Once this is merged with main:
compact_step(VRAM compaction,RX_VK_COMPACT=1, off by default) rebuilds a moved image "as create() made it" withci.extent = {t->width, t->height, t->depth}and copiest->width >> lper level. For a scaled shadow map that makes a game-sized image whilersstays above 1. The next pass then gets a render area and viewport ofimage_width(tex), past the image's extent, which is a validation error or a GPU fault. It only applies to textures not created as targets and with compaction on, but it's a one-line fix: useimage_width(t)/image_height(t)there and in the copy regions.Thanks for going through it this closely. All points are addressed: the branch is rebased on main (
d7a73062), the menu conflicts are resolved by keeping both rows, and the fixes are infda8a1cc.if (at.scale != 1.0f) d.bias[2] *= at.scale;sits right after the game's bias is read. Only a depth-only pass over a scaled map has a scale, so nothing else changes.compact_stepnow makes the image atimage_width(t)/image_height(t), and its copy regions use them too.clear_rect: removed. The two clears callscissor_rectdirectly.gpu/vk/shadow_res.h, with no Vulkan.create,scissor_rectandvk_xfer.cppall use it. The newtests/test_shadow_resolution.pycompiles the header and checks:edge()andimage_size().nx2/build.py's renderer flags (syntax-only). The C++ fixture builds with clang targeting MSVC. CI still waits for approval to run llvm-mingw and Linux.Follow-up in
cdb8791f:test_vulkan_clear_mip's stand-inTexturegetsrsand theshadow_res.hhelpers thatclear_texnow uses; without them the fixture didn't compile. I've now run the wholetests/run_all.pyon this branch locally (clang targeting MSVC, the CPM Vulkan headers, glslang 11.12). It gives the same results as main atd7a73062on the same machine: 325 passed, and the 18 failures are the same 18 main has here, all down to this PC's toolchain.Heads-up: this conflicts with main now. Could you rebase onto main and resolve the conflicts? Thanks!
The follow-ups to hckrman101's review look right to me: the slope-bias scale in vk_draw.cpp, compact_step building at image_width/image_height, and shadow_res.h with its test. A few things are left before this can be judged. The title isn't a conventional commit, so the only check that ran fails; something like "feat(vk): shadow resolution option" would pass. The branch conflicts with main again in vk_menu.cpp and vk_texture.cpp, so llvm-mingw and Linux have still never built it. The description has no screenshots, and this changes what's on screen; a Game vs 4x pair of the same far shadow would do. Game and 1.5x are still unplayed, and 1.5x is where the non-integer edges are. Also worth saying in the description: a buffer copy of a scaled map only gets its top-left corner (the warn in copy_b2t), so the option is shaped around how OoT uses its maps. The default stays Game, so nobody's picture changes until they opt in.
Shadow resolution option: render the shadow maps largerto feat(vk): shadow resolution optionRebuilt on main at
51da0464(5e94a6ac), and the title is now a Conventional Commit. Changes from the rebase:preset_exempt;test_preset_exemptcaught that it should be.texture_level_units' line, whichtest_native_astc_texture_countpins.The whole local
run_all.pymatches main: 433 passed, and the failures are main's own on this machine. Still to come: Game and 1.5x on this head, and a Game vs 4x screenshot pair.github-sync referenced this pull request2026-11-12 13:39:09 +00:00
The title, the rebase and the description are done. 5e94a6a merges cleanly with current main, and CI is green, llvm-mingw and the AppImage included. I also read the row's placement under Detail (it's preset_exempt) and the budget change in create(). At Game, shadow_resolution_factor() is 1 and qualifies() is never reached, so nobody's picture changes.
Two things from my last review are still open, as the description says:
Once those are posted, I'd be glad to see this go in.