WIP: perf(vk): the static shadow map made smaller on cards with little VRAM (RX_VK_SHADOW_MAP_SIZE) #1367
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1367
Loading…
Reference in a new issue
No description provided.
Delete branch "GrimVisage/Longshot:perf/half-size-static-shadow"
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?
Type: perf · Risk: medium · Tested on: Linux, RX 9070 XT (RADV) · Needs: Windows, an 8 GB card (RX 6600-class); a card under 6 GB
Why
On 8 GB cards the game runs out of video memory in some areas. Textures then get dropped and the frame rate falls,
for example to 15 fps on an RX 6600 in #1066. One piece of that is a single image the game makes whenever an area
loads: a 12288 x 12288 static shadow map that takes 288 MB of VRAM on every GPU. That is about 4% of everything
an 8 GB card lets the renderer use. Made smaller on cards with little VRAM, it gives back 126 MB at 3/4 size or
216 MB at half size, and the shadows still fall in the same places. Fixes #1295. See #1066.
What changed
The static shadow map can now be made at 75% or 50% of its side, as 9216 x 9216 (162 MB) or 6144 x 6144 (72 MB).
Its draws' viewport, scissor and clears shrink by the same share. Because the game samples it through normalized
coordinates as a depth comparison, the same coordinates land on the same spot in the smaller image. By default
(Auto) it is made at 50% where the driver allows the process under 6 GB, at 75% under 8.5 GB or on an integrated
GPU, and at full size everywhere else.
RX_VK_SHADOW_MAP_SIZE=100,75or50picks the size on any card.gpu/vk/static_shadow_half.h(new) recognizes the image: 2D, NVN 0x32 (D16), one level and layer,not multisampled, square, at least 8192 a side. It holds the Auto rule (
auto_percent), the switch(
percent) and the rectangle and viewport scaling.create()ingpu/vk/vk_texture.cppdecides the size onceper process, logs it, and sets
Texture::rt_pct(vk_texture.h).gpu/vk/vk_draw.cpp,targets()carries the depth target's share (Targets::depth_pct, only with nocolour target bound; a colour target bound alongside it is logged once).
dynamic_statescales the viewportand scissor, and
clear_rectscales depth clears. The share goes into the fast-path key (up[14]).gpu/vk/vk_xfer.cpp,resolve()scales a copy's rectangle into or out of the image.copy_bufferout of it is skipped and logged.upload_innerclears the image when the upload is all zero (the game's only upload ofit). Any other upload is skipped and logged. Write-back to guest memory is never done for it. None of these
happened in any run here.
gpu/vk/switches.defand in docs/development.md, "Switches for testing and debugging".tests/test_static_shadow_half.cpp/.pycover which textures count, the Auto rule, the switch'svalues, the sizes, and the rectangle and viewport scaling at 75 and 50.
Measurements
Verdict: no cost and no measured gain on this PC. On this card (16 GB) Auto keeps the whole map, and main and
this PR are the same within the spread. With an 8 GB card's budget modelled (
RX_VK_TEST_ALLOWED_MB=6500), Automakes the map at 9216 (126 MB less), and fps stays within the spread. That is shown best by the same build with only
the switch changed. A first main-against-PR series at that budget had Kokiri Forest slower on the PR's side. The
switch-only pairs didn't repeat it: there the best Kokiri run was a 75% one. At this budget a run's fps depends
mostly on how its area loads go, because a load that drops many textures leaves a lower texture budget for the rest
of the area. The modelled budget never makes the driver really short, so what 126 MB gives back on a real 8 GB card,
where the driver moves memory to system RAM, is in Must be tested.
Hardware: Fedora 45 (Linux 7.3.3), AMD Radeon RX 9070 XT 16 GB, radv Mesa 26.2.7, Ryzen 5 5600X, 32 GB
Scene: child Link, a test save, noon. The Market standing 30 s then turning 30 s, then Kokiri Forest and Hyrule
Field the same, each after a teleport and 15 s to settle. 2560x1440 fullscreen, the Auto preset's settings for this
PC (FSR 4 Quality, 1707x960 -> 2560x1440), mesh shaders by the default (the compute path), frame generation off, cap
240 (
HOS_FPS_MAX=240; no part came near it),RX_VK_AUTO_TUNE=0.Method: each part's median fps and 1% low from the frame log (
RX_VK_FRAME_LOG); the texture budget and VRAM fromthe log's
vk: VRAM:lines. One job at a time through the job queue's timing mode, one options file for every run,the route through
scripts/longshot_ctl.py(debug tools on for the teleports). Series 1: two test builds from6d72ca93(dev_packs.py), a warm-up of each, then main, PR, PR, main, as this card and again withRX_VK_TEST_ALLOWED_MB=6500. Series 2: the PR's build alone at 6500,RX_VK_SHADOW_MAP_SIZE=100against75, awarm-up, then 100, 75, 75, 100 (stopped there: the sides overlapped). The median of the runs on each side.
How to reproduce: the same route on any save in the Market;
RX_VK_TEST_ALLOWED_MB=6500for the modelled budget,RX_VK_SHADOW_MAP_SIZE=100or75to pick the size.Baseline: the measured commit was 7e080be9 on main
6d72ca93. This PR is that commit rebased onto544229a2, whose onecommit (#1332) is Windows-only (
load_global's#ifdef _WIN32), so the Linux numbers hold.Series 1, as this card (Auto: the whole map on both sides), fps (runs; median):
6d72ca93Series 1,
RX_VK_TEST_ALLOWED_MB=6500(Auto on this PR: 75%), fps (runs; median):6d72ca93Series 2,
RX_VK_TEST_ALLOWED_MB=6500, the switch alone, fps (runs; median):Screenshots of the same spot and frame of a scripted route (RX 9070 XT, 2560x1440, the game's own upscaler: that
test build had no FSR 4), left to right
RX_VK_SHADOW_MAP_SIZE=100(whole, as main),75,50, all three onthis change on main
1764fed2(the same code as this PR; the size the only difference):At 75 the edges are close to whole; at 50 the branches' shadows are visibly coarser and stepped.
Flags and settings
This adds one switch,
RX_VK_SHADOW_MAP_SIZE.RX_VK_SHADOW_MAP_SIZE100,75or50on any card100to compareTesting
Tested:
python -I -B tests/run_all.pyon Linux, on this PR and on main544229a2: the same tests fail on both on this PC(checks that read source main has since changed,
lz4not installed,tests/test_switch_table.py'sRX_VK_PGO_FILErow, andtests/test_tested_configurations.py, which stops at2026-11-16-shadow-map-slots-gumminaomi-on.mdfrom #1256). This PR's 12docs/tested/files read fine with itsread_row.tests/test_static_shadow_half.pypasses, and so does each test that differed between thetwo runs when run alone.
Mountain Trail, standing and turning. Shadows land in the same places at every size. The log shows no skipped
copy, upload or write-back.
Not tested: a real card with 8 GB or less, and Windows. This PC has 16 GB;
RX_VK_TEST_ALLOWED_MBonly modelsthe budget. An integrated GPU (Auto: 75).
Must be tested:
Market, standing then turning, on main and on this PR. Expect the log to say
the static shadow map: made at 9216x9216, 75%, the frame rate in Kokiri Forest the same or better than main (the gain, if any, is whatthis PC could not show), and shadows in the
same places (Test Farm:
@Beanstalk windows, amd, 8 GB— see the request comment).6144x6144, 50%and about216 MB less (Test Farm, if a farm PC has one).
Risks
What could break: the static shadow map's shadows, if a game path reads the image another way than the ones
seen here: a buffer copy out of it, an upload that isn't all zero, a write-back, or a colour target bound beside
it. Each one is logged when it happens. On cards that get a smaller map, its shadows' edges are coarser. Cards
allowed 8.5 GB or more get the whole map, as on main.
Turning it off:
RX_VK_SHADOW_MAP_SIZE=100.Compatibility: nothing changes for saves, longshot_options.ini or the vk ABI. The fast-path key gains the
depth target's share, so nothing is translated again.
Issues
Fixes #1295
See #1066
Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.docs/tested/for each new measured run (format indocs/tested-configurations.md).🤖 Generated with Claude Code
Tested in game: RX 9070 XT, radv Mesa 26.2.7, Fedora 45: Market, Kokiri Forest, Hyrule Field, Kakariko Village and Death Mountain Trail at RX_VK_SHADOW_MAP_SIZE=100, 75 and 50, and with Auto at RX_VK_TEST_ALLOWED_MB=6500; shadows in the same places at every size, edges coarser at 50, no copy, upload or write-back of the map skipped, no crash
Possibly related, for context:
The measurements are of 7e080be9 on main
6d72ca93; this PR is that commit rebased onto main544229a2(1e0959fa, the same diff) plus the 12docs/tested/files (581a9d5d). The one commit in between, #1332, changes only Windows code (load_globalunder#ifdef _WIN32ingpu/vk/vk_main.cpp, and its test), so the Linux numbers hold without measuring again.@Beanstalk windows, amd, an 8 GB card (RX 6600 / 6600 XT / 6650 XT class), the driver's default settings: compare main and this PR in Kokiri Forest and the Market, standing still, then turning. On this PR the log should say
the static shadow map: made at 9216x9216, 75%. Compare VRAM used (the log's VRAM lines), fps and the 1% low against main, and check that the shadows on the ground fall in the same places. If a farm PC has a card the driver allows under 6 GB (a 6 GB or 4 GB card), the same there, expecting6144x6144, 50%.@GrimVisage 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
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.