gpu(native): make list upload memory title memory the GPU reaches #100
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/100"
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 Olima34 on 2026-11-26T14:42:34Z.
What this changes
Refs #15 (the
Box32Rehydrationdispatch whoset0was the malloc address0x60000022eb80).On macOS a command list's upload block (list method 0x4a0,
allocate_upload, where the BVH builder writes its instance descriptions) wasvec![0; len]: heap memory above 2^40 that the native host's pool table did not know. NeitherNativeHost::resolve(root views: "title address … is not in a mapped pool") nor the shaders' page table, built from the same mappings, could reach it, so the BVH builder's shaders read zeros there. On Windows the same block isVirtualAlloc2'd in [4 GiB, 2^40) and registered withshadow.victory_platform::mem::reserve_in, in whole 16 KiB pages (what a Metal buffer over it needs, as the title's pools have), so it comes zeroed.glue::pools()(pool_created, thenmappedat its own address), sopool_bufferwraps it like any title pool and the page table shows it. Its pool id has bit 63 set;xmem_physicalnumbers the title's pools from 1 up, so the two never meet.Title::retire: one fence of ours per queue, signalled behind held work), thenunmapped,pool_releasedand unmapped from the address space, as the title's pools are. If a fence cannot be queued, the memory is kept for good rather than freed under the GPU.refreshdrops what is retired and done.This addresses the
t0half of what the issue describes. Whether the[49, 1, 1]overrun goes away once the shader reads real instance data still needs a game run.How it was tested
victory-gpuon arm64 with the Metal Shader Converter (164 tests):upload_blocks_are_pools_of_their_own(addresses in [4 GiB, 2^40), 16 KiB aligned, zeroed, resolved by the pool table as the same bytes, ids apart from the title's, gone from the table and intake_releasedafter drop),retired_memory_outlives_the_work_queued_before_it(on Metal: what is retired is dropped only once the GPU is past the work queued before it), and the existingallocate_uploadtest now also checks that the block resolves as the same bytes and is gone once retired. The new checks fail onmain.cargo test --workspace,cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victorycargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings, also with--all-features(the Windows path compiles unchanged)cargo xtask policyChecklist
VICTORY_*variable and documented (none added)Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T15:04:39Z.
Thanks for this, the t0 side of #100 is right and a real step. We ran it, and on its own it doesn't yet get the story load past the prologue. Details below.
Setup: Apple M5 Pro, macOS 27.2.1,
--console series-s, story-mode load,mainataf380ca+ #100.What we saw
0x7f8000007f800000) no longer appeared at ~80 s. Instead the title hung there, and at ~112 s its own 30 s hang watchdog crashed it (first-chance write at image+0x23cf683, then unhandled at image+0x55e56f8). That run still logged 229 "title address ... is not in a mapped pool" warnings.NativeHost::memory_tablecallsPoolTable::mappings()on every compute dispatch that uses the page table (thousands per frame). That clones the whole mapping map under the device lock before checking whether the cached table is current. Asampleshowed 52 of 54 pump-thread samples inmemory_args -> PoolTable::mappings, with title threads parked on that lock (one inglue::mirrorviacreate_placed_uav). We have a local fix (PoolTable::mappings_if_changed(generation), with a test) and will send it as its own PR. Worth checking whether per-upload pools make other per-dispatch paths slower too.DispatchX/Dispatchstore group counts unscaled, and the host passes them todispatchThreadgroupswith numthreads from the DXIL. So the over-wide writes (previously measured at 49x8192 bytes past the end of the BVH destination buffer) most likely come from the title's own inputs, for example a count in Constants[0] (0x4a80 in an earlier trace), or data that a refused shader or a GPU-written buffer never copied back to title memory (see #46).Questions for the author
retire()covers only queues that exist at call time. Could it free an upload block that a later-created queue still reads?refs()==1test inlist_releaseagainst a concurrent AddRef.Thanks again, this is useful groundwork, and we'll link the
memory_tablePR here once it's up.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-26T15:28:42Z.
Thanks for running it. I've pushed three commits for your points; the branch is rebased on
main.Q4,
refs()==1inlist_release. You were right that it was unsafe, through two concurrentReleases rather than anAddRef. A concurrentAddRefon the last reference is already the caller's bug under COM rules. But two releases of a list holding two references could both read 2, so neither retired the blocks, and the lastrelease_boxedfreed them at once, under queued work. The retire now happens inside the release whose atomic decrement reaches 0:object::release_boxed_before, afetch_updatethat runs the callback only on 1 → 0.glue::lockedhands that callback the already locked host, so nothing locks twice. The new testa_list_released_from_two_threads_retires_its_upload_memoryreleases from two threads through a barrier while a queue is held behind a fence. It failed 27 times out of 30 with the old check, and 0 out of 30 now.Q3,
retire()and queues made later. A queue created afterretirecannot read the block: the block is only read by work recorded before the reset or release that retired it, that work only reaches the GPU throughExecuteCommandListson a queue that already exists (or sits inheld, whichholds_workcovers), the native host has no bundles, andExecuteIndirectisn't executed. A test now pins that rule. Checking it turned up a real gap, though: a queue the title releases.forget_queuedropped it from the table while command buffers it had already sent could still read the block. It now leaves a mark on that queue's fence, andretirewaits for any marks not yet passed.Per-dispatch cost. As you suspected, one pool per block changed the pool table at every
allocate_uploadand every free, so even withmappings_if_changedthe page table would have been rebuilt every frame. Blocks are now carved from an arena (native/arena.rs):retire.A test runs 100 allocate/free cycles after warm-up and checks that the pool count and the table generation stay the same.
Q1, the instance data behind
t0. I can't run the game, so I can't say it is correct. What the change does guarantee, and what a test checks, is that the GPU now reads the very bytes the title wrote through the pointerallocate_uploadreturned: the pool table resolves that address to the same host address. Before, the GPU could not read it at all. Whether those bytes are non-zero depends on the title having written them before the dispatch runs. A dump of[t0, t0 + 64)at theBox32Rehydrationdispatch on your side would settle it.Q2,
Constants[0]and the destination. From the numbers in your trace:u1 + Constants[0]=0x831be0100 + 0x4a80=0x831be4b80, exactly where you measured the writes start. SoConstants[0]looks like a byte offset into the destination.u1sits0x100past a 128 KiB boundary (0x831be0000), and the buffer ends at0x831c00000, 128 KiB later. The destination looks like a 128 KiB block with a 256-byte header.0x1b480bytes, which is 13.6 groups' worth.So the group count, or the 8 KiB per group, doesn't come from the size of this block. That fits your point that the over-wide writes come from the title's own inputs. If the dispatch's group count is computed from data the GPU produced (a count written by an earlier pass), #46 (GPU writes not copied back to title memory) would be my first suspect.
Related: I sent #102 for the 229 warnings. Each comes from a whole
ExecuteCommandListspiece being refused for one command at unmapped memory, which also drops the piece's valid dispatches, copies and value writes. It drops that command alone, the way #57 does.Tests:
victory-gpuon arm64 with Metal, 4 passes, 174/174 each; arm64cargo test --workspace(692); the x86_64 suites; both Windows clippy runs. None of it has been checked in the game.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T15:55:44Z.
Review: COMMENTED
Holding this one. The t0 side is right, but together with #102 and #105 it still does not get the story load past the prologue (crash ~100 s in, preceded by a hang on a job semaphore). GPU compute writes are ruled out; the current lead is physical pages owned twice in xmem_posix. Changing which memory the GPU reaches before that is understood risks hiding or moving the fault, so it will not be merged until then. No further work needed on this PR for now.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-30T09:17:24Z.
Closing: the same change landed in BareMetalVI (e96b28ac "a command list's upload memory is graphics memory the GPU reaches", then 4a7532f7 and 68afe2a1). The project lives at BareMetalVI/BareMetalVI now.
Pull request closed