perf(lift): lifted stores mark only GPU pages, by a page bitmap (RX_MARK_BITMAP) #1617
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
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1617
Loading…
Reference in a new issue
No description provided.
Delete branch "dyst/Longshot:perf/mark-bitmap"
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: Windows 11, RTX 3080, Ryzen 9 3900X · Needs: a check that the picture is unchanged; Linux, AMD, Intel and Steam Deck runs; this branch measured on its own
This is ballotstomper's work (their commit 72db7c7d on their fork's
perf/rdna2), brought onto main so the measurements below have a place to live. It is opened as WIP to be discussed, not merged as it is; ballotstomper, take it over, fold it into your own PR, or say how you'd like it done.TL;DR
Each store the translated game makes also wrote a mark for its memory page, so that the renderer could find what the game changed. The renderer only reads the marks of pages the GPU uses, and most of the game's stores are to other memory. This skips the mark unless the store is on a page the GPU has mapped, tested with a small bitmap. On a CPU-limited PC it raised the Market's frame rate by about 11% on its own, and by 17-22% together with building all the translated code at
-O2. It is on by default (RX_MARK_BITMAP=0when building turns it off), and the limitations below are real: read them before trusting the numbers.Breakdown
host/mark_bitmap.c(new): a bit for each page the GPU can read. A page's bit is set when a GPU mapping covering it is made, and for the page before it too. Bits are never cleared.host/nvdrv.c:map_addsets the bits before the mapping counts.nx2/rtgen.py: in anA64_MARK_BITMAPbuild,A64_MARKmarks only when the store's first byte is on such a page.nx2/build.py: the translated code is compiled with that define unlessRX_MARK_BITMAP=0. The host's own writes keep marking every page.RX_MARK_BITMAP=0: the translated C and the runtime header are as before, every lifted store marks its page.rtgen.pypass with it off.Why
The wiki's CPU rework plan (track D, the write marks rule; question 1) asks what the marks cost the frame. ballotstomper measured it on Linux: a build without the lifted code's marks ran the game's threads 2.2-2.7 ms a frame faster while moving. With this bitmap the Market walk went from 40.4 to 46.1 fps on a Ryzen 5 5600X and RX 6750 XT. With every page's bit set again (
HOS_MARK_BITMAP_ALL=1), it walked at 41.3, so the bitmap is nearly all of that gain. The numbers below check it on another OS, GPU vendor and CPU.#1558 (HumanBean) does the same thing another way, filtering the marks by the GPU's backing ranges, on Linux. dukenheimer measured no frame-rate gain from it on a Steam Deck. The two should become one.
What changed
host/mark_bitmap.c(new):a64_gpu_pages, 16 MB of zeroed static data for the 512 GB guest window, of which only the heap's part is ever touched (~210 KB).hos_gpu_pages_set(guest, size)sets the bits.HOS_MARK_BITMAP_ALL=1sets every bit at the start.host/nvdrv.c:map_addcallshos_gpu_pages_setwhen the mapping's GPU address is the guest address.nx2/rtgen.py:A64_GPU_PAGE(a)and the bitmap form ofA64_MARK, under#if defined(A64_MARK_BITMAP).nx2/build.py:MARK_BITMAP, added to the translated code's flags unlessRX_MARK_BITMAP=0(or off, false, no). Adapted from ballotstomper's hunk, which joined aRX_NO_GUEST_MARKSswitch main doesn't have.gpu/vk/switches.def:HOS_MARK_BITMAP_ALL's row.Measurements
Verdict: faster where the CPU limits the frame: +11% in the Market from the bitmap, +17-22% with all translated code at
-O2; +5-7% in Hyrule Field. But the measured builds were not this branch alone (see "What was measured").What was measured
RX_VK_FRAME_TRACE=1) gives the median frame time by area.310e7c9d, throughscripts/dev_build.py pack. main is the base alone. The other sides also carry:A64_MARK_BITMAPalways defined. The same code as here, with the switch on.LONGSHOT_CHUNK_OPT=all LONGSHOT_CHUNK_LEVEL=O2, an existing build option, not part of this PR. On this PC the pack took 51 minutes against 18 at-O1.Results
Median frame rate by area, from the frame trace's median frame time:
-O2-O2-O3-O2is about +9%. Series 3 stopped after its first round when the disk filled, so it is one pair.-O2; frames over 50 ms 139, 54 and 59. Hyrule Field's p99 is about the same on every side (48.6-51.1 ms).-O3against-O2(one round, -2.5%); 8 virtual cores against 6 (HOS_CORES=8, the warm-up only, slightly slower).Flags and settings
On by default at build time;
RX_MARK_BITMAP=0turns it off.HOS_MARK_BITMAP_ALL=1at run time: every page's bit set, the A/B's control.Testing
Tested:
-O1,-O2and-O3). Each played to its end: no crash or hang, and every game patch applied.RX_MARK_BITMAP=0),tests/test_mark_groups.py,test_exclusive_marks.py,test_fpx_sticky.py,test_fastfp_override.py,test_split_giants.pyandtest_switches_removed.pypass.test_switch_table.py's failures are main's own; this row isn't among them.test_libc_hooks.pyfails here and on main alike.Not tested:
A64_MARK_BITMAPyet.tests/run_all.pyin full.Must be tested:
RX_VK_DUMP_FILE): the Market, Kokiri Forest, a cutscene, a menu, a load.Risks
What could break:
map_addsets bits only for mappings whose GPU address is the guest address (va == guest). The game's stores to a page the GPU reads through any other mapping, or reads without a mappingmap_addsees, would no longer be marked, and the renderer would draw that memory stale.Turning it off: build with
RX_MARK_BITMAP=0;HOS_MARK_BITMAP_ALL=1in a build with it.Compatibility: nothing changes for a player's files.
Checklist
Everyone
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why. In builds with this change and others; the picture not compared.
in Risks. The picture is unchecked.
main. On310e7c9d, where it was measured.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named). The checks above only.third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.RX_,HOS_orLONGSHOT_switch has its row ingpu/vk/switches.def.🤖 Generated with Claude Code
Tested in game: Windows 11, RTX 3080 (NVIDIA driver), Ryzen 9 3900X: 14 runs of PR #801's route (a Hyrule Field walk and look round, then the Market) in packs over
310e7c9dthat carry this change with A64_MARK_BITMAP on, together with #1560, #1469's local registers + #1587, and a zstd change of mine; all played to the end with no crash or hang. Not yet: this branch built and run alone, and the picture compared with main's (no screenshots were taken).@Beanstalk
@HumanBean approval of
410b074recorded. This diff touches sensitive paths, so a second member ofBigBeansmust approve it too.Beanstalk test farm
Commit
ce2dd9e· tier untrusted · approved by nobody yet · dashboardThis diff touches sensitive paths, so it needs two members of
BigBeans:nx2/build.py,nx2/rtgen.pyA member of
BigBeanscan review this commit and comment@Beanstalkto test it.A data point from a second PC, since the description says the two were not yet measured together: this change stacks with #1576 (registers as locals, vector rewrites).
Windows 11, Ryzen 9 9900X, RTX 4070 SUPER, 4K DLSS Quality, 90 cap, the Castle Town market on a recorded route, ballotstomper's commit 72db7c7d picked onto #1576's code (not this branch's head),
RX_MARK_BITMAP=1. Median game work a frame, one run each, the same five runtime switches on every side:430eef4f-O1-O2So about 1.5 ms from the bitmap on top of #1576 here. At 4K this PC is GPU-limited near 70 fps with it, so the fps hardly moves between the last two rows. No picture difference seen by eye in several hours of play on the
-O2build; not compared by screenshots.Measured and written with the help of an AI coding agent.
afb21bbf: the page bitmap is now on by default (nx2/build.py: the translated code gets -DA64_MARK_BITMAP unless RX_MARK_BITMAP=0, off, false or no); HOS_MARK_BITMAP_ALL's row says so. The description's default lines are updated. Still owed before this can leave WIP: the picture check (same frames with and without it), and the Linux, Steam Deck, AMD and Intel runs. ballotstomper, the default flip is the only change to your code.Rebased onto main
c507b98c(30 commits on), cleanly:96e50eb5,566c43a5,ce2dd9e8. test_mark_groups, test_exclusive_marks, test_fastfp_override, test_split_giants and test_switches_removed pass; test_fpx_sticky and test_switch_table fail on this PC as they do on mainc507b98c(no C++ headers for that check's compiler here; the switch table's rows main lacks), neither about this change.afb21bbfedce2dd9e8a3WIP: perf(lift): lifted stores mark only GPU pages, by a page bitmap (RX_MARK_BITMAP)to perf(lift): lifted stores mark only GPU pages, by a page bitmap (RX_MARK_BITMAP)