perf(gpu): forward texture enhanced barriers as resource-scoped host barriers #408

Open
github-bot wants to merge 6 commits from github-bot/gh-408 into main AGit
Owner

@⁠tommiehansen on GitHub · 2026-12-04 01:08 UTC · original
tommiehansen:perf/texture-scoped-barriers → main · +1424 −24 · 7 files · 6 commits · open

Why

Global texture barriers may over-synchronize unrelated resources.

What changes

Opt-in VICTORY_TEXTURE_BARRIERS=1, resource-scoped enhanced barriers with lifetime/eligibility checks and existing fallback.

Benchmark results

CPU-only Standard at 79ab078: 0.009→0.046 ms, +406.28%, exact planning output; global barrier count 16→13, two resource transitions and two resource UAV barriers in fixture.

Why this should be merged / current decision

No verified net performance benefit. Hold opt-in implementation until GPU synchronization savings outweigh measured planning cost.

Validation

Standard. fd5767f CI passed ten targeted tests and all-targets; one ignored. Unchanged-main descriptor PSO failure reproduced separately.

Compatibility

Preserve upstream CountBatch, translation statistics and fallback. Physical parity and timing outstanding.

Archived detailed evidence and review history.

**@⁠tommiehansen** on GitHub · 2026-12-04 01:08 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/408) `tommiehansen:perf/texture-scoped-barriers` → `main` · +1424 −24 · 7 files · 6 commits · open ## Why Global texture barriers may over-synchronize unrelated resources. ## What changes Opt-in `VICTORY_TEXTURE_BARRIERS=1`, resource-scoped enhanced barriers with lifetime/eligibility checks and existing fallback. ## Benchmark results CPU-only Standard at 79ab078: 0.009→0.046 ms, +406.28%, exact planning output; global barrier count 16→13, two resource transitions and two resource UAV barriers in fixture. ## Why this should be merged / current decision No verified net performance benefit. Hold opt-in implementation until GPU synchronization savings outweigh measured planning cost. ## Validation [Standard](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47503640056/job/145622974702). fd5767f [CI](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47577257669) passed ten targeted tests and all-targets; one ignored. Unchanged-main descriptor PSO failure reproduced separately. ## Compatibility Preserve upstream CountBatch, translation statistics and fallback. Physical parity and timing outstanding. [Archived detailed evidence and review history](https://github.com/tommiehansen/VIctory-xmem/blob/04dd44857abe222961157663b89a4dfed4c7277c/archive/pr-descriptions-20261206.md).
- Add opt-in VICTORY_TEXTURE_BARRIERS=1 path preserving texture resource identity and layouts/accesses across direct and thin command recording
- Parse D3D12_TEXTURE_BARRIER entries into Plan/TextureWait with layout/access-to-state mapping and compile-time Win32 ABI assertions
- Resolve guest textures (and aliases/depth colour twins) to host copies via hosted_if_made and HostList::barrier_move so states stay coherent with HostList::prelude and later ensure_state transitions
- Emit resource-scoped D3D12_RESOURCE_BARRIER_TYPE_TRANSITION / _UAV barriers for textures while keeping buffer and global barriers on global sync
- Add standalone waits.rs unit tests, thin-stream round-trip test, and per-frame diagnostic counters
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 01:12:08 +00:00
Approve only named whole-resource UAV dependencies on live committed untwinned copies with tracked, legal host state. Validate the entire batch before mutation, preserve original global synchronization on fallback, and retain and verify guest references across thin translation.
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-04 02:12 UTC · original

Tested a56159f natively on Windows 11 (MSVC) with real D3D12, one NVIDIA desktop card plus WARP.

Full cargo test -p victory-gpu --lib (skipping descriptor::tests::views_die_with_their_resource) gives 339 passed / 5 failed / 23 ignored on the merge-base, and this PR gives 346 / 5 / 24 with the switch unset and the same with VICTORY_TEXTURE_BARRIERS=1. The five failures are the ones main already has on this machine (two indirect::tests::host_list_*, two pipeline::host library loads, the flaky watch one). The new tests are CPU only, so I also ran a throwaway local test (not pushed) that sends barrier groups through a newer-layout title list with the switch on and submits it, in a diagnostics build with VICTORY_D3D12_DEBUG=1, on the card and on WARP. Before each planned call it puts the texture into UAV state in the back list the same way a dispatch would, through ensure_state.

Eight calls, same result on both adapters.

  • whole texture UAV to SRV gets one resource transition and no global barrier
  • whole texture UAV to UAV gets one resource UAV barrier
  • SyncBefore ALL goes global
  • one mip of a 3-mip texture goes global
  • texture made but not yet used in this list goes global
  • texture with no host copy yet goes global
  • same texture twice in one call goes global
  • list has it as SRV but the guest says UAV before goes global

So 2 calls scoped, 6 global, and the debug layer had nothing to say about any of the barriers. I checked that it was really validating by adding one wrong transition at the end, which it reported.

I looked at 7383d45 first and this head fixes what I had noted there. Unnamed syncs (ALL, COPY, RESOLVE, SPLIT) and partial subresource ranges or non-zero flags now stay on the global path (eligible_texture_wait, waits.rs:333-356), unmade or untracked textures fall back instead of being skipped (resource.rs:1744, host.rs:5241), and groups_asked is back to main's logic, so a call with nothing to wait for records the same as before. The old access-derived mapping, with the comment about layout 18 and the let _ for unused constants, is gone and barrier_state (waits.rs:487) is a strict whitelist now. With the switch unset the recording and replay are the same as main's apart from the extra false passed to count_groups.

Only remark left is about how often it'll actually fire. A texture has to already be tracked in the same host list, so a barrier at the start of a list on something the previous list wrote always takes the global path. That's the safe choice, it just means the RDNA numbers will depend a lot on how a title splits its lists.

Clippy -p victory-gpu --all-targets, with and without diagnostics, shows the same warnings as the merge-base.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-04 02:12 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/408#issuecomment-7398698252) Tested a56159f natively on Windows 11 (MSVC) with real D3D12, one NVIDIA desktop card plus WARP. Full `cargo test -p victory-gpu --lib` (skipping `descriptor::tests::views_die_with_their_resource`) gives 339 passed / 5 failed / 23 ignored on the merge-base, and this PR gives 346 / 5 / 24 with the switch unset and the same with `VICTORY_TEXTURE_BARRIERS=1`. The five failures are the ones main already has on this machine (two `indirect::tests::host_list_*`, two `pipeline::host` library loads, the flaky `watch` one). The new tests are CPU only, so I also ran a throwaway local test (not pushed) that sends barrier groups through a newer-layout title list with the switch on and submits it, in a `diagnostics` build with `VICTORY_D3D12_DEBUG=1`, on the card and on WARP. Before each planned call it puts the texture into UAV state in the back list the same way a dispatch would, through `ensure_state`. Eight calls, same result on both adapters. - whole texture UAV to SRV gets one resource transition and no global barrier - whole texture UAV to UAV gets one resource UAV barrier - SyncBefore ALL goes global - one mip of a 3-mip texture goes global - texture made but not yet used in this list goes global - texture with no host copy yet goes global - same texture twice in one call goes global - list has it as SRV but the guest says UAV before goes global So 2 calls scoped, 6 global, and the debug layer had nothing to say about any of the barriers. I checked that it was really validating by adding one wrong transition at the end, which it reported. I looked at 7383d45 first and this head fixes what I had noted there. Unnamed syncs (ALL, COPY, RESOLVE, SPLIT) and partial subresource ranges or non-zero flags now stay on the global path (`eligible_texture_wait`, waits.rs:333-356), unmade or untracked textures fall back instead of being skipped (resource.rs:1744, host.rs:5241), and `groups_asked` is back to main's logic, so a call with nothing to wait for records the same as before. The old access-derived mapping, with the comment about layout 18 and the `let _` for unused constants, is gone and `barrier_state` (waits.rs:487) is a strict whitelist now. With the switch unset the recording and replay are the same as main's apart from the extra `false` passed to `count_groups`. Only remark left is about how often it'll actually fire. A texture has to already be tracked in the same host list, so a barrier at the start of a list on something the previous list wrote always takes the global path. That's the safe choice, it just means the RDNA numbers will depend a lot on how a title splits its lists. Clippy `-p victory-gpu --all-targets`, with and without `diagnostics`, shows the same warnings as the merge-base. AI-assisted: yes
Author
Owner

@⁠fsrajner on GitHub · 2026-12-04 08:14 UTC · original

Tested on top of main together with the other PRs listed below, with VICTORY_TEXTURE_BARRIERS=1 and without it. There is no measurable change in this scene. The worst window was a bit tighter with the switch (61.5 vs 82.9 ms). The 82.9 ms came from a first run that re-prepared shaders, so I would not read anything into it. No visual problems were noticed in these headless runs, but I did not check the output image.

Setup: RX 9070 XT 16 GB, Ryzen 7 7800X3D, CachyOS, RADV from this repo's setup.sh. Series X, 3840x2160 output, FSR 4 Quality (4.1.2), RT at defaults, headless gamescope. Same save (the intro); the game stops 120 s after the first press. The figures come from the 5 s stats: frame windows after loading. 2 runs per variant; main = 0fd7614. The PR build is main + #382 + #392 + #393 + #408 + #445 + #369 together. #398 was left out because it conflicts with #369 in the residency planning. The #369 merge conflicted only with local counters.

variant ms/frame (runs) 5 s windows > 40 ms worst 5% worst window long frames (longest)
main 47 (48, 45) 86.5% 59.3 ms 62.8 ms 1184 (275 ms)
PR build, defaults 46 (46, 46) 85.7% 61.3 ms 82.9 ms 1176 (254 ms)
PR build + VICTORY_TEXTURE_BARRIERS=1 46 (46, 46) 88.9% 59.0 ms 61.5 ms 1137 (172 ms)
PR build + VICTORY_CARD_KEPT_MB=9216 45 (44, 46) 83.8% 63.4 ms 65.1 ms 1171 (201 ms)

The first run of main and of the PR build each began by re-preparing shaders after a translator change. That is likely where the 48 ms run and the 82.9 ms worst window come from. Otherwise the spread between runs is about ±1 ms/frame, so all of these are within noise. In this scene the card is the limit (about 21-24 ms of GPU wait per frame).

**@⁠fsrajner** on GitHub · 2026-12-04 08:14 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/408#issuecomment-7405690143) Tested on top of main together with the other PRs listed below, with `VICTORY_TEXTURE_BARRIERS=1` and without it. There is no measurable change in this scene. The worst window was a bit tighter with the switch (61.5 vs 82.9 ms). The 82.9 ms came from a first run that re-prepared shaders, so I would not read anything into it. No visual problems were noticed in these headless runs, but I did not check the output image. **Setup:** RX 9070 XT 16 GB, Ryzen 7 7800X3D, CachyOS, RADV from this repo's `setup.sh`. Series X, 3840x2160 output, FSR 4 Quality (4.1.2), RT at defaults, headless gamescope. Same save (the intro); the game stops 120 s after the first press. The figures come from the 5 s `stats: frame` windows after loading. 2 runs per variant; main = 0fd7614. The PR build is main + #382 + #392 + #393 + #408 + #445 + #369 together. #398 was left out because it conflicts with #369 in the residency planning. The #369 merge conflicted only with local counters. | variant | ms/frame (runs) | 5 s windows > 40 ms | worst 5% | worst window | long frames (longest) | |---|---|---|---|---|---| | main | 47 (48, 45) | 86.5% | 59.3 ms | 62.8 ms | 1184 (275 ms) | | PR build, defaults | 46 (46, 46) | 85.7% | 61.3 ms | 82.9 ms | 1176 (254 ms) | | PR build + `VICTORY_TEXTURE_BARRIERS=1` | 46 (46, 46) | 88.9% | 59.0 ms | 61.5 ms | 1137 (172 ms) | | PR build + `VICTORY_CARD_KEPT_MB=9216` | 45 (44, 46) | 83.8% | 63.4 ms | 65.1 ms | 1171 (201 ms) | The first run of main and of the PR build each began by re-preparing shaders after a translator change. That is likely where the 48 ms run and the 82.9 ms worst window come from. Otherwise the spread between runs is about ±1 ms/frame, so all of these are within noise. In this scene the card is the limit (about 21-24 ms of GPU wait per frame).
Author
Owner

@⁠Luxuride on GitHub · 2026-12-04 12:20 UTC · original

Careful, self-documenting patch — and it makes the thing it speeds up about seven times slower on the CPU, with zero D3D12 calls ever executed. Park it until someone can show a frame-time win.

The numbers are your own: planning cost +676% paired (4.98 µs → 37.96 µs per 1024 calls) to narrow 3 of 16 synthetic calls. That is a record-path regression bought with an unmeasured GPU-side maybe, and the GPU side is exactly where an off-by-one in a barrier state pair becomes a black screen under vkd3d-proton.

Two things that would have to change before it is reviewable at all:

  • "No D3D12 calls were executed" — 1,426 lines that have never issued a barrier, verified by a shim plus six parser tests (crates/victory-gpu/src/waits.rs:1086). Either someone runs it on a real device and reports the frame time, or it stays a draft.
  • The switch is documented nowhere a user looks: waits.rs:135 is the only mention. Nothing in docs/SETTINGS.md, nothing in run.conf.default, so per README.md:125 it never appears in the F1 menu. A switch that does nothing until someone reads the source is a switch nobody will ever turn on.

Credit where it is due: try_barrier_copies (crates/victory-gpu/src/host.rs:5241-5268) validates every op before mutating any state entry, so a mid-way ScopeFallback cannot leave tracked states half-advanced. That was the thing most likely to be wrong and it is right.

42 behind, no conflict. If it comes back, bring the measured delta and the docs/SETTINGS.md row.

**@⁠Luxuride** on GitHub · 2026-12-04 12:20 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/408#issuecomment-7411297425) Careful, self-documenting patch — and it makes the thing it speeds up about seven times slower on the CPU, with zero D3D12 calls ever executed. Park it until someone can show a frame-time win. The numbers are your own: planning cost +676% paired (4.98 µs → 37.96 µs per 1024 calls) to narrow 3 of 16 synthetic calls. That is a record-path regression bought with an unmeasured GPU-side maybe, and the GPU side is exactly where an off-by-one in a barrier state pair becomes a black screen under vkd3d-proton. Two things that would have to change before it is reviewable at all: - "No D3D12 calls were executed" — 1,426 lines that have never issued a barrier, verified by a shim plus six parser tests (`crates/victory-gpu/src/waits.rs:1086`). Either someone runs it on a real device and reports the frame time, or it stays a draft. - The switch is documented nowhere a user looks: `waits.rs:135` is the only mention. Nothing in `docs/SETTINGS.md`, nothing in `run.conf.default`, so per `README.md:125` it never appears in the F1 menu. A switch that does nothing until someone reads the source is a switch nobody will ever turn on. Credit where it is due: `try_barrier_copies` (`crates/victory-gpu/src/host.rs:5241-5268`) validates every op before mutating any state entry, so a mid-way `ScopeFallback` cannot leave tracked states half-advanced. That was the thing most likely to be wrong and it is right. 42 behind, no conflict. If it comes back, bring the measured delta and the `docs/SETTINGS.md` row.
Author
Owner

@⁠Xough on GitHub · 2026-12-04 21:43 UTC · original

Tested on an RX 6700 XT (12 GB, RDNA 2), Ryzen 9 7900X, CachyOS, ray tracing off, preset high, FSR 4.1 performance, no frame generation, 1920x1080 output. Built-in benchmark (VICTORY_BENCH=nort, 3 min each, first 60 s excluded), this PR merged on top of main.

VICTORY_TEXTURE_BARRIERS avg fps 1% low
unset (off) 30.5 17.6
1, run 1 30.6 17.7
1, run 2 31.2 17.7

No measurable difference here, within run-to-run noise (about 0.3-0.5 fps). I only measured frame rates, not rendering correctness. A frame in this scene records roughly 500 barriers, so replacing some global ones does not move the total much on this card.

**@⁠Xough** on GitHub · 2026-12-04 21:43 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/408#issuecomment-7425056508) Tested on an RX 6700 XT (12 GB, RDNA 2), Ryzen 9 7900X, CachyOS, ray tracing off, preset high, FSR 4.1 performance, no frame generation, 1920x1080 output. Built-in benchmark (`VICTORY_BENCH=nort`, 3 min each, first 60 s excluded), this PR merged on top of main. | `VICTORY_TEXTURE_BARRIERS` | avg fps | 1% low | |---|---|---| | unset (off) | 30.5 | 17.6 | | 1, run 1 | 30.6 | 17.7 | | 1, run 2 | 31.2 | 17.7 | No measurable difference here, within run-to-run noise (about 0.3-0.5 fps). I only measured frame rates, not rendering correctness. A frame in this scene records roughly 500 barriers, so replacing some global ones does not move the total much on this card.
github-bot changed title from gpu: forward texture enhanced barriers as resource-scoped host barriers to perf(gpu): forward texture enhanced barriers as resource-scoped host barriers 2026-12-04 22:20:03 +00:00
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-05 10:21 UTC · original

Thanks for the reviews and hardware runs. The switch is now documented in both SETTINGS.md and run.conf.default. Kal0s-design's native D3D12 test also exercised actual barriers. The new Standard CPU comparison still shows extra planning cost (about 37 µs per synthetic sample), and the gameplay tests show no measurable gain. It remains experimental.

**@⁠tommiehansen** on GitHub · 2026-12-05 10:21 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/408#issuecomment-7436382875) Thanks for the reviews and hardware runs. The switch is now documented in both SETTINGS.md and run.conf.default. [Kal0s-design's native D3D12 test](https://git.gtahub.st/github/lobomfz--VIctory-xmem/pulls/408) also exercised actual barriers. The new Standard CPU comparison still shows extra planning cost (about 37 µs per synthetic sample), and the gameplay tests show no measurable gain. It remains experimental.
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/408/head:github-bot/gh-408'
git switch 'github-bot/gh-408'

Merge

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