Keep refreshes in front across title writes that miss them (VICTORY_KEEP_AHEAD) #388

Closed
SmartIngenieriayDesarrollo wants to merge 656 commits from upstream-pr/388 into main
SmartIngenieriayDesarrollo commented 2026-11-27 23:26:21 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by SmartIngenieriayDesarrollo on 2026-11-27T23:26:21Z.


Most refreshes in a frame copy nothing. I counted 85 to 89 % of 9,000–11,000 refreshes per frame coming back empty, about 38 ms of the submitting thread. Almost all of that waste starts with one small write.

When a submission copies a few bytes into title memory, either a buffer copy done at submission or a placed copy at its place in the lists, Batch::title_written throws away every copy that refresh_front / refresh_ahead had already brought up to date. Every later list then adds, flushes and checks those copies again, even though the write touched none of them.

With VICTORY_KEEP_AHEAD=1 (off by default), such a write drops only the copies whose refreshed range contains one of its bytes:

  • byte for byte, not by 64 KiB page;
  • pending refreshes are still flushed before the write, and textures are still checked again after it;
  • a write into memory that physical-page views show (inplace::shown_bytes) still drops everything, as today;
  • Step::Run work, which may write anywhere, is unchanged;
  • diagnostics builds log per frame how many writes kept copies, and how many copies were kept and dropped.

Measured on a Ryzen 7 5700X3D with one DDR4-3200 module (single channel) and an RX 7800 XT, Series S, Vice-Tay 791648b plus a frame CSV patch: a 120 s cutscene, runs A B B A, 10.94 → 11.98 fps (+9.5 %).

  • Both B runs were outside the A range.
  • Preparation fell 9.9 % and copies 20.6 %.
  • The p10 frame rate rose 12.7 %.

I kept it on through the rest of my tuning, but I haven't repeated an alternating A/B on current main (0148258).

On a PC like mine every flush is memory bandwidth taken from the frame. On a high-end PC it is still submitting-thread time handed back.

Two tests cover it: a_title_write_drops_only_the_ranges_ahead_it_touches (the batch bookkeeping) and a_title_write_refreshes_again_only_the_copies_it_touches. The second runs a real copy over the end of one range and checks that every host copy still matches title memory, with the switch on and off. Checks: cargo clippy -p victory-gpu --all-targets --locked -- -D warnings is clean and cargo test -p victory-gpu --lib --locked gives 529 passed, 0 failed, the two new tests included (Windows 11, MSVC, the repo toolchain). cargo fmt --check only flags files this PR does not touch.

— El_Santo

AI-assisted; measured and tested on my machine.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:issue:5534405721 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/388). Originally posted by [SmartIngenieriayDesarrollo](https://github.com/SmartIngenieriayDesarrollo) on 2026-11-27T23:26:21Z. --- Most refreshes in a frame copy nothing. I counted 85 to 89 % of 9,000–11,000 refreshes per frame coming back empty, about 38 ms of the submitting thread. Almost all of that waste starts with one small write. When a submission copies a few bytes into title memory, either a buffer copy done at submission or a placed copy at its place in the lists, `Batch::title_written` throws away every copy that `refresh_front` / `refresh_ahead` had already brought up to date. Every later list then adds, flushes and checks those copies again, even though the write touched none of them. With `VICTORY_KEEP_AHEAD=1` (off by default), such a write drops only the copies whose refreshed range contains one of its bytes: - byte for byte, not by 64 KiB page; - pending refreshes are still flushed before the write, and textures are still checked again after it; - a write into memory that physical-page views show (`inplace::shown_bytes`) still drops everything, as today; - `Step::Run` work, which may write anywhere, is unchanged; - diagnostics builds log per frame how many writes kept copies, and how many copies were kept and dropped. Measured on a Ryzen 7 5700X3D with one DDR4-3200 module (single channel) and an RX 7800 XT, Series S, Vice-Tay `791648b` plus a frame CSV patch: a 120 s cutscene, runs A B B A, **10.94 → 11.98 fps (+9.5 %)**. - Both B runs were outside the A range. - Preparation fell 9.9 % and copies 20.6 %. - The p10 frame rate rose 12.7 %. I kept it on through the rest of my tuning, but I haven't repeated an alternating A/B on current `main` (`0148258`). On a PC like mine every flush is memory bandwidth taken from the frame. On a high-end PC it is still submitting-thread time handed back. Two tests cover it: `a_title_write_drops_only_the_ranges_ahead_it_touches` (the batch bookkeeping) and `a_title_write_refreshes_again_only_the_copies_it_touches`. The second runs a real copy over the end of one range and checks that every host copy still matches title memory, with the switch on and off. Checks: `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` is clean and `cargo test -p victory-gpu --lib --locked` gives 529 passed, 0 failed, the two new tests included (Windows 11, MSVC, the repo toolchain). `cargo fmt --check` only flags files this PR does not touch. — El_Santo _AI-assisted; measured and tested on my machine._
chatgpt-codex-connector[bot] commented 2026-11-27 23:26:33 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by chatgpt-codex-connector[bot] on 2026-11-27T23:26:33Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T23:29:08.070462Z 0334d59 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7230144030 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/388#issuecomment-7230144030). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-27T23:26:33Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"0334d598083f7e8b1015c316f2b60485acbee4f4","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-27T23:29:08.070462Z">2026-11-27T23:29:08.070462Z</relative-time> | `0334d59` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
akimfomin commented 2026-11-28 00:04:00 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by akimfomin on 2026-11-28T00:04:00Z.


I ran PortBridge’s tree check between #388 0334d59 and #379 ecc003e. The pair combines without a Git conflict. There is one useful combined control: exercise #379’s mapped alias with KEEP_AHEAD both off and on. Pre-refresh a buffer through view B, write through view A, then verify the refreshed bytes through B and both texture heaps’ notices. #388 already falls back to a full refresh for any mapped portion of the write; the combined check would preserve that guard if the PRs land together. The tree check and source review are from PortBridge, with no new GPU run.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7230619436 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/388#issuecomment-7230619436). Originally posted by [akimfomin](https://github.com/akimfomin) on 2026-11-28T00:04:00Z. --- I ran PortBridge’s tree check between #388 `0334d59` and #379 `ecc003e`. The pair combines without a Git conflict. There is one useful combined control: exercise #379’s mapped alias with KEEP_AHEAD both off and on. Pre-refresh a buffer through view B, write through view A, then verify the refreshed bytes through B and both texture heaps’ notices. #388 already falls back to a full refresh for [any mapped portion of the write](https://github.com/TaynanGT/Vice-Tay/blob/0334d598083f7e8b1015c316f2b60485acbee4f4/crates/victory-gpu/src/inplace.rs#L485-L499); the combined check would preserve that guard if the PRs land together. The tree check and source review are from [PortBridge](https://github.com/akimfomin/PortBridge), with no new GPU run.
Garu667 commented 2026-11-28 02:27:55 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by Garu667 on 2026-11-28T02:27:55Z.


Tested on NVIDIA: RTX 3080 10 GB, i5-13600K, 32 GB. Series S, automatic NVIDIA profile. One build, fe7c6e5 + 0334d59, switching only VICTORY_KEEP_AHEAD. Same boat save each run: prologue recap, then the fishing cutscene. About 4 min of play, one interval per 5 s. Runs in order A B A B.

Run KEEP_AHEAD Median FPS Mean FPS P10 Intervals < 5 FPS Preparing (median)
223 off 13.6 12.3 2.4 12 48.5 ms
224 on 17.2 16.0 3.6 5 41.6 ms
225 off 16.4 15.2 3.1 7 44.9 ms
226 on 16.4 16.1 8.6 3 42.7 ms

Both "on" runs are above both "off" runs on mean FPS and preparation time. Against the closer off run (225), that is about +6 % mean FPS and -6 % preparation. The log shows the switch doing its job: 1,700–5,100 copies kept and 13–14 dropped per frame.

I saw no picture difference between the two settings in the captures. Caveat: these runs had no VICTORY_BCPACK_TABLES, so BCPack textures were noise in all four. The workload is the same on both sides, but textures were not checked.

🤖 Generated with Claude Code

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7232379793 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/388#issuecomment-7232379793). Originally posted by [Garu667](https://github.com/Garu667) on 2026-11-28T02:27:55Z. --- Tested on NVIDIA: RTX 3080 10 GB, i5-13600K, 32 GB. Series S, automatic NVIDIA profile. One build, `fe7c6e5` + `0334d59`, switching only `VICTORY_KEEP_AHEAD`. Same boat save each run: prologue recap, then the fishing cutscene. About 4 min of play, one interval per 5 s. Runs in order A B A B. | Run | KEEP_AHEAD | Median FPS | Mean FPS | P10 | Intervals < 5 FPS | Preparing (median) | | --- | :---: | ---: | ---: | ---: | ---: | ---: | | 223 | off | 13.6 | 12.3 | 2.4 | 12 | 48.5 ms | | 224 | **on** | 17.2 | 16.0 | 3.6 | 5 | 41.6 ms | | 225 | off | 16.4 | 15.2 | 3.1 | 7 | 44.9 ms | | 226 | **on** | 16.4 | 16.1 | 8.6 | 3 | 42.7 ms | Both "on" runs are above both "off" runs on mean FPS and preparation time. Against the closer off run (225), that is about +6 % mean FPS and -6 % preparation. The log shows the switch doing its job: 1,700–5,100 copies kept and 13–14 dropped per frame. I saw no picture difference between the two settings in the captures. Caveat: these runs had no `VICTORY_BCPACK_TABLES`, so BCPack textures were noise in all four. The workload is the same on both sides, but textures were not checked. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Kal0s-design commented 2026-11-28 18:53:28 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by Kal0s-design on 2026-11-28T18:53:28Z.


Read through 0334d59 for a refresh that could be skipped when it shouldn't be, since the speed side is covered above.

  • title_wrote_keeping does what title_written does (flush with the write, textures.clear()), and only replaces ahead.clear() with a byte overlap filter. The flush still runs before the filter, so a pending refresh of a copy the write overlaps reads the bytes from before the write, then that copy leaves ahead and the next list refreshes it again. That's the same order as without the switch.
  • Batch::add only skips when the requested range is inside the kept (from, to). A list that later asks for more of a kept copy than was refreshed in front still refreshes it, so keeping a copy whose to ends before the write can't hide a write past to.
  • Copies that alias the written bytes at other addresses go through the shown_bytes fallback. Two shadows over the same addresses are compared by address, so both drop.
  • Step::Run and the non-free placed copies don't change.

Natively on Windows (NVIDIA card) the 159 host:: tests pass with VICTORY_KEEP_AHEAD=0 and with =1. The two new tests passed 100 of 100 repeated runs, and the branch merges cleanly on current main (fe7c6e5). It's based on 0148258, so a rebase wouldn't hurt before merging.

I found nothing to change.

AI-assisted: yes

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7244130930 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/388#issuecomment-7244130930). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-11-28T18:53:28Z. --- Read through `0334d59` for a refresh that could be skipped when it shouldn't be, since the speed side is covered above. - `title_wrote_keeping` does what `title_written` does (flush with the write, `textures.clear()`), and only replaces `ahead.clear()` with a byte overlap filter. The flush still runs before the filter, so a pending refresh of a copy the write overlaps reads the bytes from before the write, then that copy leaves `ahead` and the next list refreshes it again. That's the same order as without the switch. - `Batch::add` only skips when the requested range is inside the kept `(from, to)`. A list that later asks for more of a kept copy than was refreshed in front still refreshes it, so keeping a copy whose `to` ends before the write can't hide a write past `to`. - Copies that alias the written bytes at other addresses go through the `shown_bytes` fallback. Two shadows over the same addresses are compared by address, so both drop. - `Step::Run` and the non-free placed copies don't change. Natively on Windows (NVIDIA card) the 159 `host::` tests pass with `VICTORY_KEEP_AHEAD=0` and with `=1`. The two new tests passed 100 of 100 repeated runs, and the branch merges cleanly on current `main` (`fe7c6e5`). It's based on `0148258`, so a rebase wouldn't hurt before merging. I found nothing to change. AI-assisted: yes
SmartIngenieriayDesarrollo commented 2026-11-28 20:59:56 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by SmartIngenieriayDesarrollo on 2026-11-28T20:59:56Z.


Thanks for the independent checks, this is exactly what I hoped for.

  • @Garu667: the RTX 3080 / i5-13600K A B A B is very useful. It shows the gain isn't limited to single-channel DDR4: preparation −6 %, mean +6 %, and the P10 rose too. Thanks for counting kept and dropped copies.
  • @Kal0s-design: thanks for the careful read. You confirmed the two properties I cared about most: the flush still runs before the filter, and Batch::add refreshes a kept copy when a later list asks past its to.
  • @akimfomin: good idea on the #379 combined control. If both land, I'll run your pre-refresh-through-B / write-through-A case with the switch off and on.

It merges cleanly on fe7c6e5. I can rebase it if you'd like a fresh base.

— El_Santo

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7245696945 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/388#issuecomment-7245696945). Originally posted by [SmartIngenieriayDesarrollo](https://github.com/SmartIngenieriayDesarrollo) on 2026-11-28T20:59:56Z. --- Thanks for the independent checks, this is exactly what I hoped for. - @Garu667: the RTX 3080 / i5-13600K A B A B is very useful. It shows the gain isn't limited to single-channel DDR4: preparation −6 %, mean +6 %, and the P10 rose too. Thanks for counting kept and dropped copies. - @Kal0s-design: thanks for the careful read. You confirmed the two properties I cared about most: the flush still runs before the filter, and `Batch::add` refreshes a kept copy when a later list asks past its `to`. - @akimfomin: good idea on the #379 combined control. If both land, I'll run your pre-refresh-through-B / write-through-A case with the switch off and on. It merges cleanly on `fe7c6e5`. I can rebase it if you'd like a fresh base. — El_Santo
TaynanGT commented 2026-11-29 11:37:33 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-29T11:37:33Z.


Thanks for incorporating the independent checks. Please keep the combined #379 control separate from the isolated KEEP_AHEAD comparison, particularly the pre-refresh and alias-write ordering. The measured gains are encouraging but not a reason to broaden the default before correctness is checked.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7255239049 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/388#issuecomment-7255239049). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-29T11:37:33Z. --- Thanks for incorporating the independent checks. Please keep the combined #379 control separate from the isolated KEEP_AHEAD comparison, particularly the pre-refresh and alias-write ordering. The measured gains are encouraging but not a reason to broaden the default before correctness is checked.
TaynanGT commented 2026-11-30 17:10:23 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-30T17:10:23Z.


main has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current main and open a new PR; I'll review it there.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7285833570 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/388#issuecomment-7285833570). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-30T17:10:23Z. --- `main` has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current `main` and open a new PR; I'll review it there.

Pull request closed

Sign in to join this conversation.
No reviewers
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
TaynanGT/Vice-Tay!388
No description provided.