GPU: refresh unwatched textures without a region query; detile into cached memory #388

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

@⁠ItsYusei99 on GitHub · 2026-11-24 02:51 UTC · original
ItsYusei99:perf/texture-refresh-no-region-query → main · +32 −13 · 1 files · 1 commits · open

Under Wine, the menus and the intro stuttered. Each frame spent about 28 ms refreshing sampled textures. Two parts of Staging::refresh_now caused it.

1. committed() on the unwatched path. Before it hashes a texture that is not write-watched, refresh_now checks committed(self.memory, size). That check walks the range with VirtualQuery, one region at a time. Wine implements VirtualQuery with a server round trip, so for big texture pools this one check costs most of the refresh. The path now copies the whole texture out with host::read_into (ReadProcessMemory) into Last::read, which the watched path already uses. The copy fails by itself when any page is not committed, so it replaces the check and keeps the same "not committed, skip it" result. A side effect: the hash and the detile now read the copy rather than the title's memory directly. That removes the fault #143 describes, where the title unmaps the pages between the check and the read.

2. Detiling straight into the upload heap. detile wrote each subresource directly into the mapped staging buffer. That buffer is an upload heap, which is write-combined memory, and the scattered writes of a detile are very slow there. Each subresource is now detiled into a cached scratch Vec kept in Last, then copied to the staging buffer in one sequential copy_nonoverlapping.

Cost: one extra CPU copy of each unwatched texture per refresh (the read), and one scratch buffer per staged texture, as large as its biggest subresource.

Measured

Linux, Wine 11.22, vkd3d-proton 3.2.0, RTX 4070 (driver 620.70.06), Ryzen 7 9800X3D. These are frame lines in the menu intro:

  • Before: about 28 ms per frame preparing textures, and the menu stuttered.
  • After: about 7 ms, and the menu runs at a steady 30 fps.

I measured this on my local tree, which also carries other patches: #177, and a 16-bit render target substitution like #89. I have not re-measured on this exact commit, and I have not measured the two parts separately. Not tested on native Windows. VirtualQuery is much cheaper there, so most of the gain there would come from part 2, if any.

Relation to open PRs

  • #143 also reads unwatched textures through a kernel copy, but it keeps the committed() check, which is the slow call under Wine. It uses a thread-local buffer, so it keeps no copy per texture. If that memory matters more, this change can use #143's / #215's thread-local scratch instead of Last::read, as long as the committed() call goes away.
  • #184 parallelises the detile writes into the upload heap. This change makes each subresource a single sequential write, so the two would need merging by hand.

Checks

  • cargo xwin test -p victory-gpu under Wine: 43 passed, 1 ignored.
  • cargo xwin clippy -p victory-gpu --all-targets: no warnings in texture.rs. The one warning is at host.rs:267, which is on main.
  • Release and diag (--features diagnostics) builds OK. cargo xtask policy passes, and rustfmt --check texture.rs is clean.

🤖 Generated with Claude Code

**@⁠ItsYusei99** on GitHub · 2026-11-24 02:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/388) `ItsYusei99:perf/texture-refresh-no-region-query` → `main` · +32 −13 · 1 files · 1 commits · open Under Wine, the menus and the intro stuttered. Each frame spent about 28 ms refreshing sampled textures. Two parts of `Staging::refresh_now` caused it. **1. `committed()` on the unwatched path.** Before it hashes a texture that is not write-watched, `refresh_now` checks `committed(self.memory, size)`. That check walks the range with `VirtualQuery`, one region at a time. Wine implements `VirtualQuery` with a server round trip, so for big texture pools this one check costs most of the refresh. The path now copies the whole texture out with `host::read_into` (`ReadProcessMemory`) into `Last::read`, which the watched path already uses. The copy fails by itself when any page is not committed, so it replaces the check and keeps the same "not committed, skip it" result. A side effect: the hash and the detile now read the copy rather than the title's memory directly. That removes the fault #143 describes, where the title unmaps the pages between the check and the read. **2. Detiling straight into the upload heap.** `detile` wrote each subresource directly into the mapped staging buffer. That buffer is an upload heap, which is write-combined memory, and the scattered writes of a detile are very slow there. Each subresource is now detiled into a cached scratch `Vec` kept in `Last`, then copied to the staging buffer in one sequential `copy_nonoverlapping`. Cost: one extra CPU copy of each unwatched texture per refresh (the read), and one scratch buffer per staged texture, as large as its biggest subresource. ### Measured Linux, Wine 11.22, vkd3d-proton 3.2.0, RTX 4070 (driver 620.70.06), Ryzen 7 9800X3D. These are frame lines in the menu intro: - Before: about 28 ms per frame preparing textures, and the menu stuttered. - After: about 7 ms, and the menu runs at a steady 30 fps. I measured this on my local tree, which also carries other patches: #177, and a 16-bit render target substitution like #89. I have not re-measured on this exact commit, and I have not measured the two parts separately. Not tested on native Windows. `VirtualQuery` is much cheaper there, so most of the gain there would come from part 2, if any. ### Relation to open PRs - #143 also reads unwatched textures through a kernel copy, but it keeps the `committed()` check, which is the slow call under Wine. It uses a thread-local buffer, so it keeps no copy per texture. If that memory matters more, this change can use #143's / #215's thread-local scratch instead of `Last::read`, as long as the `committed()` call goes away. - #184 parallelises the detile writes into the upload heap. This change makes each subresource a single sequential write, so the two would need merging by hand. ### Checks - `cargo xwin test -p victory-gpu` under Wine: 43 passed, 1 ignored. - `cargo xwin clippy -p victory-gpu --all-targets`: no warnings in `texture.rs`. The one warning is at `host.rs:267`, which is on `main`. - Release and `diag` (`--features diagnostics`) builds OK. `cargo xtask policy` passes, and `rustfmt --check texture.rs` is clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:02:09 +00:00
Author
Owner

@⁠ChruutvoLuzi on GitHub · 2026-11-24 03:08 UTC · original

Native Windows numbers, since the description says it isn't tested there. RTX 4090, driver 621.01, Windows 11, i9-14900K, diag build, from boot through the first mission's opening. Base: d2a4bae plus other PRs I was testing; two runs with this PR and two without. The other PRs differ slightly between the runs (#282 and a depth-view patch from #392), and neither touches texture refresh. This PR (e54b675) conflicts with #89 in detile; I kept #89's detile_subresource call and pointed it at this PR's scratch buffer, followed by this PR's single copy to the staging buffer.

From the textures X ms Y MB part of the frame lines, as time per MB:

Menus (the same screens each run) World
Without this PR 0.27 and 0.22 ms/MB 0.39 and 0.57 ms/MB
With this PR 0.35 and 0.34 ms/MB 0.69 and 0.66 ms/MB

In the world that's 86 to 95 ms of texture preparation per frame with this PR, against 54 to 68 ms without, for 118 to 137 MB.

So on native Windows it costs about 40% more per MB in the menus and more in the world. That fits the caveat in the description: VirtualQuery is cheap here, so skipping committed() saves little, while the extra read into last.read and the copy out of the scratch buffer add work. Would it make sense to keep the old path on native Windows and use this one only under Wine, or to keep just the detile-into-cached-memory part?

AI-assisted (Claude Code).

**@⁠ChruutvoLuzi** on GitHub · 2026-11-24 03:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/388#issuecomment-7120802647) Native Windows numbers, since the description says it isn't tested there. RTX 4090, driver 621.01, Windows 11, i9-14900K, diag build, from boot through the first mission's opening. Base: `d2a4bae` plus other PRs I was testing; two runs with this PR and two without. The other PRs differ slightly between the runs (#282 and a depth-view patch from #392), and neither touches texture refresh. This PR (`e54b675`) conflicts with #89 in `detile`; I kept #89's `detile_subresource` call and pointed it at this PR's scratch buffer, followed by this PR's single copy to the staging buffer. From the `textures X ms Y MB` part of the frame lines, as time per MB: | | Menus (the same screens each run) | World | |---|---|---| | Without this PR | 0.27 and 0.22 ms/MB | 0.39 and 0.57 ms/MB | | With this PR | 0.35 and 0.34 ms/MB | 0.69 and 0.66 ms/MB | In the world that's 86 to 95 ms of texture preparation per frame with this PR, against 54 to 68 ms without, for 118 to 137 MB. So on native Windows it costs about 40% more per MB in the menus and more in the world. That fits the caveat in the description: `VirtualQuery` is cheap here, so skipping `committed()` saves little, while the extra read into `last.read` and the copy out of the scratch buffer add work. Would it make sense to keep the old path on native Windows and use this one only under Wine, or to keep just the detile-into-cached-memory part? AI-assisted (Claude Code).
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 13:10 UTC · original

A phase split from a real title run on the gap your thread lacks: Linux/Wine, AMD. I instrumented Staging::refresh locally (not upstream) to time its parts; this is a release build of main ffe310e, package 1.0.2.1, build unknown (b99f876b…).

Setup: RX 9060 XT (RDNA4, RADV 26.3.1), Arch Linux, kernel 6.18.x; Wine 11.22 (system), DXVK 3.1.1 dxgi, vkd3d-proton 3.2.0 (Proton Experimental DLLs), WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=n".

In-world, per 512 texture refreshes:

window committed (VirtualQuery) watch (GetWriteWatch) hash detile copy
a 4049 ms 1064 ms 205 ms 0 ms 0 ms
b 2054 ms 698 ms 104 ms 31 ms 17 ms
c 666 ms 614 ms 179 ms 0 ms 0 ms

The frame line in the same run is textures 871–1413 ms / 80–91 MB, so the region query on the unwatched path is the largest single part, ahead of the write-watch askings and hashing. copy/detile are small.

That matches what this PR removes. It also suggests #776 (write-watch askings) and #401 (hash bypass) stack after it, but this one is the biggest on Wine, where each VirtualQuery/GetWriteWatch crosses into the host kernel.

Not tested: a controlled A/B with the PR itself (I can run it on this machine next), Windows/NVIDIA, long sessions (runs freeze at #774 ~3 min in).

**@⁠DaviTostes** on GitHub · 2026-11-24 13:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/388#issuecomment-7132446449) A phase split from a real title run on the gap your thread lacks: **Linux/Wine, AMD**. I instrumented `Staging::refresh` locally (not upstream) to time its parts; this is a release build of `main` `ffe310e`, package 1.0.2.1, `build unknown (b99f876b…)`. **Setup:** RX 9060 XT (RDNA4, RADV 26.3.1), Arch Linux, kernel 6.18.x; Wine 11.22 (system), DXVK 3.1.1 `dxgi`, vkd3d-proton 3.2.0 (Proton Experimental DLLs), `WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=n"`. In-world, per 512 texture refreshes: | window | `committed` (VirtualQuery) | `watch` (GetWriteWatch) | `hash` | `detile` | `copy` | |---|---:|---:|---:|---:|---:| | a | **4049 ms** | 1064 ms | 205 ms | 0 ms | 0 ms | | b | **2054 ms** | 698 ms | 104 ms | 31 ms | 17 ms | | c | 666 ms | 614 ms | 179 ms | 0 ms | 0 ms | The frame line in the same run is `textures 871–1413 ms / 80–91 MB`, so the **region query on the unwatched path is the largest single part**, ahead of the write-watch askings and hashing. `copy`/`detile` are small. That matches what this PR removes. It also suggests #776 (write-watch askings) and #401 (hash bypass) stack after it, but this one is the biggest on Wine, where each `VirtualQuery`/`GetWriteWatch` crosses into the host kernel. **Not tested:** a controlled A/B with the PR itself (I can run it on this machine next), Windows/NVIDIA, long sessions (runs freeze at #774 ~3 min in).
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 13:41 UTC · original

Stack result on AMD/Wine (main ffe310e + #783 + this PR + #282 + #454), real game, release build:

  • textures 421 → 215 ms per world frame (mean of 35 world lines), bytes unchanged (~92–98 MB); the VirtualQuery share is gone.
  • copies also drop with #783: 2627 → 1263 ms.
  • world fps 0.32 → 0.59 (directional; different scene mix), no rectangles not expanded warnings with #282.
  • Still the dark frozen background; ~3 min in, Wine RtlReleaseSRWLockExclusive and no frame progress. With #454's VICTORY_NO_WATCHDOG=1 the process stays alive instead of the title's null-write exit.

Setup: RX 9060 XT (RDNA4/RADV 26.3.1), Arch, Wine 11.22, DXVK 3.1.1 dxgi, vkd3d-proton 3.2.0, package 1.0.2.1. Not a controlled same-save A/B; not tested on Windows/NVIDIA.

This was the biggest texture win in the stack — thanks.

**@⁠DaviTostes** on GitHub · 2026-11-24 13:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/388#issuecomment-7133193682) Stack result on AMD/Wine (main `ffe310e` + #783 + this PR + #282 + #454), real game, release build: - textures **421 → 215 ms** per world frame (mean of 35 world lines), bytes unchanged (~92–98 MB); the `VirtualQuery` share is gone. - copies also drop with #783: 2627 → 1263 ms. - world fps 0.32 → 0.59 (directional; different scene mix), no `rectangles not expanded` warnings with #282. - Still the dark frozen background; ~3 min in, Wine `RtlReleaseSRWLockExclusive` and no frame progress. With #454's `VICTORY_NO_WATCHDOG=1` the process stays alive instead of the title's null-write exit. Setup: RX 9060 XT (RDNA4/RADV 26.3.1), Arch, Wine 11.22, DXVK 3.1.1 `dxgi`, vkd3d-proton 3.2.0, package 1.0.2.1. Not a controlled same-save A/B; not tested on Windows/NVIDIA. This was the biggest texture win in the stack — thanks.
Author
Owner

@⁠Yaekai on GitHub · 2026-11-24 15:54 UTC · original

Independent test & review on Windows 11 + NVIDIA RTX 3070 (8 GB, Rust 1.98.1) at head e54b675:

  • cargo test -p victory-gpu --lib texture: passed (3 passed, 0 failed, 1 ignored).
  • cargo clippy -p victory-gpu -- -D warnings: 0 warnings.
  • Live GTA VI (1.0.2.1, --console series-s, release build on ffe310e with #452 + #493 + #587 + #211 + #492): ran 19+ minutes in the world (~135–145 MB/frame texture uploads, ~45 ms/frame) with zero texture corruption or stalls.
  • One minor note: detile() computes len = pitch * rows * f.Depth (same as before this PR); if #601 lands alongside this, clamping len to the allocated staging slice (footprint_len) composes cleanly with the cached linear scratch buffer here.

Looks clean and ready to merge once rebased on main.

**@⁠Yaekai** on GitHub · 2026-11-24 15:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/388#issuecomment-7136818633) Independent test & review on Windows 11 + NVIDIA RTX 3070 (8 GB, Rust 1.98.1) at head `e54b675`: - `cargo test -p victory-gpu --lib texture`: passed (3 passed, 0 failed, 1 ignored). - `cargo clippy -p victory-gpu -- -D warnings`: 0 warnings. - Live GTA VI (`1.0.2.1`, `--console series-s`, release build on `ffe310e` with `#452` + `#493` + `#587` + `#211` + `#492`): ran 19+ minutes in the world (~135–145 MB/frame texture uploads, ~45 ms/frame) with zero texture corruption or stalls. - One minor note: `detile()` computes `len = pitch * rows * f.Depth` (same as before this PR); if `#601` lands alongside this, clamping `len` to the allocated staging slice (`footprint_len`) composes cleanly with the cached `linear` scratch buffer here. Looks clean and ready to merge once rebased on `main`.
Author
Owner

@⁠neonbyte1 on GitHub · 2026-11-24 16:29 UTC · original

Measured on Linux: RTX 5090, Wine 11.22 with the wineserver view-tree patch from #340, vkd3d-proton from GE-Proton11-14. Prologue world frames, medians over about 55 summary lines per run.

With this PR merged together with #514, textures was 10.6 ms per frame, compared with 7.8 ms before both. So no gain showed on this setup.

The patched wineserver has already made the VirtualQuery walk this PR removes cheap. With a stock wineserver (no view-tree patch), textures was 46–213 ms per frame in the same scenes. That's the setup where this PR's saving should show up; I haven't measured this PR on a stock wineserver.

AI-assisted (Claude Code).

**@⁠neonbyte1** on GitHub · 2026-11-24 16:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/388#issuecomment-7137744044) Measured on Linux: RTX 5090, Wine 11.22 with the wineserver view-tree patch from #340, vkd3d-proton from GE-Proton11-14. Prologue world frames, medians over about 55 summary lines per run. With this PR merged together with #514, `textures` was 10.6 ms per frame, compared with 7.8 ms before both. So no gain showed on this setup. The patched wineserver has already made the `VirtualQuery` walk this PR removes cheap. With a stock wineserver (no view-tree patch), `textures` was 46–213 ms per frame in the same scenes. That's the setup where this PR's saving should show up; I haven't measured this PR on a stock wineserver. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:31 UTC · original

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (4118f33b). Conflicting files: crates/victory-gpu/src/texture.rs.

The content will be reviewed once the branch is rebased onto main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/388#issuecomment-7148590796) <!-- victory-triage v1 head=e54b6756f5b2a9c218f8f8c7ab4f8931d7ab9030 verdict=needs-rebase at=2026-11-25T00:24:46Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (4118f33b). Conflicting files: `crates/victory-gpu/src/texture.rs`. The content will be reviewed once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠aycow on GitHub · 2026-11-25 01:33 UTC · original · edited 2026-11-25 01:36 UTC

@⁠ItsYusei99 I tested a local FIND-2 candidate on ccfb029 that preserves the exact BLAKE3 digest. It speeds up single-caller synthetic refreshes but loses under concurrent refresh, so it stays off by default. #388 already gives the unwatched hash and detile an immutable input through the checked read. If your design keeps that snapshot stable through both operations, I can test the digest change against it and measure the added read and scratch costs together. Would that input lifetime still hold with your current revision?

Local follow-up: exact #388 e54b675 and the FIND-2 candidate compose with the digest and detiler using the same owned input under the existing lock. Both strict GPU Clippy configurations passed. Digest, range, and staging checks also passed with hashing off and on using the default hardware adapter and WARP. Combined read/scratch cost and title impact remain unmeasured.

**@⁠aycow** on GitHub · 2026-11-25 01:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/388#issuecomment-7149681313) · edited 2026-11-25 01:36 UTC @⁠ItsYusei99 I tested a local FIND-2 candidate on `ccfb029` that preserves the exact BLAKE3 digest. It speeds up single-caller synthetic refreshes but loses under concurrent refresh, so it stays off by default. #388 already gives the unwatched hash and detile an immutable input through the checked read. If your design keeps that snapshot stable through both operations, I can test the digest change against it and measure the added read and scratch costs together. Would that input lifetime still hold with your current revision? Local follow-up: exact #388 `e54b675` and the FIND-2 candidate compose with the digest and detiler using the same owned input under the existing lock. Both strict GPU Clippy configurations passed. Digest, range, and staging checks also passed with hashing off and on using the default hardware adapter and WARP. Combined read/scratch cost and title impact remain unmeasured.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/texture.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/388/head:github-bot/gh-388'
git switch 'github-bot/gh-388'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-388'
git switch 'github-bot/gh-388'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-388'
git switch 'github-bot/gh-388'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-388'
git switch 'main'
git merge --squash 'github-bot/gh-388'
git switch 'main'
git merge --ff-only 'github-bot/gh-388'
git switch 'main'
git merge 'github-bot/gh-388'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!388
No description provided.