perf(game): mark unmapped descriptor and event NVN2 pools CPU_NO_ACCESS #2902
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
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2902
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/pc-phase-d-engine-sites"
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
Specializes two boot-time NVN2 pool-creation sites on PC (
HOS_POOL_FLAGS_SITES, enabled by default) via declarative worker-threadreplacehooks ingame/sites/:pool.descFlags(f_80966440+0x130mov w1, #0x22): setsCPU_NO_ACCESS | GPU_CACHED(0x21) instead of0x22for the unmapped descriptor pool (verified zeronvnMemoryPoolMap/nvnBufferMapcallers).pool.eventFlags(f_80f69040+0x24cmov w1, #0x12, Site 1 for the 4 KBNVNeventpool; Site 2+0x3e4nvnBufferMapis kept untouched via 8-word signature disambiguation): setsCPU_NO_ACCESS | GPU_UNCACHED(0x11).In
KokiriForest_Child(1280x720, 4 interleaved runs), Avg FPS improves from90.21(92.48warm) to93.59(+3.7%all /+1.2%warm), 1% Low improves from35.80(42.81warm) to43.92(+22.7%/+2.6%warm), 0.1% Low improves from20.01(27.31warm) to28.92(+44.5%/+5.9%warm), andmemsync_csv_meandrops-6.6%(0.711 -> 0.664 ms) with0warnings and0left-out CPU R/W. Read first:game/sites/sites.toml,game/sites/e0f3ccfaf50065ae4ea01eb5aeb13b1a45da3348/locations.toml,game/sites.def,game/oot_sites.c, andHOS_POOL_FLAGS_SITESingpu/vk/switches.def.Testing
Tested: Windows 11, Intel Core i7-9700 (8C/8T), NVIDIA GeForce RTX 4060 (driver
621.40), built cleanly viacargo test -p sites,dev.py pack, anddev.py rt. Ran 4 interleaved 35 s A/B runs (BASE_1,POOL_1,POOL_2,BASE_2,3,090–3,296frames/run,1280x720,RX_VK_IMMEDIATE=1,RX_VK_FRAME_TRACE=1) plus an earlier 4-run bisect confirmingpool.descFlags+pool.eventFlags(POOL_195.05Avg /45.221% Low) outperforms adding hot write-before-flushinvalidatereplacehooks (93.21/42.95due toCtxsync overhead) vs warmBASE_2(92.02/42.62), with0warnings andCPU reads or writes of one left out: 0. Tests:cargo test -p sites(49unit +4repository tests passed);tests/run_all.py:2 passed(test_site_chain.py,test_doc_anchors.py),1 failedpre-existing onorigin/main @ 28cb22b9e(test_switch_table.py: upstreamLONGSHOT_LAUNCHER_STARTUPinhost/launcher_startup.h:9;HOS_POOL_FLAGS_SITESpassed).Still to test:
@Beanstalk linux: build on Linux and runcargo test -p sitesandpython -I -B tests/run_all.py, expecting clean site placement andtest_site_chain/test_doc_anchorspass (@Beanstalk linux).@Beanstalk windows: run full CI check suite and smoke-testKokiriForest_Child+ save load/event sync, expecting zero NVN event regressions (@Beanstalk windows).Measurements
Verdict: Improves Avg FPS from
90.21(92.48warm) to93.59(+3.7%all /+1.2%warm), P50 FPS from95.71to97.23(+1.6%), 1% Low FPS from35.80to43.92(+22.7%,P9921.08 -> 18.39 ms), 0.1% Low FPS from20.01to28.92(+44.5%), and cutsmemsync_csv_meanby-6.6%(0.711 -> 0.664 ms).HOS_POOL_FLAGS_SITESships enabled (1).Setup: Windows 11, i7-9700, RTX 4060 (
621.40);KokiriForest_Child(kokiri-start),1280x720(resolution=0,HOS_RES_SCALE=1.0,quality_preset=6),RX_VK_IMMEDIATE=1,frame_generation=0,HOS_FPS_MAX=1000,HOS_AUDIO=0,RX_VK_FRAME_TRACE=1(frames.csv), 4 interleaved 35 s runs after 8 s settle togglingHOS_POOL_FLAGS_SITES=0vs1.Baseline:
origin/main @ 28cb22b9e(this PR @ df65e1c47withHOS_POOL_FLAGS_SITES=0).0) @df65e1c471) @df65e1c47BASE87.93, 92.48 vsPOOL93.35, 93.82)BASE94.88, 96.53 vsPOOL97.18, 97.28)BASE28.79, 42.81 vsPOOL41.15, 46.69)BASE12.71, 27.31 vsPOOL27.42, 30.42)memsync_csv_mean(ms)Risks
If the game ever reads back on CPU from either the
f_80966440descriptor pool orf_80f69040Site 1 ([x22+168]4 KBNVNeventpool) without going through hostNVNevent/nvn_gpu_write, marking themCPU_NO_ACCESS(0x1) would omit write-back diffs. Both hooks are guarded byHOS_POOL_FLAGS_SITES=0(runtime kill switch restoring original0x22/0x12), andpool.eventFlagsuses an 8-word signature so Site 2 (nvnBufferMap) is never matched. No changes tovk_api.h, saves, or pipeline caches.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Tested in game: Windows 11, i7-9700, RTX 4060 (621.40), KokiriForest_Child 1280x720: HOS_POOL_FLAGS_SITES=1 improves Avg FPS +3.7% (90.21 -> 93.59, warm 92.48 -> 93.59), 1% Low +22.7% (35.80 -> 43.92), 0.1% Low +44.5% (20.01 -> 28.92), memsync -6.6%, 0 warnings, 0 left-out CPU R/W.
Possibly related, for context:
@review
@beanstalk
Beanstalk test farm · 🔄 testing (0 of 4 reports so far)
Commit
df65e1c· approved by HumanBean (reviewed) · dashboard⚠️ Note: The farm cannot run the requested unit tests or full CI suite through this plan, or directly measure memsync CSV time, 0.1% lows, or omitted CPU reads and writes.
⚠️ Note: The default-enabled hooks are compared with main; the kill-switch-off configuration is not separately measured.
Done (started 00:31 UTC). Comment
@Beanstalkto run it again.linuxwindows+nvidiaamdintelWhat was tested
What will be tested · AI plan (
gpt-6.1-terra)The farm will compare main and the pull request over three starts per side on Linux and Windows NVIDIA, as well as AMD and Intel GPUs. From the Kokiri save it will measure uncapped frame times in Kokiri Forest and the Market for 35 seconds each, with warm-up and stationary picture comparisons. Crashes, substantial frame-time regressions or picture differences beyond the allowed tolerance fail the pull request; the runs also exercise save loading and scene transitions.
kokiri-start(settings vsync=2, resolution=1, frame_rate_cap=6, quality_preset=0, frame_generation=0; switchesHOS_OUTPUT_RES=1280x720,RX_VK_AUTO_TUNE=0), then teleport to Kokiri Forest, take the picture kokiri to compare with main, measure kokiri for 35 s (after 10 s warm-up), teleport to Market, take the picture market to compare with main, measure market for 35 s (after 10 s warm-up); 3 runs on each side.Recommendation: Approve. The code is ready: only testing is left. The reported performance gain is within the run-to-run spread and has no confirmed mechanism in the host pool tracking path. Recommend approval; not approved on the forge.
The change marks two boot-time pools as CPU-inaccessible, with the aim of reducing synchronization work. It adds two game-specific hooks and a default-on kill switch, but the host still registers both pools for the same tracking regardless of their flags.
Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
game/oot_sites.c:781: The claimed FPS and synchronization gain is not separated from run-to-run variation, and the changed flag does not alter pool tracking in the host initialization path. (more on the line) Do: Run longer interleaved comparisons of the actual base and PR at player settings, including a heavy scene, and record the pool-specific synchronization work and RAM/VRAM on affected Tier 1 systems. (@fixdoes its part first: Instrument pool-specific synchronization work so the run can identify whether these flags change it.)game/oot_sites.c:787: The event pool's CPU access semantics change on every supported platform, but the reported run does not cover the event and save-load paths on the other Tier 1 systems. (more on the line) Do: Run event synchronization and save-load smoke tests on the affected Tier 1 Windows and Linux hardware, including Steam Deck.@fixcan do L1.Questions (2) (not confirmed from the code; they don't hold the recommendation)
game/oot_sites.c:775: Can these two pool-creation sites execute concurrently before either callback has initialized the cached switch?Checks: Still running: 10 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven. The reported average FPS ranges overlap: 87.93–92.48 before and 93.35–93.82 after, while the warm comparison is only +1.2%. The 1% low ranges also overlap, and the comparison uses the PR with its switch off rather than a separate base build.
Other systems: Pool initialization and event synchronization run on Windows and Linux and across GPU vendors. Only Windows with an RTX 4060 was reported; Linux, AMD and Steam Deck behavior and event synchronization remain untested. Pool tracking is enabled independently of the changed flags.
Switches: HOS_POOL_FLAGS_SITES is added, default on; 0 restores the original pool flags. Its row is present, but the measurements do not establish that the default benefits all supported systems.
Reviewed:
df65e1c47aagainst28cb22b9ed: Read the diff, commit, repository rules, PR template, standards, hook documentation, changed callbacks and their pool and event handling paths. The large site tables and switch table were skimmed; the complete changed files were not all read in full. docs/review-checklist.md and the adjacent Tooling checkout were absent.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no builds or tests were run. CI is still running. The requested Test Farm run could not be submitted: no Test Farm tool was available and the network is closed.
Overlaps and merge order: Unknown; network access is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -772,0 +778,4 @@/* pool.descFlags (replace mov w1, #0x22 in f_80966440): unmapped descriptor pool becomes CPU_NO_ACCESS (0x21). */int hos_site_pool_desc_flags(Ctx *A64_NOESC c) {c->x[1] = hos_pool_flags_sites_on() ? 0x21ULL : 0x22ULL;L1 (should fix): The claimed FPS and synchronization gain is not separated from run-to-run variation, and the changed flag does not alter pool tracking in the host initialization path.
When: nvnMemoryPoolInitialize calls hos_gpu_track and rx_nvn_pool_created for these pools regardless of their CPU access flags; the reported before and after 1% low ranges overlap. Players therefore have no demonstrated reduction in the tracking work this change is intended to save.
Do: Run longer interleaved comparisons of the actual base and PR at player settings, including a heavy scene, and record the pool-specific synchronization work and RAM/VRAM on affected Tier 1 systems.
@ -772,0 +784,4 @@/* pool.eventFlags (replace mov w1, #0x12 in f_80f69040): 4 KB NVNevent pool becomes CPU_NO_ACCESS (0x11). */int hos_site_pool_event_flags(Ctx *A64_NOESC c) {c->x[1] = hos_pool_flags_sites_on() ? 0x11ULL : 0x12ULL;L2 (should fix): The event pool's CPU access semantics change on every supported platform, but the reported run does not cover the event and save-load paths on the other Tier 1 systems.
When: The new flag makes nvnMemoryPoolMap return null for this pool and changes the flags visible to the game; an event or save-load path using those semantics on Linux, AMD or Steam Deck has not been exercised.
Do: Run event synchronization and save-load smoke tests on the affected Tier 1 Windows and Linux hardware, including Steam Deck.
Follow-up now that this is merged (
19f9da05e, 1 Dec), answering BeanBot's two questions and saying where the testing stands.Farm: the
@beanstalkrun HumanBean started ondf65e1cnever produced a result. The PR was merged about ten minutes later and every job was cancelled (dashboard: 0 of 4 reports). The only measurement is still my own four-run A/B on one PC (i7-9700 / RTX 4060). BeanBot read those numbers correctly: the before and after FPS and 1 % low ranges overlap (average 87.93–92.48 vs 93.35–93.82, warm +1.2 %), so they don't show a gain.Q1: which host path uses these flags to cut sync work? On
main@b4d56f526there is no such path in the renderer's tracking. You're right:nvnMemoryPoolInitializeregisters every pool the same way whatever its flags (host/nvn_native.c:343,hos_gpu_track(o->gpu, o->size, 1), thenrx_nvn_pool_created). Only three places readCPU_NO_ACCESS:nvnMemoryPoolMapreturns 0 for such a pool (host/nvn_native.c:398).nvnMemoryPoolInvalidateMappedRangeandnvnBufferInvalidateMappedRangeskiprx_nvn_invalidatefor it (host/nvn_native.c:414and:562). These skips came with #2899, after this PR was measured.So when I measured this PR, the flag change alone could not reduce write-watch scans, captures or write-backs. The
memsync_csv_mean−6.6 % and the FPS change are run-to-run spread, not an effect of the flags. The tracking and write-back path that would use the flags is #2858 (HOS_POOL_FLAGS/RX_VK_POOL_FLAGS), which is still open. HumanBean's port of that path, measured alone on an RTX 3090 / Linux PC, came out −0.9 %, also within spread (#2886 comment). I should not have reported this PR as a measured speedup, and I'm correcting that here. I'm leavingHOS_POOL_FLAGS_SITESon, as merged. No system has shown it slower, and the flags are correct for these two pools: neither is mapped by the CPU (the descriptor pool has nonvnMemoryPoolMap/nvnBufferMapcaller, and the event pool's mapped site 2 keeps its flags). They are groundwork for #2858, not a speedup by themselves.Q2: can the two sites race on the cached switch? In the C version that merged, yes.
hos_pool_flags_sites_on()used a plainstatic int v = -1with no synchronization, so two pool-creation threads could both read -1 and both writeenv_on_or(...). Both would write the same value, so the outcome could not differ, but it was formally a data race. Since #2822 moved the hooks to Rust, the switch is astd::sync::OnceLock<bool>read withget_or_init(game/crates/game-core/src/engine.rs:358-361), so there is no race now. Nothing to change.Testing before merging (L1, L2): neither has run on any other system. The farm run was cancelled, and I can't test Linux, AMD or Steam Deck here. L2's event and save-load smoke test on other Tier 1 systems still needs the farm or a tester. L1's per-pool sync instrumentation would only show a change once #2858's path is in. Until then there is nothing for these flags to change in the tracking, so I'll measure them as part of #2858 rather than here.
@siantm this PR is closed or unknown to the farm.