Defer one draw's buffer refreshes under one lock #155

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

@⁠Adika713 on GitHub · 2026-11-25 17:42 UTC · original
Adika713:perf/refresh-batch → main · +114 −11 · 3 files · 1 commits · open

STATUS: pending publication.

Defer the buffers of one draw under a single lock.

draw::State::prepare_for called Shadow::refresh once per vertex and index
buffer. Each call took the host list's deferred-work mutex just to insert one
range. The ranges are now collected while building the views and deferred in
one call, preserving their order and deduplication.

What is in it

  • HostList::defer_refreshes takes one lock for a slice of ranges;
    defer_refresh delegates to it.
  • Shadow::refresh_params exposes the clamping already done by refresh,
    so prepare_for can collect ranges without deferring them one by one.
  • A test that the batched call produces the same steps in the same order as
    one call per range, and an ignored CPU-only A/B benchmark.

Tested

AMD Radeon RX 6950 XT (RDNA2), Ryzen 5 3600, 32 GB RAM, Windows 11,
rustc/cargo 1.98.1. No game data; the game was not run. Isolated
CARGO_TARGET_DIR.

cargo test --release -p victory-gpu --lib defer_refresh_batching -- --ignored --nocapture --test-threads=1,
3 runs, median of 5 samples, per range:

  • one lock per range: 51.6 / 50.7 / 53.4 ns
  • batched: 32.3 / 33.1 / 33.7 ns

Correctness:

  • cargo check -p victory-gpu --lib --tests --locked: exit 0.
  • cargo test -p victory-gpu --lib host:: -- --test-threads=1: 21 passed, 0 failed, 2 ignored, 94 filtered.
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 1 passed, 0 failed, 116 filtered.
  • Full victory-gpu lib, 20 serial runs with the pre-existing #102 flake skipped: 0 failed; each 111 passed, 0 failed, 5 ignored, 1 filtered.
  • cargo test --workspace --no-fail-fast --locked: no new failures. Known xmem and policy failures remain; the two known shader failures did not recur in this run. victory-gpu 112 passed, 0 failed, 5 ignored.

Not tested

  • In-game FPS. No game files or paths were supplied, so this makes no claim
    about frame rate.
  • NVIDIA hardware.
  • Open PR #127 changes the vertex-buffer hunk in draw.rs; if both land, that
    hunk needs rebasing. PR #139 adds a keep call before another
    shadow.refresh site; no overlapping line was changed here.

AI use

AI-assisted: OpenCode, model Big Pickle. No game data.

**@⁠Adika713** on GitHub · 2026-11-25 17:42 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/155) `Adika713:perf/refresh-batch` → `main` · +114 −11 · 3 files · 1 commits · open STATUS: pending publication. Defer the buffers of one draw under a single lock. `draw::State::prepare_for` called `Shadow::refresh` once per vertex and index buffer. Each call took the host list's deferred-work mutex just to insert one range. The ranges are now collected while building the views and deferred in one call, preserving their order and deduplication. **What is in it** - `HostList::defer_refreshes` takes one lock for a slice of ranges; `defer_refresh` delegates to it. - `Shadow::refresh_params` exposes the clamping already done by `refresh`, so `prepare_for` can collect ranges without deferring them one by one. - A test that the batched call produces the same steps in the same order as one call per range, and an ignored CPU-only A/B benchmark. **Tested** AMD Radeon RX 6950 XT (RDNA2), Ryzen 5 3600, 32 GB RAM, Windows 11, rustc/cargo 1.98.1. No game data; the game was not run. Isolated `CARGO_TARGET_DIR`. `cargo test --release -p victory-gpu --lib defer_refresh_batching -- --ignored --nocapture --test-threads=1`, 3 runs, median of 5 samples, per range: - one lock per range: **51.6 / 50.7 / 53.4 ns** - batched: **32.3 / 33.1 / 33.7 ns** Correctness: - `cargo check -p victory-gpu --lib --tests --locked`: exit 0. - `cargo test -p victory-gpu --lib host:: -- --test-threads=1`: 21 passed, 0 failed, 2 ignored, 94 filtered. - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 1 passed, 0 failed, 116 filtered. - Full `victory-gpu` lib, 20 serial runs with the pre-existing #102 flake skipped: 0 failed; each 111 passed, 0 failed, 5 ignored, 1 filtered. - `cargo test --workspace --no-fail-fast --locked`: no new failures. Known xmem and policy failures remain; the two known shader failures did not recur in this run. `victory-gpu` 112 passed, 0 failed, 5 ignored. **Not tested** - In-game FPS. No game files or paths were supplied, so this makes no claim about frame rate. - NVIDIA hardware. - Open PR #127 changes the vertex-buffer hunk in `draw.rs`; if both land, that hunk needs rebasing. PR #139 adds a `keep` call before another `shadow.refresh` site; no overlapping line was changed here. **AI use** AI-assisted: OpenCode, model Big Pickle. No game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:49 +00:00
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-25 17:50 UTC · original

Tested PR head 65c671a on Bazzite Linux 45, NVIDIA GeForce RTX 3090 (host driver 620.73.04), GE-Proton 10-34 / Wine 10.0 and vkd3d-proton 3.0.0.

The correctness test host::tests::defer_refreshes_matches_one_call_per_range passed under Proton (1 passed, 0 failed). I also ran the ignored release A/B benchmark under Proton, with the host GPU initialized, one run of five samples:

  • one lock per range: median 28.4 ns/range
  • batched: median 18.2 ns/range

The batching was about 36% lower in this Proton run. These timings are Proton-specific and should not be compared directly with the PR's native Windows measurements or treated as an in-game FPS result.

**@⁠KernelSmoker** on GitHub · 2026-11-25 17:50 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/155#issuecomment-7170080800) Tested PR head `65c671a` on Bazzite Linux 45, NVIDIA GeForce RTX 3090 (host driver 620.73.04), GE-Proton 10-34 / Wine 10.0 and vkd3d-proton 3.0.0. The correctness test `host::tests::defer_refreshes_matches_one_call_per_range` passed under Proton (1 passed, 0 failed). I also ran the ignored release A/B benchmark under Proton, with the host GPU initialized, one run of five samples: - one lock per range: median **28.4 ns/range** - batched: median **18.2 ns/range** The batching was about 36% lower in this Proton run. These timings are Proton-specific and should not be compared directly with the PR's native Windows measurements or treated as an in-game FPS result.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-25 18:57 UTC · original

Measured head 65c671a on an RX 7900 XT, Windows 11 build 26300, Rust 1.98.1, release build, separate target dir. I did not run the game.

KernelSmoker's Proton run, and mine here, reproduce the direction of defer_refresh_batching. Here it gives 25-36 ns per range one at a time against 17-29 ns batched. However, the benchmark does not measure what prepare_for now does:

  • Its baseline, list.defer_refresh, is this PR's version. That version goes through defer_refreshes(&[(shadow.clone(), ..)]) and clones the Arc on every call. main clones only when a range is new to the list.
  • The ranges vector is built once, outside the timed loop. In prepare_for, every draw now allocates a Vec and clones and drops an Arc for each buffer.

I added a local ignored test that times the whole per-draw path for ranges already deferred in the list, i.e. the same buffers drawn again. It is single-threaded, and each figure is the median of 7 samples. The ranges below come from 6 runs, on a machine with other jobs running:

buffers per draw main's Shadow::refresh, per buffer this PR, collect + defer_refreshes
1 23-34 ns 59-96 ns
2 44-65 ns 99-124 ns
3 67-94 ns 110-163 ns
8 203-248 ns 322-415 ns

In every run, the collected path was slower than main for each buffer count. So the gain in the description comes from how the benchmark is set up; on this path the PR costs more per draw. I did not measure ranges deferred for the first time in a list, or several recording threads at once.

If the lock itself is the cost, a possible variant: keep defer_refresh as on main, and move the Arc that shadow::find returns into a fixed-size array on the stack (32 vertex buffers plus the index buffer) once the view is built. That avoids both the allocation and the extra clones.

Tests: victory-gpu lib gives 112 passed, 0 failed in parallel. Serial runs hit only the known frame::waits_end_on_ticks_and_count_frames and #102 watch flakes.

**@⁠adrianmjim** on GitHub · 2026-11-25 18:57 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/155#issuecomment-7171627452) Measured head 65c671a on an RX 7900 XT, Windows 11 build 26300, Rust 1.98.1, release build, separate target dir. I did not run the game. KernelSmoker's Proton run, and mine here, reproduce the direction of `defer_refresh_batching`. Here it gives 25-36 ns per range one at a time against 17-29 ns batched. However, the benchmark does not measure what `prepare_for` now does: - Its baseline, `list.defer_refresh`, is this PR's version. That version goes through `defer_refreshes(&[(shadow.clone(), ..)])` and clones the `Arc` on every call. main clones only when a range is new to the list. - The `ranges` vector is built once, outside the timed loop. In `prepare_for`, every draw now allocates a `Vec` and clones and drops an `Arc` for each buffer. I added a local ignored test that times the whole per-draw path for ranges already deferred in the list, i.e. the same buffers drawn again. It is single-threaded, and each figure is the median of 7 samples. The ranges below come from 6 runs, on a machine with other jobs running: | buffers per draw | main's `Shadow::refresh`, per buffer | this PR, collect + `defer_refreshes` | |---|---|---| | 1 | 23-34 ns | 59-96 ns | | 2 | 44-65 ns | 99-124 ns | | 3 | 67-94 ns | 110-163 ns | | 8 | 203-248 ns | 322-415 ns | In every run, the collected path was slower than main for each buffer count. So the gain in the description comes from how the benchmark is set up; on this path the PR costs more per draw. I did not measure ranges deferred for the first time in a list, or several recording threads at once. If the lock itself is the cost, a possible variant: keep `defer_refresh` as on main, and move the `Arc` that `shadow::find` returns into a fixed-size array on the stack (32 vertex buffers plus the index buffer) once the view is built. That avoids both the allocation and the extra clones. Tests: `victory-gpu` lib gives 112 passed, 0 failed in parallel. Serial runs hit only the known `frame::waits_end_on_ticks_and_count_frames` and #102 watch flakes.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-26 05:11 UTC · original

Concurrency check on Windows/RDNA2 (RX 6950 XT, Windows 11 build 26300, Rust 1.98.1). I merged this PR (65c671a) onto main 4f62c2a plus #210, which fixes list::tests::lists_are_cut_at_waits_that_follow_work, a test that fails in every release run on main. Then I ran the release victory-gpu lib test binary 10 times, with the default thread count:

  • This PR: 9 runs passed (114 passed, 5 ignored); 1 run died without a result line, as on the base.
  • The same base without the PR: 1 run failed on the known flake watch::tests::written_pages_are_reported_to_every_asker (#102), and 1 run died without a result line.

No new failure, deadlock or hang showed up in these runs. Ten runs are a small sample for races. Not run in the game.

harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-26 05:11 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/155#issuecomment-7183255722) Concurrency check on Windows/RDNA2 (RX 6950 XT, Windows 11 build 26300, Rust 1.98.1). I merged this PR (`65c671a`) onto `main` `4f62c2a` plus #210, which fixes `list::tests::lists_are_cut_at_waits_that_follow_work`, a test that fails in every release run on `main`. Then I ran the release `victory-gpu` lib test binary 10 times, with the default thread count: - This PR: 9 runs passed (114 passed, 5 ignored); 1 run died without a result line, as on the base. - The same base without the PR: 1 run failed on the known flake `watch::tests::written_pages_are_reported_to_every_asker` (#102), and 1 run died without a result line. No new failure, deadlock or hang showed up in these runs. Ten runs are a small sample for races. Not run in the game. harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300 AI-assisted (Claude Code); no game data.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/155/head:github-bot/gh-155'
git switch 'github-bot/gh-155'

Merge

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