gpu: opt-in zero-allocation thin-stream peephole folding (VICTORY_THIN_PEEPHOLE=1) #4886

Open
github-bot wants to merge 1 commit from github-bot/gh-4885 into main AGit
Owner

@⁠lyufeng000 on GitHub · 2026-12-01 12:47 UTC · original
lyufeng000:pr/thin-peephole → main · +1261 −86 · 1 files · 1 commits · open

Summary

Split out from Stage 0 of #4856 per @tikD1337's suggestion and A/B benchmarks as a clean, single-file, zero-extra-thread change (crates/victory-gpu/src/list/thin.rs).

Strictly opt-in behind VICTORY_THIN_PEEPHOLE=1 (off by default), leaving the default list::thin replay path completely untouched.


Architecture (PeepholeWindow / translate_peephole)

Stack-allocated, single-pass peephole optimizer placed ahead of list::thin replay:

  • Class A (scalar/pipeline state): folds consecutive writes and suppresses zero-diff redundant bindings (PIPELINE, ROOT, TOPOLOGY, STENCIL_REF, BLEND_FACTOR, SAMPLE_MASK, VIEWPORTS, SCISSORS, INDEX_BUFFER, TARGETS, HEAPS, SHADING_RATE), resetting committed history on RESET and CLEAR_STATE. TARGETS flushes any pending coalesced copy first to preserve copy-vs-target ordering.
  • Class B (root slots & vertex buffers): dead-write elimination for identical (kind, slot) or vertex-buffer range overwrites before a flush boundary.
  • Class C (barriers & contiguous copies): skips truly empty BARRIER/BARRIER_GROUPS (w[0] == 0) while strictly preserving upstream's bit-63 narrow BARRIER_GROUPS skip marker (w[0] == 1 << 63 -> state.synced()), and merges adjacent COPY_BUFFER/COPY_MEMORY calls under four gates (same kind/buffers, contiguous offsets, dst != src non-aliasing including buffer_base overlap check, and capped byte budget).
  • Hard boundaries & safety: draws, dispatches, clears, resolves, queries, waits, indirects, EXTERNAL, UPLOAD, and CLOSE flush all pending state in original order before replay, and abandoned recordings stop immediately before emitting actions.

Verification

  • Unit tests (cargo test --locked -p victory-gpu --lib list::thin::tests -- --test-threads=1): 10 passed; 0 failed (including all 4 new peep_* tests).
  • Clippy (cargo clippy --locked -p victory-gpu --lib --tests): 0 warnings in crates/victory-gpu/src/list/thin.rs.

Independent --release A/B Benchmarks (from #4856 by @tikD1337)

Measured on Ryzen 5 7600 (6C/12T) + RTX 4070 Ti SUPER 16 GB (Driver 621.1.0, ReBAR ON, VICTORY_SUBMIT_SPLIT=1, VICTORY_DLSS=1 Quality, Series S mode, 105 s steady 3D runs, 0 crashes):

Configuration 3D FPS (>=200 lists) Frame ms card (GPU) submit_prep Matched 5.5k–6.5k
Base (5fabb46e, PC=1) 23.24 43.03 ms 38.8 ms 35.6 ms 23.70 FPS
VICTORY_THIN_PEEPHOLE=1 solo (PC=1) 27.00 37.04 ms 34.2 ms 28.9 ms 27.40 FPS (+16.2%)
THIN_PEEPHOLE=1 + LOW_L0_DMA stack (PC=0) 27.52 36.34 ms 21.1 ms 32.9 ms 27.90 FPS (~10.9k heavy: 21.7 FPS vs 16.3)
**@⁠lyufeng000** on GitHub · 2026-12-01 12:47 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4885) `lyufeng000:pr/thin-peephole` → `main` · +1261 −86 · 1 files · 1 commits · open ## Summary Split out from Stage 0 of #4856 per `@tikD1337`'s suggestion and A/B benchmarks as a clean, single-file, zero-extra-thread change (`crates/victory-gpu/src/list/thin.rs`). Strictly opt-in behind **`VICTORY_THIN_PEEPHOLE=1`** (**off by default**), leaving the default `list::thin` replay path completely untouched. --- ## Architecture (`PeepholeWindow` / `translate_peephole`) Stack-allocated, single-pass peephole optimizer placed ahead of `list::thin` replay: - **Class A (scalar/pipeline state)**: folds consecutive writes and suppresses zero-diff redundant bindings (`PIPELINE`, `ROOT`, `TOPOLOGY`, `STENCIL_REF`, `BLEND_FACTOR`, `SAMPLE_MASK`, `VIEWPORTS`, `SCISSORS`, `INDEX_BUFFER`, `TARGETS`, `HEAPS`, `SHADING_RATE`), resetting committed history on `RESET` and `CLEAR_STATE`. `TARGETS` flushes any pending coalesced copy first to preserve copy-vs-target ordering. - **Class B (root slots & vertex buffers)**: dead-write elimination for identical `(kind, slot)` or vertex-buffer range overwrites before a flush boundary. - **Class C (barriers & contiguous copies)**: skips truly empty `BARRIER`/`BARRIER_GROUPS` (`w[0] == 0`) while strictly preserving upstream's bit-63 narrow `BARRIER_GROUPS` skip marker (`w[0] == 1 << 63` -> `state.synced()`), and merges adjacent `COPY_BUFFER`/`COPY_MEMORY` calls under four gates (same kind/buffers, contiguous offsets, `dst != src` non-aliasing including `buffer_base` overlap check, and capped byte budget). - **Hard boundaries & safety**: draws, dispatches, clears, resolves, queries, waits, indirects, `EXTERNAL`, `UPLOAD`, and `CLOSE` flush all pending state in original order before replay, and abandoned recordings stop immediately before emitting actions. --- ## Verification - **Unit tests (`cargo test --locked -p victory-gpu --lib list::thin::tests -- --test-threads=1`)**: **10 passed; 0 failed** (including all 4 new `peep_*` tests). - **Clippy (`cargo clippy --locked -p victory-gpu --lib --tests`)**: **0 warnings** in `crates/victory-gpu/src/list/thin.rs`. ### Independent `--release` A/B Benchmarks (from #4856 by `@tikD1337`) Measured on **Ryzen 5 7600 (6C/12T) + RTX 4070 Ti SUPER 16 GB** (Driver `621.1.0`, ReBAR ON, `VICTORY_SUBMIT_SPLIT=1`, `VICTORY_DLSS=1` Quality, Series S mode, 105 s steady 3D runs, 0 crashes): | Configuration | 3D FPS (`>=200` lists) | Frame ms | `card` (GPU) | `submit_prep` | Matched `5.5k–6.5k` | | --- | ---: | ---: | ---: | ---: | ---: | | **Base** (`5fabb46e`, `PC=1`) | 23.24 | 43.03 ms | 38.8 ms | 35.6 ms | 23.70 FPS | | **`VICTORY_THIN_PEEPHOLE=1` solo (`PC=1`)** | **27.00** | **37.04 ms** | **34.2 ms** | **28.9 ms** | **27.40 FPS (+16.2%)** | | **`THIN_PEEPHOLE=1` + `LOW_L0_DMA` stack (`PC=0`)** | **27.52** | **36.34 ms** | **21.1 ms** | 32.9 ms | **27.90 FPS** (`~10.9k` heavy: **21.7 FPS** vs 16.3) |
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 12:48:40 +00:00
Author
Owner

@⁠tikD1337 on GitHub · 2026-12-01 13:10 UTC · original

Thank you for splitting this out, @⁠lyufeng000 — and get some well-deserved rest!

Verified that crates/victory-gpu/src/list/thin.rs at #4885 head (1e4a174b) is byte-for-byte identical to the Stage 0 code from #4855 (bc15e0a5) tested earlier on origin/main (5fabb46e, Ryzen 5 7600 + RTX 4070 Ti SUPER, Win11 26300, Driver 621.1.0, DLSS Quality, 105 s steady 3D --release runs):

  • Single-file, 0 extra threads, opt-in behind VICTORY_THIN_PEEPHOLE=1 (off by default) -> zero default-path risk.
  • Isolated VICTORY_THIN_PEEPHOLE=1 solo gave 27.00 FPS (37.04 ms) vs 23.24 FPS (43.03 ms) base (+16.2%, submit_prep 35.6 -> 28.9 ms, card 38.8 -> 34.2 ms), 0 crashes (peep_* 4/4 PASS).
  • Stacked with POMXARK 01/03/04 + #4527 (VICTORY_PORT_CONSTANTS=0) hit 27.52 FPS (36.34 ms, 5.5k–6.5k: 27.90 FPS, ~10.9k: 21.7 FPS, card 21.1 ms), 0 crashes.

(FWIW to reviewers: the red CI check run is unrelated pre-existing clippy items in host/menu.rs and host/panel.rs on main, nothing in list/thin.rs.)

**@⁠tikD1337** on GitHub · 2026-12-01 13:10 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4885#issuecomment-7312204629) Thank you for splitting this out, @⁠lyufeng000 — and get some well-deserved rest! Verified that `crates/victory-gpu/src/list/thin.rs` at `#4885` head (`1e4a174b`) is byte-for-byte identical to the Stage 0 code from `#4855` (`bc15e0a5`) tested earlier on `origin/main` (`5fabb46e`, Ryzen 5 7600 + RTX 4070 Ti SUPER, Win11 `26300`, Driver `621.1.0`, DLSS Quality, `105 s` steady 3D `--release` runs): - Single-file, 0 extra threads, opt-in behind `VICTORY_THIN_PEEPHOLE=1` (off by default) -> zero default-path risk. - Isolated `VICTORY_THIN_PEEPHOLE=1` solo gave **27.00 FPS (`37.04 ms`)** vs **23.24 FPS (`43.03 ms`)** base (`+16.2%`, `submit_prep 35.6 -> 28.9 ms`, `card 38.8 -> 34.2 ms`), `0` crashes (`peep_*` `4/4 PASS`). - Stacked with `POMXARK 01/03/04` + `#4527` (`VICTORY_PORT_CONSTANTS=0`) hit **27.52 FPS** (`36.34 ms`, `5.5k–6.5k`: **27.90 FPS**, `~10.9k`: **21.7 FPS**, `card 21.1 ms`), `0` crashes. *(FWIW to reviewers: the red CI `check` run is unrelated pre-existing clippy items in `host/menu.rs` and `host/panel.rs` on `main`, nothing in `list/thin.rs`.)*
Author
Owner

@⁠POMXARK on GitHub · 2026-12-01 15:26 UTC · original

VERDICT: KEPT IN TREE (opt-in =0 default) — Unit tests PASS (minor test update noted), clean paired A/B is neutral on our 3.3k-draw cutscene once procmem aliasing is removed

Tested head 1e4a174b cleanly on top of v2026.11.30.03 (e1251c31).

Hardware & Setup

  • GPU / CPU / RAM / OS: RTX 5080 16 GB (ReBAR ON) / Ryzen 7 5700X (8C/16T) / 32 GB DDR4 / Windows 11 23H2
  • Profile: Series X, 1440p, DLSS Quality, warm shader cache, same --release binary toggled via --set VICTORY_THIN_PEEPHOLE=0 vs 1 with VICTORY_PROCESS_MEMORY=0 (eliminating the 5s VirtualQuery storm that previously aliased paired runs).

Unit Test Note

  • On v2026.11.30.03 (with query PRs merged), list::thin::tests::bindings_record_no_work failed (47 != 49) until Plain::BEGIN_QUERY and Plain::END_QUERY were added to the work list in thin.rs. After that fix: list::thin::tests 10/10 PASS.

Same-Binary Paired A/B (VICTORY_PROCESS_MEMORY=0, 45s 3D opening/diner cutscene)

Metric THIN_PEEPHOLE=0 med (p75) THIN_PEEPHOLE=1 med (p75) Delta med
FPS 18.65 (20.20) 17.50 (18.40) -1.15 (higher draw count)
frame_ms 53.65 ms (56.50) 57.15 ms (59.10) +3.50 ms
draws/frame 3,184 3,424 +240 (+7.5%)
Normalized ms / 1k draws 16.85 ms 16.70 ms -0.15 ms (-0.9%, neutral)
thin worker time / call 6.59 us/call 6.55 us/call -0.6% (neutral)
Repeated state calls folded 0 241 / frame working as intended
Screenshots / visual check Clean Clean (2/2 PNG verified, 0 artifacts) Clean

Summary: The peephole folding itself is clean, zero-thread, and folds ~241 redundant state calls/frame without visual regressions. On our 3.3k-draw cutscene with VICTORY_PROCESS_MEMORY=0 it measures neutral per draw/call (-0.9%), whereas on heavier draw windows (~10.9k draws, as @⁠tikD1337 measured) it should scale better. Kept in our build as opt-in (=0 default).

Full applied PR & patch chain on top of v2026.11.30.03 (e1251c31)
  • Upstream PRs already applied in this test tree: #4500 (Blackwell upload strides), #4501 (prebuild prologue irradiance-cache), #4496 (water tiled light VICTORY_WAVE_FOLDED_FIRST), #4506, #4545 (wide non-XOR texture detile cache tiling), #4558, #4567, #4571, #4648 (AVX2 landing), #4651 (SAME_PRINT), #4659 (TELEMETRY_OFF), #4885 (VICTORY_THIN_PEEPHOLE, opt-in).
  • Custom patch stack (POMXARK/victory-city-bench, patches/v2026.11.30.03/01..06, reviewed in Discussion #3556):
    • 01: COLD_WW_RO 1 MiB chunks + out-of-GUARDS 64-stripe VP_STRIPE
    • 02: VICTORY_STEPS_FAST=1 + VICTORY_LISTED_TWINS=0
    • 03: VICTORY_LOW_L0_DMA=1 (0xb10000 MEM_WRITE_WATCH 4K + L0→L1 GPU DMA)
    • 04: VICTORY_DESC_MIRROR_CAP=1 + VICTORY_SOFT_BATCH=1 (4 MiB LAZY_AT)
    • 05–06: Review hardening (ARMING bitmap + reopen_striped_block + real-path race test, dropped ahead_intact, strict per-range card_l0_dma_allows).
  • Runtime flags: --dlss quality, VICTORY_PROCESS_MEMORY=0, VICTORY_PORT_CONSTANTS=0, VICTORY_WC_BAR=3, VICTORY_CARD_CPU_FILE=0, VICTORY_MAP_ONCE=1, VICTORY_SCRATCH_CARD=1, VICTORY_ASK_FIRST=1, VICTORY_SWEEP_OFF_THREAD=0, VICTORY_DUE_INDEX=0, VICTORY_GUARD_SHARDED=1, VICTORY_STEPS_FAST=1, VICTORY_LISTED_TWINS=0, VICTORY_LOW_L0_DMA=1, VICTORY_DESC_MIRROR_CAP=1, VICTORY_SOFT_BATCH=1.
**@⁠POMXARK** on GitHub · 2026-12-01 15:26 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4885#issuecomment-7315911839) **VERDICT: KEPT IN TREE (opt-in `=0` default) — Unit tests PASS (minor test update noted), clean paired A/B is neutral on our 3.3k-draw cutscene once `procmem` aliasing is removed** Tested head `1e4a174b` cleanly on top of `v2026.11.30.03` (`e1251c31`). ### Hardware & Setup - **GPU / CPU / RAM / OS:** RTX 5080 16 GB (ReBAR ON) / Ryzen 7 5700X (8C/16T) / 32 GB DDR4 / Windows 11 23H2 - **Profile:** Series X, 1440p, DLSS Quality, warm shader cache, **same `--release` binary** toggled via `--set VICTORY_THIN_PEEPHOLE=0` vs `1` with `VICTORY_PROCESS_MEMORY=0` (eliminating the 5s `VirtualQuery` storm that previously aliased paired runs). ### Unit Test Note - On `v2026.11.30.03` (with query PRs merged), `list::thin::tests::bindings_record_no_work` failed (`47 != 49`) until `Plain::BEGIN_QUERY` and `Plain::END_QUERY` were added to the `work` list in `thin.rs`. After that fix: **`list::thin::tests` 10/10 PASS**. ### Same-Binary Paired A/B (`VICTORY_PROCESS_MEMORY=0`, 45s 3D opening/diner cutscene) | Metric | `THIN_PEEPHOLE=0` med (p75) | `THIN_PEEPHOLE=1` med (p75) | Delta med | |---|---:|---:|---:| | **FPS** | `18.65` (`20.20`) | `17.50` (`18.40`) | `-1.15` (higher draw count) | | **frame_ms** | `53.65 ms` (`56.50`) | `57.15 ms` (`59.10`) | `+3.50 ms` | | **draws/frame** | `3,184` | `3,424` | `+240 (+7.5%)` | | **Normalized ms / 1k draws** | **`16.85 ms`** | **`16.70 ms`** | **`-0.15 ms (-0.9%, neutral)`** | | **thin worker time / call** | `6.59 us/call` | `6.55 us/call` | **`-0.6% (neutral)`** | | **Repeated state calls folded** | `0` | **`241 / frame`** | **working as intended** | | **Screenshots / visual check** | Clean | Clean (`2/2` PNG verified, 0 artifacts) | Clean | **Summary:** The peephole folding itself is clean, zero-thread, and folds ~241 redundant state calls/frame without visual regressions. On our 3.3k-draw cutscene with `VICTORY_PROCESS_MEMORY=0` it measures neutral per draw/call (`-0.9%`), whereas on heavier draw windows (`~10.9k` draws, as @⁠tikD1337 measured) it should scale better. Kept in our build as opt-in (`=0` default). <details> <summary>Full applied PR &amp; patch chain on top of <code>v2026.11.30.03</code> (<code>e1251c31</code>)</summary> - Upstream PRs already applied in this test tree: `#4500` (Blackwell upload strides), `#4501` (prebuild prologue irradiance-cache), `#4496` (water tiled light `VICTORY_WAVE_FOLDED_FIRST`), `#4506`, `#4545` (wide non-XOR texture detile cache tiling), `#4558`, `#4567`, `#4571`, `#4648` (AVX2 landing), `#4651` (`SAME_PRINT`), `#4659` (`TELEMETRY_OFF`), `#4885` (`VICTORY_THIN_PEEPHOLE`, opt-in). - Custom patch stack (`POMXARK/victory-city-bench`, `patches/v2026.11.30.03/01..06`, reviewed in Discussion #3556): - `01`: `COLD_WW_RO` 1 MiB chunks + out-of-`GUARDS` 64-stripe `VP_STRIPE` - `02`: `VICTORY_STEPS_FAST=1` + `VICTORY_LISTED_TWINS=0` - `03`: `VICTORY_LOW_L0_DMA=1` (`0xb10000` MEM_WRITE_WATCH 4K + L0→L1 GPU DMA) - `04`: `VICTORY_DESC_MIRROR_CAP=1` + `VICTORY_SOFT_BATCH=1` (4 MiB `LAZY_AT`) - `05`–`06`: Review hardening (`ARMING` bitmap + `reopen_striped_block` + real-path race test, dropped `ahead_intact`, strict per-range `card_l0_dma_allows`). - Runtime flags: `--dlss quality`, `VICTORY_PROCESS_MEMORY=0`, `VICTORY_PORT_CONSTANTS=0`, `VICTORY_WC_BAR=3`, `VICTORY_CARD_CPU_FILE=0`, `VICTORY_MAP_ONCE=1`, `VICTORY_SCRATCH_CARD=1`, `VICTORY_ASK_FIRST=1`, `VICTORY_SWEEP_OFF_THREAD=0`, `VICTORY_DUE_INDEX=0`, `VICTORY_GUARD_SHARDED=1`, `VICTORY_STEPS_FAST=1`, `VICTORY_LISTED_TWINS=0`, `VICTORY_LOW_L0_DMA=1`, `VICTORY_DESC_MIRROR_CAP=1`, `VICTORY_SOFT_BATCH=1`. </details>
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/4886/head:github-bot/gh-4885'
git switch 'github-bot/gh-4885'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-4885'
git switch 'github-bot/gh-4885'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-4885'
git switch 'github-bot/gh-4885'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-4885'
git switch 'main'
git merge --squash 'github-bot/gh-4885'
git switch 'main'
git merge --ff-only 'github-bot/gh-4885'
git switch 'main'
git merge 'github-bot/gh-4885'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!4886
No description provided.