Proposal: record list calls on the title's threads, translate them on worker threads (about 20 µs a call today) #2584
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 Marvisak/VIctory. Originally posted by shawshanker18 on 2026-11-25T16:18:15Z.
Idea
The title's render threads call the D3D12.X list methods, and the layer translates each call right there, on the title's thread. On the console these calls are a few dozen instructions each (they write packets into a command buffer). Here they are much more: address lookups in shared maps, descriptor mirroring, state tracking, then the host call.
Proposal: record now, translate later, off the title's threads:
Close(or at submission), worker threads translate the logs into host lists. Several lists translate in parallel; one list's log could also split at barriers.Why (measured, fxceless fork, RTX 4050 Laptop, Ryzen 7 7735HS, lit world)
descriptor::mirrorintolock_contended), allocation, and, in diag builds withVICTORY_D3D12_DRED, string formatting for command notes (see #913).Even with no reduction in total work, moving it off the title's critical path and spreading it over idle cores should cut the title's frame time. Combined with reusing translated lists across frames (separate proposal), total work could drop too.
Open questions
No game data in this proposal.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T18:46:22Z.
Automated triage for the maintainers.
This is a performance proposal for the GPU layer: record command-list calls on the title's threads and translate them later on worker threads. It fits the project's scope, and it is labelled and kept as a request.
The timings quoted come from a fork, not from main. A per-call cost measured on main, along with the list of calls that must stay synchronous, would settle the open questions.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-26T14:49:51Z.
Per-call cost on main (
63bcca4), as the triage asked: every D3D12.X list method the title calls most, through the list's method table, on a host device.Method. An
#[ignore]d test,pipeline::list_bench, one commit on top of main: KainanP/VIctory@perf/list-call-bench (cargo test -p victory-gpu --release list_bench -- --ignored --nocapture). The setup is close to the title's:State::binddoes all of its CPU work for those bindings.Each row is the best of 5 × 20,000 calls, with lists closed and reset every 2,000 calls. The binary ran 7 times interleaved with other builds, and the table gives the median. Hardware: RTX 4060 Laptop GPU (driver 32.0.16.1047), Core i7-14650HX, Windows 11, release profile, idle machine. No game data.
SetGraphicsRootConstantBufferView(0x150)with_state: two uncontended mutexes (segment list, draw state), then aVecstore. No host call.SetGraphicsRootDescriptorTable(0x120)SetGraphicsRoot32BitConstant(s)(0x130/0x140),SetComputeRoot32BitConstants(0x138)VecresizeIASetIndexBuffer/IASetVertexBuffers(0x178/0x180)SetPipelineState(0xc8)SetDescriptorHeaps(0x100)RSSetViewports/RSSetScissorRects(0xa8/0xb0)to_vec()allocation per call that keeps them for the next segment (Fixed)ResourceBarrier, one texture transition (0xd0)Vecper call, and the hostResourceBarrier(not split further)ResourceBarrier, one buffer (0xd0)buffer_bytes, aVec, a host UAV barrierDrawIndexedInstanced, nothing changed since the last draw (0x68)resource::alias_source120 (builds the texture's full console layout underTEXTURES_AT),list::ensure_state70 (resource lock, twoGetDesc, per-list state map), host copy lookups +title_writtenGetDesc+ upload check ~85,HostHeap::mirror43 (made+VIEWSlocks). Three root constant buffers ≈ 3 × 45 (shadow::findunderBUFFERS, a SipHash set insert). About 0.4 µs left over: user-dataVecs and the host calls (not split).Dispatch(0x70), two-entry table + root CBVExecuteIndirect, one indexed draw (0x1d8)ExecuteIndirect, one dispatchHostHeap::made,VIEWS,TEXTURES_AT,BUFFERS, and the per-resourcehostmutexes of textures all threads readSo on main a state-setting call is ~20–60 ns. The cost is in the draws, dispatches and indirect executions, through what each table entry does, and it grows about 3.8× when five threads record at once. Per call, averaged over the draw sequence: ~0.7 µs on one thread and ~2.6 µs per thread on five. The 20 µs a call in the proposal was measured on a fork, with the world's heaps (many more textures per draw,
sync_heapsholdingSHADER_HEAPSwhile title threads write views) and, in diag builds, command notes. None of that is modelled here.Open PRs on the same path, same benchmark, each merged on main (median of 7 interleaved runs):
DrawIndexedInstancedDispatchExecuteIndirect, indexedalias_sourcefrom building the layout per texture view (120 → 14 ns). Merge one of them, not both.Vecwith a linearcontains. In the draw sequence each draw refreshes a new constant-ring position, so the scan grows with the list, and #3238's draw sequence (2388) costs more than its bare draw (1966). On main and on every other build the sequence adds ~70 ns over the bare draw. A frame's lists refresh thousands of ranges, so #1978's version of thealias_sourcechange is the safer one.HostHeap::mirror(43 → 18 ns) and is the one that pays off under five threads.GetDesc(ensure_state70 → 35 ns). On one thread it adds ~600 ns per draw to any of the above. On five threads it should merge with or after #2821: on top of #1978 alone, five threads get slower, because with less work between them the threads queue on the remaining shared locks more.Calls that must stay synchronous (for the record-now/translate-later design; #3184 implements it behind
VICTORY_DEFER_LISTS): the ones that return something the title reads (QueryInterface,Release,GetType0x40, the upload allocation 0x4a0, the driver hint 0x318).Reset/ResetX/lastReleasemust first drain the log, since they free what the logged calls read. Everything else returns nothing or a constant (ResourceBarrierreturns 0) and can be logged, as long as what its pointers name is copied at the call (viewports, scissors, barriers, root constant arrays, vertex/index views, target handles, clear values, copy locations, rectangles). Today descriptor-table contents are read when a draw is translated, which is at the call, and title buffers are read at submission. Deferring translation moves the descriptor read later, closer to when the console's GPU reads them.AI use: Claude Code (Claude Opus 5.5) wrote the benchmark, ran the measurements and drafted this comment.
Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-26T15:27:00Z.
Update on the 5-thread scaling from my last comment (7195391455).
I profiled the draw sequence on five threads with per-call-site lock counters, on main + #1978 + #2821 + #3258. The most contended lock was
TEXTURES_ATinalias_source: it's taken six times per draw, and another thread held it on 36% of those takes. After it camedescriptor::VIEWS(taken inview_at), each texture'shostmutex, andshadow::BUFFERS.HostHeap::madeisn't on this path because the slots are already made. Two PRs remove the first two from the read path:Draw sequence (
list_bench,VICTORY_LIST_BENCH_SCALING=1), ns per draw per thread, medians of 7 interleaved runs, RTX 4060 Laptop + i7-14650HX:#3274 alone on main: 3144 → 2325 on one thread and 12119 → 7836 on five. What's left on five threads is mostly the shared
Arccount of each texture's host copy andshadow::BUFFERS. None of this has been measured in a game yet. An A/B of #3274 (with #2821) in a title that records on several threads would be the useful next number.Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-26T16:26:17Z.
Follow-up to the per-call table (7195391455) and the scaling note (7196282096). Same bench and machine: RTX 4060 Laptop, i7-14650HX, release, builds interleaved, median of 7 runs. Four unrelated Python jobs were using the CPU throughout.
1.
ExecuteIndirect(4.7 µs on main). I benchmarked the two open PRs that batch the per-call argument clamp. The bench branch now hasVICTORY_LIST_BENCH_INDIRECT=1, which runs indirect draws and dispatches on 1 and 5 threads, with the list's close and the submission prelude timed. Full tables are on #2472 (7197569095) and #3197 (7197569697). Indexed draw, ns per call:VICTORY_CLAMP_WINDOW=1)On the CPU, both PRs remove the same ~1.8 µs per indirect draw. This bench is the best case for both: the list only has non-writing indirect draws. What separates them is how much of a real frame each covers, and their GPU time, and I measured neither. Neither PR touches indirect dispatches (3.0 µs vs 0.86 µs for a plain
Dispatch). I found no open PR for those. Both pass their tests on RTX 4060, Intel UHD and WARP, with the same failures as on main.2.
RSSetViewports/RSSetScissorRects/ResourceBarrierper-callVecs. No open PR removed these, so I opened #3297. It reuses the keptVec, and barriers go into a stack array. ns per call: viewports 50 → 23, scissors 56 → 28, barrier on a texture 312 → 262, barrier on a buffer 191 → 145. #3297 overlaps #3176 and #3129 on the same lines, and its description says how to combine them.3.
BUFFERSreads left after #3274/#3275. As an experiment, I put a thread-local cache in front ofshadow::findon main + #1978 + #2821 + #3258 + #3274 + #3275. The cache holds the last few buffers found, validated by a generation counter bumped on every register/unregister/copy made. Draw sequence, ns per draw:findcacheThat is −24% on five threads, with the
Arc<Shadow>clone still paid on every hit. The experiment isn't a fix as written. It cached a buffer's whole range without checking for buffers nested inside it, and it heldArcs in thread-locals. #1356 (wbkepler) already does this properly: a per-list cache validated by a buffer-table generation, with aCachedRangethat is only as wide as no other buffer intrudes. But #1356 needs a rebase (BUFFERSis aMutexon main, anRwLockwith #2821, and #2096 restructures it). Splitting that cache out of #1356 and rebasing it looks like the next clear win for the title's threads, so I haven't opened a competing PR. I didn't measure the per-textureArccount on the host copy separately.AI use: Claude Code (Claude Opus 5.5) ran the measurements and drafted this comment.
Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-26T22:32:39Z.
Scaling update, list bench draw sequence (RTX 4060, release,
VICTORY_LIST_BENCH_SCALING=1, median of 7 interleaved runs).Stack = main + #1978 + #2821 + #3258 + #3274 + #3275 + rebased #1356 (fork branch
rebase/1356-cached-range):Caveat: a game was running during these runs (CPU 46–69 %). Absolute values are inflated. On a quiet machine the same stack measured ~1.4 / ~2.5 µs earlier. Compare the columns, not the absolute values.
A per-call-site lock profile at 5 threads on that stack showed that what was left was the title resource's
hostmutex taken on every texture read (6 takes per draw, 65 % contended, ~740 ns per draw), together with theArcclone and drop of the host copy. #3405 (needs #3258) lets a list keep the copies it read, validated by a per-resource generation that every write of the host copy bumps. Per read this is one load, with no shared lock and no refcount change. The list holds the copies until its reset, after its submission. The PR has the safety argument and a test that releases a texture while a list reading it is recorded and in flight. After it, no lock on the 5-thread path is contended. The rest of the 1→5 thread gap is in list-local locks plus things a lock profiler can't see (the target transitions' texture clones, which #3249 addresses, and COM refcounts).Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-27T06:36:42Z.
Re @KainanP's scaling table above and @AurumCarlos's review on #3391: my #3391 (
mirror_draw: oneVIEWSlock per heap per draw instead of one per table entry) is the same cost as the title resource'shostmutex in that profile, answered by paying the lock once instead of by removing it. Your stack (#3258 + #3274 + #3275 + #3405) removes it properly, so if that is the direction, #3391 is superseded and I'll close it rather than have it land and be undone.Numbers behind the choice (Intel Arc B580, 256 table entries in one draw): per-entry
mirror755 µs vs one batched call 547 µs underVIEWScontention (~1.4x), and 585 vs 627 µs uncontended (the batching's ownVecand clone cost is a small loss there). It is worth something only while the registry lock is still on the draw path — exactly what #3275 takes away.If it helps your sequence, I'd rather it be a no from me than a rebase conflict for you: say the word and I close #3391; otherwise it stays open as an interim in case #3275 is a while away. Synthetic tests only, no game data.
Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-27T12:02:20Z.
Follow-up: open PRs on the list-call path, measured with this bench (
VICTORY_LIST_BENCH_SCALING=1, RTX 4060 Laptop, release, medians of 7 interleaved runs, two batches; quiet machine this time, no game). ns per draw, change against each base, 1 thread / 5 threads:(Stack = main + #1978 + #2821 + #3258 + #3274 + #3275 + rebased #1356 + #3405. With no foreign load it measures 1.11 / 1.46 µs, against 2.5 / 9.0 µs on
main.)readable.transitionno longer makes on reads. #3258 already removes that clone, so on the stack it adds nothing here. Its targets memo isn't exercised, because the bench binds no targets. That corrects what I wrote above: on this bench the remaining 1→5 thread gap (+32 % on the stack) is not the target-transition clones.keepdedup. #3218 targets a fragmented or saturated dynamic range, which this bench doesn't create.main(only the #1744 pair) or on the stack. The stack's port of #3405 fails its owna_list_lends_a_read_copy_only_while_it_is_the_texturesat the "let go at the reset" assert; #3405's head passes it. The cause is in the port's older copy of the test, not the code: it shadowsfirstwithArc::downgrade(&first)without dropping the strongArc, so the test itself keeps the copy alive. #3405's head drops it first. Details and caveats are in each PR.Not looked at, because they aren't on this path or this bench doesn't reach them: #3107 (targets), #3113 (unaligned root CBVs; the bench's are aligned), #3215 (submission time).
AI use: Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by Fran-co-F on 2026-11-29T03:25:29Z.
An in-game data point for this proposal, from a different machine and OS: per-draw cost is what decides playability once you move, more than memory coherency.
Setup: Ryzen 7 9800X3D, RX 9070 XT, Linux. SlaktarnVI fork under Wine 11.17, Series X profile. Fifteen minutes of real play with a pad, 5-s windows, real fps (frame generation not counted):
VICTORY_ASYNC_SUBMIT) costs a median of about 5.9 µs per draw of the frame. Its time is not only per draw (it also refreshes title-memory copies per submission), and it was 11.1 µs per draw before our memory changes.So we agree with the direction here and in @KainanP's bench stack (#3258, #3274, #3275, #3405, #1356): cheaper and more parallel draw translation is the lever for actually playing. We are not working on it ourselves. If someone wants a tester on RDNA4/Linux with a reproducible route (same save, same walk, per-window logs), we can run their branch and report.
Full write-up of our memory-side work: Slaktarn700/SlaktarnVI#15.