Repository navigation
Conversation
In the world the guards of view memory took about 18 ms a frame (run int-c: "guards 18.1-18.4 ms"). Most askings find their whole range clean (1,572 of 2,619 a frame in run int-h-1), and finding that out counted the range's clean blocks one by one in a tree of blocks. - `clean` is a set of bits, 64 blocks to a word: whether all of a range is clean is answered a word at a time (`Blocks::holds`), and the clean blocks of a range are read off the words in order. - `writes` asks whether the range is a view the guards already know once, and hands the answer to `guard`, which looked it up a second time under the lock. - `writes_into` fills a list the caller keeps between askings: building a new list at each asking showed in the submitting thread's profile (run int-b: vectors built from tree iterators 3.9% and 3.1% of its samples, their growth 3.3%). `writes` keeps its form on top of it. - Diagnostics builds count, per frame, the guards' askings, those of ranges known as views, those found all clean, the blocks the others walk, the questions to Windows about memory and the protections asked. What is reported written does not change. In later runs with other changes in between, the guards took 11.3-12.2 ms a frame (runs int-h-1, int-i-1, int-j-1). A test checks the bit set against a tree of blocks over random insertions, removals and ranges.
…VICTORY_INDIRECT_WINDOW_DRAWS, off by default) With VICTORY_INDIRECT_WINDOW=1 the indirect records clamped in one pass stay usable by the next indirect draws (a window) until something may have written the arguments. Every direct draw and mesh dispatch ended the window, so the next indirect draw paid a clamping pass of its own. With VICTORY_INDIRECT_WINDOW_DRAWS=1 only a draw whose shaders can store to buffers (or whose host pipeline is not known) ends it: no other draw writes the argument buffer or the list's scratch buffer. Dispatches, a new host list and everything else that ended a window still do. Off by default. Measured only together with the other switches of this branch (see the pull request); not measured on its own.
The title's recording threads and the submitting thread look up the host copies of title buffers (BUFFERS) and of memory outside buffers (LOOSE) thousands of times a frame, and each lookup took one Mutex: in a 10 s profile of run int-b, `lookup` was 12.4% of a recording thread's samples, a thread that spent 33.8% in contended locks. - Both maps are behind an RwLock. A lookup that finds the copy made (nearly every one) holds the lock shared; making a copy takes it alone and picks again, since another thread may have made the copy in between. Letting idle windows go still takes the lock alone, so no window is handed out while it is being let go. - The refreshes on the submitting thread keep their list of written pages in a thread-local between askings (`watch::writes_into`). No change in what is copied or when. Not measured in the game on its own: the frame-rate table of the pull request covers it together with the other changes.
…FFERS_MIN_KB, off by default) The host copies of title buffers kept in the card's memory had a floor of 1 MiB (VICTORY_CARD_BUFFERS_MIN_MB cannot go lower), so shaders read the smaller title buffers over the bus from the copy in the processor's memory. VICTORY_CARD_BUFFERS_MIN_KB gives the floor in KiB instead (0: every title buffer), still within VICTORY_CARD_BUFFERS_MB. Unset, nothing changes. With 0, run int-m-kb kept 3,540 copies (1,182 MB) in the card's memory where runs int-m-1 and int-m-2 of the same build kept 97 (941 MB), and its frames took 65.6-71.5 ms against 100.6-109.7 ms. The logs do not record the other switches of those runs, so the gain is not shown to come from this switch alone.
…frame (VICTORY_GUARD_HOLES_FRAME, off by default) The title's streamed buffers lie over placeholders with holes, and the guards asked Windows (VirtualQuery) about every uncommitted run they walked, at every asking: 10,258-11,872 questions a frame in the world (runs int-i-1, int-k-2), inside the submitting thread's kernel time. - With VICTORY_GUARD_HOLES_FRAME=1 the end of an uncommitted run is kept until the next frame is presented, or until the runtime maps or unmaps memory. What is given up: a block the title commits with an ordinary commit (no word from the runtime) after the frame's first question about it is copied as zeros until the next frame. - A protection refused for a range is tried again block by block as before, but a block that is not committed now answers for the whole uncommitted run it begins (one question, no protection asked for the rest of it). The blocks noted absent are the same. - `queue::presented()` is in every build, not only diagnostics builds. Run int-k-3 against int-k-2: 6,276-6,600 questions a frame against 11,864-11,872, and the submitting thread's kernel time in its submissions 15.6-16.9 ms a frame against 18.1-25.6 ms; the picture of the first world cell was right.
…ked at every submission `card_dirty` walked every copy kept in the card's memory at every submission (Vec::retain over weak references) to find the few that changed. With the title's small buffers on the card that was 3,540 copies times 29 submissions a frame: 352-370 ms in a 10 s profile of the submitting thread (run int-m-kb). - A card copy has a `queued` mark and goes into CARD_QUEUE with the first range that changes on its CPU side; `card_dirty` empties only that queue, clearing the mark under the copy's `dirty` lock, so a change after that queues it again. - CARDED holds weak references by the copy's address (a weak reference keeps the allocation, so no other copy can have that address while the entry is there). Entries of copies that are gone are swept when they may be half of the map. - The test that builds a `Card` by hand sets the new field. The same ranges are sent to the card, in the same submissions. Run st-o-kv against int-m-kb: `card_dirty` took 19 ms of a 10 s profile and preparing a frame 48.4-49.6 ms against 50.6-52.8 ms; the frame time did not change (70.7-71.5 ms against 65.6-71.5 ms, within the scenes' spread).
…mit (VICTORY_GUARD_HOLES_FRAME=2, off by default) With VICTORY_GUARD_HOLES_FRAME=1 the guards still asked Windows about every uncommitted run once a frame: 12,210-12,219 questions a frame in the world (run st-o-kv), nearly all with the answer of the frame before. - VICTORY_GUARD_HOLES_FRAME=2 keeps a hole, its blocks counted as clean, with no question and no walk, until the runtime tells of a mapping there (`title_memory_remapped`) or of a commit (`title_pages_changed`). The commits told of are the title's `VirtualAlloc` (stood in front of only while this level is on), `XMemVirtualAlloc` with MEM_COMMIT, `XMemAllocDefault`, and the layer's own allocations for the title (`resource::Memory`). They are queued and applied by the next asking, so the title's threads never wait for the guards. - As a safety net a share of the holes is looked at again every frame, each hole once every VICTORY_GUARD_HOLES_RECHECK frames (16 unset; 0 never). A hole found committed or mapped with no word from the runtime is logged with what Windows says of it. - `absent` is a set of bits like `clean`. What is given up: memory committed in a way the runtime does not tell of is copied as zeros until its hole is looked at again (at most 16 frames by default). Run st-q-kv2 against st-o-kv: 443-445 questions a frame against 12,210-12,219, guards 5.0 ms a frame against 12.0-12.1 ms, preparing a frame 40.2-42.4 ms against 48.4-49.6 ms, frames 65.2-67.8 ms against 70.7-71.5 ms. No hole looked at again was found committed (no such line in the log of st-q-kv2 or of its repeat st-q-kv2r).
…y (VICTORY_REFRESH_COMPARE, off by default) The write watch is kept by 64 KiB page and names a page for one byte written, our own writes included: what a landing puts into title memory is in the copy already, yet the next refresh took the whole page again and, for a copy in the card's memory, sent it up to the card. With VICTORY_REFRESH_COMPARE=1 a refresh reads the named pages the copy took before, compares them with the copy and takes, and marks to be sent up, only the 4 KiB steps that differ. Pages the copy never took, and title memory that cannot be read, are taken whole as before. The frame line tells what was read and what differed. A test checks the steps taken against the bytes changed. Run st-t-rc against st-t-k (same build, without the switch): 96.1 MB a frame of written pages read, 11.7 MB of them different; sent up to the card 11.0-11.2 MB a frame in 480-494 ranges against 97.4-97.9 MB in 797-870; frames 69.9-72.2 ms against 72.0-73.6 ms. The refresh takes about as long on the submitting thread as before: it reads and compares where it read and wrote.
…s (VICTORY_WIDE_COMPARE, off by default) With VICTORY_REFRESH_COMPARE=1 the submitting thread reads and compares about 100 MB of written pages a frame, a page at a time: work bound by one core's memory speed, as the snapshots were. - `copy_stale` gathers the runs a refresh has to compare and hands them to `copy_changed` at once. - With VICTORY_WIDE_COMPARE=1 a refresh with 1 MiB or more to compare cuts it into pieces of about 256 KiB, at 64 KiB page boundaries, for the victory-wide threads and itself. Each piece reads, compares and writes only its own bytes of the copy; the change notes (`changed`, `card_changed`) and unreadable stretches stay on the refreshing thread, after the bytes are in. - `wide_apart` does not take other callers' work off the queue while its caller holds the copy's page lock, and a victory-wide thread never spreads work again. Tests check the cutting at page boundaries and the steps taken. Measured with VICTORY_HEAP_SYNC=0 (run st-u-wc-hs0 against st-t-rc-hs0, 10 s profiles): `update_free` 2,226 ms against 2,676 ms on the submitting thread; frames 60.3-61.7 ms against 60.9-63.7 ms, within the noise: there the card is the limit. With heap sync on, frames 68.5-72.3 ms (st-u-wc) against 69.9-72.2 ms (st-t-rc). Hence off by default.
…EW_RECHECK, off by default) With VICTORY_VIEW_GUARD=0 (about 30 ms a frame cheaper in the world) a write through another view of the same pages does not fault at the guarded view, and the copy there keeps the old bytes for good. In the first world room a wall was missing in 7 of 10 runs with VIEW_GUARD=0 and drawn in the 3 runs with it on (96.0-100.8 ms a frame, st-u-vg). With VICTORY_VIEW_RECHECK=N, once a frame, the clean blocks in the words of blocks whose number is the frame modulo N are made due: the next asking reports them written once and their copies read them again (with VICTORY_REFRESH_COMPARE=1 only the bytes that differ are taken). The blocks stay read-only, so no protection is asked of Windows, and the holes are left to `holes_due`. Diagnostics builds count the blocks made due. A test checks a turn's share of the blocks. What is given up: a copy can still be up to N frames behind; this is a bound, not the guarantee VIEW_GUARD=1 gives. Without REFRESH_COMPARE every block made due is taken whole (not measured). Measured in the world with REFRESH_COMPARE and WIDE_COMPARE on: N=64, 421-431 blocks a frame made due, frames 69.4-75.7 ms (st-v-rk64 and st-v-rk64b), the wall drawn in both; N=16, 1,691-1,699 blocks a frame, frames 74.8-81.8 ms (st-v-rk16), wall drawn; without the recheck, 68.5-72.3 ms (st-u-wc). Three runs with the wall drawn are few: that the wall was lost to writes through other views is a hypothesis supported by this count only.
…t time) Hardware-verified on RTX 5070 Laptop GPU (8 GB) in 95s 3D gameplay (0 crashes). Includes upstream PRs (#1677, fxceless#987, fxceless#188, fxceless#610) plus Phase 1-3 changes: - descriptor/host.rs: lock-free AtomicU64 + 64-striped slot_locks/kept in HostHeap::mirror - host.rs & queue.rs: victory-reaper background thread for COM/late-wait drops; Held::Present 2nd MPO plane support for VICTORY_ASYNC_PRESENT=1 - xmem.rs: XMemMapPhysicalPagesScatter single-lock hoisting, no-op skipping, exact 64 KiB placeholder fast path (preserving 64 KiB page independence) - shadow.rs: move D3D12 buffer allocations (shared_buffer, card_for, window_card_for, place_for) outside BUFFERS/LOOSE write locks - draw.rs, host.rs, indirect.rs, list.rs: 2-slot isolated indirect_window_scratch ring synced with draw::State::windows, remove post-clamp global UAV(None) barrier, use targeted uav_barrier_for(src/count) via UAV cleanliness tracking, default VICTORY_TEXTURE_STAGE_MB=48 Measured 1000 Hz profile (baseline -> Phase 3): - usual frame: 183.2 ms -> 102 ms (-45%) - GPU all other lists: 70.3 ms -> 36.4 ms (-48%) - GPU card busy: 47% -> 68% - shadow RwLock wait: 93.46 ms (P1+2) -> 0.00 ms (-100%) - execute_indirect: 167.05 ms (P1+2) -> 78.10 ms (-53%)
|
I tried the 4 KiB changed-chunk compare with 64 KiB-and-larger card buffers on an RX 7900 XT (RADV 26.3.1, Wine 11.22). The integration build also tracked dirty card buffers. It presented 665 frames in 73.74 seconds, 9.02 FPS at 4,847 draws/frame. The comparable small-card-buffer run without those two changes was 8.36 FPS. Lower upload volume was visible in the frame measurements, but the two changes were bundled, so this does not isolate the compare’s FPS effect. I also sampled previously initialized pages about to be refreshed on the RX 7900 XT. Across 9,984 samples from a first-room run, all 646,286,720 bytes were readable. Chunks containing a changed byte covered 31.18% at 4 KiB, 39.27% at 16 KiB and 55.84% at 64 KiB. The samples compare against the CPU staging copy and the renderer still performs its normal refresh. The sampler and build instructions are on my fork. |
…and questions to Windows per frame, and four switches for re-arming (VICTORY_TRACK_REARM=consume, VICTORY_TRACK_VOLATILE=<n>, VICTORY_TRACK_WIDEN=<size>, VICTORY_TRACK_HYGIENE=1; all off)
Stage 2 of the coherence plan (reports/, "LA solution"): the protocol of
the guards on view memory and the bookkeeping around it. Wave 7's logs
place the cost first. Guard faults are 300-700 a frame, while the title
streams too (copystat's "guard faults", the frame log's "faults: P page,
G guard"); the 30,000-225,000 "page faults" a frame beside them are the
process's soft faults of new mappings, not write traps. What the guards
pay for is the re-arming: 7,000-16,000 view blocks walked and guarded
again a frame ("view memory askings ... walked N blocks"), some 470 calls
a frame guarding the other views of a page, 8-30 ms a frame of "guards".
Re-arms were already made where a copy consumes a block: the check
before each copy, protect then copy.
- Diagnostics, one line with each frame-rate line ("write tracking per
frame"): guard faults, on how many distinct blocks, on blocks guarded
with other views and over how many distinct pages, on the submitting
thread; the handler's time and its wait for the guards' lock; re-arms,
on how many distinct blocks, in how many protections and their time;
protections of other views, protections giving write access back, and
their time; runs of blocks whose protection Windows refused; view
blocks made not clean by cause (faults, writes told, another view
written, mappings, first seen); questions to Windows and their time;
the submitting thread's askings, their time and their waits for the
journal's and the guards' locks; open blocks; blocks opened around
faults. Every protection and question of the guards goes through one
of two timed helpers.
- VICTORY_TRACK_REARM=consume: a check's re-arms are made at its end:
its runs cut at the runtime's views (a protection asked across two
views is refused, then retried block by block with a question to
Windows for each block), and the other views of the check's blocks
gathered and guarded in runs instead of one protection each.
- VICTORY_TRACK_VOLATILE=<n>: a block found written at n consecutive
checks that covered it is left open: not guarded again, reported
written at every check (so copied at every consumption, as it was
while it faulted), and guarded again once after 32 checks as a probe.
Never a block with other views, and forgotten when the runtime maps or
unmaps it or another view of its pages appears.
- VICTORY_TRACK_WIDEN=<size> (256K, 1M; a bare number is KiB): while
DirectStorage wrote in the last half second, a fault opens every
guarded block of the aligned window around it.
- VICTORY_TRACK_HYGIENE=1: whether a range is a view is answered from
the runtime's views when one lies in it (no walk of the address space,
which steps through each 64 KiB placeholder of a hole); a protection
refused for a run is retried block by block, and a block found
uncommitted answers for its whole uncommitted run (one question;
from fxceless#987, whose bit set of clean blocks and
answers kept for holes the view set and the parked blocks already
cover here).
Tests, on memory only: re-arms joined over a check guard the other views
again (a write through a view no copy checks is seen at the checked one,
twice); a block written at every check is left open, probed after 32
checks, and tracked as before once a check finds it clean. With the
switches off the guards work as before: the watch tests pass unchanged.
…joined into runs at the check's end (VICTORY_TRACK_REARM=consume), blocks written at every check left open with a probe (VICTORY_TRACK_VOLATILE=n), wider openings while DirectStorage writes (VICTORY_TRACK_WIDEN), view questions from the runtime's view list and refused runs retried (VICTORY_TRACK_HYGIENE=1, from fxceless#987); all off
Draft. This branch itself has not been run in the game yet. Every frame time and count below was measured on our integration branch (this repository's
mainwith several open pull requests and these commits on top), not on this branch. Each number names the run it comes from. The checks that were run on this branch are listed further down.Why
In the world of the title we test with, a large share of each frame went into keeping the host copies of title memory current, on the submitting thread:
card_dirtywalked all 3,540 card copies at each of about 29 submissions a frame (run int-m-kb);What changes
Always on. These change how an answer is found, not the answer:
watch.rs).clean(andabsent) are bit sets, 64 blocks to a word. Whether a range is all clean is answered a word at a time.writeslooks up once whether a range is a view the guards know, andwrites_intofills a list the caller keeps between askings. A test checks the bit set against a tree of blocks. Diagnostics builds log the guards' askings, the questions to Windows and the protections asked, per frame.watch.rs). It is still retried block by block, but a block that is not committed answers for the whole uncommitted run it begins: one question to Windows, and no protection asked for the rest of the run. The blocks noted absent are the same as before.shadow.rs).BUFFERSandLOOSEare behind anRwLock. A lookup that finds the copy (nearly every one) takes the lock shared.shadow.rs).card_dirtynow empties a queue of the copies that changed, instead of walking every copy in the card's memory at every submission. The same ranges are sent, in the same submissions.queue::presented()is in every build, not only diagnostics builds.Behind switches, all off unless set:
VICTORY_INDIRECT_WINDOW_DRAWS=1VICTORY_INDIRECT_WINDOW=1, a draw ends an indirect draw window only if its shaders can store to buffers, or if its host pipeline is not known. Dispatches and new host lists still end the window.VICTORY_CARD_BUFFERS_MIN_KB=<KiB>VICTORY_CARD_BUFFERS_MB.VICTORY_GUARD_HOLES_FRAME=1VICTORY_GUARD_HOLES_FRAME=2VirtualAlloc,XMemVirtualAllocwithMEM_COMMIT,XMemAllocDefault, and the layer's own allocations for the title. As a safety net, each hole is looked at again once everyVICTORY_GUARD_HOLES_RECHECKframes (16 if unset; 0: never). A hole found committed with no word from the runtime is logged.VICTORY_REFRESH_COMPARE=1VICTORY_WIDE_COMPARE=1VICTORY_REFRESH_COMPARE=1, a refresh with 1 MiB or more to compare is split into pieces of about 256 KiB. The snapshot threads and the refreshing thread share them.VICTORY_VIEW_RECHECK=<N>VICTORY_VIEW_GUARD=0. Once a frame, a share of the clean guarded blocks is reported written once, so each block's copies read it again every N frames. WithVICTORY_REFRESH_COMPARE=1only the bytes that differ are taken. No protection is asked of Windows.VICTORY_VIEW_GUARD=1gives.On the integration branch we ran these switches together:
VICTORY_GUARD_HOLES_FRAME=2 VICTORY_REFRESH_COMPARE=1 VICTORY_WIDE_COMPARE=1 VICTORY_CARD_BUFFERS_MIN_KB=0 VICTORY_CARD_BUFFERS_MB=2048 VICTORY_INDIRECT_WINDOW=1 VICTORY_INDIRECT_WINDOW_DRAWS=1. We also setVICTORY_VIEW_GUARD=0 VICTORY_VIEW_RECHECK=64, which trades correctness for time (see the table below).Measured on our integration branch, not on this branch
Machine: Ryzen 7 9800X3D, RTX 5070 Ti 16 GB, 32 GB RAM, Windows 11. Frame times are the readings of the frame-rate line in the first world cell, several per run; the noise from run to run is about 3-4 ms. "Before" and "after" are neighbouring runs of the integration branch, so other changes may lie between them where noted.
VICTORY_GUARD_HOLES_FRAME=1card_dirty352-370 ms in a 10 s profile; preparing a frame 50.6-52.8 mscard_dirty19 ms; preparing 48.4-49.6 ms. Frames 70.7-71.5 ms against 65.6-71.5 ms: no changeVICTORY_GUARD_HOLES_FRAME=2VICTORY_REFRESH_COMPARE=1VICTORY_WIDE_COMPARE=1(withVICTORY_HEAP_SYNC=0)Shadow::update_free2,676 ms in a 10 s profile; frames 60.9-63.7 msVICTORY_VIEW_RECHECK=64(withVICTORY_VIEW_GUARD=0)VICTORY_CARD_BUFFERS_MIN_KB=0The trade-off behind
VICTORY_VIEW_RECHECK: withVICTORY_VIEW_GUARD=1the world ran at 96.0-100.8 ms a frame (st-u-vg), against 68.5-72.3 ms with it off (st-u-wc). With it off, our notes record a wall of the first world room missing in 7 of 10 runs, because a write through another view of the same pages does not reach the guarded copy. The wall was drawn in all three runs withVICTORY_VIEW_RECHECK(st-v-rk64, st-v-rk64b, st-v-rk16). Three runs are few, so that cause is still a hypothesis.With all of this and the other pull requests, the integration branch still runs the title at about 13-17 fps in the world: 68.1-77.1 ms a frame with the default switches (st-z-play), and 57.0-64.9 ms with
VICTORY_HEAP_SYNC=0 VICTORY_MERGE_GAP=64(st-z-hs0-gap).Checks on this branch
All on this branch's tree (Windows 11, the toolchain of
rust-toolchain.toml):cargo build --profile diag -p victory --locked(withoutdiagnostics): builds.cargo build --profile diag -p victory --features diagnostics --locked: builds.cargo test --profile diag -p victory-gpu --locked: 175 passed, 0 failed, 5 ignored, in each of the last two runs. One earlier run of the same tree stopped with an access violation in the test process after 54 tests had passed. Run again one test at a time, that binary had 174 passed and 1 failed (indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields, which passed in both later runs). The access violation did not come back, and its cause was not found.cargo xtask policy: passes.Left out
heap_pass::Picked::planover B-tree maps). It needsheap_pass.rsfrom GPU: heap buffer pass looks only at marked slots; time split and visi… #523, which is still open. On the integration branch it tookPicked::planfrom 1,195 ms to 262 ms in a 10 s profile (st-x-play → st-y-play). It can follow GPU: heap buffer pass looks only at marked slots; time split and visi… #523.VICTORY_RELAY_COPY_QUEUE, which we also ran with. It is not our work, so it is not part of this pull request.VICTORY_FILL_AHEAD). No gain was measured, andmainalready reads ahead by default (fill_ahead;VICTORY_FILL_WAIT=1turns it off).VICTORY_MERGE_RUNS.mainalready has both (IDLE_MOSTis 512 there).main'sviewedset behindVICTORY_VIEW_KNOWN, off by default; our variant behaved likeVICTORY_VIEW_KNOWN=1.Related
cleanset inwatch.rs, to runs of blocks. Whichever goes in first, the other needs a rebase.