Proposal: record list calls on the title's threads, translate them on worker threads (about 20 µs a call today) #2586
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#2586
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?
@shawshanker18 on GitHub · 2026-11-25 16:18 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 18:46 UTC · original
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
@KainanP on GitHub · 2026-11-26 14:49 UTC · original
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.
@KainanP on GitHub · 2026-11-26 15:27 UTC · original
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.@KainanP on GitHub · 2026-11-26 16:26 UTC · original
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.