Skip to content

GPU: coalesce identical write declarations within a submission - #435

Open
melon0918 wants to merge 1 commit into
Marvisak:mainfrom
melon0918:perf/avoid-duplicate-gpu-writes
Open

melon0918 wants to merge 1 commit into
Marvisak:mainfrom
melon0918:perf/avoid-duplicate-gpu-writes

Conversation

@melon0918

Copy link
Copy Markdown

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).

@DaviTostes

Copy link
Copy Markdown

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.
  • GPU: track each write range once per submission #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.

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Owner

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

@jeremygold02

jeremygold02 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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

  • GPU: track each write range once per submission #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants