perf(vk): reduce renderer CPU work and add bounded diagnostics #1541
Open
mikaba-eu wants to merge 19 commits from
mikaba-eu/pr/renderer-performance into main
pull from: mikaba-eu/pr/renderer-performance
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
1 participant
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!1541
Loading…
Reference in a new issue
No description provided.
Delete branch "mikaba-eu/pr/renderer-performance"
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?
Repeated renderer preparation and avoidable CPU contention add work to frame submission, while existing traces make it difficult to identify where time is spent. This PR reduces that repeated work and adds bounded diagnostics without promising a particular gameplay frame rate. Implemented with GPT-6 Astra medium & xhigh.
Merged upstream
ddafc1f9, retaining its topology/color-type helpers and shader-answer validation changes. The earlier local page-copy experiments remain disabled; this PR does not contain the experimental material/packet/query redesign or external neural processing.Validation: the refreshed branch passes the full Linux source suite: 377 passed, 0 failed, 14 skipped, using the bundled Clang toolchain. The subsequent HDR/FSR update also passed all 17 affected menu/upscaler checks. The final builder-only upstream update passed 11 affected checks. The skipped checks require unavailable platform/hardware/tool dependencies. Earlier combined-branch gameplay evidence is recorded in
docs/tested-configurations.md; it is not an isolated speedup measurement for this refreshed PR. Windows and AMD gameplay were not tested locally.The final source includes upstream
2e62a977; its release-only changes passed both affected release/update checks.Heads-up: this conflicts with main now (a lot landed today). Could you merge main into the branch (or rebase) and resolve the conflicts? Thanks!
Merged current main (
1392ea3) and resolved the conflicts, preserving upstream replacements where they supersede our changes. Migrated local tests to the new per-test runner declarations. Independent source suites and the combined suite pass; fresh Linux gameplay results and limitations are recorded in the updated description. Hyrule Field and a warm Forest run completed the short movement tests, but camera hitches remain; earlier memory-guard stops and the incomplete Market event are not reported as passes. AI-assisted development: GPT-6-Astra (medium and xhigh).Refreshed again to main
117eae7and resolved the new Anti-Lag source-fixture conflict. Complete Linux source suite re-run: 320 passed, 0 failed, 18 skipped. Existing gameplay evidence remains explicitly tied to its tested build.Heads-up: this conflicts with main now. Could you rebase onto main and resolve the conflicts? Thanks!
There's useful work in here, and the tests you changed get stronger rather than weaker.
test_program_answer_domainsnow checks thatresolved_answers_validagrees withstill_validin every case, which is a nice touch. But in its current form I don't think this can be reviewed or merged as one unit. I covered the riskiest parts: the Linux affinity changes, the stage-lowering cache, the pick validation, the switches and the test edits. I didn't review the capture, trace or analysis scripts in depth.blocking: merge conflicts. Against current
origin/mainit conflicts ingpu/vk/vk_draw.cpp,vk_memory.cpp,vk_replay.cpp,vk_shader.cpp,vk_texture.cpp,tests/test_antilag.pyandtests/test_present_semaphores.py. hckrman101 asked for a rebase again today. With this much of the replay touched, a re-resolution is effectively a new change and needs its own test pass.blocking: scope. CONTRIBUTING asks for one topic per PR, and that a bug fix not carry refactors. This PR has at least six independent changes with different risk profiles:
host/hos_thread.c,host/posix/win32_posix.c,gpu/vk/vk_thread_affinity.h,vk_jobs.cpp).vk_stage_cache.h,vk_shader.cppread_code).vk_shader.cppresolved_answers_valid).Each could merge (or be reverted) independently. Part of the Linux affinity work is already on main:
process_affinitytaken before main exists there now. Please split along those lines, ideally starting with the uniform ordering fix.should fix: new switches default to on, and none are documented where switches live.
HOS_PIN_RENDER(host/hos_thread.c:774, on by default) changes where the Presentation Thread runs on every Linux machine.RX_VK_STAGE_CACHE(gpu/vk/vk_shader.cpp:165) is on by default.RX_VK_PICK_REREAD,RX_VK_STAGE_TRACE,RX_VK_STAGE_TRACE_ROWS,RX_VK_SLOW_STAGE_US,RX_VK_PRESENT_STAGES,RX_VK_CAPTURE_CPU_UNCACHEDandRX_VK_SHADOW_COMPARE_STATSare also new.docs/development.md's switch table has none of them; two appear only in the newdocs/renderer-performance.md. They are also read withatoi/presence rather thanenv_on(#2042), soHOS_PIN_RENDER=offwould leave pinning on. CONTRIBUTING also says new switches are "off, or neutral, unless asked for". A default-on placement change on Linux needs measurements on the Deck and on a desktop with few cores, given #2263's findings about how sensitive this is.should fix
gpu/vk/vk_shader.cpp:167:static thread_local StageCache<Code, kControlSize> cache(64u << 20)gives each thread its own 64 MB budget (up to 4096 entries).read_coderuns on every thread that makes programs: the recording threads, the parallel-replay workers, and the precompile pool at:2352, which startshardware_concurrency()threads. So the worst case is 64 MB times the thread count, and a stage lowered on one thread is lowered again on every other. A single shared cache under a lock (lowering is far costlier than the lookup) with one process-wide budget would bound memory and hit more often. If per-thread is deliberate, please give the worst-case total for a 16-thread CPU and for the Deck.should fix
host/posix/win32_posix.c:312: main'sGetProcessAffinityMaskfalls back to reading the mask again when the constructor didn't run or its call failed. This version returnsFALSEinstead. Callers such ashos_thread_pinand #2263'shos_short_sleep_timerthen see an unknown processor count. Please keep main's fallback when you resolve this file.question
gpu/vk/vk_shader.cpp:2218-2223:resolved_answers_validmatchesstill_validgiven the same handles, which the test now proves. Butanswer_handlesnow stores the full handle, sampler bits included, instead of& 0xFFFFF. So a sampler-only change now counts as "differ" and goes to revalidation, where before it was a direct hit. That's correct, but was the hit rate in Kokiri measured before and after? Otherwise this part may cost more than it saves.No new commits since my review at
131b0a3, so every point there still stands. The branch conflicts with current main in the same seven files:vk_draw.cpp,vk_memory.cpp,vk_replay.cpp,vk_shader.cpp,vk_texture.cpp,tests/test_antilag.pyandtests/test_present_semaphores.py. None of its pieces has landed separately: main has novk_stage_cache.h,resolved_answers_valid,HOS_PIN_RENDERorRX_VK_STAGE_CACHE.The still-open points are:
env_on;vk_shader.cpp:167;GetProcessAffinityMaskfallback atwin32_posix.c:312.One addition: #2172 is stacked on this branch and contains all of its commits. Splitting this PR means #2172 has to be rebased onto whichever pieces land, so it's worth planning those two together.