GPU: a submission's write ranges deduplicated through a set, not a scan #10

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

@⁠LICObr on GitHub · 2026-11-25 11:37 UTC · original
LICObr:gpu/dedup-write-ranges-hashed → main · +11 −20 · 1 files · 1 commits · open

Problem

HostQueue::execute collects the GPU write ranges of every list in a submission (Step::GpuWrite, then batch.bindless_writes) into card_writes and cpu_back. It keeps each range once by scanning the ranges kept so far (target.iter().any(...)), so the cost grows with steps × distinct ranges on the submitting thread. defer_gpu_write does not dedupe at push time (unlike defer_refresh with refreshed). Every list of a world frame declares its UAV ranges again, so the same ranges show up many times per submission.

Change

  • A HashSet of (Arc::as_ptr(shadow), address, len) beside the two vectors. A range is pushed only the first time it is seen.
  • Same ranges, same order, same split between card and CPU copy-back as before. Only the lookup changes.
  • 11 lines in place of 20, in host.rs only.

Verification

  • cargo check -p victory-gpu --all-targets --all-features --target x86_64-pc-windows-msvc: builds.
  • cargo clippy -p victory-gpu --all-targets: no new warning in the changed code. The crate does not build under -D warnings today because of victory-shader (#2).
  • Not measured in a game run. I don't know how many write ranges a world submission declares. With thousands it should show on the submitting thread; with dozens it won't. If you can, a VICTORY_PROFILE run before and after would tell. I'm happy to adjust or drop it if it doesn't show up.
**@⁠LICObr** on GitHub · 2026-11-25 11:37 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/10) `LICObr:gpu/dedup-write-ranges-hashed` → `main` · +11 −20 · 1 files · 1 commits · open ## Problem `HostQueue::execute` collects the GPU write ranges of every list in a submission (`Step::GpuWrite`, then `batch.bindless_writes`) into `card_writes` and `cpu_back`. It keeps each range once by scanning the ranges kept so far (`target.iter().any(...)`), so the cost grows with steps × distinct ranges on the submitting thread. `defer_gpu_write` does not dedupe at push time (unlike `defer_refresh` with `refreshed`). Every list of a world frame declares its UAV ranges again, so the same ranges show up many times per submission. ## Change - A `HashSet` of `(Arc::as_ptr(shadow), address, len)` beside the two vectors. A range is pushed only the first time it is seen. - Same ranges, same order, same split between card and CPU copy-back as before. Only the lookup changes. - 11 lines in place of 20, in `host.rs` only. ## Verification - `cargo check -p victory-gpu --all-targets --all-features --target x86_64-pc-windows-msvc`: builds. - `cargo clippy -p victory-gpu --all-targets`: no new warning in the changed code. The crate does not build under `-D warnings` today because of `victory-shader` (#2). - **Not measured in a game run.** I don't know how many write ranges a world submission declares. With thousands it should show on the submitting thread; with dozens it won't. If you can, a `VICTORY_PROFILE` run before and after would tell. I'm happy to adjust or drop it if it doesn't show up.
execute() collected the GPU write ranges of every list in a submission
and kept each once by scanning the ranges kept so far: quadratic in the
ranges declared, which every list of a world frame declares again. A set
of (copy, address, length) beside the two lists keeps the same ranges in
the same order.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:33:04 +00:00
Author
Owner

@⁠Ekabusto on GitHub · 2026-11-25 12:47 UTC · original

Checked locally: victory-gpu builds and cargo test -p victory-gpu --lib passes (106 passed, 4 ignored; this branch is on 4cbe9d7, which has 3 fewer tests than main). It merges into current main without conflicts, and clippy has one warning fewer than on main.

The change keeps behaviour: a shadow is either card or CPU for its whole life, so keying the set on (shadow, address, len) without the target picks the same vector the scan did, and the first occurrence keeps its place, so order is unchanged. Looks good to me; as you say, whether it shows up depends on how many ranges a world submission declares.

Reviewed on Windows 11 (build 26300), Rust 1.98.1, each PR in its own worktree; no game data, not run in the game. AI-assisted (Claude Code).

**@⁠Ekabusto** on GitHub · 2026-11-25 12:47 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/10#issuecomment-7162859532) Checked locally: `victory-gpu` builds and `cargo test -p victory-gpu --lib` passes (106 passed, 4 ignored; this branch is on `4cbe9d7`, which has 3 fewer tests than `main`). It merges into current `main` without conflicts, and clippy has one warning fewer than on `main`. The change keeps behaviour: a shadow is either card or CPU for its whole life, so keying the set on `(shadow, address, len)` without the target picks the same vector the scan did, and the first occurrence keeps its place, so order is unchanged. Looks good to me; as you say, whether it shows up depends on how many ranges a world submission declares. Reviewed on Windows 11 (build 26300), Rust 1.98.1, each PR in its own worktree; no game data, not run in the game. AI-assisted (Claude Code).
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 14:48 UTC · original · reviewed

AI-assisted static review (ChatGPT); I inspected the diff but did not run tests.

**@⁠gut0to** on GitHub · 2026-11-27 14:48 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/10#pullrequestreview-6089879259) · **reviewed** AI-assisted static review (ChatGPT); I inspected the diff but did not run tests.
@ -1201,1 +1203,4 @@
let mut cpu_back: Vec<(std::sync::Arc<crate::shadow::Shadow>, usize, usize)> = Vec::new();
let mut seen = std::collections::HashSet::new();
let mut add = |shadow: &std::sync::Arc<crate::shadow::Shadow>, address: usize, len: usize| {
if seen.insert((std::sync::Arc::as_ptr(shadow) as usize, address, len)) {
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 14:48 UTC · original

Could the range-key logic get a deterministic helper test? The set spans both per-list GpuWrite entries and batch.bindless_writes, so correctness depends on deduplicating only the full (Shadow identity, address, length) tuple. A test could feed the same tuple from both sources, then reuse the same bounds with a different Shadow and a different range on the original, asserting only the true duplicate is removed. That would guard against silently dropping write or copy-back ranges if this key changes later.

**@⁠gut0to** on GitHub · 2026-11-27 14:48 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/10#discussion_r4720768271) Could the range-key logic get a deterministic helper test? The set spans both per-list `GpuWrite` entries and `batch.bindless_writes`, so correctness depends on deduplicating only the full `(Shadow identity, address, length)` tuple. A test could feed the same tuple from both sources, then reuse the same bounds with a different `Shadow` and a different range on the original, asserting only the true duplicate is removed. That would guard against silently dropping write or copy-back ranges if this key changes later.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/host.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-10'
git switch 'github-bot/gh-10'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-10'
git switch 'github-bot/gh-10'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-10'
git switch 'main'
git merge --squash 'github-bot/gh-10'
git switch 'main'
git merge --ff-only 'github-bot/gh-10'
git switch 'main'
git merge 'github-bot/gh-10'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.