WIP: perf(vk): keep lowered shader stages by their bytes, so a new program of known code is not parsed again #2891
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
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
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2891
Loading…
Reference in a new issue
No description provided.
Delete branch "(deleted):perf/shader-parse-cache"
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
After an area loads, the game makes new programs of shader code it has used before. On main the same code was then parsed and lowered again on the replay thread: about 85 ms per arrival in symbolized samples (
program_pick > codes_of > read_live_code > parse_code > LowerToMaxwell). Two caches miss it:codes_ofkeeps stages by program serial, and drops them when the game frees the program.read_live_code's only other cache is a 32-slot ring of weak references.This keeps each lowered stage by its bytes:
bytes.keyplusdev.native_mma; a hit needs the 216-byte control section and the whole code area to match byte for byte.RX_VK_PARSE_CACHE=0puts back the ring exactly as before.Read first:
gpu/vk/parse_cache.h, andread_live_codeingpu/vk/vk_shader.cpp.Note:
vk_shader.cppis in the shader translator's stamp, so players prepare the shaders once after updating.Testing
Tested: Windows 11, AMD Radeon RX 6800, driver 26.10.1, with the other two PRs (Measurements). No visual differences seen.
Checks:
tests/test_parse_cache.py(new): matching, collisions, eviction, the cap, 8 threads.tests/test_live_shader_stage.py: runs the realread_live_codewith the cache on and off; its "all owners released" step fails on main.clang++ -fsyntax-only -Wall -Wextraon the changed files.Still to test:
Measurements
Verdict: each change does the work it targets (below), but on its own none moves total stutter at area changes beyond run-to-run noise. Together with its two sibling PRs, the worst frame at an arrival is 15-25% shorter. An earlier claim here of "-20% stutter in the loads" was mostly how long each load took: the loads' length alone varies from 3,300 to 4,900 frames between runs of the same build.
Setup:
kokiri-start, then teleports to Market (child), Hyrule Field (child), Kakariko Village, Kokiri Forest, Hyrule Field (adult) and Lake Hylia (adult). 25 s in each with the camera turning, plus 20 s walking in circles in Hyrule Field.RX_VK_FRAME_TRACE=1).28cb22b9(5)In play (the walk and the camera turns, outside the arrivals), every run of every build has a median frame of 9.8-10.0 ms and 0-1 frames of 33 ms or more.
What the worst arrival frames are spent on, in the runs with all three: draw 100-440 ms, mostly in the recording's commands (up to 396 ms: the first bindings of vertex and index buffers, which import host memory and make mirrors) and descriptors. A change that imports pools ahead of their first binding is being measured on top of these three.
Risks
VK_ERROR_OUT_OF_DEVICE_MEMORYshortly after arriving in Market (7.8 of 15.5 GB of VRAM in use), and the game stopped drawing. It has not come back in nine runs since, and no run of main or the nightly (about 20) has refused a submit. Until it is explained, treat this PR as a possible cause.RX_VK_PARSE_CACHE=0.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (Not run yet: the checks reading the changed files pass, apart from failures they share with main.)main, or Measurements says why there is nothing to measure. (Measured: no stutter gain on its own beyond the noise.)third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def. (Rows added; defaults to be confirmed by this PR's own A/B.)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.🤖 Generated with Claude Code
Tested in game: Windows 11, AMD Radeon RX 6800, driver 26.10.1, i7-13700: a pack over main
28cb22b9with the texture block reserve, shader parse cache and sparse bind PRs together, six teleport tours through Market, Hyrule Field (child and adult), Kakariko, Kokiri Forest and Lake Hylia with the player's settings; no visual differences, loads stutter about 20% less, frame rate in play unchanged. One run (the first after the build) froze with refused submits (VK_ERROR_OUT_OF_DEVICE_MEMORY), not seen again in nine runs: under investigation, see Risks.Measurements corrected: each change built alone over main (two runs each), against five runs of main. The earlier '-20% stutter in the loads' was mostly load length varying between runs. On its own this change does not move visible stutter at arrivals beyond the noise; with its two siblings the worst arrival frame is 15-25% shorter. Staying WIP while the next change (imports made ahead of their first binding) is measured on top.
Closing as not significant: the stutter a player sees at an area change is not measurably lower with this change, alone or together with its siblings (#2890, #2891, #2892) and three further fixes. Each does the work it targets; the frames that stutter just move to other work.
Setup: Windows 11, RX 6800, driver 26.10.1, the player's settings, uncapped. A six-teleport tour, each run a separate launch in timing mode. Visible stutter is what frames of 25 ms or more spend over 16.7 ms, from 1 s before control returns to 2 s after, summed over the six arrivals.
28cb22b9(8 runs)What did show:
What holds an arrival frame now, from symbolized samples: host-memory imports of the game's re-created area pools (39% of the replay thread), and mirrors rebuilt after the loading screen (~16%). The first frame of an area pays for whatever is first used in it; moving one cost earlier did not shorten that frame overall.
The branches stay on conongnang's fork in case someone picks this up.
🤖 Generated with Claude Code
Pull request closed