GPU: deduplicate identical per-list defer_gpu_write declarations #3114

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

@⁠fuzeofficlal on GitHub · 2026-11-26 08:29 UTC · original
fuzeofficlal:perf/gpu-dedup-per-list-gpu-writes → main · +265 −8 · 1 files · 1 commits · open

Summary

HostList::defer_gpu_write previously pushed a new Step::GpuWrite into Deferred::copies on every draw or dispatch, even when the same command list repeatedly declared the exact same (shadow, address, len, marked, memory) tuple with no intervening step that writes title memory. In world command lists this appends thousands of redundant Step::GpuWrite entries per frame, repeating Arc::clone, batch.flush() / shadow.writing(...) lock acquisitions in run_deferred, and HashMap deduplication work in Host::execute.

This change mirrors the existing per-list Deferred::refreshed deduplication:

  • Track recorded declarations in Deferred::gpu_writes: HashSet<(usize, usize, usize, bool, bool)> keyed by (Arc::as_ptr(shadow) as usize, address, len, marked, memory).
    • Including both marked and memory in the key ensures that an earlier marked == true declaration never suppresses a subsequent marked == false declaration (which must flush and take a pre-submit snapshot), and an earlier memory == false declaration never suppresses a subsequent memory == true declaration (which governs withholding() on title-memory misses).
    • Because the first accepted declaration pushes Step::GpuWrite(shadow.clone(), ...) into Deferred::copies, the Arc<Shadow> stays alive until HostList::reset() replaces Deferred, so Arc::as_ptr(shadow) cannot alias another copy while in gpu_writes.
  • Add Deferred::title_written(&mut self) to clear both refreshed and gpu_writes, called by HostList::defer_copy and HostList::defer (merging defer's two self.deferred() lock acquisitions into one). HostList::reset continues to reset the entire Deferred struct.

Verification

  • Added four tests in crates/victory-gpu/src/host.rs (host::gpu_write_dedup::*):
    • identical_gpu_writes_deduplicate_until_title_written_or_reset
    • distinct_marked_and_memory_flags_are_never_collapsed
    • deduped_marked_then_unmarked_and_post_copy_writes_copy_back
    • deduped_ordinary_then_memory_write_still_withholds_on_miss
  • Hardware D3D12 (RTX 5090): cargo test -p victory-gpu --lib --locked -- host::gpu_write_dedup:: host::batch:: host::withholding:: — 6 passed, 0 failed.
  • WARP (VICTORY_D3D12_WARP=1): cargo test -p victory-gpu --locked --features diagnostics — 250 passed, 0 failed (1 existing benchmark ignored), verified across 4 consecutive parallel runs.
  • cargo clippy --workspace --all-targets --locked -- -D warnings and --all-features: 0 warnings.
  • cargo test -p xtask --locked policy::tests::repository_passes_policy: passed.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 08:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/3114) `fuzeofficlal:perf/gpu-dedup-per-list-gpu-writes` → `main` · +265 −8 · 1 files · 1 commits · open ### Summary `HostList::defer_gpu_write` previously pushed a new `Step::GpuWrite` into `Deferred::copies` on every draw or dispatch, even when the same command list repeatedly declared the exact same `(shadow, address, len, marked, memory)` tuple with no intervening step that writes title memory. In world command lists this appends thousands of redundant `Step::GpuWrite` entries per frame, repeating `Arc::clone`, `batch.flush()` / `shadow.writing(...)` lock acquisitions in `run_deferred`, and `HashMap` deduplication work in `Host::execute`. This change mirrors the existing per-list `Deferred::refreshed` deduplication: - Track recorded declarations in `Deferred::gpu_writes: HashSet<(usize, usize, usize, bool, bool)>` keyed by `(Arc::as_ptr(shadow) as usize, address, len, marked, memory)`. - Including both `marked` and `memory` in the key ensures that an earlier `marked == true` declaration never suppresses a subsequent `marked == false` declaration (which must flush and take a pre-submit snapshot), and an earlier `memory == false` declaration never suppresses a subsequent `memory == true` declaration (which governs `withholding()` on title-memory misses). - Because the first accepted declaration pushes `Step::GpuWrite(shadow.clone(), ...)` into `Deferred::copies`, the `Arc<Shadow>` stays alive until `HostList::reset()` replaces `Deferred`, so `Arc::as_ptr(shadow)` cannot alias another copy while in `gpu_writes`. - Add `Deferred::title_written(&mut self)` to clear both `refreshed` and `gpu_writes`, called by `HostList::defer_copy` and `HostList::defer` (merging `defer`'s two `self.deferred()` lock acquisitions into one). `HostList::reset` continues to reset the entire `Deferred` struct. ### Verification - Added four tests in `crates/victory-gpu/src/host.rs` (`host::gpu_write_dedup::*`): - `identical_gpu_writes_deduplicate_until_title_written_or_reset` - `distinct_marked_and_memory_flags_are_never_collapsed` - `deduped_marked_then_unmarked_and_post_copy_writes_copy_back` - `deduped_ordinary_then_memory_write_still_withholds_on_miss` - Hardware D3D12 (RTX 5090): `cargo test -p victory-gpu --lib --locked -- host::gpu_write_dedup:: host::batch:: host::withholding::` — 6 passed, 0 failed. - WARP (`VICTORY_D3D12_WARP=1`): `cargo test -p victory-gpu --locked --features diagnostics` — 250 passed, 0 failed (1 existing benchmark ignored), verified across 4 consecutive parallel runs. - `cargo clippy --workspace --all-targets --locked -- -D warnings` and `--all-features`: 0 warnings. - `cargo test -p xtask --locked policy::tests::repository_passes_policy`: passed.
HostList::defer_gpu_write previously appended a Step::GpuWrite entry on
every dispatch/draw unconditionally, even when the same command list
repeatedly declared the exact same (shadow, address, len, marked, memory)
tuple with no intervening title-memory write.

Track declared writes in Deferred::gpu_writes keyed by
(Arc::as_ptr(shadow), address, len, marked, memory)—preserving every
distinct (marked, memory) combination so unmarked snapshots and
title-memory withholding semantics are never lost—and clear both
refreshed and gpu_writes via Deferred::title_written() on defer_copy and
defer (as well as HostList::reset).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:34:13 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 08:53 UTC · original · approved these changes

Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib host::gpu_write_dedup:: -- --test-threads=1: 4/4 passed on RTX 5090 and WARP.
  • cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 10/10 passed on RTX 5090 and WARP.
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed on RTX 5090.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly deduplicates identical per-list defer_gpu_write declarations without collapsing distinct marked/memory flags or breaking post-copy/withholding semantics.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 08:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/3114#pullrequestreview-6071021448) · **approved these changes** Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib host::gpu_write_dedup:: -- --test-threads=1`: 4/4 passed on RTX 5090 and WARP. - `cargo test -p victory-gpu --lib shadow:: -- --test-threads=1`: 10/10 passed on RTX 5090 and WARP. - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 20/20 passed on RTX 5090. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly deduplicates identical per-list `defer_gpu_write` declarations without collapsing distinct marked/memory flags or breaking post-copy/withholding semantics. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
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/3114/head:github-bot/gh-3114'
git switch 'github-bot/gh-3114'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3114'
git switch 'github-bot/gh-3114'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3114'
git switch 'github-bot/gh-3114'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3114'
git switch 'main'
git merge --squash 'github-bot/gh-3114'
git switch 'main'
git merge --ff-only 'github-bot/gh-3114'
git switch 'main'
git merge 'github-bot/gh-3114'
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/Marvisak--VIctory!3114
No description provided.