Repository navigation
GPU: reuse own-byte copy buffers (VICTORY_EXACT_REUSE), log card-cap turn-downs, split bind time - #1390
Closed
Alpacher wants to merge 3 commits into
Closed
GPU: reuse own-byte copy buffers (VICTORY_EXACT_REUSE), log card-cap turn-downs, split bind time#1390Alpacher wants to merge 3 commits into
Alpacher wants to merge 3 commits into
Conversation
added 3 commits
November 26, 2026 23:21
shadow::exact() made a new committed buffer for every new (address, len) a title view at a ring position asks for (300-675 a frame on an RTX 5070), under the lock every list-recording thread takes. Now the buffers of copies let go of are pooled by width (256 MB at most) and handed to a new copy only once nothing but the copy held them, STARTED + VICTORY_EXACT_REUSE_LAG (64) submissions have finished and VICTORY_EXACT_REUSE_FRAMES (3) frames have passed; zeroed, with a new Shadow. Creation and the idle sweep (every 32 new copies, cheap tests first) run outside the lock. VICTORY_EXACT_REUSE=0: as before.
…Y_CARD_BUFFERS_MB The cap check in card_room_for refused silently: once 512 MB of copies were made (the default under a 12 GiB budget), later big buffers stayed in the PC's memory and were compared on the CPU (162 MB a frame on an RTX 5070) with nothing in the log.
State::bind's whole time and its parts (early texture pass, descriptor tables, title memory by address, the rest) per frame. VICTORY_BIND_SPLIT=0: not timed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
From:
Alpacher/victory-fork:pr/fxceless-v9-perfInto:
fxceless/victory-fork:mainBase:
52ac4ec("GPU: dynamic descriptor slots go back only to the heap that took them (#1324)")Commits (oldest first):
06b1fa4515e421a522721Diff vs
origin/main: 3 files changed, 376 insertions(+), 22 deletions(-)This PR adds no new crates, no
Cargo.toml/Cargo.lockchanges and no scripts, and it doesn't touchvictory-shader. Every behaviour change sits behind an env var that has an=0fallback to the exact old path.TL;DR
shadow::exact()used to create a brand-new committed buffer for every view whose bytes needed their own copy. GTA VI's rings move every frame, so that meant hundreds of buffers a frame, created under the lock every list-recording thread takes.VICTORY_CARD_BUFFERS_MBcap, big title buffers silently stayed in system memory and were compared on the CPU: 161.9 MB a frame on the 5070.State::bind(whole, early textures, descriptor tables, title memory by address, rest). This is what pinned the hot spot fixed in item 1.Separately, for reviewers: the face "spike" corruption seen downstream was caused by
PORT_CONSTANTS(in-place graphics region), not by exact reuse. See the section on it below.Test rig and method
game_scarlett_master.exe), Series X modetracing::info!output ofvictory.exe, read from full run logs. Where a line says "since the start", the number is cumulative.1. Exact-copy buffer reuse:
VICTORY_EXACT_REUSEFiles:
crates/victory-gpu/src/shadow.rs(exact copies, pool, tests) andcrates/victory-gpu/src/host.rs(two counters exposed)Problem
Some title views (SRV/UAV/CBV over raw title memory) start at a byte offset that doesn't fall on their copy's element boundaries.
shadow::exact()gives each such view its own byte-exact copy, keyed by(address, len). GTA VI suballocates constants and per-draw data from rings, so the view addresses change every frame.What we measured:
CreateCommittedResource, made while holding theexactmap lock that every list-recording thread contends on.references(), an AddRef/Release round-trip on the COM object) ran first.Mechanism
Pool (
Spares<T>,SPARES)len.next_multiple_of(256), sincemain'sShadowhas nowidth()).host::retire(), so they get the normal deferred-release path.Reuse gate (
spare_gate)A spare is stamped
(started + lag, frame + frames)when it is given back. Herestartedishost::submissions_started()at that moment andframeisframe::current().take()hands it out only when both of these hold:host::submissions_finished() >= started + VICTORY_EXACT_REUSE_LAG(default 64). Every submission that could have named the buffer, plus 64 more, has completed on the GPU.frame::current() >= frame + VICTORY_EXACT_REUSE_FRAMES(default 3).When a copy is let go
A copy goes back to the pool only after the sweep finds it idle. The tests run cheapest first:
Arc::strong_count == 1: only the map holds it.LATELYframes.references(): the COM refcount shows that no descriptor slot or list view (Kept) still holds it.On reuse
write_bytes) and gets a newShadow. Nothing from its last life carries over: no contents, no tracking state.Lock scope
SWEEP_EVERY = 32new copies, not on every miss.exactlock. If two threads race to create the same key, the loser gives its buffer to the pool with gate(0, 0). Nobody ever saw that buffer, so it is reusable at once.Stats
EXACT_STATSgrows to 3 counters: copies asked for, copies made with a new buffer, and copies given a spare.exact_lineframe line now shows reused counts and the pool size. Its existing text, including "VICTORY_VIEW_OWN_COPY=0", is kept.host.rsadditions (read-only Acquire loads of counters that already exist)pub(crate) fn submissions_started() -> u64pub(crate) fn submissions_finished() -> u64Why it is safe
STARTEDvalue seen at give-back, plus a 64-submission margin. That covers lists recorded but not yet sent. It is the same margin the codebase's deferred retire uses, for the same reason.Arc, descriptor slot or list view still points at the buffer.Shadow, so a reused buffer is indistinguishable from a freshly created one.VICTORY_EXACT_REUSE=0gives the pre-PR behaviour: always create, no pool, no gate.Unit tests (new,
shadow::spare_tests)a_spare_is_taken_only_of_its_width_and_after_its_gate: width matching, and refusal before the gate.a_spare_waits_past_the_lag_and_some_frames:spare_gatearithmetic, and that both conditions (submissions and frames) are needed.spares_keep_to_their_bytes_oldest_first_and_refuse_big_ones: the byte cap, oldest-first eviction, and refusal of items over 1/8 of the cap.Measured (RTX 5070, from the
VICTORY_BIND_SPLITline)bindtotal (all threads)run-v9-20261126-225548run-v9-20261126-225146Memory-mapping waits for new card memory
VICTORY_WAIT_RESIDENTpath waits for every new committed resource to be GPU-VA-mapped before use. Cumulative counts:maindoesn't have that waiting path. Onmain, the same saving shows up asCreateCommittedResourcecalls avoided, plus the OS's own residency work.Reported end to end: with reuse on, CPU utilisation went from about 89% to 59% in the same scene.
2. Card-cap turn-down log (diagnostic, no behaviour change)
File:
crates/victory-gpu/src/shadow.rs(cap check incard_room_for, newCARD_CAPPEDcounter)Problem
VICTORY_CARD_BUFFERS_MBcaps the total size of title-buffer copies kept in the card's memory. It defaults to 512 MB when the budget is 12 GiB or less, and the RTX 5070 reports 11,175 MB.card_room_forreturnedNonewithout logging anything, unlike its other turn-downs. Later big buffers stayed in system memory, where shader writes to them are compared on the CPU, and every GPU access to them crosses PCIe.Mechanism
static CARD_CAPPED: [AtomicU64; 2], holding the count and bytes turned down by the cap since the start.info!line is logged for the first 16 refusals and then every 64th:no card copy for a title buffer of N KiB: the copies made hold X MB of at most Y MB (VICTORY_CARD_BUFFERS_MB); K buffers turned down so far for it (B MB), frame FWhy it is safe
fetch_subandreturn None) is unchanged.Measured
run-v8-20261126-215944run-v9-20261126-225146/-225548VICTORY_CARD_BUFFERS_MB=1024)3. Bind-time split:
VICTORY_BIND_SPLITFiles:
crates/victory-gpu/src/draw.rs:BIND_NS,bind_split(),BindLap,bind_split_line(), and laps inState::bindcrates/victory-gpu/src/host.rs: one call from the frame lineProblem
Dispatches and indirect executions were costing 40–60 µs of CPU each on the 5070, and no log line showed where that time went inside
State::bind.Mechanism
static BIND_NS: [AtomicU64; 5]holds nanoseconds for the whole ofbind, the early texture pass, descriptor tables and title memory by address, plus a bind count.BindLapis an RAII guard. It recordsInstant::now()onstart(part)and adds the elapsed time onDrop, so every earlyreturn falseinbindis still counted.State::bindgets four laps:0: the whole function;1: aroundearly_textures();2: aroundtables();3: aroundmemory_ready().bind_split_line(frames)is called from the host frame line, right before the heap-buffer-pass stats. It swaps the counters to zero and logs:binding draws and dispatches per frame (VICTORY_BIND_SPLIT=0: not timed): N binds X ms (all threads), of them the early texture pass … ms, descriptor tables … ms, title memory by address … ms, the rest (root views and their refreshes, the heap pass, state) … mswhole − (early + tables + memory)with saturating subtraction.Why it is safe
Instant::now()pair and one relaxedfetch_addper lap, about 4 laps a bind, at 9,000–10,000 binds a frame.VICTORY_BIND_SPLIT=0turns off both the timing (BindLapholdsNone) and the line. The flag is read once through aOnceLock.New environment variables
VICTORY_EXACT_REUSE0)=0gives the pre-PR path: always create, no poolVICTORY_EXACT_REUSE_LAG64STARTEDbefore reuseVICTORY_EXACT_REUSE_FRAMES3VICTORY_BIND_SPLIT0)State::bindand its parts, and log them per frame=0: not timed, no lineinfo!line on an existing refusal path.VICTORY_CARD_BUFFERS_MB, is unchanged (512 MB default when the budget is 12 GiB or less).Root-cause note: face spikes came from
PORT_CONSTANTS, notEXACT_REUSEThis is context for review, because exact reuse was first suspected.
Symptom (downstream). Characters' faces and skinned meshes showed vertex "spikes". The first user A/B toggled exact reuse, the in-place port and render scale together, so it pointed at reuse.
Finding, from code analysis plus a one-variable-at-a-time A/B:
VICTORY_PORT_CONSTANTS(renderer port 1) places the title's 185 MB graphics region in place. It is opened from its address as CUSTOM/system-memory heaps throughOpenExistingHeapFromAddress1. The 174 MB heap at0x34e10000holds the constants ring and skinning output.Relevance to
main.maindoesn't have the port-1 / in-place path (VICTORY_PORT_CONSTANTS) orVICTORY_PLACED_ORDER, so this PR can't trigger the issue. If the port lands later, it should stay opt-in, and exact copies shouldn't snapshot in-place GPU-written memory.End-to-end results (downstream fork with this PR's code, RTX 5070 / 5800X3D, GTA VI, Series X mode)
run-v8-20261126-220247) reached 9.4 fps / 106.1 ms.VICTORY_PLACED_ORDER). They are not a claim for this PR alone. This PR's own effect is the bind and table numbers in section 1.Not ported (no equivalent code in
main)VICTORY_THIN_OPS(bind split lived inlist/thin.rs)mainhas nolist/thin.rs, so the split is logged from the host frame line insteadVICTORY_CARD_STEPS_WHYmainhas nohost/card_steps.rsVICTORY_MAPPED_SHARED/VICTORY_WAIT_RESIDENTstatsmainhas nowait_resident/ mapped trackingVICTORY_PLACED_ORDER,VICTORY_PORT_CONSTANTSmainhas no placed-copy ordering or in-place portBIND_NS[8])mainAdaptations from the downstream version:
shadow.len.next_multiple_of(256), becausemain'sShadowhas nowidth().crate::host::retire, becausemainhas noretire_resource/bury_lag. The 64-submission lag is carried in the reuse gate itself.Verification
All of this was run on Windows 11 (RTX 5070 rig), on branch
pr/fxceless-v9-perfata522721, with an isolated target dir.main. The suite includes the 3 newshadow::spare_tests.cargo build --release -p victorysucceeded with 0 warnings.victory.exe(9,050,112 bytes; SHA-256 begins93D1015DCFA3B779).rustfmt --edition 2024 --checkparses all three touched files cleanly.--locked: no lockfile changes.Manual A/B on the rig:
VICTORY_EXACT_REUSE=0vs on: the bind/table numbers above.VICTORY_BIND_SPLIT=0removes the timing line.