draw: a draw record after a compute write opens a new indirect batch (#523) #597

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

@⁠t-jonesy on GitHub · 2026-12-05 14:19 UTC · original
t-jonesy:up/indirect-split → main · +78 −4 · 3 files · 1 commits · open

Fixes #523.

Problem

#523 describes it in full. In short, the title culls and then draws several times over one 32 KiB ExecuteIndirect argument buffer: C c K, then kind-10 mesh draws, and the next group reuses the same argument addresses.

On main, State::batched() keeps the open batch when only buffers_written() has set wrote. The batch is dropped only at synced(). So a later group's draws can be served by the batch opened for an earlier group, whose clamp pass ran before this group's culling rewrote the counts. Vehicle bodies then go missing or solid black at some camera angles.

Change

This is the variant in the last row of #523's table:

  • Draws split. A draw record (kinds 0, 1 and 10) asked for after a compute write opens a new batch.
    • On lists with named barriers, open_batch takes a wait flag, so the clamp pass waits for COMPUTE (around(.., wait)).
    • On other lists, a UAV barrier goes in front of the reopened batch.
  • Dispatches stay. Dispatches (kind 2) remain in the open batch. Re-batching them cost about 30% in #523's test, from the ray-tracing dispatches.
  • Switch. VICTORY_INDIRECT_SPLIT_AFTER_WRITE=0 gives the old behaviour.
  • Counter. A per-frame line, indirect draw batches opened anew after a compute write per frame, counts the splits. It is logged only when there are any.
  • Unit test. The decision is factored into splits_after(kind, wrote), so a pure unit test pins it.

Default

This PR turns the fix on by default. It is a correctness fix for a reproducible picture bug, its reporter measured no cost, and we measured none. If you would rather have it opt-in at first, as #523's patch was written, flipping it is a one-line change.

Evidence

  • #523's reporter (RX 9070 XT, Series X, 2560x1440 with FSR 4 Quality, at a place where it reproduces every time): with this variant the vehicles are fixed, at 29.3-29.7 fps against 29.4 unchanged.
  • Ours (RX 9070 XT, Ryzen 9 7950X3D, 3840x2160 output with FSR 4 Performance, ray tracing on):
    • Build: a fork build carrying this change.
    • Runs: a fixed idle scene with a steady camera, no frame cap. Four arms were interleaved over four rounds, 4 runs each.
    • Result: 37.91 ± 1.16 fps with it against 38.06 ± 1.48 without, a paired difference of 0.15 fps, within the scene's noise. The 1% low was 27.9 against 28.4. The arm without it also had three other switches off, so this is not an isolated A/B.
    • No regressions seen in screenshots.
    • Not verified by eye: we did not reproduce the missing bodies on our machine, so we have not confirmed the fix visually ourselves.

Risks

  • Each split costs a clamp pass plus a wait or UAV barrier. This is cheap in the title's cull-then-draw pattern, measured at both ends above. A title that interleaves compute writes and indirect draws far more often would pay more per frame. The new line shows how often it happens.
  • It is a workaround where the symptom shows. As #523 notes, the exact condition is probably "a shader whose unordered views overlap a source of the open batch was recorded". That condition would cover dispatches without their cost, but it is not written here.
  • The shadow and bush pops #523 mentions are a separate fault. The reporter measured no change in them with this variant.

Switches

Setting Default Values Effect
VICTORY_INDIRECT_SPLIT_AFTER_WRITE 1 0, 1 An indirect draw recorded after a compute shader that writes buffers gets its own clamp pass, after that write. 0: as before

Documented in docs/SETTINGS.md (Textures and glass, with the other picture fixes; happy to move it).

Testing

  • Unit tests, under Wine: draw::tests 2 passed, including the new a_draw_after_a_compute_write_opens_a_new_batch. It covers draws, indexed draws and mesh dispatches after a COMPUTE write, the no-write and draws-only cases, and that dispatches never split.
  • Build checks: ./build.sh check (victory, Windows target) and cargo check --tests -p victory-gpu are clean, apart from main's existing room_lately warning.
  • indirect::tests: its one open_batch call passes wait = false. It was not run here, because it needs a GPU.
  • Not run in game on this branch. The code is the same as the fork build measured above, apart from the switch plumbing.

Open questions

  • Default on, or opt-in for a release first?
  • Should the split also need the open batch's sources to overlap the written buffers? That is the narrower condition #523 suggests, and it could later extend the fix to dispatches.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ETU6PfySRvsjk18uHFtWya

**@⁠t-jonesy** on GitHub · 2026-12-05 14:19 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/597) `t-jonesy:up/indirect-split` → `main` · +78 −4 · 3 files · 1 commits · open Fixes #523. ## Problem #523 describes it in full. In short, the title culls and then draws several times over one 32 KiB ExecuteIndirect argument buffer: `C c K`, then kind-10 mesh draws, and the next group reuses the same argument addresses. On main, `State::batched()` keeps the open batch when only `buffers_written()` has set `wrote`. The batch is dropped only at `synced()`. So a later group's draws can be served by the batch opened for an earlier group, whose clamp pass ran before this group's culling rewrote the counts. Vehicle bodies then go missing or solid black at some camera angles. ## Change This is the variant in the last row of #523's table: - **Draws split.** A draw record (kinds 0, 1 and 10) asked for after a compute write opens a new batch. - On lists with named barriers, `open_batch` takes a `wait` flag, so the clamp pass waits for COMPUTE (`around(.., wait)`). - On other lists, a UAV barrier goes in front of the reopened batch. - **Dispatches stay.** Dispatches (kind 2) remain in the open batch. Re-batching them cost about 30% in #523's test, from the ray-tracing dispatches. - **Switch.** `VICTORY_INDIRECT_SPLIT_AFTER_WRITE=0` gives the old behaviour. - **Counter.** A per-frame line, `indirect draw batches opened anew after a compute write per frame`, counts the splits. It is logged only when there are any. - **Unit test.** The decision is factored into `splits_after(kind, wrote)`, so a pure unit test pins it. ## Default This PR turns the fix on by default. It is a correctness fix for a reproducible picture bug, its reporter measured no cost, and we measured none. If you would rather have it opt-in at first, as #523's patch was written, flipping it is a one-line change. ## Evidence - **#523's reporter** (RX 9070 XT, Series X, 2560x1440 with FSR 4 Quality, at a place where it reproduces every time): with this variant the vehicles are fixed, at 29.3-29.7 fps against 29.4 unchanged. - **Ours** (RX 9070 XT, Ryzen 9 7950X3D, 3840x2160 output with FSR 4 Performance, ray tracing on): - **Build:** a fork build carrying this change. - **Runs:** a fixed idle scene with a steady camera, no frame cap. Four arms were interleaved over four rounds, 4 runs each. - **Result:** 37.91 ± 1.16 fps with it against 38.06 ± 1.48 without, a paired difference of 0.15 fps, within the scene's noise. The 1% low was 27.9 against 28.4. The arm without it also had three other switches off, so this is not an isolated A/B. - **No regressions** seen in screenshots. - **Not verified by eye:** we did not reproduce the missing bodies on our machine, so we have not confirmed the fix visually ourselves. ## Risks - **Each split costs a clamp pass** plus a wait or UAV barrier. This is cheap in the title's cull-then-draw pattern, measured at both ends above. A title that interleaves compute writes and indirect draws far more often would pay more per frame. The new line shows how often it happens. - **It is a workaround where the symptom shows.** As #523 notes, the exact condition is probably "a shader whose unordered views overlap a source of the open batch was recorded". That condition would cover dispatches without their cost, but it is not written here. - **The shadow and bush pops #523 mentions are a separate fault.** The reporter measured no change in them with this variant. ## Switches | Setting | Default | Values | Effect | |---|---|---|---| | `VICTORY_INDIRECT_SPLIT_AFTER_WRITE` | `1` | 0, 1 | An indirect draw recorded after a compute shader that writes buffers gets its own clamp pass, after that write. `0`: as before | Documented in `docs/SETTINGS.md` (Textures and glass, with the other picture fixes; happy to move it). ## Testing - **Unit tests, under Wine:** `draw::tests` 2 passed, including the new `a_draw_after_a_compute_write_opens_a_new_batch`. It covers draws, indexed draws and mesh dispatches after a COMPUTE write, the no-write and draws-only cases, and that dispatches never split. - **Build checks:** `./build.sh check` (victory, Windows target) and `cargo check --tests -p victory-gpu` are clean, apart from main's existing `room_lately` warning. - **`indirect::tests`:** its one `open_batch` call passes `wait = false`. It was not run here, because it needs a GPU. - **Not run in game on this branch.** The code is the same as the fork build measured above, apart from the switch plumbing. ## Open questions - Default on, or opt-in for a release first? - Should the split also need the open batch's sources to overlap the written buffers? That is the narrower condition #523 suggests, and it could later extend the fix to dispatches. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ETU6PfySRvsjk18uHFtWya
The title culls and then draws several times over one 32 KiB
ExecuteIndirect argument buffer (C c K, then kind-10 mesh draws).
`State::batched()` kept the open batch when only `buffers_written()` had
set `wrote`; the batch was dropped only at `synced()`. So a later group's
draws were served by the batch opened for an earlier group, whose clamp
pass ran before this group's culling rewrote the counts: vehicle bodies
missing or solid black (#523).

Now a draw record (kinds 0, 1 and 10) asked for after a compute write
opens a new batch. On lists with named barriers `open_batch` takes a
`wait` flag (`around(.., wait)`, so the pass waits for COMPUTE); on other
lists a UAV barrier goes in front of it. Dispatches (kind 2) are left as
they are: re-batching them cost about 30 % in #523's test. This is the
last row of #523's table, the variant its reporter measured fixed at
29.3-29.7 fps against 29.4.

`VICTORY_INDIRECT_SPLIT_AFTER_WRITE=0` gives the old behaviour. A new
per-frame line counts the batches opened anew.

Measured on an RX 9070 XT (RADV), idle scene, 16 interleaved runs of a
downstream build: 37.91 fps with it against 38.06 without, within noise
(the arm without it also had three other switches off, so this is no
isolated A/B). Not checked by eye here: the bodies of #523 were not
reproduced on this machine.

Tests, under Wine: draw 2 passed, the new
`a_draw_after_a_compute_write_opens_a_new_batch` among them; `cargo
check` of victory and of victory-gpu's tests clean apart from the
existing `room_lately` warning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ETU6PfySRvsjk18uHFtWya
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 14:21:34 +00:00
github-bot force-pushed github-bot/gh-597 from 17ed40ef32 to b9e685bc32 2026-12-05 22:22:24 +00:00 Compare
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/597/head:github-bot/gh-597'
git switch 'github-bot/gh-597'

Merge

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