GPU: coalesce identical write declarations within a submission #435

Open
melon0918 wants to merge 1 commit from upstream-pr/435 into main
melon0918 commented 2026-11-24 03:20:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by melon0918 on 2026-11-24T03:20:53Z.


What changed

World passes declare the same writable shadow-buffer ranges repeatedly. Each repeat used to flush the accumulated refreshes, even after the first declaration had taken the pre-submit snapshot and marked that exact range pending. Store the first declaration per shadow, address and length in the submission batch. Use that same ordered list for copy-back after the fence, replacing the second pass over the deferred command steps.

Verification

  • Windows 10 22H2, RX 7900 XT, AMD driver 25.5.1. cargo test --locked -p victory-gpu --features diagnostics -- --test-threads=1 passed 46 tests with one existing benchmark ignored. The added test covers repeated declarations, overlapping ranges, distinct shadows, and submission boundaries.
  • Compared hardware diagnostic runs of the same local integration stack with this change toggled. Across the first ten comparable world log windows after the transition, median reported CPU copy time was 768 ms/frame before and 109 ms/frame after. These are two real runs with varying draw counts and pipeline compilation, so the numbers describe the observed workload rather than a controlled frame-rate benchmark. The 3D picture is still incomplete.
  • cargo xtask policy passed. The PR contains only source and a synthetic test. AI-assisted (Codex).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6573867547 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/435). Originally posted by [melon0918](https://github.com/melon0918) on 2026-11-24T03:20:53Z. --- ### What changed World passes declare the same writable shadow-buffer ranges repeatedly. Each repeat used to flush the accumulated refreshes, even after the first declaration had taken the pre-submit snapshot and marked that exact range pending. Store the first declaration per shadow, address and length in the submission batch. Use that same ordered list for copy-back after the fence, replacing the second pass over the deferred command steps. ### Verification - Windows 10 22H2, RX 7900 XT, AMD driver 25.5.1. `cargo test --locked -p victory-gpu --features diagnostics -- --test-threads=1` passed 46 tests with one existing benchmark ignored. The added test covers repeated declarations, overlapping ranges, distinct shadows, and submission boundaries. - Compared hardware diagnostic runs of the same local integration stack with this change toggled. Across the first ten comparable world log windows after the transition, median reported CPU copy time was 768 ms/frame before and 109 ms/frame after. These are two real runs with varying draw counts and pipeline compilation, so the numbers describe the observed workload rather than a controlled frame-rate benchmark. The 3D picture is still incomplete. - `cargo xtask policy` passed. The PR contains only source and a synthetic test. AI-assisted (Codex).
mercuryVM commented 2026-11-24 06:53:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T05:41:20Z.

Review: APPROVED


Tested 657efd8 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (265 passed, 0 failed).

I checked that dropping the repeated flush() + writing() keeps behaviour the same:

  • For a range already declared, Shadow::writing already returned early. The merged snapshot range equals the existing one, so the snapshot was never retaken. The only effects of a repeat were an extra pending entry and an extra refresh flush.
  • Refreshes queued between two declarations are still flushed by the next title_written() step or by the batch flush before the lists run. The copy-back compare (host != old && t != h) gives the same result whichever flush applied them.
  • Copy-back now walks batch.gpu_writes in declaration order with the same per-shadow, address and length dedup the removed loop did. It also covers lists named twice in one submission, since the batch spans the whole submission.

No issues found. I cannot reproduce the CPU-copy timings without a game package here.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6034259787 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/435#pullrequestreview-6034259787). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T05:41:20Z. **Review:** APPROVED --- Tested 657efd8 on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (265 passed, 0 failed). I checked that dropping the repeated `flush()` + `writing()` keeps behaviour the same: - For a range already declared, `Shadow::writing` already returned early. The merged snapshot range equals the existing one, so the snapshot was never retaken. The only effects of a repeat were an extra `pending` entry and an extra refresh flush. - Refreshes queued between two declarations are still flushed by the next `title_written()` step or by the batch flush before the lists run. The copy-back compare (`host != old && t != h`) gives the same result whichever flush applied them. - Copy-back now walks `batch.gpu_writes` in declaration order with the same per-shadow, address and length dedup the removed loop did. It also covers lists named twice in one submission, since the batch spans the whole submission. No issues found. I cannot reproduce the CPU-copy timings without a game package here. AI-assisted (Claude Code).
DaviTostes commented 2026-11-24 06:55:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T03:35:15Z.


Overlaps with #440: both deduplicate Step::GpuWrite per submission in crates/victory-gpu/src/host.rs, and they conflict textually — git merge-tree --write-tree pr435 pr440 reports CONFLICT (content) in host.rs. Worth choosing one.

Both were verified separately on Arch Linux x86_64, Windows MSVC release build under Wine 11.22 (--test-threads=1):

  • this PR (657efd8): victory-gpu 44 passed, 0 failed, 1 ignored; the new host::batch::exact_gpu_writes_are_declared_once_per_submission passes.
  • #440 (0ba3e44): 44 passed, 0 failed, 1 ignored; its shadow::submission_tests::repeated_gpu_writes_keep_their_first_copy_back_order also passes.

The difference is where the state lives: this PR dedupes in Batch::new_gpu_write and keeps copy-back deferred steps, #440 collects Batch::copy_back in first-declaration order (and adds the ordering test). Both fix the same repeated-range cost.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121235959 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/435#issuecomment-7121235959). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T03:35:15Z. --- Overlaps with #440: both deduplicate `Step::GpuWrite` per submission in `crates/victory-gpu/src/host.rs`, and they conflict textually — `git merge-tree --write-tree pr435 pr440` reports `CONFLICT (content)` in `host.rs`. Worth choosing one. Both were verified separately on **Arch Linux x86_64**, Windows MSVC release build under **Wine 11.22** (`--test-threads=1`): - this PR (`657efd8`): `victory-gpu` **44 passed, 0 failed, 1 ignored**; the new `host::batch::exact_gpu_writes_are_declared_once_per_submission` passes. - #440 (`0ba3e44`): **44 passed, 0 failed, 1 ignored**; its `shadow::submission_tests::repeated_gpu_writes_keep_their_first_copy_back_order` also passes. The difference is where the state lives: this PR dedupes in `Batch::new_gpu_write` and keeps copy-back deferred steps, #440 collects `Batch::copy_back` in first-declaration order (and adds the ordering test). Both fix the same repeated-range cost.
Marvisak commented 2026-11-25 01:07:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:17:47Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-gpu/src/host.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148360114 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/435#issuecomment-7148360114). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:17:47Z. --- <!-- victory-triage v1 head=657efd8279422a5e35b51d9240350b223ecfb4e8 verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-gpu/src/host.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
jeremygold02 commented 2026-11-25 03:03:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T02:59:58Z.


Triage verdict — Narrow the scope and rebase (657efd8)

Evidence

  • There are two things to preserve if this is rebased. Current main at 940d32f already deduplicates exact keys for copy-back and combines their missed status. The remaining opportunity here is reducing repeated preparation before submission. That path still flushes on each unmarked declaration.

Checks and limits

  • The later callback regression on #440 is relevant to the old approval: it saw byte 0 on this head (657efd8) where the expected byte was 33.
  • This is a source comparison and a reference to the published test, not a new GPU run.

Next step

  • #440 is closed unmerged, but its test is worth carrying forward. I’d keep this PR’s exact-key test, preserve the current copy-back eligibility bookkeeping, and verify that a repeated unmarked declaration still flushes before a subsequent host callback.

This verification was AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151482600 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/435#issuecomment-7151482600). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T02:59:58Z. --- **Triage verdict — Narrow the scope and rebase** (`657efd8`) **Evidence** - There are two things to preserve if this is rebased. [Current `main` at `940d32f`](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/crates/victory-gpu/src/host.rs#L959-L988) already deduplicates exact keys for copy-back and combines their `missed` status. The remaining opportunity here is reducing repeated preparation before submission. [That path](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/crates/victory-gpu/src/host.rs#L1854-L1861) still flushes on each unmarked declaration. **Checks and limits** - The [later callback regression on #440](https://github.com/Marvisak/VIctory/pull/440#issuecomment-7136070981) is relevant to the old approval: it saw byte `0` on this head (`657efd8`) where the expected byte was `33`. - This is a source comparison and a reference to the published test, not a new GPU run. **Next step** - #440 is closed unmerged, but its test is worth carrying forward. I’d keep this PR’s exact-key test, preserve the current copy-back eligibility bookkeeping, and verify that a repeated unmarked declaration still flushes before a subsequent host callback. This verification was AI-assisted.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/435:upstream-pr/435'
git switch 'upstream-pr/435'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/435'
git switch 'upstream-pr/435'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/435'
git switch 'upstream-pr/435'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/435'
git switch 'main'
git merge --squash 'upstream-pr/435'
git switch 'main'
git merge --ff-only 'upstream-pr/435'
git switch 'main'
git merge 'upstream-pr/435'
git push origin 'main'
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
Marvisak/VIctory!435
No description provided.