Skip to content

perf: opt-in AVX2 changed-run detection - #1233

Open
spk-c wants to merge 2 commits into
fxceless:mainfrom
spk-c:submit/avx2-changed-runs
Open

spk-c wants to merge 2 commits into
fxceless:mainfrom
spk-c:submit/avx2-changed-runs

Conversation

@spk-c

@spk-c spk-c commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Opt-in VICTORY_CHANGED_RUNS_AVX2=1 with runtime feature detection and SSE2 fallback; preserves the existing changed-run mode selection. Includes unaligned and short-input parity test and an ignored manual release microbenchmark. Related open PR #1178 adds AVX2 to other shadow/merge helpers; this focuses on the changed-run scanner, and any interaction should be reviewed. No end-to-end FPS claim.

Validation

All CI steps passed for this isolated change against the corrected test baseline in the fork: https://github.com/spk-c/victory-fork/actions/runs/45731796714.

This submission is a single commit rebased onto upstream a183ea2; exact-revision upstream CI is pending. Upstream's pre-existing CI failures are addressed separately in #1228. Draft pending baseline and upstream review. AI-assisted.

Independent validation

UwUCammie's parity and microbenchmark report on Ryzen 7 9700X / Wine 11.22 / znver5: unaligned and short-input cases passed; 16 MiB median SSE2 to AVX2 times (µs): equal 1594→1260, sparse 6092→4738, dense 39525→45255, all changed 1114→868. Four first-room pairs on 9700X/RX 7900 XT in an integration build gave 9.05 vs 9.10 FPS overall; differences +0.07, +0.00, +0.08, +0.06 FPS. These are independent integration results, not proof of a universal speedup or exact-head gameplay validation. Dense-case regression supports retaining opt-in.

Refresh against upstream 52ac4ec

New head db46f83d4b8fb37b46d5fbbd7aa40edcdd0fdd08; the AVX2/SSE2 parity test for unaligned and short inputs passed. No new performance benchmark. Clean isolated workspace Cargo Check and strict all-feature Clippy passed. Original commits are preserved. PR-only diff check passed. Full upstream CI approval and source-size policy fix #1357 remain pending.

Isolated contribution based on a183ea2. AI-assisted.

Copy link
Copy Markdown

Ran the parity test and the release microbenchmark on a Ryzen 7 9700X under Wine 11.22, with -C target-cpu=znver5. The unaligned and short-input cases passed. For the 16 MiB inputs, median SSE2 → AVX2 time was 1,594 → 1,260 µs for equal bytes, 6,092 → 4,738 µs for sparse changes, 39,525 → 45,255 µs for dense changes, and 1,114 → 868 µs for all bytes changed. These are synthetic timings. The dense case is a reason to keep the switch available when measuring gameplay. Tested integration

Copy link
Copy Markdown

I ran four first-room pairs on the 9700X / RX 7900 XT with this change in the gather-and-worker build. SSE2 gave 700 presents in 77.39 s (9.05 FPS). AVX2 gave 720 in 79.13 s (9.10 FPS). The four on-minus-off differences were +0.07, +0.00, +0.08 and +0.06 FPS. The AVX2 counter saw 929 MiB while enabled and zero while disabled.

The character and courtyard were visible at both checks. The sparse CPU fixture is quicker on this machine, but the first-room gain was small. Build, route and measurements

e4glevlr added a commit to e4glevlr/victory-fork that referenced this pull request Nov 26, 2026
3.1 Driver-call dedups from VIctory-NVIDIA (each on unless =0):
    - ca1d519, VICTORY_BIND_CACHE: set_targets does not set the same
      render targets and depth again. The views are compared (title
      resource, host texture, record words), not the handles. Merged with
      the target formats of Phase 2: formats are taken for every call,
      views are made only when the targets change. replay() forgets the
      targets for the new host list after a cut, State::reset() does on a
      title reset. The other OMSetRenderTargets calls here are on lists of
      their own (indirect, over) or at a list's close (the depth plane
      pass), after the title's last draw.
    - b32fb99, VICTORY_DECLARE_ONCE: a range shaders write is declared
      once until the list next writes title memory (Copy or Run steps,
      Deferred::title_written). The key holds this tree's `marked` flag
      too. Exact: Shadow::writing already takes each byte once per
      submission and later refreshes copy into the snapshot, so the
      skipped steps only repeated a flush and a lock.
    - ab86ef7: a pipeline a list binds again is not kept and named
      again (HostList::bind_pipeline). With the card's clock per pipeline
      (cardmeter) every bind still ends the span before it.
    - c96525d: a root constant buffer not 256-byte aligned is filled
      into scratch once per host list until the list next writes title
      memory (HostList::fill_scratch). Each part after a cut is a host
      list of its own, with its own scratch.

3.2 fxceless 32be36d (PR fxceless#1237) with PR fxceless#1245, VICTORY_LOOKUP_CACHE=1|alt
    (off by default): a thread remembers what its asks for a buffer's
    host copy found while the tables are unchanged. fxceless#1245: the
    generation is bumped after registering under the table lock, and a
    cached window is checked against the window table under its lock
    before it is handed out (both fxceless#1245 tests). Here as well: a buffer's
    copy in place is never cached, since in_place_let_go takes those out
    when their memory is about to be remapped. Every table change in this
    tree bumps the counter (register, unregister, in_place_let_go, the
    idle sweep, window creation).

3.3 fxceless PR fxceless#1240, the exact parts only:
    - VICTORY_RAM_TRIM_MB (off unless set): below that much available
      memory, the lesser of physical RAM and remaining commit (as fxceless#822's
      committed_cache_idle_ms already weighs them), the sweep runs every
      500 ms and also drains the reuse pools: CPU snapshot buffers, spare
      texture staging buffers, idle host lists past 16.
    - A descriptor page of zeros whose slots were never looked at is not
      fingerprinted (mirror_copied_page).
    - Not taken: VICTORY_TEXTURE_MAX_DIM (drops detail), skipping the
      zero fill of staging slices above the tail mip (would upload stale
      bytes where tiles are mapped), the batched mirror (a rewrite of
      mirror(), whose per-slot logic differs here), and the PR's own
      VICTORY_BIND_CACHE (3.1 has one).

3.4 fxceless PRs fxceless#1230, fxceless#1232, fxceless#1233:
    - fxceless#1230: contiguous readback pieces of one source join into one
      CopyBufferRegion (VICTORY_READBACK_COALESCE=1; off), with its tests.
    - fxceless#1232: join_ranges compacts in place (same result; test against
      the allocating form).
    - fxceless#1233: AVX2 changed-run detection (VICTORY_CHANGED_RUNS_AVX2=1 and a
      runtime avx2 check; off). This tree has no SSE2 form of
      changed_runs, so the AVX2 kernel and its mask walker were taken
      alone and checked against this tree's walk
      (avx2_changed_runs_match_the_walk).

3.5 WIDE scalar buffer loads (fxceless c36971b, shader part as in
    VIctory-NVIDIA 200a9cc) on bit 128: bit 64 stays MERGE. Not in ALL;
    VICTORY_SHADER_OPT=255 (or any value with 128) asks for it, since
    parse_shader_opt now masks with KNOWN = ALL | WIDE. The cache key
    already holds the whole mask. raw_dwords reads one console load four
    dwords a call on both raw smem paths; test
    scalar_buffer_loads_read_the_same_dwords_one_call_or_four (Windows,
    software adapter).

Gate: Windows check, diagnostics check, clippy -D warnings (default and
all features), tests 342 passed / 0 failed / 8 ignored, policy 230 files
ok, viz. victory-gpu tests and the Windows-only shader tests are built
and linted, not run (pc-home offline).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AI-assisted: keep original tested commit in history; local all-feature check, strict Clippy and focused synthetic tests passed. Upstream asset-policy baseline remains open (fxceless#1357).
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.

2 participants