Skip to content

tuning-v3: from 132 to 99 ms a frame on an i5-10400F (CBV_ROOT, CBV_CARD, measured switches) - #3102

Draft
Sumo1433 wants to merge 56 commits into
trustno1-coder:mainfrom
Sumo1433:tuning-v3
Draft

Sumo1433 wants to merge 56 commits into
trustno1-coder:mainfrom
Sumo1433:tuning-v3

Conversation

@Sumo1433

Copy link
Copy Markdown

tuning-v3: how I got my 6-core PC from 132 to 99 ms a frame

Hi. I play on an i5-10400F, and for me the game was stuck around 7 real fps. For the last few days I've been digging into where the frame goes and trying things. This branch is what came out of it. I'm sharing it because some of it may help people with a similar CPU, and because I'd really like a second pair of eyes on it.

My PC: i5-10400F (6 cores / 12 threads), RTX 4070 12 GB, 32 GB DDR4-2666, Windows 11. In game: Series X mode, 1080p, DLSS Performance, frame generation 2X.

The branch is built on main d459907 from 28.11, so the 29.11 releases aren't in it.

Numbers

Same street, standing still, about 10,000 draws a frame:

Build ms per frame real fps with FG 2X
v2026.11.28.03 136–161 6–7 12–15
main d459907 132 7.5 ~15
this branch 99 ~10 ~20

That's still not 30 fps, but it's playable now. All of it was measured on my one PC, so take it as a data point, not a promise.

What actually holds the frame on a CPU like mine

The card is mostly idle. Two things matter:

  • The submitting thread prepares submissions one after another. If it works 110 ms a frame, the frame is at least 110 ms.
  • The THIN threads translate the game's command lists into D3D12 calls in parallel.

You can see which one is your wall in the log: compare that thread worked X ms with your ms/frame. For me they ended up almost equal, so the submitting thread was the thing to fix.

What helped

VICTORY_CBV_ROOT=1 (new here)

Most draws read their constants through descriptor tables, and those tables were being rebuilt for almost every draw, about 12,000 a frame for me. With this switch the shader translator reads those constants through root views (t240..t243) instead. The table stays the same and gets reused.

For me: 12,000 → 6,000 rebuilt tables a frame, and THIN CPU time went from 540–557 to 458 ms a frame.

Downside: the shader cache key changes, so the first start rebuilds the cache (--preload, about 20 minutes for me). After that, always start with the same switch.

VICTORY_CBV_CARD (new here, on by default)

This one came from reading my own logs after CBV_ROOT. Some of those constants are written by the game's compute shaders, so every frame the CPU sat and waited for the card to finish before it could copy them: about 26 ms in a single wait. Now the card does that copy itself, in the right order (needs VICTORY_CARD_STEPS=2, which is the default here).

A/B inside one run, 16 phases of 20 s each:

  • waits for the card: 41 → 3 ms a frame
  • submitting thread: 114 → 90 ms
  • frame: 120 → 99 ms, p90 155 → 108 ms
  • no device lost

It only does anything together with CBV_ROOT. VICTORY_CBV_CARD=0 turns it off.

VICTORY_THIN_THREADS

Going from 4 to 8 saved me 9.6 ms. 12 was no better than 8. If you have more cores, I'd start at logical threads minus 4 and try ±2. You can compare inside one run: VICTORY_THIN_THREADS=N, VICTORY_THIN_ACTIVE=M (M smaller), VICTORY_AB=20,VICTORY_THIN_MORE.

VICTORY_PORT_CONSTANTS=1

On my PC it took 12.8 ms off the submitting thread. But PR #2923 says it starves the card over PCIe and should stay off, and the original author saw it get worse on a 12 GB card. So I honestly don't know how it behaves on other machines. Please measure it on yours before keeping it.

Smaller ones I kept

My launch switches:

--set VICTORY_THIN_THREADS=8 --set VICTORY_PORT_CONSTANTS=1 --set VICTORY_SPARE_SCRATCH_MB=512
--set VICTORY_CARD_AWAKE=0 --set VICTORY_LIST_VIEWS_KEEP=1 --set VICTORY_SWEEP_ASIDE=1
--set VICTORY_CBV_ROOT=1

If your PC is different

  • More cores: raise VICTORY_THIN_THREADS (see above).
  • Older board or slow PCIe: try with VICTORY_PORT_CONSTANTS off.
  • 16 GB of RAM: lower VICTORY_SPARE_SCRATCH_MB to 128–256. It's PC memory kept around for reuse.
  • Resizable BAR on: VICTORY_WC_BAR=runs was slower for me. I haven't checked VICTORY_WC_BAR=1.
  • AMD card: I only tested CBV_ROOT and CBV_CARD on NVIDIA. I'd be very curious what happens.

What didn't help me

  • VICTORY_GUARD_HOT=50 made it 4.6 ms slower.
  • VICTORY_WC_BAR=runs, VICTORY_INPLACE=1, VICTORY_LIST_VIEWS_TEXTURES=1: no gain.
  • VICTORY_PAGE_STAMPS=1, my own VICTORY_LAZY_READS=1, VICTORY_HEAP_ROUND=64, GUARD_REST, UNDER_WIDE, LAND_ECHO: within noise.
  • DLSS Quality instead of Performance: costs card time when the CPU is the limit anyway.
  • Extra frame generation on top (MFG Unlocker, Lossless Scaling): at ~10 real fps it looks bad.

How I measure

The scene keeps changing (5,000 to 11,000 draws a frame), so two separate runs can't really be compared. I compare inside one run:

  1. Build with diagnostics: cargo build --profile diag --features diagnostics -p victory.
  2. Start with --set VICTORY_AB=20,SWITCH_A,SWITCH_B. The combination changes every 20 seconds.
  3. Stand somewhere busy for 5–8 minutes.
  4. Run python scripts/ab.py <log>. It brings all phases to the same number of draws and prints one line per combination, with its spread.

If the difference is smaller than the spread, it's noise. I learned that the hard way: a lot of my "wins" disappeared once I started measuring like this.

Known problems

  • CBV_ROOT means a long first start and a shader cache separate from your other builds.
  • Once, textures were black for a few seconds at the start of a run, then they loaded. I haven't seen it since.
  • Two tests fail here, same as on the base: ambient::raise_opt_in_chroma_scrub… (an opt-in feature that's off) and bury_drops_retired_objects_asynchronously (flaky under load).
  • One PC, one person. That's the main reason I'm posting this.

If you want to help

I'd be happy to hear from anyone who tries it, good results or bad. Post your CPU and card, ms/frame and that thread worked before and after, and the ab.py output. A bad result is useful too: it shows where a switch should stay off. The submitting thread still takes about 90 of my 99 ms, so that's where I'm looking next. If you have ideas there, I'm all ears.

Thanks

Most of this branch is other people's work that I merged and measured. Thank you:

I wrote parts of my own code with AI tools (Claude, Codex, Gemini). Every switch here was checked in the game before I kept it.

mikael-jarvinen and others added 30 commits November 28, 2026 12:59
…d ahead ranges, chunked journal checks, and folded Shadow::ranged
…oost

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e first one that waits for flights before the wait
…while a submission asks the write watch, so recording threads stop queueing on the memory mutex behind it
… indirect buffers' moves to common when a list closes
…s movie lease says

On d459907 the movie-plane gate held all 1,884 gameplay presents off while
DLSS upscaled normally (Bink calls go on during play). VICTORY_DLSSG_MOVIE_GATE=1
brings the old gate back. Prepared by Codex (codex-main worktree).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t list until its reset, so lists the title keeps hold no allocators, off by default
…the list bound before at the same epoch and buffer count without looking it up and asking its refresh again
With HDR on in Windows and HDR on in the F1 menu (VICTORY_HDR=1), the title renders HDR and the layer presents it as HDR10 at the luminance of the display. The interface and the layer's own overlays are at paper white (VICTORY_HDR_PAPER_WHITE, 203 nits by default).
…tants heap)

Conflicts with main's card_has_before(): its helper kept, trustno1-coder#501's lazy sweep added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hunks are kept

On a 32 GB PC the 128 MiB were too few outdoors: some 12 chunks a frame were
made anew, 4-5 ms of the frame waiting for new memory (tuning-v3, 29.11).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… not shader writes)

Conflicts: draw.rs keeps main's diagnostics wide_write beside trustno1-coder#1014's shader_writes;
host.rs runs both lazy_found and check_gpu_ro.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With VICTORY_SWEEP_AHEAD the sweep already lets go only through retire, but it
still took the submitting thread some 45 ms once a second (8-9 ms a frame).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
local and others added 26 commits November 29, 2026 03:59
In a profile the sweep took 9.8 % of the submitting thread, some 65 ms once a
second: slot_evict's look over every slot of the heaps (slots_showing, SipHash
sets) and let_go_idle's over every texture. It lets go through retire and only
what no list holds, as with VICTORY_SWEEP_AHEAD.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dings

Port of tuning's 893d3a3/261024e/7682e36 onto main: views were made again in
every recording (make_twinned 15 % of the translating threads in a profile of
29.11). A view of another recording is used again if its buffer identity holds,
now with where the view begins in its copy (kept copies are reused, trustno1-coder#181).
Pairs of slots are evicted by a clock instead of clearing all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…IDE in diagnostics builds

The keeping's slots are cleared when it is switched: the pairs of one way are
not known to the other.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… slot was looked at again

The part of the slots not written that each pass looks at was most of the pass's
28 ms of the helpers' CPU a frame. VICTORY_AB may switch 16 and 64 (HEAP_ROUND_LONG).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pair_for looked each of up to 8 owners up in the map to see if this recording used
it (3.2 % of the translating threads); the clock reads the owner's recording now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cherry-picked without the PR's base merges (no shader changes, no rewarm).
Kept ours where both sides did the same work: trustno1-coder#1609's KEPT/merged/ahead_covers
over their AHEAD_KEPT/normalized/covers (VICTORY_AHEAD_SEARCH dropped),
ours bury pool (now behind VICTORY_BURY_ASIDE), card_take/card_record split
(their sync-list join of SUBMIT_FAST_2 dropped). SWEEP_ASYNC and SWEEP_ASIDE
both kept. Dead-RT reclaim and aliased_rt left out (from 6ba7fa8, not here).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e dwords the title changed

WC_BAR=1 rewrote whole pages of write-combined buffers mapped on the card and took back what shaders wrote (upstream trustno1-coder#553). =runs compares title memory with a reference and writes changed dwords only; copies below VICTORY_WC_NO_BACK_MIN_KB keep two sides (trustno1-coder#355/trustno1-coder#481).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s' unaligned raw twins moved, not nulled), trustno1-coder#2226 (HOST_WRITTEN behind RwLock), trustno1-coder#2116 (small safe copies by SSE2, VICTORY_SMALL_COPY), trustno1-coder#2062 (committed bytes between views in sparse texture reads)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lating threads compared within a run); port of trustno1-coder#1735's thin.rs part (VICTORY_THIN_REPEAT)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, slots), direct entries and make_listed outcomes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…across recordings by their host texture, first level shown, base and view words

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t SRVs (promoted_cbvs), kept in the shader cache after the other fields only when there are some

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es through root SRVs t240..t243 (raw loads of a snapshot the host binds at each draw); a table whose constant buffers are all read so leaves them out of its plan, so it is no longer made afresh for every draw

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The XMA thread spent 1,170 of 5,345 sampled stacks in VLC decoding.
Read a wide word when available and use an 8-bit prefix table when the
legacy search agrees on every suffix. Keep PCM and error behavior
identical and keep the legacy path with VICTORY_XMA_FAST_BITS=0.

Release, four frames per 2 KiB packet: mono 56.78 -> 37.28 us,
stereo 112.29 -> 76.49 us. Tests compare PCM, overlap, errors and
bit positions across the two paths.
Keep one scratch buffer per APU connection and zero the live PCM span
for each packet. Avoid allocating and zeroing up to 45 KiB per
PROCESS while preserving decoding, trimming, PCM and results.
VICTORY_OPUS_REUSE_PCM=0 selects the old allocation.

Release A/B in apu::process, us/packet:
CELT mono 9.31 -> 8.63, stereo 45.99 -> 44.51,
SILK mono 12.78 -> 12.04, hybrid mono 27.71 -> 27.41.
Compare the bytes and results from both paths on 16 saved packets,
malformed input and 120 ms repacketized inputs.
… give the host the end of them (max_end): the snapshot holds at least that, zeros past the buffer's size (a root SRV is unbounded; reads past the snapshot removed the device)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…from a table by page, not a walk of the journal's tree

Of 5,500 refreshes a frame 4,600 copy nothing (log of 2026-11-29), most of
them the heap's buffer views, one copy each, every frame. Each was told so by
a walk of the journal's tree of every page ever found written, down from its
root, the copies in no order of their addresses: JournalView::nothing_new was
3 % of the submitting thread's samples (profile of 2026-11-29), and the same
walks ran on the helpers.

The journal keeps the same as a table by page, the asking that last found it
written, with the latest of each 1 MiB beside it, under its lock. A range
nothing wrote since the copy took it whole is told in one look per 1 MiB, the
rest page by page against what the copy took when, as the tree is. The answer
is the tree's (watch::stamps_tests, refresh_tests::stamps_tell_what_the_tree_tells),
and refreshed ranges hold title memory with it
(refreshed_ranges_hold_title_memory_with_stamps, unchanged_ranges_are_known_by_stamps).

Measured in refresh_tests::clean_copies_told_so (4,400 copies as they were,
release, Wine on a 2-core VM, three runs): 153-264 ns a copy by the tree,
77-116 by the table, journals of 120,000 and 400,000 pages; the batch's flush
of them on two threads 757-908 us, 373-418. refresh_tests::frame_of_refreshes:
45.8 and 46.4 ms a frame, 44.7 and 44.3.

Off by default. Kept from the first note when the switch is set or VICTORY_AB
names it (diagnostics: VICTORY_AB=20,VICTORY_PAGE_STAMPS), else not at all:
544 KiB per 4 GiB of address space written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ShC5KuZncUedmxu6SXXK4G
…efer_fill_buffer, which with VICTORY_CARD_STEPS fills a buffer from its start: the constants went over the chunk's first bytes and the device hung

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… submission, so the same for every draw of the list), as fresh tables are: the fills per draw tripled the submitting thread's fills

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…once per view and list until a title copy (the lookup of its host copy was most of it)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…an write is filled by the card at its place (FillTo::Buffer has an offset), so constants a flight's shaders write no longer hold the submitting thread until it lands (10-26 ms a frame with CBV_ROOT)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…) waits for flights 41 -> 3 ms a frame, submitting thread 114 -> 90 ms, frame 120 -> 99 ms; =0 turns it off

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…it yourself, thanks) and scripts/ab.py for VICTORY_AB phases

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants