native: the code behind the lit world at about 3.5 fps (draft, reference branch to split) #437
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/437"
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?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Ketan-Kapse on 2026-11-27T18:21:25Z.
Refs #380, #79, #356
What this is
A draft, for reference: all of our native macOS host work as one commit on
a6a58361(166 files, about 31,300 added lines). It replaces the earlier version of this draft (b998bb65base, about 1.8 fps). It is far larger than one change and touches areas other people have claimed, so I do not expect it to be merged as it is. The intent is to make the code readable and testable by others, and to split out whatever is wanted as separate pull requests. Tell me which pieces and I will cut them. Main has moved pasta6a58361since, so expect conflicts.What it shows on screen (counts and descriptions only)
Apple M4 Pro, 24 GB, macOS 27.0.1,
--console series-s. Switches:VICTORY_METAL_RESIDENCY_SETS=1 VICTORY_TEXTURE_DROP_TOP_MIP=1 VICTORY_TRACE_FRAME_TIME=1(a 270 s run, warm caches).What is new since the earlier version of this draft
VICTORY_TEXTURE_DROP_TOP_MIP=1, a GPU copy into the top level of a texture made without it was dropped silently. The title builds skin and clothing textures on the GPU at run time (decoration bakes, then GPU block compression into BC1/BC3/BC7 top levels), so characters showed black heads or stale clothing. Such a texture is now made again with every level (VICTORY_COPY_FULL, default on;=0restores the old behaviour, with a warning per skipped copy). This fixed the faces in our runs.VICTORY_NO_COMM_WAVES).VICTORY_TRACE_GPU_FAILS=names,VICTORY_TRACE_GATE=1,VICTORY_TRACE_STALE, copy traces underVICTORY_TRACE_TARGETS. Notes indocs/outfit-notes.mdanddocs/hang-notes.md.VICTORY_PLACED_SHARE=1(crashed the title once) andVICTORY_BAKE_SOURCES=1(froze the world once).Please check before anything from here is taken
resolution.rsand the step-over code compare short byte patterns at fixed image offsets of one title build before changing them, the waycrash.rsmatches the clwb loops. If that is over the line for the "nothing from the game" rule, say so and I will drop those files.ClearUnorderedAccessViewon buffers). Details and what was ruled out are indocs/hang-notes.md.VICTORY_TEXTURE_DROP_TOP_MIP=1is still needed on 24 GB. Covered-clear (VICTORY_COVERED_CLEAR) still nulls some views the title samples.docs/native-host.md.How it was tested
cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warningson this commit: clean.cargo xtask policyon this commit: 473 files ok. The.dxilfixtures are compiled from the.hlslfiles next to them.emit::wave32_testsdifference noted in the earlier version of this draft.Checklist
resolution.rs)VICTORY_*variable and documentedImported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Ketan-Kapse on 2026-11-27T18:33:37Z.
CI status after
556974a7: the Windowscheckjob now fails on one test only, the one named in the description (emit::wave32_tests::a_branch_on_a_first_lane_read_is_not_uniform_across_the_halves: expects(0, false), this branch's console-flow lowering gives(6, true); 548 other shader tests pass). The first run's failure (native::descriptors::tests::default_texture_srv_replaces_the_texture_in_the_backend_slot) was ours and is fixed:native::safe_readhad no Windows arm, somirrordecoded a zero record there.I have left the shader test as it is on purpose. It pins main's behaviour for a branch on a first-lane read, and the console-flow lowering changes that behaviour, so whether the lowering or the test should give way is your call, not something to settle by editing the test in a reference branch.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T20:59:34Z.
Ran this branch on another Mac: M5 Max, 36 GB, macOS 26.5, Series S. Tree: #437 (head at
b998bb65) plus #358, with only local mute and window switches on top. Same switches as the description:VICTORY_CONSOLE_PIPELINES=0 VICTORY_METAL_RESIDENCY_SETS=1 VICTORY_TEXTURE_DROP_TOP_MIP=1 VICTORY_OUTPUT=1280x720 VICTORY_UPSCALER=6 VICTORY_STEP_OVER=pool VICTORY_PIPELINE_TIMEOUT_S=15.It renders lit here too. On a cold cache (337 s) the prologue cutscene reached the 1280x720 output target, correctly lit. At about frame 1850 it showed the silhouette at the mesh window against the sunlit yard and watchtower. Results: 0 failed command buffers, 0 out-of-memory errors, GPU "In use system memory" peak about 14 GB, back to about 1 GB at exit, 44 refused shader sets (23 of them the divergent cross-lane cascade shaders, as you listed).
A stall on a warm cache, two runs out of two. With the cache warm, presents stopped at frame about 1490 and about 1570 (just after the cutscene starts), at 260% CPU, with no GPU errors and nothing left queued. A thread dump at the stall had the title's main thread in
WaitForSingleObjectand two title threads busy in title code. The cold run, which was slower because of compiles, went straight past that point.VICTORY_TEXTURE_BACK=1(which #449 makes the default), the warm run went past it: the cutscene advanced (yard fence, then the window again) and the run kept presenting to its cap (frame 1920 at 363 s, 0 GPU errors, 274 textures copied back).So on this Mac the title seems to wait on something the GPU writes, and copy-back unblocks it.
Two things for splitting this up:
wave32_tests::a_branch_on_a_first_lane_read_is_not_uniform_across_the_halvesfails on this branch. It passes on main and on #438 alone.VICTORY_LOCKSTEP_WAVES=1, the translator panics during prewarm within 5 s (bitcode.rs:1064 "forward reference outside a phi"and:990 "use of a void value"). My conflict resolution was trivial, keeping both sides, atoptions()and aroundfind_sections(), so it may be mine. But the two don't combine as they stand.The same window shot on the cold run without copy-back was clean, so the speckle comes with copy-back. Next, I'm narrowing which copied-back textures the stall needs and which ones bring the noise, starting with copy-back limited to small textures. I'll post what that finds.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T22:35:08Z.
Two small speed-ups for this branch, with a test. They're in one commit on top of your head: https://github.com/derz92/Native-Victory-macOS/commits/perf/437-mirror (
ec78c8d1). Cherry-pick it if you want them.remirror_tablesmirrors the record it just read. It used to callmirror(handle)for each changed entry, which searches the heaps again and reads the record again throughrecord_at(mach_vm_read_overwrite, one system call each, about 80k a world frame here). It now calls a newmirror_record(heap, index, record, pool_gen, res_gen)with the record from the span read. The generations are captured before the span read, so at worst a stamp is older than the bytes, which means a needless remirror and never a stale entry marked current. New test:an_entry_mirrored_from_a_stale_record_is_rebuilt_at_the_next_check.twin_planechecks the view format beforetexture_info_of. For every 2D view at mip 0, it read the title's resource description (about 25 µs) before finding that a colour view can't show a depth plane. It now returns early unless the format is one the plane match takes (R32F/R32U/R16Unorm/R16U/R8U) or a depth format. The depth-format case keeps the lazyregister_depthexactly as before. On this Mac that lookup alone was about 100 ms of a world frame.Measured on an M5 Max, Series S, warm cache, your switches, median of the last 120 world frames. This is one run per step, so read it as indicative:
The image is unchanged, by screen captures of the same cutscene shots. Checks on this commit:
victory-gpu --lib484 passed (twice), Windows clippy clean, policy ok. On one of three parallel runs,texture_tests::releasing_a_gpu_written_texture_releases_its_placed_aliasfailed and then passed alone 3 of 3 times, so it looks flaky rather than caused by this.Also a correction from me: copy-back turned out to have nothing to do with the warm-cache stall I mentioned above. Details on #456.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T22:51:12Z.
On the missing hair, a lead:
VICTORY_MESH_OVER_LIMIT=1brings it back on this Mac.Your branch refuses four mesh programs on the 32 KiB output guard here (declared outputs of 33,792, 36,864 and 38,400 bytes). With the guard bypassed, on the same binary and switches, all four compiled through the converter and Metal on macOS 26.5 with no error, and the 300 s run had 0 failed command buffers. Two visible differences:
So the outputs fit on this Mac despite the declared size. Maybe the declared size overstates what Metal needs, or Apple's limit is higher on M5. Do you know where the 32,768 comes from? If it's Metal's documented mesh payload limit, it might be worth checking the actual pipeline creation result instead of the declared size, and refusing only if that fails.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Ketan-Kapse on 2026-11-27T22:55:23Z.
@derz92 thank you, all three comments were useful. Answers and what has changed here since.
#438 with this branch: same result here, so it is not your merge. I merged #438 the same way (both sides kept at
options()and aroundfind_sections()) and ran the translator over the 38 kept containers that this branch refuses for "a cross-lane operation between host waves in divergent code", withVICTORY_LOCKSTEP_WAVES=1: 3 translate, 19 are refused (11 "an s_barrier the console waves of a lockstep group may reach unevenly", 8 "an exchange between host waves in an earlier block"), 16 panic (12 "use of a void value", 4 "forward reference outside a phi"). The panics also happen withVICTORY_NO_CONSOLE_FLOW=1.Your speed commit. The second half (the view-format check before
texture_info_ofintwin_plane) is ported by hand on my side and passesvictory-gpu --libon Metal; your commit no longer applies as it is because that part ofhost.rshas been reworked since. The first half is covered by that rework: the table scan now reads the records once and mirrors from what it read. I will measure thetwin_planepart in a game run and report.The 32 KiB mesh guard. Good find. The number is the guard this branch took over; I do not have a source for it that I trust, and I had not tested what Metal really accepts. I am testing that now on an M4 Pro (synthetic mesh pipelines at several declared sizes: does creation fail, does it render correctly), and separately trimming the outputs a paired pixel shader never reads. The aim is zero mesh programs refused for size. One reason for care: an older build on the Wine route that built such pipelines anyway hung the GPU queue here. Your result also changes how I read our screenshots: the spikes on the character's head are probably skipped hair and head meshes, not a skinning fault as I had guessed.
Since the description above (same Mac, same scene, 8-minute runs):
b998bb65the dormitory interior is black except for sun patches (before the merge it was dim but visible), and some wall meshes are not drawn. Being bisected now.VICTORY_COVERED_CLEARstill frees nothing.None of this is pushed to this branch yet. I will update the draft once the interior lighting and the mesh guard are sorted, and then split out whatever is wanted.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T23:06:22Z.
Thanks, that all helps. A request: could you push the three mirroring passes (the decode cache by record content, the clean marks, and dense per-entry state) as soon as they pass your tests, even before the interior lighting and the mesh guard are sorted, perhaps on a separate branch? They don't touch lighting. I can then A/B them here on the M5 Max (one binary, settled-world medians, three runs each way) and report numbers alongside your M4 Pro ones. On this Mac the frame is about 360 to 400 ms with
hold_submitabout 190 ms, so mirroring is still the biggest CPU item here too.One more data point for your lock work: in our counters, about 70% of the title's device descriptor writes (14k to 24k of 19k to 30k a frame) land in heaps that aren't shader-visible, and each takes the title lock through
glue::mirror. Skipping the lock for them can't simply droprealize, though: the first attempt here pushed texture creation into submission. I'm measuring a version that keeps that part.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-28T01:03:00Z.
@Ketan-Kapse this PR has become the base for my own testing, thank you. I put fixes on top of it and pushed the result as the branch
lit-world/base-3(#518, the cross-page loads, texture fixes, the page table for described pipelines, the image null-view test), so you can see what I am running.One ask: you wrote that your local tree translates 31 of 38 cross-lane programs by if-conversion. Could you push that work, even unfinished, as a draft PR or a branch? On this base the prologue interior is still black for me, and the trace says the light is lost at cross-lane computes (#526, #527). Your if-conversion is the fix I would otherwise have to write from scratch, and I would rather build on yours and credit you.
Also, if you still have the switches and the commit where the dormitory was lit before you merged
b998bb65, please post them. I could not find a lit interior on any pushed tree.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-28T01:35:10Z.
A correction to my mesh-guard comment: please disregard it. In that run the oversized programs were still refused by the second check (
mesh_refused_over_limit=10753). I'd searched for the wrong message and concluded they had compiled. So the hair and yard differences weren't from them, and your skinning guess may stand. A later run onlit-world/base-3with every check bypassed shows Metal refusing them itself at pipeline creation ("Total mesh size (36864) exceeds the maximum mesh size allowed (32768)"), so the 32 KiB limit is real on macOS 26.5 / M5 Max, and your output-trimming approach is the way. Details on #528. Sorry for the noise.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-28T02:14:43Z.
@LakshanSivakumar, since
lit-world/base-3is your test base: here are four speed changes on top of it, about +48% world frame rate here. They're on a branch: https://github.com/derz92/Native-Victory-macOS/commits/perf/base-3 (5 commits on9a0d811d).A/B on one Mac, same switches, settled world (median of the last 120 s, frames with more than 500 draws; M5 Max, Series S,
VICTORY_METAL_RESIDENCY_SETS=1, #437's switches):(One plain run froze at the #456 point, so there are two plain runs.)
What's in it, with what each one moves:
twin_planechecks the view format beforetexture_info_of(Ketan already ported this). A colour view can't show a depth plane, and reading the title's resource description cost about 25 µs × 4,000 image mirrors a frame. Depth-format views still register lazily. Movesmirror.VICTORY_PROBE_PER_FRAME=1(opt-in): the hot and blank texture probes share one budget per presented frame instead of one per submission (about 17 a frame). Trade-off: a texture write can be noticed up to a frame later. Moveshold_sync.native/content_hash.rs, non-cryptographic, independent of how the input is split, tested). Shader and placement keys stay BLAKE3. One catch: with hashing ~10× cheaper, the uncapped scanner covers far more memory and finds more of the title's CPU texture writes, so texture sync read 560–700 MiB/s instead of 200–290 and uploaded more, and on its own it was slower. It pays only together withVICTORY_TEXTURE_SCAN_MBPS(300 in these runs). That's your existing switch, with its documented stale-texture trade-off.VICTORY_CONCURRENT_COMPUTE=1(opt-in, experiment): a concurrent compute encoder with a memory barrier wherever the pipeline changes and around indirect dispatches. WithVICTORY_PASS_TIMING(#484), the costliest world passes were chains of hundreds of tiny dispatches of one pipeline (972 in one pass, about 22 µs each), serialised by the default encoder. GPU time per frame went from 77 to 59 ms in a single-run comparison, with no visible glitches or GPU errors over about 10 runs. It's a guess: back-to-back dispatches of one pipeline are taken not to depend on each other, and the title's barriers aren't followed yet. It needs a better rule before it could be a default.All on by default in the A/B run except where marked opt-in. Checks on the branch:
victory-gpu --lib507 passed, Windows clippy clean, policy ok. Take any part that's useful; I can split them into separate PRs against whichever base you prefer.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-28T05:20:36Z.
Two more on
perf/base-3(same link as above), each A/B'd on one Mac with everything else identical. Settled-world medians, M5 Max, Series S:remirror_tablesmirrors the record its span read gave (mirror_record): norecord_atsystem call or heap search per changed entry. Ketan said his rework covers this, butlit-world/base-3didn't have it. 413 / 415 / 420 ms vs 452 / 453 ms (−8.5%). It comes withan_entry_mirrored_from_a_stale_record_is_rebuilt_at_the_next_check.PoolTable::signaturecaches each range's value until the table's generation changes. On base-3,mirror_record's buffer path callsalias_signatureper mirror, which walks every mapping the view spans and SipHashes them. Step timers put that at about 51 ms of a 130 ms mirror budget. The same large views come up thousands of times between two table changes. 388 / 391 ms vs 407 / 414 / 415 ms (−5.5%), withmirror88 vs 106–110 ms. Test:memory::tests::a_signature_follows_every_change_of_the_table(a remap or unmap never gets the cached value).With all six on this branch, base-3 here goes from about 722 ms (1.39 fps) to about 390 ms (2.55 fps). Checks:
victory-gpu --lib509 passed, Windows clippy clean, policy ok.Also, two experiments that didn't help here, so nobody repeats them: taking the per-entry heap maps off SipHash (an integer hasher on
mirrored,pending_mirrorandspanned), and a memo that skips a bound table whose bytes are unchanged (95% of checks hit it, but the time is in the changed ring entries). Neither moved the frame time.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-28T08:35:04Z.
@Ketan-Kapse, your new head (
7badeaa7) on an M5 Max, macOS 26.5, Series S, with your switches (VICTORY_METAL_RESIDENCY_SETS=1 VICTORY_TEXTURE_DROP_TOP_MIP=1), warm cache: settled world median 297–334 ms (about 3.0 fps), 0 GPU errors, a clean picture. Very nice jump from the previous head.Five of my earlier changes still add on top of it. They're on a branch on your head: https://github.com/derz92/Native-Victory-macOS/commits/perf/ketan-35 (8 commits). A/B on one Mac, alternating, 300 s world caps:
7badeaa7as isVICTORY_PROBE_PER_FRAME=1 VICTORY_CONCURRENT_COMPUTE=1 VICTORY_TEXTURE_SCAN_MBPS=300)Most of the gain is GPU time per frame, 106–123 → 73–75 ms, from the concurrent compute encoder (barriers only at pipeline changes and around indirect dispatches; still a guess about dependencies, see the docs line). The rest comes from the content hash plus scan cap (texture-sync hashing was BLAKE3 under Rosetta, 2 GB/s against 19 GB/s), per-frame probe budgets, and caching
PoolTable::signatureandresolveper table generation (with tests that a change never returns a cached value).Checks on the branch:
victory-gpu --lib578 passed, Windows clippy clean,xtask policyok. I left #565 (VICTORY_LOOKUP_EXIT) out of the branch because its docs pushnative-host.mdover the policy size limit. It does rescue the #456 freeze on your head too, in my runs. Take whatever is useful.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.