WIP: feat(proc): the renderer in a process of its own, phases 2 to 7 (Linux; Windows unverified; off by default) #3176
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3176
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:feat/renderer-split-phases2-7"
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
Phases 2 to 7 of moving the renderer into a process of its own, on top of #3116 (review that first; this PR's diff includes it until it merges). With
LONGSHOT_RENDER_PROCESS=1on Linux the builder starts the renderer as its own sandboxed process, the window and input move into it, and the game's own sandbox loses the GPU, the display, the shader caches and the add-ons. Off by default (a kill switch while the split is finished; the row says so). With it off, players get the in-process hardening and fixes below.renderer-role(Landlock + seccomp profile of its own, no player files, no network), the import self-test before the game starts (fallback in-process before the game, never after), a two-child supervisor, the renderer's crash record and crash window,longshot_render.soin the build, fonts handed to the renderer by the builder (never from the game).scripts/gen_rp_calls.pygenerates both proxies fromgpu/vk/rp_calls.def, every argument checked on arrival; one-way batches, published values, the GPU lookups andnvn_invalidate_quickanswered in the game.Profile::GameSplitnarrows the game's Landlock profile.longshot_render.dll.gpu/vk/record_bounds.h);draw_meshindex wrap (out-of-bounds read), a texture size that looped over 128 M pages, a rectangle check overflow;tests/test_fuzz_checks.py,tests/test_shader_fuzz.py), which found translator bugs fixed here: a local-memory size wrapping an array to length 0, 64 KB of shared memory taking a constant buffer's ArrayStride (invalid without an extension: AMD and Intel allow 64 KB), wrong barrier scope outside compute, missing 1D declarations, zero-vertex mesh programs.Read first:
gpu/proc/rp_role.h,builder/crates/build-core/src/render_proc.rs,gpu/proc/rp_custom.c,host/rp_game.c,gpu/vk/record_bounds.h,docs/dev/reference/sandbox.md.Testing
Tested: Linux (CachyOS, kernel 7.3), RTX 3090, NVIDIA driver 0x9b118180, headless through the queue:
dev.py smokewithLONGSHOT_RENDER_PROCESS=1): the renderer in its own process, play reached from kokiri-start, 1,500 frames, the Insert menu opened, 3 of the game's fonts given to the UI, the renderer ends cleanly with the game;--window): PASS, the window in the renderer's process;c52a7778: the split's smoke run PASS ("the import self-test passed on AMD Radeon RX 580 Series (RADV POLARIS10): dma-bufs (udmabuf)", the renderer in its own process, no fallback, no crash, 3 of the game's menu fonts given), and the in-process smoke run PASS;hos_key_asynccalling itself on Linux,c52a7778) fixed, withtests/test_key_async_posix.py.Game-free: test_rp_marshal (75 checks, ASan, llvm-mingw), test_rp_sides_link, test_rp_input, test_rp_calls, test_rp_transport (172, Wine), test_render_arena, test_stream_bounds, test_record_bounds, test_record_pointers, test_registration_host_copies, test_invalidate_quick, test_rp_font_pack, test_fuzz_checks, test_shader_fuzz, test_core_filter, test_sandbox_linux, test_sandbox_profile, test_switch_table, test_translator_stamp_inputs, test_drawn_page_map, test_doc_anchors; cargo build-core (229), build-compile, synthetic-game render_process (50 runs in a row), crash; check_host_compile Linux. Windows: the role chain end to end under Wine.
Still to test:
LONGSHOT_GAMESCOPE=0,LONGSHOT_RENDER_PROCESS=1) on Wayland and X11: keyboard, mouse capture, the Insert menu, text fields and an input method, the clipboard, F11 / Alt+Enter, pause in background, close and Quit, Restart now, MangoHud and the Steam overlay; expecting all as in-process.Measurements
Verdict: with the split off (the default) no change against main; with it on, the same as in-process in the Market (within the spread), on this PC.
Split on against off, the same runtime (Market, windowed, 1080p uncapped, Render resolution 67 %;
dev.py ab --env LONGSHOT_RENDER_PROCESS=1 --scene market --runs 2), at17054a6a:How it got there (same scene, split on): about 600 round trips a frame at first; then values published in shared memory, one-way bookkeeping,
nvn_invalidate_quickand the slow invalidate answered in the game where the renderer has nothing to do (render thread included), the fence table in place, the game's write marks shared (aligned at build-compile, no re-lift), and the renderer's twin threads spinning while their slot is hot (LONGSHOT_RP_HOT_SPIN: on with 8 or more logical CPUs left to the renderer, off below, where any spin measured worse). About 24 crossings a frame remain (slow invalidates the renderer must act on, submits whose capture is taken at the call, presents, waits not met).Switch off, against main (windowed, Market,
dev.py ab --scene market --runs 2), at17054a6a:a98cf28a17054a6a(
dev.py abwrote no write-up only because the builder's crash-block descriptor number differs between runs, 10 and 11.)Risks
LONGSHOT_RENDER_PROCESSunset. A revert is enough; nothing persists.Checklist
Ready for review
main; the title is a Conventional Commit. (Stacked on #3116.)mise run testpasses (any failure that also fails onmainis named). (Touched checks pass run directly; the whole suite in CI.)main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.gpu/vk/switches.def.tests/that reads changed source is updated, not weakened.MKWVK_API_VERSIONbumped (MkwVkHostorMkwVkRendereringpu/vk/vk_api.hchanged).nn_video.chere for want of FFmpeg headers: CI decides.)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
https://claude.ai/code/session_017vw8e45R4CfYVK3VeGVd2h
gpu/proc/rp_shared.h (the control arena's layout and its hash), gpu/proc/rp_transport.{h,c}: slots, twin threads with nesting, futex/event wake-ups, peer death and clean shutdown, hostile-peer checks (copy, check, use), with a per-op check hook for the checks rp_calls.def will generate. tests/test_rp_transport.py drives tests/rp_transport_test.c: two processes, gcc and clang, ASan fuzzer, llvm-mingw under Wine. Co-Authored-By: Claude Opus 5.5 <[email protected]>scripts/gen_rp_calls.py writes gpu/proc/rp_calls_gen.{h,c} from gpu/vk/rp_calls.def (checked in; tests/test_rp_marshal.py fails when they are not current): the game's proxy MkwVkRenderer and the renderer's proxy MkwVkHost, each member written into the transport and its answer read back; the ops each side serves, whose decoder is also the transport's per-op check (copy, then check, then use; every length bounded); the blobs for the game side's lists (UI frames, world layer models and draws, effects, program hooks, settings rows, texture replacements, renderer actions), packed in one canonical order and rebuilt with every region checked to be the next and every count bounded; RP_CALLS_HASH, so two builds whose calls differ refuse each other. rp_calls.def gets a crossing column (T, S, L, I, R: the plan's 4.1 and 4.2 'First') and its blocking and thread columns corrected. Pointers into the guest window or the render arena pass as their address and are range-checked where they arrive; anything else is copied. Payloads past a slot's 64 KB go in pieces (gpu/proc/rp_marshal.c). The S counters (fence, replayed, the maps generation) live in the control arena's state page; nvn_wait is answered from replayed when it can be. gpu/proc/rp_custom.c writes by hand what no shape says: function pointers as tickets (shot's done, the trial's apply, nested on the caller), texels, page lists, RomFS files, pack pictures, translations by identity, and the R members (GPU address lookups over the render arena, the clocks). The game (host/rp_game.c): reserve_guest and the render arena map the builder's memfds when given; rx_start takes the split's renderer when the control arena is in the environment and the run is headless, else loads longshot_vk here as before. The renderer (gpu/proc/rp_stub.c): rp_render_serve, rp_role.h's contract, loads longshot_vk and runs mkwvk_init with the proxy host when the game asks. Tests: tests/test_rp_marshal.py runs a game and a renderer process over one control arena with the real generated proxies, a fake renderer and a fake host: every generated call and callback round-trips (a conformance suite written from the generator's shapes), nested and from a renderer thread; the hand-written members; the blobs; hostile payloads refused. gcc, clang, ASan and UBSan; the Windows build compiled with llvm-mingw. Co-Authored-By: Claude Opus 5.5 <[email protected]>The waiter drains the channel after the renderer's end, looking for a death notice. During the handshake it raced the handshake for the same channel: it took a refusal the handshake was waiting for, and the handshake then read the channel as closed. a_refusal_a_death_or_silence_before_ready_falls_back failed in about 1 of 20 to 50 runs, on selftest:refuse ("closed its channel before ready") and once on start:crash ("did not answer ready"). Watch.talking is set until the handshake ends; the waiter drains only after it (the handshake handles a death notice itself). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017vw8e45R4CfYVK3VeGVd2hTested in game: Linux (CachyOS, kernel 7.3), RTX 3090, NVIDIA driver 0x9b118180, headless through the queue: with LONGSHOT_RENDER_PROCESS=1 the renderer ran in its own process, smoke run PASS (play from kokiri-start, 1500 frames, Insert menu, game fonts given to the UI, clean end); timed A/B in the Market split vs in-process: 121.8/123.1 vs 127.4/129.6 fps. Switch off: the same runs' in-process sides; change A/B against main running.
Possibly related, for context:
Blocker found by the change A/B against main (Market, windowed, split off): this PR's build hangs at boot in a window (no frame, the control bridge never answers); main runs at 127.9/128.2 fps. Headless in-process and split runs are fine. Being fixed; the PR stays WIP until a windowed run passes.
Fixed in
c52a7778:hos_key_async(Linux) called itself, so the first key read in a window looped forever. Windowed change A/B against main with the split off: 127.3/128.4 (main) vs 128.1/127.7 fps (this PR), no change. The split's smoke run in a window passes.Folded into #3116 (one PR for the whole split), same commits.
Pull request closed