Refresh the textures new to a submission on several threads (less texture pop-in on a Radeon 8060S; no frame-rate change shown) #222

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

@⁠SPFCChris on GitHub · 2026-11-26 03:19 UTC · original
SPFCChris:perf/parallel-texture-refresh → main · +30 −5 · 1 files · 1 commits · open

What this changes on screen was judged by eye and by a slot count, not by frame rate: I could not show a frame-rate change either way. It was measured on top of #148, #178 and #179, not on main alone. See "Measured".

What it is for

While a scene streams in, many textures become visible to bindless slots at once. Each such texture is queued (texture::upload_first) and, at the next submission, Early::take read, hashed and detiled them one after another on the submitting thread. On a Radeon 8060S that is where textures arrive late after a scene cut.

The change

One place, Early::take in host.rs (30 lines):

  • The textures that are due are collected first (the same test as before: not one the lists use when late, and not already refreshed in this submission).
  • They are refreshed through in_parallel, several at a time. Each Staging has its own buffer, its own notes and its own lock, and Batch::texture_due lets a texture in only once, so no two threads touch the same one.
  • The states and barriers of those that changed are then applied on the submitting thread, in the same order as before.
  • VICTORY_TEXTURE_THREADS=0 refreshes them one after another, as before. With one texture due nothing is spread.

The textures the lists themselves ask for (Step::Texture in run_deferred) are still refreshed in turn; that is a separate step.

The repository's rx9070xt branch does the same thing its own way (VICTORY_WIDE_TEXTURES, Batch::refresh_textures).

Measured

Radeon 8060S (Ryzen AI Max+ 395), diag build, Series X profile, opening cutscene, 220 s in the world per run. All on main (4f62c2a) plus #148, #178, #179 (with its fix), the terminator fix of #156/#207 and local diagnostics, with the switches of #215 off. On that build in_parallel keeps its threads (#178); on main alone it makes them at each call, which I have not measured with this change.

By eye: the two first runs with this on were the first on this machine without badly late textures after scene cuts.

A pair on one build, every frame logged (slots waiting = bindless slots not yet made, which show nothing):

frames in 220 s median frame time with slots waiting slots waiting x time stalls (frames over 3x the median)
VICTORY_TEXTURE_THREADS=0 1,079 163 ms 33 % 309 thousand slot-seconds 31, 32.5 s
default (several threads) 1,205 148 ms 24 % 207 thousand slot-seconds 34, 33.3 s

Two more runs with it on, against one run of the build before it: 1,118 and 1,068 frames against 1,141; 26 and 29 stalls (28.8 and 31.0 s) against 49 (41.7 s).

What I take from this: a third fewer slot-seconds in the pair, fewer stalls in one comparison and no change in the other, and frame rates that differ by less than two runs of the same build do (about 10 % here). The texture refresh itself costs more processor time summed over the threads (7.6 ms a frame against 4.9).

Stability

  • Three runs of about four minutes in the world with this on and the switches of #215 off: no device loss.
  • The same night, on the same build: one run with this off lost the device (DEVICE_HUNG), and of two runs with this on and the switches of #215 on, one hung the whole machine (GPU engine timeout). I do not think this change is the cause (it happens with it off too), but I cannot rule it out from five runs.

Tested

  • cargo test -p victory-gpu --lib --locked on this branch: 113 passed, 0 failed, 4 ignored, in six runs of seven. In the first run after a clean build pipeline::library::tests::concurrent_atomic_writes_publish_one_complete_file failed and the test process ended with an access violation; it passed alone and in every run after. I have not looked into that test.
  • cargo clippy -p victory-gpu --locked: 40 warnings in the library, as on main; none in the changed lines.

Not tested

  • This branch as it is in the game (main alone renders wrongly on this GPU without #148).
  • Any other GPU or CPU.
  • A build without diagnostics.
  • Anything past the opening cutscene.
  • No new unit test: Early::take needs a device and a title's lists.

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

🤖 Generated with Claude Code

**@⁠SPFCChris** on GitHub · 2026-11-26 03:19 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/222) `SPFCChris:perf/parallel-texture-refresh` → `main` · +30 −5 · 1 files · 1 commits · open **What this changes on screen was judged by eye and by a slot count, not by frame rate: I could not show a frame-rate change either way. It was measured on top of #148, #178 and #179, not on `main` alone. See "Measured".** ## What it is for While a scene streams in, many textures become visible to bindless slots at once. Each such texture is queued (`texture::upload_first`) and, at the next submission, `Early::take` read, hashed and detiled them one after another on the submitting thread. On a Radeon 8060S that is where textures arrive late after a scene cut. ## The change One place, `Early::take` in `host.rs` (30 lines): - The textures that are due are collected first (the same test as before: not one the lists use when `late`, and not already refreshed in this submission). - They are refreshed through `in_parallel`, several at a time. Each `Staging` has its own buffer, its own notes and its own lock, and `Batch::texture_due` lets a texture in only once, so no two threads touch the same one. - The states and barriers of those that changed are then applied on the submitting thread, in the same order as before. - `VICTORY_TEXTURE_THREADS=0` refreshes them one after another, as before. With one texture due nothing is spread. The textures the lists themselves ask for (`Step::Texture` in `run_deferred`) are still refreshed in turn; that is a separate step. The repository's `rx9070xt` branch does the same thing its own way (`VICTORY_WIDE_TEXTURES`, `Batch::refresh_textures`). ## Measured Radeon 8060S (Ryzen AI Max+ 395), diag build, Series X profile, opening cutscene, 220 s in the world per run. **All on `main` (`4f62c2a`) plus #148, #178, #179 (with its fix), the terminator fix of #156/#207 and local diagnostics**, with the switches of #215 off. On that build `in_parallel` keeps its threads (#178); on `main` alone it makes them at each call, which I have not measured with this change. By eye: the two first runs with this on were the first on this machine without badly late textures after scene cuts. A pair on one build, every frame logged (slots waiting = bindless slots not yet made, which show nothing): | | frames in 220 s | median frame | time with slots waiting | slots waiting x time | stalls (frames over 3x the median) | |---|---|---|---|---|---| | `VICTORY_TEXTURE_THREADS=0` | 1,079 | 163 ms | 33 % | 309 thousand slot-seconds | 31, 32.5 s | | default (several threads) | 1,205 | 148 ms | 24 % | 207 thousand slot-seconds | 34, 33.3 s | Two more runs with it on, against one run of the build before it: 1,118 and 1,068 frames against 1,141; 26 and 29 stalls (28.8 and 31.0 s) against 49 (41.7 s). What I take from this: a third fewer slot-seconds in the pair, fewer stalls in one comparison and no change in the other, and frame rates that differ by less than two runs of the same build do (about 10 % here). The texture refresh itself costs more processor time summed over the threads (7.6 ms a frame against 4.9). ## Stability - Three runs of about four minutes in the world with this on and the switches of #215 off: no device loss. - The same night, on the same build: one run with this **off** lost the device (`DEVICE_HUNG`), and of two runs with this on and the switches of #215 **on**, one hung the whole machine (GPU engine timeout). I do not think this change is the cause (it happens with it off too), but I cannot rule it out from five runs. ## Tested - `cargo test -p victory-gpu --lib --locked` on this branch: 113 passed, 0 failed, 4 ignored, in six runs of seven. In the first run after a clean build `pipeline::library::tests::concurrent_atomic_writes_publish_one_complete_file` failed and the test process ended with an access violation; it passed alone and in every run after. I have not looked into that test. - `cargo clippy -p victory-gpu --locked`: 40 warnings in the library, as on `main`; none in the changed lines. ## Not tested - This branch as it is in the game (`main` alone renders wrongly on this GPU without #148). - Any other GPU or CPU. - A build without `diagnostics`. - Anything past the opening cutscene. - No new unit test: `Early::take` needs a device and a title's lists. AI-assisted (Claude Code); no game data. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A bindless slot that begins to view a texture queues it for the next
submission (`texture::upload_first`), and `Early::take` then read, hashed
and detiled each one in turn on the submitting thread. While a scene
streams in that is many textures at once. Each has its own staging
buffer, notes and lock, so they are now refreshed through `in_parallel`,
several at a time; states and barriers are applied afterwards in the
same order as before. `VICTORY_TEXTURE_THREADS=0` refreshes them one
after another as before.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:38:12 +00:00
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 19:54 UTC · original

Native Windows results for 032e27e, base 4f62c2a. Machine: Windows 11 (build 26300), Radeon RX 7900 XT (driver 32.0.32029.2010), 16 logical CPUs, Rust 1.98.1. Other jobs were running on the machine at the same time. I did not run the game.

The description says this was not measured on main alone, without #178. The timings below cover that case.

Code reading (build without diagnostics):

  • refresh writes only its own staging buffer and takes only its own last lock. Two shared locks are involved: the write-watch journal, and briefly the windows map in committed(). The journal is held across GetWriteWatch. For write-watched textures the queries therefore still run one at a time. Only the copy and the detiling run in parallel.
  • Nothing under refresh calls in_parallel, so no call is nested inside another. The barriers are added in the same order as before.
  • SCRATCH is per thread. On main the helper threads are new at each call. Each one allocates and zero-fills a buffer as large as the largest texture it reads, at every call. With #178 the five kept threads each keep their buffer, up to 64 MiB each. I did not measure this.
  • From reading only: on rx9070xt (81ebb7b), Batch::refresh_textures (host.rs:7962) also takes the write-watch journal through watch::writes (texture.rs:1186) and keeps one read buffer per thread (texture.rs:423-440). It runs on kept threads (wide_each, shadow.rs:1580), so it does not pay the per-call thread cost measured below on main without #178.

Local test, not part of the PR:

  • Setup: 96 textures, pushed onto the queue that upload_first uses. Sizes from 16x16 to 1024x1024, RGBA8, in SW_64KB_D, SW_4KB_S or linear layout. Half are in write-watched memory and half are hashed.
  • Steps: four submissions. First, all textures are new. Then two thirds are rewritten. Then none are rewritten, and some are queued twice. Then one fifth are rewritten. After each submission, every host texture was read back and compared byte for byte with its texels, and its state was checked.
  • Results: it passed 15 times on the 7900 XT and 15 times on WARP, both with and without VICTORY_TEXTURE_THREADS=0. It also passed 5 times in each of those four setups on this PR merged with #178. The read-backs were identical in every run.
  • A change that marks the wrong texture as refreshed makes the test fail, with and without threads. So the test does check this.

Timing of Early::take alone: release build, no GPU work, measured after the 7900 XT device is created. Each figure is the median of 5 alternating runs of 30 takes, in µs. Before each take, every texture's memory was changed, unless the row says "unchanged". The =0 column is this PR with VICTORY_TEXTURE_THREADS=0.

textures memory =0 this PR this PR + #178
2 × 256x256 hashed 174 162 92
4 × 256x256 hashed 320 259 107
8 × 64x64 hashed 78 211 26
32 × 64x64 hashed 300 211 70
8 × 256x256 hashed 636 370 179
32 × 256x256 hashed 2,471 696 570
16 × 1024x1024 hashed 20,943 8,437 6,376
32 × 256x256 write-watched 1,127 535 382
16 × 1024x1024 write-watched 9,617 7,335 4,613
32 × 256x256, unchanged write-watched 26 208 58
16 × 1024x1024, unchanged write-watched 77 210 113
  • On main alone, this PR was faster in every row that took 300 µs or more with =0. It was about even at 174 µs. Takes with little work, or with unchanged write-watched textures, cost about 210 µs instead of 26 to 78 µs.
  • With #178 and VICTORY_HELPERS=0 (threads made at each call), the figures are close to "this PR". So the extra cost on main comes from making the threads. With #178 and VICTORY_TEXTURE_THREADS=0, they match =0.
  • With #178 it was faster than =0 in every row where the textures had changed. Unchanged write-watched textures were still slower than =0: 58 against 26 µs, and 113 against 77 µs.
  • In unit tests, hashed textures that did not change are hashed again at every take, because the back-off is off under cfg(test). I left those cases out.

Unit tests (victory-gpu --lib, debug), alternating runs: 70 of 4f62c2a, 70 of this PR, and 30 of this PR with =0. Runs with at least one failure: 17 on 4f62c2a, 16 on this PR, 12 with =0.

  • watch:: guard-page tests: failed on all three.
  • queue:: tests: 1 run on 4f62c2a, 2 with =0, 0 on this PR.
  • query::tests::queries_not_run_keep_their_stand_in_values: 1 run with =0 only.
  • pipeline::library::tests::concurrent_atomic_writes_publish_one_complete_file: 4 of 70 on this PR, 1 of 30 with =0, 0 of 70 on 4f62c2a. It has failed on 4f62c2a on this machine in earlier runs, and the description mentions it too. It also failed with =0, where Early::take uses no threads.
  • descriptor::host::tests::bindless_plan_is_remade_only_when_slots_change: 1 of 70 on this PR, 0 of 70 on 4f62c2a. It failed at its first assert (first.reads.len() was 0, not 1). That test only builds a heap's bindless plan and does not submit anything. I don't think it is related, but one failure is not enough to rule it out.

Not tested:

  • The game or frame times.
  • Another GPU or CPU.
  • The diagnostics feature.

I have the test as a local branch if it is useful.

**@⁠adrianmjim** on GitHub · 2026-11-26 19:54 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/222#issuecomment-7202084999) Native Windows results for 032e27e, base 4f62c2a. Machine: Windows 11 (build 26300), Radeon RX 7900 XT (driver 32.0.32029.2010), 16 logical CPUs, Rust 1.98.1. Other jobs were running on the machine at the same time. I did not run the game. The description says this was not measured on `main` alone, without #178. The timings below cover that case. Code reading (build without `diagnostics`): - `refresh` writes only its own staging buffer and takes only its own `last` lock. Two shared locks are involved: the write-watch journal, and briefly the windows map in `committed()`. The journal is held across `GetWriteWatch`. For write-watched textures the queries therefore still run one at a time. Only the copy and the detiling run in parallel. - Nothing under `refresh` calls `in_parallel`, so no call is nested inside another. The barriers are added in the same order as before. - `SCRATCH` is per thread. On `main` the helper threads are new at each call. Each one allocates and zero-fills a buffer as large as the largest texture it reads, at every call. With #178 the five kept threads each keep their buffer, up to 64 MiB each. I did not measure this. - From reading only: on `rx9070xt` (81ebb7b), `Batch::refresh_textures` (host.rs:7962) also takes the write-watch journal through `watch::writes` (texture.rs:1186) and keeps one read buffer per thread (texture.rs:423-440). It runs on kept threads (`wide_each`, shadow.rs:1580), so it does not pay the per-call thread cost measured below on `main` without #178. Local test, not part of the PR: - Setup: 96 textures, pushed onto the queue that `upload_first` uses. Sizes from 16x16 to 1024x1024, RGBA8, in `SW_64KB_D`, `SW_4KB_S` or linear layout. Half are in write-watched memory and half are hashed. - Steps: four submissions. First, all textures are new. Then two thirds are rewritten. Then none are rewritten, and some are queued twice. Then one fifth are rewritten. After each submission, every host texture was read back and compared byte for byte with its texels, and its state was checked. - Results: it passed 15 times on the 7900 XT and 15 times on WARP, both with and without `VICTORY_TEXTURE_THREADS=0`. It also passed 5 times in each of those four setups on this PR merged with #178. The read-backs were identical in every run. - A change that marks the wrong texture as refreshed makes the test fail, with and without threads. So the test does check this. Timing of `Early::take` alone: release build, no GPU work, measured after the 7900 XT device is created. Each figure is the median of 5 alternating runs of 30 takes, in µs. Before each take, every texture's memory was changed, unless the row says "unchanged". The `=0` column is this PR with `VICTORY_TEXTURE_THREADS=0`. | textures | memory | `=0` | this PR | this PR + #178 | |---|---|---|---|---| | 2 × 256x256 | hashed | 174 | 162 | 92 | | 4 × 256x256 | hashed | 320 | 259 | 107 | | 8 × 64x64 | hashed | 78 | 211 | 26 | | 32 × 64x64 | hashed | 300 | 211 | 70 | | 8 × 256x256 | hashed | 636 | 370 | 179 | | 32 × 256x256 | hashed | 2,471 | 696 | 570 | | 16 × 1024x1024 | hashed | 20,943 | 8,437 | 6,376 | | 32 × 256x256 | write-watched | 1,127 | 535 | 382 | | 16 × 1024x1024 | write-watched | 9,617 | 7,335 | 4,613 | | 32 × 256x256, unchanged | write-watched | 26 | 208 | 58 | | 16 × 1024x1024, unchanged | write-watched | 77 | 210 | 113 | - On `main` alone, this PR was faster in every row that took 300 µs or more with `=0`. It was about even at 174 µs. Takes with little work, or with unchanged write-watched textures, cost about 210 µs instead of 26 to 78 µs. - With #178 and `VICTORY_HELPERS=0` (threads made at each call), the figures are close to "this PR". So the extra cost on `main` comes from making the threads. With #178 and `VICTORY_TEXTURE_THREADS=0`, they match `=0`. - With #178 it was faster than `=0` in every row where the textures had changed. Unchanged write-watched textures were still slower than `=0`: 58 against 26 µs, and 113 against 77 µs. - In unit tests, hashed textures that did not change are hashed again at every take, because the back-off is off under `cfg(test)`. I left those cases out. Unit tests (`victory-gpu --lib`, debug), alternating runs: 70 of 4f62c2a, 70 of this PR, and 30 of this PR with `=0`. Runs with at least one failure: 17 on 4f62c2a, 16 on this PR, 12 with `=0`. - `watch::` guard-page tests: failed on all three. - `queue::` tests: 1 run on 4f62c2a, 2 with `=0`, 0 on this PR. - `query::tests::queries_not_run_keep_their_stand_in_values`: 1 run with `=0` only. - `pipeline::library::tests::concurrent_atomic_writes_publish_one_complete_file`: 4 of 70 on this PR, 1 of 30 with `=0`, 0 of 70 on 4f62c2a. It has failed on 4f62c2a on this machine in earlier runs, and the description mentions it too. It also failed with `=0`, where `Early::take` uses no threads. - `descriptor::host::tests::bindless_plan_is_remade_only_when_slots_change`: 1 of 70 on this PR, 0 of 70 on 4f62c2a. It failed at its first assert (`first.reads.len()` was 0, not 1). That test only builds a heap's bindless plan and does not submit anything. I don't think it is related, but one failure is not enough to rule it out. Not tested: - The game or frame times. - Another GPU or CPU. - The `diagnostics` feature. I have the test as a local branch if it is useful.
Author
Owner

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

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

**@⁠gut0to** on GitHub · 2026-11-27 14:42 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/222#pullrequestreview-6089804925) · **reviewed** AI-assisted static review (ChatGPT); I inspected the diff but did not run tests.
@ -3001,0 +3014,4 @@
dirty[i].store(true, Ordering::Relaxed);
}
}
};
Author
Owner

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

Could this parallel refresh/result-to-barrier path be factored behind an injectable refresh callback and covered by a deterministic test? dirty is indexed separately from due, then the original order is used to emit transitions; a mixed set completing out of order should still refresh each eligible staging once, skip used/duplicate entries, and transition only changed textures in submission order. Covering both serial and parallel modes would protect the new ordering invariant without requiring title data or a GPU.

**@⁠gut0to** on GitHub · 2026-11-27 14:42 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/222#discussion_r4720707407) Could this parallel refresh/result-to-barrier path be factored behind an injectable refresh callback and covered by a deterministic test? `dirty` is indexed separately from `due`, then the original order is used to emit transitions; a mixed set completing out of order should still refresh each eligible staging once, skip used/duplicate entries, and transition only changed textures in submission order. Covering both serial and parallel modes would protect the new ordering invariant without requiring title data or a GPU.
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/222/head:github-bot/gh-222'
git switch 'github-bot/gh-222'

Merge

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