Proposal: record list calls on the title's threads, translate them on worker threads (about 20 µs a call today) #2584

Open
opened 2026-11-25 16:18:15 +00:00 by shawshanker18 · 8 comments
shawshanker18 commented 2026-11-25 16:18:15 +00:00 (Migrated from github.com)
Contributor

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:

  1. Each list method appends a compact record (opcode plus the argument words, copied by value) to a per-list log. About 100 ns, no locks, no host calls.
  2. At 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.
  3. What must happen at call time stays at call time (anything that returns a value to the title, or reads title memory that may change before submission). The rest is deferred.

Why (measured, fxceless fork, RTX 4050 Laptop, Ryzen 7 7735HS, lit world)

  • 5 title threads each spend 150-180 ms a frame inside list calls, about 8,500 calls each: roughly 20 µs a call. On the console the same work is a few milliseconds a frame in total.
  • A sampling profile of those threads (an in-process sampler, diag build) shows mutex contention (descriptor::mirror into lock_contended), allocation, and, in diag builds with VICTORY_D3D12_DRED, string formatting for command notes (see #913).
  • During a frame about half of the 16 hardware threads are idle.

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

  • Which list methods have observable side effects that must stay synchronous.
  • Descriptor-heap bytes the title writes between recording and submission: deferred translation must see the heap as the GPU would at execution, which is the console's behaviour.

No game data in this proposal.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6608715309 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/2586). Originally posted by [shawshanker18](https://github.com/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**: 1. Each list method appends a compact record (opcode plus the argument words, copied by value) to a per-list log. About 100 ns, no locks, no host calls. 2. At `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. 3. What must happen at call time stays at call time (anything that returns a value to the title, or reads title memory that may change before submission). The rest is deferred. ## Why (measured, fxceless fork, RTX 4050 Laptop, Ryzen 7 7735HS, lit world) - 5 title threads each spend **150-180 ms a frame inside list calls**, about 8,500 calls each: roughly **20 µs a call**. On the console the same work is a few milliseconds a frame in total. - A sampling profile of those threads (an in-process sampler, diag build) shows mutex contention (`descriptor::mirror` into `lock_contended`), allocation, and, in diag builds with `VICTORY_D3D12_DRED`, string formatting for command notes (see #913). - During a frame about half of the 16 hardware threads are idle. 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 - Which list methods have observable side effects that must stay synchronous. - Descriptor-heap bytes the title writes between recording and submission: deferred translation must see the heap as the GPU would at execution, which is the console's behaviour. No game data in this proposal.
Marvisak commented 2026-11-25 19:06:30 +00:00 (Migrated from github.com)
Author
Contributor

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171377198 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/2586#issuecomment-7171377198). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T18:46:22Z. --- <!-- victory-issue-triage v1 verdict=tracked seen=2026-11-25T16:18:15Z at=2026-11-25T19:09:00Z --> 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](https://claude.ai/code)_
KainanP commented 2026-11-26 15:02:35 +00:00 (Migrated from github.com)
Author
Contributor

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:

  • title buffers in write-watched memory, a shader-visible title view heap of 4,096 slots, and eight 64×64 textures;
  • graphics pipelines whose translations read two root constant buffers, four root constants and a six-texture table, and a compute pipeline that reads a texture + raw UAV table and a root constant buffer. The host code reads nothing, so State::bind does 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.

method (older-layout slot) ns/call what dominates
SetGraphicsRootConstantBufferView (0x150) 24 with_state: two uncontended mutexes (segment list, draw state), then a Vec store. No host call.
SetGraphicsRootDescriptorTable (0x120) 24 same
SetGraphicsRoot32BitConstant(s) (0x130/0x140), SetComputeRoot32BitConstants (0x138) 22–23 same, plus a small Vec resize
IASetIndexBuffer / IASetVertexBuffers (0x178/0x180) 21–22 same
SetPipelineState (0xc8) 27 same. The host pipeline is bound at the next draw.
SetDescriptorHeaps (0x100) 21 same, plus one heap lookup
RSSetViewports / RSSetScissorRects (0xa8/0xb0) 50 / 56 the host call, plus a to_vec() allocation per call that keeps them for the next segment (Fixed)
ResourceBarrier, one texture transition (0xd0) 312 host lookup, a Vec per call, and the host ResourceBarrier (not split further)
ResourceBarrier, one buffer (0xd0) 198 buffer_bytes, a Vec, a host UAV barrier
DrawIndexedInstanced, nothing changed since the last draw (0x68) 2,713 the six table entries, ~320 ns each, ≈1.9 µs: resource::alias_source 120 (builds the texture's full console layout under TEXTURES_AT), list::ensure_state 70 (resource lock, two GetDesc, per-list state map), host copy lookups + title_written GetDesc + upload check ~85, HostHeap::mirror 43 (made + VIEWS locks). Three root constant buffers ≈ 3 × 45 (shadow::find under BUFFERS, a SipHash set insert). About 0.4 µs left over: user-data Vecs and the host calls (not split).
draw sequence: root CBV + 4 constants + index buffer + draw, per draw 2,780 the draw. The three setters add ~70 ns.
Dispatch (0x70), two-entry table + root CBV 855 the same per-entry work
ExecuteIndirect, one indexed draw (0x1d8) 4,660 a draw's bind, plus the argument refresh and the clamp dispatch recorded per call
ExecuteIndirect, one dispatch 2,899 the same
draw sequence on 5 threads at once, per draw per thread 10,526 (vs 2,780 on 1 thread) contention on the shared locks above: HostHeap::made, VIEWS, TEXTURES_AT, BUFFERS, and the per-resource host mutexes of textures all threads read

So 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_heaps holding SHADER_HEAPS while 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):

ns per draw main #1978 #3238 #2102 #2821 #3061 / #3005 / #2848 / #3215 #3258 (new) #1978+#2102+#2821+#3005+#3061 the same + #3258
DrawIndexedInstanced 2713 2046 1966 2663 2480 2571–2704 2047 1774 1132
draw sequence, 1 thread 2780 2118 2388 2640 2731 2738–2839 2186 1844 1236
draw sequence, 5 threads 10526 6664 6615 9897 8170 9316–10859 9831 4539 4537
Dispatch 855 733 708 835 828 819–851 748 627 522
ExecuteIndirect, indexed 4660 3893 3661 4611 4389 4518–4746 4120 3550 2835
  • #1978 and #3238 both stop alias_source from building the layout per texture view (120 → 14 ns). Merge one of them, not both.
  • #3238 also turns the list's refreshed-range set into a Vec with a linear contains. 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 the alias_source change is the safer one.
  • #2821 halves HostHeap::mirror (43 → 18 ns) and is the one that pays off under five threads.
  • #3258 (opened now) takes the texture's host copy once per read and keeps its flags instead of calling GetDesc (ensure_state 70 → 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.
  • #3061, #3005, #2848 and #3215 change nothing measurable here. Their paths (capped heaps, the first-use exchange, copy-back and heap sync, submission) aren't exercised.

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, GetType 0x40, the upload allocation 0x4a0, the driver hint 0x318). Reset/ResetX/last Release must first drain the log, since they free what the logged calls read. Everything else returns nothing or a constant (ResourceBarrier returns 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7195391455 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/2586#issuecomment-7195391455). Originally posted by [KainanP](https://github.com/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](https://github.com/KainanP/VIctory/tree/perf/list-call-bench) (`cargo test -p victory-gpu --release list_bench -- --ignored --nocapture`). The setup is close to the title's: - title buffers in write-watched memory, a shader-visible title view heap of 4,096 slots, and eight 64×64 textures; - graphics pipelines whose translations read two root constant buffers, four root constants and a six-texture table, and a compute pipeline that reads a texture + raw UAV table and a root constant buffer. The host code reads nothing, so `State::bind` does 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. | method (older-layout slot) | ns/call | what dominates | |---|---:|---| | `SetGraphicsRootConstantBufferView` (0x150) | 24 | `with_state`: two uncontended mutexes (segment list, draw state), then a `Vec` store. No host call. | | `SetGraphicsRootDescriptorTable` (0x120) | 24 | same | | `SetGraphicsRoot32BitConstant(s)` (0x130/0x140), `SetComputeRoot32BitConstants` (0x138) | 22–23 | same, plus a small `Vec` resize | | `IASetIndexBuffer` / `IASetVertexBuffers` (0x178/0x180) | 21–22 | same | | `SetPipelineState` (0xc8) | 27 | same. The host pipeline is bound at the next draw. | | `SetDescriptorHeaps` (0x100) | 21 | same, plus one heap lookup | | `RSSetViewports` / `RSSetScissorRects` (0xa8/0xb0) | 50 / 56 | the host call, plus a `to_vec()` allocation per call that keeps them for the next segment (`Fixed`) | | `ResourceBarrier`, one texture transition (0xd0) | 312 | host lookup, a `Vec` per call, and the host `ResourceBarrier` (not split further) | | `ResourceBarrier`, one buffer (0xd0) | 198 | `buffer_bytes`, a `Vec`, a host UAV barrier | | **`DrawIndexedInstanced`**, nothing changed since the last draw (0x68) | **2,713** | the six table entries, ~320 ns each, ≈1.9 µs: `resource::alias_source` 120 (builds the texture's full console layout under `TEXTURES_AT`), `list::ensure_state` 70 (resource lock, two `GetDesc`, per-list state map), host copy lookups + `title_written` `GetDesc` + upload check ~85, `HostHeap::mirror` 43 (`made` + `VIEWS` locks). Three root constant buffers ≈ 3 × 45 (`shadow::find` under `BUFFERS`, a SipHash set insert). About 0.4 µs left over: user-data `Vec`s and the host calls (not split). | | draw sequence: root CBV + 4 constants + index buffer + draw, per draw | 2,780 | the draw. The three setters add ~70 ns. | | `Dispatch` (0x70), two-entry table + root CBV | 855 | the same per-entry work | | `ExecuteIndirect`, one indexed draw (0x1d8) | 4,660 | a draw's bind, plus the argument refresh and the clamp dispatch recorded per call | | `ExecuteIndirect`, one dispatch | 2,899 | the same | | **draw sequence on 5 threads at once**, per draw per thread | **10,526** (vs 2,780 on 1 thread) | contention on the shared locks above: `HostHeap::made`, `VIEWS`, `TEXTURES_AT`, `BUFFERS`, and the per-resource `host` mutexes of textures all threads read | So 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_heaps` holding `SHADER_HEAPS` while 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): | ns per draw | main | #1978 | #3238 | #2102 | #2821 | #3061 / #3005 / #2848 / #3215 | #3258 (new) | #1978+#2102+#2821+#3005+#3061 | the same + #3258 | |---|---:|---:|---:|---:|---:|---:|---:|---:|---:| | `DrawIndexedInstanced` | 2713 | 2046 | 1966 | 2663 | 2480 | 2571–2704 | 2047 | 1774 | **1132** | | draw sequence, 1 thread | 2780 | 2118 | 2388 | 2640 | 2731 | 2738–2839 | 2186 | 1844 | **1236** | | draw sequence, 5 threads | 10526 | 6664 | 6615 | 9897 | 8170 | 9316–10859 | 9831 | 4539 | **4537** | | `Dispatch` | 855 | 733 | 708 | 835 | 828 | 819–851 | 748 | 627 | **522** | | `ExecuteIndirect`, indexed | 4660 | 3893 | 3661 | 4611 | 4389 | 4518–4746 | 4120 | 3550 | **2835** | - #1978 and #3238 both stop `alias_source` from building the layout per texture view (120 → 14 ns). Merge one of them, not both. - #3238 also turns the list's refreshed-range set into a `Vec` with a linear `contains`. 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 the `alias_source` change is the safer one. - #2821 halves `HostHeap::mirror` (43 → 18 ns) and is the one that pays off under five threads. - #3258 (opened now) takes the texture's host copy once per read and keeps its flags instead of calling `GetDesc` (`ensure_state` 70 → 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. - #3061, #3005, #2848 and #3215 change nothing measurable here. Their paths (capped heaps, the first-use exchange, copy-back and heap sync, submission) aren't exercised. **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`, `GetType` 0x40, the upload allocation 0x4a0, the driver hint 0x318). `Reset`/`ResetX`/last `Release` must first drain the log, since they free what the logged calls read. Everything else returns nothing or a constant (`ResourceBarrier` returns 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 commented 2026-11-26 16:05:05 +00:00 (Migrated from github.com)
Author
Contributor

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_AT in alias_source: it's taken six times per draw, and another thread held it on 36% of those takes. After it came descriptor::VIEWS (taken in view_at), each texture's host mutex, and shadow::BUFFERS. HostHeap::made isn't on this path because the slots are already made. Two PRs remove the first two from the read path:

  • #3274: a texture with no GPU writer at its memory keeps that answer, checked against a per-bucket change count, so its reads skip the lock.
  • #3275: each recording thread keeps the views it looked up, checked against lock-free per-entry generations.

Draw sequence (list_bench, VICTORY_LIST_BENCH_SCALING=1), ns per draw per thread, medians of 7 interleaved runs, RTX 4060 Laptop + i7-14650HX:

tree 1 thread 5 threads 5 / 1
main 3144 12119 3.85×
main + #1978 + #2821 + #3258 1559 5100 3.27×
the same + #3274 1430 2895 2.02×
the same + #3274 + #3275 1426 2824 1.98×

#3274 alone on main: 3144 → 2325 on one thread and 12119 → 7836 on five. What's left on five threads is mostly the shared Arc count of each texture's host copy and shadow::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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7196282096 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/2586#issuecomment-7196282096). Originally posted by [KainanP](https://github.com/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_AT` in `alias_source`: it's taken six times per draw, and another thread held it on 36% of those takes. After it came `descriptor::VIEWS` (taken in `view_at`), each texture's `host` mutex, and `shadow::BUFFERS`. `HostHeap::made` isn't on this path because the slots are already made. Two PRs remove the first two from the read path: - #3274: a texture with no GPU writer at its memory keeps that answer, checked against a per-bucket change count, so its reads skip the lock. - #3275: each recording thread keeps the views it looked up, checked against lock-free per-entry generations. Draw sequence (`list_bench`, `VICTORY_LIST_BENCH_SCALING=1`), ns per draw per thread, medians of 7 interleaved runs, RTX 4060 Laptop + i7-14650HX: | tree | 1 thread | 5 threads | 5 / 1 | |---|---:|---:|---:| | main | 3144 | 12119 | 3.85× | | main + #1978 + #2821 + #3258 | 1559 | 5100 | 3.27× | | the same + #3274 | 1430 | 2895 | 2.02× | | the same + #3274 + #3275 | 1426 | 2824 | 1.98× | #3274 alone on main: 3144 → 2325 on one thread and 12119 → 7836 on five. What's left on five threads is mostly the shared `Arc` count of each texture's host copy and `shadow::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 commented 2026-11-26 16:26:17 +00:00 (Migrated from github.com)
Author
Contributor

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 has VICTORY_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:

main + #2472 + #3197 (VICTORY_CLAMP_WINDOW=1)
1 thread 4,870 3,212 3,186
1 thread, on main + #1978 + #2821 + #3258 + #3274 + #3275 3,260 1,449 1,449
5 threads, same stack 4,345 2,742 2,687

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 / ResourceBarrier per-call Vecs. No open PR removed these, so I opened #3297. It reuses the kept Vec, 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. BUFFERS reads left after #3274/#3275. As an experiment, I put a thread-local cache in front of shadow::find on 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:

1 thread 5 threads (per thread)
stack 1,351 [1,271–1,708] 2,485 [2,427–2,597]
+ find cache 1,242 [1,197–1,286] 1,894 [1,829–1,954]

That 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 held Arcs in thread-locals. #1356 (wbkepler) already does this properly: a per-list cache validated by a buffer-table generation, with a CachedRange that is only as wide as no other buffer intrudes. But #1356 needs a rebase (BUFFERS is a Mutex on main, an RwLock with #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-texture Arc count on the host copy separately.

AI use: Claude Code (Claude Opus 5.5) ran the measurements and drafted this comment.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7197644545 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/2586#issuecomment-7197644545). Originally posted by [KainanP](https://github.com/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 has `VICTORY_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: | | main | + #2472 | + #3197 (`VICTORY_CLAMP_WINDOW=1`) | |---|---:|---:|---:| | 1 thread | 4,870 | 3,212 | 3,186 | | 1 thread, on main + #1978 + #2821 + #3258 + #3274 + #3275 | 3,260 | 1,449 | 1,449 | | 5 threads, same stack | 4,345 | 2,742 | 2,687 | 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` / `ResourceBarrier` per-call `Vec`s.** No open PR removed these, so I opened #3297. It reuses the kept `Vec`, 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. `BUFFERS` reads left after #3274/#3275.** As an experiment, I put a thread-local cache in front of `shadow::find` on 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: | | 1 thread | 5 threads (per thread) | |---|---:|---:| | stack | 1,351 [1,271–1,708] | 2,485 [2,427–2,597] | | + `find` cache | 1,242 [1,197–1,286] | **1,894** [1,829–1,954] | That 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 held `Arc`s in thread-locals. #1356 (wbkepler) already does this properly: a per-list cache validated by a buffer-table generation, with a `CachedRange` that is only as wide as no other buffer intrudes. But #1356 needs a rebase (`BUFFERS` is a `Mutex` on main, an `RwLock` with #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-texture `Arc` count on the host copy separately. _AI use: Claude Code (Claude Opus 5.5) ran the measurements and drafted this comment._
KainanP commented 2026-11-26 22:32:39 +00:00 (Migrated from github.com)
Author
Contributor

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):

per draw stack + #1356 + #3405
1 thread 1759 ns 1788 ns
5 threads 3102 ns 2731 ns

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 host mutex taken on every texture read (6 takes per draw, 65 % contended, ~740 ns per draw), together with the Arc clone 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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204772549 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/2586#issuecomment-7204772549). Originally posted by [KainanP](https://github.com/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`): | per draw | stack + #1356 | + #3405 | |---|---|---| | 1 thread | 1759 ns | 1788 ns | | 5 threads | 3102 ns | **2731 ns** | 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 `host` mutex** taken on every texture read (6 takes per draw, 65 % contended, ~740 ns per draw), together with the `Arc` clone 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).
borosf commented 2026-11-27 06:36:42 +00:00 (Migrated from github.com)
Author
Contributor

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: one VIEWS lock per heap per draw instead of one per table entry) is the same cost as the title resource's host mutex 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 mirror 755 µs vs one batched call 547 µs under VIEWS contention (~1.4x), and 585 vs 627 µs uncontended (the batching's own Vec and 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7211684675 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/2586#issuecomment-7211684675). Originally posted by [borosf](https://github.com/borosf) on 2026-11-27T06:36:42Z. --- Re @KainanP's scaling table above and @AurumCarlos's review on #3391: my #3391 (`mirror_draw`: one `VIEWS` lock per heap per draw instead of one per table entry) is the same cost as the title resource's `host` mutex 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 `mirror` 755 µs vs one batched call 547 µs under `VIEWS` contention (~1.4x), and 585 vs 627 µs uncontended (the batching's own `Vec` and 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.
KainanP commented 2026-11-27 12:02:20 +00:00 (Migrated from github.com)
Author
Contributor

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:

on main on the stack
base 2506 / 8959 · 2557 / 9047 1110 / 1488 · 1114 / 1460
#3249 −85…−127 / noise ±0 / ±0
#3379 −27…−105 / noise −49…−67 / −41…−57
#1825 ±0 / noise ±0 / ±0
#3218 ±0 / noise ±0 / ±0

(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.)

  • #3379 is the only one that moves the stack, about 4–6 % on one thread and 3–4 % on five. It merges with a one-line conflict against #1356 in readable.
  • #3249: on this bench its gain is the texture clone that transition no 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.
  • #1825 is covered by #3379's general keep dedup. #3218 targets a fragmented or saturated dynamic range, which this bench doesn't create.
  • All four pass their own tests on the RTX and add no failures, on main (only the #1744 pair) or on the stack. The stack's port of #3405 fails its own a_list_lends_a_read_copy_only_while_it_is_the_textures at 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 shadows first with Arc::downgrade(&first) without dropping the strong Arc, 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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7217764993 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/2586#issuecomment-7217764993). Originally posted by [KainanP](https://github.com/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: | | on main | on the stack | |---|---|---| | base | 2506 / 8959 · 2557 / 9047 | 1110 / 1488 · 1114 / 1460 | | #3249 | **−85…−127** / noise | ±0 / ±0 | | #3379 | −27…−105 / noise | **−49…−67 / −41…−57** | | #1825 | ±0 / noise | ±0 / ±0 | | #3218 | ±0 / noise | ±0 / ±0 | (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`.) - **#3379** is the only one that moves the stack, about 4–6 % on one thread and 3–4 % on five. It merges with a one-line conflict against #1356 in `readable`. - **#3249**: on this bench its gain is the texture clone that `transition` no 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. - **#1825** is covered by #3379's general `keep` dedup. **#3218** targets a fragmented or saturated dynamic range, which this bench doesn't create. - All four pass their own tests on the RTX and add no failures, on `main` (only the #1744 pair) or on the stack. The stack's port of #3405 fails its own `a_list_lends_a_read_copy_only_while_it_is_the_textures` at 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 shadows `first` with `Arc::downgrade(&first)` without dropping the strong `Arc`, 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)._
Fran-co-F commented 2026-11-29 03:25:29 +00:00 (Migrated from github.com)
Author
Contributor

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):

draws/frame windows median real fps
1,000-3,000 7 29.0
3,000-5,000 21 24.0
5,000-7,000 26 19.3
> 7,000 23 11.8
  • Correlation of fps with draws over the session: −0.68.
  • The submitting thread of ours (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.
  • Standing in a static scene the same build runs about 3,000 draws per frame and its numbers look fine. Moving into the street pushes it to 9,700-13,800 draws, and the worst windows drop to 5-9 fps.

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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7250039120 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/2586#issuecomment-7250039120). Originally posted by [Fran-co-F](https://github.com/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](https://github.com/Slaktarn700/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): | draws/frame | windows | median real fps | |---|---|---| | 1,000-3,000 | 7 | 29.0 | | 3,000-5,000 | 21 | 24.0 | | 5,000-7,000 | 26 | 19.3 | | > 7,000 | 23 | 11.8 | - Correlation of fps with draws over the session: −0.68. - The submitting thread of ours (`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. - Standing in a static scene the same build runs about 3,000 draws per frame and its numbers look fine. Moving into the street pushes it to 9,700-13,800 draws, and the worst windows drop to 5-9 fps. 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.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory#2584
No description provided.