Skip to content

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

Open
ItsYusei99 wants to merge 1 commit into
Marvisak:mainfrom
ItsYusei99:perf/texture-refresh-no-region-query
Open

ItsYusei99 wants to merge 1 commit into
Marvisak:mainfrom
ItsYusei99:perf/texture-refresh-no-region-query

Conversation

@ItsYusei99

Copy link
Copy Markdown

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

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

…ached memory

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ChruutvoLuzi

Copy link
Copy Markdown

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).

@DaviTostes

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

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.

@Yaekai

Yaekai commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.

@neonbyte1

Copy link
Copy Markdown

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).

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
PastiiJay added a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

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

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


Generated by Claude Code

@aycow

aycow commented Nov 25, 2026 •

Copy link
Copy Markdown

@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.

HoLa-Lee pushed a commit to HoLa-Lee/victory-wave-wide-barriers that referenced this pull request Nov 25, 2026
docs/value-vs-upstream.md: the most-starred forks are all doing shader fidelity (JMAN730 42 stars,
DexNom wave64 masks, PastiiJay FidelityFX) and nobody measures frame composition, host memory or how
to drive the menus. Group by group: rpcrt4 and Marvisak#928 are upstream's; COPY_PLAIN, FRAME_LOG,
DRIVER_WATCH supersede ours; the texture-refresh numbers complement Marvisak#388 and Marvisak#1873; the staging
budget, the page-bitmap detile, the pad-stick gap (Marvisak#1702's missing half), the terms page, the
committed saves, the wave64 sentence (Marvisak#2105/Marvisak#599/Marvisak#2035), the ALERT_ERROR_SUPPORT trap and the
memory series complement Marvisak#1479 - with what is worth sending where.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants