Texture read-backs: no title-memory lock or TICKETS held while tiling #270

Open
DB85656 wants to merge 1 commit from upstream-pr/270 into stable-amd
DB85656 commented 2026-11-29 17:22:13 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by DB85656 on 2026-11-29T17:22:13Z.


What

texback::land took the whole title-memory read lock (title_memory_reading()) and TICKETS at its start and held both to the end: across mapping the read-back buffer and tiling every subresource into the console layout. Every remap of title memory, and every ticket invalidation (remapped / replaced / released), waited for a landing to finish.

Now:

  • the mapping read is for this allocation alone (title_memory_reading_in(at, size); with VICTORY_MAP_LOCK_FINE=1 only a change of that memory waits);
  • it and TICKETS are held only while the allocation's bytes are read and while the tiled result is written back; mapping and tiling run without either;
  • the ticket is checked again, under both, before copy_mapped, so a remap or release during the tiling skips the write, exactly as a change before the landing did. Both checks go through one still_valid() (same "skipping texture readbacks whose title allocation changed" line).

Lock order (mapping, then TICKETS) is unchanged. Nothing else changes: same bytes copied, same skips.

Measured

On my build (beta-amd base, Core Ultra 7 265KF, RX 9060 XT, 4K, VICTORY_MAP_LOCK_FINE=1), in the game: texture read-back landings went from peaks of 60.75 ms to about 1-2 ms, and waits on the mapping lock fell from several seconds to a few tens of ms per 5 s window. With VICTORY_MAP_LOCK_FINE off (the default) the gain comes only from not holding the lock while tiling.

Testing

  • This commit is the same change ported onto current stable-amd (texback.rs was identical there, the patch applied as is), but it has not been built or run on stable-amd yet. texback::tests passed on my branch.
  • A -BenchLength test A/B on stable-amd will follow in a comment.

🤖 Generated with Claude Code

<!-- greyfinch-sync:PastiiJay/klbf-lab:issue:5553181418 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/270). Originally posted by [DB85656](https://github.com/DB85656) on 2026-11-29T17:22:13Z. --- ## What `texback::land` took the whole title-memory read lock (`title_memory_reading()`) and `TICKETS` at its start and held both to the end: across mapping the read-back buffer and tiling every subresource into the console layout. Every remap of title memory, and every ticket invalidation (`remapped` / `replaced` / `released`), waited for a landing to finish. Now: - the mapping read is for this allocation alone (`title_memory_reading_in(at, size)`; with `VICTORY_MAP_LOCK_FINE=1` only a change of that memory waits); - it and `TICKETS` are held only while the allocation's bytes are read and while the tiled result is written back; mapping and tiling run without either; - the ticket is checked again, under both, before `copy_mapped`, so a remap or release during the tiling skips the write, exactly as a change before the landing did. Both checks go through one `still_valid()` (same "skipping texture readbacks whose title allocation changed" line). Lock order (mapping, then `TICKETS`) is unchanged. Nothing else changes: same bytes copied, same skips. ## Measured On my build (beta-amd base, Core Ultra 7 265KF, RX 9060 XT, 4K, `VICTORY_MAP_LOCK_FINE=1`), in the game: texture read-back landings went from peaks of 60.75 ms to about 1-2 ms, and waits on the mapping lock fell from several seconds to a few tens of ms per 5 s window. With `VICTORY_MAP_LOCK_FINE` off (the default) the gain comes only from not holding the lock while tiling. ## Testing - This commit is the same change ported onto current `stable-amd` (`texback.rs` was identical there, the patch applied as is), but it has **not been built or run on `stable-amd` yet**. `texback::tests` passed on my branch. - A `-BenchLength test` A/B on `stable-amd` will follow in a comment. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
PastiiJay commented 2026-11-29 17:25:57 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-29T17:25:57Z.


thanks @DB85656, getting the locks off the tiling path is the kind of change that adds up. it's passed on for the next round.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7259685855 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/270#issuecomment-7259685855). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-29T17:25:57Z. --- thanks @DB85656, getting the locks off the tiling path is the kind of change that adds up. it's passed on for the next round.
efsebayern commented 2026-11-29 18:25:14 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by efsebayern on 2026-11-29T18:25:14Z.


I tested the exact stable-amd base 72d557f and PR head 4cbf331 on Windows 11 25H2, i7-13700K, RTX 4080 SUPER (621.40), and 32 GB RAM. Both were unmodified diag builds with diagnostics. Profile X, title upscaler to 1440p, RT and frame generation off, VICTORY_MAP_LOCK_FINE=1.

Each run started from the same manual save and a fresh copy of the same prewarmed shader/pipeline cache. I used the benchmark's input lock, ran each build for 125 seconds from its first world frame, and included complete diagnostic windows between world +20 and +120 seconds. FPS is weighted by each host window's duration.

Run, in order Avg FPS Avg draws/frame Mapping reader waits/s Total reader wait ms per 5 s Longest reader wait, ms Texture readbacks landed, approx.
A1 · base 9.99 7,301 52.9 1,969 325 16,768
B1 · PR 7.01 9,110 45.0 2,668 508 11,520
B2 · PR 9.23 6,467 29.1 1,587 384 14,848
A2 · base 9.77 6,191 57.8 2,522 227 14,720

Both PR runs had fewer reader waits per second, with mapping activity in a similar range across all runs (872–935 changes/s). Total wait time varied, and both PR runs had a longer individual worst wait than either base run. The wait counters cover all readers of the mapping lock. The PR's per-landing lock hold time was outside the scope of these counters.

This sample did not establish an FPS gain or regression. Draw load varied across repeats from the same save, particularly in B1. Pipeline queues were mostly clear during the sampled windows (max pending 0, 0, 7, 1 in run order). All four runs exercised the texture readback path and completed without device removal. Visual equivalence remains unverified.

cargo test --locked --profile diag -p victory-gpu --features diagnostics --lib texback::tests on the PR head passed the allocation-ticket invalidation test.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7260468400 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/270#issuecomment-7260468400). Originally posted by [efsebayern](https://github.com/efsebayern) on 2026-11-29T18:25:14Z. --- I tested the exact `stable-amd` base `72d557f` and PR head `4cbf331` on Windows 11 25H2, i7-13700K, RTX 4080 SUPER (621.40), and 32 GB RAM. Both were unmodified `diag` builds with `diagnostics`. Profile X, title upscaler to 1440p, RT and frame generation off, `VICTORY_MAP_LOCK_FINE=1`. Each run started from the same manual save and a fresh copy of the same prewarmed shader/pipeline cache. I used the benchmark's input lock, ran each build for 125 seconds from its first world frame, and included complete diagnostic windows between world +20 and +120 seconds. FPS is weighted by each host window's duration. | Run, in order | Avg FPS | Avg draws/frame | Mapping reader waits/s | Total reader wait ms per 5 s | Longest reader wait, ms | Texture readbacks landed, approx. | | --- | ---: | ---: | ---: | ---: | ---: | ---: | | A1 · base | 9.99 | 7,301 | 52.9 | 1,969 | 325 | 16,768 | | B1 · PR | 7.01 | 9,110 | 45.0 | 2,668 | 508 | 11,520 | | B2 · PR | 9.23 | 6,467 | 29.1 | 1,587 | 384 | 14,848 | | A2 · base | 9.77 | 6,191 | 57.8 | 2,522 | 227 | 14,720 | Both PR runs had fewer reader waits per second, with mapping activity in a similar range across all runs (872–935 changes/s). Total wait time varied, and both PR runs had a longer individual worst wait than either base run. The wait counters cover all readers of the mapping lock. The PR's per-landing lock hold time was outside the scope of these counters. This sample did not establish an FPS gain or regression. Draw load varied across repeats from the same save, particularly in B1. Pipeline queues were mostly clear during the sampled windows (max pending 0, 0, 7, 1 in run order). All four runs exercised the texture readback path and completed without device removal. Visual equivalence remains unverified. `cargo test --locked --profile diag -p victory-gpu --features diagnostics --lib texback::tests` on the PR head passed the allocation-ticket invalidation test.
co11ector commented 2026-11-30 07:59:55 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by co11ector on 2026-11-30T07:59:55Z.


Same shape on RDNA 4 (16 GB, Windows 11), v26.11.17, Profile X, FSR 3.1, FG x2.

47-minute run with the per-frame lines on. 17 gaps of 1.5 s or more in the log; the four largest all begin on the line right after victory_gpu::texback: texture readback landed copied=432768 bytes=262144:

  • 26.8 s, 23.4 s, 13.7 s, 13.1 s (the engine logs nothing in between, so the main thread is in it)

The first line after the 26.8 s gap is watch::fine: mapping lock readers (VICTORY_MAP_LOCK_FINE=1), last 5 s: 416 waits 3915.3 ms (longest 108.0 ms).

Private commit was 29.1 GB of 32 GB at that point (commit limit 82 GB, 5.9 GB of RAM free), so page faults are part of it; but the stall always lands on a read-back, and a 108 ms longest wait does not explain 26 s.

Card at the same moment: 11.9 GB in use of a 13.7 GB budget (KLBF_TEXTURE_SHARE=40).

For what it is worth, the #333 leak is not active in this run yet: views.list has 1 entry and shapes is at 125k of 4,194,304, so these stalls are not the shapes saturation.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7272364296 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/270#issuecomment-7272364296). Originally posted by [co11ector](https://github.com/co11ector) on 2026-11-30T07:59:55Z. --- Same shape on RDNA 4 (16 GB, Windows 11), v26.11.17, Profile X, FSR 3.1, FG x2. 47-minute run with the per-frame lines on. 17 gaps of 1.5 s or more in the log; the four largest all begin on the line right after `victory_gpu::texback: texture readback landed copied=432768 bytes=262144`: - 26.8 s, 23.4 s, 13.7 s, 13.1 s (the engine logs nothing in between, so the main thread is in it) The first line after the 26.8 s gap is `watch::fine: mapping lock readers (VICTORY_MAP_LOCK_FINE=1), last 5 s: 416 waits 3915.3 ms (longest 108.0 ms)`. Private commit was 29.1 GB of 32 GB at that point (commit limit 82 GB, 5.9 GB of RAM free), so page faults are part of it; but the stall always lands on a read-back, and a 108 ms longest wait does not explain 26 s. Card at the same moment: 11.9 GB in use of a 13.7 GB budget (`KLBF_TEXTURE_SHARE=40`). For what it is worth, the #333 leak is not active in this run yet: `views.list` has 1 entry and `shapes` is at 125k of 4,194,304, so these stalls are not the shapes saturation.
PastiiJay commented 2026-11-30 09:57:56 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-30T09:57:56Z.


Thanks again, third excellent report tonight (#329, #145 and this one). You're right about the spot: when a read-back lands, both the title-memory read lock and the tickets list are held for the whole read, tiling and copy, so a remap waiting on that lock can leave everything else queued behind it. Tiling outside the locks and keeping only the check and the copy under them is the direction we're looking at.

An A/B to confirm, same save, same drive: VICTORY_TEXTURE_BACK=0. It turns those read-backs off. Test only: with it, boats sit too low in the water, since that's what the read-backs are for. If the big freezes go away, that confirms it.

Also: is VICTORY_MAP_LOCK_FINE something you set yourself, or did it come from the launcher?

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7274925682 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/270#issuecomment-7274925682). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-30T09:57:56Z. --- Thanks again, third excellent report tonight (#329, #145 and this one). You're right about the spot: when a read-back lands, both the title-memory read lock and the tickets list are held for the whole read, tiling and copy, so a remap waiting on that lock can leave everything else queued behind it. Tiling outside the locks and keeping only the check and the copy under them is the direction we're looking at. An A/B to confirm, same save, same drive: `VICTORY_TEXTURE_BACK=0`. It turns those read-backs off. Test only: with it, boats sit too low in the water, since that's what the read-backs are for. If the big freezes go away, that confirms it. Also: is `VICTORY_MAP_LOCK_FINE` something you set yourself, or did it come from the launcher?
co11ector commented 2026-11-30 10:58:29 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by co11ector on 2026-11-30T10:58:29Z.


VICTORY_MAP_LOCK_FINE=1 comes from KLBF's own play.ps1, line 367 (VICTORY_MAP_LOCK_FINE = '1'; VICTORY_POOL_CAP = '1'); my launch profile copies that line verbatim. Nothing I added.

On #333: I checked my logs and you are right, the shape path is not the problem in KLBF. In the 47-minute run the memory, more: line shows shapes of placed views kept: 124453 -> 125753 and of the view table's entries 1 are constant buffer views and 0 views of placed memory, so KLBF_PLACED_NORMAL is doing its job and nothing reached the 2^22 cap.

I will run the VICTORY_TEXTURE_BACK=0 A/B on the same save and post the freeze gaps here. The boats sitting low is fine for a test.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7276345250 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/270#issuecomment-7276345250). Originally posted by [co11ector](https://github.com/co11ector) on 2026-11-30T10:58:29Z. --- `VICTORY_MAP_LOCK_FINE=1` comes from KLBF's own `play.ps1`, line 367 (`VICTORY_MAP_LOCK_FINE = '1'; VICTORY_POOL_CAP = '1'`); my launch profile copies that line verbatim. Nothing I added. On #333: I checked my logs and you are right, the shape path is not the problem in KLBF. In the 47-minute run the `memory, more:` line shows `shapes of placed views kept: 124453 -> 125753` and `of the view table's entries 1 are constant buffer views and 0 views of placed memory`, so `KLBF_PLACED_NORMAL` is doing its job and nothing reached the 2^22 cap. I will run the `VICTORY_TEXTURE_BACK=0` A/B on the same save and post the freeze gaps here. The boats sitting low is fine for a test.
PastiiJay commented 2026-11-30 10:59:17 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-30T10:59:17Z.


Thanks @co11ector, good to know VICTORY_MAP_LOCK_FINE=1 comes from our own launcher defaults, noted. And thanks for checking the #333 path in your logs too. Looking forward to the VICTORY_TEXTURE_BACK=0 A/B.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7276367737 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/270#issuecomment-7276367737). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-30T10:59:17Z. --- Thanks @co11ector, good to know `VICTORY_MAP_LOCK_FINE=1` comes from our own launcher defaults, noted. And thanks for checking the #333 path in your logs too. Looking forward to the `VICTORY_TEXTURE_BACK=0` A/B.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/270:upstream-pr/270'
git switch 'upstream-pr/270'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'stable-amd'
git merge --no-ff 'upstream-pr/270'
git switch 'upstream-pr/270'
git rebase 'stable-amd'
git switch 'stable-amd'
git merge --ff-only 'upstream-pr/270'
git switch 'upstream-pr/270'
git rebase 'stable-amd'
git switch 'stable-amd'
git merge --no-ff 'upstream-pr/270'
git switch 'stable-amd'
git merge --squash 'upstream-pr/270'
git switch 'stable-amd'
git merge --ff-only 'upstream-pr/270'
git switch 'stable-amd'
git merge 'upstream-pr/270'
git push origin 'stable-amd'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
PastiiJay/klbf-lab!270
No description provided.